chiark / gitweb /
networkd: netdev - give up early when setting already set ifindex
authorTom Gundersen <teg@jklm.no>
Sat, 19 Apr 2014 15:14:36 +0000 (17:14 +0200)
committerTom Gundersen <teg@jklm.no>
Sat, 19 Apr 2014 16:41:58 +0000 (18:41 +0200)
We may receive RTM_NEWLINK messages with missing LINKINFO after the initial NEWLINK message,
don't bother verifying these, just drop out early after checking that the ifindex is not in conflict.

src/network/networkd-netdev.c

index 30cb74b..717ecdf 100644 (file)
@@ -392,6 +392,29 @@ int netdev_set_ifindex(NetDev *netdev, sd_rtnl_message *message) {
                 return -EINVAL;
         }
 
                 return -EINVAL;
         }
 
+        r = sd_rtnl_message_link_get_ifindex(message, &ifindex);
+        if (r < 0) {
+                log_error_netdev(netdev, "Could not get ifindex: %s", strerror(-r));
+                netdev_enter_failed(netdev);
+                return r;
+        } else if (ifindex <= 0) {
+                log_error_netdev(netdev, "Got invalid ifindex: %d", ifindex);
+                netdev_enter_failed(netdev);
+                return r;
+        }
+
+
+        if (netdev->ifindex > 0) {
+                if (netdev->ifindex != ifindex) {
+                        log_error_netdev(netdev, "Could not set ifindex to %d, already set to %d",
+                                         ifindex, netdev->ifindex);
+                        netdev_enter_failed(netdev);
+                        return -EEXIST;
+                } else
+                        /* ifindex already set to the same for this netdev */
+                        return 0;
+        }
+
         r = sd_rtnl_message_read_string(message, IFLA_IFNAME, &received_name);
         if (r < 0) {
                 log_error_netdev(netdev, "Could not get IFNAME");
         r = sd_rtnl_message_read_string(message, IFLA_IFNAME, &received_name);
         if (r < 0) {
                 log_error_netdev(netdev, "Could not get IFNAME");
@@ -437,24 +460,6 @@ int netdev_set_ifindex(NetDev *netdev, sd_rtnl_message *message) {
                 return r;
         }
 
                 return r;
         }
 
-        r = sd_rtnl_message_link_get_ifindex(message, &ifindex);
-        if (r < 0) {
-                log_error_netdev(netdev, "Could not get ifindex: %s", strerror(-r));
-                netdev_enter_failed(netdev);
-                return r;
-        } else if (ifindex <= 0) {
-                log_error_netdev(netdev, "Got invalid ifindex: %d", ifindex);
-                netdev_enter_failed(netdev);
-                return r;
-        }
-
-        if (netdev->ifindex > 0 && netdev->ifindex != ifindex) {
-                log_error_netdev(netdev, "Could not set ifindex to %d, already set to %d",
-                                 ifindex, netdev->ifindex);
-                netdev_enter_failed(netdev);
-                return -EEXIST;
-        }
-
         netdev->ifindex = ifindex;
 
         netdev_enter_ready(netdev);
         netdev->ifindex = ifindex;
 
         netdev_enter_ready(netdev);