Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FS#3222 - The primary static ip address changes after reloading /etc/config/network with a different metric #8099

Closed
openwrt-bot opened this issue Jul 10, 2020 · 0 comments
Labels

Comments

@openwrt-bot
Copy link

kingarley:

Device: tested with x86
Software version: found in lede, don't think it's fixed in the later versions
netifd version: netifd-2017-01-25

Reproduce (/etc/config/network):
config interface 'eth0_1'
option ifname 'eth0'
option proto 'static'
option ipaddr '1.1.1.3 1.1.1.2 1.1.1.1'
option netmask '255.255.255.0'
option metric '1001'
ip a gives the ip addresses in this order: 1.1.1.3, 1.1.1.2, 1.1.1.1
change the metric from '1001' to '1002' in /etc/config/network
call /etc/init.d/network reload
ip a gives the ip addresses in this order: 1.1.1.1, 1.1.1.2, 1.1.1.3

Code (netifd/interface.c)
in static void
interface_change_config(struct interface *if_old, struct interface *if_new)

UPDATE(metric, reload_ip);
UPDATE(proto_ip.no_defaultroute, reload_ip);
UPDATE(ip4table, reload_ip);
UPDATE(ip6table, reload_ip);

...
...
if (reload_ip) {
bool config_ip_enabled = if_old->config_ip.enabled;
bool proto_ip_enabled = if_old->proto_ip.enabled;

	interface_ip_set_enabled(&if_old->config_ip, false);
	interface_ip_set_enabled(&if_old->proto_ip, false);
	interface_ip_set_enabled(&if_old->proto_ip, proto_ip_enabled);
	interface_ip_set_enabled(&if_old->config_ip, config_ip_enabled);
}

interface_ip_set_enabled(&if_old->proto_ip, false);
interface_ip_set_enabled(&if_old->proto_ip, proto_ip_enabled);
The call to interface_ip_set_enabled with 'true' iterates the if_old_proto_ip vlist:
vlist_for_each_element(&ip->addr, addr, node)
which doesn't retain the original order of the static ip addresses in the /etc/config/network, which means the ip addresses are added in a different order, thus changing the primary ip address.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant