[OpenWrt-Devel] [PATCH 2/5] netifd: Fix macvlan delete via netlink

Hans Dedecker dedeckeh at gmail.com
Wed Jun 18 02:55:45 EDT 2014


Fix macvlan delete via netlink as netlink attribute IFLA_IFNAME data size was incorrect.
In addition some minor improvements.

Signed-off-by: Hans Dedecker <dedeckeh at gmail.com>
---
 system-linux.c |   17 ++++++++---------
 1 files changed, 8 insertions(+), 9 deletions(-)

diff --git a/system-linux.c b/system-linux.c
index ea71f65..9b5cffa 100644
--- a/system-linux.c
+++ b/system-linux.c
@@ -691,7 +691,7 @@ int system_macvlan_add(struct device *macvlan, struct device *dev, struct macvla
 {
 	struct nl_msg *msg;
 	struct nlattr *linkinfo, *data;
-	struct ifinfomsg iim = { .ifi_family = AF_INET };
+	struct ifinfomsg iim = { .ifi_family = AF_UNSPEC, };
 	int ifindex = system_if_resolve(dev);
 	int i, rv;
 	static const struct {
@@ -716,13 +716,13 @@ int system_macvlan_add(struct device *macvlan, struct device *dev, struct macvla
 
 	if (cfg->flags & MACVLAN_OPT_MACADDR)
 		nla_put(msg, IFLA_ADDRESS, sizeof(cfg->macaddr), cfg->macaddr);
-	nla_put(msg, IFLA_IFNAME, IFNAMSIZ, macvlan->ifname);
+	nla_put_string(msg, IFLA_IFNAME, macvlan->ifname);
 	nla_put_u32(msg, IFLA_LINK, ifindex);
 
 	if (!(linkinfo = nla_nest_start(msg, IFLA_LINKINFO)))
 		goto nla_put_failure;
 
-	nla_put(msg, IFLA_INFO_KIND, strlen("macvlan"), "macvlan");
+	nla_put_string(msg, IFLA_INFO_KIND, "macvlan");
 
 	if (!(data = nla_nest_start(msg, IFLA_INFO_DATA)))
 		goto nla_put_failure;
@@ -754,10 +754,10 @@ nla_put_failure:
 int system_macvlan_del(struct device *macvlan)
 {
 	struct nl_msg *msg;
-	struct ifinfomsg iim;
-
-	iim.ifi_family = AF_INET;
-	iim.ifi_index  = 0;
+	struct ifinfomsg iim = {
+		.ifi_family = AF_UNSPEC,
+		.ifi_index = 0,
+	};
 
 	msg = nlmsg_alloc_simple(RTM_DELLINK, 0);
 
@@ -766,8 +766,7 @@ int system_macvlan_del(struct device *macvlan)
 
 	nlmsg_append(msg, &iim, sizeof(iim), 0);
 
-	nla_put(msg, IFLA_INFO_KIND, strlen("macvlan"), "macvlan");
-	nla_put(msg, IFLA_IFNAME, sizeof(macvlan->ifname), macvlan->ifname);
+	nla_put_string(msg, IFLA_IFNAME, macvlan->ifname);
 
 	system_rtnl_call(msg);
 
-- 
1.7.1
_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel



More information about the openwrt-devel mailing list