1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2025-01-07 17:17:44 +03:00

network/dhcp6: set hostname even if UseAddress=no

Follow-up for f963f8953d and
1536b7b2d0.

(cherry picked from commit 8fead9c9e46e5f71ae6f6b038ff7f72c5a13b663)
(cherry picked from commit 30cf66855b6e31e7de2bff6d79d5c2d9fc17d684)
(cherry picked from commit f4189fdd1d)
(cherry picked from commit 51ed671255)
This commit is contained in:
Yu Watanabe 2024-09-16 04:45:13 +09:00 committed by Luca Boccassi
parent 51ac5cfc05
commit 831c6a1fe0

View File

@ -275,25 +275,35 @@ static int dhcp6_address_acquired(Link *link) {
return r;
}
if (link->network->dhcp6_use_hostname) {
const char *dhcpname = NULL;
_cleanup_free_ char *hostname = NULL;
return 0;
}
(void) sd_dhcp6_lease_get_fqdn(link->dhcp6_lease, &dhcpname);
static int dhcp6_request_hostname(Link *link) {
_cleanup_free_ char *hostname = NULL;
const char *dhcpname = NULL;
int r;
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);
}
}
assert(link);
assert(link->network);
if (!link->network->dhcp6_use_hostname)
return 0;
r = sd_dhcp6_lease_get_fqdn(link->dhcp6_lease, &dhcpname);
if (r == -ENODATA)
return 0;
if (r < 0)
return r;
r = shorten_overlong(dhcpname, &hostname);
if (r < 0)
return log_link_warning_errno(link, r, "Unable to shorten overlong DHCP hostname '%s': %m", dhcpname);
if (r == 1)
log_link_notice(link, "Overlong DHCP hostname received, shortened from '%s' to '%s'", dhcpname, hostname);
r = manager_set_hostname(link->manager, hostname);
if (r < 0)
log_link_warning_errno(link, r, "Failed to set transient hostname to '%s', ignoring: %m", hostname);
return 0;
}
@ -313,6 +323,10 @@ static int dhcp6_lease_ip_acquired(sd_dhcp6_client *client, Link *link) {
lease_old = TAKE_PTR(link->dhcp6_lease);
link->dhcp6_lease = sd_dhcp6_lease_ref(lease);
r = dhcp6_request_hostname(link);
if (r < 0)
return r;
r = dhcp6_address_acquired(link);
if (r < 0)
return r;