Skip to content

Commit

Permalink
networkd: start ipv4ll when dhcp has trouble getting a lease
Browse files Browse the repository at this point in the history
  • Loading branch information
keszybz authored and aj-bagwell committed Jan 7, 2021
1 parent e6b0d8f commit 51214e7
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 17 deletions.
7 changes: 5 additions & 2 deletions man/systemd.network.xml
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,9 @@
<para>Enables link-local address autoconfiguration. Accepts <option>yes</option>,
<option>no</option>, <option>ipv4</option>, and <option>ipv6</option>. An IPv6 link-local address
is configured when <option>yes</option> or <option>ipv6</option>. An IPv4 link-local address is
configured when <option>yes</option> or <option>ipv4</option>.</para>
configured when <option>yes</option> or <option>ipv4</option> and when DHCPv4 autoconfiguration
has been unsuccessful for some time. (IPv4 link-local address autoconfiguration will usually
happen in parallel with repeated attempts to acquire a DHCPv4 lease).</para>

<para>Defaults to <option>no</option> when <varname>Bridge=yes</varname> is set, and
<option>ipv6</option> otherwise.</para>
Expand Down Expand Up @@ -1550,7 +1552,8 @@
<para>Specifies how many times the DHCPv4 client configuration should be attempted. Takes a
number or <literal>infinity</literal>. Defaults to <literal>infinity</literal>. Note that the
time between retries is increased exponentially, up to approximately one per minute, so the
network will not be overloaded even if this number is high.</para>
network will not be overloaded even if this number is high. The default is suitable in most
circumstances.</para>
</listitem>
</varlistentry>

Expand Down
15 changes: 15 additions & 0 deletions src/network/networkd-dhcp4.c
Original file line number Diff line number Diff line change
Expand Up @@ -1033,6 +1033,21 @@ static int dhcp4_handler(sd_dhcp_client *client, int event, void *userdata) {
if (r != 0)
return -ENOMSG;
break;

case SD_DHCP_CLIENT_EVENT_TRANSIENT_FAILURE:
if (link_ipv4ll_enabled(link)) {
assert(link->ipv4ll);

if (!sd_ipv4ll_is_running(link->ipv4ll)) {
log_link_debug(link, "Problems acquiring DHCP lease, acquiring IPv4 link-local address");

r = sd_ipv4ll_start(link->ipv4ll);
if (r < 0)
return log_link_warning_errno(link, r, "Could not acquire IPv4 link-local address: %m");
}
}
break;

default:
if (event < 0)
log_link_warning_errno(link, event, "DHCP error: Client failed: %m");
Expand Down
19 changes: 8 additions & 11 deletions src/network/networkd-link.c
Original file line number Diff line number Diff line change
Expand Up @@ -1509,7 +1509,14 @@ static int link_acquire_ipv4_conf(Link *link) {
assert(link->manager);
assert(link->manager->event);

if (link_ipv4ll_enabled(link)) {
if (link->dhcp_client) {
log_link_debug(link, "Acquiring DHCPv4 lease");

r = sd_dhcp_client_start(link->dhcp_client);
if (r < 0)
return log_link_warning_errno(link, r, "Could not acquire DHCPv4 lease: %m");

} else if (link_ipv4ll_enabled(link)) {
assert(link->ipv4ll);

log_link_debug(link, "Acquiring IPv4 link-local address");
Expand All @@ -1519,16 +1526,6 @@ static int link_acquire_ipv4_conf(Link *link) {
return log_link_warning_errno(link, r, "Could not acquire IPv4 link-local address: %m");
}

if (link_dhcp4_enabled(link)) {
assert(link->dhcp_client);

log_link_debug(link, "Acquiring DHCPv4 lease");

r = sd_dhcp_client_start(link->dhcp_client);
if (r < 0)
return log_link_warning_errno(link, r, "Could not acquire DHCPv4 lease: %m");
}

return 0;
}

Expand Down
1 change: 0 additions & 1 deletion test/test-network/conf/dhcp-client-vrf.network
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@ Name=veth99
[Network]
DHCP=yes
IPv6AcceptRA=yes
LinkLocalAddressing=yes
VRF=vrf99
3 changes: 0 additions & 3 deletions test/test-network/systemd-networkd-tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2990,15 +2990,13 @@ def test_dhcp_client_vrf(self):
print('## ip address show vrf vrf99')
output = check_output('ip address show vrf vrf99')
print(output)
self.assertRegex(output, 'inet 169.254.[0-9]*.[0-9]*/16 brd 169.254.255.255 scope link veth99')
self.assertRegex(output, 'inet 192.168.5.[0-9]*/24 brd 192.168.5.255 scope global dynamic veth99')
self.assertRegex(output, 'inet6 2600::[0-9a-f]*/128 scope global (dynamic noprefixroute|noprefixroute dynamic)')
self.assertRegex(output, 'inet6 .* scope link')

print('## ip address show dev veth99')
output = check_output('ip address show dev veth99')
print(output)
self.assertRegex(output, 'inet 169.254.[0-9]*.[0-9]*/16 brd 169.254.255.255 scope link veth99')
self.assertRegex(output, 'inet 192.168.5.[0-9]*/24 brd 192.168.5.255 scope global dynamic veth99')
self.assertRegex(output, 'inet6 2600::[0-9a-f]*/128 scope global (dynamic noprefixroute|noprefixroute dynamic)')
self.assertRegex(output, 'inet6 .* scope link')
Expand All @@ -3007,7 +3005,6 @@ def test_dhcp_client_vrf(self):
output = check_output('ip route show vrf vrf99')
print(output)
self.assertRegex(output, 'default via 192.168.5.1 dev veth99 proto dhcp src 192.168.5.')
self.assertRegex(output, '169.254.0.0/16 dev veth99 proto kernel scope link src 169.254')
self.assertRegex(output, '192.168.5.0/24 dev veth99 proto kernel scope link src 192.168.5')
self.assertRegex(output, '192.168.5.0/24 via 192.168.5.5 dev veth99 proto dhcp')
self.assertRegex(output, '192.168.5.1 dev veth99 proto dhcp scope link src 192.168.5')
Expand Down

0 comments on commit 51214e7

Please sign in to comment.