From: Roy Marples Date: Tue, 10 Sep 2013 09:56:11 +0000 (+0000) Subject: Instead of just renaming the interface on Linux, take the FreeBSD X-Git-Tag: v6.1.0~10 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=7c3225083f99af0f4c2787d015707883150897ea;p=thirdparty%2Fdhcpcd.git Instead of just renaming the interface on Linux, take the FreeBSD approach and remove the old and create a new one. This simple change allows the the allow/deny rules to be followed. --- diff --git a/dev/udev.c b/dev/udev.c index 56f790f6..1eaa510c 100644 --- a/dev/udev.c +++ b/dev/udev.c @@ -69,15 +69,17 @@ libudev_handledata(__unused void *arg) subsystem = udev_device_get_subsystem(device); ifname = udev_device_get_sysname(device); action = udev_device_get_action(device); - udev_device_unref(device); /* udev filter documentation says "usually" so double check */ if (strcmp(subsystem, "net") == 0) { - if (strcmp(action, "add") == 0) + syslog(LOG_DEBUG, "%s: libudev: %s", ifname, action); + if (strcmp(action, "add") == 0 || strcmp(action, "move") == 0) handle_interface(1, ifname); else if (strcmp(action, "remove") == 0) handle_interface(-1, ifname); } + + udev_device_unref(device); } int diff --git a/dhcpcd.c b/dhcpcd.c index 085510ee..f94b2d4f 100644 --- a/dhcpcd.c +++ b/dhcpcd.c @@ -392,22 +392,6 @@ configure_interface(struct interface *ifp, int argc, char **argv) configure_interface1(ifp); } -int -handle_rename(unsigned int ifindex, const char *ifname) -{ - struct interface *ifp; - - TAILQ_FOREACH(ifp, ifaces, next) { - if (ifp->index == ifindex && strcmp(ifp->name, ifname)) { - syslog(LOG_INFO, "%s: renamed 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) { diff --git a/dhcpcd.h b/dhcpcd.h index 15ca3e18..4f0f56f5 100644 --- a/dhcpcd.h +++ b/dhcpcd.h @@ -85,7 +85,6 @@ 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 d474ede3..ddbfc0ed 100644 --- a/if-linux.c +++ b/if-linux.c @@ -415,6 +415,26 @@ static short l2addr_len(unsigned short if_type) } } +static int +handle_rename(unsigned int ifindex, const char *ifname) +{ + struct interface *ifp; + + TAILQ_FOREACH(ifp, ifaces, next) { + if (ifp->index == ifindex && strcmp(ifp->name, ifname)) { + handle_interface(-1, ifp->name); +#ifdef LIBUDEV + /* Let udev announce the interface for renaming */ + if (libudev_listening()) + return 1; +#endif + handle_interface(1, ifname); + return 1; + } + } + return 0; +} + static int link_netlink(struct nlmsghdr *nlm) {