From 9aca538eeab60b4b370700901485b0b2d4d39793 Mon Sep 17 00:00:00 2001 From: krw Date: Sat, 9 Dec 2017 15:48:04 +0000 Subject: [PATCH] Add ACTION_IGNORE and nuke ignored_options, ignored_option_count fields in struct client_config. --- sbin/dhclient/clparse.c | 11 +++++++---- sbin/dhclient/dhclient.c | 25 ++++++++++--------------- sbin/dhclient/dhcpd.h | 7 +++---- 3 files changed, 20 insertions(+), 23 deletions(-) diff --git a/sbin/dhclient/clparse.c b/sbin/dhclient/clparse.c index ee00f748233..d40694cacd4 100644 --- a/sbin/dhclient/clparse.c +++ b/sbin/dhclient/clparse.c @@ -1,4 +1,4 @@ -/* $OpenBSD: clparse.c,v 1.153 2017/12/08 20:17:28 krw Exp $ */ +/* $OpenBSD: clparse.c,v 1.154 2017/12/09 15:48:04 krw Exp $ */ /* Parser for dhclient config and lease files. */ @@ -256,8 +256,9 @@ read_client_leases(char *name, struct client_lease_tq *tq) void parse_client_statement(FILE *cfile, char *name, int nested) { + uint8_t list[DHO_COUNT]; char *val; - int i, token; + int i, count, token; token = next_token(NULL, cfile); @@ -290,9 +291,11 @@ parse_client_statement(FILE *cfile, char *name, int nested) parse_semi(cfile); break; case TOK_IGNORE: - if (parse_option_list(cfile, &config->ignored_option_count, - config->ignored_options) == 1) + if (parse_option_list(cfile, &count, list) == 1) { + for (i = 0; i < count; i++) + config->default_actions[list[i]] = ACTION_IGNORE; parse_semi(cfile); + } break; case TOK_INITIAL_INTERVAL: if (parse_lease_time(cfile, &config->initial_interval) == 1) diff --git a/sbin/dhclient/dhclient.c b/sbin/dhclient/dhclient.c index 264eaebc2e0..24d44045a70 100644 --- a/sbin/dhclient/dhclient.c +++ b/sbin/dhclient/dhclient.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dhclient.c,v 1.539 2017/12/08 20:17:28 krw Exp $ */ +/* $OpenBSD: dhclient.c,v 1.540 2017/12/09 15:48:04 krw Exp $ */ /* * Copyright 2004 Henning Brauer @@ -2187,7 +2187,7 @@ struct client_lease * apply_defaults(struct client_lease *lease) { struct client_lease *newlease; - int i, j; + int i; newlease = clone_lease(lease); if (newlease == NULL) @@ -2207,18 +2207,13 @@ apply_defaults(struct client_lease *lease) newlease->next_server.s_addr = config->next_server.s_addr; for (i = 0; i < DHO_COUNT; i++) { - for (j = 0; j < config->ignored_option_count; j++) { - if (config->ignored_options[j] == i) { - free(newlease->options[i].data); - newlease->options[i].data = NULL; - newlease->options[i].len = 0; - break; - } - } - if (j < config->ignored_option_count) - continue; - switch (config->default_actions[i]) { + case ACTION_IGNORE: + free(newlease->options[i].data); + newlease->options[i].data = NULL; + newlease->options[i].len = 0; + break; + case ACTION_SUPERSEDE: free(newlease->options[i].data); newlease->options[i].len = config->defaults[i].len; @@ -2392,8 +2387,8 @@ apply_ignore_list(char *ignore_list) list[ix++] = i; } - config->ignored_option_count = ix; - memcpy(config->ignored_options, list, sizeof(config->ignored_options)); + for (i = 0; i < ix; i++) + config->default_actions[list[i]] = ACTION_IGNORE; } void diff --git a/sbin/dhclient/dhcpd.h b/sbin/dhclient/dhcpd.h index 6b46965fce4..8e337255a2c 100644 --- a/sbin/dhclient/dhcpd.h +++ b/sbin/dhclient/dhcpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: dhcpd.h,v 1.240 2017/12/07 19:03:15 krw Exp $ */ +/* $OpenBSD: dhcpd.h,v 1.241 2017/12/09 15:48:04 krw Exp $ */ /* * Copyright (c) 2004 Henning Brauer @@ -88,7 +88,8 @@ struct client_config { ACTION_DEFAULT, ACTION_SUPERSEDE, ACTION_PREPEND, - ACTION_APPEND + ACTION_APPEND, + ACTION_IGNORE } default_actions[DHO_COUNT]; struct in_addr address; @@ -96,10 +97,8 @@ struct client_config { struct option_data send_options[DHO_COUNT]; uint8_t required_options[DHO_COUNT]; uint8_t requested_options[DHO_COUNT]; - uint8_t ignored_options[DHO_COUNT]; int requested_option_count; int required_option_count; - int ignored_option_count; time_t timeout; time_t initial_interval; time_t link_timeout; -- 2.20.1