diff options
author | olc <olc@satem.(none)> | 2009-07-20 13:56:30 (GMT) |
---|---|---|
committer | Thomas Graf <tgr@lsx.localdomain> | 2009-09-02 19:10:48 (GMT) |
commit | 2ead49f0d5873628156e50dfed7da14619a4172d (patch) | |
tree | f0fad488c20a805c6c27db6be53b7b3849b3cb7c | |
parent | e0af9e1802d4f0c49e838ff94a187f590eb9e2cd (diff) | |
download | libnl-2ead49f0d5873628156e50dfed7da14619a4172d.zip libnl-2ead49f0d5873628156e50dfed7da14619a4172d.tar.gz libnl-2ead49f0d5873628156e50dfed7da14619a4172d.tar.bz2 |
Add support for getting and deleting queueing classes.
-rw-r--r-- | include/netlink/route/class.h | 5 | ||||
-rw-r--r-- | lib/route/class.c | 78 |
2 files changed, 83 insertions, 0 deletions
diff --git a/include/netlink/route/class.h b/include/netlink/route/class.h index 012128b..480095e 100644 --- a/include/netlink/route/class.h +++ b/include/netlink/route/class.h @@ -28,6 +28,7 @@ extern struct rtnl_class * rtnl_class_alloc(void); extern void rtnl_class_put(struct rtnl_class *); extern int rtnl_class_alloc_cache(struct nl_sock *, int, struct nl_cache **); +extern struct rtnl_class *rtnl_class_get(struct nl_cache *, int, uint32_t); /* leaf qdisc access */ extern struct rtnl_qdisc * rtnl_class_leaf_qdisc(struct rtnl_class *, @@ -38,6 +39,10 @@ extern int rtnl_class_build_add_request(struct rtnl_class *, int, extern int rtnl_class_add(struct nl_sock *, struct rtnl_class *, int); +extern int rtnl_class_build_delete_request(struct rtnl_class *, + struct nl_msg **); +extern int rtnl_class_delete(struct nl_sock *, struct rtnl_class *); + extern void rtnl_class_set_ifindex(struct rtnl_class *, int); extern int rtnl_class_get_ifindex(struct rtnl_class *); extern void rtnl_class_set_handle(struct rtnl_class *, uint32_t); diff --git a/lib/route/class.c b/lib/route/class.c index 2bfd7dd..ddf2d2e 100644 --- a/lib/route/class.c +++ b/lib/route/class.c @@ -157,6 +157,60 @@ int rtnl_class_add(struct nl_sock *sk, struct rtnl_class *class, int flags) return wait_for_ack(sk); } +int rtnl_class_build_delete_request(struct rtnl_class *class, + struct nl_msg **result) +{ + struct nl_msg *msg; + struct tcmsg tchdr; + int required = TCA_ATTR_IFINDEX | TCA_ATTR_PARENT; + + if ((class->ce_mask & required) != required) + BUG(); + + msg = nlmsg_alloc_simple(RTM_DELTCLASS, 0); + if (!msg) + return -NLE_NOMEM; + + tchdr.tcm_family = AF_UNSPEC; + tchdr.tcm_handle = class->c_handle; + tchdr.tcm_parent = class->c_parent; + tchdr.tcm_ifindex = class->c_ifindex; + if (nlmsg_append(msg, &tchdr, sizeof(tchdr), NLMSG_ALIGNTO) < 0) { + nlmsg_free(msg); + return -NLE_MSGSIZE; + } + + *result = msg; + return 0; +} + +/** + * Delete a class + * @arg sk Netlink socket. + * @arg class class to delete + * + * Builds a netlink message by calling rtnl_class_build_delete_request(), + * sends the request to the kernel and waits for the ACK to be + * received and thus blocks until the request has been processed. + * + * @return 0 on success or a negative error code + */ +int rtnl_class_delete(struct nl_sock *sk, struct rtnl_class *class) +{ + struct nl_msg *msg; + int err; + + if ((err = rtnl_class_build_delete_request(class, &msg)) < 0) + return err; + + err = nl_send_auto_complete(sk, msg); + nlmsg_free(msg); + if (err < 0) + return err; + + return wait_for_ack(sk); +} + /** @} */ /** @@ -196,6 +250,30 @@ int rtnl_class_alloc_cache(struct nl_sock *sk, int ifindex, return 0; } +/** + * Look up class by its handle in the provided cache + * @arg cache class cache + * @arg ifindex interface the class is attached to + * @arg handle class handle + * @return pointer to class inside the cache or NULL if no match was found. + */ +struct rtnl_class *rtnl_class_get(struct nl_cache *cache, int ifindex, + uint32_t handle) +{ + 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_handle == handle && class->c_ifindex == ifindex) { + nl_object_get((struct nl_object *) class); + return class; + } + } + return NULL; +} + /** @} */ static struct nl_cache_ops rtnl_class_ops = { |