]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Rename ifp->family -> ifp->hwtype so it's less confusing
authorRoy Marples <roy@marples.name>
Thu, 23 Apr 2020 13:33:48 +0000 (14:33 +0100)
committerRoy Marples <roy@marples.name>
Thu, 23 Apr 2020 13:33:48 +0000 (14:33 +0100)
src/arp.c
src/bpf.c
src/dhcp.c
src/dhcpcd.h
src/duid.c
src/if-linux.c
src/if.c
src/ipv6.c

index 270a22f01695c3f0558b8537591306f545e9e231..f13fa139549b97e02455f9e900ce24ad194e868d 100644 (file)
--- a/src/arp.c
+++ b/src/arp.c
@@ -76,7 +76,7 @@ arp_request(const struct interface *ifp,
        uint8_t *p;
        const struct iarp_state *state;
 
-       ar.ar_hrd = htons(ifp->family);
+       ar.ar_hrd = htons(ifp->hwtype);
        ar.ar_pro = htons(ETHERTYPE_IP);
        ar.ar_hln = ifp->hwlen;
        ar.ar_pln = sizeof(tip->s_addr);
@@ -197,8 +197,8 @@ static bool
 arp_validate(const struct interface *ifp, struct arphdr *arp)
 {
 
-       /* Families must match */
-       if (arp->ar_hrd != htons(ifp->family))
+       /* Address type must match */
+       if (arp->ar_hrd != htons(ifp->hwtype))
                return false;
 
        /* Protocol must be IP. */
index e648513c481cce84c0a1d05c7fc2d13fabc935d9..c9f3b084f240bdcc8e1bb92d9a5470eb8540114b 100644 (file)
--- a/src/bpf.c
+++ b/src/bpf.c
@@ -85,7 +85,7 @@ size_t
 bpf_frame_header_len(const struct interface *ifp)
 {
 
-       switch (ifp->family) {
+       switch (ifp->hwtype) {
        case ARPHRD_ETHER:
                return sizeof(struct ether_header);
        default:
@@ -98,7 +98,7 @@ bpf_frame_header_src(const struct interface *ifp, void *fh, size_t *len)
 {
        uint8_t *f = fh;
 
-       switch (ifp->family) {
+       switch (ifp->hwtype) {
        case ARPHRD_ETHER:
                *len = sizeof(((struct ether_header *)0)->ether_shost);
                return f + offsetof(struct ether_header, ether_shost);
@@ -114,7 +114,7 @@ bpf_frame_header_dst(const struct interface *ifp, void *fh, size_t *len)
 {
        uint8_t *f = fh;
 
-       switch (ifp->family) {
+       switch (ifp->hwtype) {
        case ARPHRD_ETHER:
                *len = sizeof(((struct ether_header *)0)->ether_dhost);
                return f + offsetof(struct ether_header, ether_dhost);
@@ -132,7 +132,7 @@ int
 bpf_frame_bcast(const struct interface *ifp, const char *frame)
 {
 
-       switch (ifp->family) {
+       switch (ifp->hwtype) {
        case ARPHRD_ETHER:
                return memcmp(frame +
                    offsetof(struct ether_header, ether_dhost),
@@ -322,7 +322,7 @@ bpf_send(const struct interface *ifp, int fd, uint16_t protocol,
        struct iovec iov[2];
        struct ether_header eh;
 
-       switch(ifp->family) {
+       switch(ifp->hwtype) {
        case ARPHRD_ETHER:
                memset(&eh.ether_dhost, 0xff, sizeof(eh.ether_dhost));
                memcpy(&eh.ether_shost, ifp->hwaddr, sizeof(eh.ether_shost));
@@ -451,7 +451,7 @@ static const struct bpf_insn bpf_arp_ether [] = {
        /* Load frame header length into X */
        BPF_STMT(BPF_LDX + BPF_W + BPF_IMM, sizeof(struct ether_header)),
 
-       /* Make sure the hardware family matches. */
+       /* Make sure the hardware type matches. */
        BPF_STMT(BPF_LD + BPF_H + BPF_IND, offsetof(struct arphdr, ar_hrd)),
        BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, ARPHRD_ETHER, 1, 0),
        BPF_STMT(BPF_RET + BPF_K, 0),
@@ -503,7 +503,7 @@ bpf_arp(struct interface *ifp, int fd)
 
        bp = bpf;
        /* Check frame header. */
-       switch(ifp->family) {
+       switch(ifp->hwtype) {
        case ARPHRD_ETHER:
                memcpy(bp, bpf_arp_ether, sizeof(bpf_arp_ether));
                bp += BPF_ARP_ETHER_LEN;
@@ -653,7 +653,7 @@ bpf_bootp(struct interface *ifp, int fd)
 
        bp = bpf;
        /* Check frame header. */
-       switch(ifp->family) {
+       switch(ifp->hwtype) {
 #ifdef ARPHRD_NONE
        case ARPHRD_NONE:
                memcpy(bp, bpf_bootp_none, sizeof(bpf_bootp_none));
index bcb4ee9b194027331a9d10622b97bd8a0d4a88be..9af2dbd027d5163c81357fff6c9db11a8f4ab8b7 100644 (file)
@@ -782,7 +782,7 @@ make_message(struct bootp **bootpm, const struct interface *ifp, uint8_t type)
                bootp->ciaddr = state->addr->addr.s_addr;
 
        bootp->op = BOOTREQUEST;
-       bootp->htype = (uint8_t)ifp->family;
+       bootp->htype = (uint8_t)ifp->hwtype;
        if (ifp->hwlen != 0 && ifp->hwlen < sizeof(bootp->chaddr)) {
                bootp->hlen = (uint8_t)ifp->hwlen;
                memcpy(&bootp->chaddr, &ifp->hwaddr, ifp->hwlen);
@@ -3823,7 +3823,7 @@ dhcp_init(struct interface *ifp)
                        if (state->clientid == NULL)
                                goto eexit;
                        state->clientid[0] = len;
-                       state->clientid[1] = (uint8_t)ifp->family;
+                       state->clientid[1] = (uint8_t)ifp->hwtype;
                        memcpy(state->clientid + 2, ifp->hwaddr,
                            ifp->hwlen);
                }
@@ -4043,7 +4043,7 @@ dhcp_start(struct interface *ifp)
 
        /* If we haven't specified a ClientID and our hardware address
         * length is greater than BOOTP CHADDR then we enforce a ClientID
-        * of the hardware address family and the hardware address.
+        * of the hardware address type and the hardware address.
         * If there is no hardware address and no ClientID set,
         * force a DUID based ClientID. */
        if (ifp->hwlen > 16)
@@ -4053,7 +4053,7 @@ dhcp_start(struct interface *ifp)
 
        /* Firewire and InfiniBand interfaces require ClientID and
         * the broadcast option being set. */
-       switch (ifp->family) {
+       switch (ifp->hwtype) {
        case ARPHRD_IEEE1394:   /* FALLTHROUGH */
        case ARPHRD_INFINIBAND:
                ifp->options->options |= DHCPCD_CLIENTID | DHCPCD_BROADCAST;
index ac61d926e4ab8ba5c9d45908d179b14936ab8114..57d177e30eb2c8ee3c47106ee4ce6a1dd09f1085 100644 (file)
@@ -82,7 +82,7 @@ struct interface {
        unsigned int index;
        unsigned int active;
        unsigned int flags;
-       sa_family_t family;
+       uint16_t hwtype; /* ARPHRD_ETHER for example */
        unsigned char hwaddr[HWADDR_LEN];
        uint8_t hwlen;
        unsigned short vlanid;
index 0d6c6f8f5f67b22017d331fc44075865d97fe939..d411d667253cfe95887014403bbdfba70943a9c1 100644 (file)
@@ -130,7 +130,7 @@ duid_make(void *d, const struct interface *ifp, uint16_t type)
        u16 = htons(type);
        memcpy(p, &u16, sizeof(u16));
        p += sizeof(u16);
-       u16 = htons(ifp->family);
+       u16 = htons(ifp->hwtype);
        memcpy(p, &u16, sizeof(u16));
        p += sizeof(u16);
        if (type == DUID_LLT) {
index 5f069c1fb7b99f8cd0132bbc45acbd4b57d9ce10..e3338465c03aed9ef6d3cc3022deaabb3802a6ae 100644 (file)
@@ -438,7 +438,7 @@ int
 if_setmac(struct interface *ifp, void *mac, uint8_t maclen)
 {
        struct ifreq ifr = {
-               .ifr_hwaddr.sa_family = ifp->family,
+               .ifr_hwaddr.sa_family = ifp->hwtype,
        };
 
        if (ifp->hwlen != maclen || maclen > sizeof(ifr.ifr_hwaddr.sa_data)) {
index f73dfc7ed94d0946bbf64b04a71ac8b04cbc4e1c..7471df616ed6ad93804fbf3fc6701306ea64f06a 100644 (file)
--- a/src/if.c
+++ b/src/if.c
@@ -485,13 +485,9 @@ if_discover(struct dhcpcd_ctx *ctx, struct ifaddrs **ifaddrs,
                if_noconf = ((argc == 0 || argc == -1) && ctx->ifac == 0 &&
                    !if_hasconf(ctx, spec.devname));
 
-               /* Don't allow loopback or pointopoint unless explicit.
-                * Don't allow some reserved interface names unless explicit. */
-               if (if_noconf) {
-                       if (ifa->ifa_flags & (IFF_LOOPBACK | IFF_POINTOPOINT) ||
-                           if_ignore(ctx, spec.devname))
-                               active = IF_INACTIVE;
-               }
+               /* Don't allow some reserved interface names unless explicit. */
+               if (if_noconf && if_ignore(ctx, spec.devname))
+                       active = IF_INACTIVE;
 
                ifp = calloc(1, sizeof(*ifp));
                if (ifp == NULL) {
@@ -533,6 +529,7 @@ if_discover(struct dhcpcd_ctx *ctx, struct ifaddrs **ifaddrs,
 #ifdef IFT_TUNNEL
                        case IFT_TUNNEL: /* FALLTHROUGH */
 #endif
+                       case IFT_LOOP: /* FALLTHROUGH */
                        case IFT_PPP:
                                /* Don't allow unless explicit */
                                if (if_noconf) {
@@ -551,16 +548,16 @@ if_discover(struct dhcpcd_ctx *ctx, struct ifaddrs **ifaddrs,
                        case IFT_L3IPVLAN: /* FALLTHROUGH */
 #endif
                        case IFT_ETHER:
-                               ifp->family = ARPHRD_ETHER;
+                               ifp->hwtype = ARPHRD_ETHER;
                                break;
 #ifdef IFT_IEEE1394
                        case IFT_IEEE1394:
-                               ifp->family = ARPHRD_IEEE1394;
+                               ifp->hwtype = ARPHRD_IEEE1394;
                                break;
 #endif
 #ifdef IFT_INFINIBAND
                        case IFT_INFINIBAND:
-                               ifp->family = ARPHRD_INFINIBAND;
+                               ifp->hwtype = ARPHRD_INFINIBAND;
                                break;
 #endif
                        default:
@@ -572,7 +569,7 @@ if_discover(struct dhcpcd_ctx *ctx, struct ifaddrs **ifaddrs,
                                            " interface type 0x%.2x",
                                            ifp->name, sdl->sdl_type);
                                /* Pretend it's ethernet */
-                               ifp->family = ARPHRD_ETHER;
+                               ifp->hwtype = ARPHRD_ETHER;
                                break;
                        }
                        ifp->hwlen = sdl->sdl_alen;
@@ -580,63 +577,35 @@ if_discover(struct dhcpcd_ctx *ctx, struct ifaddrs **ifaddrs,
 #elif AF_PACKET
                        sll = (const void *)ifa->ifa_addr;
                        ifp->index = (unsigned int)sll->sll_ifindex;
-                       ifp->family = sll->sll_hatype;
+                       ifp->hwtype = sll->sll_hatype;
                        ifp->hwlen = sll->sll_halen;
                        if (ifp->hwlen != 0)
                                memcpy(ifp->hwaddr, sll->sll_addr, ifp->hwlen);
-#endif
-               }
-#ifdef SIOCGIFHWADDR
-               else {
-                       /* This is a huge bug in getifaddrs(3) as there
-                        * is no reason why this can't be returned in
-                        * ifa_addr. */
-                       memset(&ifr, 0, sizeof(ifr));
-                       strlcpy(ifr.ifr_name, ifa->ifa_name,
-                           sizeof(ifr.ifr_name));
-                       if (ioctl(ctx->pf_inet_fd, SIOCGIFHWADDR, &ifr) == -1)
-                               logerr("%s: SIOCGIFHWADDR", ifa->ifa_name);
-                       ifp->family = ifr.ifr_hwaddr.sa_family;
-                       if (ioctl(ctx->pf_inet_fd, SIOCGIFINDEX, &ifr) == -1)
-                               logerr("%s: SIOCGIFINDEX", ifa->ifa_name);
-                       ifp->index = (unsigned int)ifr.ifr_ifindex;
-               }
-#endif
 
-               /* Ensure hardware address is valid. */
-               if (!if_valid_hwaddr(ifp->hwaddr, ifp->hwlen))
-                       ifp->hwlen = 0;
-
-               /* We only work on ethernet by default */
-               if (ifp->family != ARPHRD_ETHER) {
-                       if ((argc == 0 || argc == -1) &&
-                           ctx->ifac == 0 && !if_hasconf(ctx, ifp->name))
-                               active = IF_INACTIVE;
-                       switch (ifp->family) {
-                       case ARPHRD_IEEE1394:
-                       case ARPHRD_INFINIBAND:
-#ifdef ARPHRD_LOOPBACK
+                       switch(ifp->hwtype) {
+                       case ARPHRD_ETHER:      /* FALLTHROUGH */
+                       case ARPHRD_IEEE1394:   /* FALLTHROUGH */
+                       case ARPHRD_INFINIBAND: /* FALLTHROUGH */
+                       case ARPHRD_NONE:       /* FALLTHROUGH */
+                               break;
                        case ARPHRD_LOOPBACK:
-#endif
-#ifdef ARPHRD_PPP
                        case ARPHRD_PPP:
-#endif
-#ifdef ARPHRD_NONE
-                       case ARPHRD_NONE:
-#endif
-                               /* We don't warn for supported families */
+                               if (if_noconf) {
+                                       logdebugx("%s: ignoring due to"
+                                           " interface type and"
+                                           " no config",
+                                           ifp->name);
+                                       active = IF_INACTIVE;
+                               }
                                break;
-
-/* IFT already checked */
-#ifndef AF_LINK
                        default:
                                if (active)
                                        logwarnx("%s: unsupported"
-                                           " interface family 0x%.2x",
-                                           ifp->name, ifp->family);
+                                           " interface type 0x%.2x",
+                                           ifp->name, ifp->hwtype);
                                break;
-#endif
                        }
+#endif
                }
 
                if (!(ctx->options & (DHCPCD_DUMPLEASE | DHCPCD_TEST))) {
index 954f47f0cc34443ba8da2828cf882be3ebbc7465..f6734e93437024c656f44ecc63b6a04e7a5dfa01 100644 (file)
@@ -1406,7 +1406,7 @@ ipv6_addlinklocal(struct interface *ifp)
 
        /* Check sanity before malloc */
        if (!(ifp->options->options & DHCPCD_SLAACPRIVATE)) {
-               switch (ifp->family) {
+               switch (ifp->hwtype) {
                case ARPHRD_ETHER:
                        /* Check for a valid hardware address */
                        if (ifp->hwlen != 6 && ifp->hwlen != 8) {
@@ -1446,7 +1446,7 @@ nextslaacprivate:
                ap->dadcounter = dadcounter;
        } else {
                memcpy(ap->addr.s6_addr, ap->prefix.s6_addr, 8);
-               switch (ifp->family) {
+               switch (ifp->hwtype) {
                case ARPHRD_ETHER:
                        if (ifp->hwlen == 6) {
                                ap->addr.s6_addr[ 8] = ifp->hwaddr[0];