1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2024-12-22 13:33:56 +03:00

networkd: add UseFQDN option for DHCPv6

Similar to DHCPv4's UseHostname option, add a UseFQDN config option in
[DHCPv6] to set the system's transient hostname if the FQDN option is
set in the DHCPv6 response from the server.
This commit is contained in:
Vinnie Magro 2021-01-28 16:24:34 -08:00 committed by Yu Watanabe
parent 39755e0014
commit f963f8953d
6 changed files with 31 additions and 0 deletions

View File

@ -1926,6 +1926,13 @@ IPv6Token=prefixstable:2002:da8:1::</programlisting></para>
</listitem>
</varlistentry>
<varlistentry>
<term><varname>UseFQDN=</varname></term>
<listitem>
<para>Equivalent of <varname>UseHostname=</varname> in the [DHCPv4] section.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><varname>RouteMetric=</varname></term>
<listitem>

View File

@ -11,6 +11,7 @@
#include "escape.h"
#include "hashmap.h"
#include "hostname-setup.h"
#include "hostname-util.h"
#include "missing_network.h"
#include "networkd-address.h"
@ -1073,6 +1074,25 @@ static int dhcp6_address_acquired(Link *link) {
return r;
}
if (link->network->dhcp6_use_fqdn) {
const char *dhcpname = NULL;
_cleanup_free_ char *hostname = NULL;
(void) sd_dhcp6_lease_get_fqdn(link->dhcp6_lease, &dhcpname);
if (dhcpname) {
r = shorten_overlong(dhcpname, &hostname);
if (r < 0)
log_link_warning_errno(link, r, "Unable to shorten overlong DHCP hostname '%s', ignoring: %m", dhcpname);
if (r == 1)
log_link_notice(link, "Overlong DHCP hostname received, shortened from '%s' to '%s'", dhcpname, hostname);
}
if (hostname) {
r = manager_set_hostname(link->manager, hostname);
if (r < 0)
log_link_error_errno(link, r, "Failed to set transient hostname to '%s': %m", hostname);
}
}
return 0;
}

View File

@ -223,6 +223,7 @@ DHCPv4.RouteMTUBytes, config_parse_mtu,
DHCPv4.FallbackLeaseLifetimeSec, config_parse_dhcp_fallback_lease_lifetime, 0, 0
DHCPv6.UseAddress, config_parse_bool, 0, offsetof(Network, dhcp6_use_address)
DHCPv6.UseDNS, config_parse_dhcp_use_dns, 0, 0
DHCPv6.UseFQDN, config_parse_bool, 0, offsetof(Network, dhcp6_use_fqdn)
DHCPv6.UseNTP, config_parse_dhcp_use_ntp, 0, 0
DHCPv6.RapidCommit, config_parse_bool, 0, offsetof(Network, dhcp6_rapid_commit)
DHCPv6.MUDURL, config_parse_dhcp6_mud_url, 0, 0

View File

@ -374,6 +374,7 @@ int network_load_one(Manager *manager, OrderedHashmap **networks, const char *fi
.dhcp6_use_address = true,
.dhcp6_use_dns = true,
.dhcp6_use_fqdn = true,
.dhcp6_use_ntp = true,
.dhcp6_rapid_commit = true,
.dhcp6_route_metric = DHCP_ROUTE_METRIC,

View File

@ -159,6 +159,7 @@ struct Network {
bool dhcp6_use_address;
bool dhcp6_use_dns;
bool dhcp6_use_dns_set;
bool dhcp6_use_fqdn;
bool dhcp6_use_ntp;
bool dhcp6_use_ntp_set;
bool dhcp6_rapid_commit;

View File

@ -127,6 +127,7 @@ FallbackLeaseLifetimeSec=
UseAddress=
UseNTP=
UseDNS=
UseFQDN=
RapidCommit=
ForceDHCPv6PDOtherInformation=
PrefixDelegationHint=