initrd: set the bootif MAC in existing connection with ifname

If an existing connection has an interface name set and the generator
finds a BOOTIF argument, it creates a new connection for BOOTIF.

Instead, the generator should set the MAC in the existing connection;
this sounds more correct and it is what the network-legacy module
does.

https://bugzilla.redhat.com/show_bug.cgi?id=1915493
This commit is contained in:
Beniamino Galvani 2021-03-11 08:51:15 +01:00
parent 5f73646524
commit 389575a6b1
2 changed files with 8 additions and 33 deletions

View file

@ -1207,12 +1207,11 @@ nmi_cmdline_reader_parse(const char * sysfs_dir,
s_wired = nm_connection_get_setting_wired(connection);
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))) {
if (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",

View file

@ -1925,7 +1925,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("ip=eth0:dhcp", "BOOTIF=00-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 *ARGV[] = {ARGV0, ARGV1};
guint i;
@ -1937,15 +1937,15 @@ test_bootif_hwtype(void)
NMSettingIPConfig * s_ip6;
connections = _parse_cons(ARGV[i]);
g_assert_cmpint(g_hash_table_size(connections), ==, 2);
g_assert_cmpint(g_hash_table_size(connections), ==, 1);
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);
@ -1961,30 +1961,6 @@ 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));
}
}