summary refs log tree commit diff
path: root/libnm-core
diff options
context:
space:
mode:
Diffstat (limited to 'libnm-core')
-rw-r--r--libnm-core/nm-keyfile/nm-keyfile-utils.c4
-rw-r--r--libnm-core/nm-keyfile/nm-keyfile.c2
-rw-r--r--libnm-core/nm-setting-bridge.c7
-rw-r--r--libnm-core/nm-setting-connection.c23
-rw-r--r--libnm-core/nm-setting-wired.c7
-rw-r--r--libnm-core/nm-setting-wireguard.c9
-rw-r--r--libnm-core/nm-utils.c62
-rw-r--r--libnm-core/tests/test-setting.c8
8 files changed, 64 insertions, 58 deletions
diff --git a/libnm-core/nm-keyfile/nm-keyfile-utils.c b/libnm-core/nm-keyfile/nm-keyfile-utils.c
index 0ffce40b..01b42ac7 100644
--- a/libnm-core/nm-keyfile/nm-keyfile-utils.c
+++ b/libnm-core/nm-keyfile/nm-keyfile-utils.c
@@ -144,12 +144,12 @@ nm_keyfile_plugin_kf_get_integer_list_uint (GKeyFile *key_file,
 	gs_free guint *int_values = NULL;
 	gsize i, num_ints;
 
+	NM_SET_OUT (out_length, 0);
+
 	g_return_val_if_fail (key_file != NULL, NULL);
 	g_return_val_if_fail (group_name != NULL, NULL);
 	g_return_val_if_fail (key != NULL, NULL);
 
-	NM_SET_OUT (out_length, 0);
-
 	values = nm_keyfile_plugin_kf_get_string_list (key_file, group_name, key, &num_ints, &key_file_error);
 
 	if (key_file_error)
diff --git a/libnm-core/nm-keyfile/nm-keyfile.c b/libnm-core/nm-keyfile/nm-keyfile.c
index 77af2b64..79f9c5f9 100644
--- a/libnm-core/nm-keyfile/nm-keyfile.c
+++ b/libnm-core/nm-keyfile/nm-keyfile.c
@@ -2296,9 +2296,9 @@ wired_s390_options_writer_full (KeyfileWriterInfo *info,
 
 	n = nm_setting_wired_get_num_s390_options (s_wired);
 	for (i = 0; i < n; i++) {
+		gs_free char *key_to_free = NULL;
 		const char *opt_key;
 		const char *opt_val;
-		gs_free char *key_to_free = NULL;
 
 		nm_setting_wired_get_s390_option (s_wired, i, &opt_key, &opt_val);
 		nm_keyfile_plugin_kf_set_string (info->keyfile,
diff --git a/libnm-core/nm-setting-bridge.c b/libnm-core/nm-setting-bridge.c
index 2ead2739..5082547e 100644
--- a/libnm-core/nm-setting-bridge.c
+++ b/libnm-core/nm-setting-bridge.c
@@ -268,6 +268,13 @@ nm_bridge_vlan_get_vid_range (const NMBridgeVlan *vlan,
                               guint16 *vid_start,
                               guint16 *vid_end)
 {
+	/* with LTO and optimization, the compiler complains that the
+	 * output variables are not initialized. In practice, the function
+	 * only sets the output on success. But make the compiler happy.
+	 */
+	NM_SET_OUT (vid_start, 0);
+	NM_SET_OUT (vid_end, 0);
+
 	g_return_val_if_fail (NM_IS_BRIDGE_VLAN (vlan, TRUE), 0);
 
 	NM_SET_OUT (vid_start, vlan->vid_start);
diff --git a/libnm-core/nm-setting-connection.c b/libnm-core/nm-setting-connection.c
index 018129be..03f8fb23 100644
--- a/libnm-core/nm-setting-connection.c
+++ b/libnm-core/nm-setting-connection.c
@@ -689,7 +689,7 @@ nm_setting_connection_is_slave_type (NMSettingConnection *setting,
  * @setting: the #NMSettingConnection
  *
  * Returns: the %NM_SETTING_CONNECTION_WAIT_DEVICE_TIMEOUT property with
- *   the timeout in milli seconds. -1 is the default.
+ *   the timeout in milliseconds. -1 is the default.
  *
  * Since: 1.20
  */
@@ -1218,20 +1218,6 @@ after_interface_name:
 		return FALSE;
 	}
 
-	if (   priv->wait_device_timeout != -1
-	    && !priv->interface_name) {
-		/* currently, only waiting by interface-name is implemented. Hence reject
-		 * configurations that are not implemented (yet). */
-		g_set_error (error,
-		             NM_CONNECTION_ERROR,
-		             NM_CONNECTION_ERROR_INVALID_PROPERTY,
-		             _("wait-device-timeout requires %s"),
-		             NM_SETTING_CONNECTION_INTERFACE_NAME);
-		g_prefix_error (error, "%s.%s: ", NM_SETTING_CONNECTION_SETTING_NAME,
-		                NM_SETTING_CONNECTION_WAIT_DEVICE_TIMEOUT);
-		return FALSE;
-	}
-
 	if (priv->mud_url) {
 		if (!priv->mud_url[0]) {
 			g_set_error_literal (error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_INVALID_PROPERTY,
@@ -2314,10 +2300,9 @@ nm_setting_connection_class_init (NMSettingConnectionClass *klass)
 	 * Timeout in milliseconds to wait for device at startup.
 	 * During boot, devices may take a while to be detected by the driver.
 	 * This property will cause to delay NetworkManager-wait-online.service
-	 * and nm-online to give the device a chance to appear.
-	 *
-	 * Note that this property only works together with NMSettingConnection:interface-name
-	 * to identify the device that will be waited for.
+	 * and nm-online to give the device a chance to appear. This works by
+	 * waiting for the given timeout until a compatible device for the
+	 * profile is available and managed.
 	 *
 	 * The value 0 means no wait time. The default value is -1, which
 	 * currently has the same meaning as no wait time.
diff --git a/libnm-core/nm-setting-wired.c b/libnm-core/nm-setting-wired.c
index ab13d88a..8b0f2558 100644
--- a/libnm-core/nm-setting-wired.c
+++ b/libnm-core/nm-setting-wired.c
@@ -490,6 +490,13 @@ nm_setting_wired_get_s390_option (NMSettingWired *setting,
 {
 	NMSettingWiredPrivate *priv;
 
+	/* with LTO and optimization, the compiler complains that the
+	 * output variables are not initialized. In practice, the function
+	 * only sets the output on success. But make the compiler happy.
+	 */
+	NM_SET_OUT (out_key,   NULL);
+	NM_SET_OUT (out_value, NULL);
+
 	g_return_val_if_fail (NM_IS_SETTING_WIRED (setting), FALSE);
 
 	priv = NM_SETTING_WIRED_GET_PRIVATE (setting);
diff --git a/libnm-core/nm-setting-wireguard.c b/libnm-core/nm-setting-wireguard.c
index 2bd633ce..3b2815c0 100644
--- a/libnm-core/nm-setting-wireguard.c
+++ b/libnm-core/nm-setting-wireguard.c
@@ -592,13 +592,16 @@ nm_wireguard_peer_get_allowed_ip (const NMWireGuardPeer *self,
 {
 	const char *s;
 
+	/* With LTO, the compiler might warn about the g_return_val_if_fail()
+	 * code path not initializing the output argument. Workaround that by
+	 * always setting the out argument. */
+	NM_SET_OUT (out_is_valid, FALSE);
+
 	g_return_val_if_fail (NM_IS_WIREGUARD_PEER (self, TRUE), NULL);
 
 	if (   !self->allowed_ips
-	    || idx >= self->allowed_ips->len) {
-		NM_SET_OUT (out_is_valid, FALSE);
+	    || idx >= self->allowed_ips->len)
 		return NULL;
-	}
 
 	s = self->allowed_ips->pdata[idx];
 	NM_SET_OUT (out_is_valid, s[0] != ALLOWED_IP_INVALID_X);
diff --git a/libnm-core/nm-utils.c b/libnm-core/nm-utils.c
index 425c3027..b2527283 100644
--- a/libnm-core/nm-utils.c
+++ b/libnm-core/nm-utils.c
@@ -2067,8 +2067,8 @@ nm_utils_ip_addresses_from_variant (GVariant *value,
 
 		g_variant_iter_init (&attrs_iter, addr_var);
 		while (g_variant_iter_next (&attrs_iter, "{&sv}", &attr_name, &attr_val)) {
-			if (   strcmp (attr_name, "address") != 0
-			    && strcmp (attr_name, "prefix") != 0)
+			if (!NM_IN_STRSET (attr_name, "address",
+			                              "prefix"))
 				nm_ip_address_set_attribute (addr, attr_name, attr_val);
 			g_variant_unref (attr_val);
 		}
@@ -2193,10 +2193,10 @@ nm_utils_ip_routes_from_variant (GVariant *value,
 
 		g_variant_iter_init (&attrs_iter, route_var);
 		while (g_variant_iter_next (&attrs_iter, "{&sv}", &attr_name, &attr_val)) {
-			if (   strcmp (attr_name, "dest") != 0
-			    && strcmp (attr_name, "prefix") != 0
-			    && strcmp (attr_name, "next-hop") != 0
-			    && strcmp (attr_name, "metric") != 0)
+			if (!NM_IN_STRSET (attr_name, "dest",
+			                              "prefix",
+			                              "next-hop",
+			                              "metric"))
 				nm_ip_route_set_attribute (route, attr_name, attr_val);
 			g_variant_unref (attr_val);
 		}
@@ -2376,7 +2376,8 @@ _nm_utils_string_append_tc_qdisc_rest (GString *string, NMTCQdisc *qdisc)
 	const char *kind = nm_tc_qdisc_get_kind (qdisc);
 	gs_free char *str = NULL;
 
-	if (handle != TC_H_UNSPEC && strcmp (kind, "ingress") != 0) {
+	if (   handle != TC_H_UNSPEC
+	    && !NM_IN_STRSET (kind, "ingress", "clsact")) {
 		g_string_append (string, "handle ");
 		_string_append_tc_handle (string, handle);
 		g_string_append_c (string, ' ');
@@ -2468,7 +2469,7 @@ _tc_read_common_opts (const char *str,
 	variant = g_hash_table_lookup (ht, "kind");
 	if (variant) {
 		*kind = g_variant_dup_string (variant, NULL);
-		if (strcmp (*kind, "ingress") == 0) {
+		if (NM_IN_STRSET (*kind, "ingress", "clsact")) {
 			if (*parent == TC_H_UNSPEC)
 				*parent = TC_H_INGRESS;
 			if (*handle == TC_H_UNSPEC)
@@ -2524,7 +2525,7 @@ nm_utils_tc_qdisc_from_str (const char *str, GError **error)
 		return NULL;
 
 	for (i = 0; rest && tc_qdisc_attribute_spec[i]; i++) {
-		if (strcmp (tc_qdisc_attribute_spec[i]->kind, kind) == 0) {
+		if (nm_streq (tc_qdisc_attribute_spec[i]->kind, kind)) {
 			options = nm_utils_parse_variant_attributes (rest,
 			                                             ' ', ' ', FALSE,
 			                                             tc_qdisc_attribute_spec[i]->attrs,
@@ -2670,9 +2671,9 @@ nm_utils_tc_action_from_str (const char *str, GError **error)
 	}
 
 	kind = g_variant_get_string (variant, NULL);
-	if (strcmp (kind, "simple") == 0)
+	if (nm_streq (kind, "simple"))
 		attrs = tc_action_simple_attribute_spec;
-	else if (strcmp (kind, "mirred") == 0)
+	else if (nm_streq (kind, "mirred"))
 		attrs = tc_action_mirred_attribute_spec;
 	else
 		attrs = NULL;
@@ -3750,11 +3751,11 @@ nm_utils_wifi_channel_to_freq (guint32 channel, const char *band)
 {
 	int i = 0;
 
-	if (!strcmp (band, "a")) {
+	if (nm_streq (band, "a")) {
 		while (a_table[i].chan && (a_table[i].chan != channel))
 			i++;
 		return a_table[i].freq;
-	} else if (!strcmp (band, "bg")) {
+	} else if (nm_streq (band, "bg")) {
 		while (bg_table[i].chan && (bg_table[i].chan != channel))
 			i++;
 		return bg_table[i].freq;
@@ -3776,17 +3777,17 @@ nm_utils_wifi_channel_to_freq (guint32 channel, const char *band)
 guint32
 nm_utils_wifi_find_next_channel (guint32 channel, int direction, char *band)
 {
-	size_t a_size = sizeof (a_table) / sizeof (struct cf_pair);
-	size_t bg_size = sizeof (bg_table) / sizeof (struct cf_pair);
+	size_t a_size = G_N_ELEMENTS (a_table);
+	size_t bg_size = G_N_ELEMENTS (bg_table);
 	struct cf_pair *pair = NULL;
 
-	if (!strcmp (band, "a")) {
+	if (nm_streq (band, "a")) {
 		if (channel < a_table[0].chan)
 			return a_table[0].chan;
 		if (channel > a_table[a_size - 2].chan)
 			return a_table[a_size - 2].chan;
 		pair = &a_table[0];
-	} else if (!strcmp (band, "bg")) {
+	} else if (nm_streq (band, "bg")) {
 		if (channel < bg_table[0].chan)
 			return bg_table[0].chan;
 		if (channel > bg_table[bg_size - 2].chan)
@@ -3826,9 +3827,9 @@ nm_utils_wifi_is_channel_valid (guint32 channel, const char *band)
 	struct cf_pair *table = NULL;
 	int i = 0;
 
-	if (!strcmp (band, "a"))
+	if (nm_streq (band, "a"))
 		table = a_table;
-	else if (!strcmp (band, "bg"))
+	else if (nm_streq (band, "bg"))
 		table = bg_table;
 	else
 		return FALSE;
@@ -5080,8 +5081,8 @@ nm_utils_bond_mode_string_to_int (const char *mode)
 		return -1;
 
 	for (i = 0; i < G_N_ELEMENTS (bond_mode_table); i++) {
-		if (   strcmp (mode, bond_mode_table[i].str) == 0
-		    || strcmp (mode, bond_mode_table[i].num) == 0)
+		if (NM_IN_STRSET (mode, bond_mode_table[i].str,
+		                        bond_mode_table[i].num))
 			return i;
 	}
 	return -1;
@@ -5139,13 +5140,13 @@ _nm_utils_strstrdictkey_equal  (gconstpointer a, gconstpointer b)
 		return FALSE;
 
 	if (k1->type & STRSTRDICTKEY_ALL_SET) {
-		if (strcmp (k1->data, k2->data) != 0)
+		if (!nm_streq (k1->data, k2->data))
 			return FALSE;
 
 		if (k1->type == STRSTRDICTKEY_ALL_SET) {
 			gsize l = strlen (k1->data) + 1;
 
-			return strcmp (&k1->data[l], &k2->data[l]) == 0;
+			return nm_streq (&k1->data[l], &k2->data[l]);
 		}
 	}
 
@@ -5196,7 +5197,7 @@ validate_dns_option (const char *name,
 		return !!*name;
 
 	for (desc = option_descs; desc->name; desc++) {
-		if (!strcmp (name, desc->name) &&
+		if (nm_streq (name, desc->name) &&
 		    numeric == desc->numeric &&
 		    (!desc->ipv6_only || ipv6))
 			return TRUE;
@@ -5286,26 +5287,21 @@ _nm_utils_dns_option_validate (const char *option,
  */
 gssize _nm_utils_dns_option_find_idx (GPtrArray *array, const char *option)
 {
-	gboolean ret;
-	char *option_name, *tmp_name;
+	gs_free char *option_name = NULL;
 	guint i;
 
 	if (!_nm_utils_dns_option_validate (option, &option_name, NULL, FALSE, NULL))
 		return -1;
 
 	for (i = 0; i < array->len; i++) {
+		gs_free char *tmp_name = NULL;
+
 		if (_nm_utils_dns_option_validate (array->pdata[i], &tmp_name, NULL, FALSE, NULL)) {
-			ret = strcmp (tmp_name, option_name);
-			g_free (tmp_name);
-			if (!ret) {
-				g_free (option_name);
+			if (nm_streq (tmp_name, option_name))
 				return i;
-			}
 		}
-
 	}
 
-	g_free (option_name);
 	return -1;
 }
 
diff --git a/libnm-core/tests/test-setting.c b/libnm-core/tests/test-setting.c
index 359c20c4..7a8193ee 100644
--- a/libnm-core/tests/test-setting.c
+++ b/libnm-core/tests/test-setting.c
@@ -2298,6 +2298,14 @@ test_tc_config_qdisc (void)
 	nm_tc_qdisc_unref (qdisc1);
 	nm_tc_qdisc_unref (qdisc2);
 
+	qdisc1 = nm_utils_tc_qdisc_from_str ("clsact", &error);
+	nmtst_assert_success (qdisc1, error);
+	str = nm_utils_tc_qdisc_to_str (qdisc1, &error);
+	nmtst_assert_success (str, error);
+	g_assert_cmpstr (str, ==, "clsact");
+	nm_tc_qdisc_unref (qdisc1);
+	g_free (str);
+
 #define CHECK_ATTRIBUTE(qdisc, name, vtype, type, value) \
 	variant = nm_tc_qdisc_get_attribute (qdisc, name); \
 	g_assert (variant); \