From a4e266465257215a66f633e011af974713e8c048 Mon Sep 17 00:00:00 2001 From: krw Date: Wed, 20 Dec 2017 18:51:14 +0000 Subject: [PATCH] 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@ --- sbin/dhclient/dhclient.c | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) 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 @@ -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) { -- 2.20.1