summaryrefslogtreecommitdiff
path: root/libnm-core
diff options
context:
space:
mode:
authorBeniamino Galvani <bgalvani@redhat.com>2017-02-16 00:14:25 +0100
committerBeniamino Galvani <bgalvani@redhat.com>2017-03-06 15:20:25 +0100
commitcdfa6251021b097f4dfa1e723c546dd83fd9c44d (patch)
tree762b62ca7376515936d23f4d6ee96fb7e72cc83d /libnm-core
parentdad1071374640a71a4a87026064e5c30cabbd948 (diff)
downloadNetworkManager-cdfa6251021b097f4dfa1e723c546dd83fd9c44d.tar.gz
keyfile: support route options
Diffstat (limited to 'libnm-core')
-rw-r--r--libnm-core/nm-keyfile-reader.c31
-rw-r--r--libnm-core/nm-keyfile-writer.c19
2 files changed, 49 insertions, 1 deletions
diff --git a/libnm-core/nm-keyfile-reader.c b/libnm-core/nm-keyfile-reader.c
index c071264d32..b955dbf617 100644
--- a/libnm-core/nm-keyfile-reader.c
+++ b/libnm-core/nm-keyfile-reader.c
@@ -429,6 +429,31 @@ read_one_ip_address_or_route (KeyfileReaderInfo *info,
}
static void
+fill_route_attributes (GKeyFile *kf, NMIPRoute *route, const char *setting, const char *key, int family)
+{
+ gs_free char *value = NULL;
+ gs_unref_hashtable GHashTable *hash = NULL;
+ GHashTableIter iter;
+ char *name;
+ GVariant *variant;
+
+ value = nm_keyfile_plugin_kf_get_string (kf, setting, key, NULL);
+ if (!value || !value[0])
+ return;
+
+ hash = nm_utils_parse_variant_attributes (value, ',', '=', TRUE,
+ nm_ip_route_get_variant_attribute_spec (),
+ NULL);
+ if (hash) {
+ g_hash_table_iter_init (&iter, hash);
+ while (g_hash_table_iter_next (&iter, (gpointer *) &name, (gpointer *) &variant)) {
+ if (nm_ip_route_attribute_validate (name, variant, family, NULL, NULL))
+ nm_ip_route_set_attribute (route, name, g_variant_ref (variant));
+ }
+ }
+}
+
+static void
ip_address_or_route_parser (KeyfileReaderInfo *info, NMSetting *setting, const char *key)
{
const char *setting_name = nm_setting_get_name (setting);
@@ -454,6 +479,7 @@ ip_address_or_route_parser (KeyfileReaderInfo *info, NMSetting *setting, const c
for (key_basename = key_names; *key_basename; key_basename++) {
char *key_name;
gpointer item;
+ char options_key[128];
/* -1 means no suffix */
if (i >= 0)
@@ -463,6 +489,11 @@ ip_address_or_route_parser (KeyfileReaderInfo *info, NMSetting *setting, const c
item = read_one_ip_address_or_route (info, key, setting_name, key_name, ipv6, routes,
gateway ? NULL : &gateway, setting);
+ if (item && routes) {
+ nm_sprintf_buf (options_key, "%s_options", key_name);
+ fill_route_attributes (info->keyfile, item, setting_name, options_key, ipv6 ? AF_INET6 : AF_INET);
+ }
+
g_free (key_name);
if (info->error) {
diff --git a/libnm-core/nm-keyfile-writer.c b/libnm-core/nm-keyfile-writer.c
index 21aeca2fa8..13a29ccdcc 100644
--- a/libnm-core/nm-keyfile-writer.c
+++ b/libnm-core/nm-keyfile-writer.c
@@ -138,7 +138,7 @@ write_ip_values (GKeyFile *file,
int family, i;
const char *addr, *gw;
guint32 plen, metric;
- char key_name[30], *key_name_idx;
+ char key_name[64], *key_name_idx;
if (!array->len)
return;
@@ -188,6 +188,23 @@ write_ip_values (GKeyFile *file,
sprintf (key_name_idx, "%d", i + 1);
nm_keyfile_plugin_kf_set_string (file, setting_name, key_name, output->str);
+
+ 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]));
+
+ attributes = nm_utils_format_variant_attributes (hash, ',', '=');
+ if (attributes) {
+ g_strlcat (key_name, "_options", sizeof (key_name));
+ nm_keyfile_plugin_kf_set_string (file, setting_name, key_name, attributes);
+ }
+ }
}
g_string_free (output, TRUE);
}