From 92296fdf80be06196e97ed7b6c0479bb09d2c8ec Mon Sep 17 00:00:00 2001 From: Packit Service Date: Apr 07 2021 22:22:24 +0000 Subject: Apply patch 1025-initrd-timeout-carrier-rh1917773.patch patch_name: 1025-initrd-timeout-carrier-rh1917773.patch present_in_specfile: true location_in_specfile: 27 --- diff --git a/man/nm-initrd-generator.xml b/man/nm-initrd-generator.xml index 37f5ffd..fcfb54f 100644 --- a/man/nm-initrd-generator.xml +++ b/man/nm-initrd-generator.xml @@ -105,6 +105,20 @@ + + + + path + + + + Output directory for config files. + + + + + + @@ -133,6 +147,7 @@ + diff --git a/shared/nm-glib-aux/nm-macros-internal.h b/shared/nm-glib-aux/nm-macros-internal.h index 57ddee0..63ae67b 100644 --- a/shared/nm-glib-aux/nm-macros-internal.h +++ b/shared/nm-glib-aux/nm-macros-internal.h @@ -253,6 +253,9 @@ static inline int nm_close (int fd); NM_AUTO_DEFINE_FCN_VOID0 (void *, _nm_auto_free_impl, free) #define nm_auto_free nm_auto(_nm_auto_free_impl) +NM_AUTO_DEFINE_FCN0 (GKeyFile *, _nm_auto_unref_keyfile, g_key_file_unref); +#define nm_auto_unref_keyfile nm_auto(_nm_auto_unref_keyfile) + NM_AUTO_DEFINE_FCN0 (GVariantIter *, _nm_auto_free_variant_iter, g_variant_iter_free) #define nm_auto_free_variant_iter nm_auto(_nm_auto_free_variant_iter) diff --git a/src/initrd/nm-initrd-generator.c b/src/initrd/nm-initrd-generator.c index 5a93480..5b92763 100644 --- a/src/initrd/nm-initrd-generator.c +++ b/src/initrd/nm-initrd-generator.c @@ -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; } diff --git a/src/initrd/nm-initrd-generator.h b/src/initrd/nm-initrd-generator.h index e7647ed..9a2068b 100644 --- a/src/initrd/nm-initrd-generator.h +++ b/src/initrd/nm-initrd-generator.h @@ -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__ */ diff --git a/src/initrd/nmi-cmdline-reader.c b/src/initrd/nmi-cmdline-reader.c index 17e0ce5..b114079 100644 --- a/src/initrd/nmi-cmdline-reader.c +++ b/src/initrd/nmi-cmdline-reader.c @@ -31,6 +31,8 @@ typedef struct { gboolean ignore_auto_dns; int dhcp_timeout; char *dhcp4_vci; + + gint64 carrier_timeout_sec; } Reader; static Reader * @@ -970,7 +972,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; @@ -1005,6 +1010,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); } } @@ -1159,5 +1167,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); } diff --git a/src/initrd/tests/test-cmdline-reader.c b/src/initrd/tests/test-cmdline-reader.c index c4c5c74..259b1c4 100644 --- a/src/initrd/tests/test-cmdline-reader.c +++ b/src/initrd/tests/test-cmdline-reader.c @@ -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); @@ -400,11 +416,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); @@ -445,11 +463,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); @@ -497,11 +517,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); @@ -532,11 +554,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); @@ -587,11 +611,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); @@ -671,11 +697,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); @@ -756,11 +784,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); @@ -840,11 +870,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"); @@ -905,11 +937,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); @@ -987,11 +1021,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"); @@ -1050,11 +1086,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); @@ -1112,11 +1150,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); @@ -1187,11 +1227,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"); @@ -1257,11 +1299,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"); @@ -1334,11 +1378,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"); @@ -1402,11 +1448,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); @@ -1425,11 +1473,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); @@ -1446,11 +1496,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); @@ -1487,11 +1539,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 @@ -1512,11 +1566,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)); @@ -1592,11 +1648,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)); @@ -1627,11 +1685,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 @@ -1645,11 +1705,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); @@ -1683,11 +1745,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); @@ -1732,11 +1796,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); @@ -1769,11 +1835,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); @@ -1834,11 +1902,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); @@ -1876,11 +1946,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 @@ -1894,11 +1966,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); @@ -1910,12 +1984,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); @@ -1923,12 +1998,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 @@ -1939,11 +2015,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); @@ -1963,11 +2041,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); @@ -1983,6 +2063,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) @@ -2027,8 +2122,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 (); }