netifd: Remove superfluous system_if_resolve calls
[project/netifd.git] / system-linux.c
index 02574fcbeea6f5ab77ad0493c0ccb7d3840d9366..01c3deb65b9de5460ce66e8c26d2e52f2116afe8 100644 (file)
@@ -316,11 +316,7 @@ static int cb_rtnl_event(struct nl_msg *msg, void *arg)
                goto out;
 
        struct device *dev = device_get(nla_data(nla[IFLA_IFNAME]), false);
-       if (!dev)
-               goto out;
-
-       device_set_ifindex(dev, ifi->ifi_index);
-       if (dev->type->keep_link_status)
+       if (!dev || dev->type->keep_link_status)
                goto out;
 
        if (!system_get_dev_sysctl("/sys/class/net/%s/carrier", dev->ifname, buf, sizeof(buf)))
@@ -497,7 +493,7 @@ int system_bridge_delif(struct device *bridge, struct device *dev)
        return system_bridge_if(bridge->ifname, dev, SIOCBRDELIF, NULL);
 }
 
-static int system_if_resolve(struct device *dev)
+int system_if_resolve(struct device *dev)
 {
        struct ifreq ifr;
        strncpy(ifr.ifr_name, dev->ifname, sizeof(ifr.ifr_name));
@@ -764,7 +760,6 @@ 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_UNSPEC, };
-       int ifindex = system_if_resolve(dev);
        int i, rv;
        static const struct {
                const char *name;
@@ -776,9 +771,6 @@ int system_macvlan_add(struct device *macvlan, struct device *dev, struct macvla
                { "passthru", MACVLAN_MODE_PASSTHRU },
        };
 
-       if (ifindex == 0)
-               return -ENOENT;
-
        msg = nlmsg_alloc_simple(RTM_NEWLINK, NLM_F_REQUEST | NLM_F_CREATE | NLM_F_EXCL);
 
        if (!msg)
@@ -789,7 +781,7 @@ 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_string(msg, IFLA_IFNAME, macvlan->ifname);
-       nla_put_u32(msg, IFLA_LINK, ifindex);
+       nla_put_u32(msg, IFLA_LINK, dev->ifindex);
 
        if (!(linkinfo = nla_nest_start(msg, IFLA_LINKINFO)))
                goto nla_put_failure;
@@ -881,12 +873,8 @@ int system_vlandev_add(struct device *vlandev, struct device *dev, struct vlande
        struct nl_msg *msg;
        struct nlattr *linkinfo, *data;
        struct ifinfomsg iim = { .ifi_family = AF_UNSPEC };
-       int ifindex = system_if_resolve(dev);
        int rv;
 
-       if (ifindex == 0)
-               return -ENOENT;
-
        msg = nlmsg_alloc_simple(RTM_NEWLINK, NLM_F_REQUEST | NLM_F_CREATE | NLM_F_EXCL);
 
        if (!msg)
@@ -894,7 +882,7 @@ int system_vlandev_add(struct device *vlandev, struct device *dev, struct vlande
 
        nlmsg_append(msg, &iim, sizeof(iim), 0);
        nla_put_string(msg, IFLA_IFNAME, vlandev->ifname);
-       nla_put_u32(msg, IFLA_LINK, ifindex);
+       nla_put_u32(msg, IFLA_LINK, dev->ifindex);
        
        if (!(linkinfo = nla_nest_start(msg, IFLA_LINKINFO)))
                goto nla_put_failure;
@@ -1006,7 +994,6 @@ int system_if_up(struct device *dev)
 {
        system_if_get_settings(dev, &dev->orig_settings);
        system_if_apply_settings(dev, &dev->settings, dev->settings.flags);
-       device_set_ifindex(dev, system_if_resolve(dev));
        return system_if_flags(dev->ifname, IFF_UP, 0);
 }