diff --git a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c index a2557f6af7..2b4abffbe5 100644 --- a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c +++ b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c @@ -1506,11 +1506,23 @@ make_ip6_setting (shvarFile *ifcfg, if (strcmp (method, NM_SETTING_IP6_CONFIG_METHOD_IGNORE) == 0) return NM_SETTING (s_ip6); - value = svGetValueString (ifcfg, "DHCP_HOSTNAME"); - if (value && value[0]) + value = svGetValueString (ifcfg, "DHCPV6_HOSTNAME"); + /* Use DHCP_HOSTNAME as fallback if it is in FQDN format and ipv6.method is + * auto or dhcp: this is required to support old ifcfg files + */ + if (!value && ( !strcmp (method, NM_SETTING_IP6_CONFIG_METHOD_AUTO) + || !strcmp (method, NM_SETTING_IP6_CONFIG_METHOD_DHCP))) { + value = svGetValueString (ifcfg, "DHCP_HOSTNAME"); + if (value && !strchr (value, '.')) + g_clear_pointer (&value, g_free); + } + if (value) g_object_set (s_ip6, NM_SETTING_IP_CONFIG_DHCP_HOSTNAME, value, NULL); g_free (value); + g_object_set (s_ip6, NM_SETTING_IP_CONFIG_DHCP_SEND_HOSTNAME, + svGetValueBoolean (ifcfg, "DHCPV6_SEND_HOSTNAME", TRUE), NULL); + /* Read static IP addresses. * Read them even for AUTO and DHCP methods - in this case the addresses are * added to the automatic ones. Note that this is not currently supported by diff --git a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c index 6f335cb90d..fdeb8cf9a4 100644 --- a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c +++ b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c @@ -2442,6 +2442,23 @@ error: return success; } +static void +write_ip6_setting_dhcp_hostname (NMSettingIPConfig *s_ip6, shvarFile *ifcfg) +{ + const char *hostname; + + hostname = nm_setting_ip_config_get_dhcp_hostname (s_ip6); + svSetValueString (ifcfg, "DHCPV6_HOSTNAME", hostname); + + /* Missing DHCPV6_SEND_HOSTNAME means TRUE, and we prefer not write it + * explicitly in that case, because it is NM-specific variable + */ + if (nm_setting_ip_config_get_dhcp_send_hostname (s_ip6)) + svUnsetValue (ifcfg, "DHCPV6_SEND_HOSTNAME"); + else + svSetValueString (ifcfg, "DHCPV6_SEND_HOSTNAME", "no"); +} + static gboolean write_ip6_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) { @@ -2469,6 +2486,8 @@ write_ip6_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) svUnsetValue (ifcfg, "IPV6INIT"); svUnsetValue (ifcfg, "IPV6_AUTOCONF"); svUnsetValue (ifcfg, "DHCPV6C"); + svUnsetValue (ifcfg, "DHCPV6_HOSTNAME"); + svUnsetValue (ifcfg, "DHCPV6_SEND_HOSTNAME"); svUnsetValue (ifcfg, "IPV6_DEFROUTE"); svUnsetValue (ifcfg, "IPV6_PEERDNS"); svUnsetValue (ifcfg, "IPV6_PEERROUTES"); @@ -2506,9 +2525,7 @@ write_ip6_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) svUnsetValue (ifcfg, "DHCPV6C"); } - hostname = nm_setting_ip_config_get_dhcp_hostname (s_ip6); - if (hostname) - svSetValueString (ifcfg, "DHCP_HOSTNAME", hostname); + write_ip6_setting_dhcp_hostname (s_ip6, ifcfg); /* Write out IP addresses */ num = nm_setting_ip_config_get_num_addresses (s_ip6); @@ -2566,6 +2583,7 @@ write_ip6_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) g_free (ip4_domains); } + /* handle IPV6_DEFROUTE */ /* IPV6_DEFROUTE has the opposite meaning from 'never-default' */ if (nm_setting_ip_config_get_never_default(s_ip6)) 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 a35a830b86..9a9d48d3e9 100644 --- a/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c +++ b/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c @@ -3891,7 +3891,7 @@ test_read_write_wired_dhcp_send_hostname (void) g_assert (s_ip6); g_assert (nm_setting_ip_config_get_dhcp_send_hostname (s_ip4) == TRUE); g_assert_cmpstr (nm_setting_ip_config_get_dhcp_hostname (s_ip4), ==, "svata-pulec"); - g_assert_cmpstr (nm_setting_ip_config_get_dhcp_hostname (s_ip6), ==, "svata-pulec"); + g_assert_null (nm_setting_ip_config_get_dhcp_hostname (s_ip6)); /* Set dhcp-send-hostname=false dhcp-hostname="kamil-patka" and write the connection. */ g_object_set (s_ip4, NM_SETTING_IP_CONFIG_DHCP_SEND_HOSTNAME, FALSE, NULL);