diff options
author | Kenneth R Westerback <krw@cvs.openbsd.org> | 2012-10-27 23:08:54 +0000 |
---|---|---|
committer | Kenneth R Westerback <krw@cvs.openbsd.org> | 2012-10-27 23:08:54 +0000 |
commit | ab511a5cc56acdc5f723411098bb1ead3075d5e0 (patch) | |
tree | f2b7a926be0d01090db6ecefa3a25802daf72897 | |
parent | a4f754ad67aa4517d148b7f5a0a2a60e6ec6243e (diff) |
Change dhclient.conf directive 'ignore' to take a list of option names
rather than list of option declarations. e.g. 'ignore routers;'
instead of 'ignore routers 1.2.3.4;' The value in the declaration
was being ignored anyway.
While there clean up the related code a bit.
-rw-r--r-- | sbin/dhclient/clparse.c | 11 | ||||
-rw-r--r-- | sbin/dhclient/dhclient.c | 149 | ||||
-rw-r--r-- | sbin/dhclient/dhclient.conf.5 | 22 | ||||
-rw-r--r-- | sbin/dhclient/dhcpd.h | 4 | ||||
-rw-r--r-- | sbin/dhclient/options.c | 14 |
5 files changed, 97 insertions, 103 deletions
diff --git a/sbin/dhclient/clparse.c b/sbin/dhclient/clparse.c index 9119943c496..877c4330008 100644 --- a/sbin/dhclient/clparse.c +++ b/sbin/dhclient/clparse.c @@ -1,4 +1,4 @@ -/* $OpenBSD: clparse.c,v 1.40 2012/08/26 23:33:29 krw Exp $ */ +/* $OpenBSD: clparse.c,v 1.41 2012/10/27 23:08:53 krw Exp $ */ /* Parser for dhclient config and lease files... */ @@ -154,7 +154,8 @@ read_client_leases(void) void parse_client_statement(FILE *cfile) { - int token, code; + u_int8_t ignorelist[256]; + int token, code, count, i; switch (next_token(NULL, cfile)) { case TOK_SEND: @@ -171,9 +172,9 @@ parse_client_statement(FILE *cfile) config->default_actions[code] = ACTION_SUPERSEDE; return; case TOK_IGNORE: - code = parse_option_decl(cfile, &config->defaults[0]); - if (code != -1) - config->default_actions[code] = ACTION_IGNORE; + count = parse_option_list(cfile, ignorelist); + for (i = 0; i < count; i++) + config->default_actions[ignorelist[i]] = ACTION_IGNORE; return; case TOK_APPEND: code = parse_option_decl(cfile, &config->defaults[0]); diff --git a/sbin/dhclient/dhclient.c b/sbin/dhclient/dhclient.c index c1c37ebfd20..9ce6f69e391 100644 --- a/sbin/dhclient/dhclient.c +++ b/sbin/dhclient/dhclient.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dhclient.c,v 1.157 2012/10/10 17:44:43 krw Exp $ */ +/* $OpenBSD: dhclient.c,v 1.158 2012/10/27 23:08:53 krw Exp $ */ /* * Copyright 2004 Henning Brauer <henning@openbsd.org> @@ -1430,8 +1430,7 @@ write_client_lease(struct client_lease *lease) if (lease->options[i].len) fprintf(leaseFile, " option %s %s;\n", dhcp_options[i].name, - pretty_print_option(i, lease->options[i].data, - lease->options[i].len, 1, 1)); + pretty_print_option(i, &lease->options[i], 1)); t = gmtime(&lease->renewal); fprintf(leaseFile, " renew %d %d/%d/%d %02d:%02d:%02d;\n", @@ -1501,9 +1500,9 @@ priv_script_init(char *reason) void priv_script_write_params(char *prefix, struct client_lease *lease) { - u_int8_t dbuf[1500]; - int i, len = 0; - char tbuf[128]; + char buf[256]; + struct option_data o; + int i; script_set_env(prefix, "ip_address", piaddr(lease->address)); @@ -1535,84 +1534,75 @@ priv_script_write_params(char *prefix, struct client_lease *lease) if (lease->server_name) script_set_env(prefix, "server_name", lease->server_name); + for (i = 0; i < 256; i++) { - u_int8_t *dp = NULL; - - if (config->defaults[i].len) { - if (lease->options[i].len) { - switch (config->default_actions[i]) { - case ACTION_IGNORE: - /* handled below */ - break; - case ACTION_DEFAULT: - dp = lease->options[i].data; - len = lease->options[i].len; - break; - case ACTION_SUPERSEDE: -supersede: - dp = config->defaults[i].data; - len = config->defaults[i].len; - break; - case ACTION_PREPEND: - len = config->defaults[i].len + - lease->options[i].len; - if (len >= sizeof(dbuf)) { - warning("no space to %s %s", - "prepend option", - dhcp_options[i].name); - goto supersede; - } - dp = dbuf; - memcpy(dp, - config->defaults[i].data, - config->defaults[i].len); - memcpy(dp + - config->defaults[i].len, - lease->options[i].data, - lease->options[i].len); - dp[len] = '\0'; - break; - case ACTION_APPEND: - len = config->defaults[i].len + - lease->options[i].len; - if (len >= sizeof(dbuf)) { - warning("no space to %s %s", - "append option", - dhcp_options[i].name); - goto supersede; - } - dp = dbuf; - memcpy(dp, lease->options[i].data, - lease->options[i].len); - memcpy(dp + lease->options[i].len, + if (!dhcp_option_ev_name(buf, sizeof(buf), &dhcp_options[i])) + continue; + + switch (config->default_actions[i]) { + case ACTION_IGNORE: + break; + + case ACTION_DEFAULT: + if (lease->options[i].len) + script_set_env(prefix, buf, + pretty_print_option(i, &lease->options[i], + 0)); + else if (config->defaults[i].len) + script_set_env(prefix, buf, + pretty_print_option(i, &config->defaults[i], + 0)); + break; + + case ACTION_SUPERSEDE: + if (config->defaults[i].len) + script_set_env(prefix, buf, + pretty_print_option(i, &config->defaults[i], + 0)); + break; + + case ACTION_PREPEND: + o.len = config->defaults[i].len + lease->options[i].len; + if (o.len > 0) { + o.data = calloc(1, o.len); + if (o.data == NULL) + error("no space to prepend '%s' to %s", config->defaults[i].data, - config->defaults[i].len); - dp[len] = '\0'; - } - } else { - dp = config->defaults[i].data; - len = config->defaults[i].len; + dhcp_options[i].name); + memcpy(o.data, config->defaults[i].data, + config->defaults[i].len); + memcpy(o.data + config->defaults[i].len, + lease->options[i].data, + lease->options[i].len); + script_set_env(prefix, buf, + pretty_print_option(i, &o, 0)); + free(o.data); } - } else if (lease->options[i].len) { - len = lease->options[i].len; - dp = lease->options[i].data; - } else { - len = 0; - } - if (len && config->default_actions[i] == ACTION_IGNORE) { - len = 0; - } - if (len) { - char name[256]; + break; - if (dhcp_option_ev_name(name, sizeof(name), - &dhcp_options[i])) - script_set_env(prefix, name, - pretty_print_option(i, dp, len, 0, 0)); + case ACTION_APPEND: + o.len = config->defaults[i].len + lease->options[i].len; + if (o.len > 0) { + o.data = calloc(1, o.len); + if (o.data == NULL) + error("no space to append '%s' to %s", + config->defaults[i].data, + dhcp_options[i].name); + memcpy(o.data, lease->options[i].data, + lease->options[i].len); + memcpy(o.data + lease->options[i].len, + config->defaults[i].data, + config->defaults[i].len); + script_set_env(prefix, buf, + pretty_print_option(i, &o, 0)); + free(o.data); + } + break; } } - snprintf(tbuf, sizeof(tbuf), "%d", (int)lease->expiry); - script_set_env(prefix, "expiry", tbuf); + + snprintf(buf, sizeof(buf), "%d", (int)lease->expiry); + script_set_env(prefix, "expiry", buf); } void @@ -1844,8 +1834,7 @@ check_option(struct client_lease *l, int option) /* we use this, since this is what gets passed to dhclient-script */ - opbuf = pretty_print_option(option, l->options[option].data, - l->options[option].len, 0, 0); + opbuf = pretty_print_option(option, &l->options[option], 0); sbuf = option_as_string(option, l->options[option].data, l->options[option].len); diff --git a/sbin/dhclient/dhclient.conf.5 b/sbin/dhclient/dhclient.conf.5 index d6da0655414..980b19c7c48 100644 --- a/sbin/dhclient/dhclient.conf.5 +++ b/sbin/dhclient/dhclient.conf.5 @@ -1,4 +1,4 @@ -.\" $OpenBSD: dhclient.conf.5,v 1.23 2012/09/22 20:09:43 jmc Exp $ +.\" $OpenBSD: dhclient.conf.5,v 1.24 2012/10/27 23:08:53 krw Exp $ .\" .\" Copyright (c) 1997 The Internet Software Consortium. .\" All rights reserved. @@ -36,7 +36,7 @@ .\" see ``http://www.isc.org/isc''. To learn more about Vixie .\" Enterprises, see ``http://www.vix.com''. .\" -.Dd $Mdocdate: September 22 2012 $ +.Dd $Mdocdate: October 27 2012 $ .Dt DHCLIENT.CONF 5 .Os .Sh NAME @@ -179,6 +179,16 @@ DHCP Options are defined in .Xr dhcp-options 5 . .Bl -tag -width Ds .It Xo +.Ic ignore Op Ar option +.Oo , Ar ... option Oc ; +.Xc +The +.Ic ignore +statement causes the client to discard values provided by the server for +the specified options. +Only the option names should be specified in the ignore statement \- not +option parameters. +.It Xo .Ic request Op Ar option .Oo , Ar ... option Oc ; .Xc @@ -244,14 +254,6 @@ in the .Ic supersede statement. .It Xo -.Ic ignore No { Op Ar option declaration -.Oo , Ar ... option declaration Oc } -.Xc -If for some set of options the client should always ignore the -value supplied by the server, these values can be defined in the -.Ic ignore -statement. -.It Xo .Ic prepend No { Op Ar option declaration .Oo , Ar ... option declaration Oc } .Xc diff --git a/sbin/dhclient/dhcpd.h b/sbin/dhclient/dhcpd.h index d0e7cabce62..3e3450a3202 100644 --- a/sbin/dhclient/dhcpd.h +++ b/sbin/dhclient/dhcpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: dhcpd.h,v 1.81 2012/09/18 09:34:09 krw Exp $ */ +/* $OpenBSD: dhcpd.h,v 1.82 2012/10/27 23:08:53 krw Exp $ */ /* * Copyright (c) 2004 Henning Brauer <henning@openbsd.org> @@ -208,7 +208,7 @@ extern struct client_config *config; /* options.c */ int cons_options(struct option_data *); -char *pretty_print_option(unsigned int, unsigned char *, int, int, int); +char *pretty_print_option(unsigned int, struct option_data *, int); void do_packet(int, unsigned int, struct iaddr, struct hardware *); /* errwarn.c */ diff --git a/sbin/dhclient/options.c b/sbin/dhclient/options.c index 6d2eb78c76b..0d635a51486 100644 --- a/sbin/dhclient/options.c +++ b/sbin/dhclient/options.c @@ -1,4 +1,4 @@ -/* $OpenBSD: options.c,v 1.41 2012/06/26 14:46:42 krw Exp $ */ +/* $OpenBSD: options.c,v 1.42 2012/10/27 23:08:53 krw Exp $ */ /* DHCP options parsing and reassembly. */ @@ -198,14 +198,16 @@ cons_options(struct option_data *options) * Format the specified option so that a human can easily read it. */ char * -pretty_print_option(unsigned int code, unsigned char *data, int len, - int emit_commas, int emit_quotes) +pretty_print_option(unsigned int code, struct option_data *option, + int emit_punct) { static char optbuf[32768]; /* XXX */ int hunksize = 0, numhunk = -1, numelem = 0; char fmtbuf[32], *op = optbuf; int i, j, k, opleft = sizeof(optbuf); + unsigned char *data = option->data; unsigned char *dp = data; + int len = option->len; struct in_addr foo; char comma; @@ -213,7 +215,7 @@ pretty_print_option(unsigned int code, unsigned char *data, int len, if (code > 255) error("pretty_print_option: bad code %d", code); - if (emit_commas) + if (emit_punct) comma = ','; else comma = ' '; @@ -316,7 +318,7 @@ pretty_print_option(unsigned int code, unsigned char *data, int len, size_t oplen; switch (fmtbuf[j]) { case 't': - if (emit_quotes) { + if (emit_punct) { *op++ = '"'; opleft--; } @@ -345,7 +347,7 @@ pretty_print_option(unsigned int code, unsigned char *data, int len, opleft--; } } - if (emit_quotes) { + if (emit_punct) { *op++ = '"'; opleft--; } |