[PATCH 1/4] veth: alloc link struct for peer when parsing netlink message

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


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

diff --git a/lib/route/link/veth.c b/lib/route/link/veth.c
index 4ce1f10..0cac428 100644
--- a/lib/route/link/veth.c
+++ b/lib/route/link/veth.c
@@ -42,7 +42,6 @@ static int veth_parse(struct rtnl_link *link, struct nlattr *data,
 {
 	struct nlattr *tb[VETH_INFO_MAX+1];
 	struct nlattr *peer_tb[IFLA_MAX + 1];
-	struct rtnl_link *peer = link->l_info;
 	int err;
 
 	NL_DBG(3, "Parsing veth link info");
@@ -51,9 +50,12 @@ static int veth_parse(struct rtnl_link *link, struct nlattr *data,
 		goto errout;
 
 	if (tb[VETH_INFO_PEER]) {
+		struct rtnl_link *peer = rtnl_link_alloc();
 		struct nlattr *nla_peer;
 		struct ifinfomsg *ifi;
 
+		if (!peer)
+			return -NLE_NOMEM;
 		nla_peer = tb[VETH_INFO_PEER];
 		ifi = nla_data(nla_peer);
 
@@ -72,6 +74,7 @@ static int veth_parse(struct rtnl_link *link, struct nlattr *data,
 		err = rtnl_link_info_parse(peer, peer_tb);
 		if (err < 0)
 			goto errout;
+		link->l_info = peer;
 	}
 
 	err = 0;
-- 
1.8.1.4




More information about the libnl mailing list