initrd: add support for rd.net.timeout.carrier

Add support for `carrier-wait-timeout` setting from kernel cmdline.

This will create a new `15-carrier-timeout.conf` file in
/run/NetworkManager/conf.d with the parameter value as specified.

The setting also inserts `match-device` to `*`, matching all devices.

NB: The parameter on kernel cmdline is specified in seconds. This is
done to be backwards compatible with with network-legacy module. However
the generated setting will automatically multiply specified value by
1000 and store timeout value in ms.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/626

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/730
(cherry picked from commit e300138892)
(cherry picked from commit f55eeff70a)
This commit is contained in:
Adarsh J 2021-01-18 03:15:14 +09:00 committed by Thomas Haller
parent 4b58ecb592
commit 7a91960989
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728
5 changed files with 226 additions and 60 deletions

View file

@ -102,6 +102,20 @@
</listitem>
</varlistentry>
<varlistentry>
<term>
<group choice='plain'>
<arg choice='plain'><option>-r</option></arg>
<arg choice='plain'><option>--run-config-dir</option></arg>
</group>
<arg choice='plain'><replaceable>path</replaceable></arg>
</term>
<listitem>
<para>Output directory for config files.</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<group choice='plain'>
@ -133,6 +147,7 @@
<member><option>rd.peerdns</option></member>
<member><option>rd.bootif</option></member>
<member><option>rd.net.timeout.dhcp</option></member>
<member><option>rd.net.timeout.carrier</option></member>
<member><option>BOOTIF</option></member>
</simplelist>

View file

@ -9,6 +9,7 @@
#include "nm-keyfile/nm-keyfile-internal.h"
#include "nm-initrd-generator.h"
#include "nm-glib-aux/nm-io-utils.h"
#include "nm-config.h"
/*****************************************************************************/
@ -65,6 +66,7 @@ err_out:
#define DEFAULT_SYSFS_DIR "/sys"
#define DEFAULT_INITRD_DATA_DIR NMRUNDIR "/initrd"
#define DEFAULT_RUN_CONFIG_DIR NMRUNDIR "/conf.d"
int
main (int argc, char *argv[])
@ -73,12 +75,14 @@ main (int argc, char *argv[])
gs_free char *connections_dir = NULL;
gs_free char *initrd_dir = NULL;
gs_free char *sysfs_dir = NULL;
gs_free char *run_config_dir = NULL;
gboolean dump_to_stdout = FALSE;
gs_strfreev char **remaining = NULL;
GOptionEntry option_entries[] = {
{ "connections-dir", 'c', 0, G_OPTION_ARG_FILENAME, &connections_dir, "Output connection directory", NM_KEYFILE_PATH_NAME_RUN },
{ "initrd-data-dir", 'i', 0, G_OPTION_ARG_FILENAME, &initrd_dir, "Output initrd data directory", DEFAULT_INITRD_DATA_DIR },
{ "sysfs-dir", 'd', 0, G_OPTION_ARG_FILENAME, &sysfs_dir, "The sysfs mount point", DEFAULT_SYSFS_DIR },
{ "run-config-dir", 'r', 0, G_OPTION_ARG_FILENAME, &run_config_dir, "Output config directory", DEFAULT_RUN_CONFIG_DIR },
{ "stdout", 's', 0, G_OPTION_ARG_NONE, &dump_to_stdout, "Dump connections to standard output", NULL },
{ G_OPTION_REMAINING, '\0', 0, G_OPTION_ARG_STRING_ARRAY, &remaining, NULL, NULL },
{ NULL }
@ -87,9 +91,11 @@ main (int argc, char *argv[])
gs_free_error GError *error = NULL;
gs_free char *hostname = NULL;
int errsv;
gint64 carrier_timeout_sec = 0;
option_context = g_option_context_new ("-- [ip=...] [rd.route=...] [bridge=...] [bond=...] [team=...] [vlan=...] "
"[bootdev=...] [nameserver=...] [rd.peerdns=...] [rd.bootif=...] [BOOTIF=...] [rd.znet=...] ... ");
"[bootdev=...] [nameserver=...] [rd.peerdns=...] [rd.bootif=...] [BOOTIF=...] "
"[rd.znet=...] [rd.net.timeout.carrier=...] ... ");
g_option_context_set_summary (option_context, "Generate early NetworkManager configuration.");
g_option_context_set_description (option_context,
@ -114,31 +120,40 @@ main (int argc, char *argv[])
sysfs_dir = g_strdup (DEFAULT_SYSFS_DIR);
if (!initrd_dir)
initrd_dir = g_strdup (DEFAULT_INITRD_DATA_DIR);
if (dump_to_stdout)
nm_clear_g_free (&connections_dir);
if (connections_dir && g_mkdir_with_parents (connections_dir, 0755) != 0) {
errsv = errno;
_LOGW (LOGD_CORE, "%s: %s", connections_dir, nm_strerror_native (errsv));
return 1;
}
if (!run_config_dir)
run_config_dir = g_strdup (DEFAULT_RUN_CONFIG_DIR);
connections = nmi_cmdline_reader_parse (sysfs_dir,
(const char *const*) remaining,
&hostname);
g_hash_table_foreach (connections, output_conn, connections_dir);
g_hash_table_destroy (connections);
(const char *const *) remaining,
&hostname,
&carrier_timeout_sec);
if (dump_to_stdout) {
nm_clear_g_free (&connections_dir);
nm_clear_g_free (&initrd_dir);
nm_clear_g_free (&run_config_dir);
if (hostname)
g_print ("\n*** Hostname '%s' ***\n", hostname);
if (carrier_timeout_sec != 0) {
g_print ("\n*** Carrier Wait Timeout %" G_GINT64_FORMAT " sec ***\n",
carrier_timeout_sec);
}
} else {
if (g_mkdir_with_parents (connections_dir, 0755) != 0) {
errsv = errno;
_LOGW (LOGD_CORE, "%s: %s", connections_dir, nm_strerror_native (errsv));
return 1;
}
if (g_mkdir_with_parents (initrd_dir, 0755) != 0) {
errsv = errno;
_LOGW (LOGD_CORE, "%s: %s", initrd_dir, nm_strerror_native (errsv));
return 1;
}
if (g_mkdir_with_parents (run_config_dir, 0755) != 0) {
errsv = errno;
_LOGW (LOGD_CORE, "%s: %s", run_config_dir, nm_strerror_native (errsv));
return 1;
}
if (hostname) {
gs_free char *hostname_file = NULL;
@ -152,7 +167,32 @@ main (int argc, char *argv[])
return 1;
}
}
if (carrier_timeout_sec != 0) {
nm_auto_unref_keyfile GKeyFile *keyfile = NULL;
gs_free char *filename = NULL;
keyfile = g_key_file_new ();
g_key_file_set_list_separator (keyfile, NM_CONFIG_KEYFILE_LIST_SEPARATOR);
filename = g_strdup_printf ("%s/15-carrier-timeout.conf", run_config_dir);
g_key_file_set_value (keyfile,
NM_CONFIG_KEYFILE_GROUPPREFIX_DEVICE "-15-carrier-timeout",
NM_CONFIG_KEYFILE_KEY_MATCH_DEVICE,
"*");
g_key_file_set_int64 (keyfile,
NM_CONFIG_KEYFILE_GROUPPREFIX_DEVICE "-15-carrier-timeout",
NM_CONFIG_KEYFILE_KEY_DEVICE_CARRIER_WAIT_TIMEOUT,
carrier_timeout_sec * 1000);
if (!g_key_file_save_to_file (keyfile, filename, &error)) {
_LOGW (LOGD_CORE, "%s: %s", filename, error->message);
return 1;
}
}
}
g_hash_table_foreach (connections, output_conn, connections_dir);
g_hash_table_destroy (connections);
return 0;
}

