From: Roy Marples Date: Mon, 9 Sep 2013 20:22:12 +0000 (+0000) Subject: Fix interface renaming and carrier reporting when using udev X-Git-Tag: v6.1.0~13 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=1f88304a4e055f5a311ad3131353bc78ff5d3d76;p=thirdparty%2Fdhcpcd.git Fix interface renaming and carrier reporting when using udev --- diff --git a/dhcpcd.c b/dhcpcd.c index 8bddb4ca..8665b907 100644 --- a/dhcpcd.c +++ b/dhcpcd.c @@ -392,19 +392,28 @@ configure_interface(struct interface *ifp, int argc, char **argv) configure_interface1(ifp); } +int +handle_rename(unsigned int index, const char *ifname) +{ + struct interface *ifp; + + TAILQ_FOREACH(ifp, ifaces, next) { + if (ifp->index == index && strcmp(ifp->name, ifname)) { + syslog(LOG_INFO, "%s: rename to %s", ifp->name, ifname); + strlcpy(ifp->name, ifname, sizeof(ifp->name)); + return 1; + } + } + return 0; +} + void handle_carrier(int carrier, int flags, const char *ifname) { struct interface *ifp; - if (!(options & DHCPCD_LINK)) - return; ifp = find_interface(ifname); - if (ifp == NULL) { - handle_interface(1, ifname); - return; - } - if (!(ifp->options->options & DHCPCD_LINK)) + if (ifp == NULL || !(ifp->options->options & DHCPCD_LINK)) return; if (carrier == LINK_UNKNOWN) diff --git a/dhcpcd.h b/dhcpcd.h index 4f0f56f5..15ca3e18 100644 --- a/dhcpcd.h +++ b/dhcpcd.h @@ -85,6 +85,7 @@ struct interface *find_interface(const char *); int handle_args(struct fd_list *, int, char **); void handle_carrier(int, int, const char *); void handle_interface(int, const char *); +int handle_rename(unsigned int, const char *); void handle_hwaddr(const char *, const unsigned char *, size_t); void drop_interface(struct interface *, const char *); int select_profile(struct interface *, const char *); diff --git a/if-linux.c b/if-linux.c index 6758a25a..d474ede3 100644 --- a/if-linux.c +++ b/if-linux.c @@ -422,13 +422,7 @@ link_netlink(struct nlmsghdr *nlm) struct rtattr *rta, *hwaddr; struct ifinfomsg *ifi; char ifn[IF_NAMESIZE + 1]; - -#ifdef LIBUDEV - if (nlm->nlmsg_type == RTM_NEWLINK || nlm->nlmsg_type == RTM_DELLINK) { - if (libudev_listening()) - return 1; - } -#endif + struct interface *ifp; len = link_route(nlm); if (len != 0) @@ -451,6 +445,7 @@ link_netlink(struct nlmsghdr *nlm) len = NLMSG_PAYLOAD(nlm, sizeof(*ifi)); *ifn = '\0'; hwaddr = NULL; + while (RTA_OK(rta, len)) { switch (rta->rta_type) { case IFLA_WIRELESS: @@ -483,6 +478,22 @@ link_netlink(struct nlmsghdr *nlm) return 1; } + /* Check for interface name change */ + if (handle_rename(ifi->ifi_index, ifn)) + return 1; + + /* Check for a new interface */ + ifp = find_interface(ifn); + if (ifp == NULL) { +#ifdef LIBUDEV + /* Let udev announce the interface for renaming */ + if (libudev_listening()) + return 1; +#endif + handle_interface(1, ifn); + return 1; + } + /* Re-read hardware address and friends */ if (!(ifi->ifi_flags & IFF_UP) && hwaddr) { len = l2addr_len(ifi->ifi_type);