remove device_{route,addr}->device
[project/netifd.git] / system-linux.c
index 34d7cae..58ac5d4 100644 (file)
@@ -602,15 +602,18 @@ system_if_apply_settings(struct device *dev, struct device_settings *s)
        strncpy(ifr.ifr_name, dev->ifname, sizeof(ifr.ifr_name));
        if (s->flags & DEV_OPT_MTU) {
                ifr.ifr_mtu = s->mtu;
-               ioctl(sock_ioctl, SIOCSIFMTU, &ifr);
+               if (ioctl(sock_ioctl, SIOCSIFMTU, &ifr) < 0)
+                       s->flags &= ~DEV_OPT_MTU;
        }
        if (s->flags & DEV_OPT_TXQUEUELEN) {
                ifr.ifr_qlen = s->txqueuelen;
-               ioctl(sock_ioctl, SIOCSIFTXQLEN, &ifr);
+               if (ioctl(sock_ioctl, SIOCSIFTXQLEN, &ifr) < 0)
+                       s->flags &= ~DEV_OPT_TXQUEUELEN;
        }
        if (s->flags & DEV_OPT_MACADDR) {
                memcpy(&ifr.ifr_hwaddr, s->macaddr, sizeof(s->macaddr));
-               ioctl(sock_ioctl, SIOCSIFHWADDR, &ifr);
+               if (ioctl(sock_ioctl, SIOCSIFHWADDR, &ifr) < 0)
+                       s->flags &= ~DEV_OPT_MACADDR;
        }
 }
 
@@ -813,14 +816,6 @@ static int system_addr(struct device *dev, struct device_addr *addr, int cmd)
 
        struct nl_msg *msg;
 
-       dev = addr->device;
-       if (dev) {
-               if (!dev->ifindex)
-                       return -1;
-
-               ifa.ifa_index = dev->ifindex;
-       }
-
        msg = nlmsg_alloc_simple(cmd, 0);
        if (!msg)
                return -1;
@@ -871,14 +866,6 @@ static int system_rt(struct device *dev, struct device_route *route, int cmd)
        if (cmd == RTM_NEWROUTE)
                flags |= NLM_F_CREATE | NLM_F_REPLACE;
 
-       dev = route->device;
-       if (dev) {
-               if (!dev->ifindex)
-                       return -1;
-
-               ifindex = dev->ifindex;
-       }
-
        msg = nlmsg_alloc_simple(cmd, flags);
        if (!msg)
                return -1;
@@ -888,6 +875,9 @@ static int system_rt(struct device *dev, struct device_route *route, int cmd)
        if (route->mask)
                nla_put(msg, RTA_DST, alen, &route->addr);
 
+       if (route->metric >= 0)
+               nla_put_u32(msg, RTA_PRIORITY, route->metric);
+
        if (have_gw)
                nla_put(msg, RTA_GATEWAY, alen, &route->nexthop);