Module Name:    src
Committed By:   roy
Date:           Mon Nov 14 09:23:42 UTC 2022

Modified Files:
        src/sys/net: if_ethersubr.c
        src/sys/sys: mbuf.h

Log Message:
net: Store a pointer to the Layer 2 Sender Hardware address in mbuf

The BSD networking stack is designed around passing a mbuf down the chain
and each layer removes the part it's interested in before passing it to
the next. This makes it easy for each layer to do it's work,
but non trivial to work backwards.

As such we now store a pointer to the Senders Hardware address in the
mbuf packet header so that protocols can perform any required validation.


To generate a diff of this commit:
cvs rdiff -u -r1.320 -r1.321 src/sys/net/if_ethersubr.c
cvs rdiff -u -r1.232 -r1.233 src/sys/sys/mbuf.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/net/if_ethersubr.c
diff -u src/sys/net/if_ethersubr.c:1.320 src/sys/net/if_ethersubr.c:1.321
--- src/sys/net/if_ethersubr.c:1.320	Sat Sep  3 02:47:59 2022
+++ src/sys/net/if_ethersubr.c	Mon Nov 14 09:23:42 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_ethersubr.c,v 1.320 2022/09/03 02:47:59 thorpej Exp $	*/
+/*	$NetBSD: if_ethersubr.c,v 1.321 2022/11/14 09:23:42 roy Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -61,7 +61,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_ethersubr.c,v 1.320 2022/09/03 02:47:59 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_ethersubr.c,v 1.321 2022/11/14 09:23:42 roy Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -886,6 +886,10 @@ ether_input(struct ifnet *ifp, struct mb
 #endif
 	}
 
+	/* Store the senders hardware address */
+	m->m_pkthdr.l2_sha = &eh->ether_shost;
+	m->m_pkthdr.l2_shalen = ETHER_ADDR_LEN;
+
 	/* Strip off the Ethernet header. */
 	m_adj(m, ehlen);
 

Index: src/sys/sys/mbuf.h
diff -u src/sys/sys/mbuf.h:1.232 src/sys/sys/mbuf.h:1.233
--- src/sys/sys/mbuf.h:1.232	Fri Feb 19 14:51:59 2021
+++ src/sys/sys/mbuf.h	Mon Nov 14 09:23:42 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: mbuf.h,v 1.232 2021/02/19 14:51:59 christos Exp $	*/
+/*	$NetBSD: mbuf.h,v 1.233 2022/11/14 09:23:42 roy Exp $	*/
 
 /*
  * Copyright (c) 1996, 1997, 1999, 2001, 2007 The NetBSD Foundation, Inc.
@@ -203,6 +203,9 @@ struct pkthdr {
 	int	pattr_af;		/* ALTQ: address family */
 	void	*pattr_class;		/* ALTQ: sched class set by classifier */
 	void	*pattr_hdr;		/* ALTQ: saved header position in mbuf */
+
+	void		*l2_sha;		/* l2 sender host address */
+	size_t		l2_shalen;		/* length of the sender address */
 };
 
 /* Checksumming flags (csum_flags). */

Reply via email to