about summary refs log tree commit diff
path: root/libnm-core/nm-setting-ip-config.c
diff options
context:
space:
mode:
authorMichael Biebl <biebl@debian.org>2018-06-04 00:07:45 +0200
committerMichael Biebl <biebl@debian.org>2018-06-04 00:07:45 +0200
commit04bc9e1cd3544445d883ad29ea108c1645c8e7b7 (patch)
treed10c354b1b980ca8a7b9e48ec9019e8ed88bde2b /libnm-core/nm-setting-ip-config.c
parentee9c73a923909e23a649407be77e25235d769e25 (diff)
New upstream version 1.11.4 upstream/1.11.4
Diffstat (limited to 'libnm-core/nm-setting-ip-config.c')
-rw-r--r--libnm-core/nm-setting-ip-config.c131
1 files changed, 56 insertions, 75 deletions
diff --git a/libnm-core/nm-setting-ip-config.c b/libnm-core/nm-setting-ip-config.c
index 779d4428..c7f8c555 100644
--- a/libnm-core/nm-setting-ip-config.c
+++ b/libnm-core/nm-setting-ip-config.c
@@ -526,6 +526,14 @@ nm_ip_address_set_prefix (NMIPAddress *address,
 	address->prefix = prefix;
 }
 
+const char **
+_nm_ip_address_get_attribute_names (const NMIPAddress *address, gboolean sorted, guint *out_length)
+{
+	nm_assert (address);
+
+	return nm_utils_strdict_get_keys (address->attributes, sorted, out_length);
+}
+
 /**
  * nm_ip_address_get_attribute_names:
  * @address: the #NMIPAddress
@@ -537,22 +545,12 @@ nm_ip_address_set_prefix (NMIPAddress *address,
 char **
 nm_ip_address_get_attribute_names (NMIPAddress *address)
 {
-	GHashTableIter iter;
-	const char *key;
-	GPtrArray *names;
-
-	g_return_val_if_fail (address != NULL, NULL);
+	const char **names;
 
-	names = g_ptr_array_new ();
+	g_return_val_if_fail (address, NULL);
 
-	if (address->attributes) {
-		g_hash_table_iter_init (&iter, address->attributes);
-		while (g_hash_table_iter_next (&iter, (gpointer *) &key, NULL))
-			g_ptr_array_add (names, g_strdup (key));
-	}
-	g_ptr_array_add (names, NULL);
-
-	return (char **) g_ptr_array_free (names, FALSE);
+	names = _nm_ip_address_get_attribute_names (address, TRUE, NULL);
+	return nm_utils_strv_make_deep_copied_nonnull (names);
 }
 
 /**
@@ -593,7 +591,7 @@ nm_ip_address_set_attribute (NMIPAddress *address, const char *name, GVariant *v
 	g_return_if_fail (strcmp (name, "address") != 0 && strcmp (name, "prefix") != 0);
 
 	if (!address->attributes) {
-		address->attributes = g_hash_table_new_full (g_str_hash, g_str_equal,
+		address->attributes = g_hash_table_new_full (nm_str_hash, g_str_equal,
 		                                             g_free, (GDestroyNotify) g_variant_unref);
 	}
 
@@ -1131,33 +1129,14 @@ _nm_ip_route_get_attributes_direct (NMIPRoute *route)
  *
  * Returns: (array length=out_length) (transfer container): a %NULL-terminated array
  *   of attribute names or %NULL if there are no attributes. The order of the returned
- *   names is undefined.
+ *   names depends on @sorted.
  **/
 const char **
 _nm_ip_route_get_attribute_names (const NMIPRoute *route, gboolean sorted, guint *out_length)
 {
-	const char **names;
-	guint length;
-
-	g_return_val_if_fail (route != NULL, NULL);
-
-	if (   !route->attributes
-	    || !g_hash_table_size (route->attributes)) {
-		NM_SET_OUT (out_length, 0);
-		return NULL;
-	}
+	nm_assert (route);
 
-	names = (const char **) g_hash_table_get_keys_as_array (route->attributes, &length);
-	if (   sorted
-	    && length > 1) {
-		g_qsort_with_data (names,
-		                   length,
-		                   sizeof (char *),
-		                   nm_strcmp_p_with_data,
-		                   NULL);
-	}
-	NM_SET_OUT (out_length, length);
-	return names;
+	return nm_utils_strdict_get_keys (route->attributes, sorted, out_length);
 }
 
 /**
@@ -1171,21 +1150,12 @@ _nm_ip_route_get_attribute_names (const NMIPRoute *route, gboolean sorted, guint
 char **
 nm_ip_route_get_attribute_names (NMIPRoute *route)
 {
-	char **names;
-	guint i, len;
+	const char **names;
 
 	g_return_val_if_fail (route != NULL, NULL);
 
-	names = (char **) _nm_ip_route_get_attribute_names (route, TRUE, &len);
-	if (!names)
-		return g_new0 (char *, 1);
-
-	nm_assert (len > 0 && names && names[len] == NULL);
-	for (i = 0; i < len; i++) {
-		nm_assert (names[i]);
-		names[i] = g_strdup (names[i]);
-	}
-	return names;
+	names = _nm_ip_route_get_attribute_names (route, TRUE, NULL);
+	return nm_utils_strv_make_deep_copied_nonnull (names);
 }
 
 /**
@@ -1227,7 +1197,7 @@ nm_ip_route_set_attribute (NMIPRoute *route, const char *name, GVariant *value)
 	                  && strcmp (name, "next-hop") != 0 && strcmp (name, "metric") != 0);
 
 	if (!route->attributes) {
-		route->attributes = g_hash_table_new_full (g_str_hash, g_str_equal,
+		route->attributes = g_hash_table_new_full (nm_str_hash, g_str_equal,
 		                                           g_free, (GDestroyNotify) g_variant_unref);
 	}
 
@@ -2553,7 +2523,7 @@ verify (NMSetting *setting, NMConnection *connection, GError **error)
 			return FALSE;
 		}
 
-		label = nm_ip_address_get_attribute (addr, "label");
+		label = nm_ip_address_get_attribute (addr, NM_IP_ADDRESS_ATTRIBUTE_LABEL);
 		if (label) {
 			if (!g_variant_is_of_type (label, G_VARIANT_TYPE_STRING)) {
 				g_set_error (error,
@@ -2960,7 +2930,10 @@ nm_setting_ip_config_class_init (NMSettingIPConfigClass *setting_class)
 	/**
 	 * NMSettingIPConfig:dns-search:
 	 *
-	 * Array of DNS search domains.
+	 * Array of DNS search domains. Domains starting with a tilde ('~')
+	 * are considered 'routing' domains and are used only to decide the
+	 * interface over which a query must be forwarded; they are not used
+	 * to complete unqualified host names.
 	 **/
 	g_object_class_install_property
 		(object_class, PROP_DNS_SEARCH,
@@ -2990,24 +2963,34 @@ nm_setting_ip_config_class_init (NMSettingIPConfigClass *setting_class)
 	/**
 	 * NMSettingIPConfig:dns-priority:
 	 *
-	 * Intra-connection DNS priority.
+	 * DNS servers priority.
+	 *
+	 * The relative priority for DNS servers specified by this setting.  A lower
+	 * value is better (higher priority).  Zero selects the default value, which
+	 * is 50 for VPNs and 100 for other connections.
+	 *
+	 * Note that the priority is to order DNS settings for multiple active
+	 * connections.  It does not disambiguate multiple DNS servers within the
+	 * same connection profile.
 	 *
-	 * The relative priority to be used when determining the order of DNS
-	 * servers in resolv.conf.  A lower value means that servers will be on top
-	 * of the file.  Zero selects the default value, which is 50 for VPNs and
-	 * 100 for other connections.  Note that the priority is to order DNS
-	 * settings for multiple active connections. It does not disambiguate
-	 * multiple DNS servers within the same connection profile. For that,
-	 * just specify the DNS servers in the desired order.
-	 * When multiple devices have configurations with the same priority, the
-	 * one with an active default route will be preferred.
-	 * Note that when using dns=dnsmasq the order is meaningless
-	 * since dnsmasq forwards queries to all known servers at the same time.
+	 * When using dns=default, servers with higher priority will be on top of
+	 * resolv.conf.  To prioritize a given server over another one within the
+	 * same connection, just specify them in the desired order.  When multiple
+	 * devices have configurations with the same priority, the one with an
+	 * active default route will be preferred.  Negative values have the special
+	 * effect of excluding other configurations with a greater priority value;
+	 * so in presence of at least a negative priority, only DNS servers from
+	 * connections with the lowest priority value will be used.
 	 *
-	 * Negative values have the special effect of excluding other configurations
-	 * with a greater priority value; so in presence of at least a negative
-	 * priority, only DNS servers from connections with the lowest priority
-	 * value will be used.
+	 * When using a DNS resolver that supports split-DNS as dns=dnsmasq or
+	 * dns=systemd-resolved, each connection is used to query domains in its
+	 * search list.  Queries for domains not present in any search list are
+	 * routed through connections having the '~.' special wildcard domain, which
+	 * is added automatically to connections with the default route (or can be
+	 * added manually).  When multiple connections specify the same domain, the
+	 * one with the highest priority (lowest numerical value) wins.  If a
+	 * connection specifies a domain which is subdomain of another domain with a
+	 * negative DNS priority value, the subdomain is ignored.
 	 *
 	 * Since: 1.4
 	 **/
@@ -3020,11 +3003,9 @@ nm_setting_ip_config_class_init (NMSettingIPConfigClass *setting_class)
 	                       G_PARAM_STATIC_STRINGS));
 
 	/**
-	 * NMSettingIPConfig:addresses:
+	 * NMSettingIPConfig:addresses: (type GPtrArray(NMIPAddress))
 	 *
 	 * Array of IP addresses.
-	 *
-	 * Element-Type: NMIPAddress
 	 **/
 	g_object_class_install_property
 		(object_class, PROP_ADDRESSES,
@@ -3061,11 +3042,9 @@ nm_setting_ip_config_class_init (NMSettingIPConfigClass *setting_class)
 	                                     NULL);
 
 	/**
-	 * NMSettingIPConfig:routes:
+	 * NMSettingIPConfig:routes: (type GPtrArray(NMIPRoute))
 	 *
 	 * Array of IP routes.
-	 *
-	 * Element-Type: NMIPRoute
 	 **/
 	g_object_class_install_property
 		(object_class, PROP_ROUTES,
@@ -3232,9 +3211,11 @@ nm_setting_ip_config_class_init (NMSettingIPConfigClass *setting_class)
 	 * addresses on the network.  If an address conflict is detected, the
 	 * activation will fail.  A zero value means that no duplicate address
 	 * detection is performed, -1 means the default value (either configuration
-	 * ipvx.dad-timeout override or 3 seconds).  A value greater than zero is a
+	 * ipvx.dad-timeout override or zero).  A value greater than zero is a
 	 * timeout in milliseconds.
 	 *
+	 * The property is currently implemented only for IPv4.
+	 *
 	 * Since: 1.2
 	 **/
 	g_object_class_install_property