diff options
author | Thomas Haller <thaller@redhat.com> | 2022-03-14 07:28:49 (GMT) |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2022-03-14 07:28:49 (GMT) |
commit | c980034d9fc3e23b9ef7c5431307c3ad574841b0 (patch) | |
tree | 6321257641d90329f0e5bd01333f1886a4cf5c0d | |
parent | 90577b5835430cabbebdea99cbfaf6a45f6d5287 (diff) | |
parent | a694c33c07d41e28e937520c0fdde238e28ab5c2 (diff) | |
download | libnl-c980034d9fc3e23b9ef7c5431307c3ad574841b0.zip libnl-c980034d9fc3e23b9ef7c5431307c3ad574841b0.tar.gz libnl-c980034d9fc3e23b9ef7c5431307c3ad574841b0.tar.bz2 |
route/cls: merge branch 'westermo:classifier-api-extension'
https://github.com/thom311/libnl/pull/243
-rw-r--r-- | include/netlink/route/classifier.h | 4 | ||||
-rw-r--r-- | lib/route/cls.c | 72 | ||||
-rw-r--r-- | libnl-route-3.sym | 6 |
3 files changed, 80 insertions, 2 deletions
diff --git a/include/netlink/route/classifier.h b/include/netlink/route/classifier.h index 48f7e6d..d92652b 100644 --- a/include/netlink/route/classifier.h +++ b/include/netlink/route/classifier.h @@ -20,6 +20,10 @@ extern void rtnl_cls_put(struct rtnl_cls *); extern int rtnl_cls_alloc_cache(struct nl_sock *, int, uint32_t, struct nl_cache **); +extern struct rtnl_cls *rtnl_cls_find_by_handle(struct nl_cache *cache, int ifindex, + uint32_t parent, uint32_t handle); +extern struct rtnl_cls *rtnl_cls_find_by_prio(struct nl_cache *cache, int ifindex, + uint32_t parent, uint16_t prio); extern void rtnl_cls_cache_set_tc_params(struct nl_cache *, int, uint32_t); diff --git a/lib/route/cls.c b/lib/route/cls.c index b8daae4..8583103 100644 --- a/lib/route/cls.c +++ b/lib/route/cls.c @@ -357,6 +357,78 @@ void rtnl_cls_cache_set_tc_params(struct nl_cache *cache, cache->c_iarg2 = parent; } +/** + * Search classifier by interface index, parent and handle + * @arg cache Classifier cache + * @arg ifindex Interface index + * @arg parent Parent + * @arg handle Handle + * + * Searches a classifier cache previously allocated with rtnl_cls_alloc_cache() + * and searches for a classifier matching the interface index, parent + * and handle. + * + * The reference counter is incremented before returning the classifier, + * therefore the reference must be given back with rtnl_cls_put() after usage. + * + * @return Classifier or NULL if no match was found. + */ +struct rtnl_cls *rtnl_cls_find_by_handle(struct nl_cache *cache, int ifindex, uint32_t parent, + uint32_t handle) +{ + struct rtnl_cls *cls; + + if (cache->c_ops != &rtnl_cls_ops) + return NULL; + + nl_list_for_each_entry(cls, &cache->c_items, ce_list) { + if ((cls->c_parent == parent) && + (cls->c_ifindex == ifindex)&& + (cls->c_handle == handle)) { + nl_object_get((struct nl_object *) cls); + return cls; + } + } + + return NULL; +} + +/** + * Search classifier by interface index, parent and priority + * @arg cache Classifier cache + * @arg ifindex Interface index + * @arg parent Parent + * @arg prio Priority + * + * Searches a classifier cache previously allocated with rtnl_cls_alloc_cache() + * and searches for a classifier matching the interface index, parent + * and prio. + * + * The reference counter is incremented before returning the classifier, + * therefore the reference must be given back with rtnl_cls_put() after usage. + * + * @return Classifier or NULL if no match was found. + */ +struct rtnl_cls *rtnl_cls_find_by_prio(struct nl_cache *cache, int ifindex, + uint32_t parent, uint16_t prio) +{ + struct rtnl_cls *cls; + + if (cache->c_ops != &rtnl_cls_ops) + return NULL; + + nl_list_for_each_entry(cls, &cache->c_items, ce_list) { + if ((cls->c_parent == parent) && + (cls->c_ifindex == ifindex) && + (cls->c_prio == prio)) { + nl_object_get((struct nl_object *) cls); + return cls; + } + } + + return NULL; +} + /** @} */ static void cls_dump_line(struct rtnl_tc *tc, struct nl_dump_params *p) diff --git a/libnl-route-3.sym b/libnl-route-3.sym index 5d5d2ae..7821658 100644 --- a/libnl-route-3.sym +++ b/libnl-route-3.sym @@ -1153,6 +1153,8 @@ global: libnl_3_6 { global: + rtnl_cls_find_by_handle; + rtnl_cls_find_by_prio; rtnl_link_ip6_tnl_get_fwmark; rtnl_link_ip6_tnl_set_fwmark; rtnl_link_ip6gre_add; @@ -1183,14 +1185,14 @@ global: rtnl_link_ip6gre_set_ttl; rtnl_link_ip6vti_add; rtnl_link_ip6vti_alloc; - rtnl_link_ip6vti_get_ikey; rtnl_link_ip6vti_get_fwmark; + rtnl_link_ip6vti_get_ikey; rtnl_link_ip6vti_get_link; rtnl_link_ip6vti_get_local; rtnl_link_ip6vti_get_okey; rtnl_link_ip6vti_get_remote; - rtnl_link_ip6vti_set_ikey; rtnl_link_ip6vti_set_fwmark; + rtnl_link_ip6vti_set_ikey; rtnl_link_ip6vti_set_link; rtnl_link_ip6vti_set_local; rtnl_link_ip6vti_set_okey; |