Bring in in_{add,scrub}prefix() from OpenBSD.
authorSepherosa Ziehau <sephe@dragonflybsd.org>
Sat, 27 Dec 2008 13:13:53 +0000 (21:13 +0800)
committerSepherosa Ziehau <sephe@dragonflybsd.org>
Wed, 31 Dec 2008 10:14:38 +0000 (18:14 +0800)
commit102e97f31733741a73135d716be6fb305e8842fd
tree234a83a3ab8544796c3c16f46cdea656fce6eb7d
parent52163b732511c4622844381d8b5a55484831c4e7
Bring in in_{add,scrub}prefix() from OpenBSD.

These two functions are used to add/delete "prefix route" for
interface addresses.

in_addprefix() allows addresses with same prefix to be added by
checking the prefix's existence before calling rtinit(), if same
prefix exists, it returns silently.  Originally rtinit() will fail
in in_ifinit() and the address will not be added.  This function
at least makes the result of address assignment consistent in
following two cases:

ifconfig iface1 inet 192.168.5.2
ifconfig iface0 inet 192.168.5.1

Origianlly last command will fail, since the route to 192.168.5.0/24
already exists.

ifconfig iface0 inet 192.168.5.1
ifconfig iface0 down
ifconfig iface1 inet 192.168.5.2
ifconfig iface0 up

However, originally, above commands sequence will successfully add
192.168.5.1 to iface0 ;)

To make in_addprefix() function properly following fix is brought
in from ru@freebsd.org via OpenBSD:
  For loopback, set ia_dstaddr instead of ia_ifa.ifa_dstaddr in
  in_ifinit()

Following changes are made to the OpenBSD's in_addprefix():
- Don't try to match the prefix against the address to be added.
- Test subnetmask only if the tested address and the to be added
  address are not for loopback or point to point interface.

in_scrubprefix() will try to find an address with same prefix
as the to-be-deleted address.  If suitable address is found, then
in addition to delete the to-be-deleted address's prefix route,
a new prefix route associated with the suitable address will be
installed.

Following changes are made to OpenBSD's in_scrubprefix():
- Don't try to match the prefix against the address to be deleted.
- Don't even try to add prefix route for an address whose parent
  interface is not up yet.
sys/netinet/in.c