Subject: misc/2474: /etc/ifaliases doesn't set netmas
To: None <gnats-bugs@NetBSD.ORG>
From: Andrew Gillham <gillhaa@ghost.whirlpool.com>
List: netbsd-bugs
Date: 05/26/1996 21:33:34
>Number:         2474
>Category:       misc
>Synopsis:       /etc/ifaliases doesn't set netmas
>Confidential:   no
>Severity:       serious
>Priority:       low
>Responsible:    misc-bug-people (Misc Bug People)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sun May 26 21:50:01 1996
>Last-Modified:
>Originator:     Andrew Gillham
>Organization:
Whirlpool Corporation
>Release:        May 26, 1996
>Environment:
	
System: NetBSD ghost 1.1B NetBSD 1.1B (GHOST) #0: Fri May 24 00:30:08 EDT 1996 root@ghost:/usr/src/sys/arch/i386/compile/GHOST i386


>Description:
	Using /etc/netstart and /etc/ifaliases to assign additional
	ip addresses to the same interface, the netmask is not set
	for any additional addresses.  This makes for "interesting"
	routing problems.
Here is a sample output of 'netstat -in':
Name  Mtu   Network     Address              Ipkts Ierrs    Opkts Oerrs  Coll
ed0   1500  <Link>      0.0.c0.ec.3e.96        859     0     1720     0     0
ed0   1500  158.52.44   158.52.44.1            859     0     1720     0     0
ed0   1500  158.52      158.52.44.10           859     0     1720     0     0
lo0   32768 <Link>                             121     0      121     0     0
lo0   32768 127         127.0.0.1              121     0      121     0     0
ppp0  1500  <Link>                            9857   579     8857     0     0
ppp0  1500  158.52.44   158.52.44.1           9857   579     8857     0     0
ppp1* 1500  <Link>                               0     0        0     0     0

As you can see, the ip address of 158.52.44.1 was added with a netmask
of 255.255.255.0, while the alias address 158.52.44.10 ended up using
the default for a class B, 255.255.0.0.  
For some reason, the machine will now be "confused" about routing to
other 158.52.xx subnets.  It looks like netmask of the last address
added is being used or something.  I'll draw a small diagram to show
the problem I've been seeing.
[the numbers are the last 2 octets of ip address, 255.255.255.0 mask]
static       |--------|
to 2.0       | NetBSD | default route to 1.1
|-------|    | 1.2    |
| cisco |    | 1.3    | 1.3, 1.4 are aliases
| 1.1   |    | 1.4    |
|-------|    |--------|
    |             |
|------------------------|
           |
       |--------|  28.8k ppp  |--------|
       | NetBSD |-------      | NetBSD | using ppp 'defaultroute'
       | 1.5    |      /      | 2.1    |
       |--------|      -------|--------|
         default
         to 1.1

What happens is that the NetBSD machine with the (fictictious) ip
address of 1.2 can't communicate with 2.1 at all, if it(1.2) has an
alias.  Setting an alias with the correct netmask solves the problem.


>How-To-Repeat:
	Configure a similar design with a NetBSD machine providing PPP
	for another subnet.  No RIP, only default routes pointing to
	a cisco router, which has a static entry for the other subnet.
	You *should* see the problem.
	Note that this configuration was not a problem with NetBSD 1.1
	on the PPP server (ip address x.x.1.5).  After I upgraded to 1.1B
	this became a problem.
	
>Fix:

	Here is a patch that will modify the way /etc/ifaliases works.
	The new syntax is: address netmask interface.
	Example:
	/etc/ifaliases:
	158.52.44.10 255.255.255.0 ed0

	The patch:
	
*** netstart.11	Sun May 26 21:10:18 1996
--- netstart	Sun May 26 21:10:46 1996
***************
*** 105,119 ****
  # /etc/ifaliases, if it exists, contains the names of additional IP
  # addresses for each interface. It is formatted as a series of lines
  # that contain
! # address interface
  if [ -f /etc/ifaliases ]; then
  (
      set -- `cat /etc/ifaliases`
  
!     while [ $# -ge 2 ] ; do
! 	ifconfig $2 inet alias $1
  	route add $1 localhost
!         shift 2
      done
   )
  fi
--- 105,119 ----
  # /etc/ifaliases, if it exists, contains the names of additional IP
  # addresses for each interface. It is formatted as a series of lines
  # that contain
! # address netmask interface
  if [ -f /etc/ifaliases ]; then
  (
      set -- `cat /etc/ifaliases`
  
!     while [ $# -ge 3 ] ; do
! 	ifconfig $3 inet alias $1 netmask $2
  	route add $1 localhost
!         shift 3
      done
   )
  fi

>Audit-Trail:
>Unformatted: