diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2016-11-22 23:22:04 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-11-22 23:22:04 -0500 |
commit | ee43050b40628368f938b6f366b4a6e94ea898a1 (patch) | |
tree | c2d2098c5dd0bb2f84b31153f0260e72d2a6d7c2 /src/network/networkd-dhcp4.c | |
parent | 6d9e45e97fb1157d5670d533f55819a59e7ae336 (diff) | |
parent | ef8b0084552e05f28b9132d5dfc75edae164a991 (diff) |
Merge pull request #4692 from poettering/networkd-dhcp
Various networkd/DHCP fixes.
Diffstat (limited to 'src/network/networkd-dhcp4.c')
-rw-r--r-- | src/network/networkd-dhcp4.c | 44 |
1 files changed, 25 insertions, 19 deletions
diff --git a/src/network/networkd-dhcp4.c b/src/network/networkd-dhcp4.c index 614bceefab..ca23c1c2a7 100644 --- a/src/network/networkd-dhcp4.c +++ b/src/network/networkd-dhcp4.c @@ -536,6 +536,28 @@ static void dhcp4_handler(sd_dhcp_client *client, int event, void *userdata) { return; } +static int dhcp4_set_hostname(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_dhcp_client_set_hostname(link->dhcp_client, hn); +} + int dhcp4_configure(Link *link) { int r; @@ -605,25 +627,9 @@ int dhcp4_configure(Link *link) { if (r < 0) return r; - if (link->network->dhcp_send_hostname) { - _cleanup_free_ char *hostname = NULL; - const char *hn = NULL; - - if (!link->network->dhcp_hostname) { - hostname = gethostname_malloc(); - if (!hostname) - return -ENOMEM; - - hn = hostname; - } else - hn = link->network->dhcp_hostname; - - if (!is_localhost(hn)) { - r = sd_dhcp_client_set_hostname(link->dhcp_client, hn); - if (r < 0) - return r; - } - } + r = dhcp4_set_hostname(link); + if (r < 0) + return r; if (link->network->dhcp_vendor_class_identifier) { r = sd_dhcp_client_set_vendor_class_identifier(link->dhcp_client, |