ifcfg-rh: support RES_OPTIONS

This commit is contained in:
Beniamino Galvani 2015-03-26 14:56:00 +01:00
parent e7ff906f91
commit bb9c7e2c18
2 changed files with 103 additions and 0 deletions

View file

@ -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;

View file

@ -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);