Commit a9b50793 authored by Beniamino Galvani's avatar Beniamino Galvani
Browse files

ifcfg-rh: use separate variables for DNS searches

DNS searches from the ipv4 and ipv6 settings were joined and written
to the same ifcfg-rh "DOMAIN" variable and so the connection read back
from disk was different from the one written.

Instead, introduce a separate variable for ipv6 searches; to preserve
backwards compatibility, still read the "DOMAIN" variable for ipv6
when ipv4 is disabled so that we don't lose DNS searches on upgrade.

https://bugzilla.redhat.com/show_bug.cgi?id=1517794
parent 993a726c
......@@ -550,7 +550,7 @@ nm_setting_ip6_config_class_init (NMSettingIP6ConfigClass *ip6_class)
/* ---ifcfg-rh---
* property: dns-search
* variable: DOMAIN
* variable: IPV6_DOMAIN
* format: string (space-separated domains)
* description: List of DNS search domains.
* ---end---
......
......@@ -1670,6 +1670,7 @@ make_ip6_setting (shvarFile *ifcfg,
GError **error)
{
NMSettingIPConfig *s_ip6 = NULL;
const char *v;
char *value = NULL;
char *str_value;
char *route6_path = NULL;
......@@ -1918,8 +1919,6 @@ make_ip6_setting (shvarFile *ifcfg,
g_free (value);
}
/* DNS searches ('DOMAIN' key) are read by make_ip4_setting() and included in NMSettingIPConfig */
if (!routes_read) {
/* NOP */
} else {
......@@ -1930,7 +1929,23 @@ make_ip6_setting (shvarFile *ifcfg,
g_free (route6_path);
}
/* DNS searches */
nm_clear_g_free (&value);
v = svGetValueStr (ifcfg, "IPV6_DOMAIN", &value);
if (v) {
gs_free const char **searches = NULL;
searches = nm_utils_strsplit_set (v, " ");
if (searches) {
for (iter = searches; *iter; iter++) {
if (!nm_setting_ip_config_add_dns_search (s_ip6, *iter))
PARSE_WARNING ("duplicate DNS domain '%s'", *iter);
}
}
}
/* DNS options */
nm_clear_g_free (&value);
parse_dns_options (s_ip6, svGetValue (ifcfg, "IPV6_RES_OPTIONS", &value));
g_free (value);
......@@ -5484,9 +5499,9 @@ connection_from_file_full (const char *filename,
nm_connection_add_setting (connection, s_ip4);
}
/* There is only one DOMAIN variable and it is read and put to IPv4 config
* But if IPv4 is disabled or the config fails for some reason, we read
* DOMAIN and put the values into IPv6 config instead.
/* For backwards compatibility, if IPv4 is disabled or the
* config fails for some reason, we read DOMAIN and put the
* values into IPv6 config instead of IPv4.
*/
check_dns_search_domains (parsed, s_ip4, s_ip6);
......
......@@ -2593,21 +2593,20 @@ write_ip6_setting (NMConnection *connection,
}
}
/* Write out DNS domains - 'DOMAIN' key is shared for both IPv4 and IPv6 domains */
/* Write out DNS domains */
num = nm_setting_ip_config_get_num_dns_searches (s_ip6);
if (num > 0) {
gs_free char *ip4_domains = NULL;
nm_auto_free_gstring GString *searches = NULL;
searches = g_string_new (svGetValueStr (ifcfg, "DOMAIN", &ip4_domains));
searches = g_string_new (NULL);
for (i = 0; i < num; i++) {
if (searches->len > 0)
g_string_append_c (searches, ' ');
g_string_append (searches, nm_setting_ip_config_get_dns_search (s_ip6, i));
}
svSetValueStr (ifcfg, "DOMAIN", searches->str);
}
svSetValueStr (ifcfg, "IPV6_DOMAIN", searches->str);
} else
svUnsetValue (ifcfg, "IPV6_DOMAIN");
/* handle IPV6_DEFROUTE */
/* IPV6_DEFROUTE has the opposite meaning from 'never-default' */
......
......@@ -7,7 +7,7 @@ USERCTL=yes
NM_CONTROLLED=yes
PEERDNS=yes
DNS1=1:2:3:4::a
DOMAIN="lorem.com ipsum.org dolor.edu"
IPV6_DOMAIN="lorem.com ipsum.org dolor.edu"
IPV6INIT=yes
IPV6_AUTOCONF=no
IPV6ADDR="1001:abba::1234/56"
......
......@@ -4187,23 +4187,15 @@ test_write_wired_static (void)
nmtst_assert_connection_verifies (connection);
_writer_new_connection_FIXME (connection,
TEST_SCRATCH_DIR "/network-scripts/",
&testfile);
_writer_new_connection (connection,
TEST_SCRATCH_DIR "/network-scripts/",
&testfile);
route6file = utils_get_route6_path (testfile);
reread = _connection_from_file (testfile, NULL, TYPE_ETHERNET, NULL);
/* FIXME: currently DNS domains from IPv6 setting are stored in 'DOMAIN' key in ifcfg-file
* However after re-reading they are dropped into IPv4 setting.
* So, in order to comparison succeeded, move DNS domains back to IPv6 setting.
*/
reread_s_ip4 = nm_connection_get_setting_ip4_config (reread);
reread_s_ip6 = nm_connection_get_setting_ip6_config (reread);
nm_setting_ip_config_add_dns_search (reread_s_ip6, nm_setting_ip_config_get_dns_search (reread_s_ip4, 2));
nm_setting_ip_config_add_dns_search (reread_s_ip6, nm_setting_ip_config_get_dns_search (reread_s_ip4, 3));
nm_setting_ip_config_remove_dns_search (reread_s_ip4, 3);
nm_setting_ip_config_remove_dns_search (reread_s_ip4, 2);
g_assert_cmpint (nm_setting_ip_config_get_route_metric (reread_s_ip4), ==, 204);
g_assert_cmpint (nm_setting_ip_config_get_route_metric (reread_s_ip6), ==, 206);
......@@ -4341,17 +4333,8 @@ test_write_wired_static_with_generic (void)
route6file = utils_get_route6_path (testfile);
reread = _connection_from_file (testfile, NULL, TYPE_ETHERNET, NULL);
/* FIXME: currently DNS domains from IPv6 setting are stored in 'DOMAIN' key in ifcfg-file
* However after re-reading they are dropped into IPv4 setting.
* So, in order to comparison succeeded, move DNS domains back to IPv6 setting.
*/
reread_s_ip4 = nm_connection_get_setting_ip4_config (reread);
reread_s_ip6 = nm_connection_get_setting_ip6_config (reread);
nm_setting_ip_config_add_dns_search (reread_s_ip6, nm_setting_ip_config_get_dns_search (reread_s_ip4, 2));
nm_setting_ip_config_add_dns_search (reread_s_ip6, nm_setting_ip_config_get_dns_search (reread_s_ip4, 3));
nm_setting_ip_config_remove_dns_search (reread_s_ip4, 3);
nm_setting_ip_config_remove_dns_search (reread_s_ip4, 2);
g_assert_cmpint (nm_setting_ip_config_get_route_metric (reread_s_ip4), ==, 204);
g_assert_cmpint (nm_setting_ip_config_get_route_metric (reread_s_ip6), ==, 206);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment