changeset 5166:a70f6ddefe3c draft

Rename ifp->family -> ifp->hwtype so it's less confusing
author Roy Marples <roy@marples.name>
date Thu, 23 Apr 2020 14:33:48 +0100
parents edce7d4339b8
children bb0276072b5d
files 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
diffstat 8 files changed, 45 insertions(+), 76 deletions(-) [+]
line wrap: on
line diff
--- a/src/arp.c	Wed Apr 22 16:57:40 2020 +0100
+++ b/src/arp.c	Thu Apr 23 14:33:48 2020 +0100
@@ -76,7 +76,7 @@
 	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 @@
 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. */
--- a/src/bpf.c	Wed Apr 22 16:57:40 2020 +0100
+++ b/src/bpf.c	Thu Apr 23 14:33:48 2020 +0100
@@ -85,7 +85,7 @@
 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 @@
 {
 	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 @@
 {
 	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 @@
 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 @@
 	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 @@
 	/* 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 @@
 
 	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 @@
 
 	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));
--- a/src/dhcp.c	Wed Apr 22 16:57:40 2020 +0100
+++ b/src/dhcp.c	Thu Apr 23 14:33:48 2020 +0100
@@ -782,7 +782,7 @@
 		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 @@
 			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 @@
 
 	/* 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 @@
 
 	/* 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;
--- a/src/dhcpcd.h	Wed Apr 22 16:57:40 2020 +0100
+++ b/src/dhcpcd.h	Thu Apr 23 14:33:48 2020 +0100
@@ -82,7 +82,7 @@
 	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;
--- a/src/duid.c	Wed Apr 22 16:57:40 2020 +0100
+++ b/src/duid.c	Thu Apr 23 14:33:48 2020 +0100
@@ -130,7 +130,7 @@
 	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) {
--- a/src/if-linux.c	Wed Apr 22 16:57:40 2020 +0100
+++ b/src/if-linux.c	Thu Apr 23 14:33:48 2020 +0100
@@ -438,7 +438,7 @@
 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)) {
--- a/src/if.c	Wed Apr 22 16:57:40 2020 +0100
+++ b/src/if.c	Thu Apr 23 14:33:48 2020 +0100
@@ -485,13 +485,9 @@
 		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 @@
 #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 @@
 			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 @@
 					    " 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 @@
 #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
-			}
 		}
 
 		if (!(ctx->options & (DHCPCD_DUMPLEASE | DHCPCD_TEST))) {
--- a/src/ipv6.c	Wed Apr 22 16:57:40 2020 +0100
+++ b/src/ipv6.c	Thu Apr 23 14:33:48 2020 +0100
@@ -1406,7 +1406,7 @@
 
 	/* 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 @@
 		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];