diff options
author | Lubomir Rintel <lkundrak@v3.sk> | 2019-11-07 18:54:54 +0100 |
---|---|---|
committer | Lubomir Rintel <lkundrak@v3.sk> | 2019-11-18 13:40:48 +0100 |
commit | 30f81543198d331b64776893e4d5d81ddd08ecf9 (patch) | |
tree | 958ef2c0a3613164bccb1c57f9fc666288d7df61 | |
parent | f581756af68df985873d42c937592a9286d3409f (diff) | |
download | NetworkManager-30f81543198d331b64776893e4d5d81ddd08ecf9.tar.gz |
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.
-rw-r--r-- | src/initrd/nmi-cmdline-reader.c | 7 | ||||
-rw-r--r-- | src/initrd/tests/test-cmdline-reader.c | 34 |
2 files changed, 41 insertions, 0 deletions
diff --git a/src/initrd/nmi-cmdline-reader.c b/src/initrd/nmi-cmdline-reader.c index b00ca5962d..8e07f66341 100644 --- a/src/initrd/nmi-cmdline-reader.c +++ b/src/initrd/nmi-cmdline-reader.c @@ -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, diff --git a/src/initrd/tests/test-cmdline-reader.c b/src/initrd/tests/test-cmdline-reader.c index 35935e7c07..1a34afa87d 100644 --- a/src/initrd/tests/test-cmdline-reader.c +++ b/src/initrd/tests/test-cmdline-reader.c @@ -309,6 +309,39 @@ test_multiple (void) } 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) { gs_unref_hashtable GHashTable *connections = NULL; @@ -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); |