From ed@compy.fxq.nl  Fri Oct  8 11:47:14 2004
Return-Path: <ed@compy.fxq.nl>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 2539A16A4CE
	for <FreeBSD-gnats-submit@freebsd.org>; Fri,  8 Oct 2004 11:47:14 +0000 (GMT)
Received: from compy.fxq.nl (cp265563-a.mill1.nb.home.nl [217.121.83.210])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 633C743D41
	for <FreeBSD-gnats-submit@freebsd.org>; Fri,  8 Oct 2004 11:47:13 +0000 (GMT)
	(envelope-from ed@compy.fxq.nl)
Received: from compy.fxq.nl (localhost [127.0.0.1])
	by compy.fxq.nl (8.13.1/8.13.1) with ESMTP id i98BlACh000654
	for <FreeBSD-gnats-submit@freebsd.org>; Fri, 8 Oct 2004 13:47:10 +0200 (CEST)
	(envelope-from ed@compy.fxq.nl)
Received: (from ed@localhost)
	by compy.fxq.nl (8.13.1/8.13.1/Submit) id i98BlAwx000653;
	Fri, 8 Oct 2004 13:47:10 +0200 (CEST)
	(envelope-from ed)
Message-Id: <200410081147.i98BlAwx000653@compy.fxq.nl>
Date: Fri, 8 Oct 2004 13:47:10 +0200 (CEST)
From: Ed Schouten <ed@il.fontys.nl>
Reply-To: Ed Schouten <ed@il.fontys.nl>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: PF can't properly detect interface after 'ifconfig XXX name YYY'
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         72444
>Category:       kern
>Synopsis:       PF can't properly detect interface after 'ifconfig XXX name YYY'
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    pf
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Oct 08 11:50:16 GMT 2004
>Closed-Date:    Wed Nov 24 16:59:44 GMT 2004
>Last-Modified:  Wed Nov 24 16:59:44 GMT 2004
>Originator:     Ed Schouten
>Release:        FreeBSD 5.3-BETA7 i386
>Organization:
(none)
>Environment:
System: FreeBSD compy.fxq.nl 5.3-BETA7 FreeBSD 5.3-BETA7 #0: Thu Oct 7 13:24:34 CEST 2004 ed@compy.fxq.nl:/usr/obj/usr/src/sys/COMPY i386


	Intel Celeron 400 MHz
	256 MB SDRAM memory
	3 network interfaces:
	 - pcn0
	 - xl0
	 - rl0
	
>Description:
	When I rename my network interfaces with ifconfig, I can't use them with PF anymore.
	For example:

	nat on rl0 from 10.0.0.0/24 to any -> (rl0)

	This line works. But renaming the interface:

	ifconfig rl0 name foo

	and using the following line in pf.conf:

	nat on foo from 10.0.0.0/24 to any (foo)

	does not. It won't apply NAT to my network packets (according to tcpdump).

>How-To-Repeat:
	ifconfig rl0 name foo
>Fix:
	Sorry, don't have one.
>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->mlaier 
Responsible-Changed-By: glebius 
Responsible-Changed-When: Fri Oct 8 12:18:09 GMT 2004 
Responsible-Changed-Why:  
Over to pf maintainer. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=72444 

