Generate correct DLT_NULL headers before passing packets to bpf.

Do not modify m_len before passing mbuf chains to bpf.
Don't forget to pass packets to bpf when running in Crynwr mode (LINK0).

Partially based on a patch by Bill Fenner <fenner@freebsd.org>.

PR:             bin/7241
This commit is contained in:
Dag-Erling Smørgrav 1999-02-08 14:12:38 +00:00
parent 9539cd4d92
commit 8f84257ed7
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=43773

View File

@ -24,7 +24,7 @@
* SUCH DAMAGE.
*
* From Id: lpt.c,v 1.55.2.1 1996/11/12 09:08:38 phk Exp
* $Id: if_plip.c,v 1.8 1999/01/23 17:07:49 nsouch Exp $
* $Id: if_plip.c,v 1.9 1999/01/30 15:35:39 nsouch Exp $
*/
/*
@ -256,7 +256,7 @@ lpattach (struct ppb_device *dev)
if_attach(ifp);
#if NBPFILTER > 0
bpfattach(ifp, DLT_NULL, LPIPHDRLEN);
bpfattach(ifp, DLT_NULL, sizeof(u_int32_t));
#endif
return (1);
@ -445,6 +445,26 @@ clpinbyte (int spin, struct ppb_device *dev)
return (ctrecvl[cl] | ctrecvh[c]);
}
#if NBPFILTER > 0
static void
lptap(struct ifnet *ifp, struct mbuf *m)
{
/*
* Send a packet through 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).
*/
u_int32_t af = AF_INET;
struct mbuf m0;
m0.m_next = m;
m0.m_len = sizeof(u_int32_t);
m0.m_data = (char *)&af;
bpf_mtap(ifp, &m0);
}
#endif
static void
lpintr (int unit)
{
@ -504,6 +524,10 @@ lpintr (int unit)
sc->sc_if.if_ibytes += len;
top = m_devget(sc->sc_ifbuf + CLPIPHDRLEN, len, 0, &sc->sc_if, 0);
if (top) {
#if NBPFILTER > 0
if (sc->sc_if.if_bpf)
lptap(&sc->sc_if, top);
#endif
IF_ENQUEUE(&ipintrq, top);
schednetisr(NETISR_IP);
}
@ -548,18 +572,17 @@ lpintr (int unit)
IF_DROP(&ipintrq);
goto done;
}
#if NBPFILTER > 0
if (sc->sc_if.if_bpf) {
bpf_tap(&sc->sc_if, sc->sc_ifbuf, len);
}
#endif
len -= LPIPHDRLEN;
sc->sc_if.if_ipackets++;
sc->sc_if.if_ibytes += len;
top = m_devget(sc->sc_ifbuf + LPIPHDRLEN, len, 0, &sc->sc_if, 0);
if (top) {
IF_ENQUEUE(&ipintrq, top);
schednetisr(NETISR_IP);
#if NBPFILTER > 0
if (sc->sc_if.if_bpf)
lptap(&sc->sc_if, top);
#endif
IF_ENQUEUE(&ipintrq, top);
schednetisr(NETISR_IP);
}
}
goto done;
@ -610,8 +633,7 @@ lpoutput (struct ifnet *ifp, struct mbuf *m,
u_char *cp = "\0\0";
u_char chksum = 0;
int count = 0;
int i;
int spin;
int i, len, spin;
/* We need a sensible value if we abort */
cp++;
@ -668,7 +690,8 @@ lpoutput (struct ifnet *ifp, struct mbuf *m,
mm = m;
do {
cp = mtod(mm, u_char *);
while (mm->m_len--) {
len = mm->m_len;
while (len--) {
chksum += *cp;
if (clpoutbyte(*cp++, LPMAXSPIN2, &sc->lp_dev))
goto nend;
@ -691,6 +714,10 @@ lpoutput (struct ifnet *ifp, struct mbuf *m,
} else {
ifp->if_opackets++;
ifp->if_obytes += m->m_pkthdr.len;
#if NBPFILTER > 0
if (ifp->if_bpf)
lptap(ifp, m);
#endif
}
m_freem(m);
@ -716,7 +743,8 @@ lpoutput (struct ifnet *ifp, struct mbuf *m,
mm = m;
do {
cp = mtod(mm,u_char *);
while (mm->m_len--)
len = mm->m_len;
while (len--)
if (lpoutbyte(*cp++, LPMAXSPIN2, &sc->lp_dev))
goto end;
} while ((mm = mm->m_next));
@ -734,23 +762,8 @@ lpoutput (struct ifnet *ifp, struct mbuf *m,
ifp->if_opackets++;
ifp->if_obytes += m->m_pkthdr.len;
#if NBPFILTER > 0
if (ifp->if_bpf) {
/*
* We need to prepend the packet type as
* a two 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_short hdr = 0x800;
m0.m_next = m;
m0.m_len = 2;
m0.m_data = (char *)&hdr;
bpf_mtap(ifp, &m0);
}
if (ifp->if_bpf)
lptap(ifp, m);
#endif
}