diff options
author | Beniamino Galvani <bgalvani@redhat.com> | 2021-03-12 09:47:18 +0100 |
---|---|---|
committer | Beniamino Galvani <bgalvani@redhat.com> | 2021-03-12 09:47:18 +0100 |
commit | 88aae71f22b7db61d9e4ce50d0451d2e0401b893 (patch) | |
tree | cd4a709266b38ae24330d1f38bb5dcab814a3584 | |
parent | 4d609dd92f2922e92888e02b5b857e4d7b10a37e (diff) | |
parent | c27626a0ce4da8438503d764815542927def6dce (diff) | |
download | NetworkManager-88aae71f22b7db61d9e4ce50d0451d2e0401b893.tar.gz |
initrd: merge branch 'bg/initrd-fixes'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/779
-rw-r--r-- | src/core/initrd/nmi-cmdline-reader.c | 25 | ||||
-rw-r--r-- | src/core/initrd/tests/test-cmdline-reader.c | 72 |
2 files changed, 61 insertions, 36 deletions
diff --git a/src/core/initrd/nmi-cmdline-reader.c b/src/core/initrd/nmi-cmdline-reader.c index d3e4bdf8be..15b4af7b70 100644 --- a/src/core/initrd/nmi-cmdline-reader.c +++ b/src/core/initrd/nmi-cmdline-reader.c @@ -393,8 +393,9 @@ reader_read_all_connections_from_fw(Reader *reader, const char *sysfs_dir) static void reader_parse_ip(Reader *reader, const char *sysfs_dir, char *argument) { - NMConnection * connection; - NMSettingIPConfig *s_ip4 = NULL, *s_ip6 = NULL; + NMConnection * connection; + NMSettingConnection *s_con; + NMSettingIPConfig * s_ip4 = NULL, *s_ip6 = NULL; gs_unref_hashtable GHashTable *ibft = NULL; const char * tmp; const char * tmp2; @@ -501,6 +502,7 @@ reader_parse_ip(Reader *reader, const char *sysfs_dir, char *argument) g_hash_table_add(reader->explicit_ip_connections, g_object_ref(connection)); + s_con = nm_connection_get_setting_connection(connection); s_ip4 = nm_connection_get_setting_ip4_config(connection); s_ip6 = nm_connection_get_setting_ip6_config(connection); @@ -550,6 +552,12 @@ reader_parse_ip(Reader *reader, const char *sysfs_dir, char *argument) nm_assert_not_reached(); if (address) { + /* We don't want to have multiple devices up with the + * same static address. */ + g_object_set(s_con, + NM_SETTING_CONNECTION_MULTI_CONNECT, + NM_CONNECTION_MULTI_CONNECT_SINGLE, + NULL); switch (client_ip_family) { case AF_INET: g_object_set(s_ip4, @@ -605,7 +613,7 @@ reader_parse_ip(Reader *reader, const char *sysfs_dir, char *argument) NULL); } } else if (NM_IN_STRSET(kind, "auto6", "dhcp6")) { - g_object_set(s_ip4, NM_SETTING_IP_CONFIG_MAY_FAIL, FALSE, NULL); + g_object_set(s_ip6, NM_SETTING_IP_CONFIG_MAY_FAIL, FALSE, NULL); if (nm_setting_ip_config_get_num_addresses(s_ip4) == 0) { g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, @@ -1207,12 +1215,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", diff --git a/src/core/initrd/tests/test-cmdline-reader.c b/src/core/initrd/tests/test-cmdline-reader.c index 153d9442df..1ce892c0ca 100644 --- a/src/core/initrd/tests/test-cmdline-reader.c +++ b/src/core/initrd/tests/test-cmdline-reader.c @@ -456,6 +456,47 @@ test_if_ip4_manual(void) } static void +test_if_ip4_manual_no_dev(void) +{ + gs_unref_hashtable GHashTable *connections = NULL; + const char *const * ARGV = NM_MAKE_STRV("ip=192.0.2.2::192.0.2.1:24:::"); + NMConnection * connection; + NMSettingConnection * s_con; + NMSettingIPConfig * s_ip4; + NMSettingIPConfig * s_ip6; + NMIPAddress * ip_addr; + + connection = _parse_con(ARGV, "default_connection"); + g_assert_cmpstr(nm_connection_get_id(connection), ==, "Wired Connection"); + + s_con = nm_connection_get_setting_connection(connection); + g_assert(s_con); + g_assert_cmpint(nm_setting_connection_get_wait_device_timeout(s_con), ==, -1); + g_assert_cmpint(nm_setting_connection_get_multi_connect(s_con), + ==, + NM_CONNECTION_MULTI_CONNECT_SINGLE); + + 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_MANUAL); + g_assert(!nm_setting_ip_config_get_ignore_auto_dns(s_ip4)); + g_assert_cmpint(nm_setting_ip_config_get_num_routes(s_ip4), ==, 0); + g_assert_cmpint(nm_setting_ip_config_get_num_addresses(s_ip4), ==, 1); + ip_addr = nm_setting_ip_config_get_address(s_ip4, 0); + g_assert(ip_addr); + g_assert_cmpstr(nm_ip_address_get_address(ip_addr), ==, "192.0.2.2"); + g_assert_cmpint(nm_ip_address_get_prefix(ip_addr), ==, 24); + g_assert_cmpstr(nm_setting_ip_config_get_gateway(s_ip4), ==, "192.0.2.1"); + + 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_may_fail(s_ip6)); +} + +static void test_if_ip6_manual(void) { gs_unref_hashtable GHashTable *connections = NULL; @@ -1925,7 +1966,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,38 +1978,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); - - 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)); - - 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); @@ -1976,7 +1994,7 @@ test_bootif_hwtype(void) ==, 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)); + g_assert(!nm_setting_ip_config_get_may_fail(s_ip4)); s_ip6 = nm_connection_get_setting_ip6_config(connection); g_assert(s_ip6); @@ -1984,7 +2002,6 @@ test_bootif_hwtype(void) ==, 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)); } } @@ -2147,6 +2164,7 @@ main(int argc, char **argv) g_test_add_func("/initrd/cmdline/if_dhcp6", test_if_dhcp6); g_test_add_func("/initrd/cmdline/if_auto_with_mtu_and_mac", test_if_auto_with_mtu_and_mac); g_test_add_func("/initrd/cmdline/if_ip4_manual", test_if_ip4_manual); + g_test_add_func("/initrd/cmdline/if_ip4_manual_no_dev", test_if_ip4_manual_no_dev); g_test_add_func("/initrd/cmdline/if_ip6_manual", test_if_ip6_manual); g_test_add_func("/initrd/cmdline/if_mac_ifname", test_if_mac_ifname); g_test_add_func("/initrd/cmdline/if_off", test_if_off); |