]> git.ipfire.org Git - thirdparty/dhcp.git/commitdiff
[master]
authorShawn Routhier <sar@isc.org>
Tue, 13 Nov 2012 20:56:02 +0000 (12:56 -0800)
committerShawn Routhier <sar@isc.org>
Tue, 13 Nov 2012 20:56:02 +0000 (12:56 -0800)
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]

RELNOTES
client/dhc6.c
client/dhclient-script.8
client/dhclient.c
includes/dhcpd.h

index 80e129294ffdd99306a873d1100404fe0591a823..a2e886bd786121e43372cff56d7c234ebd55853a 100644 (file)
--- a/RELNOTES
+++ b/RELNOTES
@@ -154,6 +154,12 @@ work on other platforms. Please report any problems and suggested fixes to
   server-identifier option to use for the NAK.
   [ISC-Bugs #25689]
 
+- 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.
+
                        Changes since 4.2.3
 
 ! Add a check for a null pointer before calling the regexec function.
index f9220486deb8e283f4321433e1343dfbb3f50208..8974e7a6afc385cc20bee62a9ad60566d2a3d75b 100644 (file)
@@ -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();
@@ -5100,6 +5109,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.
  */
index 5606d058635d491a075a2c1b28b435f0f067150d..f493e71f5af33a1565214f3784b46a158948ce78 100644 (file)
@@ -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
index fa8a3130ce59793f434958607298f8497964e24e..b998256108b5f5d473cc0791d28cbead7130b1ad 100644 (file)
@@ -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);
        }
 
index b8792fae2a150fd920a8c4c96a3657d1d77233ba..9945df04b67f561afd20919c5f53ef7685c60afb 100644 (file)
@@ -2721,6 +2721,7 @@ void client_option_envadd (struct option_cache *, struct packet *,
                           struct binding_scope **, struct universe *, void *);
 void script_write_params (struct client_state *, const char *,
                          struct client_lease *);
+void script_write_requested (struct client_state *);
 int script_go (struct client_state *);
 void client_envadd (struct client_state *,
                    const char *, const char *, const char *, ...)