From f6d654b18f059a0fe2ba82ae05c0c22295c86af4 Mon Sep 17 00:00:00 2001 From: Beniamino Galvani Date: Mon, 22 Jun 2020 11:56:51 +0200 Subject: [PATCH 1/2] initrd: generate connections with IPv6 method 'auto' instead of 'ignore' When the initrd generator creates a connection with IPv6 method 'ignore', the kernel will do IPv6 autoconfiguration on the interface. However, it is preferable to let NetworkManager configure the interface directly instead of relying on kernel. Therefore, change the IPv6 method to 'auto'. Note that we still set ipv6.may-fail to 'yes' so that a failure during IPv6 autoconfiguration doesn't bring down the interface. --- src/initrd/nmi-cmdline-reader.c | 2 +- src/initrd/tests/test-cmdline-reader.c | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/initrd/nmi-cmdline-reader.c b/src/initrd/nmi-cmdline-reader.c index 7513b4c976..2f4a8582fb 100644 --- a/src/initrd/nmi-cmdline-reader.c +++ b/src/initrd/nmi-cmdline-reader.c @@ -479,7 +479,7 @@ reader_parse_ip (Reader *reader, const char *sysfs_dir, char *argument) NULL); if (nm_setting_ip_config_get_num_addresses (s_ip6) == 0) { g_object_set (s_ip6, - NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, + NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_AUTO, NULL); } } else if (nm_streq0 (kind, "dhcp6")) { diff --git a/src/initrd/tests/test-cmdline-reader.c b/src/initrd/tests/test-cmdline-reader.c index 5379c3a3bf..74a6e65cd2 100644 --- a/src/initrd/tests/test-cmdline-reader.c +++ b/src/initrd/tests/test-cmdline-reader.c @@ -191,6 +191,7 @@ test_if_ip4_manual (void) "hostname1.example.com:eth4"); NMConnection *connection; NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; NMIPAddress *ip_addr; gs_free char *hostname = NULL; @@ -237,6 +238,11 @@ test_if_ip4_manual (void) g_assert_cmpint (nm_ip_address_get_prefix (ip_addr), ==, 26); g_assert_cmpstr (nm_setting_ip_config_get_gateway (s_ip4), ==, "203.0.113.1"); g_assert_cmpstr (nm_setting_ip_config_get_dhcp_hostname (s_ip4), ==, "hostname1.example.com"); + + 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 (nm_setting_ip_config_get_may_fail (s_ip6)); } static void @@ -1086,7 +1092,7 @@ test_bootif (void) 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_IGNORE); + g_assert_cmpstr (nm_setting_ip_config_get_method (s_ip6), ==, NM_SETTING_IP6_CONFIG_METHOD_AUTO); g_assert (!nm_setting_ip_config_get_ignore_auto_dns (s_ip6)); } @@ -1124,7 +1130,7 @@ test_bootif_hwtype (void) 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_IGNORE); + g_assert_cmpstr (nm_setting_ip_config_get_method (s_ip6), ==, NM_SETTING_IP6_CONFIG_METHOD_AUTO); g_assert (!nm_setting_ip_config_get_ignore_auto_dns (s_ip6)); connection = g_hash_table_lookup (connections, "bootif_connection"); From a39eb9ac148dc5566a908d65833033d74da8f16d Mon Sep 17 00:00:00 2001 From: Beniamino Galvani Date: Mon, 22 Jun 2020 12:00:22 +0200 Subject: [PATCH 2/2] initrd: set ipv6.method=auto when the autoconfiguration field is 'none' The 7th field of: ip=:[]:::::{none|off|dhcp|on|any|dhcp6|auto6|ibft}:[:[][:]] specifies which kind of autoconfiguration to do. 'none' and 'off' mean static addresses. The old network module of dracut used to leave kernel IPv6 autoconfiguration enabled when IPv4 static addresses were configured. With NM, this corresponds to enabling IPv6 auto method. https://bugzilla.redhat.com/show_bug.cgi?id=1848943 --- src/initrd/nmi-cmdline-reader.c | 2 +- src/initrd/tests/test-cmdline-reader.c | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/initrd/nmi-cmdline-reader.c b/src/initrd/nmi-cmdline-reader.c index 2f4a8582fb..69e5e56d07 100644 --- a/src/initrd/nmi-cmdline-reader.c +++ b/src/initrd/nmi-cmdline-reader.c @@ -464,7 +464,7 @@ reader_parse_ip (Reader *reader, const char *sysfs_dir, char *argument) if (NM_IN_STRSET (kind, "none", "off")) { if (nm_setting_ip_config_get_num_addresses (s_ip6) == 0) { g_object_set (s_ip6, - NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_DISABLED, + NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_AUTO, NULL); } if (nm_setting_ip_config_get_num_addresses (s_ip4) == 0) { diff --git a/src/initrd/tests/test-cmdline-reader.c b/src/initrd/tests/test-cmdline-reader.c index 74a6e65cd2..110770554c 100644 --- a/src/initrd/tests/test-cmdline-reader.c +++ b/src/initrd/tests/test-cmdline-reader.c @@ -186,7 +186,7 @@ test_if_ip4_manual (void) { gs_unref_hashtable GHashTable *connections = NULL; const char *const*ARGV = NM_MAKE_STRV ("ip=192.0.2.2::192.0.2.1:255.255.255.0:" - "hostname0.example.com:eth3::192.0.2.53", + "hostname0.example.com:eth3:none:192.0.2.53", "ip=203.0.113.2::203.0.113.1:26:" "hostname1.example.com:eth4"); NMConnection *connection; @@ -220,6 +220,11 @@ test_if_ip4_manual (void) g_assert_cmpstr (nm_setting_ip_config_get_gateway (s_ip4), ==, "192.0.2.1"); g_assert_cmpstr (nm_setting_ip_config_get_dhcp_hostname (s_ip4), ==, "hostname0.example.com"); + 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 (nm_setting_ip_config_get_may_fail (s_ip6)); + connection = g_hash_table_lookup (connections, "eth4"); g_assert (connection); nmtst_assert_connection_verifies_without_normalization (connection);