From: Max Laier <max@love2party.net>
To: freebsd-gnats-submit@freebsd.org, ed@il.fontys.nl
Cc:  
Subject: Re: kern/72444: PF can't properly detect interface after 'ifconfig XXX name YYY'
Date: Fri, 8 Oct 2004 15:58:44 +0200

 --Boundary-00=_W0pZBx1MfpSv+kA
 Content-Type: text/plain;
   charset="us-ascii"
 Content-Transfer-Encoding: 7bit
 Content-Disposition: inline
 
 Can you try the attached patch to src/sys/contrib/pf/net/pf_if.c , please?
 
 Also to be found at: http://people.freebsd.org/~mlaier/pf_if.c.diff
 
 -- 
  Max
 
 --Boundary-00=_W0pZBx1MfpSv+kA
 Content-Type: text/x-diff;
   charset="us-ascii";
   name="pf_if.c.diff"
 Content-Transfer-Encoding: 7bit
 Content-Disposition: attachment;
 	filename="pf_if.c.diff"
 
 Index: pf_if.c
 ===================================================================
 RCS file: /usr/store/mlaier/fcvs/src/sys/contrib/pf/net/pf_if.c,v
 retrieving revision 1.5
 diff -u -r1.5 pf_if.c
 --- pf_if.c	16 Aug 2004 17:58:12 -0000	1.5
 +++ pf_if.c	8 Oct 2004 13:57:34 -0000
 @@ -341,8 +341,7 @@
  
  		/* add/modify interface */
  		if (p == NULL)
 -			p = pfi_if_create(ifp->if_xname, q,
 -			    realname?PFI_IFLAG_INSTANCE:PFI_IFLAG_PLACEHOLDER);
 +			p = pfi_if_create(ifp->if_xname, q, PFI_IFLAG_INSTANCE);
  		else {
  			/* remove from the dummy group */
  			/* XXX: copy stats? We should not have any!!! */
 @@ -354,10 +353,8 @@
  			q->pfik_addcnt++;
  			TAILQ_INSERT_TAIL(&q->pfik_grouphead, p,
  			    pfik_instances);
 -			if (realname) {
 -				p->pfik_flags &= ~PFI_IFLAG_PLACEHOLDER;
 -				p->pfik_flags |= PFI_IFLAG_INSTANCE;
 -			}
 +			p->pfik_flags &= ~PFI_IFLAG_PLACEHOLDER;
 +			p->pfik_flags |= PFI_IFLAG_INSTANCE;
  		}
  		if (p == NULL)
  			panic("pfi_attach_ifnet: "
 
 --Boundary-00=_W0pZBx1MfpSv+kA--
State-Changed-From-To: open->analyzed 
State-Changed-By: mlaier 
State-Changed-When: Fri Oct 8 14:12:36 GMT 2004 
State-Changed-Why:  
Patch available for testing. 


Responsible-Changed-From-To: mlaier->pf 
Responsible-Changed-By: mlaier 
Responsible-Changed-When: Fri Oct 8 14:12:36 GMT 2004 
Responsible-Changed-Why:  
Over to freebsd-pf mailinglist for review. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=72444 

From: "Ed Schouten" <ed@il.fontys.nl>
To: max@love2party.net
Cc: freebsd-gnats-submit@freebsd.org
Subject: Re: kern/72444: PF can't properly detect interface after 'ifconfig 
     XXX name YYY'
Date: Fri, 8 Oct 2004 16:49:44 +0200 (CEST)

 Hello Max,
 
 On Fri, October 8, 2004 3:58 pm, Max Laier said:
 > Can you try the attached patch to src/sys/contrib/pf/net/pf_if.c , please?
 
 I tried it and it works like a charm! Thanks for your quick response! :)
 
 Yours,
 -- 
  Ed Schouten <ed@il.fontys.nl>
  Website: http://g-rave.nl/

