network: update MAC address in IPv4 ACD clients

When the MAC address of a link is updated, an address on the link may
be under checking address duplication. Or, (currently such code is not
implemented yet, but) address duplication check may be restarted later.
For that case, the IPv4 ACD clients must use the new updated MAC address.
This commit is contained in:
Yu Watanabe 2020-10-04 09:27:42 +09:00
parent 490ccbd5e5
commit d93d655c40
3 changed files with 50 additions and 0 deletions

View File

@ -1402,6 +1402,51 @@ static int ipv4_dad_configure(Address *address) {
return sd_ipv4acd_start(address->acd, true);
}
static int ipv4_dad_update_mac_one(Address *address) {
bool running;
int r;
assert(address);
if (!address->acd)
return 0;
running = sd_ipv4acd_is_running(address->acd);
if (running) {
r = sd_ipv4acd_stop(address->acd);
if (r < 0)
return r;
}
r = sd_ipv4acd_set_mac(address->acd, &address->link->mac);
if (r < 0)
return r;
if (running) {
r = sd_ipv4acd_start(address->acd, true);
if (r < 0)
return r;
}
return 0;
}
int ipv4_dad_update_mac(Link *link) {
Address *address;
int k, r = 0;
assert(link);
SET_FOREACH(address, link->addresses) {
k = ipv4_dad_update_mac_one(address);
if (k < 0 && r >= 0)
r = k;
}
return r;
}
int ipv4_dad_stop(Link *link) {
Address *address;
int k, r = 0;

View File

@ -66,6 +66,7 @@ int link_serialize_addresses(Link *link, FILE *f);
int link_deserialize_addresses(Link *link, const char *addresses);
int ipv4_dad_stop(Link *link);
int ipv4_dad_update_mac(Link *link);
int manager_rtnl_process_address(sd_netlink *nl, sd_netlink_message *message, Manager *m);

View File

@ -2697,6 +2697,10 @@ int link_update(Link *link, sd_netlink_message *m) {
if (r < 0)
return log_link_warning_errno(link, r, "Could not update MAC for NDisc: %m");
}
r = ipv4_dad_update_mac(link);
if (r < 0)
return log_link_warning_errno(link, r, "Could not update MAC address in IPv4 ACD client: %m");
}
old_master = link->master_ifindex;