]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
For Linux, keep the alias on the interface so we don't have to guess
authorRoy Marples <roy@marples.name>
Thu, 22 Jan 2015 20:10:18 +0000 (20:10 +0000)
committerRoy Marples <roy@marples.name>
Thu, 22 Jan 2015 20:10:18 +0000 (20:10 +0000)
all the time.

dhcpcd.h
if-linux.c
if.c

index 73a5d434819e579f7dae4a7081fd75735e86deec..d17e21c93c1b58686ce7aec26f701711eb2f14f3 100644 (file)
--- 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;
index a2d87b62ba38a9381955d89ff1ef8c14bcf91655..133352042ab8824057aa5990715f00fbb36da3a0 100644 (file)
@@ -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 78bc27f4d24dde212ed640eb924d71c728069293..26d0386cf454f78b7784cbf29ceaf397292cd853 100644 (file)
--- 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;
                }