summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJiří Klimeš <jklimes@redhat.com>2013-12-05 14:27:08 +0100
committerJiří Klimeš <jklimes@redhat.com>2013-12-12 08:42:33 +0100
commit97af7e6ee58d8b419bc93f5d9b789b342c61a727 (patch)
treec82d513252b5304097bf8ca4a8715c382bcb8eb4
parent98bcbd2d2417e965f673220e8ec087a8d3b22ad5 (diff)
downloadNetworkManager-97af7e6ee58d8b419bc93f5d9b789b342c61a727.tar.gz
ifcfg-rh: read/write dhcp-send-hostname as DHCP_SEND_HOSTNAME (rh #1001529)
It is an extension compared to initscripts (not in sysconfig.txt). But it is necessary for preserving dhcp-send-hostname. Missing DHCP_SEND_HOSTNAME is treated as "yes", which matches dhcp-send-hostname default value being TRUE. https://bugzilla.redhat.com/show_bug.cgi?id=1001529
-rw-r--r--src/settings/plugins/ifcfg-rh/reader.c8
-rw-r--r--src/settings/plugins/ifcfg-rh/tests/network-scripts/Makefile.am1
-rw-r--r--src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-dhcp-send-hostname12
-rw-r--r--src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c70
-rw-r--r--src/settings/plugins/ifcfg-rh/writer.c9
5 files changed, 97 insertions, 3 deletions
diff --git a/src/settings/plugins/ifcfg-rh/reader.c b/src/settings/plugins/ifcfg-rh/reader.c
index e2cff0b2cf..2c808cf1f5 100644
--- a/src/settings/plugins/ifcfg-rh/reader.c
+++ b/src/settings/plugins/ifcfg-rh/reader.c
@@ -15,7 +15,7 @@
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
- * Copyright (C) 2008 - 2012 Red Hat, Inc.
+ * Copyright (C) 2008 - 2013 Red Hat, Inc.
*/
#include <config.h>
@@ -1365,7 +1365,11 @@ make_ip4_setting (shvarFile *ifcfg,
if (!strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_AUTO)) {
value = svGetValue (ifcfg, "DHCP_HOSTNAME", FALSE);
if (value && strlen (value))
- g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_DHCP_HOSTNAME, value, NULL);
+ g_object_set (s_ip4,
+ NM_SETTING_IP4_CONFIG_DHCP_HOSTNAME, value,
+ NM_SETTING_IP4_CONFIG_DHCP_SEND_HOSTNAME,
+ svTrueValue (ifcfg, "DHCP_SEND_HOSTNAME", TRUE),
+ NULL);
g_free (value);
value = svGetValue (ifcfg, "DHCP_CLIENT_ID", FALSE);
diff --git a/src/settings/plugins/ifcfg-rh/tests/network-scripts/Makefile.am b/src/settings/plugins/ifcfg-rh/tests/network-scripts/Makefile.am
index a7d009eeb6..113c5cab30 100644
--- a/src/settings/plugins/ifcfg-rh/tests/network-scripts/Makefile.am
+++ b/src/settings/plugins/ifcfg-rh/tests/network-scripts/Makefile.am
@@ -8,6 +8,7 @@ EXTRA_DIST = \
ifcfg-test-wired-static-bootproto \
ifcfg-test-wired-dhcp \
ifcfg-test-wired-dhcp-plus-ip \
+ ifcfg-test-wired-dhcp-send-hostname \
ifcfg-test-wired-dhcp6-only \
ifcfg-test-wired-global-gateway \
network-test-wired-global-gateway \
diff --git a/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-dhcp-send-hostname b/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-dhcp-send-hostname
new file mode 100644
index 0000000000..cba380db3c
--- /dev/null
+++ b/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-dhcp-send-hostname
@@ -0,0 +1,12 @@
+# Intel Corporation 82540EP Gigabit Ethernet Controller (Mobile)
+TYPE=Ethernet
+DEVICE=eth0
+HWADDR=00:11:22:33:44:ee
+BOOTPROTO=dhcp
+ONBOOT=yes
+IPV6INIT=yes
+IPV6_AUTOCONF=yes
+USERCTL=yes
+NM_CONTROLLED=yes
+PEERDNS=no
+DHCP_HOSTNAME="svata-pulec"
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 14c4fb9f72..771cf173f8 100644
--- a/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c
+++ b/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c
@@ -6562,6 +6562,75 @@ test_write_wired_dhcp_plus_ip (void)
}
static void
+test_read_write_wired_dhcp_send_hostname (void)
+{
+ NMConnection *connection, *reread;
+ NMSettingIP4Config *s_ip4;
+ NMSettingIP6Config *s_ip6;
+ const char * dhcp_hostname = "kamil-patka";
+ char *written = NULL;
+ GError *error = NULL;
+ gboolean success = FALSE;
+
+ connection = connection_from_file (TEST_IFCFG_DIR"/network-scripts/ifcfg-test-wired-dhcp-send-hostname",
+ NULL, TYPE_ETHERNET, NULL, NULL,
+ NULL, NULL, NULL, &error, NULL);
+ g_assert_no_error (error);
+ g_assert (connection != NULL);
+
+ /* Check dhcp-hostname and dhcp-send-hostname */
+ s_ip4 = nm_connection_get_setting_ip4_config (connection);
+ s_ip6 = nm_connection_get_setting_ip6_config (connection);
+ g_assert (s_ip4);
+ g_assert (s_ip6);
+ g_assert (nm_setting_ip4_config_get_dhcp_send_hostname (s_ip4) == TRUE);
+ g_assert_cmpstr (nm_setting_ip4_config_get_dhcp_hostname (s_ip4), ==, "svata-pulec");
+ g_assert_cmpstr (nm_setting_ip6_config_get_dhcp_hostname (s_ip6), ==, "svata-pulec");
+
+ /* Set dhcp-send-hostname=false dhcp-hostname="kamil-patka" and write the connection. */
+ g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_DHCP_SEND_HOSTNAME, FALSE, NULL);
+ g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_DHCP_HOSTNAME, dhcp_hostname, NULL);
+ g_object_set (s_ip6, NM_SETTING_IP4_CONFIG_DHCP_HOSTNAME, dhcp_hostname, NULL);
+
+ success = writer_new_connection (connection,
+ TEST_SCRATCH_DIR "/network-scripts/",
+ &written,
+ &error);
+ g_assert (success);
+
+ /* reread will be normalized, so we must normalize connection too. */
+ nm_utils_normalize_connection (connection, TRUE);
+
+ /* re-read the connection for comparison */
+ reread = connection_from_file (written, NULL, TYPE_ETHERNET, NULL, NULL,
+ NULL, NULL, NULL, &error, NULL);
+ unlink (written);
+ g_free (written);
+
+ g_assert_no_error (error);
+ g_assert (reread != NULL);
+
+ success = nm_connection_verify (reread, &error);
+ g_assert_no_error (error);
+ g_assert (success);
+
+ success = nm_connection_compare (connection, reread, NM_SETTING_COMPARE_FLAG_EXACT);
+ g_assert (success);
+
+ /* Check dhcp-hostname and dhcp-send-hostname from the re-read connection. */
+ s_ip4 = nm_connection_get_setting_ip4_config (reread);
+ s_ip6 = nm_connection_get_setting_ip6_config (reread);
+ g_assert (s_ip4);
+ g_assert (s_ip6);
+ g_assert (nm_setting_ip4_config_get_dhcp_send_hostname (s_ip4) == FALSE);
+ g_assert_cmpstr (nm_setting_ip4_config_get_dhcp_hostname (s_ip4), ==, dhcp_hostname);
+ g_assert_cmpstr (nm_setting_ip6_config_get_dhcp_hostname (s_ip6), ==, dhcp_hostname);
+
+ g_object_unref (connection);
+ g_object_unref (reread);
+}
+
+static void
test_write_wired_static_ip6_only (void)
{
NMConnection *connection;
@@ -13215,6 +13284,7 @@ int main (int argc, char **argv)
test_read_wired_static (TEST_IFCFG_WIRED_STATIC_BOOTPROTO, "System test-wired-static-bootproto", FALSE);
test_read_wired_dhcp ();
g_test_add_func (TPATH "dhcp-plus-ip", test_read_wired_dhcp_plus_ip);
+ g_test_add_func (TPATH "dhcp-send-hostname", test_read_write_wired_dhcp_send_hostname);
test_read_wired_global_gateway ();
test_read_wired_never_default ();
test_read_wired_defroute_no ();
diff --git a/src/settings/plugins/ifcfg-rh/writer.c b/src/settings/plugins/ifcfg-rh/writer.c
index 6f302b4f7c..604d492a1d 100644
--- a/src/settings/plugins/ifcfg-rh/writer.c
+++ b/src/settings/plugins/ifcfg-rh/writer.c
@@ -15,7 +15,7 @@
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
- * Copyright (C) 2009 - 2012 Red Hat, Inc.
+ * Copyright (C) 2009 - 2013 Red Hat, Inc.
*/
#include <string.h>
@@ -1971,6 +1971,13 @@ write_ip4_setting (NMConnection *connection, shvarFile *ifcfg, GError **error)
if (value)
svSetValue (ifcfg, "DHCP_HOSTNAME", value, FALSE);
+ /* Missing DHCP_SEND_HOSTNAME means TRUE, and we prefer not write it explicitly
+ * in that case, because it is NM-specific variable
+ */
+ svSetValue (ifcfg, "DHCP_SEND_HOSTNAME",
+ nm_setting_ip4_config_get_dhcp_send_hostname (s_ip4) ? NULL : "no",
+ FALSE);
+
value = nm_setting_ip4_config_get_dhcp_client_id (s_ip4);
if (value)
svSetValue (ifcfg, "DHCP_CLIENT_ID", value, FALSE);