Module Name:    src
Committed By:   martin
Date:           Fri Nov 24 08:39:09 UTC 2017

Modified Files:
        src/sys/dev/pci [netbsd-8]: if_bge.c if_wm.c if_wmreg.h
        src/sys/net [netbsd-8]: if_ether.h if_vlan.c if_vlanvar.h

Log Message:
Pull up following revision(s) (requested by msaitoh in ticket #389):
        sys/net/if_ether.h: revision 1.69
        sys/net/if_vlan.c: revision 1.108
        sys/dev/pci/if_bge.c: revision 1.313
        sys/net/if_vlanvar.h: revision 1.11
        sys/net/if_vlanvar.h: revision 1.12
        sys/net/if_ether.h: revision 1.70
        sys/net/if_vlan.c: revision 1.110
        sys/dev/pci/if_wm.c: revision 1.544
        sys/dev/pci/if_wmreg.h: revision 1.105
  Fix a bug that a vlan packet which has priority or CFI bit in the tag causes
panic.
  Revert part of if_bge.c 1.312. It's not required to mask other than VLAN ID
bits in VLAN tag.
  Revert if_wmreg.h 1.104 and if_wm.c 1.542. It's not required to mask other
than VLAN ID bits in VLAN tag.
No functional change:
  - u_int16_t -> uint16_t
  - u_short -> uint16_t
  - tag_hash_func -> vlan_tag_hash
  - 0 -> NULL because vlr_parent is a pointer.


To generate a diff of this commit:
cvs rdiff -u -r1.310.2.1 -r1.310.2.2 src/sys/dev/pci/if_bge.c
cvs rdiff -u -r1.508.4.6 -r1.508.4.7 src/sys/dev/pci/if_wm.c
cvs rdiff -u -r1.98.6.2 -r1.98.6.3 src/sys/dev/pci/if_wmreg.h
cvs rdiff -u -r1.66.8.1 -r1.66.8.2 src/sys/net/if_ether.h
cvs rdiff -u -r1.97.2.7 -r1.97.2.8 src/sys/net/if_vlan.c
cvs rdiff -u -r1.9.80.1 -r1.9.80.2 src/sys/net/if_vlanvar.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/pci/if_bge.c
diff -u src/sys/dev/pci/if_bge.c:1.310.2.1 src/sys/dev/pci/if_bge.c:1.310.2.2
--- src/sys/dev/pci/if_bge.c:1.310.2.1	Tue Oct 24 08:38:59 2017
+++ src/sys/dev/pci/if_bge.c	Fri Nov 24 08:39:09 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_bge.c,v 1.310.2.1 2017/10/24 08:38:59 snj Exp $	*/
+/*	$NetBSD: if_bge.c,v 1.310.2.2 2017/11/24 08:39:09 martin Exp $	*/
 
 /*
  * Copyright (c) 2001 Wind River Systems
@@ -79,7 +79,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_bge.c,v 1.310.2.1 2017/10/24 08:38:59 snj Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_bge.c,v 1.310.2.2 2017/11/24 08:39:09 martin Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -4607,7 +4607,7 @@ bge_rxeof(struct bge_softc *sc)
 		 * to vlan_input() instead of ether_input().
 		 */
 		if (cur_rx->bge_flags & BGE_RXBDFLAG_VLAN_TAG) {
-			vlan_set_tag(m, cur_rx->bge_vlan_tag & ETHER_VLAN_MASK);
+			vlan_set_tag(m, cur_rx->bge_vlan_tag);
 		}
 
 		if_percpuq_enqueue(ifp->if_percpuq, m);

Index: src/sys/dev/pci/if_wm.c
diff -u src/sys/dev/pci/if_wm.c:1.508.4.6 src/sys/dev/pci/if_wm.c:1.508.4.7
--- src/sys/dev/pci/if_wm.c:1.508.4.6	Wed Nov 22 16:40:42 2017
+++ src/sys/dev/pci/if_wm.c	Fri Nov 24 08:39:09 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_wm.c,v 1.508.4.6 2017/11/22 16:40:42 martin Exp $	*/
+/*	$NetBSD: if_wm.c,v 1.508.4.7 2017/11/24 08:39:09 martin Exp $	*/
 
 /*
  * Copyright (c) 2001, 2002, 2003, 2004 Wasabi Systems, Inc.
@@ -83,7 +83,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_wm.c,v 1.508.4.6 2017/11/22 16:40:42 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_wm.c,v 1.508.4.7 2017/11/24 08:39:09 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_net_mpsafe.h"
@@ -8103,11 +8103,11 @@ wm_rxdesc_get_vlantag(struct wm_rxqueue 
 	struct wm_softc *sc = rxq->rxq_sc;
 
 	if (sc->sc_type == WM_T_82574)
-		return EXTRXC_VLAN_ID(rxq->rxq_ext_descs[idx].erx_ctx.erxc_vlan);
+		return rxq->rxq_ext_descs[idx].erx_ctx.erxc_vlan;
 	else if ((sc->sc_flags & WM_F_NEWQUEUE) != 0)
-		return NQRXC_VLAN_ID(rxq->rxq_nq_descs[idx].nqrx_ctx.nrxc_vlan);
+		return rxq->rxq_nq_descs[idx].nqrx_ctx.nrxc_vlan;
 	else
-		return WRX_VLAN_ID(rxq->rxq_descs[idx].wrx_special);
+		return rxq->rxq_descs[idx].wrx_special;
 }
 
 static inline int

Index: src/sys/dev/pci/if_wmreg.h
diff -u src/sys/dev/pci/if_wmreg.h:1.98.6.2 src/sys/dev/pci/if_wmreg.h:1.98.6.3
--- src/sys/dev/pci/if_wmreg.h:1.98.6.2	Mon Nov  6 09:54:01 2017
+++ src/sys/dev/pci/if_wmreg.h	Fri Nov 24 08:39:09 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_wmreg.h,v 1.98.6.2 2017/11/06 09:54:01 snj Exp $	*/
+/*	$NetBSD: if_wmreg.h,v 1.98.6.3 2017/11/24 08:39:09 martin Exp $	*/
 
 /*
  * Copyright (c) 2001 Wasabi Systems, Inc.
@@ -208,12 +208,6 @@ typedef union ext_rxdesc {
 #define EXTRXC_STATUS_PKTTYPE_MASK	__BITS(19,16)
 #define EXTRXC_STATUS_PKTTYPE(status)	__SHIFTOUT(status,EXTRXC_STATUS_PKTTYPE_MASK)
 
-#define	EXTRXC_VLAN_ID_MASK	__BITS(11,0)	/* VLAN identifier mask */
-#define	EXTRXC_VLAN_ID(x)	((x) & EXTRXC_VLAN_ID_MASK) /* VLAN identifier */
-#define	EXTRXC_VLAN_CFI		__BIT(12)	/* Canonical Form Indicator */
-#define	EXTRXC_VLAN_PRI_MASK	__BITS(15,13)	/* VLAN priority mask */
-#define	EXTRXC_VLAN_PRI(x)	__SHIFTOUT((x),EXTRXC_VLAN_PRI_MASK) /* VLAN priority */
-
 /* advanced RX descriptor for 82575 and newer */
 typedef union nq_rxdesc {
 	struct {
@@ -336,12 +330,6 @@ typedef union nq_rxdesc {
 #define NQRXC_STATUS_MC		__BIT(19) /* Packet received from Manageability Controller */
 					  /* "MBC" in i350 spec */
 
-#define	NQRXC_VLAN_ID_MASK	__BITS(11,0)	/* VLAN identifier mask */
-#define	NQRXC_VLAN_ID(x)	((x) & NQRXC_VLAN_ID_MASK) /* VLAN identifier */
-#define	NQRXC_VLAN_CFI		__BIT(12)	/* Canonical Form Indicator */
-#define	NQRXC_VLAN_PRI_MASK	__BITS(15,13)	/* VLAN priority mask */
-#define	NQRXC_VLAN_PRI(x)	__SHIFTOUT((x),NQRXC_VLAN_PRI_MASK) /* VLAN priority */
-
 /*
  * The Wiseman transmit descriptor.
  *

Index: src/sys/net/if_ether.h
diff -u src/sys/net/if_ether.h:1.66.8.1 src/sys/net/if_ether.h:1.66.8.2
--- src/sys/net/if_ether.h:1.66.8.1	Tue Oct 24 08:38:59 2017
+++ src/sys/net/if_ether.h	Fri Nov 24 08:39:08 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_ether.h,v 1.66.8.1 2017/10/24 08:38:59 snj Exp $	*/
+/*	$NetBSD: if_ether.h,v 1.66.8.2 2017/11/24 08:39:08 martin Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1993
@@ -59,9 +59,11 @@
 /*
  * Some Ethernet extensions.
  */
-#define	ETHER_VLAN_ENCAP_LEN 4	/* length of 802.1Q VLAN encapsulation */
-#define	ETHER_VLAN_MASK	0xFFF	/* bits in a vlan tag */
-#define	ETHER_PPPOE_ENCAP_LEN 8	/* length of PPPoE encapsulation */
+#define	ETHER_VLAN_ENCAP_LEN	4      /* length of 802.1Q VLAN encapsulation */
+#define	EVL_VLANOFTAG(tag)	((tag) & 4095)		/* VLAN ID */
+#define	EVL_PRIOFTAG(tag)	(((tag) >> 13) & 7)	/* Priority */
+#define	EVL_CFIOFTAG(tag)	(((tag) >> 12) & 1)	/* CFI */
+#define	ETHER_PPPOE_ENCAP_LEN	8	/* length of PPPoE encapsulation */
 
 /*
  * Ethernet address - 6 octets
@@ -297,12 +299,12 @@ struct ether_multistep {
 
 /* add VLAN tag to input/received packet */
 static inline void
-vlan_set_tag(struct mbuf *m, u_int16_t vlanid)
+vlan_set_tag(struct mbuf *m, uint16_t vlantag)
 {
 
-	KASSERT((vlanid & ~ETHER_VLAN_MASK) == 0);
+	/* VLAN tag contains priority, CFI and VLAN ID */
 
-	m->m_pkthdr.ether_vtag = vlanid;
+	m->m_pkthdr.ether_vtag = vlantag;
 	m->m_flags |= M_VLANTAG;
 	return;
 }

Index: src/sys/net/if_vlan.c
diff -u src/sys/net/if_vlan.c:1.97.2.7 src/sys/net/if_vlan.c:1.97.2.8
--- src/sys/net/if_vlan.c:1.97.2.7	Wed Nov 22 14:30:23 2017
+++ src/sys/net/if_vlan.c	Fri Nov 24 08:39:09 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_vlan.c,v 1.97.2.7 2017/11/22 14:30:23 martin Exp $	*/
+/*	$NetBSD: if_vlan.c,v 1.97.2.8 2017/11/24 08:39:09 martin Exp $	*/
 
 /*-
  * Copyright (c) 2000, 2001 The NetBSD Foundation, Inc.
@@ -78,7 +78,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_vlan.c,v 1.97.2.7 2017/11/22 14:30:23 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_vlan.c,v 1.97.2.8 2017/11/24 08:39:09 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -207,6 +207,7 @@ static int	vlan_unconfig_locked(struct i
     struct ifvlan_linkmib *);
 static void	vlan_hash_init(void);
 static int	vlan_hash_fini(void);
+static int	vlan_tag_hash(uint16_t, u_long);
 static struct ifvlan_linkmib*	vlan_getref_linkmib(struct ifvlan *,
     struct psref *);
 static void	vlan_putref_linkmib(struct ifvlan_linkmib *,
@@ -215,7 +216,6 @@ static void	vlan_linkmib_update(struct i
     struct ifvlan_linkmib *);
 static struct ifvlan_linkmib*	vlan_lookup_tag_psref(struct ifnet *,
     uint16_t, struct psref *);
-static int	tag_hash_func(uint16_t, u_long);
 
 LIST_HEAD(vlan_ifvlist, ifvlan);
 static struct {
@@ -381,6 +381,7 @@ vlan_config(struct ifvlan *ifv, struct i
 	struct ifvlan_linkmib *omib = NULL;
 	struct ifvlan_linkmib *checkmib = NULL;
 	struct psref_target *nmib_psref = NULL;
+	uint16_t vid = EVL_VLANOFTAG(tag);
 	int error = 0;
 	int idx;
 	bool omib_cleanup = false;
@@ -397,7 +398,7 @@ vlan_config(struct ifvlan *ifv, struct i
 	}
 
 	/* Duplicate check */
-	checkmib = vlan_lookup_tag_psref(p, tag, &psref);
+	checkmib = vlan_lookup_tag_psref(p, vid, &psref);
 	if (checkmib != NULL) {
 		vlan_putref_linkmib(checkmib, &psref);
 		error = EEXIST;
@@ -467,7 +468,7 @@ vlan_config(struct ifvlan *ifv, struct i
 	}
 
 	nmib->ifvm_p = p;
-	nmib->ifvm_tag = tag;
+	nmib->ifvm_tag = vid;
 	ifv->ifv_if.if_mtu = p->if_mtu - nmib->ifvm_mtufudge;
 	ifv->ifv_if.if_flags = p->if_flags &
 	    (IFF_UP | IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST);
@@ -479,7 +480,7 @@ vlan_config(struct ifvlan *ifv, struct i
 	ifv->ifv_if.if_type = p->if_type;
 
 	PSLIST_ENTRY_INIT(ifv, ifv_hash);
-	idx = tag_hash_func(tag, ifv_hash.mask);
+	idx = vlan_tag_hash(vid, ifv_hash.mask);
 
 	mutex_enter(&ifv_hash.lock);
 	PSLIST_WRITER_INSERT_HEAD(&ifv_hash.lists[idx], ifv, ifv_hash);
@@ -649,7 +650,7 @@ vlan_hash_fini(void)
 }
 
 static int
-tag_hash_func(uint16_t tag, u_long mask)
+vlan_tag_hash(uint16_t tag, u_long mask)
 {
 	uint32_t hash;
 
@@ -693,7 +694,7 @@ vlan_lookup_tag_psref(struct ifnet *ifp,
 	int s;
 	struct ifvlan *sc;
 
-	idx = tag_hash_func(tag, ifv_hash.mask);
+	idx = vlan_tag_hash(tag, ifv_hash.mask);
 
 	s = pserialize_read_enter();
 	PSLIST_READER_FOREACH(sc, &ifv_hash.lists[idx], struct ifvlan,
@@ -910,7 +911,7 @@ vlan_ioctl(struct ifnet *ifp, u_long cmd
 			error = EINVAL;		 /* check for valid tag */
 			break;
 		}
-		if ((pr = ifunit(vlr.vlr_parent)) == 0) {
+		if ((pr = ifunit(vlr.vlr_parent)) == NULL) {
 			error = ENOENT;
 			break;
 		}
@@ -1458,14 +1459,14 @@ void
 vlan_input(struct ifnet *ifp, struct mbuf *m)
 {
 	struct ifvlan *ifv;
-	u_int tag;
+	uint16_t vid;
 	struct ifvlan_linkmib *mib;
 	struct psref psref;
 	bool have_vtag;
 
 	have_vtag = vlan_has_tag(m);
 	if (have_vtag) {
-		tag = EVL_VLANOFTAG(vlan_get_tag(m));
+		vid = EVL_VLANOFTAG(vlan_get_tag(m));
 		m->m_flags &= ~M_VLANTAG;
 	} else {
 		switch (ifp->if_type) {
@@ -1483,7 +1484,7 @@ vlan_input(struct ifnet *ifp, struct mbu
 			evl = mtod(m, struct ether_vlan_header *);
 			KASSERT(ntohs(evl->evl_encap_proto) == ETHERTYPE_VLAN);
 
-			tag = EVL_VLANOFTAG(ntohs(evl->evl_tag));
+			vid = EVL_VLANOFTAG(ntohs(evl->evl_tag));
 
 			/*
 			 * Restore the original ethertype.  We'll remove
@@ -1495,14 +1496,14 @@ vlan_input(struct ifnet *ifp, struct mbu
 		    }
 
 		default:
-			tag = (u_int) -1;	/* XXX GCC */
+			vid = (uint16_t) -1;	/* XXX GCC */
 #ifdef DIAGNOSTIC
 			panic("vlan_input: impossible");
 #endif
 		}
 	}
 
-	mib = vlan_lookup_tag_psref(ifp, tag, &psref);
+	mib = vlan_lookup_tag_psref(ifp, vid, &psref);
 	if (mib == NULL) {
 		m_freem(m);
 		ifp->if_noproto++;

Index: src/sys/net/if_vlanvar.h
diff -u src/sys/net/if_vlanvar.h:1.9.80.1 src/sys/net/if_vlanvar.h:1.9.80.2
--- src/sys/net/if_vlanvar.h:1.9.80.1	Wed Jun 21 17:39:24 2017
+++ src/sys/net/if_vlanvar.h	Fri Nov 24 08:39:09 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_vlanvar.h,v 1.9.80.1 2017/06/21 17:39:24 snj Exp $	*/
+/*	$NetBSD: if_vlanvar.h,v 1.9.80.2 2017/11/24 08:39:09 martin Exp $	*/
 
 /*-
  * Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -71,13 +71,10 @@ struct ether_vlan_header {
 	uint16_t	evl_proto;
 } __packed;
 
-#define	EVL_VLANOFTAG(tag)	((tag) & 4095)
-#define	EVL_PRIOFTAG(tag)	(((tag) >> 13) & 7)
-
 /* Configuration structure for SIOCSETVLAN and SIOCGETVLAN ioctls. */
 struct vlanreq {
-	char	vlr_parent[IFNAMSIZ];
-	u_short	vlr_tag;
+	char		vlr_parent[IFNAMSIZ];
+	uint16_t	vlr_tag;
 };
 
 #define	SIOCSETVLAN	SIOCSIFGENERIC

Reply via email to