diff options
Diffstat (limited to 'sbin/dhclient')
-rw-r--r-- | sbin/dhclient/clparse.c | 102 | ||||
-rw-r--r-- | sbin/dhclient/dhclient.c | 105 | ||||
-rw-r--r-- | sbin/dhclient/dhcpd.h | 5 |
3 files changed, 106 insertions, 106 deletions
diff --git a/sbin/dhclient/clparse.c b/sbin/dhclient/clparse.c index 920134fb7f5..ea957ddf4ac 100644 --- a/sbin/dhclient/clparse.c +++ b/sbin/dhclient/clparse.c @@ -1,4 +1,4 @@ -/* $OpenBSD: clparse.c,v 1.169 2018/11/04 16:32:11 krw Exp $ */ +/* $OpenBSD: clparse.c,v 1.170 2019/01/13 18:45:21 krw Exp $ */ /* Parser for dhclient config and lease files. */ @@ -58,6 +58,7 @@ #include <stdint.h> #include <stdlib.h> #include <string.h> +#include <unistd.h> #include "dhcp.h" #include "dhcpd.h" @@ -834,3 +835,102 @@ parse_reject_statement(FILE *cfile) return 1; } +/* + * Apply the list of options to be ignored that was provided on the + * command line. This will override any ignore list obtained from + * dhclient.conf. + */ +void +apply_ignore_list(char *ignore_list) +{ + uint8_t list[DHO_COUNT]; + char *p; + int ix, i, j; + + memset(list, 0, sizeof(list)); + ix = 0; + + for (p = strsep(&ignore_list, ", "); p != NULL; + p = strsep(&ignore_list, ", ")) { + if (*p == '\0') + continue; + + i = name_to_code(p); + if (i == DHO_END) { + log_debug("%s: invalid option name: '%s'", log_procname, + p); + return; + } + + /* Avoid storing duplicate options in the list. */ + for (j = 0; j < ix && list[j] != i; j++) + ; + if (j == ix) + list[ix++] = i; + } + + for (i = 0; i < ix; i++) { + j = list[i]; + config->default_actions[j] = ACTION_IGNORE; + free(config->defaults[j].data); + config->defaults[j].data = NULL; + config->defaults[j].len = 0; + } +} + +void +set_default_client_identifier(struct interface_info *ifi) +{ + struct option_data *opt; + + /* + * Check both len && data so + * + * send dhcp-client-identifier ""; + * + * can be used to suppress sending the default client + * identifier. + */ + opt = &config->send_options[DHO_DHCP_CLIENT_IDENTIFIER]; + if (opt->len == 0 && opt->data == NULL) { + opt->data = calloc(1, ETHER_ADDR_LEN + 1); + if (opt->data == NULL) + fatal("default client identifier"); + opt->data[0] = HTYPE_ETHER; + memcpy(&opt->data[1], ifi->hw_address.ether_addr_octet, + ETHER_ADDR_LEN); + opt->len = ETHER_ADDR_LEN + 1; + } +} + +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); + } +} diff --git a/sbin/dhclient/dhclient.c b/sbin/dhclient/dhclient.c index 656609cd661..f65ef6932f8 100644 --- a/sbin/dhclient/dhclient.c +++ b/sbin/dhclient/dhclient.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dhclient.c,v 1.601 2019/01/10 14:49:07 krw Exp $ */ +/* $OpenBSD: dhclient.c,v 1.602 2019/01/13 18:45:21 krw Exp $ */ /* * Copyright 2004 Henning Brauer <henning@openbsd.org> @@ -142,7 +142,6 @@ void rtm_dispatch(struct interface_info *, struct rt_msghdr *); struct client_lease *apply_defaults(struct client_lease *); struct client_lease *clone_lease(struct client_lease *); -void apply_ignore_list(char *); void state_preboot(struct interface_info *); void state_reboot(struct interface_info *); @@ -182,8 +181,6 @@ struct client_lease *packet_to_lease(struct interface_info *, void go_daemon(void); 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) \ @@ -2517,49 +2514,6 @@ cleanup: return NULL; } -/* - * Apply the list of options to be ignored that was provided on the - * command line. This will override any ignore list obtained from - * dhclient.conf. - */ -void -apply_ignore_list(char *ignore_list) -{ - uint8_t list[DHO_COUNT]; - char *p; - int ix, i, j; - - memset(list, 0, sizeof(list)); - ix = 0; - - for (p = strsep(&ignore_list, ", "); p != NULL; - p = strsep(&ignore_list, ", ")) { - if (*p == '\0') - continue; - - i = name_to_code(p); - if (i == DHO_END) { - log_debug("%s: invalid option name: '%s'", log_procname, - p); - return; - } - - /* Avoid storing duplicate options in the list. */ - for (j = 0; j < ix && list[j] != i; j++) - ; - if (j == ix) - list[ix++] = i; - } - - for (i = 0; i < ix; i++) { - j = list[i]; - config->default_actions[j] = ACTION_IGNORE; - free(config->defaults[j].data); - config->defaults[j].data = NULL; - config->defaults[j].len = 0; - } -} - void take_charge(struct interface_info *ifi, int routefd) { @@ -2659,63 +2613,6 @@ get_recorded_lease(struct interface_info *ifi) return lp; } -void -set_default_client_identifier(struct interface_info *ifi) -{ - struct option_data *opt; - - /* - * Check both len && data so - * - * send dhcp-client-identifier ""; - * - * can be used to suppress sending the default client - * identifier. - */ - opt = &config->send_options[DHO_DHCP_CLIENT_IDENTIFIER]; - if (opt->len == 0 && opt->data == NULL) { - opt->data = calloc(1, ETHER_ADDR_LEN + 1); - if (opt->data == NULL) - fatal("default client identifier"); - opt->data[0] = HTYPE_ETHER; - memcpy(&opt->data[1], ifi->hw_address.ether_addr_octet, - ETHER_ADDR_LEN); - opt->len = ETHER_ADDR_LEN + 1; - } -} - -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) { diff --git a/sbin/dhclient/dhcpd.h b/sbin/dhclient/dhcpd.h index e092f13ab00..1532e68da77 100644 --- a/sbin/dhclient/dhcpd.h +++ b/sbin/dhclient/dhcpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: dhcpd.h,v 1.263 2019/01/05 21:40:44 krw Exp $ */ +/* $OpenBSD: dhcpd.h,v 1.264 2019/01/13 18:45:21 krw Exp $ */ /* * Copyright (c) 2004 Henning Brauer <henning@openbsd.org> @@ -235,6 +235,9 @@ uint32_t wrapsum(uint32_t); /* clparse.c */ void read_conf(char *); void read_lease_db(char *, struct client_lease_tq *); +void apply_ignore_list(char *); +void set_default_client_identifier(struct interface_info *); +void set_default_hostname(void); /* kroute.c */ unsigned int extract_classless_route(uint8_t *, unsigned int, |