git: 78bc3d5e1712 - main - vlan: allow net.link.vlan.mtag_pcp to be set per vnet

From: Kristof Provost <kp_at_FreeBSD.org>
Date: Mon, 14 Feb 2022 23:04:21 UTC
The branch main has been updated by kp:

URL: https://cgit.FreeBSD.org/src/commit/?id=78bc3d5e1712bc1649aa5574d2b8d153f9665113

commit 78bc3d5e1712bc1649aa5574d2b8d153f9665113
Author:     Kristof Provost <kp@FreeBSD.org>
AuthorDate: 2022-02-14 19:09:54 +0000
Commit:     Kristof Provost <kp@FreeBSD.org>
CommitDate: 2022-02-14 21:51:10 +0000

    vlan: allow net.link.vlan.mtag_pcp to be set per vnet
    
    The primary reason for this change is to facilitate testing.
    
    MFC after:      1 week
---
 sys/net/if_ethersubr.c | 9 +++++----
 sys/net/if_vlan.c      | 5 +++--
 2 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/sys/net/if_ethersubr.c b/sys/net/if_ethersubr.c
index 3209e8a82978..0427e1352ab1 100644
--- a/sys/net/if_ethersubr.c
+++ b/sys/net/if_ethersubr.c
@@ -1357,9 +1357,10 @@ SYSCTL_INT(_net_link_vlan, OID_AUTO, soft_pad, CTLFLAG_RW | CTLFLAG_VNET,
  * per-packet memory allocations and frees.  In the future, it would be
  * preferable to reuse ether_vtag for this, or similar.
  */
-int vlan_mtag_pcp = 0;
-SYSCTL_INT(_net_link_vlan, OID_AUTO, mtag_pcp, CTLFLAG_RW,
-    &vlan_mtag_pcp, 0,
+VNET_DEFINE(int, vlan_mtag_pcp) = 0;
+#define	V_vlan_mtag_pcp	VNET(vlan_mtag_pcp)
+SYSCTL_INT(_net_link_vlan, OID_AUTO, mtag_pcp, CTLFLAG_RW | CTLFLAG_VNET,
+    &VNET_NAME(vlan_mtag_pcp), 0,
     "Retain VLAN PCP information as packets are passed up the stack");
 
 bool
@@ -1411,7 +1412,7 @@ ether_8021q_frame(struct mbuf **mp, struct ifnet *ife, struct ifnet *p,
 	 * knows how to find the VLAN tag to use, so we attach a
 	 * packet tag that holds it.
 	 */
-	if (vlan_mtag_pcp && (mtag = m_tag_locate(*mp, MTAG_8021Q,
+	if (V_vlan_mtag_pcp && (mtag = m_tag_locate(*mp, MTAG_8021Q,
 	    MTAG_8021Q_PCP_OUT, NULL)) != NULL)
 		tag = EVL_MAKETAG(qtag->vid, *(uint8_t *)(mtag + 1), 0);
 	else
diff --git a/sys/net/if_vlan.c b/sys/net/if_vlan.c
index 07c325d0cb12..c8256dc087a5 100644
--- a/sys/net/if_vlan.c
+++ b/sys/net/if_vlan.c
@@ -213,7 +213,8 @@ static struct {
 	{0, NULL}
 };
 
-extern int vlan_mtag_pcp;
+VNET_DECLARE(int, vlan_mtag_pcp);
+#define	V_vlan_mtag_pcp	VNET(vlan_mtag_pcp)
 
 static const char vlanname[] = "vlan";
 static MALLOC_DEFINE(M_VLAN, vlanname, "802.1Q Virtual LAN Interface");
@@ -1430,7 +1431,7 @@ vlan_input(struct ifnet *ifp, struct mbuf *m)
 		return;
 	}
 
-	if (vlan_mtag_pcp) {
+	if (V_vlan_mtag_pcp) {
 		/*
 		 * While uncommon, it is possible that we will find a 802.1q
 		 * packet encapsulated inside another packet that also had an