git: 96f830456fd4 - main - sys/net: add a new ether_vlanid_t type

From: Kristof Provost <kp_at_FreeBSD.org>
Date: Tue, 15 Apr 2025 21:43:33 UTC
The branch main has been updated by kp:

URL: https://cgit.FreeBSD.org/src/commit/?id=96f830456fd449c4cb5a7df8a2f6c3c96993b43e

commit 96f830456fd449c4cb5a7df8a2f6c3c96993b43e
Author:     Lexi Winter <lexi@hemlock.eden.le-fay.org>
AuthorDate: 2025-04-15 16:13:23 +0000
Commit:     Kristof Provost <kp@FreeBSD.org>
CommitDate: 2025-04-15 21:42:59 +0000

    sys/net: add a new ether_vlanid_t type
    
    ether_vlanid_t is a type to represent a VLAN ID, for example inside a
    .1q tag.  since this is specific to Ethernet, put it in net/ethernet.h.
    
    change bridge to use the new type instead of uint{16,32}_t.
    
    Reviewed by:    adrian, kp
    Differential Revision:  https://reviews.freebsd.org/D49836
---
 sys/net/ethernet.h     |  5 +++++
 sys/net/if_bridge.c    | 28 ++++++++++++++++------------
 sys/net/if_bridgevar.h |  2 +-
 3 files changed, 22 insertions(+), 13 deletions(-)

