networkd: Wait for link to get carrier before setting addresses

For containers the link is effectively always up,
but for virtual and physical machines networkd may have started
before the link has gained carrier.

Networkd will configure addresses when carrier is gained,
but should also configure addresses if the link is already up.
Without this patch the addresses are set unconditionally.

Normally this isn't a problem since addresses are either fixed,
set over DHCP, or is never without carrier.
But for machines that gain carrier and are configured to select
an address from the unallocated local address pool
this causes them to pick an address from the pool twice.

This change to skip address configuration when a link is added
before it has a carrier fixes having multiple addresses assigned
if the machine starts networkd before it has gained carrier
and is configured with an address from the pool.
This commit is contained in:
Richard Maw 2017-06-07 16:30:46 +01:00
parent 410a7f15f0
commit c1835a427f
1 changed files with 6 additions and 0 deletions

View File

@ -2135,6 +2135,12 @@ static int link_joined(Link *link) {
log_link_error_errno(link, r, "Could not set bridge vlan: %m");
}
/* Skip setting up addresses until it gets carrier,
or it would try to set addresses twice,
which is bad for non-idempotent steps. */
if (!link_has_carrier(link))
return 0;
return link_enter_set_addresses(link);
}