diff options
Diffstat (limited to 'src/nm-initrd-generator')
| -rw-r--r-- | src/nm-initrd-generator/nm-initrd-generator.c | 55 | ||||
| -rw-r--r-- | src/nm-initrd-generator/nm-initrd-generator.h | 7 | ||||
| -rw-r--r-- | src/nm-initrd-generator/nmi-cmdline-reader.c | 265 | ||||
| -rw-r--r-- | src/nm-initrd-generator/nmi-dt-reader.c | 46 | ||||
| -rw-r--r-- | src/nm-initrd-generator/nmi-ibft-reader.c | 52 | ||||
| -rw-r--r-- | src/nm-initrd-generator/tests/test-cmdline-reader.c | 471 | ||||
| -rw-r--r-- | src/nm-initrd-generator/tests/test-dt-reader.c | 20 | ||||
| -rw-r--r-- | src/nm-initrd-generator/tests/test-ibft-reader.c | 62 |
8 files changed, 548 insertions, 430 deletions
diff --git a/src/nm-initrd-generator/nm-initrd-generator.c b/src/nm-initrd-generator/nm-initrd-generator.c index b78808b2..981cb14b 100644 --- a/src/nm-initrd-generator/nm-initrd-generator.c +++ b/src/nm-initrd-generator/nm-initrd-generator.c @@ -28,14 +28,14 @@ static void output_conn(gpointer key, gpointer value, gpointer user_data) { - const char * basename = key; - NMConnection * connection = value; - char * connections_dir = user_data; - nm_auto_unref_keyfile GKeyFile *file = NULL; - gs_free char * data = NULL; - gs_free_error GError *error = NULL; - gsize len; - NMSetting * setting; + const char *basename = key; + NMConnection *connection = value; + char *connections_dir = user_data; + nm_auto_unref_keyfile GKeyFile *file = NULL; + 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); @@ -79,14 +79,15 @@ err_out: int main(int argc, char *argv[]) { - GHashTable * connections; - 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[] = { + GHashTable *connections; + gs_free char *connections_dir = NULL; + gs_free char *etc_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, @@ -94,6 +95,13 @@ main(int argc, char *argv[]) &connections_dir, "Output connection directory", NM_KEYFILE_PATH_NAME_RUN}, + {"persistent-connections-dir", + 'p', + 0, + G_OPTION_ARG_FILENAME, + &etc_connections_dir, + "Persistent connection directory", + NM_KEYFILE_PATH_NAME_ETC_DEFAULT}, {"initrd-data-dir", 'i', 0, @@ -125,10 +133,10 @@ main(int argc, char *argv[]) {G_OPTION_REMAINING, '\0', 0, G_OPTION_ARG_STRING_ARRAY, &remaining, NULL, NULL}, {NULL}}; nm_auto_free_option_context GOptionContext *option_context = NULL; - gs_free_error GError *error = NULL; - gs_free char * hostname = NULL; - int errsv; - gint64 carrier_timeout_sec = 0; + 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=...] " @@ -153,6 +161,8 @@ main(int argc, char *argv[]) return 0; } + if (!etc_connections_dir) + etc_connections_dir = g_strdup(NM_KEYFILE_PATH_NAME_ETC_DEFAULT); if (!connections_dir) connections_dir = g_strdup(NM_KEYFILE_PATH_NAME_RUN); if (!sysfs_dir) @@ -162,7 +172,8 @@ main(int argc, char *argv[]) if (!run_config_dir) run_config_dir = g_strdup(DEFAULT_RUN_CONFIG_DIR); - connections = nmi_cmdline_reader_parse(sysfs_dir, + connections = nmi_cmdline_reader_parse(etc_connections_dir, + sysfs_dir, (const char *const *) remaining, &hostname, &carrier_timeout_sec); @@ -207,7 +218,7 @@ main(int argc, char *argv[]) } if (carrier_timeout_sec != 0) { nm_auto_unref_keyfile GKeyFile *keyfile = NULL; - gs_free char * filename = NULL; + gs_free char *filename = NULL; keyfile = g_key_file_new(); g_key_file_set_list_separator(keyfile, NM_CONFIG_KEYFILE_LIST_SEPARATOR); diff --git a/src/nm-initrd-generator/nm-initrd-generator.h b/src/nm-initrd-generator/nm-initrd-generator.h index 2ec52a01..4f33ac65 100644 --- a/src/nm-initrd-generator/nm-initrd-generator.h +++ b/src/nm-initrd-generator/nm-initrd-generator.h @@ -38,9 +38,10 @@ nmi_ibft_update_connection_from_nic(NMConnection *connection, GHashTable *nic, G NMConnection *nmi_dt_reader_parse(const char *sysfs_dir); -GHashTable *nmi_cmdline_reader_parse(const char * sysfs_dir, +GHashTable *nmi_cmdline_reader_parse(const char *etc_connections_dir, + const char *sysfs_dir, const char *const *argv, - char ** hostname, - gint64 * carrier_timeout_sec); + char **hostname, + gint64 *carrier_timeout_sec); #endif /* __NM_INITRD_GENERATOR_H__ */ diff --git a/src/nm-initrd-generator/nmi-cmdline-reader.c b/src/nm-initrd-generator/nmi-cmdline-reader.c index 8fafb08f..412c7510 100644 --- a/src/nm-initrd-generator/nmi-cmdline-reader.c +++ b/src/nm-initrd-generator/nmi-cmdline-reader.c @@ -27,18 +27,19 @@ /*****************************************************************************/ typedef struct { - GHashTable * hash; - GPtrArray * array; - GPtrArray * vlan_parents; - GHashTable * explicit_ip_connections; + GHashTable *hash; + GPtrArray *array; + GPtrArray *vlan_parents; + GHashTable *explicit_ip_connections; NMConnection *bootdev_connection; /* connection for bootdev=$ifname */ NMConnection *default_connection; /* connection not bound to any ifname */ - char * hostname; + char *hostname; + GHashTable *znet_ifnames; /* Parameters to be set for all connections */ gboolean ignore_auto_dns; int dhcp_timeout; - char * dhcp4_vci; + char *dhcp4_vci; gint64 carrier_timeout_sec; } Reader; @@ -55,6 +56,7 @@ reader_new(void) g_hash_table_new_full(nm_direct_hash, NULL, g_object_unref, NULL), .vlan_parents = g_ptr_array_new_with_free_func(g_free), .array = g_ptr_array_new(), + .znet_ifnames = g_hash_table_new_full(nm_str_hash, g_str_equal, g_free, g_free), }; return reader; @@ -70,6 +72,7 @@ reader_destroy(Reader *reader, gboolean free_hash) g_hash_table_unref(reader->explicit_ip_connections); hash = g_steal_pointer(&reader->hash); nm_clear_g_free(&reader->hostname); + g_hash_table_unref(reader->znet_ifnames); nm_clear_g_free(&reader->dhcp4_vci); nm_g_slice_free(reader); if (!free_hash) @@ -91,16 +94,16 @@ reader_add_connection(Reader *reader, const char *name, NMConnection *connection /* Returns a new connection owned by the reader */ static NMConnection * -reader_create_connection(Reader * reader, - const char * basename, - const char * id, - const char * ifname, - const char * mac, - const char * type_name, +reader_create_connection(Reader *reader, + const char *basename, + const char *id, + const char *ifname, + const char *mac, + const char *type_name, NMConnectionMultiConnect multi_connect) { NMConnection *connection; - NMSetting * setting; + NMSetting *setting; connection = reader_add_connection(reader, basename, nm_simple_connection_new()); @@ -195,14 +198,14 @@ reader_get_default_connection(Reader *reader) } static NMConnection * -reader_get_connection(Reader * reader, +reader_get_connection(Reader *reader, const char *iface_spec, const char *type_name, gboolean create_if_missing) { NMConnection *connection = NULL; - NMSetting * setting; - const char * ifname = NULL; + NMSetting *setting; + const char *ifname = NULL; gs_free char *mac = NULL; if (iface_spec) { @@ -216,7 +219,7 @@ reader_get_connection(Reader * reader, } if (!ifname && !mac) { - NMConnection * candidate; + NMConnection *candidate; NMSettingConnection *s_con; guint i; @@ -314,14 +317,14 @@ get_word(char **argument, const char separator) static void connection_set(NMConnection *connection, - const char * setting_name, - const char * property, - const char * value) + const char *setting_name, + const char *property, + const char *value) { - NMSetting * setting; - GType setting_type; + NMSetting *setting; + GType setting_type; nm_auto_unref_gtypeclass GObjectClass *object_class = NULL; - GParamSpec * spec; + GParamSpec *spec; setting_type = nm_setting_lookup_type(setting_name); object_class = g_type_class_ref(setting_type); @@ -355,20 +358,20 @@ static void reader_read_all_connections_from_fw(Reader *reader, const char *sysfs_dir) { gs_unref_hashtable GHashTable *ibft = NULL; - NMConnection * dt_connection; - const char * mac; - GHashTable * nic; - const char * index; - GError * error = NULL; + NMConnection *dt_connection; + const char *mac; + GHashTable *nic; + const char *index; + GError *error = NULL; guint i, length; - gs_free const char ** keys = NULL; + gs_free const char **keys = NULL; ibft = nmi_ibft_read(sysfs_dir); keys = nm_strdict_get_keys(ibft, TRUE, &length); for (i = 0; i < length; i++) { gs_unref_object NMConnection *connection = NULL; - gs_free char * name = NULL; + gs_free char *name = NULL; mac = keys[i]; nic = g_hash_table_lookup(ibft, mac); @@ -426,7 +429,7 @@ _parse_ip_method(const char *kind) "auto", "ibft", }; - gs_free char * kind_to_free = NULL; + gs_free char *kind_to_free = NULL; gs_free const char **strv = NULL; gsize i; @@ -512,26 +515,26 @@ _parse_ip_method(const char *kind) static void reader_parse_ip(Reader *reader, const char *sysfs_dir, char *argument) { - NMConnection * connection; - NMSettingConnection *s_con; - NMSettingIPConfig * s_ip4 = NULL, *s_ip6 = NULL; + NMConnection *connection; + NMSettingConnection *s_con; + NMSettingIPConfig *s_ip4 = NULL, *s_ip6 = NULL; gs_unref_hashtable GHashTable *ibft = NULL; - const char * tmp; - const char * tmp2; - const char * tmp3; - const char * kind; - 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; + const char *tmp; + const char *tmp2; + const char *tmp3; + const char *kind; + 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] = { + const char *dns[2] = { NULL, NULL, }; @@ -770,11 +773,11 @@ reader_parse_ip(Reader *reader, const char *sysfs_dir, char *argument) } } else if (nm_streq(kind, "ibft")) { NMSettingWired *s_wired; - const char * mac = NULL; - const char * ifname; - gs_free char * mac_free = NULL; - gs_free char * address_path = NULL; - GHashTable * nic = NULL; + const char *mac = NULL; + const char *ifname; + gs_free char *mac_free = NULL; + gs_free char *address_path = NULL; + GHashTable *nic = NULL; if ((s_wired = nm_connection_get_setting_wired(connection)) && (mac = nm_setting_wired_get_mac_address(s_wired))) { @@ -857,14 +860,14 @@ reader_parse_ip(Reader *reader, const char *sysfs_dir, char *argument) static void reader_parse_master(Reader *reader, char *argument, const char *type_name, const char *default_name) { - NMConnection * connection; + NMConnection *connection; NMSettingConnection *s_con; - gs_free char * master_to_free = NULL; - const char * master; - char * slaves; - const char * slave; - char * opts; - const char * mtu = NULL; + gs_free char *master_to_free = NULL; + const char *master; + char *slaves; + const char *slave; + char *opts; + const char *mtu = NULL; master = get_word(&argument, ':'); if (!master) @@ -886,8 +889,8 @@ reader_parse_master(Reader *reader, char *argument, const char *type_name, const opts = get_word(&argument, ':'); while (opts && *opts) { gs_free_error GError *error = NULL; - char * opt; - const char * opt_name; + char *opt; + const char *opt_name; opt = get_word(&opts, ','); opt_name = get_word(&opt, '='); @@ -934,17 +937,17 @@ reader_add_routes(Reader *reader, GPtrArray *array) guint i; for (i = 0; i < array->len; i++) { - NMConnection * connection = NULL; - const char * net; - const char * gateway; - const char * interface; - int family = AF_UNSPEC; - NMIPAddr net_addr = {}; - NMIPAddr gateway_addr = {}; - int net_prefix = -1; - NMIPRoute * route; - NMSettingIPConfig *s_ip; - char * argument; + NMConnection *connection = NULL; + const char *net; + const char *gateway; + const char *interface; + int family = AF_UNSPEC; + NMIPAddr net_addr = {}; + NMIPAddr gateway_addr = {}; + int net_prefix = -1; + NMIPRoute *route; + NMSettingIPConfig *s_ip; + char *argument; gs_free_error GError *error = NULL; argument = array->pdata[i]; @@ -1010,11 +1013,11 @@ reader_add_routes(Reader *reader, GPtrArray *array) static void reader_parse_vlan(Reader *reader, char *argument) { - NMConnection * connection; + NMConnection *connection; NMSettingVlan *s_vlan; - const char * vlan; - const char * phy; - const char * vlanid; + const char *vlan; + const char *phy; + const char *vlanid; vlan = get_word(&argument, ':'); phy = get_word(&argument, ':'); @@ -1044,11 +1047,11 @@ reader_parse_vlan(Reader *reader, char *argument) static void reader_parse_ib_pkey(Reader *reader, char *argument) { - NMConnection * connection; + NMConnection *connection; NMSettingInfiniband *s_ib; - char * ifname; - gs_free char * parent = NULL; - char * pkey; + char *ifname; + gs_free char *parent = NULL; + char *pkey; gint64 pkey_int; /* At the moment we only support ib.pkey=<parent>.<pkey>; @@ -1092,18 +1095,35 @@ reader_parse_ib_pkey(Reader *reader, char *argument) } static void +reader_parse_znet_ifname(Reader *reader, char *argument) +{ + char *ifname; + + ifname = get_word(&argument, ':'); + if (!ifname) { + _LOGW(LOGD_CORE, "rd.znet_ifname= without argument"); + return; + } + + if (!g_hash_table_replace(reader->znet_ifnames, g_strdup(argument), g_strdup(ifname))) { + _LOGW(LOGD_CORE, "duplicate rd.znet_ifname for ifname=%s", ifname); + } +} + +static void reader_parse_rd_znet(Reader *reader, char *argument, gboolean net_ifnames) { - const char * nettype; - const char * subchannels[4] = {0, 0, 0, 0}; - const char * tmp; - gs_free char * ifname = NULL; - const char * prefix; - NMConnection * connection; + const char *nettype; + const char *subchannels[4] = {0, 0, 0, 0}; + const char *tmp; + gs_free char *ifname = NULL; + gs_free char *str_subchannels = NULL; + const char *prefix; + NMConnection *connection; NMSettingWired *s_wired; static int count_ctc = 0; static int count_eth = 0; - int index; + int index = -1; nettype = get_word(&argument, ','); subchannels[0] = get_word(&argument, ','); @@ -1131,7 +1151,13 @@ reader_parse_rd_znet(Reader *reader, char *argument, gboolean net_ifnames) } } - if (net_ifnames == TRUE) { + str_subchannels = g_strjoinv(",", (char **) subchannels); + ifname = g_hash_table_lookup(reader->znet_ifnames, str_subchannels); + + if (ifname) { + ifname = g_strdup(ifname); + g_hash_table_remove(reader->znet_ifnames, str_subchannels); + } else if (net_ifnames == TRUE) { const char *bus_id; size_t bus_id_len; size_t bus_id_start; @@ -1144,6 +1170,7 @@ reader_parse_rd_znet(Reader *reader, char *argument, gboolean net_ifnames) ifname = g_strdup_printf("%sc%s", prefix, bus_id); } else { + nm_assert(index > -1); ifname = g_strdup_printf("%s%d", prefix, index); } @@ -1160,7 +1187,7 @@ reader_parse_rd_znet(Reader *reader, char *argument, gboolean net_ifnames) while ((tmp = get_word(&argument, ',')) != NULL) { const char *key; - char * val; + char *val; val = strchr(tmp, '='); if (!val) { @@ -1184,11 +1211,11 @@ reader_parse_rd_znet(Reader *reader, char *argument, gboolean net_ifnames) static void reader_parse_ethtool(Reader *reader, char *argument) { - NMConnection * connection; + NMConnection *connection; NMSettingWired *s_wired; - const char * autoneg_str; - const char * speed_str; - const char * interface; + const char *autoneg_str; + const char *speed_str; + const char *interface; int autoneg; guint speed; @@ -1251,11 +1278,11 @@ _normalize_conn(gpointer key, gpointer value, gpointer user_data) static void reader_add_nameservers(Reader *reader, GPtrArray *nameservers) { - NMConnection * connection; + NMConnection *connection; NMSettingIPConfig *s_ip; GHashTableIter iter; int addr_family; - const char * ns; + const char *ns; guint i; for (i = 0; i < nameservers->len; i++) { @@ -1316,21 +1343,22 @@ connection_set_needed_cb(gpointer key, gpointer value, gpointer user_data) } GHashTable * -nmi_cmdline_reader_parse(const char * sysfs_dir, +nmi_cmdline_reader_parse(const char *etc_connections_dir, + const char *sysfs_dir, const char *const *argv, - char ** hostname, - gint64 * carrier_timeout_sec) + char **hostname, + gint64 *carrier_timeout_sec) { - Reader * reader; - const char * tag; - gboolean ignore_bootif = FALSE; - gboolean neednet = FALSE; - gs_free char * bootif_val = NULL; - gs_free char * bootdev = NULL; - gboolean net_ifnames = TRUE; - gs_unref_ptrarray GPtrArray *nameservers = NULL; - gs_unref_ptrarray GPtrArray *routes = NULL; - gs_unref_ptrarray GPtrArray *znets = NULL; + Reader *reader; + const char *tag; + gboolean ignore_bootif = FALSE; + gboolean neednet = FALSE; + gs_free char *bootif_val = NULL; + gs_free char *bootdev = NULL; + gboolean net_ifnames = TRUE; + gs_unref_ptrarray GPtrArray *nameservers = NULL; + gs_unref_ptrarray GPtrArray *routes = NULL; + gs_unref_ptrarray GPtrArray *znets = NULL; int i; guint64 dhcp_timeout = 90; guint64 dhcp_num_tries = 1; @@ -1339,7 +1367,7 @@ nmi_cmdline_reader_parse(const char * sysfs_dir, for (i = 0; argv[i]; i++) { gs_free char *argument_clone = NULL; - char * argument; + char *argument; argument_clone = g_strdup(argv[i]); argument = argument_clone; @@ -1375,8 +1403,8 @@ nmi_cmdline_reader_parse(const char * sysfs_dir, for (i = 0; argv[i]; i++) { gs_free char *argument_clone = NULL; - char * argument; - char * word; + char *argument; + char *word; argument_clone = g_strdup(argv[i]); argument = argument_clone; @@ -1422,6 +1450,8 @@ nmi_cmdline_reader_parse(const char * sysfs_dir, if (!znets) znets = g_ptr_array_new_with_free_func(g_free); g_ptr_array_add(znets, g_strdup(argument)); + } else if (nm_streq(tag, "rd.znet_ifname")) { + reader_parse_znet_ifname(reader, argument); } else if (g_ascii_strcasecmp(tag, "BOOTIF") == 0) { nm_clear_g_free(&bootif_val); bootif_val = g_strdup(argument); @@ -1430,7 +1460,7 @@ nmi_cmdline_reader_parse(const char * sysfs_dir, } for (i = 0; i < reader->vlan_parents->len; i++) { - NMConnection * connection; + NMConnection *connection; NMSettingIPConfig *s_ip; /* Disable IP configuration for parent connections of VLANs, @@ -1459,9 +1489,9 @@ nmi_cmdline_reader_parse(const char * sysfs_dir, if (ignore_bootif) nm_clear_g_free(&bootif_val); if (bootif_val) { - NMConnection * connection; + NMConnection *connection; NMSettingWired *s_wired; - const char * bootif = bootif_val; + const char *bootif = bootif_val; char prefix[4]; if (!nm_utils_hwaddr_valid(bootif, ETH_ALEN)) { @@ -1512,7 +1542,8 @@ nmi_cmdline_reader_parse(const char * sysfs_dir, } if (neednet) { - if (g_hash_table_size(reader->hash) == 0) { + if (!(etc_connections_dir && g_file_test(etc_connections_dir, G_FILE_TEST_IS_DIR)) + && g_hash_table_size(reader->hash) == 0) { /* Make sure there's some connection. */ reader_get_default_connection(reader); } @@ -1531,6 +1562,10 @@ nmi_cmdline_reader_parse(const char * sysfs_dir, reader_parse_rd_znet(reader, znets->pdata[i], net_ifnames); } + if (g_hash_table_size(reader->znet_ifnames)) { + _LOGW(LOGD_CORE, "Mismatch between rd.znet_ifname and rd.znet"); + } + g_hash_table_foreach(reader->hash, _normalize_conn, NULL); NM_SET_OUT(hostname, g_steal_pointer(&reader->hostname)); diff --git a/src/nm-initrd-generator/nmi-dt-reader.c b/src/nm-initrd-generator/nmi-dt-reader.c index 99c149dc..8bd591a8 100644 --- a/src/nm-initrd-generator/nmi-dt-reader.c +++ b/src/nm-initrd-generator/nmi-dt-reader.c @@ -28,11 +28,11 @@ static gboolean dt_get_property(const char *base, const char *dev, const char *prop, - char ** contents, - size_t * length) + char **contents, + size_t *length) { - gs_free char *filename = g_build_filename(base, dev, prop, NULL); - gs_free_error GError *error = NULL; + gs_free char *filename = g_build_filename(base, dev, prop, NULL); + gs_free_error GError *error = NULL; if (!g_file_test(filename, G_FILE_TEST_EXISTS)) return FALSE; @@ -106,31 +106,31 @@ str_addr(const char *str, int *family) NMConnection * nmi_dt_reader_parse(const char *sysfs_dir) { - gs_unref_object NMConnection *connection = NULL; - gs_free char * base = NULL; - gs_free char * bootpath = NULL; - gs_strfreev char ** tokens = NULL; - char * path = NULL; - gboolean bootp = FALSE; - const char * s_ipaddr = NULL; - const char * s_netmask = NULL; - const char * s_gateway = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_free char *base = NULL; + gs_free char *bootpath = NULL; + gs_strfreev char **tokens = NULL; + char *path = NULL; + gboolean bootp = FALSE; + const char *s_ipaddr = NULL; + const char *s_netmask = NULL; + const char *s_gateway = NULL; nm_auto_unref_ip_address NMIPAddress *ipaddr = NULL; nm_auto_unref_ip_address NMIPAddress *gateway = NULL; - const char * duplex = NULL; - gs_free char * hwaddr = NULL; - gs_free char * local_hwaddr = NULL; - gs_free char * hostname = NULL; + const char *duplex = NULL; + gs_free char *hwaddr = NULL; + gs_free char *local_hwaddr = NULL; + gs_free char *hostname = NULL; guint32 speed = 0; int prefix = -1; - NMSettingIPConfig * s_ip = NULL; - NMSetting * s_ip4 = NULL; - NMSetting * s_ip6 = NULL; - NMSetting * s_wired = NULL; + NMSettingIPConfig *s_ip = NULL; + NMSetting *s_ip4 = NULL; + NMSetting *s_ip6 = NULL; + NMSetting *s_wired = NULL; int family = AF_UNSPEC; int i = 0; - char * c; - gs_free_error GError *error = NULL; + char *c; + gs_free_error GError *error = NULL; base = g_build_filename(sysfs_dir, "firmware", "devicetree", "base", NULL); diff --git a/src/nm-initrd-generator/nmi-ibft-reader.c b/src/nm-initrd-generator/nmi-ibft-reader.c index b3db3f01..196bb141 100644 --- a/src/nm-initrd-generator/nmi-ibft-reader.c +++ b/src/nm-initrd-generator/nmi-ibft-reader.c @@ -36,12 +36,12 @@ static GHashTable * load_one_nic(const char *sysfs_dir, const char *dir_name) { - gs_free char *nic_path = g_build_filename(sysfs_dir, dir_name, NULL); - GDir * nic_dir; - const char * entry_name; - char * content; + gs_free char *nic_path = g_build_filename(sysfs_dir, dir_name, NULL); + GDir *nic_dir; + const char *entry_name; + char *content; gs_free_error GError *error = NULL; - GHashTable * nic; + GHashTable *nic; g_return_val_if_fail(sysfs_dir != NULL, FALSE); @@ -77,11 +77,11 @@ load_one_nic(const char *sysfs_dir, const char *dir_name) GHashTable * nmi_ibft_read(const char *sysfs_dir) { - gs_free char *ibft_path = NULL; - GDir * ibft_dir; - const char * dir_name; - GHashTable * ibft, *nic; - char * mac; + gs_free char *ibft_path = NULL; + GDir *ibft_dir; + const char *dir_name; + GHashTable *ibft, *nic; + char *mac; gs_free_error GError *error = NULL; g_return_val_if_fail(sysfs_dir != NULL, FALSE); @@ -133,14 +133,14 @@ ip_setting_add_from_block(GHashTable *nic, NMConnection *connection, GError **er NMSettingIPConfig *s_ip = NULL; NMSettingIPConfig *s_ip4 = NULL; NMSettingIPConfig *s_ip6 = NULL; - NMIPAddress * addr; - const char * s_ipaddr = NULL; - const char * s_prefix = NULL; - const char * s_gateway = NULL; - const char * s_dns1 = NULL; - const char * s_dns2 = NULL; - const char * s_origin = NULL; - const char * method = NULL; + NMIPAddress *addr; + const char *s_ipaddr = NULL; + const char *s_prefix = NULL; + const char *s_gateway = NULL; + const char *s_dns1 = NULL; + const char *s_dns2 = NULL; + const char *s_origin = NULL; + const char *method = NULL; int family; gint64 prefix; @@ -276,14 +276,14 @@ ip_setting_add_from_block(GHashTable *nic, NMConnection *connection, GError **er } static gboolean -connection_setting_add(GHashTable * nic, +connection_setting_add(GHashTable *nic, NMConnection *connection, - const char * type, - const char * prefix, - GError ** error) + const char *type, + const char *prefix, + GError **error) { - NMSetting * s_con; - char * id, *uuid; + NMSetting *s_con; + char *id, *uuid; const char *s_index, *s_hwaddr, *s_ipaddr, *s_vlanid; s_index = (const char *) g_hash_table_lookup(nic, "index"); @@ -359,7 +359,7 @@ is_ibft_vlan_device(GHashTable *nic) static gboolean vlan_setting_add_from_block(GHashTable *nic, NMConnection *connection, GError **error) { - NMSetting * s_vlan = NULL; + NMSetting *s_vlan = NULL; const char *vlan_id_str = NULL; gint64 vlan_id = -1; @@ -397,7 +397,7 @@ vlan_setting_add_from_block(GHashTable *nic, NMConnection *connection, GError ** static gboolean wired_setting_add_from_block(GHashTable *nic, NMConnection *connection, GError **error) { - NMSetting * s_wired = NULL; + NMSetting *s_wired = NULL; const char *hwaddr = NULL; g_assert(nic); diff --git a/src/nm-initrd-generator/tests/test-cmdline-reader.c b/src/nm-initrd-generator/tests/test-cmdline-reader.c index 2cb1b2f4..d7b7b3cb 100644 --- a/src/nm-initrd-generator/tests/test-cmdline-reader.c +++ b/src/nm-initrd-generator/tests/test-cmdline-reader.c @@ -27,9 +27,10 @@ const char *const *const _ARGV = (ARGV); \ char **const _out_hostname = (out_hostname); \ gint64 *const _out_carrier_timeout_sec = (out_carrier_timeout_sec); \ - GHashTable * _connections; \ + GHashTable *_connections; \ \ - _connections = nmi_cmdline_reader_parse(TEST_INITRD_DIR "/sysfs", \ + _connections = nmi_cmdline_reader_parse(NULL, \ + TEST_INITRD_DIR "/sysfs", \ _ARGV, \ _out_hostname, \ _out_carrier_timeout_sec); \ @@ -41,7 +42,7 @@ #define _parse_cons(ARGV) \ ({ \ - GHashTable * _con_connections; \ + GHashTable *_con_connections; \ gs_free char *_con_hostname = NULL; \ gint64 _con_carrier_timeout_sec = 0; \ \ @@ -57,7 +58,7 @@ #define _parse_con(ARGV, connection_name) \ ({ \ gs_unref_hashtable GHashTable *_1_connections = NULL; \ - NMConnection * _1_connection; \ + NMConnection *_1_connection; \ const char *const _1_connection_name = (connection_name); \ \ g_assert(_1_connection_name); \ @@ -89,12 +90,12 @@ static void test_auto(void) { - const char *const *ARGV = NM_MAKE_STRV("ip=auto"); + const char *const *ARGV = NM_MAKE_STRV("ip=auto"); gs_unref_object NMConnection *connection = NULL; - NMSettingConnection * s_con; - NMSettingWired * s_wired; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; + NMSettingConnection *s_con; + NMSettingWired *s_wired; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; connection = _parse_con(ARGV, "default_connection"); @@ -140,13 +141,13 @@ static void test_dhcp_with_hostname(void) { gs_unref_hashtable GHashTable *connections = NULL; - const char *const * ARGV = NM_MAKE_STRV("ip=::::host1::dhcp,dhcp6"); - NMConnection * connection; - NMSettingConnection * s_con; - NMSettingWired * s_wired; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; - gs_free char * hostname = NULL; + const char *const *ARGV = NM_MAKE_STRV("ip=::::host1::dhcp,dhcp6"); + NMConnection *connection; + NMSettingConnection *s_con; + NMSettingWired *s_wired; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; + gs_free char *hostname = NULL; gint64 carrier_timeout_sec = 0; connections = _parse(ARGV, &hostname, &carrier_timeout_sec); @@ -198,10 +199,10 @@ test_dhcp_with_mtu(void) for (i = 0; i < G_N_ELEMENTS(ARGV); i++) { gs_unref_object NMConnection *connection = NULL; - NMSettingConnection * s_con; - NMSettingWired * s_wired; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; + NMSettingConnection *s_con; + NMSettingWired *s_wired; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; connection = _parse_con(ARGV[i], "default_connection"); @@ -259,9 +260,9 @@ test_dhcp_timeout(void) for (i = 0; i < G_N_ELEMENTS(data); i++) { gs_unref_object NMConnection *connection = NULL; - NMSettingConnection * s_con; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; + NMSettingConnection *s_con; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; connection = _parse_con(data[i].cmdline, "default_connection"); @@ -300,12 +301,12 @@ test_dhcp_timeout(void) static void test_if_auto_with_mtu(void) { - const char *const *ARGV = NM_MAKE_STRV("ip=eth0:dhcp,dhcp6:1666", "="); + const char *const *ARGV = NM_MAKE_STRV("ip=eth0:dhcp,dhcp6:1666", "="); gs_unref_object NMConnection *connection = NULL; - NMSettingConnection * s_con; - NMSettingWired * s_wired; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; + NMSettingConnection *s_con; + NMSettingWired *s_wired; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; connection = _parse_con(ARGV, "eth0"); @@ -340,10 +341,10 @@ test_if_auto_with_mtu(void) static void test_if_dhcp6(void) { - const char *const *ARGV = NM_MAKE_STRV("ip=eth1:dhcp6"); + const char *const *ARGV = NM_MAKE_STRV("ip=eth1:dhcp6"); gs_unref_object NMConnection *connection = NULL; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; connection = _parse_con(ARGV, "eth1"); @@ -365,11 +366,11 @@ test_if_dhcp6(void) static void test_if_auto_with_mtu_and_mac(void) { - const char *const *ARGV = NM_MAKE_STRV("ip=eth2:auto6:2048:00:53:ef:12:34:56"); + const char *const *ARGV = NM_MAKE_STRV("ip=eth2:auto6:2048:00:53:ef:12:34:56"); gs_unref_object NMConnection *connection = NULL; - NMSettingWired * s_wired; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; + NMSettingWired *s_wired; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; connection = _parse_con(ARGV, "eth2"); @@ -397,16 +398,16 @@ static void test_if_ip4_manual(void) { gs_unref_hashtable GHashTable *connections = NULL; - const char *const * ARGV = NM_MAKE_STRV("ip=192.0.2.2::192.0.2.1:255.255.255.0:" - "hostname0.example.com:eth3:none:192.0.2.53", + const char *const *ARGV = NM_MAKE_STRV("ip=192.0.2.2::192.0.2.1:255.255.255.0:" + "hostname0.example.com:eth3:none:192.0.2.53", "ip=203.0.113.2::203.0.113.1:26:" - "hostname1.example.com:eth4"); - NMConnection * connection; - NMSettingConnection * s_con; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; - NMIPAddress * ip_addr; - gs_free char * hostname = NULL; + "hostname1.example.com:eth4"); + NMConnection *connection; + NMSettingConnection *s_con; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; + NMIPAddress *ip_addr; + gs_free char *hostname = NULL; gint64 carrier_timeout_sec = 0; connections = _parse(ARGV, &hostname, &carrier_timeout_sec); @@ -477,12 +478,12 @@ test_if_ip4_manual(void) static void test_if_ip4_manual_no_dev(void) { - const char *const * ARGV = NM_MAKE_STRV("ip=192.0.2.2::192.0.2.1:24:::", "=foo"); - NMConnection * connection; + const char *const *ARGV = NM_MAKE_STRV("ip=192.0.2.2::192.0.2.1:24:::", "=foo"); + NMConnection *connection; NMSettingConnection *s_con; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; - NMIPAddress * ip_addr; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; + NMIPAddress *ip_addr; connection = _parse_con(ARGV, "default_connection"); g_assert_cmpstr(nm_connection_get_id(connection), ==, "Wired Connection"); @@ -518,12 +519,12 @@ static void test_if_ip6_manual(void) { gs_unref_hashtable GHashTable *connections = NULL; - const char *const * ARGV = NM_MAKE_STRV("ip=[2001:0db8::02]/64::[2001:0db8::01]::" - "hostname0.example.com:eth4::[2001:0db8::53]"); - NMConnection * connection; - NMSettingIPConfig * s_ip6; - NMIPAddress * ip_addr; - gs_free char * hostname = NULL; + const char *const *ARGV = NM_MAKE_STRV("ip=[2001:0db8::02]/64::[2001:0db8::01]::" + "hostname0.example.com:eth4::[2001:0db8::53]"); + NMConnection *connection; + NMSettingIPConfig *s_ip6; + NMIPAddress *ip_addr; + gs_free char *hostname = NULL; gint64 carrier_timeout_sec = 0; connections = _parse(ARGV, &hostname, &carrier_timeout_sec); @@ -557,13 +558,13 @@ static void test_if_off(void) { gs_unref_hashtable GHashTable *connections = NULL; - const char *const * ARGV = NM_MAKE_STRV("ip=off", + const char *const *ARGV = NM_MAKE_STRV("ip=off", "ip=ens3:off", "ip=10.0.0.8:::::ens4:off", "ip=[2001:DB8::8]:::::ens5:off"); - NMConnection * connection; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; + NMConnection *connection; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; struct { const char name[32]; const char ipv4_method[32]; @@ -599,13 +600,13 @@ static void test_if_mac_ifname(void) { gs_unref_hashtable GHashTable *connections = NULL; - const char *const * ARGV = NM_MAKE_STRV("ip=[2001:0db8::42]/64::[2001:0db8::01]::" - "hostname0:00-11-22-33-44-55::[2001:0db8::53]"); - NMConnection * connection; - NMSettingIPConfig * s_ip6; - NMSettingWired * s_wired; - NMIPAddress * ip_addr; - gs_free char * hostname = NULL; + const char *const *ARGV = NM_MAKE_STRV("ip=[2001:0db8::42]/64::[2001:0db8::01]::" + "hostname0:00-11-22-33-44-55::[2001:0db8::53]"); + NMConnection *connection; + NMSettingIPConfig *s_ip6; + NMSettingWired *s_wired; + NMIPAddress *ip_addr; + gs_free char *hostname = NULL; gint64 carrier_timeout_sec = 0; connections = _parse(ARGV, &hostname, &carrier_timeout_sec); @@ -646,11 +647,11 @@ test_multiple_merge(void) const char *const *ARGV = NM_MAKE_STRV("ip=192.0.2.2/16:::::eth0", "ip=[2001:db8::2]:::56::eth0"); gs_unref_object NMConnection *connection = NULL; - NMSettingConnection * s_con; - NMSettingWired * s_wired; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; - NMIPAddress * ip_addr; + NMSettingConnection *s_con; + NMSettingWired *s_wired; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; + NMIPAddress *ip_addr; connection = _parse_con(ARGV, "eth0"); @@ -699,10 +700,10 @@ test_multiple_bootdev(void) "ip=eth5:link6", "bootdev=eth4"); - NMConnection * connection; + NMConnection *connection; NMSettingConnection *s_con; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; connections = _parse_cons(ARGV); g_assert_cmpint(g_hash_table_size(connections), ==, 3); @@ -745,9 +746,9 @@ static void test_bootdev(void) { gs_unref_hashtable GHashTable *connections = NULL; - const char *const * ARGV = NM_MAKE_STRV("vlan=vlan2:ens5", "bootdev=ens3"); - NMConnection * connection; - NMSettingConnection * s_con; + const char *const *ARGV = NM_MAKE_STRV("vlan=vlan2:ens5", "bootdev=ens3"); + NMConnection *connection; + NMSettingConnection *s_con; connections = _parse_cons(ARGV); g_assert_cmpint(g_hash_table_size(connections), ==, 3); @@ -793,7 +794,7 @@ static void test_some_more(void) { gs_unref_hashtable GHashTable *connections = NULL; - const char *const * ARGV = NM_MAKE_STRV("bootdev=eth1", + const char *const *ARGV = NM_MAKE_STRV("bootdev=eth1", "hail", "nameserver=[2001:DB8:3::53]", "satan", @@ -802,12 +803,12 @@ test_some_more(void) "doom", "rd.peerdns=0", "rd.route=[2001:DB8:3::/48]:[2001:DB8:2::1]:ens10"); - NMConnection * connection; - NMSettingConnection * s_con; - NMSettingWired * s_wired; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; - NMIPRoute * ip_route; + NMConnection *connection; + NMSettingConnection *s_con; + NMSettingWired *s_wired; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; + NMIPRoute *ip_route; connections = _parse_cons(ARGV); g_assert_cmpint(g_hash_table_size(connections), ==, 2); @@ -883,17 +884,17 @@ static void test_bond(void) { gs_unref_hashtable GHashTable *connections = NULL; - const char *const * ARGV = NM_MAKE_STRV("rd.route=192.0.2.53::bong0", + const char *const *ARGV = NM_MAKE_STRV("rd.route=192.0.2.53::bong0", "bond=bong0:eth0,eth1:mode=balance-rr:9000", "nameserver=203.0.113.53"); - NMConnection * connection; - NMSettingConnection * s_con; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; - NMSettingBond * s_bond; - NMSettingWired * s_wired; - NMIPRoute * ip_route; - const char * master_uuid; + NMConnection *connection; + NMSettingConnection *s_con; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; + NMSettingBond *s_bond; + NMSettingWired *s_wired; + NMIPRoute *ip_route; + const char *master_uuid; connections = _parse_cons(ARGV); g_assert_cmpint(g_hash_table_size(connections), ==, 3); @@ -976,18 +977,18 @@ static void test_bond_ip(void) { gs_unref_hashtable GHashTable *connections = NULL; - const char *const * ARGV = + const char *const *ARGV = NM_MAKE_STRV("bond=bond0:eth0,eth1", "ip=192.168.1.1::192.168.1.254:24::bond0:none:1480:01:02:03:04:05:06", "nameserver=4.8.15.16"); - NMConnection * connection; + NMConnection *connection; NMSettingConnection *s_con; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; - NMSettingWired * s_wired; - NMSettingBond * s_bond; - NMIPAddress * ip_addr; - const char * master_uuid; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; + NMSettingWired *s_wired; + NMSettingBond *s_bond; + NMIPAddress *ip_addr; + const char *master_uuid; connections = _parse_cons(ARGV); g_assert_cmpint(g_hash_table_size(connections), ==, 3); @@ -1073,13 +1074,13 @@ static void test_bond_default(void) { gs_unref_hashtable GHashTable *connections = NULL; - const char *const * ARGV = NM_MAKE_STRV("bond"); - NMConnection * connection; - NMSettingConnection * s_con; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; - NMSettingBond * s_bond; - const char * master_uuid; + const char *const *ARGV = NM_MAKE_STRV("bond"); + NMConnection *connection; + NMSettingConnection *s_con; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; + NMSettingBond *s_bond; + const char *master_uuid; connections = _parse_cons(ARGV); g_assert_cmpint(g_hash_table_size(connections), ==, 2); @@ -1136,16 +1137,16 @@ static void test_bridge(void) { gs_unref_hashtable GHashTable *connections = NULL; - const char *const * ARGV = NM_MAKE_STRV("bridge=bridge0:eth0,eth1", + const char *const *ARGV = NM_MAKE_STRV("bridge=bridge0:eth0,eth1", "rd.route=192.0.2.53::bridge0", "rd.net.timeout.dhcp=10"); - NMConnection * connection; - NMSettingConnection * s_con; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; - NMSettingBridge * s_bridge; - NMIPRoute * ip_route; - const char * master_uuid; + NMConnection *connection; + NMSettingConnection *s_con; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; + NMSettingBridge *s_bridge; + NMIPRoute *ip_route; + const char *master_uuid; connections = _parse_cons(ARGV); g_assert_cmpint(g_hash_table_size(connections), ==, 3); @@ -1232,13 +1233,13 @@ static void test_bridge_default(void) { gs_unref_hashtable GHashTable *connections = NULL; - const char *const * ARGV = NM_MAKE_STRV("bridge"); - NMConnection * connection; - NMSettingConnection * s_con; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; - NMSettingBridge * s_bridge; - const char * master_uuid; + const char *const *ARGV = NM_MAKE_STRV("bridge"); + NMConnection *connection; + NMSettingConnection *s_con; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; + NMSettingBridge *s_bridge; + const char *master_uuid; connections = _parse_cons(ARGV); g_assert_cmpint(g_hash_table_size(connections), ==, 2); @@ -1295,16 +1296,16 @@ static void test_bridge_ip(void) { gs_unref_hashtable GHashTable *connections = NULL; - const char *const * ARGV = + const char *const *ARGV = NM_MAKE_STRV("ip=bridge123:auto:1280:00:11:22:33:CA:fe", "bridge=bridge123:eth0,eth1,eth2,eth3,eth4,eth5,eth6,eth7,eth8,eth9"); - NMConnection * connection; + NMConnection *connection; NMSettingConnection *s_con; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; - NMSettingWired * s_wired; - NMSettingBridge * s_bridge; - const char * master_uuid; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; + NMSettingWired *s_wired; + NMSettingBridge *s_bridge; + const char *master_uuid; guint i; connections = _parse_cons(ARGV); @@ -1364,13 +1365,13 @@ static void test_team(void) { gs_unref_hashtable GHashTable *connections = NULL; - const char *const * ARGV = NM_MAKE_STRV("team=team0:eth0,eth1", "ip=team0:dhcp6"); - NMConnection * connection; - NMSettingConnection * s_con; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; - NMSettingTeam * s_team; - const char * master_uuid; + const char *const *ARGV = NM_MAKE_STRV("team=team0:eth0,eth1", "ip=team0:dhcp6"); + NMConnection *connection; + NMSettingConnection *s_con; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; + NMSettingTeam *s_team; + const char *master_uuid; connections = _parse_cons(ARGV); g_assert_cmpint(g_hash_table_size(connections), ==, 3); @@ -1448,10 +1449,10 @@ test_vlan(void) for (i = 0; i < G_N_ELEMENTS(ARGV); i++) { gs_unref_hashtable GHashTable *connections = NULL; - NMConnection * connection; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; - NMSettingVlan * s_vlan; + NMConnection *connection; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; + NMSettingVlan *s_vlan; connections = _parse_cons(ARGV[i]); g_assert_cmpint(g_hash_table_size(connections), ==, 2); @@ -1513,10 +1514,10 @@ test_vlan_with_dhcp_on_parent(void) for (i = 0; i < G_N_ELEMENTS(ARGV); i++) { gs_unref_hashtable GHashTable *connections = NULL; - NMConnection * connection; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; - NMSettingVlan * s_vlan; + NMConnection *connection; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; + NMSettingVlan *s_vlan; connections = _parse_cons(ARGV[i]); g_assert_cmpint(g_hash_table_size(connections), ==, 2); @@ -1585,10 +1586,10 @@ test_vlan_over_bond(void) for (i = 0; i < G_N_ELEMENTS(ARGV); i++) { gs_unref_hashtable GHashTable *connections = NULL; - NMConnection * connection; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; - NMSettingVlan * s_vlan; + NMConnection *connection; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; + NMSettingVlan *s_vlan; connections = _parse_cons(ARGV[i]); g_assert_cmpint(g_hash_table_size(connections), ==, 4); @@ -1649,8 +1650,8 @@ test_vlan_over_bond(void) static void test_ibft_ip_dev(void) { - const char *const * ARGV = NM_MAKE_STRV("ip=eth0:ibft"); - NMSettingConnection *s_con; + const char *const *ARGV = NM_MAKE_STRV("ip=eth0:ibft"); + NMSettingConnection *s_con; gs_unref_object NMConnection *connection = NULL; connection = _parse_con(ARGV, "eth0"); @@ -1666,8 +1667,8 @@ test_ibft_ip_dev(void) static void test_ibft_ip_dev_mac(void) { - const char *const * ARGV = NM_MAKE_STRV("ip=00-53-06-66-ab-01:ibft"); - NMSettingConnection *s_con; + const char *const *ARGV = NM_MAKE_STRV("ip=00-53-06-66-ab-01:ibft"); + NMSettingConnection *s_con; gs_unref_object NMConnection *connection = NULL; connection = _parse_con(ARGV, "00:53:06:66:AB:01"); @@ -1684,7 +1685,7 @@ static void _test_ibft_ip(const char *const *ARGV) { gs_unref_hashtable GHashTable *connections = NULL; - NMConnection * connection; + NMConnection *connection; connections = _parse_cons(ARGV); g_assert_cmpint(g_hash_table_size(connections), ==, 2); @@ -1721,7 +1722,7 @@ static void test_ignore_extra(void) { gs_unref_hashtable GHashTable *connections = NULL; - const char *const * ARGV = NM_MAKE_STRV("blabla", "extra", "lalala"); + const char *const *ARGV = NM_MAKE_STRV("blabla", "extra", "lalala"); connections = _parse_cons(ARGV); g_assert_cmpint(g_hash_table_size(connections), ==, 0); @@ -1736,10 +1737,10 @@ test_rd_znet(void) "ip=slc600:dhcp", "rd.znet=qeth,0.0.0800,0.0.0801,0.0.0802,layer2=0,portno=1", "rd.znet=ctc,0.0.0600,0.0.0601,layer2=0,portno=0"); - NMConnection * connection; - NMSettingConnection * s_con; - NMSettingWired * s_wired; - const char *const * v_subchannels; + NMConnection *connection; + NMSettingConnection *s_con; + NMSettingWired *s_wired; + const char *const *v_subchannels; const NMUtilsNamedValue s390_options[] = { {.name = "layer2", .value_str = "0"}, {.name = "portno", .value_str = "1"}, @@ -1778,9 +1779,9 @@ test_rd_znet(void) for (i_s390_options_keys = 0; i_s390_options_keys < G_N_ELEMENTS(s390_options); i_s390_options_keys++) { const NMUtilsNamedValue *s390_option = &s390_options[i_s390_options_keys]; - const char * k; - const char * v; - const char * v2; + const char *k; + const char *v; + const char *v2; g_assert(s390_option->name); g_assert(s390_option->value_str); @@ -1830,9 +1831,9 @@ test_rd_znet_legacy(void) "rd.znet=ctc,0.0.0600,0.0.0601,layer2=0,portno=0", "ip=ctc0:dhcp", "net.ifnames=0"); - NMConnection * connection; + NMConnection *connection; NMSettingConnection *s_con; - gs_free char * hostname = NULL; + gs_free char *hostname = NULL; gint64 carrier_timeout_sec = 0; connections = _parse(ARGV, &hostname, &carrier_timeout_sec); @@ -1897,13 +1898,82 @@ test_rd_znet_malformed(void) } static void +test_rd_znet_ifnames(void) +{ + gs_unref_hashtable GHashTable *connections = NULL; + const char *const *const ARGV = + NM_MAKE_STRV("rd.znet_ifname=zeth1:0.0.0600,0.0.0601", + "rd.znet=qeth,0.0.0800,0.0.0801,0.0.0802,layer2=0,portno=1,foo", + "rd.znet=ctc,0.0.0600,0.0.0601", + "rd.znet_ifname=zeth0:0.0.0800,0.0.0801,0.0.0802", + "ip=zeth0:dhcp", + "ip=zeth1:dhcp"); + NMConnection *connection; + NMSettingConnection *s_con; + NMSettingWired *s_wired; + gs_free char *hostname = NULL; + gint64 carrier_timeout_sec = 0; + const char *const *v_subchannels; + + connections = _parse(ARGV, &hostname, &carrier_timeout_sec); + g_assert_cmpint(g_hash_table_size(connections), ==, 2); + + connection = g_hash_table_lookup(connections, "zeth0"); + g_assert(NM_IS_CONNECTION(connection)); + + s_con = nm_connection_get_setting_connection(connection); + g_assert(NM_IS_SETTING_CONNECTION(s_con)); + g_assert_cmpstr(nm_setting_connection_get_connection_type(s_con), + ==, + NM_SETTING_WIRED_SETTING_NAME); + g_assert_cmpstr(nm_setting_connection_get_id(s_con), ==, "zeth0"); + g_assert_cmpstr(nm_setting_connection_get_interface_name(s_con), ==, "zeth0"); + + s_wired = nm_connection_get_setting_wired(connection); + g_assert_cmpstr(nm_setting_wired_get_s390_nettype(s_wired), ==, "qeth"); + g_assert(s_wired); + + v_subchannels = nm_setting_wired_get_s390_subchannels(s_wired); + g_assert(v_subchannels); + g_assert_cmpstr(v_subchannels[0], ==, "0.0.0800"); + g_assert_cmpstr(v_subchannels[1], ==, "0.0.0801"); + g_assert_cmpstr(v_subchannels[2], ==, "0.0.0802"); + g_assert_cmpstr(v_subchannels[3], ==, NULL); + + nmtst_assert_connection_verifies_without_normalization(connection); + + connection = g_hash_table_lookup(connections, "zeth1"); + g_assert(NM_IS_CONNECTION(connection)); + + s_con = nm_connection_get_setting_connection(connection); + g_assert(NM_IS_SETTING_CONNECTION(s_con)); + g_assert_cmpstr(nm_setting_connection_get_connection_type(s_con), + ==, + NM_SETTING_WIRED_SETTING_NAME); + g_assert_cmpstr(nm_setting_connection_get_id(s_con), ==, "zeth1"); + g_assert_cmpstr(nm_setting_connection_get_interface_name(s_con), ==, "zeth1"); + + s_wired = nm_connection_get_setting_wired(connection); + g_assert_cmpstr(nm_setting_wired_get_s390_nettype(s_wired), ==, "ctc"); + g_assert(s_wired); + + v_subchannels = nm_setting_wired_get_s390_subchannels(s_wired); + g_assert(v_subchannels); + g_assert_cmpstr(v_subchannels[0], ==, "0.0.0600"); + g_assert_cmpstr(v_subchannels[1], ==, "0.0.0601"); + g_assert_cmpstr(v_subchannels[2], ==, NULL); + + nmtst_assert_connection_verifies_without_normalization(connection); +} + +static void test_bootif_ip(void) { - const char *const *ARGV = NM_MAKE_STRV("BOOTIF=00:53:AB:cd:02:03", "ip=dhcp"); + const char *const *ARGV = NM_MAKE_STRV("BOOTIF=00:53:AB:cd:02:03", "ip=dhcp"); gs_unref_object NMConnection *connection = NULL; - NMSettingWired * s_wired; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; + NMSettingWired *s_wired; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; connection = _parse_con(ARGV, "default_connection"); @@ -1928,11 +1998,11 @@ test_bootif_ip(void) static void test_neednet_no_args(void) { - const char *const *ARGV = NM_MAKE_STRV("rd.neednet"); + const char *const *ARGV = NM_MAKE_STRV("rd.neednet"); gs_unref_object NMConnection *connection = NULL; - NMSettingWired * s_wired; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; + NMSettingWired *s_wired; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; connection = _parse_con(ARGV, "default_connection"); @@ -1960,12 +2030,12 @@ static void test_neednet_args(void) { gs_unref_hashtable GHashTable *connections = NULL; - const char *const * ARGV = NM_MAKE_STRV("rd.neednet", + const char *const *ARGV = NM_MAKE_STRV("rd.neednet", "ip=eno1:dhcp", "ip=172.25.1.100::172.25.1.1:24::eno2", "bridge=br0:eno3"); - NMConnection * connection; - NMSettingConnection * s_con; + NMConnection *connection; + NMSettingConnection *s_con; connections = _parse_cons(ARGV); g_assert_cmpint(g_hash_table_size(connections), ==, 4); @@ -2008,11 +2078,11 @@ test_neednet_args(void) static void test_bootif_no_ip(void) { - const char *const *ARGV = NM_MAKE_STRV("BOOTIF=00:53:AB:cd:02:03"); + const char *const *ARGV = NM_MAKE_STRV("BOOTIF=00:53:AB:cd:02:03"); gs_unref_object NMConnection *connection = NULL; - NMSettingWired * s_wired; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; + NMSettingWired *s_wired; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; connection = _parse_con(ARGV, "default_connection"); @@ -2043,10 +2113,10 @@ test_bootif_hwtype(void) for (i = 0; i < G_N_ELEMENTS(ARGV); i++) { gs_unref_hashtable GHashTable *connections = NULL; - NMConnection * connection; - NMSettingWired * s_wired; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; + NMConnection *connection; + NMSettingWired *s_wired; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; connections = _parse_cons(ARGV[i]); g_assert_cmpint(g_hash_table_size(connections), ==, 2); @@ -2108,16 +2178,16 @@ static void test_nameserver(void) { gs_unref_hashtable GHashTable *connections = NULL; - const char *const * ARGV = + const char *const *ARGV = NM_MAKE_STRV("nameserver=1.1.1.1", "ip=eth0:dhcp", "ip=eth1:auto6", "ip=10.11.12.13::10.11.12.1:24:foo.example.com:eth2:none", "nameserver=1.0.0.1", "nameserver=[2606:4700:4700::1111]"); - NMConnection * connection; + NMConnection *connection; NMSettingIPConfig *s_ip; - gs_free char * hostname = NULL; + gs_free char *hostname = NULL; gint64 carrier_timeout_sec = 0; connections = _parse(ARGV, &hostname, &carrier_timeout_sec); @@ -2165,10 +2235,10 @@ test_bootif_off(void) static void test_dhcp_vendor_class_id(void) { - const char *const *ARGV; + const char *const *ARGV; gs_unref_object NMConnection *connection = NULL; - NMSettingIP4Config * s_ip4; - gs_free char * vci_long = NULL; + NMSettingIP4Config *s_ip4; + gs_free char *vci_long = NULL; char vci_arg_long[512] = {0}; ARGV = NM_MAKE_STRV("rd.net.dhcp.vendor-class=testvci", "ip=eno1:dhcp"); @@ -2196,9 +2266,9 @@ test_dhcp_vendor_class_id(void) static void test_infiniband_iface(void) { - const char *const *ARGV = NM_MAKE_STRV("ip=ib1:dhcp"); + const char *const *ARGV = NM_MAKE_STRV("ip=ib1:dhcp"); gs_unref_object NMConnection *connection = NULL; - NMSettingInfiniband * s_ib; + NMSettingInfiniband *s_ib; connection = _parse_con(ARGV, "ib1"); @@ -2215,7 +2285,7 @@ test_infiniband_mac(void) const char *const *ARGV = NM_MAKE_STRV("ip=00-11-22-33-44-55-66-77-88-99-aa-bb-cc-dd-ee-ff-00-11-22-33:dhcp"); gs_unref_object NMConnection *connection = NULL; - NMSettingInfiniband * s_ib; + NMSettingInfiniband *s_ib; connection = _parse_con(ARGV, "00:11:22:33:44:55:66:77:88:99:AA:BB:CC:DD:EE:FF:00:11:22:33"); @@ -2233,12 +2303,12 @@ 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"); + 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; + NMConnection *connection; + NMSettingInfiniband *s_ib; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; connections = _parse_cons(ARGV); g_assert_cmpint(g_hash_table_size(connections), ==, 1); @@ -2268,8 +2338,8 @@ 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; + const char *const *ARGV = NM_MAKE_STRV("rd.net.timeout.carrier=20"); + gs_free char *hostname = NULL; gint64 carrier_timeout_sec = 0; connections = _parse(ARGV, &hostname, &carrier_timeout_sec); @@ -2295,7 +2365,7 @@ test_carrier_timeout(void) G_STMT_START \ { \ gs_unref_object NMConnection *_connection = NULL; \ - NMSettingWired * _s_wired; \ + NMSettingWired *_s_wired; \ typeof(speed) _speed = speed; \ \ _connection = _parse_con(strv, "eth0"); \ @@ -2482,6 +2552,7 @@ main(int argc, char **argv) g_test_add_func("/initrd/cmdline/rd_znet/legacy", test_rd_znet_legacy); g_test_add_func("/initrd/cmdline/rd_znet/no_ip", test_rd_znet_no_ip); g_test_add_func("/initrd/cmdline/rd_znet/empty", test_rd_znet_malformed); + g_test_add_func("/initrd/cmdline/rd_znet/ifnames", test_rd_znet_ifnames); g_test_add_func("/initrd/cmdline/bootif/ip", test_bootif_ip); g_test_add_func("/initrd/cmdline/bootif/no_ip", test_bootif_no_ip); g_test_add_func("/initrd/cmdline/bootif/hwtype", test_bootif_hwtype); diff --git a/src/nm-initrd-generator/tests/test-dt-reader.c b/src/nm-initrd-generator/tests/test-dt-reader.c index c1c28e06..e194646d 100644 --- a/src/nm-initrd-generator/tests/test-dt-reader.c +++ b/src/nm-initrd-generator/tests/test-dt-reader.c @@ -25,12 +25,12 @@ static void test_read_dt_ofw(void) { - NMConnection * connection; + NMConnection *connection; NMSettingConnection *s_con; - NMSettingWired * s_wired; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; - const char * mac_address; + NMSettingWired *s_wired; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; + const char *mac_address; connection = nmi_dt_reader_parse(TEST_INITRD_DIR "/sysfs-dt"); g_assert(connection); @@ -69,12 +69,12 @@ test_read_dt_ofw(void) static void test_read_dt_slof(void) { - NMConnection * connection; + NMConnection *connection; NMSettingConnection *s_con; - NMSettingWired * s_wired; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; - NMIPAddress * ip4_addr; + NMSettingWired *s_wired; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; + NMIPAddress *ip4_addr; connection = nmi_dt_reader_parse(TEST_INITRD_DIR "/sysfs-dt-tftp"); g_assert(connection); diff --git a/src/nm-initrd-generator/tests/test-ibft-reader.c b/src/nm-initrd-generator/tests/test-ibft-reader.c index 0d437519..55925a9a 100644 --- a/src/nm-initrd-generator/tests/test-ibft-reader.c +++ b/src/nm-initrd-generator/tests/test-ibft-reader.c @@ -25,10 +25,10 @@ static NMConnection * read_connection(const char *sysfs_dir, const char *expected_mac, GError **error) { - NMConnection * connection = NULL; - gs_unref_hashtable GHashTable *ibft = NULL; - gs_free char * mac = NULL; - GHashTable * nic = NULL; + NMConnection *connection = NULL; + gs_unref_hashtable GHashTable *ibft = NULL; + gs_free char *mac = NULL; + GHashTable *nic = NULL; ibft = nmi_ibft_read(sysfs_dir); @@ -48,14 +48,14 @@ read_connection(const char *sysfs_dir, const char *expected_mac, GError **error) static void test_read_ibft_dhcp(void) { - NMConnection * connection; + NMConnection *connection; NMSettingConnection *s_con; - NMSettingWired * s_wired; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; - GError * error = NULL; - const char * mac_address; - const char * expected_mac_address = "00:33:21:98:b9:f1"; + NMSettingWired *s_wired; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; + GError *error = NULL; + const char *mac_address; + const char *expected_mac_address = "00:33:21:98:b9:f1"; connection = read_connection(TEST_INITRD_DIR "/sysfs-dhcp", expected_mac_address, &error); g_assert_no_error(error); @@ -96,15 +96,15 @@ test_read_ibft_dhcp(void) static void test_read_ibft_static(void) { - NMConnection * connection; + NMConnection *connection; NMSettingConnection *s_con; - NMSettingWired * s_wired; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; - GError * error = NULL; - const char * mac_address; - const char * expected_mac_address = "00:33:21:98:b9:f0"; - NMIPAddress * ip4_addr; + NMSettingWired *s_wired; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; + GError *error = NULL; + const char *mac_address; + const char *expected_mac_address = "00:33:21:98:b9:f0"; + NMIPAddress *ip4_addr; connection = read_connection(TEST_INITRD_DIR "/sysfs-static", expected_mac_address, &error); g_assert_no_error(error); @@ -159,9 +159,9 @@ test_read_ibft_static(void) static void test_read_ibft_bad_address(gconstpointer user_data) { - const char * sysfs_dir = user_data; + const char *sysfs_dir = user_data; NMConnection *connection; - GError * error = NULL; + GError *error = NULL; g_assert(g_file_test(sysfs_dir, G_FILE_TEST_EXISTS)); @@ -174,15 +174,15 @@ test_read_ibft_bad_address(gconstpointer user_data) static void test_read_ibft_vlan(void) { - NMConnection * connection; + NMConnection *connection; NMSettingConnection *s_con; - NMSettingWired * s_wired; - NMSettingVlan * s_vlan; - NMSettingIPConfig * s_ip4; - const char * mac_address; - const char * expected_mac_address = "00:33:21:98:b9:f0"; - NMIPAddress * ip4_addr; - GError * error = NULL; + NMSettingWired *s_wired; + NMSettingVlan *s_vlan; + NMSettingIPConfig *s_ip4; + const char *mac_address; + const char *expected_mac_address = "00:33:21:98:b9:f0"; + NMIPAddress *ip4_addr; + GError *error = NULL; connection = read_connection(TEST_INITRD_DIR "/sysfs-vlan", expected_mac_address, &error); g_assert_no_error(error); @@ -231,10 +231,10 @@ test_read_ibft_vlan(void) static void test_read_ibft(void) { - NMConnection * connection; + NMConnection *connection; NMSettingIPConfig *s_ip4; NMSettingIPConfig *s_ip6; - GError * error = NULL; + GError *error = NULL; /* This test doesn't actually test too much (apart from the presence of * IPv6 that is not covered by other tests), but the test fixture is a good |