force dhclient to release+reboot via HUP

Jeremiah Jinno jeremiah.jinno at gmail.com
Mon Nov 7 01:36:34 UTC 2011


Hello All,

I have been working on a way to force a running DHCP client to question the
lease provided by the server. In this way, a DHCP client could (within some
obvious constraints) test for server-side configuration changes.  To this
extent, I have created (and attached) a patch that will, I belive, achieve
these intentions.  However, I would greatly appreciate any critique, as I
am sure I may have overlooked some details.

An example use-case:
Boot a client into a dynamic-pool. Use your mechanism of choice (RPC, etc)
to obtain that client's MAC address(es).  Re-write a new static lease for
that client, changing the address. Ask the client to "hang up" (RPC, etc).
Client sends SIGHUP to the dhclient, which kicks off my new release-reboot
mechanism, picking up the new address... but most importantly, releasing
the old IP back into the dynamic pool.

Anyway, please let me know what you think.

Thank you,

 - Jeremiah D. Jinno





--- dhcp-4.0.1-original/client/dhclient.c       2008-10-24
11:11:59.000000000 -0700
+++ dhcp-4.0.1-hupclient/client/dhclient.c      2011-11-06
17:11:06.000000000 -0800
@@ -79,6 +79,7 @@ char *mockup_relay = NULL;
 static void usage PROTO ((void));

 static isc_result_t write_duid(struct data_string *duid);
+void sighup_handler(int sig);

 int
 main(int argc, char **argv) {
@@ -103,6 +104,9 @@ main(int argc, char **argv) {
 #endif /* DHCPv6 */
        char *s;

+        /* Setup signal handler */
+        signal(SIGHUP, sighup_handler);
+
        /* Initialize client globals. */
        memset(&default_duid, 0, sizeof(default_duid));

@@ -550,6 +554,27 @@ main(int argc, char **argv) {
        return 0;
 }

+void
+sighup_handler(int sig)
+{
+    struct interface_info *ip;
+    struct client_state *client;
+
+    log_info ("SIGHUP received. Starting release + renew process");
+
+    for (ip = interfaces ; ip ; ip = ip->next) {
+        ip->flags |= INTERFACE_RUNNING;
+        for (client = ip->client ; client ; client = client->next) {
+                do_release(client);
+                client->state = S_INIT;
+                add_timeout(cur_time + random() % 5,
+                            state_reboot, client, 0, 0);
+
+        }
+    }
+
+}
+
 static void usage ()
 {
        log_info ("%s %s", message, PACKAGE_VERSION);
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.isc.org/pipermail/dhcp-users/attachments/20111106/31e7e26b/attachment.html>


More information about the dhcp-users mailing list