summary refs log tree commit diff
path: root/libnm-core/nm-keyfile-writer.c
diff options
context:
space:
mode:
Diffstat (limited to 'libnm-core/nm-keyfile-writer.c')
-rw-r--r--libnm-core/nm-keyfile-writer.c23
1 files changed, 10 insertions, 13 deletions
diff --git a/libnm-core/nm-keyfile-writer.c b/libnm-core/nm-keyfile-writer.c
index 6a3d9a9f..30d519c4 100644
--- a/libnm-core/nm-keyfile-writer.c
+++ b/libnm-core/nm-keyfile-writer.c
@@ -47,7 +47,7 @@ typedef struct {
  * NMSettingConnection's 'type' property (which specifies the base type of the
  * connection, eg ethernet or wifi) or the 802-11-wireless setting's
  * 'security' property which specifies whether or not the AP requires
- * encrpytion.  This function handles translating those properties' values
+ * encryption.  This function handles translating those properties' values
  * from the real setting name to the more-readable alias.
  */
 static void
@@ -137,7 +137,7 @@ write_ip_values (GKeyFile *file,
 	GString *output;
 	int family, i;
 	const char *addr, *gw;
-	guint32 plen, metric;
+	guint32 plen;
 	char key_name[64], *key_name_idx;
 
 	if (!array->len)
@@ -150,25 +150,27 @@ write_ip_values (GKeyFile *file,
 
 	output = g_string_sized_new (2*INET_ADDRSTRLEN + 10);
 	for (i = 0; i < array->len; i++) {
+		gint64 metric = -1;
+
 		if (is_route) {
 			NMIPRoute *route = array->pdata[i];
 
 			addr = nm_ip_route_get_dest (route);
 			plen = nm_ip_route_get_prefix (route);
 			gw = nm_ip_route_get_next_hop (route);
-			metric = MAX (0, nm_ip_route_get_metric (route));
+			metric = nm_ip_route_get_metric (route);
 		} else {
 			NMIPAddress *address = array->pdata[i];
 
 			addr = nm_ip_address_get_address (address);
 			plen = nm_ip_address_get_prefix (address);
 			gw = i == 0 ? gateway : NULL;
-			metric = 0;
 		}
 
 		g_string_set_size (output, 0);
 		g_string_append_printf (output, "%s/%u", addr, plen);
-		if (metric || gw) {
+		if (   metric != -1
+		    || gw) {
 			/* Older versions of the plugin do not support the form
 			 * "a.b.c.d/plen,,metric", so, we always have to write the
 			 * gateway, even if there isn't one.
@@ -182,7 +184,7 @@ write_ip_values (GKeyFile *file,
 			}
 
 			g_string_append_printf (output, ",%s", gw);
-			if (metric)
+			if (is_route && metric != -1)
 				g_string_append_printf (output, ",%lu", (unsigned long) metric);
 		}
 
@@ -191,14 +193,9 @@ write_ip_values (GKeyFile *file,
 
 		if (is_route) {
 			gs_free char *attributes = NULL;
-			gs_strfreev char **names = NULL;
-			gs_unref_hashtable GHashTable *hash = g_hash_table_new (g_str_hash, g_str_equal);
-			int j;
-
-			names = nm_ip_route_get_attribute_names (array->pdata[i]);
-			for (j = 0; names && names[j]; j++)
-				g_hash_table_insert (hash, names[j], nm_ip_route_get_attribute (array->pdata[i], names[j]));
+			GHashTable *hash;
 
+			hash = _nm_ip_route_get_attributes_direct (array->pdata[i]);
 			attributes = nm_utils_format_variant_attributes (hash, ',', '=');
 			if (attributes) {
 				g_strlcat (key_name, "_options", sizeof (key_name));