ifcfg-rh: add support for DHCP hostname flags

This commit is contained in:
Beniamino Galvani
2019-07-09 14:23:58 +02:00
parent 1bde86396b
commit 292d3f2b57
6 changed files with 80 additions and 13 deletions

View File

@@ -775,6 +775,13 @@ nm_setting_ip4_config_class_init (NMSettingIP4ConfigClass *klass)
* ---end--- * ---end---
*/ */
/* ---ifcfg-rh---
* property: dhcp-hostname-flags
* variable: DHCP_HOSTNAME_FLAGS
* description: flags for the DHCP hostname and FQDN properties
* example: DHCP_HOSTNAME_FLAGS=5
*/
/** /**
* NMSettingIP4Config:dhcp-fqdn: * NMSettingIP4Config:dhcp-fqdn:
* *

View File

@@ -657,6 +657,13 @@ nm_setting_ip6_config_class_init (NMSettingIP6ConfigClass *klass)
* ---end--- * ---end---
*/ */
/* ---ifcfg-rh---
* property: dhcp-hostname-flags
* variable: DHCPV6_HOSTNAME_FLAGS
* description: flags for the DHCP hostname property
* example: DHCPV6_HOSTNAME_FLAGS=5
*/
/* ---ifcfg-rh--- /* ---ifcfg-rh---
* property: never-default * property: never-default
* variable: IPV6_DEFROUTE(+), (and IPV6_DEFAULTGW, IPV6_DEFAULTDEV in /etc/sysconfig/network) * variable: IPV6_DEFROUTE(+), (and IPV6_DEFAULTGW, IPV6_DEFAULTDEV in /etc/sysconfig/network)

View File

@@ -1579,7 +1579,7 @@ make_ip4_setting (shvarFile *ifcfg,
gboolean has_key; gboolean has_key;
shvarFile *route_ifcfg; shvarFile *route_ifcfg;
gboolean never_default; gboolean never_default;
gint64 timeout; gint64 i64;
int priority; int priority;
const char *const *item; const char *const *item;
guint32 route_table; guint32 route_table;
@@ -1682,6 +1682,14 @@ make_ip4_setting (shvarFile *ifcfg,
NULL); NULL);
} }
i64 = svGetValueInt64 (ifcfg, "DHCP_HOSTNAME_FLAGS", 10, 0, G_MAXUINT32, -1);
if (i64 > -1) {
g_object_set (s_ip4,
NM_SETTING_IP_CONFIG_DHCP_HOSTNAME_FLAGS,
(guint) i64,
NULL);
}
g_object_set (s_ip4, g_object_set (s_ip4,
NM_SETTING_IP_CONFIG_DHCP_SEND_HOSTNAME, svGetValueBoolean (ifcfg, "DHCP_SEND_HOSTNAME", TRUE), NM_SETTING_IP_CONFIG_DHCP_SEND_HOSTNAME, svGetValueBoolean (ifcfg, "DHCP_SEND_HOSTNAME", TRUE),
NM_SETTING_IP_CONFIG_DHCP_TIMEOUT, svGetValueInt64 (ifcfg, "IPV4_DHCP_TIMEOUT", 10, 0, G_MAXINT32, 0), NM_SETTING_IP_CONFIG_DHCP_TIMEOUT, svGetValueInt64 (ifcfg, "IPV4_DHCP_TIMEOUT", 10, 0, G_MAXINT32, 0),
@@ -1852,14 +1860,14 @@ make_ip4_setting (shvarFile *ifcfg,
} }
} }
timeout = svGetValueInt64 (ifcfg, "ACD_TIMEOUT", 10, -1, NM_SETTING_IP_CONFIG_DAD_TIMEOUT_MAX, -2); i64 = svGetValueInt64 (ifcfg, "ACD_TIMEOUT", 10, -1, NM_SETTING_IP_CONFIG_DAD_TIMEOUT_MAX, -2);
if (timeout == -2) { if (i64 == -2) {
timeout = svGetValueInt64 (ifcfg, "ARPING_WAIT", 10, -1, i64 = svGetValueInt64 (ifcfg, "ARPING_WAIT", 10, -1,
NM_SETTING_IP_CONFIG_DAD_TIMEOUT_MAX / 1000, -1); NM_SETTING_IP_CONFIG_DAD_TIMEOUT_MAX / 1000, -1);
if (timeout > 0) if (i64 > 0)
timeout *= 1000; i64 *= 1000;
} }
g_object_set (s_ip4, NM_SETTING_IP_CONFIG_DAD_TIMEOUT, (int) timeout, NULL); g_object_set (s_ip4, NM_SETTING_IP_CONFIG_DAD_TIMEOUT, (int) i64, NULL);
return NM_SETTING (g_steal_pointer (&s_ip4)); return NM_SETTING (g_steal_pointer (&s_ip4));
} }
@@ -1993,6 +2001,7 @@ make_ip6_setting (shvarFile *ifcfg,
gs_free const char **list = NULL; gs_free const char **list = NULL;
const char *const *iter; const char *const *iter;
guint32 i; guint32 i;
gint64 i64;
int i_val; int i_val;
GError *local = NULL; GError *local = NULL;
int priority; int priority;
@@ -2153,6 +2162,15 @@ make_ip6_setting (shvarFile *ifcfg,
g_object_set (s_ip6, NM_SETTING_IP_CONFIG_DHCP_SEND_HOSTNAME, g_object_set (s_ip6, NM_SETTING_IP_CONFIG_DHCP_SEND_HOSTNAME,
svGetValueBoolean (ifcfg, "DHCPV6_SEND_HOSTNAME", TRUE), NULL); svGetValueBoolean (ifcfg, "DHCPV6_SEND_HOSTNAME", TRUE), NULL);
i64 = svGetValueInt64 (ifcfg, "DHCPV6_HOSTNAME_FLAGS", 10, 0, G_MAXUINT32, -1);
if (i64 > -1) {
g_object_set (s_ip6,
NM_SETTING_IP_CONFIG_DHCP_HOSTNAME_FLAGS,
(guint) i64,
NULL);
}
/* Read static IP addresses. /* Read static IP addresses.
* Read them even for AUTO and DHCP methods - in this case the addresses are * 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 * added to the automatic ones. Note that this is not currently supported by

View File

@@ -2438,6 +2438,7 @@ write_ip4_setting (NMConnection *connection,
GString *searches; GString *searches;
const char *method = NULL; const char *method = NULL;
gboolean has_netmask; gboolean has_netmask;
NMDhcpHostnameFlags flags;
NM_SET_OUT (out_route_content_svformat, NULL); NM_SET_OUT (out_route_content_svformat, NULL);
NM_SET_OUT (out_route_content, NULL); NM_SET_OUT (out_route_content, NULL);
@@ -2598,6 +2599,12 @@ write_ip4_setting (NMConnection *connection,
value = nm_setting_ip4_config_get_dhcp_fqdn (NM_SETTING_IP4_CONFIG (s_ip4)); value = nm_setting_ip4_config_get_dhcp_fqdn (NM_SETTING_IP4_CONFIG (s_ip4));
svSetValueStr (ifcfg, "DHCP_FQDN", value); svSetValueStr (ifcfg, "DHCP_FQDN", value);
flags = nm_setting_ip_config_get_dhcp_hostname_flags (s_ip4);
svSetValueInt64_cond (ifcfg,
"DHCP_HOSTNAME_FLAGS",
flags != NM_DHCP_HOSTNAME_FLAG_NONE,
flags);
/* Missing DHCP_SEND_HOSTNAME means TRUE, and we prefer not write it explicitly /* Missing DHCP_SEND_HOSTNAME means TRUE, and we prefer not write it explicitly
* in that case, because it is NM-specific variable * in that case, because it is NM-specific variable
*/ */
@@ -2744,6 +2751,7 @@ write_ip4_aliases (NMConnection *connection, const char *base_ifcfg_path)
static void static void
write_ip6_setting_dhcp_hostname (NMSettingIPConfig *s_ip6, shvarFile *ifcfg) write_ip6_setting_dhcp_hostname (NMSettingIPConfig *s_ip6, shvarFile *ifcfg)
{ {
NMDhcpHostnameFlags flags;
const char *hostname; const char *hostname;
hostname = nm_setting_ip_config_get_dhcp_hostname (s_ip6); hostname = nm_setting_ip_config_get_dhcp_hostname (s_ip6);
@@ -2756,6 +2764,12 @@ write_ip6_setting_dhcp_hostname (NMSettingIPConfig *s_ip6, shvarFile *ifcfg)
svUnsetValue (ifcfg, "DHCPV6_SEND_HOSTNAME"); svUnsetValue (ifcfg, "DHCPV6_SEND_HOSTNAME");
else else
svSetValueStr (ifcfg, "DHCPV6_SEND_HOSTNAME", "no"); svSetValueStr (ifcfg, "DHCPV6_SEND_HOSTNAME", "no");
flags = nm_setting_ip_config_get_dhcp_hostname_flags (s_ip6);
svSetValueInt64_cond (ifcfg,
"DHCPV6_HOSTNAME_FLAGS",
flags != NM_DHCP_HOSTNAME_FLAG_NONE,
flags);
} }
static gboolean static gboolean

