git: ed19cb27bde8 - stable/13 - ether_demux: Defer stripping the Ethernet header.

From: John Baldwin <jhb_at_FreeBSD.org>
Date: Wed, 28 Jun 2023 01:33:10 UTC
The branch stable/13 has been updated by jhb:

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

commit ed19cb27bde8c87ece83e390b0fd40991abdc9b3
Author:     John Baldwin <jhb@FreeBSD.org>
AuthorDate: 2022-11-30 22:38:51 +0000
Commit:     John Baldwin <jhb@FreeBSD.org>
CommitDate: 2023-06-28 01:32:47 +0000

    ether_demux: Defer stripping the Ethernet header.
    
    This avoids having to undo it before invoking NetGraph's orphan input
    hook.
    
    Reviewed by:    ae, melifaro
    Sponsored by:   Chelsio Communications
    Differential Revision:  https://reviews.freebsd.org/D37510
    
    (cherry picked from commit 79b679942352a7f10d759fdee1892aa251e0f439)
---
 sys/net/if_ethersubr.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/sys/net/if_ethersubr.c b/sys/net/if_ethersubr.c
index 25daf13ccef6..9a614fbe6844 100644
--- a/sys/net/if_ethersubr.c
+++ b/sys/net/if_ethersubr.c
@@ -886,11 +886,9 @@ ether_demux(struct ifnet *ifp, struct mbuf *m)
 
 	/*
 	 * Reset layer specific mbuf flags to avoid confusing upper layers.
-	 * Strip off Ethernet header.
 	 */
 	m->m_flags &= ~M_VLANTAG;
 	m_clrprotoflags(m);
-	m_adj(m, ETHER_HDR_LEN);
 
 	/*
 	 * Dispatch frame to upper layer.
@@ -918,6 +916,10 @@ ether_demux(struct ifnet *ifp, struct mbuf *m)
 	default:
 		goto discard;
 	}
+
+	/* Strip off Ethernet header. */
+	m_adj(m, ETHER_HDR_LEN);
+
 	netisr_dispatch(isr, m);
 	return;
 
@@ -930,11 +932,6 @@ discard:
 	if (ifp->if_l2com != NULL) {
 		KASSERT(ng_ether_input_orphan_p != NULL,
 		    ("ng_ether_input_orphan_p is NULL"));
-		/*
-		 * Put back the ethernet header so netgraph has a
-		 * consistent view of inbound packets.
-		 */
-		M_PREPEND(m, ETHER_HDR_LEN, M_NOWAIT);
 		(*ng_ether_input_orphan_p)(ifp, m);
 		return;
 	}