summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkrw <krw@openbsd.org>2017-12-20 18:51:14 +0000
committerkrw <krw@openbsd.org>2017-12-20 18:51:14 +0000
commita4e266465257215a66f633e011af974713e8c048 (patch)
treea388731bf478b9f1af68c12555107b61a5d95719
parentTwo background scan fixes for iwn(4) (4965 devices only): (diff)
downloadwireguard-openbsd-a4e266465257215a66f633e011af974713e8c048.tar.xz
wireguard-openbsd-a4e266465257215a66f633e011af974713e8c048.zip
Always 'send' host-name, rather than relying on dhclient.conf to ask
for it. Removes the need to install a dhclient.conf for a default configuration. Install script simplification to follow. General enthusiasm. ok millert@ benno@ tom@ ian@
-rw-r--r--sbin/dhclient/dhclient.c39
1 files changed, 38 insertions, 1 deletions
diff --git a/sbin/dhclient/dhclient.c b/sbin/dhclient/dhclient.c
index d193457758a..278becb16e0 100644
--- a/sbin/dhclient/dhclient.c
+++ b/sbin/dhclient/dhclient.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: dhclient.c,v 1.542 2017/12/18 14:17:58 krw Exp $ */
+/* $OpenBSD: dhclient.c,v 1.543 2017/12/20 18:51:14 krw Exp $ */
/*
* Copyright 2004 Henning Brauer <henning@openbsd.org>
@@ -175,6 +175,7 @@ void go_daemon(const char *);
int rdaemon(int);
void take_charge(struct interface_info *, int);
void set_default_client_identifier(struct interface_info *);
+void set_default_hostname(void);
struct client_lease *get_recorded_lease(struct interface_info *);
#define ROUNDUP(a) \
@@ -556,6 +557,10 @@ main(int argc, char *argv[])
*/
set_default_client_identifier(ifi);
+ /*
+ * Set default hostname, if needed. */
+ set_default_hostname();
+
if ((pw = getpwnam("_dhcp")) == NULL)
fatalx("no such user: _dhcp");
@@ -2505,6 +2510,38 @@ set_default_client_identifier(struct interface_info *ifi)
}
}
+void
+set_default_hostname(void)
+{
+ char hn[HOST_NAME_MAX + 1], *p;
+ struct option_data *opt;
+ int rslt;
+
+ /*
+ * Check both len && data so
+ *
+ * send host-name "";
+ *
+ * can be used to suppress sending the default host
+ * name.
+ */
+ opt = &config->send_options[DHO_HOST_NAME];
+ if (opt->len == 0 && opt->data == NULL) {
+ rslt = gethostname(hn, sizeof(hn));
+ if (rslt == -1) {
+ log_warn("host-name");
+ return;
+ }
+ p = strchr(hn, '.');
+ if (p != NULL)
+ *p = '\0';
+ opt->data = strdup(hn);
+ if (opt->data == NULL)
+ fatal("default host-name");
+ opt->len = strlen(opt->data);
+ }
+}
+
time_t
lease_expiry(struct client_lease *lease)
{