diff --git a/sys/net/ethernet.h b/sys/net/ethernet.h
index cf92145eea8f..6eefedba8775 100644
--- a/sys/net/ethernet.h
+++ b/sys/net/ethernet.h
@@ -80,6 +80,11 @@ struct ether_addr {
 	(((addr)[0] | (addr)[1] | (addr)[2] | \
 	  (addr)[3] | (addr)[4] | (addr)[5]) == 0x00)
 
+/*
+ * This is the type of the VLAN ID inside the tag, not the tag itself.
+ */
+typedef uint16_t ether_vlanid_t;
+
 /*
  * 802.1q Virtual LAN header.
  */
diff --git a/sys/net/if_bridge.c b/sys/net/if_bridge.c
index 0dd261e6529b..c587f0d0f70a 100644
--- a/sys/net/if_bridge.c
+++ b/sys/net/if_bridge.c
@@ -266,7 +266,7 @@ struct bridge_rtnode {
 	unsigned long		brt_expire;	/* expiration time */
 	uint8_t			brt_flags;	/* address flags */
 	uint8_t			brt_addr[ETHER_ADDR_LEN];
-	uint16_t		brt_vlan;	/* vlan id */
+	ether_vlanid_t		brt_vlan;	/* vlan id */
 	struct	vnet		*brt_vnet;
 	struct	epoch_context	brt_epoch_ctx;
 };
@@ -344,21 +344,21 @@ static void	bridge_broadcast(struct bridge_softc *, struct ifnet *,
 static void	bridge_span(struct bridge_softc *, struct mbuf *);
 
 static int	bridge_rtupdate(struct bridge_softc *, const uint8_t *,
-		    uint16_t, struct bridge_iflist *, int, uint8_t);
+		    ether_vlanid_t, struct bridge_iflist *, int, uint8_t);
 static struct ifnet *bridge_rtlookup(struct bridge_softc *, const uint8_t *,
-		    uint16_t);
+		    ether_vlanid_t);
 static void	bridge_rttrim(struct bridge_softc *);
 static void	bridge_rtage(struct bridge_softc *);
 static void	bridge_rtflush(struct bridge_softc *, int);
 static int	bridge_rtdaddr(struct bridge_softc *, const uint8_t *,
-		    uint16_t);
+		    ether_vlanid_t);
 
 static void	bridge_rtable_init(struct bridge_softc *);
 static void	bridge_rtable_fini(struct bridge_softc *);
 
 static int	bridge_rtnode_addr_cmp(const uint8_t *, const uint8_t *);
 static struct bridge_rtnode *bridge_rtnode_lookup(struct bridge_softc *,
-		    const uint8_t *, uint16_t);
+		    const uint8_t *, ether_vlanid_t);
 static int	bridge_rtnode_insert(struct bridge_softc *,
 		    struct bridge_rtnode *);
 static void	bridge_rtnode_destroy(struct bridge_softc *,
@@ -2220,7 +2220,7 @@ bridge_output(struct ifnet *ifp, struct mbuf *m, struct sockaddr *sa,
 	struct bridge_iflist *sbif;
 	struct ifnet *bifp, *dst_if;
 	struct bridge_softc *sc;
-	uint16_t vlan;
+	ether_vlanid_t vlan;
 
 	NET_EPOCH_ASSERT();
 
@@ -2552,7 +2552,7 @@ bridge_input(struct ifnet *ifp, struct mbuf *m)
 	struct ifnet *bifp;
 	struct ether_header *eh;
 	struct mbuf *mc, *mc2;
-	uint16_t vlan;
+	ether_vlanid_t vlan;
 	int error;
 
 	NET_EPOCH_ASSERT();
@@ -2916,8 +2916,9 @@ bridge_span(struct bridge_softc *sc, struct mbuf *m)
  *	Add a bridge routing entry.
  */
 static int
-bridge_rtupdate(struct bridge_softc *sc, const uint8_t *dst, uint16_t vlan,
-    struct bridge_iflist *bif, int setflags, uint8_t flags)
+bridge_rtupdate(struct bridge_softc *sc, const uint8_t *dst,
+		ether_vlanid_t vlan, struct bridge_iflist *bif,
+		int setflags, uint8_t flags)
 {
 	struct bridge_rtnode *brt;
 	struct bridge_iflist *obif;
@@ -3024,7 +3025,8 @@ bridge_rtupdate(struct bridge_softc *sc, const uint8_t *dst, uint16_t vlan,
  *	Lookup the destination interface for an address.
  */
 static struct ifnet *
-bridge_rtlookup(struct bridge_softc *sc, const uint8_t *addr, uint16_t vlan)
+bridge_rtlookup(struct bridge_softc *sc, const uint8_t *addr,
+		ether_vlanid_t vlan)
 {
 	struct bridge_rtnode *brt;
 
@@ -3135,7 +3137,8 @@ bridge_rtflush(struct bridge_softc *sc, int full)
  *	Remove an address from the table.
  */
 static int
-bridge_rtdaddr(struct bridge_softc *sc, const uint8_t *addr, uint16_t vlan)
+bridge_rtdaddr(struct bridge_softc *sc, const uint8_t *addr,
+	       ether_vlanid_t vlan)
 {
 	struct bridge_rtnode *brt;
 	int found = 0;
@@ -3264,7 +3267,8 @@ bridge_rtnode_addr_cmp(const uint8_t *a, const uint8_t *b)
  *	vlan id or if zero then just return the first match.
  */
 static struct bridge_rtnode *
-bridge_rtnode_lookup(struct bridge_softc *sc, const uint8_t *addr, uint16_t vlan)
+bridge_rtnode_lookup(struct bridge_softc *sc, const uint8_t *addr,
+		     ether_vlanid_t vlan)
 {
 	struct bridge_rtnode *brt;
 	uint32_t hash;
diff --git a/sys/net/if_bridgevar.h b/sys/net/if_bridgevar.h
index 048d9fb1a18f..a77ac21c5d1d 100644
--- a/sys/net/if_bridgevar.h
+++ b/sys/net/if_bridgevar.h
@@ -188,7 +188,7 @@ struct ifbareq {
 	unsigned long	ifba_expire;		/* address expire time */
 	uint8_t		ifba_flags;		/* address flags */
 	uint8_t		ifba_dst[ETHER_ADDR_LEN];/* destination address */
-	uint16_t	ifba_vlan;		/* vlan id */
+	ether_vlanid_t	ifba_vlan;		/* vlan id */
 };
 
 #define	IFBAF_TYPEMASK	0x03	/* address type mask */