From 0bf8e505a463196aac78a9e3b054c25b122983ab Mon Sep 17 00:00:00 2001 From: Roy Marples Date: Thu, 23 Apr 2020 14:33:48 +0100 Subject: [PATCH] Rename ifp->family -> ifp->hwtype so it's less confusing --- src/arp.c | 6 ++-- src/bpf.c | 16 +++++----- src/dhcp.c | 8 ++--- src/dhcpcd.h | 2 +- src/duid.c | 2 +- src/if-linux.c | 2 +- src/if.c | 81 ++++++++++++++++---------------------------------- src/ipv6.c | 4 +-- 8 files changed, 45 insertions(+), 76 deletions(-) diff --git a/src/arp.c b/src/arp.c index 270a22f0..f13fa139 100644 --- 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. */ diff --git a/src/bpf.c b/src/bpf.c index e648513c..c9f3b084 100644 --- 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)); diff --git a/src/dhcp.c b/src/dhcp.c index bcb4ee9b..9af2dbd0 100644 --- a/src/dhcp.c +++ b/src/dhcp.c @@ -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; diff --git a/src/dhcpcd.h b/src/dhcpcd.h index ac61d926..57d177e3 100644 --- a/src/dhcpcd.h +++ b/src/dhcpcd.h @@ -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; diff --git a/src/duid.c b/src/duid.c index 0d6c6f8f..d411d667 100644 --- a/src/duid.c +++ b/src/duid.c @@ -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) { diff --git a/src/if-linux.c b/src/if-linux.c index 5f069c1f..e3338465 100644 --- a/src/if-linux.c +++ b/src/if-linux.c @@ -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)) { diff --git a/src/if.c b/src/if.c index f73dfc7e..7471df61 100644 --- 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))) { diff --git a/src/ipv6.c b/src/ipv6.c index 954f47f0..f6734e93 100644 --- a/src/ipv6.c +++ b/src/ipv6.c @@ -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]; -- 2.47.2