if: Bandaid ifa_ifwithnet() for ifaddrs w/ same netmask
authorSepherosa Ziehau <sephe@dragonflybsd.org>
Fri, 11 Dec 2015 07:39:03 +0000 (15:39 +0800)
committerSepherosa Ziehau <sephe@dragonflybsd.org>
Fri, 11 Dec 2015 07:39:03 +0000 (15:39 +0800)
commit0925f9d882e80bae6773fbae547965da8ac5ba3e
treef589ecdbbb4e3805cf16a3902ebd33258817ba0f
parentea94549901edec6a3d51c5ea4475c3b0a2164444
if: Bandaid ifa_ifwithnet() for ifaddrs w/ same netmask

The original ifaddr selection logic would cause trouble for
SO_DONTROUTE sockets, if following stuffs happened:
ifconfig drv0 inet a.b.c.1
ifconfig drv0 down
ifconfig drv1 inet a.b.c.2

The original ifaddr selection logic in ifa_ifwithnet() will
select a.b.c.1@drv0, which is down.  Instead, a.b.c.2@drv1
should be selected.

We thus prefer ifaddr w/ IFF_UP interface or is routable.

Same bandaid probably should be applied to ifa_ifwithdstaddr(),
ifa_ifwithaddr() [broadcast part], and ifaof_ifpforaddr() too.
sys/net/if.c