We have many home brewed ways to check Ethernet addresses. This diff introduces two macros similar to ETHER_IS_MULTICAST() and make use of them in bridge(4) and generic Ethernet layer.
Ok? Index: net/if_bridge.c =================================================================== RCS file: /cvs/src/sys/net/if_bridge.c,v retrieving revision 1.335 diff -u -p -r1.335 if_bridge.c --- net/if_bridge.c 9 Jun 2019 17:42:16 -0000 1.335 +++ net/if_bridge.c 15 Jul 2019 21:09:43 -0000 @@ -944,10 +944,8 @@ bridgeintr_frame(struct ifnet *brifp, st * is not broadcast or multicast, record its address. */ if ((bif->bif_flags & IFBIF_LEARNING) && - (eh.ether_shost[0] & 1) == 0 && - !(eh.ether_shost[0] == 0 && eh.ether_shost[1] == 0 && - eh.ether_shost[2] == 0 && eh.ether_shost[3] == 0 && - eh.ether_shost[4] == 0 && eh.ether_shost[5] == 0)) + !ETHER_IS_MULTICAST(eh.ether_shost) && + !ETHER_IS_ANYADDR(eh.ether_shost)) bridge_rtupdate(sc, src, src_if, 0, IFBAF_DYNAMIC, m); if ((bif->bif_flags & IFBIF_STP) && @@ -972,8 +970,7 @@ bridgeintr_frame(struct ifnet *brifp, st return; } } else { - if (memcmp(etherbroadcastaddr, eh.ether_dhost, - sizeof(etherbroadcastaddr)) == 0) + if (ETHER_IS_BCASTADDR(eh.ether_dhost)) m->m_flags |= M_BCAST; else m->m_flags |= M_MCAST; Index: net/if_ethersubr.c =================================================================== RCS file: /cvs/src/sys/net/if_ethersubr.c,v retrieving revision 1.259 diff -u -p -r1.259 if_ethersubr.c --- net/if_ethersubr.c 20 Feb 2019 00:03:15 -0000 1.259 +++ net/if_ethersubr.c 15 Jul 2019 21:13:37 -0000 @@ -377,8 +377,7 @@ ether_input(struct ifnet *ifp, struct mb goto dropanyway; } - if (memcmp(etherbroadcastaddr, eh->ether_dhost, - ETHER_ADDR_LEN) == 0) + if (ETHER_IS_BCASTADDR(eh->ether_dhost)) m->m_flags |= M_BCAST; else m->m_flags |= M_MCAST; Index: netinet/if_ether.c =================================================================== RCS file: /cvs/src/sys/netinet/if_ether.c,v retrieving revision 1.239 diff -u -p -r1.239 if_ether.c --- netinet/if_ether.c 13 Jun 2019 08:15:26 -0000 1.239 +++ netinet/if_ether.c 15 Jul 2019 21:15:28 -0000 @@ -516,8 +516,8 @@ in_arpinput(struct ifnet *ifp, struct mb sin.sin_len = sizeof(sin); sin.sin_family = AF_INET; - if (ETHER_IS_MULTICAST(&ea->arp_sha[0]) && - !memcmp(ea->arp_sha, etherbroadcastaddr, sizeof(ea->arp_sha))) { + if (ETHER_IS_MULTICAST(ea->arp_sha) && + ETHER_IS_BCASTADDR(ea->arp_sha)) { inet_ntop(AF_INET, &isaddr, addr, sizeof(addr)); log(LOG_ERR, "arp: ether address is broadcast for IP address " "%s!\n", addr); Index: netinet/if_ether.h =================================================================== RCS file: /cvs/src/sys/netinet/if_ether.h,v retrieving revision 1.75 diff -u -p -r1.75 if_ether.h --- netinet/if_ether.h 5 Jul 2019 01:23:22 -0000 1.75 +++ netinet/if_ether.h 15 Jul 2019 21:16:32 -0000 @@ -108,6 +108,10 @@ struct ether_vlan_header { #include <net/ethertypes.h> #define ETHER_IS_MULTICAST(addr) (*(addr) & 0x01) /* is address mcast/bcast? */ +#define ETHER_IS_ANYADDR(addr) \ + (memcmp(etheranyaddr, (addr), sizeof(etheranyaddr)) == 0) +#define ETHER_IS_BCASTADDR(addr) \ + (memcmp(etherbroadcastaddr, (addr), sizeof(etherbroadcastaddr)) == 0) #define ETHERMTU (ETHER_MAX_LEN - ETHER_HDR_LEN - ETHER_CRC_LEN) #define ETHERMIN (ETHER_MIN_LEN - ETHER_HDR_LEN - ETHER_CRC_LEN)