Skip site navigation (1)Skip section navigation (2)
Date:      08 Feb 1999 04:53:19 +0100
From:      Dag-Erling Smorgrav <des@flood.ping.uio.no>
To:        Dag-Erling Smorgrav <des@flood.ping.uio.no>
Cc:        Bill Fenner <fenner@parc.xerox.com>, hackers@FreeBSD.ORG, nsouch@FreeBSD.ORG, wpaul@FreeBSD.ORG, jkh@FreeBSD.ORG, peter.jeremy@auss2.alcatel.com.au
Subject:   Re: Regarding tcpdump and plip
Message-ID:  <xzpsoch1rgw.fsf@flood.ping.uio.no>
In-Reply-To: Dag-Erling Smorgrav's message of "08 Feb 1999 02:40:39 %2B0100"
References:  <99Feb7.160220pst.177534@crevenia.parc.xerox.com> <xzp90e9brl4.fsf@flood.ping.uio.no>

next in thread | previous in thread | raw e-mail | index | archive | help
Dag-Erling Smorgrav <des@flood.ping.uio.no> writes:
> The first of the two attached patches (hopefully) fixes the bpf
> problem. It compiles and links, but I haven't tested it yet (waiting
> for make world to complete).

Well, it's 5 am over here and I finally got it licked :) It was a
little hairier than I thought because a) I can't just barge in and set
LPIPHDRLEN to 4, because it's used by non-bpf-related stuff, and b)
the transmit loop in lpoutput() modified the m_len field in each mbuf
along the chain *before* passing it on to bpf; the result was a lot of
empty packets (all outgoing packets would show up blank in bpf output)

Patches are attached. I'll commit them after I get some sleep :)

DES
-- 
Dag-Erling Smorgrav - des@flood.ping.uio.no

Index: if_plip.c
===================================================================
RCS file: /home/ncvs/src/sys/dev/ppbus/if_plip.c,v
retrieving revision 1.9
diff -u -r1.9 if_plip.c
--- if_plip.c	1999/01/30 15:35:39	1.9
+++ if_plip.c	1999/02/08 03:32:23
@@ -256,7 +256,7 @@
 	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 @@
 	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 @@
 	    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 @@
 		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 @@
     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 @@
 	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 @@
 	} 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 @@
     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 @@
 	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
     }
 
Index: nlpt.c
===================================================================
RCS file: /home/ncvs/src/sys/dev/ppbus/nlpt.c,v
retrieving revision 1.13
diff -u -r1.13 nlpt.c
--- nlpt.c	1999/01/27 20:09:19	1.13
+++ nlpt.c	1999/02/08 00:52:13
@@ -221,6 +221,9 @@
 }
 
 /*
+ * Probe simplified by replacing multiple loops with a hardcoded
+ * test pattern - 1999/02/08 des@freebsd.org
+ *
  * New lpt port probe Geoff Rehmet - Rhodes University - 14/2/94
  * Based partially on Rod Grimes' printer probe
  *
@@ -267,38 +270,29 @@
 static int
 nlpt_detect(struct lpt_data *sc)
 {
-	int		status;
-	u_char		data;
-	u_char		mask;
-	int		i, error;
+	static u_char	testbyte[18] = {
+		0x55,			/* alternating zeros */
+		0xaa,			/* alternating ones */
+		0xfe, 0xfd, 0xfb, 0xf7,
+		0xef, 0xdf, 0xbf, 0x7f,	/* walking zero */
+		0x01, 0x02, 0x04, 0x08,
+		0x10, 0x20, 0x40, 0x80	/* walking one */
+	};
+	int		i, error, status;
 
 	status = 1;				/* assume success */
 
 	if ((error = lpt_request_ppbus(sc, PPB_DONTWAIT))) {
 		printf(LPT_NAME ": cannot alloc ppbus (%d)!\n", error);
-		status = 0 ; goto end_probe ;
-	}
-
-	mask = 0xff;
-	data = 0x55;				/* Alternating zeros */
-	if (!nlpt_port_test(sc, data, mask))
-		{ status = 0 ; goto end_probe ; }
-
-	data = 0xaa;				/* Alternating ones */
-	if (!nlpt_port_test(sc, data, mask))
-		{ status = 0 ; goto end_probe ; }
-
-	for (i = 0; i < 8; i++)	{		/* Walking zero */
-		data = ~(1 << i);
-		if (!nlpt_port_test(sc, data, mask))
-			{ status = 0 ; goto end_probe ; }
+		status = 0;
+		goto end_probe;
 	}
 
-	for (i = 0; i < 8; i++)	{		/* Walking one */
-		data = (1 << i);
-		if (!nlpt_port_test(sc, data, mask))
-			{ status = 0 ; goto end_probe ; }
-	}
+	for (i = 0; i < 18 && status; i++)
+		if (!nlpt_port_test(sc, testbyte[i], 0xff)) {
+			status = 0;
+			goto end_probe;
+		}
 
 end_probe:
 	/* write 0's to control and data ports */

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?xzpsoch1rgw.fsf>