On 18.05.2013 16:43, Ondrej Zajicek wrote:
On Wed, May 15, 2013 at 09:18:10PM +0400, Slawa Olhovchenkov wrote:
So this is a problem with multiple IPs on an iface. On BSD, we support just one primary address in OSPF (others are just handled as stubs). Lexicographically smallest address was chosen. Unfortunately the kernel chose a different one as a source address. Why lexicographically smallest? Why not first from getifaddrs() list? Well, this is mainly a consequence of the facts that primary address selection is currently in platform independent code and on Linux the order of addressess has no real meaning. Therefore it seemed to be a good idea to make it more deterministic, i.e. independent on the order in which the addresses appeared.
Perhaps the best idea would be to remove the whole primary address selection (as it does more harm than good) and replace it by platform dependent flag that this address is preferred for the interface (and don't even use this flag on Linux).
We enumerate addresses on BSD using CTL_NET / NET_RT_IFLIST sysctl scan. Does anyone know whether is a reliable way to determine which one of returned addresses is the primary one or whether we should just add an It should be the first one, yes. The problem starts when the primary address gets removed. I'm thinking of adding special flag to ifa_flags indicating that address is primary, and either use RTM_NEWADDR to announce new primary address (sent before RTM_DELADDR) or completely new message like RTM_PRIMADDR with the same data.
However, I probably can do this for FreeBSD only, and something has to be implemented for other *BSD flavors..
another call of SIOCGIFADDR (as suggested by Alexander V. Chernikov)? It seems that platform-dependent code with addional constantly open socket calling SIOCGIFADDR on address change is the easiest hack^Wthing to do.. I would guess it is the first one, but i am not sure if that is specified or just a coincidence.