[PATCH 5/6] u32: add action removal API

Cong Wang xiyou.wangcong at gmail.com
Thu Dec 5 18:48:29 EST 2013


Signed-off-by: Cong Wang <xiyou.wangcong at gmail.com>
---
 include/netlink/route/action.h  |  1 +
 include/netlink/route/cls/u32.h |  1 +
 lib/route/act.c                 | 16 ++++++++++++++++
 lib/route/cls/u32.c             | 19 +++++++++++++++++++
 4 files changed, 37 insertions(+)

diff --git a/include/netlink/route/action.h b/include/netlink/route/action.h
index be52767..c80f6cf 100644
--- a/include/netlink/route/action.h
+++ b/include/netlink/route/action.h
@@ -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 *);
diff --git a/include/netlink/route/cls/u32.h b/include/netlink/route/cls/u32.h
index 5d8d1ab..34328d9 100644
--- a/include/netlink/route/cls/u32.h
+++ b/include/netlink/route/cls/u32.h
@@ -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
 }
diff --git a/lib/route/act.c b/lib/route/act.c
index 32613e0..9c00453 100644
--- a/lib/route/act.c
+++ b/lib/route/act.c
@@ -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);
diff --git a/lib/route/cls/u32.c b/lib/route/cls/u32.c
index 687690d..e79ec9b 100644
--- a/lib/route/cls/u32.c
+++ b/lib/route/cls/u32.c
@@ -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;
+}
 /** @} */
 
 /**
-- 
1.8.3.1




More information about the libnl mailing list