From 51b1fd976f25d1411daa655e1817d936c31eb062 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 20 May 2015 14:29:49 +0200 Subject: [PATCH] ifcfg-rh: distinguish in reader and writer between unset and empty dns-options --- src/settings/plugins/ifcfg-rh/reader.c | 11 +++++++---- .../tests/network-scripts/ifcfg-test-wired-static | 1 + .../network-scripts/ifcfg-test-wired-static-bootproto | 1 + src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c | 10 ++++++++++ src/settings/plugins/ifcfg-rh/writer.c | 6 ++++-- 5 files changed, 23 insertions(+), 6 deletions(-) diff --git a/src/settings/plugins/ifcfg-rh/reader.c b/src/settings/plugins/ifcfg-rh/reader.c index ccbcdb07ab..71bb2b942d 100644 --- a/src/settings/plugins/ifcfg-rh/reader.c +++ b/src/settings/plugins/ifcfg-rh/reader.c @@ -677,6 +677,9 @@ parse_dns_options (NMSettingIPConfig *ip_config, char *value) if (!value) return; + if (!nm_setting_ip_config_has_dns_options (ip_config)) + nm_setting_ip_config_clear_dns_options (ip_config, TRUE); + options = g_strsplit (value, " ", 0); if (options) { char **item; @@ -927,7 +930,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); + dns_options = svGetValueFull (network_ifcfg, "RES_OPTIONS", FALSE); /* If there was a global gateway device specified, then only connections * for that device can be the default connection. @@ -1105,7 +1108,7 @@ make_ip4_setting (shvarFile *ifcfg, } /* DNS options */ - value = svGetValue (ifcfg, "RES_OPTIONS", FALSE); + value = svGetValueFull (ifcfg, "RES_OPTIONS", FALSE); parse_dns_options (s_ip4, value); parse_dns_options (s_ip4, dns_options); g_free (value); @@ -1317,7 +1320,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); + dns_options = svGetValueFull (network_ifcfg, "RES_OPTIONS", FALSE); if (ipv6_defaultgw) { default_dev = strchr (ipv6_defaultgw, '%'); @@ -1515,7 +1518,7 @@ make_ip6_setting (shvarFile *ifcfg, } /* DNS options */ - value = svGetValue (ifcfg, "RES_OPTIONS", FALSE); + value = svGetValueFull (ifcfg, "RES_OPTIONS", FALSE); parse_dns_options (s_ip6, value); parse_dns_options (s_ip6, dns_options); g_free (value); diff --git a/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-static b/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-static index c8315f45d3..6d49c01c1f 100644 --- a/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-static +++ b/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-static @@ -18,3 +18,4 @@ IPV6ADDR=dead:beaf::1 IPV6ADDR_SECONDARIES="dead:beaf::2/56" DNS3=1:2:3:4::a DNS4=1:2:3:4::b +RES_OPTIONS= diff --git a/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-static-bootproto b/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-static-bootproto index ee821503e2..a01f655833 100644 --- a/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-static-bootproto +++ b/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-static-bootproto @@ -13,3 +13,4 @@ DNS2=4.2.2.2 IPADDR=192.168.1.5 NETMASK=255.255.255.0 GATEWAY=192.168.1.1 +RES_OPTIONS= diff --git a/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c b/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c index 77021d69a6..350ea534fc 100644 --- a/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c +++ b/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c @@ -484,6 +484,9 @@ test_read_wired_static (const char *file, g_assert_cmpstr (nm_setting_ip_config_get_method (s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_MANUAL); g_assert (nm_setting_ip_config_get_may_fail (s_ip4)); + g_assert (nm_setting_ip_config_has_dns_options (s_ip4)); + g_assert_cmpint (nm_setting_ip_config_get_num_dns_options (s_ip4), ==, 0); + /* DNS Addresses */ g_assert_cmpint (nm_setting_ip_config_get_num_dns (s_ip4), ==, 2); g_assert_cmpstr (nm_setting_ip_config_get_dns (s_ip4, 0), ==, "4.2.2.1"); @@ -506,6 +509,9 @@ test_read_wired_static (const char *file, g_assert_cmpstr (nm_setting_ip_config_get_method (s_ip6), ==, NM_SETTING_IP6_CONFIG_METHOD_MANUAL); g_assert (nm_setting_ip_config_get_may_fail (s_ip6)); + g_assert (nm_setting_ip_config_has_dns_options (s_ip6)); + g_assert_cmpint (nm_setting_ip_config_get_num_dns_options (s_ip6), ==, 0); + /* DNS Addresses */ g_assert_cmpint (nm_setting_ip_config_get_num_dns (s_ip6), ==, 2); g_assert_cmpstr (nm_setting_ip_config_get_dns (s_ip6, 0), ==, "1:2:3:4::a"); @@ -525,6 +531,7 @@ test_read_wired_static (const char *file, g_assert_cmpstr (nm_ip_address_get_address (ip6_addr), ==, "dead:beaf::2"); } else { g_assert_cmpstr (nm_setting_ip_config_get_method (s_ip6), ==, NM_SETTING_IP6_CONFIG_METHOD_IGNORE); + g_assert (!nm_setting_ip_config_has_dns_options (s_ip6)); } g_object_unref (connection); @@ -563,6 +570,9 @@ test_read_wired_static_no_prefix (gconstpointer user_data) g_assert (s_ip4); g_assert_cmpstr (nm_setting_ip_config_get_method (s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_MANUAL); + g_assert (!nm_setting_ip_config_has_dns_options (s_ip4)); + g_assert_cmpint (nm_setting_ip_config_get_num_dns_options (s_ip4), ==, 0); + g_assert_cmpint (nm_setting_ip_config_get_num_addresses (s_ip4), ==, 1); ip4_addr = nm_setting_ip_config_get_address (s_ip4, 0); g_assert (ip4_addr); diff --git a/src/settings/plugins/ifcfg-rh/writer.c b/src/settings/plugins/ifcfg-rh/writer.c index 9924eb0f06..e432d1b95e 100644 --- a/src/settings/plugins/ifcfg-rh/writer.c +++ b/src/settings/plugins/ifcfg-rh/writer.c @@ -2506,14 +2506,16 @@ write_res_options (NMConnection *connection, shvarFile *ifcfg, GError **error) } } - if (array->len > 0) { + if (array->len > 0 + || (s_ip4 && nm_setting_ip_config_has_dns_options (s_ip4)) + || (s_ip6 && nm_setting_ip_config_has_dns_options (s_ip6))) { 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); + svSetValueFull (ifcfg, "RES_OPTIONS", value->str, FALSE); g_string_free (value, TRUE); } else svSetValue (ifcfg, "RES_OPTIONS", NULL, FALSE);