]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Fix interface renaming and carrier reporting when using udev
authorRoy Marples <roy@marples.name>
Mon, 9 Sep 2013 20:22:12 +0000 (20:22 +0000)
committerRoy Marples <roy@marples.name>
Mon, 9 Sep 2013 20:22:12 +0000 (20:22 +0000)
dhcpcd.c
dhcpcd.h
if-linux.c

index 8bddb4ca962feabb833a835b59a6012f59c6c31c..8665b9074c8a2c954796930e7066f9f1c579e408 100644 (file)
--- 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)
index 4f0f56f5e802a66f0bd20c7aeffa4087abeeb235..15ca3e187eb69cb122f7285a14c6a8462146f475 100644 (file)
--- 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 *);
index 6758a25a2b02f4da36537e3389a6674f5ebd3f42..d474ede332aa13c68474db636c48743550c414f4 100644 (file)
@@ -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);