diff options
author | Shawn Routhier <sar@isc.org> | 2012-11-13 12:56:02 -0800 |
---|---|---|
committer | Shawn Routhier <sar@isc.org> | 2012-11-13 12:56:02 -0800 |
commit | 10613724a97140bc22c2e17f8627dd898c5064ac (patch) | |
tree | b3d3aa208ae581037a3b52922e7d2a15cd32c853 /client | |
parent | d56788df77ad347ffb0dc459bcfd5e13567abbaa (diff) | |
download | isc-dhcp-10613724a97140bc22c2e17f8627dd898c5064ac.tar.gz |
[master]
The client now passes information about the options it requested
from the server to the script code via environment variables.
These variables are of the form requested_<option_name>=1 with
the option name being the same as used in the new_* and old_*
variables. [ISC-Bugs #29068]
Diffstat (limited to 'client')
-rw-r--r-- | client/dhc6.c | 35 | ||||
-rw-r--r-- | client/dhclient-script.8 | 23 | ||||
-rw-r--r-- | client/dhclient.c | 31 |
3 files changed, 81 insertions, 8 deletions
diff --git a/client/dhc6.c b/client/dhc6.c index f9220486..8974e7a6 100644 --- a/client/dhc6.c +++ b/client/dhc6.c @@ -109,6 +109,7 @@ static void make_client6_options(struct client_state *client, static void script_write_params6(struct client_state *client, const char *prefix, struct option_state *options); +static void script_write_requested6(struct client_state *client); static isc_boolean_t active_prefix(struct client_state *client); static int check_timing6(struct client_state *client, u_int8_t msg_type, @@ -4339,6 +4340,7 @@ start_bound(struct client_state *client) dhc6_marshall_values("old_", client, old, oldia, oldaddr); dhc6_marshall_values("new_", client, lease, ia, addr); + script_write_requested6(client); script_go(client); } @@ -4355,6 +4357,7 @@ start_bound(struct client_state *client) dhc6_marshall_values("new_", client, lease, ia, NULL); + script_write_requested6(client); script_go(client); } @@ -4371,6 +4374,7 @@ start_bound(struct client_state *client) old->bindings->addrs : NULL); dhc6_marshall_values("new_", client, lease, NULL, NULL); + script_write_requested6(client); script_go(client); } @@ -4649,6 +4653,7 @@ do_depref(void *input) script_init(client, "DEPREF6", NULL); dhc6_marshall_values("cur_", client, lease, ia, addr); + script_write_requested6(client); script_go(client); addr->flags |= DHC6_ADDR_DEPREFFED; @@ -4702,6 +4707,7 @@ do_expire(void *input) script_init(client, "EXPIRE6", NULL); dhc6_marshall_values("old_", client, lease, ia, addr); + script_write_requested6(client); script_go(client); addr->flags |= DHC6_ADDR_EXPIRED; @@ -4766,6 +4772,7 @@ unconfigure6(struct client_state *client, const char *reason) if (client->active_lease != NULL) script_write_params6(client, "old_", client->active_lease->options); + script_write_requested6(client); script_go(client); return; } @@ -4781,6 +4788,7 @@ unconfigure6(struct client_state *client, const char *reason) script_init(client, reason, NULL); dhc6_marshall_values("old_", client, client->active_lease, ia, addr); + script_write_requested6(client); script_go(client); #if defined (NSUPDATE) @@ -4874,6 +4882,7 @@ start_informed(struct client_state *client) script_write_params6(client, "old_", client->old_lease->options); script_write_params6(client, "new_", client->active_lease->options); + script_write_requested6(client); script_go(client); go_daemon(); @@ -5101,6 +5110,32 @@ script_write_params6(struct client_state *client, const char *prefix, } /* + * A clone of the DHCPv4 routine. + * Write out the environment variables for the objects that the + * client requested. If the object was requested the variable will be: + * requested_<option_name>=1 + * If it wasn't requested there won't be a variable. + */ +static void script_write_requested6(client) + struct client_state *client; +{ + int i; + struct option **req; + char name[256]; + req = client->config->requested_options; + + if (req == NULL) + return; + + for (i = 0 ; req[i] != NULL ; i++) { + if ((req[i]->universe == &dhcpv6_universe) && + dhcp_option_ev_name (name, sizeof(name), req[i])) { + client_envadd(client, "requested_", name, "%d", 1); + } + } +} + +/* * Check if there is something not fully defined in the active lease. */ static isc_boolean_t diff --git a/client/dhclient-script.8 b/client/dhclient-script.8 index 5606d058..f493e71f 100644 --- a/client/dhclient-script.8 +++ b/client/dhclient-script.8 @@ -1,5 +1,6 @@ .\" dhclient-script.8 .\" +.\" Copyright (c) 2012 by Internet Systems Consortium, Inc. ("ISC") .\" Copyright (c) 2009-2010 by Internet Systems Consortium, Inc. ("ISC") .\" Copyright (c) 2004-2005 by Internet Systems Consortium, Inc. ("ISC") .\" Copyright (c) 1996-2003 by Internet Software Consortium @@ -125,7 +126,13 @@ options acquired from the server are passed using the option name described in \fBdhcp-options\fR, except that dashes (\'-\') are replaced by underscores (\'_\') in order to make valid shell variables, and the variable names start with new_. So for example, the new subnet mask -would be passed in $new_subnet_mask. +would be passed in $new_subnet_mask. The options that the client +explicitly requested via a PRL or ORO option are passed with the same +option name as above but prepended with requested_ and with a value of 1, +or example requested_subnet_mask=1. No such variable is defined for +options not requested by the client or options that don't require a +request option, such as the ip address (*_ip_address) or expiration +time (*_expiry). .PP Before actually configuring the address, dhclient-script should somehow ARP for it and exit with a nonzero status if it receives a @@ -152,13 +159,13 @@ address not be used if it is identical to the bound IP address in this case. .SH RENEW When a binding has been renewed, the script is called as in BOUND, -except that in addition to all the variables starting with $new_, -there is another set of variables starting with $old_. Persistent -settings that may have changed need to be deleted - for example, if a -local route to the bound address is being configured, the old local -route should be deleted. If the default route has changed, the old default -route should be deleted. If the static routes have changed, the old -ones should be deleted. Otherwise, processing can be done as with +except that in addition to all the variables starting with $new_, and +$requested_ there is another set of variables starting with $old_. +Persistent settings that may have changed need to be deleted - for +example, if a local route to the bound address is being configured, +the old local route should be deleted. If the default route has changed, +the old default route should be deleted. If the static routes have changed, +the old ones should be deleted. Otherwise, processing can be done as with BOUND. .SH REBIND The DHCP client has rebound to a new DHCP server. This can be handled diff --git a/client/dhclient.c b/client/dhclient.c index fa8a3130..b9982561 100644 --- a/client/dhclient.c +++ b/client/dhclient.c @@ -1199,6 +1199,7 @@ void bind_lease (client) if (client -> active && client -> state != S_REBOOTING) script_write_params (client, "old_", client -> active); script_write_params (client, "new_", client -> new); + script_write_requested(client); if (client -> alias) script_write_params (client, "alias_", client -> alias); @@ -1305,6 +1306,7 @@ void state_stop (cpp) if (client->active) { script_init(client, "STOP", client->active->medium); script_write_params(client, "old_", client->active); + script_write_requested(client); if (client->alias) script_write_params(client, "alias_", client->alias); script_go(client); @@ -1779,6 +1781,7 @@ void dhcpnak (packet) */ script_init(client, "EXPIRE", NULL); script_write_params(client, "old_", client->active); + script_write_requested(client); if (client->alias) script_write_params(client, "alias_", client->alias); script_go(client); @@ -1947,6 +1950,7 @@ void state_panic (cpp) script_init (client, "TIMEOUT", client -> active -> medium); script_write_params (client, "new_", client -> active); + script_write_requested(client); if (client -> alias) script_write_params (client, "alias_", client -> alias); @@ -2085,6 +2089,7 @@ void send_request (cpp) /* Run the client script with the new parameters. */ script_init (client, "EXPIRE", (struct string_list *)0); script_write_params (client, "old_", client -> active); + script_write_requested(client); if (client -> alias) script_write_params (client, "alias_", client -> alias); @@ -3261,6 +3266,31 @@ void script_write_params (client, prefix, lease) client_envadd (client, prefix, "expiry", "%d", (int)(lease -> expiry)); } +/* + * Write out the environment variables for the objects that the + * client requested. If the object was requested the variable will be: + * requested_<option_name>=1 + * If it wasn't requested there won't be a variable. + */ +void script_write_requested(client) + struct client_state *client; +{ + int i; + struct option **req; + char name[256]; + req = client->config->requested_options; + + if (req == NULL) + return; + + for (i = 0 ; req[i] != NULL ; i++) { + if ((req[i]->universe == &dhcp_universe) && + dhcp_option_ev_name(name, sizeof(name), req[i])) { + client_envadd(client, "requested_", name, "%d", 1); + } + } +} + int script_go (client) struct client_state *client; { @@ -3568,6 +3598,7 @@ void do_release(client) script_write_params (client, "alias_", client -> alias); script_write_params (client, "old_", client -> active); + script_write_requested(client); script_go (client); } |