diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2018-08-06 07:58:50 +0200 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2018-08-06 07:59:34 +0200 |
commit | cad8d67194314354befbdf84bb04f91cbc26b75f (patch) | |
tree | 9832581ab59680ac86008f4382b51b4aeab22425 | |
parent | 685499007fc536f5e78ebb49cb67561e186f665e (diff) | |
parent | 10c6e7e51ec515a509698120ea13cb2e0a325a3a (diff) | |
download | systemd-cad8d67194314354befbdf84bb04f91cbc26b75f.tar.gz |
Merge pull request #9775 from yuwata/follow-up-9766
-rw-r--r-- | man/systemd.network.xml | 21 | ||||
-rw-r--r-- | src/network/networkd-dhcp4.c | 11 | ||||
-rw-r--r-- | src/network/networkd-dhcp6.c | 11 | ||||
-rw-r--r-- | src/network/networkd-network.c | 27 | ||||
-rw-r--r-- | src/resolve/resolved-dns-trust-anchor.c | 10 |
5 files changed, 54 insertions, 26 deletions
diff --git a/man/systemd.network.xml b/man/systemd.network.xml index 8a80b0cf4f..cbf53f323a 100644 --- a/man/systemd.network.xml +++ b/man/systemd.network.xml @@ -1194,25 +1194,28 @@ <varlistentry> <term><varname>SendHostname=</varname></term> <listitem> - <para>When true (the default), the machine's hostname will - be sent to the DHCP server.</para> + <para>When true (the default), the machine's hostname will be sent to the DHCP server. + Note that the machine's hostname must consist only of 7-bit ASCII lower-case characters and + no spaces or dots, and be formatted as a valid DNS domain name. Otherwise, the hostname is not + sent even if this is set to true.</para> </listitem> </varlistentry> <varlistentry> <term><varname>UseHostname=</varname></term> <listitem> <para>When true (the default), the hostname received from - the DHCP server will be set as the transient hostname of the system + the DHCP server will be set as the transient hostname of the system. </para> </listitem> </varlistentry> <varlistentry> - <term><varname>Hostname=</varname></term> - <listitem> - <para>Use this value for the hostname which is sent to the - DHCP server, instead of machine's hostname.</para> - </listitem> - </varlistentry> + <term><varname>Hostname=</varname></term> + <listitem> + <para>Use this value for the hostname which is sent to the DHCP server, instead of machine's hostname. + Note that the specified hostname must consist only of 7-bit ASCII lower-case characters and + no spaces or dots, and be formatted as a valid DNS domain name.</para> + </listitem> + </varlistentry> <varlistentry> <term><varname>UseDomains=</varname></term> <listitem> diff --git a/src/network/networkd-dhcp4.c b/src/network/networkd-dhcp4.c index 5616046f4f..08656334e0 100644 --- a/src/network/networkd-dhcp4.c +++ b/src/network/networkd-dhcp4.c @@ -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, diff --git a/src/network/networkd-dhcp6.c b/src/network/networkd-dhcp6.c index e954754c20..0ec4deb716 100644 --- a/src/network/networkd-dhcp6.c +++ b/src/network/networkd-dhcp6.c @@ -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) diff --git a/src/network/networkd-network.c b/src/network/networkd-network.c index 1f1cdced8f..c8f7c4f98a 100644 --- a/src/network/networkd-network.c +++ b/src/network/networkd-network.c @@ -971,7 +971,8 @@ int config_parse_hostname( void *data, void *userdata) { - char **hostname = data, *hn = NULL; + _cleanup_free_ char *hn = NULL; + char **hostname = data; int r; assert(filename); @@ -984,13 +985,20 @@ int config_parse_hostname( if (!hostname_is_valid(hn, false)) { log_syntax(unit, LOG_ERR, filename, line, 0, "Hostname is not valid, ignoring assignment: %s", rvalue); - free(hn); return 0; } - free(*hostname); - *hostname = hostname_cleanup(hn); - return 0; + r = dns_name_is_valid(hn); + if (r < 0) { + log_syntax(unit, LOG_ERR, filename, line, r, "Failed to check validity of hostname '%s', ignoring assignment: %m", rvalue); + return 0; + } + if (r == 0) { + log_syntax(unit, LOG_ERR, filename, line, 0, "Hostname is not a valid DNS domain name, ignoring assignment: %s", rvalue); + return 0; + } + + return free_and_replace(*hostname, hn); } int config_parse_timezone( @@ -1005,7 +1013,8 @@ int config_parse_timezone( void *data, void *userdata) { - char **datap = data, *tz = NULL; + _cleanup_free_ char *tz = NULL; + char **datap = data; int r; assert(filename); @@ -1018,14 +1027,10 @@ int config_parse_timezone( if (!timezone_is_valid(tz, LOG_ERR)) { log_syntax(unit, LOG_ERR, filename, line, 0, "Timezone is not valid, ignoring assignment: %s", rvalue); - free(tz); return 0; } - free(*datap); - *datap = tz; - - return 0; + return free_and_replace(*datap, tz); } int config_parse_dhcp_server_dns( diff --git a/src/resolve/resolved-dns-trust-anchor.c b/src/resolve/resolved-dns-trust-anchor.c index 533e438fae..bf5b07cdd3 100644 --- a/src/resolve/resolved-dns-trust-anchor.c +++ b/src/resolve/resolved-dns-trust-anchor.c @@ -218,7 +218,10 @@ static int dns_trust_anchor_load_positive(DnsTrustAnchor *d, const char *path, u if (r < 0) return log_warning_errno(r, "Unable to parse domain in line %s:%u: %m", path, line); - if (!dns_name_is_valid(domain)) { + r = dns_name_is_valid(domain); + if (r < 0) + return log_warning_errno(r, "Failed to chack validity of domain name '%s', at line %s:%u, ignoring line: %m", domain, path, line); + if (r == 0) { log_warning("Domain name %s is invalid, at line %s:%u, ignoring line.", domain, path, line); return -EINVAL; } @@ -385,7 +388,10 @@ static int dns_trust_anchor_load_negative(DnsTrustAnchor *d, const char *path, u if (r < 0) return log_warning_errno(r, "Unable to parse line %s:%u: %m", path, line); - if (!dns_name_is_valid(domain)) { + r = dns_name_is_valid(domain); + if (r < 0) + return log_warning_errno(r, "Failed to chack validity of domain name '%s', at line %s:%u, ignoring line: %m", domain, path, line); + if (r == 0) { log_warning("Domain name %s is invalid, at line %s:%u, ignoring line.", domain, path, line); return -EINVAL; } |