diff options
author | Volodymyr Bendiuga <volodymyr.bendiuga@westermo.se> | 2016-03-02 08:59:07 (GMT) |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2022-03-10 09:58:24 (GMT) |
commit | b3333e0f7802f985ed2998b42f2544b70976cd00 (patch) | |
tree | b6454f57c41d3afcdcc8be4b750641538922bedd | |
parent | 9a391880b54e42f0069bfd998a506d8132e7fcdd (diff) | |
download | libnl-b3333e0f7802f985ed2998b42f2544b70976cd00.zip libnl-b3333e0f7802f985ed2998b42f2544b70976cd00.tar.gz libnl-b3333e0f7802f985ed2998b42f2544b70976cd00.tar.bz2 |
route/qdisc: allow fetching qdiscs by their kind
API:
rtnl_qdisc_get_by_kind()
This function allows getting qdisc based on
its kind, i.e. tbf, htb, cbq, etc.
Signed-off-by: Volodymyr Bendiuga <volodymyr.bendiuga@westermo.se>
https://github.com/thom311/libnl/pull/244
-rw-r--r-- | include/netlink/route/qdisc.h | 2 | ||||
-rw-r--r-- | lib/route/qdisc.c | 32 | ||||
-rw-r--r-- | libnl-route-3.sym | 1 |
3 files changed, 35 insertions, 0 deletions
diff --git a/include/netlink/route/qdisc.h b/include/netlink/route/qdisc.h index 02000fa..7d963a5 100644 --- a/include/netlink/route/qdisc.h +++ b/include/netlink/route/qdisc.h @@ -27,6 +27,8 @@ extern struct rtnl_qdisc * extern struct rtnl_qdisc * rtnl_qdisc_get_by_parent(struct nl_cache *, int, uint32_t); +extern struct rtnl_qdisc *rtnl_qdisc_get_by_kind(struct nl_cache *cache, + int ifindex, char *kind); extern int rtnl_qdisc_build_add_request(struct rtnl_qdisc *, int, struct nl_msg **); diff --git a/lib/route/qdisc.c b/lib/route/qdisc.c index 2488d66..62c4390 100644 --- a/lib/route/qdisc.c +++ b/lib/route/qdisc.c @@ -397,6 +397,38 @@ struct rtnl_qdisc *rtnl_qdisc_get_by_parent(struct nl_cache *cache, } /** + * Search qdisc by kind + * @arg cache Qdisc cache + * @arg ifindex Interface index + * @arg kind Qdisc kind (tbf, htb, cbq, etc) + * + * Searches a qdisc cache previously allocated with rtnl_qdisc_alloc_cache() + * and searches for a qdisc matching the interface index and kind. + * + * The reference counter is incremented before returning the qdisc, therefore + * the reference must be given back with rtnl_qdisc_put() after usage. + * + * @return pointer to qdisc inside the cache or NULL if no match was found. + */ +struct rtnl_qdisc *rtnl_qdisc_get_by_kind(struct nl_cache *cache, + int ifindex, char *kind) +{ + struct rtnl_qdisc *q; + + if (cache->c_ops != &rtnl_qdisc_ops) + return NULL; + + nl_list_for_each_entry(q, &cache->c_items, ce_list) { + if ((q->q_ifindex == ifindex) && (!strcmp(q->q_kind, kind))) { + nl_object_get((struct nl_object *) q); + return q; + } + } + + return NULL; +} + +/** * Search qdisc by interface index and handle * @arg cache Qdisc cache * @arg ifindex Interface index diff --git a/libnl-route-3.sym b/libnl-route-3.sym index e7c343b..fa39f58 100644 --- a/libnl-route-3.sym +++ b/libnl-route-3.sym @@ -1180,6 +1180,7 @@ global: rtnl_link_is_ip6gre; rtnl_link_macsec_get_offload; rtnl_link_macsec_set_offload; + rtnl_qdisc_get_by_kind; rtnl_route_nh_get_encap_mpls_dst; rtnl_route_nh_get_encap_mpls_ttl; } libnl_3_5; |