View file

@ -36,6 +36,9 @@ gboolean nmi_ibft_update_connection_from_nic (NMConnection *connection, GHashTab
NMConnection *nmi_dt_reader_parse (const char *sysfs_dir);
GHashTable *nmi_cmdline_reader_parse (const char *sysfs_dir, const char *const*argv, char **hostname);
GHashTable *nmi_cmdline_reader_parse (const char *sysfs_dir,
const char *const *argv,
char **hostname,
gint64 *carrier_timeout_sec);
#endif /* __NM_INITRD_GENERATOR_H__ */

View file

@ -31,6 +31,8 @@ typedef struct {
gboolean ignore_auto_dns;
int dhcp_timeout;
char *dhcp4_vci;
gint64 carrier_timeout_sec;
} Reader;
static Reader *
@ -971,7 +973,10 @@ connection_set_needed_cb (gpointer key, gpointer value, gpointer user_data)
}
GHashTable *
nmi_cmdline_reader_parse (const char *sysfs_dir, const char *const*argv, char **hostname)
nmi_cmdline_reader_parse (const char *sysfs_dir,
const char *const*argv,
char **hostname,
gint64 *carrier_timeout_sec)
{
Reader *reader;
const char *tag;
@ -1006,6 +1011,9 @@ nmi_cmdline_reader_parse (const char *sysfs_dir, const char *const*argv, char **
} else if (nm_streq (tag, "rd.net.dhcp.vendor-class")) {
if (nm_utils_validate_dhcp4_vendor_class_id (argument, NULL))
nm_utils_strdup_reset (&reader->dhcp4_vci, argument);
} else if (nm_streq (tag, "rd.net.timeout.carrier")) {
reader->carrier_timeout_sec = _nm_utils_ascii_str_to_int64 (argument,
10, 0, G_MAXINT32, 0);
}
}
@ -1160,5 +1168,7 @@ nmi_cmdline_reader_parse (const char *sysfs_dir, const char *const*argv, char **
NM_SET_OUT (hostname, g_steal_pointer (&reader->hostname));
NM_SET_OUT (carrier_timeout_sec, reader->carrier_timeout_sec);
return reader_destroy (reader, FALSE);
}

