From owner-freebsd-hackers Thu Mar 7 15:30: 6 2002 Delivered-To: freebsd-hackers@freebsd.org Received: from gw.wa3dbj.vix.com (dbj-pa.pp.vix.com [204.152.184.150]) by hub.freebsd.org (Postfix) with ESMTP id 0964237B41B for ; Thu, 7 Mar 2002 15:29:49 -0800 (PST) Received: from gw.wa3dbj.vix.com (boggs@[127.0.0.1]) by gw.wa3dbj.vix.com (8.9.3/8.9.3) with ESMTP id PAA15449 for ; Thu, 7 Mar 2002 15:29:44 -0800 (PST) Message-Id: <200203072329.PAA15449@gw.wa3dbj.vix.com> X-Mailer: exmh version 2.1.0 09/18/1999 To: FreeBSD-hackers@freebsd.org Subject: Berkeley Packet Filter question Date: Thu, 07 Mar 2002 15:29:44 -0800 From: David Boggs Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG [reposted from FreeBSD-questions] I'm writing a network device driver. I'm using FreeBSD 4.4-RELEASE. I can't get BPF to work; it dereferences a nil pointer. Attached below is some BPF code. As I read it, bpfattach() is passed an ifp (struct ifnet *). It mallocs a 'bpf_if' (1) and installs the ifp in it (2). Then it uses this pointer to ZERO a pointer in the ifp named if_bpf (3) (presumably a back-pointer). Later, bpf_mtap() is called, and it picks up the back-pointer to the if_bpf (4) (which has been ZEROed) and dereferences it (5), causing a type 12 trap. Grepping through other device drivers, I note that most of them don't call bpfattach(), but two or three do. Those that do, are NOT passing a struct ifnet * as the first argument. What's going on here? My driver is for a synchronous serial line. The proper place for snooping packets is in sppp, rather than in each individual driver. Why doesn't sppp call bpf? Why should I ever have to deal with this? /David Boggs void bpfattach(ifp, dlt, hdrlen) struct ifnet *ifp; u_int dlt, hdrlen; { struct bpf_if *bp; (1) bp = (struct bpf_if *)malloc(sizeof(*bp), M_BPF, M_DONTWAIT); (2) bp->bif_ifp = ifp; ..... (3) bp->bif_ifp->if_bpf = 0; /* this seems wrong */ ..... } void bpf_mtap(ifp, m) struct ifnet *ifp; struct mbuf *m; { (4) struct bpf_if *bp = ifp->if_bpf; ..... (5) for (d = bp->bif_dlist; d != 0; d = d->bd_next) { ..... } ------- End of Forwarded Message To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message