From c21d4ce125e3335e272246b9fe1d5edf1daf29f0 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 --- src/nm-initrd-generator/nmi-cmdline-reader.c | 11 +++---- .../tests/test-cmdline-reader.c | 30 +++++++++++++++++-- 2 files changed, 33 insertions(+), 8 deletions(-) diff --git a/src/nm-initrd-generator/nmi-cmdline-reader.c b/src/nm-initrd-generator/nmi-cmdline-reader.c index 37f3f51c3d..2353e2ea0e 100644 --- a/src/nm-initrd-generator/nmi-cmdline-reader.c +++ b/src/nm-initrd-generator/nmi-cmdline-reader.c @@ -1234,11 +1234,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/nm-initrd-generator/tests/test-cmdline-reader.c b/src/nm-initrd-generator/tests/test-cmdline-reader.c index 9292c44114..5cb11e872a 100644 --- a/src/nm-initrd-generator/tests/test-cmdline-reader.c +++ b/src/nm-initrd-generator/tests/test-cmdline-reader.c @@ -1982,7 +1982,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; @@ -1994,15 +1994,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); @@ -2018,6 +2018,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)); } }