View file

@ -31,11 +31,13 @@ test_auto (void)
NMSettingIPConfig *s_ip4;
NMSettingIPConfig *s_ip6;
gs_free char *hostname = NULL;
gint64 carrier_timeout_sec = 0;
connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV, &hostname);
connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV, &hostname, &carrier_timeout_sec);
g_assert (connections);
g_assert_cmpint (g_hash_table_size (connections), ==, 1);
g_assert_cmpstr (hostname, ==, NULL);
g_assert_cmpint (carrier_timeout_sec, ==, 0);
connection = g_hash_table_lookup (connections, "default_connection");
g_assert (connection);
@ -86,11 +88,13 @@ test_dhcp_with_hostname (void)
NMSettingIPConfig *s_ip4;
NMSettingIPConfig *s_ip6;
gs_free char *hostname = NULL;
gint64 carrier_timeout_sec = 0;
connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV, &hostname);
connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV, &hostname, &carrier_timeout_sec);
g_assert (connections);
g_assert_cmpint (g_hash_table_size (connections), ==, 1);
g_assert_cmpstr (hostname, ==, "host1");
g_assert_cmpint (carrier_timeout_sec, ==, 0);
connection = g_hash_table_lookup (connections, "default_connection");
g_assert (connection);
@ -138,11 +142,13 @@ test_dhcp_with_mtu (void)
NMSettingIPConfig *s_ip4;
NMSettingIPConfig *s_ip6;
gs_free char *hostname = NULL;
gint64 carrier_timeout_sec = 0;
connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV[i], &hostname);
connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV[i], &hostname, &carrier_timeout_sec);
g_assert (connections);
g_assert_cmpint (g_hash_table_size (connections), ==, 1);
g_assert_cmpstr (hostname, ==, NULL);
g_assert_cmpint (carrier_timeout_sec, ==, 0);
connection = g_hash_table_lookup (connections, "default_connection");
g_assert (connection);
@ -182,11 +188,13 @@ test_if_auto_with_mtu (void)
NMSettingIPConfig *s_ip4;
NMSettingIPConfig *s_ip6;
gs_free char *hostname = NULL;
gint64 carrier_timeout_sec = 0;
connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV, &hostname);
connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV, &hostname, &carrier_timeout_sec);
g_assert (connections);
g_assert_cmpint (g_hash_table_size (connections), ==, 1);
g_assert_cmpstr (hostname, ==, NULL);
g_assert_cmpint (carrier_timeout_sec, ==, 0);
connection = g_hash_table_lookup (connections, "eth0");
g_assert (connection);
@ -217,11 +225,13 @@ test_if_dhcp6 (void)
NMSettingIPConfig *s_ip4;
NMSettingIPConfig *s_ip6;
gs_free char *hostname = NULL;
gint64 carrier_timeout_sec = 0;
connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV, &hostname);
connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV, &hostname, &carrier_timeout_sec);
g_assert (connections);
g_assert_cmpint (g_hash_table_size (connections), ==, 1);
g_assert_cmpstr (hostname, ==, NULL);
g_assert_cmpint (carrier_timeout_sec, ==, 0);
connection = g_hash_table_lookup (connections, "eth1");
g_assert (connection);
@ -250,11 +260,13 @@ test_if_auto_with_mtu_and_mac (void)
NMSettingIPConfig *s_ip4;
NMSettingIPConfig *s_ip6;
gs_free char *hostname = NULL;
gint64 carrier_timeout_sec = 0;
connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV, &hostname);
connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV, &hostname, &carrier_timeout_sec);
g_assert (connections);
g_assert_cmpint (g_hash_table_size (connections), ==, 1);
g_assert_cmpstr (hostname, ==, NULL);
g_assert_cmpint (carrier_timeout_sec, ==, 0);
connection = g_hash_table_lookup (connections, "eth2");
g_assert (connection);
@ -292,11 +304,13 @@ test_if_ip4_manual (void)
NMSettingIPConfig *s_ip6;
NMIPAddress *ip_addr;
gs_free char *hostname = NULL;
gint64 carrier_timeout_sec = 0;
connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV, &hostname);
connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV, &hostname, &carrier_timeout_sec);
g_assert (connections);
g_assert_cmpint (g_hash_table_size (connections), ==, 2);
g_assert_cmpstr (hostname, ==, "hostname1.example.com");
g_assert_cmpint (carrier_timeout_sec, ==, 0);
connection = g_hash_table_lookup (connections, "eth3");
g_assert (connection);
@ -362,11 +376,13 @@ test_if_ip6_manual (void)
NMSettingIPConfig *s_ip6;
NMIPAddress *ip_addr;
gs_free char *hostname = NULL;
gint64 carrier_timeout_sec = 0;
connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV, &hostname);
connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV, &hostname, &carrier_timeout_sec);
g_assert (connections);
g_assert_cmpint (g_hash_table_size (connections), ==, 1);
g_assert_cmpstr (hostname, ==, "hostname0.example.com");
g_assert_cmpint (carrier_timeout_sec, ==, 0);
connection = g_hash_table_lookup (connections, "eth4");
g_assert (connection);
@ -411,11 +427,13 @@ test_if_off (void)
{"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},
};
gint64 carrier_timeout_sec = 0;
connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV, &hostname);
connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV, &hostname, &carrier_timeout_sec);
g_assert (connections);
g_assert_cmpint (g_hash_table_size (connections), ==, G_N_ELEMENTS (conn_expected));
g_assert_cmpstr (hostname, ==, NULL);
g_assert_cmpint (carrier_timeout_sec, ==, 0);
for (int i = 0; i < G_N_ELEMENTS (conn_expected); ++i) {
connection = g_hash_table_lookup (connections, conn_expected[i].name);
@ -443,11 +461,13 @@ test_if_mac_ifname (void)
NMSettingWired *s_wired;
NMIPAddress *ip_addr;
gs_free char *hostname = NULL;
gint64 carrier_timeout_sec = 0;
connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV, &hostname);
connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV, &hostname, &carrier_timeout_sec);
g_assert (connections);
g_assert_cmpint (g_hash_table_size (connections), ==, 1);
g_assert_cmpstr (hostname, ==, "hostname0");
g_assert_cmpint (carrier_timeout_sec, ==, 0);
connection = g_hash_table_lookup (connections, "00:11:22:33:44:55");
g_assert (connection);
@ -488,11 +508,13 @@ test_multiple_merge (void)
NMSettingIPConfig *s_ip6;
NMIPAddress *ip_addr;
gs_free char *hostname = NULL;
gint64 carrier_timeout_sec = 0;
connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV, &hostname);
connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV, &hostname, &carrier_timeout_sec);
g_assert (connections);
g_assert_cmpint (g_hash_table_size (connections), ==, 1);
g_assert_cmpstr (hostname, ==, NULL);
g_assert_cmpint (carrier_timeout_sec, ==, 0);
connection = g_hash_table_lookup (connections, "eth0");
g_assert (connection);
@ -540,11 +562,13 @@ test_multiple_bootdev (void)
NMSettingIPConfig *s_ip4;
NMSettingIPConfig *s_ip6;
gs_free char *hostname = NULL;
gint64 carrier_timeout_sec = 0;
connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV, &hostname);
connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV, &hostname, &carrier_timeout_sec);
g_assert (connections);
g_assert_cmpint (g_hash_table_size (connections), ==, 2);
g_assert_cmpstr (hostname, ==, NULL);
g_assert_cmpint (carrier_timeout_sec, ==, 0);
connection = g_hash_table_lookup (connections, "eth3");
g_assert (connection);
@ -575,11 +599,13 @@ test_bootdev (void)
NMConnection *connection;
NMSettingConnection *s_con;
gs_free char *hostname = NULL;
gint64 carrier_timeout_sec = 0;
connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV, &hostname);
connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV, &hostname, &carrier_timeout_sec);
g_assert (connections);
g_assert_cmpint (g_hash_table_size (connections), ==, 3);
g_assert_cmpstr (hostname, ==, NULL);
g_assert_cmpint (carrier_timeout_sec, ==, 0);
connection = g_hash_table_lookup (connections, "ens3");
g_assert (connection);
@ -630,11 +656,13 @@ test_some_more (void)
NMSettingIPConfig *s_ip6;
NMIPRoute *ip_route;
gs_free char *hostname = NULL;
gint64 carrier_timeout_sec = 0;
connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV, &hostname);
connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV, &hostname, &carrier_timeout_sec);
g_assert (connections);
g_assert_cmpint (g_hash_table_size (connections), ==, 2);
g_assert_cmpstr (hostname, ==, NULL);
g_assert_cmpint (carrier_timeout_sec, ==, 0);
connection = g_hash_table_lookup (connections, "eth1");
g_assert (connection);
@ -715,11 +743,13 @@ test_bond (void)
NMIPRoute *ip_route;
const char *master_uuid;
gs_free char *hostname = NULL;
gint64 carrier_timeout_sec = 0;
connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV, &hostname);
connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV, &hostname, &carrier_timeout_sec);
g_assert (connections);
g_assert_cmpint (g_hash_table_size (connections), ==, 3);
g_assert_cmpstr (hostname, ==, NULL);
g_assert_cmpint (carrier_timeout_sec, ==, 0);
connection = g_hash_table_lookup (connections, "bong0");
g_assert (connection);
@ -804,11 +834,13 @@ test_bond_ip (void)
NMIPAddress *ip_addr;
const char *master_uuid;
gs_free char *hostname = NULL;
gint64 carrier_timeout_sec = 0;
connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV, &hostname);
connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV, &hostname, &carrier_timeout_sec);
g_assert (connections);
g_assert_cmpint (g_hash_table_size (connections), ==, 3);
g_assert_cmpstr (hostname, ==, NULL);
g_assert_cmpint (carrier_timeout_sec, ==, 0);
connection = g_hash_table_lookup (connections, "bond0");
g_assert (connection);
@ -888,11 +920,13 @@ test_bond_default (void)
NMSettingBond *s_bond;
const char *master_uuid;
gs_free char *hostname = NULL;
gint64 carrier_timeout_sec = 0;
connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV, &hostname);
connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV, &hostname, &carrier_timeout_sec);
g_assert (connections);
g_assert_cmpint (g_hash_table_size (connections), ==, 2);
g_assert_cmpstr (hostname, ==, NULL);
g_assert_cmpint (carrier_timeout_sec, ==, 0);
connection = g_hash_table_lookup (connections, "bond0");
@ -953,11 +987,13 @@ test_bridge (void)
NMIPRoute *ip_route;
const char *master_uuid;
gs_free char *hostname = NULL;
gint64 carrier_timeout_sec = 0;
connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV, &hostname);
connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV, &hostname, &carrier_timeout_sec);
g_assert (connections);
g_assert_cmpint (g_hash_table_size (connections), ==, 3);
g_assert_cmpstr (hostname, ==, NULL);
g_assert_cmpint (carrier_timeout_sec, ==, 0);
connection = g_hash_table_lookup (connections, "bridge0");
g_assert (connection);
@ -1035,11 +1071,13 @@ test_bridge_default (void)
NMSettingBridge *s_bridge;
const char *master_uuid;
gs_free char *hostname = NULL;
gint64 carrier_timeout_sec = 0;
connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV, &hostname);
connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV, &hostname, &carrier_timeout_sec);
g_assert (connections);
g_assert_cmpint (g_hash_table_size (connections), ==, 2);
g_assert_cmpstr (hostname, ==, NULL);
g_assert_cmpint (carrier_timeout_sec, ==, 0);
connection = g_hash_table_lookup (connections, "br0");
@ -1098,11 +1136,13 @@ test_bridge_ip (void)
const char *master_uuid;
gs_free char *hostname = NULL;
guint i;
gint64 carrier_timeout_sec = 0;
connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV, &hostname);
connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV, &hostname, &carrier_timeout_sec);
g_assert (connections);
g_assert_cmpint (g_hash_table_size (connections), ==, 11);
g_assert_cmpstr (hostname, ==, NULL);
g_assert_cmpint (carrier_timeout_sec, ==, 0);
connection = g_hash_table_lookup (connections, "bridge123");
g_assert (connection);
@ -1160,11 +1200,13 @@ test_team (void)
NMSettingTeam *s_team;
const char *master_uuid;
gs_free char *hostname = NULL;
gint64 carrier_timeout_sec = 0;
connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV, &hostname);
connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV, &hostname, &carrier_timeout_sec);
g_assert (connections);
g_assert_cmpint (g_hash_table_size (connections), ==, 3);
g_assert_cmpstr (hostname, ==, NULL);
g_assert_cmpint (carrier_timeout_sec, ==, 0);
connection = g_hash_table_lookup (connections, "team0");
g_assert (connection);
@ -1235,11 +1277,13 @@ test_vlan (void)
NMSettingIPConfig *s_ip6;
NMSettingVlan *s_vlan;
gs_free char *hostname = NULL;
gint64 carrier_timeout_sec = 0;
connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV[i], &hostname);
connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV[i], &hostname, &carrier_timeout_sec);
g_assert (connections);
g_assert_cmpint (g_hash_table_size (connections), ==, 2);
g_assert_cmpstr (hostname, ==, NULL);
g_assert_cmpint (carrier_timeout_sec, ==, 0);
/* VLAN eth0.100 */
connection = g_hash_table_lookup (connections, "eth0.100");
@ -1305,11 +1349,13 @@ test_vlan_with_dhcp_on_parent (void)
NMSettingIPConfig *s_ip6;
NMSettingVlan *s_vlan;
gs_free char *hostname = NULL;
gint64 carrier_timeout_sec = 0;
connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV[i], &hostname);
connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV[i], &hostname, &carrier_timeout_sec);
g_assert (connections);
g_assert_cmpint (g_hash_table_size (connections), ==, 2);
g_assert_cmpstr (hostname, ==, NULL);
g_assert_cmpint (carrier_timeout_sec, ==, 0);
/* VLAN eth0.100 */
connection = g_hash_table_lookup (connections, "eth0.100");
@ -1382,11 +1428,13 @@ test_vlan_over_bond (void)
NMSettingIPConfig *s_ip6;
NMSettingVlan *s_vlan;
gs_free char *hostname = NULL;
gint64 carrier_timeout_sec = 0;
connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV[i], &hostname);
connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV[i], &hostname, &carrier_timeout_sec);
g_assert (connections);
g_assert_cmpint (g_hash_table_size (connections), ==, 4);
g_assert_cmpstr (hostname, ==, NULL);
g_assert_cmpint (carrier_timeout_sec, ==, 0);
/* VLAN vlan1 */
connection = g_hash_table_lookup (connections, "vlan1");
@ -1450,11 +1498,13 @@ test_ibft_ip_dev (void)
NMSettingConnection *s_con;
NMConnection *connection;
gs_free char *hostname = NULL;
gint64 carrier_timeout_sec = 0;
connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV, &hostname);
connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV, &hostname, &carrier_timeout_sec);
g_assert (connections);
g_assert_cmpint (g_hash_table_size (connections), ==, 1);
g_assert_cmpstr (hostname, ==, NULL);
g_assert_cmpint (carrier_timeout_sec, ==, 0);
connection = g_hash_table_lookup (connections, "eth0");
g_assert (connection);
@ -1473,11 +1523,13 @@ test_ibft_ip_dev_mac (void)
NMSettingConnection *s_con;
NMConnection *connection;
gs_free char *hostname = NULL;
gint64 carrier_timeout_sec = 0;
connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV, &hostname);
connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV, &hostname, &carrier_timeout_sec);
g_assert (connections);
g_assert_cmpint (g_hash_table_size (connections), ==, 1);
g_assert_cmpstr (hostname, ==, NULL);
g_assert_cmpint (carrier_timeout_sec, ==, 0);
connection = g_hash_table_lookup (connections, "00:53:06:66:AB:01");
g_assert (connection);
@ -1494,11 +1546,13 @@ _test_ibft_ip (const char *const*ARGV)
gs_unref_hashtable GHashTable *connections = NULL;
NMConnection *connection;
gs_free char *hostname = NULL;
gint64 carrier_timeout_sec = 0;
connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV, &hostname);
connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV, &hostname, &carrier_timeout_sec);
g_assert (connections);
g_assert_cmpint (g_hash_table_size (connections), ==, 2);
g_assert_cmpstr (hostname, ==, NULL);
g_assert_cmpint (carrier_timeout_sec, ==, 0);
connection = g_hash_table_lookup (connections, "ibft0");
g_assert (connection);
@ -1535,11 +1589,13 @@ test_ignore_extra (void)
gs_unref_hashtable GHashTable *connections = NULL;
const char *const*ARGV = NM_MAKE_STRV ("blabla", "extra", "lalala");
gs_free char *hostname = NULL;
gint64 carrier_timeout_sec = 0;
connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV, &hostname);
connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV, &hostname, &carrier_timeout_sec);
g_assert (connections);
g_assert_cmpint (g_hash_table_size (connections), ==, 0);
g_assert_cmpstr (hostname, ==, NULL);
g_assert_cmpint (carrier_timeout_sec, ==, 0);
}
static void
@ -1560,11 +1616,13 @@ test_rd_znet (void)
};
int i_s390_options_keys;
gs_free char *hostname = NULL;
gint64 carrier_timeout_sec = 0;
connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV, &hostname);
connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV, &hostname, &carrier_timeout_sec);
g_assert (connections);
g_assert_cmpint (g_hash_table_size (connections), ==, 2);
g_assert_cmpstr (hostname, ==, "foo.example.com");
g_assert_cmpint (carrier_timeout_sec, ==, 0);
connection = g_hash_table_lookup (connections, "enc800");
g_assert (NM_IS_CONNECTION (connection));
@ -1640,11 +1698,13 @@ test_rd_znet_legacy (void)
NMConnection *connection;
NMSettingConnection *s_con;
gs_free char *hostname = NULL;
gint64 carrier_timeout_sec = 0;
connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV, &hostname);
connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV, &hostname, &carrier_timeout_sec);
g_assert (connections);
g_assert_cmpint (g_hash_table_size (connections), ==, 2);
g_assert_cmpstr (hostname, ==, "foo.example.com");
g_assert_cmpint (carrier_timeout_sec, ==, 0);
connection = g_hash_table_lookup (connections, "eth0");
g_assert (NM_IS_CONNECTION (connection));
@ -1675,11 +1735,13 @@ test_rd_znet_no_ip (void)
gs_unref_hashtable GHashTable *connections = NULL;
const char *const*const ARGV = NM_MAKE_STRV ("rd.znet=qeth,0.0.0800,0.0.0801,0.0.0802,layer2=0,portno=1");
gs_free char *hostname = NULL;
gint64 carrier_timeout_sec = 0;
connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV, &hostname);
connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV, &hostname, &carrier_timeout_sec);
g_assert (connections);
g_assert_cmpint (g_hash_table_size (connections), ==, 0);
g_assert_cmpstr (hostname, ==, NULL);
g_assert_cmpint (carrier_timeout_sec, ==, 0);
}
static void
@ -1693,11 +1755,13 @@ test_bootif_ip (void)
NMSettingIPConfig *s_ip4;
NMSettingIPConfig *s_ip6;
gs_free char *hostname = NULL;
gint64 carrier_timeout_sec = 0;
connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV, &hostname);
connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV, &hostname, &carrier_timeout_sec);
g_assert (connections);
g_assert_cmpint (g_hash_table_size (connections), ==, 1);
g_assert_cmpstr (hostname, ==, NULL);
g_assert_cmpint (carrier_timeout_sec, ==, 0);
connection = g_hash_table_lookup (connections, "default_connection");
g_assert (connection);
@ -1731,11 +1795,13 @@ test_neednet (void)
NMConnection *connection;
NMSettingConnection *s_con;
gs_free char *hostname = NULL;
gint64 carrier_timeout_sec = 0;
connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV, &hostname);
connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV, &hostname, &carrier_timeout_sec);
g_assert (connections);
g_assert_cmpint (g_hash_table_size (connections), ==, 4);
g_assert_cmpstr (hostname, ==, NULL);
g_assert_cmpint (carrier_timeout_sec, ==, 0);
connection = g_hash_table_lookup (connections, "eno1");
g_assert (connection);
@ -1780,11 +1846,13 @@ test_bootif_no_ip (void)
NMSettingIPConfig *s_ip4;
NMSettingIPConfig *s_ip6;
gs_free char *hostname = NULL;
gint64 carrier_timeout_sec = 0;
connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV, &hostname);
connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV, &hostname, &carrier_timeout_sec);
g_assert (connections);
g_assert_cmpint (g_hash_table_size (connections), ==, 1);
g_assert_cmpstr (hostname, ==, NULL);
g_assert_cmpint (carrier_timeout_sec, ==, 0);
connection = g_hash_table_lookup (connections, "default_connection");
g_assert (connection);
@ -1817,11 +1885,13 @@ test_bootif_hwtype (void)
NMSettingIPConfig *s_ip4;
NMSettingIPConfig *s_ip6;
gs_free char *hostname = NULL;
gint64 carrier_timeout_sec = 0;
connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV, &hostname);
connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV, &hostname, &carrier_timeout_sec);
g_assert (connections);
g_assert_cmpint (g_hash_table_size (connections), ==, 2);
g_assert_cmpstr (hostname, ==, NULL);
g_assert_cmpint (carrier_timeout_sec, ==, 0);
connection = g_hash_table_lookup (connections, "eth0");
g_assert (connection);
@ -1882,11 +1952,13 @@ test_nameserver (void)
NMConnection *connection;
NMSettingIPConfig *s_ip;
gs_free char *hostname = NULL;
gint64 carrier_timeout_sec = 0;
connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV, &hostname);
connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV, &hostname, &carrier_timeout_sec);
g_assert (connections);
g_assert_cmpint (g_hash_table_size (connections), ==, 3);
g_assert_cmpstr (hostname, ==, "foo.example.com");
g_assert_cmpint (carrier_timeout_sec, ==, 0);
connection = g_hash_table_lookup (connections, "eth0");
g_assert (connection);
@ -1924,11 +1996,13 @@ test_bootif_off (void)
gs_unref_hashtable GHashTable *connections = NULL;
const char *const*ARGV = NM_MAKE_STRV ("BOOTIF=01-00-53-AB-cd-02-03", "rd.bootif=0");
gs_free char *hostname = NULL;
gint64 carrier_timeout_sec = 0;
connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV, &hostname);
connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV, &hostname, &carrier_timeout_sec);
g_assert (connections);
g_assert_cmpint (g_hash_table_size (connections), ==, 0);
g_assert_cmpstr (hostname, ==, NULL);
g_assert_cmpint (carrier_timeout_sec, ==, 0);
}
static void
@ -1942,11 +2016,13 @@ test_dhcp_vendor_class_id (void)
gs_free char *hostname = NULL;
gs_free char *vci_long = NULL;
char vci_arg_long[512] = {0};
gint64 carrier_timeout_sec = 0;
connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV, &hostname);
connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV, &hostname, &carrier_timeout_sec);
g_assert (connections);
g_assert_cmpint (g_hash_table_size (connections), ==, 1);
g_assert_cmpstr (hostname, ==, NULL);
g_assert_cmpint (carrier_timeout_sec, ==, 0);
connection = g_hash_table_lookup (connections, "eno1");
g_assert (connection);
@ -1958,12 +2034,13 @@ test_dhcp_vendor_class_id (void)
ARGV = NM_MAKE_STRV ("rd.net.dhcp.vendor-class",
"ip=eno1:dhcp");
connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV, &hostname);
connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV, &hostname, &carrier_timeout_sec);
connection = g_hash_table_lookup (connections, "eno1");
g_assert (connection);
nmtst_assert_connection_verifies_without_normalization (connection);
s_ip4 = NM_SETTING_IP4_CONFIG (nm_connection_get_setting_ip4_config (connection));
g_assert (nm_setting_ip4_config_get_dhcp_vendor_class_identifier (s_ip4) == NULL);
g_assert_cmpint (carrier_timeout_sec, ==, 0);
nm_clear_pointer (&connections, g_hash_table_unref);
@ -1971,12 +2048,13 @@ test_dhcp_vendor_class_id (void)
vci_long = g_strdup_printf ("rd.net.dhcp.vendor-class=%s", vci_arg_long);
ARGV = NM_MAKE_STRV (vci_long,
"ip=eno1:dhcp");
connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV, &hostname);
connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV, &hostname, &carrier_timeout_sec);
connection = g_hash_table_lookup (connections, "eno1");
g_assert (connection);
nmtst_assert_connection_verifies_without_normalization (connection);
s_ip4 = NM_SETTING_IP4_CONFIG (nm_connection_get_setting_ip4_config (connection));
g_assert (nm_setting_ip4_config_get_dhcp_vendor_class_identifier (s_ip4) == NULL);
g_assert_cmpint (carrier_timeout_sec, ==, 0);
}
static void
@ -1987,11 +2065,13 @@ test_infiniband_iface (void)
NMConnection *connection;
NMSettingInfiniband *s_ib;
gs_free char *hostname = NULL;
gint64 carrier_timeout_sec = 0;
connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV, &hostname);
connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV, &hostname, &carrier_timeout_sec);
g_assert (connections);
g_assert_cmpint (g_hash_table_size (connections), ==, 1);
g_assert_cmpstr (hostname, ==, NULL);
g_assert_cmpint (carrier_timeout_sec, ==, 0);
connection = g_hash_table_lookup (connections, "ib1");
g_assert (connection);
@ -2011,11 +2091,13 @@ test_infiniband_mac (void)
NMConnection *connection;
NMSettingInfiniband *s_ib;
gs_free char *hostname = NULL;
gint64 carrier_timeout_sec = 0;
connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV, &hostname);
connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV, &hostname, &carrier_timeout_sec);
g_assert (connections);
g_assert_cmpint (g_hash_table_size (connections), ==, 1);
g_assert_cmpstr (hostname, ==, NULL);
g_assert_cmpint (carrier_timeout_sec, ==, 0);
connection = g_hash_table_lookup (connections, "00:11:22:33:44:55:66:77:88:99:AA:BB:CC:DD:EE:FF:00:11:22:33");
g_assert (connection);
@ -2031,6 +2113,21 @@ test_infiniband_mac (void)
"00:11:22:33:44:55:66:77:88:99:AA:BB:CC:DD:EE:FF:00:11:22:33");
}
static void
test_carrier_timeout (void)
{
gs_unref_hashtable GHashTable *connections = NULL;
const char *const *ARGV = NM_MAKE_STRV ("rd.net.timeout.carrier=20");
gs_free char *hostname = NULL;
gint64 carrier_timeout_sec = 0;
connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV, &hostname, &carrier_timeout_sec);
g_assert (connections);
g_assert_cmpint (g_hash_table_size (connections), ==, 0);
g_assert_cmpstr (hostname, ==, NULL);
g_assert_cmpint (carrier_timeout_sec, ==, 20);
}
NMTST_DEFINE ();
int main (int argc, char **argv)
@ -2076,8 +2173,9 @@ int main (int argc, char **argv)
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/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/iface", test_infiniband_iface);
g_test_add_func ("/initrd/cmdline/infiniband/mac", test_infiniband_mac);
g_test_add_func ("/initrd/cmdline/carrier_timeout", test_carrier_timeout);
return g_test_run ();
}