From: Max Laier <max@love2party.net>
To: freebsd-gnats-submit@freebsd.org, ed@il.fontys.nl
Cc:  
Subject: Re: kern/72444: PF can't properly detect interface after 'ifconfig XXX name YYY'
Date: Mon, 25 Oct 2004 00:00:17 +0200

 --Boundary-00=_zXCfBCdi0Ycu4DN
 Content-Type: text/plain;
   charset="us-ascii"
 Content-Transfer-Encoding: 7bit
 Content-Disposition: inline
 
 I have uploaded an updated diff. This version should do better with module 
 load/unload and allow the use of "6to4" interfaces. Please test and tell me 
 if it introduces other problems.
 
 Diff attached or at: http://people.freebsd.org/~mlaier/pf_if.c.diff
 
 -- 
  Max
 
 --Boundary-00=_zXCfBCdi0Ycu4DN
 Content-Type: text/x-diff;
   charset="us-ascii";
   name="pf_if.c.diff"
 Content-Transfer-Encoding: 7bit
 Content-Disposition: attachment;
 	filename="pf_if.c.diff"
 
 Index: pf_if.c
 ===================================================================
 RCS file: /usr/store/mlaier/fcvs/src/sys/contrib/pf/net/pf_if.c,v
 retrieving revision 1.6
 diff -u -r1.6 pf_if.c
 --- pf_if.c	14 Sep 2004 15:20:24 -0000	1.6
 +++ pf_if.c	24 Oct 2004 21:52:45 -0000
 @@ -157,12 +157,11 @@
  #ifdef __FreeBSD__
  	PF_LOCK();
  	IFNET_RLOCK();
 -	TAILQ_FOREACH(ifp, &ifnet, if_link)
 -		if (ifp->if_dunit != IF_DUNIT_NONE) {
 -			IFNET_RUNLOCK();
 -			pfi_attach_ifnet(ifp);
 -			IFNET_RLOCK();
 -		}
 +	TAILQ_FOREACH(ifp, &ifnet, if_link) {
 +		IFNET_RUNLOCK();
 +		pfi_attach_ifnet(ifp);
 +		IFNET_RLOCK();
 +	}
  	IFNET_RUNLOCK();
  	PF_UNLOCK();
  	pfi_dummy = pfi_if_create("notyet", pfi_self,
 @@ -248,8 +247,7 @@
  pfi_attach_ifnet_event(void *arg __unused, struct ifnet *ifp)
  {
  	PF_LOCK();
 -	if (ifp->if_dunit != IF_DUNIT_NONE)
 -		pfi_attach_ifnet(ifp);
 +	pfi_attach_ifnet(ifp);
  	PF_UNLOCK();
  }
  
 @@ -341,8 +339,8 @@
  
  		/* add/modify interface */
  		if (p == NULL)
 -			p = pfi_if_create(ifp->if_xname, q,
 -			    realname?PFI_IFLAG_INSTANCE:PFI_IFLAG_PLACEHOLDER);
 +			p = pfi_if_create(ifp->if_xname, q, PFI_IFLAG_INSTANCE |
 +			    (realname?0:PFI_IFLAG_PLACEHOLDER));
  		else {
  			/* remove from the dummy group */
  			/* XXX: copy stats? We should not have any!!! */
 @@ -354,10 +352,9 @@
  			q->pfik_addcnt++;
  			TAILQ_INSERT_TAIL(&q->pfik_grouphead, p,
  			    pfik_instances);
 -			if (realname) {
 +			if (realname)
  				p->pfik_flags &= ~PFI_IFLAG_PLACEHOLDER;
 -				p->pfik_flags |= PFI_IFLAG_INSTANCE;
 -			}
 +			p->pfik_flags |= PFI_IFLAG_INSTANCE;
  		}
  		if (p == NULL)
  			panic("pfi_attach_ifnet: "
 @@ -874,6 +871,7 @@
  	if (p->pfik_rules > 0 || p->pfik_states > 0) {
  		/* move back to the dummy group */
  		p->pfik_parent = pfi_dummy;
 +		p->pfik_flags &= ~PFI_IFLAG_INSTANCE;
  		pfi_dummy->pfik_addcnt++;
  		TAILQ_INSERT_TAIL(&pfi_dummy->pfik_grouphead, p,
  		    pfik_instances);
 @@ -912,11 +910,8 @@
   */
  
  	IFNET_RLOCK();
 -	TAILQ_FOREACH(ifp, &ifnet, if_link) {
 -		if (ifp->if_dunit == IF_DUNIT_NONE)
 -			continue;
 +	TAILQ_FOREACH(ifp, &ifnet, if_link)
  		pfi_newgroup(ifp->if_dname, PFI_IFLAG_DYNAMIC);
 -	}
  	IFNET_RUNLOCK();
  #else
  	char		*buses[] = PFI_DYNAMIC_BUSES;
 
 --Boundary-00=_zXCfBCdi0Ycu4DN--
State-Changed-From-To: analyzed->patched 
State-Changed-By: mlaier 
State-Changed-When: Wed Nov 3 17:22:01 GMT 2004 
State-Changed-Why:  
Patch committed to HEAD. Please check if it works for you. The patch from 
above should apply to RELENG_5(_3) without problems. Thanks for the report, 
sorry that the fix didn't make 5.3 

http://www.freebsd.org/cgi/query-pr.cgi?pr=72444 
State-Changed-From-To: patched->closed 
State-Changed-By: mlaier 
State-Changed-When: Wed Nov 24 16:58:12 GMT 2004 
State-Changed-Why:  
The fix has been MFCed to RELENG_5. Thanks. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=72444 
>Unformatted:
