[PATCH 2/4] veth: implement ->io_free

Cong Wang xiyou.wangcong at gmail.com
Sun Mar 23 15:02:08 EDT 2014


So that veth link can be just put by rtnl_link_put()

Signed-off-by: Cong Wang <xiyou.wangcong at gmail.com>
---
 lib/route/link/veth.c | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)

diff --git a/lib/route/link/veth.c b/lib/route/link/veth.c
index 0cac428..65e9a87 100644
--- a/lib/route/link/veth.c
+++ b/lib/route/link/veth.c
@@ -143,6 +143,16 @@ static int veth_put_attrs(struct nl_msg *msg, struct rtnl_link *link)
 	return 0;
 }
 
+static void veth_free(struct rtnl_link *link)
+{
+	struct rtnl_link *peer = rtnl_link_veth_get_peer(link);
+	link->l_info = NULL;
+	if (peer) {
+		peer->l_info = NULL;
+		rtnl_link_put(peer);
+	}
+}
+
 static struct rtnl_link_info_ops veth_info_ops = {
 	.io_name		= "veth",
 	.io_parse		= veth_parse,
@@ -152,6 +162,7 @@ static struct rtnl_link_info_ops veth_info_ops = {
 	},
 	.io_clone		= veth_clone,
 	.io_put_attrs		= veth_put_attrs,
+	.io_free		= veth_free,
 };
 
 /** @cond SKIP */
@@ -219,8 +230,12 @@ struct rtnl_link *rtnl_link_veth_get_peer(struct rtnl_link *link)
 void rtnl_link_veth_release(struct rtnl_link *link)
 {
 	struct rtnl_link *peer = rtnl_link_veth_get_peer(link);
-	rtnl_link_put(peer);
+	link->l_info = NULL;
 	rtnl_link_put(link);
+	if (peer) {
+		peer->l_info = NULL;
+		rtnl_link_put(peer);
+	}
 }
 
 /**
@@ -266,9 +281,7 @@ int rtnl_link_veth_add(struct nl_sock *sock, const char *name,
 	rtnl_link_set_ns_pid(peer, pid);
 	err = rtnl_link_add(sock, link, NLM_F_CREATE);
 
-	rtnl_link_put(peer);
 	rtnl_link_put(link);
-
         return err;
 }
 
-- 
1.8.1.4




More information about the libnl mailing list