summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authord0u9 <d0u9.su@outlook.com>2018-04-01 16:48:11 +0800
committerThomas Haller <thaller@redhat.com>2018-04-11 13:05:09 +0200
commit17f0459c8d1891473c315315c0f5c25f38b24d6b (patch)
tree158909ef29cf92bfb3302b527f6457e470eab44b /lib
parent2a3a66977936471b93526adda7faa1ac231f78d7 (diff)
downloadlibnl-17f0459c8d1891473c315315c0f5c25f38b24d6b.tar.gz
route/class: add new api rtnl_class_get_by_parent()
This function searches a class cache previously allocated with rtnl_class_alloc_cache() and searches for a class matching the interface index and parent qdisc. https://github.com/thom311/libnl/pull/185
Diffstat (limited to 'lib')
-rw-r--r--lib/route/class.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/lib/route/class.c b/lib/route/class.c
index 56ad1d86..0b9a235c 100644
--- a/lib/route/class.c
+++ b/lib/route/class.c
@@ -367,6 +367,38 @@ struct rtnl_class *rtnl_class_get(struct nl_cache *cache, int ifindex,
return NULL;
}
+/**
+ * Search class by interface index and parent
+ * @arg cache Traffic class cache
+ * @arg ifindex Interface index
+ * @arg parent Handle of parent qdisc
+ *
+ * Searches a class cache previously allocated with rtnl_class_alloc_cache()
+ * and searches for a class matching the interface index and parent qdisc.
+ *
+ * The reference counter is incremented before returning the class, therefore
+ * the reference must be given back with rtnl_class_put() after usage.
+ *
+ * @return pointer to class inside the cache or NULL if no match was found.
+ */
+struct rtnl_class *rtnl_class_get_by_parent(struct nl_cache *cache, int ifindex,
+ uint32_t parent)
+{
+ struct rtnl_class *class;
+
+ if (cache->c_ops != &rtnl_class_ops)
+ return NULL;
+
+ nl_list_for_each_entry(class, &cache->c_items, ce_list) {
+ if (class->c_parent == parent && class->c_ifindex == ifindex) {
+ nl_object_get((struct nl_object *) class);
+ return class;
+ }
+ }
+
+ return NULL;
+}
+
/** @} */
/**