network: DHCP: ignore error in setting hostname when it is given by uname()

C.f. #9759.
This commit is contained in:
Yu Watanabe 2018-08-02 16:31:10 +09:00
parent 19f9e4e2c8
commit a8494759b4
2 changed files with 18 additions and 4 deletions

View 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,

View 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)