From 5eadbb29c74fb9d252bd74de9d9b3a6bbe967b8a Mon Sep 17 00:00:00 2001 From: Beniamino Galvani Date: Fri, 26 Mar 2021 07:26:55 +0100 Subject: [PATCH] Revert "initrd: set the bootif MAC in existing connection with ifname" This reverts commit 389575a6b137bdd4601de2d52286052e68c0c5da. When the command line contains BOOTIF and there is another ip= argument specifying an interface name, we can follow 2 approaches: a) BOOTIF creates a new distinct connection with DHCP (the behaviour before the commit) b) the connection generated for ip= will be also be bound to the BOOTIF MAC (the behavior introduced by the commit) Restore a) because we can't be sure that the MAC address refers to the same interface. In that case it's preferable to generate a different connection. https://bugzilla.redhat.com/show_bug.cgi?id=1915493#c35 (cherry picked from commit c21d4ce125e3335e272246b9fe1d5edf1daf29f0) --- src/core/initrd/nmi-cmdline-reader.c | 11 ++++---- src/core/initrd/tests/test-cmdline-reader.c | 30 ++++++++++++++++++--- 2 files changed, 33 insertions(+), 8 deletions(-) diff --git a/src/core/initrd/nmi-cmdline-reader.c b/src/core/initrd/nmi-cmdline-reader.c index 659da7b8eb..0a24199efe 100644 --- a/src/core/initrd/nmi-cmdline-reader.c +++ b/src/core/initrd/nmi-cmdline-reader.c @@ -1232,11 +1232,12 @@ nmi_cmdline_reader_parse(const char * sysfs_dir, s_wired = nm_connection_get_setting_wired(connection); - if (nm_setting_wired_get_mac_address(s_wired) - && !nm_utils_hwaddr_matches(nm_setting_wired_get_mac_address(s_wired), - -1, - bootif, - -1)) { + if (nm_connection_get_interface_name(connection) + || (nm_setting_wired_get_mac_address(s_wired) + && !nm_utils_hwaddr_matches(nm_setting_wired_get_mac_address(s_wired), + -1, + bootif, + -1))) { connection = reader_create_connection(reader, "bootif_connection", "BOOTIF Connection", diff --git a/src/core/initrd/tests/test-cmdline-reader.c b/src/core/initrd/tests/test-cmdline-reader.c index 1226987b01..e3a3753e06 100644 --- a/src/core/initrd/tests/test-cmdline-reader.c +++ b/src/core/initrd/tests/test-cmdline-reader.c @@ -1983,7 +1983,7 @@ static void test_bootif_hwtype(void) { const char *const *ARGV0 = NM_MAKE_STRV("ip=eth0:dhcp", "BOOTIF=01-00-53-AB-cd-02-03"); - const char *const *ARGV1 = NM_MAKE_STRV("BOOTIF=00-00-53-Ab-cD-02-03", "ip=:::::eth0:dhcp"); + const char *const *ARGV1 = NM_MAKE_STRV("ip=eth0:dhcp", "BOOTIF=00-00-53-Ab-cD-02-03"); const char *const *ARGV[] = {ARGV0, ARGV1}; guint i; @@ -1995,15 +1995,15 @@ test_bootif_hwtype(void) NMSettingIPConfig * s_ip6; connections = _parse_cons(ARGV[i]); - g_assert_cmpint(g_hash_table_size(connections), ==, 1); + g_assert_cmpint(g_hash_table_size(connections), ==, 2); connection = g_hash_table_lookup(connections, "eth0"); nmtst_assert_connection_verifies_without_normalization(connection); g_assert_cmpstr(nm_connection_get_id(connection), ==, "eth0"); s_wired = nm_connection_get_setting_wired(connection); + g_assert(!nm_setting_wired_get_mac_address(s_wired)); g_assert(s_wired); - g_assert_cmpstr(nm_setting_wired_get_mac_address(s_wired), ==, "00:53:AB:CD:02:03"); s_ip4 = nm_connection_get_setting_ip4_config(connection); g_assert(s_ip4); @@ -2019,6 +2019,30 @@ test_bootif_hwtype(void) ==, 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"); + nmtst_assert_connection_verifies_without_normalization(connection); + g_assert_cmpstr(nm_connection_get_id(connection), ==, "BOOTIF Connection"); + + s_wired = nm_connection_get_setting_wired(connection); + g_assert_cmpstr(nm_setting_wired_get_mac_address(s_wired), ==, "00:53:AB:CD:02:03"); + g_assert(s_wired); + + 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(!nm_setting_ip_config_get_ignore_auto_dns(s_ip4)); + g_assert(nm_setting_ip_config_get_may_fail(s_ip4)); + + 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_ignore_auto_dns(s_ip6)); + g_assert(nm_setting_ip_config_get_may_fail(s_ip6)); } }