git: 5c332527d15f - stable/13 - ng_pppoe: introduce new sysctl net.graph.pppoe.lcp_pcp

From: Eugene Grosbein <eugen_at_FreeBSD.org>
Date: Mon, 16 May 2022 02:33:07 UTC
The branch stable/13 has been updated by eugen:

URL: https://cgit.FreeBSD.org/src/commit/?id=5c332527d15fa3bd93e157477454dfe0bab68cd7

commit 5c332527d15fa3bd93e157477454dfe0bab68cd7
Author:     Eugene Grosbein <eugen@FreeBSD.org>
AuthorDate: 2022-05-01 16:34:08 +0000
Commit:     Eugene Grosbein <eugen@FreeBSD.org>
CommitDate: 2022-05-16 02:31:56 +0000

    ng_pppoe: introduce new sysctl net.graph.pppoe.lcp_pcp
    
    New sysctl allows to mark transmitted PPPoE LCP Control
    ethernet frames with needed 3-bit Priority Code Point (PCP) value.
    Confirming driver like if_vlan(4) uses the value to fill
    IEEE 802.1p class of service field.
    
    This is similar to Cisco IOS "control-packets vlan cos priority"
    command.
    
    It helps to avoid premature disconnection of user sessions
    due to control frame drops (LCP Echo etc.)
    if network infrastructure has a botteleck at a switch
    or the xdsl DSLAM.
    
    See also:
    https://sourceforge.net/p/mpd/discussion/44692/thread/c7abe70e3a/
    
    Tested by:      Klaus Fokuhl at SourceForge
    
    (cherry picked from commit 2e547442ab3822d3d7c46a68f152032ef5fe337c)
    (cherry picked from commit 28903f396af4b151e16ea606cda66a9244fb179f)
---
 share/man/man4/ng_pppoe.4 | 17 +++++++++++++++--
 sys/netgraph/ng_pppoe.c   | 22 ++++++++++++++++++++++
 2 files changed, 37 insertions(+), 2 deletions(-)

diff --git a/share/man/man4/ng_pppoe.4 b/share/man/man4/ng_pppoe.4
index d4ca53e68714..ff53d4ef3a95 100644
--- a/share/man/man4/ng_pppoe.4
+++ b/share/man/man4/ng_pppoe.4
@@ -35,7 +35,7 @@
 .\" $FreeBSD$
 .\" $Whistle: ng_pppoe.8,v 1.1 1999/01/25 23:46:27 archie Exp $
 .\"
-.Dd February 14, 2018
+.Dd May 1, 2022
 .Dt NG_PPPOE 4
 .Os
 .Sh NAME
@@ -320,6 +320,18 @@ This node shuts down upon receipt of a
 control message, when all session have been disconnected or when the
 .Dv ethernet
 hook is disconnected.
+.Sh SYSCTL VARIABLES
+The node can mark transmitted LCP Ethernet packets (protocol 0xc021)
+with 3-bit Priority Code Point (PCP) referring to IEEE 802.1p
+class of service with following
+.Xr sysctl 8
+variable.
+.Bl -tag -width indent
+.It Va net.graph.pppoe.lcp_pcp: 0..7 (default: 0)
+Set it to non-zero value to be used by parent network interface driver
+like
+.Xr vlan 4
+.El
 .Sh EXAMPLES
 The following code uses
 .Dv libnetgraph
@@ -556,7 +568,8 @@ setup(char *ethername, char *service, char *sessname,
 .Xr ng_ppp 4 ,
 .Xr ng_socket 4 ,
 .Xr ngctl 8 ,
-.Xr ppp 8
+.Xr ppp 8 ,
+.Xr vlan 4
 .Rs
 .%A L. Mamakos
 .%A K. Lidl
diff --git a/sys/netgraph/ng_pppoe.c b/sys/netgraph/ng_pppoe.c
index e07f77b9d541..92a17286ccae 100644
--- a/sys/netgraph/ng_pppoe.c
+++ b/sys/netgraph/ng_pppoe.c
@@ -49,8 +49,13 @@
 #include <sys/malloc.h>
 #include <sys/errno.h>
 #include <sys/epoch.h>
+#include <sys/socket.h>
+#include <sys/sysctl.h>
 #include <sys/syslog.h>
 #include <net/ethernet.h>
+#include <net/if.h>
+#include <net/if_vlan_var.h>
+#include <net/vnet.h>
 
 #include <netgraph/ng_message.h>
 #include <netgraph/netgraph.h>
@@ -64,8 +69,19 @@ static MALLOC_DEFINE(M_NETGRAPH_PPPOE, "netgraph_pppoe", "netgraph pppoe node");
 #define M_NETGRAPH_PPPOE M_NETGRAPH
 #endif
 
+/* Some PPP protocol numbers we're interested in */
+#define PROT_LCP		0xc021
+
 #define SIGNOFF "session closed"
 
+VNET_DEFINE_STATIC(u_int32_t, ng_pppoe_lcp_pcp) = 0;
+#define V_ng_pppoe_lcp_pcp	VNET(ng_pppoe_lcp_pcp)
+
+SYSCTL_NODE(_net_graph, OID_AUTO, pppoe, CTLFLAG_RW, 0, "PPPoE");
+SYSCTL_UINT(_net_graph_pppoe, OID_AUTO, lcp_pcp,
+	CTLFLAG_VNET | CTLFLAG_RW, &VNET_NAME(ng_pppoe_lcp_pcp), 0,
+	"Set PCP for LCP");
+
 /*
  * This section contains the netgraph method declarations for the
  * pppoe node. These methods define the netgraph pppoe 'type'.
@@ -1438,6 +1454,12 @@ ng_pppoe_rcvdata(hook_p hook, item_p item)
 			    mtod(m, u_char *)[1] == 0x03)
 				m_adj(m, 2);
 		}
+
+		if (V_ng_pppoe_lcp_pcp && m->m_pkthdr.len >= 2 &&
+		    m->m_len >= 2 && (m = m_pullup(m, 2)) &&
+		    mtod(m, uint16_t *)[0] == htons(PROT_LCP))
+			EVL_APPLY_PRI(m, (uint8_t)(V_ng_pppoe_lcp_pcp & 0x7));
+
 		/*
 		 * Bang in a pre-made header, and set the length up
 		 * to be correct. Then send it to the ethernet driver.