Currently, drivers that support hardware offload of VLAN tag

processing are forced to toggle this functionality when the card
is put in and out of promiscuous mode.  The main reason for this
is because the hardware strips the VLAN tag, making it impossible
for the tag information to show up in network diagnostic tools like
tcpdump(1).

This change introduces ether_vlan_mtap(), which is called if the
mbuf has M_VLANTAG set.  VLAN information is extracted from the
mbuf and inserted into a stack allocated ether vlan header which
is then inserted through the bpf machinery via bpf_mtap2(). The
original mbuf's data pointer and lengths are temporarily adjusted
to eliminate the original Ethernet header for the duration of the
tap operation. This should have no long term effects on the mbuf.

Also, define a new macro, ETHER_BPF_MTAP which should be used
by drivers which support hardware offload of VLAN tag processing.

The fixes for the relevant drivers will follow shortly.

Discussed with:		rwatson, andre, jhb (and others)
Much feedback from:	sam, ru
MFC after:	1 month [1]

[1] The version that is eventually MFCed will be somewhat
    different then this, as there has been significant work
    done to the VLAN code in HEAD.
This commit is contained in:
Christian S.J. Peron 2006-11-18 23:17:22 +00:00
parent a602be7b07
commit 52f1277eea
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=164396
2 changed files with 59 additions and 0 deletions

View File

@ -343,6 +343,22 @@ struct ether_addr {
#define ETHERMTU (ETHER_MAX_LEN-ETHER_HDR_LEN-ETHER_CRC_LEN)
#define ETHERMIN (ETHER_MIN_LEN-ETHER_HDR_LEN-ETHER_CRC_LEN)
#define ETHERMTU_JUMBO (ETHER_MAX_LEN_JUMBO - ETHER_HDR_LEN - ETHER_CRC_LEN)
/*
* 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
* ether_vlan_mtap. This function will re-insert VLAN tags for the duration
* of the tap, show they show up properly for network analyzers.
*/
#define ETHER_BPF_MTAP(_ifp, _m) do { \
if (bpf_peers_present((_ifp)->if_bpf)) { \
M_ASSERTVALID(_m); \
if (((_m)->m_flags & M_VLANTAG) != 0) \
ether_vlan_mtap((_ifp)->if_bpf, (_m), NULL, 0); \
else \
bpf_mtap((_ifp)->if_bpf, (_m)); \
} \
} while (0)
#ifdef _KERNEL
@ -350,6 +366,7 @@ struct ifnet;
struct mbuf;
struct rtentry;
struct sockaddr;
struct bpf_if;
extern uint32_t ether_crc32_le(const uint8_t *, size_t);
extern uint32_t ether_crc32_be(const uint8_t *, size_t);
@ -361,6 +378,8 @@ extern int ether_output(struct ifnet *,
struct mbuf *, struct sockaddr *, struct rtentry *);
extern int ether_output_frame(struct ifnet *, struct mbuf *);
extern char *ether_sprintf(const u_int8_t *);
void ether_vlan_mtap(struct bpf_if *, struct mbuf *,
void *, u_int);
#else /* _KERNEL */

View File

@ -1185,5 +1185,45 @@ static moduledata_t ether_mod = {
0
};
void
ether_vlan_mtap(struct bpf_if *bp, struct mbuf *m, void *data, u_int dlen)
{
struct ether_vlan_header vlan;
struct mbuf mv, mb;
KASSERT((m->m_flags & M_VLANTAG) != 0,
("%s: vlan information not present", __func__));
KASSERT(m->m_len >= sizeof(struct ether_header),
("%s: mbuf not large enough for header", __func__));
bcopy(mtod(m, char *), &vlan, sizeof(struct ether_header));
vlan.evl_proto = vlan.evl_encap_proto;
vlan.evl_encap_proto = htons(ETHERTYPE_VLAN);
vlan.evl_tag = htons(m->m_pkthdr.ether_vtag);
m->m_len -= sizeof(struct ether_header);
m->m_data += sizeof(struct ether_header);
/*
* If a data link has been supplied by the caller, then we will need to
* re-create a stack allocated mbuf chain with the following structure:
*
* (1) mbuf #1 will contain the supplied data link
* (2) mbuf #2 will contain the vlan header
* (3) mbuf #3 will contain the original mbuf's packet data
*
* Otherwise, submit the packet and vlan header via bpf_mtap2().
*/
if (data != NULL) {
mv.m_next = m;
mv.m_data = (caddr_t)&vlan;
mv.m_len = sizeof(vlan);
mb.m_next = &mv;
mb.m_data = data;
mb.m_len = dlen;
bpf_mtap(bp, &mb);
} else
bpf_mtap2(bp, &vlan, sizeof(vlan), m);
m->m_len += sizeof(struct ether_header);
m->m_data -= sizeof(struct ether_header);
}
DECLARE_MODULE(ether, ether_mod, SI_SUB_INIT_IF, SI_ORDER_ANY);
MODULE_VERSION(ether, 1);