View File

@@ -8,7 +8,12 @@ USERCTL=yes
IPV6INIT=no IPV6INIT=no
NM_CONTROLLED=yes NM_CONTROLLED=yes
PEERDNS=no PEERDNS=no
DHCP_HOSTNAME=foobar DHCP_FQDN=foo.bar
DHCP_HOSTNAME_FLAGS=6
DNS1=4.2.2.1 DNS1=4.2.2.1
DNS2=4.2.2.2 DNS2=4.2.2.2
IPV6_AUTOCONF=no
IPV6INIT=yes
DHCPV6C=yes
DHCPV6_HOSTNAME_FLAGS=8
DHCPV6_HOSTNAME=foo.bar

View File

@@ -887,6 +887,7 @@ test_read_wired_dhcp (void)
NMSettingConnection *s_con; NMSettingConnection *s_con;
NMSettingWired *s_wired; NMSettingWired *s_wired;
NMSettingIPConfig *s_ip4; NMSettingIPConfig *s_ip4;
NMSettingIPConfig *s_ip6;
char *unmanaged = NULL; char *unmanaged = NULL;
char expected_mac_address[ETH_ALEN] = { 0x00, 0x11, 0x22, 0x33, 0x44, 0xee }; char expected_mac_address[ETH_ALEN] = { 0x00, 0x11, 0x22, 0x33, 0x44, 0xee };
const char *mac; const char *mac;
@@ -916,11 +917,23 @@ test_read_wired_dhcp (void)
s_ip4 = nm_connection_get_setting_ip4_config (connection); s_ip4 = nm_connection_get_setting_ip4_config (connection);
g_assert (s_ip4); g_assert (s_ip4);
g_assert_cmpstr (nm_setting_ip_config_get_method (s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_AUTO); g_assert_cmpstr (nm_setting_ip_config_get_method (s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_AUTO);
g_assert_cmpstr (nm_setting_ip_config_get_dhcp_hostname (s_ip4), ==, "foobar"); g_assert_cmpstr (nm_setting_ip4_config_get_dhcp_fqdn (NM_SETTING_IP4_CONFIG (s_ip4)), ==, "foo.bar");
g_assert (nm_setting_ip_config_get_ignore_auto_dns (s_ip4)); g_assert (nm_setting_ip_config_get_ignore_auto_dns (s_ip4));
g_assert_cmpuint (nm_setting_ip_config_get_num_dns (s_ip4), ==, 2); g_assert_cmpuint (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"); g_assert_cmpstr (nm_setting_ip_config_get_dns (s_ip4, 0), ==, "4.2.2.1");
g_assert_cmpstr (nm_setting_ip_config_get_dns (s_ip4, 1), ==, "4.2.2.2"); g_assert_cmpstr (nm_setting_ip_config_get_dns (s_ip4, 1), ==, "4.2.2.2");
g_assert_cmpuint (nm_setting_ip_config_get_dhcp_hostname_flags (s_ip4),
==,
NM_DHCP_HOSTNAME_FLAG_FQDN_ENCODED | NM_DHCP_HOSTNAME_FLAG_FQDN_NO_UPDATE);
/* ===== IPv6 SETTING ===== */
s_ip6 = nm_connection_get_setting_ip6_config (connection);
g_assert (s_ip6);
g_assert_cmpstr (nm_setting_ip_config_get_method (s_ip6), ==, NM_SETTING_IP6_CONFIG_METHOD_DHCP);
g_assert_cmpstr (nm_setting_ip_config_get_dhcp_hostname (s_ip6), ==, "foo.bar");
g_assert_cmpuint (nm_setting_ip_config_get_dhcp_hostname_flags (s_ip6),
==,
NM_DHCP_HOSTNAME_FLAG_FQDN_CLEAR_FLAGS);
g_object_unref (connection); g_object_unref (connection);
} }
@@ -4457,7 +4470,8 @@ test_write_wired_dhcp (void)
g_object_set (s_ip4, g_object_set (s_ip4,
NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO,
NM_SETTING_IP4_CONFIG_DHCP_CLIENT_ID, "random-client-id-00:22:33", NM_SETTING_IP4_CONFIG_DHCP_CLIENT_ID, "random-client-id-00:22:33",
NM_SETTING_IP_CONFIG_DHCP_HOSTNAME, "awesome-hostname", NM_SETTING_IP4_CONFIG_DHCP_FQDN, "awesome.hostname",
NM_SETTING_IP_CONFIG_DHCP_HOSTNAME_FLAGS, (guint) NM_DHCP_HOSTNAME_FLAG_FQDN_ENCODED,
NM_SETTING_IP_CONFIG_IGNORE_AUTO_ROUTES, TRUE, NM_SETTING_IP_CONFIG_IGNORE_AUTO_ROUTES, TRUE,
NM_SETTING_IP_CONFIG_IGNORE_AUTO_DNS, TRUE, NM_SETTING_IP_CONFIG_IGNORE_AUTO_DNS, TRUE,
NM_SETTING_IP_CONFIG_DHCP_IAID, "2864434397", NM_SETTING_IP_CONFIG_DHCP_IAID, "2864434397",
@@ -4470,8 +4484,10 @@ test_write_wired_dhcp (void)
nm_connection_add_setting (connection, NM_SETTING (s_ip6)); nm_connection_add_setting (connection, NM_SETTING (s_ip6));
g_object_set (s_ip6, g_object_set (s_ip6,
NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_DHCP,
NM_SETTING_IP_CONFIG_MAY_FAIL, TRUE, NM_SETTING_IP_CONFIG_MAY_FAIL, TRUE,
NM_SETTING_IP_CONFIG_DHCP_HOSTNAME, "awesome.hostname",
NM_SETTING_IP_CONFIG_DHCP_HOSTNAME_FLAGS, (guint) NM_DHCP_HOSTNAME_FLAG_FQDN_NO_UPDATE,
NULL); NULL);
_writer_new_connection (connection, _writer_new_connection (connection,