From bfe522304da217296e2a61040f58e35ec5d6f3f2 Mon Sep 17 00:00:00 2001 From: Michael Biebl Date: Mon, 16 Aug 2021 09:51:46 +0200 Subject: New upstream version 1.30.6 --- .../plugins/ifcfg-rh/nms-ifcfg-rh-reader.c | 3 +- .../settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.c | 1 + .../settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.h | 2 +- .../plugins/ifcfg-rh/nms-ifcfg-rh-writer.c | 40 +++++------ .../ifcfg-test-tc-write-empty.cexpected | 15 ++++ .../plugins/ifcfg-rh/tests/test-ifcfg-rh.c | 80 ++++++++++++++++++++++ .../settings/plugins/keyfile/nms-keyfile-utils.c | 6 +- 7 files changed, 123 insertions(+), 24 deletions(-) create mode 100644 src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-tc-write-empty.cexpected (limited to 'src/core/settings') diff --git a/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c b/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c index 209957d9..a42c4188 100644 --- a/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c +++ b/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c @@ -2707,7 +2707,8 @@ make_tc_setting(shvarFile *ifcfg) } if (nm_setting_tc_config_get_num_qdiscs(s_tc) > 0 - || nm_setting_tc_config_get_num_tfilters(s_tc) > 0) + || nm_setting_tc_config_get_num_tfilters(s_tc) > 0 + || svGetValueBoolean(ifcfg, "TC_COMMIT", FALSE)) return NM_SETTING(s_tc); g_object_unref(s_tc); diff --git a/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.c b/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.c index 8da5de47..ada1942a 100644 --- a/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.c +++ b/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.c @@ -1026,6 +1026,7 @@ const NMSIfcfgKeyTypeInfo nms_ifcfg_well_known_keys[] = { _KEY_TYPE("STABLE_ID", NMS_IFCFG_KEY_TYPE_IS_PLAIN), _KEY_TYPE("STP", NMS_IFCFG_KEY_TYPE_IS_PLAIN), _KEY_TYPE("SUBCHANNELS", NMS_IFCFG_KEY_TYPE_IS_PLAIN), + _KEY_TYPE("TC_COMMIT", NMS_IFCFG_KEY_TYPE_IS_PLAIN), _KEY_TYPE("TEAM_CONFIG", NMS_IFCFG_KEY_TYPE_IS_PLAIN), _KEY_TYPE("TEAM_MASTER", NMS_IFCFG_KEY_TYPE_IS_PLAIN), _KEY_TYPE("TEAM_MASTER_UUID", NMS_IFCFG_KEY_TYPE_IS_PLAIN), diff --git a/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.h b/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.h index 36ec9225..04a1b63d 100644 --- a/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.h +++ b/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.h @@ -33,7 +33,7 @@ typedef struct { NMSIfcfgKeyTypeFlags key_flags; } NMSIfcfgKeyTypeInfo; -extern const NMSIfcfgKeyTypeInfo nms_ifcfg_well_known_keys[247]; +extern const NMSIfcfgKeyTypeInfo nms_ifcfg_well_known_keys[248]; const NMSIfcfgKeyTypeInfo *nms_ifcfg_well_known_key_find_info(const char *key, gssize *out_idx); diff --git a/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c b/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c index a968fce0..45b76456 100644 --- a/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c +++ b/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c @@ -1137,7 +1137,7 @@ write_wired_setting(NMConnection *connection, shvarFile *ifcfg, GError **error) svSetValueStr(ifcfg, "CTCPROT", nm_setting_wired_get_s390_option_by_key(s_wired, "ctcprot")); num_opts = nm_setting_wired_get_num_s390_options(s_wired); - if (s390_subchannels && num_opts) { + if (num_opts > 0) { nm_auto_free_gstring GString *tmp = NULL; for (i = 0; i < num_opts; i++) { @@ -2511,46 +2511,46 @@ write_sriov_setting(NMConnection *connection, shvarFile *ifcfg) } } -static gboolean -write_tc_setting(NMConnection *connection, shvarFile *ifcfg, GError **error) +static void +write_tc_setting(NMConnection *connection, shvarFile *ifcfg) { NMSettingTCConfig *s_tc; - guint i, num, n; + guint num_qdiscs; + guint num_filters; + guint i; + guint n; char tag[64]; s_tc = nm_connection_get_setting_tc_config(connection); if (!s_tc) - return TRUE; + return; - num = nm_setting_tc_config_get_num_qdiscs(s_tc); - for (n = 1, i = 0; i < num; i++) { + num_qdiscs = nm_setting_tc_config_get_num_qdiscs(s_tc); + for (n = 1, i = 0; i < num_qdiscs; i++) { NMTCQdisc * qdisc; gs_free char *str = NULL; qdisc = nm_setting_tc_config_get_qdisc(s_tc, i); - str = nm_utils_tc_qdisc_to_str(qdisc, error); - if (!str) - return FALSE; - + str = nm_utils_tc_qdisc_to_str(qdisc, NULL); + nm_assert(str); svSetValueStr(ifcfg, numbered_tag(tag, "QDISC", n), str); n++; } - num = nm_setting_tc_config_get_num_tfilters(s_tc); - for (n = 1, i = 0; i < num; i++) { + num_filters = nm_setting_tc_config_get_num_tfilters(s_tc); + for (n = 1, i = 0; i < num_filters; i++) { NMTCTfilter * tfilter; gs_free char *str = NULL; tfilter = nm_setting_tc_config_get_tfilter(s_tc, i); - str = nm_utils_tc_tfilter_to_str(tfilter, error); - if (!str) - return FALSE; - + str = nm_utils_tc_tfilter_to_str(tfilter, NULL); + nm_assert(str); svSetValueStr(ifcfg, numbered_tag(tag, "FILTER", n), str); n++; } - return TRUE; + if (num_qdiscs == 0 && num_filters == 0) + svSetValueBoolean(ifcfg, "TC_COMMIT", TRUE); } static void @@ -3373,9 +3373,7 @@ do_write_construct(NMConnection * connection, write_match_setting(connection, ifcfg); write_hostname_setting(connection, ifcfg); write_sriov_setting(connection, ifcfg); - - if (!write_tc_setting(connection, ifcfg, error)) - return FALSE; + write_tc_setting(connection, ifcfg); route_path_is_svformat = utils_has_route_file_new_syntax(route_path); diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-tc-write-empty.cexpected b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-tc-write-empty.cexpected new file mode 100644 index 00000000..4df768b4 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-tc-write-empty.cexpected @@ -0,0 +1,15 @@ +TYPE=Ethernet +PROXY_METHOD=none +BROWSER_ONLY=no +TC_COMMIT=yes +BOOTPROTO=none +IPADDR=1.1.1.3 +PREFIX=24 +GATEWAY=1.1.1.1 +DEFROUTE=yes +IPV4_FAILURE_FATAL=no +IPV6INIT=no +NAME="Test Write TC config" +UUID=${UUID} +DEVICE=eth0 +ONBOOT=yes diff --git a/src/core/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c b/src/core/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c index 59127d01..9d9ed626 100644 --- a/src/core/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c +++ b/src/core/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c @@ -11108,6 +11108,85 @@ test_tc_read(void) g_object_unref(connection); } +static void +test_tc_write_empty(void) +{ + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; + NMSettingConnection * s_con; + NMSettingIPConfig * s_ip4; + NMSettingIPConfig * s_ip6; + NMSettingWired * s_wired; + NMSettingTCConfig * s_tc; + NMIPAddress * addr; + GError * error = NULL; + + connection = nm_simple_connection_new(); + + /* Connection setting */ + s_con = (NMSettingConnection *) nm_setting_connection_new(); + nm_connection_add_setting(connection, NM_SETTING(s_con)); + + g_object_set(s_con, + NM_SETTING_CONNECTION_ID, + "Test Write TC config", + NM_SETTING_CONNECTION_UUID, + nm_utils_uuid_generate_a(), + NM_SETTING_CONNECTION_AUTOCONNECT, + TRUE, + NM_SETTING_CONNECTION_INTERFACE_NAME, + "eth0", + NM_SETTING_CONNECTION_TYPE, + NM_SETTING_WIRED_SETTING_NAME, + NULL); + + /* Wired setting */ + s_wired = (NMSettingWired *) nm_setting_wired_new(); + nm_connection_add_setting(connection, NM_SETTING(s_wired)); + + /* IP4 setting */ + s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); + nm_connection_add_setting(connection, NM_SETTING(s_ip4)); + + g_object_set(s_ip4, + NM_SETTING_IP_CONFIG_METHOD, + NM_SETTING_IP4_CONFIG_METHOD_MANUAL, + NM_SETTING_IP_CONFIG_GATEWAY, + "1.1.1.1", + NM_SETTING_IP_CONFIG_MAY_FAIL, + TRUE, + NULL); + + addr = nm_ip_address_new(AF_INET, "1.1.1.3", 24, &error); + g_assert_no_error(error); + nm_setting_ip_config_add_address(s_ip4, addr); + nm_ip_address_unref(addr); + + /* IP6 setting */ + s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); + nm_connection_add_setting(connection, NM_SETTING(s_ip6)); + + g_object_set(s_ip6, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, NULL); + + /* TC setting */ + s_tc = (NMSettingTCConfig *) nm_setting_tc_config_new(); + nm_connection_add_setting(connection, NM_SETTING(s_tc)); + + nm_connection_add_setting(connection, nm_setting_proxy_new()); + + nmtst_assert_connection_verifies_without_normalization(connection); + + _writer_new_connec_exp(connection, + TEST_SCRATCH_DIR, + TEST_IFCFG_DIR "/ifcfg-test-tc-write-empty.cexpected", + &testfile); + + reread = _connection_from_file(testfile, NULL, TYPE_BOND, NULL); + + nmtst_assert_connection_equals(connection, FALSE, reread, FALSE); +} + static void test_tc_write(void) { @@ -11848,6 +11927,7 @@ main(int argc, char **argv) g_test_add_func(TPATH "tc/read", test_tc_read); g_test_add_func(TPATH "tc/write", test_tc_write); + g_test_add_func(TPATH "tc/write_empty", test_tc_write_empty); g_test_add_func(TPATH "utils/test_well_known_keys", test_well_known_keys); g_test_add_func(TPATH "utils/test_utils_has_route_file_new_syntax", test_utils_has_route_file_new_syntax); diff --git a/src/core/settings/plugins/keyfile/nms-keyfile-utils.c b/src/core/settings/plugins/keyfile/nms-keyfile-utils.c index f3dffdae..ca1233f5 100644 --- a/src/core/settings/plugins/keyfile/nms-keyfile-utils.c +++ b/src/core/settings/plugins/keyfile/nms-keyfile-utils.c @@ -137,7 +137,11 @@ nms_keyfile_nmmeta_read(const char * dirname, NMMETA_KF_GROUP_NAME_NMMETA, NMMETA_KF_KEY_NAME_NMMETA_UUID, NULL); - if (!nm_streq0(v_uuid, uuid)) + if (!v_uuid) + return FALSE; + if (strncmp(v_uuid, uuid, uuid_len) != 0) + return FALSE; + if (v_uuid[uuid_len] != '\0') return FALSE; loaded_path = g_key_file_get_string(kf, -- cgit 1.3.0-6-gf8a5 From e74c568b07b50b97873fb4ee1d776dedefbd54d6 Mon Sep 17 00:00:00 2001 From: Michael Biebl Date: Fri, 1 Oct 2021 23:05:04 +0200 Subject: New upstream version 1.32.12 --- src/core/settings/nm-agent-manager.c | 4 +- src/core/settings/nm-secret-agent.c | 10 +- src/core/settings/nm-settings-connection.c | 542 ++++++++++++--------- src/core/settings/nm-settings-connection.h | 12 +- src/core/settings/nm-settings-plugin.c | 2 +- src/core/settings/nm-settings-storage.c | 5 +- src/core/settings/nm-settings-storage.h | 15 +- src/core/settings/nm-settings.c | 250 +++++++--- src/core/settings/nm-settings.h | 5 + src/core/settings/plugins/ifcfg-rh/meson.build | 2 - src/core/settings/plugins/ifcfg-rh/nm-ifdown | 47 +- src/core/settings/plugins/ifcfg-rh/nm-ifup | 47 +- .../plugins/ifcfg-rh/nms-ifcfg-rh-plugin.c | 10 +- .../plugins/ifcfg-rh/nms-ifcfg-rh-reader.c | 93 ++-- .../plugins/ifcfg-rh/nms-ifcfg-rh-storage.c | 5 +- .../settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.c | 20 +- .../settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.h | 4 +- .../plugins/ifcfg-rh/nms-ifcfg-rh-writer.c | 184 ++++--- src/core/settings/plugins/ifcfg-rh/shvar.c | 261 +++++++--- src/core/settings/plugins/ifcfg-rh/shvar.h | 3 + .../ifcfg-System_test-bridge-component-a.cexpected | 2 +- .../ifcfg-System_test-bridge-component-b.cexpected | 2 +- ...System_test-wired-802-1X-subj-matches.cexpected | 2 +- .../ifcfg-Test_Write_Bridge_Component.cexpected | 2 +- .../ifcfg-Test_Write_Wired_Static_Routes.cexpected | 2 +- .../ifcfg-test-static-routes-legacy.cexpected | 2 +- .../network-scripts/ifcfg-test-vlan-vlanid-use | 4 + .../ifcfg-test-vlan-vlanid-use.cexpected | 15 + .../ifcfg-test-wifi-wpa-eap-suite-b-192-tls | 1 - .../ifcfg-test-wifi-wpa-eap-ttls-tls | 1 - .../ifcfg-test-write-unknown-4.expected | 6 +- .../ifcfg-test_roundtrip_ethtool-1.cexpected | 14 + .../ifcfg-test_roundtrip_ethtool-2.cexpected | 15 + .../ifcfg-test_roundtrip_ethtool-3.cexpected | 15 + .../ifcfg-test_roundtrip_ethtool-4.cexpected | 15 + .../ifcfg-test_roundtrip_ethtool-5.cexpected | 15 + .../plugins/ifcfg-rh/tests/test-ifcfg-rh.c | 325 +++++++++--- src/core/settings/plugins/ifupdown/meson.build | 2 - .../plugins/ifupdown/nms-ifupdown-parser.c | 26 +- .../plugins/ifupdown/nms-ifupdown-plugin.c | 2 +- .../plugins/ifupdown/tests/test-ifupdown.c | 2 +- .../settings/plugins/keyfile/nms-keyfile-plugin.c | 28 +- .../settings/plugins/keyfile/nms-keyfile-reader.c | 2 +- .../settings/plugins/keyfile/nms-keyfile-storage.c | 7 +- .../settings/plugins/keyfile/nms-keyfile-utils.c | 32 +- .../settings/plugins/keyfile/nms-keyfile-writer.c | 9 +- .../plugins/keyfile/tests/test-keyfile-settings.c | 5 +- 47 files changed, 1427 insertions(+), 647 deletions(-) mode change 100644 => 100755 src/core/settings/plugins/ifcfg-rh/nm-ifdown mode change 100644 => 100755 src/core/settings/plugins/ifcfg-rh/nm-ifup create mode 100644 src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-vlan-vlanid-use create mode 100644 src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-vlan-vlanid-use.cexpected create mode 100644 src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test_roundtrip_ethtool-1.cexpected create mode 100644 src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test_roundtrip_ethtool-2.cexpected create mode 100644 src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test_roundtrip_ethtool-3.cexpected create mode 100644 src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test_roundtrip_ethtool-4.cexpected create mode 100644 src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test_roundtrip_ethtool-5.cexpected (limited to 'src/core/settings') diff --git a/src/core/settings/nm-agent-manager.c b/src/core/settings/nm-agent-manager.c index 7e617909..a1c2eb9c 100644 --- a/src/core/settings/nm-agent-manager.c +++ b/src/core/settings/nm-agent-manager.c @@ -9,7 +9,7 @@ #include -#include "nm-libnm-core-intern/nm-common-macros.h" +#include "libnm-core-aux-intern/nm-common-macros.h" #include "nm-dbus-interface.h" #include "nm-secret-agent.h" #include "nm-auth-utils.h" @@ -19,7 +19,7 @@ #include "nm-session-monitor.h" #include "nm-simple-connection.h" #include "NetworkManagerUtils.h" -#include "nm-core-internal.h" +#include "libnm-core-intern/nm-core-internal.h" #include "c-list/src/c-list.h" /*****************************************************************************/ diff --git a/src/core/settings/nm-secret-agent.c b/src/core/settings/nm-secret-agent.c index 7e7c5d7d..45152c27 100644 --- a/src/core/settings/nm-secret-agent.c +++ b/src/core/settings/nm-secret-agent.c @@ -10,11 +10,11 @@ #include #include -#include "nm-glib-aux/nm-c-list.h" -#include "nm-glib-aux/nm-dbus-aux.h" +#include "libnm-glib-aux/nm-c-list.h" +#include "libnm-glib-aux/nm-dbus-aux.h" #include "nm-dbus-interface.h" -#include "nm-core-internal.h" -#include "nm-libnm-core-intern/nm-auth-subject.h" +#include "libnm-core-intern/nm-core-internal.h" +#include "libnm-core-aux-intern/nm-auth-subject.h" #include "nm-simple-connection.h" #include "NetworkManagerUtils.h" #include "c-list/src/c-list.h" @@ -583,7 +583,7 @@ nm_secret_agent_delete_secrets(NMSecretAgent * self, priv = NM_SECRET_AGENT_GET_PRIVATE(self); /* No secrets sent; agents must be smart enough to track secrets using the UUID or something */ - dict = nm_connection_to_dbus(connection, NM_CONNECTION_SERIALIZE_NO_SECRETS); + dict = nm_connection_to_dbus(connection, NM_CONNECTION_SERIALIZE_WITH_NON_SECRET); call_id = _call_id_new(self, METHOD_DELETE_SECRETS, path, NULL, callback, callback_data); diff --git a/src/core/settings/nm-settings-connection.c b/src/core/settings/nm-settings-connection.c index 0ff07189..b423bf5b 100644 --- a/src/core/settings/nm-settings-connection.c +++ b/src/core/settings/nm-settings-connection.c @@ -10,8 +10,9 @@ #include "c-list/src/c-list.h" -#include "nm-glib-aux/nm-keyfile-aux.h" -#include "nm-libnm-core-intern/nm-common-macros.h" +#include "libnm-glib-aux/nm-keyfile-aux.h" +#include "libnm-glib-aux/nm-c-list.h" +#include "libnm-core-aux-intern/nm-common-macros.h" #include "nm-config.h" #include "nm-config-data.h" #include "nm-dbus-interface.h" @@ -20,7 +21,7 @@ #include "nm-auth-utils.h" #include "nm-agent-manager.h" #include "NetworkManagerUtils.h" -#include "nm-core-internal.h" +#include "libnm-core-intern/nm-core-internal.h" #include "nm-audit-manager.h" #include "nm-settings.h" #include "nm-dbus-manager.h" @@ -30,10 +31,13 @@ #define AUTOCONNECT_RETRIES_FOREVER -1 #define AUTOCONNECT_RESET_RETRIES_TIMER 300 -#define _NM_SETTINGS_UPDATE2_FLAG_ALL_PERSIST_MODES \ - ((NMSettingsUpdate2Flags)( \ - NM_SETTINGS_UPDATE2_FLAG_TO_DISK | NM_SETTINGS_UPDATE2_FLAG_IN_MEMORY \ - | NM_SETTINGS_UPDATE2_FLAG_IN_MEMORY_DETACHED | NM_SETTINGS_UPDATE2_FLAG_IN_MEMORY_ONLY)) +#define SEEN_BSSIDS_MAX 30 + +#define _NM_SETTINGS_UPDATE2_FLAG_ALL_PERSIST_MODES \ + ((NMSettingsUpdate2Flags) (NM_SETTINGS_UPDATE2_FLAG_TO_DISK \ + | NM_SETTINGS_UPDATE2_FLAG_IN_MEMORY \ + | NM_SETTINGS_UPDATE2_FLAG_IN_MEMORY_DETACHED \ + | NM_SETTINGS_UPDATE2_FLAG_IN_MEMORY_ONLY)) /*****************************************************************************/ @@ -58,6 +62,56 @@ nm_settings_connections_array_to_connections(NMSettingsConnection *const *connec /*****************************************************************************/ +typedef struct { + char bssid[sizeof(NMEtherAddr) * 3]; + CList seen_bssids_lst; +} SeenBssidEntry; + +static inline SeenBssidEntry * +_seen_bssid_entry_init_stale(SeenBssidEntry *entry, const NMEtherAddr *bssid_bin) +{ + _nm_utils_hwaddr_ntoa(bssid_bin, sizeof(NMEtherAddr), TRUE, entry->bssid, sizeof(entry->bssid)); + return entry; +} + +static inline SeenBssidEntry * +_seen_bssid_entry_new_stale_bin(const NMEtherAddr *bssid_bin) +{ + return _seen_bssid_entry_init_stale(g_slice_new(SeenBssidEntry), bssid_bin); +} + +static inline SeenBssidEntry * +_seen_bssid_entry_new_stale_copy(const SeenBssidEntry *src) +{ + SeenBssidEntry *entry; + + entry = g_slice_new(SeenBssidEntry); + memcpy(entry->bssid, src->bssid, sizeof(entry->bssid)); + return entry; +} + +static void +_seen_bssid_entry_free(gpointer data) +{ + SeenBssidEntry *entry = data; + + c_list_unlink_stale(&entry->seen_bssids_lst); + nm_g_slice_free(entry); +} + +/*****************************************************************************/ + +static GHashTable * +_seen_bssids_hash_new(void) +{ + return g_hash_table_new_full(nm_str_hash, + g_str_equal, + (GDestroyNotify) _seen_bssid_entry_free, + NULL); +} + +/*****************************************************************************/ + NM_GOBJECT_PROPERTIES_DEFINE(NMSettingsConnection, PROP_UNSAVED, PROP_FLAGS, PROP_FILENAME, ); enum { UPDATED_INTERNAL, FLAGS_CHANGED, LAST_SIGNAL }; @@ -79,19 +133,17 @@ typedef struct _NMSettingsConnectionPrivate { NMConnection *connection; + struct { + NMConnectionSerializationOptions options; + GVariant * variant; + } getsettings_cached; + NMSettingsStorage *storage; char *filename; NMDevice *default_wired_device; - /* Caches secrets from on-disk connections; were they not cached any - * call to nm_connection_clear_secrets() wipes them out and we'd have - * to re-read them from disk which defeats the purpose of having the - * connection in-memory at all. - */ - GVariant *system_secrets; - /* Caches secrets from agents during the activation process; if new system * secrets are returned from an agent, they get written out to disk, * triggering a re-read of the connection, which reads only system @@ -100,7 +152,8 @@ typedef struct _NMSettingsConnectionPrivate { */ GVariant *agent_secrets; - GHashTable *seen_bssids; /* Up-to-date BSSIDs that's been seen for the connection */ + CList seen_bssids_lst_head; + GHashTable *seen_bssids_hash; guint64 timestamp; /* Up-to-date timestamp of connection use */ @@ -168,8 +221,9 @@ static const GDBusSignalInfo signal_info_updated; static const GDBusSignalInfo signal_info_removed; static const NMDBusInterfaceInfoExtended interface_info_settings_connection; -static void update_system_secrets_cache(NMSettingsConnection *self, NMConnection *new); -static void update_agent_secrets_cache(NMSettingsConnection *self, NMConnection *new); +static void update_agent_secrets_cache(NMSettingsConnection *self, NMConnection *new); +static guint _get_seen_bssids(NMSettingsConnection *self, + const char * strv_buf[static(SEEN_BSSIDS_MAX + 1)]); /*****************************************************************************/ @@ -248,10 +302,53 @@ nm_settings_connection_still_valid(NMSettingsConnection *self) /*****************************************************************************/ -static GHashTable * -_seen_bssids_hash_new(void) +static void +_getsettings_cached_clear(NMSettingsConnectionPrivate *priv) { - return g_hash_table_new_full(nm_str_hash, g_str_equal, g_free, NULL); + if (nm_clear_pointer(&priv->getsettings_cached.variant, g_variant_unref)) { + priv->getsettings_cached.options.timestamp.has = FALSE; + priv->getsettings_cached.options.timestamp.val = 0; + nm_clear_g_free((gpointer *) &priv->getsettings_cached.options.seen_bssids); + } +} + +static GVariant * +_getsettings_cached_get(NMSettingsConnection *self, const NMConnectionSerializationOptions *options) +{ + NMSettingsConnectionPrivate *priv = NM_SETTINGS_CONNECTION_GET_PRIVATE(self); + GVariant * variant; + + if (priv->getsettings_cached.variant) { + if (nm_connection_serialization_options_equal(&priv->getsettings_cached.options, options)) { +#if NM_MORE_ASSERTS > 10 + gs_unref_variant GVariant *variant2 = NULL; + + variant = nm_connection_to_dbus_full(priv->connection, + NM_CONNECTION_SERIALIZE_WITH_NON_SECRET, + options); + nm_assert(variant); + variant2 = g_variant_new("(@a{sa{sv}})", variant); + nm_assert(g_variant_equal(priv->getsettings_cached.variant, variant2)); +#endif + return priv->getsettings_cached.variant; + } + _getsettings_cached_clear(priv); + } + + nm_assert(!priv->getsettings_cached.options.seen_bssids); + + variant = nm_connection_to_dbus_full(priv->connection, + NM_CONNECTION_SERIALIZE_WITH_NON_SECRET, + options); + nm_assert(variant); + + priv->getsettings_cached.variant = g_variant_ref_sink(g_variant_new("(@a{sa{sv}})", variant)); + + priv->getsettings_cached.options = *options; + priv->getsettings_cached.options.seen_bssids = + nm_utils_strv_dup_packed(priv->getsettings_cached.options.seen_bssids, -1); + + return priv->getsettings_cached.variant; } /*****************************************************************************/ @@ -287,6 +384,9 @@ _nm_settings_connection_set_connection(NMSettingsConnection * self, priv->connection = g_object_ref(new_connection); nmtst_connection_assert_unchanging(priv->connection); + _getsettings_cached_clear(priv); + _nm_settings_notify_sorted_by_autoconnect_priority_maybe_changed(priv->settings); + /* note that we only return @connection_old if the new connection actually differs from * before. * @@ -298,11 +398,6 @@ _nm_settings_connection_set_connection(NMSettingsConnection * self, NM_SET_OUT(out_connection_old, g_steal_pointer(&connection_old)); } - if (NM_FLAGS_HAS(update_reason, NM_SETTINGS_CONNECTION_UPDATE_REASON_CLEAR_SYSTEM_SECRETS)) - update_system_secrets_cache(self, NULL); - else if (NM_FLAGS_HAS(update_reason, NM_SETTINGS_CONNECTION_UPDATE_REASON_RESET_SYSTEM_SECRETS)) - update_system_secrets_cache(self, priv->connection); - if (NM_FLAGS_HAS(update_reason, NM_SETTINGS_CONNECTION_UPDATE_REASON_CLEAR_AGENT_SECRETS)) update_agent_secrets_cache(self, NULL); else if (NM_FLAGS_HAS(update_reason, NM_SETTINGS_CONNECTION_UPDATE_REASON_RESET_AGENT_SECRETS)) @@ -433,64 +528,21 @@ nm_settings_connection_check_permission(NMSettingsConnection *self, const char * /*****************************************************************************/ -static void -update_system_secrets_cache(NMSettingsConnection *self, NMConnection *new) -{ - NMSettingsConnectionPrivate *priv = NM_SETTINGS_CONNECTION_GET_PRIVATE(self); - gs_unref_object NMConnection *connection_cloned = NULL; - gs_unref_variant GVariant *old_secrets = NULL; - - old_secrets = g_steal_pointer(&priv->system_secrets); - - if (!new) - goto out; - - /* FIXME: improve NMConnection API so we can avoid the overhead of cloning the connection, - * in particular if there are no secrets to begin with. */ - - connection_cloned = nm_simple_connection_new_clone(new); - - /* Clear out non-system-owned and not-saved secrets */ - _nm_connection_clear_secrets_by_secret_flags(connection_cloned, NM_SETTING_SECRET_FLAG_NONE); - - priv->system_secrets = nm_g_variant_ref_sink( - nm_connection_to_dbus(connection_cloned, NM_CONNECTION_SERIALIZE_ONLY_SECRETS)); - -out: - if (_LOGT_ENABLED()) { - if ((!!old_secrets) != (!!priv->system_secrets)) { - _LOGT("update system secrets: secrets %s", old_secrets ? "cleared" : "set"); - } else if (priv->system_secrets && !g_variant_equal(old_secrets, priv->system_secrets)) - _LOGT("update system secrets: secrets updated"); - } -} - static void update_agent_secrets_cache(NMSettingsConnection *self, NMConnection *new) { - NMSettingsConnectionPrivate *priv = NM_SETTINGS_CONNECTION_GET_PRIVATE(self); - gs_unref_object NMConnection *connection_cloned = NULL; - gs_unref_variant GVariant *old_secrets = NULL; + NMSettingsConnectionPrivate *priv = NM_SETTINGS_CONNECTION_GET_PRIVATE(self); + gs_unref_variant GVariant *old_secrets = NULL; old_secrets = g_steal_pointer(&priv->agent_secrets); - if (!new) - goto out; - - /* FIXME: improve NMConnection API so we can avoid the overhead of cloning the connection, - * in particular if there are no secrets to begin with. */ - - connection_cloned = nm_simple_connection_new_clone(new); - - /* Clear out non-system-owned secrets */ - _nm_connection_clear_secrets_by_secret_flags(connection_cloned, - NM_SETTING_SECRET_FLAG_NOT_SAVED - | NM_SETTING_SECRET_FLAG_AGENT_OWNED); - - priv->agent_secrets = nm_g_variant_ref_sink( - nm_connection_to_dbus(connection_cloned, NM_CONNECTION_SERIALIZE_ONLY_SECRETS)); + if (new) { + priv->agent_secrets = nm_g_variant_ref_sink( + nm_connection_to_dbus(new, + NM_CONNECTION_SERIALIZE_WITH_SECRETS_AGENT_OWNED + | NM_CONNECTION_SERIALIZE_WITH_SECRETS_NOT_SAVED)); + } -out: if (_LOGT_ENABLED()) { if ((!!old_secrets) != (!!priv->agent_secrets)) { _LOGT("update agent secrets: secrets %s", old_secrets ? "cleared" : "set"); @@ -499,39 +551,6 @@ out: } } -void -nm_settings_connection_clear_secrets(NMSettingsConnection *self, - gboolean clear_cached_system_secrets, - gboolean persist) -{ - gs_unref_object NMConnection *connection_cloned = NULL; - - if (!nm_settings_connection_still_valid(self)) - return; - - /* FIXME: add API to NMConnection so that we can clone a profile without secrets. */ - - connection_cloned = nm_simple_connection_new_clone(nm_settings_connection_get_connection(self)); - - nm_connection_clear_secrets(connection_cloned); - - if (!nm_settings_connection_update( - self, - connection_cloned, - persist ? NM_SETTINGS_CONNECTION_PERSIST_MODE_KEEP - : NM_SETTINGS_CONNECTION_PERSIST_MODE_NO_PERSIST, - NM_SETTINGS_CONNECTION_INT_FLAGS_NONE, - NM_SETTINGS_CONNECTION_INT_FLAGS_NONE, - NM_SETTINGS_CONNECTION_UPDATE_REASON_IGNORE_PERSIST_FAILURE - | (clear_cached_system_secrets - ? NM_SETTINGS_CONNECTION_UPDATE_REASON_CLEAR_SYSTEM_SECRETS - : NM_SETTINGS_CONNECTION_UPDATE_REASON_NONE) - | NM_SETTINGS_CONNECTION_UPDATE_REASON_CLEAR_AGENT_SECRETS, - "clear-secrets", - NULL)) - nm_assert_not_reached(); -} - static gboolean _secrets_update(NMConnection * connection, const char * setting_name, @@ -829,6 +848,18 @@ nm_settings_connection_new_secrets(NMSettingsConnection *self, return TRUE; } +static gboolean +match_secret_by_setting_name_and_flags_cb(NMSetting * setting, + const char * secret, + NMSettingSecretFlags flags, + gpointer user_data) +{ + const char *get_secrets_setting_name = user_data; + + return nm_streq(nm_setting_get_name(setting), get_secrets_setting_name) + && NM_FLAGS_HAS(flags, NM_SETTING_SECRET_FLAG_AGENT_OWNED); +} + static void get_secrets_done_cb(NMAgentManager * manager, NMAgentManagerCallId call_id_a, @@ -846,7 +877,6 @@ get_secrets_done_cb(NMAgentManager * manager, NMSettingsConnectionPrivate *priv; NMConnection * applied_connection; gs_free_error GError *local = NULL; - gs_unref_variant GVariant *system_secrets = NULL; gs_unref_object NMConnection *new_connection = NULL; gboolean agent_had_system = FALSE; ForEachSecretFlags cmp_flags = {NM_SETTING_SECRET_FLAG_NONE, NM_SETTING_SECRET_FLAG_NONE}; @@ -917,18 +947,12 @@ get_secrets_done_cb(NMAgentManager * manager, _LOGD("(%s:%p) secrets request completed", setting_name, call_id); - system_secrets = nm_g_variant_ref(priv->system_secrets); - new_connection = nm_simple_connection_new_clone(nm_settings_connection_get_connection(self)); - nm_connection_clear_secrets(new_connection); - - if (!_secrets_update(new_connection, setting_name, system_secrets, NULL, &local)) { - _LOGD("(%s:%p) failed to update with existing secrets: %s", - setting_name, - call_id, - local->message); - } + /* Remove old agent-owned secrets in the requested setting */ + nm_connection_clear_secrets_with_flags(new_connection, + match_secret_by_setting_name_and_flags_cb, + (gpointer) setting_name); /* Update the connection with the agent's secrets; by this point if any * system-owned secrets exist in 'secrets' the agent that provided them @@ -962,7 +986,8 @@ get_secrets_done_cb(NMAgentManager * manager, NM_SETTINGS_CONNECTION_INT_FLAGS_NONE, NM_SETTINGS_CONNECTION_INT_FLAGS_NONE, NM_SETTINGS_CONNECTION_UPDATE_REASON_IGNORE_PERSIST_FAILURE - | NM_SETTINGS_CONNECTION_UPDATE_REASON_RESET_SYSTEM_SECRETS + | (agent_had_system ? NM_SETTINGS_CONNECTION_UPDATE_REASON_RESET_SYSTEM_SECRETS + : NM_SETTINGS_CONNECTION_UPDATE_REASON_NONE) | NM_SETTINGS_CONNECTION_UPDATE_REASON_RESET_AGENT_SECRETS, "get-new-secrets", NULL)) @@ -970,6 +995,8 @@ get_secrets_done_cb(NMAgentManager * manager, applied_connection = call_id->applied_connection; if (applied_connection) { + gs_unref_variant GVariant *filtered_secrets2 = NULL; + get_cmp_flags(self, call_id, applied_connection, @@ -981,18 +1008,12 @@ get_secrets_done_cb(NMAgentManager * manager, &agent_had_system, &cmp_flags); - nm_connection_clear_secrets(applied_connection); - - if (!system_secrets - || nm_connection_update_secrets(applied_connection, - setting_name, - system_secrets, - NULL)) { - gs_unref_variant GVariant *filtered_secrets2 = NULL; + nm_connection_clear_secrets_with_flags(applied_connection, + match_secret_by_setting_name_and_flags_cb, + (gpointer) setting_name); - filtered_secrets2 = validate_secret_flags(applied_connection, secrets, &cmp_flags); - nm_connection_update_secrets(applied_connection, setting_name, filtered_secrets2, NULL); - } + filtered_secrets2 = validate_secret_flags(applied_connection, secrets, &cmp_flags); + nm_connection_update_secrets(applied_connection, setting_name, filtered_secrets2, NULL); } _get_secrets_info_callback(call_id, agent_username, setting_name, local); @@ -1060,7 +1081,8 @@ nm_settings_connection_get_secrets(NMSettingsConnection * self, NMAgentManagerCallId call_id_a; gs_free char * joined_hints = NULL; NMSettingsConnectionCallId * call_id; - GError * local = NULL; + GError * local = NULL; + gs_unref_variant GVariant *system_secrets = NULL; g_return_val_if_fail(NM_IS_SETTINGS_CONNECTION(self), NULL); g_return_val_if_fail( @@ -1111,14 +1133,15 @@ nm_settings_connection_get_secrets(NMSettingsConnection * self, * Then we know that the this request probably did not yet include the latest secret-agent. */ priv->last_secret_agent_version_id = nm_agent_manager_get_agent_version_id(priv->agent_mgr); - /* Use priv->system_secrets to work around the fact that nm_connection_clear_secrets() - * will clear secrets on this object's settings. - */ + system_secrets = nm_g_variant_ref_sink( + nm_connection_to_dbus(nm_settings_connection_get_connection(self), + NM_CONNECTION_SERIALIZE_WITH_SECRETS_SYSTEM_OWNED)); + call_id_a = nm_agent_manager_get_secrets(priv->agent_mgr, nm_dbus_object_get_path(NM_DBUS_OBJECT(self)), nm_settings_connection_get_connection(self), subject, - priv->system_secrets, + system_secrets, setting_name, flags, hints, @@ -1325,9 +1348,8 @@ get_settings_auth_cb(NMSettingsConnection * self, GError * error, gpointer data) { - gs_free const char ** seen_bssids = NULL; - NMConnectionSerializationOptions options = {}; - GVariant * settings; + const char * seen_bssids_strv[SEEN_BSSIDS_MAX + 1]; + NMConnectionSerializationOptions options = {}; if (error) { g_dbus_method_invocation_return_gerror(context, error); @@ -1347,17 +1369,15 @@ get_settings_auth_cb(NMSettingsConnection * self, * from the same reason as timestamp. Thus we put it here to GetSettings() * return settings too. */ - seen_bssids = nm_settings_connection_get_seen_bssids(self); - options.seen_bssids = seen_bssids; + _get_seen_bssids(self, seen_bssids_strv); + options.seen_bssids = seen_bssids_strv; /* Secrets should *never* be returned by the GetSettings method, they * get returned by the GetSecrets method which can be better * protected against leakage of secrets to unprivileged callers. */ - settings = nm_connection_to_dbus_full(nm_settings_connection_get_connection(self), - NM_CONNECTION_SERIALIZE_NO_SECRETS, - &options); - g_dbus_method_invocation_return_value(context, g_variant_new("(@a{sa{sv}})", settings)); + + g_dbus_method_invocation_return_value(context, _getsettings_cached_get(self, &options)); } static void @@ -1488,14 +1508,21 @@ update_auth_cb(NMSettingsConnection * self, if (!_nm_connection_aggregate(info->new_settings, NM_CONNECTION_AGGREGATE_ANY_SECRETS, NULL)) { + gs_unref_variant GVariant *secrets = NULL; + /* If the new connection has no secrets, we do not want to remove all * secrets, rather we keep all the existing ones. Do that by merging * them in to the new connection. */ + secrets = nm_g_variant_ref_sink( + nm_connection_to_dbus(nm_settings_connection_get_connection(self), + NM_CONNECTION_SERIALIZE_WITH_SECRETS)); + + if (secrets) + nm_connection_update_secrets(info->new_settings, NULL, secrets, NULL); + if (priv->agent_secrets) nm_connection_update_secrets(info->new_settings, NULL, priv->agent_secrets, NULL); - if (priv->system_secrets) - nm_connection_update_secrets(info->new_settings, NULL, priv->system_secrets, NULL); } else { /* Cache the new secrets from the agent, as stuff like inotify-triggered * changes to connection's backing config files will blow them away if @@ -1558,6 +1585,7 @@ update_auth_cb(NMSettingsConnection * self, : NM_SETTINGS_CONNECTION_UPDATE_REASON_REAPPLY_PARTIAL) | NM_SETTINGS_CONNECTION_UPDATE_REASON_RESET_SYSTEM_SECRETS | NM_SETTINGS_CONNECTION_UPDATE_REASON_RESET_AGENT_SECRETS + | NM_SETTINGS_CONNECTION_UPDATE_REASON_UPDATE_NON_SECRET | (NM_FLAGS_HAS(info->flags, NM_SETTINGS_UPDATE2_FLAG_BLOCK_AUTOCONNECT) ? NM_SETTINGS_CONNECTION_UPDATE_REASON_BLOCK_AUTOCONNECT : NM_SETTINGS_CONNECTION_UPDATE_REASON_NONE), @@ -1568,7 +1596,7 @@ update_auth_cb(NMSettingsConnection * self, gs_unref_object NMConnection *for_agent = NULL; /* Dupe the connection so we can clear out non-agent-owned secrets, - * as agent-owned secrets are the only ones we send back be saved. + * as agent-owned secrets are the only ones we send back to be saved. * Only send secrets to agents of the same UID that called update too. */ for_agent = nm_simple_connection_new_clone(nm_settings_connection_get_connection(self)); @@ -1754,10 +1782,10 @@ impl_settings_connection_update2(NMDBusObject * obj, g_variant_get(parameters, "(@a{sa{sv}}u@a{sv})", &settings, &flags_u, &args); if (NM_FLAGS_ANY(flags_u, - ~((guint32)(_NM_SETTINGS_UPDATE2_FLAG_ALL_PERSIST_MODES - | NM_SETTINGS_UPDATE2_FLAG_VOLATILE - | NM_SETTINGS_UPDATE2_FLAG_BLOCK_AUTOCONNECT - | NM_SETTINGS_UPDATE2_FLAG_NO_REAPPLY)))) { + ~((guint32) (_NM_SETTINGS_UPDATE2_FLAG_ALL_PERSIST_MODES + | NM_SETTINGS_UPDATE2_FLAG_VOLATILE + | NM_SETTINGS_UPDATE2_FLAG_BLOCK_AUTOCONNECT + | NM_SETTINGS_UPDATE2_FLAG_NO_REAPPLY)))) { error = g_error_new_literal(NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_ARGUMENTS, "Unknown flags"); @@ -1888,9 +1916,9 @@ dbus_get_agent_secrets_cb(NMSettingsConnection * self, * by the time we get here. */ dict = nm_connection_to_dbus(nm_settings_connection_get_connection(self), - NM_CONNECTION_SERIALIZE_ONLY_SECRETS); + NM_CONNECTION_SERIALIZE_WITH_SECRETS); if (!dict) - dict = g_variant_new_array(G_VARIANT_TYPE("{sa{sv}}"), NULL, 0); + dict = nm_g_variant_singleton_aLsaLsvII(); g_dbus_method_invocation_return_value(context, g_variant_new("(@a{sa{sv}})", dict)); } } @@ -1959,8 +1987,9 @@ dbus_clear_secrets_auth_cb(NMSettingsConnection * self, GError * error, gpointer user_data) { - NMSettingsConnectionPrivate *priv = NM_SETTINGS_CONNECTION_GET_PRIVATE(self); - gs_free_error GError *local = NULL; + NMSettingsConnectionPrivate *priv = NM_SETTINGS_CONNECTION_GET_PRIVATE(self); + gs_free_error GError *local = NULL; + gs_unref_object NMConnection *connection_cloned = NULL; if (error) { g_dbus_method_invocation_return_gerror(context, error); @@ -1973,7 +2002,24 @@ dbus_clear_secrets_auth_cb(NMSettingsConnection * self, return; } - nm_settings_connection_clear_secrets(self, TRUE, TRUE); + /* FIXME: add API to NMConnection so that we can clone a profile without secrets. */ + + connection_cloned = nm_simple_connection_new_clone(nm_settings_connection_get_connection(self)); + + nm_connection_clear_secrets(connection_cloned); + + if (!nm_settings_connection_update( + self, + connection_cloned, + NM_SETTINGS_CONNECTION_PERSIST_MODE_KEEP, + NM_SETTINGS_CONNECTION_INT_FLAGS_NONE, + NM_SETTINGS_CONNECTION_INT_FLAGS_NONE, + NM_SETTINGS_CONNECTION_UPDATE_REASON_IGNORE_PERSIST_FAILURE + | NM_SETTINGS_CONNECTION_UPDATE_REASON_CLEAR_SYSTEM_SECRETS + | NM_SETTINGS_CONNECTION_UPDATE_REASON_CLEAR_AGENT_SECRETS, + "clear-secrets", + NULL)) + nm_assert_not_reached(); /* Tell agents to remove secrets for this connection */ nm_agent_manager_delete_secrets(priv->agent_mgr, @@ -2142,7 +2188,9 @@ _cmp_last_resort(NMSettingsConnection *a, NMSettingsConnection *b) /* hm, same UUID. Use their pointer value to give them a stable * order. */ - return (a > b) ? -1 : 1; + NM_CMP_DIRECT_PTR(a, b); + + return nm_assert_unreachable_val(0); } /* sorting for "best" connections. @@ -2183,6 +2231,15 @@ nm_settings_connection_cmp_autoconnect_priority(NMSettingsConnection *a, NMSetti return _cmp_last_resort(a, b); } +int +nm_settings_connection_cmp_autoconnect_priority_with_data(gconstpointer pa, + gconstpointer pb, + gpointer user_data) +{ + return nm_settings_connection_cmp_autoconnect_priority((NMSettingsConnection *) pa, + (NMSettingsConnection *) pb); +} + int nm_settings_connection_cmp_autoconnect_priority_p_with_data(gconstpointer pa, gconstpointer pb, @@ -2243,6 +2300,8 @@ nm_settings_connection_update_timestamp(NMSettingsConnection *self, guint64 time _LOGT("timestamp: set timestamp %" G_GUINT64_FORMAT, timestamp); + _nm_settings_notify_sorted_by_autoconnect_priority_maybe_changed(priv->settings); + if (!priv->kf_db_timestamps) return; @@ -2293,68 +2352,66 @@ _nm_settings_connection_register_kf_dbs(NMSettingsConnection *self, if (priv->kf_db_seen_bssids != kf_db_seen_bssids) { gs_strfreev char **tmp_strv = NULL; - gsize i, len; + gsize len; + gsize i; + guint result_len; nm_key_file_db_unref(priv->kf_db_seen_bssids); priv->kf_db_seen_bssids = nm_key_file_db_ref(kf_db_seen_bssids); tmp_strv = nm_key_file_db_get_string_list(priv->kf_db_seen_bssids, connection_uuid, &len); - nm_clear_pointer(&priv->seen_bssids, g_hash_table_unref); + if (priv->seen_bssids_hash) + g_hash_table_remove_all(priv->seen_bssids_hash); - if (len > 0) { - _LOGT("read %zu seen-bssids from keyfile database \"%s\"", - len, - nm_key_file_db_get_filename(priv->kf_db_seen_bssids)); - priv->seen_bssids = _seen_bssids_hash_new(); - for (i = len; i > 0;) - g_hash_table_add(priv->seen_bssids, g_steal_pointer(&tmp_strv[--i])); - nm_clear_g_free(&tmp_strv); - } else { - NMSettingWireless *s_wifi; + for (result_len = 0, i = 0; i < len; i++) { + NMEtherAddr addr_bin; + SeenBssidEntry *entry; - _LOGT("no seen-bssids from keyfile database \"%s\"", - nm_key_file_db_get_filename(priv->kf_db_seen_bssids)); + nm_assert(result_len == nm_g_hash_table_size(priv->seen_bssids_hash)); + if (result_len >= SEEN_BSSIDS_MAX) + break; - /* If this connection didn't have an entry in the seen-bssids database, - * maybe this is the first time we've read it in, so populate the - * seen-bssids list from the deprecated seen-bssids property of the - * wifi setting. - */ - s_wifi = - nm_connection_get_setting_wireless(nm_settings_connection_get_connection(self)); - if (s_wifi) { - len = nm_setting_wireless_get_num_seen_bssids(s_wifi); - if (len > 0) { - priv->seen_bssids = _seen_bssids_hash_new(); - for (i = 0; i < len; i++) { - const char *bssid = nm_setting_wireless_get_seen_bssid(s_wifi, i); - - g_hash_table_add(priv->seen_bssids, g_strdup(bssid)); - } - } + if (!_nm_utils_hwaddr_aton_exact(tmp_strv[i], &addr_bin, sizeof(addr_bin))) + continue; + + if (!priv->seen_bssids_hash) + priv->seen_bssids_hash = _seen_bssids_hash_new(); + + entry = _seen_bssid_entry_new_stale_bin(&addr_bin); + c_list_link_tail(&priv->seen_bssids_lst_head, &entry->seen_bssids_lst); + if (!g_hash_table_insert(priv->seen_bssids_hash, entry, entry)) { + /* duplicate detected! The @entry key was freed by g_hash_table_insert(). */ + continue; } + result_len++; } + if (result_len > 0) { + _LOGT("read %u seen-bssids from keyfile database \"%s\"", + result_len, + nm_key_file_db_get_filename(priv->kf_db_seen_bssids)); + } else + nm_clear_pointer(&priv->seen_bssids_hash, g_hash_table_destroy); + + nm_assert(nm_g_hash_table_size(priv->seen_bssids_hash) == result_len); + nm_assert(result_len <= SEEN_BSSIDS_MAX); } } -/** - * nm_settings_connection_get_seen_bssids: - * @self: the #NMSettingsConnection - * - * Returns current list of seen BSSIDs for the connection. - * - * Returns: (transfer container) list of seen BSSIDs (in the standard hex-digits-and-colons notation). - * The caller is responsible for freeing the list, but not the content. - **/ -const char ** -nm_settings_connection_get_seen_bssids(NMSettingsConnection *self) +static guint +_get_seen_bssids(NMSettingsConnection *self, const char *strv_buf[static(SEEN_BSSIDS_MAX + 1)]) { - g_return_val_if_fail(NM_IS_SETTINGS_CONNECTION(self), NULL); + NMSettingsConnectionPrivate *priv = NM_SETTINGS_CONNECTION_GET_PRIVATE(self); + SeenBssidEntry * entry; + guint i; - return nm_utils_strdict_get_keys(NM_SETTINGS_CONNECTION_GET_PRIVATE(self)->seen_bssids, - TRUE, - NULL); + i = 0; + c_list_for_each_entry (entry, &priv->seen_bssids_lst_head, seen_bssids_lst) { + nm_assert(i <= SEEN_BSSIDS_MAX); + strv_buf[i++] = entry->bssid; + } + strv_buf[i] = NULL; + return i; } /** @@ -2368,14 +2425,17 @@ gboolean nm_settings_connection_has_seen_bssid(NMSettingsConnection *self, const char *bssid) { NMSettingsConnectionPrivate *priv; + NMEtherAddr addr_bin; g_return_val_if_fail(NM_IS_SETTINGS_CONNECTION(self), FALSE); g_return_val_if_fail(bssid, FALSE); + nm_assert(_nm_utils_hwaddr_aton_exact(bssid, &addr_bin, sizeof(addr_bin))); priv = NM_SETTINGS_CONNECTION_GET_PRIVATE(self); - return priv->seen_bssids - && g_hash_table_contains(NM_SETTINGS_CONNECTION_GET_PRIVATE(self)->seen_bssids, bssid); + return priv->seen_bssids_hash + && g_hash_table_contains(NM_SETTINGS_CONNECTION_GET_PRIVATE(self)->seen_bssids_hash, + bssid); } /** @@ -2390,15 +2450,47 @@ void nm_settings_connection_add_seen_bssid(NMSettingsConnection *self, const char *seen_bssid) { NMSettingsConnectionPrivate *priv = NM_SETTINGS_CONNECTION_GET_PRIVATE(self); - gs_free const char ** strv = NULL; + const char * seen_bssids_strv[SEEN_BSSIDS_MAX + 1]; + NMEtherAddr addr_bin; const char * connection_uuid; + SeenBssidEntry entry_stack; + SeenBssidEntry * entry; + guint i; - g_return_if_fail(seen_bssid != NULL); + g_return_if_fail(seen_bssid); - if (!priv->seen_bssids) - priv->seen_bssids = _seen_bssids_hash_new(); + if (!_nm_utils_hwaddr_aton_exact(seen_bssid, &addr_bin, sizeof(addr_bin))) + g_return_if_reached(); - g_hash_table_add(priv->seen_bssids, g_strdup(seen_bssid)); + _seen_bssid_entry_init_stale(&entry_stack, &addr_bin); + + if (!priv->seen_bssids_hash) { + priv->seen_bssids_hash = _seen_bssids_hash_new(); + entry = NULL; + } else + entry = g_hash_table_lookup(priv->seen_bssids_hash, &entry_stack); + + if (entry) { + if (!nm_c_list_move_front(&priv->seen_bssids_lst_head, &entry->seen_bssids_lst)) { + /* no change. */ + return; + } + } else { + entry = _seen_bssid_entry_new_stale_copy(&entry_stack); + c_list_link_front(&priv->seen_bssids_lst_head, &entry->seen_bssids_lst); + if (!g_hash_table_add(priv->seen_bssids_hash, entry)) + nm_assert_not_reached(); + + if (g_hash_table_size(priv->seen_bssids_hash) > SEEN_BSSIDS_MAX) { + g_hash_table_remove( + priv->seen_bssids_hash, + c_list_last_entry(&priv->seen_bssids_lst_head, SeenBssidEntry, seen_bssids_lst)); + } + } + + nm_assert(g_hash_table_size(priv->seen_bssids_hash) <= SEEN_BSSIDS_MAX); + nm_assert(g_hash_table_size(priv->seen_bssids_hash) + == c_list_length(&priv->seen_bssids_lst_head)); if (!priv->kf_db_seen_bssids) return; @@ -2407,12 +2499,8 @@ nm_settings_connection_add_seen_bssid(NMSettingsConnection *self, const char *se if (!connection_uuid) return; - strv = nm_utils_strdict_get_keys(priv->seen_bssids, TRUE, NULL); - - nm_key_file_db_set_string_list(priv->kf_db_seen_bssids, - connection_uuid, - strv ?: NM_PTRARRAY_EMPTY(const char *), - -1); + i = _get_seen_bssids(self, seen_bssids_strv); + nm_key_file_db_set_string_list(priv->kf_db_seen_bssids, connection_uuid, seen_bssids_strv, i); } /*****************************************************************************/ @@ -2623,7 +2711,7 @@ nm_settings_connection_init(NMSettingsConnection *self) self->_priv = priv; c_list_init(&self->_connections_lst); - + c_list_init(&priv->seen_bssids_lst_head); c_list_init(&priv->call_ids_lst_head); c_list_init(&priv->auth_lst_head); @@ -2659,15 +2747,16 @@ dispose(GObject *object) _get_secrets_cancel(self, call_id, TRUE); } - nm_clear_pointer(&priv->system_secrets, g_variant_unref); nm_clear_pointer(&priv->agent_secrets, g_variant_unref); - nm_clear_pointer(&priv->seen_bssids, g_hash_table_destroy); + nm_clear_pointer(&priv->seen_bssids_hash, g_hash_table_destroy); g_clear_object(&priv->agent_mgr); g_clear_object(&priv->connection); + _getsettings_cached_clear(priv); + nm_clear_pointer(&priv->kf_db_timestamps, nm_key_file_db_unref); nm_clear_pointer(&priv->kf_db_seen_bssids, nm_key_file_db_unref); @@ -2732,20 +2821,17 @@ static const NMDBusInterfaceInfoExtended interface_info_settings_connection = { .out_args = NM_DEFINE_GDBUS_ARG_INFOS(NM_DEFINE_GDBUS_ARG_INFO("result", "a{sv}"), ), ), .handle = impl_settings_connection_update2, ), ), - .signals = NM_DEFINE_GDBUS_SIGNAL_INFOS(&nm_signal_info_property_changed_legacy, - &signal_info_updated, - &signal_info_removed, ), + .signals = NM_DEFINE_GDBUS_SIGNAL_INFOS(&signal_info_updated, &signal_info_removed, ), .properties = NM_DEFINE_GDBUS_PROPERTY_INFOS( - NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE_L("Unsaved", - "b", - NM_SETTINGS_CONNECTION_UNSAVED), + NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE("Unsaved", + "b", + NM_SETTINGS_CONNECTION_UNSAVED), NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE("Flags", "u", NM_SETTINGS_CONNECTION_FLAGS), NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE("Filename", "s", NM_SETTINGS_CONNECTION_FILENAME), ), ), - .legacy_property_changed = TRUE, }; static void diff --git a/src/core/settings/nm-settings-connection.h b/src/core/settings/nm-settings-connection.h index 7c61dbeb..fa3dbcfb 100644 --- a/src/core/settings/nm-settings-connection.h +++ b/src/core/settings/nm-settings-connection.h @@ -63,6 +63,9 @@ typedef enum { NM_SETTINGS_CONNECTION_UPDATE_REASON_BLOCK_AUTOCONNECT = (1u << 8), + /* Is anything other than secrets changing */ + NM_SETTINGS_CONNECTION_UPDATE_REASON_UPDATE_NON_SECRET = (1u << 9), + } NMSettingsConnectionUpdateReason; typedef enum { @@ -274,10 +277,6 @@ nm_settings_connection_get_secrets(NMSettingsConnection * self, void nm_settings_connection_cancel_secrets(NMSettingsConnection * self, NMSettingsConnectionCallId *call_id); -void nm_settings_connection_clear_secrets(NMSettingsConnection *self, - gboolean clear_cached_system_secrets, - gboolean persist); - gboolean nm_settings_connection_check_visibility(NMSettingsConnection *self, NMSessionMonitor * session_monitor); @@ -324,6 +323,9 @@ int nm_settings_connection_cmp_timestamp_p_with_data(gconstpointer pa, gpointer user_data); int nm_settings_connection_cmp_autoconnect_priority(NMSettingsConnection *a, NMSettingsConnection *b); +int nm_settings_connection_cmp_autoconnect_priority_with_data(gconstpointer pa, + gconstpointer pb, + gpointer user_data); int nm_settings_connection_cmp_autoconnect_priority_p_with_data(gconstpointer pa, gconstpointer pb, gpointer user_data); @@ -338,8 +340,6 @@ gboolean nm_settings_connection_get_timestamp(NMSettingsConnection *self, guint6 void nm_settings_connection_update_timestamp(NMSettingsConnection *self, guint64 timestamp); -const char **nm_settings_connection_get_seen_bssids(NMSettingsConnection *self); - gboolean nm_settings_connection_has_seen_bssid(NMSettingsConnection *self, const char *bssid); void nm_settings_connection_add_seen_bssid(NMSettingsConnection *self, const char *seen_bssid); diff --git a/src/core/settings/nm-settings-plugin.c b/src/core/settings/nm-settings-plugin.c index 9e81caab..66cc19b6 100644 --- a/src/core/settings/nm-settings-plugin.c +++ b/src/core/settings/nm-settings-plugin.c @@ -9,7 +9,7 @@ #include "nm-settings-plugin.h" #include "nm-utils.h" -#include "nm-core-internal.h" +#include "libnm-core-intern/nm-core-internal.h" #include "nm-settings-connection.h" diff --git a/src/core/settings/nm-settings-storage.c b/src/core/settings/nm-settings-storage.c index c56ba075..e284b822 100644 --- a/src/core/settings/nm-settings-storage.c +++ b/src/core/settings/nm-settings-storage.c @@ -7,6 +7,7 @@ #include "nm-settings-storage.h" +#include "libnm-glib-aux/nm-uuid.h" #include "nm-utils.h" #include "nm-settings-plugin.h" @@ -72,7 +73,7 @@ set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *ps case PROP_UUID: /* construct-only */ self->_uuid = g_value_dup_string(value); - nm_assert(!self->_uuid || nm_utils_is_uuid(self->_uuid)); + nm_assert(!self->_uuid || nm_uuid_is_normalized(self->_uuid)); break; case PROP_FILENAME: /* construct-only */ @@ -97,7 +98,7 @@ NMSettingsStorage * nm_settings_storage_new(NMSettingsPlugin *plugin, const char *uuid, const char *filename) { nm_assert(NM_IS_SETTINGS_PLUGIN(plugin)); - nm_assert(nm_utils_is_uuid(uuid)); + nm_assert(nm_uuid_is_normalized(uuid)); return g_object_new(NM_TYPE_SETTINGS_STORAGE, NM_SETTINGS_STORAGE_PLUGIN, diff --git a/src/core/settings/nm-settings-storage.h b/src/core/settings/nm-settings-storage.h index 970cfd77..2e5e1c55 100644 --- a/src/core/settings/nm-settings-storage.h +++ b/src/core/settings/nm-settings-storage.h @@ -48,36 +48,35 @@ GType nm_settings_storage_get_type(void); NMSettingsStorage * nm_settings_storage_new(struct _NMSettingsPlugin *plugin, const char *uuid, const char *filename); +/* forward declare so we don't have to include "nm-settings-plugin.h" here. */ +GType nm_settings_plugin_get_type(void); + static inline struct _NMSettingsPlugin * nm_settings_storage_get_plugin(const NMSettingsStorage *self) { - GType nm_settings_plugin_get_type(void); - g_return_val_if_fail(NM_IS_SETTINGS_STORAGE(self), NULL); nm_assert(G_TYPE_CHECK_INSTANCE_TYPE(self->_plugin, nm_settings_plugin_get_type())); return self->_plugin; } +gboolean nm_uuid_is_normalized_full(const char *str); + static inline const char * nm_settings_storage_get_uuid(const NMSettingsStorage *self) { - gboolean nm_utils_is_uuid(const char *str); - g_return_val_if_fail(NM_IS_SETTINGS_STORAGE(self), NULL); - nm_assert(nm_utils_is_uuid(self->_uuid)); + nm_assert(nm_uuid_is_normalized_full(self->_uuid)); return self->_uuid; } static inline const char * nm_settings_storage_get_uuid_opt(const NMSettingsStorage *self) { - gboolean nm_utils_is_uuid(const char *str); - g_return_val_if_fail(NM_IS_SETTINGS_STORAGE(self), NULL); - nm_assert(!self->_uuid || nm_utils_is_uuid(self->_uuid)); + nm_assert(!self->_uuid || nm_uuid_is_normalized_full(self->_uuid)); return self->_uuid; } diff --git a/src/core/settings/nm-settings.c b/src/core/settings/nm-settings.c index 3d31fb8b..f9f98de7 100644 --- a/src/core/settings/nm-settings.c +++ b/src/core/settings/nm-settings.c @@ -20,9 +20,10 @@ #include #endif -#include "nm-libnm-core-intern/nm-common-macros.h" -#include "nm-glib-aux/nm-keyfile-aux.h" -#include "nm-keyfile-internal.h" +#include "libnm-core-aux-intern/nm-common-macros.h" +#include "libnm-glib-aux/nm-uuid.h" +#include "libnm-glib-aux/nm-keyfile-aux.h" +#include "libnm-core-intern/nm-keyfile-internal.h" #include "nm-dbus-interface.h" #include "nm-connection.h" #include "nm-setting-8021x.h" @@ -44,17 +45,17 @@ #include "nm-setting-proxy.h" #include "nm-setting-bond.h" #include "nm-utils.h" -#include "nm-core-internal.h" +#include "libnm-core-intern/nm-core-internal.h" -#include "nm-std-aux/c-list-util.h" -#include "nm-glib-aux/nm-c-list.h" +#include "libnm-std-aux/c-list-util.h" +#include "libnm-glib-aux/nm-c-list.h" #include "nm-dbus-object.h" #include "devices/nm-device-ethernet.h" #include "nm-settings-connection.h" #include "nm-settings-plugin.h" #include "nm-dbus-manager.h" #include "nm-auth-utils.h" -#include "nm-libnm-core-intern/nm-auth-subject.h" +#include "libnm-core-aux-intern/nm-auth-subject.h" #include "nm-session-monitor.h" #include "plugins/keyfile/nms-keyfile-plugin.h" #include "plugins/keyfile/nms-keyfile-storage.h" @@ -139,7 +140,7 @@ nm_assert_storage_data_lst(CList *head) u = nm_settings_storage_get_uuid(sd->storage); if (!uuid) { uuid = u; - nm_assert(nm_utils_is_uuid(uuid)); + nm_assert(nm_uuid_is_normalized(uuid)); } else nm_assert(nm_streq0(uuid, u)); } @@ -182,7 +183,7 @@ _sett_conn_entry_new(const char *uuid) SettConnEntry *sett_conn_entry; gsize l_p_1; - nm_assert(nm_utils_is_uuid(uuid)); + nm_assert(nm_uuid_is_normalized(uuid)); l_p_1 = strlen(uuid) + 1; @@ -370,6 +371,7 @@ typedef struct { CList connections_lst_head; NMSettingsConnection **connections_cached_list; + NMSettingsConnection **connections_cached_list_sorted_by_autoconnect_priority; GSList *unmanaged_specs; GSList *unrecognized_specs; @@ -386,8 +388,17 @@ typedef struct { guint kf_db_flush_idle_id_timestamps; guint kf_db_flush_idle_id_seen_bssids; + bool kf_db_pruned_timestamps; + bool kf_db_pruned_seen_bssid; + bool started : 1; + /* Whether NMSettingsConnections changed in a way that affects the comparison + * with nm_settings_connection_cmp_autoconnect_priority_with_data(). In that case, + * we may need to re-sort the connections_cached_list_sorted_by_autoconnect_priority + * list. */ + bool sorted_by_autoconnect_priority_maybe_changed : 1; + } NMSettingsPrivate; struct _NMSettings { @@ -487,6 +498,8 @@ _startup_complete_check_is_ready(NMSettings * self, conn = nm_settings_connection_get_connection(sett_conn); nm_manager_for_each_device (priv->manager, device, tmp_lst) { + gs_free_error GError *error = NULL; + if (!nm_device_is_real(device)) continue; @@ -497,7 +510,13 @@ _startup_complete_check_is_ready(NMSettings * self, continue; } - if (!nm_device_check_connection_compatible(device, conn, NULL)) + /* Check that device is compatible with the device. We are also happy + * with a device compatible but for which the connection is disallowed + * by NM configuration. */ + if (!nm_device_check_connection_compatible(device, conn, &error) + && !g_error_matches(error, + NM_UTILS_ERROR, + NM_UTILS_ERROR_CONNECTION_AVAILABLE_DISALLOWED)) continue; return TRUE; @@ -1433,7 +1452,8 @@ _plugin_connections_reload(NMSettings *self) NM_SETTINGS_CONNECTION_INT_FLAGS_NONE, TRUE, NM_SETTINGS_CONNECTION_UPDATE_REASON_RESET_SYSTEM_SECRETS - | NM_SETTINGS_CONNECTION_UPDATE_REASON_RESET_AGENT_SECRETS); + | NM_SETTINGS_CONNECTION_UPDATE_REASON_RESET_AGENT_SECRETS + | NM_SETTINGS_CONNECTION_UPDATE_REASON_UPDATE_NON_SECRET); for (iter = priv->plugins; iter; iter = iter->next) nm_settings_plugin_load_connections_done(iter->data); @@ -1460,7 +1480,7 @@ _add_connection_to_first_plugin(NMSettings * self, uuid = nm_connection_get_uuid(new_connection); - nm_assert(nm_utils_is_uuid(uuid)); + nm_assert(nm_uuid_is_normalized(uuid)); for (iter = priv->plugins; iter; iter = iter->next) { NMSettingsPlugin *plugin = NM_SETTINGS_PLUGIN(iter->data); @@ -1541,9 +1561,7 @@ _add_connection_to_first_plugin(NMSettings * self, } agent_owned_secrets = - nm_connection_to_dbus(new_connection, - NM_CONNECTION_SERIALIZE_ONLY_SECRETS - | NM_CONNECTION_SERIALIZE_WITH_SECRETS_AGENT_OWNED); + nm_connection_to_dbus(new_connection, NM_CONNECTION_SERIALIZE_WITH_SECRETS_AGENT_OWNED); connection_to_add_real = _connection_changed_normalize_connection(storage, connection_to_add, @@ -1912,7 +1930,8 @@ again_delete_tombstone: _NM_SETTINGS_CONNECTION_INT_FLAGS_PERSISTENT_MASK, FALSE, NM_SETTINGS_CONNECTION_UPDATE_REASON_RESET_SYSTEM_SECRETS - | NM_SETTINGS_CONNECTION_UPDATE_REASON_RESET_AGENT_SECRETS + | NM_SETTINGS_CONNECTION_UPDATE_REASON_CLEAR_AGENT_SECRETS + | NM_SETTINGS_CONNECTION_UPDATE_REASON_UPDATE_NON_SECRET | (NM_FLAGS_HAS(add_reason, NM_SETTINGS_CONNECTION_ADD_REASON_BLOCK_AUTOCONNECT) ? NM_SETTINGS_CONNECTION_UPDATE_REASON_BLOCK_AUTOCONNECT : NM_SETTINGS_CONNECTION_UPDATE_REASON_NONE)); @@ -2218,9 +2237,7 @@ nm_settings_update_connection(NMSettings * self, nm_assert(nm_streq(uuid, nm_settings_storage_get_uuid(new_storage))); agent_owned_secrets = - nm_connection_to_dbus(connection, - NM_CONNECTION_SERIALIZE_ONLY_SECRETS - | NM_CONNECTION_SERIALIZE_WITH_SECRETS_AGENT_OWNED); + nm_connection_to_dbus(connection, NM_CONNECTION_SERIALIZE_WITH_SECRETS_AGENT_OWNED); new_connection_real = _connection_changed_normalize_connection(new_storage, new_connection, agent_owned_secrets, @@ -2297,7 +2314,7 @@ nm_settings_delete_connection(NMSettings * self, nm_assert(NM_IS_SETTINGS_STORAGE(cur_storage)); uuid = nm_settings_storage_get_uuid(cur_storage); - nm_assert(nm_utils_is_uuid(uuid)); + nm_assert(nm_uuid_is_normalized(uuid)); sett_conn_entry = _sett_conn_entries_get(self, uuid); @@ -2691,9 +2708,9 @@ impl_settings_add_connection2(NMDBusObject * obj, g_variant_get(parameters, "(@a{sa{sv}}u@a{sv})", &settings, &flags_u, &args); if (NM_FLAGS_ANY(flags_u, - ~((guint32)(NM_SETTINGS_ADD_CONNECTION2_FLAG_TO_DISK - | NM_SETTINGS_ADD_CONNECTION2_FLAG_IN_MEMORY - | NM_SETTINGS_ADD_CONNECTION2_FLAG_BLOCK_AUTOCONNECT)))) { + ~((guint32) (NM_SETTINGS_ADD_CONNECTION2_FLAG_TO_DISK + | NM_SETTINGS_ADD_CONNECTION2_FLAG_IN_MEMORY + | NM_SETTINGS_ADD_CONNECTION2_FLAG_BLOCK_AUTOCONNECT)))) { g_dbus_method_invocation_take_error(invocation, g_error_new_literal(NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_ARGUMENTS, @@ -2814,7 +2831,8 @@ impl_settings_load_connections(NMDBusObject * obj, NM_SETTINGS_CONNECTION_INT_FLAGS_NONE, TRUE, NM_SETTINGS_CONNECTION_UPDATE_REASON_RESET_SYSTEM_SECRETS - | NM_SETTINGS_CONNECTION_UPDATE_REASON_RESET_AGENT_SECRETS); + | NM_SETTINGS_CONNECTION_UPDATE_REASON_RESET_AGENT_SECRETS + | NM_SETTINGS_CONNECTION_UPDATE_REASON_UPDATE_NON_SECRET); for (iter = priv->plugins; iter; iter = iter->next) nm_settings_plugin_load_connections_done(iter->data); @@ -2832,7 +2850,7 @@ impl_settings_load_connections(NMDBusObject * obj, g_dbus_method_invocation_return_value(invocation, g_variant_new("(b^as)", - (gboolean)(!failures), + (gboolean) (!failures), failures ? (const char **) failures->pdata : NM_PTRARRAY_EMPTY(const char *))); @@ -2870,25 +2888,48 @@ impl_settings_reload_connections(NMDBusObject * obj, /*****************************************************************************/ +void +_nm_settings_notify_sorted_by_autoconnect_priority_maybe_changed(NMSettings *self) +{ + NMSettingsPrivate *priv = NM_SETTINGS_GET_PRIVATE(self); + + priv->sorted_by_autoconnect_priority_maybe_changed = TRUE; +} + static void _clear_connections_cached_list(NMSettingsPrivate *priv) { - if (!priv->connections_cached_list) - return; + if (priv->connections_cached_list) { + nm_assert(priv->connections_len == NM_PTRARRAY_LEN(priv->connections_cached_list)); + +#if NM_MORE_ASSERTS + /* set the pointer to a bogus value. This makes it more apparent + * if somebody has a reference to the cached list and still uses + * it. That is a bug, this code just tries to make it blow up + * more eagerly. */ + memset(priv->connections_cached_list, + 0x43, + sizeof(NMSettingsConnection *) * (priv->connections_len + 1)); +#endif - nm_assert(priv->connections_len == NM_PTRARRAY_LEN(priv->connections_cached_list)); + nm_clear_g_free(&priv->connections_cached_list); + } + if (priv->connections_cached_list_sorted_by_autoconnect_priority) { + nm_assert(priv->connections_len + == NM_PTRARRAY_LEN(priv->connections_cached_list_sorted_by_autoconnect_priority)); #if NM_MORE_ASSERTS - /* set the pointer to a bogus value. This makes it more apparent - * if somebody has a reference to the cached list and still uses - * it. That is a bug, this code just tries to make it blow up - * more eagerly. */ - memset(priv->connections_cached_list, - 0x43, - sizeof(NMSettingsConnection *) * (priv->connections_len + 1)); + /* set the pointer to a bogus value. This makes it more apparent + * if somebody has a reference to the cached list and still uses + * it. That is a bug, this code just tries to make it blow up + * more eagerly. */ + memset(priv->connections_cached_list_sorted_by_autoconnect_priority, + 0x42, + sizeof(NMSettingsConnection *) * (priv->connections_len + 1)); #endif - nm_clear_g_free(&priv->connections_cached_list); + nm_clear_g_free(&priv->connections_cached_list_sorted_by_autoconnect_priority); + } } static void @@ -3027,6 +3068,65 @@ nm_settings_get_connections(NMSettings *self, guint *out_len) return priv->connections_cached_list; } +NMSettingsConnection *const * +nm_settings_get_connections_sorted_by_autoconnect_priority(NMSettings *self, guint *out_len) +{ + NMSettingsPrivate *priv; + gboolean needs_sort = FALSE; + + g_return_val_if_fail(NM_IS_SETTINGS(self), NULL); + + priv = NM_SETTINGS_GET_PRIVATE(self); + + nm_assert(priv->connections_len == c_list_length(&priv->connections_lst_head)); + nm_assert( + !priv->connections_cached_list_sorted_by_autoconnect_priority + || (priv->connections_len + == NM_PTRARRAY_LEN(priv->connections_cached_list_sorted_by_autoconnect_priority))); + + if (!priv->connections_cached_list_sorted_by_autoconnect_priority) { + NMSettingsConnection *const *list_cached; + guint len; + + list_cached = nm_settings_get_connections(self, &len); + priv->connections_cached_list_sorted_by_autoconnect_priority = + nm_memdup(list_cached, sizeof(NMSettingsConnection *) * (len + 1)); + needs_sort = (len > 1); + } else if (priv->sorted_by_autoconnect_priority_maybe_changed) { + if (!nm_utils_ptrarray_is_sorted( + (gconstpointer *) priv->connections_cached_list_sorted_by_autoconnect_priority, + priv->connections_len, + FALSE, + nm_settings_connection_cmp_autoconnect_priority_with_data, + NULL)) { + /* We cache the sorted list, but we don't monitor all entries whether they + * get modified to invalidate the sort order. So every time we have to check + * whether the sort order is still correct. The vast majority of the time it + * is, and this check is faster than sorting anew. */ + needs_sort = TRUE; + } + } else { + nm_assert(nm_utils_ptrarray_is_sorted( + (gconstpointer *) priv->connections_cached_list_sorted_by_autoconnect_priority, + priv->connections_len, + TRUE, + nm_settings_connection_cmp_autoconnect_priority_with_data, + NULL)); + } + + priv->sorted_by_autoconnect_priority_maybe_changed = FALSE; + if (needs_sort) { + g_qsort_with_data(priv->connections_cached_list_sorted_by_autoconnect_priority, + priv->connections_len, + sizeof(NMSettingsConnection *), + nm_settings_connection_cmp_autoconnect_priority_p_with_data, + NULL); + } + + NM_SET_OUT(out_len, priv->connections_len); + return priv->connections_cached_list_sorted_by_autoconnect_priority; +} + /** * nm_settings_get_connections_clone: * @self: the #NMSetting @@ -3058,9 +3158,13 @@ nm_settings_get_connections_clone(NMSettings * self, g_return_val_if_fail(NM_IS_SETTINGS(self), NULL); - list_cached = nm_settings_get_connections(self, &len); + if (sort_compare_func == nm_settings_connection_cmp_autoconnect_priority_p_with_data) { + list_cached = nm_settings_get_connections_sorted_by_autoconnect_priority(self, &len); + sort_compare_func = NULL; + } else + list_cached = nm_settings_get_connections(self, &len); -#if NM_MORE_ASSERTS +#if NM_MORE_ASSERTS > 10 nm_assert(list_cached); for (i = 0; i < len; i++) nm_assert(NM_IS_SETTINGS_CONNECTION(list_cached[i])); @@ -3204,7 +3308,7 @@ add_plugin_load_file(NMSettings *self, const char *pname, GError **error) /* errors after this point are fatal, because we loaded the shared library already. */ - if (!g_module_symbol(module, "nm_settings_plugin_factory", (gpointer)(&factory_func))) { + if (!g_module_symbol(module, "nm_settings_plugin_factory", (gpointer) (&factory_func))) { g_set_error(error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, @@ -3591,6 +3695,41 @@ again: /*****************************************************************************/ +static gboolean +_kf_db_prune_predicate(const char *uuid, gpointer user_data) +{ + return !!nm_settings_get_connection_by_uuid(user_data, uuid); +} + +static void +_kf_db_to_file(NMSettings *self, gboolean is_timestamps, gboolean force_write) +{ + NMSettingsPrivate *priv = NM_SETTINGS_GET_PRIVATE(self); + NMKeyFileDB * kf_db; + bool * p_kf_db_pruned; + + if (is_timestamps) { + kf_db = priv->kf_db_timestamps; + p_kf_db_pruned = &priv->kf_db_pruned_timestamps; + } else { + kf_db = priv->kf_db_seen_bssids; + p_kf_db_pruned = &priv->kf_db_pruned_seen_bssid; + } + + if (!*p_kf_db_pruned) { + /* we only prune the DB once, because afterwards every + * add/remove of an connection will lead to a direct update. */ + *p_kf_db_pruned = TRUE; + nm_key_file_db_prune(kf_db, _kf_db_prune_predicate, self); + + /* once we also go over the directory, and see whether we + * have any left over temporary files to delete. */ + nm_key_file_db_prune_tmp_files(kf_db); + } + + nm_key_file_db_to_file(kf_db, force_write); +} + G_GNUC_PRINTF(4, 5) static void _kf_db_log_fcn(NMKeyFileDB *kf_db, int syslog_level, gpointer user_data, const char *fmt, ...) @@ -3639,7 +3778,7 @@ _kf_db_got_dirty_flush(NMSettings *self, gboolean is_timestamps) } if (nm_key_file_db_is_dirty(kf_db)) - nm_key_file_db_to_file(kf_db, FALSE); + _kf_db_to_file(self, is_timestamps, FALSE); else { _LOGT("[%s-keyfile]: skip saving changes to \"%s\"", prefix, @@ -3692,15 +3831,10 @@ _kf_db_got_dirty_fcn(NMKeyFileDB *kf_db, gpointer user_data) void nm_settings_kf_db_write(NMSettings *self) { - NMSettingsPrivate *priv; - g_return_if_fail(NM_IS_SETTINGS(self)); - priv = NM_SETTINGS_GET_PRIVATE(self); - if (priv->kf_db_timestamps) - nm_key_file_db_to_file(priv->kf_db_timestamps, TRUE); - if (priv->kf_db_seen_bssids) - nm_key_file_db_to_file(priv->kf_db_seen_bssids, TRUE); + _kf_db_to_file(self, TRUE, TRUE); + _kf_db_to_file(self, FALSE, TRUE); } /*****************************************************************************/ @@ -3938,8 +4072,8 @@ finalize(GObject *object) nm_clear_g_source(&priv->kf_db_flush_idle_id_timestamps); nm_clear_g_source(&priv->kf_db_flush_idle_id_seen_bssids); - nm_key_file_db_to_file(priv->kf_db_timestamps, FALSE); - nm_key_file_db_to_file(priv->kf_db_seen_bssids, FALSE); + _kf_db_to_file(self, TRUE, FALSE); + _kf_db_to_file(self, FALSE, FALSE); nm_key_file_db_destroy(priv->kf_db_timestamps); nm_key_file_db_destroy(priv->kf_db_seen_bssids); @@ -4027,18 +4161,16 @@ static const NMDBusInterfaceInfoExtended interface_info_settings = { .in_args = NM_DEFINE_GDBUS_ARG_INFOS(NM_DEFINE_GDBUS_ARG_INFO("hostname", "s"), ), ), .handle = impl_settings_save_hostname, ), ), - .signals = NM_DEFINE_GDBUS_SIGNAL_INFOS(&nm_signal_info_property_changed_legacy, - &signal_info_new_connection, + .signals = NM_DEFINE_GDBUS_SIGNAL_INFOS(&signal_info_new_connection, &signal_info_connection_removed, ), .properties = NM_DEFINE_GDBUS_PROPERTY_INFOS( - NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE_L("Connections", - "ao", - NM_SETTINGS_CONNECTIONS), - NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE_L("Hostname", "s", NM_SETTINGS_HOSTNAME), - NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE_L("CanModify", - "b", - NM_SETTINGS_CAN_MODIFY), ), ), - .legacy_property_changed = TRUE, + NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE("Connections", + "ao", + NM_SETTINGS_CONNECTIONS), + NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE("Hostname", "s", NM_SETTINGS_HOSTNAME), + NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE("CanModify", + "b", + NM_SETTINGS_CAN_MODIFY), ), ), }; static void diff --git a/src/core/settings/nm-settings.h b/src/core/settings/nm-settings.h index 09a0af57..ce18fecc 100644 --- a/src/core/settings/nm-settings.h +++ b/src/core/settings/nm-settings.h @@ -79,6 +79,9 @@ void nm_settings_add_connection_dbus(NMSettings * self, NMSettingsConnection *const *nm_settings_get_connections(NMSettings *settings, guint *out_len); +NMSettingsConnection *const * +nm_settings_get_connections_sorted_by_autoconnect_priority(NMSettings *self, guint *out_len); + NMSettingsConnection **nm_settings_get_connections_clone(NMSettings * self, guint * out_len, NMSettingsConnectionFilterFunc func, @@ -127,4 +130,6 @@ const char *nm_settings_get_startup_complete_blocked_reason(NMSettings *self, void nm_settings_kf_db_write(NMSettings *settings); +void _nm_settings_notify_sorted_by_autoconnect_priority_maybe_changed(NMSettings *self); + #endif /* __NM_SETTINGS_H__ */ diff --git a/src/core/settings/plugins/ifcfg-rh/meson.build b/src/core/settings/plugins/ifcfg-rh/meson.build index a2f11a92..c62fa89d 100644 --- a/src/core/settings/plugins/ifcfg-rh/meson.build +++ b/src/core/settings/plugins/ifcfg-rh/meson.build @@ -28,7 +28,6 @@ libnms_ifcfg_rh_core = static_library( 'shvar.c', ), dependencies: core_default_dep, - c_args: daemon_c_flags, ) libnm_settings_plugin_ifcfg_rh = shared_module( @@ -38,7 +37,6 @@ libnm_settings_plugin_ifcfg_rh = shared_module( 'nms-ifcfg-rh-plugin.c', ), dependencies: core_plugin_dep, - c_args: daemon_c_flags, link_with: libnms_ifcfg_rh_core, link_args: ldflags_linker_script_settings, link_depends: linker_script_settings, diff --git a/src/core/settings/plugins/ifcfg-rh/nm-ifdown b/src/core/settings/plugins/ifcfg-rh/nm-ifdown old mode 100644 new mode 100755 index e7bd73ae..3b05ef1c --- a/src/core/settings/plugins/ifcfg-rh/nm-ifdown +++ b/src/core/settings/plugins/ifcfg-rh/nm-ifdown @@ -1,3 +1,44 @@ -#!/bin/sh -nmcli connection load "/etc/sysconfig/network-scripts/ifcfg-$1" && -exec nmcli connection down filename "/etc/sysconfig/network-scripts/ifcfg-$1" +#!/bin/bash + +CONFIG="$1" + +if [ -z "${CONFIG}" ] ; then + echo $"Usage: ifdown " >&2 + exit 1 +fi + +usage_and_fail() { + cat <&2 +$1! + +See all profiles with \`nmcli connection\`. +Reload files from disk with \`nmcli connection reload\` +Deactivate the desired profile with \`nmcli connection down \"\$NAME\"\` +EOF + exit 1 +} + +OLD_IFS="$IFS" + +re='^/etc/sysconfig/network-scripts/ifcfg-[^/]+$' +for f in "/etc/sysconfig/network-scripts/ifcfg-$CONFIG" "/etc/sysconfig/network-scripts/$CONFIG" ; do + [[ "$f" =~ $re ]] || continue + [ -f "$f" ] || continue + + nmcli connection load "$f" \ + && nmcli connection down filename "$f" \ + && exit 0 + + usage_and_fail "Failure to deactivate file \"$CONFIG\"" +done + +IFS=$'\n ' +APATHS=( $(nmcli -g GENERAL.DBUS-PATH connection show --active "$CONFIG" 2>/dev/null) ) +IFS="$OLD_IFS" +if [ "${#APATHS[@]}" -eq 1 ] ; then + nmcli connection down apath "${APATHS[0]}" \ + && exit 0 + usage_and_fail "Failure to deactivate profile \"$CONFIG\" (apath ${APATHS[@]})" +fi + +usage_and_fail "No suitable profile \"$CONFIG\" found" diff --git a/src/core/settings/plugins/ifcfg-rh/nm-ifup b/src/core/settings/plugins/ifcfg-rh/nm-ifup old mode 100644 new mode 100755 index 96637a92..6b32fe1b --- a/src/core/settings/plugins/ifcfg-rh/nm-ifup +++ b/src/core/settings/plugins/ifcfg-rh/nm-ifup @@ -1,3 +1,44 @@ -#!/bin/sh -nmcli connection load "/etc/sysconfig/network-scripts/ifcfg-$1" && -exec nmcli connection up filename "/etc/sysconfig/network-scripts/ifcfg-$1" +#!/bin/bash + +CONFIG="$1" + +if [ -z "${CONFIG}" ] ; then + echo $"Usage: ifup " >&2 + exit 1 +fi + +usage_and_fail() { + cat <&2 +$1! + +See all profiles with \`nmcli connection\`. +Reload files from disk with \`nmcli connection reload\` +Activate the desired profile with \`nmcli connection up \"\$NAME\"\` +EOF + exit 1 +} + +OLD_IFS="$IFS" + +re='^/etc/sysconfig/network-scripts/ifcfg-[^/]+$' +for f in "/etc/sysconfig/network-scripts/ifcfg-$CONFIG" "/etc/sysconfig/network-scripts/$CONFIG" ; do + [[ "$f" =~ $re ]] || continue + [ -f "$f" ] || continue + + nmcli connection load "$f" \ + && nmcli connection up filename "$f" \ + && exit 0 + + usage_and_fail "Failure to activate file \"$CONFIG\"" +done + +IFS=$'\n ' +UUIDS=( $(nmcli -g connection.uuid connection show "$CONFIG" 2>/dev/null) ) +IFS="$OLD_IFS" +if [ "${#UUIDS[@]}" -eq 1 ] ; then + nmcli connection up uuid "${UUIDS[0]}" \ + && exit 0 + usage_and_fail "Failure to activate profile \"$CONFIG\" (uuid ${UUIDS[0]})" +fi + +usage_and_fail "No suitable profile \"$CONFIG\" found" diff --git a/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-plugin.c b/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-plugin.c index d114db0f..5038ac6a 100644 --- a/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-plugin.c +++ b/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-plugin.c @@ -13,12 +13,12 @@ #include #include -#include "nm-std-aux/c-list-util.h" -#include "nm-glib-aux/nm-c-list.h" -#include "nm-glib-aux/nm-io-utils.h" -#include "nm-std-aux/nm-dbus-compat.h" +#include "libnm-std-aux/c-list-util.h" +#include "libnm-glib-aux/nm-c-list.h" +#include "libnm-glib-aux/nm-io-utils.h" +#include "libnm-std-aux/nm-dbus-compat.h" #include "nm-utils.h" -#include "nm-core-internal.h" +#include "libnm-core-intern/nm-core-internal.h" #include "nm-config.h" #include "nm-dbus-manager.h" #include "settings/nm-settings-plugin.h" diff --git a/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c b/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c index a42c4188..03b347f9 100644 --- a/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c +++ b/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c @@ -18,7 +18,8 @@ #include #include -#include "nm-glib-aux/nm-secret-utils.h" +#include "libnm-glib-aux/nm-uuid.h" +#include "libnm-glib-aux/nm-secret-utils.h" #include "nm-connection.h" #include "nm-dbus-interface.h" #include "nm-setting-connection.h" @@ -38,11 +39,11 @@ #include "nm-setting-user.h" #include "nm-setting-proxy.h" #include "nm-setting-generic.h" -#include "nm-core-internal.h" +#include "libnm-core-intern/nm-core-internal.h" #include "nm-utils.h" -#include "nm-base/nm-ethtool-base.h" +#include "libnm-base/nm-ethtool-base.h" -#include "platform/nm-platform.h" +#include "libnm-platform/nm-platform.h" #include "NetworkManagerUtils.h" #include "nms-ifcfg-rh-common.h" @@ -405,11 +406,9 @@ make_connection_setting(const char *file, /* Try for a UUID key before falling back to hashing the file name */ uuid = svGetValueStr(ifcfg, "UUID", &uuid_free); if (!uuid) { - uuid_free = nm_utils_uuid_generate_from_string(svFileGetName(ifcfg), - -1, - NM_UTILS_UUID_TYPE_LEGACY, - NULL); - uuid = uuid_free; + uuid_free = + nm_uuid_generate_from_string_str(svFileGetName(ifcfg), -1, NM_UUID_TYPE_LEGACY, NULL); + uuid = uuid_free; } g_object_set(s_con, @@ -1896,6 +1895,8 @@ make_ip4_setting(shvarFile *ifcfg, svGetValueBoolean(ifcfg, "DHCP_SEND_HOSTNAME", TRUE), NM_SETTING_IP_CONFIG_DHCP_TIMEOUT, (int) svGetValueInt64(ifcfg, "IPV4_DHCP_TIMEOUT", 10, 0, G_MAXINT32, 0), + NM_SETTING_IP_CONFIG_REQUIRED_TIMEOUT, + (int) svGetValueInt64(ifcfg, "IPV4_REQUIRED_TIMEOUT", 10, 0, G_MAXINT32, -1), NULL); nm_clear_g_free(&value); @@ -1986,7 +1987,11 @@ make_ip4_setting(shvarFile *ifcfg, } else if (nm_utils_ipaddr_is_valid(AF_INET6, v)) { /* Ignore IPv6 addresses */ } else { - PARSE_WARNING("invalid DNS server address %s", v); + g_set_error(error, + NM_SETTINGS_ERROR, + NM_SETTINGS_ERROR_INVALID_CONNECTION, + "Invalid DNS server address '%s'", + v); return NULL; } } @@ -2153,6 +2158,8 @@ read_aliases(NMSettingIPConfig *s_ip4, gboolean read_defroute, const char *filen continue; } + svWarnInvalid(parsed, "alias", _NMLOG_DOMAIN); + device = svGetValueStr(parsed, "DEVICE", &device_value); if (!device) { PARSE_WARNING("alias file '%s' has no DEVICE", full_path); @@ -2404,6 +2411,8 @@ make_ip6_setting(shvarFile *ifcfg, shvarFile *network_ifcfg, gboolean routes_rea svGetValueBoolean(ifcfg, "DHCPV6_SEND_HOSTNAME", TRUE), NM_SETTING_IP_CONFIG_DHCP_TIMEOUT, (int) svGetValueInt64(ifcfg, "IPV6_DHCP_TIMEOUT", 10, 0, G_MAXINT32, 0), + NM_SETTING_IP_CONFIG_REQUIRED_TIMEOUT, + (int) svGetValueInt64(ifcfg, "IPV6_REQUIRED_TIMEOUT", 10, 0, G_MAXINT32, -1), NM_SETTING_IP6_CONFIG_RA_TIMEOUT, (int) svGetValueInt64(ifcfg, "IPV6_RA_TIMEOUT", 10, 0, G_MAXINT32, 0), NULL); @@ -2505,7 +2514,11 @@ make_ip6_setting(shvarFile *ifcfg, shvarFile *network_ifcfg, gboolean routes_rea } else if (nm_utils_ipaddr_is_valid(AF_INET, v)) { /* Ignore IPv4 addresses */ } else { - PARSE_WARNING("invalid DNS server address %s", v); + g_set_error(error, + NM_SETTINGS_ERROR, + NM_SETTINGS_ERROR_INVALID_CONNECTION, + "Invalid DNS server address '%s'", + v); return NULL; } } @@ -4303,7 +4316,7 @@ make_wireless_setting(shvarFile *ifcfg, GError **error) bytes = g_bytes_new(value, value_len); ssid_len = g_bytes_get_size(bytes); - if (ssid_len > 32 || ssid_len == 0) { + if (ssid_len == 0 || ssid_len > NM_IW_ESSID_MAX_SIZE) { g_set_error(error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, @@ -4679,7 +4692,9 @@ static NM_UTILS_STRING_TABLE_LOOKUP_DEFINE( {"--coalesce", NM_ETHTOOL_TYPE_COALESCE}, {"--features", NM_ETHTOOL_TYPE_FEATURE}, {"--offload", NM_ETHTOOL_TYPE_FEATURE}, + {"--pause", NM_ETHTOOL_TYPE_PAUSE}, {"--set-ring", NM_ETHTOOL_TYPE_RING}, + {"-A", NM_ETHTOOL_TYPE_PAUSE}, {"-C", NM_ETHTOOL_TYPE_COALESCE}, {"-G", NM_ETHTOOL_TYPE_RING}, {"-K", NM_ETHTOOL_TYPE_FEATURE}, ); @@ -4719,7 +4734,7 @@ parse_ethtool_option(const char * value, w_iter = &words[2]; while (w_iter && *w_iter) { - if (ethtool_type == NM_ETHTOOL_TYPE_FEATURE) { + if (NM_IN_SET(ethtool_type, NM_ETHTOOL_TYPE_FEATURE, NM_ETHTOOL_TYPE_PAUSE)) { w_iter = _next_ethtool_options_nmternary(w_iter, ethtool_type, &ifcfg_option); if (ifcfg_option.has_value) { @@ -5022,6 +5037,7 @@ make_wired_setting(shvarFile *ifcfg, const char *file, NMSetting8021x **s_8021x, const char * cvalue; gs_free char * value = NULL; gboolean found = FALSE; + NMTernary accept_all_mac_addresses; s_wired = NM_SETTING_WIRED(nm_setting_wired_new()); @@ -5119,15 +5135,15 @@ make_wired_setting(shvarFile *ifcfg, const char *file, NMSetting8021x **s_8021x, for (i = 0; options && options[i]; i++) { const char *line = options[i]; const char *equals; - gboolean valid = FALSE; equals = strchr(line, '='); - if (equals) { - ((char *) equals)[0] = '\0'; - valid = nm_setting_wired_add_s390_option(s_wired, line, equals + 1); - } - if (!valid) - PARSE_WARNING("invalid s390 OPTION '%s'", line); + if (!equals) + continue; + + /* Here we don't verify the key/value further. If the file contains invalid keys, + * we will later reject the connection as invalid. */ + ((char *) equals)[0] = '\0'; + nm_setting_wired_add_s390_option(s_wired, line, equals + 1); } found = TRUE; } @@ -5180,6 +5196,15 @@ make_wired_setting(shvarFile *ifcfg, const char *file, NMSetting8021x **s_8021x, } nm_clear_g_free(&value); + accept_all_mac_addresses = svGetValueTernary(ifcfg, "ACCEPT_ALL_MAC_ADDRESSES"); + if (accept_all_mac_addresses != NM_TERNARY_DEFAULT) { + g_object_set(s_wired, + NM_SETTING_WIRED_ACCEPT_ALL_MAC_ADDRESSES, + accept_all_mac_addresses, + NULL); + found = TRUE; + } + if (!found) { g_set_error(error, NM_UTILS_ERROR, @@ -6072,15 +6097,14 @@ make_vlan_setting(shvarFile *ifcfg, const char *file, GError **error) v = iface_name + 4; } - if (v) { - int device_vlan_id; - - /* Grab VLAN ID from interface name; this takes precedence over the - * separate VLAN_ID property for backwards compat. + if (vlan_id == -1 && v) { + /* Grab VLAN ID from interface name; The explicit VLAN_ID option takes precedence + * over detecting the ID based on PHYSDEV. + * + * Note that older versions of NetworkManager had a bug and this would overwrite the + * VLAN_ID in this case. */ - device_vlan_id = _nm_utils_ascii_str_to_int64(v, 10, 0, 4095, -1); - if (device_vlan_id != -1) - vlan_id = device_vlan_id; + vlan_id = _nm_utils_ascii_str_to_int64(v, 10, 0, 4095, -1); } } @@ -6288,6 +6312,7 @@ connection_from_file_full(const char *filename, NMSetting * s_ip4; NMSetting * s_ip6; const char * ifcfg_name = NULL; + gs_free char * s_tmp = NULL; gboolean has_ip4_defroute = FALSE; gboolean has_complex_routes_v4; gboolean has_complex_routes_v6; @@ -6315,8 +6340,6 @@ connection_from_file_full(const char *filename, if (!main_ifcfg) return NULL; - network_ifcfg = svOpenFile(network_file, NULL); - if (!svGetValueBoolean(main_ifcfg, "NM_CONTROLLED", TRUE)) { connection = create_unhandled_connection(filename, main_ifcfg, "unmanaged", out_unhandled); if (!connection) { @@ -6330,6 +6353,16 @@ connection_from_file_full(const char *filename, return g_steal_pointer(&connection); } + if (NM_IN_STRSET(svGetValueStr(main_ifcfg, "DEVICE", &s_tmp), "lo")) { + /* "lo" is not handled by NetworkManager and we ignore it. */ + } else + svWarnInvalid(main_ifcfg, "ifcfg", _NMLOG_DOMAIN); + nm_clear_g_free(&s_tmp); + + network_ifcfg = svOpenFile(network_file, NULL); + /* we don't call svWarnInvalid(network_ifcfg), because we will load this file for + * every profile. So we would get a large number of duplicate warnings. */ + /* iBFT is handled by nm-initrd-generator during boot. */ bootproto = svGetValueStr_cp(main_ifcfg, "BOOTPROTO"); if (bootproto && !g_ascii_strcasecmp(bootproto, "ibft")) { diff --git a/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-storage.c b/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-storage.c index 3f674dea..134bdf68 100644 --- a/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-storage.c +++ b/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-storage.c @@ -7,8 +7,9 @@ #include "nms-ifcfg-rh-storage.h" +#include "libnm-glib-aux/nm-uuid.h" #include "nm-utils.h" -#include "nm-core-internal.h" +#include "libnm-core-intern/nm-core-internal.h" #include "nm-connection.h" #include "nms-ifcfg-rh-plugin.h" @@ -88,7 +89,7 @@ static NMSIfcfgRHStorage * _storage_new(NMSIfcfgRHPlugin *plugin, const char *uuid, const char *filename) { nm_assert(NMS_IS_IFCFG_RH_PLUGIN(plugin)); - nm_assert(!uuid || nm_utils_is_uuid(uuid)); + nm_assert(!uuid || nm_uuid_is_normalized(uuid)); nm_assert(filename && filename[0] == '/'); return g_object_new(NMS_TYPE_IFCFG_RH_STORAGE, diff --git a/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.c b/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.c index ada1942a..febfc120 100644 --- a/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.c +++ b/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.c @@ -9,7 +9,7 @@ #include -#include "nm-core-internal.h" +#include "libnm-core-intern/nm-core-internal.h" #include "NetworkManagerUtils.h" #include "nms-ifcfg-rh-common.h" @@ -593,6 +593,9 @@ const char *const _nm_ethtool_ifcfg_names[] = { ETHT_NAME(NM_ETHTOOL_ID_FEATURE_TX_UDP_TNL_CSUM_SEGMENTATION, "tx-udp_tnl-csum-segmentation"), ETHT_NAME(NM_ETHTOOL_ID_FEATURE_TX_UDP_TNL_SEGMENTATION, "tx-udp_tnl-segmentation"), ETHT_NAME(NM_ETHTOOL_ID_FEATURE_TX_VLAN_STAG_HW_INSERT, "tx-vlan-stag-hw-insert"), + ETHT_NAME(NM_ETHTOOL_ID_PAUSE_AUTONEG, "pause-autoneg"), + ETHT_NAME(NM_ETHTOOL_ID_PAUSE_RX, "pause-rx"), + ETHT_NAME(NM_ETHTOOL_ID_PAUSE_TX, "pause-tx"), ETHT_NAME(NM_ETHTOOL_ID_RING_RX, "rx"), ETHT_NAME(NM_ETHTOOL_ID_RING_RX_JUMBO, "rx-jumbo"), ETHT_NAME(NM_ETHTOOL_ID_RING_RX_MINI, "rx-mini"), @@ -722,6 +725,15 @@ static NM_UTILS_STRING_TABLE_LOOKUP_DEFINE( {"rx-mini", NM_ETHTOOL_ID_RING_RX_MINI}, {"tx", NM_ETHTOOL_ID_RING_TX}, ); +static NM_UTILS_STRING_TABLE_LOOKUP_DEFINE( + _get_ethtoolid_pause_by_name, + NMEthtoolID, + { nm_assert(name); }, + { return NM_ETHTOOL_ID_UNKNOWN; }, + {"pause-autoneg", NM_ETHTOOL_ID_PAUSE_AUTONEG}, + {"pause-rx", NM_ETHTOOL_ID_PAUSE_RX}, + {"pause-tx", NM_ETHTOOL_ID_PAUSE_TX}, ); + const NMEthtoolData * nms_ifcfg_rh_utils_get_ethtool_by_name(const char *name, NMEthtoolType ethtool_type) { @@ -737,6 +749,9 @@ nms_ifcfg_rh_utils_get_ethtool_by_name(const char *name, NMEthtoolType ethtool_t case NM_ETHTOOL_TYPE_RING: id = _get_ethtoolid_ring_by_name(name); break; + case NM_ETHTOOL_TYPE_PAUSE: + id = _get_ethtoolid_pause_by_name(name); + break; default: nm_assert_not_reached(); return NULL; @@ -800,6 +815,7 @@ nms_ifcfg_rh_utils_is_numbered_tag_impl(const char *key, } const NMSIfcfgKeyTypeInfo nms_ifcfg_well_known_keys[] = { + _KEY_TYPE("ACCEPT_ALL_MAC_ADDRESSES", NMS_IFCFG_KEY_TYPE_IS_PLAIN), _KEY_TYPE("ACD_TIMEOUT", NMS_IFCFG_KEY_TYPE_IS_PLAIN), _KEY_TYPE("ADDRESS", NMS_IFCFG_KEY_TYPE_IS_NUMBERED), _KEY_TYPE("AP_ISOLATION", NMS_IFCFG_KEY_TYPE_IS_PLAIN), @@ -942,6 +958,7 @@ const NMSIfcfgKeyTypeInfo nms_ifcfg_well_known_keys[] = { _KEY_TYPE("IPV4_DHCP_TIMEOUT", NMS_IFCFG_KEY_TYPE_IS_PLAIN), _KEY_TYPE("IPV4_DNS_PRIORITY", NMS_IFCFG_KEY_TYPE_IS_PLAIN), _KEY_TYPE("IPV4_FAILURE_FATAL", NMS_IFCFG_KEY_TYPE_IS_PLAIN), + _KEY_TYPE("IPV4_REQUIRED_TIMEOUT", NMS_IFCFG_KEY_TYPE_IS_PLAIN), _KEY_TYPE("IPV4_ROUTE_METRIC", NMS_IFCFG_KEY_TYPE_IS_PLAIN), _KEY_TYPE("IPV4_ROUTE_TABLE", NMS_IFCFG_KEY_TYPE_IS_PLAIN), _KEY_TYPE("IPV6ADDR", NMS_IFCFG_KEY_TYPE_IS_PLAIN), @@ -964,6 +981,7 @@ const NMSIfcfgKeyTypeInfo nms_ifcfg_well_known_keys[] = { _KEY_TYPE("IPV6_PRIVACY", NMS_IFCFG_KEY_TYPE_IS_PLAIN), _KEY_TYPE("IPV6_PRIVACY_PREFER_PUBLIC_IP", NMS_IFCFG_KEY_TYPE_IS_PLAIN), _KEY_TYPE("IPV6_RA_TIMEOUT", NMS_IFCFG_KEY_TYPE_IS_PLAIN), + _KEY_TYPE("IPV6_REQUIRED_TIMEOUT", NMS_IFCFG_KEY_TYPE_IS_PLAIN), _KEY_TYPE("IPV6_RES_OPTIONS", NMS_IFCFG_KEY_TYPE_IS_PLAIN), _KEY_TYPE("IPV6_ROUTE_METRIC", NMS_IFCFG_KEY_TYPE_IS_PLAIN), _KEY_TYPE("IPV6_ROUTE_TABLE", NMS_IFCFG_KEY_TYPE_IS_PLAIN), diff --git a/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.h b/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.h index 04a1b63d..b7751ec9 100644 --- a/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.h +++ b/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.h @@ -7,7 +7,7 @@ #define _UTILS_H_ #include "nm-connection.h" -#include "nm-base/nm-ethtool-base.h" +#include "libnm-base/nm-ethtool-base.h" #include "shvar.h" @@ -33,7 +33,7 @@ typedef struct { NMSIfcfgKeyTypeFlags key_flags; } NMSIfcfgKeyTypeInfo; -extern const NMSIfcfgKeyTypeInfo nms_ifcfg_well_known_keys[248]; +extern const NMSIfcfgKeyTypeInfo nms_ifcfg_well_known_keys[251]; const NMSIfcfgKeyTypeInfo *nms_ifcfg_well_known_key_find_info(const char *key, gssize *out_idx); diff --git a/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c b/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c index 45b76456..ef85b6bf 100644 --- a/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c +++ b/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c @@ -15,8 +15,9 @@ #include #include -#include "nm-glib-aux/nm-enum-utils.h" -#include "nm-glib-aux/nm-io-utils.h" +#include "libnm-glib-aux/nm-enum-utils.h" +#include "libnm-glib-aux/nm-str-buf.h" +#include "libnm-glib-aux/nm-io-utils.h" #include "nm-manager.h" #include "nm-setting-connection.h" #include "nm-setting-wired.h" @@ -32,9 +33,9 @@ #include "nm-setting-team.h" #include "nm-setting-team-port.h" #include "nm-utils.h" -#include "nm-core-internal.h" +#include "libnm-core-intern/nm-core-internal.h" #include "NetworkManagerUtils.h" -#include "nm-base/nm-ethtool-base.h" +#include "libnm-base/nm-ethtool-base.h" #include "nms-ifcfg-rh-common.h" #include "nms-ifcfg-rh-reader.h" @@ -203,18 +204,18 @@ write_object(NMSetting8021x * s_8021x, g_return_val_if_fail(ifcfg != NULL, FALSE); g_return_val_if_fail(objtype != NULL, FALSE); - scheme = (*(objtype->vtable->scheme_func))(s_8021x); + scheme = (*(objtype->vtable->scheme_func)) (s_8021x); switch (scheme) { case NM_SETTING_802_1X_CK_SCHEME_UNKNOWN: break; case NM_SETTING_802_1X_CK_SCHEME_BLOB: - blob = (*(objtype->vtable->blob_func))(s_8021x); + blob = (*(objtype->vtable->blob_func)) (s_8021x); break; case NM_SETTING_802_1X_CK_SCHEME_PATH: - value = (*(objtype->vtable->path_func))(s_8021x); + value = (*(objtype->vtable->path_func)) (s_8021x); break; case NM_SETTING_802_1X_CK_SCHEME_PKCS11: - value = (*(objtype->vtable->uri_func))(s_8021x); + value = (*(objtype->vtable->uri_func)) (s_8021x); break; default: g_set_error(error, @@ -227,8 +228,8 @@ write_object(NMSetting8021x * s_8021x, /* Set the password for certificate/private key. */ nm_sprintf_buf(secret_name, "%s_PASSWORD", objtype->ifcfg_rh_key); nm_sprintf_buf(secret_flags, "%s_PASSWORD_FLAGS", objtype->ifcfg_rh_key); - password = (*(objtype->vtable->passwd_func))(s_8021x); - flags = (*(objtype->vtable->pwflag_func))(s_8021x); + password = (*(objtype->vtable->passwd_func)) (s_8021x); + flags = (*(objtype->vtable->pwflag_func)) (s_8021x); set_secret(ifcfg, secrets, secret_name, password, secret_flags, flags); if (!objtype->vtable->format_func) @@ -299,6 +300,7 @@ write_blobs(GHashTable *blobs, GError **error) g_bytes_get_size(blob), 0600, NULL, + NULL, &write_error)) { g_set_error(error, NM_SETTINGS_ERROR, @@ -862,7 +864,7 @@ write_wireless_setting(NMConnection *connection, return FALSE; } ssid_data = g_bytes_get_data(ssid, &ssid_len); - if (!ssid_len || ssid_len > 32) { + if (ssid_len == 0 || ssid_len > NM_IW_ESSID_MAX_SIZE) { g_set_error(error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, @@ -903,9 +905,9 @@ write_wireless_setting(NMConnection *connection, svSetValueStr(ifcfg, "ESSID", str->str); g_string_free(str, TRUE); } else { - char buf[33]; + char buf[NM_IW_ESSID_MAX_SIZE + 1]; - nm_assert(ssid_len <= 32); + nm_assert(ssid_len <= NM_IW_ESSID_MAX_SIZE); memcpy(buf, ssid_data, ssid_len); buf[ssid_len] = '\0'; svSetValueStr(ifcfg, "ESSID", buf); @@ -1075,25 +1077,18 @@ write_hostname_setting(NMConnection *connection, shvarFile *ifcfg) svSetValueInt64_cond(ifcfg, "HOSTNAME_ONLY_FROM_DEFAULT", t != NM_TERNARY_DEFAULT, t); } -static gboolean -write_wired_setting(NMConnection *connection, shvarFile *ifcfg, GError **error) +static void +write_wired_setting_impl(NMSettingWired *s_wired, shvarFile *ifcfg, gboolean is_virtual) { - NMSettingWired * s_wired; const char *const *s390_subchannels; - guint32 mtu, num_opts, i; + guint32 mtu; + guint32 num_opts; + guint32 i; const char *const *macaddr_blacklist; - s_wired = nm_connection_get_setting_wired(connection); - if (!s_wired) { - g_set_error(error, - NM_SETTINGS_ERROR, - NM_SETTINGS_ERROR_FAILED, - "Missing '%s' setting", - NM_SETTING_WIRED_SETTING_NAME); - return FALSE; - } - - svSetValueStr(ifcfg, "HWADDR", nm_setting_wired_get_mac_address(s_wired)); + svSetValue(ifcfg, + "HWADDR", + nm_setting_wired_get_mac_address(s_wired) ?: (is_virtual ? "" : NULL)); svSetValueStr(ifcfg, "MACADDR", nm_setting_wired_get_cloned_mac_address(s_wired)); @@ -1167,8 +1162,42 @@ write_wired_setting(NMConnection *connection, shvarFile *ifcfg, GError **error) svSetValueStr(ifcfg, "OPTIONS", tmp->str); } + svSetValueTernary(ifcfg, + "ACCEPT_ALL_MAC_ADDRESSES", + nm_setting_wired_get_accept_all_mac_addresses(s_wired)); +} + +static gboolean +write_wired_setting(NMConnection *connection, shvarFile *ifcfg, GError **error) +{ + NMSettingWired *s_wired; + + s_wired = nm_connection_get_setting_wired(connection); + if (!s_wired) { + g_set_error(error, + NM_SETTINGS_ERROR, + NM_SETTINGS_ERROR_FAILED, + "Missing '%s' setting", + NM_SETTING_WIRED_SETTING_NAME); + return FALSE; + } + svSetValueStr(ifcfg, "TYPE", TYPE_ETHERNET); + write_wired_setting_impl(s_wired, ifcfg, FALSE); + return TRUE; +} + +static gboolean +write_wired_for_virtual(NMConnection *connection, shvarFile *ifcfg) +{ + NMSettingWired *s_wired; + + s_wired = nm_connection_get_setting_wired(connection); + if (!s_wired) + return FALSE; + + write_wired_setting_impl(s_wired, ifcfg, TRUE); return TRUE; } @@ -1334,6 +1363,26 @@ write_ethtool_setting(NMConnection *connection, shvarFile *ifcfg, GError **error g_string_append(str, nms_ifcfg_rh_utils_get_ethtool_name(ethtool_id)); g_string_append_printf(str, " %" G_GUINT32_FORMAT, u32); } + for (ethtool_id = _NM_ETHTOOL_ID_PAUSE_FIRST; ethtool_id <= _NM_ETHTOOL_ID_PAUSE_LAST; + ethtool_id++) { + nm_assert(nms_ifcfg_rh_utils_get_ethtool_name(ethtool_id)); + if (!nm_setting_option_get_boolean(NM_SETTING(s_ethtool), + nm_ethtool_data[ethtool_id]->optname, + &b)) + continue; + + _ethtool_gstring_prepare(&str, &is_first, 'A', iface); + g_string_append_c(str, ' '); + g_string_append(str, nms_ifcfg_rh_utils_get_ethtool_name(ethtool_id)); + g_string_append(str, b ? " on" : " off"); + } + + if (!str) { + /* Write an empty dummy "-A" option without arguments. This is to + * ensure that the reader will create an (all default) NMSettingEthtool. + * Also, it seems that `ethtool -A "$IFACE"` is silently accepted. */ + _ethtool_gstring_prepare(&str, &is_first, 'A', iface); + } } if (str) { @@ -1366,35 +1415,6 @@ vlan_priority_maplist_to_stringlist(NMSettingVlan *s_vlan, NMVlanPriorityMap map return value; } -static gboolean -write_wired_for_virtual(NMConnection *connection, shvarFile *ifcfg) -{ - NMSettingWired *s_wired; - gboolean has_wired = FALSE; - - s_wired = nm_connection_get_setting_wired(connection); - if (s_wired) { - const char *device_mac, *cloned_mac; - guint32 mtu; - - has_wired = TRUE; - - device_mac = nm_setting_wired_get_mac_address(s_wired); - svSetValue(ifcfg, "HWADDR", device_mac ?: ""); - - cloned_mac = nm_setting_wired_get_cloned_mac_address(s_wired); - svSetValueStr(ifcfg, "MACADDR", cloned_mac); - - svSetValueStr(ifcfg, - "GENERATE_MAC_ADDRESS_MASK", - nm_setting_wired_get_generate_mac_address_mask(s_wired)); - - mtu = nm_setting_wired_get_mtu(s_wired); - svSetValueInt64_cond(ifcfg, "MTU", mtu != 0, mtu); - } - return has_wired; -} - static gboolean write_vlan_setting(NMConnection *connection, shvarFile *ifcfg, gboolean *wired, GError **error) { @@ -1542,36 +1562,40 @@ write_team_setting(NMConnection *connection, shvarFile *ifcfg, gboolean *wired, static gboolean write_bridge_vlans(NMSetting * setting, - const char *property_name, + gboolean is_port, shvarFile * ifcfg, const char *key, GError ** error) { - gs_unref_ptrarray GPtrArray *vlans = NULL; - NMBridgeVlan * vlan; - GString * string; - guint i; + GPtrArray * vlans; + NMBridgeVlan * vlan; + nm_auto_str_buf NMStrBuf strbuf = NM_STR_BUF_INIT(0, FALSE); + guint i; - g_object_get(setting, property_name, &vlans, NULL); + if (is_port) + vlans = _nm_setting_bridge_port_get_vlans(NM_SETTING_BRIDGE_PORT(setting)); + else + vlans = _nm_setting_bridge_get_vlans(NM_SETTING_BRIDGE(setting)); if (!vlans || !vlans->len) return TRUE; - string = g_string_new(""); for (i = 0; i < vlans->len; i++) { gs_free char *vlan_str = NULL; vlan = vlans->pdata[i]; vlan_str = nm_bridge_vlan_to_str(vlan, error); - if (!vlan_str) - return FALSE; - if (string->len > 0) - g_string_append(string, ","); - nm_utils_escaped_tokens_escape_gstr_assert(vlan_str, ",", string); + if (!vlan_str) { + /* nm_bridge_vlan_to_str() cannot fail (for now). */ + nm_assert_not_reached(); + continue; + } + if (strbuf.len > 0) + nm_str_buf_append_c(&strbuf, ','); + nm_str_buf_append(&strbuf, nm_utils_escaped_tokens_escape_unnecessary(vlan_str, ",")); } - svSetValueStr(ifcfg, key, string->str); - g_string_free(string, TRUE); + svSetValueStr(ifcfg, key, nm_str_buf_get_str(&strbuf)); return TRUE; } @@ -1807,11 +1831,7 @@ write_bridge_setting(NMConnection *connection, shvarFile *ifcfg, gboolean *wired svSetValueStr(ifcfg, "BRIDGING_OPTS", opts->str); g_string_free(opts, TRUE); - if (!write_bridge_vlans((NMSetting *) s_bridge, - NM_SETTING_BRIDGE_VLANS, - ifcfg, - "BRIDGE_VLANS", - error)) + if (!write_bridge_vlans((NMSetting *) s_bridge, FALSE, ifcfg, "BRIDGE_VLANS", error)) return FALSE; svSetValueStr(ifcfg, "TYPE", TYPE_BRIDGE); @@ -1862,11 +1882,7 @@ write_bridge_port_setting(NMConnection *connection, shvarFile *ifcfg, GError **e svSetValueStr(ifcfg, "BRIDGING_OPTS", string->str); g_string_free(string, TRUE); - if (!write_bridge_vlans((NMSetting *) s_port, - NM_SETTING_BRIDGE_PORT_VLANS, - ifcfg, - "BRIDGE_PORT_VLANS", - error)) + if (!write_bridge_vlans((NMSetting *) s_port, TRUE, ifcfg, "BRIDGE_PORT_VLANS", error)) return FALSE; return TRUE; @@ -2824,6 +2840,9 @@ write_ip4_setting(NMConnection *connection, timeout = nm_setting_ip_config_get_dhcp_timeout(s_ip4); svSetValueInt64_cond(ifcfg, "IPV4_DHCP_TIMEOUT", timeout != 0, timeout); + timeout = nm_setting_ip_config_get_required_timeout(s_ip4); + svSetValueInt64_cond(ifcfg, "IPV4_REQUIRED_TIMEOUT", timeout != -1, timeout); + svSetValueBoolean(ifcfg, "IPV4_FAILURE_FATAL", !nm_setting_ip_config_get_may_fail(s_ip4)); route_metric = nm_setting_ip_config_get_route_metric(s_ip4); @@ -3021,6 +3040,9 @@ write_ip6_setting(NMConnection *connection, timeout = nm_setting_ip_config_get_dhcp_timeout(s_ip6); svSetValueInt64_cond(ifcfg, "IPV6_DHCP_TIMEOUT", timeout != 0, timeout); + timeout = nm_setting_ip_config_get_required_timeout(s_ip6); + svSetValueInt64_cond(ifcfg, "IPV6_REQUIRED_TIMEOUT", timeout != -1, timeout); + flags = nm_setting_ip_config_get_dhcp_hostname_flags(s_ip6); svSetValueInt64_cond(ifcfg, "DHCPV6_HOSTNAME_FLAGS", diff --git a/src/core/settings/plugins/ifcfg-rh/shvar.c b/src/core/settings/plugins/ifcfg-rh/shvar.c index 386bcac7..d82efb3c 100644 --- a/src/core/settings/plugins/ifcfg-rh/shvar.c +++ b/src/core/settings/plugins/ifcfg-rh/shvar.c @@ -14,10 +14,11 @@ #include #include -#include "nm-core-internal.h" +#include "libnm-glib-aux/nm-str-buf.h" +#include "libnm-core-intern/nm-core-internal.h" #include "nm-core-utils.h" -#include "nm-glib-aux/nm-enum-utils.h" -#include "nm-glib-aux/nm-io-utils.h" +#include "libnm-glib-aux/nm-enum-utils.h" +#include "libnm-glib-aux/nm-io-utils.h" #include "c-list/src/c-list.h" #include "nms-ifcfg-rh-utils.h" @@ -152,17 +153,42 @@ _escape_ansic(const char *source) const char *p; char * dest; char * q; + gsize n_alloc; nm_assert(source); - p = (const char *) source; - /* Each source byte needs maximally four destination chars (\777) */ - q = dest = g_malloc(strlen(source) * 4 + 1 + 3); + n_alloc = 4; + for (p = source; p[0]; p++) { + switch (*p) { + case '\b': + case '\f': + case '\n': + case '\r': + case '\t': + case '\v': + case '\\': + case '"': + case '\'': + n_alloc += 2; + break; + default: + if (!nm_ascii_is_regular(*p)) + n_alloc += 4; + else + n_alloc += 1; + break; + } + } + + dest = g_malloc(n_alloc); + + q = dest; *q++ = '$'; *q++ = '\''; - while (*p) { + for (p = source; p[0]; p++) { + nm_assert(q < &dest[n_alloc]); switch (*p) { case '\b': *q++ = '\\'; @@ -195,7 +221,7 @@ _escape_ansic(const char *source) *q++ = *p; break; default: - if ((*p < ' ') || (*p >= 0177)) { + if (!nm_ascii_is_regular(*p)) { *q++ = '\\'; *q++ = '0' + (((*p) >> 6) & 07); *q++ = '0' + (((*p) >> 3) & 07); @@ -204,12 +230,11 @@ _escape_ansic(const char *source) *q++ = *p; break; } - p++; } *q++ = '\''; *q++ = '\0'; - nm_assert(q - dest <= strlen(source) * 4 + 1 + 3); + nm_assert(q - dest == n_alloc); return dest; } @@ -217,7 +242,7 @@ _escape_ansic(const char *source) /*****************************************************************************/ #define _char_req_escape(ch) NM_IN_SET(ch, '"', '\\', '$', '`') -#define _char_req_escape_old(ch) NM_IN_SET(ch, '"', '\\', '\'', '$', '`', '~') +#define _char_req_escape_old(ch) NM_IN_SET(ch, '"', '\\', '$', '`', '\'', '~') #define _char_req_quotes(ch) NM_IN_SET(ch, ' ', '\'', '~', '\t', '|', '&', ';', '(', ')', '<', '>') const char * @@ -226,29 +251,48 @@ svEscape(const char *s, char **to_free) char *new; gsize mangle = 0; gboolean requires_quotes = FALSE; - int newlen; - size_t i, j, slen; + gsize n_alloc; + gsize slen; + gsize i; + gsize j; + gboolean all_ascii = TRUE; for (slen = 0; s[slen]; slen++) { if (_char_req_escape(s[slen])) mangle++; else if (_char_req_quotes(s[slen])) requires_quotes = TRUE; - else if (s[slen] < ' ') { - /* if the string contains newline we can only express it using ANSI C quotation - * (as we don't support line continuation). - * Additionally, ANSI control characters look odd with regular quotation, so handle - * them too. */ - return (*to_free = _escape_ansic(s)); + else if (!nm_ascii_is_regular(s[slen])) { + if (nm_ascii_is_ctrl_or_del(s[slen])) { + /* if the string contains newline we can only express it using ANSI C quotation + * (as we don't support line continuation). + * Additionally, ANSI control characters look odd with regular quotation, so handle + * them too. */ + return (*to_free = _escape_ansic(s)); + } + all_ascii = FALSE; + requires_quotes = TRUE; } } + + if (!all_ascii && !g_utf8_validate(s, -1, NULL)) { + /* The string is not valid ASCII/UTF-8. We can escape that via + * _escape_ansic(), however the reader might have a problem to + * do something sensible with the blob later. + * + * This is really a bug of the caller, which should not present us with + * non-text in the first place. But at this place, we cannot handle the + * error better, so just escape it. */ + return (*to_free = _escape_ansic(s)); + } + if (!mangle && !requires_quotes) { *to_free = NULL; return s; } - newlen = slen + mangle + 3; /* 3 is extra ""\0 */ - new = g_malloc(newlen); + n_alloc = slen + mangle + 3; /* 3 is extra ""\0 */ + new = g_malloc(n_alloc); j = 0; new[j++] = '"'; @@ -260,7 +304,7 @@ svEscape(const char *s, char **to_free) new[j++] = '"'; new[j++] = '\0'; - nm_assert(j == slen + mangle + 3); + nm_assert(j == n_alloc); *to_free = new; return new; @@ -318,14 +362,14 @@ _ch_hex_get(char ch) } static void -_gstr_init(GString **str, const char *value, gsize i) +_strbuf_init(NMStrBuf *str, const char *value, gsize i) { nm_assert(str); nm_assert(value); - if (!(*str)) { - /* if @str is not yet initialized, it allocates - * a new GString and copies @i characters from + if (str->allocated == 0) { + /* if @str is not yet initialized, it initializes + * a new NMStrBuf and copies @i characters from * @value over. * * Unescaping usually does not extend the length of a string, @@ -335,20 +379,26 @@ _gstr_init(GString **str, const char *value, gsize i) * (FACTOR*strlen(value) + CONST), which is non trivial to get * right in all cases. Also, we would have to provision for the * very unlikely extreme case. - * Instead, use a GString buffer which can grow as needed. But for an + * Instead, use a NMStrBuf buffer which can grow as needed. But for an * initial guess, strlen(value) is a good start */ - *str = g_string_new_len(NULL, strlen(value) + 3); - if (i) - g_string_append_len(*str, value, i); + nm_str_buf_maybe_expand(str, strlen(value) + 3u, FALSE); + nm_str_buf_append_len(str, value, i); } } const char * svUnescape(const char *value, char **to_free) { - gsize i, j; - GString *str = NULL; + return svUnescape_full(value, to_free, TRUE); +} + +const char * +svUnescape_full(const char *value, char **to_free, gboolean check_utf8) +{ + NMStrBuf str = NM_STR_BUF_INIT(0, FALSE); int looks_like_old_svescaped = -1; + gsize i; + gsize j; /* we handle bash syntax here (note that ifup has #!/bin/bash. * Thus, see https://www.gnu.org/software/bash/manual/html_node/Quoting.html#Quoting */ @@ -395,20 +445,20 @@ svUnescape(const char *value, char **to_free) if (value[i] == '\\') { /* backslash escape */ - _gstr_init(&str, value, i); + _strbuf_init(&str, value, i); i++; if (G_UNLIKELY(value[i] == '\0')) { /* we don't support line continuation */ goto out_error; } - g_string_append_c(str, value[i]); + nm_str_buf_append_c(&str, value[i]); i++; goto loop1_next; } if (value[i] == '\'') { /* single quotes */ - _gstr_init(&str, value, i); + _strbuf_init(&str, value, i); i++; j = i; while (TRUE) { @@ -420,14 +470,14 @@ svUnescape(const char *value, char **to_free) break; j++; } - g_string_append_len(str, &value[i], j - i); + nm_str_buf_append_len(&str, &value[i], j - i); i = j + 1; goto loop1_next; } if (value[i] == '"') { /* double quotes */ - _gstr_init(&str, value, i); + _strbuf_init(&str, value, i); i++; while (TRUE) { if (value[i] == '"') { @@ -466,11 +516,11 @@ svUnescape(const char *value, char **to_free) if (looks_like_old_svescaped < 0) looks_like_old_svescaped = _looks_like_old_svescaped(value); if (!looks_like_old_svescaped) - g_string_append_c(str, '\\'); + nm_str_buf_append_c(&str, '\\'); } else - g_string_append_c(str, '\\'); + nm_str_buf_append_c(&str, '\\'); } - g_string_append_c(str, value[i]); + nm_str_buf_append_c(&str, value[i]); i++; } goto loop1_next; @@ -478,7 +528,7 @@ svUnescape(const char *value, char **to_free) if (value[i] == '$' && value[i + 1] == '\'') { /* ANSI-C Quoting */ - _gstr_init(&str, value, i); + _strbuf_init(&str, value, i); i += 2; while (TRUE) { char ch; @@ -552,7 +602,7 @@ svUnescape(const char *value, char **to_free) } } /* like bash, we cut too large numbers off. E.g. A=$'\772' becomes 0xfa */ - g_string_append_c(str, (guint8) v); + nm_str_buf_append_c(&str, (guint8) v); } else if (NM_IN_SET(value[i], 'x', 'u', 'U')) { const char escape_type = value[i]; int max_digits = escape_type == 'x' ? 2 : escape_type == 'u' ? 4 : 8; @@ -561,8 +611,7 @@ svUnescape(const char *value, char **to_free) i++; if (!_ch_hex_is(value[i])) { /* missing hex value after "\x" escape. This is treated like no escaping. */ - g_string_append_c(str, '\\'); - g_string_append_c(str, escape_type); + nm_str_buf_append_c(&str, '\\', escape_type); } else { v = _ch_hex_get(value[i]); i++; @@ -574,22 +623,21 @@ svUnescape(const char *value, char **to_free) i++; } if (escape_type == 'x') - g_string_append_c(str, v); + nm_str_buf_append_c(&str, v); else { /* we treat the unicode escapes as utf-8 encoded values. */ - g_string_append_unichar(str, v); + nm_str_buf_append_unichar(&str, v); } } } else { - g_string_append_c(str, '\\'); - g_string_append_c(str, value[i]); + nm_str_buf_append_c(&str, '\\', value[i]); i++; } goto loop_ansic_next; } } else ch = value[i]; - g_string_append_c(str, ch); + nm_str_buf_append_c(&str, ch); i++; loop_ansic_next:; } @@ -603,8 +651,8 @@ loop_ansic_next:; } /* an unquoted, regular character. Just consume it directly. */ - if (str) - g_string_append_c(str, value[i]); + if (str.allocated > 0) + nm_str_buf_append_c(&str, value[i]); i++; loop1_next:; @@ -614,22 +662,30 @@ loop1_next:; out_value: if (i == 0) { - nm_assert(!str); + nm_assert(str.allocated == 0); + nm_assert(!str._priv_str); *to_free = NULL; return ""; } - if (str) { - if (str->len == 0 || str->str[0] == '\0') { - g_string_free(str, TRUE); + if (str.allocated > 0) { + if (check_utf8 && !nm_str_buf_utf8_validate(&str)) + goto out_error; + if (str.len == 0 || nm_str_buf_get_str_unsafe(&str)[0] == '\0') { + nm_str_buf_destroy(&str); *to_free = NULL; return ""; } else { - *to_free = g_string_free(str, FALSE); + *to_free = nm_str_buf_finalize(&str, NULL); return *to_free; } } + if (check_utf8 && !g_utf8_validate(value, i, NULL)) { + *to_free = NULL; + return NULL; + } + if (value[i] != '\0') { *to_free = g_strndup(value, i); return *to_free; @@ -639,8 +695,7 @@ out_value: return value; out_error: - if (str) - g_string_free(str, TRUE); + nm_str_buf_destroy(&str); *to_free = NULL; return NULL; } @@ -1095,9 +1150,8 @@ _svGetValue(shvarFile *s, const char *key, char **to_free) if (line && line->line) { v = svUnescape(line->line, to_free); if (!v) { - /* a wrongly quoted value is treated like the empty string. - * See also svWriteFile(), which handles unparsable values - * that way. */ + /* a wrongly quoted value or non-UTF-8 is treated like the empty string. + * See also svWriteFile(), which handles unparsable values that way. */ nm_assert(!*to_free); return ""; } @@ -1470,6 +1524,91 @@ svUnsetValue(shvarFile *s, const char *key) /*****************************************************************************/ +void +svWarnInvalid(shvarFile *s, const char *file_type, NMLogDomain log_domain) +{ + shvarLine *line; + gsize n; + + if (!nm_logging_enabled(LOGL_WARN, log_domain)) + return; + + n = 0; + c_list_for_each_entry (line, &s->lst_head, lst) { + gs_free char *s_tmp = NULL; + + n++; + + if (!line->key) { + const char *str; + + nm_assert(line->line); + str = nm_str_skip_leading_spaces(line->line); + if (!NM_IN_SET(str[0], '\0', '#')) { + nm_log_warn(log_domain, + "ifcfg-rh: %s,%s:%zu: invalid line ignored", + file_type, + s->fileName, + n); + } + continue; + } + + if (g_hash_table_lookup(s->lst_idx, line) != line) { + nm_log_warn( + log_domain, + "ifcfg-rh: %s,%s:%zu: key %s is duplicated and the early occurrence ignored", + file_type, + s->fileName, + n, + line->key); + continue; + } + + if (!line->line) { + /* the line is deleted via svUnsetValue(). Ignore. */ + continue; + } + + if (!svUnescape(line->line, &s_tmp)) { + if (!svUnescape_full(line->line, &s_tmp, FALSE)) { + nm_log_warn(log_domain, + "ifcfg-rh: %s,%s:%zu: key %s is badly quoted and is treated as \"\"", + file_type, + s->fileName, + n, + line->key); + } else { + nm_log_warn(log_domain, + "ifcfg-rh: %s,%s:%zu: key %s does not contain valid UTF-8 and is " + "treated as \"\"", + file_type, + s->fileName, + n, + line->key); + } + continue; + } + + /* TODO: we read different shell scripts, and whether a key is recognized + * depends on the type. For example, alias files only accept a subset of + * known keys. + * + * Basically, depending on the @file_type, different keys are valid. */ + if (!nms_ifcfg_rh_utils_is_well_known_key(line->key)) { + nm_log_dbg(log_domain, + "ifcfg-rh: %s,%s:%zu: key %s is unknown and ignored", + file_type, + s->fileName, + n, + line->key); + continue; + } + } +} + +/*****************************************************************************/ + /* Write the current contents iff modified. Returns FALSE on error * and TRUE on success. Do not write if no values have been modified. * The mode argument is only used if creating the file, not if diff --git a/src/core/settings/plugins/ifcfg-rh/shvar.h b/src/core/settings/plugins/ifcfg-rh/shvar.h index 6965d873..cf91642f 100644 --- a/src/core/settings/plugins/ifcfg-rh/shvar.h +++ b/src/core/settings/plugins/ifcfg-rh/shvar.h @@ -107,6 +107,7 @@ void svCloseFile(shvarFile *s); const char *svEscape(const char *s, char **to_free); const char *svUnescape(const char *s, char **to_free); +const char *svUnescape_full(const char *value, char **to_free, gboolean check_utf8); static inline void _nm_auto_shvar_file_close(shvarFile **p_s) @@ -120,4 +121,6 @@ _nm_auto_shvar_file_close(shvarFile **p_s) } #define nm_auto_shvar_file_close nm_auto(_nm_auto_shvar_file_close) +void svWarnInvalid(shvarFile *s, const char *file_type, NMLogDomain log_domain); + #endif /* _SHVAR_H */ diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-System_test-bridge-component-a.cexpected b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-System_test-bridge-component-a.cexpected index d81d9187..aebcd2b8 100644 --- a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-System_test-bridge-component-a.cexpected +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-System_test-bridge-component-a.cexpected @@ -1,5 +1,5 @@ -HWADDR=00:22:15:59:62:97 TYPE=Ethernet +HWADDR=00:22:15:59:62:97 BRIDGING_OPTS="priority=28 hairpin_mode=1" NAME="System test-bridge-component" UUID=${UUID} diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-System_test-bridge-component-b.cexpected b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-System_test-bridge-component-b.cexpected index 2e69c5e7..71d2cda8 100644 --- a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-System_test-bridge-component-b.cexpected +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-System_test-bridge-component-b.cexpected @@ -1,5 +1,5 @@ -HWADDR=00:22:15:59:62:97 TYPE=Ethernet +HWADDR=00:22:15:59:62:97 NAME="System test-bridge-component" UUID=${UUID} DEVICE=eth0 diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-System_test-wired-802-1X-subj-matches.cexpected b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-System_test-wired-802-1X-subj-matches.cexpected index 59a6f79b..240cd5c1 100644 --- a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-System_test-wired-802-1X-subj-matches.cexpected +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-System_test-wired-802-1X-subj-matches.cexpected @@ -1,5 +1,5 @@ -HWADDR=00:11:22:33:44:EE TYPE=Ethernet +HWADDR=00:11:22:33:44:EE KEY_MGMT=IEEE8021X IEEE_8021X_EAP_METHODS=PEAP IEEE_8021X_IDENTITY="Jara Cimrman" diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_Bridge_Component.cexpected b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_Bridge_Component.cexpected index a8ff8df3..d31d8ff5 100644 --- a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_Bridge_Component.cexpected +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_Bridge_Component.cexpected @@ -1,6 +1,6 @@ +TYPE=Ethernet HWADDR=31:33:33:37:BE:CD MTU=1492 -TYPE=Ethernet BRIDGING_OPTS="priority=50 path_cost=33" BRIDGE_PORT_VLANS="1 untagged,2 pvid,4-4094 untagged" NAME="Test Write Bridge Component" diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_Wired_Static_Routes.cexpected b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_Wired_Static_Routes.cexpected index cd8fc96f..cc29a2cc 100644 --- a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_Wired_Static_Routes.cexpected +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_Wired_Static_Routes.cexpected @@ -1,6 +1,6 @@ +TYPE=Ethernet HWADDR=31:33:33:37:BE:CD MTU=1492 -TYPE=Ethernet PROXY_METHOD=none BROWSER_ONLY=no BOOTPROTO=none diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-static-routes-legacy.cexpected b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-static-routes-legacy.cexpected index a28c5c1c..8197f320 100644 --- a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-static-routes-legacy.cexpected +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-static-routes-legacy.cexpected @@ -1,5 +1,5 @@ -HWADDR=00:16:41:11:22:33 TYPE=Ethernet +HWADDR=00:16:41:11:22:33 PROXY_METHOD=none BROWSER_ONLY=no BOOTPROTO=dhcp diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-vlan-vlanid-use b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-vlan-vlanid-use new file mode 100644 index 00000000..fc9c8a45 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-vlan-vlanid-use @@ -0,0 +1,4 @@ +VLAN=yes +TYPE=Vlan +DEVICE=eth0.9 +VLAN_ID=10 diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-vlan-vlanid-use.cexpected b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-vlan-vlanid-use.cexpected new file mode 100644 index 00000000..a7be14ce --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-vlan-vlanid-use.cexpected @@ -0,0 +1,15 @@ +VLAN=yes +TYPE=Vlan +PHYSDEV=eth0 +VLAN_ID=10 +REORDER_HDR=yes +GVRP=no +MVRP=no +HWADDR= +PROXY_METHOD=none +BROWSER_ONLY=no +IPV6INIT=no +NAME="Vlan test-vlan-vlanid-use" +UUID=${UUID} +DEVICE=eth0.9 +ONBOOT=yes diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-wpa-eap-suite-b-192-tls b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-wpa-eap-suite-b-192-tls index 9a74bb4d..a21c301c 100644 --- a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-wpa-eap-suite-b-192-tls +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-wpa-eap-suite-b-192-tls @@ -3,7 +3,6 @@ DEVICE=eth2 HWADDR=00:16:41:11:22:33 BOOTPROTO=dhcp ONBOOT=yes -ONBOOT=yes USERCTL=yes IPV6INIT=no NM_CONTROLLED=yes diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-wpa-eap-ttls-tls b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-wpa-eap-ttls-tls index 42ed1d68..bb63d5e8 100644 --- a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-wpa-eap-ttls-tls +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-wpa-eap-ttls-tls @@ -4,7 +4,6 @@ DEVICE=eth2 HWADDR=00:16:41:11:22:33 BOOTPROTO=dhcp ONBOOT=yes -ONBOOT=yes USERCTL=yes IPV6INIT=no NM_CONTROLLED=yes diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-4.expected b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-4.expected index 040ddc9d..92c03b12 100644 --- a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-4.expected +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-4.expected @@ -13,8 +13,10 @@ #L2 METRIC1='' -METRIC2=$'\U0x' -METRIC3=$'x\U0' +METRIC2= +#NM: METRIC2=$'\U0x' +METRIC3= +#NM: METRIC3=$'x\U0' #L4 IPADDR=set-by-test1 diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test_roundtrip_ethtool-1.cexpected b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test_roundtrip_ethtool-1.cexpected new file mode 100644 index 00000000..5186f90c --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test_roundtrip_ethtool-1.cexpected @@ -0,0 +1,14 @@ +TYPE=Ethernet +PROXY_METHOD=none +BROWSER_ONLY=no +BOOTPROTO=dhcp +DEFROUTE=yes +IPV4_FAILURE_FATAL=no +IPV6INIT=yes +IPV6_AUTOCONF=yes +IPV6_DEFROUTE=yes +IPV6_FAILURE_FATAL=no +IPV6_ADDR_GEN_MODE=stable-privacy +NAME=test_roundtrip_ethtool +UUID=${UUID} +ONBOOT=yes diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test_roundtrip_ethtool-2.cexpected b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test_roundtrip_ethtool-2.cexpected new file mode 100644 index 00000000..5632ebec --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test_roundtrip_ethtool-2.cexpected @@ -0,0 +1,15 @@ +TYPE=Ethernet +PROXY_METHOD=none +BROWSER_ONLY=no +ETHTOOL_OPTS="-A net0" +BOOTPROTO=dhcp +DEFROUTE=yes +IPV4_FAILURE_FATAL=no +IPV6INIT=yes +IPV6_AUTOCONF=yes +IPV6_DEFROUTE=yes +IPV6_FAILURE_FATAL=no +IPV6_ADDR_GEN_MODE=stable-privacy +NAME=test_roundtrip_ethtool +UUID=${UUID} +ONBOOT=yes diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test_roundtrip_ethtool-3.cexpected b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test_roundtrip_ethtool-3.cexpected new file mode 100644 index 00000000..96eec43b --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test_roundtrip_ethtool-3.cexpected @@ -0,0 +1,15 @@ +TYPE=Ethernet +PROXY_METHOD=none +BROWSER_ONLY=no +ETHTOOL_OPTS="autoneg on" +BOOTPROTO=dhcp +DEFROUTE=yes +IPV4_FAILURE_FATAL=no +IPV6INIT=yes +IPV6_AUTOCONF=yes +IPV6_DEFROUTE=yes +IPV6_FAILURE_FATAL=no +IPV6_ADDR_GEN_MODE=stable-privacy +NAME=test_roundtrip_ethtool +UUID=${UUID} +ONBOOT=yes diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test_roundtrip_ethtool-4.cexpected b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test_roundtrip_ethtool-4.cexpected new file mode 100644 index 00000000..90250a30 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test_roundtrip_ethtool-4.cexpected @@ -0,0 +1,15 @@ +TYPE=Ethernet +PROXY_METHOD=none +BROWSER_ONLY=no +ETHTOOL_OPTS="-K net0 rx on" +BOOTPROTO=dhcp +DEFROUTE=yes +IPV4_FAILURE_FATAL=no +IPV6INIT=yes +IPV6_AUTOCONF=yes +IPV6_DEFROUTE=yes +IPV6_FAILURE_FATAL=no +IPV6_ADDR_GEN_MODE=stable-privacy +NAME=test_roundtrip_ethtool +UUID=${UUID} +ONBOOT=yes diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test_roundtrip_ethtool-5.cexpected b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test_roundtrip_ethtool-5.cexpected new file mode 100644 index 00000000..721eacb2 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test_roundtrip_ethtool-5.cexpected @@ -0,0 +1,15 @@ +TYPE=Ethernet +PROXY_METHOD=none +BROWSER_ONLY=no +ETHTOOL_OPTS="autoneg on ; -K net0 rx on" +BOOTPROTO=dhcp +DEFROUTE=yes +IPV4_FAILURE_FATAL=no +IPV6INIT=yes +IPV6_AUTOCONF=yes +IPV6_DEFROUTE=yes +IPV6_FAILURE_FATAL=no +IPV6_ADDR_GEN_MODE=stable-privacy +NAME=test_roundtrip_ethtool +UUID=${UUID} +ONBOOT=yes diff --git a/src/core/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c b/src/core/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c index 9d9ed626..d9829f84 100644 --- a/src/core/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c +++ b/src/core/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c @@ -17,7 +17,8 @@ #include #include -#include "nm-glib-aux/nm-json-aux.h" +#include "libnm-glib-aux/nm-uuid.h" +#include "libnm-glib-aux/nm-json-aux.h" #include "nm-utils.h" #include "nm-setting-connection.h" #include "nm-setting-wired.h" @@ -36,9 +37,9 @@ #include "nm-setting-serial.h" #include "nm-setting-vlan.h" #include "nm-setting-dcb.h" -#include "nm-core-internal.h" -#include "nm-base/nm-ethtool-base.h" -#include "nm-base/nm-ethtool-utils-base.h" +#include "libnm-core-intern/nm-core-internal.h" +#include "libnm-base/nm-ethtool-base.h" +#include "libnm-base/nm-ethtool-utils-base.h" #include "NetworkManagerUtils.h" @@ -180,8 +181,20 @@ _assert_expected_content(NMConnection *connection, const char *filename, const c } if (len_expectd != len_written || memcmp(content_expectd, content_written, len_expectd) != 0) { - if (g_getenv("NMTST_IFCFG_RH_UPDATE_EXPECTED") - || nm_streq0(g_getenv("NM_TEST_REGENERATE"), "1")) { + static int rewrite_static = 0; + int rewrite; + + rewrite = g_atomic_int_get(&rewrite_static); + if (G_UNLIKELY(rewrite == 0)) { + rewrite = (g_getenv("NMTST_IFCFG_RH_UPDATE_EXPECTED") + || nm_streq0(g_getenv("NM_TEST_REGENERATE"), "1")) + ? 1 + : -1; + if (!g_atomic_int_compare_and_exchange(&rewrite_static, 0, rewrite)) + g_assert_not_reached(); + } + + if (rewrite > 0) { if (uuid) { gs_free char *search = g_strdup_printf("UUID=%s\n", uuid); const char * s; @@ -209,15 +222,16 @@ _assert_expected_content(NMConnection *connection, const char *filename, const c success = g_file_set_contents(expected, content_written, len_written, &error); nmtst_assert_success(success, error); } else { - g_error("The content of \"%s\" (%zu) differs from \"%s\" (%zu). Set " - "NMTST_IFCFG_RH_UPDATE_EXPECTED=yes to update the files " - "inplace\n\n>>>%s<<<\n\n>>>%s<<<\n", - filename, - len_written, - expected, - len_expectd, - content_written, - content_expectd); + g_error( + "The content of \"%s\" (%zu) differs from \"%s\" (%zu). Set " + "NMTST_IFCFG_RH_UPDATE_EXPECTED=yes (or NM_TEST_REGENERATE=1) to update the files " + "inplace\n\n>>>%s<<<\n\n>>>%s<<<\n", + filename, + len_written, + expected, + len_expectd, + content_written, + content_expectd); } } } @@ -359,8 +373,10 @@ _writer_new_connection_reread(NMConnection * connection, if (out_filename) *out_filename = filename; - else + else { + nmtst_file_unlink(filename); g_free(filename); + } } static void @@ -722,10 +738,13 @@ test_read_variables_corner_cases(void) const char * mac; char expected_mac_address[ETH_ALEN] = {0x00, 0x16, 0x41, 0x11, 0x22, 0x33}; + NMTST_EXPECT_NM_WARN("*key NAME is badly quoted and is treated as \"\"*"); + NMTST_EXPECT_NM_WARN("*key ZONE is badly quoted and is treated as \"\"*"); connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-variables-corner-cases-1", NULL, TYPE_ETHERNET, NULL); + g_test_assert_expected_messages(); /* ===== CONNECTION SETTING ===== */ s_con = nm_connection_get_setting_connection(connection); @@ -814,10 +833,12 @@ test_read_unrecognized(void) gs_free char * unhandled_spec = NULL; guint64 expected_timestamp = 0; + NMTST_EXPECT_NM_WARN("*key NAME is badly quoted and is treated as \"\"*"); connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-unrecognized", NULL, NULL, &unhandled_spec); + g_test_assert_expected_messages(); g_assert_cmpstr(unhandled_spec, ==, "unrecognized:mac:00:11:22:33"); /* ===== CONNECTION SETTING ===== */ @@ -988,10 +1009,12 @@ test_read_wired_dhcp(void) char expected_mac_address[ETH_ALEN] = {0x00, 0x11, 0x22, 0x33, 0x44, 0xee}; const char * mac; + NMTST_EXPECT_NM_WARN("*key IPV6INIT is duplicated and the early occurrence ignored*"); connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wired-dhcp", NULL, TYPE_ETHERNET, &unmanaged); + g_test_assert_expected_messages(); g_assert(unmanaged == NULL); /* ===== CONNECTION SETTING ===== */ @@ -2519,7 +2542,7 @@ test_write_dns_options(void) NM_SETTING_CONNECTION_ID, "Test DNS options", NM_SETTING_CONNECTION_UUID, - nm_utils_uuid_generate_a(), + nm_uuid_generate_random_str_a(), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, @@ -3567,10 +3590,12 @@ test_read_wifi_wpa_eap_tls(void) char * unmanaged = NULL; const char * expected_privkey_password = "test1"; + NMTST_EXPECT_NM_WARN("*key ONBOOT is duplicated and the early occurrence ignored*"); connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wifi-wpa-eap-tls", NULL, TYPE_ETHERNET, &unmanaged); + g_test_assert_expected_messages(); g_assert(!unmanaged); /* ===== WIRELESS SETTING ===== */ @@ -3775,10 +3800,12 @@ test_read_wifi_wep_eap_ttls_chap(void) NMSetting8021x * s_8021x; char * unmanaged = NULL; + NMTST_EXPECT_NM_WARN("*key ONBOOT is duplicated and the early occurrence ignored*"); connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wifi-wep-eap-ttls-chap", NULL, TYPE_WIRELESS, &unmanaged); + g_test_assert_expected_messages(); g_assert(!unmanaged); /* ===== WIRELESS SETTING ===== */ @@ -3932,6 +3959,76 @@ test_read_wired_unknown_ethtool_opt(void) g_assert_cmpstr(nm_setting_wired_get_wake_on_lan_password(s_wired), ==, "00:11:22:33:44:55"); } +static void +test_roundtrip_ethtool(void) +{ + gs_unref_object NMConnection *connection = NULL; + NMSetting * s_ethtool; + NMSetting * s_wired; + + connection = nmtst_create_minimal_connection("test_roundtrip_ethtool", + NULL, + NM_SETTING_WIRED_SETTING_NAME, + NULL); + _writer_new_connec_exp(connection, + TEST_SCRATCH_DIR, + TEST_IFCFG_DIR "/ifcfg-test_roundtrip_ethtool-1.cexpected", + NULL); + g_clear_object(&connection); + + connection = nmtst_create_minimal_connection("test_roundtrip_ethtool", + NULL, + NM_SETTING_WIRED_SETTING_NAME, + NULL); + s_ethtool = nm_setting_ethtool_new(); + nm_connection_add_setting(connection, s_ethtool); + _writer_new_connec_exp(connection, + TEST_SCRATCH_DIR, + TEST_IFCFG_DIR "/ifcfg-test_roundtrip_ethtool-2.cexpected", + NULL); + g_clear_object(&connection); + + connection = nmtst_create_minimal_connection("test_roundtrip_ethtool", + NULL, + NM_SETTING_WIRED_SETTING_NAME, + NULL); + s_wired = nm_connection_get_setting(connection, NM_TYPE_SETTING_WIRED); + g_object_set(s_wired, NM_SETTING_WIRED_AUTO_NEGOTIATE, TRUE, NULL); + _writer_new_connec_exp(connection, + TEST_SCRATCH_DIR, + TEST_IFCFG_DIR "/ifcfg-test_roundtrip_ethtool-3.cexpected", + NULL); + g_clear_object(&connection); + + connection = nmtst_create_minimal_connection("test_roundtrip_ethtool", + NULL, + NM_SETTING_WIRED_SETTING_NAME, + NULL); + s_ethtool = nm_setting_ethtool_new(); + nm_connection_add_setting(connection, s_ethtool); + nm_setting_option_set_boolean(s_ethtool, NM_ETHTOOL_OPTNAME_FEATURE_RX, TRUE); + _writer_new_connec_exp(connection, + TEST_SCRATCH_DIR, + TEST_IFCFG_DIR "/ifcfg-test_roundtrip_ethtool-4.cexpected", + NULL); + g_clear_object(&connection); + + connection = nmtst_create_minimal_connection("test_roundtrip_ethtool", + NULL, + NM_SETTING_WIRED_SETTING_NAME, + NULL); + s_wired = nm_connection_get_setting(connection, NM_TYPE_SETTING_WIRED); + g_object_set(s_wired, NM_SETTING_WIRED_AUTO_NEGOTIATE, TRUE, NULL); + s_ethtool = nm_setting_ethtool_new(); + nm_connection_add_setting(connection, s_ethtool); + nm_setting_option_set_boolean(s_ethtool, NM_ETHTOOL_OPTNAME_FEATURE_RX, TRUE); + _writer_new_connec_exp(connection, + TEST_SCRATCH_DIR, + TEST_IFCFG_DIR "/ifcfg-test_roundtrip_ethtool-5.cexpected", + NULL); + g_clear_object(&connection); +} + static void test_read_wifi_hidden(void) { @@ -3977,7 +4074,7 @@ test_write_wifi_hidden(void) NM_SETTING_CONNECTION_ID, "Test Write Wi-Fi Hidden", NM_SETTING_CONNECTION_UUID, - nm_utils_uuid_generate_a(), + nm_uuid_generate_random_str_a(), NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRELESS_SETTING_NAME, NULL); @@ -4062,7 +4159,7 @@ test_write_wifi_mac_random(gconstpointer user_data) NM_SETTING_CONNECTION_ID, val, NM_SETTING_CONNECTION_UUID, - nm_utils_uuid_generate_a(), + nm_uuid_generate_random_str_a(), NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRELESS_SETTING_NAME, NULL); @@ -4122,7 +4219,7 @@ test_write_wired_wake_on_lan(void) NM_SETTING_CONNECTION_ID, "Test Write Wired Wake-on-LAN", NM_SETTING_CONNECTION_UUID, - nm_utils_uuid_generate_a(), + nm_uuid_generate_random_str_a(), NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRED_SETTING_NAME, NULL); @@ -4305,7 +4402,7 @@ test_write_wifi_band_a(void) NM_SETTING_CONNECTION_ID, "Test Write Wi-Fi Band A", NM_SETTING_CONNECTION_UUID, - nm_utils_uuid_generate_a(), + nm_uuid_generate_random_str_a(), NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRELESS_SETTING_NAME, NULL); @@ -4363,7 +4460,7 @@ test_write_wifi_ap_mode(void) NM_SETTING_CONNECTION_ID, "Test Write Wi-Fi AP Mode", NM_SETTING_CONNECTION_UUID, - nm_utils_uuid_generate_a(), + nm_uuid_generate_random_str_a(), NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRELESS_SETTING_NAME, NULL); @@ -4676,7 +4773,7 @@ test_write_wired_static(void) NM_SETTING_CONNECTION_ID, "Test Write Wired Static", NM_SETTING_CONNECTION_UUID, - nm_utils_uuid_generate_a(), + nm_uuid_generate_random_str_a(), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_AUTOCONNECT_RETRIES, @@ -4831,7 +4928,7 @@ test_write_wired_static_with_generic(void) NM_SETTING_CONNECTION_ID, "Test Write Wired Static", NM_SETTING_CONNECTION_UUID, - nm_utils_uuid_generate_a(), + nm_uuid_generate_random_str_a(), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_AUTOCONNECT_RETRIES, @@ -4999,7 +5096,7 @@ test_write_wired_dhcp(void) NM_SETTING_CONNECTION_ID, "Test Write Wired DHCP", NM_SETTING_CONNECTION_UUID, - nm_utils_uuid_generate_a(), + nm_uuid_generate_random_str_a(), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, @@ -5111,7 +5208,7 @@ test_write_routing_rules(void) NM_SETTING_CONNECTION_ID, "Test Write Routing Rules", NM_SETTING_CONNECTION_UUID, - nm_utils_uuid_generate_a(), + nm_uuid_generate_random_str_a(), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, @@ -5169,7 +5266,7 @@ test_write_wired_match(void) NM_SETTING_CONNECTION_ID, "Test Write Wired with Match setting", NM_SETTING_CONNECTION_UUID, - nm_utils_uuid_generate_a(), + nm_uuid_generate_random_str_a(), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, @@ -5315,7 +5412,7 @@ test_write_wired_static_ip6_only(void) NM_SETTING_CONNECTION_ID, "Test Write Wired Static IP6 Only", NM_SETTING_CONNECTION_UUID, - nm_utils_uuid_generate_a(), + nm_uuid_generate_random_str_a(), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, @@ -5432,7 +5529,7 @@ test_write_wired_static_ip6_only_gw(gconstpointer user_data) NM_SETTING_CONNECTION_ID, id, NM_SETTING_CONNECTION_UUID, - nm_utils_uuid_generate_a(), + nm_uuid_generate_random_str_a(), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, @@ -5587,7 +5684,7 @@ test_write_wired_static_routes(void) NM_SETTING_CONNECTION_ID, "Test Write Wired Static Routes", NM_SETTING_CONNECTION_UUID, - nm_utils_uuid_generate_a(), + nm_uuid_generate_random_str_a(), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, @@ -5711,7 +5808,7 @@ test_write_wired_dhcp_8021x_peap_mschapv2(void) NM_SETTING_CONNECTION_ID, "Test Write Wired DHCP 802.1x PEAP MSCHAPv2", NM_SETTING_CONNECTION_UUID, - nm_utils_uuid_generate_a(), + nm_uuid_generate_random_str_a(), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, @@ -5813,7 +5910,7 @@ test_write_wired_8021x_tls(gconstpointer test_data) NM_SETTING_CONNECTION_ID, "Test Write Wired 802.1x TLS Blobs", NM_SETTING_CONNECTION_UUID, - nm_utils_uuid_generate_a(), + nm_uuid_generate_random_str_a(), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, @@ -5983,7 +6080,7 @@ test_write_wired_aliases(void) NM_SETTING_CONNECTION_ID, "alias0", NM_SETTING_CONNECTION_UUID, - nm_utils_uuid_generate_a(), + nm_uuid_generate_random_str_a(), NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRED_SETTING_NAME, NULL); @@ -6110,7 +6207,7 @@ test_write_gateway(void) NM_SETTING_CONNECTION_ID, "Test Write Static Addresses Gateway", NM_SETTING_CONNECTION_UUID, - nm_utils_uuid_generate_a(), + nm_uuid_generate_random_str_a(), NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRED_SETTING_NAME, NULL); @@ -6187,7 +6284,7 @@ test_write_wifi_open(void) NM_SETTING_CONNECTION_ID, "Test Write Wifi Open", NM_SETTING_CONNECTION_UUID, - nm_utils_uuid_generate_a(), + nm_uuid_generate_random_str_a(), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, @@ -6273,7 +6370,7 @@ test_write_wifi_open_hex_ssid(void) NM_SETTING_CONNECTION_ID, "Test Write Wifi Open Hex SSID", NM_SETTING_CONNECTION_UUID, - nm_utils_uuid_generate_a(), + nm_uuid_generate_random_str_a(), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, @@ -6347,7 +6444,7 @@ test_write_wifi_wep(void) NM_SETTING_CONNECTION_ID, "Test Write Wifi WEP", NM_SETTING_CONNECTION_UUID, - nm_utils_uuid_generate_a(), + nm_uuid_generate_random_str_a(), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, @@ -6445,7 +6542,7 @@ test_write_wifi_wep_adhoc(void) NM_SETTING_CONNECTION_ID, "Test Write Wifi WEP AdHoc", NM_SETTING_CONNECTION_UUID, - nm_utils_uuid_generate_a(), + nm_uuid_generate_random_str_a(), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, @@ -6539,7 +6636,7 @@ test_write_wifi_wep_passphrase(void) NM_SETTING_CONNECTION_ID, "Test Write Wifi WEP Passphrase", NM_SETTING_CONNECTION_UUID, - nm_utils_uuid_generate_a(), + nm_uuid_generate_random_str_a(), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, @@ -6634,7 +6731,7 @@ test_write_wifi_wep_40_ascii(void) NM_SETTING_CONNECTION_ID, "Test Write Wifi WEP 40 ASCII", NM_SETTING_CONNECTION_UUID, - nm_utils_uuid_generate_a(), + nm_uuid_generate_random_str_a(), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, @@ -6732,7 +6829,7 @@ test_write_wifi_wep_104_ascii(void) NM_SETTING_CONNECTION_ID, "Test Write Wifi WEP 104 ASCII", NM_SETTING_CONNECTION_UUID, - nm_utils_uuid_generate_a(), + nm_uuid_generate_random_str_a(), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, @@ -6833,7 +6930,7 @@ test_write_wifi_leap(void) NM_SETTING_CONNECTION_ID, "Test Write Wifi LEAP", NM_SETTING_CONNECTION_UUID, - nm_utils_uuid_generate_a(), + nm_uuid_generate_random_str_a(), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, @@ -6931,7 +7028,7 @@ test_write_wifi_leap_secret_flags(gconstpointer data) NM_SETTING_CONNECTION_ID, "Test Write Wifi LEAP Secret Flags", NM_SETTING_CONNECTION_UUID, - nm_utils_uuid_generate_a(), + nm_uuid_generate_random_str_a(), NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRELESS_SETTING_NAME, NULL); @@ -7037,7 +7134,7 @@ test_write_wifi_wpa_psk(gconstpointer test_data) NM_SETTING_CONNECTION_ID, args.name, NM_SETTING_CONNECTION_UUID, - nm_utils_uuid_generate_a(), + nm_uuid_generate_random_str_a(), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, @@ -7142,7 +7239,7 @@ test_write_wifi_wpa_psk_adhoc(void) NM_SETTING_CONNECTION_ID, "Test Write Wifi WPA PSK", NM_SETTING_CONNECTION_UUID, - nm_utils_uuid_generate_a(), + nm_uuid_generate_random_str_a(), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, @@ -7252,7 +7349,7 @@ test_write_wifi_wpa_eap_tls(void) NM_SETTING_CONNECTION_ID, "Test Write Wifi WPA EAP-TLS", NM_SETTING_CONNECTION_UUID, - nm_utils_uuid_generate_a(), + nm_uuid_generate_random_str_a(), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, @@ -7295,8 +7392,8 @@ test_write_wifi_wpa_eap_tls(void) g_object_set(s_8021x, NM_SETTING_802_1X_IDENTITY, "Bill Smith", NULL); g_object_set(s_8021x, NM_SETTING_802_1X_PHASE1_AUTH_FLAGS, - (guint)(NM_SETTING_802_1X_AUTH_FLAGS_TLS_1_0_DISABLE - | NM_SETTING_802_1X_AUTH_FLAGS_TLS_1_1_DISABLE), + (guint) (NM_SETTING_802_1X_AUTH_FLAGS_TLS_1_0_DISABLE + | NM_SETTING_802_1X_AUTH_FLAGS_TLS_1_1_DISABLE), NULL); nm_setting_802_1x_add_eap_method(s_8021x, "tls"); @@ -7379,7 +7476,7 @@ test_write_wifi_wpa_eap_ttls_tls(void) NM_SETTING_CONNECTION_ID, "Test Write Wifi WPA EAP-TTLS (TLS)", NM_SETTING_CONNECTION_UUID, - nm_utils_uuid_generate_a(), + nm_uuid_generate_random_str_a(), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, @@ -7515,7 +7612,7 @@ test_write_wifi_wpa_eap_ttls_mschapv2(void) NM_SETTING_CONNECTION_ID, "Test Write Wifi WPA EAP-TTLS (MSCHAPv2)", NM_SETTING_CONNECTION_UUID, - nm_utils_uuid_generate_a(), + nm_uuid_generate_random_str_a(), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, @@ -7630,7 +7727,7 @@ test_write_wifi_wpa_then_open(void) NM_SETTING_CONNECTION_ID, "random wifi connection", NM_SETTING_CONNECTION_UUID, - nm_utils_uuid_generate_a(), + nm_uuid_generate_random_str_a(), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, @@ -7747,7 +7844,7 @@ test_write_wifi_wpa_then_wep_with_perms(void) NM_SETTING_CONNECTION_ID, "random wifi connection 2", NM_SETTING_CONNECTION_UUID, - nm_utils_uuid_generate_a(), + nm_uuid_generate_random_str_a(), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_PERMISSIONS, @@ -7872,7 +7969,7 @@ test_write_wifi_dynamic_wep_leap(void) NM_SETTING_CONNECTION_ID, "Test Write Wifi Dynamic WEP LEAP", NM_SETTING_CONNECTION_UUID, - nm_utils_uuid_generate_a(), + nm_uuid_generate_random_str_a(), NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRELESS_SETTING_NAME, NULL); @@ -7969,7 +8066,7 @@ test_write_wired_qeth_dhcp(void) NM_SETTING_CONNECTION_ID, "Test Write Wired qeth Static", NM_SETTING_CONNECTION_UUID, - nm_utils_uuid_generate_a(), + nm_uuid_generate_random_str_a(), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, @@ -8043,7 +8140,7 @@ test_write_wired_ctc_dhcp(void) NM_SETTING_CONNECTION_ID, "Test Write Wired ctc Static", NM_SETTING_CONNECTION_UUID, - nm_utils_uuid_generate_a(), + nm_uuid_generate_random_str_a(), NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRED_SETTING_NAME, NULL); @@ -8118,7 +8215,7 @@ test_write_permissions(void) NM_SETTING_CONNECTION_ID, "Test Write Permissions", NM_SETTING_CONNECTION_UUID, - nm_utils_uuid_generate_a(), + nm_uuid_generate_random_str_a(), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, @@ -8187,7 +8284,7 @@ test_write_wifi_wep_agent_keys(void) NM_SETTING_CONNECTION_ID, "Test Write Wifi WEP Agent Owned", NM_SETTING_CONNECTION_UUID, - nm_utils_uuid_generate_a(), + nm_uuid_generate_random_str_a(), NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRELESS_SETTING_NAME, NULL); @@ -8273,7 +8370,7 @@ test_write_wired_pppoe(void) NM_SETTING_CONNECTION_ID, "Test Write Wired PPPoE", NM_SETTING_CONNECTION_UUID, - nm_utils_uuid_generate_a(), + nm_uuid_generate_random_str_a(), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, @@ -8334,7 +8431,7 @@ test_write_vpn(void) NM_SETTING_CONNECTION_ID, "Test Write VPN", NM_SETTING_CONNECTION_UUID, - nm_utils_uuid_generate_a(), + nm_uuid_generate_random_str_a(), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, @@ -8392,7 +8489,7 @@ test_write_mobile_broadband(gconstpointer data) NM_SETTING_CONNECTION_ID, gsm ? "Test Write GSM" : "Test Write CDMA", NM_SETTING_CONNECTION_UUID, - nm_utils_uuid_generate_a(), + nm_uuid_generate_random_str_a(), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, @@ -8510,7 +8607,7 @@ test_write_bridge_main(void) NM_SETTING_CONNECTION_ID, "Test Write Bridge Main", NM_SETTING_CONNECTION_UUID, - nm_utils_uuid_generate_a(), + nm_uuid_generate_random_str_a(), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_INTERFACE_NAME, @@ -8639,7 +8736,7 @@ test_write_bridge_component(void) NM_SETTING_CONNECTION_ID, "Test Write Bridge Component", NM_SETTING_CONNECTION_UUID, - nm_utils_uuid_generate_a(), + nm_uuid_generate_random_str_a(), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, @@ -8786,6 +8883,38 @@ test_read_vlan_only_vlan_id(void) g_object_unref(connection); } +static void +test_read_vlan_vlanid_use(void) +{ + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; + NMSettingVlan * s_vlan; + + connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-vlan-vlanid-use", + NULL, + TYPE_ETHERNET, + NULL); + + g_assert_cmpstr(nm_connection_get_interface_name(connection), ==, "eth0.9"); + + s_vlan = nm_connection_get_setting_vlan(connection); + g_assert(s_vlan); + + g_assert_cmpstr(nm_setting_vlan_get_parent(s_vlan), ==, "eth0"); + g_assert_cmpint(nm_setting_vlan_get_id(s_vlan), ==, 10); + g_assert_cmpint(nm_setting_vlan_get_flags(s_vlan), ==, NM_VLAN_FLAG_REORDER_HEADERS); + + _writer_new_connec_exp(connection, + TEST_SCRATCH_DIR, + TEST_IFCFG_DIR "/ifcfg-test-vlan-vlanid-use.cexpected", + &testfile); + + reread = _connection_from_file(testfile, NULL, TYPE_ETHERNET, NULL); + + nmtst_assert_connection_equals(connection, TRUE, reread, FALSE); +} + static void test_read_vlan_only_device(void) { @@ -8991,7 +9120,7 @@ test_write_vlan_reorder_hdr(void) NM_SETTING_CONNECTION_ID, "Test Write VLAN reorder_hdr", NM_SETTING_CONNECTION_UUID, - nm_utils_uuid_generate_a(), + nm_uuid_generate_random_str_a(), NM_SETTING_CONNECTION_AUTOCONNECT, FALSE, NM_SETTING_CONNECTION_TYPE, @@ -9046,7 +9175,7 @@ test_write_ethernet_missing_ipv6(void) NM_SETTING_CONNECTION_ID, "Test Write Ethernet Without IPv6 Setting", NM_SETTING_CONNECTION_UUID, - nm_utils_uuid_generate_a(), + nm_uuid_generate_random_str_a(), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, @@ -9170,7 +9299,7 @@ test_write_bond_main(void) NM_SETTING_CONNECTION_ID, "Test Write Bond Main", NM_SETTING_CONNECTION_UUID, - nm_utils_uuid_generate_a(), + nm_uuid_generate_random_str_a(), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_INTERFACE_NAME, @@ -9270,7 +9399,7 @@ test_write_bond_slave(void) NM_SETTING_CONNECTION_ID, "Test Write Bond Slave", NM_SETTING_CONNECTION_UUID, - nm_utils_uuid_generate_a(), + nm_uuid_generate_random_str_a(), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, @@ -9357,7 +9486,7 @@ test_write_infiniband(void) NM_SETTING_CONNECTION_ID, "Test Write InfiniBand", NM_SETTING_CONNECTION_UUID, - nm_utils_uuid_generate_a(), + nm_uuid_generate_random_str_a(), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, @@ -9446,7 +9575,7 @@ test_write_bond_slave_ib(void) NM_SETTING_CONNECTION_ID, "Test Write Bond Slave InfiniBand", NM_SETTING_CONNECTION_UUID, - nm_utils_uuid_generate_a(), + nm_uuid_generate_random_str_a(), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, @@ -9604,7 +9733,7 @@ test_write_dcb_basic(void) NM_SETTING_CONNECTION_ID, "dcb-test", NM_SETTING_CONNECTION_UUID, - nm_utils_uuid_generate_a(), + nm_uuid_generate_random_str_a(), NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRED_SETTING_NAME, NM_SETTING_CONNECTION_INTERFACE_NAME, @@ -9850,7 +9979,7 @@ test_write_fcoe_mode(gconstpointer user_data) NM_SETTING_CONNECTION_ID, "fcoe-test", NM_SETTING_CONNECTION_UUID, - nm_utils_uuid_generate_a(), + nm_uuid_generate_random_str_a(), NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRED_SETTING_NAME, NM_SETTING_CONNECTION_INTERFACE_NAME, @@ -9968,7 +10097,7 @@ test_write_team_master(void) NM_SETTING_CONNECTION_ID, "Test Write Team Master", NM_SETTING_CONNECTION_UUID, - nm_utils_uuid_generate_a(), + nm_uuid_generate_random_str_a(), NM_SETTING_CONNECTION_INTERFACE_NAME, "team0", NM_SETTING_CONNECTION_TYPE, @@ -10060,7 +10189,7 @@ test_write_team_port(void) NM_SETTING_CONNECTION_ID, "Test Write Team Port", NM_SETTING_CONNECTION_UUID, - nm_utils_uuid_generate_a(), + nm_uuid_generate_random_str_a(), NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRED_SETTING_NAME, NM_SETTING_CONNECTION_MASTER, @@ -10119,7 +10248,7 @@ test_write_team_infiniband_port(void) NM_SETTING_CONNECTION_ID, "Test Write Team Infiniband Port", NM_SETTING_CONNECTION_UUID, - nm_utils_uuid_generate_a(), + nm_uuid_generate_random_str_a(), NM_SETTING_CONNECTION_TYPE, NM_SETTING_INFINIBAND_SETTING_NAME, NM_SETTING_CONNECTION_MASTER, @@ -10309,7 +10438,7 @@ test_write_proxy_basic(void) NM_SETTING_CONNECTION_ID, "Test Write Proxy Basic", NM_SETTING_CONNECTION_UUID, - nm_utils_uuid_generate_a(), + nm_uuid_generate_random_str_a(), NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRED_SETTING_NAME, NULL); @@ -10358,7 +10487,7 @@ _svUnescape(const char *str, char **to_free) str = (str_free = g_strdup(str)); } - s = svUnescape(str, to_free); + s = svUnescape_full(str, to_free, FALSE); if (*to_free) { g_assert(s == *to_free); g_assert(s[0]); @@ -10366,6 +10495,37 @@ _svUnescape(const char *str, char **to_free) g_assert(s == NULL || (!s[0] && (s < str || s > strchr(str, '\0'))) || (s[0] && s >= str && s <= strchr(str, '\0'))); } + + { + const char * s2; + gs_free char *to_free2 = NULL; + + gboolean is_utf8 = s && g_utf8_validate(s, -1, NULL); + + s2 = svUnescape_full(str, &to_free2, TRUE); + if (NM_IN_STRSET(str, "$'\\U0x'", "$'\\x0'", "$'\\008'", "$'\\08'")) { + g_assert_cmpstr(s2, ==, NULL); + g_assert(!to_free2); + g_assert_cmpstr(s, ==, ""); + g_assert(!*to_free); + } else if (NM_IN_STRSET(str, "$'x\\U0'")) { + g_assert_cmpstr(s2, ==, NULL); + g_assert(!to_free2); + g_assert_cmpstr(s, ==, "x"); + g_assert(*to_free == s); + } else if (!is_utf8) { + g_assert(!s2); + g_assert(!to_free2); + } else if (!to_free2) { + g_assert_cmpstr(s, ==, s2); + g_assert(s == s2); + } else { + g_assert_cmpstr(s, ==, s2); + g_assert(s != s2); + g_assert(s2 == to_free2); + } + } + return s; } @@ -10547,6 +10707,9 @@ test_svUnescape(void) V1("\"\\'\"''", "\\'"), V0("\"b\\~b\" ", "b\\~b"), V1("\"b\\~b\"x", "b\\~bx"), + + V0("$'x\\U0'", "x"), + V0("$'\\U0x'", ""), }; const UnescapeTestData data_ansi[] = { /* strings inside $''. They cannot be compared directly, but must @@ -10733,7 +10896,7 @@ test_write_unknown(gconstpointer test_data) _svGetValue_check(sv, "METRIC", NULL); _svGetValue_check(sv, "METRIC1", ""); _svGetValue_check(sv, "METRIC2", ""); - _svGetValue_check(sv, "METRIC3", "x"); + _svGetValue_check(sv, "METRIC3", ""); _svGetValue_check(sv, "IPADDR", "set-by-test1"); _svGetValue_check(sv, "IPADDR2", "set-by-test2"); @@ -10999,7 +11162,7 @@ test_sriov_write(void) NM_SETTING_CONNECTION_ID, "Test Write SR-IOV config", NM_SETTING_CONNECTION_UUID, - nm_utils_uuid_generate_a(), + nm_uuid_generate_random_str_a(), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_INTERFACE_NAME, @@ -11132,7 +11295,7 @@ test_tc_write_empty(void) NM_SETTING_CONNECTION_ID, "Test Write TC config", NM_SETTING_CONNECTION_UUID, - nm_utils_uuid_generate_a(), + nm_uuid_generate_random_str_a(), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_INTERFACE_NAME, @@ -11213,7 +11376,7 @@ test_tc_write(void) NM_SETTING_CONNECTION_ID, "Test Write TC config", NM_SETTING_CONNECTION_UUID, - nm_utils_uuid_generate_a(), + nm_uuid_generate_random_str_a(), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_INTERFACE_NAME, @@ -11405,6 +11568,7 @@ test_ethtool_names(void) } s_idxs[] = { {_NM_ETHTOOL_ID_FEATURE_FIRST, _NM_ETHTOOL_ID_FEATURE_LAST}, {_NM_ETHTOOL_ID_COALESCE_FIRST, _NM_ETHTOOL_ID_COALESCE_LAST}, + {_NM_ETHTOOL_ID_PAUSE_FIRST, _NM_ETHTOOL_ID_PAUSE_LAST}, {_NM_ETHTOOL_ID_RING_FIRST, _NM_ETHTOOL_ID_RING_LAST}, }; const NMEthtoolData *data; @@ -11599,6 +11763,8 @@ main(int argc, char **argv) g_test_add_func(TPATH "802-1x/password_raw", test_read_write_802_1x_password_raw); g_test_add_func(TPATH "802-1x/tls-p12-no-client-cert", test_read_802_1x_tls_p12_no_client_cert); + g_test_add_func(TPATH "wired/roundtrip/ethtool", test_roundtrip_ethtool); + g_test_add_data_func(TPATH "wired/read/aliases/good/0", GINT_TO_POINTER(0), test_read_wired_aliases_good); @@ -11705,6 +11871,7 @@ main(int argc, char **argv) g_test_add_func(TPATH "vlan/read/physdev", test_read_vlan_physdev); g_test_add_func(TPATH "vlan/read/reorder-hdr-1", test_read_vlan_reorder_hdr_1); g_test_add_func(TPATH "vlan/read/reorder-hdr-2", test_read_vlan_reorder_hdr_2); + g_test_add_func(TPATH "vlan/read/vlanid-use", test_read_vlan_vlanid_use); g_test_add_func(TPATH "wired/read/read-wake-on-lan", test_read_wired_wake_on_lan); g_test_add_func(TPATH "wired/read/read-auto-negotiate-off", test_read_wired_auto_negotiate_off); g_test_add_func(TPATH "wired/read/read-auto-negotiate-on", test_read_wired_auto_negotiate_on); diff --git a/src/core/settings/plugins/ifupdown/meson.build b/src/core/settings/plugins/ifupdown/meson.build index dd252783..1bff8155 100644 --- a/src/core/settings/plugins/ifupdown/meson.build +++ b/src/core/settings/plugins/ifupdown/meson.build @@ -7,14 +7,12 @@ libnms_ifupdown_core = static_library( 'nms-ifupdown-parser.c', ), dependencies: core_default_dep, - c_args: daemon_c_flags, ) libnm_settings_plugin_ifupdown = shared_module( 'nm-settings-plugin-ifupdown', sources: 'nms-ifupdown-plugin.c', dependencies: core_plugin_dep, - c_args: daemon_c_flags, link_with: libnms_ifupdown_core, link_args: ldflags_linker_script_settings, link_depends: linker_script_settings, diff --git a/src/core/settings/plugins/ifupdown/nms-ifupdown-parser.c b/src/core/settings/plugins/ifupdown/nms-ifupdown-parser.c index a4974a96..db6b1aef 100644 --- a/src/core/settings/plugins/ifupdown/nms-ifupdown-parser.c +++ b/src/core/settings/plugins/ifupdown/nms-ifupdown-parser.c @@ -12,7 +12,8 @@ #include #include -#include "nm-core-internal.h" +#include "libnm-glib-aux/nm-uuid.h" +#include "libnm-core-intern/nm-core-internal.h" #include "settings/nm-settings-plugin.h" #include "nms-ifupdown-plugin.h" @@ -32,14 +33,6 @@ /*****************************************************************************/ -#define _str_has_prefix(val, prefix, require_suffix) \ - ({ \ - const char *_val = (val); \ - \ - (strncmp(_val, "" prefix "", NM_STRLEN(prefix)) == 0) \ - && (!(require_suffix) || _val[NM_STRLEN(prefix)] != '\0'); \ - }) - static const char * _ifupdownplugin_guess_connection_type(if_block *block) { @@ -51,8 +44,7 @@ _ifupdownplugin_guess_connection_type(if_block *block) if_data *ifb; c_list_for_each_entry (ifb, &block->data_lst_head, data_lst) { - if (_str_has_prefix(ifb->key, "wireless-", FALSE) - || _str_has_prefix(ifb->key, "wpa-", FALSE)) { + if (NM_STR_HAS_PREFIX(ifb->key, "wireless-") || NM_STR_HAS_PREFIX(ifb->key, "wpa-")) { ret_type = NM_SETTING_WIRELESS_SETTING_NAME; break; } @@ -102,7 +94,7 @@ update_wireless_setting_from_if_block(NMConnection *connection, if_block *block) wireless_setting = NM_SETTING_WIRELESS(nm_setting_wireless_new()); c_list_for_each_entry (curr, &block->data_lst_head, data_lst) { - if (_str_has_prefix(curr->key, "wireless-", TRUE)) { + if (NM_STR_HAS_PREFIX_WITH_MORE(curr->key, "wireless-")) { const char *newkey = map_by_mapping(mapping, curr->key + NM_STRLEN("wireless-")); _LOGI("wireless setting key: %s='%s'", newkey, curr->data); @@ -137,7 +129,7 @@ update_wireless_setting_from_if_block(NMConnection *connection, if_block *block) } else { g_object_set(wireless_setting, newkey, curr->data, NULL); } - } else if (_str_has_prefix(curr->key, "wpa-", TRUE)) { + } else if (NM_STR_HAS_PREFIX_WITH_MORE(curr->key, "wpa-")) { const char *newkey = map_by_mapping(mapping, curr->key + NM_STRLEN("wpa-")); if (nm_streq0(newkey, "ssid")) { @@ -304,7 +296,7 @@ update_wireless_security_setting_from_if_block(NMConnection *connection, if_bloc wireless_security_setting = NM_SETTING_WIRELESS_SECURITY(nm_setting_wireless_security_new()); c_list_for_each_entry (curr, &block->data_lst_head, data_lst) { - if (_str_has_prefix(curr->key, "wireless-", TRUE)) { + if (NM_STR_HAS_PREFIX_WITH_MORE(curr->key, "wireless-")) { const char * key = curr->key + NM_STRLEN("wireless-"); char * property_value = NULL; gpointer typed_property_value = NULL; @@ -336,7 +328,7 @@ wireless_next: if (typed_property_value && free_func) (*free_func)(typed_property_value); - } else if (_str_has_prefix(curr->key, "wpa-", TRUE)) { + } else if (NM_STR_HAS_PREFIX_WITH_MORE(curr->key, "wpa-")) { const char * key = curr->key + NM_STRLEN("wpa-"); char * property_value = NULL; gpointer typed_property_value = NULL; @@ -644,7 +636,7 @@ ifupdown_new_connection_from_if_block(if_block *block, gboolean autoconnect, GEr type = _ifupdownplugin_guess_connection_type(block); idstr = g_strconcat("Ifupdown (", block->name, ")", NULL); - uuid = nm_utils_uuid_generate_from_string(idstr, -1, NM_UTILS_UUID_TYPE_LEGACY, NULL); + uuid = nm_uuid_generate_from_string_str(idstr, -1, NM_UUID_TYPE_LEGACY, NULL); g_object_set(s_con, NM_SETTING_CONNECTION_TYPE, type, @@ -655,7 +647,7 @@ ifupdown_new_connection_from_if_block(if_block *block, gboolean autoconnect, GEr NM_SETTING_CONNECTION_UUID, uuid, NM_SETTING_CONNECTION_AUTOCONNECT, - (gboolean)(!!autoconnect), + (gboolean) (!!autoconnect), NULL); _LOGD("update_connection_setting_from_if_block: name:%s, type:%s, id:%s, uuid: %s", diff --git a/src/core/settings/plugins/ifupdown/nms-ifupdown-plugin.c b/src/core/settings/plugins/ifupdown/nms-ifupdown-plugin.c index 34523f8d..80a5638a 100644 --- a/src/core/settings/plugins/ifupdown/nms-ifupdown-plugin.c +++ b/src/core/settings/plugins/ifupdown/nms-ifupdown-plugin.c @@ -9,7 +9,7 @@ #include "nms-ifupdown-plugin.h" -#include "nm-core-internal.h" +#include "libnm-core-intern/nm-core-internal.h" #include "nm-core-utils.h" #include "nm-config.h" #include "settings/nm-settings-plugin.h" diff --git a/src/core/settings/plugins/ifupdown/tests/test-ifupdown.c b/src/core/settings/plugins/ifupdown/tests/test-ifupdown.c index 6e3eb0e7..0e8db733 100644 --- a/src/core/settings/plugins/ifupdown/tests/test-ifupdown.c +++ b/src/core/settings/plugins/ifupdown/tests/test-ifupdown.c @@ -5,7 +5,7 @@ #include "src/core/nm-default-daemon.h" -#include "nm-core-internal.h" +#include "libnm-core-intern/nm-core-internal.h" #include "settings/plugins/ifupdown/nms-ifupdown-interface-parser.h" #include "settings/plugins/ifupdown/nms-ifupdown-parser.h" diff --git a/src/core/settings/plugins/keyfile/nms-keyfile-plugin.c b/src/core/settings/plugins/keyfile/nms-keyfile-plugin.c index 789bfc1a..e8ae1814 100644 --- a/src/core/settings/plugins/keyfile/nms-keyfile-plugin.c +++ b/src/core/settings/plugins/keyfile/nms-keyfile-plugin.c @@ -13,19 +13,20 @@ #include #include -#include "nm-std-aux/c-list-util.h" -#include "nm-glib-aux/nm-c-list.h" -#include "nm-glib-aux/nm-io-utils.h" +#include "libnm-std-aux/c-list-util.h" +#include "libnm-glib-aux/nm-c-list.h" +#include "libnm-glib-aux/nm-uuid.h" +#include "libnm-glib-aux/nm-io-utils.h" #include "nm-connection.h" #include "nm-setting.h" #include "nm-setting-connection.h" #include "nm-utils.h" #include "nm-config.h" -#include "nm-core-internal.h" -#include "nm-keyfile-internal.h" +#include "libnm-core-intern/nm-core-internal.h" +#include "libnm-core-intern/nm-keyfile-internal.h" -#include "systemd/nm-sd-utils-shared.h" +#include "libnm-systemd-shared/nm-sd-utils-shared.h" #include "settings/nm-settings-plugin.h" #include "settings/nm-settings-storage.h" @@ -233,7 +234,7 @@ _read_from_file(const char * full_filename, nm_assert(!connection || (_nm_connection_verify(connection, NULL) == NM_SETTING_VERIFY_SUCCESS)); - nm_assert(!connection || nm_utils_is_uuid(nm_connection_get_uuid(connection))); + nm_assert(!connection || nm_uuid_is_normalized(nm_connection_get_uuid(connection))); return connection; } @@ -260,7 +261,7 @@ _nm_assert_storage(gpointer plugin /* NMSKeyfilePlugin */, uuid = nms_keyfile_storage_get_uuid(storage); - nm_assert(nm_utils_is_uuid(uuid)); + nm_assert(nm_uuid_is_normalized(uuid)); nm_assert(((NMSKeyfileStorage *) storage)->is_meta_data || !(((NMSKeyfileStorage *) storage)->u.conn_data.connection) @@ -1106,7 +1107,7 @@ nms_keyfile_plugin_set_nmmeta_tombstone(NMSKeyfilePlugin * self, const char * dirname; nm_assert(NMS_IS_KEYFILE_PLUGIN(self)); - nm_assert(nm_utils_is_uuid(uuid)); + nm_assert(nm_uuid_is_normalized(uuid)); nm_assert(!out_storage || !*out_storage); nm_assert(!shadowed_storage || (set && in_memory)); @@ -1246,9 +1247,9 @@ nms_keyfile_plugin_init(NMSKeyfilePlugin *plugin) /* dirname_libs are a set of read-only directories with lower priority than /etc or /run. * There is nothing complicated about having multiple of such directories, so dirname_libs * is a list (which currently only has at most one directory). */ - priv->dirname_libs[0] = nm_sd_utils_path_simplify(g_strdup(NM_KEYFILE_PATH_NAME_LIB), FALSE); + priv->dirname_libs[0] = nm_sd_utils_path_simplify(g_strdup(NM_KEYFILE_PATH_NAME_LIB)); priv->dirname_libs[1] = NULL; - priv->dirname_run = nm_sd_utils_path_simplify(g_strdup(NM_KEYFILE_PATH_NAME_RUN), FALSE); + priv->dirname_run = nm_sd_utils_path_simplify(g_strdup(NM_KEYFILE_PATH_NAME_RUN)); priv->dirname_etc = nm_config_data_get_value(NM_CONFIG_GET_DATA_ORIG, NM_CONFIG_KEYFILE_GROUP_KEYFILE, NM_CONFIG_KEYFILE_KEY_KEYFILE_PATH, @@ -1261,10 +1262,9 @@ nms_keyfile_plugin_init(NMSKeyfilePlugin *plugin) } else if (!priv->dirname_etc || priv->dirname_etc[0] != '/') { /* either invalid path or unspecified. Use the default. */ g_free(priv->dirname_etc); - priv->dirname_etc = - nm_sd_utils_path_simplify(g_strdup(NM_KEYFILE_PATH_NAME_ETC_DEFAULT), FALSE); + priv->dirname_etc = nm_sd_utils_path_simplify(g_strdup(NM_KEYFILE_PATH_NAME_ETC_DEFAULT)); } else - nm_sd_utils_path_simplify(priv->dirname_etc, FALSE); + nm_sd_utils_path_simplify(priv->dirname_etc); /* no duplicates */ if (NM_IN_STRSET(priv->dirname_libs[0], priv->dirname_etc, priv->dirname_run)) diff --git a/src/core/settings/plugins/keyfile/nms-keyfile-reader.c b/src/core/settings/plugins/keyfile/nms-keyfile-reader.c index 70b047f3..8b9d982f 100644 --- a/src/core/settings/plugins/keyfile/nms-keyfile-reader.c +++ b/src/core/settings/plugins/keyfile/nms-keyfile-reader.c @@ -9,7 +9,7 @@ #include -#include "nm-keyfile-internal.h" +#include "libnm-core-intern/nm-keyfile-internal.h" #include "NetworkManagerUtils.h" #include "nms-keyfile-utils.h" diff --git a/src/core/settings/plugins/keyfile/nms-keyfile-storage.c b/src/core/settings/plugins/keyfile/nms-keyfile-storage.c index 89be817a..8c526c81 100644 --- a/src/core/settings/plugins/keyfile/nms-keyfile-storage.c +++ b/src/core/settings/plugins/keyfile/nms-keyfile-storage.c @@ -7,8 +7,9 @@ #include "nms-keyfile-storage.h" +#include "libnm-glib-aux/nm-uuid.h" #include "nm-utils.h" -#include "nm-core-internal.h" +#include "libnm-core-intern/nm-core-internal.h" #include "nms-keyfile-plugin.h" /*****************************************************************************/ @@ -108,7 +109,7 @@ _storage_new(NMSKeyfilePlugin * plugin, NMSKeyfileStorage *self; nm_assert(NMS_IS_KEYFILE_PLUGIN(plugin)); - nm_assert(nm_utils_is_uuid(uuid)); + nm_assert(nm_uuid_is_normalized(uuid)); nm_assert(filename && filename[0] == '/'); self = g_object_new(NMS_TYPE_KEYFILE_STORAGE, @@ -135,7 +136,7 @@ nms_keyfile_storage_new_tombstone(NMSKeyfilePlugin * plugin, { NMSKeyfileStorage *self; - nm_assert(nm_utils_is_uuid(uuid)); + nm_assert(nm_uuid_is_normalized(uuid)); nm_assert(filename && filename[0] == '/'); nm_assert(nms_keyfile_nmmeta_check_filename(filename, NULL)); nm_assert(NM_IN_SET(storage_type, NMS_KEYFILE_STORAGE_TYPE_ETC, NMS_KEYFILE_STORAGE_TYPE_RUN)); diff --git a/src/core/settings/plugins/keyfile/nms-keyfile-utils.c b/src/core/settings/plugins/keyfile/nms-keyfile-utils.c index ca1233f5..e2c68bbe 100644 --- a/src/core/settings/plugins/keyfile/nms-keyfile-utils.c +++ b/src/core/settings/plugins/keyfile/nms-keyfile-utils.c @@ -10,8 +10,9 @@ #include #include -#include "nm-glib-aux/nm-io-utils.h" -#include "nm-keyfile-internal.h" +#include "libnm-glib-aux/nm-uuid.h" +#include "libnm-glib-aux/nm-io-utils.h" +#include "libnm-core-intern/nm-keyfile-internal.h" #include "nm-utils.h" #include "nm-setting-wired.h" #include "nm-setting-wireless.h" @@ -30,9 +31,9 @@ const char * nms_keyfile_nmmeta_check_filename(const char *filename, guint *out_uuid_len) { - const char *uuid; const char *s; gsize len; + char uuid[37]; s = strrchr(filename, '/'); if (s) @@ -50,17 +51,18 @@ nms_keyfile_nmmeta_check_filename(const char *filename, guint *out_uuid_len) len -= NM_STRLEN(NM_KEYFILE_PATH_SUFFIX_NMMETA); - if (!NM_IN_SET(len, 36, 40)) { + if (len != 36) { /* the remaining part of the filename has not the right length to - * contain a UUID (according to nm_utils_is_uuid()). */ + * contain a UUID (according to nm_uuid_is_normalized()). */ return NULL; } - uuid = nm_strndup_a(100, filename, len, NULL); - if (!nm_utils_is_uuid(uuid)) + memcpy(uuid, filename, 36); + uuid[36] = '\0'; + if (!nm_uuid_is_normalized(uuid)) return NULL; - NM_SET_OUT(out_uuid_len, len); + NM_SET_OUT(out_uuid_len, 36); return filename; } @@ -71,7 +73,7 @@ nms_keyfile_nmmeta_filename(const char *dirname, const char *uuid, gboolean temp char *s; nm_assert(dirname && dirname[0] == '/'); - nm_assert(nm_utils_is_uuid(uuid) && !strchr(uuid, '/')); + nm_assert(nm_uuid_is_normalized(uuid) && !strchr(uuid, '/')); if (g_snprintf(filename, sizeof(filename), @@ -80,7 +82,7 @@ nms_keyfile_nmmeta_filename(const char *dirname, const char *uuid, gboolean temp NM_KEYFILE_PATH_SUFFIX_NMMETA, temporary ? "~" : "") >= sizeof(filename)) { - /* valid uuids are limited in length (nm_utils_is_uuid). The buffer should always + /* valid uuids are limited in length (nm_uuid_is_normalized). The buffer should always * be large enough. */ nm_assert_not_reached(); } @@ -215,7 +217,7 @@ nms_keyfile_nmmeta_write(const char *dirname, int errsv; nm_assert(dirname && dirname[0] == '/'); - nm_assert(nm_utils_is_uuid(uuid) && !strchr(uuid, '/')); + nm_assert(nm_uuid_is_normalized(uuid) && !strchr(uuid, '/')); nm_assert(!loaded_path || loaded_path[0] == '/'); nm_assert(!shadowed_storage || loaded_path); @@ -273,7 +275,13 @@ nms_keyfile_nmmeta_write(const char *dirname, contents = g_key_file_to_data(kf, &length, NULL); - if (!nm_utils_file_set_contents(full_filename, contents, length, 0600, &errsv, NULL)) { + if (!nm_utils_file_set_contents(full_filename, + contents, + length, + 0600, + NULL, + &errsv, + NULL)) { NM_SET_OUT(out_full_filename, g_steal_pointer(&full_filename_tmp)); return -NM_ERRNO_NATIVE(errsv); } diff --git a/src/core/settings/plugins/keyfile/nms-keyfile-writer.c b/src/core/settings/plugins/keyfile/nms-keyfile-writer.c index 0e2c94b5..70afdc23 100644 --- a/src/core/settings/plugins/keyfile/nms-keyfile-writer.c +++ b/src/core/settings/plugins/keyfile/nms-keyfile-writer.c @@ -12,12 +12,12 @@ #include #include -#include "nm-keyfile-internal.h" +#include "libnm-core-intern/nm-keyfile-internal.h" #include "nms-keyfile-utils.h" #include "nms-keyfile-reader.h" -#include "nm-glib-aux/nm-io-utils.h" +#include "libnm-glib-aux/nm-io-utils.h" /*****************************************************************************/ @@ -125,13 +125,14 @@ cert_writer(NMConnection * connection, /* FIXME(keyfile-parse-in-memory): writer must not access/write to the file system before * being sure that the entire profile can be written and all circumstances are good to - * proceed. That means, while writing we must only collect the blogs in-memory, and write + * proceed. That means, while writing we must only collect the blobs in-memory, and write * them all in the end together (or not at all). */ success = nm_utils_file_set_contents(new_path, (const char *) blob_data, blob_len, 0600, NULL, + NULL, &local); if (success) { /* Write the path value to the keyfile. @@ -378,7 +379,7 @@ _internal_write_connection(NMConnection * connection, } } - nm_utils_file_set_contents(path, kf_content_buf, kf_content_len, 0600, NULL, &local_err); + nm_utils_file_set_contents(path, kf_content_buf, kf_content_len, 0600, NULL, NULL, &local_err); if (local_err) { g_set_error(error, NM_SETTINGS_ERROR, diff --git a/src/core/settings/plugins/keyfile/tests/test-keyfile-settings.c b/src/core/settings/plugins/keyfile/tests/test-keyfile-settings.c index 348b0ed6..a13c2586 100644 --- a/src/core/settings/plugins/keyfile/tests/test-keyfile-settings.c +++ b/src/core/settings/plugins/keyfile/tests/test-keyfile-settings.c @@ -15,7 +15,8 @@ #include #include -#include "nm-core-internal.h" +#include "libnm-glib-aux/nm-uuid.h" +#include "libnm-core-intern/nm-core-internal.h" #include "settings/plugins/keyfile/nms-keyfile-reader.h" #include "settings/plugins/keyfile/nms-keyfile-writer.h" @@ -2289,7 +2290,7 @@ test_read_missing_id_uuid(void) gs_free char * expected_uuid = NULL; const char * FILENAME = TEST_KEYFILES_DIR "/Test_Missing_ID_UUID"; - expected_uuid = _nm_utils_uuid_generate_from_strings("keyfile", FILENAME, NULL); + expected_uuid = nm_uuid_generate_from_strings("keyfile", FILENAME, NULL); connection = keyfile_read_connection_from_file(FILENAME); -- cgit 1.3.0-6-gf8a5 From 88c227d90a6b7b388c5c85d72802a0ca8f05ed5c Mon Sep 17 00:00:00 2001 From: Michael Biebl Date: Thu, 13 Jan 2022 22:30:39 +0100 Subject: New upstream version 1.34.0 --- src/core/settings/nm-settings-connection.c | 4 +- src/core/settings/nm-settings.c | 10 +- .../plugins/ifcfg-rh/nms-ifcfg-rh-plugin.c | 2 +- .../plugins/ifcfg-rh/nms-ifcfg-rh-reader.c | 214 +- .../plugins/ifcfg-rh/nms-ifcfg-rh-storage.c | 2 +- .../settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.c | 2 + .../settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.h | 2 +- .../plugins/ifcfg-rh/nms-ifcfg-rh-writer.c | 111 +- ...System_test-wired-802-1X-subj-matches.cexpected | 2 + .../ifcfg-Test_Write_Bond_Main.cexpected | 3 + .../ifcfg-Test_Write_Permissions.cexpected | 3 + .../ifcfg-Test_Write_Wifi_LEAP.cexpected | 3 + .../ifcfg-Test_Write_Wifi_WEP_104_ASCII.cexpected | 3 + .../ifcfg-Test_Write_Wired_Static_Routes.cexpected | 2 + .../ifcfg-Test_Write_Wired_match.cexpected | 2 + .../ifcfg-Vlan_test-vlan-interface.cexpected | 2 + .../tests/network-scripts/ifcfg-dcb-test.cexpected | 1 - .../ifcfg-random_wifi_connection.cexpected | 2 + .../ifcfg-random_wifi_connection_2.cexpected | 2 + .../tests/network-scripts/ifcfg-test-bond-port | 9 + .../ifcfg-test-ip6-disabled.cexpected | 2 + .../ifcfg-test-sriov-write.cexpected | 3 + .../ifcfg-test-static-routes-legacy.cexpected | 2 + .../ifcfg-test-tc-write-empty.cexpected | 3 + .../network-scripts/ifcfg-test-tc-write.cexpected | 3 + .../ifcfg-test-vlan-vlanid-use.cexpected | 2 + .../plugins/ifcfg-rh/tests/test-ifcfg-rh.c | 3788 ++++++-------------- .../ifupdown/nms-ifupdown-interface-parser.c | 2 +- .../plugins/ifupdown/nms-ifupdown-parser.c | 8 +- .../plugins/ifupdown/nms-ifupdown-plugin.c | 6 +- .../settings/plugins/keyfile/nms-keyfile-plugin.c | 18 +- .../settings/plugins/keyfile/nms-keyfile-storage.c | 2 +- .../plugins/keyfile/tests/test-keyfile-settings.c | 8 +- 33 files changed, 1445 insertions(+), 2783 deletions(-) create mode 100644 src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-bond-port (limited to 'src/core/settings') diff --git a/src/core/settings/nm-settings-connection.c b/src/core/settings/nm-settings-connection.c index b423bf5b..71da97d0 100644 --- a/src/core/settings/nm-settings-connection.c +++ b/src/core/settings/nm-settings-connection.c @@ -346,7 +346,7 @@ _getsettings_cached_get(NMSettingsConnection *self, const NMConnectionSerializat priv->getsettings_cached.options = *options; priv->getsettings_cached.options.seen_bssids = - nm_utils_strv_dup_packed(priv->getsettings_cached.options.seen_bssids, -1); + nm_strv_dup_packed(priv->getsettings_cached.options.seen_bssids, -1); return priv->getsettings_cached.variant; } @@ -382,7 +382,7 @@ _nm_settings_connection_set_connection(NMSettingsConnection * self, NM_SETTING_COMPARE_FLAG_EXACT)) { connection_old = priv->connection; priv->connection = g_object_ref(new_connection); - nmtst_connection_assert_unchanging(priv->connection); + nm_assert_connection_unchanging(priv->connection); _getsettings_cached_clear(priv); _nm_settings_notify_sorted_by_autoconnect_priority_maybe_changed(priv->settings); diff --git a/src/core/settings/nm-settings.c b/src/core/settings/nm-settings.c index f9f98de7..b71b9d18 100644 --- a/src/core/settings/nm-settings.c +++ b/src/core/settings/nm-settings.c @@ -17,7 +17,7 @@ #include #if HAVE_SELINUX - #include +#include #endif #include "libnm-core-aux-intern/nm-common-macros.h" @@ -1352,7 +1352,7 @@ _connection_changed_track(NMSettings * self, || (_nm_connection_verify(connection, NULL) == NM_SETTING_VERIFY_SUCCESS)); nm_assert(!connection || nm_streq0(uuid, nm_connection_get_uuid(connection))); - nmtst_connection_assert_unchanging(connection); + nm_assert_connection_unchanging(connection); sett_conn_entry = _sett_conn_entries_get(self, uuid) ?: _sett_conn_entries_create_and_add(self, uuid); @@ -3372,7 +3372,7 @@ load_plugins(NMSettings *self, const char *const *plugins, GError **error) continue; } - if (nm_utils_strv_find_first((char **) plugins, iter - plugins, pname) >= 0) { + if (nm_strv_find_first(plugins, iter - plugins, pname) >= 0) { /* the plugin is already mentioned in the list previously. * Don't load a duplicate. */ continue; @@ -3452,7 +3452,7 @@ impl_settings_save_hostname(NMDBusObject * obj, g_variant_get(parameters, "(&s)", &hostname); /* Minimal validation of the hostname */ - if (!nm_hostname_manager_validate_hostname(hostname)) { + if (!nm_utils_validate_hostname(hostname)) { error_code = NM_SETTINGS_ERROR_INVALID_HOSTNAME; error_reason = "The hostname was too long or contained invalid characters"; goto err; @@ -3938,7 +3938,7 @@ get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) priv->connections_len, G_STRUCT_OFFSET(NMSettingsConnection, _connections_lst), TRUE); - g_value_take_boxed(value, nm_utils_strv_make_deep_copied(strv)); + g_value_take_boxed(value, nm_strv_make_deep_copied(strv)); break; case PROP_STARTUP_COMPLETE: g_value_set_boolean(value, !nm_settings_get_startup_complete_blocked_reason(self, FALSE)); diff --git a/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-plugin.c b/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-plugin.c index 5038ac6a..8fdc01fb 100644 --- a/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-plugin.c +++ b/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-plugin.c @@ -848,7 +848,7 @@ _unhandled_specs_from_hashtable(GHashTable *hash) GSList * list = NULL; guint i, l; - keys = nm_utils_strdict_get_keys(hash, TRUE, &l); + keys = nm_strdict_get_keys(hash, TRUE, &l); for (i = l; i > 0;) { i--; list = g_slist_prepend(list, g_strdup(keys[i])); diff --git a/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c b/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c index 03b347f9..6dd5ef05 100644 --- a/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c +++ b/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c @@ -31,6 +31,7 @@ #include "nm-setting-ethtool.h" #include "nm-setting-8021x.h" #include "nm-setting-bond.h" +#include "nm-setting-bond-port.h" #include "nm-setting-team.h" #include "nm-setting-team-port.h" #include "nm-setting-bridge.h" @@ -474,7 +475,7 @@ make_connection_setting(const char *file, if (v) { gs_free const char **items = NULL; - items = nm_utils_strsplit_set(v, " "); + items = nm_strsplit_set(v, " "); for (iter = items; iter && *iter; iter++) { if (!nm_setting_connection_add_permission(s_con, "user", *iter, NULL)) PARSE_WARNING("invalid USERS item '%s'", *iter); @@ -490,7 +491,7 @@ make_connection_setting(const char *file, if (v) { gs_free const char **items = NULL; - items = nm_utils_strsplit_set(v, " \t"); + items = nm_strsplit_set(v, " \t"); for (iter = items; iter && *iter; iter++) { if (!nm_setting_connection_add_secondary(s_con, *iter)) PARSE_WARNING("secondary connection UUID '%s' already added", *iter); @@ -633,6 +634,15 @@ make_connection_setting(const char *file, PARSE_WARNING("invalid LLMNR setting"); g_object_set(s_con, NM_SETTING_CONNECTION_LLMNR, i_val, NULL); + i_val = NM_SETTING_CONNECTION_DNS_OVER_TLS_DEFAULT; + if (!svGetValueEnum(ifcfg, + "DNS_OVER_TLS", + nm_setting_connection_dns_over_tls_get_type(), + &i_val, + NULL)) + PARSE_WARNING("invalid DNS_OVER_TLS setting"); + g_object_set(s_con, NM_SETTING_CONNECTION_DNS_OVER_TLS, i_val, NULL); + return NM_SETTING(s_con); } @@ -1036,7 +1046,7 @@ parse_route_line(const char *line, * Maybe later we want to support some form of quotation here. * Which of course, would be incompatible with initscripts. */ - words_free = nm_utils_strsplit_set(line, " \t\n"); + words_free = nm_strsplit_set(line, " \t\n"); words = words_free ?: NM_PTRARRAY_EMPTY(const char *); @@ -1582,7 +1592,7 @@ parse_dns_options(NMSettingIPConfig *ip_config, const char *value) if (!nm_setting_ip_config_has_dns_options(ip_config)) nm_setting_ip_config_clear_dns_options(ip_config, TRUE); - options = nm_utils_strsplit_set(value, " "); + options = nm_strsplit_set(value, " "); if (options) { for (item = options; *item; item++) { if (!nm_setting_ip_config_add_dns_option(ip_config, *item)) @@ -1974,26 +1984,27 @@ make_ip4_setting(shvarFile *ifcfg, /* DNS servers * Pick up just IPv4 addresses (IPv6 addresses are taken by make_ip6_setting()) */ - for (i = 1; i <= 10; i++) { + for (i = 1; i < 10000; i++) { char tag[256]; numbered_tag(tag, "DNS", i); nm_clear_g_free(&value); v = svGetValueStr(ifcfg, tag, &value); - if (v) { - if (nm_utils_ipaddr_is_valid(AF_INET, v)) { - if (!nm_setting_ip_config_add_dns(s_ip4, v)) - PARSE_WARNING("duplicate DNS server %s", tag); - } else if (nm_utils_ipaddr_is_valid(AF_INET6, v)) { - /* Ignore IPv6 addresses */ - } else { - g_set_error(error, - NM_SETTINGS_ERROR, - NM_SETTINGS_ERROR_INVALID_CONNECTION, - "Invalid DNS server address '%s'", - v); - return NULL; - } + if (!v) + break; + + if (nm_utils_ipaddr_is_valid(AF_INET, v)) { + if (!nm_setting_ip_config_add_dns(s_ip4, v)) + PARSE_WARNING("duplicate DNS server %s", tag); + } else if (nm_utils_ipaddr_is_valid(AF_INET6, v)) { + /* Ignore IPv6 addresses */ + } else { + g_set_error(error, + NM_SETTINGS_ERROR, + NM_SETTINGS_ERROR_INVALID_CONNECTION, + "Invalid DNS server address '%s'", + v); + return NULL; } } @@ -2003,7 +2014,7 @@ make_ip4_setting(shvarFile *ifcfg, if (v) { gs_free const char **searches = NULL; - searches = nm_utils_strsplit_set(v, " "); + searches = nm_strsplit_set(v, " "); if (searches) { for (item = searches; *item; item++) { if (!nm_setting_ip_config_add_dns_search(s_ip4, *item)) @@ -2063,7 +2074,7 @@ make_ip4_setting(shvarFile *ifcfg, if (v) { gs_free const char **searches = NULL; - searches = nm_utils_strsplit_set(v, " "); + searches = nm_strsplit_set(v, " "); if (searches) { for (item = searches; *item; item++) { if (!nm_setting_ip_config_add_dns_search(s_ip4, *item)) @@ -2249,6 +2260,7 @@ make_ip6_setting(shvarFile *ifcfg, shvarFile *network_ifcfg, gboolean routes_rea gboolean ip6_privacy = FALSE, ip6_privacy_prefer_public_ip; NMSettingIP6ConfigPrivacy ip6_privacy_val; guint32 route_table; + gboolean is_disabled; s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); @@ -2375,10 +2387,9 @@ make_ip6_setting(shvarFile *ifcfg, shvarFile *network_ifcfg, gboolean routes_rea NULL); /* Don't bother to read IP, DNS and routes when IPv6 is disabled */ - if (NM_IN_STRSET(method, - NM_SETTING_IP6_CONFIG_METHOD_IGNORE, - NM_SETTING_IP6_CONFIG_METHOD_DISABLED)) - return NM_SETTING(g_steal_pointer(&s_ip6)); + is_disabled = NM_IN_STRSET(method, + NM_SETTING_IP6_CONFIG_METHOD_IGNORE, + NM_SETTING_IP6_CONFIG_METHOD_DISABLED); nm_clear_g_free(&value); v = svGetValueStr(ifcfg, "DHCPV6_DUID", &value); @@ -2437,16 +2448,24 @@ make_ip6_setting(shvarFile *ifcfg, shvarFile *network_ifcfg, gboolean routes_rea ipv6addr_secondaries ?: "", NULL); - list = nm_utils_strsplit_set(value, " "); - for (iter = list, i = 0; iter && *iter; iter++, i++) { - NMIPAddress *addr = NULL; + list = nm_strsplit_set(value, " "); + if (list) { + if (is_disabled) + PARSE_WARNING("ignore IPv6 addresses with method disabled/ignore"); + else { + for (iter = list, i = 0; *iter; iter++, i++) { + nm_auto_unref_ip_address NMIPAddress *addr = NULL; - if (!parse_full_ip6_address(ifcfg, *iter, i, &addr, error)) - return NULL; + if (!parse_full_ip6_address(ifcfg, *iter, i, &addr, is_disabled ? NULL : error)) { + if (is_disabled) + break; + return NULL; + } - if (!nm_setting_ip_config_add_address(s_ip6, addr)) - PARSE_WARNING("duplicate IP6 address"); - nm_ip_address_unref(addr); + if (!nm_setting_ip_config_add_address(s_ip6, addr)) + PARSE_WARNING("duplicate IP6 address"); + } + } } /* Gateway */ @@ -2462,18 +2481,20 @@ make_ip6_setting(shvarFile *ifcfg, shvarFile *network_ifcfg, gboolean routes_rea } if (v) { char *ptr; + if ((ptr = strchr(v, '%')) != NULL) *ptr = '\0'; /* remove %interface prefix if present */ if (!nm_utils_ipaddr_is_valid(AF_INET6, v)) { - g_set_error(error, - NM_SETTINGS_ERROR, - NM_SETTINGS_ERROR_INVALID_CONNECTION, - "Invalid IP6 address '%s'", - v); - return NULL; - } - - g_object_set(s_ip6, NM_SETTING_IP_CONFIG_GATEWAY, v, NULL); + if (!is_disabled) { + g_set_error(error, + NM_SETTINGS_ERROR, + NM_SETTINGS_ERROR_INVALID_CONNECTION, + "Invalid IP6 address '%s'", + v); + return NULL; + } + } else + g_object_set(s_ip6, NM_SETTING_IP_CONFIG_GATEWAY, v, NULL); } } @@ -2497,23 +2518,27 @@ make_ip6_setting(shvarFile *ifcfg, shvarFile *network_ifcfg, gboolean routes_rea /* DNS servers * Pick up just IPv6 addresses (IPv4 addresses are taken by make_ip4_setting()) */ - for (i = 1; i <= 10; i++) { + for (i = 1; i < 10000; i++) { char tag[256]; numbered_tag(tag, "DNS", i); nm_clear_g_free(&value); v = svGetValueStr(ifcfg, tag, &value); - if (!v) { - /* all done */ + if (!v) break; - } if (nm_utils_ipaddr_is_valid(AF_INET6, v)) { + if (is_disabled) { + PARSE_WARNING("ignore DNS server addresses with method disabled/ignore"); + break; + } if (!nm_setting_ip_config_add_dns(s_ip6, v)) PARSE_WARNING("duplicate DNS server %s", tag); } else if (nm_utils_ipaddr_is_valid(AF_INET, v)) { /* Ignore IPv4 addresses */ } else { + if (is_disabled) + continue; g_set_error(error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, @@ -2540,11 +2565,15 @@ make_ip6_setting(shvarFile *ifcfg, shvarFile *network_ifcfg, gboolean routes_rea if (v) { gs_free const char **searches = NULL; - searches = nm_utils_strsplit_set(v, " "); + searches = nm_strsplit_set(v, " "); if (searches) { - for (iter = searches; *iter; iter++) { - if (!nm_setting_ip_config_add_dns_search(s_ip6, *iter)) - PARSE_WARNING("duplicate DNS domain '%s'", *iter); + if (is_disabled) { + PARSE_WARNING("ignore IPV6_DOMAIN with method disabled/ignore"); + } else { + for (iter = searches; *iter; iter++) { + if (!nm_setting_ip_config_add_dns_search(s_ip6, *iter)) + PARSE_WARNING("duplicate DNS domain '%s'", *iter); + } } } } @@ -2957,7 +2986,7 @@ read_dcb_percent_array(shvarFile * ifcfg, return TRUE; } - split = nm_utils_strsplit_set(val, ","); + split = nm_strsplit_set(val, ","); if (NM_PTRARRAY_LEN(split) != 8) { PARSE_WARNING("invalid %s percentage list value '%s'", prop, val); g_set_error_literal(error, @@ -3001,6 +3030,7 @@ make_dcb_setting(shvarFile *ifcfg, NMSetting **out_setting, GError **error) gs_unref_object NMSettingDcb *s_dcb = NULL; gboolean dcb_on; NMSettingDcbFlags flags = NM_SETTING_DCB_FLAG_NONE; + gs_free char * val = NULL; g_return_val_if_fail(out_setting, FALSE); *out_setting = NULL; @@ -3020,21 +3050,18 @@ make_dcb_setting(shvarFile *ifcfg, NMSetting **out_setting, GError **error) error)) { return FALSE; } - if (nm_setting_dcb_get_app_fcoe_flags(s_dcb) & NM_SETTING_DCB_FLAG_ENABLE) { - gs_free char *val = NULL; - val = svGetValueStr_cp(ifcfg, KEY_DCB_APP_FCOE_MODE); - if (val) { - if (NM_IN_STRSET(val, NM_SETTING_DCB_FCOE_MODE_FABRIC, NM_SETTING_DCB_FCOE_MODE_VN2VN)) - g_object_set(G_OBJECT(s_dcb), NM_SETTING_DCB_APP_FCOE_MODE, val, NULL); - else { - PARSE_WARNING("invalid FCoE mode '%s'", val); - g_set_error_literal(error, - NM_SETTINGS_ERROR, - NM_SETTINGS_ERROR_INVALID_CONNECTION, - "invalid FCoE mode"); - return FALSE; - } + val = svGetValueStr_cp(ifcfg, KEY_DCB_APP_FCOE_MODE); + if (val) { + if (NM_IN_STRSET(val, NM_SETTING_DCB_FCOE_MODE_FABRIC, NM_SETTING_DCB_FCOE_MODE_VN2VN)) + g_object_set(G_OBJECT(s_dcb), NM_SETTING_DCB_APP_FCOE_MODE, val, NULL); + else { + PARSE_WARNING("invalid FCoE mode '%s'", val); + g_set_error_literal(error, + NM_SETTINGS_ERROR, + NM_SETTINGS_ERROR_INVALID_CONNECTION, + "invalid FCoE mode"); + return FALSE; } } @@ -3376,7 +3403,7 @@ fill_wpa_ciphers(shvarFile *ifcfg, NMSettingWirelessSecurity *wsec, gboolean gro if (!p) return TRUE; - list = nm_utils_strsplit_set(p, " "); + list = nm_strsplit_set(p, " "); for (iter = list; iter && *iter; iter++, i++) { if (!strcmp(*iter, "CCMP")) { if (group) @@ -3612,7 +3639,7 @@ parse_8021x_phase2_auth(shvarFile * ifcfg, } inner_auth = g_ascii_strdown(v, -1); - list = nm_utils_strsplit_set(inner_auth, " "); + list = nm_strsplit_set(inner_auth, " "); for (iter = list; iter && *iter; iter++) { if (NM_IN_STRSET(*iter, "pap", "chap", "mschap", "mschapv2", "gtc", "otp", "md5")) { if (num_auth == 0) { @@ -3787,7 +3814,7 @@ eap_fast_reader(const char * eap_method, if (fast_provisioning) { gs_free const char **list = NULL; - list = nm_utils_strsplit_set(fast_provisioning, " \t"); + list = nm_strsplit_set(fast_provisioning, " \t"); for (iter = list; iter && *iter; iter++) { if (strcmp(*iter, "allow-unauth") == 0) allow_unauth = TRUE; @@ -3865,7 +3892,7 @@ read_8021x_list_value(shvarFile * ifcfg, if (!v) return; - strv = nm_utils_strsplit_set(v, " \t"); + strv = nm_strsplit_set(v, " \t"); if (strv) g_object_set(setting, prop_name, strv, NULL); } @@ -3892,7 +3919,7 @@ fill_8021x(shvarFile *ifcfg, const char *file, const char *key_mgmt, gboolean wi return NULL; } - list = nm_utils_strsplit_set(v, " "); + list = nm_strsplit_set(v, " "); s_8021x = (NMSetting8021x *) nm_setting_802_1x_new(); @@ -4245,7 +4272,7 @@ transform_hwaddr_blacklist(const char *blacklist) const char **strv; gsize i, j; - strv = nm_utils_strsplit_set(blacklist, " \t"); + strv = nm_strsplit_set(blacklist, " \t"); if (!strv) return NULL; for (i = 0, j = 0; strv[j]; j++) { @@ -4714,7 +4741,7 @@ parse_ethtool_option(const char * value, gs_free const char **words = NULL; NMEthtoolType ethtool_type = NM_ETHTOOL_TYPE_UNKNOWN; - words = nm_utils_strsplit_set(value, " \t\n"); + words = nm_strsplit_set(value, " \t\n"); if (!words) return; @@ -4976,7 +5003,7 @@ parse_ethtool_options(shvarFile *ifcfg, NMConnection *connection) gs_free const char **opts = NULL; const char *const * iter; - opts = nm_utils_strsplit_set(ethtool_opts, ";"); + opts = nm_strsplit_set(ethtool_opts, ";"); for (iter = opts; iter && iter[0]; iter++) { /* in case of repeated wol_passwords, parse_ethtool_option() * will do the right thing and clear wol_password before resetting. */ @@ -5084,7 +5111,7 @@ make_wired_setting(shvarFile *ifcfg, const char *file, NMSetting8021x **s_8021x, gs_free const char **chans = NULL; guint32 num_chans; - chans = nm_utils_strsplit_set(cvalue, ","); + chans = nm_strsplit_set(cvalue, ","); num_chans = NM_PTRARRAY_LEN(chans); if (num_chans < 2 || num_chans > 3) { PARSE_WARNING("invalid SUBCHANNELS '%s' (%u channels, 2 or 3 expected)", @@ -5456,7 +5483,7 @@ make_bond_setting(shvarFile *ifcfg, const char *file, GError **error) gs_free const char **items = NULL; const char *const * iter; - items = nm_utils_strsplit_set(v, " "); + items = nm_strsplit_set(v, " "); for (iter = items; iter && *iter; iter++) { gs_free char *key = NULL; const char * val; @@ -5474,6 +5501,31 @@ make_bond_setting(shvarFile *ifcfg, const char *file, GError **error) return (NMSetting *) s_bond; } +static NMSetting * +make_bond_port_setting(shvarFile *ifcfg) +{ + NMSetting * s_port = NULL; + gs_free char *value_to_free = NULL; + const char * value; + guint queue_id; + + g_return_val_if_fail(ifcfg != NULL, FALSE); + + value = svGetValue(ifcfg, "BOND_PORT_QUEUE_ID", &value_to_free); + if (value) { + s_port = nm_setting_bond_port_new(); + queue_id = + _nm_utils_ascii_str_to_uint64(value, 10, 0, G_MAXUINT16, NM_BOND_PORT_QUEUE_ID_DEF); + if (errno != 0) { + PARSE_WARNING("Invalid bond port queue_id value '%s'", value); + return s_port; + } + g_object_set(G_OBJECT(s_port), NM_SETTING_BOND_PORT_QUEUE_ID, queue_id, NULL); + } + + return s_port; +} + static NMConnection * bond_connection_from_ifcfg(const char *file, shvarFile *ifcfg, GError **error) { @@ -5766,7 +5818,7 @@ handle_bridging_opts(NMSetting * setting, gs_free const char **items = NULL; const char *const * iter; - items = nm_utils_strsplit_set(value, " "); + items = nm_strsplit_set(value, " "); for (iter = items; iter && *iter; iter++) { gs_free char *key = NULL; const char * val; @@ -6027,7 +6079,7 @@ parse_prio_map_list(NMSettingVlan *s_vlan, shvarFile *ifcfg, const char *key, NM v = svGetValueStr(ifcfg, key, &value); if (!v) return; - list = nm_utils_strsplit_set(v, ","); + list = nm_strsplit_set(v, ","); for (iter = list; iter && *iter; iter++) { if (!strchr(*iter, ':')) @@ -6138,7 +6190,7 @@ make_vlan_setting(shvarFile *ifcfg, const char *file, GError **error) gs_free const char **strv = NULL; const char *const * ptr; - strv = nm_utils_strsplit_set(v, ", "); + strv = nm_strsplit_set(v, ", "); for (ptr = strv; ptr && *ptr; ptr++) { if (nm_streq(*ptr, "GVRP") && gvrp == -1) vlan_flags |= NM_VLAN_FLAG_GVRP; @@ -6284,7 +6336,7 @@ check_dns_search_domains(shvarFile *ifcfg, NMSetting *s_ip4, NMSetting *s_ip6) gs_free const char **searches = NULL; const char *const * item; - searches = nm_utils_strsplit_set(v, " "); + searches = nm_strsplit_set(v, " "); if (searches) { for (item = searches; *item; item++) { if (!nm_setting_ip_config_add_dns_search(NM_SETTING_IP_CONFIG(s_ip6), *item)) @@ -6641,6 +6693,10 @@ connection_from_file_full(const char *filename, if (setting) nm_connection_add_setting(connection, setting); + setting = make_bond_port_setting(main_ifcfg); + if (setting) + nm_connection_add_setting(connection, setting); + setting = make_team_port_setting(main_ifcfg); if (setting) nm_connection_add_setting(connection, setting); diff --git a/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-storage.c b/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-storage.c index 134bdf68..3feb4440 100644 --- a/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-storage.c +++ b/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-storage.c @@ -112,7 +112,7 @@ nms_ifcfg_rh_storage_new_connection(NMSIfcfgRHPlugin * plugin, nm_assert(NM_IS_CONNECTION(connection_take)); nm_assert(_nm_connection_verify(connection_take, NULL) == NM_SETTING_VERIFY_SUCCESS); - nmtst_connection_assert_unchanging(connection_take); + nm_assert_connection_unchanging(connection_take); self = _storage_new(plugin, nm_connection_get_uuid(connection_take), filename); self->connection = connection_take; diff --git a/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.c b/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.c index febfc120..1afdf8ee 100644 --- a/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.c +++ b/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.c @@ -827,6 +827,7 @@ const NMSIfcfgKeyTypeInfo nms_ifcfg_well_known_keys[] = { _KEY_TYPE("BAND", NMS_IFCFG_KEY_TYPE_IS_PLAIN), _KEY_TYPE("BONDING_MASTER", NMS_IFCFG_KEY_TYPE_IS_PLAIN), _KEY_TYPE("BONDING_OPTS", NMS_IFCFG_KEY_TYPE_IS_PLAIN), + _KEY_TYPE("BOND_PORT_QUEUE_ID", NMS_IFCFG_KEY_TYPE_IS_PLAIN), _KEY_TYPE("BOOTPROTO", NMS_IFCFG_KEY_TYPE_IS_PLAIN), _KEY_TYPE("BRIDGE", NMS_IFCFG_KEY_TYPE_IS_PLAIN), _KEY_TYPE("BRIDGE_MACADDR", NMS_IFCFG_KEY_TYPE_IS_PLAIN), @@ -891,6 +892,7 @@ const NMSIfcfgKeyTypeInfo nms_ifcfg_well_known_keys[] = { _KEY_TYPE("DHCPv6_DUID", NMS_IFCFG_KEY_TYPE_IS_PLAIN), _KEY_TYPE("DHCPv6_IAID", NMS_IFCFG_KEY_TYPE_IS_PLAIN), _KEY_TYPE("DNS", NMS_IFCFG_KEY_TYPE_IS_NUMBERED), + _KEY_TYPE("DNS_OVER_TLS", NMS_IFCFG_KEY_TYPE_IS_PLAIN), _KEY_TYPE("DOMAIN", NMS_IFCFG_KEY_TYPE_IS_PLAIN), _KEY_TYPE("ESSID", NMS_IFCFG_KEY_TYPE_IS_PLAIN), _KEY_TYPE("ETHTOOL_OPTS", NMS_IFCFG_KEY_TYPE_IS_PLAIN), diff --git a/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.h b/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.h index b7751ec9..6b396a9a 100644 --- a/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.h +++ b/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.h @@ -33,7 +33,7 @@ typedef struct { NMSIfcfgKeyTypeFlags key_flags; } NMSIfcfgKeyTypeInfo; -extern const NMSIfcfgKeyTypeInfo nms_ifcfg_well_known_keys[251]; +extern const NMSIfcfgKeyTypeInfo nms_ifcfg_well_known_keys[253]; const NMSIfcfgKeyTypeInfo *nms_ifcfg_well_known_key_find_info(const char *key, gssize *out_idx); diff --git a/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c b/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c index ef85b6bf..263c9253 100644 --- a/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c +++ b/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c @@ -19,6 +19,7 @@ #include "libnm-glib-aux/nm-str-buf.h" #include "libnm-glib-aux/nm-io-utils.h" #include "nm-manager.h" +#include "nm-setting-bond-port.h" #include "nm-setting-connection.h" #include "nm-setting-wired.h" #include "nm-setting-wireless.h" @@ -204,18 +205,18 @@ write_object(NMSetting8021x * s_8021x, g_return_val_if_fail(ifcfg != NULL, FALSE); g_return_val_if_fail(objtype != NULL, FALSE); - scheme = (*(objtype->vtable->scheme_func)) (s_8021x); + scheme = (*(objtype->vtable->scheme_func))(s_8021x); switch (scheme) { case NM_SETTING_802_1X_CK_SCHEME_UNKNOWN: break; case NM_SETTING_802_1X_CK_SCHEME_BLOB: - blob = (*(objtype->vtable->blob_func)) (s_8021x); + blob = (*(objtype->vtable->blob_func))(s_8021x); break; case NM_SETTING_802_1X_CK_SCHEME_PATH: - value = (*(objtype->vtable->path_func)) (s_8021x); + value = (*(objtype->vtable->path_func))(s_8021x); break; case NM_SETTING_802_1X_CK_SCHEME_PKCS11: - value = (*(objtype->vtable->uri_func)) (s_8021x); + value = (*(objtype->vtable->uri_func))(s_8021x); break; default: g_set_error(error, @@ -228,8 +229,8 @@ write_object(NMSetting8021x * s_8021x, /* Set the password for certificate/private key. */ nm_sprintf_buf(secret_name, "%s_PASSWORD", objtype->ifcfg_rh_key); nm_sprintf_buf(secret_flags, "%s_PASSWORD_FLAGS", objtype->ifcfg_rh_key); - password = (*(objtype->vtable->passwd_func)) (s_8021x); - flags = (*(objtype->vtable->pwflag_func)) (s_8021x); + password = (*(objtype->vtable->passwd_func))(s_8021x); + flags = (*(objtype->vtable->pwflag_func))(s_8021x); set_secret(ifcfg, secrets, secret_name, password, secret_flags, flags); if (!objtype->vtable->format_func) @@ -1442,12 +1443,12 @@ write_vlan_setting(NMConnection *connection, shvarFile *ifcfg, gboolean *wired, svSetValueBoolean(ifcfg, "REORDER_HDR", NM_FLAGS_HAS(vlan_flags, NM_VLAN_FLAG_REORDER_HEADERS)); svSetValueBoolean(ifcfg, "GVRP", NM_FLAGS_HAS(vlan_flags, NM_VLAN_FLAG_GVRP)); - nm_utils_strbuf_init(s_buf, &s_buf_ptr, &s_buf_len); + nm_strbuf_init_arr(s_buf, &s_buf_ptr, &s_buf_len); if (NM_FLAGS_HAS(vlan_flags, NM_VLAN_FLAG_LOOSE_BINDING)) - nm_utils_strbuf_append_str(&s_buf_ptr, &s_buf_len, "LOOSE_BINDING"); + nm_strbuf_append_str(&s_buf_ptr, &s_buf_len, "LOOSE_BINDING"); if (!NM_FLAGS_HAS(vlan_flags, NM_VLAN_FLAG_REORDER_HEADERS)) - nm_utils_strbuf_append(&s_buf_ptr, &s_buf_len, "%sNO_REORDER_HDR", s_buf[0] ? "," : ""); + nm_strbuf_append(&s_buf_ptr, &s_buf_len, "%sNO_REORDER_HDR", s_buf[0] ? "," : ""); svSetValueStr(ifcfg, "VLAN_FLAGS", s_buf); @@ -1888,6 +1889,16 @@ write_bridge_port_setting(NMConnection *connection, shvarFile *ifcfg, GError **e return TRUE; } +static void +write_bond_port_setting(NMConnection *connection, shvarFile *ifcfg) +{ + NMSettingBondPort *s_port; + + s_port = _nm_connection_get_setting(connection, NM_TYPE_SETTING_BOND_PORT); + if (s_port) + svSetValueInt64(ifcfg, "BOND_PORT_QUEUE_ID", nm_setting_bond_port_get_queue_id(s_port)); +} + static gboolean write_team_port_setting(NMConnection *connection, shvarFile *ifcfg, GError **error) { @@ -2020,8 +2031,7 @@ write_dcb_setting(NMConnection *connection, shvarFile *ifcfg, GError **error) "APP_FCOE", nm_setting_dcb_get_app_fcoe_flags(s_dcb), nm_setting_dcb_get_app_fcoe_priority(s_dcb)); - if (nm_setting_dcb_get_app_fcoe_flags(s_dcb) & NM_SETTING_DCB_FLAG_ENABLE) - svSetValueStr(ifcfg, KEY_DCB_APP_FCOE_MODE, nm_setting_dcb_get_app_fcoe_mode(s_dcb)); + svSetValueStr(ifcfg, KEY_DCB_APP_FCOE_MODE, nm_setting_dcb_get_app_fcoe_mode(s_dcb)); write_dcb_app(ifcfg, "APP_ISCSI", @@ -2076,6 +2086,7 @@ write_connection_setting(NMSettingConnection *s_con, shvarFile *ifcfg) gint32 vint32; NMSettingConnectionMdns mdns; NMSettingConnectionLlmnr llmnr; + NMSettingConnectionDnsOverTls dns_over_tls; guint32 vuint32; const char * tmp, *mud_url; @@ -2259,6 +2270,14 @@ write_connection_setting(NMSettingConnection *s_con, shvarFile *ifcfg) if (llmnr != NM_SETTING_CONNECTION_LLMNR_DEFAULT) { svSetValueEnum(ifcfg, "LLMNR", nm_setting_connection_llmnr_get_type(), llmnr); } + + dns_over_tls = nm_setting_connection_get_dns_over_tls(s_con); + if (dns_over_tls != NM_SETTING_CONNECTION_DNS_OVER_TLS_DEFAULT) { + svSetValueEnum(ifcfg, + "DNS_OVER_TLS", + nm_setting_connection_dns_over_tls_get_type(), + dns_over_tls); + } } static char * @@ -2685,12 +2704,11 @@ write_dns_setting(shvarFile *ifcfg, NMConnection *connection, int addr_family) } } -static gboolean +static void write_ip4_setting(NMConnection *connection, shvarFile * ifcfg, shvarFile ** out_route_content_svformat, - GString ** out_route_content, - GError ** error) + GString ** out_route_content) { NMSettingIPConfig * s_ip4; const char * value; @@ -2713,7 +2731,7 @@ write_ip4_setting(NMConnection *connection, s_ip4 = nm_connection_get_setting_ip4_config(connection); if (!s_ip4) - return TRUE; + return; method = nm_setting_ip_config_get_method(s_ip4); @@ -2722,7 +2740,7 @@ write_ip4_setting(NMConnection *connection, method = NM_SETTING_IP4_CONFIG_METHOD_AUTO; if (nm_streq(method, NM_SETTING_IP4_CONFIG_METHOD_DISABLED)) - return TRUE; + return; num = nm_setting_ip_config_get_num_addresses(s_ip4); @@ -2881,8 +2899,6 @@ write_ip4_setting(NMConnection *connection, } svSetValueStr(ifcfg, "DHCP_REJECT_SERVERS", str->str); } - - return TRUE; } static void @@ -2968,11 +2984,8 @@ write_ip4_aliases(NMConnection *connection, const char *base_ifcfg_path) } } -static gboolean -write_ip6_setting(NMConnection *connection, - shvarFile * ifcfg, - GString ** out_route6_content, - GError ** error) +static void +write_ip6_setting(NMConnection *connection, shvarFile *ifcfg, GString **out_route6_content) { NMSettingIPConfig * s_ip6; const char * value; @@ -2991,17 +3004,15 @@ write_ip6_setting(NMConnection *connection, s_ip6 = nm_connection_get_setting_ip6_config(connection); if (!s_ip6) - return TRUE; + return; value = nm_setting_ip_config_get_method(s_ip6); g_assert(value); if (!strcmp(value, NM_SETTING_IP6_CONFIG_METHOD_IGNORE)) { svSetValueStr(ifcfg, "IPV6INIT", "no"); - return TRUE; } else if (!strcmp(value, NM_SETTING_IP6_CONFIG_METHOD_DISABLED)) { svSetValueStr(ifcfg, "IPV6_DISABLED", "yes"); svSetValueStr(ifcfg, "IPV6INIT", "no"); - return TRUE; } else if (!strcmp(value, NM_SETTING_IP6_CONFIG_METHOD_AUTO)) { svSetValueStr(ifcfg, "IPV6INIT", "yes"); svSetValueStr(ifcfg, "IPV6_AUTOCONF", "yes"); @@ -3148,8 +3159,6 @@ write_ip6_setting(NMConnection *connection, write_res_options(ifcfg, s_ip6, "IPV6_RES_OPTIONS"); NM_SET_OUT(out_route6_content, write_route_file(s_ip6)); - - return TRUE; } static void @@ -3228,10 +3237,11 @@ do_write_construct(NMConnection * connection, GError ** error) { NMSettingConnection * s_con; - nm_auto_shvar_file_close shvarFile *ifcfg = NULL; - gs_free char * ifcfg_name = NULL; - gs_free char * route_path = NULL; - gs_free char * route6_path = NULL; + nm_auto_shvar_file_close shvarFile *ifcfg = NULL; + const char * ifcfg_name; + gs_free char * ifcfg_name_free = NULL; + gs_free char * route_path = NULL; + gs_free char * route6_path = NULL; const char * type; gs_unref_hashtable GHashTable *blobs = NULL; gs_unref_hashtable GHashTable *secrets = NULL; @@ -3255,11 +3265,7 @@ do_write_construct(NMConnection * connection, if (filename) { /* For existing connections, 'filename' should be full path to ifcfg file */ - ifcfg = svOpenFile(filename, error); - if (!ifcfg) - return FALSE; - - ifcfg_name = g_strdup(filename); + ifcfg_name = filename; } else if (ifcfg_dir) { gs_free char *escaped = NULL; int i_path; @@ -3280,21 +3286,27 @@ do_write_construct(NMConnection * connection, if (g_file_test(path_candidate, G_FILE_TEST_EXISTS)) continue; - ifcfg_name = g_steal_pointer(&path_candidate); + ifcfg_name_free = g_steal_pointer(&path_candidate); break; } - if (!ifcfg_name) { + if (!ifcfg_name_free) { g_set_error_literal(error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, "Failed to find usable ifcfg file name"); return FALSE; } + ifcfg_name = ifcfg_name_free; + } else { + g_set_error(error, + NM_SETTINGS_ERROR, + NM_SETTINGS_ERROR_FAILED, + "No file name given for storing profile to ifcfg-rh"); + g_return_val_if_reached(FALSE); + } - ifcfg = svCreateFile(ifcfg_name); - } else - ifcfg = svCreateFile("/tmp/ifcfg-dummy"); + ifcfg = svCreateFile(ifcfg_name); route_path = utils_get_route_path(svFileGetName(ifcfg)); if (!route_path) { @@ -3377,6 +3389,8 @@ do_write_construct(NMConnection * connection, if (!write_bridge_port_setting(connection, ifcfg, error)) return FALSE; + write_bond_port_setting(connection, ifcfg); + if (!write_team_port_setting(connection, ifcfg, error)) return FALSE; @@ -3441,15 +3455,12 @@ do_write_construct(NMConnection * connection, } else route_ignore = FALSE; - if (!write_ip4_setting(connection, - ifcfg, - !route_ignore && route_path_is_svformat ? &route_content_svformat : NULL, - !route_ignore && route_path_is_svformat ? NULL : &route_content, - error)) - return FALSE; + write_ip4_setting(connection, + ifcfg, + !route_ignore && route_path_is_svformat ? &route_content_svformat : NULL, + !route_ignore && route_path_is_svformat ? NULL : &route_content); - if (!write_ip6_setting(connection, ifcfg, !route_ignore ? &route6_content : NULL, error)) - return FALSE; + write_ip6_setting(connection, ifcfg, !route_ignore ? &route6_content : NULL); write_ip_routing_rules(connection, ifcfg, route_ignore); diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-System_test-wired-802-1X-subj-matches.cexpected b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-System_test-wired-802-1X-subj-matches.cexpected index 240cd5c1..d2f5c453 100644 --- a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-System_test-wired-802-1X-subj-matches.cexpected +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-System_test-wired-802-1X-subj-matches.cexpected @@ -16,6 +16,8 @@ BOOTPROTO=dhcp DEFROUTE=yes IPV4_FAILURE_FATAL=no IPV6INIT=no +IPV6_DEFROUTE=yes +IPV6_FAILURE_FATAL=no NAME="System test-wired-802-1X-subj-matches" UUID=${UUID} DEVICE=eth0 diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_Bond_Main.cexpected b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_Bond_Main.cexpected index b288c04a..ccc0f35a 100644 --- a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_Bond_Main.cexpected +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_Bond_Main.cexpected @@ -11,6 +11,9 @@ GATEWAY=1.1.1.1 DEFROUTE=yes IPV4_FAILURE_FATAL=no IPV6INIT=no +IPV6_DEFROUTE=yes +IPV6_FAILURE_FATAL=no +IPV6_ADDR_GEN_MODE=stable-privacy NAME="Test Write Bond Main" UUID=${UUID} DEVICE=bond0 diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_Permissions.cexpected b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_Permissions.cexpected index 80e96921..d4a978b6 100644 --- a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_Permissions.cexpected +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_Permissions.cexpected @@ -5,6 +5,9 @@ BOOTPROTO=dhcp DEFROUTE=yes IPV4_FAILURE_FATAL=no IPV6INIT=no +IPV6_DEFROUTE=yes +IPV6_FAILURE_FATAL=no +IPV6_ADDR_GEN_MODE=stable-privacy NAME="Test Write Permissions" UUID=${UUID} ONBOOT=yes diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_Wifi_LEAP.cexpected b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_Wifi_LEAP.cexpected index d3db19b2..f1b01a21 100644 --- a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_Wifi_LEAP.cexpected +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_Wifi_LEAP.cexpected @@ -11,6 +11,9 @@ BOOTPROTO=dhcp DEFROUTE=yes IPV4_FAILURE_FATAL=no IPV6INIT=no +IPV6_DEFROUTE=yes +IPV6_FAILURE_FATAL=no +IPV6_ADDR_GEN_MODE=stable-privacy NAME="Test Write Wifi LEAP" UUID=${UUID} ONBOOT=yes diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_Wifi_WEP_104_ASCII.cexpected b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_Wifi_WEP_104_ASCII.cexpected index 32db7262..60540fbe 100644 --- a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_Wifi_WEP_104_ASCII.cexpected +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_Wifi_WEP_104_ASCII.cexpected @@ -10,6 +10,9 @@ BOOTPROTO=dhcp DEFROUTE=yes IPV4_FAILURE_FATAL=no IPV6INIT=no +IPV6_DEFROUTE=yes +IPV6_FAILURE_FATAL=no +IPV6_ADDR_GEN_MODE=stable-privacy NAME="Test Write Wifi WEP 104 ASCII" UUID=${UUID} ONBOOT=yes diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_Wired_Static_Routes.cexpected b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_Wired_Static_Routes.cexpected index cc29a2cc..fe864c43 100644 --- a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_Wired_Static_Routes.cexpected +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_Wired_Static_Routes.cexpected @@ -17,6 +17,8 @@ IPV4_FAILURE_FATAL=no ACD_TIMEOUT=400 ARPING_WAIT=1 IPV6INIT=no +IPV6_DEFROUTE=yes +IPV6_FAILURE_FATAL=no NAME="Test Write Wired Static Routes" UUID=${UUID} ONBOOT=yes diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_Wired_match.cexpected b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_Wired_match.cexpected index 9499278e..908cb917 100644 --- a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_Wired_match.cexpected +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_Wired_match.cexpected @@ -8,6 +8,8 @@ BOOTPROTO=dhcp DEFROUTE=yes IPV4_FAILURE_FATAL=no IPV6INIT=no +IPV6_DEFROUTE=yes +IPV6_FAILURE_FATAL=no NAME="Test Write Wired with Match setting" UUID=${UUID} ONBOOT=yes diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Vlan_test-vlan-interface.cexpected b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Vlan_test-vlan-interface.cexpected index 44eb777c..6ad151aa 100644 --- a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Vlan_test-vlan-interface.cexpected +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Vlan_test-vlan-interface.cexpected @@ -17,6 +17,8 @@ PREFIX=24 DEFROUTE=yes IPV4_FAILURE_FATAL=no IPV6INIT=no +IPV6_DEFROUTE=yes +IPV6_FAILURE_FATAL=no NAME="Vlan test-vlan-interface" UUID=${UUID} DEVICE=vlan43 diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-dcb-test.cexpected b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-dcb-test.cexpected index 56e233cc..fef36f2f 100644 --- a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-dcb-test.cexpected +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-dcb-test.cexpected @@ -4,7 +4,6 @@ DCB_APP_FCOE_ENABLE=yes DCB_APP_FCOE_ADVERTISE=yes DCB_APP_FCOE_WILLING=yes DCB_APP_FCOE_PRIORITY=5 -DCB_APP_FCOE_MODE=fabric DCB_APP_ISCSI_ENABLE=yes DCB_APP_ISCSI_ADVERTISE=yes DCB_APP_ISCSI_WILLING=yes diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-random_wifi_connection.cexpected b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-random_wifi_connection.cexpected index ead3a047..1f5e04ff 100644 --- a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-random_wifi_connection.cexpected +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-random_wifi_connection.cexpected @@ -8,6 +8,8 @@ BOOTPROTO=dhcp DEFROUTE=yes IPV4_FAILURE_FATAL=no IPV6INIT=no +IPV6_DEFROUTE=yes +IPV6_FAILURE_FATAL=no NAME="random wifi connection" UUID=${UUID} ONBOOT=yes diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-random_wifi_connection_2.cexpected b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-random_wifi_connection_2.cexpected index 7bc1ae6c..3dcdbda0 100644 --- a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-random_wifi_connection_2.cexpected +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-random_wifi_connection_2.cexpected @@ -8,6 +8,8 @@ BOOTPROTO=dhcp DEFROUTE=yes IPV4_FAILURE_FATAL=no IPV6INIT=no +IPV6_DEFROUTE=yes +IPV6_FAILURE_FATAL=no NAME="random wifi connection 2" UUID=${UUID} ONBOOT=yes diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-bond-port b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-bond-port new file mode 100644 index 00000000..111924c0 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-bond-port @@ -0,0 +1,9 @@ +TYPE=Ethernet +NAME=eth0 +UUID=43737e70-7c4f-4b67-9f4f-6d2d4747b1ff +DEVICE=eth0 +ONBOOT=yes +LLDP=no +MASTER=bond99 +SLAVE=yes +BOND_PORT_QUEUE_ID=1 diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-ip6-disabled.cexpected b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-ip6-disabled.cexpected index cae51b89..b3199c01 100644 --- a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-ip6-disabled.cexpected +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-ip6-disabled.cexpected @@ -6,6 +6,8 @@ DEFROUTE=yes IPV4_FAILURE_FATAL=no IPV6_DISABLED=yes IPV6INIT=no +IPV6_DEFROUTE=yes +IPV6_FAILURE_FATAL=no NAME="Test Write Wired Disabled IP6" UUID=${UUID} ONBOOT=yes diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-sriov-write.cexpected b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-sriov-write.cexpected index c882c479..a77c615d 100644 --- a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-sriov-write.cexpected +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-sriov-write.cexpected @@ -12,6 +12,9 @@ GATEWAY=1.1.1.1 DEFROUTE=yes IPV4_FAILURE_FATAL=no IPV6INIT=no +IPV6_DEFROUTE=yes +IPV6_FAILURE_FATAL=no +IPV6_ADDR_GEN_MODE=stable-privacy NAME="Test Write SR-IOV config" UUID=${UUID} DEVICE=eth0 diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-static-routes-legacy.cexpected b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-static-routes-legacy.cexpected index 8197f320..41714df6 100644 --- a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-static-routes-legacy.cexpected +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-static-routes-legacy.cexpected @@ -6,6 +6,8 @@ BOOTPROTO=dhcp DEFROUTE=yes IPV4_FAILURE_FATAL=no IPV6INIT=no +IPV6_DEFROUTE=yes +IPV6_FAILURE_FATAL=no NAME=test-static-routes-legacy UUID=ba60d05a-7898-820d-c2db-427a88f8f2a5 DEVICE=eth0 diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-tc-write-empty.cexpected b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-tc-write-empty.cexpected index 4df768b4..1125ef55 100644 --- a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-tc-write-empty.cexpected +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-tc-write-empty.cexpected @@ -9,6 +9,9 @@ GATEWAY=1.1.1.1 DEFROUTE=yes IPV4_FAILURE_FATAL=no IPV6INIT=no +IPV6_DEFROUTE=yes +IPV6_FAILURE_FATAL=no +IPV6_ADDR_GEN_MODE=stable-privacy NAME="Test Write TC config" UUID=${UUID} DEVICE=eth0 diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-tc-write.cexpected b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-tc-write.cexpected index a67ca598..d87efd72 100644 --- a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-tc-write.cexpected +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-tc-write.cexpected @@ -10,6 +10,9 @@ GATEWAY=1.1.1.1 DEFROUTE=yes IPV4_FAILURE_FATAL=no IPV6INIT=no +IPV6_DEFROUTE=yes +IPV6_FAILURE_FATAL=no +IPV6_ADDR_GEN_MODE=stable-privacy NAME="Test Write TC config" UUID=${UUID} DEVICE=eth0 diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-vlan-vlanid-use.cexpected b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-vlan-vlanid-use.cexpected index a7be14ce..2eaec850 100644 --- a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-vlan-vlanid-use.cexpected +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-vlan-vlanid-use.cexpected @@ -9,6 +9,8 @@ HWADDR= PROXY_METHOD=none BROWSER_ONLY=no IPV6INIT=no +IPV6_DEFROUTE=yes +IPV6_FAILURE_FATAL=no NAME="Vlan test-vlan-vlanid-use" UUID=${UUID} DEVICE=eth0.9 diff --git a/src/core/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c b/src/core/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c index d9829f84..b1cfdfec 100644 --- a/src/core/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c +++ b/src/core/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c @@ -167,9 +167,8 @@ _assert_expected_content(NMConnection *connection, const char *filename, const c g_string_erase(str, i, NM_STRLEN("${UUID}")); g_string_insert_len(str, i, uuid, j); - g_free(content_expectd); - len_expectd = str->len; - content_expectd = g_string_free(str, FALSE); + len_expectd = str->len; + nm_strdup_reset_take(&content_expectd, g_string_free(str, FALSE)); i += j; continue; } @@ -344,7 +343,7 @@ _writer_new_connection_reread(NMConnection * connection, { gboolean success; GError * error = NULL; - char * filename = NULL; + gs_free char * filename = NULL; gs_unref_object NMConnection *con_verified = NULL; gs_unref_object NMConnection *reread_copy = NULL; NMConnection **reread = out_reread ?: ((nmtst_get_rand_uint32() % 2) ? &reread_copy : NULL); @@ -372,11 +371,9 @@ _writer_new_connection_reread(NMConnection * connection, _assert_expected_content(con_verified, filename, expected); if (out_filename) - *out_filename = filename; - else { + *out_filename = g_steal_pointer(&filename); + else nmtst_file_unlink(filename); - g_free(filename); - } } static void @@ -467,12 +464,10 @@ test_read_netmask_1(void) connection = _connection_from_file(FILENAME, NULL, TYPE_ETHERNET, NULL); - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con); + s_con = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); g_assert_cmpstr(nm_setting_connection_get_id(s_con), ==, "System netmask-1"); - s_ip4 = nm_connection_get_setting_ip4_config(connection); - g_assert(s_ip4); + s_ip4 = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_assert_cmpuint(nm_setting_ip_config_get_num_dns(s_ip4), ==, 1); ip4_addr = nm_setting_ip_config_get_address(s_ip4, 0); g_assert(ip4_addr); @@ -501,12 +496,12 @@ verify_cert_or_key(NMSetting8021x *s_compare, const char * privkey_password, const char * property) { - NMSetting8021x * s_8021x; - GError * error = NULL; - gboolean success = FALSE; - const char * expected = NULL, *setting = NULL; - gboolean phase2 = FALSE; - NMSetting8021xCKScheme scheme = NM_SETTING_802_1X_CK_SCHEME_UNKNOWN; + gs_unref_object NMSetting8021x *s_8021x = NULL; + GError * error = NULL; + gboolean success = FALSE; + const char * expected = NULL, *setting = NULL; + gboolean phase2 = FALSE; + NMSetting8021xCKScheme scheme = NM_SETTING_802_1X_CK_SCHEME_UNKNOWN; if (strstr(property, "phase2")) phase2 = TRUE; @@ -615,28 +610,24 @@ verify_cert_or_key(NMSetting8021x *s_compare, setting = nm_setting_802_1x_get_private_key_path(s_compare); } g_assert_cmpstr(setting, ==, expected); - - g_object_unref(s_8021x); return TRUE; } static void test_read_basic(void) { - NMConnection * connection; - NMSettingConnection *s_con; - NMSettingWired * s_wired; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; - const char * mac; - char expected_mac_address[ETH_ALEN] = {0x00, 0x16, 0x41, 0x11, 0x22, 0x33}; + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection * s_con; + NMSettingWired * s_wired; + NMSettingIPConfig * s_ip4; + NMSettingIPConfig * s_ip6; + const char * mac; + char expected_mac_address[ETH_ALEN] = {0x00, 0x16, 0x41, 0x11, 0x22, 0x33}; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-minimal", NULL, TYPE_ETHERNET, NULL); - /* ===== CONNECTION SETTING ===== */ - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con); + s_con = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); g_assert_cmpstr(nm_setting_connection_get_id(s_con), ==, "System test-minimal"); g_assert_cmpint(nm_setting_connection_get_timestamp(s_con), ==, 0); g_assert(nm_setting_connection_get_autoconnect(s_con)); @@ -647,47 +638,38 @@ test_read_basic(void) * depending on where the tests are run. */ - /* ===== WIRED SETTING ===== */ - s_wired = nm_connection_get_setting_wired(connection); - g_assert(s_wired); + s_wired = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRED); g_assert_cmpint(nm_setting_wired_get_mtu(s_wired), ==, 0); - /* MAC address */ mac = nm_setting_wired_get_mac_address(s_wired); g_assert(mac); g_assert(nm_utils_hwaddr_matches(mac, -1, expected_mac_address, ETH_ALEN)); - /* ===== IPv4 SETTING ===== */ - s_ip4 = nm_connection_get_setting_ip4_config(connection); - g_assert(s_ip4); + s_ip4 = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_DISABLED); g_assert(nm_setting_ip_config_get_never_default(s_ip4) == FALSE); - /* ===== IPv6 SETTING ===== */ - s_ip6 = nm_connection_get_setting_ip6_config(connection); - g_assert(s_ip6); + s_ip6 = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_IP6_CONFIG); g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip6), ==, NM_SETTING_IP6_CONFIG_METHOD_IGNORE); g_assert(nm_setting_ip_config_get_never_default(s_ip6) == FALSE); - - g_object_unref(connection); } static void test_read_miscellaneous_variables(void) { - NMConnection * connection; - NMSettingConnection *s_con; - NMSettingWired * s_wired; - NMSettingIPConfig * s_ip4; - char * expected_mac_blacklist[3] = {"00:16:41:11:22:88", + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection * s_con; + NMSettingWired * s_wired; + NMSettingIPConfig * s_ip4; + char * expected_mac_blacklist[3] = {"00:16:41:11:22:88", "00:16:41:11:22:99", "6a:5d:5a:fa:dd:f0"}; - int mac_blacklist_num, i; - guint64 expected_timestamp = 0; + int mac_blacklist_num, i; + guint64 expected_timestamp = 0; NMTST_EXPECT_NM_WARN("*invalid MAC in HWADDR_BLACKLIST 'XX:aa:invalid'*"); connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-misc-variables", @@ -696,19 +678,14 @@ test_read_miscellaneous_variables(void) NULL); g_test_assert_expected_messages(); - /* ===== CONNECTION SETTING ===== */ - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con); + s_con = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); g_assert_cmpint(nm_setting_connection_get_timestamp(s_con), ==, expected_timestamp); g_assert(nm_setting_connection_get_autoconnect(s_con)); g_assert_cmpint(nm_setting_connection_get_autoconnect_retries(s_con), ==, 100); - /* ===== WIRED SETTING ===== */ - s_wired = nm_connection_get_setting_wired(connection); - g_assert(s_wired); + s_wired = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRED); g_assert_cmpint(nm_setting_wired_get_mtu(s_wired), ==, 0); - /* MAC blacklist */ mac_blacklist_num = nm_setting_wired_get_num_mac_blacklist_items(s_wired); g_assert_cmpint(mac_blacklist_num, ==, 3); for (i = 0; i < mac_blacklist_num; i++) @@ -717,26 +694,22 @@ test_read_miscellaneous_variables(void) expected_mac_blacklist[i], -1)); - /* ===== IPv4 SETTING ===== */ - s_ip4 = nm_connection_get_setting_ip4_config(connection); - g_assert(s_ip4); + s_ip4 = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_DISABLED); g_assert(nm_setting_ip_config_get_never_default(s_ip4) == FALSE); - - g_object_unref(connection); } static void test_read_variables_corner_cases(void) { - NMConnection * connection; - NMSettingConnection *s_con; - NMSettingWired * s_wired; - NMSettingIPConfig * s_ip4; - const char * mac; - char expected_mac_address[ETH_ALEN] = {0x00, 0x16, 0x41, 0x11, 0x22, 0x33}; + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection * s_con; + NMSettingWired * s_wired; + NMSettingIPConfig * s_ip4; + const char * mac; + char expected_mac_address[ETH_ALEN] = {0x00, 0x16, 0x41, 0x11, 0x22, 0x33}; NMTST_EXPECT_NM_WARN("*key NAME is badly quoted and is treated as \"\"*"); NMTST_EXPECT_NM_WARN("*key ZONE is badly quoted and is treated as \"\"*"); @@ -746,9 +719,7 @@ test_read_variables_corner_cases(void) NULL); g_test_assert_expected_messages(); - /* ===== CONNECTION SETTING ===== */ - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con); + s_con = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); g_assert_cmpstr(nm_setting_connection_get_id(s_con), ==, "System test-variables-corner-cases-1"); @@ -756,34 +727,27 @@ test_read_variables_corner_cases(void) g_assert_cmpint(nm_setting_connection_get_timestamp(s_con), ==, 0); g_assert(nm_setting_connection_get_autoconnect(s_con)); - /* ===== WIRED SETTING ===== */ - s_wired = nm_connection_get_setting_wired(connection); - g_assert(s_wired); + s_wired = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRED); g_assert_cmpint(nm_setting_wired_get_mtu(s_wired), ==, 0); - /* MAC address */ mac = nm_setting_wired_get_mac_address(s_wired); g_assert(mac); g_assert(nm_utils_hwaddr_matches(mac, -1, expected_mac_address, ETH_ALEN)); - /* ===== IPv4 SETTING ===== */ - s_ip4 = nm_connection_get_setting_ip4_config(connection); - g_assert(s_ip4); + s_ip4 = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_DISABLED); g_assert(nm_setting_ip_config_get_never_default(s_ip4) == FALSE); - - g_object_unref(connection); } static void test_read_unmanaged(void) { - NMConnection * connection; - NMSettingConnection *s_con; - char * unhandled_spec = NULL; - guint64 expected_timestamp = 0; + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection * s_con; + gs_free char * unhandled_spec = NULL; + guint64 expected_timestamp = 0; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-nm-controlled", NULL, @@ -791,24 +755,19 @@ test_read_unmanaged(void) &unhandled_spec); g_assert_cmpstr(unhandled_spec, ==, "unmanaged:mac:00:11:22:33:f8:9f"); - /* ===== CONNECTION SETTING ===== */ - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con); + s_con = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); g_assert_cmpstr(nm_setting_connection_get_id(s_con), ==, "System test-nm-controlled"); g_assert_cmpint(nm_setting_connection_get_timestamp(s_con), ==, expected_timestamp); g_assert(nm_setting_connection_get_autoconnect(s_con)); - - g_free(unhandled_spec); - g_object_unref(connection); } static void test_read_unmanaged_unrecognized(void) { - NMConnection * connection; - NMSettingConnection *s_con; - gs_free char * unhandled_spec = NULL; - guint64 expected_timestamp = 0; + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection * s_con; + gs_free char * unhandled_spec = NULL; + guint64 expected_timestamp = 0; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-nm-controlled-unrecognized", NULL, @@ -816,22 +775,18 @@ test_read_unmanaged_unrecognized(void) &unhandled_spec); g_assert_cmpstr(unhandled_spec, ==, "unmanaged:interface-name:=ipoac0"); - /* ===== CONNECTION SETTING ===== */ - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con); + s_con = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); g_assert_cmpstr(nm_setting_connection_get_id(s_con), ==, "PigeonNet"); g_assert_cmpint(nm_setting_connection_get_timestamp(s_con), ==, expected_timestamp); - - g_object_unref(connection); } static void test_read_unrecognized(void) { - NMConnection * connection; - NMSettingConnection *s_con; - gs_free char * unhandled_spec = NULL; - guint64 expected_timestamp = 0; + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection * s_con; + gs_free char * unhandled_spec = NULL; + guint64 expected_timestamp = 0; NMTST_EXPECT_NM_WARN("*key NAME is badly quoted and is treated as \"\"*"); connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-unrecognized", @@ -841,30 +796,26 @@ test_read_unrecognized(void) g_test_assert_expected_messages(); g_assert_cmpstr(unhandled_spec, ==, "unrecognized:mac:00:11:22:33"); - /* ===== CONNECTION SETTING ===== */ - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con); + s_con = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); g_assert_cmpstr(nm_setting_connection_get_id(s_con), ==, "System test-unrecognized"); g_assert_cmpint(nm_setting_connection_get_timestamp(s_con), ==, expected_timestamp); - - g_object_unref(connection); } static void test_read_wired_static(gconstpointer test_data) { - NMConnection * connection; - NMSettingConnection *s_con; - NMSettingWired * s_wired; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; - char * unmanaged = NULL; - const char * mac; - char expected_mac_address[ETH_ALEN] = {0x00, 0x11, 0x22, 0x33, 0x44, 0xee}; - NMIPAddress * ip4_addr; - NMIPAddress * ip6_addr; - const char * file, *expected_id; - gpointer expect_ip6_p; + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection * s_con; + NMSettingWired * s_wired; + NMSettingIPConfig * s_ip4; + NMSettingIPConfig * s_ip6; + char * unmanaged = NULL; + const char * mac; + char expected_mac_address[ETH_ALEN] = {0x00, 0x11, 0x22, 0x33, 0x44, 0xee}; + NMIPAddress *ip4_addr; + NMIPAddress *ip6_addr; + const char * file, *expected_id; + gpointer expect_ip6_p; nmtst_test_data_unpack(test_data, &file, &expected_id, &expect_ip6_p); @@ -873,26 +824,19 @@ test_read_wired_static(gconstpointer test_data) connection = _connection_from_file(file, NULL, TYPE_ETHERNET, &unmanaged); g_assert_cmpstr(unmanaged, ==, NULL); - /* ===== CONNECTION SETTING ===== */ - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con); + s_con = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); g_assert_cmpstr(nm_setting_connection_get_id(s_con), ==, expected_id); g_assert_cmpint(nm_setting_connection_get_timestamp(s_con), ==, 0); g_assert(nm_setting_connection_get_autoconnect(s_con)); - /* ===== WIRED SETTING ===== */ - s_wired = nm_connection_get_setting_wired(connection); - g_assert(s_wired); + s_wired = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRED); g_assert_cmpint(nm_setting_wired_get_mtu(s_wired), ==, 1492); - /* MAC address */ mac = nm_setting_wired_get_mac_address(s_wired); g_assert(mac); g_assert(nm_utils_hwaddr_matches(mac, -1, expected_mac_address, ETH_ALEN)); - /* ===== IPv4 SETTING ===== */ - s_ip4 = nm_connection_get_setting_ip4_config(connection); - g_assert(s_ip4); + s_ip4 = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_MANUAL); @@ -901,24 +845,19 @@ test_read_wired_static(gconstpointer test_data) g_assert(nm_setting_ip_config_has_dns_options(s_ip4)); g_assert_cmpint(nm_setting_ip_config_get_num_dns_options(s_ip4), ==, 0); - /* DNS Addresses */ g_assert_cmpint(nm_setting_ip_config_get_num_dns(s_ip4), ==, 2); g_assert_cmpstr(nm_setting_ip_config_get_dns(s_ip4, 0), ==, "4.2.2.1"); g_assert_cmpstr(nm_setting_ip_config_get_dns(s_ip4, 1), ==, "4.2.2.2"); - /* IP addresses */ g_assert_cmpint(nm_setting_ip_config_get_num_addresses(s_ip4), ==, 1); ip4_addr = nm_setting_ip_config_get_address(s_ip4, 0); g_assert(ip4_addr); g_assert_cmpint(nm_ip_address_get_prefix(ip4_addr), ==, 24); g_assert_cmpstr(nm_ip_address_get_address(ip4_addr), ==, "192.168.1.5"); - /* Gateway */ g_assert_cmpstr(nm_setting_ip_config_get_gateway(s_ip4), ==, "192.168.1.1"); - /* ===== IPv6 SETTING ===== */ - s_ip6 = nm_connection_get_setting_ip6_config(connection); - g_assert(s_ip6); + s_ip6 = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_IP6_CONFIG); if (GPOINTER_TO_INT(expect_ip6_p)) { g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip6), ==, @@ -951,19 +890,18 @@ test_read_wired_static(gconstpointer test_data) NM_SETTING_IP6_CONFIG_METHOD_IGNORE); g_assert(!nm_setting_ip_config_has_dns_options(s_ip6)); } - - g_object_unref(connection); } static void test_read_wired_static_no_prefix(gconstpointer user_data) { - guint32 expected_prefix = GPOINTER_TO_UINT(user_data); - NMConnection * connection; - NMSettingConnection *s_con; - NMSettingIPConfig * s_ip4; - NMIPAddress * ip4_addr; - char * file, *expected_id; + guint32 expected_prefix = GPOINTER_TO_UINT(user_data); + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection * s_con; + NMSettingIPConfig * s_ip4; + NMIPAddress * ip4_addr; + gs_free char * file = NULL; + gs_free char * expected_id = NULL; file = g_strdup_printf(TEST_IFCFG_DIR "/ifcfg-test-wired-static-no-prefix-%u", expected_prefix); expected_id = g_strdup_printf("System test-wired-static-no-prefix-%u", expected_prefix); @@ -972,14 +910,10 @@ test_read_wired_static_no_prefix(gconstpointer user_data) connection = _connection_from_file(file, NULL, TYPE_ETHERNET, NULL); g_test_assert_expected_messages(); - /* ===== CONNECTION SETTING ===== */ - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con); + s_con = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); g_assert_cmpstr(nm_setting_connection_get_id(s_con), ==, expected_id); - /* ===== IPv4 SETTING ===== */ - s_ip4 = nm_connection_get_setting_ip4_config(connection); - g_assert(s_ip4); + s_ip4 = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_MANUAL); @@ -991,23 +925,19 @@ test_read_wired_static_no_prefix(gconstpointer user_data) ip4_addr = nm_setting_ip_config_get_address(s_ip4, 0); g_assert(ip4_addr); g_assert_cmpint(nm_ip_address_get_prefix(ip4_addr), ==, expected_prefix); - - g_free(file); - g_free(expected_id); - g_object_unref(connection); } static void test_read_wired_dhcp(void) { - NMConnection * connection; - NMSettingConnection *s_con; - NMSettingWired * s_wired; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; - char * unmanaged = NULL; - char expected_mac_address[ETH_ALEN] = {0x00, 0x11, 0x22, 0x33, 0x44, 0xee}; - const char * mac; + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection * s_con; + NMSettingWired * s_wired; + NMSettingIPConfig * s_ip4; + NMSettingIPConfig * s_ip6; + char * unmanaged = NULL; + char expected_mac_address[ETH_ALEN] = {0x00, 0x11, 0x22, 0x33, 0x44, 0xee}; + const char *mac; NMTST_EXPECT_NM_WARN("*key IPV6INIT is duplicated and the early occurrence ignored*"); connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wired-dhcp", @@ -1017,25 +947,18 @@ test_read_wired_dhcp(void) g_test_assert_expected_messages(); g_assert(unmanaged == NULL); - /* ===== CONNECTION SETTING ===== */ - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con); + s_con = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); g_assert_cmpstr(nm_setting_connection_get_id(s_con), ==, "System test-wired-dhcp"); g_assert_cmpuint(nm_setting_connection_get_timestamp(s_con), ==, 0); g_assert(nm_setting_connection_get_autoconnect(s_con)); - /* ===== WIRED SETTING ===== */ - s_wired = nm_connection_get_setting_wired(connection); - g_assert(s_wired); + s_wired = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRED); - /* MAC address */ mac = nm_setting_wired_get_mac_address(s_wired); g_assert(mac); g_assert(nm_utils_hwaddr_matches(mac, -1, expected_mac_address, sizeof(expected_mac_address))); - /* ===== IPv4 SETTING ===== */ - s_ip4 = nm_connection_get_setting_ip4_config(connection); - g_assert(s_ip4); + s_ip4 = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_AUTO); g_assert_cmpstr(nm_setting_ip4_config_get_dhcp_fqdn(NM_SETTING_IP4_CONFIG(s_ip4)), ==, @@ -1048,35 +971,29 @@ test_read_wired_dhcp(void) ==, NM_DHCP_HOSTNAME_FLAG_FQDN_ENCODED | NM_DHCP_HOSTNAME_FLAG_FQDN_NO_UPDATE); - /* ===== IPv6 SETTING ===== */ - s_ip6 = nm_connection_get_setting_ip6_config(connection); - g_assert(s_ip6); + s_ip6 = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_IP6_CONFIG); g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip6), ==, NM_SETTING_IP6_CONFIG_METHOD_DHCP); g_assert_cmpstr(nm_setting_ip_config_get_dhcp_hostname(s_ip6), ==, "foo.bar"); g_assert_cmpuint(nm_setting_ip_config_get_dhcp_hostname_flags(s_ip6), ==, NM_DHCP_HOSTNAME_FLAG_FQDN_CLEAR_FLAGS); - - g_object_unref(connection); } static void test_read_wired_dhcp_plus_ip(void) { - NMConnection * connection; - NMSettingIPConfig *s_ip4; - NMSettingIPConfig *s_ip6; - NMIPAddress * ip4_addr; - NMIPAddress * ip6_addr; + gs_unref_object NMConnection *connection = NULL; + NMSettingIPConfig * s_ip4; + NMSettingIPConfig * s_ip6; + NMIPAddress * ip4_addr; + NMIPAddress * ip6_addr; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wired-dhcp-plus-ip", NULL, TYPE_ETHERNET, NULL); - /* ===== IPv4 SETTING ===== */ - s_ip4 = nm_connection_get_setting_ip4_config(connection); - g_assert(s_ip4); + s_ip4 = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_AUTO); g_assert(nm_setting_ip_config_get_may_fail(s_ip4)); @@ -1100,9 +1017,7 @@ test_read_wired_dhcp_plus_ip(void) g_assert_cmpint(nm_ip_address_get_prefix(ip4_addr), ==, 16); g_assert_cmpstr(nm_ip_address_get_address(ip4_addr), ==, "9.8.7.6"); - /* ===== IPv6 SETTING ===== */ - s_ip6 = nm_connection_get_setting_ip6_config(connection); - g_assert(s_ip6); + s_ip6 = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_IP6_CONFIG); g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip6), ==, NM_SETTING_IP6_CONFIG_METHOD_AUTO); g_assert(nm_setting_ip_config_get_may_fail(s_ip6)); @@ -1127,25 +1042,21 @@ test_read_wired_dhcp_plus_ip(void) g_assert(ip6_addr); g_assert_cmpint(nm_ip_address_get_prefix(ip6_addr), ==, 96); g_assert_cmpstr(nm_ip_address_get_address(ip6_addr), ==, "3001:abba::3234"); - - g_object_unref(connection); } static void test_read_wired_shared_plus_ip(void) { - NMConnection * connection; - NMSettingIPConfig *s_ip4; - NMIPAddress * ip4_addr; + gs_unref_object NMConnection *connection = NULL; + NMSettingIPConfig * s_ip4; + NMIPAddress * ip4_addr; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wired-shared-plus-ip", NULL, TYPE_ETHERNET, NULL); - /* ===== IPv4 SETTING ===== */ - s_ip4 = nm_connection_get_setting_ip4_config(connection); - g_assert(s_ip4); + s_ip4 = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_SHARED); @@ -1160,19 +1071,16 @@ test_read_wired_shared_plus_ip(void) /* Gateway */ g_assert_cmpstr(nm_setting_ip_config_get_gateway(s_ip4), ==, "1.1.1.1"); - - g_object_unref(connection); } static void test_read_wired_global_gateway(void) { - NMConnection * connection; - NMSettingConnection *s_con; - NMSettingWired * s_wired; - NMSettingIPConfig * s_ip4; - NMIPAddress * ip4_addr; - char * unmanaged = NULL; + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection * s_con; + NMSettingIPConfig * s_ip4; + NMIPAddress * ip4_addr; + char * unmanaged = NULL; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wired-global-gateway", TEST_IFCFG_DIR "/network-test-wired-global-gateway", @@ -1180,18 +1088,12 @@ test_read_wired_global_gateway(void) &unmanaged); g_assert(unmanaged == NULL); - /* ===== CONNECTION SETTING ===== */ - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con); + s_con = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); g_assert_cmpstr(nm_setting_connection_get_id(s_con), ==, "System test-wired-global-gateway"); - /* ===== WIRED SETTING ===== */ - s_wired = nm_connection_get_setting_wired(connection); - g_assert(s_wired); + nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRED); - /* ===== IPv4 SETTING ===== */ - s_ip4 = nm_connection_get_setting_ip4_config(connection); - g_assert(s_ip4); + s_ip4 = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_MANUAL); @@ -1204,19 +1106,16 @@ test_read_wired_global_gateway(void) /* Gateway */ g_assert_cmpstr(nm_setting_ip_config_get_gateway(s_ip4), ==, "192.168.1.2"); - - g_object_unref(connection); } /* Ignore GATEWAY from /etc/sysconfig/network for automatic connections */ static void test_read_wired_global_gateway_ignore(void) { - NMConnection * connection; - NMSettingConnection *s_con; - NMSettingWired * s_wired; - NMSettingIPConfig * s_ip4; - char * unmanaged = NULL; + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection * s_con; + NMSettingIPConfig * s_ip4; + char * unmanaged = NULL; NMTST_EXPECT_NM_WARN("*ignoring GATEWAY (/etc/sysconfig/network) for * because the connection " "has no static addresses"); @@ -1227,20 +1126,14 @@ test_read_wired_global_gateway_ignore(void) g_test_assert_expected_messages(); g_assert(unmanaged == NULL); - /* ===== CONNECTION SETTING ===== */ - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con); + s_con = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); g_assert_cmpstr(nm_setting_connection_get_id(s_con), ==, "System test-wired-global-gateway-ignore"); - /* ===== WIRED SETTING ===== */ - s_wired = nm_connection_get_setting_wired(connection); - g_assert(s_wired); + nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRED); - /* ===== IPv4 SETTING ===== */ - s_ip4 = nm_connection_get_setting_ip4_config(connection); - g_assert(s_ip4); + s_ip4 = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_AUTO); /* Addresses */ @@ -1248,25 +1141,21 @@ test_read_wired_global_gateway_ignore(void) /* Gateway */ g_assert_cmpstr(nm_setting_ip_config_get_gateway(s_ip4), ==, NULL); - - g_object_unref(connection); } static void test_read_wired_obsolete_gateway_n(void) { - NMConnection * connection; - NMSettingIPConfig *s_ip4; - NMIPAddress * ip4_addr; + gs_unref_object NMConnection *connection = NULL; + NMSettingIPConfig * s_ip4; + NMIPAddress * ip4_addr; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wired-obsolete-gateway-n", NULL, TYPE_ETHERNET, NULL); - /* ===== IPv4 SETTING ===== */ - s_ip4 = nm_connection_get_setting_ip4_config(connection); - g_assert(s_ip4); + s_ip4 = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_MANUAL); @@ -1280,8 +1169,6 @@ test_read_wired_obsolete_gateway_n(void) /* Gateway */ g_assert_cmpstr(nm_setting_ip_config_get_gateway(s_ip4), ==, "1.1.1.1"); - - g_object_unref(connection); } static void @@ -1294,7 +1181,8 @@ test_user_1(void) connection = nmtst_create_minimal_connection("Test User 1", NULL, NM_SETTING_WIRED_SETTING_NAME, NULL); - s_user = NM_SETTING_USER(nm_setting_user_new()); + + s_user = _nm_connection_new_setting(connection, NM_TYPE_SETTING_USER); #define _USER_SET_DATA(s_user, key, val) \ G_STMT_START \ @@ -1330,8 +1218,6 @@ test_user_1(void) _USER_SET_DATA_X(s_user, "my.keys.1"); _USER_SET_DATA_X(s_user, "my.other.KEY.42"); - nm_connection_add_setting(connection, NM_SETTING(s_user)); - _writer_new_connec_exp(connection, TEST_SCRATCH_DIR, TEST_IFCFG_DIR "/ifcfg-Test_User_1.cexpected", @@ -1345,42 +1231,35 @@ test_user_1(void) static void test_read_wired_never_default(void) { - NMConnection * connection; - NMSettingIPConfig *s_ip4; - NMSettingIPConfig *s_ip6; + gs_unref_object NMConnection *connection = NULL; + NMSettingIPConfig * s_ip4; + NMSettingIPConfig * s_ip6; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wired-never-default", TEST_IFCFG_DIR "/network-test-wired-never-default", TYPE_ETHERNET, NULL); - /* ===== WIRED SETTING ===== */ - g_assert(nm_connection_get_setting_wired(connection)); + nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRED); - /* ===== IPv4 SETTING ===== */ - s_ip4 = nm_connection_get_setting_ip4_config(connection); - g_assert(s_ip4); + s_ip4 = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_AUTO); g_assert(nm_setting_ip_config_get_never_default(s_ip4)); g_assert_cmpint(nm_setting_ip_config_get_num_dns(s_ip4), ==, 0); - /* ===== IPv6 SETTING ===== */ - s_ip6 = nm_connection_get_setting_ip6_config(connection); - g_assert(s_ip6); + s_ip6 = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_IP6_CONFIG); g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip6), ==, NM_SETTING_IP6_CONFIG_METHOD_AUTO); g_assert(nm_setting_ip_config_get_never_default(s_ip6)); - - g_object_unref(connection); } static void test_read_wired_defroute_no(void) { - NMConnection * connection; - NMSettingConnection *s_con; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; - char * unmanaged = NULL; + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection * s_con; + NMSettingIPConfig * s_ip4; + NMSettingIPConfig * s_ip6; + char * unmanaged = NULL; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wired-defroute-no", NULL, @@ -1388,33 +1267,28 @@ test_read_wired_defroute_no(void) &unmanaged); g_assert(unmanaged == NULL); - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con); + s_con = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); g_assert_cmpstr(nm_setting_connection_get_id(s_con), ==, "System test-wired-defroute-no"); - g_assert(nm_connection_get_setting_wired(connection)); + nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRED); - s_ip4 = nm_connection_get_setting_ip4_config(connection); - g_assert(s_ip4); + s_ip4 = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_AUTO); g_assert(nm_setting_ip_config_get_never_default(s_ip4)); - s_ip6 = nm_connection_get_setting_ip6_config(connection); - g_assert(s_ip6); + s_ip6 = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_IP6_CONFIG); g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip6), ==, NM_SETTING_IP6_CONFIG_METHOD_AUTO); g_assert(nm_setting_ip_config_get_never_default(s_ip6)); - - g_object_unref(connection); } static void test_read_wired_defroute_no_gatewaydev_yes(void) { - NMConnection * connection; - NMSettingConnection *s_con; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; - char * unmanaged = NULL; + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection * s_con; + NMSettingIPConfig * s_ip4; + NMSettingIPConfig * s_ip6; + char * unmanaged = NULL; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wired-defroute-no-gatewaydev-yes", @@ -1422,58 +1296,45 @@ test_read_wired_defroute_no_gatewaydev_yes(void) TYPE_ETHERNET, &unmanaged); - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con); + s_con = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); g_assert_cmpstr(nm_setting_connection_get_id(s_con), ==, "System test-wired-defroute-no-gatewaydev-yes"); - g_assert(nm_connection_get_setting_wired(connection)); + nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRED); - s_ip4 = nm_connection_get_setting_ip4_config(connection); - g_assert(s_ip4); + s_ip4 = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_AUTO); g_assert(nm_setting_ip_config_get_never_default(s_ip4) == FALSE); - s_ip6 = nm_connection_get_setting_ip6_config(connection); - g_assert(s_ip6); + s_ip6 = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_IP6_CONFIG); g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip6), ==, NM_SETTING_IP6_CONFIG_METHOD_AUTO); g_assert(nm_setting_ip_config_get_never_default(s_ip6) == FALSE); - - g_object_unref(connection); } static void test_read_wired_static_routes(void) { - NMConnection * connection; - NMSettingConnection *s_con; - NMSettingWired * s_wired; - NMSettingIPConfig * s_ip4; - NMIPRoute * ip4_route; + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection * s_con; + NMSettingIPConfig * s_ip4; + NMIPRoute * ip4_route; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wired-static-routes", NULL, TYPE_ETHERNET, NULL); - /* ===== CONNECTION SETTING ===== */ - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con); + s_con = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); g_assert_cmpstr(nm_setting_connection_get_id(s_con), ==, "System test-wired-static-routes"); - /* ===== WIRED SETTING ===== */ - s_wired = nm_connection_get_setting_wired(connection); - g_assert(s_wired); + nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRED); - /* ===== IPv4 SETTING ===== */ - s_ip4 = nm_connection_get_setting_ip4_config(connection); - g_assert(s_ip4); + s_ip4 = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_MANUAL); - /* Routes */ g_assert_cmpint(nm_setting_ip_config_get_num_routes(s_ip4), ==, 4); ip4_route = nm_setting_ip_config_get_route(s_ip4, 0); @@ -1524,19 +1385,16 @@ test_read_wired_static_routes(void) g_assert_cmpint(nm_ip_route_get_prefix(ip4_route), ==, 32); nmtst_assert_route_attribute_string(ip4_route, NM_IP_ROUTE_ATTRIBUTE_TYPE, "local"); nmtst_assert_route_attribute_byte(ip4_route, NM_IP_ROUTE_ATTRIBUTE_SCOPE, 254); - - g_object_unref(connection); } static void test_read_wired_static_routes_legacy(void) { - NMConnection * connection; - NMSettingConnection *s_con; - NMSettingWired * s_wired; - NMSettingIPConfig * s_ip4; - char * unmanaged = NULL; - NMIPRoute * ip4_route; + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection * s_con; + NMSettingIPConfig * s_ip4; + char * unmanaged = NULL; + NMIPRoute * ip4_route; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wired-static-routes-legacy", NULL, @@ -1544,28 +1402,18 @@ test_read_wired_static_routes_legacy(void) &unmanaged); g_assert(!unmanaged); - /* ===== CONNECTION SETTING ===== */ - - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con); + s_con = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); g_assert_cmpstr(nm_setting_connection_get_id(s_con), ==, "System test-wired-static-routes-legacy"); - /* ===== WIRED SETTING ===== */ - - s_wired = nm_connection_get_setting_wired(connection); - g_assert(s_wired); + nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRED); - /* ===== IPv4 SETTING ===== */ - - s_ip4 = nm_connection_get_setting_ip4_config(connection); - g_assert(s_ip4); + s_ip4 = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_MANUAL); - /* Routes */ g_assert_cmpint(nm_setting_ip_config_get_num_routes(s_ip4), ==, 5); /* Route #1 */ @@ -1612,20 +1460,17 @@ test_read_wired_static_routes_legacy(void) g_assert(ip4_route != NULL); g_assert_cmpstr(nm_ip_route_get_dest(ip4_route), ==, "1.2.3.4"); nmtst_assert_route_attribute_string(ip4_route, NM_IP_ROUTE_ATTRIBUTE_TYPE, "local"); - - g_object_unref(connection); } static void test_read_wired_ipv4_manual(gconstpointer data) { - NMConnection * connection; - NMSettingConnection *s_con; - NMSettingWired * s_wired; - NMSettingIPConfig * s_ip4; - char * unmanaged = NULL; - NMIPAddress * ip4_addr; - const char * file, *expected_id; + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection * s_con; + NMSettingIPConfig * s_ip4; + char * unmanaged = NULL; + NMIPAddress * ip4_addr; + const char * file, *expected_id; nmtst_test_data_unpack(data, &file, &expected_id); @@ -1634,21 +1479,12 @@ test_read_wired_ipv4_manual(gconstpointer data) connection = _connection_from_file(file, NULL, TYPE_ETHERNET, &unmanaged); g_assert(!unmanaged); - /* ===== CONNECTION SETTING ===== */ - - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con); + s_con = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); g_assert_cmpstr(nm_setting_connection_get_id(s_con), ==, expected_id); - /* ===== WIRED SETTING ===== */ - - s_wired = nm_connection_get_setting_wired(connection); - g_assert(s_wired); - - /* ===== IPv4 SETTING ===== */ + nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRED); - s_ip4 = nm_connection_get_setting_ip4_config(connection); - g_assert(s_ip4); + s_ip4 = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_MANUAL); @@ -1674,21 +1510,18 @@ test_read_wired_ipv4_manual(gconstpointer data) g_assert(ip4_addr != NULL); g_assert_cmpstr(nm_ip_address_get_address(ip4_addr), ==, "3.3.3.3"); g_assert_cmpint(nm_ip_address_get_prefix(ip4_addr), ==, 8); - - g_object_unref(connection); } static void test_read_wired_ipv6_manual(void) { - NMConnection * connection; - NMSettingConnection *s_con; - NMSettingWired * s_wired; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; - char * unmanaged = NULL; - NMIPAddress * ip6_addr; - NMIPRoute * ip6_route; + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection * s_con; + NMSettingIPConfig * s_ip4; + NMSettingIPConfig * s_ip6; + char * unmanaged = NULL; + NMIPAddress * ip6_addr; + NMIPRoute * ip6_route; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wired-ipv6-manual", NULL, @@ -1696,21 +1529,12 @@ test_read_wired_ipv6_manual(void) &unmanaged); g_assert(!unmanaged); - /* ===== CONNECTION SETTING ===== */ - - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con); + s_con = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); g_assert_cmpstr(nm_setting_connection_get_id(s_con), ==, "System test-wired-ipv6-manual"); - /* ===== WIRED SETTING ===== */ + nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRED); - s_wired = nm_connection_get_setting_wired(connection); - g_assert(s_wired); - - /* ===== IPv4 SETTING ===== */ - - s_ip4 = nm_connection_get_setting_ip4_config(connection); - g_assert(s_ip4); + s_ip4 = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); /* DNS Addresses */ g_assert_cmpint(nm_setting_ip_config_get_num_dns(s_ip4), ==, 2); @@ -1721,10 +1545,7 @@ test_read_wired_ipv6_manual(void) g_assert_cmpstr(nm_setting_ip_config_get_dns_search(s_ip4, 1), ==, "ipsum.org"); g_assert_cmpstr(nm_setting_ip_config_get_dns_search(s_ip4, 2), ==, "dolor.edu"); - /* ===== IPv6 SETTING ===== */ - - s_ip6 = nm_connection_get_setting_ip6_config(connection); - g_assert(s_ip6); + s_ip6 = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_IP6_CONFIG); g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip6), ==, NM_SETTING_IP6_CONFIG_METHOD_MANUAL); @@ -1794,22 +1615,19 @@ test_read_wired_ipv6_manual(void) /* DNS domains - none as domains are stuffed to 'ipv4' setting */ g_assert_cmpint(nm_setting_ip_config_get_num_dns_searches(s_ip6), ==, 0); - - g_object_unref(connection); } static void test_read_wired_ipv6_only(gconstpointer test_data) { - NMConnection * connection; - NMSettingConnection *s_con; - NMSettingWired * s_wired; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; - char * unmanaged = NULL; - NMIPAddress * ip6_addr; - const char * method; - const char * file, *expected_id; + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection * s_con; + NMSettingIPConfig * s_ip4; + NMSettingIPConfig * s_ip6; + char * unmanaged = NULL; + NMIPAddress * ip6_addr; + const char * method; + const char * file, *expected_id; nmtst_test_data_unpack(test_data, &file, &expected_id); @@ -1818,29 +1636,17 @@ test_read_wired_ipv6_only(gconstpointer test_data) connection = _connection_from_file(file, NULL, TYPE_ETHERNET, &unmanaged); g_assert(!unmanaged); - /* ===== CONNECTION SETTING ===== */ - - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con); + s_con = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); g_assert_cmpstr(nm_setting_connection_get_id(s_con), ==, expected_id); - /* ===== WIRED SETTING ===== */ + nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRED); - s_wired = nm_connection_get_setting_wired(connection); - g_assert(s_wired); - - /* ===== IPv4 SETTING ===== */ - - s_ip4 = nm_connection_get_setting_ip4_config(connection); - g_assert(s_ip4); + s_ip4 = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); method = nm_setting_ip_config_get_method(s_ip4); g_assert_cmpstr(method, ==, NM_SETTING_IP4_CONFIG_METHOD_DISABLED); - /* ===== IPv6 SETTING ===== */ - - s_ip6 = nm_connection_get_setting_ip6_config(connection); - g_assert(s_ip6); + s_ip6 = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_IP6_CONFIG); g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip6), ==, NM_SETTING_IP6_CONFIG_METHOD_MANUAL); @@ -1863,20 +1669,17 @@ test_read_wired_ipv6_only(gconstpointer test_data) g_assert_cmpstr(nm_setting_ip_config_get_dns_search(s_ip6, 0), ==, "lorem.com"); g_assert_cmpstr(nm_setting_ip_config_get_dns_search(s_ip6, 1), ==, "ipsum.org"); g_assert_cmpstr(nm_setting_ip_config_get_dns_search(s_ip6, 2), ==, "dolor.edu"); - - g_object_unref(connection); } static void test_read_wired_dhcp6_only(void) { - NMConnection * connection; - NMSettingConnection *s_con; - NMSettingWired * s_wired; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; - char * unmanaged = NULL; - const char * method; + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection * s_con; + NMSettingIPConfig * s_ip4; + NMSettingIPConfig * s_ip6; + char * unmanaged = NULL; + const char * method; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wired-dhcp6-only", NULL, @@ -1884,32 +1687,18 @@ test_read_wired_dhcp6_only(void) &unmanaged); g_assert(!unmanaged); - /* ===== CONNECTION SETTING ===== */ - - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con); + s_con = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); g_assert_cmpstr(nm_setting_connection_get_id(s_con), ==, "System test-wired-dhcp6-only"); - /* ===== WIRED SETTING ===== */ - - s_wired = nm_connection_get_setting_wired(connection); - g_assert(s_wired); - - /* ===== IPv4 SETTING ===== */ + nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRED); - s_ip4 = nm_connection_get_setting_ip4_config(connection); - g_assert(s_ip4); + s_ip4 = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); method = nm_setting_ip_config_get_method(s_ip4); g_assert_cmpstr(method, ==, NM_SETTING_IP4_CONFIG_METHOD_DISABLED); - /* ===== IPv6 SETTING ===== */ - - s_ip6 = nm_connection_get_setting_ip6_config(connection); - g_assert(s_ip6); + s_ip6 = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_IP6_CONFIG); g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip6), ==, NM_SETTING_IP6_CONFIG_METHOD_DHCP); - - g_object_unref(connection); } static void @@ -1926,24 +1715,23 @@ test_read_wired_autoip(void) &unmanaged); g_assert(unmanaged == NULL); - s_ip4 = nm_connection_get_setting_ip4_config(connection); - g_assert(s_ip4); + s_ip4 = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_LINK_LOCAL); g_assert(!nm_setting_ip_config_get_may_fail(s_ip4)); g_assert(nm_setting_ip_config_get_ignore_auto_dns(s_ip4)); - s_con = nm_connection_get_setting_connection(connection); + s_con = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); g_assert_cmpint(nm_setting_connection_get_wait_device_timeout(s_con), ==, 2600); } static void test_read_onboot_no(void) { - NMConnection * connection; - NMSettingConnection *s_con; - char * unmanaged = NULL; + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection * s_con; + char * unmanaged = NULL; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-onboot-no", NULL, @@ -1951,39 +1739,32 @@ test_read_onboot_no(void) &unmanaged); g_assert(!unmanaged); - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con); + s_con = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); g_assert(!nm_setting_connection_get_autoconnect(s_con)); - - g_object_unref(connection); } static void test_read_noip(void) { - NMConnection * connection; - NMSettingIPConfig *s_ip4; - NMSettingIPConfig *s_ip6; + gs_unref_object NMConnection *connection = NULL; + NMSettingIPConfig * s_ip4; + NMSettingIPConfig * s_ip6; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-noip", NULL, TYPE_ETHERNET, NULL); - s_ip4 = nm_connection_get_setting_ip4_config(connection); - g_assert(s_ip4); + s_ip4 = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_DISABLED); g_assert(nm_setting_ip_config_get_never_default(s_ip4) == FALSE); - s_ip6 = nm_connection_get_setting_ip6_config(connection); - g_assert(s_ip6); + s_ip6 = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_IP6_CONFIG); g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip6), ==, NM_SETTING_IP6_CONFIG_METHOD_IGNORE); g_assert(nm_setting_ip_config_get_never_default(s_ip6) == FALSE); - - g_object_unref(connection); } #define TEST_IFCFG_WIRED_8021x_PEAP_MSCHAPV2_CA_CERT TEST_IFCFG_DIR "/test_ca_cert.pem" @@ -1991,16 +1772,15 @@ test_read_noip(void) static void test_read_wired_8021x_peap_mschapv2(void) { - NMConnection * connection; - NMSettingWired * s_wired; - NMSettingIPConfig *s_ip4; - NMSetting8021x * s_8021x; - NMSetting8021x * tmp_8021x; - char * unmanaged = NULL; - GError * error = NULL; - gboolean success = FALSE; - const char * expected_ca_cert_path; - const char * read_ca_cert_path; + gs_unref_object NMConnection *connection = NULL; + NMSettingIPConfig * s_ip4; + NMSetting8021x * s_8021x; + gs_unref_object NMSetting8021x *tmp_8021x = NULL; + char * unmanaged = NULL; + GError * error = NULL; + gboolean success = FALSE; + const char * expected_ca_cert_path; + const char * read_ca_cert_path; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wired-8021x-peap-mschapv2", NULL, @@ -2008,20 +1788,12 @@ test_read_wired_8021x_peap_mschapv2(void) &unmanaged); g_assert(!unmanaged); - /* ===== WIRED SETTING ===== */ + nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRED); - s_wired = nm_connection_get_setting_wired(connection); - g_assert(s_wired); - - /* ===== IPv4 SETTING ===== */ - - s_ip4 = nm_connection_get_setting_ip4_config(connection); - g_assert(s_ip4); + s_ip4 = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_AUTO); - /* ===== 802.1x SETTING ===== */ - s_8021x = nm_connection_get_setting_802_1x(connection); - g_assert(s_8021x); + s_8021x = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_802_1X); g_assert_cmpint(nm_setting_802_1x_get_num_eap_methods(s_8021x), ==, 1); g_assert_cmpstr(nm_setting_802_1x_get_eap_method(s_8021x, 0), ==, "peap"); @@ -2049,33 +1821,26 @@ test_read_wired_8021x_peap_mschapv2(void) g_assert(read_ca_cert_path); g_assert_cmpstr(read_ca_cert_path, ==, expected_ca_cert_path); - - g_object_unref(tmp_8021x); - - g_object_unref(connection); } static void test_read_wired_8021x_tls_secret_flags(gconstpointer test_data) { - NMConnection * connection; - NMSettingWired *s_wired; - NMSetting8021x *s_8021x; - char * dirname, *tmp; - const char * ifcfg; - gpointer expected_flags_p; + gs_unref_object NMConnection *connection = NULL; + NMSetting8021x * s_8021x; + gs_free char * dirname = NULL; + gs_free char * tmp1 = NULL; + gs_free char * tmp2 = NULL; + const char * ifcfg; + gpointer expected_flags_p; nmtst_test_data_unpack(test_data, &ifcfg, &expected_flags_p); connection = _connection_from_file(ifcfg, NULL, TYPE_ETHERNET, NULL); - /* ===== WIRED SETTING ===== */ - s_wired = nm_connection_get_setting_wired(connection); - g_assert(s_wired); + nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRED); - /* ===== 802.1x SETTING ===== */ - s_8021x = nm_connection_get_setting_802_1x(connection); - g_assert(s_8021x); + s_8021x = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_802_1X); g_assert_cmpint(nm_setting_802_1x_get_num_eap_methods(s_8021x), ==, 1); g_assert_cmpstr(nm_setting_802_1x_get_eap_method(s_8021x, 0), ==, "tls"); g_assert_cmpstr(nm_setting_802_1x_get_identity(s_8021x), ==, "David Smith"); @@ -2084,18 +1849,13 @@ test_read_wired_8021x_tls_secret_flags(gconstpointer test_data) GPOINTER_TO_INT(expected_flags_p)); dirname = g_path_get_dirname(ifcfg); - tmp = g_build_path("/", dirname, "test_ca_cert.pem", NULL); - g_assert_cmpstr(nm_setting_802_1x_get_ca_cert_path(s_8021x), ==, tmp); - g_free(tmp); - tmp = g_build_path("/", dirname, "test1_key_and_cert.pem", NULL); - g_assert_cmpstr(nm_setting_802_1x_get_client_cert_path(s_8021x), ==, tmp); - g_assert_cmpstr(nm_setting_802_1x_get_private_key_path(s_8021x), ==, tmp); - g_free(tmp); + tmp1 = g_build_path("/", dirname, "test_ca_cert.pem", NULL); + g_assert_cmpstr(nm_setting_802_1x_get_ca_cert_path(s_8021x), ==, tmp1); - g_free(dirname); - - g_object_unref(connection); + tmp2 = g_build_path("/", dirname, "test1_key_and_cert.pem", NULL); + g_assert_cmpstr(nm_setting_802_1x_get_client_cert_path(s_8021x), ==, tmp2); + g_assert_cmpstr(nm_setting_802_1x_get_private_key_path(s_8021x), ==, tmp2); } static void @@ -2111,9 +1871,7 @@ test_read_write_802_1X_subj_matches(void) TYPE_ETHERNET, NULL); - /* ===== 802.1x SETTING ===== */ - s_8021x = nm_connection_get_setting_802_1x(connection); - g_assert(s_8021x); + s_8021x = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_802_1X); g_assert_cmpint(nm_setting_802_1x_get_num_eap_methods(s_8021x), ==, 1); g_assert_cmpstr(nm_setting_802_1x_get_eap_method(s_8021x, 0), ==, "peap"); g_assert_cmpstr(nm_setting_802_1x_get_identity(s_8021x), ==, "Jara Cimrman"); @@ -2143,8 +1901,7 @@ test_read_write_802_1X_subj_matches(void) nmtst_assert_connection_equals(connection, TRUE, reread, FALSE); /* Check 802.1X stuff of the re-read connection. */ - s_8021x = nm_connection_get_setting_802_1x(reread); - g_assert(s_8021x); + s_8021x = nmtst_connection_assert_setting(reread, NM_TYPE_SETTING_802_1X); g_assert_cmpint(nm_setting_802_1x_get_num_eap_methods(s_8021x), ==, 1); g_assert_cmpstr(nm_setting_802_1x_get_eap_method(s_8021x, 0), ==, "peap"); g_assert_cmpstr(nm_setting_802_1x_get_identity(s_8021x), ==, "Jara Cimrman"); @@ -2168,8 +1925,8 @@ test_read_write_802_1X_subj_matches(void) static void test_read_802_1x_ttls_eapgtc(void) { - NMConnection * connection; - NMSetting8021x *s_8021x; + gs_unref_object NMConnection *connection = NULL; + NMSetting8021x * s_8021x; /* Test that EAP-* inner methods are correctly read into the * NMSetting8021x::autheap property. @@ -2180,9 +1937,7 @@ test_read_802_1x_ttls_eapgtc(void) TYPE_WIRELESS, NULL); - /* ===== 802.1x SETTING ===== */ - s_8021x = nm_connection_get_setting_802_1x(connection); - g_assert(s_8021x); + s_8021x = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_802_1X); /* EAP methods */ g_assert_cmpint(nm_setting_802_1x_get_num_eap_methods(s_8021x), ==, 1); @@ -2191,8 +1946,6 @@ test_read_802_1x_ttls_eapgtc(void) /* Auth methods */ g_assert_cmpstr(nm_setting_802_1x_get_phase2_auth(s_8021x), ==, NULL); g_assert_cmpstr(nm_setting_802_1x_get_phase2_autheap(s_8021x), ==, "gtc"); - - g_object_unref(connection); } static void @@ -2208,8 +1961,7 @@ test_read_802_1x_tls_p12_no_client_cert(void) TYPE_ETHERNET, NULL); - s_8021x = nm_connection_get_setting_802_1x(connection); - g_assert(s_8021x); + s_8021x = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_802_1X); g_assert_cmpint(nm_setting_802_1x_get_private_key_scheme(s_8021x), ==, @@ -2242,9 +1994,7 @@ test_read_write_802_1x_password_raw(void) TYPE_ETHERNET, NULL); - /* ===== 802.1x SETTING ===== */ - s_8021x = nm_connection_get_setting_802_1x(connection); - g_assert(s_8021x); + s_8021x = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_802_1X); bytes = nm_setting_802_1x_get_password_raw(s_8021x); g_assert(bytes); @@ -2269,18 +2019,18 @@ test_read_write_802_1x_password_raw(void) static void test_read_wired_aliases_good(gconstpointer test_data) { - const int N = GPOINTER_TO_INT(test_data); - NMConnection * connection; - NMSettingConnection *s_con; - NMSettingIPConfig * s_ip4; - int expected_num_addresses; - const char * expected_address_0[] = {"192.168.1.5", + const int N = GPOINTER_TO_INT(test_data); + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection * s_con; + NMSettingIPConfig * s_ip4; + int expected_num_addresses; + const char * expected_address_0[] = {"192.168.1.5", "192.168.1.6", "192.168.1.9", "192.168.1.99", NULL}; - const char * expected_address_3[] = {"192.168.1.5", "192.168.1.6", NULL}; - const char * expected_label_0[] = { + const char * expected_address_3[] = {"192.168.1.5", "192.168.1.6", NULL}; + const char * expected_label_0[] = { NULL, "aliasem0:1", "aliasem0:2", @@ -2305,19 +2055,13 @@ test_read_wired_aliases_good(gconstpointer test_data) connection = _connection_from_file(path, NULL, TYPE_ETHERNET, NULL); - /* ===== CONNECTION SETTING ===== */ - - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con); + s_con = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); if (N == 0) g_assert_cmpstr(nm_setting_connection_get_id(s_con), ==, "System aliasem0"); else g_assert_cmpstr(nm_setting_connection_get_id(s_con), ==, "System aliasem3"); - /* ===== IPv4 SETTING ===== */ - - s_ip4 = nm_connection_get_setting_ip4_config(connection); - g_assert(s_ip4); + s_ip4 = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_MANUAL); @@ -2358,33 +2102,25 @@ test_read_wired_aliases_good(gconstpointer test_data) for (i = 0; i < expected_num_addresses; i++) g_assert(!expected_address[i]); - - g_object_unref(connection); } static void test_read_wired_aliases_bad(const char *base, const char *expected_id) { - NMConnection * connection; - NMSettingConnection *s_con; - NMSettingIPConfig * s_ip4; - NMIPAddress * ip4_addr; + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection * s_con; + NMSettingIPConfig * s_ip4; + NMIPAddress * ip4_addr; g_assert(expected_id); connection = _connection_from_file(base, NULL, TYPE_ETHERNET, NULL); g_test_assert_expected_messages(); - /* ===== CONNECTION SETTING ===== */ - - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con); + s_con = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); g_assert_cmpstr(nm_setting_connection_get_id(s_con), ==, expected_id); - /* ===== IPv4 SETTING ===== */ - - s_ip4 = nm_connection_get_setting_ip4_config(connection); - g_assert(s_ip4); + s_ip4 = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_MANUAL); @@ -2400,8 +2136,6 @@ test_read_wired_aliases_bad(const char *base, const char *expected_id) /* Gateway */ g_assert_cmpstr(nm_setting_ip_config_get_gateway(s_ip4), ==, "192.168.1.1"); - - g_object_unref(connection); } static void @@ -2421,13 +2155,15 @@ test_read_wired_aliases_bad_2(void) static void test_read_dns_options(void) { - NMConnection * connection; - NMSettingIPConfig *s_ip4, *s_ip6; - char * unmanaged = NULL; - const char * option; - const char * options4[] = {"ndots:3", "single-request-reopen"}; - const char * options6[] = {"inet6"}; - guint32 i, num; + gs_unref_object NMConnection *connection = NULL; + NMSettingIPConfig * s_ip4; + NMSettingIPConfig * s_ip6; + char * unmanaged = NULL; + const char * option; + const char * options4[] = {"ndots:3", "single-request-reopen"}; + const char * options6[] = {"inet6"}; + guint32 num; + guint32 i; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-dns-options", NULL, @@ -2435,11 +2171,9 @@ test_read_dns_options(void) &unmanaged); g_assert_cmpstr(unmanaged, ==, NULL); - s_ip4 = nm_connection_get_setting_ip4_config(connection); - g_assert(s_ip4); + s_ip4 = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); - s_ip6 = nm_connection_get_setting_ip6_config(connection); - g_assert(s_ip6); + s_ip6 = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_IP6_CONFIG); num = nm_setting_ip_config_get_num_dns_options(s_ip4); g_assert_cmpint(num, ==, G_N_ELEMENTS(options4)); @@ -2456,8 +2190,6 @@ test_read_dns_options(void) option = nm_setting_ip_config_get_dns_option(s_ip6, i); g_assert_cmpstr(options6[i], ==, option); } - - g_object_unref(connection); } static void @@ -2477,8 +2209,7 @@ test_clear_master(void) &unmanaged); g_assert_cmpstr(unmanaged, ==, NULL); - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con); + s_con = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); g_assert_cmpstr(nm_setting_connection_get_master(s_con), ==, "br0"); g_assert_cmpstr(nm_setting_connection_get_slave_type(s_con), ==, "bridge"); @@ -2534,10 +2265,7 @@ test_write_dns_options(void) connection = nm_simple_connection_new(); - /* Connection setting */ - s_con = (NMSettingConnection *) nm_setting_connection_new(); - nm_connection_add_setting(connection, NM_SETTING(s_con)); - + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); g_object_set(s_con, NM_SETTING_CONNECTION_ID, "Test DNS options", @@ -2549,16 +2277,10 @@ test_write_dns_options(void) NM_SETTING_WIRED_SETTING_NAME, NULL); - /* Wired setting */ - s_wired = (NMSettingWired *) nm_setting_wired_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wired)); - + s_wired = _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRED); g_object_set(s_wired, NM_SETTING_WIRED_MAC_ADDRESS, mac, NM_SETTING_WIRED_MTU, mtu, NULL); - /* IP4 setting */ - s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip4)); - + s_ip4 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL, @@ -2576,10 +2298,7 @@ test_write_dns_options(void) nm_setting_ip_config_add_dns_option(s_ip4, "debug"); - /* IP6 setting */ - s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip6)); - + s_ip6 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP6_CONFIG); g_object_set(s_ip6, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_MANUAL, @@ -2608,23 +2327,20 @@ test_write_dns_options(void) static void test_read_wifi_open(void) { - NMConnection * connection; - NMSettingConnection * s_con; - NMSettingWireless * s_wireless; - NMSettingWirelessSecurity *s_wsec; - NMSettingIPConfig * s_ip4, *s_ip6; - GBytes * ssid; - const char * mac; + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection * s_con; + NMSettingWireless * s_wifi; + NMSettingIPConfig * s_ip4; + NMSettingIPConfig * s_ip6; + GBytes * ssid; + const char * mac; char expected_mac_address[ETH_ALEN] = {0x00, 0x16, 0x41, 0x11, 0x22, 0x33}; const char *expected_ssid = "blahblah"; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wifi-open", NULL, TYPE_WIRELESS, NULL); - /* ===== CONNECTION SETTING ===== */ - - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con); + s_con = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); g_assert_cmpstr(nm_setting_connection_get_id(s_con), ==, "System blahblah (test-wifi-open)"); /* UUID can't be tested if the ifcfg does not contain the UUID key, because @@ -2636,109 +2352,83 @@ test_read_wifi_open(void) g_assert(nm_setting_connection_get_autoconnect(s_con)); g_assert_cmpint(nm_setting_connection_get_autoconnect_priority(s_con), ==, -1); - /* ===== WIRELESS SETTING ===== */ + s_wifi = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRELESS); - s_wireless = nm_connection_get_setting_wireless(connection); - g_assert(s_wireless); - - /* MAC address */ - mac = nm_setting_wireless_get_mac_address(s_wireless); + mac = nm_setting_wireless_get_mac_address(s_wifi); g_assert(mac); g_assert(nm_utils_hwaddr_matches(mac, -1, expected_mac_address, sizeof(expected_mac_address))); - g_assert_cmpint(nm_setting_wireless_get_mtu(s_wireless), ==, 0); + g_assert_cmpint(nm_setting_wireless_get_mtu(s_wifi), ==, 0); - ssid = nm_setting_wireless_get_ssid(s_wireless); + ssid = nm_setting_wireless_get_ssid(s_wifi); g_assert(ssid); g_assert_cmpmem(g_bytes_get_data(ssid, NULL), g_bytes_get_size(ssid), expected_ssid, strlen(expected_ssid)); - g_assert(!nm_setting_wireless_get_bssid(s_wireless)); - g_assert_cmpstr(nm_setting_wireless_get_mode(s_wireless), ==, "infrastructure"); - g_assert_cmpint(nm_setting_wireless_get_channel(s_wireless), ==, 1); - - /* ===== Wi-Fi SECURITY SETTING ===== */ - s_wsec = nm_connection_get_setting_wireless_security(connection); - g_assert(s_wsec == NULL); + g_assert(!nm_setting_wireless_get_bssid(s_wifi)); + g_assert_cmpstr(nm_setting_wireless_get_mode(s_wifi), ==, "infrastructure"); + g_assert_cmpint(nm_setting_wireless_get_channel(s_wifi), ==, 1); - /* ===== IPv4 SETTING ===== */ + nmtst_connection_assert_no_setting(connection, NM_TYPE_SETTING_WIRELESS_SECURITY); - s_ip4 = nm_connection_get_setting_ip4_config(connection); - g_assert(s_ip4); + s_ip4 = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_assert_cmpint(nm_setting_ip_config_get_route_metric(s_ip4), ==, 104); g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_AUTO); - s_ip6 = nm_connection_get_setting_ip6_config(connection); - g_assert(s_ip6); + s_ip6 = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_IP6_CONFIG); g_assert_cmpint(nm_setting_ip_config_get_route_metric(s_ip6), ==, 106); - - g_object_unref(connection); } static void test_read_wifi_open_auto(void) { - NMConnection * connection; - NMSettingConnection *s_con; - NMSettingWireless * s_wireless; + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection * s_con; + NMSettingWireless * s_wifi; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wifi-open-auto", NULL, TYPE_WIRELESS, NULL); - /* ===== CONNECTION SETTING ===== */ - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con); + s_con = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); g_assert_cmpstr(nm_setting_connection_get_id(s_con), ==, "System blahblah (test-wifi-open-auto)"); - /* ===== WIRELESS SETTING ===== */ - s_wireless = nm_connection_get_setting_wireless(connection); - g_assert(s_wireless); - g_assert_cmpstr(nm_setting_wireless_get_mode(s_wireless), ==, "infrastructure"); - - g_object_unref(connection); + s_wifi = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRELESS); + g_assert_cmpstr(nm_setting_wireless_get_mode(s_wifi), ==, "infrastructure"); } static void test_read_wifi_open_ssid_hex(void) { - NMConnection * connection; - NMSettingConnection *s_con; - NMSettingWireless * s_wireless; - GBytes * ssid; - const char * expected_ssid = "blahblah"; + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection * s_con; + NMSettingWireless * s_wifi; + GBytes * ssid; + const char * expected_ssid = "blahblah"; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wifi-open-ssid-hex", NULL, TYPE_WIRELESS, NULL); - /* ===== CONNECTION SETTING ===== */ - - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con); + s_con = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); g_assert_cmpstr(nm_setting_connection_get_id(s_con), ==, "System blahblah (test-wifi-open-ssid-hex)"); - /* ===== WIRELESS SETTING ===== */ + s_wifi = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRELESS); - s_wireless = nm_connection_get_setting_wireless(connection); - g_assert(s_wireless); - - ssid = nm_setting_wireless_get_ssid(s_wireless); + ssid = nm_setting_wireless_get_ssid(s_wifi); g_assert(ssid); g_assert_cmpmem(g_bytes_get_data(ssid, NULL), g_bytes_get_size(ssid), expected_ssid, strlen(expected_ssid)); - - g_object_unref(connection); } static void @@ -2746,7 +2436,7 @@ test_read_wifi_open_ssid_hex_bad(void) { gs_unref_object NMConnection *connection = NULL; NMSettingConnection * s_con; - NMSettingWireless * s_wireless; + NMSettingWireless * s_wifi; GBytes * ssid; const char * expected_ssid = "0x626cxx"; @@ -2755,16 +2445,14 @@ test_read_wifi_open_ssid_hex_bad(void) TYPE_WIRELESS, NULL); - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con); + s_con = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); g_assert_cmpstr(nm_setting_connection_get_id(s_con), ==, "System 0x626cxx (test-wifi-open-ssid-bad-hex)"); - s_wireless = nm_connection_get_setting_wireless(connection); - g_assert(s_wireless); + s_wifi = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRELESS); - ssid = nm_setting_wireless_get_ssid(s_wireless); + ssid = nm_setting_wireless_get_ssid(s_wifi); g_assert(ssid); g_assert_cmpmem(g_bytes_get_data(ssid, NULL), g_bytes_get_size(ssid), @@ -2781,50 +2469,42 @@ test_read_wifi_open_ssid_bad(gconstpointer data) static void test_read_wifi_open_ssid_quoted(void) { - NMConnection * connection; - NMSettingConnection *s_con; - NMSettingWireless * s_wireless; - GBytes * ssid; - const char * expected_ssid = "foo\"bar\\"; + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection * s_con; + NMSettingWireless * s_wifi; + GBytes * ssid; + const char * expected_ssid = "foo\"bar\\"; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wifi-open-ssid-quoted", NULL, TYPE_WIRELESS, NULL); - /* ===== CONNECTION SETTING ===== */ - - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con); + s_con = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); g_assert_cmpstr(nm_setting_connection_get_id(s_con), ==, "System foo\"bar\\ (test-wifi-open-ssid-quoted)"); - /* ===== WIRELESS SETTING ===== */ + s_wifi = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRELESS); - s_wireless = nm_connection_get_setting_wireless(connection); - g_assert(s_wireless); - - ssid = nm_setting_wireless_get_ssid(s_wireless); + ssid = nm_setting_wireless_get_ssid(s_wifi); g_assert(ssid); g_assert_cmpmem(g_bytes_get_data(ssid, NULL), g_bytes_get_size(ssid), expected_ssid, strlen(expected_ssid)); - - g_object_unref(connection); } static void test_read_wifi_wep(void) { - NMConnection * connection; - NMSettingConnection * s_con; - NMSettingWireless * s_wireless; - NMSettingWirelessSecurity *s_wsec; - NMSettingIPConfig * s_ip4; - GBytes * ssid; - const char * mac; + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection * s_con; + NMSettingWireless * s_wifi; + NMSettingWirelessSecurity * s_wsec; + NMSettingIPConfig * s_ip4; + GBytes * ssid; + const char * mac; char expected_mac_address[ETH_ALEN] = {0x00, 0x16, 0x41, 0x11, 0x22, 0x33}; const char * expected_ssid = "blahblah"; NMWepKeyType key_type; @@ -2832,10 +2512,7 @@ test_read_wifi_wep(void) connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wifi-wep", NULL, TYPE_WIRELESS, NULL); - /* ===== CONNECTION SETTING ===== */ - - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con); + s_con = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); g_assert_cmpstr(nm_setting_connection_get_id(s_con), ==, "System blahblah (test-wifi-wep)"); /* UUID can't be tested if the ifcfg does not contain the UUID key, because @@ -2846,34 +2523,27 @@ test_read_wifi_wep(void) g_assert_cmpint(nm_setting_connection_get_timestamp(s_con), ==, 0); g_assert(nm_setting_connection_get_autoconnect(s_con)); - /* ===== WIRELESS SETTING ===== */ - - s_wireless = nm_connection_get_setting_wireless(connection); - g_assert(s_wireless); + s_wifi = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRELESS); - /* MAC address */ - mac = nm_setting_wireless_get_mac_address(s_wireless); + mac = nm_setting_wireless_get_mac_address(s_wifi); g_assert(mac); g_assert(nm_utils_hwaddr_matches(mac, -1, expected_mac_address, sizeof(expected_mac_address))); /* MTU */ - g_assert_cmpint(nm_setting_wireless_get_mtu(s_wireless), ==, 0); + g_assert_cmpint(nm_setting_wireless_get_mtu(s_wifi), ==, 0); - ssid = nm_setting_wireless_get_ssid(s_wireless); + ssid = nm_setting_wireless_get_ssid(s_wifi); g_assert(ssid); g_assert_cmpmem(g_bytes_get_data(ssid, NULL), g_bytes_get_size(ssid), expected_ssid, strlen(expected_ssid)); - g_assert(!nm_setting_wireless_get_bssid(s_wireless)); - g_assert_cmpstr(nm_setting_wireless_get_mode(s_wireless), ==, "infrastructure"); - g_assert_cmpint(nm_setting_wireless_get_channel(s_wireless), ==, 1); - - /* ===== WIRELESS SECURITY SETTING ===== */ + g_assert(!nm_setting_wireless_get_bssid(s_wifi)); + g_assert_cmpstr(nm_setting_wireless_get_mode(s_wifi), ==, "infrastructure"); + g_assert_cmpint(nm_setting_wireless_get_channel(s_wifi), ==, 1); - s_wsec = nm_connection_get_setting_wireless_security(connection); - g_assert(s_wsec); + s_wsec = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRELESS_SECURITY); g_assert_cmpstr(nm_setting_wireless_security_get_key_mgmt(s_wsec), ==, "none"); g_assert_cmpstr(nm_setting_wireless_security_get_auth_alg(s_wsec), ==, "shared"); g_assert_cmpint(nm_setting_wireless_security_get_wep_tx_keyidx(s_wsec), ==, 0); @@ -2888,35 +2558,27 @@ test_read_wifi_wep(void) g_assert(!nm_setting_wireless_security_get_wep_key(s_wsec, 2)); g_assert(!nm_setting_wireless_security_get_wep_key(s_wsec, 3)); - /* ===== IPv4 SETTING ===== */ - - s_ip4 = nm_connection_get_setting_ip4_config(connection); - g_assert(s_ip4); + s_ip4 = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_AUTO); - - g_object_unref(connection); } static void test_read_wifi_wep_adhoc(void) { - NMConnection * connection; - NMSettingConnection * s_con; - NMSettingWireless * s_wireless; - NMSettingWirelessSecurity *s_wsec; - NMSettingIPConfig * s_ip4; - GBytes * ssid; - const char * expected_ssid = "blahblah"; + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection * s_con; + NMSettingWireless * s_wifi; + NMSettingWirelessSecurity * s_wsec; + NMSettingIPConfig * s_ip4; + GBytes * ssid; + const char * expected_ssid = "blahblah"; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wifi-wep-adhoc", NULL, TYPE_WIRELESS, NULL); - /* ===== CONNECTION SETTING ===== */ - - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con); + s_con = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); g_assert_cmpstr(nm_setting_connection_get_id(s_con), ==, "System blahblah (test-wifi-wep-adhoc)"); @@ -2928,26 +2590,20 @@ test_read_wifi_wep_adhoc(void) g_assert(!nm_setting_connection_get_autoconnect(s_con)); - /* ===== WIRELESS SETTING ===== */ + s_wifi = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRELESS); - s_wireless = nm_connection_get_setting_wireless(connection); - g_assert(s_wireless); - - ssid = nm_setting_wireless_get_ssid(s_wireless); + ssid = nm_setting_wireless_get_ssid(s_wifi); g_assert(ssid); g_assert_cmpmem(g_bytes_get_data(ssid, NULL), g_bytes_get_size(ssid), expected_ssid, strlen(expected_ssid)); - g_assert(!nm_setting_wireless_get_bssid(s_wireless)); - g_assert_cmpstr(nm_setting_wireless_get_mode(s_wireless), ==, "adhoc"); - g_assert_cmpint(nm_setting_wireless_get_channel(s_wireless), ==, 11); - - /* ===== WIRELESS SECURITY SETTING ===== */ + g_assert(!nm_setting_wireless_get_bssid(s_wifi)); + g_assert_cmpstr(nm_setting_wireless_get_mode(s_wifi), ==, "adhoc"); + g_assert_cmpint(nm_setting_wireless_get_channel(s_wifi), ==, 11); - s_wsec = nm_connection_get_setting_wireless_security(connection); - g_assert(s_wsec); + s_wsec = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRELESS_SECURITY); g_assert_cmpstr(nm_setting_wireless_security_get_key_mgmt(s_wsec), ==, "none"); g_assert(!nm_setting_wireless_security_get_auth_alg(s_wsec)); g_assert_cmpint(nm_setting_wireless_security_get_wep_tx_keyidx(s_wsec), ==, 0); @@ -2959,10 +2615,7 @@ test_read_wifi_wep_adhoc(void) g_assert(!nm_setting_wireless_security_get_wep_key(s_wsec, 2)); g_assert(!nm_setting_wireless_security_get_wep_key(s_wsec, 3)); - /* ===== IPv4 SETTING ===== */ - - s_ip4 = nm_connection_get_setting_ip4_config(connection); - g_assert(s_ip4); + s_ip4 = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_AUTO); /* Ignore auto DNS */ @@ -2972,37 +2625,24 @@ test_read_wifi_wep_adhoc(void) g_assert_cmpint(nm_setting_ip_config_get_num_dns(s_ip4), ==, 2); g_assert_cmpstr(nm_setting_ip_config_get_dns(s_ip4, 0), ==, "4.2.2.1"); g_assert_cmpstr(nm_setting_ip_config_get_dns(s_ip4, 1), ==, "4.2.2.2"); - - g_object_unref(connection); } static void test_read_wifi_wep_passphrase(void) { - NMConnection * connection; - NMSettingConnection * s_con; - NMSettingWireless * s_wireless; - NMSettingWirelessSecurity *s_wsec; + gs_unref_object NMConnection *connection = NULL; + NMSettingWirelessSecurity * s_wsec; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wifi-wep-passphrase", NULL, TYPE_WIRELESS, NULL); - /* ===== CONNECTION SETTING ===== */ - - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con); - - /* ===== WIRELESS SETTING ===== */ - - s_wireless = nm_connection_get_setting_wireless(connection); - g_assert(s_wireless); + nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); - /* ===== WIRELESS SECURITY SETTING ===== */ + nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRELESS); - s_wsec = nm_connection_get_setting_wireless_security(connection); - g_assert(s_wsec); + s_wsec = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRELESS_SECURITY); g_assert_cmpstr(nm_setting_wireless_security_get_key_mgmt(s_wsec), ==, "none"); g_assert_cmpint(nm_setting_wireless_security_get_wep_tx_keyidx(s_wsec), ==, 0); g_assert_cmpint(nm_setting_wireless_security_get_wep_key_type(s_wsec), @@ -3012,38 +2652,25 @@ test_read_wifi_wep_passphrase(void) g_assert(!nm_setting_wireless_security_get_wep_key(s_wsec, 1)); g_assert(!nm_setting_wireless_security_get_wep_key(s_wsec, 2)); g_assert(!nm_setting_wireless_security_get_wep_key(s_wsec, 3)); - - g_object_unref(connection); } static void test_read_wifi_wep_40_ascii(void) { - NMConnection * connection; - NMSettingConnection * s_con; - NMSettingWireless * s_wireless; - NMSettingWirelessSecurity *s_wsec; - NMWepKeyType key_type; + gs_unref_object NMConnection *connection = NULL; + NMSettingWirelessSecurity * s_wsec; + NMWepKeyType key_type; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wifi-wep-40-ascii", NULL, TYPE_WIRELESS, NULL); - /* ===== CONNECTION SETTING ===== */ - - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con); - - /* ===== WIRELESS SETTING ===== */ - - s_wireless = nm_connection_get_setting_wireless(connection); - g_assert(s_wireless); + nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); - /* ===== WIRELESS SECURITY SETTING ===== */ + nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRELESS); - s_wsec = nm_connection_get_setting_wireless_security(connection); - g_assert(s_wsec); + s_wsec = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRELESS_SECURITY); g_assert_cmpstr(nm_setting_wireless_security_get_key_mgmt(s_wsec), ==, "none"); g_assert_cmpint(nm_setting_wireless_security_get_wep_tx_keyidx(s_wsec), ==, 0); @@ -3054,38 +2681,25 @@ test_read_wifi_wep_40_ascii(void) g_assert(!nm_setting_wireless_security_get_wep_key(s_wsec, 1)); g_assert(!nm_setting_wireless_security_get_wep_key(s_wsec, 2)); g_assert(!nm_setting_wireless_security_get_wep_key(s_wsec, 3)); - - g_object_unref(connection); } static void test_read_wifi_wep_104_ascii(void) { - NMConnection * connection; - NMSettingConnection * s_con; - NMSettingWireless * s_wireless; - NMSettingWirelessSecurity *s_wsec; - NMWepKeyType key_type; + gs_unref_object NMConnection *connection = NULL; + NMSettingWirelessSecurity * s_wsec; + NMWepKeyType key_type; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wifi-wep-104-ascii", NULL, TYPE_WIRELESS, NULL); - /* ===== CONNECTION SETTING ===== */ - - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con); + nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); - /* ===== WIRELESS SETTING ===== */ + nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRELESS); - s_wireless = nm_connection_get_setting_wireless(connection); - g_assert(s_wireless); - - /* ===== WIRELESS SECURITY SETTING ===== */ - - s_wsec = nm_connection_get_setting_wireless_security(connection); - g_assert(s_wsec); + s_wsec = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRELESS_SECURITY); g_assert_cmpstr(nm_setting_wireless_security_get_key_mgmt(s_wsec), ==, "none"); g_assert_cmpint(nm_setting_wireless_security_get_wep_tx_keyidx(s_wsec), ==, 0); @@ -3096,64 +2710,45 @@ test_read_wifi_wep_104_ascii(void) g_assert(!nm_setting_wireless_security_get_wep_key(s_wsec, 1)); g_assert(!nm_setting_wireless_security_get_wep_key(s_wsec, 2)); g_assert(!nm_setting_wireless_security_get_wep_key(s_wsec, 3)); - - g_object_unref(connection); } static void test_read_wifi_leap(void) { - NMConnection * connection; - NMSettingConnection * s_con; - NMSettingWireless * s_wireless; - NMSettingWirelessSecurity *s_wsec; + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection * s_con; + NMSettingWirelessSecurity * s_wsec; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wifi-leap", NULL, TYPE_WIRELESS, NULL); - /* ===== CONNECTION SETTING ===== */ - - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con); + s_con = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); g_assert_cmpstr(nm_setting_connection_get_id(s_con), ==, "System blahblah (test-wifi-leap)"); - /* ===== WIRELESS SETTING ===== */ - - s_wireless = nm_connection_get_setting_wireless(connection); - g_assert(s_wireless); - - /* ===== WIRELESS SECURITY SETTING ===== */ + nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRELESS); - s_wsec = nm_connection_get_setting_wireless_security(connection); - g_assert(s_wsec); + s_wsec = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRELESS_SECURITY); g_assert_cmpstr(nm_setting_wireless_security_get_key_mgmt(s_wsec), ==, "ieee8021x"); g_assert_cmpstr(nm_setting_wireless_security_get_auth_alg(s_wsec), ==, "leap"); g_assert_cmpstr(nm_setting_wireless_security_get_leap_username(s_wsec), ==, "Bill Smith"); g_assert_cmpstr(nm_setting_wireless_security_get_leap_password(s_wsec), ==, "foobarblah"); - - g_object_unref(connection); } static void test_read_wifi_leap_secret_flags(gconstpointer test_data) { - NMConnection * connection; - NMSettingWireless * s_wifi; - NMSettingWirelessSecurity *s_wsec; - const char * file; - gpointer expected_flags_p; + gs_unref_object NMConnection *connection = NULL; + NMSettingWirelessSecurity * s_wsec; + const char * file; + gpointer expected_flags_p; nmtst_test_data_unpack(test_data, &file, &expected_flags_p); connection = _connection_from_file(file, NULL, TYPE_WIRELESS, NULL); - /* ===== WIRELESS SETTING ===== */ - s_wifi = nm_connection_get_setting_wireless(connection); - g_assert(s_wifi); + nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRELESS); - /* ===== WIRELESS SECURITY SETTING ===== */ - s_wsec = nm_connection_get_setting_wireless_security(connection); - g_assert(s_wsec); + s_wsec = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRELESS_SECURITY); g_assert(g_strcmp0(nm_setting_wireless_security_get_key_mgmt(s_wsec), "ieee8021x") == 0); g_assert(g_strcmp0(nm_setting_wireless_security_get_auth_alg(s_wsec), "leap") == 0); @@ -3162,8 +2757,6 @@ test_read_wifi_leap_secret_flags(gconstpointer test_data) g_assert(nm_setting_wireless_security_get_leap_password_flags(s_wsec) == GPOINTER_TO_INT(expected_flags_p)); g_assert(nm_setting_wireless_security_get_leap_password(s_wsec) == NULL); - - g_object_unref(connection); } static void @@ -3179,13 +2772,13 @@ test_ifcfg_no_trailing_newline(void) static void test_read_wifi_wpa_psk(void) { - NMConnection * connection; - NMSettingConnection * s_con; - NMSettingWireless * s_wireless; - NMSettingWirelessSecurity *s_wsec; - NMSettingIPConfig * s_ip4; - GBytes * ssid; - const char * mac; + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection * s_con; + NMSettingWireless * s_wifi; + NMSettingWirelessSecurity * s_wsec; + NMSettingIPConfig * s_ip4; + GBytes * ssid; + const char * mac; char expected_mac_address[ETH_ALEN] = {0x00, 0x16, 0x41, 0x11, 0x22, 0x33}; const char *expected_ssid = "blahblah"; guint32 n, i; @@ -3201,10 +2794,7 @@ test_read_wifi_wpa_psk(void) connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wifi-wpa-psk", NULL, TYPE_WIRELESS, NULL); - /* ===== CONNECTION SETTING ===== */ - - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con); + s_con = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); g_assert_cmpstr(nm_setting_connection_get_id(s_con), ==, "System blahblah (test-wifi-wpa-psk)"); /* UUID can't be tested if the ifcfg does not contain the UUID key, because @@ -3215,32 +2805,26 @@ test_read_wifi_wpa_psk(void) g_assert_cmpint(nm_setting_connection_get_timestamp(s_con), ==, 0); g_assert(nm_setting_connection_get_autoconnect(s_con)); - /* ===== WIRELESS SETTING ===== */ - - s_wireless = nm_connection_get_setting_wireless(connection); - g_assert(s_wireless); + s_wifi = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRELESS); - mac = nm_setting_wireless_get_mac_address(s_wireless); + mac = nm_setting_wireless_get_mac_address(s_wifi); g_assert(mac); g_assert(nm_utils_hwaddr_matches(mac, -1, expected_mac_address, sizeof(expected_mac_address))); - g_assert_cmpint(nm_setting_wireless_get_mtu(s_wireless), ==, 0); + g_assert_cmpint(nm_setting_wireless_get_mtu(s_wifi), ==, 0); - ssid = nm_setting_wireless_get_ssid(s_wireless); + ssid = nm_setting_wireless_get_ssid(s_wifi); g_assert(ssid); g_assert_cmpmem(g_bytes_get_data(ssid, NULL), g_bytes_get_size(ssid), expected_ssid, strlen(expected_ssid)); - g_assert(!nm_setting_wireless_get_bssid(s_wireless)); - g_assert_cmpstr(nm_setting_wireless_get_mode(s_wireless), ==, "infrastructure"); - g_assert_cmpint(nm_setting_wireless_get_channel(s_wireless), ==, 1); + g_assert(!nm_setting_wireless_get_bssid(s_wifi)); + g_assert_cmpstr(nm_setting_wireless_get_mode(s_wifi), ==, "infrastructure"); + g_assert_cmpint(nm_setting_wireless_get_channel(s_wifi), ==, 1); - /* ===== WIRELESS SECURITY SETTING ===== */ - - s_wsec = nm_connection_get_setting_wireless_security(connection); - g_assert(s_wsec); + s_wsec = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRELESS_SECURITY); g_assert_cmpstr(nm_setting_wireless_security_get_key_mgmt(s_wsec), ==, "wpa-psk"); g_assert_cmpstr(nm_setting_wireless_security_get_psk(s_wsec), ==, @@ -3295,13 +2879,8 @@ test_read_wifi_wpa_psk(void) g_assert(found_proto_wpa); g_assert(found_proto_rsn); - /* ===== IPv4 SETTING ===== */ - - s_ip4 = nm_connection_get_setting_ip4_config(connection); - g_assert(s_ip4); + s_ip4 = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_AUTO); - - g_object_unref(connection); } static void @@ -3309,7 +2888,7 @@ test_read_wifi_sae(void) { gs_unref_object NMConnection *connection = NULL; NMSettingConnection * s_con; - NMSettingWireless * s_wireless; + NMSettingWireless * s_wifi; NMSettingWirelessSecurity * s_wsec; GBytes * ssid; const char * expected_ssid = "blahblah"; @@ -3317,30 +2896,27 @@ test_read_wifi_sae(void) connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wifi-sae", NULL, TYPE_WIRELESS, NULL); - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con); + s_con = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); g_assert_cmpstr(nm_setting_connection_get_id(s_con), ==, "System blahblah (test-wifi-sae)"); g_assert_cmpint(nm_setting_connection_get_timestamp(s_con), ==, 0); g_assert(nm_setting_connection_get_autoconnect(s_con)); - s_wireless = nm_connection_get_setting_wireless(connection); - g_assert(s_wireless); + s_wifi = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRELESS); - g_assert_cmpint(nm_setting_wireless_get_mtu(s_wireless), ==, 0); + g_assert_cmpint(nm_setting_wireless_get_mtu(s_wifi), ==, 0); - ssid = nm_setting_wireless_get_ssid(s_wireless); + ssid = nm_setting_wireless_get_ssid(s_wifi); g_assert(ssid); g_assert_cmpmem(g_bytes_get_data(ssid, NULL), g_bytes_get_size(ssid), expected_ssid, strlen(expected_ssid)); - g_assert(!nm_setting_wireless_get_bssid(s_wireless)); - g_assert_cmpstr(nm_setting_wireless_get_mode(s_wireless), ==, "infrastructure"); + g_assert(!nm_setting_wireless_get_bssid(s_wifi)); + g_assert_cmpstr(nm_setting_wireless_get_mode(s_wifi), ==, "infrastructure"); - s_wsec = nm_connection_get_setting_wireless_security(connection); - g_assert(s_wsec); + s_wsec = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRELESS_SECURITY); g_assert_cmpstr(nm_setting_wireless_security_get_key_mgmt(s_wsec), ==, "sae"); g_assert_cmpstr(nm_setting_wireless_security_get_psk(s_wsec), ==, "The king is dead."); g_assert(!nm_setting_wireless_security_get_auth_alg(s_wsec)); @@ -3351,7 +2927,7 @@ test_read_wifi_owe(void) { gs_unref_object NMConnection *connection = NULL; NMSettingConnection * s_con; - NMSettingWireless * s_wireless; + NMSettingWireless * s_wifi; NMSettingWirelessSecurity * s_wsec; GBytes * ssid; const char * expected_ssid = "blahblah_owe"; @@ -3359,30 +2935,27 @@ test_read_wifi_owe(void) connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wifi-owe", NULL, TYPE_WIRELESS, NULL); - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con); + s_con = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); g_assert_cmpstr(nm_setting_connection_get_id(s_con), ==, "System blahblah_owe (test-wifi-owe)"); g_assert_cmpint(nm_setting_connection_get_timestamp(s_con), ==, 0); g_assert(nm_setting_connection_get_autoconnect(s_con)); - s_wireless = nm_connection_get_setting_wireless(connection); - g_assert(s_wireless); + s_wifi = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRELESS); - g_assert_cmpint(nm_setting_wireless_get_mtu(s_wireless), ==, 0); + g_assert_cmpint(nm_setting_wireless_get_mtu(s_wifi), ==, 0); - ssid = nm_setting_wireless_get_ssid(s_wireless); + ssid = nm_setting_wireless_get_ssid(s_wifi); g_assert(ssid); g_assert_cmpmem(g_bytes_get_data(ssid, NULL), g_bytes_get_size(ssid), expected_ssid, strlen(expected_ssid)); - g_assert(!nm_setting_wireless_get_bssid(s_wireless)); - g_assert_cmpstr(nm_setting_wireless_get_mode(s_wireless), ==, "infrastructure"); + g_assert(!nm_setting_wireless_get_bssid(s_wifi)); + g_assert_cmpstr(nm_setting_wireless_get_mode(s_wifi), ==, "infrastructure"); - s_wsec = nm_connection_get_setting_wireless_security(connection); - g_assert(s_wsec); + s_wsec = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRELESS_SECURITY); g_assert_cmpstr(nm_setting_wireless_security_get_key_mgmt(s_wsec), ==, "owe"); g_assert(!nm_setting_wireless_security_get_psk(s_wsec)); g_assert(!nm_setting_wireless_security_get_auth_alg(s_wsec)); @@ -3391,71 +2964,47 @@ test_read_wifi_owe(void) static void test_read_wifi_wpa_psk_2(void) { - NMConnection * connection; - NMSettingConnection * s_con; - NMSettingWireless * s_wireless; - NMSettingWirelessSecurity *s_wsec; + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection * s_con; + NMSettingWirelessSecurity * s_wsec; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wifi-wpa-psk-2", NULL, TYPE_WIRELESS, NULL); - /* ===== CONNECTION SETTING ===== */ - - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con); + s_con = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); g_assert_cmpstr(nm_setting_connection_get_id(s_con), ==, "System ipsum (test-wifi-wpa-psk-2)"); - /* ===== WIRELESS SETTING ===== */ - - s_wireless = nm_connection_get_setting_wireless(connection); - g_assert(s_wireless); + nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRELESS); - /* ===== WIRELESS SECURITY SETTING ===== */ - - s_wsec = nm_connection_get_setting_wireless_security(connection); - g_assert(s_wsec); + s_wsec = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRELESS_SECURITY); g_assert_cmpstr(nm_setting_wireless_security_get_psk(s_wsec), ==, "They're really saying I love you. >>`<< '"); - - g_object_unref(connection); } static void test_read_wifi_wpa_psk_unquoted(void) { - NMConnection * connection; - NMSettingConnection * s_con; - NMSettingWireless * s_wireless; - NMSettingWirelessSecurity *s_wsec; + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection * s_con; + NMSettingWirelessSecurity * s_wsec; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wifi-wpa-psk-unquoted", NULL, TYPE_WIRELESS, NULL); - /* ===== CONNECTION SETTING ===== */ - - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con); + s_con = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); g_assert_cmpstr(nm_setting_connection_get_id(s_con), ==, "System blahblah (test-wifi-wpa-psk-unquoted)"); - /* ===== WIRELESS SETTING ===== */ + nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRELESS); - s_wireless = nm_connection_get_setting_wireless(connection); - g_assert(s_wireless); - - /* ===== WIRELESS SECURITY SETTING ===== */ - - s_wsec = nm_connection_get_setting_wireless_security(connection); - g_assert(s_wsec); + s_wsec = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRELESS_SECURITY); g_assert_cmpstr(nm_setting_wireless_security_get_psk(s_wsec), ==, "54336845e2f3f321c4c7"); - - g_object_unref(connection); } static void @@ -3472,36 +3021,27 @@ test_read_wifi_wpa_psk_unquoted2(void) static void test_read_wifi_wpa_psk_adhoc(void) { - NMConnection * connection; - NMSettingConnection * s_con; - NMSettingWireless * s_wireless; - NMSettingWirelessSecurity *s_wsec; - NMSettingIPConfig * s_ip4; + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection * s_con; + NMSettingWireless * s_wifi; + NMSettingWirelessSecurity * s_wsec; + NMSettingIPConfig * s_ip4; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wifi-wpa-psk-adhoc", NULL, TYPE_WIRELESS, NULL); - /* ===== CONNECTION SETTING ===== */ - - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con); + s_con = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); g_assert_cmpstr(nm_setting_connection_get_id(s_con), ==, "System blahblah (test-wifi-wpa-psk-adhoc)"); - /* ===== WIRELESS SETTING ===== */ + s_wifi = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRELESS); - s_wireless = nm_connection_get_setting_wireless(connection); - g_assert(s_wireless); + g_assert_cmpstr(nm_setting_wireless_get_mode(s_wifi), ==, "adhoc"); - g_assert_cmpstr(nm_setting_wireless_get_mode(s_wireless), ==, "adhoc"); - - /* ===== WIRELESS SECURITY SETTING ===== */ - - s_wsec = nm_connection_get_setting_wireless_security(connection); - g_assert(s_wsec); + s_wsec = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRELESS_SECURITY); g_assert_cmpstr(nm_setting_wireless_security_get_key_mgmt(s_wsec), ==, "wpa-psk"); g_assert_cmpstr(nm_setting_wireless_security_get_psk(s_wsec), ==, @@ -3516,64 +3056,45 @@ test_read_wifi_wpa_psk_adhoc(void) g_assert_cmpint(nm_setting_wireless_security_get_num_protos(s_wsec), ==, 1); g_assert_cmpstr(nm_setting_wireless_security_get_proto(s_wsec, 0), ==, "rsn"); - /* ===== IPv4 SETTING ===== */ - - s_ip4 = nm_connection_get_setting_ip4_config(connection); - g_assert(s_ip4); + s_ip4 = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_AUTO); - - g_object_unref(connection); } static void test_read_wifi_wpa_psk_hex(void) { - NMConnection * connection; - NMSettingConnection * s_con; - NMSettingWireless * s_wireless; - NMSettingWirelessSecurity *s_wsec; - NMSettingIPConfig * s_ip4; - GBytes * ssid; - const char * expected_ssid = "blahblah"; + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection * s_con; + NMSettingWireless * s_wifi; + NMSettingWirelessSecurity * s_wsec; + NMSettingIPConfig * s_ip4; + GBytes * ssid; + const char * expected_ssid = "blahblah"; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wifi-wpa-psk-hex", NULL, TYPE_WIRELESS, NULL); - /* ===== CONNECTION SETTING ===== */ - - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con); + s_con = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); g_assert_cmpstr(nm_setting_connection_get_id(s_con), ==, "System blahblah (test-wifi-wpa-psk-hex)"); - /* ===== WIRELESS SETTING ===== */ - - s_wireless = nm_connection_get_setting_wireless(connection); - g_assert(s_wireless); + s_wifi = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRELESS); - ssid = nm_setting_wireless_get_ssid(s_wireless); + ssid = nm_setting_wireless_get_ssid(s_wifi); g_assert(ssid); - g_assert(nm_utils_gbytes_equal_mem(ssid, expected_ssid, strlen(expected_ssid))); + g_assert(nm_g_bytes_equal_mem(ssid, expected_ssid, strlen(expected_ssid))); - /* ===== WIRELESS SECURITY SETTING ===== */ - - s_wsec = nm_connection_get_setting_wireless_security(connection); - g_assert(s_wsec); + s_wsec = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRELESS_SECURITY); g_assert_cmpstr(nm_setting_wireless_security_get_key_mgmt(s_wsec), ==, "wpa-psk"); g_assert_cmpstr(nm_setting_wireless_security_get_psk(s_wsec), ==, "1da190379817bc360dda52e85c388c439a21ea5c7bf819c64e9da051807deae6"); - /* ===== IPv4 SETTING ===== */ - - s_ip4 = nm_connection_get_setting_ip4_config(connection); - g_assert(s_ip4); + s_ip4 = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_AUTO); - - g_object_unref(connection); } #define TEST_IFCFG_WIFI_WPA_EAP_TLS_CA_CERT TEST_IFCFG_DIR "/test_ca_cert.pem" @@ -3583,12 +3104,11 @@ test_read_wifi_wpa_psk_hex(void) static void test_read_wifi_wpa_eap_tls(void) { - NMConnection * connection; - NMSettingWireless *s_wireless; - NMSettingIPConfig *s_ip4; - NMSetting8021x * s_8021x; - char * unmanaged = NULL; - const char * expected_privkey_password = "test1"; + gs_unref_object NMConnection *connection = NULL; + NMSettingIPConfig * s_ip4; + NMSetting8021x * s_8021x; + char * unmanaged = NULL; + const char * expected_privkey_password = "test1"; NMTST_EXPECT_NM_WARN("*key ONBOOT is duplicated and the early occurrence ignored*"); connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wifi-wpa-eap-tls", @@ -3598,20 +3118,12 @@ test_read_wifi_wpa_eap_tls(void) g_test_assert_expected_messages(); g_assert(!unmanaged); - /* ===== WIRELESS SETTING ===== */ + nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRELESS); - s_wireless = nm_connection_get_setting_wireless(connection); - g_assert(s_wireless); - - /* ===== IPv4 SETTING ===== */ - - s_ip4 = nm_connection_get_setting_ip4_config(connection); - g_assert(s_ip4); + s_ip4 = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_AUTO); - /* ===== 802.1x SETTING ===== */ - s_8021x = nm_connection_get_setting_802_1x(connection); - g_assert(s_8021x); + s_8021x = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_802_1X); g_assert_cmpint(nm_setting_802_1x_get_num_eap_methods(s_8021x), ==, 1); g_assert_cmpstr(nm_setting_802_1x_get_eap_method(s_8021x, 0), ==, "tls"); g_assert_cmpstr(nm_setting_802_1x_get_identity(s_8021x), ==, "Bill Smith"); @@ -3638,8 +3150,6 @@ test_read_wifi_wpa_eap_tls(void) TEST_IFCFG_WIFI_WPA_EAP_TLS_PRIVATE_KEY, expected_privkey_password, NM_SETTING_802_1X_PRIVATE_KEY); - - g_object_unref(connection); } /* Also use TLS defines from the previous test */ @@ -3647,12 +3157,11 @@ test_read_wifi_wpa_eap_tls(void) static void test_read_wifi_wpa_eap_ttls_tls(void) { - NMConnection * connection; - NMSettingWireless *s_wireless; - NMSettingIPConfig *s_ip4; - NMSetting8021x * s_8021x; - char * unmanaged = NULL; - const char * expected_privkey_password = "test1"; + gs_unref_object NMConnection *connection = NULL; + NMSettingIPConfig * s_ip4; + NMSetting8021x * s_8021x; + char * unmanaged = NULL; + const char * expected_privkey_password = "test1"; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wifi-wpa-eap-ttls-tls", NULL, @@ -3660,20 +3169,12 @@ test_read_wifi_wpa_eap_ttls_tls(void) &unmanaged); g_assert(!unmanaged); - /* ===== WIRELESS SETTING ===== */ + nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRELESS); - s_wireless = nm_connection_get_setting_wireless(connection); - g_assert(s_wireless); - - /* ===== IPv4 SETTING ===== */ - - s_ip4 = nm_connection_get_setting_ip4_config(connection); - g_assert(s_ip4); + s_ip4 = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_AUTO); - /* ===== 802.1x SETTING ===== */ - s_8021x = nm_connection_get_setting_802_1x(connection); - g_assert(s_8021x); + s_8021x = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_802_1X); g_assert_cmpint(nm_setting_802_1x_get_num_eap_methods(s_8021x), ==, 1); g_assert_cmpstr(nm_setting_802_1x_get_eap_method(s_8021x, 0), ==, "ttls"); g_assert_cmpstr(nm_setting_802_1x_get_identity(s_8021x), ==, "Chuck Shumer"); @@ -3709,59 +3210,40 @@ test_read_wifi_wpa_eap_ttls_tls(void) TEST_IFCFG_WIFI_WPA_EAP_TLS_PRIVATE_KEY, expected_privkey_password, NM_SETTING_802_1X_PHASE2_PRIVATE_KEY); - - g_object_unref(connection); } static void test_read_wifi_wpa_eap_suite_b_192_tls(void) { - NMConnection * connection; - NMSettingWireless * s_wireless; - NMSettingWirelessSecurity *s_wireless_sec; + gs_unref_object NMConnection *connection = NULL; + NMSettingWirelessSecurity * s_wsec; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wifi-wpa-eap-suite-b-192-tls", NULL, TYPE_WIRELESS, NULL); - /* ===== WIRELESS SETTING ===== */ - - s_wireless = nm_connection_get_setting_wireless(connection); - g_assert(s_wireless); - - /* ===== WIRELESS SECURITY SETTING ===== */ + nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRELESS); - s_wireless_sec = nm_connection_get_setting_wireless_security(connection); - g_assert(s_wireless_sec); - g_assert_cmpstr(nm_setting_wireless_security_get_key_mgmt(s_wireless_sec), - ==, - "wpa-eap-suite-b-192"); - - g_object_unref(connection); + s_wsec = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRELESS_SECURITY); + g_assert_cmpstr(nm_setting_wireless_security_get_key_mgmt(s_wsec), ==, "wpa-eap-suite-b-192"); } static void test_read_wifi_dynamic_wep_leap(void) { - NMConnection * connection; - NMSettingWireless * s_wifi; - NMSettingWirelessSecurity *s_wsec; - NMSetting8021x * s_8021x; + gs_unref_object NMConnection *connection = NULL; + NMSettingWirelessSecurity * s_wsec; + NMSetting8021x * s_8021x; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wifi-dynamic-wep-leap", NULL, TYPE_WIRELESS, NULL); - /* ===== WIRELESS SETTING ===== */ - - s_wifi = nm_connection_get_setting_wireless(connection); - g_assert(s_wifi); + nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRELESS); - /* ===== Wi-Fi SECURITY SETTING ===== */ - s_wsec = nm_connection_get_setting_wireless_security(connection); - g_assert(s_wsec); + s_wsec = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRELESS_SECURITY); /* Key management */ g_assert_cmpstr(nm_setting_wireless_security_get_key_mgmt(s_wsec), ==, "ieee8021x"); @@ -3775,9 +3257,7 @@ test_read_wifi_dynamic_wep_leap(void) g_assert_cmpstr(nm_setting_wireless_security_get_leap_username(s_wsec), ==, NULL); g_assert_cmpstr(nm_setting_wireless_security_get_leap_password(s_wsec), ==, NULL); - /* ===== 802.1x SETTING ===== */ - s_8021x = nm_connection_get_setting_802_1x(connection); - g_assert(s_8021x); + s_8021x = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_802_1X); /* EAP method should be "leap" */ g_assert_cmpint(nm_setting_802_1x_get_num_eap_methods(s_8021x), ==, 1); @@ -3786,19 +3266,16 @@ test_read_wifi_dynamic_wep_leap(void) /* username & password */ g_assert_cmpstr(nm_setting_802_1x_get_identity(s_8021x), ==, "bill smith"); g_assert_cmpstr(nm_setting_802_1x_get_password(s_8021x), ==, "foobar baz"); - - g_object_unref(connection); } static void test_read_wifi_wep_eap_ttls_chap(void) { - NMConnection * connection; - NMSettingWireless * s_wireless; - NMSettingWirelessSecurity *s_wsec; - NMSettingIPConfig * s_ip4; - NMSetting8021x * s_8021x; - char * unmanaged = NULL; + gs_unref_object NMConnection *connection = NULL; + NMSettingWirelessSecurity * s_wsec; + NMSettingIPConfig * s_ip4; + NMSetting8021x * s_8021x; + char * unmanaged = NULL; NMTST_EXPECT_NM_WARN("*key ONBOOT is duplicated and the early occurrence ignored*"); connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wifi-wep-eap-ttls-chap", @@ -3808,25 +3285,15 @@ test_read_wifi_wep_eap_ttls_chap(void) g_test_assert_expected_messages(); g_assert(!unmanaged); - /* ===== WIRELESS SETTING ===== */ + nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRELESS); - s_wireless = nm_connection_get_setting_wireless(connection); - g_assert(s_wireless); - - /* ===== IPv4 SETTING ===== */ - - s_ip4 = nm_connection_get_setting_ip4_config(connection); - g_assert(s_ip4); + s_ip4 = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_AUTO); - /* ===== 802.1x SETTING ===== */ - s_wsec = nm_connection_get_setting_wireless_security(connection); - g_assert(s_wsec); + s_wsec = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRELESS_SECURITY); g_assert_cmpstr(nm_setting_wireless_security_get_key_mgmt(s_wsec), ==, "ieee8021x"); - /* ===== 802.1x SETTING ===== */ - s_8021x = nm_connection_get_setting_802_1x(connection); - g_assert(s_8021x); + s_8021x = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_802_1X); /* EAP methods */ g_assert_cmpint(nm_setting_802_1x_get_num_eap_methods(s_8021x), ==, 1); @@ -3841,38 +3308,32 @@ test_read_wifi_wep_eap_ttls_chap(void) g_assert_cmpstr(nm_setting_802_1x_get_phase2_auth(s_8021x), ==, "chap"); g_assert_cmpstr(nm_setting_802_1x_get_identity(s_8021x), ==, "David Smith"); g_assert_cmpstr(nm_setting_802_1x_get_password(s_8021x), ==, "foobar baz"); - - g_object_unref(connection); } static void test_read_wired_wake_on_lan(void) { - NMConnection * connection; - NMSettingConnection *s_con; - NMSettingWired * s_wired; + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection * s_con; + NMSettingWired * s_wired; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wired-wake-on-lan", NULL, TYPE_WIRELESS, NULL); - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con); + s_con = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); g_assert_cmpstr(nm_setting_connection_get_connection_type(s_con), ==, NM_SETTING_WIRED_SETTING_NAME); - s_wired = nm_connection_get_setting_wired(connection); - g_assert(s_wired); + s_wired = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRED); g_assert_cmpint(nm_setting_wired_get_wake_on_lan(s_wired), ==, NM_SETTING_WIRED_WAKE_ON_LAN_ARP | NM_SETTING_WIRED_WAKE_ON_LAN_PHY | NM_SETTING_WIRED_WAKE_ON_LAN_MAGIC); g_assert_cmpstr(nm_setting_wired_get_wake_on_lan_password(s_wired), ==, "00:11:22:33:44:55"); - - g_object_unref(connection); } static void @@ -3887,14 +3348,12 @@ test_read_wired_auto_negotiate_off(void) TYPE_ETHERNET, NULL); - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con); + s_con = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); g_assert_cmpstr(nm_setting_connection_get_connection_type(s_con), ==, NM_SETTING_WIRED_SETTING_NAME); - s_wired = nm_connection_get_setting_wired(connection); - g_assert(s_wired); + s_wired = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRED); g_assert(!nm_setting_wired_get_auto_negotiate(s_wired)); g_assert_cmpint(nm_setting_wired_get_speed(s_wired), ==, 100); @@ -3913,14 +3372,12 @@ test_read_wired_auto_negotiate_on(void) TYPE_ETHERNET, NULL); - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con); + s_con = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); g_assert_cmpstr(nm_setting_connection_get_connection_type(s_con), ==, NM_SETTING_WIRED_SETTING_NAME); - s_wired = nm_connection_get_setting_wired(connection); - g_assert(s_wired); + s_wired = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRED); g_assert(nm_setting_wired_get_auto_negotiate(s_wired)); g_assert_cmpint(nm_setting_wired_get_speed(s_wired), ==, 0); @@ -3939,14 +3396,12 @@ test_read_wired_unknown_ethtool_opt(void) TYPE_ETHERNET, NULL); - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con); + s_con = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); g_assert_cmpstr(nm_setting_connection_get_connection_type(s_con), ==, NM_SETTING_WIRED_SETTING_NAME); - s_wired = nm_connection_get_setting_wired(connection); - g_assert(s_wired); + s_wired = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRED); g_assert(!nm_setting_wired_get_auto_negotiate(s_wired)); g_assert(!nm_setting_wired_get_speed(s_wired)); @@ -3980,8 +3435,8 @@ test_roundtrip_ethtool(void) NULL, NM_SETTING_WIRED_SETTING_NAME, NULL); - s_ethtool = nm_setting_ethtool_new(); - nm_connection_add_setting(connection, s_ethtool); + + s_ethtool = _nm_connection_new_setting(connection, NM_TYPE_SETTING_ETHTOOL); _writer_new_connec_exp(connection, TEST_SCRATCH_DIR, TEST_IFCFG_DIR "/ifcfg-test_roundtrip_ethtool-2.cexpected", @@ -3992,7 +3447,7 @@ test_roundtrip_ethtool(void) NULL, NM_SETTING_WIRED_SETTING_NAME, NULL); - s_wired = nm_connection_get_setting(connection, NM_TYPE_SETTING_WIRED); + s_wired = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRED); g_object_set(s_wired, NM_SETTING_WIRED_AUTO_NEGOTIATE, TRUE, NULL); _writer_new_connec_exp(connection, TEST_SCRATCH_DIR, @@ -4004,8 +3459,8 @@ test_roundtrip_ethtool(void) NULL, NM_SETTING_WIRED_SETTING_NAME, NULL); - s_ethtool = nm_setting_ethtool_new(); - nm_connection_add_setting(connection, s_ethtool); + + s_ethtool = _nm_connection_new_setting(connection, NM_TYPE_SETTING_ETHTOOL); nm_setting_option_set_boolean(s_ethtool, NM_ETHTOOL_OPTNAME_FEATURE_RX, TRUE); _writer_new_connec_exp(connection, TEST_SCRATCH_DIR, @@ -4017,10 +3472,10 @@ test_roundtrip_ethtool(void) NULL, NM_SETTING_WIRED_SETTING_NAME, NULL); - s_wired = nm_connection_get_setting(connection, NM_TYPE_SETTING_WIRED); + s_wired = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRED); g_object_set(s_wired, NM_SETTING_WIRED_AUTO_NEGOTIATE, TRUE, NULL); - s_ethtool = nm_setting_ethtool_new(); - nm_connection_add_setting(connection, s_ethtool); + + s_ethtool = _nm_connection_new_setting(connection, NM_TYPE_SETTING_ETHTOOL); nm_setting_option_set_boolean(s_ethtool, NM_ETHTOOL_OPTNAME_FEATURE_RX, TRUE); _writer_new_connec_exp(connection, TEST_SCRATCH_DIR, @@ -4032,24 +3487,20 @@ test_roundtrip_ethtool(void) static void test_read_wifi_hidden(void) { - NMConnection * connection; - NMSettingConnection *s_con; - NMSettingWireless * s_wifi; + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection * s_con; + NMSettingWireless * s_wifi; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wifi-hidden", NULL, TYPE_WIRELESS, NULL); - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con); + s_con = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); g_assert_cmpstr(nm_setting_connection_get_connection_type(s_con), ==, NM_SETTING_WIRELESS_SETTING_NAME); - s_wifi = nm_connection_get_setting_wireless(connection); - g_assert(s_wifi); + s_wifi = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRELESS); g_assert(nm_setting_wireless_get_hidden(s_wifi) == TRUE); - - g_object_unref(connection); } static void @@ -4061,15 +3512,12 @@ test_write_wifi_hidden(void) NMSettingConnection * s_con; NMSettingWireless * s_wifi; shvarFile * f; - GBytes * ssid; - const unsigned char ssid_data[] = {0x54, 0x65, 0x73, 0x74, 0x20, 0x53, 0x53, 0x49, 0x44}; + gs_unref_bytes GBytes *ssid = + nmtst_gbytes_from_arr(0x54, 0x65, 0x73, 0x74, 0x20, 0x53, 0x53, 0x49, 0x44); connection = nm_simple_connection_new(); - /* Connection setting */ - s_con = (NMSettingConnection *) nm_setting_connection_new(); - nm_connection_add_setting(connection, NM_SETTING(s_con)); - + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); g_object_set(s_con, NM_SETTING_CONNECTION_ID, "Test Write Wi-Fi Hidden", @@ -4079,16 +3527,9 @@ test_write_wifi_hidden(void) NM_SETTING_WIRELESS_SETTING_NAME, NULL); - /* Wifi setting */ - s_wifi = (NMSettingWireless *) nm_setting_wireless_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wifi)); - - ssid = g_bytes_new(ssid_data, sizeof(ssid_data)); - + s_wifi = _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRELESS); g_object_set(s_wifi, NM_SETTING_WIRELESS_SSID, ssid, NM_SETTING_WIRELESS_HIDDEN, TRUE, NULL); - g_bytes_unref(ssid); - nmtst_assert_connection_verifies(connection); _writer_new_connec_exp(connection, @@ -4121,8 +3562,7 @@ test_read_wifi_mac_random(gconstpointer user_data) path = g_strdup_printf(TEST_IFCFG_DIR "/ifcfg-test-wifi-mac-random-%s", name); connection = _connection_from_file(path, NULL, TYPE_WIRELESS, NULL); - s_wifi = nm_connection_get_setting_wireless(connection); - g_assert(s_wifi); + s_wifi = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRELESS); g_assert_cmpint(nm_setting_wireless_get_mac_address_randomization(s_wifi), ==, value); } @@ -4134,10 +3574,10 @@ test_write_wifi_mac_random(gconstpointer user_data) gs_unref_object NMConnection *reread = NULL; NMSettingConnection * s_con; NMSettingWireless * s_wifi; - char * val; + gs_free char * val = NULL; shvarFile * f; - GBytes * ssid; - const unsigned char ssid_data[] = {0x54, 0x65, 0x73, 0x74, 0x20, 0x53, 0x53, 0x49, 0x44}; + gs_unref_bytes GBytes *ssid = + nmtst_gbytes_from_arr(0x54, 0x65, 0x73, 0x74, 0x20, 0x53, 0x53, 0x49, 0x44); const char * name, *write_expected; gpointer value_p; NMSettingMacRandomization value; @@ -4150,9 +3590,7 @@ test_write_wifi_mac_random(gconstpointer user_data) connection = nm_simple_connection_new(); - /* Connection setting */ - s_con = (NMSettingConnection *) nm_setting_connection_new(); - nm_connection_add_setting(connection, NM_SETTING(s_con)); + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); val = g_strdup_printf("Test Write Wi-Fi MAC %s", name); g_object_set(s_con, @@ -4163,13 +3601,8 @@ test_write_wifi_mac_random(gconstpointer user_data) NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRELESS_SETTING_NAME, NULL); - g_free(val); - - /* Wifi setting */ - s_wifi = (NMSettingWireless *) nm_setting_wireless_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wifi)); - ssid = g_bytes_new(ssid_data, sizeof(ssid_data)); + s_wifi = _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRELESS); g_object_set(s_wifi, NM_SETTING_WIRELESS_SSID, ssid, @@ -4178,7 +3611,6 @@ test_write_wifi_mac_random(gconstpointer user_data) NM_SETTING_WIRELESS_MAC_ADDRESS_RANDOMIZATION, value, NULL); - g_bytes_unref(ssid); nmtst_assert_connection_verifies(connection); @@ -4205,16 +3637,12 @@ test_write_wired_wake_on_lan(void) gs_unref_object NMConnection *reread = NULL; NMSettingConnection * s_con; NMSettingWired * s_wired; - NMSettingWiredWakeOnLan wol; - char * val; + gs_free char * val = NULL; shvarFile * f; connection = nm_simple_connection_new(); - /* Connection setting */ - s_con = (NMSettingConnection *) nm_setting_connection_new(); - nm_connection_add_setting(connection, NM_SETTING(s_con)); - + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); g_object_set(s_con, NM_SETTING_CONNECTION_ID, "Test Write Wired Wake-on-LAN", @@ -4224,16 +3652,12 @@ test_write_wired_wake_on_lan(void) NM_SETTING_WIRED_SETTING_NAME, NULL); - /* Wired setting */ - s_wired = (NMSettingWired *) nm_setting_wired_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wired)); - - wol = NM_SETTING_WIRED_WAKE_ON_LAN_MULTICAST | NM_SETTING_WIRED_WAKE_ON_LAN_UNICAST - | NM_SETTING_WIRED_WAKE_ON_LAN_MAGIC; - + s_wired = _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRED); g_object_set(s_wired, NM_SETTING_WIRED_WAKE_ON_LAN, - wol, + (guint) (NM_SETTING_WIRED_WAKE_ON_LAN_MULTICAST + | NM_SETTING_WIRED_WAKE_ON_LAN_UNICAST + | NM_SETTING_WIRED_WAKE_ON_LAN_MAGIC), NM_SETTING_WIRED_WAKE_ON_LAN_PASSWORD, "00:00:00:11:22:33", NULL); @@ -4250,7 +3674,6 @@ test_write_wired_wake_on_lan(void) g_assert(val); g_assert(strstr(val, "wol")); g_assert(strstr(val, "sopass 00:00:00:11:22:33")); - g_free(val); svCloseFile(f); reread = _connection_from_file(testfile, NULL, TYPE_ETHERNET, NULL); @@ -4265,14 +3688,14 @@ test_write_wired_auto_negotiate_off(void) gs_unref_object NMConnection *connection = NULL; gs_unref_object NMConnection *reread = NULL; NMSettingWired * s_wired; - char * val; + gs_free char * val = NULL; shvarFile * f; connection = nmtst_create_minimal_connection("Test Write Wired Auto-Negotiate", NULL, NM_SETTING_WIRED_SETTING_NAME, NULL); - s_wired = nm_connection_get_setting_wired(connection); + s_wired = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRED); g_object_set(s_wired, NM_SETTING_WIRED_AUTO_NEGOTIATE, FALSE, @@ -4293,7 +3716,6 @@ test_write_wired_auto_negotiate_off(void) g_assert(strstr(val, "autoneg off")); g_assert(strstr(val, "speed 10")); g_assert(strstr(val, "duplex half")); - g_free(val); svCloseFile(f); reread = _connection_from_file(testfile, NULL, TYPE_ETHERNET, NULL); @@ -4309,20 +3731,19 @@ test_write_wired_auto_negotiate_on(void) gs_unref_object NMConnection *reread = NULL; NMSettingWired * s_wired; NMSettingEthtool * s_ethtool; - char * val; + gs_free char * val = NULL; shvarFile * f; connection = nmtst_create_minimal_connection("Test Write Wired Auto-Negotiate", NULL, NM_SETTING_WIRED_SETTING_NAME, NULL); - s_wired = nm_connection_get_setting_wired(connection); + s_wired = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRED); g_object_set(s_wired, NM_SETTING_WIRED_AUTO_NEGOTIATE, TRUE, NULL); - s_ethtool = NM_SETTING_ETHTOOL(nm_setting_ethtool_new()); + s_ethtool = _nm_connection_new_setting(connection, NM_TYPE_SETTING_ETHTOOL); nm_setting_ethtool_set_feature(s_ethtool, NM_ETHTOOL_OPTNAME_FEATURE_TX, NM_TERNARY_TRUE); nm_setting_ethtool_set_feature(s_ethtool, NM_ETHTOOL_OPTNAME_FEATURE_RXVLAN, NM_TERNARY_FALSE); - nm_connection_add_setting(connection, NM_SETTING(s_ethtool)); _writer_new_connec_exp(connection, TEST_SCRATCH_DIR, @@ -4335,7 +3756,6 @@ test_write_wired_auto_negotiate_on(void) g_assert(strstr(val, "autoneg on")); g_assert(!strstr(val, "speed")); g_assert(!strstr(val, "duplex")); - g_free(val); svCloseFile(f); reread = _connection_from_file(testfile, NULL, TYPE_ETHERNET, NULL); @@ -4344,8 +3764,7 @@ test_write_wired_auto_negotiate_on(void) nmtst_assert_connection_equals(connection, TRUE, reread, FALSE); - s_ethtool = NM_SETTING_ETHTOOL(nm_connection_get_setting(reread, NM_TYPE_SETTING_ETHTOOL)); - g_assert(s_ethtool); + s_ethtool = nmtst_connection_assert_setting(reread, NM_TYPE_SETTING_ETHTOOL); g_assert_cmpint(nm_setting_ethtool_get_feature(s_ethtool, NM_ETHTOOL_OPTNAME_FEATURE_TX), ==, NM_TERNARY_TRUE); @@ -4360,24 +3779,20 @@ test_write_wired_auto_negotiate_on(void) static void test_read_wifi_band_a(void) { - NMConnection * connection; - NMSettingConnection *s_con; - NMSettingWireless * s_wifi; + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection * s_con; + NMSettingWireless * s_wifi; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wifi-band-a", NULL, TYPE_WIRELESS, NULL); - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con); + s_con = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); g_assert_cmpstr(nm_setting_connection_get_connection_type(s_con), ==, NM_SETTING_WIRELESS_SETTING_NAME); - s_wifi = nm_connection_get_setting_wireless(connection); - g_assert(s_wifi); + s_wifi = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRELESS); g_assert_cmpstr(nm_setting_wireless_get_band(s_wifi), ==, "a"); - - g_object_unref(connection); } static void @@ -4389,15 +3804,12 @@ test_write_wifi_band_a(void) NMSettingConnection * s_con; NMSettingWireless * s_wifi; shvarFile * f; - GBytes * ssid; - const unsigned char ssid_data[] = {0x54, 0x65, 0x73, 0x74, 0x20, 0x53, 0x53, 0x49, 0x44}; + gs_unref_bytes GBytes *ssid = + nmtst_gbytes_from_arr(0x54, 0x65, 0x73, 0x74, 0x20, 0x53, 0x53, 0x49, 0x44); connection = nm_simple_connection_new(); - /* Connection setting */ - s_con = (NMSettingConnection *) nm_setting_connection_new(); - nm_connection_add_setting(connection, NM_SETTING(s_con)); - + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); g_object_set(s_con, NM_SETTING_CONNECTION_ID, "Test Write Wi-Fi Band A", @@ -4407,12 +3819,7 @@ test_write_wifi_band_a(void) NM_SETTING_WIRELESS_SETTING_NAME, NULL); - /* Wifi setting */ - s_wifi = (NMSettingWireless *) nm_setting_wireless_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wifi)); - - ssid = g_bytes_new(ssid_data, sizeof(ssid_data)); - + s_wifi = _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRELESS); g_object_set(s_wifi, NM_SETTING_WIRELESS_SSID, ssid, @@ -4422,8 +3829,6 @@ test_write_wifi_band_a(void) "a", NULL); - g_bytes_unref(ssid); - nmtst_assert_connection_verifies(connection); _writer_new_connec_exp(connection, @@ -4448,14 +3853,11 @@ test_write_wifi_ap_mode(void) gs_unref_object NMConnection *reread = NULL; NMSettingConnection * s_con; NMSettingWireless * s_wifi; - gs_unref_bytes GBytes *ssid = NULL; + gs_unref_bytes GBytes *ssid = nmtst_gbytes_from_str("MySSID"); connection = nm_simple_connection_new(); - /* Connection setting */ - s_con = (NMSettingConnection *) nm_setting_connection_new(); - nm_connection_add_setting(connection, NM_SETTING(s_con)); - + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); g_object_set(s_con, NM_SETTING_CONNECTION_ID, "Test Write Wi-Fi AP Mode", @@ -4465,12 +3867,7 @@ test_write_wifi_ap_mode(void) NM_SETTING_WIRELESS_SETTING_NAME, NULL); - /* Wifi setting */ - s_wifi = (NMSettingWireless *) nm_setting_wireless_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wifi)); - - ssid = g_bytes_new("MySSID", NM_STRLEN("MySSID")); - + s_wifi = _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRELESS); g_object_set(s_wifi, NM_SETTING_WIRELESS_SSID, ssid, @@ -4523,12 +3920,12 @@ test_read_wifi_band_bg_channel_mismatch(void) static void test_read_wired_qeth_static(void) { - NMConnection * connection; - NMSettingConnection *s_con; - NMSettingWired * s_wired; - NMSettingIPConfig * s_ip4; - char * unmanaged = NULL; - const char *const * subchannels; + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection * s_con; + NMSettingWired * s_wired; + NMSettingIPConfig * s_ip4; + char * unmanaged = NULL; + const char *const * subchannels; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wired-qeth-static", NULL, @@ -4536,16 +3933,10 @@ test_read_wired_qeth_static(void) &unmanaged); g_assert(!unmanaged); - /* ===== CONNECTION SETTING ===== */ - - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con); + s_con = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); g_assert_cmpstr(nm_setting_connection_get_id(s_con), ==, "System test-wired-qeth-static"); - /* ===== WIRED SETTING ===== */ - - s_wired = nm_connection_get_setting_wired(connection); - g_assert(s_wired); + s_wired = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRED); g_assert(!nm_setting_wired_get_mac_address(s_wired)); @@ -4563,25 +3954,20 @@ test_read_wired_qeth_static(void) g_assert_cmpstr(nm_setting_wired_get_s390_option_by_key(s_wired, "portno"), ==, "0"); g_assert_cmpstr(nm_setting_wired_get_s390_option_by_key(s_wired, "layer2"), ==, "1"); - /* ===== IPv4 SETTING ===== */ - - s_ip4 = nm_connection_get_setting_ip4_config(connection); - g_assert(s_ip4); + s_ip4 = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_MANUAL); - - g_object_unref(connection); } static void test_read_wired_ctc_static(void) { - NMConnection * connection; - NMSettingConnection *s_con; - NMSettingWired * s_wired; - char * unmanaged = NULL; - const char *const * subchannels; + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection * s_con; + NMSettingWired * s_wired; + char * unmanaged = NULL; + const char *const * subchannels; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wired-ctc-static", NULL, @@ -4589,14 +3975,10 @@ test_read_wired_ctc_static(void) &unmanaged); g_assert(unmanaged == NULL); - /* ===== CONNECTION SETTING ===== */ - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con != NULL); + s_con = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); g_assert_cmpstr(nm_setting_connection_get_id(s_con), ==, "System test-wired-ctc-static"); - /* ===== WIRED SETTING ===== */ - s_wired = nm_connection_get_setting_wired(connection); - g_assert(s_wired != NULL); + s_wired = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRED); g_assert(nm_setting_wired_get_mac_address(s_wired) == NULL); @@ -4610,28 +3992,22 @@ test_read_wired_ctc_static(void) g_assert_cmpstr(nm_setting_wired_get_s390_nettype(s_wired), ==, "ctc"); g_assert_cmpstr(nm_setting_wired_get_s390_option_by_key(s_wired, "ctcprot"), ==, "0"); - - g_object_unref(connection); } static void test_read_wifi_wep_no_keys(void) { - NMConnection * connection; - NMSettingConnection * s_con; - NMSettingWireless * s_wireless; - NMSettingWirelessSecurity *s_wsec; - NMWepKeyType key_type; + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection * s_con; + NMSettingWirelessSecurity * s_wsec; + NMWepKeyType key_type; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wifi-wep-no-keys", NULL, TYPE_WIRELESS, NULL); - /* ===== CONNECTION SETTING ===== */ - - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con); + s_con = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); g_assert_cmpstr(nm_setting_connection_get_id(s_con), ==, "System foobar (test-wifi-wep-no-keys)"); @@ -4641,15 +4017,9 @@ test_read_wifi_wep_no_keys(void) * depending on where the tests are run. */ - /* ===== WIRELESS SETTING ===== */ - - s_wireless = nm_connection_get_setting_wireless(connection); - g_assert(s_wireless); - - /* ===== WIRELESS SECURITY SETTING ===== */ + nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRELESS); - s_wsec = nm_connection_get_setting_wireless_security(connection); - g_assert(s_wsec); + s_wsec = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRELESS_SECURITY); /* Key management */ g_assert_cmpstr(nm_setting_wireless_security_get_key_mgmt(s_wsec), ==, "none"); @@ -4663,26 +4033,21 @@ test_read_wifi_wep_no_keys(void) /* WEP key index 0; we don't expect it to be filled */ g_assert(!nm_setting_wireless_security_get_wep_key(s_wsec, 0)); - - g_object_unref(connection); } static void test_read_permissions(void) { - NMConnection * connection; - NMSettingConnection *s_con; - gboolean success; - guint32 num; - const char * tmp; + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection * s_con; + gboolean success; + guint32 num; + const char * tmp; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-permissions", NULL, TYPE_ETHERNET, NULL); - /* ===== CONNECTION SETTING ===== */ - - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con); + s_con = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); num = nm_setting_connection_get_num_permissions(s_con); g_assert_cmpint(num, ==, 3); @@ -4702,18 +4067,15 @@ test_read_permissions(void) success = nm_setting_connection_get_permission(s_con, 2, NULL, &tmp, NULL); g_assert(success); g_assert_cmpstr(tmp, ==, "johnny5"); - - g_object_unref(connection); } static void test_read_wifi_wep_agent_keys(void) { - NMConnection * connection; - NMSettingWireless * s_wifi; - NMSettingWirelessSecurity *s_wsec; - NMWepKeyType key_type; - NMSettingSecretFlags flags; + gs_unref_object NMConnection *connection = NULL; + NMSettingWirelessSecurity * s_wsec; + NMWepKeyType key_type; + NMSettingSecretFlags flags; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wifi-wep-agent-keys", NULL, @@ -4724,13 +4086,9 @@ test_read_wifi_wep_agent_keys(void) * we don't have any WEP keys because they are agent owned. */ - /* ===== WIRELESS SETTING ===== */ - s_wifi = nm_connection_get_setting_wireless(connection); - g_assert(s_wifi); + nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRELESS); - /* ===== WIRELESS SECURITY SETTING ===== */ - s_wsec = nm_connection_get_setting_wireless_security(connection); - g_assert(s_wsec); + s_wsec = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRELESS_SECURITY); g_assert(strcmp(nm_setting_wireless_security_get_key_mgmt(s_wsec), "none") == 0); g_assert(nm_setting_wireless_security_get_wep_tx_keyidx(s_wsec) == 0); @@ -4743,8 +4101,6 @@ test_read_wifi_wep_agent_keys(void) flags = nm_setting_wireless_security_get_wep_key_flags(s_wsec); g_assert(flags & NM_SETTING_SECRET_FLAG_AGENT_OWNED); - - g_object_unref(connection); } static void @@ -4765,10 +4121,7 @@ test_write_wired_static(void) connection = nm_simple_connection_new(); - /* Connection setting */ - s_con = (NMSettingConnection *) nm_setting_connection_new(); - nm_connection_add_setting(connection, NM_SETTING(s_con)); - + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); g_object_set(s_con, NM_SETTING_CONNECTION_ID, "Test Write Wired Static", @@ -4782,10 +4135,7 @@ test_write_wired_static(void) NM_SETTING_WIRED_SETTING_NAME, NULL); - /* Wired setting */ - s_wired = (NMSettingWired *) nm_setting_wired_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wired)); - + s_wired = _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRED); g_object_set(s_wired, NM_SETTING_WIRED_MAC_ADDRESS, "31:33:33:37:be:cd", @@ -4793,10 +4143,7 @@ test_write_wired_static(void) (guint32) 1492, NULL); - /* IP4 setting */ - s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip4)); - + s_ip4 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL, @@ -4824,10 +4171,7 @@ test_write_wired_static(void) nm_setting_ip_config_add_dns_search(s_ip4, "foobar.com"); nm_setting_ip_config_add_dns_search(s_ip4, "lab.foobar.com"); - /* IP6 setting */ - s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip6)); - + s_ip6 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP6_CONFIG); g_object_set(s_ip6, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_MANUAL, @@ -4891,13 +4235,13 @@ test_write_wired_static(void) reread = _connection_from_file(testfile, NULL, TYPE_ETHERNET, NULL); - reread_s_ip4 = nm_connection_get_setting_ip4_config(reread); - reread_s_ip6 = nm_connection_get_setting_ip6_config(reread); + reread_s_ip4 = nmtst_connection_assert_setting(reread, NM_TYPE_SETTING_IP4_CONFIG); + reread_s_ip6 = nmtst_connection_assert_setting(reread, NM_TYPE_SETTING_IP6_CONFIG); g_assert_cmpint(nm_setting_ip_config_get_route_metric(reread_s_ip4), ==, 204); g_assert_cmpint(nm_setting_ip_config_get_route_metric(reread_s_ip6), ==, 206); - nm_connection_add_setting(connection, nm_setting_proxy_new()); + _nm_connection_new_setting(connection, NM_TYPE_SETTING_PROXY); nmtst_assert_connection_equals(connection, FALSE, reread, FALSE); } @@ -4920,10 +4264,7 @@ test_write_wired_static_with_generic(void) connection = nm_simple_connection_new(); - /* Connection setting */ - s_con = (NMSettingConnection *) nm_setting_connection_new(); - nm_connection_add_setting(connection, NM_SETTING(s_con)); - + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); g_object_set(s_con, NM_SETTING_CONNECTION_ID, "Test Write Wired Static", @@ -4937,10 +4278,7 @@ test_write_wired_static_with_generic(void) NM_SETTING_WIRED_SETTING_NAME, NULL); - /* Wired setting */ - s_wired = (NMSettingWired *) nm_setting_wired_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wired)); - + s_wired = _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRED); g_object_set(s_wired, NM_SETTING_WIRED_MAC_ADDRESS, "31:33:33:37:be:cd", @@ -4948,10 +4286,7 @@ test_write_wired_static_with_generic(void) (guint32) 1492, NULL); - /* IP4 setting */ - s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip4)); - + s_ip4 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL, @@ -4979,10 +4314,7 @@ test_write_wired_static_with_generic(void) nm_setting_ip_config_add_dns_search(s_ip4, "foobar.com"); nm_setting_ip_config_add_dns_search(s_ip4, "lab.foobar.com"); - /* IP6 setting */ - s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip6)); - + s_ip6 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP6_CONFIG); g_object_set(s_ip6, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_MANUAL, @@ -5039,21 +4371,22 @@ test_write_wired_static_with_generic(void) nm_setting_ip_config_add_dns_search(s_ip6, "foobar6.com"); nm_setting_ip_config_add_dns_search(s_ip6, "lab6.foobar.com"); - nm_connection_add_setting(connection, nm_setting_generic_new()); + _nm_connection_new_setting(connection, NM_TYPE_SETTING_GENERIC); nmtst_assert_connection_verifies(connection); _writer_new_connection_FIXME(connection, TEST_SCRATCH_DIR, &testfile); route6file = utils_get_route6_path(testfile); - reread = _connection_from_file(testfile, NULL, TYPE_ETHERNET, NULL); - reread_s_ip4 = nm_connection_get_setting_ip4_config(reread); - reread_s_ip6 = nm_connection_get_setting_ip6_config(reread); + reread = _connection_from_file(testfile, NULL, TYPE_ETHERNET, NULL); + + reread_s_ip4 = nmtst_connection_assert_setting(reread, NM_TYPE_SETTING_IP4_CONFIG); + reread_s_ip6 = nmtst_connection_assert_setting(reread, NM_TYPE_SETTING_IP6_CONFIG); g_assert_cmpint(nm_setting_ip_config_get_route_metric(reread_s_ip4), ==, 204); g_assert_cmpint(nm_setting_ip_config_get_route_metric(reread_s_ip6), ==, 206); - nm_connection_add_setting(connection, nm_setting_proxy_new()); + _nm_connection_new_setting(connection, NM_TYPE_SETTING_PROXY); { gs_unref_hashtable GHashTable *diffs = NULL; @@ -5064,8 +4397,8 @@ test_write_wired_static_with_generic(void) g_assert(g_hash_table_lookup(diffs, "generic")); g_assert(!nm_connection_compare(connection, reread, NM_SETTING_COMPARE_FLAG_EXACT)); } - g_assert(!nm_connection_get_setting(reread, NM_TYPE_SETTING_GENERIC)); - nm_connection_add_setting(reread, nm_setting_generic_new()); + nmtst_connection_assert_no_setting(reread, NM_TYPE_SETTING_GENERIC); + _nm_connection_new_setting(reread, NM_TYPE_SETTING_GENERIC); { gs_unref_hashtable GHashTable *diffs = NULL; @@ -5082,16 +4415,12 @@ test_write_wired_dhcp(void) gs_unref_object NMConnection *connection = NULL; gs_unref_object NMConnection *reread = NULL; NMSettingConnection * s_con; - NMSettingWired * s_wired; NMSettingIPConfig * s_ip4; NMSettingIPConfig * s_ip6; connection = nm_simple_connection_new(); - /* Connection setting */ - s_con = (NMSettingConnection *) nm_setting_connection_new(); - nm_connection_add_setting(connection, NM_SETTING(s_con)); - + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); g_object_set(s_con, NM_SETTING_CONNECTION_ID, "Test Write Wired DHCP", @@ -5103,14 +4432,9 @@ test_write_wired_dhcp(void) NM_SETTING_WIRED_SETTING_NAME, NULL); - /* Wired setting */ - s_wired = (NMSettingWired *) nm_setting_wired_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wired)); - - /* IP4 setting */ - s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip4)); + _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRED); + s_ip4 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, @@ -5130,10 +4454,7 @@ test_write_wired_dhcp(void) nmtst_assert_connection_verifies(connection); - /* IP6 setting */ - s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip6)); - + s_ip6 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP6_CONFIG); g_object_set(s_ip6, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_DHCP, @@ -5195,15 +4516,12 @@ test_write_routing_rules(void) gs_unref_object NMConnection *connection = NULL; gs_unref_object NMConnection *reread = NULL; NMSettingConnection * s_con; - NMSettingWired * s_wired; NMSettingIPConfig * s_ip4; NMSettingIPConfig * s_ip6; connection = nm_simple_connection_new(); - s_con = (NMSettingConnection *) nm_setting_connection_new(); - nm_connection_add_setting(connection, NM_SETTING(s_con)); - + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); g_object_set(s_con, NM_SETTING_CONNECTION_ID, "Test Write Routing Rules", @@ -5215,17 +4533,12 @@ test_write_routing_rules(void) NM_SETTING_WIRED_SETTING_NAME, NULL); - s_wired = (NMSettingWired *) nm_setting_wired_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wired)); - - s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip4)); + _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRED); + s_ip4 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); - s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip6)); - + s_ip6 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP6_CONFIG); g_object_set(s_ip6, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_AUTO, NULL); _ip_routing_rule_add_to_setting(s_ip4, "pref 10 from 0.0.0.0/0 table 1"); @@ -5251,17 +4564,13 @@ test_write_wired_match(void) gs_unref_object NMConnection *connection = NULL; gs_unref_object NMConnection *reread = NULL; NMSettingConnection * s_con; - NMSettingWired * s_wired; NMSettingMatch * s_match; NMSettingIPConfig * s_ip4; NMSettingIPConfig * s_ip6; connection = nm_simple_connection_new(); - /* Connection setting */ - s_con = (NMSettingConnection *) nm_setting_connection_new(); - nm_connection_add_setting(connection, NM_SETTING(s_con)); - + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); g_object_set(s_con, NM_SETTING_CONNECTION_ID, "Test Write Wired with Match setting", @@ -5273,31 +4582,26 @@ test_write_wired_match(void) NM_SETTING_WIRED_SETTING_NAME, NULL); - /* Wired setting */ - s_wired = (NMSettingWired *) nm_setting_wired_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wired)); - - /* IP4 setting */ - s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip4)); + _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRED); + s_ip4 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); - /* IP6 setting */ - s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip6)); - - g_object_set(s_ip6, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, NULL); + s_ip6 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP6_CONFIG); + g_object_set(s_ip6, + NM_SETTING_IP_CONFIG_METHOD, + NM_SETTING_IP6_CONFIG_METHOD_IGNORE, + NM_SETTING_IP6_CONFIG_ADDR_GEN_MODE, + (int) NM_SETTING_IP6_CONFIG_ADDR_GEN_MODE_EUI64, + NULL); - /* Match setting */ - s_match = (NMSettingMatch *) nm_setting_match_new(); + s_match = _nm_connection_new_setting(connection, NM_TYPE_SETTING_MATCH); nm_setting_match_add_interface_name(s_match, "ens*"); nm_setting_match_add_interface_name(s_match, "eth 1?"); nm_setting_match_add_interface_name(s_match, "!veth*"); nm_setting_match_add_driver(s_match, "!virtio"); nm_setting_match_add_driver(s_match, "e1000e"); nm_setting_match_add_kernel_command_line(s_match, "!ip="); - nm_connection_add_setting(connection, NM_SETTING(s_match)); nmtst_assert_connection_verifies(connection); _writer_new_connec_exp(connection, @@ -5343,10 +4647,8 @@ test_read_write_wired_dhcp_send_hostname(void) NULL); /* Check dhcp-hostname and dhcp-send-hostname */ - s_ip4 = nm_connection_get_setting_ip4_config(connection); - s_ip6 = nm_connection_get_setting_ip6_config(connection); - g_assert(s_ip4); - g_assert(s_ip6); + s_ip4 = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); + s_ip6 = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_IP6_CONFIG); g_assert(nm_setting_ip_config_get_dhcp_send_hostname(s_ip4) == TRUE); g_assert_cmpstr(nm_setting_ip_config_get_dhcp_hostname(s_ip4), ==, "svata-pulec"); g_assert(!nm_setting_ip_config_get_dhcp_hostname(s_ip6)); @@ -5363,10 +4665,8 @@ test_read_write_wired_dhcp_send_hostname(void) nmtst_assert_connection_equals(connection, TRUE, reread, FALSE); /* Check dhcp-hostname and dhcp-send-hostname from the re-read connection. */ - s_ip4 = nm_connection_get_setting_ip4_config(reread); - s_ip6 = nm_connection_get_setting_ip6_config(reread); - g_assert(s_ip4); - g_assert(s_ip6); + s_ip4 = nmtst_connection_assert_setting(reread, NM_TYPE_SETTING_IP4_CONFIG); + s_ip6 = nmtst_connection_assert_setting(reread, NM_TYPE_SETTING_IP6_CONFIG); g_assert(nm_setting_ip_config_get_dhcp_send_hostname(s_ip4) == FALSE); g_assert_cmpstr(nm_setting_ip_config_get_dhcp_hostname(s_ip4), ==, dhcp_hostname); g_assert_cmpstr(nm_setting_ip_config_get_dhcp_hostname(s_ip6), ==, dhcp_hostname); @@ -5383,8 +4683,7 @@ test_read_wired_dhcpv6_hostname_fallback(void) TYPE_ETHERNET, NULL); - s_ip6 = nm_connection_get_setting_ip6_config(connection); - g_assert(s_ip6); + s_ip6 = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_IP6_CONFIG); g_assert(nm_setting_ip_config_get_dhcp_send_hostname(s_ip6) == TRUE); g_assert_cmpstr(nm_setting_ip_config_get_dhcp_hostname(s_ip6), ==, "fully.qualified.domain"); } @@ -5404,10 +4703,7 @@ test_write_wired_static_ip6_only(void) connection = nm_simple_connection_new(); - /* Connection setting */ - s_con = (NMSettingConnection *) nm_setting_connection_new(); - nm_connection_add_setting(connection, NM_SETTING(s_con)); - + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); g_object_set(s_con, NM_SETTING_CONNECTION_ID, "Test Write Wired Static IP6 Only", @@ -5419,22 +4715,13 @@ test_write_wired_static_ip6_only(void) NM_SETTING_WIRED_SETTING_NAME, NULL); - /* Wired setting */ - s_wired = (NMSettingWired *) nm_setting_wired_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wired)); - + s_wired = _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRED); g_object_set(s_wired, NM_SETTING_WIRED_MAC_ADDRESS, "31:33:33:37:be:cd", NULL); - /* IP4 setting */ - s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip4)); - + s_ip4 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_DISABLED, NULL); - /* IP6 setting */ - s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip6)); - + s_ip6 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP6_CONFIG); g_object_set(s_ip6, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_MANUAL, NULL); /* Add addresses */ @@ -5462,7 +4749,6 @@ test_write_ip6_disabled(void) gs_unref_object NMConnection *connection = NULL; gs_unref_object NMConnection *reread = NULL; NMSettingConnection * s_con; - NMSettingWired * s_wired; NMSettingIPConfig * s_ip4; NMSettingIPConfig * s_ip6; @@ -5471,16 +4757,18 @@ test_write_ip6_disabled(void) NM_SETTING_WIRED_SETTING_NAME, &s_con); - s_wired = (NMSettingWired *) nm_setting_wired_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wired)); + _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRED); - s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip4)); + s_ip4 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); - s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip6)); - g_object_set(s_ip6, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_DISABLED, NULL); + s_ip6 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP6_CONFIG); + g_object_set(s_ip6, + NM_SETTING_IP_CONFIG_METHOD, + NM_SETTING_IP6_CONFIG_METHOD_DISABLED, + NM_SETTING_IP6_CONFIG_ADDR_GEN_MODE, + (int) NM_SETTING_IP6_CONFIG_ADDR_GEN_MODE_EUI64, + NULL); nmtst_assert_connection_verifies(connection); @@ -5513,16 +4801,14 @@ test_write_wired_static_ip6_only_gw(gconstpointer user_data) NMSettingIPConfig * s_ip6; NMIPAddress * addr6; GError * error = NULL; - char * id = NULL; + gs_free char * id = NULL; gs_free char * written_ifcfg_gateway = NULL; const char * gateway6 = user_data; shvarFile * ifcfg; connection = nm_simple_connection_new(); - /* Connection setting */ - s_con = (NMSettingConnection *) nm_setting_connection_new(); - nm_connection_add_setting(connection, NM_SETTING(s_con)); + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); id = g_strdup_printf("Test Write Wired Static IP6 Only With Gateway %s", gateway6 ?: "NULL"); g_object_set(s_con, @@ -5535,24 +4821,14 @@ test_write_wired_static_ip6_only_gw(gconstpointer user_data) NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRED_SETTING_NAME, NULL); - g_free(id); - - /* Wired setting */ - s_wired = (NMSettingWired *) nm_setting_wired_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wired)); + s_wired = _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRED); g_object_set(s_wired, NM_SETTING_WIRED_MAC_ADDRESS, "31:33:33:37:be:cd", NULL); - /* IP4 setting */ - s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip4)); - + s_ip4 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_DISABLED, NULL); - /* IP6 setting */ - s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip6)); - + s_ip6 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP6_CONFIG); g_object_set(s_ip6, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_MANUAL, @@ -5582,14 +4858,14 @@ test_write_wired_static_ip6_only_gw(gconstpointer user_data) svCloseFile(ifcfg); /* access the gateway from the loaded connection. */ - s_ip6 = nm_connection_get_setting_ip6_config(reread); - g_assert(s_ip6 && nm_setting_ip_config_get_num_addresses(s_ip6) == 1); + s_ip6 = nmtst_connection_assert_setting(reread, NM_TYPE_SETTING_IP6_CONFIG); + g_assert(nm_setting_ip_config_get_num_addresses(s_ip6) == 1); addr6 = nm_setting_ip_config_get_address(s_ip6, 0); g_assert(addr6); /* assert that the gateway was written and reloaded as expected */ if (!gateway6 || !strcmp(gateway6, "::")) { - g_assert(nm_setting_ip_config_get_gateway(s_ip6) == NULL); + g_assert_cmpstr(nm_setting_ip_config_get_gateway(s_ip6), ==, NULL); g_assert(written_ifcfg_gateway == NULL); } else { g_assert(nm_setting_ip_config_get_gateway(s_ip6) != NULL); @@ -5607,7 +4883,6 @@ test_read_write_static_routes_legacy(void) gs_unref_object NMConnection *connection = NULL; gs_unref_object NMConnection *reread = NULL; NMSettingConnection * s_con; - NMSettingWired * s_wired; NMSettingIPConfig * s_ip4; const char * tmp; @@ -5616,10 +4891,7 @@ test_read_write_static_routes_legacy(void) TYPE_ETHERNET, NULL); - /* ===== CONNECTION SETTING ===== */ - - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con); + s_con = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); /* ID */ tmp = nm_setting_connection_get_id(s_con); @@ -5628,15 +4900,9 @@ test_read_write_static_routes_legacy(void) /* Autoconnect */ g_assert(nm_setting_connection_get_autoconnect(s_con)); - /* ===== WIRED SETTING ===== */ - - s_wired = nm_connection_get_setting_wired(connection); - g_assert(s_wired); + nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRED); - /* ===== IPv4 SETTING ===== */ - - s_ip4 = nm_connection_get_setting_ip4_config(connection); - g_assert(s_ip4); + s_ip4 = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_AUTO); g_assert(!nm_setting_ip_config_get_never_default(s_ip4)); @@ -5676,10 +4942,7 @@ test_write_wired_static_routes(void) connection = nm_simple_connection_new(); - /* Connection setting */ - s_con = (NMSettingConnection *) nm_setting_connection_new(); - nm_connection_add_setting(connection, NM_SETTING(s_con)); - + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); g_object_set(s_con, NM_SETTING_CONNECTION_ID, "Test Write Wired Static Routes", @@ -5691,10 +4954,7 @@ test_write_wired_static_routes(void) NM_SETTING_WIRED_SETTING_NAME, NULL); - /* Wired setting */ - s_wired = (NMSettingWired *) nm_setting_wired_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wired)); - + s_wired = _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRED); g_object_set(s_wired, NM_SETTING_WIRED_MAC_ADDRESS, "31:33:33:37:be:cd", @@ -5702,10 +4962,7 @@ test_write_wired_static_routes(void) (guint32) 1492, NULL); - /* IP4 setting */ - s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip4)); - + s_ip4 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL, @@ -5746,15 +5003,14 @@ test_write_wired_static_routes(void) nm_setting_ip_config_add_dns_search(s_ip4, "foobar.com"); nm_setting_ip_config_add_dns_search(s_ip4, "lab.foobar.com"); - /* IP6 setting */ - s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip6)); - + s_ip6 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP6_CONFIG); g_object_set(s_ip6, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, NM_SETTING_IP_CONFIG_MAY_FAIL, TRUE, + NM_SETTING_IP6_CONFIG_ADDR_GEN_MODE, + (int) NM_SETTING_IP6_CONFIG_ADDR_GEN_MODE_EUI64, NULL); nmtst_assert_connection_verifies(connection); @@ -5770,8 +5026,7 @@ test_write_wired_static_routes(void) * connection equals. */ g_assert(!reread_same); nmtst_assert_connection_verifies_without_normalization(reread); - s_ip4 = nm_connection_get_setting_ip4_config(reread); - g_assert(s_ip4); + s_ip4 = nmtst_connection_assert_setting(reread, NM_TYPE_SETTING_IP4_CONFIG); g_assert_cmpint(nm_setting_ip_config_get_num_routes(s_ip4), ==, 2); route = nm_setting_ip_config_get_route(s_ip4, 1); g_assert(route); @@ -5791,7 +5046,6 @@ test_write_wired_dhcp_8021x_peap_mschapv2(void) gs_unref_object NMConnection *connection = NULL; gs_unref_object NMConnection *reread = NULL; NMSettingConnection * s_con; - NMSettingWired * s_wired; NMSettingIPConfig * s_ip4; NMSettingIPConfig * s_ip6; NMSetting8021x * s_8021x; @@ -5800,10 +5054,7 @@ test_write_wired_dhcp_8021x_peap_mschapv2(void) connection = nm_simple_connection_new(); - /* Connection setting */ - s_con = (NMSettingConnection *) nm_setting_connection_new(); - nm_connection_add_setting(connection, NM_SETTING(s_con)); - + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); g_object_set(s_con, NM_SETTING_CONNECTION_ID, "Test Write Wired DHCP 802.1x PEAP MSCHAPv2", @@ -5815,31 +5066,22 @@ test_write_wired_dhcp_8021x_peap_mschapv2(void) NM_SETTING_WIRED_SETTING_NAME, NULL); - /* Wired setting */ - s_wired = (NMSettingWired *) nm_setting_wired_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wired)); - - /* IP4 setting */ - s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip4)); + _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRED); + s_ip4 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); - /* IP6 setting */ - s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip6)); - + s_ip6 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP6_CONFIG); g_object_set(s_ip6, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, NM_SETTING_IP_CONFIG_MAY_FAIL, TRUE, + NM_SETTING_IP6_CONFIG_ADDR_GEN_MODE, + (int) NM_SETTING_IP6_CONFIG_ADDR_GEN_MODE_EUI64, NULL); - /* 802.1x setting */ - s_8021x = (NMSetting8021x *) nm_setting_802_1x_new(); - nm_connection_add_setting(connection, NM_SETTING(s_8021x)); - + s_8021x = _nm_connection_new_setting(connection, NM_TYPE_SETTING_802_1X); g_object_set(s_8021x, NM_SETTING_802_1X_IDENTITY, "Bob Saget", @@ -5854,7 +5096,6 @@ test_write_wired_dhcp_8021x_peap_mschapv2(void) NM_SETTING_802_1X_PHASE2_AUTH, "mschapv2", NULL); - nm_setting_802_1x_add_eap_method(s_8021x, "peap"); success = nm_setting_802_1x_set_ca_cert(s_8021x, @@ -5883,7 +5124,6 @@ test_write_wired_8021x_tls(gconstpointer test_data) gs_unref_object NMConnection *connection = NULL; gs_unref_object NMConnection *reread = NULL; NMSettingConnection * s_con; - NMSettingWired * s_wired; NMSettingIPConfig * s_ip4; NMSettingIPConfig * s_ip6; NMSetting8021x * s_8021x; @@ -5891,7 +5131,9 @@ test_write_wired_8021x_tls(gconstpointer test_data) GError * error = NULL; NMSetting8021xCKFormat format = NM_SETTING_802_1X_CK_FORMAT_UNKNOWN; const char * pw; - char * tmp; + gs_free char * tmp1 = NULL; + gs_free char * tmp2 = NULL; + gs_free char * tmp3 = NULL; gpointer scheme_p, flags_p; NMSetting8021xCKScheme scheme; NMSettingSecretFlags flags; @@ -5902,10 +5144,7 @@ test_write_wired_8021x_tls(gconstpointer test_data) connection = nm_simple_connection_new(); - /* Connection setting */ - s_con = (NMSettingConnection *) nm_setting_connection_new(); - nm_connection_add_setting(connection, NM_SETTING(s_con)); - + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); g_object_set(s_con, NM_SETTING_CONNECTION_ID, "Test Write Wired 802.1x TLS Blobs", @@ -5917,29 +5156,20 @@ test_write_wired_8021x_tls(gconstpointer test_data) NM_SETTING_WIRED_SETTING_NAME, NULL); - /* Wired setting */ - s_wired = (NMSettingWired *) nm_setting_wired_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wired)); + _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRED); - /* IP4 setting */ - s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); + s_ip4 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); - nm_connection_add_setting(connection, NM_SETTING(s_ip4)); - /* IP6 setting */ - s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); + s_ip6 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP6_CONFIG); g_object_set(s_ip6, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, NM_SETTING_IP_CONFIG_MAY_FAIL, TRUE, NULL); - nm_connection_add_setting(connection, NM_SETTING(s_ip6)); - - /* 802.1x setting */ - s_8021x = (NMSetting8021x *) nm_setting_802_1x_new(); - nm_connection_add_setting(connection, NM_SETTING(s_8021x)); + s_8021x = _nm_connection_new_setting(connection, NM_TYPE_SETTING_802_1X); g_object_set(s_8021x, NM_SETTING_802_1X_IDENTITY, "Bill Smith", NULL); nm_setting_802_1x_add_eap_method(s_8021x, "tls"); @@ -5992,8 +5222,7 @@ test_write_wired_8021x_tls(gconstpointer test_data) * matter what scheme was used in the original connection they will be read * back in as paths. */ - s_8021x = nm_connection_get_setting_802_1x(reread); - g_assert(s_8021x); + s_8021x = nmtst_connection_assert_setting(reread, NM_TYPE_SETTING_802_1X); g_assert_cmpint(nm_setting_802_1x_get_ca_cert_scheme(s_8021x), ==, NM_SETTING_802_1X_CK_SCHEME_PATH); @@ -6027,7 +5256,7 @@ test_write_wired_8021x_tls(gconstpointer test_data) * say it's not system-owned, and therefore it should not show up * in the re-read connection. */ - s_8021x = nm_connection_get_setting_802_1x(connection); + s_8021x = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_802_1X); g_object_set(s_8021x, NM_SETTING_802_1X_PRIVATE_KEY_PASSWORD, NULL, NULL); } @@ -6035,17 +5264,14 @@ test_write_wired_8021x_tls(gconstpointer test_data) } /* Clean up created certs and keys */ - tmp = utils_cert_path(testfile, "ca-cert", "der"); - nmtst_file_unlink_if_exists(tmp); - g_free(tmp); + tmp1 = utils_cert_path(testfile, "ca-cert", "der"); + nmtst_file_unlink_if_exists(tmp1); - tmp = utils_cert_path(testfile, "client-cert", "der"); - nmtst_file_unlink_if_exists(tmp); - g_free(tmp); + tmp2 = utils_cert_path(testfile, "client-cert", "der"); + nmtst_file_unlink_if_exists(tmp2); - tmp = utils_cert_path(testfile, "private-key", "pem"); - nmtst_file_unlink_if_exists(tmp); - g_free(tmp); + tmp3 = utils_cert_path(testfile, "private-key", "pem"); + nmtst_file_unlink_if_exists(tmp3); } static void @@ -6055,7 +5281,6 @@ test_write_wired_aliases(void) gs_unref_object NMConnection *connection = NULL; gs_unref_object NMConnection *reread = NULL; NMSettingConnection * s_con; - NMSettingWired * s_wired; NMSettingIPConfig * s_ip4; int num_addresses = 4; const char * ip[] = {"1.1.1.1", "1.1.1.2", "1.1.1.3", "1.1.1.4"}; @@ -6072,10 +5297,7 @@ test_write_wired_aliases(void) connection = nm_simple_connection_new(); g_assert(connection); - /* Connection setting */ - s_con = (NMSettingConnection *) nm_setting_connection_new(); - nm_connection_add_setting(connection, NM_SETTING(s_con)); - + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); g_object_set(s_con, NM_SETTING_CONNECTION_ID, "alias0", @@ -6085,14 +5307,9 @@ test_write_wired_aliases(void) NM_SETTING_WIRED_SETTING_NAME, NULL); - /* Wired setting */ - s_wired = (NMSettingWired *) nm_setting_wired_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wired)); - - /* IP4 setting */ - s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip4)); + _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRED); + s_ip4 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL, @@ -6145,7 +5362,7 @@ test_write_wired_aliases(void) * aliases get read back in essentially random order. So just * verify the aliases manually. */ - s_ip4 = nm_connection_get_setting_ip4_config(connection); + s_ip4 = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_assert(nm_setting_ip_config_get_num_addresses(s_ip4) == num_addresses); /* Addresses */ @@ -6191,7 +5408,6 @@ test_write_gateway(void) gs_unref_object NMConnection *connection = NULL; gs_unref_object NMConnection *reread = NULL; NMSettingConnection * s_con; - NMSettingWired * s_wired; NMSettingIPConfig * s_ip4; GError * error = NULL; shvarFile * f; @@ -6199,10 +5415,7 @@ test_write_gateway(void) connection = nm_simple_connection_new(); - /* Connection setting */ - s_con = (NMSettingConnection *) nm_setting_connection_new(); - nm_connection_add_setting(connection, NM_SETTING(s_con)); - + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); g_object_set(s_con, NM_SETTING_CONNECTION_ID, "Test Write Static Addresses Gateway", @@ -6212,14 +5425,9 @@ test_write_gateway(void) NM_SETTING_WIRED_SETTING_NAME, NULL); - /* Wired setting */ - s_wired = (NMSettingWired *) nm_setting_wired_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wired)); - - /* IP4 setting */ - s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip4)); + _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRED); + s_ip4 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL, @@ -6270,16 +5478,13 @@ test_write_wifi_open(void) NMSettingWireless * s_wifi; NMSettingIPConfig * s_ip4; NMSettingIPConfig * s_ip6; - GBytes * ssid; - const unsigned char ssid_data[] = {0x54, 0x65, 0x73, 0x74, 0x20, 0x53, 0x53, 0x49, 0x44}; - shvarFile * ifcfg; + gs_unref_bytes GBytes *ssid = + nmtst_gbytes_from_arr(0x54, 0x65, 0x73, 0x74, 0x20, 0x53, 0x53, 0x49, 0x44); + shvarFile *ifcfg; connection = nm_simple_connection_new(); - /* Connection setting */ - s_con = (NMSettingConnection *) nm_setting_connection_new(); - nm_connection_add_setting(connection, NM_SETTING(s_con)); - + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); g_object_set(s_con, NM_SETTING_CONNECTION_ID, "Test Write Wifi Open", @@ -6291,12 +5496,7 @@ test_write_wifi_open(void) NM_SETTING_WIRELESS_SETTING_NAME, NULL); - /* Wifi setting */ - s_wifi = (NMSettingWireless *) nm_setting_wireless_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wifi)); - - ssid = g_bytes_new(ssid_data, sizeof(ssid_data)); - + s_wifi = _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRELESS); g_object_set(s_wifi, NM_SETTING_WIRELESS_SSID, ssid, @@ -6314,23 +5514,17 @@ test_write_wifi_open(void) (guint32) 1345, NULL); - g_bytes_unref(ssid); - - /* IP4 setting */ - s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip4)); - + s_ip4 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); - /* IP6 setting */ - s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip6)); - + s_ip6 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP6_CONFIG); g_object_set(s_ip6, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, NM_SETTING_IP_CONFIG_MAY_FAIL, TRUE, + NM_SETTING_IP6_CONFIG_ADDR_GEN_MODE, + (int) NM_SETTING_IP6_CONFIG_ADDR_GEN_MODE_EUI64, NULL); nmtst_assert_connection_verifies(connection); @@ -6356,16 +5550,23 @@ test_write_wifi_open_hex_ssid(void) NMSettingWireless * s_wifi; NMSettingIPConfig * s_ip4; NMSettingIPConfig * s_ip6; - GBytes * ssid; - const unsigned char ssid_data[] = - {0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd}; + gs_unref_bytes GBytes *ssid = nmtst_gbytes_from_arr(0x11, + 0x22, + 0x33, + 0x44, + 0x55, + 0x66, + 0x77, + 0x88, + 0x99, + 0xaa, + 0xbb, + 0xcc, + 0xdd); connection = nm_simple_connection_new(); - /* Connection setting */ - s_con = (NMSettingConnection *) nm_setting_connection_new(); - nm_connection_add_setting(connection, NM_SETTING(s_con)); - + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); g_object_set(s_con, NM_SETTING_CONNECTION_ID, "Test Write Wifi Open Hex SSID", @@ -6377,12 +5578,7 @@ test_write_wifi_open_hex_ssid(void) NM_SETTING_WIRELESS_SETTING_NAME, NULL); - /* Wifi setting */ - s_wifi = (NMSettingWireless *) nm_setting_wireless_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wifi)); - - ssid = g_bytes_new(ssid_data, sizeof(ssid_data)); - + s_wifi = _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRELESS); g_object_set(s_wifi, NM_SETTING_WIRELESS_SSID, ssid, @@ -6390,18 +5586,10 @@ test_write_wifi_open_hex_ssid(void) "infrastructure", NULL); - g_bytes_unref(ssid); - - /* IP4 setting */ - s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip4)); - + s_ip4 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); - /* IP6 setting */ - s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip6)); - + s_ip6 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP6_CONFIG); g_object_set(s_ip6, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, @@ -6430,16 +5618,12 @@ test_write_wifi_wep(void) NMSettingWirelessSecurity * s_wsec; NMSettingIPConfig * s_ip4; NMSettingIPConfig * s_ip6; - GBytes * ssid; - const char * ssid_data = "blahblah"; - struct stat statbuf; + gs_unref_bytes GBytes *ssid = nmtst_gbytes_from_str("blahblah"); + struct stat statbuf; connection = nm_simple_connection_new(); - /* Connection setting */ - s_con = (NMSettingConnection *) nm_setting_connection_new(); - nm_connection_add_setting(connection, NM_SETTING(s_con)); - + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); g_object_set(s_con, NM_SETTING_CONNECTION_ID, "Test Write Wifi WEP", @@ -6451,12 +5635,7 @@ test_write_wifi_wep(void) NM_SETTING_WIRELESS_SETTING_NAME, NULL); - /* Wifi setting */ - s_wifi = (NMSettingWireless *) nm_setting_wireless_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wifi)); - - ssid = g_bytes_new(ssid_data, strlen(ssid_data)); - + s_wifi = _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRELESS); g_object_set(s_wifi, NM_SETTING_WIRELESS_SSID, ssid, @@ -6464,12 +5643,7 @@ test_write_wifi_wep(void) "infrastructure", NULL); - g_bytes_unref(ssid); - - /* Wireless security setting */ - s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wsec)); - + s_wsec = _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRELESS_SECURITY); g_object_set(s_wsec, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "none", @@ -6483,21 +5657,17 @@ test_write_wifi_wep(void) nm_setting_wireless_security_set_wep_key(s_wsec, 2, "aaaaaaaaaaaaaaaaaaaaaaaaaa"); nm_setting_wireless_security_set_wep_key(s_wsec, 3, "BBBBBBBBBBBBBBBBBBBBBBBBBB"); - /* IP4 setting */ - s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip4)); - + s_ip4 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); - /* IP6 setting */ - s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip6)); - + s_ip6 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP6_CONFIG); g_object_set(s_ip6, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, NM_SETTING_IP_CONFIG_MAY_FAIL, TRUE, + NM_SETTING_IP6_CONFIG_ADDR_GEN_MODE, + (int) NM_SETTING_IP6_CONFIG_ADDR_GEN_MODE_EUI64, NULL); nmtst_assert_connection_verifies(connection); @@ -6527,17 +5697,13 @@ test_write_wifi_wep_adhoc(void) NMSettingIPConfig * s_ip4; NMSettingIPConfig * s_ip6; GError * error = NULL; - GBytes * ssid; - const char * ssid_data = "blahblah"; - struct stat statbuf; - NMIPAddress * addr; + gs_unref_bytes GBytes *ssid = nmtst_gbytes_from_str("blahblah"); + struct stat statbuf; + NMIPAddress * addr; connection = nm_simple_connection_new(); - /* Connection setting */ - s_con = (NMSettingConnection *) nm_setting_connection_new(); - nm_connection_add_setting(connection, NM_SETTING(s_con)); - + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); g_object_set(s_con, NM_SETTING_CONNECTION_ID, "Test Write Wifi WEP AdHoc", @@ -6549,27 +5715,14 @@ test_write_wifi_wep_adhoc(void) NM_SETTING_WIRELESS_SETTING_NAME, NULL); - /* Wifi setting */ - s_wifi = (NMSettingWireless *) nm_setting_wireless_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wifi)); - - ssid = g_bytes_new(ssid_data, strlen(ssid_data)); - + s_wifi = _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRELESS); g_object_set(s_wifi, NM_SETTING_WIRELESS_SSID, ssid, NM_SETTING_WIRELESS_MODE, "adhoc", NULL); - g_bytes_unref(ssid); - - /* Wireless security setting */ - s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wsec)); - + s_wsec = _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRELESS_SECURITY); g_object_set(s_wsec, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "none", NULL); nm_setting_wireless_security_set_wep_key(s_wsec, 0, "0123456789abcdef0123456789"); - /* IP4 setting */ - s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip4)); - + s_ip4 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL, @@ -6585,10 +5738,7 @@ test_write_wifi_wep_adhoc(void) nm_setting_ip_config_add_dns(s_ip4, "4.2.2.1"); - /* IP6 setting */ - s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip6)); - + s_ip6 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP6_CONFIG); g_object_set(s_ip6, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, @@ -6622,16 +5772,12 @@ test_write_wifi_wep_passphrase(void) NMSettingWirelessSecurity * s_wsec; NMSettingIPConfig * s_ip4; NMSettingIPConfig * s_ip6; - GBytes * ssid; - const char * ssid_data = "blahblah"; - struct stat statbuf; + gs_unref_bytes GBytes *ssid = nmtst_gbytes_from_str("blahblah"); + struct stat statbuf; connection = nm_simple_connection_new(); - /* Connection setting */ - s_con = (NMSettingConnection *) nm_setting_connection_new(); - nm_connection_add_setting(connection, NM_SETTING(s_con)); - + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); g_object_set(s_con, NM_SETTING_CONNECTION_ID, "Test Write Wifi WEP Passphrase", @@ -6643,12 +5789,7 @@ test_write_wifi_wep_passphrase(void) NM_SETTING_WIRELESS_SETTING_NAME, NULL); - /* Wifi setting */ - s_wifi = (NMSettingWireless *) nm_setting_wireless_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wifi)); - - ssid = g_bytes_new(ssid_data, strlen(ssid_data)); - + s_wifi = _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRELESS); g_object_set(s_wifi, NM_SETTING_WIRELESS_SSID, ssid, @@ -6656,12 +5797,7 @@ test_write_wifi_wep_passphrase(void) "infrastructure", NULL); - g_bytes_unref(ssid); - - /* Wireless security setting */ - s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wsec)); - + s_wsec = _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRELESS_SECURITY); g_object_set(s_wsec, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "none", @@ -6674,16 +5810,10 @@ test_write_wifi_wep_passphrase(void) NULL); nm_setting_wireless_security_set_wep_key(s_wsec, 0, "asdfdjaslfjasd;flasjdfl;aksdf"); - /* IP4 setting */ - s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip4)); - + s_ip4 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); - /* IP6 setting */ - s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip6)); - + s_ip6 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP6_CONFIG); g_object_set(s_ip6, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, @@ -6717,16 +5847,12 @@ test_write_wifi_wep_40_ascii(void) NMSettingWirelessSecurity * s_wsec; NMSettingIPConfig * s_ip4; NMSettingIPConfig * s_ip6; - GBytes * ssid; - const char * ssid_data = "blahblah40"; - struct stat statbuf; + gs_unref_bytes GBytes *ssid = nmtst_gbytes_from_str("blahblah40"); + struct stat statbuf; connection = nm_simple_connection_new(); - /* Connection setting */ - s_con = (NMSettingConnection *) nm_setting_connection_new(); - nm_connection_add_setting(connection, NM_SETTING(s_con)); - + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); g_object_set(s_con, NM_SETTING_CONNECTION_ID, "Test Write Wifi WEP 40 ASCII", @@ -6738,12 +5864,7 @@ test_write_wifi_wep_40_ascii(void) NM_SETTING_WIRELESS_SETTING_NAME, NULL); - /* Wifi setting */ - s_wifi = (NMSettingWireless *) nm_setting_wireless_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wifi)); - - ssid = g_bytes_new(ssid_data, strlen(ssid_data)); - + s_wifi = _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRELESS); g_object_set(s_wifi, NM_SETTING_WIRELESS_SSID, ssid, @@ -6751,12 +5872,7 @@ test_write_wifi_wep_40_ascii(void) "infrastructure", NULL); - g_bytes_unref(ssid); - - /* Wireless security setting */ - s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wsec)); - + s_wsec = _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRELESS_SECURITY); g_object_set(s_wsec, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "none", @@ -6772,16 +5888,10 @@ test_write_wifi_wep_40_ascii(void) nm_setting_wireless_security_set_wep_key(s_wsec, 2, "dolor"); nm_setting_wireless_security_set_wep_key(s_wsec, 3, "donec"); - /* IP4 setting */ - s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip4)); - + s_ip4 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); - /* IP6 setting */ - s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip6)); - + s_ip6 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP6_CONFIG); g_object_set(s_ip6, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, @@ -6815,16 +5925,12 @@ test_write_wifi_wep_104_ascii(void) NMSettingWirelessSecurity * s_wsec; NMSettingIPConfig * s_ip4; NMSettingIPConfig * s_ip6; - GBytes * ssid; - const char * ssid_data = "blahblah104"; - struct stat statbuf; + gs_unref_bytes GBytes *ssid = nmtst_gbytes_from_str("blahblah104"); + struct stat statbuf; connection = nm_simple_connection_new(); - /* Connection setting */ - s_con = (NMSettingConnection *) nm_setting_connection_new(); - nm_connection_add_setting(connection, NM_SETTING(s_con)); - + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); g_object_set(s_con, NM_SETTING_CONNECTION_ID, "Test Write Wifi WEP 104 ASCII", @@ -6836,12 +5942,7 @@ test_write_wifi_wep_104_ascii(void) NM_SETTING_WIRELESS_SETTING_NAME, NULL); - /* Wifi setting */ - s_wifi = (NMSettingWireless *) nm_setting_wireless_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wifi)); - - ssid = g_bytes_new(ssid_data, strlen(ssid_data)); - + s_wifi = _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRELESS); g_object_set(s_wifi, NM_SETTING_WIRELESS_SSID, ssid, @@ -6849,12 +5950,7 @@ test_write_wifi_wep_104_ascii(void) "infrastructure", NULL); - g_bytes_unref(ssid); - - /* Wireless security setting */ - s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wsec)); - + s_wsec = _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRELESS_SECURITY); g_object_set(s_wsec, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "none", @@ -6870,16 +5966,10 @@ test_write_wifi_wep_104_ascii(void) nm_setting_wireless_security_set_wep_key(s_wsec, 2, "WEP-104 ASCII"); nm_setting_wireless_security_set_wep_key(s_wsec, 3, "thisismyascii"); - /* IP4 setting */ - s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip4)); - + s_ip4 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); - /* IP6 setting */ - s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip6)); - + s_ip6 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP6_CONFIG); g_object_set(s_ip6, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, @@ -6916,16 +6006,12 @@ test_write_wifi_leap(void) NMSettingWirelessSecurity * s_wsec; NMSettingIPConfig * s_ip4; NMSettingIPConfig * s_ip6; - GBytes * ssid; - const char * ssid_data = "blahblah"; - struct stat statbuf; + gs_unref_bytes GBytes *ssid = nmtst_gbytes_from_str("blahblah"); + struct stat statbuf; connection = nm_simple_connection_new(); - /* Connection setting */ - s_con = (NMSettingConnection *) nm_setting_connection_new(); - nm_connection_add_setting(connection, NM_SETTING(s_con)); - + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); g_object_set(s_con, NM_SETTING_CONNECTION_ID, "Test Write Wifi LEAP", @@ -6937,12 +6023,7 @@ test_write_wifi_leap(void) NM_SETTING_WIRELESS_SETTING_NAME, NULL); - /* Wifi setting */ - s_wifi = (NMSettingWireless *) nm_setting_wireless_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wifi)); - - ssid = g_bytes_new(ssid_data, strlen(ssid_data)); - + s_wifi = _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRELESS); g_object_set(s_wifi, NM_SETTING_WIRELESS_SSID, ssid, @@ -6950,12 +6031,7 @@ test_write_wifi_leap(void) "infrastructure", NULL); - g_bytes_unref(ssid); - - /* Wireless security setting */ - s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wsec)); - + s_wsec = _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRELESS_SECURITY); g_object_set(s_wsec, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "ieee8021x", @@ -6967,16 +6043,10 @@ test_write_wifi_leap(void) "foobar22", NULL); - /* IP4 setting */ - s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip4)); - + s_ip4 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); - /* IP6 setting */ - s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip6)); - + s_ip6 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP6_CONFIG); g_object_set(s_ip6, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, @@ -7013,17 +6083,13 @@ test_write_wifi_leap_secret_flags(gconstpointer data) NMSettingWirelessSecurity * s_wsec; NMSettingIPConfig * s_ip4; NMSettingIPConfig * s_ip6; - GBytes * ssid; - const char * ssid_data = "blahblah"; - NMSettingSecretFlags flags = GPOINTER_TO_UINT(data); + gs_unref_bytes GBytes *ssid = nmtst_gbytes_from_str("blahblah"); + NMSettingSecretFlags flags = GPOINTER_TO_UINT(data); connection = nm_simple_connection_new(); g_assert(connection); - /* Connection setting */ - s_con = (NMSettingConnection *) nm_setting_connection_new(); - nm_connection_add_setting(connection, NM_SETTING(s_con)); - + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); g_object_set(s_con, NM_SETTING_CONNECTION_ID, "Test Write Wifi LEAP Secret Flags", @@ -7033,23 +6099,15 @@ test_write_wifi_leap_secret_flags(gconstpointer data) NM_SETTING_WIRELESS_SETTING_NAME, NULL); - /* Wifi setting */ - s_wifi = (NMSettingWireless *) nm_setting_wireless_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wifi)); - - ssid = g_bytes_new(ssid_data, strlen(ssid_data)); + s_wifi = _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRELESS); g_object_set(s_wifi, NM_SETTING_WIRELESS_SSID, ssid, NM_SETTING_WIRELESS_MODE, "infrastructure", NULL); - g_bytes_unref(ssid); - - /* Wireless security setting */ - s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wsec)); + s_wsec = _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRELESS_SECURITY); g_object_set(s_wsec, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "ieee8021x", @@ -7063,15 +6121,10 @@ test_write_wifi_leap_secret_flags(gconstpointer data) flags, NULL); - /* IP4 setting */ - s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip4)); + s_ip4 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); - /* IP6 setting */ - s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip6)); - + s_ip6 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP6_CONFIG); g_object_set(s_ip6, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, @@ -7108,8 +6161,7 @@ test_write_wifi_wpa_psk(gconstpointer test_data) NMSettingWirelessSecurity * s_wsec; NMSettingIPConfig * s_ip4; NMSettingIPConfig * s_ip6; - GBytes * ssid; - const char * ssid_data = "blahblah"; + gs_unref_bytes GBytes *ssid = nmtst_gbytes_from_str("blahblah"); struct { const char *name, *psk; gpointer wep_group_p, wpa_p, wpa2_p; @@ -7126,10 +6178,7 @@ test_write_wifi_wpa_psk(gconstpointer test_data) connection = nm_simple_connection_new(); - /* Connection setting */ - s_con = (NMSettingConnection *) nm_setting_connection_new(); - nm_connection_add_setting(connection, NM_SETTING(s_con)); - + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); g_object_set(s_con, NM_SETTING_CONNECTION_ID, args.name, @@ -7141,12 +6190,7 @@ test_write_wifi_wpa_psk(gconstpointer test_data) NM_SETTING_WIRELESS_SETTING_NAME, NULL); - /* Wifi setting */ - s_wifi = (NMSettingWireless *) nm_setting_wireless_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wifi)); - - ssid = g_bytes_new(ssid_data, strlen(ssid_data)); - + s_wifi = _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRELESS); g_object_set(s_wifi, NM_SETTING_WIRELESS_SSID, ssid, @@ -7154,12 +6198,7 @@ test_write_wifi_wpa_psk(gconstpointer test_data) "infrastructure", NULL); - g_bytes_unref(ssid); - - /* Wireless security setting */ - s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wsec)); - + s_wsec = _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRELESS_SECURITY); g_object_set(s_wsec, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "wpa-psk", @@ -7184,16 +6223,10 @@ test_write_wifi_wpa_psk(gconstpointer test_data) nm_setting_wireless_security_add_group(s_wsec, "ccmp"); } - /* IP4 setting */ - s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip4)); - + s_ip4 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); - /* IP6 setting */ - s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip6)); - + s_ip6 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP6_CONFIG); g_object_set(s_ip6, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, @@ -7225,16 +6258,12 @@ test_write_wifi_wpa_psk_adhoc(void) NMSettingIPConfig * s_ip4; NMSettingIPConfig * s_ip6; GError * error = NULL; - GBytes * ssid; - const char * ssid_data = "blahblah"; - NMIPAddress * addr; + gs_unref_bytes GBytes *ssid = nmtst_gbytes_from_str("blahblah"); + NMIPAddress * addr; connection = nm_simple_connection_new(); - /* Connection setting */ - s_con = (NMSettingConnection *) nm_setting_connection_new(); - nm_connection_add_setting(connection, NM_SETTING(s_con)); - + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); g_object_set(s_con, NM_SETTING_CONNECTION_ID, "Test Write Wifi WPA PSK", @@ -7246,12 +6275,7 @@ test_write_wifi_wpa_psk_adhoc(void) NM_SETTING_WIRELESS_SETTING_NAME, NULL); - /* Wifi setting */ - s_wifi = (NMSettingWireless *) nm_setting_wireless_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wifi)); - - ssid = g_bytes_new(ssid_data, strlen(ssid_data)); - + s_wifi = _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRELESS); g_object_set(s_wifi, NM_SETTING_WIRELESS_SSID, ssid, @@ -7263,12 +6287,7 @@ test_write_wifi_wpa_psk_adhoc(void) "bg", NULL); - g_bytes_unref(ssid); - - /* Wireless security setting */ - s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wsec)); - + s_wsec = _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRELESS_SECURITY); g_object_set(s_wsec, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "wpa-psk", @@ -7280,10 +6299,7 @@ test_write_wifi_wpa_psk_adhoc(void) nm_setting_wireless_security_add_pairwise(s_wsec, "ccmp"); nm_setting_wireless_security_add_group(s_wsec, "ccmp"); - /* IP4 setting */ - s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip4)); - + s_ip4 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL, @@ -7299,10 +6315,7 @@ test_write_wifi_wpa_psk_adhoc(void) nm_setting_ip_config_add_dns(s_ip4, "4.2.2.1"); - /* IP6 setting */ - s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip6)); - + s_ip6 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP6_CONFIG); g_object_set(s_ip6, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, @@ -7336,15 +6349,11 @@ test_write_wifi_wpa_eap_tls(void) NMSettingIPConfig * s_ip6; gboolean success; GError * error = NULL; - GBytes * ssid; - const char * ssid_data = "blahblah"; + gs_unref_bytes GBytes *ssid = nmtst_gbytes_from_str("blahblah"); connection = nm_simple_connection_new(); - /* Connection setting */ - s_con = (NMSettingConnection *) nm_setting_connection_new(); - nm_connection_add_setting(connection, NM_SETTING(s_con)); - + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); g_object_set(s_con, NM_SETTING_CONNECTION_ID, "Test Write Wifi WPA EAP-TLS", @@ -7356,12 +6365,7 @@ test_write_wifi_wpa_eap_tls(void) NM_SETTING_WIRELESS_SETTING_NAME, NULL); - /* Wifi setting */ - s_wifi = (NMSettingWireless *) nm_setting_wireless_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wifi)); - - ssid = g_bytes_new(ssid_data, strlen(ssid_data)); - + s_wifi = _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRELESS); g_object_set(s_wifi, NM_SETTING_WIRELESS_SSID, ssid, @@ -7369,12 +6373,7 @@ test_write_wifi_wpa_eap_tls(void) "infrastructure", NULL); - g_bytes_unref(ssid); - - /* Wireless security setting */ - s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wsec)); - + s_wsec = _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRELESS_SECURITY); g_object_set(s_wsec, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "wpa-eap", @@ -7385,17 +6384,14 @@ test_write_wifi_wpa_eap_tls(void) nm_setting_wireless_security_add_pairwise(s_wsec, "tkip"); nm_setting_wireless_security_add_group(s_wsec, "tkip"); - /* Wireless security setting */ - s_8021x = (NMSetting8021x *) nm_setting_802_1x_new(); - nm_connection_add_setting(connection, NM_SETTING(s_8021x)); - - g_object_set(s_8021x, NM_SETTING_802_1X_IDENTITY, "Bill Smith", NULL); + s_8021x = _nm_connection_new_setting(connection, NM_TYPE_SETTING_802_1X); g_object_set(s_8021x, + NM_SETTING_802_1X_IDENTITY, + "Bill Smith", NM_SETTING_802_1X_PHASE1_AUTH_FLAGS, (guint) (NM_SETTING_802_1X_AUTH_FLAGS_TLS_1_0_DISABLE | NM_SETTING_802_1X_AUTH_FLAGS_TLS_1_1_DISABLE), NULL); - nm_setting_802_1x_add_eap_method(s_8021x, "tls"); success = nm_setting_802_1x_set_ca_cert(s_8021x, @@ -7420,16 +6416,10 @@ test_write_wifi_wpa_eap_tls(void) &error); nmtst_assert_success(success, error); - /* IP4 setting */ - s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip4)); - + s_ip4 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); - /* IP6 setting */ - s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip6)); - + s_ip6 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP6_CONFIG); g_object_set(s_ip6, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, @@ -7463,15 +6453,11 @@ test_write_wifi_wpa_eap_ttls_tls(void) NMSettingIPConfig * s_ip6; gboolean success; GError * error = NULL; - GBytes * ssid; - const char * ssid_data = "blahblah"; + gs_unref_bytes GBytes *ssid = nmtst_gbytes_from_str("blahblah"); connection = nm_simple_connection_new(); - /* Connection setting */ - s_con = (NMSettingConnection *) nm_setting_connection_new(); - nm_connection_add_setting(connection, NM_SETTING(s_con)); - + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); g_object_set(s_con, NM_SETTING_CONNECTION_ID, "Test Write Wifi WPA EAP-TTLS (TLS)", @@ -7483,12 +6469,7 @@ test_write_wifi_wpa_eap_ttls_tls(void) NM_SETTING_WIRELESS_SETTING_NAME, NULL); - /* Wifi setting */ - s_wifi = (NMSettingWireless *) nm_setting_wireless_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wifi)); - - ssid = g_bytes_new(ssid_data, strlen(ssid_data)); - + s_wifi = _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRELESS); g_object_set(s_wifi, NM_SETTING_WIRELESS_SSID, ssid, @@ -7496,23 +6477,14 @@ test_write_wifi_wpa_eap_ttls_tls(void) "infrastructure", NULL); - g_bytes_unref(ssid); - - /* Wireless security setting */ - s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wsec)); - + s_wsec = _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRELESS_SECURITY); g_object_set(s_wsec, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "wpa-eap", NULL); nm_setting_wireless_security_add_proto(s_wsec, "rsn"); nm_setting_wireless_security_add_pairwise(s_wsec, "ccmp"); nm_setting_wireless_security_add_group(s_wsec, "ccmp"); - /* Wireless security setting */ - s_8021x = (NMSetting8021x *) nm_setting_802_1x_new(); - nm_connection_add_setting(connection, NM_SETTING(s_8021x)); - + s_8021x = _nm_connection_new_setting(connection, NM_TYPE_SETTING_802_1X); nm_setting_802_1x_add_eap_method(s_8021x, "ttls"); - g_object_set(s_8021x, NM_SETTING_802_1X_IDENTITY, "Bill Smith", @@ -7556,16 +6528,10 @@ test_write_wifi_wpa_eap_ttls_tls(void) &error); nmtst_assert_success(success, error); - /* IP4 setting */ - s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip4)); - + s_ip4 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); - /* IP6 setting */ - s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip6)); - + s_ip6 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP6_CONFIG); g_object_set(s_ip6, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, @@ -7599,15 +6565,11 @@ test_write_wifi_wpa_eap_ttls_mschapv2(void) NMSettingIPConfig * s_ip6; gboolean success; GError * error = NULL; - GBytes * ssid; - const char * ssid_data = "blahblah"; + gs_unref_bytes GBytes *ssid = nmtst_gbytes_from_str("blahblah"); connection = nm_simple_connection_new(); - /* Connection setting */ - s_con = (NMSettingConnection *) nm_setting_connection_new(); - nm_connection_add_setting(connection, NM_SETTING(s_con)); - + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); g_object_set(s_con, NM_SETTING_CONNECTION_ID, "Test Write Wifi WPA EAP-TTLS (MSCHAPv2)", @@ -7619,12 +6581,7 @@ test_write_wifi_wpa_eap_ttls_mschapv2(void) NM_SETTING_WIRELESS_SETTING_NAME, NULL); - /* Wifi setting */ - s_wifi = (NMSettingWireless *) nm_setting_wireless_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wifi)); - - ssid = g_bytes_new(ssid_data, strlen(ssid_data)); - + s_wifi = _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRELESS); g_object_set(s_wifi, NM_SETTING_WIRELESS_SSID, ssid, @@ -7632,12 +6589,7 @@ test_write_wifi_wpa_eap_ttls_mschapv2(void) "infrastructure", NULL); - g_bytes_unref(ssid); - - /* Wireless security setting */ - s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wsec)); - + s_wsec = _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRELESS_SECURITY); g_object_set(s_wsec, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "wpa-eap", NULL); nm_setting_wireless_security_add_proto(s_wsec, "wpa"); nm_setting_wireless_security_add_proto(s_wsec, "rsn"); @@ -7646,12 +6598,8 @@ test_write_wifi_wpa_eap_ttls_mschapv2(void) nm_setting_wireless_security_add_group(s_wsec, "tkip"); nm_setting_wireless_security_add_group(s_wsec, "ccmp"); - /* Wireless security setting */ - s_8021x = (NMSetting8021x *) nm_setting_802_1x_new(); - nm_connection_add_setting(connection, NM_SETTING(s_8021x)); - + s_8021x = _nm_connection_new_setting(connection, NM_TYPE_SETTING_802_1X); nm_setting_802_1x_add_eap_method(s_8021x, "ttls"); - g_object_set(s_8021x, NM_SETTING_802_1X_IDENTITY, "Bill Smith", @@ -7670,16 +6618,10 @@ test_write_wifi_wpa_eap_ttls_mschapv2(void) &error); nmtst_assert_success(success, error); - /* IP4 setting */ - s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip4)); - + s_ip4 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); - /* IP6 setting */ - s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip6)); - + s_ip6 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP6_CONFIG); g_object_set(s_ip6, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, @@ -7704,14 +6646,14 @@ test_write_wifi_wpa_then_open(void) nmtst_auto_unlinkfile char *testfile = NULL; gs_free char * keyfile = NULL; gs_unref_object NMConnection *connection = NULL; - gs_unref_object NMConnection *reread = NULL; + gs_unref_object NMConnection *reread1 = NULL; + gs_unref_object NMConnection *reread2 = NULL; NMSettingConnection * s_con; NMSettingWireless * s_wifi; NMSettingWirelessSecurity * s_wsec; NMSettingIPConfig * s_ip4; NMSettingIPConfig * s_ip6; - GBytes * ssid; - const char * ssid_data = "blahblah"; + gs_unref_bytes GBytes *ssid = nmtst_gbytes_from_str("blahblah"); /* Test that writing out a WPA config then changing that to an open * config doesn't leave various WPA-related keys lying around in the ifcfg. @@ -7719,10 +6661,7 @@ test_write_wifi_wpa_then_open(void) connection = nm_simple_connection_new(); - /* Connection setting */ - s_con = (NMSettingConnection *) nm_setting_connection_new(); - nm_connection_add_setting(connection, NM_SETTING(s_con)); - + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); g_object_set(s_con, NM_SETTING_CONNECTION_ID, "random wifi connection", @@ -7734,12 +6673,7 @@ test_write_wifi_wpa_then_open(void) NM_SETTING_WIRELESS_SETTING_NAME, NULL); - /* Wifi setting */ - s_wifi = (NMSettingWireless *) nm_setting_wireless_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wifi)); - - ssid = g_bytes_new(ssid_data, strlen(ssid_data)); - + s_wifi = _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRELESS); g_object_set(s_wifi, NM_SETTING_WIRELESS_SSID, ssid, @@ -7747,12 +6681,7 @@ test_write_wifi_wpa_then_open(void) "infrastructure", NULL); - g_bytes_unref(ssid); - - /* Wireless security setting */ - s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wsec)); - + s_wsec = _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRELESS_SECURITY); g_object_set(s_wsec, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "wpa-psk", @@ -7768,30 +6697,26 @@ test_write_wifi_wpa_then_open(void) nm_setting_wireless_security_add_pairwise(s_wsec, "ccmp"); nm_setting_wireless_security_add_group(s_wsec, "ccmp"); - /* IP4 setting */ - s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip4)); + s_ip4 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); - /* IP6 setting */ - s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip6)); + s_ip6 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP6_CONFIG); g_object_set(s_ip6, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, NM_SETTING_IP_CONFIG_MAY_FAIL, TRUE, + NM_SETTING_IP6_CONFIG_ADDR_GEN_MODE, + (int) NM_SETTING_IP6_CONFIG_ADDR_GEN_MODE_EUI64, NULL); nmtst_assert_connection_verifies(connection); _writer_new_connection(connection, TEST_SCRATCH_DIR, &testfile); - reread = _connection_from_file(testfile, NULL, TYPE_WIRELESS, NULL); - - nmtst_assert_connection_equals(connection, TRUE, reread, FALSE); + reread1 = _connection_from_file(testfile, NULL, TYPE_WIRELESS, NULL); - g_object_unref(reread); + nmtst_assert_connection_equals(connection, TRUE, reread1, FALSE); nmtst_connection_normalize(connection); @@ -7806,9 +6731,9 @@ test_write_wifi_wpa_then_open(void) keyfile = utils_get_keys_path(testfile); g_assert(!g_file_test(keyfile, G_FILE_TEST_EXISTS)); - reread = _connection_from_file(testfile, NULL, TYPE_WIRELESS, NULL); + reread2 = _connection_from_file(testfile, NULL, TYPE_WIRELESS, NULL); - nmtst_assert_connection_equals(connection, TRUE, reread, FALSE); + nmtst_assert_connection_equals(connection, TRUE, reread2, FALSE); } static void @@ -7817,16 +6742,15 @@ test_write_wifi_wpa_then_wep_with_perms(void) nmtst_auto_unlinkfile char *testfile = NULL; nmtst_auto_unlinkfile char *keyfile = NULL; gs_unref_object NMConnection *connection = NULL; - gs_unref_object NMConnection *reread = NULL; + gs_unref_object NMConnection *reread1 = NULL; + gs_unref_object NMConnection *reread2 = NULL; NMSettingConnection * s_con; NMSettingWireless * s_wifi; NMSettingWirelessSecurity * s_wsec; NMSettingIPConfig * s_ip4; NMSettingIPConfig * s_ip6; gboolean success; - GBytes * ssid; - char ** perms; - const char * ssid_data = "SomeSSID"; + gs_unref_bytes GBytes *ssid = nmtst_gbytes_from_str("SomeSSID"); /* Test that writing out a WPA config then changing that to a WEP * config works and doesn't cause infinite loop or other issues. @@ -7835,11 +6759,7 @@ test_write_wifi_wpa_then_wep_with_perms(void) connection = nm_simple_connection_new(); g_assert(connection); - /* Connection setting */ - s_con = (NMSettingConnection *) nm_setting_connection_new(); - nm_connection_add_setting(connection, NM_SETTING(s_con)); - - perms = g_strsplit("user:superman:", ",", -1); + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); g_object_set(s_con, NM_SETTING_CONNECTION_ID, "random wifi connection 2", @@ -7848,19 +6768,13 @@ test_write_wifi_wpa_then_wep_with_perms(void) NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_PERMISSIONS, - perms, + NM_MAKE_STRV("user:superman:"), NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRELESS_SETTING_NAME, NULL); - g_strfreev(perms); g_assert_cmpint(nm_setting_connection_get_num_permissions(s_con), ==, 1); - /* Wifi setting */ - s_wifi = (NMSettingWireless *) nm_setting_wireless_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wifi)); - - ssid = g_bytes_new(ssid_data, strlen(ssid_data)); - + s_wifi = _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRELESS); g_object_set(s_wifi, NM_SETTING_WIRELESS_SSID, ssid, @@ -7868,12 +6782,7 @@ test_write_wifi_wpa_then_wep_with_perms(void) "infrastructure", NULL); - g_bytes_unref(ssid); - - /* Wireless security setting */ - s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wsec)); - + s_wsec = _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRELESS_SECURITY); g_object_set(s_wsec, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "wpa-psk", @@ -7889,38 +6798,31 @@ test_write_wifi_wpa_then_wep_with_perms(void) nm_setting_wireless_security_add_pairwise(s_wsec, "ccmp"); nm_setting_wireless_security_add_group(s_wsec, "ccmp"); - /* IP4 setting */ - s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip4)); - + s_ip4 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); - /* IP6 setting */ - s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip6)); - + s_ip6 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP6_CONFIG); g_object_set(s_ip6, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, NM_SETTING_IP_CONFIG_MAY_FAIL, TRUE, + NM_SETTING_IP6_CONFIG_ADDR_GEN_MODE, + (int) NM_SETTING_IP6_CONFIG_ADDR_GEN_MODE_EUI64, NULL); nmtst_assert_connection_verifies(connection); _writer_new_connection(connection, TEST_SCRATCH_DIR, &testfile); - reread = _connection_from_file(testfile, NULL, TYPE_WIRELESS, NULL); - - nmtst_assert_connection_equals(connection, TRUE, reread, FALSE); + reread1 = _connection_from_file(testfile, NULL, TYPE_WIRELESS, NULL); - g_object_unref(reread); + nmtst_assert_connection_equals(connection, TRUE, reread1, FALSE); nmtst_connection_normalize(connection); /* Now change the connection to WEP and recheck */ - s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wsec)); + s_wsec = _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRELESS_SECURITY); g_object_set(s_wsec, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "none", NULL); nm_setting_wireless_security_set_wep_key(s_wsec, 0, "abraka dabra"); @@ -7931,11 +6833,11 @@ test_write_wifi_wpa_then_wep_with_perms(void) testfile, TEST_IFCFG_DIR "/ifcfg-random_wifi_connection_2.cexpected"); - reread = _connection_from_file(testfile, NULL, TYPE_WIRELESS, NULL); + reread2 = _connection_from_file(testfile, NULL, TYPE_WIRELESS, NULL); nmtst_connection_normalize(connection); success = nm_connection_compare(connection, - reread, + reread2, NM_SETTING_COMPARE_FLAG_IGNORE_AGENT_OWNED_SECRETS | NM_SETTING_COMPARE_FLAG_IGNORE_NOT_SAVED_SECRETS); g_assert(success); @@ -7956,15 +6858,12 @@ test_write_wifi_dynamic_wep_leap(void) NMSetting8021x * s_8021x; NMSettingIPConfig * s_ip4; NMSettingIPConfig * s_ip6; - GBytes * ssid; - const char * ssid_data = "blahblah"; - shvarFile * ifcfg; + gs_unref_bytes GBytes *ssid = nmtst_gbytes_from_str("blahblah"); + shvarFile * ifcfg; connection = nm_simple_connection_new(); - /* Connection setting */ - s_con = (NMSettingConnection *) nm_setting_connection_new(); - nm_connection_add_setting(connection, NM_SETTING(s_con)); + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); g_object_set(s_con, NM_SETTING_CONNECTION_ID, "Test Write Wifi Dynamic WEP LEAP", @@ -7974,12 +6873,7 @@ test_write_wifi_dynamic_wep_leap(void) NM_SETTING_WIRELESS_SETTING_NAME, NULL); - /* Wifi setting */ - s_wifi = (NMSettingWireless *) nm_setting_wireless_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wifi)); - - ssid = g_bytes_new(ssid_data, strlen(ssid_data)); - + s_wifi = _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRELESS); g_object_set(s_wifi, NM_SETTING_WIRELESS_SSID, ssid, @@ -7987,20 +6881,11 @@ test_write_wifi_dynamic_wep_leap(void) "infrastructure", NULL); - g_bytes_unref(ssid); - - /* Wireless security setting */ - s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wsec)); - + s_wsec = _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRELESS_SECURITY); g_object_set(s_wsec, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "ieee8021x", NULL); - /* Wireless security setting */ - s_8021x = (NMSetting8021x *) nm_setting_802_1x_new(); - nm_connection_add_setting(connection, NM_SETTING(s_8021x)); - + s_8021x = _nm_connection_new_setting(connection, NM_TYPE_SETTING_802_1X); nm_setting_802_1x_add_eap_method(s_8021x, "leap"); - g_object_set(s_8021x, NM_SETTING_802_1X_IDENTITY, "Bill Smith", @@ -8008,15 +6893,10 @@ test_write_wifi_dynamic_wep_leap(void) ";alkdfja;dslkfjsad;lkfjsadf", NULL); - /* IP4 setting */ - s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); + s_ip4 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); - nm_connection_add_setting(connection, NM_SETTING(s_ip4)); - - /* IP6 setting */ - s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip6)); + s_ip6 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP6_CONFIG); g_object_set(s_ip6, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, @@ -8054,14 +6934,10 @@ test_write_wired_qeth_dhcp(void) NMSettingWired * s_wired; NMSettingIPConfig * s_ip4; NMSettingIPConfig * s_ip6; - char ** subchans; connection = nm_simple_connection_new(); - /* Connection setting */ - s_con = (NMSettingConnection *) nm_setting_connection_new(); - nm_connection_add_setting(connection, NM_SETTING(s_con)); - + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); g_object_set(s_con, NM_SETTING_CONNECTION_ID, "Test Write Wired qeth Static", @@ -8073,34 +6949,23 @@ test_write_wired_qeth_dhcp(void) NM_SETTING_WIRED_SETTING_NAME, NULL); - /* Wired setting */ - s_wired = (NMSettingWired *) nm_setting_wired_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wired)); - - subchans = g_strsplit("0.0.600,0.0.601,0.0.602", ",", -1); + s_wired = _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRED); g_object_set(s_wired, NM_SETTING_WIRED_S390_SUBCHANNELS, - subchans, + NM_MAKE_STRV("0.0.600", "0.0.601", "0.0.602"), NM_SETTING_WIRED_S390_NETTYPE, "qeth", NULL); - g_strfreev(subchans); nm_setting_wired_add_s390_option(s_wired, "portname", "FOOBAR"); nm_setting_wired_add_s390_option(s_wired, "portno", "1"); nm_setting_wired_add_s390_option(s_wired, "layer2", "0"); nm_setting_wired_add_s390_option(s_wired, "protocol", "blahbalh"); - /* IP4 setting */ - s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip4)); - + s_ip4 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); - /* IP6 setting */ - s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip6)); - + s_ip6 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP6_CONFIG); g_object_set(s_ip6, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, @@ -8127,15 +6992,11 @@ test_write_wired_ctc_dhcp(void) NMSettingWired * s_wired; NMSettingIPConfig * s_ip4; NMSettingIPConfig * s_ip6; - char ** subchans; shvarFile * ifcfg; connection = nm_simple_connection_new(); - /* Connection setting */ - s_con = (NMSettingConnection *) nm_setting_connection_new(); - nm_connection_add_setting(connection, NM_SETTING(s_con)); - + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); g_object_set(s_con, NM_SETTING_CONNECTION_ID, "Test Write Wired ctc Static", @@ -8145,29 +7006,19 @@ test_write_wired_ctc_dhcp(void) NM_SETTING_WIRED_SETTING_NAME, NULL); - /* Wired setting */ - s_wired = (NMSettingWired *) nm_setting_wired_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wired)); - - subchans = g_strsplit("0.0.600,0.0.601", ",", -1); + s_wired = _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRED); g_object_set(s_wired, NM_SETTING_WIRED_S390_SUBCHANNELS, - subchans, + NM_MAKE_STRV("0.0.600", "0.0.601"), NM_SETTING_WIRED_S390_NETTYPE, "ctc", NULL); - g_strfreev(subchans); nm_setting_wired_add_s390_option(s_wired, "ctcprot", "0"); - /* IP4 setting */ - s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip4)); + s_ip4 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); - /* IP6 setting */ - s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip6)); - + s_ip6 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP6_CONFIG); g_object_set(s_ip6, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, @@ -8201,16 +7052,12 @@ test_write_permissions(void) gs_unref_object NMConnection *connection = NULL; gs_unref_object NMConnection *reread = NULL; NMSettingConnection * s_con; - NMSettingWired * s_wired; NMSettingIPConfig * s_ip4; NMSettingIPConfig * s_ip6; connection = nm_simple_connection_new(); - /* Connection setting */ - s_con = (NMSettingConnection *) nm_setting_connection_new(); - nm_connection_add_setting(connection, NM_SETTING(s_con)); - + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); g_object_set(s_con, NM_SETTING_CONNECTION_ID, "Test Write Permissions", @@ -8226,20 +7073,12 @@ test_write_permissions(void) nm_setting_connection_add_permission(s_con, "user", "foobar", NULL); nm_setting_connection_add_permission(s_con, "user", "asdfasdf", NULL); - /* Wired setting */ - s_wired = (NMSettingWired *) nm_setting_wired_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wired)); - - /* IP4 setting */ - s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip4)); + _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRED); + s_ip4 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); - /* IP6 setting */ - s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip6)); - + s_ip6 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP6_CONFIG); g_object_set(s_ip6, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, @@ -8270,16 +7109,12 @@ test_write_wifi_wep_agent_keys(void) NMSettingWirelessSecurity * s_wsec; NMSettingIPConfig * s_ip4; NMSettingIPConfig * s_ip6; - const char * str_ssid = "foobarbaz"; - GBytes * ssid; + gs_unref_bytes GBytes *ssid = nmtst_gbytes_from_str("foobarbaz"); connection = nm_simple_connection_new(); g_assert(connection != NULL); - /* Connection setting */ - s_con = (NMSettingConnection *) nm_setting_connection_new(); - nm_connection_add_setting(connection, NM_SETTING(s_con)); - + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); g_object_set(s_con, NM_SETTING_CONNECTION_ID, "Test Write Wifi WEP Agent Owned", @@ -8289,39 +7124,28 @@ test_write_wifi_wep_agent_keys(void) NM_SETTING_WIRELESS_SETTING_NAME, NULL); - /* IP4 setting */ - s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip4)); + s_ip4 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); - /* IP6 setting */ - s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip6)); - + s_ip6 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP6_CONFIG); g_object_set(s_ip6, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, NM_SETTING_IP_CONFIG_MAY_FAIL, TRUE, + NM_SETTING_IP6_CONFIG_ADDR_GEN_MODE, + (int) NM_SETTING_IP6_CONFIG_ADDR_GEN_MODE_EUI64, NULL); - /* Wifi setting */ - s_wifi = (NMSettingWireless *) nm_setting_wireless_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wifi)); - - ssid = g_bytes_new(str_ssid, strlen(str_ssid)); + s_wifi = _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRELESS); g_object_set(s_wifi, NM_SETTING_WIRELESS_SSID, ssid, NM_SETTING_WIRELESS_MODE, "infrastructure", NULL); - g_bytes_unref(ssid); - - /* Wifi security setting */ - s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wsec)); + s_wsec = _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRELESS_SECURITY); g_object_set(s_wsec, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "none", @@ -8352,20 +7176,14 @@ test_write_wifi_wep_agent_keys(void) static void test_write_wired_pppoe(void) { - NMConnection * connection; - NMSettingConnection *s_con; - NMSettingWired * s_wired; - NMSettingIPConfig * s_ip4; - NMSettingPppoe * s_pppoe; - NMSettingPpp * s_ppp; - GError * error = NULL; + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection * s_con; + NMSettingIPConfig * s_ip4; + NMSettingPppoe * s_pppoe; connection = nm_simple_connection_new(); - /* Connection setting */ - s_con = (NMSettingConnection *) nm_setting_connection_new(); - nm_connection_add_setting(connection, NM_SETTING(s_con)); - + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); g_object_set(s_con, NM_SETTING_CONNECTION_ID, "Test Write Wired PPPoE", @@ -8377,21 +7195,13 @@ test_write_wired_pppoe(void) NM_SETTING_WIRED_SETTING_NAME, NULL); - /* Wired setting */ - s_wired = (NMSettingWired *) nm_setting_wired_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wired)); - - /* IP4 setting */ - s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip4)); + _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRED); + s_ip4 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); - /* PPPoE setting */ - s_pppoe = (NMSettingPppoe *) nm_setting_pppoe_new(); - nm_connection_add_setting(connection, NM_SETTING(s_pppoe)); - - g_object_set(G_OBJECT(s_pppoe), + s_pppoe = _nm_connection_new_setting(connection, NM_TYPE_SETTING_PPPOE); + g_object_set(s_pppoe, NM_SETTING_PPPOE_SERVICE, "stupid-service", NM_SETTING_PPPOE_USERNAME, @@ -8400,33 +7210,24 @@ test_write_wired_pppoe(void) "test1", NULL); - /* PPP setting */ - s_ppp = (NMSettingPpp *) nm_setting_ppp_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ppp)); + _nm_connection_new_setting(connection, NM_TYPE_SETTING_PPP); nmtst_assert_connection_verifies(connection); _writer_new_connection_fail(connection, TEST_SCRATCH_DIR, NULL); - - g_object_unref(connection); - g_clear_error(&error); } static void test_write_vpn(void) { - NMConnection * connection; - NMSettingConnection *s_con; - NMSettingIPConfig * s_ip4; - NMSettingVpn * s_vpn; - GError * error = NULL; + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection * s_con; + NMSettingIPConfig * s_ip4; + NMSettingVpn * s_vpn; connection = nm_simple_connection_new(); - /* Connection setting */ - s_con = (NMSettingConnection *) nm_setting_connection_new(); - nm_connection_add_setting(connection, NM_SETTING(s_con)); - + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); g_object_set(s_con, NM_SETTING_CONNECTION_ID, "Test Write VPN", @@ -8438,10 +7239,7 @@ test_write_vpn(void) NM_SETTING_VPN_SETTING_NAME, NULL); - /* VPN setting */ - s_vpn = (NMSettingVpn *) nm_setting_vpn_new(); - nm_connection_add_setting(connection, NM_SETTING(s_vpn)); - + s_vpn = _nm_connection_new_setting(connection, NM_TYPE_SETTING_VPN); g_object_set(s_vpn, NM_SETTING_VPN_SERVICE_TYPE, "awesomevpn", @@ -8452,39 +7250,27 @@ test_write_vpn(void) nm_setting_vpn_add_data_item(s_vpn, "server", "vpn.somewhere.com"); nm_setting_vpn_add_secret(s_vpn, "password", "sup3rs3cr3t"); - /* IP4 setting */ - s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip4)); - + s_ip4 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); nmtst_assert_connection_verifies(connection); _writer_new_connection_fail(connection, TEST_SCRATCH_DIR, NULL); - - g_object_unref(connection); - g_clear_error(&error); } static void test_write_mobile_broadband(gconstpointer data) { - NMConnection * connection; - NMSettingConnection *s_con; - NMSettingIPConfig * s_ip4; - NMSettingGsm * s_gsm; - NMSettingCdma * s_cdma; - NMSettingPpp * s_ppp; - NMSettingSerial * s_serial; - GError * error = NULL; - gboolean gsm = GPOINTER_TO_UINT(data); + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection * s_con; + NMSettingIPConfig * s_ip4; + NMSettingCdma * s_cdma; + NMSettingSerial * s_serial; + gboolean gsm = GPOINTER_TO_UINT(data); connection = nm_simple_connection_new(); - /* Connection setting */ - s_con = (NMSettingConnection *) nm_setting_connection_new(); - nm_connection_add_setting(connection, NM_SETTING(s_con)); - + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); g_object_set(s_con, NM_SETTING_CONNECTION_ID, gsm ? "Test Write GSM" : "Test Write CDMA", @@ -8496,22 +7282,14 @@ test_write_mobile_broadband(gconstpointer data) gsm ? NM_SETTING_GSM_SETTING_NAME : NM_SETTING_CDMA_SETTING_NAME, NULL); - if (gsm) { - /* GSM setting */ - s_gsm = (NMSettingGsm *) nm_setting_gsm_new(); - nm_connection_add_setting(connection, NM_SETTING(s_gsm)); - } else { - /* CDMA setting */ - s_cdma = (NMSettingCdma *) nm_setting_cdma_new(); - nm_connection_add_setting(connection, NM_SETTING(s_cdma)); - + if (gsm) + _nm_connection_new_setting(connection, NM_TYPE_SETTING_GSM); + else { + s_cdma = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CDMA); g_object_set(s_cdma, NM_SETTING_CDMA_NUMBER, "#777", NULL); } - /* Serial setting */ - s_serial = (NMSettingSerial *) nm_setting_serial_new(); - nm_connection_add_setting(connection, NM_SETTING(s_serial)); - + s_serial = _nm_connection_new_setting(connection, NM_TYPE_SETTING_SERIAL); g_object_set(s_serial, NM_SETTING_SERIAL_BAUD, 115200, @@ -8523,42 +7301,31 @@ test_write_mobile_broadband(gconstpointer data) 1, NULL); - /* IP4 setting */ - s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip4)); - + s_ip4 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); - /* PPP setting */ - s_ppp = (NMSettingPpp *) nm_setting_ppp_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ppp)); + _nm_connection_new_setting(connection, NM_TYPE_SETTING_PPP); nmtst_assert_connection_verifies(connection); _writer_new_connection_fail(connection, TEST_SCRATCH_DIR, NULL); - - g_object_unref(connection); - g_clear_error(&error); } static void test_read_bridge_main(void) { - NMConnection * connection; - NMSettingBridge *s_bridge; - NMSettingWired * s_wired; - const char * mac; - char expected_mac_address[ETH_ALEN] = {0x00, 0x16, 0x41, 0x11, 0x22, 0x33}; + gs_unref_object NMConnection *connection = NULL; + NMSettingBridge * s_bridge; + NMSettingWired * s_wired; + const char * mac; + char expected_mac_address[ETH_ALEN] = {0x00, 0x16, 0x41, 0x11, 0x22, 0x33}; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-bridge-main", NULL, TYPE_ETHERNET, NULL); g_assert_cmpstr(nm_connection_get_interface_name(connection), ==, "br0"); - /* ===== Bridging SETTING ===== */ - - s_bridge = nm_connection_get_setting_bridge(connection); - g_assert(s_bridge); + s_bridge = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_BRIDGE); g_assert_cmpuint(nm_setting_bridge_get_forward_delay(s_bridge), ==, 2); g_assert(nm_setting_bridge_get_stp(s_bridge)); g_assert_cmpuint(nm_setting_bridge_get_priority(s_bridge), ==, 32744); @@ -8570,14 +7337,10 @@ test_read_bridge_main(void) g_assert_cmpint(nm_setting_bridge_get_vlan_filtering(s_bridge), ==, TRUE); g_assert_cmpint(nm_setting_bridge_get_vlan_default_pvid(s_bridge), ==, 99); - /* MAC address */ - s_wired = nm_connection_get_setting_wired(connection); - g_assert(s_wired); - mac = nm_setting_wired_get_cloned_mac_address(s_wired); + s_wired = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRED); + mac = nm_setting_wired_get_cloned_mac_address(s_wired); g_assert(mac); g_assert(nm_utils_hwaddr_matches(mac, -1, expected_mac_address, ETH_ALEN)); - - g_object_unref(connection); } static void @@ -8588,8 +7351,8 @@ test_write_bridge_main(void) gs_unref_object NMConnection *reread = NULL; NMSettingConnection * s_con; NMSettingBridge * s_bridge; - NMSettingIPConfig * s_ip4, *s_ip6; - NMSettingWired * s_wired; + NMSettingIPConfig * s_ip4; + NMSettingIPConfig * s_ip6; NMIPAddress * addr; static const char * mac = "31:33:33:37:be:cd"; GError * error = NULL; @@ -8599,10 +7362,7 @@ test_write_bridge_main(void) connection = nm_simple_connection_new(); g_assert(connection); - /* Connection setting */ - s_con = (NMSettingConnection *) nm_setting_connection_new(); - nm_connection_add_setting(connection, NM_SETTING(s_con)); - + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); g_object_set(s_con, NM_SETTING_CONNECTION_ID, "Test Write Bridge Main", @@ -8616,9 +7376,7 @@ test_write_bridge_main(void) NM_SETTING_BRIDGE_SETTING_NAME, NULL); - /* bridge setting */ - s_bridge = (NMSettingBridge *) nm_setting_bridge_new(); - nm_connection_add_setting(connection, NM_SETTING(s_bridge)); + s_bridge = _nm_connection_new_setting(connection, NM_TYPE_SETTING_BRIDGE); vlans = g_ptr_array_new_with_free_func((GDestroyNotify) nm_bridge_vlan_unref); vlan = nm_bridge_vlan_new(10, 16); @@ -8644,10 +7402,7 @@ test_write_bridge_main(void) vlans, NULL); - /* IP4 setting */ - s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip4)); - + s_ip4 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL, @@ -8662,17 +7417,12 @@ test_write_bridge_main(void) nm_setting_ip_config_add_address(s_ip4, addr); nm_ip_address_unref(addr); - /* IP6 setting */ - s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip6)); - + s_ip6 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP6_CONFIG); g_object_set(s_ip6, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, NULL); - /* Wired setting */ - s_wired = (NMSettingWired *) nm_setting_wired_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wired)); + _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRED); - nm_connection_add_setting(connection, nm_setting_proxy_new()); + _nm_connection_new_setting(connection, NM_TYPE_SETTING_PROXY); nmtst_assert_connection_verifies_without_normalization(connection); @@ -8686,29 +7436,25 @@ test_write_bridge_main(void) static void test_read_bridge_component(void) { - NMConnection * connection; - NMSettingConnection *s_con; - NMSettingBridgePort *s_port; + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection * s_con; + NMSettingBridgePort * s_port; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-bridge-component", NULL, TYPE_ETHERNET, NULL); - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con); + s_con = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); g_assert_cmpstr(nm_setting_connection_get_master(s_con), ==, "br0"); g_assert_cmpstr(nm_setting_connection_get_slave_type(s_con), ==, NM_SETTING_BRIDGE_SETTING_NAME); - s_port = nm_connection_get_setting_bridge_port(connection); - g_assert(s_port); + s_port = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_BRIDGE_PORT); g_assert(nm_setting_bridge_port_get_hairpin_mode(s_port)); g_assert_cmpuint(nm_setting_bridge_port_get_priority(s_port), ==, 28); g_assert_cmpuint(nm_setting_bridge_port_get_path_cost(s_port), ==, 100); - - g_object_unref(connection); } static void @@ -8728,10 +7474,7 @@ test_write_bridge_component(void) connection = nm_simple_connection_new(); g_assert(connection); - /* Connection setting */ - s_con = (NMSettingConnection *) nm_setting_connection_new(); - nm_connection_add_setting(connection, NM_SETTING(s_con)); - + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); g_object_set(s_con, NM_SETTING_CONNECTION_ID, "Test Write Bridge Component", @@ -8747,10 +7490,7 @@ test_write_bridge_component(void) NM_SETTING_BRIDGE_SETTING_NAME, NULL); - /* Wired setting */ - s_wired = (NMSettingWired *) nm_setting_wired_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wired)); - + s_wired = _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRED); g_object_set(s_wired, NM_SETTING_WIRED_MAC_ADDRESS, mac, NM_SETTING_WIRED_MTU, mtu, NULL); /* Bridge port */ @@ -8765,8 +7505,7 @@ test_write_bridge_component(void) nm_bridge_vlan_set_pvid(vlan, TRUE); g_ptr_array_add(vlans, vlan); - s_port = nm_setting_bridge_port_new(); - nm_connection_add_setting(connection, s_port); + s_port = _nm_connection_new_setting(connection, NM_TYPE_SETTING_BRIDGE_PORT); g_object_set(s_port, NM_SETTING_BRIDGE_PORT_PRIORITY, 50, @@ -8791,8 +7530,8 @@ test_write_bridge_component(void) static void test_read_bridge_missing_stp(void) { - NMConnection * connection; - NMSettingBridge *s_bridge; + gs_unref_object NMConnection *connection = NULL; + NMSettingBridge * s_bridge; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-bridge-missing-stp", NULL, @@ -8801,13 +7540,8 @@ test_read_bridge_missing_stp(void) g_assert_cmpstr(nm_connection_get_interface_name(connection), ==, "br0"); - /* ===== Bridging SETTING ===== */ - - s_bridge = nm_connection_get_setting_bridge(connection); - g_assert(s_bridge); + s_bridge = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_BRIDGE); g_assert(nm_setting_bridge_get_stp(s_bridge) == FALSE); - - g_object_unref(connection); } #define TEST_IFCFG_VLAN_INTERFACE TEST_IFCFG_DIR "/ifcfg-test-vlan-interface" @@ -8815,16 +7549,16 @@ test_read_bridge_missing_stp(void) static void test_read_vlan_interface(void) { - NMConnection * connection; - NMSettingVlan *s_vlan; - guint32 from = 0, to = 0; + gs_unref_object NMConnection *connection = NULL; + NMSettingVlan * s_vlan; + guint32 from = 0; + guint32 to = 0; connection = _connection_from_file(TEST_IFCFG_VLAN_INTERFACE, NULL, TYPE_ETHERNET, NULL); g_assert_cmpstr(nm_connection_get_interface_name(connection), ==, "vlan43"); - s_vlan = nm_connection_get_setting_vlan(connection); - g_assert(s_vlan); + s_vlan = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_VLAN); g_assert_cmpstr(nm_setting_vlan_get_parent(s_vlan), ==, "eth9"); g_assert_cmpint(nm_setting_vlan_get_id(s_vlan), ==, 43); @@ -8857,8 +7591,6 @@ test_read_vlan_interface(void) g_assert(nm_setting_vlan_get_priority(s_vlan, NM_VLAN_EGRESS_MAP, 2, &from, &to)); g_assert_cmpint(from, ==, 14); g_assert_cmpint(to, ==, 7); - - g_object_unref(connection); } #define TEST_IFCFG_VLAN_ONLY_VLANID TEST_IFCFG_DIR "/ifcfg-test-vlan-only-vlanid" @@ -8866,21 +7598,18 @@ test_read_vlan_interface(void) static void test_read_vlan_only_vlan_id(void) { - NMConnection * connection; - NMSettingVlan *s_vlan; + gs_unref_object NMConnection *connection = NULL; + NMSettingVlan * s_vlan; connection = _connection_from_file(TEST_IFCFG_VLAN_ONLY_VLANID, NULL, TYPE_ETHERNET, NULL); g_assert(nm_connection_get_interface_name(connection) == NULL); - s_vlan = nm_connection_get_setting_vlan(connection); - g_assert(s_vlan); + s_vlan = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_VLAN); g_assert_cmpstr(nm_setting_vlan_get_parent(s_vlan), ==, "eth9"); g_assert_cmpint(nm_setting_vlan_get_id(s_vlan), ==, 43); g_assert_cmpint(nm_setting_vlan_get_flags(s_vlan), ==, NM_VLAN_FLAG_REORDER_HEADERS); - - g_object_unref(connection); } static void @@ -8898,8 +7627,7 @@ test_read_vlan_vlanid_use(void) g_assert_cmpstr(nm_connection_get_interface_name(connection), ==, "eth0.9"); - s_vlan = nm_connection_get_setting_vlan(connection); - g_assert(s_vlan); + s_vlan = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_VLAN); g_assert_cmpstr(nm_setting_vlan_get_parent(s_vlan), ==, "eth0"); g_assert_cmpint(nm_setting_vlan_get_id(s_vlan), ==, 10); @@ -8918,8 +7646,8 @@ test_read_vlan_vlanid_use(void) static void test_read_vlan_only_device(void) { - NMConnection * connection; - NMSettingVlan *s_vlan; + gs_unref_object NMConnection *connection = NULL; + NMSettingVlan * s_vlan; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-vlan-only-device", NULL, @@ -8928,40 +7656,34 @@ test_read_vlan_only_device(void) g_assert_cmpstr(nm_connection_get_interface_name(connection), ==, "eth0.9"); - s_vlan = nm_connection_get_setting_vlan(connection); - g_assert(s_vlan); + s_vlan = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_VLAN); g_assert_cmpstr(nm_setting_vlan_get_parent(s_vlan), ==, "eth0"); g_assert_cmpint(nm_setting_vlan_get_id(s_vlan), ==, 9); - - g_object_unref(connection); } static void test_read_vlan_physdev(void) { - NMConnection * connection; - NMSettingVlan *s_vlan; + gs_unref_object NMConnection *connection = NULL; + NMSettingVlan * s_vlan; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-vlan-physdev", NULL, TYPE_ETHERNET, NULL); g_assert_cmpstr(nm_connection_get_interface_name(connection), ==, "vlan0.3"); - s_vlan = nm_connection_get_setting_vlan(connection); - g_assert(s_vlan); + s_vlan = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_VLAN); g_assert_cmpstr(nm_setting_vlan_get_parent(s_vlan), ==, "eth0"); g_assert_cmpint(nm_setting_vlan_get_id(s_vlan), ==, 3); - - g_object_unref(connection); } static void test_read_vlan_reorder_hdr_1(void) { - NMConnection * connection; - NMSettingVlan *s_vlan; + gs_unref_object NMConnection *connection = NULL; + NMSettingVlan * s_vlan; NMTST_EXPECT_NM_WARN("*REORDER_HDR key is deprecated, use VLAN_FLAGS*"); connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-vlan-reorder-hdr-1", @@ -8972,22 +7694,19 @@ test_read_vlan_reorder_hdr_1(void) g_assert_cmpstr(nm_connection_get_interface_name(connection), ==, "vlan0.3"); - s_vlan = nm_connection_get_setting_vlan(connection); - g_assert(s_vlan); + s_vlan = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_VLAN); g_assert_cmpstr(nm_setting_vlan_get_parent(s_vlan), ==, "eth0"); g_assert_cmpint(nm_setting_vlan_get_id(s_vlan), ==, 3); /* Check that REORDER_HDR=0 is ignored */ g_assert_cmpint(nm_setting_vlan_get_flags(s_vlan), ==, NM_VLAN_FLAG_REORDER_HEADERS); - - g_object_unref(connection); } static void test_read_vlan_reorder_hdr_2(void) { - NMConnection * connection; - NMSettingVlan *s_vlan; + gs_unref_object NMConnection *connection = NULL; + NMSettingVlan * s_vlan; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-vlan-reorder-hdr-2", NULL, @@ -8996,61 +7715,52 @@ test_read_vlan_reorder_hdr_2(void) g_assert_cmpstr(nm_connection_get_interface_name(connection), ==, "vlan0.3"); - s_vlan = nm_connection_get_setting_vlan(connection); - g_assert(s_vlan); + s_vlan = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_VLAN); g_assert_cmpstr(nm_setting_vlan_get_parent(s_vlan), ==, "eth0"); g_assert_cmpint(nm_setting_vlan_get_id(s_vlan), ==, 3); /* Check that VLAN_FLAGS=NO_REORDER_HDR works */ g_assert_cmpint(nm_setting_vlan_get_flags(s_vlan), ==, NM_VLAN_FLAG_LOOSE_BINDING); - - g_object_unref(connection); } static void test_read_vlan_flags_1(void) { - NMConnection * connection; - NMSettingVlan *s_vlan; + gs_unref_object NMConnection *connection = NULL; + NMSettingVlan * s_vlan; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-vlan-flags-1", NULL, TYPE_ETHERNET, NULL); g_assert_cmpstr(nm_connection_get_interface_name(connection), ==, "super-vlan"); - s_vlan = nm_connection_get_setting_vlan(connection); - g_assert(s_vlan); + s_vlan = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_VLAN); g_assert_cmpstr(nm_setting_vlan_get_parent(s_vlan), ==, "eth9"); g_assert_cmpint(nm_setting_vlan_get_id(s_vlan), ==, 44); g_assert_cmpint(nm_setting_vlan_get_flags(s_vlan), ==, NM_VLAN_FLAG_LOOSE_BINDING | NM_VLAN_FLAG_REORDER_HEADERS); - - g_object_unref(connection); } static void test_read_vlan_flags_2(void) { - NMConnection * connection; - NMSettingVlan *s_vlan; + gs_unref_object NMConnection *connection = NULL; + NMSettingVlan * s_vlan; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-vlan-flags-2", NULL, TYPE_ETHERNET, NULL); g_assert_cmpstr(nm_connection_get_interface_name(connection), ==, "super-vlan"); - s_vlan = nm_connection_get_setting_vlan(connection); - g_assert(s_vlan); + s_vlan = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_VLAN); g_assert_cmpstr(nm_setting_vlan_get_parent(s_vlan), ==, "eth9"); g_assert_cmpint(nm_setting_vlan_get_id(s_vlan), ==, 44); g_assert_cmpint(nm_setting_vlan_get_flags(s_vlan), ==, NM_VLAN_FLAG_GVRP | NM_VLAN_FLAG_LOOSE_BINDING | NM_VLAN_FLAG_REORDER_HEADERS); - - g_object_unref(connection); } static void @@ -9108,14 +7818,10 @@ test_write_vlan_reorder_hdr(void) gs_unref_object NMConnection *reread = NULL; NMSettingConnection * s_con; NMSettingVlan * s_vlan; - NMSettingWired * s_wired; connection = nm_simple_connection_new(); - /* Connection setting */ - s_con = (NMSettingConnection *) nm_setting_connection_new(); - nm_connection_add_setting(connection, NM_SETTING(s_con)); - + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); g_object_set(s_con, NM_SETTING_CONNECTION_ID, "Test Write VLAN reorder_hdr", @@ -9127,14 +7833,9 @@ test_write_vlan_reorder_hdr(void) NM_SETTING_VLAN_SETTING_NAME, NULL); - /* Wired setting */ - s_wired = (NMSettingWired *) nm_setting_wired_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wired)); - - /* VLAN setting */ - s_vlan = (NMSettingVlan *) nm_setting_vlan_new(); - nm_connection_add_setting(connection, NM_SETTING(s_vlan)); + _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRED); + s_vlan = _nm_connection_new_setting(connection, NM_TYPE_SETTING_VLAN); g_object_set(s_vlan, NM_SETTING_VLAN_PARENT, "eth0", @@ -9161,16 +7862,12 @@ test_write_ethernet_missing_ipv6(void) gs_unref_object NMConnection *connection = NULL; gs_unref_object NMConnection *reread = NULL; NMSettingConnection * s_con; - NMSettingWired * s_wired; NMSettingIPConfig * s_ip4; connection = nm_simple_connection_new(); g_assert(connection); - /* Connection setting */ - s_con = (NMSettingConnection *) nm_setting_connection_new(); - nm_connection_add_setting(connection, NM_SETTING(s_con)); - + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); g_object_set(s_con, NM_SETTING_CONNECTION_ID, "Test Write Ethernet Without IPv6 Setting", @@ -9182,13 +7879,9 @@ test_write_ethernet_missing_ipv6(void) NM_SETTING_WIRED_SETTING_NAME, NULL); - /* Wired setting */ - s_wired = (NMSettingWired *) nm_setting_wired_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wired)); + _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRED); - /* IP4 setting */ - s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip4)); + s_ip4 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, @@ -9227,31 +7920,26 @@ test_read_ibft_ignored(void) static void test_read_bond_main(void) { - NMConnection * connection; - NMSettingBond *s_bond; + gs_unref_object NMConnection *connection = NULL; + NMSettingBond * s_bond; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-bond-main", NULL, TYPE_ETHERNET, NULL); g_assert_cmpstr(nm_connection_get_interface_name(connection), ==, "bond0"); - /* ===== Bonding SETTING ===== */ - - s_bond = nm_connection_get_setting_bond(connection); - g_assert(s_bond); + s_bond = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_BOND); g_assert_cmpstr(nm_setting_bond_get_option_by_name(s_bond, NM_SETTING_BOND_OPTION_MIIMON), ==, "100"); - - g_object_unref(connection); } static void test_read_bond_eth_type(void) { - NMConnection * connection; - NMSettingBond *s_bond; + gs_unref_object NMConnection *connection = NULL; + NMSettingBond * s_bond; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-bond-eth-type", NULL, @@ -9260,10 +7948,7 @@ test_read_bond_eth_type(void) g_assert_cmpstr(nm_connection_get_interface_name(connection), ==, "bond0"); - /* ===== Bonding SETTING ===== */ - - s_bond = nm_connection_get_setting_bond(connection); - g_assert(s_bond); + s_bond = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_BOND); g_assert_cmpstr(nm_setting_bond_get_option_by_name(s_bond, NM_SETTING_BOND_OPTION_MIIMON), ==, @@ -9271,8 +7956,6 @@ test_read_bond_eth_type(void) g_assert_cmpstr(nm_setting_bond_get_option_by_name(s_bond, NM_SETTING_BOND_OPTION_LACP_RATE), ==, "1"); - - g_object_unref(connection); } static void @@ -9285,16 +7968,12 @@ test_write_bond_main(void) NMSettingBond * s_bond; NMSettingIPConfig * s_ip4; NMSettingIPConfig * s_ip6; - NMSettingWired * s_wired; NMIPAddress * addr; GError * error = NULL; connection = nm_simple_connection_new(); - /* Connection setting */ - s_con = (NMSettingConnection *) nm_setting_connection_new(); - nm_connection_add_setting(connection, NM_SETTING(s_con)); - + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); g_object_set(s_con, NM_SETTING_CONNECTION_ID, "Test Write Bond Main", @@ -9308,22 +7987,14 @@ test_write_bond_main(void) NM_SETTING_BOND_SETTING_NAME, NULL); - /* Wired setting */ - s_wired = (NMSettingWired *) nm_setting_wired_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wired)); - - /* bond setting */ - s_bond = (NMSettingBond *) nm_setting_bond_new(); - nm_connection_add_setting(connection, NM_SETTING(s_bond)); + _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRED); + s_bond = _nm_connection_new_setting(connection, NM_TYPE_SETTING_BOND); nm_setting_bond_add_option(s_bond, NM_SETTING_BOND_OPTION_DOWNDELAY, "5"); nm_setting_bond_add_option(s_bond, NM_SETTING_BOND_OPTION_UPDELAY, "10"); nm_setting_bond_add_option(s_bond, NM_SETTING_BOND_OPTION_MIIMON, "100"); - /* IP4 setting */ - s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip4)); - + s_ip4 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL, @@ -9338,13 +8009,10 @@ test_write_bond_main(void) nm_setting_ip_config_add_address(s_ip4, addr); nm_ip_address_unref(addr); - /* IP6 setting */ - s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip6)); - + s_ip6 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP6_CONFIG); g_object_set(s_ip6, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, NULL); - nm_connection_add_setting(connection, nm_setting_proxy_new()); + _nm_connection_new_setting(connection, NM_TYPE_SETTING_PROXY); nmtst_assert_connection_verifies_without_normalization(connection); @@ -9361,21 +8029,18 @@ test_write_bond_main(void) static void test_read_bond_slave(void) { - NMConnection * connection; - NMSettingConnection *s_con; + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection * s_con; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-bond-slave", NULL, TYPE_ETHERNET, NULL); g_test_assert_expected_messages(); - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con); + s_con = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); g_assert_cmpstr(nm_setting_connection_get_master(s_con), ==, "bond0"); g_assert_cmpstr(nm_setting_connection_get_slave_type(s_con), ==, NM_SETTING_BOND_SETTING_NAME); - - g_object_unref(connection); } static void @@ -9391,10 +8056,7 @@ test_write_bond_slave(void) connection = nm_simple_connection_new(); - /* Connection setting */ - s_con = (NMSettingConnection *) nm_setting_connection_new(); - nm_connection_add_setting(connection, NM_SETTING(s_con)); - + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); g_object_set(s_con, NM_SETTING_CONNECTION_ID, "Test Write Bond Slave", @@ -9410,10 +8072,7 @@ test_write_bond_slave(void) NM_SETTING_BOND_SETTING_NAME, NULL); - /* Wired setting */ - s_wired = (NMSettingWired *) nm_setting_wired_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wired)); - + s_wired = _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRED); g_object_set(s_wired, NM_SETTING_WIRED_MAC_ADDRESS, mac, NM_SETTING_WIRED_MTU, mtu, NULL); nmtst_assert_connection_verifies(connection); @@ -9425,13 +8084,72 @@ test_write_bond_slave(void) nmtst_assert_connection_equals(connection, TRUE, reread, FALSE); } +static void +test_read_bond_port(void) +{ + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection * s_con = NULL; + NMSettingBondPort * s_port = NULL; + + connection = + _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-bond-port", NULL, TYPE_ETHERNET, NULL); + + s_con = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); + g_assert_cmpstr(nm_setting_connection_get_master(s_con), ==, "bond99"); + g_assert_cmpstr(nm_setting_connection_get_slave_type(s_con), ==, NM_SETTING_BOND_SETTING_NAME); + + s_port = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_BOND_PORT); + g_assert_cmpuint(nm_setting_bond_port_get_queue_id(s_port), ==, 1); +} + +static void +test_write_bond_port(void) +{ + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; + NMSettingConnection * s_con; + NMSettingBondPort * s_bond_port; + + connection = nm_simple_connection_new(); + + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); + g_object_set(s_con, + NM_SETTING_CONNECTION_ID, + "Test Write Bond Port", + NM_SETTING_CONNECTION_UUID, + nm_uuid_generate_random_str_a(), + NM_SETTING_CONNECTION_AUTOCONNECT, + TRUE, + NM_SETTING_CONNECTION_TYPE, + NM_SETTING_WIRED_SETTING_NAME, + NM_SETTING_CONNECTION_MASTER, + "bond0", + NM_SETTING_CONNECTION_SLAVE_TYPE, + NM_SETTING_BOND_SETTING_NAME, + NULL); + + _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRED); + + s_bond_port = _nm_connection_new_setting(connection, NM_TYPE_SETTING_BOND_PORT); + g_object_set(s_bond_port, NM_SETTING_BOND_PORT_QUEUE_ID, 1, NULL); + + nmtst_assert_connection_verifies(connection); + + _writer_new_connection(connection, TEST_SCRATCH_DIR, &testfile); + + reread = _connection_from_file(testfile, NULL, TYPE_ETHERNET, NULL); + + nmtst_assert_connection_equals(connection, TRUE, reread, FALSE); +} + static void test_read_infiniband(void) { - NMConnection * connection; - NMSettingInfiniband *s_infiniband; - char * unmanaged = NULL; - const char * mac; + gs_unref_object NMConnection *connection = NULL; + NMSettingInfiniband * s_infiniband; + char * unmanaged = NULL; + const char * mac; char expected_mac_address[INFINIBAND_ALEN] = {0x80, 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x00, 0x11, 0x22}; @@ -9443,22 +8161,15 @@ test_read_infiniband(void) &unmanaged); g_assert(!unmanaged); - /* ===== INFINIBAND SETTING ===== */ + s_infiniband = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_INFINIBAND); - s_infiniband = nm_connection_get_setting_infiniband(connection); - g_assert(s_infiniband); - - /* MAC address */ mac = nm_setting_infiniband_get_mac_address(s_infiniband); g_assert(mac); g_assert(nm_utils_hwaddr_matches(mac, -1, expected_mac_address, sizeof(expected_mac_address))); - /* Transport mode */ transport_mode = nm_setting_infiniband_get_transport_mode(s_infiniband); g_assert(transport_mode); g_assert_cmpstr(transport_mode, ==, "connected"); - - g_object_unref(connection); } static void @@ -9478,10 +8189,7 @@ test_write_infiniband(void) connection = nm_simple_connection_new(); - /* Connection setting */ - s_con = (NMSettingConnection *) nm_setting_connection_new(); - nm_connection_add_setting(connection, NM_SETTING(s_con)); - + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); g_object_set(s_con, NM_SETTING_CONNECTION_ID, "Test Write InfiniBand", @@ -9493,10 +8201,7 @@ test_write_infiniband(void) NM_SETTING_INFINIBAND_SETTING_NAME, NULL); - /* InfiniBand setting */ - s_infiniband = (NMSettingInfiniband *) nm_setting_infiniband_new(); - nm_connection_add_setting(connection, NM_SETTING(s_infiniband)); - + s_infiniband = _nm_connection_new_setting(connection, NM_TYPE_SETTING_INFINIBAND); g_object_set(s_infiniband, NM_SETTING_INFINIBAND_MAC_ADDRESS, mac, @@ -9506,10 +8211,7 @@ test_write_infiniband(void) "connected", NULL); - /* IP4 setting */ - s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip4)); - + s_ip4 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL, @@ -9524,10 +8226,7 @@ test_write_infiniband(void) nm_setting_ip_config_add_address(s_ip4, addr); nm_ip_address_unref(addr); - /* IP6 setting */ - s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip6)); - + s_ip6 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP6_CONFIG); g_object_set(s_ip6, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, NULL); nmtst_assert_connection_verifies(connection); @@ -9548,8 +8247,7 @@ test_read_bond_slave_ib(void) connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-bond-slave-ib", NULL, NULL, NULL); - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con); + s_con = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); g_assert_cmpstr(nm_setting_connection_get_master(s_con), ==, "bond0"); g_assert_cmpstr(nm_setting_connection_get_slave_type(s_con), ==, NM_SETTING_BOND_SETTING_NAME); @@ -9567,10 +8265,7 @@ test_write_bond_slave_ib(void) connection = nm_simple_connection_new(); - /* Connection setting */ - s_con = (NMSettingConnection *) nm_setting_connection_new(); - nm_connection_add_setting(connection, NM_SETTING(s_con)); - + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); g_object_set(s_con, NM_SETTING_CONNECTION_ID, "Test Write Bond Slave InfiniBand", @@ -9586,10 +8281,7 @@ test_write_bond_slave_ib(void) NM_SETTING_BOND_SETTING_NAME, NULL); - /* InfiniBand setting */ - s_infiniband = (NMSettingInfiniband *) nm_setting_infiniband_new(); - nm_connection_add_setting(connection, NM_SETTING(s_infiniband)); - + s_infiniband = _nm_connection_new_setting(connection, NM_TYPE_SETTING_INFINIBAND); g_object_set(s_infiniband, NM_SETTING_INFINIBAND_MAC_ADDRESS, mac, @@ -9611,9 +8303,9 @@ test_write_bond_slave_ib(void) static void test_read_bond_opts_mode_numeric(void) { - NMConnection * connection; - NMSettingConnection *s_con; - NMSettingBond * s_bond; + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection * s_con; + NMSettingBond * s_bond; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-bond-mode-numeric", NULL, @@ -9622,19 +8314,15 @@ test_read_bond_opts_mode_numeric(void) g_assert_cmpstr(nm_connection_get_interface_name(connection), ==, "bond0"); - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con); + s_con = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); g_assert_cmpstr(nm_setting_connection_get_connection_type(s_con), ==, NM_SETTING_BOND_SETTING_NAME); - s_bond = nm_connection_get_setting_bond(connection); - g_assert(s_bond); + s_bond = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_BOND); g_assert_cmpstr(nm_setting_bond_get_option_by_name(s_bond, NM_SETTING_BOND_OPTION_MODE), ==, "802.3ad"); - - g_object_unref(connection); } #define DCB_ALL_FLAGS \ @@ -9643,20 +8331,19 @@ test_read_bond_opts_mode_numeric(void) static void test_read_dcb_basic(void) { - NMConnection *connection; - NMSettingDcb *s_dcb; - guint i; - guint expected_group_ids[8] = {0, 0, 0, 0, 1, 1, 1, 0xF}; - guint expected_group_bandwidths[8] = {25, 0, 0, 75, 0, 0, 0, 0}; - guint expected_bandwidths[8] = {5, 10, 30, 25, 10, 50, 5, 0}; - gboolean expected_strict[8] = {FALSE, FALSE, TRUE, TRUE, FALSE, TRUE, FALSE, TRUE}; - guint expected_traffic_classes[8] = {7, 6, 5, 4, 3, 2, 1, 0}; - gboolean expected_pfcs[8] = {TRUE, FALSE, FALSE, TRUE, TRUE, FALSE, TRUE, FALSE}; + gs_unref_object NMConnection *connection = NULL; + NMSettingDcb * s_dcb; + guint i; + guint expected_group_ids[8] = {0, 0, 0, 0, 1, 1, 1, 0xF}; + guint expected_group_bandwidths[8] = {25, 0, 0, 75, 0, 0, 0, 0}; + guint expected_bandwidths[8] = {5, 10, 30, 25, 10, 50, 5, 0}; + gboolean expected_strict[8] = {FALSE, FALSE, TRUE, TRUE, FALSE, TRUE, FALSE, TRUE}; + guint expected_traffic_classes[8] = {7, 6, 5, 4, 3, 2, 1, 0}; + gboolean expected_pfcs[8] = {TRUE, FALSE, FALSE, TRUE, TRUE, FALSE, TRUE, FALSE}; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-dcb", NULL, TYPE_ETHERNET, NULL); - s_dcb = nm_connection_get_setting_dcb(connection); - g_assert(s_dcb); + s_dcb = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_DCB); g_assert_cmpint(nm_setting_dcb_get_app_fcoe_flags(s_dcb), ==, DCB_ALL_FLAGS); g_assert_cmpint(nm_setting_dcb_get_app_fcoe_priority(s_dcb), ==, 7); @@ -9702,8 +8389,6 @@ test_read_dcb_basic(void) g_assert_cmpint(nm_setting_dcb_get_priority_traffic_class(s_dcb, i), ==, expected_traffic_classes[i]); - - g_object_unref(connection); } static void @@ -9713,7 +8398,6 @@ test_write_dcb_basic(void) gs_unref_object NMConnection *connection = NULL; gs_unref_object NMConnection *reread = NULL; NMSettingConnection * s_con; - NMSettingWired * s_wired; NMSettingDcb * s_dcb; NMSettingIPConfig * s_ip4; NMSettingIPConfig * s_ip6; @@ -9727,9 +8411,8 @@ test_write_dcb_basic(void) connection = nm_simple_connection_new(); - s_con = (NMSettingConnection *) nm_setting_connection_new(); - nm_connection_add_setting(connection, NM_SETTING(s_con)); - g_object_set(G_OBJECT(s_con), + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); + g_object_set(s_con, NM_SETTING_CONNECTION_ID, "dcb-test", NM_SETTING_CONNECTION_UUID, @@ -9740,30 +8423,16 @@ test_write_dcb_basic(void) "eth0", NULL); - /* Wired setting */ - s_wired = (NMSettingWired *) nm_setting_wired_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wired)); - - /* IP stuff */ - s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); - g_object_set(G_OBJECT(s_ip4), - NM_SETTING_IP_CONFIG_METHOD, - NM_SETTING_IP4_CONFIG_METHOD_AUTO, - NULL); - nm_connection_add_setting(connection, NM_SETTING(s_ip4)); + _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRED); - s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); - g_object_set(G_OBJECT(s_ip6), - NM_SETTING_IP_CONFIG_METHOD, - NM_SETTING_IP6_CONFIG_METHOD_AUTO, - NULL); - nm_connection_add_setting(connection, NM_SETTING(s_ip6)); + s_ip4 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); + g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); - /* DCB */ - s_dcb = (NMSettingDcb *) nm_setting_dcb_new(); - nm_connection_add_setting(connection, NM_SETTING(s_dcb)); + s_ip6 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP6_CONFIG); + g_object_set(s_ip6, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_AUTO, NULL); - g_object_set(G_OBJECT(s_dcb), + s_dcb = _nm_connection_new_setting(connection, NM_TYPE_SETTING_DCB); + g_object_set(s_dcb, NM_SETTING_DCB_APP_FCOE_FLAGS, DCB_ALL_FLAGS, NM_SETTING_DCB_APP_FCOE_PRIORITY, @@ -9814,8 +8483,7 @@ test_read_dcb_default_app_priorities(void) TYPE_ETHERNET, NULL); - s_dcb = nm_connection_get_setting_dcb(connection); - g_assert(s_dcb); + s_dcb = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_DCB); g_assert_cmpint(nm_setting_dcb_get_app_fcoe_flags(s_dcb), ==, NM_SETTING_DCB_FLAG_ENABLE); g_assert_cmpint(nm_setting_dcb_get_app_fcoe_priority(s_dcb), ==, -1); @@ -9950,8 +8618,7 @@ test_read_fcoe_mode(gconstpointer user_data) file = g_strdup_printf(TEST_IFCFG_DIR "/ifcfg-test-fcoe-%s", expected_mode); connection = _connection_from_file(file, NULL, TYPE_ETHERNET, NULL); - s_dcb = nm_connection_get_setting_dcb(connection); - g_assert(s_dcb); + s_dcb = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_DCB); g_assert_cmpint(nm_setting_dcb_get_app_fcoe_flags(s_dcb), ==, NM_SETTING_DCB_FLAG_ENABLE); g_assert_cmpstr(nm_setting_dcb_get_app_fcoe_mode(s_dcb), ==, expected_mode); @@ -9965,7 +8632,6 @@ test_write_fcoe_mode(gconstpointer user_data) gs_unref_object NMConnection *reread = NULL; const char * expected_mode = user_data; NMSettingConnection * s_con; - NMSettingWired * s_wired; NMSettingDcb * s_dcb; NMSettingIPConfig * s_ip4; NMSettingIPConfig * s_ip6; @@ -9973,9 +8639,8 @@ test_write_fcoe_mode(gconstpointer user_data) connection = nm_simple_connection_new(); - s_con = (NMSettingConnection *) nm_setting_connection_new(); - nm_connection_add_setting(connection, NM_SETTING(s_con)); - g_object_set(G_OBJECT(s_con), + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); + g_object_set(s_con, NM_SETTING_CONNECTION_ID, "fcoe-test", NM_SETTING_CONNECTION_UUID, @@ -9986,30 +8651,16 @@ test_write_fcoe_mode(gconstpointer user_data) "eth0", NULL); - /* Wired setting */ - s_wired = (NMSettingWired *) nm_setting_wired_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wired)); - - /* IP stuff */ - s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); - g_object_set(G_OBJECT(s_ip4), - NM_SETTING_IP_CONFIG_METHOD, - NM_SETTING_IP4_CONFIG_METHOD_AUTO, - NULL); - nm_connection_add_setting(connection, NM_SETTING(s_ip4)); + _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRED); - s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); - g_object_set(G_OBJECT(s_ip6), - NM_SETTING_IP_CONFIG_METHOD, - NM_SETTING_IP6_CONFIG_METHOD_AUTO, - NULL); - nm_connection_add_setting(connection, NM_SETTING(s_ip6)); + s_ip4 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); + g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); - /* DCB */ - s_dcb = (NMSettingDcb *) nm_setting_dcb_new(); - nm_connection_add_setting(connection, NM_SETTING(s_dcb)); + s_ip6 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP6_CONFIG); + g_object_set(s_ip6, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_AUTO, NULL); - g_object_set(G_OBJECT(s_dcb), + s_dcb = _nm_connection_new_setting(connection, NM_TYPE_SETTING_DCB); + g_object_set(s_dcb, NM_SETTING_DCB_APP_FCOE_FLAGS, NM_SETTING_DCB_FLAG_ENABLE, NM_SETTING_DCB_APP_FCOE_MODE, @@ -10032,28 +8683,24 @@ test_write_fcoe_mode(gconstpointer user_data) static void test_read_team_master(gconstpointer user_data) { - const char *const PATH_NAME = user_data; - NMConnection * connection; - NMSettingConnection *s_con; - NMSettingTeam * s_team; - const char * expected_config = + const char *const PATH_NAME = user_data; + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection * s_con; + NMSettingTeam * s_team; + const char * expected_config = "{\"device\": \"team0\", \"link_watch\": {\"name\": \"ethtool\"}}"; connection = _connection_from_file(PATH_NAME, NULL, TYPE_ETHERNET, NULL); g_assert_cmpstr(nm_connection_get_interface_name(connection), ==, "team0"); - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con); + s_con = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); g_assert_cmpstr(nm_setting_connection_get_connection_type(s_con), ==, NM_SETTING_TEAM_SETTING_NAME); - s_team = nm_connection_get_setting_team(connection); - g_assert(s_team); + s_team = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_TEAM); g_assert_cmpstr(nm_setting_team_get_config(s_team), ==, expected_config); - - g_object_unref(connection); } static void @@ -10080,7 +8727,6 @@ test_write_team_master(void) gs_unref_object NMConnection *reread = NULL; NMSettingConnection * s_con; NMSettingTeam * s_team; - NMSettingWired * s_wired; NMSettingIPConfig * s_ip4; NMSettingIPConfig * s_ip6; const char * expected_config = @@ -10089,10 +8735,7 @@ test_write_team_master(void) connection = nm_simple_connection_new(); - /* Connection setting */ - s_con = (NMSettingConnection *) nm_setting_connection_new(); - nm_connection_add_setting(connection, NM_SETTING(s_con)); - + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); g_object_set(s_con, NM_SETTING_CONNECTION_ID, "Test Write Team Master", @@ -10104,29 +8747,18 @@ test_write_team_master(void) NM_SETTING_TEAM_SETTING_NAME, NULL); - /* Team setting */ - s_team = (NMSettingTeam *) nm_setting_team_new(); - nm_connection_add_setting(connection, NM_SETTING(s_team)); - + s_team = _nm_connection_new_setting(connection, NM_TYPE_SETTING_TEAM); g_object_set(s_team, NM_SETTING_TEAM_CONFIG, expected_config, NULL); - /* Wired setting */ - s_wired = (NMSettingWired *) nm_setting_wired_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wired)); - - /* IP4 setting */ - s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip4)); + _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRED); + s_ip4 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); - /* IP6 setting */ - s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip6)); - + s_ip6 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP6_CONFIG); g_object_set(s_ip6, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_AUTO, NULL); - nm_connection_add_setting(connection, nm_setting_proxy_new()); + _nm_connection_new_setting(connection, NM_TYPE_SETTING_PROXY); nmtst_assert_connection_verifies_without_normalization(connection); @@ -10145,26 +8777,22 @@ test_write_team_master(void) static void test_read_team_port(gconstpointer user_data) { - const char *const PATH_NAME = user_data; - NMConnection * connection; - NMSettingConnection *s_con; - NMSettingTeamPort * s_team_port; - const char * expected_config = "{\"p4p1\": {\"prio\": -10, \"sticky\": true}}"; + const char *const PATH_NAME = user_data; + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection * s_con; + NMSettingTeamPort * s_team_port; + const char * expected_config = "{\"p4p1\": {\"prio\": -10, \"sticky\": true}}"; connection = _connection_from_file(PATH_NAME, NULL, TYPE_ETHERNET, NULL); - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con); + s_con = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); g_assert_cmpstr(nm_setting_connection_get_connection_type(s_con), ==, NM_SETTING_WIRED_SETTING_NAME); g_assert_cmpstr(nm_setting_connection_get_master(s_con), ==, "team0"); - s_team_port = nm_connection_get_setting_team_port(connection); - g_assert(s_team_port); + s_team_port = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_TEAM_PORT); g_assert_cmpstr(nm_setting_team_port_get_config(s_team_port), ==, expected_config); - - g_object_unref(connection); } static void @@ -10175,16 +8803,12 @@ test_write_team_port(void) gs_unref_object NMConnection *reread = NULL; NMSettingConnection * s_con; NMSettingTeamPort * s_team_port; - NMSettingWired * s_wired; const char * expected_config = "{\"p4p1\": {\"prio\": -10, \"sticky\": true}}"; shvarFile * f; connection = nm_simple_connection_new(); - /* Connection setting */ - s_con = (NMSettingConnection *) nm_setting_connection_new(); - nm_connection_add_setting(connection, NM_SETTING(s_con)); - + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); g_object_set(s_con, NM_SETTING_CONNECTION_ID, "Test Write Team Port", @@ -10198,14 +8822,10 @@ test_write_team_port(void) NM_SETTING_TEAM_SETTING_NAME, NULL); - /* Team setting */ - s_team_port = (NMSettingTeamPort *) nm_setting_team_port_new(); - nm_connection_add_setting(connection, NM_SETTING(s_team_port)); + s_team_port = _nm_connection_new_setting(connection, NM_TYPE_SETTING_TEAM_PORT); g_object_set(s_team_port, NM_SETTING_TEAM_PORT_CONFIG, expected_config, NULL); - /* Wired setting */ - s_wired = (NMSettingWired *) nm_setting_wired_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wired)); + _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRED); nmtst_assert_connection_verifies(connection); @@ -10234,16 +8854,13 @@ test_write_team_infiniband_port(void) gs_unref_object NMConnection *reread = NULL; NMSettingConnection * s_con; NMSettingTeamPort * s_team_port; - NMSettingInfiniband * s_inf; + NMSettingInfiniband * s_infiniband; const char * expected_config = "{\"inf1\": {\"prio\": -10, \"sticky\": true}}"; shvarFile * f; connection = nm_simple_connection_new(); - /* Connection setting */ - s_con = (NMSettingConnection *) nm_setting_connection_new(); - nm_connection_add_setting(connection, NM_SETTING(s_con)); - + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); g_object_set(s_con, NM_SETTING_CONNECTION_ID, "Test Write Team Infiniband Port", @@ -10259,15 +8876,11 @@ test_write_team_infiniband_port(void) "inf1", NULL); - /* Team setting */ - s_team_port = (NMSettingTeamPort *) nm_setting_team_port_new(); - nm_connection_add_setting(connection, NM_SETTING(s_team_port)); + s_team_port = _nm_connection_new_setting(connection, NM_TYPE_SETTING_TEAM_PORT); g_object_set(s_team_port, NM_SETTING_TEAM_PORT_CONFIG, expected_config, NULL); - /* Infiniband setting */ - s_inf = (NMSettingInfiniband *) nm_setting_infiniband_new(); - nm_connection_add_setting(connection, NM_SETTING(s_inf)); - g_object_set(s_inf, NM_SETTING_INFINIBAND_TRANSPORT_MODE, "datagram", NULL); + s_infiniband = _nm_connection_new_setting(connection, NM_TYPE_SETTING_INFINIBAND); + g_object_set(s_infiniband, NM_SETTING_INFINIBAND_TRANSPORT_MODE, "datagram", NULL); nmtst_assert_connection_verifies(connection); @@ -10291,28 +8904,26 @@ test_write_team_infiniband_port(void) static void test_read_team_port_empty_config(void) { - NMConnection * connection; - NMSettingConnection *s_con; + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection * s_con; + NMSettingTeamPort * s_team_port; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-team-port-empty-config", NULL, TYPE_ETHERNET, NULL); - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con); + s_con = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); g_assert_cmpstr(nm_setting_connection_get_connection_type(s_con), ==, NM_SETTING_WIRED_SETTING_NAME); g_assert_cmpstr(nm_setting_connection_get_master(s_con), ==, "team0"); /* Normalization adds a team-port setting */ - g_assert(nm_connection_get_setting_team_port(connection)); + s_team_port = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_TEAM_PORT); /* empty/missing config */ - g_assert(!nm_setting_team_port_get_config(nm_connection_get_setting_team_port(connection))); - - g_object_unref(connection); + g_assert(!nm_setting_team_port_get_config(s_team_port)); } static void @@ -10359,7 +8970,7 @@ test_team_reread_slave(void) NM_SETTING_CONNECTION_SLAVE_TYPE, "team", NULL); - g_object_set(nm_connection_get_setting_vlan(connection_2), + g_object_set(nmtst_connection_assert_setting(connection_2, NM_TYPE_SETTING_VLAN), NM_SETTING_VLAN_FLAGS, 1, NM_SETTING_VLAN_ID, @@ -10367,7 +8978,9 @@ test_team_reread_slave(void) NM_SETTING_VLAN_PARENT, "enp31s0f1", NULL); - nm_connection_add_setting(connection_2, nm_setting_team_port_new()); + + _nm_connection_new_setting(connection_2, NM_TYPE_SETTING_TEAM_PORT); + nmtst_connection_normalize(connection_2); nmtst_assert_connection_equals(connection_1, FALSE, connection_2, FALSE); @@ -10392,8 +9005,8 @@ test_team_reread_slave(void) static void test_read_proxy_basic(void) { - NMConnection * connection; - NMSettingProxy *s_proxy; + gs_unref_object NMConnection *connection = NULL; + NMSettingProxy * s_proxy; /* Test basic proxy configuration */ @@ -10402,18 +9015,13 @@ test_read_proxy_basic(void) TYPE_ETHERNET, NULL); - /* ===== Proxy setting ===== */ - s_proxy = nm_connection_get_setting_proxy(connection); - g_assert(s_proxy); + s_proxy = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_PROXY); - /* Proxy method */ g_assert_cmpint(nm_setting_proxy_get_method(s_proxy), ==, NM_SETTING_PROXY_METHOD_AUTO); g_assert(nm_setting_proxy_get_browser_only(s_proxy)); g_assert_cmpstr(nm_setting_proxy_get_pac_url(s_proxy), ==, "http://wpad.mycompany.com/wpad.dat"); - - g_object_unref(connection); } static void @@ -10423,17 +9031,13 @@ test_write_proxy_basic(void) gs_unref_object NMConnection *connection = NULL; gs_unref_object NMConnection *reread = NULL; NMSettingConnection * s_con; - NMSettingWired * s_wired; NMSettingProxy * s_proxy; const char * expected_url = "https://wpad.neverland.org/wpad.dat"; shvarFile * f; connection = nm_simple_connection_new(); - /* Connection setting */ - s_con = (NMSettingConnection *) nm_setting_connection_new(); - nm_connection_add_setting(connection, NM_SETTING(s_con)); - + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); g_object_set(s_con, NM_SETTING_CONNECTION_ID, "Test Write Proxy Basic", @@ -10443,15 +9047,11 @@ test_write_proxy_basic(void) NM_SETTING_WIRED_SETTING_NAME, NULL); - /* Proxy setting */ - s_proxy = (NMSettingProxy *) nm_setting_proxy_new(); - nm_connection_add_setting(connection, NM_SETTING(s_proxy)); + s_proxy = _nm_connection_new_setting(connection, NM_TYPE_SETTING_PROXY); g_object_set(s_proxy, NM_SETTING_PROXY_METHOD, NM_SETTING_PROXY_METHOD_AUTO, NULL); g_object_set(s_proxy, NM_SETTING_PROXY_PAC_URL, expected_url, NULL); - /* Wired setting */ - s_wired = (NMSettingWired *) nm_setting_wired_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wired)); + _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRED); nmtst_assert_connection_verifies(connection); @@ -10919,12 +9519,12 @@ test_write_unknown(gconstpointer test_data) static void test_read_vlan_trailing_spaces(void) { - const char * testfile = TEST_IFCFG_DIR "/ifcfg-test-vlan-trailing-spaces"; - NMConnection * connection; - gboolean success; - GError * error = NULL; - NMSettingVlan *s_vlan; - char * contents = NULL; + const char * testfile = TEST_IFCFG_DIR "/ifcfg-test-vlan-trailing-spaces"; + gs_unref_object NMConnection *connection = NULL; + gboolean success; + GError * error = NULL; + NMSettingVlan * s_vlan; + gs_free char * contents = NULL; /* Ensure there is whitespace at the end of the VLAN interface name, * to prevent the whitespace getting stripped off and committed mistakenly @@ -10935,19 +9535,15 @@ test_read_vlan_trailing_spaces(void) g_assert(success); g_assert(contents && contents[0]); g_assert(strstr(contents, "DEVICE=\"vlan201\" \n")); - g_free(contents); connection = _connection_from_file(testfile, NULL, TYPE_ETHERNET, NULL); - s_vlan = nm_connection_get_setting_vlan(connection); - g_assert(s_vlan); + s_vlan = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_VLAN); g_assert_cmpstr(nm_connection_get_interface_name(connection), ==, "vlan201"); g_assert_cmpstr(nm_setting_vlan_get_parent(s_vlan), ==, "enccw0.0.fb00"); g_assert_cmpint(nm_setting_vlan_get_id(s_vlan), ==, 201); g_assert_cmpint(nm_setting_vlan_get_flags(s_vlan), ==, NM_VLAN_FLAG_REORDER_HEADERS); - - g_object_unref(connection); } /*****************************************************************************/ @@ -10998,31 +9594,28 @@ test_utils_name(void) static void do_test_utils_path_ifcfg(const char *desc, const char *path, const char *expected) { - char *result; + gs_free char *result = NULL; result = utils_get_ifcfg_path(path); g_assert_cmpstr(result, ==, expected); - g_free(result); } static void do_test_utils_path_keys(const char *desc, const char *path, const char *expected) { - char *result; + gs_free char *result = NULL; result = utils_get_keys_path(path); g_assert_cmpstr(result, ==, expected); - g_free(result); } static void do_test_utils_path_route(const char *desc, const char *path, const char *expected) { - char *result; + gs_free char *result = NULL; result = utils_get_route_path(path); g_assert_cmpstr(result, ==, expected); - g_free(result); } static void @@ -11092,15 +9685,15 @@ test_sriov_read(void) NMSriovVF * vf; GVariant * variant; GError * error = NULL; - char * str; + gs_free char * str1 = NULL; + gs_free char * str2 = NULL; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-sriov", NULL, TYPE_ETHERNET, NULL); g_assert_cmpstr(nm_connection_get_interface_name(connection), ==, "eth0"); - s_sriov = NM_SETTING_SRIOV(nm_connection_get_setting(connection, NM_TYPE_SETTING_SRIOV)); - g_assert(s_sriov); + s_sriov = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_SRIOV); g_assert_cmpint(nm_setting_sriov_get_total_vfs(s_sriov), ==, 16); g_assert_cmpint(nm_setting_sriov_get_num_vfs(s_sriov), ==, 3); @@ -11122,18 +9715,16 @@ test_sriov_read(void) g_assert_cmpint(g_variant_get_boolean(variant), ==, TRUE); /* VF 12 */ - vf = nm_setting_sriov_get_vf(s_sriov, 1); - str = nm_utils_sriov_vf_to_str(vf, FALSE, &error); + vf = nm_setting_sriov_get_vf(s_sriov, 1); + str1 = nm_utils_sriov_vf_to_str(vf, FALSE, &error); g_assert_no_error(error); - g_assert_cmpstr(str, ==, "12 min-tx-rate=100 trust=false vlans=1.200.ad"); - g_free(str); + g_assert_cmpstr(str1, ==, "12 min-tx-rate=100 trust=false vlans=1.200.ad"); /* VF 15 */ - vf = nm_setting_sriov_get_vf(s_sriov, 2); - str = nm_utils_sriov_vf_to_str(vf, FALSE, &error); + vf = nm_setting_sriov_get_vf(s_sriov, 2); + str2 = nm_utils_sriov_vf_to_str(vf, FALSE, &error); g_assert_no_error(error); - g_assert_cmpstr(str, ==, "15 mac=01:23:45:67:89:ab max-tx-rate=200 vlans=2"); - g_free(str); + g_assert_cmpstr(str2, ==, "15 mac=01:23:45:67:89:ab max-tx-rate=200 vlans=2"); } static void @@ -11145,7 +9736,6 @@ test_sriov_write(void) NMSettingConnection * s_con; NMSettingIPConfig * s_ip4; NMSettingIPConfig * s_ip6; - NMSettingWired * s_wired; NMSettingSriov * s_sriov; NMSriovVF * vf; gs_unref_ptrarray GPtrArray *vfs = NULL; @@ -11154,10 +9744,7 @@ test_sriov_write(void) connection = nm_simple_connection_new(); - /* Connection setting */ - s_con = (NMSettingConnection *) nm_setting_connection_new(); - nm_connection_add_setting(connection, NM_SETTING(s_con)); - + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); g_object_set(s_con, NM_SETTING_CONNECTION_ID, "Test Write SR-IOV config", @@ -11171,14 +9758,9 @@ test_sriov_write(void) NM_SETTING_WIRED_SETTING_NAME, NULL); - /* Wired setting */ - s_wired = (NMSettingWired *) nm_setting_wired_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wired)); - - /* IP4 setting */ - s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip4)); + _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRED); + s_ip4 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL, @@ -11193,15 +9775,10 @@ test_sriov_write(void) nm_setting_ip_config_add_address(s_ip4, addr); nm_ip_address_unref(addr); - /* IP6 setting */ - s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip6)); - + s_ip6 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP6_CONFIG); g_object_set(s_ip6, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, NULL); - /* SRIOV setting */ - s_sriov = (NMSettingSriov *) nm_setting_sriov_new(); - nm_connection_add_setting(connection, NM_SETTING(s_sriov)); + s_sriov = _nm_connection_new_setting(connection, NM_TYPE_SETTING_SRIOV); vfs = g_ptr_array_new_with_free_func((GDestroyNotify) nm_sriov_vf_unref); @@ -11222,7 +9799,7 @@ test_sriov_write(void) NM_TERNARY_TRUE, NULL); - nm_connection_add_setting(connection, nm_setting_proxy_new()); + _nm_connection_new_setting(connection, NM_TYPE_SETTING_PROXY); nmtst_assert_connection_verifies_without_normalization(connection); @@ -11241,18 +9818,17 @@ test_sriov_write(void) static void test_tc_read(void) { - NMConnection * connection; - NMSettingTCConfig *s_tc; - NMTCQdisc * qdisc; - NMTCTfilter * filter; - char * str; + gs_unref_object NMConnection *connection = NULL; + NMSettingTCConfig * s_tc; + NMTCQdisc * qdisc; + NMTCTfilter * filter; + gs_free char * str = NULL; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-tc", NULL, TYPE_ETHERNET, NULL); g_assert_cmpstr(nm_connection_get_interface_name(connection), ==, "eth0"); - s_tc = nm_connection_get_setting_tc_config(connection); - g_assert(s_tc); + s_tc = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_TC_CONFIG); g_assert_cmpint(nm_setting_tc_config_get_num_qdiscs(s_tc), ==, 1); qdisc = nm_setting_tc_config_get_qdisc(s_tc, 0); @@ -11266,9 +9842,6 @@ test_tc_read(void) g_assert(filter); str = nm_utils_tc_tfilter_to_str(filter, NULL); g_assert_cmpstr(str, ==, "parent 1234: matchall action simple sdata Hello"); - g_free(str); - - g_object_unref(connection); } static void @@ -11280,17 +9853,12 @@ test_tc_write_empty(void) NMSettingConnection * s_con; NMSettingIPConfig * s_ip4; NMSettingIPConfig * s_ip6; - NMSettingWired * s_wired; - NMSettingTCConfig * s_tc; NMIPAddress * addr; GError * error = NULL; connection = nm_simple_connection_new(); - /* Connection setting */ - s_con = (NMSettingConnection *) nm_setting_connection_new(); - nm_connection_add_setting(connection, NM_SETTING(s_con)); - + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); g_object_set(s_con, NM_SETTING_CONNECTION_ID, "Test Write TC config", @@ -11304,14 +9872,9 @@ test_tc_write_empty(void) NM_SETTING_WIRED_SETTING_NAME, NULL); - /* Wired setting */ - s_wired = (NMSettingWired *) nm_setting_wired_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wired)); - - /* IP4 setting */ - s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip4)); + _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRED); + s_ip4 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL, @@ -11326,17 +9889,12 @@ test_tc_write_empty(void) nm_setting_ip_config_add_address(s_ip4, addr); nm_ip_address_unref(addr); - /* IP6 setting */ - s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip6)); - + s_ip6 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP6_CONFIG); g_object_set(s_ip6, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, NULL); - /* TC setting */ - s_tc = (NMSettingTCConfig *) nm_setting_tc_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_tc)); + _nm_connection_new_setting(connection, NM_TYPE_SETTING_TC_CONFIG); - nm_connection_add_setting(connection, nm_setting_proxy_new()); + _nm_connection_new_setting(connection, NM_TYPE_SETTING_PROXY); nmtst_assert_connection_verifies_without_normalization(connection); @@ -11359,7 +9917,6 @@ test_tc_write(void) NMSettingConnection * s_con; NMSettingIPConfig * s_ip4; NMSettingIPConfig * s_ip6; - NMSettingWired * s_wired; NMSettingTCConfig * s_tc; NMTCQdisc * qdisc; NMTCTfilter * tfilter; @@ -11368,10 +9925,7 @@ test_tc_write(void) connection = nm_simple_connection_new(); - /* Connection setting */ - s_con = (NMSettingConnection *) nm_setting_connection_new(); - nm_connection_add_setting(connection, NM_SETTING(s_con)); - + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); g_object_set(s_con, NM_SETTING_CONNECTION_ID, "Test Write TC config", @@ -11385,14 +9939,9 @@ test_tc_write(void) NM_SETTING_WIRED_SETTING_NAME, NULL); - /* Wired setting */ - s_wired = (NMSettingWired *) nm_setting_wired_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wired)); - - /* IP4 setting */ - s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip4)); + _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRED); + s_ip4 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL, @@ -11407,15 +9956,10 @@ test_tc_write(void) nm_setting_ip_config_add_address(s_ip4, addr); nm_ip_address_unref(addr); - /* IP6 setting */ - s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip6)); - + s_ip6 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP6_CONFIG); g_object_set(s_ip6, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, NULL); - /* TC setting */ - s_tc = (NMSettingTCConfig *) nm_setting_tc_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_tc)); + s_tc = _nm_connection_new_setting(connection, NM_TYPE_SETTING_TC_CONFIG); qdisc = nm_tc_qdisc_new("pfifo_fast", TC_H_MAKE(0x2468 << 16, 0x2), &error); g_assert_no_error(error); @@ -11428,7 +9972,7 @@ test_tc_write(void) nm_setting_tc_config_add_tfilter(s_tc, tfilter); nm_tc_tfilter_unref(tfilter); - nm_connection_add_setting(connection, nm_setting_proxy_new()); + _nm_connection_new_setting(connection, NM_TYPE_SETTING_PROXY); nmtst_assert_connection_verifies_without_normalization(connection); @@ -12040,6 +10584,8 @@ main(int argc, char **argv) g_test_add_func(TPATH "bond/write-slave", test_write_bond_slave); g_test_add_func(TPATH "bond/write-slave-ib", test_write_bond_slave_ib); g_test_add_func(TPATH "bond/bonding-opts-numeric-mode", test_read_bond_opts_mode_numeric); + g_test_add_func(TPATH "bond/read-bond-port", test_read_bond_port); + g_test_add_func(TPATH "bond/write-bond-port", test_write_bond_port); g_test_add_func(TPATH "bridge/read-master", test_read_bridge_main); g_test_add_func(TPATH "bridge/write-master", test_write_bridge_main); diff --git a/src/core/settings/plugins/ifupdown/nms-ifupdown-interface-parser.c b/src/core/settings/plugins/ifupdown/nms-ifupdown-interface-parser.c index a8a9c40a..84986877 100644 --- a/src/core/settings/plugins/ifupdown/nms-ifupdown-interface-parser.c +++ b/src/core/settings/plugins/ifupdown/nms-ifupdown-interface-parser.c @@ -112,7 +112,7 @@ _recursive_ifparser(if_parser *parser, const char *eni_file, int quiet) /* Check if interfaces file exists and open it */ if (!g_file_test(eni_file, G_FILE_TEST_EXISTS)) { if (!quiet) - _LOGW("interfaces file %s doesn't exist", eni_file); + _LOGI("interfaces file %s doesn't exist", eni_file); return; } inp = fopen(eni_file, "re"); diff --git a/src/core/settings/plugins/ifupdown/nms-ifupdown-parser.c b/src/core/settings/plugins/ifupdown/nms-ifupdown-parser.c index db6b1aef..5bad2362 100644 --- a/src/core/settings/plugins/ifupdown/nms-ifupdown-parser.c +++ b/src/core/settings/plugins/ifupdown/nms-ifupdown-parser.c @@ -397,7 +397,7 @@ ifupdown_ip4_add_dns(NMSettingIPConfig *s_ip4, const char *dns) if (dns == NULL) return; - list = nm_utils_strsplit_set(dns, " \t"); + list = nm_strsplit_set(dns, " \t"); for (iter = list; iter && *iter; iter++) { if (!inet_pton(AF_INET, *iter, &addr)) { _LOGW(" ignoring invalid nameserver '%s'", *iter); @@ -497,7 +497,7 @@ update_ip4_setting_from_if_block(NMConnection *connection, if_block *block, GErr gs_free const char **list = NULL; const char ** iter; - list = nm_utils_strsplit_set(search_v, " \t"); + list = nm_strsplit_set(search_v, " \t"); for (iter = list; iter && *iter; iter++) { if (!nm_setting_ip_config_add_dns_search(s_ip4, *iter)) _LOGW(" duplicate DNS domain '%s'", *iter); @@ -521,7 +521,7 @@ ifupdown_ip6_add_dns(NMSettingIPConfig *s_ip6, const char *dns) if (dns == NULL) return; - list = nm_utils_strsplit_set(dns, " \t"); + list = nm_strsplit_set(dns, " \t"); for (iter = list; iter && *iter; iter++) { if (!inet_pton(AF_INET6, *iter, &addr)) { _LOGW(" ignoring invalid nameserver '%s'", *iter); @@ -605,7 +605,7 @@ update_ip6_setting_from_if_block(NMConnection *connection, if_block *block, GErr gs_free const char **list = NULL; const char ** iter; - list = nm_utils_strsplit_set(search_v, " \t"); + list = nm_strsplit_set(search_v, " \t"); for (iter = list; iter && *iter; iter++) { if (!nm_setting_ip_config_add_dns_search(s_ip6, *iter)) _LOGW(" duplicate DNS domain '%s'", *iter); diff --git a/src/core/settings/plugins/ifupdown/nms-ifupdown-plugin.c b/src/core/settings/plugins/ifupdown/nms-ifupdown-plugin.c index 80a5638a..602a7327 100644 --- a/src/core/settings/plugins/ifupdown/nms-ifupdown-plugin.c +++ b/src/core/settings/plugins/ifupdown/nms-ifupdown-plugin.c @@ -189,7 +189,7 @@ _unmanaged_specs(GHashTable *eni_ifaces) GSList * specs = NULL; guint i, len; - keys = nm_utils_strdict_get_keys(eni_ifaces, TRUE, &len); + keys = nm_strdict_get_keys(eni_ifaces, TRUE, &len); for (i = len; i > 0;) { i--; specs = g_slist_prepend(specs, @@ -264,7 +264,7 @@ load_eni_ifaces(NMSIfupdownPlugin *self) _LOGD("parse: found bridge ports %s for %s", ports, block->name); - port_ifaces = nm_utils_strsplit_set(ports, " \t"); + port_ifaces = nm_strsplit_set(ports, " \t"); for (i = 0; port_ifaces && port_ifaces[i]; i++) { const char *token = port_ifaces[i]; @@ -323,7 +323,7 @@ load_eni_ifaces(NMSIfupdownPlugin *self) NM_PRINT_FMT_QUOTED(local, " (", local->message, ")", "")); sd = NULL; } else { - nmtst_connection_assert_unchanging(connection); + nm_assert_connection_unchanging(connection); uuid = nm_connection_get_uuid(connection); if (!storage) diff --git a/src/core/settings/plugins/keyfile/nms-keyfile-plugin.c b/src/core/settings/plugins/keyfile/nms-keyfile-plugin.c index e8ae1814..aa36ee8f 100644 --- a/src/core/settings/plugins/keyfile/nms-keyfile-plugin.c +++ b/src/core/settings/plugins/keyfile/nms-keyfile-plugin.c @@ -101,27 +101,27 @@ _extra_flags_to_string(char * str, const char *str0 = str; if (!is_nm_generated && !is_volatile && !is_external) - nm_utils_strbuf_append_str(&str, &str_len, ""); + nm_strbuf_append_str(&str, &str_len, ""); else { char ch = '('; - nm_utils_strbuf_append_c(&str, &str_len, ' '); + nm_strbuf_append_c(&str, &str_len, ' '); if (is_nm_generated) { - nm_utils_strbuf_append_c(&str, &str_len, ch); - nm_utils_strbuf_append_str(&str, &str_len, "nm-generated"); + nm_strbuf_append_c(&str, &str_len, ch); + nm_strbuf_append_str(&str, &str_len, "nm-generated"); ch = ','; } if (is_volatile) { - nm_utils_strbuf_append_c(&str, &str_len, ch); - nm_utils_strbuf_append_str(&str, &str_len, "volatile"); + nm_strbuf_append_c(&str, &str_len, ch); + nm_strbuf_append_str(&str, &str_len, "volatile"); ch = ','; } if (is_external) { - nm_utils_strbuf_append_c(&str, &str_len, ch); - nm_utils_strbuf_append_str(&str, &str_len, "external"); + nm_strbuf_append_c(&str, &str_len, ch); + nm_strbuf_append_str(&str, &str_len, "external"); ch = ','; } - nm_utils_strbuf_append_c(&str, &str_len, ')'); + nm_strbuf_append_c(&str, &str_len, ')'); } return str0; diff --git a/src/core/settings/plugins/keyfile/nms-keyfile-storage.c b/src/core/settings/plugins/keyfile/nms-keyfile-storage.c index 8c526c81..ec0634c4 100644 --- a/src/core/settings/plugins/keyfile/nms-keyfile-storage.c +++ b/src/core/settings/plugins/keyfile/nms-keyfile-storage.c @@ -168,7 +168,7 @@ nms_keyfile_storage_new_connection(NMSKeyfilePlugin * plugin, nm_assert(filename && filename[0] == '/'); nm_assert(storage_type >= NMS_KEYFILE_STORAGE_TYPE_RUN && storage_type <= _NMS_KEYFILE_STORAGE_TYPE_LIB_LAST); - nmtst_connection_assert_unchanging(connection_take); + nm_assert_connection_unchanging(connection_take); self = _storage_new(plugin, nm_connection_get_uuid(connection_take), diff --git a/src/core/settings/plugins/keyfile/tests/test-keyfile-settings.c b/src/core/settings/plugins/keyfile/tests/test-keyfile-settings.c index a13c2586..4ceed49d 100644 --- a/src/core/settings/plugins/keyfile/tests/test-keyfile-settings.c +++ b/src/core/settings/plugins/keyfile/tests/test-keyfile-settings.c @@ -992,7 +992,7 @@ test_read_intlike_ssid(void) ssid = nm_setting_wireless_get_ssid(s_wifi); g_assert(ssid); - g_assert(nm_utils_gbytes_equal_mem(ssid, expected_ssid, strlen(expected_ssid))); + g_assert(nm_g_bytes_equal_mem(ssid, expected_ssid, strlen(expected_ssid))); } static void @@ -1010,7 +1010,7 @@ test_read_intlike_ssid_2(void) ssid = nm_setting_wireless_get_ssid(s_wifi); g_assert(ssid); - g_assert(nm_utils_gbytes_equal_mem(ssid, expected_ssid, strlen(expected_ssid))); + g_assert(nm_g_bytes_equal_mem(ssid, expected_ssid, strlen(expected_ssid))); } static void @@ -1774,7 +1774,7 @@ test_write_wired_8021x_tls_connection_blob(void) password_raw = nm_setting_802_1x_get_password_raw(s_8021x); g_assert(password_raw); - g_assert(nm_utils_gbytes_equal_mem(password_raw, PASSWORD_RAW, NM_STRLEN(PASSWORD_RAW))); + g_assert(nm_g_bytes_equal_mem(password_raw, PASSWORD_RAW, NM_STRLEN(PASSWORD_RAW))); unlink(testfile); @@ -2160,7 +2160,7 @@ test_read_new_wireless_group_names(void) ssid = nm_setting_wireless_get_ssid(s_wifi); g_assert(ssid); - g_assert(nm_utils_gbytes_equal_mem(ssid, expected_ssid, strlen(expected_ssid))); + g_assert(nm_g_bytes_equal_mem(ssid, expected_ssid, strlen(expected_ssid))); g_assert_cmpstr(nm_setting_wireless_get_mode(s_wifi), ==, NM_SETTING_WIRELESS_MODE_INFRA); -- cgit 1.3.0-6-gf8a5