]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network: DHCP: ignore error in setting hostname when it is given by uname()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 2 Aug 2018 07:31:10 +0000 (16:31 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 6 Aug 2018 01:48:02 +0000 (10:48 +0900)
C.f. #9759.

src/network/networkd-dhcp4.c
src/network/networkd-dhcp6.c

index 5616046f4f62c350ae8bfa567981906291aab2d6..08656334e0b41b4d3bd73630e988ab95f7f88b0b 100644 (file)
@@ -599,7 +599,14 @@ static int dhcp4_set_hostname(Link *link) {
                 hn = hostname;
         }
 
-        return sd_dhcp_client_set_hostname(link->dhcp_client, hn);
+        r = sd_dhcp_client_set_hostname(link->dhcp_client, hn);
+        if (r == -EINVAL && hostname)
+                /* Ignore error when the machine's hostname is not suitable to send in DHCP packet. */
+                log_link_warning_errno(link, r, "DHCP4 CLIENT: Failed to set hostname from kernel hostname, ignoring: %m");
+        else if (r < 0)
+                return log_link_error_errno(link, r, "DHCP4 CLIENT: Failed to set hostname: %m");
+
+        return 0;
 }
 
 static bool promote_secondaries_enabled(const char *ifname) {
@@ -737,7 +744,7 @@ int dhcp4_configure(Link *link) {
 
         r = dhcp4_set_hostname(link);
         if (r < 0)
-                return log_link_error_errno(link, r, "DHCP4 CLIENT: Failed to set hostname: %m");
+                return r;
 
         if (link->network->dhcp_vendor_class_identifier) {
                 r = sd_dhcp_client_set_vendor_class_identifier(link->dhcp_client,
index e954754c2069770f3352c188d8aad6766b4ab620..0ec4deb71642721a120ea8ddad485329d5625efd 100644 (file)
@@ -453,7 +453,14 @@ static int dhcp6_set_hostname(sd_dhcp6_client *client, Link *link) {
                 hn = hostname;
         }
 
-        return sd_dhcp6_client_set_fqdn(client, hn);
+        r = sd_dhcp6_client_set_fqdn(client, hn);
+        if (r == -EINVAL && hostname)
+                /* Ignore error when the machine's hostname is not suitable to send in DHCP packet. */
+                log_link_warning_errno(link, r, "DHCP6 CLIENT: Failed to set hostname from kernel hostname, ignoring: %m");
+        else if (r < 0)
+                return log_link_error_errno(link, r, "DHCP6 CLIENT: Failed to set hostname: %m");
+
+        return 0;
 }
 
 int dhcp6_configure(Link *link) {
@@ -497,7 +504,7 @@ int dhcp6_configure(Link *link) {
 
         r = dhcp6_set_hostname(client, link);
         if (r < 0)
-                return log_link_error_errno(link, r, "DHCP6 CLIENT: Failed to set hostname: %m");
+                return r;
 
         r = sd_dhcp6_client_set_ifindex(client, link->ifindex);
         if (r < 0)