diff options
| author | Sebastien Bacher <seb128@ubuntu.com> | 2021-08-25 15:23:22 +0200 |
|---|---|---|
| committer | Sebastien Bacher <seb128@ubuntu.com> | 2021-08-25 15:23:22 +0200 |
| commit | cfb80376641fa49137b9996130352697e7f8b436 (patch) | |
| tree | 4ac3eb90a08f27a8bff2372052f8ae78f7e7c3aa /src/nm-initrd-generator | |
| parent | 35779c6675728fa6f0fd0a21cefb904408509c23 (diff) | |
New upstream version 1.32.10
Diffstat (limited to 'src/nm-initrd-generator')
| -rw-r--r-- | src/nm-initrd-generator/meson.build | 2 | ||||
| -rw-r--r-- | src/nm-initrd-generator/nm-initrd-generator.c | 8 | ||||
| -rw-r--r-- | src/nm-initrd-generator/nm-initrd-generator.h | 3 | ||||
| -rw-r--r-- | src/nm-initrd-generator/nmi-cmdline-reader.c | 151 | ||||
| -rw-r--r-- | src/nm-initrd-generator/tests/test-cmdline-reader.c | 289 |
5 files changed, 429 insertions, 24 deletions
diff --git a/src/nm-initrd-generator/meson.build b/src/nm-initrd-generator/meson.build index 896ed3ec..080fe7e4 100644 --- a/src/nm-initrd-generator/meson.build +++ b/src/nm-initrd-generator/meson.build @@ -34,8 +34,8 @@ executable( libnm_platform, libnm_base, libnm_systemd_shared, - libnm_log_core, libnm_udev_aux, + libnm_log_core, libnm_glib_aux, libnm_std_aux, libc_siphash, diff --git a/src/nm-initrd-generator/nm-initrd-generator.c b/src/nm-initrd-generator/nm-initrd-generator.c index 490a4547..b78808b2 100644 --- a/src/nm-initrd-generator/nm-initrd-generator.c +++ b/src/nm-initrd-generator/nm-initrd-generator.c @@ -35,6 +35,14 @@ output_conn(gpointer key, gpointer value, gpointer user_data) gs_free char * data = NULL; gs_free_error GError *error = NULL; gsize len; + NMSetting * setting; + + setting = nm_setting_user_new(); + nm_connection_add_setting(connection, setting); + nm_setting_user_set_data(NM_SETTING_USER(setting), + NM_USER_TAG_ORIGIN, + "nm-initrd-generator", + NULL); if (!nm_connection_normalize(connection, NULL, NULL, &error)) goto err_out; diff --git a/src/nm-initrd-generator/nm-initrd-generator.h b/src/nm-initrd-generator/nm-initrd-generator.h index 56dcfd68..2ec52a01 100644 --- a/src/nm-initrd-generator/nm-initrd-generator.h +++ b/src/nm-initrd-generator/nm-initrd-generator.h @@ -9,7 +9,8 @@ #include "nm-connection.h" #include "nm-utils.h" -#define NMI_WAIT_DEVICE_TIMEOUT_MS 60000 +#define NMI_WAIT_DEVICE_TIMEOUT_MSEC 60000 +#define NMI_IP_REQUIRED_TIMEOUT_MSEC 20000 static inline int get_ip_address_family(const char *str, gboolean with_prefix) diff --git a/src/nm-initrd-generator/nmi-cmdline-reader.c b/src/nm-initrd-generator/nmi-cmdline-reader.c index 799fd5dc..5c42f83c 100644 --- a/src/nm-initrd-generator/nmi-cmdline-reader.c +++ b/src/nm-initrd-generator/nmi-cmdline-reader.c @@ -119,6 +119,8 @@ reader_create_connection(Reader * reader, reader->dhcp_timeout, NM_SETTING_IP4_CONFIG_DHCP_VENDOR_CLASS_IDENTIFIER, reader->dhcp4_vci, + NM_SETTING_IP_CONFIG_REQUIRED_TIMEOUT, + NMI_IP_REQUIRED_TIMEOUT_MSEC, NULL); setting = nm_setting_ip6_config_new(); @@ -401,18 +403,19 @@ reader_parse_ip(Reader *reader, const char *sysfs_dir, char *argument) gs_unref_hashtable GHashTable *ibft = NULL; const char * tmp; const char * tmp2; - const char * kind = NULL; - const char * client_ip = NULL; - const char * peer = NULL; - const char * gateway_ip = NULL; - const char * netmask = NULL; - const char * client_hostname = NULL; - const char * iface_spec = NULL; - const char * mtu = NULL; - const char * macaddr = NULL; - int client_ip_family = AF_UNSPEC; - int client_ip_prefix = -1; - const char * dns[2] = { + const char * kind = NULL; + const char * client_ip = NULL; + const char * peer = NULL; + const char * gateway_ip = NULL; + const char * netmask = NULL; + const char * client_hostname = NULL; + const char * iface_spec = NULL; + const char * mtu = NULL; + const char * macaddr = NULL; + int client_ip_family = AF_UNSPEC; + int client_ip_prefix = -1; + gboolean clear_ip4_required_timeout = TRUE; + const char * dns[2] = { NULL, NULL, }; @@ -436,6 +439,7 @@ reader_parse_ip(Reader *reader, const char *sysfs_dir, char *argument) "none", "off", "dhcp", + "single-dhcp", "on" "any", "dhcp6", @@ -601,7 +605,7 @@ reader_parse_ip(Reader *reader, const char *sysfs_dir, char *argument) NM_SETTING_IP4_CONFIG_METHOD_DISABLED, NULL); } - } else if (nm_streq0(kind, "dhcp")) { + } else if (NM_IN_STRSET(kind, "dhcp", "single-dhcp")) { g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, @@ -679,8 +683,13 @@ reader_parse_ip(Reader *reader, const char *sysfs_dir, char *argument) g_clear_error(&error); } } + } else { + clear_ip4_required_timeout = FALSE; } + if (clear_ip4_required_timeout) + g_object_set(s_ip4, NM_SETTING_IP_CONFIG_REQUIRED_TIMEOUT, -1, NULL); + if (peer && *peer) _LOGW(LOGD_CORE, "Ignoring peer: %s (not implemented)\n", peer); @@ -908,6 +917,56 @@ reader_parse_vlan(Reader *reader, char *argument) } static void +reader_parse_ib_pkey(Reader *reader, char *argument) +{ + NMConnection * connection; + NMSettingInfiniband *s_ib; + char * ifname; + gs_free char * parent = NULL; + char * pkey; + gint64 pkey_int; + + /* At the moment we only support ib.pkey=<parent>.<pkey>; + * in the future we want to possibly support other options: + * ib.pkey=<parent>.<pkey>:<option>:... + */ + ifname = get_word(&argument, ':'); + if (!ifname) { + _LOGW(LOGD_CORE, "ib.pkey= without argument"); + return; + } + + parent = g_strdup(ifname); + pkey = strchr(parent, '.'); + if (!pkey) { + _LOGW(LOGD_CORE, "No pkey found for '%s'", ifname); + return; + } + + *pkey = '\0'; + pkey++; + + pkey_int = _nm_utils_ascii_str_to_int64(pkey, 16, 0, 0xFFFF, -1); + if (pkey_int == -1) { + _LOGW(LOGD_CORE, "Invalid pkey '%s'", pkey); + return; + } + + connection = reader_get_connection(reader, ifname, NM_SETTING_INFINIBAND_SETTING_NAME, TRUE); + + s_ib = nm_connection_get_setting_infiniband(connection); + g_object_set(s_ib, + NM_SETTING_INFINIBAND_PARENT, + parent, + NM_SETTING_INFINIBAND_P_KEY, + (int) pkey_int, + NULL); + + if (argument && *argument) + _LOGW(LOGD_CORE, "Ignoring extra: '%s' for ib.pkey=", argument); +} + +static void reader_parse_rd_znet(Reader *reader, char *argument, gboolean net_ifnames) { const char * nettype; @@ -998,6 +1057,65 @@ reader_parse_rd_znet(Reader *reader, char *argument, gboolean net_ifnames) } static void +reader_parse_ethtool(Reader *reader, char *argument) +{ + const char * interface = NULL; + NMConnection * connection = NULL; + NMSettingWired *s_wired = NULL; + const char * autoneg_str = NULL; + gboolean autoneg = FALSE; + const char * speed_str = NULL; + guint speed = 0; + + interface = get_word(&argument, ':'); + if (!interface) { + _LOGW(LOGD_CORE, "Impossible to set rd.ethtool options: invalid format"); + return; + } + + if (!*argument) { + _LOGW(LOGD_CORE, "Could not find rd.ethtool options to set"); + return; + } + + connection = reader_get_connection(reader, interface, NM_SETTING_WIRED_SETTING_NAME, TRUE); + s_wired = nm_connection_get_setting_wired(connection); + + autoneg_str = get_word(&argument, ':'); + if (autoneg_str) { + autoneg = _nm_utils_ascii_str_to_bool(autoneg_str, -1); + if (autoneg == -1) + _LOGW(LOGD_CORE, + "Invalid value for rd.ethtool.autoneg, rd.ethtool.autoneg was not set"); + else + g_object_set(s_wired, NM_SETTING_WIRED_AUTO_NEGOTIATE, autoneg, NULL); + } + if (!*argument) + return; + + speed_str = get_word(&argument, ':'); + if (speed_str) { + speed = _nm_utils_ascii_str_to_int64(speed_str, 10, 0, G_MAXUINT32, -1); + if (speed == -1) + _LOGW(LOGD_CORE, "Invalid value for rd.ethtool.speed, rd.ethtool.speed was not set"); + else + g_object_set(s_wired, + NM_SETTING_WIRED_SPEED, + speed, + NM_SETTING_WIRED_DUPLEX, + "full", + NULL); + } + + if (!*argument) + return; + else + _LOGW(LOGD_CORE, + "Invalid extra argument '%s' for rd.ethtool, this value was not set", + argument); +} + +static void _normalize_conn(gpointer key, gpointer value, gpointer user_data) { NMConnection *connection = value; @@ -1062,7 +1180,7 @@ connection_set_needed(NMConnection *connection) g_object_set(s_con, NM_SETTING_CONNECTION_WAIT_DEVICE_TIMEOUT, - (int) NMI_WAIT_DEVICE_TIMEOUT_MS, + (int) NMI_WAIT_DEVICE_TIMEOUT_MSEC, NULL); } @@ -1151,6 +1269,8 @@ nmi_cmdline_reader_parse(const char * sysfs_dir, reader_parse_master(reader, argument, NM_SETTING_TEAM_SETTING_NAME, NULL); else if (nm_streq(tag, "vlan")) reader_parse_vlan(reader, argument); + else if (nm_streq(tag, "ib.pkey")) + reader_parse_ib_pkey(reader, argument); else if (nm_streq(tag, "bootdev")) { g_free(bootdev); bootdev = g_strdup(argument); @@ -1176,7 +1296,8 @@ nmi_cmdline_reader_parse(const char * sysfs_dir, } else if (g_ascii_strcasecmp(tag, "BOOTIF") == 0) { nm_clear_g_free(&bootif_val); bootif_val = g_strdup(argument); - } + } else if (nm_streq(tag, "rd.ethtool")) + reader_parse_ethtool(reader, argument); } for (i = 0; i < reader->vlan_parents->len; i++) { diff --git a/src/nm-initrd-generator/tests/test-cmdline-reader.c b/src/nm-initrd-generator/tests/test-cmdline-reader.c index 5cb11e87..b0dcf06d 100644 --- a/src/nm-initrd-generator/tests/test-cmdline-reader.c +++ b/src/nm-initrd-generator/tests/test-cmdline-reader.c @@ -275,6 +275,7 @@ test_dhcp_timeout(void) ==, NM_SETTING_IP4_CONFIG_METHOD_AUTO); g_assert_cmpint(nm_setting_ip_config_get_dhcp_timeout(s_ip4), ==, data[i].timeout); + g_assert_cmpint(nm_setting_ip_config_get_required_timeout(s_ip4), ==, -1); s_ip6 = nm_connection_get_setting_ip6_config(connection); g_assert(s_ip6); @@ -282,6 +283,7 @@ test_dhcp_timeout(void) ==, NM_SETTING_IP6_CONFIG_METHOD_AUTO); g_assert_cmpint(nm_setting_ip_config_get_dhcp_timeout(s_ip6), ==, data[i].timeout); + g_assert_cmpint(nm_setting_ip_config_get_required_timeout(s_ip6), ==, -1); } } @@ -420,6 +422,7 @@ test_if_ip4_manual(void) 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"); g_assert_cmpstr(nm_setting_ip_config_get_dhcp_hostname(s_ip4), ==, "hostname0.example.com"); + g_assert_cmpint(nm_setting_ip_config_get_required_timeout(s_ip4), ==, -1); s_ip6 = nm_connection_get_setting_ip6_config(connection); g_assert(s_ip6); @@ -427,6 +430,7 @@ test_if_ip4_manual(void) ==, NM_SETTING_IP6_CONFIG_METHOD_DISABLED); g_assert(nm_setting_ip_config_get_may_fail(s_ip6)); + g_assert_cmpint(nm_setting_ip_config_get_required_timeout(s_ip6), ==, -1); connection = g_hash_table_lookup(connections, "eth4"); nmtst_assert_connection_verifies_without_normalization(connection); @@ -702,7 +706,7 @@ test_multiple_bootdev(void) g_assert(s_con); g_assert_cmpint(nm_setting_connection_get_wait_device_timeout(s_con), ==, - NMI_WAIT_DEVICE_TIMEOUT_MS); + NMI_WAIT_DEVICE_TIMEOUT_MSEC); 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); @@ -744,7 +748,7 @@ test_bootdev(void) g_assert_cmpstr(nm_setting_connection_get_interface_name(s_con), ==, "ens3"); g_assert_cmpint(nm_setting_connection_get_wait_device_timeout(s_con), ==, - NMI_WAIT_DEVICE_TIMEOUT_MS); + NMI_WAIT_DEVICE_TIMEOUT_MSEC); connection = g_hash_table_lookup(connections, "vlan2"); nmtst_assert_connection_verifies_without_normalization(connection); @@ -1153,6 +1157,9 @@ test_bridge(void) g_assert_cmpint(nm_ip_route_get_metric(ip_route), ==, -1); g_assert(!nm_ip_route_get_next_hop(ip_route)); g_assert_cmpint(nm_ip_route_get_prefix(ip_route), ==, 32); + g_assert_cmpint(nm_setting_ip_config_get_required_timeout(s_ip4), + ==, + NMI_IP_REQUIRED_TIMEOUT_MSEC); s_ip6 = nm_connection_get_setting_ip6_config(connection); g_assert(s_ip6); @@ -1162,6 +1169,7 @@ test_bridge(void) g_assert(!nm_setting_ip_config_get_gateway(s_ip6)); g_assert_cmpint(nm_setting_ip_config_get_num_routes(s_ip6), ==, 0); g_assert_cmpint(nm_setting_ip_config_get_dhcp_timeout(s_ip6), ==, 10); + g_assert_cmpint(nm_setting_ip_config_get_required_timeout(s_ip6), ==, -1); s_bridge = nm_connection_get_setting_bridge(connection); g_assert(s_bridge); @@ -1902,7 +1910,38 @@ test_bootif_ip(void) } static void -test_neednet(void) +test_neednet_no_args(void) +{ + const char *const *ARGV = NM_MAKE_STRV("rd.neednet"); + gs_unref_object NMConnection *connection = NULL; + NMSettingWired * s_wired; + NMSettingIPConfig * s_ip4; + NMSettingIPConfig * s_ip6; + + connection = _parse_con(ARGV, "default_connection"); + + g_assert_cmpstr(nm_connection_get_id(connection), ==, "Wired Connection"); + + s_wired = nm_connection_get_setting_wired(connection); + 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_may_fail(s_ip4)); + g_assert_cmpint(nm_setting_ip_config_get_required_timeout(s_ip4), + ==, + NMI_IP_REQUIRED_TIMEOUT_MSEC); + + 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)); + g_assert_cmpint(nm_setting_ip_config_get_required_timeout(s_ip6), ==, -1); +} + +static void +test_neednet_args(void) { gs_unref_hashtable GHashTable *connections = NULL; const char *const * ARGV = NM_MAKE_STRV("rd.neednet", @@ -1922,7 +1961,7 @@ test_neednet(void) g_assert_cmpstr(nm_setting_connection_get_interface_name(s_con), ==, "eno1"); g_assert_cmpint(nm_setting_connection_get_wait_device_timeout(s_con), ==, - NMI_WAIT_DEVICE_TIMEOUT_MS); + NMI_WAIT_DEVICE_TIMEOUT_MSEC); connection = g_hash_table_lookup(connections, "eno2"); nmtst_assert_connection_verifies_without_normalization(connection); @@ -1931,7 +1970,7 @@ test_neednet(void) g_assert_cmpstr(nm_setting_connection_get_interface_name(s_con), ==, "eno2"); g_assert_cmpint(nm_setting_connection_get_wait_device_timeout(s_con), ==, - NMI_WAIT_DEVICE_TIMEOUT_MS); + NMI_WAIT_DEVICE_TIMEOUT_MSEC); connection = g_hash_table_lookup(connections, "eno3"); nmtst_assert_connection_verifies_without_normalization(connection); @@ -1940,7 +1979,7 @@ test_neednet(void) g_assert_cmpstr(nm_setting_connection_get_interface_name(s_con), ==, "eno3"); g_assert_cmpint(nm_setting_connection_get_wait_device_timeout(s_con), ==, - NMI_WAIT_DEVICE_TIMEOUT_MS); + NMI_WAIT_DEVICE_TIMEOUT_MSEC); connection = g_hash_table_lookup(connections, "br0"); nmtst_assert_connection_verifies_without_normalization(connection); @@ -2176,6 +2215,40 @@ test_infiniband_mac(void) } static void +test_infiniband_pkey(void) +{ + const char *const *const ARGV = NM_MAKE_STRV("ib.pkey=ib0.8004", "ip=ib0.8004:dhcp"); + gs_unref_hashtable GHashTable *connections = NULL; + NMConnection * connection; + NMSettingInfiniband * s_ib; + NMSettingIPConfig * s_ip4; + NMSettingIPConfig * s_ip6; + + connections = _parse_cons(ARGV); + g_assert_cmpint(g_hash_table_size(connections), ==, 1); + + connection = g_hash_table_lookup(connections, "ib0.8004"); + g_assert_cmpstr(nm_connection_get_connection_type(connection), + ==, + NM_SETTING_INFINIBAND_SETTING_NAME); + g_assert_cmpstr(nm_connection_get_interface_name(connection), ==, "ib0.8004"); + + s_ib = nm_connection_get_setting_infiniband(connection); + g_assert(s_ib); + g_assert_cmpint(nm_setting_infiniband_get_p_key(s_ib), ==, 0x8004); + + 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_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_may_fail(s_ip6)); +} + +static void test_carrier_timeout(void) { gs_unref_hashtable GHashTable *connections = NULL; @@ -2189,6 +2262,205 @@ test_carrier_timeout(void) g_assert_cmpint(carrier_timeout_sec, ==, 20); } +/* Obs1.: this function is implemented as macro, and not as a function, + * to show the correct line in g_assert() debug */ +#define _ethtool_connection_check_and_get(connection) \ + ({ \ + NMSettingWired *_s_wired = NULL; \ + NMConnection * _connection = connection; \ + \ + g_assert(nm_connection_get_setting_connection(_connection)); \ + g_assert(nm_connection_is_type(_connection, NM_SETTING_WIRED_SETTING_NAME)); \ + g_assert(nm_connection_get_setting_ip4_config(_connection)); \ + g_assert(nm_connection_get_setting_ip6_config(_connection)); \ + _s_wired = nm_connection_get_setting_wired(_connection); \ + g_assert(NM_IS_SETTING_WIRED(_s_wired)); \ + \ + _s_wired; \ + }) + +static void +test_rd_ethtool(void) +{ + const char *const *ARGV = NULL; + NMConnection * connection = NULL; + GHashTable * connections = NULL; + NMSettingWired * s_wired = NULL; + + ARGV = NM_MAKE_STRV("rd.ethtool="); + NMTST_EXPECT_NM_WARN("cmdline-reader: Impossible to set rd.ethtool options: invalid format"); + connections = _parse_cons(ARGV); + g_assert_cmpint(g_hash_table_size(connections), ==, 0); + g_hash_table_unref(connections); + g_test_assert_expected_messages(); + + ARGV = NM_MAKE_STRV("rd.ethtool=eth0"); + NMTST_EXPECT_NM_WARN("cmdline-reader: Could not find rd.ethtool options to set"); + connections = _parse_cons(ARGV); + g_assert_cmpint(g_hash_table_size(connections), ==, 0); + g_hash_table_unref(connections); + g_test_assert_expected_messages(); + + ARGV = NM_MAKE_STRV("rd.ethtool=eth0:"); + NMTST_EXPECT_NM_WARN("cmdline-reader: Could not find rd.ethtool options to set"); + connections = _parse_cons(ARGV); + g_assert_cmpint(g_hash_table_size(connections), ==, 0); + g_hash_table_unref(connections); + g_test_assert_expected_messages(); + + ARGV = NM_MAKE_STRV("rd.ethtool=::"); + NMTST_EXPECT_NM_WARN("cmdline-reader: Impossible to set rd.ethtool options: invalid format"); + connections = _parse_cons(ARGV); + g_assert_cmpint(g_hash_table_size(connections), ==, 0); + g_test_assert_expected_messages(); + g_hash_table_unref(connections); + + ARGV = NM_MAKE_STRV("rd.ethtool=eth0:on"); + connection = _parse_con(ARGV, "eth0"); + s_wired = _ethtool_connection_check_and_get(connection); + g_assert(nm_setting_wired_get_auto_negotiate(s_wired)); + g_object_unref(connection); + + ARGV = NM_MAKE_STRV("rd.ethtool=eth0:off"); + connection = _parse_con(ARGV, "eth0"); + s_wired = _ethtool_connection_check_and_get(connection); + g_assert(!nm_setting_wired_get_auto_negotiate(s_wired)); + g_object_unref(connection); + + ARGV = NM_MAKE_STRV("rd.ethtool=eth0:true"); + connection = _parse_con(ARGV, "eth0"); + s_wired = _ethtool_connection_check_and_get(connection); + g_assert(nm_setting_wired_get_auto_negotiate(s_wired)); + g_object_unref(connection); + + ARGV = NM_MAKE_STRV("rd.ethtool=eth0:false"); + connection = _parse_con(ARGV, "eth0"); + s_wired = _ethtool_connection_check_and_get(connection); + g_assert(!nm_setting_wired_get_auto_negotiate(s_wired)); + g_object_unref(connection); + + ARGV = NM_MAKE_STRV("rd.ethtool=eth0:1"); + connection = _parse_con(ARGV, "eth0"); + s_wired = _ethtool_connection_check_and_get(connection); + g_assert(nm_setting_wired_get_auto_negotiate(s_wired)); + g_object_unref(connection); + + ARGV = NM_MAKE_STRV("rd.ethtool=eth0:0"); + connection = _parse_con(ARGV, "eth0"); + s_wired = _ethtool_connection_check_and_get(connection); + g_assert(!nm_setting_wired_get_auto_negotiate(s_wired)); + g_object_unref(connection); + + ARGV = NM_MAKE_STRV("rd.ethtool=eth0:randomstring"); + NMTST_EXPECT_NM_WARN( + "cmdline-reader: Invalid value for rd.ethtool.autoneg, rd.ethtool.autoneg was not set"); + connections = _parse_cons(ARGV); + g_assert_cmpint(g_hash_table_size(connections), ==, 1); + g_test_assert_expected_messages(); + g_hash_table_unref(connections); + + ARGV = NM_MAKE_STRV("rd.ethtool=eth0::"); + connections = _parse_cons(ARGV); + g_assert_cmpint(g_hash_table_size(connections), ==, 1); + g_hash_table_unref(connections); + + ARGV = NM_MAKE_STRV("rd.ethtool=eth0::astring"); + NMTST_EXPECT_NM_WARN( + "cmdline-reader: Invalid value for rd.ethtool.speed, rd.ethtool.speed was not set"); + connections = _parse_cons(ARGV); + g_assert_cmpint(g_hash_table_size(connections), ==, 1); + g_test_assert_expected_messages(); + g_hash_table_unref(connections); + + ARGV = NM_MAKE_STRV("rd.ethtool=eth0::1000000000000000000000000000000000000"); + NMTST_EXPECT_NM_WARN( + "cmdline-reader: Invalid value for rd.ethtool.speed, rd.ethtool.speed was not set"); + connections = _parse_cons(ARGV); + g_assert_cmpint(g_hash_table_size(connections), ==, 1); + g_test_assert_expected_messages(); + g_hash_table_unref(connections); + + ARGV = NM_MAKE_STRV("rd.ethtool=eth0::0.67"); + NMTST_EXPECT_NM_WARN( + "cmdline-reader: Invalid value for rd.ethtool.speed, rd.ethtool.speed was not set"); + connections = _parse_cons(ARGV); + g_assert_cmpint(g_hash_table_size(connections), ==, 1); + g_test_assert_expected_messages(); + g_hash_table_unref(connections); + + ARGV = NM_MAKE_STRV("rd.ethtool=eth0::-23"); + NMTST_EXPECT_NM_WARN( + "cmdline-reader: Invalid value for rd.ethtool.speed, rd.ethtool.speed was not set"); + connections = _parse_cons(ARGV); + g_assert_cmpint(g_hash_table_size(connections), ==, 1); + g_test_assert_expected_messages(); + g_hash_table_unref(connections); + + ARGV = NM_MAKE_STRV("rd.ethtool=eth0:1:10"); + connection = _parse_con(ARGV, "eth0"); + s_wired = _ethtool_connection_check_and_get(connection); + g_assert(nm_setting_wired_get_auto_negotiate(s_wired)); + g_assert_cmpint(nm_setting_wired_get_speed(s_wired), ==, 10); + g_assert_cmpstr(nm_setting_wired_get_duplex(s_wired), ==, "full"); + g_object_unref(connection); + + ARGV = NM_MAKE_STRV("rd.ethtool=eth0::100"); + connection = _parse_con(ARGV, "eth0"); + s_wired = _ethtool_connection_check_and_get(connection); + g_assert(!nm_setting_wired_get_auto_negotiate(s_wired)); + g_assert_cmpint(nm_setting_wired_get_speed(s_wired), ==, 100); + g_assert_cmpstr(nm_setting_wired_get_duplex(s_wired), ==, "full"); + g_object_unref(connection); + + ARGV = NM_MAKE_STRV("rd.ethtool=eth0:::bogus"); + NMTST_EXPECT_NM_WARN( + "cmdline-reader: Invalid extra argument 'bogus' for rd.ethtool, this value was not set"); + connections = _parse_cons(ARGV); + g_assert_cmpint(g_hash_table_size(connections), ==, 1); + g_test_assert_expected_messages(); + g_hash_table_unref(connections); + + ARGV = NM_MAKE_STRV("rd.ethtool=eth0::10:bogus"); + NMTST_EXPECT_NM_WARN( + "cmdline-reader: Invalid extra argument 'bogus' for rd.ethtool, this value was not set"); + connection = _parse_con(ARGV, "eth0"); + s_wired = _ethtool_connection_check_and_get(connection); + g_assert(!nm_setting_wired_get_auto_negotiate(s_wired)); + g_assert_cmpint(nm_setting_wired_get_speed(s_wired), ==, 10); + g_assert_cmpstr(nm_setting_wired_get_duplex(s_wired), ==, "full"); + g_test_assert_expected_messages(); + g_object_unref(connection); + + ARGV = NM_MAKE_STRV("rd.ethtool=eth0:on:100:bogus"); + NMTST_EXPECT_NM_WARN( + "cmdline-reader: Invalid extra argument 'bogus' for rd.ethtool, this value was not set"); + connection = _parse_con(ARGV, "eth0"); + s_wired = _ethtool_connection_check_and_get(connection); + g_assert(nm_setting_wired_get_auto_negotiate(s_wired)); + g_assert_cmpint(nm_setting_wired_get_speed(s_wired), ==, 100); + g_assert_cmpstr(nm_setting_wired_get_duplex(s_wired), ==, "full"); + g_test_assert_expected_messages(); + g_object_unref(connection); + + ARGV = NM_MAKE_STRV("rd.ethtool=eth0:on:100:bogus"); + NMTST_EXPECT_NM_WARN( + "cmdline-reader: Invalid extra argument 'bogus' for rd.ethtool, this value was not set"); + connection = _parse_con(ARGV, "eth0"); + s_wired = _ethtool_connection_check_and_get(connection); + g_assert(nm_setting_wired_get_auto_negotiate(s_wired)); + g_assert_cmpint(nm_setting_wired_get_speed(s_wired), ==, 100); + g_assert_cmpstr(nm_setting_wired_get_duplex(s_wired), ==, "full"); + g_test_assert_expected_messages(); + g_object_unref(connection); + + ARGV = NM_MAKE_STRV("rd.ethtool=:::"); + NMTST_EXPECT_NM_WARN("cmdline-reader: Impossible to set rd.ethtool options: invalid format"); + connections = _parse_cons(ARGV); + g_assert_cmpint(g_hash_table_size(connections), ==, 0); + g_test_assert_expected_messages(); + g_hash_table_unref(connections); +} + NMTST_DEFINE(); int @@ -2236,11 +2508,14 @@ main(int argc, char **argv) g_test_add_func("/initrd/cmdline/bootif/no_ip", test_bootif_no_ip); g_test_add_func("/initrd/cmdline/bootif/hwtype", test_bootif_hwtype); g_test_add_func("/initrd/cmdline/bootif/off", test_bootif_off); - g_test_add_func("/initrd/cmdline/neednet", test_neednet); + g_test_add_func("/initrd/cmdline/neednet/no_args", test_neednet_no_args); + g_test_add_func("/initrd/cmdline/neednet/args", test_neednet_args); g_test_add_func("/initrd/cmdline/dhcp/vendor_class_id", test_dhcp_vendor_class_id); g_test_add_func("/initrd/cmdline/infiniband/iface", test_infiniband_iface); g_test_add_func("/initrd/cmdline/infiniband/mac", test_infiniband_mac); + g_test_add_func("/initrd/cmdline/infiniband/pkey", test_infiniband_pkey); g_test_add_func("/initrd/cmdline/carrier_timeout", test_carrier_timeout); + g_test_add_func("/initrd/cmdline/rd_ethtool", test_rd_ethtool); return g_test_run(); } |