1 diff -up dhcp-3.1.0/omapip/dispatch.c.libdhcp4client dhcp-3.1.0/omapip/dispatch.c
2 --- dhcp-3.1.0/omapip/dispatch.c.libdhcp4client 2005-03-17 15:15:21.000000000 -0500
3 +++ dhcp-3.1.0/omapip/dispatch.c 2007-10-24 14:55:56.000000000 -0400
6 #include <omapip/omapip_p.h>
8 -static omapi_io_object_t omapi_io_states;
9 +omapi_io_object_t omapi_io_states;
12 OMAPI_OBJECT_ALLOC (omapi_io,
13 diff -up dhcp-3.1.0/omapip/errwarn.c.libdhcp4client dhcp-3.1.0/omapip/errwarn.c
14 --- dhcp-3.1.0/omapip/errwarn.c.libdhcp4client 2007-10-24 14:55:56.000000000 -0400
15 +++ dhcp-3.1.0/omapip/errwarn.c 2007-10-24 14:57:16.000000000 -0400
16 @@ -39,6 +39,11 @@ static char copyright[] =
17 #include <omapip/omapip_p.h>
21 +#include <isc-dhcp/libdhcp_control.h>
22 +extern LIBDHCP_Control *libdhcp_control;
28 @@ -48,7 +53,9 @@ int log_priority;
29 void (*log_cleanup) (void);
31 #define CVT_BUF_MAX 1023
33 static char mbuf [CVT_BUF_MAX + 1];
35 static char fbuf [CVT_BUF_MAX + 1];
37 /* Log an error message, then exit... */
38 @@ -58,6 +65,16 @@ void log_fatal (const char * fmt, ... )
41 do_percentm (fbuf, fmt);
44 + if (libdhcp_control && (libdhcp_control->eh)) {
45 + va_start (list, fmt);
46 + libdhcp_control->eh(libdhcp_control, LOG_FATAL, fbuf, list);
48 + libdhcp_control->finished = 1;
53 /* %Audit% This is log output. %2004.06.17,Safe%
54 * If we truncate we hope the user can get a hint from the log.
55 @@ -91,6 +108,7 @@ void log_fatal (const char * fmt, ... )
62 /* Log an error message... */
63 @@ -101,6 +119,13 @@ int log_error (const char * fmt, ...)
65 do_percentm (fbuf, fmt);
68 + if (libdhcp_control && libdhcp_control->eh) {
69 + va_start (list, fmt);
70 + libdhcp_control->eh(libdhcp_control, LOG_ERR, fbuf, list);
74 /* %Audit% This is log output. %2004.06.17,Safe%
75 * If we truncate we hope the user can get a hint from the log.
77 @@ -116,7 +141,7 @@ int log_error (const char * fmt, ...)
78 write (STDERR_FILENO, mbuf, strlen (mbuf));
79 write (STDERR_FILENO, "\n", 1);
86 @@ -128,6 +153,13 @@ int log_info (const char *fmt, ...)
88 do_percentm (fbuf, fmt);
91 + if (libdhcp_control && libdhcp_control->eh) {
92 + va_start (list, fmt);
93 + libdhcp_control->eh(libdhcp_control, LOG_INFO, fbuf, list);
97 /* %Audit% This is log output. %2004.06.17,Safe%
98 * If we truncate we hope the user can get a hint from the log.
100 @@ -143,7 +175,7 @@ int log_info (const char *fmt, ...)
101 write (STDERR_FILENO, mbuf, strlen (mbuf));
102 write (STDERR_FILENO, "\n", 1);
109 @@ -154,7 +186,13 @@ int log_debug (const char *fmt, ...)
112 do_percentm (fbuf, fmt);
115 + if (libdhcp_control && libdhcp_control->eh) {
116 + va_start (list, fmt);
117 + libdhcp_control->eh(libdhcp_control, LOG_DEBUG, fbuf, list);
121 /* %Audit% This is log output. %2004.06.17,Safe%
122 * If we truncate we hope the user can get a hint from the log.
124 @@ -170,7 +208,7 @@ int log_debug (const char *fmt, ...)
125 write (STDERR_FILENO, mbuf, strlen (mbuf));
126 write (STDERR_FILENO, "\n", 1);
133 diff -up dhcp-3.1.0/omapip/alloc.c.libdhcp4client dhcp-3.1.0/omapip/alloc.c
134 --- dhcp-3.1.0/omapip/alloc.c.libdhcp4client 2006-02-24 18:16:30.000000000 -0500
135 +++ dhcp-3.1.0/omapip/alloc.c 2007-10-24 14:55:56.000000000 -0400
136 @@ -40,6 +40,33 @@ static char copyright[] =
138 #include <omapip/omapip_p.h>
141 +/* OK, we need a quick and dirty way of freeing all memory used by libdhcp.
142 + All pointers will be stored in a glibc tree on alloc, and removed on free.
143 + This is not too expensive for light single-call library use.
146 +extern void tdestroy (void *root, void (*free_node)(void *nodep));
147 +static void *all_pointers=0L;
148 +static int ptr_comparator(const void *p1, const void *p2) {
149 + return ((p1 == p2) ? 0 : ((p1 > p2) ? 1 : -1));
152 +static void record_pointer(void *ptr) {
153 + tsearch(ptr, &(all_pointers), ptr_comparator);
156 +static void forget_pointer(void *ptr) {
157 + tdelete(ptr, &(all_pointers), ptr_comparator);
160 +void omapi_free_all_pointers(void) {
161 + if (all_pointers != NULL)
162 + tdestroy(all_pointers, free);
163 + all_pointers = NULL;
167 #if defined (DEBUG_MEMORY_LEAKAGE) || defined (DEBUG_MALLOC_POOL) || \
168 defined (DEBUG_MEMORY_LEAKAGE_ON_EXIT)
169 struct dmalloc_preamble *dmalloc_list;
170 @@ -78,7 +105,9 @@ VOIDPTR dmalloc (size, file, line)
176 + record_pointer(foo);
180 bar = (VOIDPTR)(foo + DMDOFFSET);
181 @@ -200,6 +229,9 @@ void dfree (ptr, file, line)
182 0, (unsigned char *)ptr + DMDOFFSET, 0, 1, RC_MALLOC);
186 + forget_pointer(ptr);
190 #if defined (DEBUG_MEMORY_LEAKAGE) || defined (DEBUG_MALLOC_POOL) || \
191 diff -up dhcp-3.1.0/configure.libdhcp4client dhcp-3.1.0/configure
192 --- dhcp-3.1.0/configure.libdhcp4client 2005-03-17 15:14:55.000000000 -0500
193 +++ dhcp-3.1.0/configure 2007-10-24 14:55:56.000000000 -0400
194 @@ -246,7 +246,7 @@ if [ ! -d $workname ]; then
197 if [ x"$dirs" = x ]; then
198 - dirs=". client server relay common omapip dhcpctl minires dst"
199 + dirs=". client server relay common omapip dhcpctl minires dst libdhcp4client"
203 diff -up dhcp-3.1.0/dst/hmac_link.c.libdhcp4client dhcp-3.1.0/dst/hmac_link.c
204 --- dhcp-3.1.0/dst/hmac_link.c.libdhcp4client 2001-02-22 02:22:08.000000000 -0500
205 +++ dhcp-3.1.0/dst/hmac_link.c 2007-10-24 14:55:56.000000000 -0400
206 @@ -38,6 +38,10 @@ static const char rcsid[] = "$Header: /p
208 #include "dst_internal.h"
211 +extern void* dmalloc(size_t,char *,int);
217 @@ -86,7 +90,11 @@ dst_hmac_md5_sign(const int mode, DST_KE
220 if (mode & SIG_MODE_INIT)
222 + ctx = (MD5_CTX *) dmalloc(sizeof(*ctx),__FILE__,__LINE__);
224 ctx = (MD5_CTX *) malloc(sizeof(*ctx));
227 ctx = (MD5_CTX *) *context;
229 @@ -153,7 +161,11 @@ dst_hmac_md5_verify(const int mode, DST_
232 if (mode & SIG_MODE_INIT)
234 + ctx = (MD5_CTX *) dmalloc(sizeof(*ctx),__FILE__,__LINE__);
236 ctx = (MD5_CTX *) malloc(sizeof(*ctx));
239 ctx = (MD5_CTX *) *context;
241 @@ -217,8 +229,11 @@ dst_buffer_to_hmac_md5(DST_KEY *dkey, co
243 if (dkey == NULL || key == NULL || keylen < 0)
247 + if ((hkey = (HMAC_Key *) dmalloc(sizeof(HMAC_Key),__FILE__,__LINE__)) == NULL)
249 if ((hkey = (HMAC_Key *) malloc(sizeof(HMAC_Key))) == NULL)
253 memset(hkey->hk_ipad, 0, sizeof(hkey->hk_ipad));
254 @@ -347,7 +362,11 @@ dst_hmac_md5_key_from_file_format(DST_KE
259 + tmp = dmalloc(len + 2,__FILE__,__LINE__);
261 tmp = malloc(len + 2);
265 key_len = b64_pton((char *)tmp, key, HMAC_LEN+1); /* see above */
266 @@ -439,8 +458,11 @@ dst_hmac_md5_generate_key(DST_KEY *key,
269 len = size > 64 ? 64 : size;
271 + buff = dmalloc(len+8,__FILE__,__LINE__);
273 buff = malloc(len+8);
276 n = dst_random(DST_RAND_SEMI, len, buff);
277 n += dst_random(DST_RAND_KEY, len, buff);
278 if (n <= len) { /* failed getting anything */
279 @@ -463,7 +485,11 @@ dst_hmac_md5_init()
281 if (dst_t_func[KEY_HMAC_MD5] != NULL)
284 + dst_t_func[KEY_HMAC_MD5] = dmalloc(sizeof(struct dst_func),__FILE__,__LINE__);
286 dst_t_func[KEY_HMAC_MD5] = malloc(sizeof(struct dst_func));
288 if (dst_t_func[KEY_HMAC_MD5] == NULL)
290 memset(dst_t_func[KEY_HMAC_MD5], 0, sizeof(struct dst_func));
291 diff -up dhcp-3.1.0/common/discover.c.libdhcp4client dhcp-3.1.0/common/discover.c
292 --- dhcp-3.1.0/common/discover.c.libdhcp4client 2006-11-07 18:41:39.000000000 -0500
293 +++ dhcp-3.1.0/common/discover.c 2007-10-24 14:55:56.000000000 -0400
294 @@ -121,6 +121,10 @@ isc_result_t interface_initialize (omapi
295 register that interface with the network I/O software, figure out what
296 subnet it's on, and add it to the list of interfaces. */
299 +int have_setup_fallback = 0;
302 void discover_interfaces (state)
305 @@ -141,7 +145,9 @@ void discover_interfaces (state)
310 static int setup_fallback = 0;
314 /* Create an unbound datagram socket to do the SIOCGIFADDR ioctl on. */
315 @@ -695,10 +701,17 @@ void discover_interfaces (state)
316 log_fatal ("Not configured to listen on any interfaces!");
320 + if (!have_setup_fallback) {
321 + have_setup_fallback = 1;
322 + maybe_setup_fallback ();
325 if (!setup_fallback) {
327 maybe_setup_fallback ();
331 #if defined (HAVE_SETFD)
332 if (fallback_interface) {
333 diff -up dhcp-3.1.0/common/tree.c.libdhcp4client dhcp-3.1.0/common/tree.c
334 --- dhcp-3.1.0/common/tree.c.libdhcp4client 2007-02-14 17:41:22.000000000 -0500
335 +++ dhcp-3.1.0/common/tree.c 2007-10-24 14:55:56.000000000 -0400
336 @@ -41,7 +41,7 @@ static char copyright[] =
337 #include <omapip/omapip_p.h>
340 -struct binding_scope *global_scope;
341 +struct binding_scope __attribute__ ((visibility ("default"))) *global_scope;
343 static int do_host_lookup PROTO ((struct data_string *,
344 struct dns_host_entry *));
345 @@ -2761,6 +2761,7 @@ int evaluate_numeric_expression (result,
346 result of that evaluation. There should never be both an expression
347 and a valid data_string. */
349 +__attribute__ ((visibility ("default")))
350 int evaluate_option_cache (result, packet, lease, client_state,
351 in_options, cfg_options, scope, oc, file, line)
352 struct data_string *result;
353 diff -up dhcp-3.1.0/common/options.c.libdhcp4client dhcp-3.1.0/common/options.c
354 --- dhcp-3.1.0/common/options.c.libdhcp4client 2007-05-23 15:26:22.000000000 -0400
355 +++ dhcp-3.1.0/common/options.c 2007-10-24 14:55:56.000000000 -0400
356 @@ -2501,6 +2501,7 @@ int fqdn_option_space_encapsulate (resul
360 +__attribute__ ((visibility ("default")))
361 void option_space_foreach (struct packet *packet, struct lease *lease,
362 struct client_state *client_state,
363 struct option_state *in_options,
364 diff -up dhcp-3.1.0/common/dispatch.c.libdhcp4client dhcp-3.1.0/common/dispatch.c
365 --- dhcp-3.1.0/common/dispatch.c.libdhcp4client 2007-10-24 14:55:56.000000000 -0400
366 +++ dhcp-3.1.0/common/dispatch.c 2007-10-24 14:55:56.000000000 -0400
367 @@ -39,8 +39,24 @@ static char copyright[] =
371 -struct timeout *timeouts;
372 -static struct timeout *free_timeouts;
375 + struct timeout *next;
378 + void (*func) PROTO ((void *));
385 +static struct timeout *timeouts = NULL;
386 +static int ntimeouts = 0;
388 +static struct timeout *timeouts = NULL;
389 +static struct timeout *free_timeouts = NULL;
392 void set_time(TIME t)
394 @@ -53,9 +69,41 @@ void set_time(TIME t)
396 struct timeval *process_outstanding_timeouts (struct timeval *tvp)
400 + struct timeout t = { 0 };
402 /* Call any expired timeouts, and then if there's
403 still a timeout registered, time out the select
409 + for (i = 0; i < ntimeouts && timeouts[i].when <= cur_time;) {
410 + struct timeout *new_timeouts;
413 + memmove(&t, &timeouts[i], sizeof (t));
415 + n = (ntimeouts - i - 1) * sizeof (t);
416 + memmove(&timeouts[i+1], &timeouts[i], n);
418 + n = --ntimeouts * sizeof (t);
419 + new_timeouts = realloc(timeouts, n);
420 + /* XXX broken API, no way to return error here */
421 + if (new_timeouts || !n)
422 + timeouts = new_timeouts;
427 + t.unref(t.what, MDL);
429 + if (tvp && ntimeouts) {
430 + tvp->tv_sec = timeouts[0].when;
436 @@ -73,9 +121,15 @@ struct timeval *process_outstanding_time
437 tvp -> tv_sec = timeouts -> when;
447 return (struct timeval *)0;
451 /* Wait for packets to come in using select(). When one does, call
452 @@ -104,13 +158,28 @@ void add_timeout (when, where, what, ref
457 + struct timeout t = {
464 + struct timeout *new_timeouts;
467 struct timeout *t, *q;
470 /* See if this timeout supersedes an existing timeout. */
472 + for (i = 0; i < ntimeouts; i++) {
473 + struct timeout *q = &timeouts[i];
475 t = (struct timeout *)0;
476 for (q = timeouts; q; q = q -> next) {
477 - if ((where == NULL || q -> func == where) &&
478 - q -> what == what) {
479 + if ((where == NULL || q -> func == where) && q -> what == what) {
481 t -> next = q -> next;
483 @@ -119,7 +188,29 @@ void add_timeout (when, where, what, ref
490 + /* If this one is already in the list with a different time,
491 + * remove it and re-add */
492 + if ((where == NULL || q->func == where) &&
494 + size_t n = (--ntimeouts - i) * sizeof (*q);
495 + memmove(&t, q, sizeof (t));
498 + memmove(&timeouts[i], &timeouts[i+1], n);
501 + new_timeouts = realloc(timeouts, ntimeouts * sizeof (*q));
502 + /* XXX broken API, no way to return error here */
504 + timeouts = new_timeouts;
508 + add_timeout(when, where, what, ref, unref);
510 /* If we didn't supersede a timeout, allocate a timeout
513 @@ -128,7 +219,7 @@ void add_timeout (when, where, what, ref
514 free_timeouts = q -> next;
516 q = ((struct timeout *)
517 - dmalloc (sizeof (struct timeout), MDL));
518 + dmalloc (sizeof (struct timeout), MDL));
520 log_fatal ("add_timeout: no memory!");
522 @@ -158,22 +249,76 @@ void add_timeout (when, where, what, ref
523 if (t -> next -> when > q -> when) {
524 q -> next = t -> next;
529 + } else if (timeouts[i].when > when) {
536 + /* If we didn't supersede an existing timeout, then pos is set
537 + * to the timeout which will post after this one. Insert this
538 + * one before it. */
540 + new_timeouts = realloc(timeouts, sizeof (t) * (ntimeouts+1));
541 + /* XXX broken API, no way to return error here */
542 + if (new_timeouts) {
545 + * n = 10-3 * sizeof (t) = 7 * sizeof (t)
547 + size_t n = (ntimeouts - pos) * sizeof (t);
549 + timeouts = new_timeouts;
550 + memmove(&timeouts[pos+1], &timeouts[pos], n);
551 + memmove(&timeouts[pos], &t, sizeof (t));
557 q -> next = (struct timeout *)0;
561 void cancel_timeout (where, what)
562 void (*where) PROTO ((void *));
569 struct timeout *t, *q;
572 /* Look for this timeout on the list, and unlink it if we find it. */
574 + for (i = 0; i < ntimeouts; i++) {
575 + struct timeout *new_timeouts, *q = &timeouts[i];
577 + if (q->func == where && q->what == what) {
580 + memmove(&t, q, sizeof (t));
582 + n = (ntimeouts - i - 1) * sizeof (t);
583 + memmove(&timeouts[i+1], &timeouts[i], n);
585 + n = --ntimeouts * sizeof (t);
586 + new_timeouts = realloc(timeouts, n);
587 + /* XXX broken API, no way to return error here */
588 + if (new_timeouts || !n)
589 + timeouts = new_timeouts;
592 + t.unref(t.what, MDL);
596 t = (struct timeout *)0;
597 for (q = timeouts; q; q = q -> next) {
598 if (q -> func == where && q -> what == what) {
599 @@ -193,10 +338,15 @@ void cancel_timeout (where, what)
600 q -> next = free_timeouts;
606 void cancel_all_timeouts ()
609 + cur_time = TIME_MAX;
610 + process_outstanding_timeouts(NULL);
612 struct timeout *t, *n;
613 for (t = timeouts; t; t = n) {
615 @@ -205,13 +355,20 @@ void cancel_all_timeouts ()
616 t -> next = free_timeouts;
622 +__attribute__ ((visibility ("default")))
623 void relinquish_timeouts ()
627 + cancel_timeout(timeouts[0].func, timeouts[0].what);
629 struct timeout *t, *n;
630 for (t = free_timeouts; t; t = n) {
636 diff -up dhcp-3.1.0/common/alloc.c.libdhcp4client dhcp-3.1.0/common/alloc.c
637 --- dhcp-3.1.0/common/alloc.c.libdhcp4client 2006-06-01 16:23:17.000000000 -0400
638 +++ dhcp-3.1.0/common/alloc.c 2007-10-24 14:55:56.000000000 -0400
639 @@ -1013,7 +1013,11 @@ int executable_statement_reference (ptr,
644 +struct packet *free_packets;
646 static struct packet *free_packets;
649 #if defined (DEBUG_MEMORY_LEAKAGE) || \
650 defined (DEBUG_MEMORY_LEAKAGE_ON_EXIT)
651 diff -up dhcp-3.1.0/includes/dhcpd.h.libdhcp4client dhcp-3.1.0/includes/dhcpd.h
652 --- dhcp-3.1.0/includes/dhcpd.h.libdhcp4client 2007-10-24 14:55:56.000000000 -0400
653 +++ dhcp-3.1.0/includes/dhcpd.h 2007-10-24 14:55:56.000000000 -0400
654 @@ -1000,14 +1000,6 @@ struct hardware_link {
656 typedef void (*tvref_t)(void *, void *, const char *, int);
657 typedef void (*tvunref_t)(void *, const char *, int);
659 - struct timeout *next;
661 - void (*func) PROTO ((void *));
668 struct protocol *next;
669 @@ -1960,7 +1952,6 @@ extern void (*bootp_packet_handler) PROT
670 struct dhcp_packet *, unsigned,
672 struct iaddr, struct hardware *));
673 -extern struct timeout *timeouts;
674 extern omapi_object_type_t *dhcp_type_interface;
675 #if defined (TRACING)
676 trace_type_t *interface_trace;
677 diff -up dhcp-3.1.0/client/dhclient.c.libdhcp4client dhcp-3.1.0/client/dhclient.c
678 --- dhcp-3.1.0/client/dhclient.c.libdhcp4client 2007-10-24 14:55:56.000000000 -0400
679 +++ dhcp-3.1.0/client/dhclient.c 2007-10-24 14:56:20.000000000 -0400
680 @@ -82,16 +82,52 @@ int quiet=0;
682 int bootp_broadcast_always = 0;
685 +FILE *leaseFile = NULL;
688 extern u_int32_t default_requested_options[];
689 #ifdef EXTENDED_NEW_OPTION_INFO
690 int extended_option_environment = 0;
692 static void usage PROTO ((void));
695 +#include "isc-dhcp/libdhcp_control.h"
696 +LIBDHCP_Control *libdhcp_control;
697 +static void libdhcp_dispatch(void)
699 + struct timeval tv = { 0, 0 }, *tvp;
700 + isc_result_t status;
702 + /* Wait for a packet, or a timeout, or libdhcp being finished */
704 + tvp = process_outstanding_timeouts(&tv);
705 + status = omapi_one_dispatch(0, tvp);
707 + if (libdhcp_control && ((status == ISC_R_TIMEDOUT) || (libdhcp_control->timeout && (time(NULL) >= (libdhcp_control->timeout + libdhcp_control->now))))) {
708 + if (libdhcp_control->callback)
709 + libdhcp_control->callback(libdhcp_control, DHC_TIMEDOUT, NULL);
713 + } while ((status != ISC_R_TIMEDOUT) && ((!libdhcp_control) || (!(libdhcp_control->finished))));
716 +extern void omapi_free_all_pointers(void);
718 +__attribute__ ((visibility ("default")))
719 +int dhcpv4_client (libdhcp_ctl, argc, argv, envp)
720 + LIBDHCP_Control *libdhcp_ctl;
722 int main (argc, argv, envp)
728 + libdhcp_control = libdhcp_ctl;
733 @@ -120,6 +156,7 @@ int main (argc, argv, envp)
734 char *arg_conf = NULL;
735 int arg_conf_len = 0;
738 /* Make sure that file descriptors 0 (stdin), 1, (stdout), and
739 2 (stderr) are open. To do this, we assume that when we
740 open a file the lowest available file decriptor is used. */
741 @@ -143,6 +180,7 @@ int main (argc, argv, envp)
742 #if !(defined (DEBUG) || defined (SYSLOG_4_2) || defined (__CYGWIN32__))
743 setlogmask (LOG_UPTO (LOG_INFO));
747 /* Set up the OMAPI. */
748 status = omapi_init ();
749 @@ -439,6 +477,10 @@ int main (argc, argv, envp)
754 + if (libdhcp_control && (libdhcp_control->capability & DHCP_USE_PID_FILE))
758 log_info ("%s %s", message, DHCP_VERSION);
759 log_info (copyright);
760 @@ -449,6 +491,7 @@ int main (argc, argv, envp)
766 /* If we're given a relay agent address to insert, for testing
767 purposes, figure out what it is. */
768 @@ -680,11 +723,17 @@ int main (argc, argv, envp)
773 + if (libdhcp_control && (libdhcp_control->capability & DHCP_USE_LEASE_DATABASE)) {
775 /* Parse the lease database. */
776 read_client_leases ();
778 /* Rewrite the lease database... */
779 rewrite_client_leases ();
785 /* config_counter(&snd_counter, &rcv_counter); */
786 @@ -703,7 +752,7 @@ int main (argc, argv, envp)
788 /* Nothing more to do. */
789 log_info ("No broadcast interfaces found - exiting.");
793 } else if (!release_mode && !exit_mode) {
794 /* Call the script with the list of interfaces. */
795 @@ -799,6 +848,7 @@ int main (argc, argv, envp)
796 dmalloc_outstanding = 0;
800 /* If we're not supposed to wait before getting the address,
803 @@ -811,6 +861,126 @@ int main (argc, argv, envp)
805 /* Start dispatching packets and timeouts... */
808 + if (libdhcp_control) {
809 + if (libdhcp_control->timeout)
810 + libdhcp_control->now = time(NULL);
812 + libdhcp_control->now = 0;
815 + libdhcp_dispatch();
817 + /* libdhcp is finished with us. */
819 + /* close all file descriptors: */
820 + for (ip = interfaces; ip; ip = ip->next) {
821 + shutdown(ip->wfdesc, SHUT_RDWR);
824 + if (ip->rfdesc != ip->wfdesc)
828 + if (fallback_interface != 0) {
829 + ip = fallback_interface;
830 + shutdown(ip->wfdesc, SHUT_RDWR);
833 + if (ip->rfdesc != ip->wfdesc)
838 + fclose (leaseFile);
842 + char *current_pid_file = _PATH_DHCLIENT_PID;
844 + /* Free ALL allocated memory: */
845 + omapi_free_all_pointers();
847 + /* Re-Initialize globals: */
849 + client_env_count = 0;
850 + default_lease_time = 43200;
852 + dhcp_max_agent_option_packet_length = 0;
854 + memset(&(iaddr_any.iabuf[0]), '\0', 4);
855 + iaddr_broadcast.len = 4;
856 + memset(&(iaddr_broadcast.iabuf[0]), 0xff, 4);
857 + interfaces_requested = 0;
860 + libdhcp_control = 0;
867 + max_lease_time = 86400;
868 + path_dhclient_conf = _PATH_DHCLIENT_CONF;
869 + path_dhclient_db = _PATH_DHCLIENT_DB;
870 + path_dhclient_pid = _PATH_DHCLIENT_PID;
871 + strcpy(&(path_dhclient_script_array[0]), _PATH_DHCLIENT_SCRIPT);
872 + path_dhclient_script = path_dhclient_script_array;
874 + resolver_inited = 0;
876 + global_scope = NULL;
878 + group_name_hash = NULL;
880 + dummy_interfaces = NULL;
881 + fallback_interface = NULL;
882 + extern int have_setup_fallback;
883 + have_setup_fallback = 0;
884 + quiet_interface_discovery = 1;
888 + dhcp_type_interface = NULL;
889 + interface_vector = NULL;
890 + interface_count = 0;
894 + dhcp_type_interface = NULL;
895 + dhcp_type_group = NULL;
896 + dhcp_type_shared_network = NULL;
897 + dhcp_type_control = NULL;
898 + memset(&dhcp_universe, '\0', sizeof(struct universe));
899 + memset(&nwip_universe, '\0', sizeof(struct universe));
900 + memset(&fqdn_universe, '\0', sizeof(struct universe));
903 + universe_count = 0;
905 + config_universe = 0;
906 + extern struct hash_bucket *free_hash_buckets;
907 + free_hash_buckets = NULL;
908 + extern struct dhcp_packet *dhcp_free_list;
909 + dhcp_free_list = NULL;
910 + extern struct packet *packet_free_list;
911 + packet_free_list = NULL;
912 + extern struct binding_value *free_binding_values;
913 + free_binding_values = NULL;
914 + extern struct expression *free_expressions;
915 + free_expressions = NULL;
916 + extern struct option_cache *free_option_caches;
917 + free_option_caches = NULL;
918 + extern struct packet *free_packets;
919 + free_packets = NULL;
920 + extern pair free_pairs;
922 + extern omapi_io_object_t omapi_io_states;
923 + memset(&omapi_io_states, '\0', sizeof(omapi_io_states));
924 + dhcp_control_object = NULL;
925 + unlink(current_pid_file);
930 @@ -1203,7 +1373,20 @@ void dhcpack (packet)
931 if (client -> new -> rebind < cur_time)
932 client -> new -> rebind = TIME_MAX;
935 + /* We need the server's siaddr for the 'bootServer'
938 + u_int32_t set_siaddr = 0;
939 + set_siaddr = client->packet.siaddr.s_addr;
940 + client->packet.siaddr.s_addr = packet->raw->siaddr.s_addr;
946 + client->packet.siaddr.s_addr = set_siaddr;
950 void bind_lease (client)
951 @@ -1241,6 +1424,9 @@ void bind_lease (client)
956 + if (libdhcp_control && (libdhcp_control->capability & DHCP_USE_LEASE_DATABASE))
958 /* Write out the new lease. */
959 write_client_lease (client, client -> new, 0, 0);
961 @@ -1343,11 +1529,13 @@ int commit_leases ()
966 int write_lease (lease)
973 int write_host (host)
974 struct host_decl *host;
975 @@ -1957,6 +2145,10 @@ void state_panic (cpp)
976 tell the shell script that we failed to allocate an address,
977 and try again later. */
980 + script_init (client, "FAIL", (struct string_list *)0);
984 log_info ("Unable to obtain a lease on first try.%s",
986 @@ -2579,7 +2771,9 @@ void destroy_client_lease (lease)
987 free_client_lease (lease, MDL);
994 void rewrite_client_leases ()
996 @@ -2960,6 +3154,54 @@ void script_write_params (client, prefix
997 int script_go (client)
998 struct client_state *client;
1001 + struct string_list *sp;
1003 + if (libdhcp_control && libdhcp_control->callback) {
1007 + for (sp = client->env; sp; sp = sp->next)
1008 + if (strncmp(sp->string, "reason=", 7) == 0) {
1009 + reason = sp->string + 7;
1013 + if (strcmp(reason,"NBI") == 0)
1014 + dhcmsg = DHC4_NBI;
1015 + else if (strcmp(reason,"PREINIT") == 0)
1016 + dhcmsg = DHC4_PREINIT;
1017 + else if (strcmp(reason,"BOUND") == 0)
1018 + dhcmsg = DHC4_BOUND;
1019 + else if (strcmp(reason,"RENEW") == 0)
1020 + dhcmsg = DHC4_RENEW;
1021 + else if (strcmp(reason,"REBOOT") == 0)
1022 + dhcmsg = DHC4_REBOOT;
1023 + else if (strcmp(reason,"REBIND") == 0)
1024 + dhcmsg = DHC4_REBIND;
1025 + else if (strcmp(reason,"STOP") == 0)
1026 + dhcmsg = DHC4_STOP;
1027 + else if (strcmp(reason,"MEDIUM") == 0)
1028 + dhcmsg = DHC4_MEDIUM;
1029 + else if (strcmp(reason,"TIMEOUT") == 0)
1030 + dhcmsg = DHC4_TIMEOUT;
1031 + else if (strcmp(reason,"FAIL") == 0)
1032 + dhcmsg = DHC4_FAIL;
1033 + else if (strcmp(reason,"EXPIRE") == 0)
1034 + dhcmsg = DHC4_EXPIRE;
1035 + else if (strcmp(reason,"RELEASE") == 0)
1036 + dhcmsg = DHC4_RELEASE;
1038 + dhcmsg = DHC4_NBI;
1040 + (*libdhcp_control->callback) (libdhcp_control, dhcmsg, client);
1042 + if (libdhcp_control->decline)
1051 @@ -3038,6 +3280,7 @@ int script_go (client)
1052 GET_TIME (&cur_time);
1053 return (WIFEXITED (wstatus) ?
1054 WEXITSTATUS (wstatus) : -WTERMSIG (wstatus));
1058 void client_envadd (struct client_state *client,
1059 @@ -3120,6 +3363,9 @@ void go_daemon ()
1061 /* Don't become a daemon if the user requested otherwise. */
1064 + if (libdhcp_control && (libdhcp_control->capability & DHCP_USE_PID_FILE ))
1066 write_client_pid_file ();
1069 @@ -3129,6 +3375,10 @@ void go_daemon ()
1077 /* Stop logging to stderr... */
1080 diff -up dhcp-3.1.0/Makefile.dist.libdhcp4client dhcp-3.1.0/Makefile.dist
1081 --- dhcp-3.1.0/Makefile.dist.libdhcp4client 2005-03-17 15:14:54.000000000 -0500
1082 +++ dhcp-3.1.0/Makefile.dist 2007-10-24 14:55:56.000000000 -0400
1084 # http://www.isc.org/
1087 -SUBDIRS= common $(MINIRES) dst omapip server client relay dhcpctl
1088 +SUBDIRS= common $(MINIRES) dst omapip server client relay dhcpctl libdhcp4client
1091 @for dir in ${SUBDIRS}; do \
1092 --- dhcp-3.1.0/minires/Makefile.dist.orig 2007-12-25 12:41:11.744624000 +0100
1093 +++ dhcp-3.1.0/minires/Makefile.dist 2007-12-25 12:54:35.448726491 +0100
1095 ns_date.o ns_parse.o ns_sign.o ns_name.o ns_samedomain.o ns_verify.o
1097 INCLUDES = $(BINDINC) -I$(TOP)/includes
1098 -CFLAGS = $(DEBUG) $(PREDEFINES) $(INCLUDES) $(COPTS) -DHMAC_MD5 -DMINIRES_LIB
1099 +CFLAGS = $(DEBUG) $(PREDEFINES) $(INCLUDES) $(COPTS) -DHMAC_MD5 -DMINIRES_LIB -fPIC