networkd: drop DHCPv4 config on stop, keep on restart, by default

This partially reverts 95355a281c.

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.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2019-10-01 17:12:31 +02:00
parent ab76be5581
commit 800603524a
3 changed files with 10 additions and 8 deletions

View File

@ -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>

View File

@ -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");

View File

@ -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)