Factor out the hand-crafting of mbufs from the interface files. Reviewed by
gimpy. XXX: I could have used bpf_mtap2 on some of the new functions, but I chose not to, because I just wanted to do what amounts to a code move.
This commit is contained in:
parent
396c380971
commit
0f7d471853
102
sys/net/bpf.c
102
sys/net/bpf.c
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: bpf.c,v 1.103 2004/08/19 18:33:24 christos Exp $ */
|
||||
/* $NetBSD: bpf.c,v 1.104 2004/08/19 20:58:23 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1990, 1991, 1993
|
||||
|
@ -39,7 +39,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: bpf.c,v 1.103 2004/08/19 18:33:24 christos Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: bpf.c,v 1.104 2004/08/19 20:58:23 christos Exp $");
|
||||
|
||||
#include "bpfilter.h"
|
||||
|
||||
|
@ -66,6 +66,7 @@ __KERNEL_RCSID(0, "$NetBSD: bpf.c,v 1.103 2004/08/19 18:33:24 christos Exp $");
|
|||
#include <sys/sysctl.h>
|
||||
|
||||
#include <net/if.h>
|
||||
#include <net/slip.h>
|
||||
|
||||
#include <net/bpf.h>
|
||||
#include <net/bpfdesc.h>
|
||||
|
@ -78,6 +79,8 @@ __KERNEL_RCSID(0, "$NetBSD: bpf.c,v 1.103 2004/08/19 18:33:24 christos Exp $");
|
|||
|
||||
#if defined(_KERNEL_OPT)
|
||||
#include "opt_bpf.h"
|
||||
#include "sl.h"
|
||||
#include "strip.h"
|
||||
#endif
|
||||
|
||||
#ifndef BPF_BUFSIZE
|
||||
|
@ -1286,6 +1289,101 @@ bpf_mtap(void *arg, struct mbuf *m)
|
|||
bpf_deliver(bp, cpfn, marg, pktlen, buflen, m->m_pkthdr.rcvif);
|
||||
}
|
||||
|
||||
/*
|
||||
* We need to prepend the address family as
|
||||
* a four byte field. Cons up a dummy header
|
||||
* to pacify bpf. This is safe because bpf
|
||||
* will only read from the mbuf (i.e., it won't
|
||||
* try to free it or keep a pointer a to it).
|
||||
*/
|
||||
void
|
||||
bpf_mtap_af(void *arg, u_int32_t af, struct mbuf *m)
|
||||
{
|
||||
struct mbuf m0;
|
||||
|
||||
m0.m_flags = 0;
|
||||
m0.m_next = m;
|
||||
m0.m_len = 4;
|
||||
m0.m_data = (char *)⁡
|
||||
|
||||
bpf_mtap(arg, &m0);
|
||||
}
|
||||
|
||||
void
|
||||
bpf_mtap_et(void *arg, u_int16_t et, struct mbuf *m)
|
||||
{
|
||||
struct mbuf m0;
|
||||
|
||||
m0.m_flags = 0;
|
||||
m0.m_next = m;
|
||||
m0.m_len = 14;
|
||||
m0.m_data = m0.m_dat;
|
||||
|
||||
((u_int32_t *)m0.m_data)[0] = 0;
|
||||
((u_int32_t *)m0.m_data)[1] = 0;
|
||||
((u_int32_t *)m0.m_data)[2] = 0;
|
||||
((u_int16_t *)m0.m_data)[6] = et;
|
||||
|
||||
bpf_mtap(arg, &m0);
|
||||
}
|
||||
|
||||
#if NSL > 0 || NSTRIP > 0
|
||||
/*
|
||||
* Put the SLIP pseudo-"link header" in place.
|
||||
* Note this M_PREPEND() should never fail,
|
||||
* swince we know we always have enough space
|
||||
* in the input buffer.
|
||||
*/
|
||||
void
|
||||
bpf_mtap_sl_in(void *arg, u_char *chdr, struct mbuf **m)
|
||||
{
|
||||
int s;
|
||||
u_char *hp;
|
||||
|
||||
M_PREPEND(*m, SLIP_HDRLEN, M_DONTWAIT);
|
||||
if (*m == NULL)
|
||||
return;
|
||||
|
||||
hp = mtod(*m, u_char *);
|
||||
hp[SLX_DIR] = SLIPDIR_IN;
|
||||
(void)memcpy(&hp[SLX_CHDR], chdr, CHDR_LEN);
|
||||
|
||||
s = splnet();
|
||||
bpf_mtap(arg, *m);
|
||||
splx(s);
|
||||
|
||||
m_adj(*m, SLIP_HDRLEN);
|
||||
}
|
||||
|
||||
/*
|
||||
* Put the SLIP pseudo-"link header" in
|
||||
* place. The compressed header is now
|
||||
* at the beginning of the mbuf.
|
||||
*/
|
||||
void
|
||||
bpf_mtap_sl_out(void *arg, u_char *chdr, struct mbuf *m)
|
||||
{
|
||||
struct mbuf m0;
|
||||
u_char *hp;
|
||||
int s;
|
||||
|
||||
m0.m_flags = 0;
|
||||
m0.m_next = m;
|
||||
m0.m_data = m0.m_dat;
|
||||
m0.m_len = SLIP_HDRLEN;
|
||||
|
||||
hp = mtod(&m0, u_char *);
|
||||
|
||||
hp[SLX_DIR] = SLIPDIR_OUT;
|
||||
(void)memcpy(&hp[SLX_CHDR], chdr, CHDR_LEN);
|
||||
|
||||
s = splnet();
|
||||
bpf_mtap(arg, &m0);
|
||||
splx(s);
|
||||
m_freem(m);
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Move the packet data from interface memory (pkt) into the
|
||||
* store buffer. Return 1 if it's time to wakeup a listener (buffer full),
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: bpf.h,v 1.40 2004/08/19 18:33:24 christos Exp $ */
|
||||
/* $NetBSD: bpf.h,v 1.41 2004/08/19 20:58:23 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1990, 1991, 1993
|
||||
|
@ -251,6 +251,10 @@ int bpf_validate(struct bpf_insn *, int);
|
|||
void bpf_tap(void *, u_char *, u_int);
|
||||
void bpf_mtap(void *, struct mbuf *);
|
||||
void bpf_mtap2(void *, void *, u_int, struct mbuf *);
|
||||
void bpf_mtap_af(void *, u_int32_t, struct mbuf *);
|
||||
void bpf_mtap_et(void *, u_int16_t, struct mbuf *);
|
||||
void bpf_mtap_sl_in(void *, u_char *, struct mbuf **);
|
||||
void bpf_mtap_sl_out(void *, u_char *, struct mbuf *);
|
||||
void bpfattach(struct ifnet *, u_int, u_int);
|
||||
void bpfattach2(struct ifnet *, u_int, u_int, void *);
|
||||
void bpfdetach(struct ifnet *);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: if_faith.c,v 1.27 2004/04/21 18:40:38 itojun Exp $ */
|
||||
/* $NetBSD: if_faith.c,v 1.28 2004/08/19 20:58:23 christos Exp $ */
|
||||
/* $KAME: if_faith.c,v 1.21 2001/02/20 07:59:26 itojun Exp $ */
|
||||
|
||||
/*
|
||||
|
@ -40,7 +40,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: if_faith.c,v 1.27 2004/04/21 18:40:38 itojun Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: if_faith.c,v 1.28 2004/08/19 20:58:23 christos Exp $");
|
||||
|
||||
#include "opt_inet.h"
|
||||
|
||||
|
@ -181,28 +181,8 @@ faithoutput(ifp, m, dst, rt)
|
|||
m->m_data += sizeof(int);
|
||||
}
|
||||
|
||||
if (ifp->if_bpf) {
|
||||
/*
|
||||
* We need to prepend the address family as
|
||||
* a four byte field. Cons up a faith header
|
||||
* to pacify bpf. This is safe because bpf
|
||||
* will only read from the mbuf (i.e., it won't
|
||||
* try to free it or keep a pointer a to it).
|
||||
*/
|
||||
struct mbuf m0;
|
||||
u_int32_t af = dst->sa_family;
|
||||
|
||||
m0.m_next = m;
|
||||
m0.m_len = 4;
|
||||
m0.m_data = (char *)⁡
|
||||
|
||||
#ifdef HAVE_OLD_BPF
|
||||
bpf_mtap(ifp, &m0);
|
||||
#else
|
||||
bpf_mtap(ifp->if_bpf, &m0);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
if (ifp->if_bpf)
|
||||
bpf_mtap_af(ifp->if_bpf, dst->sa_family, m);
|
||||
|
||||
if (rt && rt->rt_flags & (RTF_REJECT|RTF_BLACKHOLE)) {
|
||||
m_freem(m);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: if_gif.c,v 1.45 2004/04/21 18:40:38 itojun Exp $ */
|
||||
/* $NetBSD: if_gif.c,v 1.46 2004/08/19 20:58:24 christos Exp $ */
|
||||
/* $KAME: if_gif.c,v 1.76 2001/08/20 02:01:02 kjc Exp $ */
|
||||
|
||||
/*
|
||||
|
@ -31,7 +31,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: if_gif.c,v 1.45 2004/04/21 18:40:38 itojun Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: if_gif.c,v 1.46 2004/08/19 20:58:24 christos Exp $");
|
||||
|
||||
#include "opt_inet.h"
|
||||
#include "opt_iso.h"
|
||||
|
@ -399,13 +399,8 @@ gifintr(arg)
|
|||
}
|
||||
family = *mtod(m, int *);
|
||||
#if NBPFILTER > 0
|
||||
if (ifp->if_bpf) {
|
||||
#ifdef HAVE_OLD_BPF
|
||||
bpf_mtap(ifp, m);
|
||||
#else
|
||||
if (ifp->if_bpf)
|
||||
bpf_mtap(ifp->if_bpf, m);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
m_adj(m, sizeof(int));
|
||||
|
||||
|
@ -456,27 +451,8 @@ gif_input(m, af, ifp)
|
|||
m->m_pkthdr.rcvif = ifp;
|
||||
|
||||
#if NBPFILTER > 0
|
||||
if (ifp->if_bpf) {
|
||||
/*
|
||||
* We need to prepend the address family as
|
||||
* a four byte field. Cons up a dummy header
|
||||
* to pacify bpf. This is safe because bpf
|
||||
* will only read from the mbuf (i.e., it won't
|
||||
* try to free it or keep a pointer a to it).
|
||||
*/
|
||||
struct mbuf m0;
|
||||
u_int32_t af1 = af;
|
||||
|
||||
m0.m_next = m;
|
||||
m0.m_len = 4;
|
||||
m0.m_data = (char *)&af1;
|
||||
|
||||
#ifdef HAVE_OLD_BPF
|
||||
bpf_mtap(ifp, &m0);
|
||||
#else
|
||||
bpf_mtap(ifp->if_bpf, &m0);
|
||||
#endif
|
||||
}
|
||||
if (ifp->if_bpf)
|
||||
bpf_mtap_af(ifp->if_bpf, af, m);
|
||||
#endif /*NBPFILTER > 0*/
|
||||
|
||||
/*
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: if_gre.c,v 1.51 2004/05/13 11:29:40 tron Exp $ */
|
||||
/* $NetBSD: if_gre.c,v 1.52 2004/08/19 20:58:24 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1998 The NetBSD Foundation, Inc.
|
||||
|
@ -46,7 +46,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: if_gre.c,v 1.51 2004/05/13 11:29:40 tron Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: if_gre.c,v 1.52 2004/08/19 20:58:24 christos Exp $");
|
||||
|
||||
#include "opt_inet.h"
|
||||
#include "opt_ns.h"
|
||||
|
@ -203,17 +203,8 @@ gre_output(struct ifnet *ifp, struct mbuf *m, struct sockaddr *dst,
|
|||
ip = NULL;
|
||||
|
||||
#if NBPFILTER >0
|
||||
if (ifp->if_bpf) {
|
||||
/* see comment of other if_foo.c files */
|
||||
struct mbuf m0;
|
||||
u_int32_t af = dst->sa_family;
|
||||
|
||||
m0.m_next = m;
|
||||
m0.m_len = 4;
|
||||
m0.m_data = (char *)⁡
|
||||
|
||||
bpf_mtap(ifp->if_bpf, &m0);
|
||||
}
|
||||
if (ifp->if_bpf)
|
||||
bpf_mtap_af(ifp->if_bpf, dst->sa_family, m);
|
||||
#endif
|
||||
|
||||
m->m_flags &= ~(M_BCAST|M_MCAST);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: if_ieee1394subr.c,v 1.25 2003/10/26 19:09:44 christos Exp $ */
|
||||
/* $NetBSD: if_ieee1394subr.c,v 1.26 2004/08/19 20:58:24 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2000 The NetBSD Foundation, Inc.
|
||||
|
@ -37,7 +37,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: if_ieee1394subr.c,v 1.25 2003/10/26 19:09:44 christos Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: if_ieee1394subr.c,v 1.26 2004/08/19 20:58:24 christos Exp $");
|
||||
|
||||
#include "opt_inet.h"
|
||||
#include "bpfilter.h"
|
||||
|
@ -186,19 +186,8 @@ ieee1394_output(struct ifnet *ifp, struct mbuf *m0, struct sockaddr *dst,
|
|||
looutput(ifp, mcopy, dst, rt);
|
||||
#if NBPFILTER > 0
|
||||
/* XXX: emulate DLT_EN10MB */
|
||||
if (ifp->if_bpf) {
|
||||
struct mbuf mb;
|
||||
|
||||
mb.m_flags = 0;
|
||||
mb.m_next = m0;
|
||||
mb.m_len = 14;
|
||||
mb.m_data = mb.m_dat;
|
||||
((u_int32_t *)mb.m_data)[0] = 0;
|
||||
((u_int32_t *)mb.m_data)[1] = 0;
|
||||
((u_int32_t *)mb.m_data)[2] = 0;
|
||||
((u_int16_t *)mb.m_data)[6] = etype;
|
||||
bpf_mtap(ifp->if_bpf, &mb);
|
||||
}
|
||||
if (ifp->if_bpf)
|
||||
bpf_mtap_et(ifp->if_bpf, etype, m);
|
||||
#endif
|
||||
myaddr = (struct ieee1394_hwaddr *)LLADDR(ifp->if_sadl);
|
||||
if ((ifp->if_flags & IFF_SIMPLEX) &&
|
||||
|
@ -367,19 +356,8 @@ ieee1394_input(struct ifnet *ifp, struct mbuf *m)
|
|||
m_adj(m, sizeof(*ih) + sizeof(*iuh));
|
||||
#if NBPFILTER > 0
|
||||
/* XXX: emulate DLT_EN10MB */
|
||||
if (ifp->if_bpf) {
|
||||
struct mbuf mb;
|
||||
|
||||
mb.m_flags = 0;
|
||||
mb.m_next = m;
|
||||
mb.m_len = 14;
|
||||
mb.m_data = mb.m_dat;
|
||||
((u_int32_t *)mb.m_data)[0] = 0;
|
||||
((u_int32_t *)mb.m_data)[1] = 0;
|
||||
((u_int32_t *)mb.m_data)[2] = 0;
|
||||
((u_int16_t *)mb.m_data)[6] = iuh->iuh_etype;
|
||||
bpf_mtap(ifp->if_bpf, &mb);
|
||||
}
|
||||
if (ifp->if_bpf)
|
||||
bpf_mtap_et(ifp->if_bpf, iuh->iuh_etype, m);
|
||||
#endif
|
||||
|
||||
switch (etype) {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: if_loop.c,v 1.50 2004/04/21 18:40:39 itojun Exp $ */
|
||||
/* $NetBSD: if_loop.c,v 1.51 2004/08/19 20:58:24 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
|
||||
|
@ -65,7 +65,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: if_loop.c,v 1.50 2004/04/21 18:40:39 itojun Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: if_loop.c,v 1.51 2004/08/19 20:58:24 christos Exp $");
|
||||
|
||||
#include "opt_inet.h"
|
||||
#include "opt_atalk.h"
|
||||
|
@ -200,24 +200,8 @@ looutput(ifp, m, dst, rt)
|
|||
if ((m->m_flags & M_PKTHDR) == 0)
|
||||
panic("looutput: no header mbuf");
|
||||
#if NBPFILTER > 0
|
||||
if (ifp->if_bpf && (ifp->if_flags & IFF_LOOPBACK)) {
|
||||
/*
|
||||
* We need to prepend the address family as
|
||||
* a four byte field. Cons up a dummy header
|
||||
* to pacify bpf. This is safe because bpf
|
||||
* will only read from the mbuf (i.e., it won't
|
||||
* try to free it or keep a pointer to it).
|
||||
*/
|
||||
struct mbuf m0;
|
||||
u_int32_t af = dst->sa_family;
|
||||
|
||||
m0.m_flags = 0;
|
||||
m0.m_next = m;
|
||||
m0.m_len = 4;
|
||||
m0.m_data = (char *)⁡
|
||||
|
||||
bpf_mtap(ifp->if_bpf, &m0);
|
||||
}
|
||||
if (ifp->if_bpf && (ifp->if_flags & IFF_LOOPBACK))
|
||||
bpf_mtap_af(ifp->if_bpf, dst->sa_family, m);
|
||||
#endif
|
||||
m->m_pkthdr.rcvif = ifp;
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: if_sl.c,v 1.85 2004/04/21 18:40:40 itojun Exp $ */
|
||||
/* $NetBSD: if_sl.c,v 1.86 2004/08/19 20:58:24 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1987, 1989, 1992, 1993
|
||||
|
@ -60,7 +60,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: if_sl.c,v 1.85 2004/04/21 18:40:40 itojun Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: if_sl.c,v 1.86 2004/08/19 20:58:24 christos Exp $");
|
||||
|
||||
#include "sl.h"
|
||||
#if NSL > 0
|
||||
|
@ -766,31 +766,9 @@ slintr(void *arg)
|
|||
&sc->sc_comp, 1);
|
||||
}
|
||||
#if NBPFILTER > 0
|
||||
if (sc->sc_if.if_bpf && bpf_m != NULL) {
|
||||
/*
|
||||
* Put the SLIP pseudo-"link header" in
|
||||
* place. The compressed header is now
|
||||
* at the beginning of the mbuf.
|
||||
*/
|
||||
struct mbuf n;
|
||||
u_char *hp;
|
||||
|
||||
n.m_flags = 0;
|
||||
n.m_next = bpf_m;
|
||||
n.m_data = n.m_dat;
|
||||
n.m_len = SLIP_HDRLEN;
|
||||
|
||||
hp = mtod(&n, u_char *);
|
||||
|
||||
hp[SLX_DIR] = SLIPDIR_OUT;
|
||||
memcpy(&hp[SLX_CHDR], mtod(m, caddr_t),
|
||||
CHDR_LEN);
|
||||
|
||||
s = splnet();
|
||||
bpf_mtap(sc->sc_if.if_bpf, &n);
|
||||
splx(s);
|
||||
m_freem(bpf_m);
|
||||
}
|
||||
if (sc->sc_if.if_bpf && bpf_m != NULL)
|
||||
bpf_mtap_sl_out(sc->sc_if.if_bpf, mtod(m, u_char *),
|
||||
bpf_m);
|
||||
#endif
|
||||
sc->sc_lastpacket = time;
|
||||
|
||||
|
@ -951,27 +929,9 @@ slintr(void *arg)
|
|||
m->m_pkthdr.len = m->m_len = len;
|
||||
#if NBPFILTER > 0
|
||||
if (sc->sc_if.if_bpf) {
|
||||
/*
|
||||
* Put the SLIP pseudo-"link header" in place.
|
||||
* Note this M_PREPEND() should bever fail,
|
||||
* since we know we always have enough space
|
||||
* in the input buffer.
|
||||
*/
|
||||
u_char *hp;
|
||||
|
||||
M_PREPEND(m, SLIP_HDRLEN, M_DONTWAIT);
|
||||
bpf_mtap_sl_in(sc->sc_if.if_bpf, chdr, &m);
|
||||
if (m == NULL)
|
||||
continue;
|
||||
|
||||
hp = mtod(m, u_char *);
|
||||
hp[SLX_DIR] = SLIPDIR_IN;
|
||||
memcpy(&hp[SLX_CHDR], chdr, CHDR_LEN);
|
||||
|
||||
s = splnet();
|
||||
bpf_mtap(sc->sc_if.if_bpf, m);
|
||||
splx(s);
|
||||
|
||||
m_adj(m, SLIP_HDRLEN);
|
||||
}
|
||||
#endif /* NBPFILTER > 0 */
|
||||
/*
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: if_stf.c,v 1.39 2004/04/26 01:41:15 matt Exp $ */
|
||||
/* $NetBSD: if_stf.c,v 1.40 2004/08/19 20:58:24 christos Exp $ */
|
||||
/* $KAME: if_stf.c,v 1.62 2001/06/07 22:32:16 itojun Exp $ */
|
||||
|
||||
/*
|
||||
|
@ -75,7 +75,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: if_stf.c,v 1.39 2004/04/26 01:41:15 matt Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: if_stf.c,v 1.40 2004/08/19 20:58:24 christos Exp $");
|
||||
|
||||
#include "opt_inet.h"
|
||||
|
||||
|
@ -397,28 +397,8 @@ stf_output(ifp, m, dst, rt)
|
|||
}
|
||||
|
||||
#if NBPFILTER > 0
|
||||
if (ifp->if_bpf) {
|
||||
/*
|
||||
* We need to prepend the address family as
|
||||
* a four byte field. Cons up a dummy header
|
||||
* to pacify bpf. This is safe because bpf
|
||||
* will only read from the mbuf (i.e., it won't
|
||||
* try to free it or keep a pointer a to it).
|
||||
*/
|
||||
struct mbuf m0;
|
||||
u_int32_t af = AF_INET6;
|
||||
|
||||
m0.m_flags = 0;
|
||||
m0.m_next = m;
|
||||
m0.m_len = 4;
|
||||
m0.m_data = (char *)⁡
|
||||
|
||||
#ifdef HAVE_OLD_BPF
|
||||
bpf_mtap(ifp, &m0);
|
||||
#else
|
||||
bpf_mtap(ifp->if_bpf, &m0);
|
||||
#endif
|
||||
}
|
||||
if (ifp->if_bpf)
|
||||
bpf_mtap_af(ifp->if_bpf, AF_INET6, m);
|
||||
#endif /*NBPFILTER > 0*/
|
||||
|
||||
M_PREPEND(m, sizeof(struct ip), M_DONTWAIT);
|
||||
|
@ -673,28 +653,8 @@ in_stf_input(struct mbuf *m, ...)
|
|||
m->m_pkthdr.rcvif = ifp;
|
||||
|
||||
#if NBPFILTER > 0
|
||||
if (ifp->if_bpf) {
|
||||
/*
|
||||
* We need to prepend the address family as
|
||||
* a four byte field. Cons up a dummy header
|
||||
* to pacify bpf. This is safe because bpf
|
||||
* will only read from the mbuf (i.e., it won't
|
||||
* try to free it or keep a pointer a to it).
|
||||
*/
|
||||
struct mbuf m0;
|
||||
u_int32_t af = AF_INET6;
|
||||
|
||||
m0.m_flags = 0;
|
||||
m0.m_next = m;
|
||||
m0.m_len = 4;
|
||||
m0.m_data = (char *)⁡
|
||||
|
||||
#ifdef HAVE_OLD_BPF
|
||||
bpf_mtap(ifp, &m0);
|
||||
#else
|
||||
bpf_mtap(ifp->if_bpf, &m0);
|
||||
#endif
|
||||
}
|
||||
if (ifp->if_bpf)
|
||||
bpf_mtap_af(ifp->if_bpf, AF_INET6, m);
|
||||
#endif /*NBPFILTER > 0*/
|
||||
|
||||
/*
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: if_strip.c,v 1.52 2004/04/21 18:40:41 itojun Exp $ */
|
||||
/* $NetBSD: if_strip.c,v 1.53 2004/08/19 20:58:24 christos Exp $ */
|
||||
/* from: NetBSD: if_sl.c,v 1.38 1996/02/13 22:00:23 christos Exp $ */
|
||||
|
||||
/*
|
||||
|
@ -87,7 +87,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: if_strip.c,v 1.52 2004/04/21 18:40:41 itojun Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: if_strip.c,v 1.53 2004/08/19 20:58:24 christos Exp $");
|
||||
|
||||
#include "strip.h"
|
||||
|
||||
|
@ -1157,31 +1157,9 @@ stripintr(void *arg)
|
|||
&sc->sc_comp, 1);
|
||||
}
|
||||
#if NBPFILTER > 0
|
||||
if (sc->sc_if.if_bpf && bpf_m != NULL) {
|
||||
/*
|
||||
* Put the SLIP pseudo-"link header" in
|
||||
* place. The compressed header is now
|
||||
* at the beginning of the mbuf.
|
||||
*/
|
||||
struct mbuf n;
|
||||
u_char *hp;
|
||||
|
||||
n.m_flags = 0;
|
||||
n.m_next = bpf_m;
|
||||
n.m_data = n.m_dat;
|
||||
n.m_len = SLIP_HDRLEN;
|
||||
|
||||
hp = mtod(&n, u_char *);
|
||||
|
||||
hp[SLX_DIR] = SLIPDIR_OUT;
|
||||
memcpy(&hp[SLX_CHDR], mtod(m, caddr_t),
|
||||
CHDR_LEN);
|
||||
|
||||
s = splnet();
|
||||
bpf_mtap(sc->sc_if.if_bpf, &n);
|
||||
splx(s);
|
||||
m_freem(bpf_m);
|
||||
}
|
||||
if (sc->sc_if.if_bpf && bpf_m != NULL)
|
||||
bpf_mtap_sl_out(sc->sc_if.if_bpf, mtod(m, u_char *),
|
||||
bpf_m);
|
||||
#endif
|
||||
sc->sc_lastpacket = time;
|
||||
|
||||
|
@ -1260,27 +1238,9 @@ stripintr(void *arg)
|
|||
m->m_pkthdr.len = m->m_len = len;
|
||||
#if NPBFILTER > 0
|
||||
if (sc->sc_if.if_bpf) {
|
||||
/*
|
||||
* Put the SLIP pseudo-"link header" in place.
|
||||
* Note this M_PREPEND() should never fail,
|
||||
* swince we know we always have enough space
|
||||
* in the input buffer.
|
||||
*/
|
||||
u_char *hp;
|
||||
|
||||
M_PREPEND(m, SLIP_HDRLEN, M_DONTWAIT);
|
||||
bpf_mtap_sl_in(sc->sc_if.if_bpf, chdr, &m);
|
||||
if (m == NULL)
|
||||
continue;
|
||||
|
||||
hp = mtod(m, u_char *);
|
||||
hp[SLX_DIR] = SLIPDIR_IN;
|
||||
memcpy(&hp[SLX_CHDR], chdr, CHDR_LEN);
|
||||
|
||||
s = splnet();
|
||||
bpf_mtap(sc->sc_if.if_bpf, m);
|
||||
splx(s);
|
||||
|
||||
m_adj(m, SLIP_HDRLEN);
|
||||
}
|
||||
#endif
|
||||
/*
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: if_tun.c,v 1.71 2004/06/06 04:36:29 dyoung Exp $ */
|
||||
/* $NetBSD: if_tun.c,v 1.72 2004/08/19 20:58:24 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1988, Julian Onions <jpo@cs.nott.ac.uk>
|
||||
|
@ -15,7 +15,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: if_tun.c,v 1.71 2004/06/06 04:36:29 dyoung Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: if_tun.c,v 1.72 2004/08/19 20:58:24 christos Exp $");
|
||||
|
||||
#include "tun.h"
|
||||
|
||||
|
@ -520,16 +520,8 @@ tun_output(ifp, m0, dst, rt)
|
|||
IFQ_CLASSIFY(&ifp->if_snd, m0, dst->sa_family, &pktattr);
|
||||
|
||||
#if NBPFILTER > 0
|
||||
if (ifp->if_bpf) {
|
||||
/*
|
||||
* We need to prepend the address family as
|
||||
* a four-byte field. Note that dst->sa_family
|
||||
* is not always a four-byte field.
|
||||
*/
|
||||
u_int32_t af = dst->sa_family;
|
||||
|
||||
bpf_mtap2(ifp->if_bpf, &af, sizeof(af), m0);
|
||||
}
|
||||
if (ifp->if_bpf)
|
||||
bpf_mtap_af(ifp->if_bpf, dst->sa_family, m0);
|
||||
#endif
|
||||
|
||||
switch(dst->sa_family) {
|
||||
|
@ -884,24 +876,8 @@ tunwrite(dev, uio, ioflag)
|
|||
top->m_pkthdr.rcvif = ifp;
|
||||
|
||||
#if NBPFILTER > 0
|
||||
if (ifp->if_bpf) {
|
||||
/*
|
||||
* We need to prepend the address family as
|
||||
* a four byte field. Cons up a dummy header
|
||||
* to pacify bpf. This is safe because bpf
|
||||
* will only read from the mbuf (i.e., it won't
|
||||
* try to free it or keep a pointer to it).
|
||||
*/
|
||||
struct mbuf m;
|
||||
u_int32_t af = AF_INET;
|
||||
|
||||
m.m_flags = 0;
|
||||
m.m_next = top;
|
||||
m.m_len = sizeof(af);
|
||||
m.m_data = (char *)⁡
|
||||
|
||||
bpf_mtap(ifp->if_bpf, &m);
|
||||
}
|
||||
if (ifp->if_bpf)
|
||||
bpf_mtap_af(ifp->if_bpf, AF_INET, top);
|
||||
#endif
|
||||
|
||||
s = splnet();
|
||||
|
|
Loading…
Reference in New Issue