]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/network/networkd-dhcp6.c
Add SPDX license identifiers to source files under the LGPL
[thirdparty/systemd.git] / src / network / networkd-dhcp6.c
index 15acf56a5f167fba6bd58773982427155f99dc82..e5df3d22b169db279fd84e9a7c1316b278a3db0c 100644 (file)
@@ -1,3 +1,4 @@
+/* SPDX-License-Identifier: LGPL-2.1+ */
 /***
   This file is part of systemd.
 
 
 #include "sd-dhcp6-client.h"
 
+#include "hostname-util.h"
 #include "network-internal.h"
-#include "networkd.h"
+#include "networkd-link.h"
+#include "networkd-manager.h"
 
 static int dhcp6_lease_address_acquired(sd_dhcp6_client *client, Link *link);
 
@@ -125,7 +128,6 @@ static void dhcp6_handler(sd_dhcp6_client *client, int event, void *userdata) {
 
         assert(link);
         assert(link->network);
-        assert(link->manager);
 
         if (IN_SET(link->state, LINK_STATE_FAILED, LINK_STATE_LINGER))
                 return;
@@ -211,6 +213,28 @@ int dhcp6_request_address(Link *link, int ir) {
         return 0;
 }
 
+static int dhcp6_set_hostname(sd_dhcp6_client *client, Link *link) {
+        _cleanup_free_ char *hostname = NULL;
+        const char *hn;
+        int r;
+
+        assert(link);
+
+        if (!link->network->dhcp_send_hostname)
+                hn = NULL;
+        else if (link->network->dhcp_hostname)
+                hn = link->network->dhcp_hostname;
+        else {
+                r = gethostname_strict(&hostname);
+                if (r < 0 && r != -ENXIO) /* ENXIO: no hostname set or hostname is "localhost" */
+                        return r;
+
+                hn = hostname;
+        }
+
+        return sd_dhcp6_client_set_fqdn(client, hn);
+}
+
 int dhcp6_configure(Link *link) {
         sd_dhcp6_client *client = NULL;
         int r;
@@ -247,6 +271,11 @@ int dhcp6_configure(Link *link) {
         if (r < 0)
                 goto error;
 
+        r = dhcp6_set_hostname(client, link);
+        log_link_warning(link, "dhcp6_set_hostname: %d", r);
+        if (r < 0)
+                return r;
+
         r = sd_dhcp6_client_set_ifindex(client, link->ifindex);
         if (r < 0)
                 goto error;