From eugen@www.svzserv.kemerovo.su  Wed Aug 28 04:08:50 2002
Return-Path: <eugen@www.svzserv.kemerovo.su>
Received: from mx1.FreeBSD.org (mx1.FreeBSD.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id D91E637B400
	for <FreeBSD-gnats-submit@freebsd.org>; Wed, 28 Aug 2002 04:08:50 -0700 (PDT)
Received: from www.svzserv.kemerovo.su (www.svzserv.kemerovo.su [213.184.65.80])
	by mx1.FreeBSD.org (Postfix) with ESMTP id E0E7E43E77
	for <FreeBSD-gnats-submit@freebsd.org>; Wed, 28 Aug 2002 04:08:48 -0700 (PDT)
	(envelope-from eugen@www.svzserv.kemerovo.su)
Received: from www.svzserv.kemerovo.su (eugen@localhost [127.0.0.1])
	by www.svzserv.kemerovo.su (8.12.5/8.12.5) with ESMTP id g7SB8iie055927
	for <FreeBSD-gnats-submit@freebsd.org>; Wed, 28 Aug 2002 19:08:44 +0800 (KRAST)
	(envelope-from eugen@www.svzserv.kemerovo.su)
Received: (from eugen@localhost)
	by www.svzserv.kemerovo.su (8.12.5/8.12.5/Submit) id g7SB8hLh055925;
	Wed, 28 Aug 2002 19:08:43 +0800 (KRAST)
Message-Id: <200208281108.g7SB8hLh055925@www.svzserv.kemerovo.su>
Date: Wed, 28 Aug 2002 19:08:43 +0800 (KRAST)
From: Eugene Grosbein <eugen@www.svzserv.kemerovo.su>
Reply-To: Eugene Grosbein <eugen@www.svzserv.kemerovo.su>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: arp(8) fails due to ioctl SIOCGIFNETMASK failure
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         42120
>Category:       bin
>Synopsis:       arp(8) fails due to ioctl SIOCGIFNETMASK failure
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    glebius
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Aug 28 04:10:03 PDT 2002
>Closed-Date:    Sat Oct 21 05:50:50 GMT 2006
>Last-Modified:  Sat Oct 21 05:50:50 GMT 2006
>Originator:     Eugene Grosbein
>Release:        FreeBSD 4.6-STABLE i386
>Organization:
Svyaz Service JSC
>Environment:
System: FreeBSD 4.6-STABLE

>Description:

	We have an ARP-proxy gateway box that used to announce its MAC address
	for number of IP addresses. It translates them using natd then.
	It ran 3.x for years without a problem. Today I've upgraded it
	to 4.6-STABLE, all services run find except of ARP proxying.

	This interface (fxp0) has an alias with netmask 0xffffffff.
	ifconfig fxp0 shows alias before primary ip address that
	has netmask 0xffffff00, it does this for unknown reason as
	my rc.conf is the same. Well, that's basically OK
	exect of the fact that 'arp client_ip auto pub' cannot find
	interface in this case.

>How-To-Repeat:
	
	Suppose we have fxp0 without IP address.
	Let's see:

	# ifconfig fxp0
	fxp0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500
		ether 00:90:27:35:05:1b
		media: Ethernet autoselect (100baseTX <full-duplex>)
		status: active

	# ifconfig fxp0 inet 190.0.0.1 netmask 0xffffff00
	# ifconfig fxp0 inet 190.0.0.2 netmask 0xffffffff alias
	# ifconfig fxp0
	fxp0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500
		inet 190.0.0.1 netmask 0xffffff00 broadcast 190.0.0.255
		inet 190.0.0.2 netmask 0xffffffff broadcast 190.0.0.2
		ether 00:90:27:35:05:1b
		media: Ethernet autoselect (100baseTX <full-duplex>)
		status: active
	# arp -a -d
	# arp -s 190.0.0.3 auto pub
	using interface fxp0 for proxy with address 00:90:27:35:05:1b
	# ping -c 1 190.0.0.1
	PING 190.0.0.1 (190.0.0.1): 56 data bytes
	64 bytes from 190.0.0.1: icmp_seq=0 ttl=64 time=0.295 ms
	
	--- 190.0.0.1 ping statistics ---
	1 packets transmitted, 1 packets received, 0% packet loss
	round-trip min/avg/max/stddev = 0.295/0.295/0.295/0.000 ms
	# arp -a -n
	? (190.0.0.1) at 00:90:27:35:05:1b on fxp0 permanent [ethernet]
	? (190.0.0.3) at 00:90:27:35:05:1b on fxp0 permanent published [ethernet]

	That's what expected. Now clean up and start from beginning.

	# ifconfig fxp0 delete
	# ifconfig fxp0 delete
	# arp -a -d
	# ifconfig fxp0
	fxp0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500
		ether 00:90:27:35:05:1b
		media: Ethernet autoselect (100baseTX <full-duplex>)
		status: active

	But now make it go backwards (I don't know why it came to be
	in this way for my real box):
	
	# ifconfig fxp0 inet 190.0.0.2 netmask 0xffffffff
	# ifconfig fxp0 inet 190.0.0.1 netmask 0xffffff00 alias
	# ifconfig fxp0
		fxp0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500
		inet 190.0.0.2 netmask 0xffffffff broadcast 190.0.0.2
		inet 190.0.0.1 netmask 0xffffff00 broadcast 190.0.0.255
		ether 00:90:27:35:05:1b
		media: Ethernet autoselect (100baseTX <full-duplex>)
		status: active

	That's what I see after my box is loaded. Now try to play with ARP.
	# arp -a -d
	# arp -s 190.0.0.3 auto pub
	no interface found for 190.0.0.3

	arp(8) now cannot find an interface. I digged it for little
	and see that ioctl(sock,SIOCGIFNETMASK,&ifreq) returns
	0xffffffff twice for netmask, it does not return 0xffffff00
	so its really not arp's fault.

>Fix:

	Unknown for me. I was forced to rewrite my file for arp -f
	to not use 'auto' and use real MAC of fxp0 instead.
>Release-Note:
>Audit-Trail:

From: Dmitry Frolov <frolov@riss-telecom.ru>
To: freebsd-gnats-submit@FreeBSD.org, eugen@www.svzserv.kemerovo.su
Cc:  
Subject: Re: kern/42120: arp(8) fails due to ioctl SIOCGIFNETMASK failure
Date: Fri, 6 Dec 2002 15:23:07 +0600

 We experienced same behavior from arp(8). Workaround was to use
 route(8) with -proxy option.
 
 However we made a fix: according to sys/netinet/in.c (see in_control()
 function) we should set alias address in SIOCGIFNETMASK ifreq
 to get correct netmask for that address.
 
 Here is the patch (made for 4.6-R, but code in -current
 still the same):
 
 --- usr.sbin/arp/arp.c.orig	Thu Jul 11 16:24:31 2002
 +++ usr.sbin/arp/arp.c	Thu Jul 11 16:24:17 2002
 @@ -703,6 +703,8 @@
  			 * Get its netmask and check that it's on 
  			 * the right subnet.
  			 */
 +			((struct sockaddr_in *)&ifreq.ifr_addr)->sin_addr.s_addr =
 +				ina;
  			if (ioctl(sock, SIOCGIFNETMASK, &ifreq) < 0)
  				continue;
  			mask = ((struct sockaddr_in *)
 
 Also note that it's not a kern but bin problem.
 
 -- 
 Dmitry Frolov <frolov@riss-telecom.ru>
 RISS-Telecom Network, Novosibirsk, Russia
 66415911@ICQ, +7 3832 NO WA1T, DVF-RIPE
Responsible-Changed-From-To: freebsd-bugs->bms 
Responsible-Changed-By: bms 
Responsible-Changed-When: Tue 30 Sep 2003 23:56:21 PDT 
Responsible-Changed-Why:  
I'll look into this. 

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

From: Bruce M Simpson <bms@spc.org>
To: freebsd-gnats-submit@FreeBSD.org, eugen@www.svzserv.kemerovo.su
Cc:  
Subject: Re: kern/42120: arp(8) fails due to ioctl SIOCGIFNETMASK failure
Date: Wed, 1 Oct 2003 13:19:10 +0100

 The situation outlined within the PR is reproducible. The submitted patch
 doesn't solve the problem. Please supply your rc.conf settings and any
 script(s) which set up the ARP table for proxy arp.
 
 It would also help if the submitter reproduces their original test case,
 =66rom the system console, with the command 'route -nv monitor' running und=
 er
 the misc/screen port and the script(1) utility.
 
 The behaviour of netmasks with regards to aliases on the same IP subnet
 is documented in ifconfig(8). This behaviour is a result of how the
 routing table lookup works where cloned LLINFO routes are concerned.
 Consider the following lines in sys/netinet/in.c:
 
         case SIOCGIFNETMASK:
                 *((struct sockaddr_in *)&ifr->ifr_addr) =3D ia->ia_sockmask;
                 return (0);
 
 The netmask thus returned is always the netmask of the primary IP address.
 This is by definition the first address configured upon the interface;
 whilst I'm not an authority on this by any means, it looks correct to me.
 
 A /32 sockmask on the *primary* address is going to yield the wrong result
 for a LAN.
 
 The behaviour observed in the reproduced test case is not normal and hoses
 the routing table, requiring a reboot to do anything useful. An inconsisten=
 cy
 is evident within the routing table, as follows:-
 
 (after the ping step)
 81.3.72.75         00:90:27:59:40:2c  UHLW        0        2    lo0
 
 Not correct. This is inconsistent. This route should be:-
 81.3.72.75         127.0.0.1          UGHS        0        0    lo0
 
 This seems to break Layer 2 routing, and the routing table. Subsequent
 route adds with LLINFO seem to fail.
 
 BMS

From: Eugene Grosbein <eugen@kuzbass.ru>
To: Bruce M Simpson <bms@spc.org>
Cc: freebsd-gnats-submit@FreeBSD.org, eugen@www.svzserv.kemerovo.su
Subject: Re: kern/42120: arp(8) fails due to ioctl SIOCGIFNETMASK failure
Date: Thu, 02 Oct 2003 11:22:24 +0800

 Bruce M Simpson wrote:
 > 
 > The situation outlined within the PR is reproducible. The submitted patch
 > doesn't solve the problem. Please supply your rc.conf settings and any
 > script(s) which set up the ARP table for proxy arp.
 > 
 > It would also help if the submitter reproduces their original test case,
 > from the system console, with the command 'route -nv monitor' running under
 > the misc/screen port and the script(1) utility.
 
 Hi!
 
 My problem is generally gone because after power down/up cycle
 it runs as expected. I think now that the original problem
 appeared as a result of multiuser -> single user -> multiuser cycle
 and a manner of /etc/rc* scripts add IP addresses for interfaces.
 
 I'm back to 'auto' entries now.
 
 Sorry, I cannot experiment with this machine, 
 it is core router in production.
 
 Perhaps, you'd close the PR if this effect is expected.
 
 Eugene Grosbein
State-Changed-From-To: open->closed 
State-Changed-By: bms 
State-Changed-When: Tue 25 Nov 2003 04:35:55 PST 
State-Changed-Why:  
Closed at submitter's request. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=42120 
State-Changed-From-To: closed->open 
State-Changed-By: glebius 
State-Changed-When: Fri Oct 13 12:29:36 UTC 2006 
State-Changed-Why:  
The problem hadn't been fixed, so the PR shouldn't have been closed. 


Responsible-Changed-From-To: bms->glebius 
Responsible-Changed-By: glebius 
Responsible-Changed-When: Fri Oct 13 12:29:36 UTC 2006 
Responsible-Changed-Why:  
I'm going to fix the problem. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=42120 
State-Changed-From-To: open->patched 
State-Changed-By: glebius 
State-Changed-When: Fri Oct 13 12:39:45 UTC 2006 
State-Changed-Why:  
Fix committed to HEAD. 

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

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/42120: commit references a PR
Date: Fri, 13 Oct 2006 12:38:59 +0000 (UTC)

 glebius     2006-10-13 12:38:44 UTC
 
   FreeBSD src repository
 
   Modified files:
     usr.sbin/arp         arp.c 
   Log:
   - Before doing ioctl(SIOCGIFNETMASK) put the proper IP address into the ifreq,
     to obtain correct netmask in case of interface with multiple aliases.
   - While here, remove a comment with a bad idea.
   
   PR:             bin/42120
   Submitted by:   Dmitry Frolov <frolov riss-telecom.ru>
   
   Revision  Changes    Path
   1.64      +1 -1      src/usr.sbin/arp/arp.c
 _______________________________________________
 cvs-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/cvs-all
 To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/42120: commit references a PR
Date: Sat, 21 Oct 2006 05:43:46 +0000 (UTC)

 glebius     2006-10-21 05:43:29 UTC
 
   FreeBSD src repository
 
   Modified files:        (Branch: RELENG_6)
     usr.sbin/arp         arp.c 
   Log:
     - Before doing ioctl(SIOCGIFNETMASK) put the proper IP address into the ifreq,
       to obtain correct netmask in case of interface with multiple aliases.
     - While here, remove a comment with a bad idea.
   
     PR:           bin/42120
     Submitted by: Dmitry Frolov <frolov riss-telecom.ru>
   
   Approved by:    re (hrs)
   
   Revision  Changes    Path
   1.58.2.4  +1 -1      src/usr.sbin/arp/arp.c
 _______________________________________________
 cvs-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/cvs-all
 To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: patched->closed 
State-Changed-By: glebius 
State-Changed-When: Sat Oct 21 05:50:37 UTC 2006 
State-Changed-Why:  
Merged to RELENG_6. 

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