summaryrefslogtreecommitdiffstats
path: root/src/network
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2024-09-15 21:45:13 +0200
committerYu Watanabe <watanabe.yu+github@gmail.com>2024-10-15 11:23:59 +0200
commit8fead9c9e46e5f71ae6f6b038ff7f72c5a13b663 (patch)
tree407092a803b49f96033865385939b9fd40e661cb /src/network
parentsd-dhcp6-lease: use free_and_replace_full() (diff)
downloadsystemd-8fead9c9e46e5f71ae6f6b038ff7f72c5a13b663.tar.xz
systemd-8fead9c9e46e5f71ae6f6b038ff7f72c5a13b663.zip
network/dhcp6: set hostname even if UseAddress=no
Follow-up for f963f8953daeab03b892616ce0c65f7572932187 and 1536b7b2d00819615bf8eba194de7ccd20c3689f.
Diffstat (limited to 'src/network')
-rw-r--r--src/network/networkd-dhcp6.c52
1 files changed, 33 insertions, 19 deletions
diff --git a/src/network/networkd-dhcp6.c b/src/network/networkd-dhcp6.c
index 3f773cbb99..39471d6628 100644
--- a/src/network/networkd-dhcp6.c
+++ b/src/network/networkd-dhcp6.c
@@ -264,25 +264,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;
-
- (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;
+}
+
+static int dhcp6_request_hostname(Link *link) {
+ _cleanup_free_ char *hostname = NULL;
+ const char *dhcpname = NULL;
+ int r;
+
+ 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;
}
@@ -302,6 +312,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;