From: Roy Marples Date: Sun, 15 Apr 2018 13:36:36 +0000 (+0000) Subject: Linux: Improve interface renaming X-Git-Tag: v7.0.4~16 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f8fe2d50e3e1c722fe20273718bc8feb809719dd;p=thirdparty%2Fdhcpcd.git Linux: Improve interface renaming --- diff --git a/src/if-linux.c b/src/if-linux.c index 152cffed..21e333bf 100644 --- a/src/if-linux.c +++ b/src/if-linux.c @@ -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;