initrd: merge branch 'ac/cmdline_reader_ipv6_off' into master

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/539
(cherry picked from commit 3093a0073b)
(cherry picked from commit 10f2600832)
This commit is contained in:
Beniamino Galvani 2020-11-24 10:48:49 +01:00
commit 5b579d8aa7
3 changed files with 56 additions and 3 deletions

9
NEWS
View file

@ -1,3 +1,12 @@
===============================================
NetworkManager-1.26.6
Overview of changes since NetworkManager-1.26.4
===============================================
* Change the behavior of nm-initrd-generator so that the 'ip=off|none' kernel
cmdline argument actually generates a connection which disables both
ipv4 and ipv6. Previously the generated connection would disable ipv4
but ipv6 would be set to the 'auto' method.
===============================================
NetworkManager-1.26.4
Overview of changes since NetworkManager-1.26.2

View file

@ -507,7 +507,7 @@ reader_parse_ip (Reader *reader, const char *sysfs_dir, char *argument)
if (NM_IN_STRSET (kind, "none", "off")) {
if (nm_setting_ip_config_get_num_addresses (s_ip6) == 0) {
g_object_set (s_ip6,
NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_AUTO,
NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_DISABLED,
NULL);
}
if (nm_setting_ip_config_get_num_addresses (s_ip4) == 0) {

View file

@ -228,7 +228,7 @@ test_if_ip4_manual (void)
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_cmpstr (nm_setting_ip_config_get_method (s_ip6), ==, NM_SETTING_IP6_CONFIG_METHOD_DISABLED);
g_assert (nm_setting_ip_config_get_may_fail (s_ip6));
connection = g_hash_table_lookup (connections, "eth4");
@ -293,6 +293,49 @@ test_if_ip6_manual (void)
g_assert_cmpstr (nm_setting_ip_config_get_dhcp_hostname (s_ip6), ==, "hostname0.example.com");
}
static void
test_if_off (void)
{
gs_unref_hashtable GHashTable *connections = NULL;
const char *const *ARGV = NM_MAKE_STRV ("ip=off",
"ip=ens3:off",
"ip=10.0.0.8:::::ens4:off",
"ip=[2001:DB8::8]:::::ens5:off");
NMConnection *connection;
NMSettingIPConfig *s_ip4;
NMSettingIPConfig *s_ip6;
gs_free char *hostname = NULL;
struct {
const char name[32];
const char ipv4_method[32];
const char ipv6_method[32];
} conn_expected[] = {
{"default_connection", NM_SETTING_IP4_CONFIG_METHOD_DISABLED, NM_SETTING_IP6_CONFIG_METHOD_DISABLED},
{"ens3", NM_SETTING_IP4_CONFIG_METHOD_DISABLED, NM_SETTING_IP6_CONFIG_METHOD_DISABLED},
{"ens4", NM_SETTING_IP4_CONFIG_METHOD_MANUAL, NM_SETTING_IP6_CONFIG_METHOD_DISABLED},
{"ens5", NM_SETTING_IP4_CONFIG_METHOD_DISABLED, NM_SETTING_IP6_CONFIG_METHOD_MANUAL},
};
connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV, &hostname);
g_assert (connections);
g_assert_cmpint (g_hash_table_size (connections), ==, G_N_ELEMENTS (conn_expected));
g_assert_cmpstr (hostname, ==, NULL);
for (int i = 0; i < G_N_ELEMENTS (conn_expected); ++i) {
connection = g_hash_table_lookup (connections, conn_expected[i].name);
g_assert (connection);
nmtst_assert_connection_verifies_without_normalization (connection);
s_ip4 = nm_connection_get_setting_ip4_config (connection);
g_assert (s_ip4);
g_assert_cmpstr (nm_setting_ip_config_get_method (s_ip4), ==, conn_expected[i].ipv4_method);
s_ip6 = nm_connection_get_setting_ip6_config (connection);
g_assert (s_ip6);
g_assert_cmpstr (nm_setting_ip_config_get_method (s_ip6), ==, conn_expected[i].ipv6_method);
}
}
static void
test_if_mac_ifname (void)
{
@ -681,7 +724,7 @@ test_bond_ip (void)
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_cmpstr (nm_setting_ip_config_get_method (s_ip6), ==, NM_SETTING_IP6_CONFIG_METHOD_DISABLED);
g_assert (!nm_setting_ip_config_get_ignore_auto_dns (s_ip6));
g_assert_cmpint (nm_setting_ip_config_get_num_dns (s_ip6), ==, 0);
g_assert (!nm_setting_ip_config_get_gateway (s_ip6));
@ -1665,6 +1708,7 @@ int main (int argc, char **argv)
g_test_add_func ("/initrd/cmdline/if_ip4_manual", test_if_ip4_manual);
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);
g_test_add_func ("/initrd/cmdline/multiple/merge", test_multiple_merge);
g_test_add_func ("/initrd/cmdline/multiple/bootdev", test_multiple_bootdev);
g_test_add_func ("/initrd/cmdline/nameserver", test_nameserver);