network: add KeepConfiguration=dhcp-on-stop
The option prevents to drop lease address on stop. By setting this, we can safely restart networkd.
This commit is contained in:
parent
7da377ef16
commit
95355a281c
|
@ -680,14 +680,15 @@ static void link_enter_unmanaged(Link *link) {
|
||||||
link_dirty(link);
|
link_dirty(link);
|
||||||
}
|
}
|
||||||
|
|
||||||
int link_stop_clients(Link *link) {
|
int link_stop_clients(Link *link, bool may_keep_dhcp) {
|
||||||
int r = 0, k;
|
int r = 0, k;
|
||||||
|
|
||||||
assert(link);
|
assert(link);
|
||||||
assert(link->manager);
|
assert(link->manager);
|
||||||
assert(link->manager->event);
|
assert(link->manager->event);
|
||||||
|
|
||||||
if (link->dhcp_client) {
|
if (link->dhcp_client && (!may_keep_dhcp || !link->network ||
|
||||||
|
!FLAGS_SET(link->network->keep_configuration, KEEP_CONFIGURATION_DHCP_ON_STOP))) {
|
||||||
k = sd_dhcp_client_stop(link->dhcp_client);
|
k = sd_dhcp_client_stop(link->dhcp_client);
|
||||||
if (k < 0)
|
if (k < 0)
|
||||||
r = log_link_warning_errno(link, k, "Could not stop DHCPv4 client: %m");
|
r = log_link_warning_errno(link, k, "Could not stop DHCPv4 client: %m");
|
||||||
|
@ -731,7 +732,7 @@ void link_enter_failed(Link *link) {
|
||||||
|
|
||||||
link_set_state(link, LINK_STATE_FAILED);
|
link_set_state(link, LINK_STATE_FAILED);
|
||||||
|
|
||||||
link_stop_clients(link);
|
link_stop_clients(link, false);
|
||||||
|
|
||||||
link_dirty(link);
|
link_dirty(link);
|
||||||
}
|
}
|
||||||
|
@ -2579,7 +2580,7 @@ static int link_configure(Link *link) {
|
||||||
/* Drop foreign config, but ignore loopback or critical devices.
|
/* Drop foreign config, but ignore loopback or critical devices.
|
||||||
* We do not want to remove loopback address or addresses used for root NFS. */
|
* We do not want to remove loopback address or addresses used for root NFS. */
|
||||||
if (!(link->flags & IFF_LOOPBACK) &&
|
if (!(link->flags & IFF_LOOPBACK) &&
|
||||||
!(link->network->keep_configuration & (KEEP_CONFIGURATION_DHCP | KEEP_CONFIGURATION_STATIC))) {
|
!(link->network->keep_configuration & (KEEP_CONFIGURATION_DHCP_ON_START | KEEP_CONFIGURATION_STATIC))) {
|
||||||
r = link_drop_foreign_config(link);
|
r = link_drop_foreign_config(link);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
@ -3265,7 +3266,7 @@ static int link_carrier_lost(Link *link) {
|
||||||
if (link->setting_mtu)
|
if (link->setting_mtu)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
r = link_stop_clients(link);
|
r = link_stop_clients(link, false);
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
link_enter_failed(link);
|
link_enter_failed(link);
|
||||||
return r;
|
return r;
|
||||||
|
|
|
@ -175,7 +175,7 @@ int dhcp6_configure(Link *link);
|
||||||
int dhcp6_request_address(Link *link, int ir);
|
int dhcp6_request_address(Link *link, int ir);
|
||||||
int dhcp6_lease_pd_prefix_lost(sd_dhcp6_client *client, Link* link);
|
int dhcp6_lease_pd_prefix_lost(sd_dhcp6_client *client, Link* link);
|
||||||
|
|
||||||
int link_stop_clients(Link *link);
|
int link_stop_clients(Link *link, bool may_keep_dhcp);
|
||||||
|
|
||||||
const char* link_state_to_string(LinkState s) _const_;
|
const char* link_state_to_string(LinkState s) _const_;
|
||||||
LinkState link_state_from_string(const char *s) _pure_;
|
LinkState link_state_from_string(const char *s) _pure_;
|
||||||
|
|
|
@ -1447,7 +1447,7 @@ void manager_free(Manager *m) {
|
||||||
if (link->dhcp6_client)
|
if (link->dhcp6_client)
|
||||||
(void) dhcp6_lease_pd_prefix_lost(link->dhcp6_client, link);
|
(void) dhcp6_lease_pd_prefix_lost(link->dhcp6_client, link);
|
||||||
|
|
||||||
link_stop_clients(link);
|
(void) link_stop_clients(link, true);
|
||||||
|
|
||||||
link_unref(link);
|
link_unref(link);
|
||||||
}
|
}
|
||||||
|
|
|
@ -247,11 +247,13 @@ int network_verify(Network *network) {
|
||||||
/* CriticalConnection=yes also preserve foreign static configurations. */
|
/* CriticalConnection=yes also preserve foreign static configurations. */
|
||||||
network->keep_configuration = KEEP_CONFIGURATION_YES;
|
network->keep_configuration = KEEP_CONFIGURATION_YES;
|
||||||
else
|
else
|
||||||
network->keep_configuration = KEEP_CONFIGURATION_NO;
|
/* For backward compatibility, we do not release DHCP addresses on manager stop. */
|
||||||
|
network->keep_configuration = KEEP_CONFIGURATION_DHCP_ON_STOP;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (network->keep_configuration < 0)
|
if (network->keep_configuration < 0)
|
||||||
network->keep_configuration = KEEP_CONFIGURATION_NO;
|
/* For backward compatibility, we do not release DHCP addresses on manager stop. */
|
||||||
|
network->keep_configuration = KEEP_CONFIGURATION_DHCP_ON_STOP;
|
||||||
|
|
||||||
LIST_FOREACH_SAFE(addresses, address, address_next, network->static_addresses)
|
LIST_FOREACH_SAFE(addresses, address, address_next, network->static_addresses)
|
||||||
if (address_section_verify(address) < 0)
|
if (address_section_verify(address) < 0)
|
||||||
|
@ -1774,10 +1776,11 @@ DEFINE_CONFIG_PARSE_ENUM(config_parse_keep_configuration, keep_configuration, Ke
|
||||||
"Failed to parse KeepConfiguration= setting");
|
"Failed to parse KeepConfiguration= setting");
|
||||||
|
|
||||||
static const char* const keep_configuration_table[_KEEP_CONFIGURATION_MAX] = {
|
static const char* const keep_configuration_table[_KEEP_CONFIGURATION_MAX] = {
|
||||||
[KEEP_CONFIGURATION_NO] = "no",
|
[KEEP_CONFIGURATION_NO] = "no",
|
||||||
[KEEP_CONFIGURATION_DHCP] = "dhcp",
|
[KEEP_CONFIGURATION_DHCP_ON_STOP] = "dhcp-on-stop",
|
||||||
[KEEP_CONFIGURATION_STATIC] = "static",
|
[KEEP_CONFIGURATION_DHCP] = "dhcp",
|
||||||
[KEEP_CONFIGURATION_YES] = "yes",
|
[KEEP_CONFIGURATION_STATIC] = "static",
|
||||||
|
[KEEP_CONFIGURATION_YES] = "yes",
|
||||||
};
|
};
|
||||||
|
|
||||||
DEFINE_STRING_TABLE_LOOKUP_WITH_BOOLEAN(keep_configuration, KeepConfiguration, KEEP_CONFIGURATION_YES);
|
DEFINE_STRING_TABLE_LOOKUP_WITH_BOOLEAN(keep_configuration, KeepConfiguration, KEEP_CONFIGURATION_YES);
|
||||||
|
|
|
@ -79,10 +79,12 @@ typedef enum RADVPrefixDelegation {
|
||||||
} RADVPrefixDelegation;
|
} RADVPrefixDelegation;
|
||||||
|
|
||||||
typedef enum KeepConfiguration {
|
typedef enum KeepConfiguration {
|
||||||
KEEP_CONFIGURATION_NO = 0,
|
KEEP_CONFIGURATION_NO = 0,
|
||||||
KEEP_CONFIGURATION_DHCP = 1 << 0,
|
KEEP_CONFIGURATION_DHCP_ON_START = 1 << 0,
|
||||||
KEEP_CONFIGURATION_STATIC = 1 << 1,
|
KEEP_CONFIGURATION_DHCP_ON_STOP = 1 << 1,
|
||||||
KEEP_CONFIGURATION_YES = KEEP_CONFIGURATION_DHCP | KEEP_CONFIGURATION_STATIC,
|
KEEP_CONFIGURATION_DHCP = KEEP_CONFIGURATION_DHCP_ON_START | KEEP_CONFIGURATION_DHCP_ON_STOP,
|
||||||
|
KEEP_CONFIGURATION_STATIC = 1 << 2,
|
||||||
|
KEEP_CONFIGURATION_YES = KEEP_CONFIGURATION_DHCP | KEEP_CONFIGURATION_STATIC,
|
||||||
_KEEP_CONFIGURATION_MAX,
|
_KEEP_CONFIGURATION_MAX,
|
||||||
_KEEP_CONFIGURATION_INVALID = -1,
|
_KEEP_CONFIGURATION_INVALID = -1,
|
||||||
} KeepConfiguration;
|
} KeepConfiguration;
|
||||||
|
|
Loading…
Reference in a new issue