]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Linux: Improve interface renaming
authorRoy Marples <roy@marples.name>
Sun, 15 Apr 2018 13:36:36 +0000 (13:36 +0000)
committerRoy Marples <roy@marples.name>
Sun, 15 Apr 2018 13:36:36 +0000 (13:36 +0000)
src/if-linux.c

index 152cffedfa362874fefe2b7edac4228544852385..21e333bf13657edc30b2df3c4709fe3fd53a61db 100644 (file)
@@ -652,23 +652,6 @@ l2addr_len(unsigned short if_type)
        return 0;
 }
 
-static int
-handle_rename(struct dhcpcd_ctx *ctx, unsigned int ifindex, const char *ifname)
-{
-       struct interface *ifp;
-
-       TAILQ_FOREACH(ifp, ctx->ifaces, next) {
-               if (ifp->index == ifindex && strcmp(ifp->name, ifname)) {
-                       dhcpcd_handleinterface(ctx, -1, ifp->name);
-                       /* Let dev announce the interface for renaming */
-                       if (!dev_listening(ctx))
-                               dhcpcd_handleinterface(ctx, 1, ifname);
-                       return 1;
-               }
-       }
-       return 0;
-}
-
 #ifdef INET6
 static int
 link_neigh(struct dhcpcd_ctx *ctx, __unused struct interface *ifp,
@@ -783,12 +766,9 @@ link_netlink(struct dhcpcd_ctx *ctx, struct interface *ifp,
                return 0;
        }
 
-       /* Check for interface name change */
-       if (handle_rename(ctx, (unsigned int)ifi->ifi_index, ifn))
-               return 0;
-
        /* Check for a new interface */
-       if ((ifp = if_find(ctx->ifaces, ifn)) == NULL) {
+       ifp = if_findindex(ctx->ifaces, (unsigned int)ifi->ifi_index);
+       if (ifp == NULL) {
                /* If are listening to a dev manager, let that announce
                 * the interface rather than the kernel. */
                if (dev_listening(ctx) < 1)
@@ -796,6 +776,13 @@ link_netlink(struct dhcpcd_ctx *ctx, struct interface *ifp,
                return 0;
        }
 
+       /* Handle interface being renamed */
+       if (strcmp(ifp->name, ifn) != 0) {
+               dhcpcd_handleinterface(ctx, -1, ifn);
+               dhcpcd_handleinterface(ctx, 1, ifn);
+               return 0;
+       }
+
        /* Re-read hardware address and friends */
        if (!(ifi->ifi_flags & IFF_UP) && hwaddr) {
                uint8_t l;