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>no</literal>.
- </para>
+ <literal>dhcp</literal> and <literal>static</literal>. Defaults to
+ <literal>dhcp-on-stop</literal> when <command>systemd-networkd</command> is running in
+ initrd, <literal>yes</literal> when the root filesystem is a network filesystem, and
+ <literal>no</literal> otherwise.</para>
</listitem>
</varlistentry>
</variablelist>
return sd_event_exit(sd_event_source_get_event(s), 0);
}
+static int manager_set_keep_configuration(Manager *m) {
+ int r;
+
+ 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;
+ return 0;
+ }
+
+ r = path_is_network_fs("/");
+ if (r < 0)
+ return log_error_errno(r, "Failed to detect if root is network filesystem: %m");
+ if (r == 0) {
+ m->keep_configuration = _KEEP_CONFIGURATION_INVALID;
+ return 0;
+ }
+
+ log_debug("Running on network filesystem, enabling KeepConfiguration= by default.");
+ m->keep_configuration = KEEP_CONFIGURATION_YES;
+ return 0;
+}
+
int manager_setup(Manager *m) {
int r;
if (r < 0)
return r;
+ r = manager_set_keep_configuration(m);
+ if (r < 0)
+ return r;
+
m->state_file = strdup("/run/systemd/netif/state");
if (!m->state_file)
return -ENOMEM;
return -ENOMEM;
*m = (Manager) {
+ .keep_configuration = _KEEP_CONFIGURATION_INVALID,
.test_mode = test_mode,
.speed_meter_interval_usec = SPEED_METER_DEFAULT_TIME_INTERVAL,
.online_state = _LINK_ONLINE_STATE_INVALID,
Hashmap *polkit_registry;
int ethtool_fd;
+ KeepConfiguration keep_configuration;
+
bool test_mode;
bool enumerating;
bool dirty;
int r;
assert(network);
+ assert(network->manager);
assert(network->filename);
if (net_match_is_empty(&network->match) && !network->conditions)
}
if (network->dhcp_critical >= 0) {
- if (network->keep_configuration >= 0)
- log_warning("%s: Both KeepConfiguration= and deprecated CriticalConnection= are set. "
- "Ignoring CriticalConnection=.", network->filename);
- else if (network->dhcp_critical)
+ if (network->keep_configuration >= 0) {
+ if (network->manager->keep_configuration < 0)
+ log_warning("%s: Both KeepConfiguration= and deprecated CriticalConnection= are set. "
+ "Ignoring CriticalConnection=.", network->filename);
+ } else if (network->dhcp_critical)
/* CriticalConnection=yes also preserve foreign static configurations. */
network->keep_configuration = KEEP_CONFIGURATION_YES;
else
.allmulticast = -1,
.promiscuous = -1,
- .keep_configuration = _KEEP_CONFIGURATION_INVALID,
+ .keep_configuration = manager->keep_configuration,
.dhcp_duid.type = _DUID_TYPE_INVALID,
.dhcp_critical = -1,
#include "net-condition.h"
#include "networkd-address.h"
#include "networkd-conf.h"
+#include "networkd-manager.h"
#include "networkd-network.h"
#include "strv.h"
}
static void test_config_parse_address_one(const char *rvalue, int family, unsigned n_addresses, const union in_addr_union *u, unsigned char prefixlen) {
+ _cleanup_(manager_freep) Manager *manager = NULL;
_cleanup_(network_unrefp) Network *network = NULL;
+ assert_se(manager_new(&manager, /* test_mode = */ true) >= 0);
assert_se(network = new0(Network, 1));
network->n_ref = 1;
+ network->manager = manager;
assert_se(network->filename = strdup("hogehoge.network"));
+
assert_se(config_parse_match_ifnames("network", "filename", 1, "section", 1, "Name", 0, "*", &network->match.ifname, network) == 0);
assert_se(config_parse_address("network", "filename", 1, "section", 1, "Address", 0, rvalue, network, network) == 0);
assert_se(ordered_hashmap_size(network->addresses_by_section) == 1);