From 1621a6ddb1b3f5c51ad774012150bd56cf65fcea Mon Sep 17 00:00:00 2001 From: Beniamino Galvani Date: Wed, 22 Jul 2020 13:56:39 +0200 Subject: [PATCH 1/2] dhcp: export the DHCPv6 FQDN option The dhclient backend already exports all the option passed by dhclient, including the FDQN. Export it also for the systemd backend. --- src/dhcp/nm-dhcp-options.c | 1 + src/dhcp/nm-dhcp-options.h | 2 ++ src/dhcp/nm-dhcp-systemd.c | 8 ++++++++ 3 files changed, 11 insertions(+) diff --git a/src/dhcp/nm-dhcp-options.c b/src/dhcp/nm-dhcp-options.c index b10635fc6..d902c77c8 100644 --- a/src/dhcp/nm-dhcp-options.c +++ b/src/dhcp/nm-dhcp-options.c @@ -183,6 +183,7 @@ const NMDhcpOption _nm_dhcp_option_dhcp6_options[] = { REQ (NM_DHCP_OPTION_DHCP6_DNS_SERVERS, "dhcp6_name_servers", TRUE ), REQ (NM_DHCP_OPTION_DHCP6_DOMAIN_LIST, "dhcp6_domain_search", TRUE ), REQ (NM_DHCP_OPTION_DHCP6_SNTP_SERVERS, "dhcp6_sntp_servers", TRUE ), + REQ (NM_DHCP_OPTION_DHCP6_FQDN, "fqdn_fqdn", FALSE ), REQ (NM_DHCP_OPTION_DHCP6_MUD_URL, "dhcp6_mud_url", FALSE ), /* Internal values */ diff --git a/src/dhcp/nm-dhcp-options.h b/src/dhcp/nm-dhcp-options.h index 7c0121702..bc3df5acd 100644 --- a/src/dhcp/nm-dhcp-options.h +++ b/src/dhcp/nm-dhcp-options.h @@ -160,7 +160,9 @@ typedef enum { NM_DHCP_OPTION_DHCP6_DNS_SERVERS = 23, NM_DHCP_OPTION_DHCP6_DOMAIN_LIST = 24, NM_DHCP_OPTION_DHCP6_SNTP_SERVERS = 31, + NM_DHCP_OPTION_DHCP6_FQDN = 39, NM_DHCP_OPTION_DHCP6_MUD_URL = 112, + /* Internal values */ NM_DHCP_OPTION_DHCP6_NM_IP_ADDRESS = 1026, NM_DHCP_OPTION_DHCP6_NM_PREFIXLEN = 1027, diff --git a/src/dhcp/nm-dhcp-systemd.c b/src/dhcp/nm-dhcp-systemd.c index a30a5e588..792dc19a3 100644 --- a/src/dhcp/nm-dhcp-systemd.c +++ b/src/dhcp/nm-dhcp-systemd.c @@ -740,6 +740,7 @@ lease_to_ip6_config (NMDedupMultiIndex *multi_idx, uint32_t lft_pref, lft_valid; char addr_str[NM_UTILS_INET_ADDRSTRLEN]; char **domains; + const char *s; nm_auto_free_gstring GString *str = NULL; int num, i; @@ -808,6 +809,13 @@ lease_to_ip6_config (NMDedupMultiIndex *multi_idx, str->str); } + if (sd_dhcp6_lease_get_fqdn (lease, &s) >= 0) { + nm_dhcp_option_add_option (options, + _nm_dhcp_option_dhcp6_options, + NM_DHCP_OPTION_DHCP6_FQDN, + s); + } + NM_SET_OUT (out_options, g_steal_pointer (&options)); return g_steal_pointer (&ip6_config); } From 1f74ea52f5818c6e7d5cacd1dffdb2e1f5ee1913 Mon Sep 17 00:00:00 2001 From: Beniamino Galvani Date: Wed, 22 Jul 2020 13:49:42 +0200 Subject: [PATCH 2/2] policy: get the DHCPv6 hostname from the FQDN option There isn't any 'host-name' option for DHCPv6. Read instead the 'fqdn-fqdn' option that carries the FQDN assigned by the server to the client. --- src/nm-policy.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nm-policy.c b/src/nm-policy.c index d0ddeb9c3..1490d9061 100644 --- a/src/nm-policy.c +++ b/src/nm-policy.c @@ -764,7 +764,7 @@ update_system_hostname (NMPolicy *self, const char *msg) /* Grab a hostname out of the device's DHCP6 config */ dhcp_config = nm_device_get_dhcp_config (get_default_device (self, AF_INET6), AF_INET6); if (dhcp_config) { - dhcp_hostname = nm_dhcp_config_get_option (dhcp_config, "host_name"); + dhcp_hostname = nm_dhcp_config_get_option (dhcp_config, "fqdn_fqdn"); if (dhcp_hostname && dhcp_hostname[0]) { p = nm_str_skip_leading_spaces (dhcp_hostname); if (p[0]) {