summaryrefslogtreecommitdiff
path: root/src/networkd.c
diff options
context:
space:
mode:
authorƁukasz Zemczak <sil2100@vexillium.org>2021-06-15 16:10:55 +0200
committerGitHub <noreply@github.com>2021-06-15 16:10:55 +0200
commit2a7fc684eb6f2ec1c81b6a802796ec66a8cbf965 (patch)
treea9689f35a73a2f576df950f44f9f97779cfff729 /src/networkd.c
parent44dab84ab91c314504d3a0d2f5db851ec45e6077 (diff)
Implicitly consider devices with activation-mode set as optional (#214)
When the networkd backend is used, whenever an interface defines activation-mode it also needs to be implicitly marked as optional. Both of the available activation-mode states end up with the interface not being brought up by networkd on boot, and this can cause systemd to wait indefinitely for the interface to go online during wait-online. Currently systemd doesn't make this NeededForOnline=no assumption for us, so we need to do it ourselves. I tried re-using the existing code for marking as optional not to duplicate too much code, so it's basically just moving stuff around.
Diffstat (limited to 'src/networkd.c')
-rw-r--r--src/networkd.c28
1 files changed, 17 insertions, 11 deletions
diff --git a/src/networkd.c b/src/networkd.c
index 0b4ff59..98e107b 100644
--- a/src/networkd.c
+++ b/src/networkd.c
@@ -549,6 +549,7 @@ write_network_file(const NetplanNetDefinition* def, const char* rootdir, const c
GString* link = NULL;
GString* s = NULL;
mode_t orig_umask;
+ gboolean is_optional = def->optional;
if (def->type == NETPLAN_DEF_TYPE_VLAN && def->sriov_vlan_filter) {
g_debug("%s is defined as a hardware SR-IOV filtered VLAN, postponing creation", def->id);
@@ -561,17 +562,6 @@ write_network_file(const NetplanNetDefinition* def, const char* rootdir, const c
/* Prepare the [Network] section */
network = g_string_sized_new(200);
- if (def->optional || def->optional_addresses) {
- if (def->optional) {
- g_string_append(link, "RequiredForOnline=no\n");
- }
- for (unsigned i = 0; NETPLAN_OPTIONAL_ADDRESS_TYPES[i].name != NULL; ++i) {
- if (def->optional_addresses & NETPLAN_OPTIONAL_ADDRESS_TYPES[i].flag) {
- g_string_append_printf(link, "OptionalAddresses=%s\n", NETPLAN_OPTIONAL_ADDRESS_TYPES[i].name);
- }
- }
- }
-
/* The ActivationPolicy setting is available in systemd v248+ */
if (def->activation_mode) {
const char* mode;
@@ -580,6 +570,22 @@ write_network_file(const NetplanNetDefinition* def, const char* rootdir, const c
else /* "off" */
mode = "always-down";
g_string_append_printf(link, "ActivationPolicy=%s\n", mode);
+ /* When activation-mode is used we default to being optional.
+ * Otherwise systemd might wait indefinitely for the interface to
+ * become online.
+ */
+ is_optional = TRUE;
+ }
+
+ if (is_optional || def->optional_addresses) {
+ if (is_optional) {
+ g_string_append(link, "RequiredForOnline=no\n");
+ }
+ for (unsigned i = 0; NETPLAN_OPTIONAL_ADDRESS_TYPES[i].name != NULL; ++i) {
+ if (def->optional_addresses & NETPLAN_OPTIONAL_ADDRESS_TYPES[i].flag) {
+ g_string_append_printf(link, "OptionalAddresses=%s\n", NETPLAN_OPTIONAL_ADDRESS_TYPES[i].name);
+ }
+ }
}
if (def->mtubytes)