From e1ffbca217ef83e1ea6ff18be4d48b9041a1610a Mon Sep 17 00:00:00 2001 From: Sepherosa Ziehau Date: Mon, 10 Mar 2008 12:59:52 +0000 Subject: [PATCH] Add ETHER_BPF_MTAP() which will call vlan_ether_ptap() for packets whose vlan tagging is offloaded to NIC. Obtained-from: FreeBSD --- sys/dev/netif/bce/if_bce.c | 5 +++-- sys/dev/netif/bge/if_bge.c | 5 +++-- sys/dev/netif/em/if_em.c | 5 +++-- sys/dev/netif/nfe/if_nfe.c | 5 +++-- sys/dev/netif/nge/if_nge.c | 5 +++-- sys/dev/netif/re/if_re.c | 5 +++-- sys/dev/netif/stge/if_stge.c | 5 +++-- sys/dev/netif/ti/if_ti.c | 5 +++-- sys/dev/netif/txp/if_txp.c | 5 +++-- sys/dev/netif/vge/if_vge.c | 5 +++-- sys/net/ethernet.h | 21 ++++++++++++++++++++- 11 files changed, 50 insertions(+), 21 deletions(-) diff --git a/sys/dev/netif/bce/if_bce.c b/sys/dev/netif/bce/if_bce.c index 1536d3a0f..3299cd763 100644 --- a/sys/dev/netif/bce/if_bce.c +++ b/sys/dev/netif/bce/if_bce.c @@ -28,7 +28,7 @@ * THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/dev/bce/if_bce.c,v 1.31 2007/05/16 23:34:11 davidch Exp $ - * $DragonFly: src/sys/dev/netif/bce/if_bce.c,v 1.2 2008/03/10 10:47:57 sephe Exp $ + * $DragonFly: src/sys/dev/netif/bce/if_bce.c,v 1.3 2008/03/10 12:59:51 sephe Exp $ */ /* @@ -71,6 +71,7 @@ #include #include #include +#include #include #include @@ -4515,7 +4516,7 @@ bce_start(struct ifnet *ifp) count++; /* Send a copy of the frame to any BPF listeners. */ - BPF_MTAP(ifp, m_head); + ETHER_BPF_MTAP(ifp, m_head); } if (count == 0) { diff --git a/sys/dev/netif/bge/if_bge.c b/sys/dev/netif/bge/if_bge.c index dd13712e7..d7fb71217 100644 --- a/sys/dev/netif/bge/if_bge.c +++ b/sys/dev/netif/bge/if_bge.c @@ -31,7 +31,7 @@ * THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/dev/bge/if_bge.c,v 1.3.2.39 2005/07/03 03:41:18 silby Exp $ - * $DragonFly: src/sys/dev/netif/bge/if_bge.c,v 1.89 2008/03/10 10:47:57 sephe Exp $ + * $DragonFly: src/sys/dev/netif/bge/if_bge.c,v 1.90 2008/03/10 12:59:51 sephe Exp $ * */ @@ -96,6 +96,7 @@ #include #include #include +#include #include #include @@ -2781,7 +2782,7 @@ bge_start(struct ifnet *ifp) } need_trans = 1; - BPF_MTAP(ifp, m_head); + ETHER_BPF_MTAP(ifp, m_head); } if (!need_trans) diff --git a/sys/dev/netif/em/if_em.c b/sys/dev/netif/em/if_em.c index 5fceb2761..d5a966f1e 100644 --- a/sys/dev/netif/em/if_em.c +++ b/sys/dev/netif/em/if_em.c @@ -64,7 +64,7 @@ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $DragonFly: src/sys/dev/netif/em/if_em.c,v 1.64 2008/03/10 10:47:57 sephe Exp $ + * $DragonFly: src/sys/dev/netif/em/if_em.c,v 1.65 2008/03/10 12:59:51 sephe Exp $ * $FreeBSD$ */ /* @@ -119,6 +119,7 @@ #include #include #include +#include #ifdef INET #include @@ -834,7 +835,7 @@ em_start(struct ifnet *ifp) ifq_dequeue(&ifp->if_snd, m_head); /* Send a copy of the frame to the BPF listener */ - BPF_MTAP(ifp, m_head); + ETHER_BPF_MTAP(ifp, m_head); /* Set timeout in case hardware has problems transmitting. */ ifp->if_timer = EM_TX_TIMEOUT; diff --git a/sys/dev/netif/nfe/if_nfe.c b/sys/dev/netif/nfe/if_nfe.c index 783478efb..7ca3a865f 100644 --- a/sys/dev/netif/nfe/if_nfe.c +++ b/sys/dev/netif/nfe/if_nfe.c @@ -1,5 +1,5 @@ /* $OpenBSD: if_nfe.c,v 1.63 2006/06/17 18:00:43 brad Exp $ */ -/* $DragonFly: src/sys/dev/netif/nfe/if_nfe.c,v 1.18 2008/03/10 10:47:57 sephe Exp $ */ +/* $DragonFly: src/sys/dev/netif/nfe/if_nfe.c,v 1.19 2008/03/10 12:59:51 sephe Exp $ */ /* * Copyright (c) 2006 The DragonFly Project. All rights reserved. @@ -78,6 +78,7 @@ #include #include #include +#include #include #include @@ -1188,7 +1189,7 @@ nfe_start(struct ifnet *ifp) if (m0 == NULL) break; - BPF_MTAP(ifp, m0); + ETHER_BPF_MTAP(ifp, m0); if (nfe_encap(sc, ring, m0) != 0) { ifp->if_flags |= IFF_OACTIVE; diff --git a/sys/dev/netif/nge/if_nge.c b/sys/dev/netif/nge/if_nge.c index 5a0c2da6b..8d51ca4f7 100644 --- a/sys/dev/netif/nge/if_nge.c +++ b/sys/dev/netif/nge/if_nge.c @@ -31,7 +31,7 @@ * THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/dev/nge/if_nge.c,v 1.13.2.13 2003/02/05 22:03:57 mbr Exp $ - * $DragonFly: src/sys/dev/netif/nge/if_nge.c,v 1.45 2008/03/10 10:47:57 sephe Exp $ + * $DragonFly: src/sys/dev/netif/nge/if_nge.c,v 1.46 2008/03/10 12:59:51 sephe Exp $ */ /* @@ -110,6 +110,7 @@ #include #include #include +#include #include @@ -1620,7 +1621,7 @@ nge_start(struct ifnet *ifp) ifq_dequeue(&ifp->if_snd, m_head); need_trans = 1; - BPF_MTAP(ifp, m_head); + ETHER_BPF_MTAP(ifp, m_head); } if (!need_trans) diff --git a/sys/dev/netif/re/if_re.c b/sys/dev/netif/re/if_re.c index bf4abd888..ce6ad44cf 100644 --- a/sys/dev/netif/re/if_re.c +++ b/sys/dev/netif/re/if_re.c @@ -33,7 +33,7 @@ * THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/dev/re/if_re.c,v 1.25 2004/06/09 14:34:01 naddy Exp $ - * $DragonFly: src/sys/dev/netif/re/if_re.c,v 1.37 2008/03/10 10:47:57 sephe Exp $ + * $DragonFly: src/sys/dev/netif/re/if_re.c,v 1.38 2008/03/10 12:59:51 sephe Exp $ */ /* @@ -135,6 +135,7 @@ #include #include #include +#include #include #include @@ -2006,7 +2007,7 @@ re_start(struct ifnet *ifp) * If there's a BPF listener, bounce a copy of this frame * to him. */ - BPF_MTAP(ifp, m_head2); + ETHER_BPF_MTAP(ifp, m_head2); } if (!need_trans) { diff --git a/sys/dev/netif/stge/if_stge.c b/sys/dev/netif/stge/if_stge.c index 53b0ffb14..7ece21f54 100644 --- a/sys/dev/netif/stge/if_stge.c +++ b/sys/dev/netif/stge/if_stge.c @@ -1,6 +1,6 @@ /* $NetBSD: if_stge.c,v 1.32 2005/12/11 12:22:49 christos Exp $ */ /* $FreeBSD: src/sys/dev/stge/if_stge.c,v 1.2 2006/08/12 01:21:36 yongari Exp $ */ -/* $DragonFly: src/sys/dev/netif/stge/if_stge.c,v 1.3 2008/03/10 10:47:57 sephe Exp $ */ +/* $DragonFly: src/sys/dev/netif/stge/if_stge.c,v 1.4 2008/03/10 12:59:52 sephe Exp $ */ /*- * Copyright (c) 2001 The NetBSD Foundation, Inc. @@ -67,6 +67,7 @@ #include #include #include +#include #include #include @@ -1334,7 +1335,7 @@ stge_start(struct ifnet *ifp) * If there's a BPF listener, bounce a copy of this frame * to him. */ - BPF_MTAP(ifp, m_head); + ETHER_BPF_MTAP(ifp, m_head); } if (enq > 0) { diff --git a/sys/dev/netif/ti/if_ti.c b/sys/dev/netif/ti/if_ti.c index 5d1b65a77..0c5e74052 100644 --- a/sys/dev/netif/ti/if_ti.c +++ b/sys/dev/netif/ti/if_ti.c @@ -30,7 +30,7 @@ * THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/pci/if_ti.c,v 1.25.2.14 2002/02/15 04:20:20 silby Exp $ - * $DragonFly: src/sys/dev/netif/ti/if_ti.c,v 1.49 2008/03/10 10:47:57 sephe Exp $ + * $DragonFly: src/sys/dev/netif/ti/if_ti.c,v 1.50 2008/03/10 12:59:52 sephe Exp $ */ /* @@ -100,6 +100,7 @@ #include #include #include +#include #include @@ -1948,7 +1949,7 @@ ti_start(struct ifnet *ifp) ifq_dequeue(&ifp->if_snd, m_head); need_trans = 1; - BPF_MTAP(ifp, m_head); + ETHER_BPF_MTAP(ifp, m_head); } if (!need_trans) diff --git a/sys/dev/netif/txp/if_txp.c b/sys/dev/netif/txp/if_txp.c index cea33c0c1..f5a6b4b04 100644 --- a/sys/dev/netif/txp/if_txp.c +++ b/sys/dev/netif/txp/if_txp.c @@ -1,6 +1,6 @@ /* $OpenBSD: if_txp.c,v 1.48 2001/06/27 06:34:50 kjc Exp $ */ /* $FreeBSD: src/sys/dev/txp/if_txp.c,v 1.4.2.4 2001/12/14 19:50:43 jlemon Exp $ */ -/* $DragonFly: src/sys/dev/netif/txp/if_txp.c,v 1.46 2008/03/10 10:47:57 sephe Exp $ */ +/* $DragonFly: src/sys/dev/netif/txp/if_txp.c,v 1.47 2008/03/10 12:59:52 sephe Exp $ */ /* * Copyright (c) 2001 @@ -59,6 +59,7 @@ #include #include #include +#include #include #include @@ -1271,7 +1272,7 @@ txp_start(struct ifnet *ifp) ifp->if_timer = 5; ifq_dequeue(&ifp->if_snd, m); - BPF_MTAP(ifp, m); + ETHER_BPF_MTAP(ifp, m); WRITE_REG(sc, r->r_reg, TXP_IDX2OFFSET(prod)); } diff --git a/sys/dev/netif/vge/if_vge.c b/sys/dev/netif/vge/if_vge.c index 554eeadb1..742046821 100644 --- a/sys/dev/netif/vge/if_vge.c +++ b/sys/dev/netif/vge/if_vge.c @@ -30,7 +30,7 @@ * THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/dev/vge/if_vge.c,v 1.24 2006/02/14 12:44:56 glebius Exp $ - * $DragonFly: src/sys/dev/netif/vge/if_vge.c,v 1.6 2008/03/10 10:47:57 sephe Exp $ + * $DragonFly: src/sys/dev/netif/vge/if_vge.c,v 1.7 2008/03/10 12:59:52 sephe Exp $ */ /* @@ -104,6 +104,7 @@ #include #include #include +#include #include @@ -1706,7 +1707,7 @@ vge_start(struct ifnet *ifp) * If there's a BPF listener, bounce a copy of this frame * to him. */ - BPF_MTAP(ifp, m_head); + ETHER_BPF_MTAP(ifp, m_head); } if (idx == sc->vge_ldata.vge_tx_prodidx) diff --git a/sys/net/ethernet.h b/sys/net/ethernet.h index 2145322a8..3edef508a 100644 --- a/sys/net/ethernet.h +++ b/sys/net/ethernet.h @@ -2,7 +2,7 @@ * Fundamental constants relating to ethernet. * * $FreeBSD: src/sys/net/ethernet.h,v 1.12.2.8 2002/12/01 14:03:09 sobomax Exp $ - * $DragonFly: src/sys/net/ethernet.h,v 1.15 2007/10/13 10:50:34 sephe Exp $ + * $DragonFly: src/sys/net/ethernet.h,v 1.16 2008/03/10 12:59:52 sephe Exp $ * */ @@ -381,6 +381,25 @@ extern int (*vlan_input_tag_p)(struct mbuf *m, uint16_t t); /* XXX: unlock */ \ } while (0) +/* + * The ETHER_BPF_MTAP macro should be used by drivers which support hardware + * offload for VLAN tag processing. It will check the mbuf to see if it has + * M_VLANTAG set, and if it does, will pass the packet along to + * vlan_ether_ptap. This function will re-insert VLAN tags for the duration + * of the tap, so they show up properly for network analyzers. + */ +#define ETHER_BPF_MTAP(_ifp, _m) do { \ + if ((_ifp)->if_bpf) { \ + M_ASSERTPKTHDR((_m)); \ + if ((_m)->m_flags & M_VLANTAG) { \ + vlan_ether_ptap((_ifp)->if_bpf, (_m), \ + (_m)->m_pkthdr.ether_vlantag); \ + } else { \ + bpf_mtap((_ifp)->if_bpf, (_m)); \ + } \ + } \ +} while (0) + struct altq_pktattr; struct ifaltq; -- 2.11.4.GIT