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
This commit is contained in:
Jiří Klimeš 2013-12-05 14:27:08 +01:00
parent 98bcbd2d24
commit 97af7e6ee5
5 changed files with 97 additions and 3 deletions

View file

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

View file

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

View file

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

View file

@ -6561,6 +6561,75 @@ test_write_wired_dhcp_plus_ip (void)
g_object_unref (reread);
}
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)
{
@ -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 ();

View file

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