From richier@tuna.imag.fr  Wed Feb  5 05:26:52 1997
Received: from tuna.imag.fr (tuna.imag.fr [192.44.68.19])
          by freefall.freebsd.org (8.8.5/8.8.5) with ESMTP id FAA14505
          for <FreeBSD-gnats-submit@freebsd.org>; Wed, 5 Feb 1997 05:26:45 -0800 (PST)
Received: (from richier@localhost) by tuna.imag.fr (8.8.3/8.8.3) id OAA00408; Wed, 5 Feb 1997 14:26:01 +0100 (MET)
Message-Id: <199702051326.OAA00408@tuna.imag.fr>
Date: Wed, 5 Feb 1997 14:26:01 +0100 (MET)
From: Jean-Luc.Richier@imag.fr
Reply-To: Jean-Luc.Richier@imag.fr
To: FreeBSD-gnats-submit@freebsd.org
Subject: Bug in bpfattach
X-Send-Pr-Version: 3.2

>Number:         2667
>Category:       kern
>Synopsis:       bpfattach can hang the system
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    wollman
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Wed Feb  5 05:30:00 PST 1997
>Closed-Date:    Tue Dec 21 05:15:05 PST 1999
>Last-Modified:  Tue Dec 21 05:15:22 PST 1999
>Originator:     Jean-Luc Richier
>Release:        FreeBSD 2.1.6-RELEASE i386
>Organization:
Institut IMAg, Grenoble, France
>Environment:


>Description:

While working on the IPv6 extensions for NetBSD and FreeBSD,
I discovered a problem with bpfattach behaviour. 
If one tries to make extensions to NetBSD, this behaviour raise problems.
Therefore I suggest corrections to the base distribution code.

If the ifattach function is called while a bpf filter is open, the system
hangs.

>How-To-Repeat:

  - Make a modfication in the system which allows to configure a new driver at
    any time (In my case, it is a dynamic modification of the number of IPv6
    tunnel drivers)
  - open bpf filters, for example run ``rarpd -a''
  - configure a new driver
  - some seconds later, the system will hang

>Fix:
Add a static variable to test if it is the first call to bpfattach

*** sys/net/bpf.c.DIST	Sat Jun  8 08:14:15 1996
--- sys/net/bpf.c	Wed Feb  5 11:43:23 1997
***************
*** 1271,1276 ****
--- 1271,1277 ----
  {
  	struct bpf_if *bp;
  	int i;
+ 	static int already = 0;
  #if BSD < 199103
  	static struct bpf_if bpf_ifs[NBPFILTER];
  	static int bpfifno;
***************
*** 1303,1311 ****
  	/*
  	 * 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 (bootverbose)
  		printf("bpf: %s%d attached\n", ifp->if_name, ifp->if_unit);
--- 1304,1314 ----
  	/*
  	 * Mark all the descriptors free if this hasn't been done.
  	 */
! 	if(!already) {
! 		already = 1;
  		for (i = 0; i < NBPFILTER; ++i)
  			D_MARKFREE(&bpf_dtab[i]);
+ 	}
  
  	if (bootverbose)
  		printf("bpf: %s%d attached\n", ifp->if_name, ifp->if_unit);
>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->wollman 
Responsible-Changed-By: mpp 
Responsible-Changed-When: Sat Feb 22 22:48:00 PST 1997 
Responsible-Changed-Why:  
networking problem (PR includes patch) 
State-Changed-From-To: open->closed 
State-Changed-By: sheldonh 
State-Changed-When: Tue Dec 21 05:15:05 PST 1999 
State-Changed-Why:  
Fixed in CURRENT 1999-10-03: 

rev 1.35        src/sys/net/bpf.c 

Fixed since FreeBSD 2.2.5-RELEASE, now.  Time for closure, methinks. :-) 
>Unformatted:
