summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBeniamino Galvani <bgalvani@redhat.com>2015-03-26 14:56:00 +0100
committerBeniamino Galvani <bgalvani@redhat.com>2015-05-13 17:15:34 +0200
commitbb9c7e2c188f351ef78e506fdd8c45df0a9315c5 (patch)
treed0731623d80ea5854f4f20b7961e9fc64ea3e8d3
parente7ff906f910e948f3a0b0ddd08f7c645c9a09cc4 (diff)
downloadNetworkManager-bb9c7e2c188f351ef78e506fdd8c45df0a9315c5.tar.gz
ifcfg-rh: support RES_OPTIONS
-rw-r--r--src/settings/plugins/ifcfg-rh/reader.c44
-rw-r--r--src/settings/plugins/ifcfg-rh/writer.c59
2 files changed, 103 insertions, 0 deletions
diff --git a/src/settings/plugins/ifcfg-rh/reader.c b/src/settings/plugins/ifcfg-rh/reader.c
index 1081ab8f81..ed49f40e66 100644
--- a/src/settings/plugins/ifcfg-rh/reader.c
+++ b/src/settings/plugins/ifcfg-rh/reader.c
@@ -667,6 +667,29 @@ error:
return success;
}
+static void
+parse_dns_options (NMSettingIPConfig *ip_config, char *value)
+{
+ char **options = NULL;
+
+ g_return_if_fail (ip_config);
+
+ if (!value)
+ return;
+
+ options = g_strsplit (value, " ", 0);
+ if (options) {
+ char **item;
+ for (item = options; *item; item++) {
+ if (strlen (*item)) {
+ if (!nm_setting_ip_config_add_dns_option (ip_config, *item))
+ PARSE_WARNING ("can't add DNS option '%s'", *item);
+ }
+ }
+ g_strfreev (options);
+ }
+}
+
static gboolean
parse_full_ip6_address (shvarFile *ifcfg,
const char *network_file,
@@ -880,6 +903,7 @@ make_ip4_setting (shvarFile *ifcfg,
char *value = NULL;
char *route_path = NULL;
char *method;
+ char *dns_options = NULL;
gs_free char *gateway = NULL;
gint32 i;
shvarFile *network_ifcfg;
@@ -903,6 +927,7 @@ make_ip4_setting (shvarFile *ifcfg,
/* Get the connection ifcfg device name and the global gateway device */
value = svGetValue (ifcfg, "DEVICE", FALSE);
gatewaydev = svGetValue (network_ifcfg, "GATEWAYDEV", FALSE);
+ dns_options = svGetValue (network_ifcfg, "RES_OPTIONS", FALSE);
/* If there was a global gateway device specified, then only connections
* for that device can be the default connection.
@@ -1079,6 +1104,14 @@ make_ip4_setting (shvarFile *ifcfg,
g_free (value);
}
+ /* DNS options */
+ value = svGetValue (ifcfg, "RES_OPTIONS", FALSE);
+ parse_dns_options (s_ip4, value);
+ parse_dns_options (s_ip4, dns_options);
+ g_free (value);
+ g_free (dns_options);
+ dns_options = NULL;
+
/* Static routes - route-<name> file */
route_path = utils_get_route_path (ifcfg->fileName);
@@ -1135,6 +1168,7 @@ make_ip4_setting (shvarFile *ifcfg,
return NM_SETTING (s_ip4);
done:
+ g_free (dns_options);
g_free (route_path);
g_object_unref (s_ip4);
return NULL;
@@ -1251,6 +1285,7 @@ make_ip6_setting (shvarFile *ifcfg,
char *value = NULL;
char *str_value;
char *route6_path = NULL;
+ char *dns_options = NULL;
gboolean ipv6init, ipv6forwarding, ipv6_autoconf, dhcp6 = FALSE;
char *method = NM_SETTING_IP6_CONFIG_METHOD_MANUAL;
char *ipv6addr, *ipv6addr_secondaries;
@@ -1284,6 +1319,7 @@ make_ip6_setting (shvarFile *ifcfg,
value = svGetValue (ifcfg, "DEVICE", FALSE);
ipv6_defaultgw = svGetValue (network_ifcfg, "IPV6_DEFAULTGW", FALSE);
ipv6_defaultdev = svGetValue (network_ifcfg, "IPV6_DEFAULTDEV", FALSE);
+ dns_options = svGetValue (network_ifcfg, "RES_OPTIONS", FALSE);
if (ipv6_defaultgw) {
default_dev = strchr (ipv6_defaultgw, '%');
@@ -1480,9 +1516,17 @@ make_ip6_setting (shvarFile *ifcfg,
g_free (route6_path);
}
+ /* DNS options */
+ value = svGetValue (ifcfg, "RES_OPTIONS", FALSE);
+ parse_dns_options (s_ip6, value);
+ parse_dns_options (s_ip6, dns_options);
+ g_free (value);
+ g_free (dns_options);
+
return NM_SETTING (s_ip6);
error:
+ g_free (dns_options);
g_free (route6_path);
g_object_unref (s_ip6);
return NULL;
diff --git a/src/settings/plugins/ifcfg-rh/writer.c b/src/settings/plugins/ifcfg-rh/writer.c
index 75547641b1..0a54eaf643 100644
--- a/src/settings/plugins/ifcfg-rh/writer.c
+++ b/src/settings/plugins/ifcfg-rh/writer.c
@@ -42,6 +42,7 @@
#include <nm-setting-team-port.h>
#include "nm-core-internal.h"
#include <nm-utils.h>
+#include <nm-utils-private.h>
#include "nm-logging.h"
#include "gsystem-local-alloc.h"
@@ -2464,6 +2465,61 @@ error:
return FALSE;
}
+static void
+add_dns_option (GPtrArray *array, const char *option)
+{
+ if (_nm_utils_dns_option_find_idx (array, option) < 0)
+ g_ptr_array_add (array, (gpointer) option);
+}
+
+static gboolean
+write_res_options (NMConnection *connection, shvarFile *ifcfg, GError **error)
+{
+ NMSettingIPConfig *s_ip6;
+ NMSettingIPConfig *s_ip4;
+ const char *method;
+ int i, num_options;
+ GPtrArray *array;
+ GString *value;
+
+ s_ip4 = nm_connection_get_setting_ip4_config (connection);
+ s_ip6 = nm_connection_get_setting_ip6_config (connection);
+ array = g_ptr_array_new ();
+
+ if (s_ip4) {
+ method = nm_setting_ip_config_get_method (s_ip4);
+ if (g_strcmp0 (method, NM_SETTING_IP4_CONFIG_METHOD_DISABLED)) {
+ num_options = nm_setting_ip_config_get_num_dns_options (s_ip4);
+ for (i = 0; i < num_options; i++)
+ add_dns_option (array, nm_setting_ip_config_get_dns_option (s_ip4, i));
+ }
+ }
+
+ if (s_ip6) {
+ method = nm_setting_ip_config_get_method (s_ip6);
+ if (g_strcmp0 (method, NM_SETTING_IP6_CONFIG_METHOD_IGNORE)) {
+ num_options = nm_setting_ip_config_get_num_dns_options (s_ip6);
+ for (i = 0; i < num_options; i++)
+ add_dns_option (array, nm_setting_ip_config_get_dns_option (s_ip6, i));
+ }
+ }
+
+ if (array->len > 0) {
+ value = g_string_new (NULL);
+ for (i = 0; i < array->len; i++) {
+ if (i > 0)
+ g_string_append_c (value, ' ');
+ g_string_append (value, array->pdata[i]);
+ }
+ svSetValue (ifcfg, "RES_OPTIONS", value->str, FALSE);
+ g_string_free (value, TRUE);
+ } else
+ svSetValue (ifcfg, "RES_OPTIONS", NULL, FALSE);
+
+ g_ptr_array_unref (array);
+ return TRUE;
+}
+
static char *
escape_id (const char *id)
{
@@ -2611,6 +2667,9 @@ write_connection (NMConnection *connection,
if (!write_ip6_setting (connection, ifcfg, error))
goto out;
+
+ if (!write_res_options (connection, ifcfg, error))
+ goto out;
}
write_connection_setting (s_con, ifcfg);