Module Name: src
Committed By: yamaguchi
Date: Mon Jun 20 08:20:09 UTC 2022
Modified Files:
src/sys/net: bpf.h if.h if_ethersubr.c
Log Message:
bpf(4): added support for VLAN hardware offloading of ethernet devices
To generate a diff of this commit:
cvs rdiff -u -r1.77 -r1.78 src/sys/net/bpf.h
cvs rdiff -u -r1.297 -r1.298 src/sys/net/if.h
cvs rdiff -u -r1.313 -r1.314 src/sys/net/if_ethersubr.c
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/bpf.h
diff -u src/sys/net/bpf.h:1.77 src/sys/net/bpf.h:1.78
--- src/sys/net/bpf.h:1.77 Wed Jun 9 15:44:15 2021
+++ src/sys/net/bpf.h Mon Jun 20 08:20:09 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: bpf.h,v 1.77 2021/06/09 15:44:15 martin Exp $ */
+/* $NetBSD: bpf.h,v 1.78 2022/06/20 08:20:09 yamaguchi Exp $ */
/*
* Copyright (c) 1990, 1991, 1993
@@ -474,8 +474,13 @@ bpf_attach2(struct ifnet *_ifp, u_int _d
static __inline void
bpf_mtap(struct ifnet *_ifp, struct mbuf *_m, u_int _direction)
{
- if (_ifp->if_bpf)
- bpf_ops->bpf_mtap(_ifp->if_bpf, _m, _direction);
+ if (_ifp->if_bpf) {
+ if (_ifp->if_bpf_mtap) {
+ _ifp->if_bpf_mtap(_ifp->if_bpf, _m, _direction);
+ } else {
+ bpf_ops->bpf_mtap(_ifp->if_bpf, _m, _direction);
+ }
+ }
}
static __inline void
Index: src/sys/net/if.h
diff -u src/sys/net/if.h:1.297 src/sys/net/if.h:1.298
--- src/sys/net/if.h:1.297 Mon Jun 20 08:02:25 2022
+++ src/sys/net/if.h Mon Jun 20 08:20:09 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: if.h,v 1.297 2022/06/20 08:02:25 yamaguchi Exp $ */
+/* $NetBSD: if.h,v 1.298 2022/06/20 08:20:09 yamaguchi Exp $ */
/*-
* Copyright (c) 1999, 2000, 2001 The NetBSD Foundation, Inc.
@@ -340,6 +340,8 @@ typedef struct ifnet {
#define if_watchdog if_slowtimo
void (*if_drain) /* :: routine to release resources */
(struct ifnet *);
+ void (*if_bpf_mtap) /* :: bpf routine */
+ (struct bpf_if *, struct mbuf *, u_int);
struct ifaltq if_snd; /* q: output queue (includes altq) */
struct ifaddr *if_dl; /* i: identity of this interface. */
const struct sockaddr_dl
Index: src/sys/net/if_ethersubr.c
diff -u src/sys/net/if_ethersubr.c:1.313 src/sys/net/if_ethersubr.c:1.314
--- src/sys/net/if_ethersubr.c:1.313 Mon Jun 20 08:14:48 2022
+++ src/sys/net/if_ethersubr.c Mon Jun 20 08:20:09 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: if_ethersubr.c,v 1.313 2022/06/20 08:14:48 yamaguchi Exp $ */
+/* $NetBSD: if_ethersubr.c,v 1.314 2022/06/20 08:20:09 yamaguchi 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.313 2022/06/20 08:14:48 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_ethersubr.c,v 1.314 2022/06/20 08:20:09 yamaguchi Exp $");
#ifdef _KERNEL_OPT
#include "opt_inet.h"
@@ -971,6 +971,37 @@ error:
return;
}
+static void
+ether_bpf_mtap(struct bpf_if *bp, struct mbuf *m, u_int direction)
+{
+ struct ether_vlan_header evl;
+ struct m_hdr mh, md;
+
+ KASSERT(bp != NULL);
+
+ if (!vlan_has_tag(m)) {
+ bpf_mtap3(bp, m, direction);
+ return;
+ }
+
+ memcpy(&evl, mtod(m, char *), ETHER_HDR_LEN);
+ evl.evl_proto = evl.evl_encap_proto;
+ evl.evl_encap_proto = htons(ETHERTYPE_VLAN);
+ evl.evl_tag = htons(vlan_get_tag(m));
+
+ md.mh_flags = 0;
+ md.mh_data = m->m_data + ETHER_HDR_LEN;
+ md.mh_len = m->m_len - ETHER_HDR_LEN;
+ md.mh_next = m->m_next;
+
+ mh.mh_flags = 0;
+ mh.mh_data = (char *)&evl;
+ mh.mh_len = sizeof(evl);
+ mh.mh_next = (struct mbuf *)&md;
+
+ bpf_mtap3(bp, (struct mbuf *)&mh, direction);
+}
+
/*
* Convert Ethernet address to printable (loggable) representation.
*/
@@ -1011,6 +1042,7 @@ ether_ifattach(struct ifnet *ifp, const
ifp->if_mtu = ETHERMTU;
ifp->if_output = ether_output;
ifp->_if_input = ether_input;
+ ifp->if_bpf_mtap = ether_bpf_mtap;
if (ifp->if_baudrate == 0)
ifp->if_baudrate = IF_Mbps(10); /* just a default */