]> git.ipfire.org Git - thirdparty/libnl.git/commitdiff
Add support for getting and deleting queueing classes.
authorolc <olc@satem.(none)>
Mon, 20 Jul 2009 13:56:30 +0000 (15:56 +0200)
committerThomas Graf <tgr@lsx.localdomain>
Wed, 2 Sep 2009 19:10:48 +0000 (21:10 +0200)
include/netlink/route/class.h
lib/route/class.c

index 012128b9cd7af20105cb2d0ec5684949b5bdbaf6..480095e1f7bf26de75cdfe19e77e3666d6b20f41 100644 (file)
@@ -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);
index 2bfd7dd837f3dcb6468fe823935b15784ef37044..ddf2d2e8506862959a1187419b6263d60c2522cb 100644 (file)
@@ -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 = {