initrd: don't overwrite just any connection's name with bootdev= argument

It is really not clear what the user could have meant by specifying a
bootdev= argument, and we deal with it just by ensuring a device with
that name whould come up.

We therefore pick a default connection if there's one (that is a
conneciton that we create if the device name is unspecified, as in
"ip=auto"), otherwise we create a new one.
This commit is contained in:
Lubomir Rintel 2019-11-07 18:54:54 +01:00
parent f581756af6
commit 30f8154319
2 changed files with 41 additions and 0 deletions

View file

@ -630,6 +630,13 @@ parse_bootdev (GHashTable *connections, char *argument)
connection = get_conn (connections, NULL, NULL);
if ( nm_connection_get_interface_name (connection)
&& strcmp (nm_connection_get_interface_name (connection), argument) != 0) {
/* If the default connection already has an interface name,
* we should not overwrite it. Create a new one instead. */
connection = get_conn (connections, argument, NULL);
}
s_con = nm_connection_get_setting_connection (connection);
g_object_set (s_con,
NM_SETTING_CONNECTION_INTERFACE_NAME, argument,

View file

@ -308,6 +308,39 @@ test_multiple (void)
g_assert_cmpstr (nm_ip_address_get_address (ip_addr), ==, "2001:db8::2");
}
static void
test_bootdev (void)
{
gs_unref_hashtable GHashTable *connections = NULL;
const char *const*ARGV = NM_MAKE_STRV ("vlan=vlan2:ens5", "bootdev=ens3");
NMConnection *connection;
NMSettingConnection *s_con;
connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV);
g_assert (connections);
g_assert_cmpint (g_hash_table_size (connections), ==, 2);
connection = g_hash_table_lookup (connections, "ens3");
g_assert (connection);
nmtst_assert_connection_verifies_without_normalization (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), ==, "ens3");
g_assert_cmpstr (nm_setting_connection_get_interface_name (s_con), ==, "ens3");
connection = g_hash_table_lookup (connections, "vlan2");
g_assert (connection);
nmtst_assert_connection_verifies_without_normalization (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_VLAN_SETTING_NAME);
g_assert_cmpstr (nm_setting_connection_get_id (s_con), ==, "vlan2");
g_assert_cmpstr (nm_setting_connection_get_interface_name (s_con), ==, "vlan2");
}
static void
test_some_more (void)
{
@ -917,6 +950,7 @@ int main (int argc, char **argv)
g_test_add_func ("/initrd/cmdline/if_ip6_manual", test_if_ip6_manual);
g_test_add_func ("/initrd/cmdline/multiple", test_multiple);
g_test_add_func ("/initrd/cmdline/some_more", test_some_more);
g_test_add_func ("/initrd/cmdline/bootdev", test_bootdev);
g_test_add_func ("/initrd/cmdline/no_bootif", test_no_bootif);
g_test_add_func ("/initrd/cmdline/bond", test_bond);
g_test_add_func ("/initrd/cmdline/bond/default", test_bond_default);