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

next in thread | previous in thread | raw e-mail | index | archive | help
[cc:ed to jkh because of the last two paragraphs]

Bill Fenner <fenner@parc.xerox.com> writes:
> Ugh.  Can you tell what mode the device is going to be in when you
> bpf_attach()?  (Presumably not).  I guess bpf might end up needing
> a mechanism to change what you told it in bpf_attach().  I wonder what
> happens if someone's got a bpf open on the device when that happens;
> probably nothing good...

No, I just throw away the fake Ethernet header and put a DLT_NULL
header on instead. It's much simpler, and no useful information is
lost since the fake Ethernet header in the incoming packet is blank
except for the type field, which we reproduce (or rather, translate to
AF_INET) in the DLT_NULL header.

Whoever originally added bpf support to the lpt driver must have been
smoking some really strong stuff. Not only does the current code
produce invalid (and therefore useless) bpf packets, but in Crynwr
mode it doesn't pass incoming packets to bpf at all!

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). The second patch is equivalent to the one
committed to lpt.c last February (simplified port probe). It's been in
lpt.c long enough to be considered stable, and I'd like to MFC it (and
the first patch as well if it turns out OK - it can't possibly make
matters worse than they already are)

I'd really, *really* like to rip out the lpt driver, since its
functionality is completely duplicated by the nlpt and lpip drivers,
which seem pretty stable now. Keeping the lpt driver will only result
in slowing down ppbus development. I don't think ppbus + nlpt + plip
is significantly larger than lpt, so size is not an argument. And if
we ever want to rip out lpt, we have to rip it out *now* before 3.1 is
released, or we'll have a hard time doing it before 4.0 goes -STABLE
in a year or two.

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 00:25:46
@@ -123,7 +123,7 @@
 #define	CLPIP_SHAKE	0x80	/* This bit toggles between nibble reception */
 #define MLPIPHDRLEN	CLPIPHDRLEN
 
-#define LPIPHDRLEN	2	/* We send 0x08, 0x00 in front of packet */
+#define LPIPHDRLEN	4	/* We send AF_INET in front of packet */
 #define	LPIP_SHAKE	0x40	/* This bit toggles between nibble reception */
 #if !defined(MLPIPHDRLEN) || LPIPHDRLEN > MLPIPHDRLEN
 #define MLPIPHDRLEN	LPIPHDRLEN
@@ -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 = LPIPHDRLEN;
+	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;
@@ -734,23 +757,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?xzp90e9brl4.fsf>