[Patch v2 3/4] veth: implement ->io_free

Cong Wang xiyou.wangcong at gmail.com
Fri Mar 28 21:08:17 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 cf2e513..c6a4cc7 100644
--- a/lib/route/link/veth.c
+++ b/lib/route/link/veth.c
@@ -163,6 +163,16 @@ static int veth_alloc(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,
@@ -173,6 +183,7 @@ static struct rtnl_link_info_ops veth_info_ops = {
 	.io_alloc		= veth_alloc,
 	.io_clone		= veth_clone,
 	.io_put_attrs		= veth_put_attrs,
+	.io_free		= veth_free,
 };
 
 /** @cond SKIP */
@@ -227,8 +238,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);
+	}
 }
 
 /**
@@ -274,9 +289,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.7.11.7




More information about the libnl mailing list