Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/net bpf(4): added support for VLAN hardware offloading o...



details:   https://anonhg.NetBSD.org/src/rev/26826f19b738
branches:  trunk
changeset: 367260:26826f19b738
user:      yamaguchi <yamaguchi%NetBSD.org@localhost>
date:      Mon Jun 20 08:20:09 2022 +0000

description:
bpf(4): added support for VLAN hardware offloading of ethernet devices

diffstat:

 sys/net/bpf.h          |  11 ++++++++---
 sys/net/if.h           |   4 +++-
 sys/net/if_ethersubr.c |  36 ++++++++++++++++++++++++++++++++++--
 3 files changed, 45 insertions(+), 6 deletions(-)

diffs (107 lines):

diff -r 22f8295bfced -r 26826f19b738 sys/net/bpf.h
--- a/sys/net/bpf.h     Mon Jun 20 08:14:48 2022 +0000
+++ b/sys/net/bpf.h     Mon Jun 20 08:20:09 2022 +0000
@@ -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 @@
 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
diff -r 22f8295bfced -r 26826f19b738 sys/net/if.h
--- a/sys/net/if.h      Mon Jun 20 08:14:48 2022 +0000
+++ b/sys/net/if.h      Mon Jun 20 08:20:09 2022 +0000
@@ -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 @@
 #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
diff -r 22f8295bfced -r 26826f19b738 sys/net/if_ethersubr.c
--- a/sys/net/if_ethersubr.c    Mon Jun 20 08:14:48 2022 +0000
+++ b/sys/net/if_ethersubr.c    Mon Jun 20 08:20:09 2022 +0000
@@ -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 @@
        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 @@
        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 */
 



Home | Main Index | Thread Index | Old Index