summaryrefslogtreecommitdiffstats
path: root/lib/route
diff options
context:
space:
mode:
authorCong Wang <xiyou.wangcong@gmail.com>2014-04-02 01:03:31 (GMT)
committerThomas Haller <thaller@redhat.com>2014-04-09 07:10:19 (GMT)
commit6c8f67b87a6a9a9f8f2579cfebbed9b3844cd4fc (patch)
tree2cf2435e68945b34fad8f5c0c5e98fa1e90116a9 /lib/route
parent12bd035b053f2df4369da47f893fefcdeec6389d (diff)
downloadlibnl-6c8f67b87a6a9a9f8f2579cfebbed9b3844cd4fc.zip
libnl-6c8f67b87a6a9a9f8f2579cfebbed9b3844cd4fc.tar.gz
libnl-6c8f67b87a6a9a9f8f2579cfebbed9b3844cd4fc.tar.bz2
veth: implement ->io_free
So that veth link can be just put by rtnl_link_put() Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com> Acked-by: Thomas Graf <tgraf@suug.ch> Signed-off-by: Thomas Haller <thaller@redhat.com>
Diffstat (limited to 'lib/route')
-rw-r--r--lib/route/link/veth.c18
1 files changed, 14 insertions, 4 deletions
diff --git a/lib/route/link/veth.c b/lib/route/link/veth.c
index 5282ccb..2ce3cff 100644
--- a/lib/route/link/veth.c
+++ b/lib/route/link/veth.c
@@ -165,6 +165,18 @@ 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);
+ if (peer) {
+ link->l_info = NULL;
+ /* avoid calling this recursively */
+ peer->l_info = NULL;
+ rtnl_link_put(peer);
+ }
+ /* the caller should finally free link */
+}
+
static struct rtnl_link_info_ops veth_info_ops = {
.io_name = "veth",
.io_parse = veth_parse,
@@ -175,6 +187,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 */
@@ -228,8 +241,7 @@ 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);
+ veth_free(link);
rtnl_link_put(link);
}
@@ -276,9 +288,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;
}