summaryrefslogtreecommitdiff
path: root/src/network/networkd-link.c
diff options
context:
space:
mode:
authorEugene Yakubovich <eugene.yakubovich@coreos.com>2014-07-01 11:58:49 -0700
committerTom Gundersen <teg@jklm.no>2014-07-01 22:02:25 +0200
commit4cc7a82c9490a3c5ae03b1d6d168ce40ba499e23 (patch)
tree0b806eddc7563072cb1398ae602ced46ee840b4c /src/network/networkd-link.c
parent0a8a0fad010018be0f46d1c2e077ade0eb27c7db (diff)
networkd: send hostname to dhcp server
Send hostname (option 12) in DISCOVER and REQUEST messages so the DHCP server could use it to register with dynamic DNS and such. To opt-out of this behaviour set SendHostname to false in [DHCP] section of .network file [tomegun: rebased, made sure a failing set_hostname is a noop and moved config from DHCPv4 to DHCP]
Diffstat (limited to 'src/network/networkd-link.c')
-rw-r--r--src/network/networkd-link.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c
index a523a3e9b2..3324276bcc 100644
--- a/src/network/networkd-link.c
+++ b/src/network/networkd-link.c
@@ -21,6 +21,7 @@
#include <netinet/ether.h>
#include <linux/if.h>
+#include <unistd.h>
#include "networkd.h"
#include "libudev-private.h"
@@ -1927,6 +1928,18 @@ static int link_enter_enslave(Link *link) {
return 0;
}
+/* make sure the hostname is not "localhost" */
+static bool is_localhost(const char *hostname) {
+ assert(hostname);
+
+ return streq(hostname, "localhost") ||
+ streq(hostname, "localhost.") ||
+ endswith(hostname, ".localhost") ||
+ endswith(hostname, ".localhost.") ||
+ endswith(hostname, ".localdomain") ||
+ endswith(hostname, ".localdomain.");
+}
+
static int link_configure(Link *link) {
int r;
@@ -1992,6 +2005,7 @@ static int link_configure(Link *link) {
if (r < 0)
return r;
}
+
if (link->network->dhcp_routes) {
r = sd_dhcp_client_set_request_option(link->dhcp_client, DHCP_OPTION_STATIC_ROUTE);
if (r < 0)
@@ -2000,6 +2014,18 @@ static int link_configure(Link *link) {
if (r < 0)
return r;
}
+
+ if (link->network->dhcp_sendhost) {
+ _cleanup_free_ char *hostname = gethostname_malloc();
+ if (!hostname)
+ return -ENOMEM;
+
+ if (!is_localhost(hostname)) {
+ r = sd_dhcp_client_set_hostname(link->dhcp_client, hostname);
+ if (r < 0)
+ return r;
+ }
+ }
}
if (link->network->dhcp_server) {