network: rename KeepConfiguration=dhcp -> dynamic

KeepConfiguration=dhcp keeps not only DHCP configurations but
also SLAAC or IPV4LL. Let's rename the value to 'dynamic'.
This commit is contained in:
Yu Watanabe 2024-11-05 12:14:01 +09:00
parent d13ce4ea0d
commit 80a89d1ad5
9 changed files with 79 additions and 41 deletions

View File

@ -1274,8 +1274,8 @@ bool link_address_is_dynamic(const Link *link, const Address *address) {
if (address->family != AF_INET)
return false;
/* Even when the address is leased from a DHCP server, networkd assign the address
* without lifetime when KeepConfiguration=dhcp. So, let's check that we have
/* Even if an IPv4 address is leased from a DHCP server with a finite lifetime, networkd assign the
* address without lifetime when KeepConfiguration=dynamic. So, let's check that we have
* corresponding routes with RTPROT_DHCP. */
SET_FOREACH(route, link->manager->routes) {
if (route->source != NETWORK_CONFIG_SOURCE_FOREIGN)
@ -1410,9 +1410,9 @@ int link_drop_unmanaged_addresses(Link *link) {
continue;
/* link_address_is_dynamic() is slightly heavy. Let's call the function only when
* KeepConfiguration=dhcp or static. */
if (IN_SET(link->network->keep_configuration, KEEP_CONFIGURATION_DHCP, KEEP_CONFIGURATION_STATIC) &&
link_address_is_dynamic(link, address) == (link->network->keep_configuration == KEEP_CONFIGURATION_DHCP))
* KeepConfiguration=dynamic or static. */
if (IN_SET(link->network->keep_configuration, KEEP_CONFIGURATION_DYNAMIC, KEEP_CONFIGURATION_STATIC) &&
link_address_is_dynamic(link, address) == (link->network->keep_configuration == KEEP_CONFIGURATION_DYNAMIC))
continue;
} else if (address->source != NETWORK_CONFIG_SOURCE_STATIC)

View File

@ -915,7 +915,7 @@ static int dhcp4_request_address(Link *link, bool announce) {
if (r < 0)
return log_link_debug_errno(link, r, "DHCP error: failed to get DHCP server IP address: %m");
if (!FLAGS_SET(link->network->keep_configuration, KEEP_CONFIGURATION_DHCP)) {
if (!FLAGS_SET(link->network->keep_configuration, KEEP_CONFIGURATION_DYNAMIC)) {
r = sd_dhcp_lease_get_lifetime_timestamp(link->dhcp_lease, CLOCK_BOOTTIME, &lifetime_usec);
if (r < 0)
return log_link_warning_errno(link, r, "DHCP error: failed to get lifetime: %m");
@ -1168,7 +1168,7 @@ static int dhcp4_handler(sd_dhcp_client *client, int event, void *userdata) {
switch (event) {
case SD_DHCP_CLIENT_EVENT_STOP:
if (FLAGS_SET(link->network->keep_configuration, KEEP_CONFIGURATION_DHCP)) {
if (FLAGS_SET(link->network->keep_configuration, KEEP_CONFIGURATION_DYNAMIC)) {
log_link_notice(link, "DHCPv4 connection considered critical, ignoring request to reconfigure it.");
return 0;
}
@ -1199,7 +1199,7 @@ static int dhcp4_handler(sd_dhcp_client *client, int event, void *userdata) {
break;
case SD_DHCP_CLIENT_EVENT_EXPIRED:
if (FLAGS_SET(link->network->keep_configuration, KEEP_CONFIGURATION_DHCP)) {
if (FLAGS_SET(link->network->keep_configuration, KEEP_CONFIGURATION_DYNAMIC)) {
log_link_notice(link, "DHCPv4 connection considered critical, ignoring request to reconfigure it.");
return 0;
}
@ -1214,7 +1214,7 @@ static int dhcp4_handler(sd_dhcp_client *client, int event, void *userdata) {
break;
case SD_DHCP_CLIENT_EVENT_IP_CHANGE:
if (FLAGS_SET(link->network->keep_configuration, KEEP_CONFIGURATION_DHCP)) {
if (FLAGS_SET(link->network->keep_configuration, KEEP_CONFIGURATION_DYNAMIC)) {
log_link_notice(link, "DHCPv4 connection considered critical, ignoring request to reconfigure it.");
return 0;
}
@ -1400,8 +1400,8 @@ static int dhcp4_set_request_address(Link *link) {
return sd_dhcp_client_set_request_address(link->dhcp_client, &link->network->dhcp_request_address);
}
/* 3. If KeepConfiguration=dhcp, use a foreign dynamic address. */
if (!FLAGS_SET(link->network->keep_configuration, KEEP_CONFIGURATION_DHCP))
/* 3. If KeepConfiguration=dynamic, use a foreign dynamic address. */
if (!FLAGS_SET(link->network->keep_configuration, KEEP_CONFIGURATION_DYNAMIC))
return 0;
SET_FOREACH(a, link->addresses) {

View File

@ -195,8 +195,8 @@ static int ipv4ll_set_address(Link *link) {
if (in4_addr_is_set(&link->network->ipv4ll_start_address))
return sd_ipv4ll_set_address(link->ipv4ll, &link->network->ipv4ll_start_address);
/* 3. If KeepConfiguration=dhcp, use a foreign IPv4LL address. */
if (!FLAGS_SET(link->network->keep_configuration, KEEP_CONFIGURATION_DHCP))
/* 3. If KeepConfiguration=dynamic, use a foreign IPv4LL address. */
if (!FLAGS_SET(link->network->keep_configuration, KEEP_CONFIGURATION_DYNAMIC))
return 0;
SET_FOREACH(a, link->addresses) {

View File

@ -369,20 +369,20 @@ void link_set_state(Link *link, LinkState state) {
link_dirty(link);
}
int link_stop_engines(Link *link, bool may_keep_dhcp) {
int link_stop_engines(Link *link, bool may_keep_dynamic) {
int r, ret = 0;
assert(link);
assert(link->manager);
assert(link->manager->event);
bool keep_dhcp =
may_keep_dhcp &&
bool keep_dynamic =
may_keep_dynamic &&
link->network &&
(link->manager->state == MANAGER_RESTARTING ||
FLAGS_SET(link->network->keep_configuration, KEEP_CONFIGURATION_DHCP_ON_STOP));
FLAGS_SET(link->network->keep_configuration, KEEP_CONFIGURATION_DYNAMIC_ON_STOP));
if (!keep_dhcp) {
if (!keep_dynamic) {
r = sd_dhcp_client_stop(link->dhcp_client);
if (r < 0)
RET_GATHER(ret, log_link_warning_errno(link, r, "Could not stop DHCPv4 client: %m"));
@ -449,7 +449,7 @@ void link_enter_failed(Link *link) {
return;
stop:
(void) link_stop_engines(link, /* may_keep_dhcp = */ false);
(void) link_stop_engines(link, /* may_keep_dynamic = */ false);
}
void link_check_ready(Link *link) {
@ -1339,7 +1339,7 @@ static void link_enter_unmanaged(Link *link) {
log_link_full(link, link->state == LINK_STATE_INITIALIZED ? LOG_DEBUG : LOG_INFO,
"Unmanaging interface.");
(void) link_stop_engines(link, /* may_keep_dhcp = */ false);
(void) link_stop_engines(link, /* may_keep_dynamic = */ false);
(void) link_drop_requests(link);
(void) link_drop_static_config(link);
@ -1410,10 +1410,10 @@ int link_reconfigure_impl(Link *link, LinkReconfigurationFlag flags) {
/* Then, apply new .network file */
link->network = network_ref(network);
if (FLAGS_SET(network->keep_configuration, KEEP_CONFIGURATION_DHCP) ||
if (FLAGS_SET(network->keep_configuration, KEEP_CONFIGURATION_DYNAMIC) ||
!FLAGS_SET(flags, LINK_RECONFIGURE_CLEANLY)) {
/* To make 'networkctl reconfigure INTERFACE' work safely for an interface whose new .network
* file has KeepConfiguration=dhcp or yes, even if a clean reconfiguration is requested,
* file has KeepConfiguration=dynamic or yes, even if a clean reconfiguration is requested,
* drop only unnecessary or possibly being changed dynamic configurations here. */
r = link_drop_dynamic_config(link, old_network);
if (r < 0)
@ -1799,7 +1799,7 @@ static int link_carrier_lost_impl(Link *link) {
if (!link->network)
return ret;
RET_GATHER(ret, link_stop_engines(link, false));
RET_GATHER(ret, link_stop_engines(link, /* may_keep_dynamic = */ false));
RET_GATHER(ret, link_drop_static_config(link));
return ret;

View File

@ -257,7 +257,7 @@ bool link_ipv6_enabled(Link *link);
int link_ipv6ll_gained(Link *link);
bool link_has_ipv6_connectivity(Link *link);
int link_stop_engines(Link *link, bool may_keep_dhcp);
int link_stop_engines(Link *link, bool may_keep_dynamic);
const char* link_state_to_string(LinkState s) _const_;
LinkState link_state_from_string(const char *s) _pure_;

View File

@ -481,7 +481,7 @@ static int manager_stop(Manager *manager, ManagerState state) {
Link *link;
HASHMAP_FOREACH(link, manager->links_by_index)
(void) link_stop_engines(link, /* may_keep_dhcp = */ true);
(void) link_stop_engines(link, /* may_keep_dynamic = */ true);
return 0;
}
@ -508,8 +508,8 @@ static int manager_set_keep_configuration(Manager *m) {
assert(m);
if (in_initrd()) {
log_debug("Running in initrd, keep DHCPv4 addresses on stopping networkd by default.");
m->keep_configuration = KEEP_CONFIGURATION_DHCP_ON_STOP;
log_debug("Running in initrd, keep dynamically assigned configurations on stopping networkd by default.");
m->keep_configuration = KEEP_CONFIGURATION_DYNAMIC_ON_STOP;
return 0;
}

View File

@ -1093,15 +1093,53 @@ int config_parse_ignore_carrier_loss(
return 0;
}
int config_parse_keep_configuration(
const char *unit,
const char *filename,
unsigned line,
const char *section,
unsigned section_line,
const char *lvalue,
int ltype,
const char *rvalue,
void *data,
void *userdata) {
KeepConfiguration t, *k = ASSERT_PTR(data);
Network *network = ASSERT_PTR(userdata);
if (isempty(rvalue)) {
*k = ASSERT_PTR(network->manager)->keep_configuration;
return 0;
}
/* backward compatibility */
if (streq(rvalue, "dhcp")) {
*k = KEEP_CONFIGURATION_DYNAMIC;
return 0;
}
if (streq(rvalue, "dhcp-on-stop")) {
*k = KEEP_CONFIGURATION_DYNAMIC_ON_STOP;
return 0;
}
t = keep_configuration_from_string(rvalue);
if (t < 0)
return log_syntax_parse_error(unit, filename, line, t, lvalue, rvalue);
*k = t;
return 0;
}
DEFINE_CONFIG_PARSE_ENUM(config_parse_required_family_for_online, link_required_address_family, AddressFamily);
DEFINE_CONFIG_PARSE_ENUM(config_parse_keep_configuration, keep_configuration, KeepConfiguration);
static const char* const keep_configuration_table[_KEEP_CONFIGURATION_MAX] = {
[KEEP_CONFIGURATION_NO] = "no",
[KEEP_CONFIGURATION_DHCP_ON_STOP] = "dhcp-on-stop",
[KEEP_CONFIGURATION_DHCP] = "dhcp",
[KEEP_CONFIGURATION_STATIC] = "static",
[KEEP_CONFIGURATION_YES] = "yes",
[KEEP_CONFIGURATION_NO] = "no",
[KEEP_CONFIGURATION_DYNAMIC_ON_STOP] = "dynamic-on-stop",
[KEEP_CONFIGURATION_DYNAMIC] = "dynamic",
[KEEP_CONFIGURATION_STATIC] = "static",
[KEEP_CONFIGURATION_YES] = "yes",
};
DEFINE_STRING_TABLE_LOOKUP_WITH_BOOLEAN(keep_configuration, KeepConfiguration, KEEP_CONFIGURATION_YES);

View File

@ -32,14 +32,14 @@
#include "socket-netlink.h"
typedef enum KeepConfiguration {
KEEP_CONFIGURATION_NO = 0,
KEEP_CONFIGURATION_DHCP_ON_START = 1 << 0,
KEEP_CONFIGURATION_DHCP_ON_STOP = 1 << 1,
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_NO = 0,
KEEP_CONFIGURATION_DYNAMIC_ON_START = 1 << 0,
KEEP_CONFIGURATION_DYNAMIC_ON_STOP = 1 << 1,
KEEP_CONFIGURATION_DYNAMIC = KEEP_CONFIGURATION_DYNAMIC_ON_START | KEEP_CONFIGURATION_DYNAMIC_ON_STOP,
KEEP_CONFIGURATION_STATIC = 1 << 2,
KEEP_CONFIGURATION_YES = KEEP_CONFIGURATION_DYNAMIC | KEEP_CONFIGURATION_STATIC,
_KEEP_CONFIGURATION_MAX,
_KEEP_CONFIGURATION_INVALID = -EINVAL,
_KEEP_CONFIGURATION_INVALID = -EINVAL,
} KeepConfiguration;
typedef enum ActivationPolicy {

View File

@ -1486,7 +1486,7 @@ int link_drop_routes(Link *link, bool only_static) {
continue;
if (IN_SET(route->protocol, RTPROT_DHCP, RTPROT_RA, RTPROT_REDIRECT) &&
FLAGS_SET(link->network->keep_configuration, KEEP_CONFIGURATION_DHCP))
FLAGS_SET(link->network->keep_configuration, KEEP_CONFIGURATION_DYNAMIC))
continue;
}
}