summaryrefslogtreecommitdiff
path: root/src/network
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2016-11-18 13:02:57 +0100
committerLennart Poettering <lennart@poettering.net>2016-11-21 22:47:47 +0100
commit7192bb81bd99108287db82d6140d5329086b0da2 (patch)
tree87c2959504b7d031995b00f7f1a5f541e4bb43f5 /src/network
parent17f6ed4d5956f4e74056ae976b638dbba33c2844 (diff)
downloadsystemd-7192bb81bd99108287db82d6140d5329086b0da2.tar.gz
networkd: rework how we set the hostname on the dhcp4 client
Let's split out the code into its own little function and let's use gethostname_strict() which already filters out localhost for us.
Diffstat (limited to 'src/network')
-rw-r--r--src/network/networkd-dhcp4.c44
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,