]> granicus.if.org Git - libnl/commitdiff
act: grab a reference when adding an action to a filter
authorCong Wang <xiyou.wangcong@gmail.com>
Thu, 24 Apr 2014 00:28:29 +0000 (17:28 -0700)
committerThomas Haller <thaller@redhat.com>
Wed, 30 Apr 2014 09:19:42 +0000 (11:19 +0200)
When we add an action to a filter, its lifetime becomes
same with the filter. So in case user frees it before
us, we could just grab a reference here.

Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
Acked-by: Thomas Graf <tgraf@suug.ch>
Signed-off-by: Thomas Haller <thaller@redhat.com>
include/netlink/route/action.h
include/netlink/utils.h
lib/route/act.c
lib/route/cls/basic.c
lib/route/cls/u32.c
lib/utils.c

index e904432ff653787e3c13c95f112a2f5a27c4f337..054bdd87b3d814ef20ee94ffee61da3824390b90 100644 (file)
@@ -22,6 +22,7 @@ extern "C" {
 #endif
 
 extern struct rtnl_act *rtnl_act_alloc(void);
+extern void            rtnl_act_get(struct rtnl_act *);
 extern void            rtnl_act_put(struct rtnl_act *);
 extern int             rtnl_act_build_add_request(struct rtnl_act *, int,
                                                   struct nl_msg **);
index 4c2aa198a7848e6c34d6913f5491f32461e26577..8faf9177807ebb0b72b881ff85e305b23d360d2d 100644 (file)
@@ -97,6 +97,13 @@ enum {
        NL_CAPABILITY_ROUTE_LINK_VETH_GET_PEER_OWN_REFERENCE = 2,
 #define NL_CAPABILITY_ROUTE_LINK_VETH_GET_PEER_OWN_REFERENCE NL_CAPABILITY_ROUTE_LINK_VETH_GET_PEER_OWN_REFERENCE
 
+       /**
+        * rtnl_u32_add_action() and rtnl_basic_add_action() now grab a reference to act
+        * caller are free to release its own
+        */
+       NL_CAPABILITY_ROUTE_LINK_CLS_ADD_ACT_OWN_REFERENCE = 3,
+#define NL_CAPABILITY_ROUTE_LINK_CLS_ADD_ACT_OWN_REFERENCE NL_CAPABILITY_ROUTE_LINK_CLS_ADD_ACT_OWN_REFERENCE
+
        __NL_CAPABILITY_MAX
 #define NL_CAPABILITY_MAX                               (__NL_CAPABILITY_MAX - 1)
 };
index 3141866365ce30407598184140a1721ca731229c..1e9673f0e637ccd35f286ab54a0389ed521dbafc 100644 (file)
@@ -178,6 +178,11 @@ struct rtnl_act *rtnl_act_alloc(void)
        return (struct rtnl_act *) tc;
 }
 
+void rtnl_act_get(struct rtnl_act *act)
+{
+       nl_object_get(OBJ_CAST(act));
+}
+
 void rtnl_act_put(struct rtnl_act *act)
 {
        nl_object_put((struct nl_object *) act);
index 5a67fae908e6d156f9c8b8d88e448aa2954cc1f7..6af3844b70bc67923e5c09c26229fb22a865eb53 100644 (file)
@@ -228,6 +228,8 @@ int rtnl_basic_add_action(struct rtnl_cls *cls, struct rtnl_act *act)
                return -NLE_NOMEM;
 
        b->b_mask |= BASIC_ATTR_ACTION;
+       /* In case user frees it */
+       rtnl_act_get(act);
        return rtnl_act_append(&b->b_act, act);
 }
 
@@ -245,9 +247,13 @@ int rtnl_basic_del_action(struct rtnl_cls *cls, struct rtnl_act *act)
        if (!(b->b_mask & BASIC_ATTR_ACTION))
                return -NLE_INVAL;
        ret = rtnl_act_remove(&b->b_act, act);
+       if (ret)
+               return ret;
+
        if (!b->b_act)
                b->b_mask &= ~BASIC_ATTR_ACTION;
-       return ret;
+       rtnl_act_put(act);
+       return 0;
 }
 /** @} */
 
index 52ab26384a583e87f5a55236cf4f8a8437e48f4a..e91c39a366efa50c4cc4b5cce3664014f69cdba4 100644 (file)
@@ -470,6 +470,8 @@ int rtnl_u32_add_action(struct rtnl_cls *cls, struct rtnl_act *act)
                return -NLE_NOMEM;
 
        u->cu_mask |= U32_ATTR_ACTION;
+       /* In case user frees it */
+       rtnl_act_get(act);
        return rtnl_act_append(&u->cu_act, act);
 }
 
@@ -488,9 +490,13 @@ int rtnl_u32_del_action(struct rtnl_cls *cls, struct rtnl_act *act)
                return -NLE_INVAL;
 
        ret = rtnl_act_remove(&u->cu_act, act);
+       if (ret)
+               return ret;
+
        if (!u->cu_act)
                u->cu_mask &= ~U32_ATTR_ACTION;
-       return ret;
+       rtnl_act_put(act);
+       return 0;
 }
 /** @} */
 
index ac36493971da4eb99e297e30da5d205fa4809f3f..e2294e6324351f62e682b4fa7d11ae87c316620f 100644 (file)
@@ -1146,7 +1146,7 @@ int nl_has_capability (int capability)
                _NL_SET(0,
                        NL_CAPABILITY_ROUTE_BUILD_MSG_SET_SCOPE,
                        NL_CAPABILITY_ROUTE_LINK_VETH_GET_PEER_OWN_REFERENCE,
-                       0,
+                       NL_CAPABILITY_ROUTE_LINK_CLS_ADD_ACT_OWN_REFERENCE,
                        0,
                        0,
                        0,