Skip to content

Commit

Permalink
networkd: drop DHCPv4 config on stop, keep on restart, by default
Browse files Browse the repository at this point in the history
This partially reverts 95355a2.

It seems that other parts of link_stop_clients() should be skipped
when restarting, but I don't know enough about those other clients to have
an opinion if it is better to stop&start them on restart or not.
Anyway, that can be done in later patches now that the support for restarts
is there.

Fixes #13625.
  • Loading branch information
keszybz committed Oct 2, 2019
1 parent ab76be5 commit 8006035
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
4 changes: 2 additions & 2 deletions man/systemd.network.xml
Original file line number Diff line number Diff line change
Expand Up @@ -876,8 +876,8 @@
lease expires. This is contrary to the DHCP specification, but may be the best choice if,
e.g., the root filesystem relies on this connection. The setting <literal>dhcp</literal>
implies <literal>dhcp-on-stop</literal>, and <literal>yes</literal> implies
<literal>dhcp</literal> and <literal>static</literal>. Defaults to
<literal>dhcp-on-stop</literal>.</para>
<literal>dhcp</literal> and <literal>static</literal>. Defaults to <literal>no</literal>.
</para>
</listitem>
</varlistentry>

Expand Down
8 changes: 6 additions & 2 deletions src/network/networkd-link.c
Original file line number Diff line number Diff line change
Expand Up @@ -770,8 +770,12 @@ int link_stop_clients(Link *link, bool may_keep_dhcp) {

dhcp4_release_old_lease(link);

if (link->dhcp_client && (!may_keep_dhcp || !link->network ||
!FLAGS_SET(link->network->keep_configuration, KEEP_CONFIGURATION_DHCP_ON_STOP))) {
bool keep_dhcp = may_keep_dhcp &&
link->network &&
(link->manager->restarting ||
FLAGS_SET(link->network->keep_configuration, KEEP_CONFIGURATION_DHCP_ON_STOP));

if (link->dhcp_client && !keep_dhcp) {
k = sd_dhcp_client_stop(link->dhcp_client);
if (k < 0)
r = log_link_warning_errno(link, k, "Could not stop DHCPv4 client: %m");
Expand Down
6 changes: 2 additions & 4 deletions src/network/networkd-network.c
Original file line number Diff line number Diff line change
Expand Up @@ -268,13 +268,11 @@ int network_verify(Network *network) {
/* CriticalConnection=yes also preserve foreign static configurations. */
network->keep_configuration = KEEP_CONFIGURATION_YES;
else
/* For backward compatibility, we do not release DHCP addresses on manager stop. */
network->keep_configuration = KEEP_CONFIGURATION_DHCP_ON_STOP;
network->keep_configuration = KEEP_CONFIGURATION_NO;
}

if (network->keep_configuration < 0)
/* For backward compatibility, we do not release DHCP addresses on manager stop. */
network->keep_configuration = KEEP_CONFIGURATION_DHCP_ON_STOP;
network->keep_configuration = KEEP_CONFIGURATION_NO;

LIST_FOREACH_SAFE(addresses, address, address_next, network->static_addresses)
if (address_section_verify(address) < 0)
Expand Down

0 comments on commit 8006035

Please sign in to comment.