]> git.ipfire.org Git - thirdparty/libnl.git/commitdiff
u32: add action removal API
authorCong Wang <xiyou.wangcong@gmail.com>
Thu, 5 Dec 2013 23:48:29 +0000 (15:48 -0800)
committerThomas Graf <tgraf@suug.ch>
Mon, 9 Dec 2013 14:36:14 +0000 (15:36 +0100)
Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
Signed-off-by: Thomas Graf <tgraf@suug.ch>
include/netlink/route/action.h
include/netlink/route/cls/u32.h
lib/route/act.c
lib/route/cls/u32.c

index be527675c0e2d4edf52ab90f60ea483db009ffd4..c80f6cf9115152f27e6b9a5bf973198bd0f874cb 100644 (file)
@@ -38,6 +38,7 @@ extern int            rtnl_act_build_delete_request(struct rtnl_act *, int,
 extern int             rtnl_act_delete(struct nl_sock *, struct rtnl_act *,
                                        int);
 extern int             rtnl_act_append(struct rtnl_act **, struct rtnl_act *);
+extern int             rtnl_act_remove(struct rtnl_act **, struct rtnl_act *);
 extern int             rtnl_act_fill(struct nl_msg *, int, struct rtnl_act *);
 extern void            rtnl_act_put_all(struct rtnl_act **);
 extern int             rtnl_act_parse(struct rtnl_act **, struct nlattr *);
index 5d8d1abec26623e7bd7d47fde83e5a5f267d0d6c..34328d9b4ad777f3a3167ed8c0093a75bbbcd073 100644 (file)
@@ -43,6 +43,7 @@ extern int    rtnl_u32_add_key_in_addr(struct rtnl_cls *, struct in_addr *,
 extern int     rtnl_u32_add_key_in6_addr(struct rtnl_cls *, struct in6_addr *,
                                          uint8_t, int, int);
 extern int     rtnl_u32_add_action(struct rtnl_cls *, struct rtnl_act *);
+extern int     rtnl_u32_del_action(struct rtnl_cls *, struct rtnl_act *);
 
 #ifdef __cplusplus
 }
index 32613e04ed3c627e9cae31162f8271c58c8b3cf9..9c00453e6f7b472e31c94730aecfd86698877e3e 100644 (file)
@@ -49,6 +49,22 @@ int rtnl_act_append(struct rtnl_act **head, struct rtnl_act *new)
        return 0;
 }
 
+int rtnl_act_remove(struct rtnl_act **head, struct rtnl_act *act)
+{
+       struct rtnl_act *a, **ap;
+
+        for (ap = head; (a = *ap) != NULL; ap = &a->a_next)
+                if (a == act)
+                        break;
+        if (a) {
+                *ap = a->a_next;
+                a->a_next = NULL;
+                return 0;
+        }
+
+       return -NLE_OBJ_NOTFOUND;
+}
+
 static int rtnl_act_fill_one(struct nl_msg *msg, struct rtnl_act *act, int order)
 {
        struct rtnl_tc *tc = TC_CAST(act);
index 687690ddda2e735068b43f71df867080dca2325c..e79ec9bef3a22afcc77c8fcbfc811705249ba3a6 100644 (file)
@@ -481,6 +481,25 @@ int rtnl_u32_add_action(struct rtnl_cls *cls, struct rtnl_act *act)
        return rtnl_act_append(&u->cu_act, act);
 }
 
+int rtnl_u32_del_action(struct rtnl_cls *cls, struct rtnl_act *act)
+{
+       struct rtnl_u32 *u;
+       int ret;
+
+       if (!act)
+               return 0;
+
+       if (!(u = rtnl_tc_data(TC_CAST(cls))))
+               return -NLE_NOMEM;
+
+       if (!(u->cu_mask & U32_ATTR_ACTION))
+               return -NLE_INVAL;
+
+       ret = rtnl_act_remove(&u->cu_act, act);
+       if (!u->cu_act)
+               u->cu_mask &= ~U32_ATTR_ACTION;
+       return ret;
+}
 /** @} */
 
 /**