From: Roy Marples Date: Thu, 22 Jan 2015 20:10:18 +0000 (+0000) Subject: For Linux, keep the alias on the interface so we don't have to guess X-Git-Tag: v6.7.0~2 X-Git-Url: http://git.ipfire.org/gitweb/?a=commitdiff_plain;h=16f1b54cd467ad25c67f44f137a1d6dd504be14a;p=thirdparty%2Fdhcpcd.git For Linux, keep the alias on the interface so we don't have to guess all the time. --- diff --git a/dhcpcd.h b/dhcpcd.h index 73a5d434..d17e21c9 100644 --- a/dhcpcd.h +++ b/dhcpcd.h @@ -60,6 +60,9 @@ struct interface { struct dhcpcd_ctx *ctx; TAILQ_ENTRY(interface) next; char name[IF_NAMESIZE]; +#ifdef __linux + char alias[IF_NAMESIZE]; +#endif unsigned int index; unsigned int flags; sa_family_t family; diff --git a/if-linux.c b/if-linux.c index a2d87b62..13335204 100644 --- a/if-linux.c +++ b/if-linux.c @@ -1239,7 +1239,7 @@ if_address(const struct interface *iface, nlm.ifa.ifa_prefixlen = inet_ntocidr(*netmask); /* This creates the aliased interface */ add_attr_l(&nlm.hdr, sizeof(nlm), IFA_LABEL, - iface->name, (unsigned short)(strlen(iface->name) + 1)); + iface->alias, (unsigned short)(strlen(iface->alias) + 1)); add_attr_l(&nlm.hdr, sizeof(nlm), IFA_LOCAL, &address->s_addr, sizeof(address->s_addr)); if (action >= 0 && broadcast) @@ -1358,7 +1358,7 @@ if_address6(const struct ipv6_addr *ap, int action) nlm.ifa.ifa_prefixlen = ap->prefix_len; /* This creates the aliased interface */ add_attr_l(&nlm.hdr, sizeof(nlm), IFA_LABEL, - ap->iface->name, (unsigned short)(strlen(ap->iface->name) + 1)); + ap->iface->alias, (unsigned short)(strlen(ap->iface->alias) + 1)); add_attr_l(&nlm.hdr, sizeof(nlm), IFA_LOCAL, &ap->addr.s6_addr, sizeof(ap->addr.s6_addr)); diff --git a/if.c b/if.c index 78bc27f4..26d0386c 100644 --- a/if.c +++ b/if.c @@ -98,20 +98,11 @@ if_carrier(struct interface *iface) #ifdef SIOCGIFMEDIA struct ifmediareq ifmr; #endif -#ifdef __linux__ - char *p; -#endif if ((s = socket(PF_INET, SOCK_DGRAM, 0)) == -1) return LINK_UNKNOWN; memset(&ifr, 0, sizeof(ifr)); strlcpy(ifr.ifr_name, iface->name, sizeof(ifr.ifr_name)); -#ifdef __linux__ - /* We can only test the real interface up */ - if ((p = strchr(ifr.ifr_name, ':'))) - *p = '\0'; -#endif - if (ioctl(s, SIOCGIFFLAGS, &ifr) == -1) { close(s); return LINK_UNKNOWN; @@ -138,19 +129,11 @@ if_setflag(struct interface *ifp, short flag) { struct ifreq ifr; int s, r; -#ifdef __linux__ - char *p; -#endif if ((s = socket(PF_INET, SOCK_DGRAM, 0)) == -1) return -1; memset(&ifr, 0, sizeof(ifr)); strlcpy(ifr.ifr_name, ifp->name, sizeof(ifr.ifr_name)); -#ifdef __linux__ - /* We can only bring the real interface up */ - if ((p = strchr(ifr.ifr_name, ':'))) - *p = '\0'; -#endif r = -1; if (ioctl(s, SIOCGIFFLAGS, &ifr) == 0) { if (flag == 0 || (ifr.ifr_flags & flag) == flag) @@ -273,6 +256,9 @@ if_discover(struct dhcpcd_ctx *ctx, int argc, char * const *argv) p = argv[i]; } else { p = ifa->ifa_name; +#ifdef __linux__ + strlcpy(ifn, ifa->ifa_name, sizeof(ifn)); +#endif /* -1 means we're discovering against a specific * interface, but we still need the below rules * to apply. */ @@ -313,7 +299,12 @@ if_discover(struct dhcpcd_ctx *ctx, int argc, char * const *argv) break; } ifp->ctx = ctx; +#ifdef __linux__ + strlcpy(ifp->name, ifn, sizeof(ifp->name)); + strlcpy(ifp->alias, p, sizeof(ifp->alias)); +#else strlcpy(ifp->name, p, sizeof(ifp->name)); +#endif ifp->flags = ifa->ifa_flags; ifp->carrier = if_carrier(ifp); @@ -546,6 +537,9 @@ if_findindexname(struct dhcpcd_ctx *ctx, unsigned int idx, const char *name) if ((ifp->options == NULL || !(ifp->options->options & DHCPCD_PFXDLGONLY)) && ((name && strcmp(ifp->name, name) == 0) || +#ifdef __linux__ + (name && strcmp(ifp->alias, name) == 0) || +#endif (!name && ifp->index == idx))) return ifp; }