summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBeniamino Galvani <bgalvani@redhat.com>2021-02-12 09:50:48 +0100
committerBeniamino Galvani <bgalvani@redhat.com>2021-02-17 11:20:17 +0100
commit7e126fe898f130f53f3e5cb2f87eca2169978b4d (patch)
tree88e6e507d79deee6530a1304bcd569a352edc499
parente258410c877ee081a19f38653d20d884d3923d04 (diff)
downloadNetworkManager-7e126fe898f130f53f3e5cb2f87eca2169978b4d.tar.gz
initrd: set autoconnect-retries=1 and increase default DHCP timeout
By default a connection is retried 4 times before it is blocked from autoconnecting. This means that if a user specifies an explicit DHCP timeout in the initrd command line, NM will wait up to 4 times more. Instead, set the "connection.autoconnect-retries" property of connections always to 1, so that NM only waits for the time specified. Before this commit a default DHCP connection would take at most (45 x 4) seconds. Since the multiplier is now only 1, also increase the DHCP timeout to have a total time of (90 x 1) seconds, which is the half than before. https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/559
-rw-r--r--src/core/initrd/nmi-cmdline-reader.c6
-rw-r--r--src/core/initrd/tests/test-cmdline-reader.c59
2 files changed, 64 insertions, 1 deletions
diff --git a/src/core/initrd/nmi-cmdline-reader.c b/src/core/initrd/nmi-cmdline-reader.c
index c83473d140..4fa97cc213 100644
--- a/src/core/initrd/nmi-cmdline-reader.c
+++ b/src/core/initrd/nmi-cmdline-reader.c
@@ -53,6 +53,7 @@ reader_new(void)
g_hash_table_new_full(nm_direct_hash, NULL, g_object_unref, NULL),
.vlan_parents = g_ptr_array_new_with_free_func(g_free),
.array = g_ptr_array_new(),
+ .dhcp_timeout = 90,
};
return reader;
@@ -147,6 +148,8 @@ reader_create_connection(Reader * reader,
type_name,
NM_SETTING_CONNECTION_MULTI_CONNECT,
multi_connect,
+ NM_SETTING_CONNECTION_AUTOCONNECT_RETRIES,
+ 1,
NULL);
if (nm_streq0(type_name, NM_SETTING_INFINIBAND_SETTING_NAME)) {
@@ -1075,7 +1078,8 @@ nmi_cmdline_reader_parse(const char * sysfs_dir,
else if (nm_streq(tag, "rd.peerdns"))
reader->ignore_auto_dns = !_nm_utils_ascii_str_to_bool(argument, TRUE);
else if (nm_streq(tag, "rd.net.timeout.dhcp")) {
- reader->dhcp_timeout = _nm_utils_ascii_str_to_int64(argument, 10, 0, G_MAXINT32, 0);
+ reader->dhcp_timeout =
+ _nm_utils_ascii_str_to_int64(argument, 10, 1, G_MAXINT32, reader->dhcp_timeout);
} else if (nm_streq(tag, "rd.net.dhcp.vendor-class")) {
if (nm_utils_validate_dhcp4_vendor_class_id(argument, NULL))
nm_utils_strdup_reset(&reader->dhcp4_vci, argument);
diff --git a/src/core/initrd/tests/test-cmdline-reader.c b/src/core/initrd/tests/test-cmdline-reader.c
index cb65cd33b1..6f3dd1a504 100644
--- a/src/core/initrd/tests/test-cmdline-reader.c
+++ b/src/core/initrd/tests/test-cmdline-reader.c
@@ -230,10 +230,63 @@ test_dhcp_with_mtu(void)
}
static void
+test_dhcp_timeout(void)
+{
+ struct {
+ const char *const *cmdline;
+ int timeout;
+ } data[] = {
+ {NM_MAKE_STRV("ip=dhcp"), 90},
+ {NM_MAKE_STRV("ip=dhcp", "rd.net.timeout.dhcp=0"), 90},
+ {NM_MAKE_STRV("ip=dhcp", "rd.net.timeout.dhcp=foobar"), 90},
+ {NM_MAKE_STRV("ip=dhcp", "rd.net.timeout.dhcp=42"), 42},
+ };
+ guint i;
+
+ for (i = 0; i < G_N_ELEMENTS(data); i++) {
+ gs_unref_object NMConnection *connection = NULL;
+ NMSettingConnection * s_con;
+ NMSettingIPConfig * s_ip4;
+ NMSettingIPConfig * s_ip6;
+
+ connection = _parse_con(data[i].cmdline, "default_connection");
+
+ s_con = nm_connection_get_setting_connection(connection);
+ g_assert(s_con);
+ g_assert_cmpstr(nm_setting_connection_get_connection_type(s_con),
+ ==,
+ NM_SETTING_WIRED_SETTING_NAME);
+ g_assert_cmpstr(nm_setting_connection_get_id(s_con), ==, "Wired Connection");
+ g_assert_cmpint(nm_setting_connection_get_timestamp(s_con), ==, 0);
+ g_assert_cmpint(nm_setting_connection_get_multi_connect(s_con),
+ ==,
+ NM_CONNECTION_MULTI_CONNECT_MULTIPLE);
+ g_assert_cmpint(nm_setting_connection_get_wait_device_timeout(s_con), ==, -1);
+ g_assert_cmpint(nm_setting_connection_get_autoconnect_retries(s_con), ==, 1);
+ g_assert(nm_setting_connection_get_autoconnect(s_con));
+
+ s_ip4 = nm_connection_get_setting_ip4_config(connection);
+ g_assert(s_ip4);
+ g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip4),
+ ==,
+ NM_SETTING_IP4_CONFIG_METHOD_AUTO);
+ g_assert_cmpint(nm_setting_ip_config_get_dhcp_timeout(s_ip4), ==, data[i].timeout);
+
+ s_ip6 = nm_connection_get_setting_ip6_config(connection);
+ g_assert(s_ip6);
+ g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip6),
+ ==,
+ NM_SETTING_IP6_CONFIG_METHOD_AUTO);
+ g_assert_cmpint(nm_setting_ip_config_get_dhcp_timeout(s_ip6), ==, data[i].timeout);
+ }
+}
+
+static void
test_if_auto_with_mtu(void)
{
const char *const *ARGV = NM_MAKE_STRV("ip=eth0:auto:1666");
gs_unref_object NMConnection *connection = NULL;
+ NMSettingConnection * s_con;
NMSettingWired * s_wired;
NMSettingIPConfig * s_ip4;
NMSettingIPConfig * s_ip6;
@@ -242,6 +295,10 @@ test_if_auto_with_mtu(void)
g_assert_cmpstr(nm_connection_get_id(connection), ==, "eth0");
+ s_con = nm_connection_get_setting_connection(connection);
+ g_assert(s_con);
+ g_assert_cmpint(nm_setting_connection_get_autoconnect_retries(s_con), ==, 1);
+
s_wired = nm_connection_get_setting_wired(connection);
g_assert(s_wired);
g_assert_cmpint(nm_setting_wired_get_mtu(s_wired), ==, 1666);
@@ -250,6 +307,7 @@ test_if_auto_with_mtu(void)
g_assert(s_ip4);
g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_AUTO);
g_assert(!nm_setting_ip_config_get_ignore_auto_dns(s_ip4));
+ g_assert_cmpint(nm_setting_ip_config_get_dhcp_timeout(s_ip4), ==, 90);
s_ip6 = nm_connection_get_setting_ip6_config(connection);
g_assert(s_ip6);
@@ -2074,6 +2132,7 @@ main(int argc, char **argv)
g_test_add_func("/initrd/cmdline/auto", test_auto);
g_test_add_func("/initrd/cmdline/dhcp_with_hostname", test_dhcp_with_hostname);
g_test_add_func("/initrd/cmdline/dhcp_with_mtu", test_dhcp_with_mtu);
+ g_test_add_func("/initrd/cmdline/dhcp_timeout", test_dhcp_timeout);
g_test_add_func("/initrd/cmdline/if_auto_with_mtu", test_if_auto_with_mtu);
g_test_add_func("/initrd/cmdline/if_dhcp6", test_if_dhcp6);
g_test_add_func("/initrd/cmdline/if_auto_with_mtu_and_mac", test_if_auto_with_mtu_and_mac);