Right now, the sorting of the list of IPs for an interface that can be received from the ubus interface of netifd is kind of unspecified. With IPv6 where multiple IPs are more common (e.g. ULA and public), this is quite bad in combination with the implementation of network_get_ipaddr6 that just returns the first address [1]. So it can be the ULA or the public address.
Part of the issue is the comparator function in netifd for addresses [2]. First, there index is compared, then the actual content. The index is just based on the order of the IPs as they are configured or received [3]. In case of odhcp6c, this list is updated from its hook and sent to netifd. The hook sends all IPs (the new list of IPs) and their order is in the end the one that is returned by netifd when queried using the ubus interface. odhcp6c itself just adds new IPs to the end of its list and cuts out old addresses from the list (using memmove to overwrite it with the following list items [4]). The end result: One can start with the public IP as the first IP and once it changes, the public IP is the second one in the list and the ULA one is the first. And this first IP is returned by network_get_ipaddr6. My favorite solution would be to sort the IPs first by their value and then by their index in netifd. This would be more deterministic and have the side effect of returning the public IPs first and then the ULA IPs (which matches e.g. "ip a"). [1] https://github.com/openwrt/openwrt/blob/v24.10.4/package/base-files/files/lib/functions/network.sh#L37 [2] https://github.com/openwrt/netifd/blob/777f5942fa7d6245f6ad29daa1daecc400344d37/interface-ip.c#L540 [3] https://github.com/openwrt/netifd/blob/777f5942fa7d6245f6ad29daa1daecc400344d37/proto.c#L175 [4] https://github.com/openwrt/odhcp6c/blob/77e1ae21e67f81840024ffe5bb7cf69a8fb0d2f0/src/odhcp6c.c#L759 _______________________________________________ openwrt-devel mailing list [email protected] https://lists.openwrt.org/mailman/listinfo/openwrt-devel
