Subject: BPF change to qe driver
To: None <port-vax@NetBSD.ORG>
From: Ken Wellsch <kcwellsc@math.uwaterloo.ca>
List: port-vax
Date: 03/17/1997 11:14:27
Although this is a year out of date, I'm sure someone can merge it into
if_qe.c or whatever it may be called these days.  This trivial change
added BPF listen-only support to the QE driver -- I've net booted both
Sun3's and Sun4's with this change to a NetBSD/1.1B uVAX-II.  Heck, even
tcpdump works although plenty of packets get dropped given the VAXen
processing speed, if the network has much activity.  Works nicely though
to view and debug a netboot.  (until tftpd cuts in with tons of sent pkts)

-- Ken Wellsch

========================================
--- if_qe.c	1996/04/17 21:26:59	1.1
+++ if_qe.c	1996/04/18 00:50:17
@@ -134,6 +134,8 @@
  * ---------------------------------------------------------------------
  */
 
+#include "bpfilter.h"
+
 /*
  * Digital Q-BUS to NI Adapter
  */
@@ -154,6 +156,11 @@
 #include <net/netisr.h>
 #include <net/route.h>
 
+#if NBPFILTER > 0
+#include <net/bpf.h>
+#include <net/bpfdesc.h>
+#endif
+
 #ifdef INET
 #include <netinet/in.h>
 #include <netinet/in_systm.h>
@@ -396,6 +403,9 @@
 	sc->qe_uba.iff_flags = UBA_CANTWAIT;
 	if_attach(ifp);
 	ether_ifattach(ifp);
+#if NBPFILTER > 0
+	bpfattach(&ifp->if_bpf, ifp, DLT_EN10MB, sizeof(struct ether_header));
+#endif
 }
 
 /*
@@ -928,6 +938,26 @@
 *(((u_long *)m->m_data)+3)
 ); }
 #endif
+
+#if NBPFILTER > 0
+	/*
+	 * Check for a BPF filter; if so, hand it up.
+	 * Note that we have to stick an extra mbuf up front, because
+	 * bpf_mtap expects to have the ether header at the front.
+	 * It doesn't matter that this results in an ill-formatted mbuf chain,
+	 * since BPF just looks at the data.  (It doesn't try to free the mbuf,
+	 * tho' it will make a copy for tcpdump.)
+	 */
+	if (sc->qe_if.if_bpf) {
+		struct mbuf m0;
+		m0.m_len = sizeof (struct ether_header);
+		m0.m_data = (caddr_t)eh;
+		m0.m_next = m;
+
+		/* Pass it up */
+		bpf_mtap(sc->qe_if.if_bpf, &m0);
+	}
+#endif	/* NBPFILTER > 0 */
 
 	if (m)
 		ether_input((struct ifnet *)&sc->qe_if, eh, m);