Subject: kern/3189: bpfattach can hang the system
To: None <tech-kern@netbsd.org>
From: Manuel Bouyer <bouyer@antioche.lip6.fr>
List: tech-kern
Date: 12/03/1998 21:17:02
Hi,
any objection to the following patch ?
This makes the bpf code initialise bpf_dtab[] at boot time rather than
at interface attach time (now that we have pcmcia hot-plug, this is not
necesserely the same thing ! :). With the current code, I think bad things
will happen if you plung in a pcmcia ethernet adapter while running
tcpump on another interface (like described in pr 3189, but with a different
senario).
Quickly tested on a desktop here (I don't have a laptop), this didn't
seem to break anything ...

--
Manuel Bouyer, LIP6, Universite Paris VI.           Manuel.Bouyer@lip6.fr
--

Index: bpf.c
===================================================================
RCS file: /cvsroot/src/sys/net/bpf.c,v
retrieving revision 1.45
diff -u -r1.45 bpf.c
--- bpf.c	1998/11/05 22:50:15	1.45
+++ bpf.c	1998/12/03 20:06:28
@@ -109,14 +109,20 @@
 
 #if BSD >= 199207 || NetBSD0_9 >= 2
 /*
- * bpfilterattach() is called at boot time in new systems.  We do
- * nothing here since old systems will not call this.
+ * bpfilterattach() is called at boot time.
  */
 /* ARGSUSED */
 void
 bpfilterattach(n)
 	int n;
 {
+	int i;
+	/*
+	 * Mark all the descriptors free.
+	 */
+	for (i = 0; i < NBPFILTER; ++i)
+		D_MARKFREE(&bpf_dtab[i]);
+
 }
 #endif
 
@@ -1330,13 +1336,6 @@
 	 * performance reasons and to alleviate alignment restrictions).
 	 */
 	bp->bif_hdrlen = BPF_WORDALIGN(hdrlen + SIZEOF_BPF_HDR) - hdrlen;
-
-	/*
-	 * Mark all the descriptors free if this hasn't been done.
-	 */
-	if (!D_ISFREE(&bpf_dtab[0]))
-		for (i = 0; i < NBPFILTER; ++i)
-			D_MARKFREE(&bpf_dtab[i]);
 
 #if 0
 	printf("bpf: %s attached\n", ifp->if_xname);