1 --- dhcp-4.0.0/configure.ac.libdhcp4client 2007-12-14 08:24:56.000000000 -1000
2 +++ dhcp-4.0.0/configure.ac 2008-01-22 17:04:28.000000000 -1000
4 AC_INIT([DHCP], [4.0.0], [dhcp-users@isc.org])
7 +dnl (from glib's configure.in ...)
9 +dnl DHCP_MICRO_VERSION += 1;
10 +dnl DHCP_INTERFACE_AGE += 1;
11 +dnl DHCP_BINARY_AGE += 1;
12 +dnl if any functions have been added, set DHCP_INTERFACE_AGE to 0.
13 +dnl if backwards compatibility has been broken (e.g., functions removed,
14 +dnl function signatures changed),
15 +dnl set DHCP_BINARY_AGE and DHCP_INTERFACE_AGE to 0.
22 +DHCP_VERSION=$DHCP_MAJOR_VERSION.$DHCP_MINOR_VERSION.$DHCP_MICRO_VERSION$DHCP_VERSION_SUFFIX
23 +LT_RELEASE=$DHCP_MAJOR_VERSION.$DHCP_MINOR_VERSION
24 +LT_CURRENT=`expr $DHCP_MICRO_VERSION - $DHCP_INTERFACE_AGE`
25 +LT_REVISION=$DHCP_INTERFACE_AGE
26 +LT_AGE=`expr $DHCP_BINARY_AGE - $DHCP_INTERFACE_AGE`
27 +AC_SUBST(DHCP_VERSION)
30 +AC_SUBST(LT_REVISION)
33 # we specify "foreign" to avoid having to have the GNU mandated files,
34 # like AUTHORS, COPYING, and such
35 AM_INIT_AUTOMAKE([foreign])
36 @@ -20,7 +47,8 @@ if test "$GCC" = "yes"; then
43 AC_CONFIG_HEADERS([includes/config.h])
45 # we sometimes need to know byte order for building packets
46 --- dhcp-4.0.0/omapip/Makefile.am.libdhcp4client 2007-05-29 06:32:11.000000000 -1000
47 +++ dhcp-4.0.0/omapip/Makefile.am 2008-01-22 17:04:28.000000000 -1000
49 lib_LIBRARIES = libomapi.a
50 +noinst_LIBRARIES = libomapiLIBDHCP.a
51 noinst_PROGRAMS = svtest
53 libomapi_a_SOURCES = protocol.c buffer.c alloc.c result.c connection.c \
54 errwarn.c listener.c dispatch.c generic.c support.c \
55 handle.c message.c convert.c hash.c auth.c inet_addr.c \
56 array.c trace.c mrtrace.c toisc.c iscprint.c
58 +libomapiLIBDHCP_a_CFLAGS = -DLIBDHCP
59 +libomapiLIBDHCP_a_SOURCES = alloc.c array.c auth.c buffer.c connection.c \
60 + convert.c dispatch.c errwarn.c handle.c hash.c listener.c \
61 + mrtrace.c result.c support.c toisc.c trace.c generic.c message.c \
65 EXTRA_DIST = $(man_MANS)
67 --- dhcp-4.1.0a1/omapip/dispatch.c~ 2008-04-27 16:03:42.000000000 +0300
68 +++ dhcp-4.1.0a1/omapip/dispatch.c 2008-04-27 16:04:03.347565427 +0300
70 #include <omapip/omapip_p.h>
73 -static omapi_io_object_t omapi_io_states;
74 +omapi_io_object_t omapi_io_states;
75 struct timeval cur_tv;
77 struct eventqueue *rw_queue_empty;
78 diff -up dhcp-4.0.0/omapip/errwarn.c.libdhcp4client dhcp-4.0.0/omapip/errwarn.c
79 --- dhcp-4.0.0/omapip/errwarn.c.libdhcp4client 2008-01-22 17:04:28.000000000 -1000
80 +++ dhcp-4.0.0/omapip/errwarn.c 2008-01-22 17:04:28.000000000 -1000
86 +#include <isc-dhcp/libdhcp_control.h>
87 +extern LIBDHCP_Control *libdhcp_control;
93 @@ -46,7 +51,9 @@ int log_priority;
94 void (*log_cleanup) (void);
96 #define CVT_BUF_MAX 1023
98 static char mbuf [CVT_BUF_MAX + 1];
100 static char fbuf [CVT_BUF_MAX + 1];
102 /* Log an error message, then exit... */
103 @@ -56,6 +63,16 @@ void log_fatal (const char * fmt, ... )
106 do_percentm (fbuf, fmt);
109 + if (libdhcp_control && (libdhcp_control->eh)) {
110 + va_start (list, fmt);
111 + libdhcp_control->eh(libdhcp_control, LOG_FATAL, fbuf, list);
113 + libdhcp_control->finished = 1;
118 /* %Audit% This is log output. %2004.06.17,Safe%
119 * If we truncate we hope the user can get a hint from the log.
120 @@ -89,6 +106,7 @@ void log_fatal (const char * fmt, ... )
127 /* Log an error message... */
128 @@ -99,6 +117,13 @@ int log_error (const char * fmt, ...)
130 do_percentm (fbuf, fmt);
133 + if (libdhcp_control && libdhcp_control->eh) {
134 + va_start (list, fmt);
135 + libdhcp_control->eh(libdhcp_control, LOG_ERR, fbuf, list);
139 /* %Audit% This is log output. %2004.06.17,Safe%
140 * If we truncate we hope the user can get a hint from the log.
142 @@ -114,7 +139,7 @@ int log_error (const char * fmt, ...)
143 write (STDERR_FILENO, mbuf, strlen (mbuf));
144 write (STDERR_FILENO, "\n", 1);
151 @@ -126,6 +151,13 @@ int log_info (const char *fmt, ...)
153 do_percentm (fbuf, fmt);
156 + if (libdhcp_control && libdhcp_control->eh) {
157 + va_start (list, fmt);
158 + libdhcp_control->eh(libdhcp_control, LOG_INFO, fbuf, list);
162 /* %Audit% This is log output. %2004.06.17,Safe%
163 * If we truncate we hope the user can get a hint from the log.
165 @@ -141,7 +173,7 @@ int log_info (const char *fmt, ...)
166 write (STDERR_FILENO, mbuf, strlen (mbuf));
167 write (STDERR_FILENO, "\n", 1);
174 @@ -152,7 +184,13 @@ int log_debug (const char *fmt, ...)
177 do_percentm (fbuf, fmt);
180 + if (libdhcp_control && libdhcp_control->eh) {
181 + va_start (list, fmt);
182 + libdhcp_control->eh(libdhcp_control, LOG_DEBUG, fbuf, list);
186 /* %Audit% This is log output. %2004.06.17,Safe%
187 * If we truncate we hope the user can get a hint from the log.
189 @@ -168,7 +206,7 @@ int log_debug (const char *fmt, ...)
190 write (STDERR_FILENO, mbuf, strlen (mbuf));
191 write (STDERR_FILENO, "\n", 1);
198 --- dhcp-4.0.0/omapip/alloc.c.libdhcp4client 2007-07-12 20:43:42.000000000 -1000
199 +++ dhcp-4.0.0/omapip/alloc.c 2008-01-22 17:04:28.000000000 -1000
202 #include <omapip/omapip_p.h>
205 +/* OK, we need a quick and dirty way of freeing all memory used by libdhcp.
206 + All pointers will be stored in a glibc tree on alloc, and removed on free.
207 + This is not too expensive for light single-call library use.
210 +extern void tdestroy (void *root, void (*free_node)(void *nodep));
211 +static void *all_pointers=0L;
212 +static int ptr_comparator(const void *p1, const void *p2) {
213 + return ((p1 == p2) ? 0 : ((p1 > p2) ? 1 : -1));
216 +static void record_pointer(void *ptr) {
217 + tsearch(ptr, &(all_pointers), ptr_comparator);
220 +static void forget_pointer(void *ptr) {
221 + tdelete(ptr, &(all_pointers), ptr_comparator);
224 +void omapi_free_all_pointers(void) {
225 + if (all_pointers != NULL)
226 + tdestroy(all_pointers, free);
227 + all_pointers = NULL;
231 #if defined (DEBUG_MEMORY_LEAKAGE) || defined (DEBUG_MALLOC_POOL) || \
232 defined (DEBUG_MEMORY_LEAKAGE_ON_EXIT)
233 struct dmalloc_preamble *dmalloc_list;
234 @@ -72,7 +99,9 @@ dmalloc(unsigned size, const char *file,
240 + record_pointer(foo);
244 bar = (void *)(foo + DMDOFFSET);
245 @@ -191,6 +220,9 @@ dfree(void *ptr, const char *file, int l
246 0, (unsigned char *)ptr + DMDOFFSET, 0, 1, RC_MALLOC);
250 + forget_pointer(ptr);
254 #if defined (DEBUG_MEMORY_LEAKAGE) || defined (DEBUG_MALLOC_POOL) || \
255 --- dhcp-4.0.0/dst/Makefile.am.libdhcp4client 2008-01-22 17:04:28.000000000 -1000
256 +++ dhcp-4.0.0/dst/Makefile.am 2008-01-22 17:04:28.000000000 -1000
257 @@ -2,7 +2,7 @@ AM_CPPFLAGS = -DMINIRES_LIB -DHMAC_MD5
259 lib_LIBRARIES = libdst.a
261 -noinst_LIBRARIES = libdstnomd5.a
262 +noinst_LIBRARIES = libdstnomd5.a libdstLIBDHCP.a
264 libdst_a_SOURCES = dst_support.c dst_api.c hmac_link.c md5_dgst.c \
266 @@ -10,4 +10,8 @@ libdst_a_SOURCES = dst_support.c dst_api
267 libdstnomd5_a_SOURCES = dst_support.c dst_api.c hmac_link.c \
270 +libdstLIBDHCP_a_CFLAGS = -DLIBDHCP
271 +libdstLIBDHCP_a_SOURCES = dst_support.c dst_api.c hmac_link.c md5_dgst.c \
274 EXTRA_DIST = dst_internal.h md5.h md5_locl.h
275 --- dhcp-4.0.0/dst/hmac_link.c.libdhcp4client 2007-12-05 14:50:22.000000000 -1000
276 +++ dhcp-4.0.0/dst/hmac_link.c 2008-01-22 17:04:28.000000000 -1000
277 @@ -39,6 +39,10 @@ static const char rcsid[] = "$Header: /p
279 #include "dst_internal.h"
282 +extern void* dmalloc(size_t,char *,int);
288 @@ -87,7 +91,11 @@ dst_hmac_md5_sign(const int mode, DST_KE
291 if (mode & SIG_MODE_INIT)
293 + ctx = (MD5_CTX *) dmalloc(sizeof(*ctx),__FILE__,__LINE__);
295 ctx = (MD5_CTX *) malloc(sizeof(*ctx));
298 ctx = (MD5_CTX *) *context;
300 @@ -154,7 +162,11 @@ dst_hmac_md5_verify(const int mode, DST_
303 if (mode & SIG_MODE_INIT)
305 + ctx = (MD5_CTX *) dmalloc(sizeof(*ctx),__FILE__,__LINE__);
307 ctx = (MD5_CTX *) malloc(sizeof(*ctx));
310 ctx = (MD5_CTX *) *context;
312 @@ -218,8 +230,11 @@ dst_buffer_to_hmac_md5(DST_KEY *dkey, co
314 if (dkey == NULL || key == NULL || keylen < 0)
318 + if ((hkey = (HMAC_Key *) dmalloc(sizeof(HMAC_Key),__FILE__,__LINE__)) == NULL)
320 if ((hkey = (HMAC_Key *) malloc(sizeof(HMAC_Key))) == NULL)
324 memset(hkey->hk_ipad, 0, sizeof(hkey->hk_ipad));
325 @@ -348,7 +363,11 @@ dst_hmac_md5_key_from_file_format(DST_KE
330 + tmp = dmalloc(len + 2,__FILE__,__LINE__);
332 tmp = malloc(len + 2);
336 key_len = b64_pton((char *)tmp, key, HMAC_LEN+1); /* see above */
337 @@ -440,8 +459,11 @@ dst_hmac_md5_generate_key(DST_KEY *key,
340 len = size > 64 ? 64 : size;
342 + buff = dmalloc(len+8,__FILE__,__LINE__);
344 buff = malloc(len+8);
347 n = dst_random(DST_RAND_SEMI, len, buff);
348 n += dst_random(DST_RAND_KEY, len, buff);
349 if (n <= len) { /* failed getting anything */
350 @@ -464,7 +486,11 @@ dst_hmac_md5_init()
352 if (dst_t_func[KEY_HMAC_MD5] != NULL)
355 + dst_t_func[KEY_HMAC_MD5] = dmalloc(sizeof(struct dst_func),__FILE__,__LINE__);
357 dst_t_func[KEY_HMAC_MD5] = malloc(sizeof(struct dst_func));
359 if (dst_t_func[KEY_HMAC_MD5] == NULL)
361 memset(dst_t_func[KEY_HMAC_MD5], 0, sizeof(struct dst_func));
362 --- dhcp-4.0.0/common/Makefile.am.libdhcp4client 2007-11-16 01:04:11.000000000 -1000
363 +++ dhcp-4.0.0/common/Makefile.am 2008-01-22 17:04:28.000000000 -1000
365 AM_CPPFLAGS = -I.. -DLOCALSTATEDIR='"@localstatedir@"'
367 -noinst_LIBRARIES = libdhcp.a
368 +noinst_LIBRARIES = libdhcp.a libdhcpLIBDHCP.a
369 libdhcp_a_SOURCES = alloc.c bpf.c comapi.c conflex.c ctrace.c discover.c \
370 dispatch.c dlpi.c dns.c ethernet.c execute.c fddi.c \
371 icmp.c inet.c lpf.c memory.c nit.c options.c packet.c \
372 parse.c print.c raw.c resolv.c socket.c tables.c tr.c \
374 +libdhcpLIBDHCP_a_CFLAGS = -DLIBDHCP
375 +libdhcpLIBDHCP_a_SOURCES = alloc.c bpf.c comapi.c conflex.c ctrace.c \
376 + discover.c dispatch.c dlpi.c dns.c ethernet.c \
377 + execute.c inet.c lpf.c memory.c nit.c options.c \
378 + packet.c parse.c print.c resolv.c socket.c \
379 + tables.c tr.c tree.c upf.c
380 man_MANS = dhcp-eval.5 dhcp-options.5
381 EXTRA_DIST = $(man_MANS)
383 --- dhcp-4.0.0/common/discover.c.libdhcp4client 2007-10-05 12:29:51.000000000 -1000
384 +++ dhcp-4.0.0/common/discover.c 2008-01-22 17:04:28.000000000 -1000
385 @@ -883,6 +883,10 @@ add_ipv6_addr_to_interface(struct interf
386 register that interface with the network I/O software, figure out what
387 subnet it's on, and add it to the list of interfaces. */
390 +int have_setup_fallback = 0;
394 discover_interfaces(int state) {
395 struct iface_conf_list ifaces;
396 @@ -902,7 +906,9 @@ discover_interfaces(int state) {
401 static int setup_fallback = 0;
404 if (!begin_iface_scan(&ifaces)) {
405 log_fatal("Can't get list of interfaces.");
406 @@ -1242,10 +1248,17 @@ discover_interfaces(int state) {
407 log_fatal ("Not configured to listen on any interfaces!");
411 + if ((local_family == AF_INET) && !have_setup_fallback) {
412 + have_setup_fallback = 1;
413 + maybe_setup_fallback ();
416 if ((local_family == AF_INET) && !setup_fallback) {
418 maybe_setup_fallback();
422 #if defined (F_SETFD)
423 if (fallback_interface) {
424 --- dhcp-4.0.0/common/tree.c.libdhcp4client 2007-08-22 03:41:37.000000000 -1000
425 +++ dhcp-4.0.0/common/tree.c 2008-01-22 17:04:28.000000000 -1000
430 -struct binding_scope *global_scope;
431 +struct binding_scope __attribute__ ((visibility ("default"))) *global_scope;
433 static int do_host_lookup PROTO ((struct data_string *,
434 struct dns_host_entry *));
435 @@ -2859,6 +2859,7 @@ int evaluate_numeric_expression (result,
436 result of that evaluation. There should never be both an expression
437 and a valid data_string. */
439 +__attribute__ ((visibility ("default")))
440 int evaluate_option_cache (result, packet, lease, client_state,
441 in_options, cfg_options, scope, oc, file, line)
442 struct data_string *result;
443 --- dhcp-4.0.0/common/options.c.libdhcp4client 2007-11-30 11:51:43.000000000 -1000
444 +++ dhcp-4.0.0/common/options.c 2008-01-22 17:04:28.000000000 -1000
445 @@ -3392,6 +3392,7 @@ fqdn6_universe_decode(struct option_stat
449 +__attribute__ ((visibility ("default")))
450 void option_space_foreach (struct packet *packet, struct lease *lease,
451 struct client_state *client_state,
452 struct option_state *in_options,
453 --- dhcp-4.0.0/common/dispatch.c.libdhcp4client 2008-01-22 17:04:28.000000000 -1000
454 +++ dhcp-4.0.0/common/dispatch.c 2008-01-22 17:04:28.000000000 -1000
459 -struct timeout *timeouts;
460 -static struct timeout *free_timeouts;
463 + struct timeout *next;
466 + void (*func) PROTO ((void *));
473 +static struct timeout *timeouts = NULL;
474 +static int ntimeouts = 0;
476 +static struct timeout *timeouts = NULL;
477 +static struct timeout *free_timeouts = NULL;
480 void set_time(TIME t)
482 @@ -48,9 +64,41 @@ void set_time(TIME t)
484 struct timeval *process_outstanding_timeouts (struct timeval *tvp)
488 + struct timeout t = { 0 };
490 /* Call any expired timeouts, and then if there's
491 still a timeout registered, time out the select
497 + for (i = 0; i < ntimeouts && timeouts[i].when <= cur_time;) {
498 + struct timeout *new_timeouts;
501 + memmove(&t, &timeouts[i], sizeof (t));
503 + n = (ntimeouts - i - 1) * sizeof (t);
504 + memmove(&timeouts[i+1], &timeouts[i], n);
506 + n = --ntimeouts * sizeof (t);
507 + new_timeouts = realloc(timeouts, n);
508 + /* XXX broken API, no way to return error here */
509 + if (new_timeouts || !n)
510 + timeouts = new_timeouts;
515 + t.unref(t.what, MDL);
517 + if (tvp && ntimeouts) {
518 + tvp->tv_sec = timeouts[0].when;
524 @@ -68,9 +116,15 @@ struct timeval *process_outstanding_time
525 tvp -> tv_sec = timeouts -> when;
535 return (struct timeval *)0;
539 /* Wait for packets to come in using select(). When one does, call
540 @@ -99,13 +153,28 @@ void add_timeout (when, where, what, ref
545 + struct timeout t = {
552 + struct timeout *new_timeouts;
555 struct timeout *t, *q;
558 /* See if this timeout supersedes an existing timeout. */
560 + for (i = 0; i < ntimeouts; i++) {
561 + struct timeout *q = &timeouts[i];
563 t = (struct timeout *)0;
564 for (q = timeouts; q; q = q -> next) {
565 - if ((where == NULL || q -> func == where) &&
566 - q -> what == what) {
567 + if ((where == NULL || q -> func == where) && q -> what == what) {
569 t -> next = q -> next;
571 @@ -114,7 +183,29 @@ void add_timeout (when, where, what, ref
578 + /* If this one is already in the list with a different time,
579 + * remove it and re-add */
580 + if ((where == NULL || q->func == where) &&
582 + size_t n = (--ntimeouts - i) * sizeof (*q);
583 + memmove(&t, q, sizeof (t));
586 + memmove(&timeouts[i], &timeouts[i+1], n);
589 + new_timeouts = realloc(timeouts, ntimeouts * sizeof (*q));
590 + /* XXX broken API, no way to return error here */
592 + timeouts = new_timeouts;
596 + add_timeout(when, where, what, ref, unref);
598 /* If we didn't supersede a timeout, allocate a timeout
601 @@ -123,7 +214,7 @@ void add_timeout (when, where, what, ref
602 free_timeouts = q -> next;
604 q = ((struct timeout *)
605 - dmalloc (sizeof (struct timeout), MDL));
606 + dmalloc (sizeof (struct timeout), MDL));
608 log_fatal ("add_timeout: no memory!");
610 @@ -153,22 +244,76 @@ void add_timeout (when, where, what, ref
611 if (t -> next -> when > q -> when) {
612 q -> next = t -> next;
617 + } else if (timeouts[i].when > when) {
624 + /* If we didn't supersede an existing timeout, then pos is set
625 + * to the timeout which will post after this one. Insert this
626 + * one before it. */
628 + new_timeouts = realloc(timeouts, sizeof (t) * (ntimeouts+1));
629 + /* XXX broken API, no way to return error here */
630 + if (new_timeouts) {
633 + * n = 10-3 * sizeof (t) = 7 * sizeof (t)
635 + size_t n = (ntimeouts - pos) * sizeof (t);
637 + timeouts = new_timeouts;
638 + memmove(&timeouts[pos+1], &timeouts[pos], n);
639 + memmove(&timeouts[pos], &t, sizeof (t));
645 q -> next = (struct timeout *)0;
649 void cancel_timeout (where, what)
650 void (*where) PROTO ((void *));
657 struct timeout *t, *q;
660 /* Look for this timeout on the list, and unlink it if we find it. */
662 + for (i = 0; i < ntimeouts; i++) {
663 + struct timeout *new_timeouts, *q = &timeouts[i];
665 + if (q->func == where && q->what == what) {
668 + memmove(&t, q, sizeof (t));
670 + n = (ntimeouts - i - 1) * sizeof (t);
671 + memmove(&timeouts[i+1], &timeouts[i], n);
673 + n = --ntimeouts * sizeof (t);
674 + new_timeouts = realloc(timeouts, n);
675 + /* XXX broken API, no way to return error here */
676 + if (new_timeouts || !n)
677 + timeouts = new_timeouts;
680 + t.unref(t.what, MDL);
684 t = (struct timeout *)0;
685 for (q = timeouts; q; q = q -> next) {
686 if (q -> func == where && q -> what == what) {
687 @@ -188,10 +333,15 @@ void cancel_timeout (where, what)
688 q -> next = free_timeouts;
694 void cancel_all_timeouts ()
697 + cur_time = TIME_MAX;
698 + process_outstanding_timeouts(NULL);
700 struct timeout *t, *n;
701 for (t = timeouts; t; t = n) {
703 @@ -200,13 +350,20 @@ void cancel_all_timeouts ()
704 t -> next = free_timeouts;
710 +__attribute__ ((visibility ("default")))
711 void relinquish_timeouts ()
715 + cancel_timeout(timeouts[0].func, timeouts[0].what);
717 struct timeout *t, *n;
718 for (t = free_timeouts; t; t = n) {
724 --- dhcp-4.0.0/common/alloc.c.libdhcp4client 2007-10-23 14:54:11.000000000 -1000
725 +++ dhcp-4.0.0/common/alloc.c 2008-01-22 17:04:28.000000000 -1000
726 @@ -1004,7 +1004,11 @@ int executable_statement_reference (ptr,
731 +struct packet *free_packets;
733 static struct packet *free_packets;
736 #if defined (DEBUG_MEMORY_LEAKAGE) || \
737 defined (DEBUG_MEMORY_LEAKAGE_ON_EXIT)
738 --- dhcp-4.1.0a1/includes/dhcpd.h~ 2008-04-27 15:59:29.000000000 +0300
739 +++ dhcp-4.1.0a1/includes/dhcpd.h 2008-04-27 16:00:57.528854928 +0300
740 @@ -1211,14 +1211,6 @@
742 typedef void (*tvref_t)(void *, void *, const char *, int);
743 typedef void (*tvunref_t)(void *, const char *, int);
745 - struct timeout *next;
746 - struct timeval when;
747 - void (*func) PROTO ((void *));
754 struct eventqueue *next;
755 @@ -1664,7 +1656,6 @@ extern const char *path_dhcpd_pid;
757 extern int dhcp_max_agent_option_packet_length;
759 -int main(int, char **);
760 void postconf_initialization(int);
761 void postdb_startup(void);
762 void cleanup PROTO ((void));
763 @@ -2337,7 +2328,6 @@ extern void (*bootp_packet_handler) PROT
764 extern void (*dhcpv6_packet_handler)(struct interface_info *,
766 int, const struct iaddr *, isc_boolean_t);
767 -extern struct timeout *timeouts;
768 extern omapi_object_type_t *dhcp_type_interface;
769 #if defined (TRACING)
770 extern trace_type_t *interface_trace;
771 @@ -2392,6 +2382,10 @@ extern struct universe dhcpv6_universe;
772 extern struct universe nwip_universe;
773 extern struct universe fqdn_universe;
774 extern struct universe vsio_universe;
775 +extern struct universe vendor_class_universe;
776 +extern struct universe vendor_universe;
777 +extern struct universe isc_universe;
778 +extern struct universe isc6_universe;
779 extern int dhcp_option_default_priority_list [];
780 extern int dhcp_option_default_priority_list_count;
781 extern const char *hardware_types [256];
782 --- dhcp-4.0.0/client/Makefile.am.libdhcp4client 2007-12-12 09:23:42.000000000 -1000
783 +++ dhcp-4.0.0/client/Makefile.am 2008-01-22 17:04:28.000000000 -1000
785 dist_sysconf_DATA = dhclient.conf
786 sbin_PROGRAMS = dhclient
787 +lib_LTLIBRARIES = libdhcp4client.la
788 dhclient_SOURCES = clparse.c dhclient.c dhc6.c \
789 scripts/bsdos scripts/freebsd scripts/linux scripts/netbsd \
790 scripts/nextstep scripts/openbsd scripts/solaris
791 dhclient_LDADD = ../common/libdhcp.a ../minires/libres.a \
792 ../omapip/libomapi.a ../dst/libdst.a
793 +libdhcp4client_la_CFLAGS = -DLIBDHCP -DLOCALSTATEDIR='"@localstatedir@"'
794 +libdhcp4client_la_LDFLAGS = -version-info \
795 + $(LT_CURRENT):$(LT_REVISION):$(LT_AGE) \
796 + -release $(LT_RELEASE)
797 +libdhcp4client_la_SOURCES = clparse.c dhclient.c dhc6.c
798 +libdhcp4client_la_LIBADD = ../common/libdhcpLIBDHCP.a ../minires/libres.a \
799 + ../omapip/libomapiLIBDHCP.a ../dst/libdstLIBDHCP.a
800 man_MANS = dhclient.8 dhclient-script.8 dhclient.conf.5 dhclient.leases.5
801 EXTRA_DIST = $(man_MANS)
803 --- dhcp-4.0.0/client/dhclient.c.libdhcp4client 2008-01-22 17:04:28.000000000 -1000
804 +++ dhcp-4.0.0/client/dhclient.c 2008-01-22 17:05:47.000000000 -1000
805 @@ -83,14 +83,50 @@ int nowait=0;
806 char *mockup_relay = NULL;
807 int bootp_broadcast_always = 0;
810 +FILE *leaseFile = NULL;
813 extern u_int32_t default_requested_options[];
815 static void usage PROTO ((void));
817 static isc_result_t write_duid(struct data_string *duid);
820 -main(int argc, char **argv) {
822 +#include "isc-dhcp/libdhcp_control.h"
823 +LIBDHCP_Control *libdhcp_control;
824 +static void libdhcp_dispatch(void)
826 + struct timeval tv = { 0, 0 }, *tvp;
827 + isc_result_t status;
829 + /* Wait for a packet, or a timeout, or libdhcp being finished */
831 + tvp = process_outstanding_timeouts(&tv);
832 + status = omapi_one_dispatch(0, tvp);
834 + if (libdhcp_control && ((status == ISC_R_TIMEDOUT) || (libdhcp_control->timeout && (time(NULL) >= (libdhcp_control->timeout + libdhcp_control->now))))) {
835 + if (libdhcp_control->callback)
836 + libdhcp_control->callback(libdhcp_control, DHC_TIMEDOUT, NULL);
840 + } while ((status != ISC_R_TIMEDOUT) && ((!libdhcp_control) || (!(libdhcp_control->finished))));
843 +extern void omapi_free_all_pointers(void);
845 +__attribute__ ((visibility ("default")))
846 +int dhcpv4_client (LIBDHCP_Control *libdhcp_ctl, int argc, char **argv,
849 +int main(int argc, char **argv, char **envp)
853 + libdhcp_control = libdhcp_ctl;
857 struct interface_info *ip;
858 @@ -122,6 +158,7 @@ main(int argc, char **argv) {
859 /* Initialize client globals. */
860 memset(&default_duid, 0, sizeof(default_duid));
863 /* Make sure that file descriptors 0 (stdin), 1, (stdout), and
864 2 (stderr) are open. To do this, we assume that when we
865 open a file the lowest available file descriptor is used. */
866 @@ -140,6 +177,7 @@ main(int argc, char **argv) {
867 #if !(defined (DEBUG) || defined (__CYGWIN32__))
868 setlogmask (LOG_UPTO (LOG_INFO));
872 /* Set up the OMAPI. */
873 status = omapi_init ();
874 @@ -485,8 +523,12 @@ main(int argc, char **argv) {
879 + if (libdhcp_control && (libdhcp_control->capability & DHCP_USE_PID_FILE))
881 write_client_pid_file();
885 log_info ("%s %s", message, PACKAGE_VERSION);
886 log_info (copyright);
887 @@ -497,6 +539,7 @@ main(int argc, char **argv) {
889 quiet_interface_discovery = 1;
893 /* If we're given a relay agent address to insert, for testing
894 purposes, figure out what it is. */
895 @@ -702,11 +745,17 @@ main(int argc, char **argv) {
900 + if (libdhcp_control && (libdhcp_control->capability & DHCP_USE_LEASE_DATABASE)) {
902 /* Parse the lease database. */
903 read_client_leases ();
905 /* Rewrite the lease database... */
906 rewrite_client_leases ();
912 /* config_counter(&snd_counter, &rcv_counter); */
913 @@ -725,7 +774,7 @@ main(int argc, char **argv) {
915 /* Nothing more to do. */
916 log_info ("No broadcast interfaces found - exiting.");
920 } else if (!release_mode && !exit_mode) {
921 /* Call the script with the list of interfaces. */
922 @@ -863,6 +912,7 @@ main(int argc, char **argv) {
923 dmalloc_outstanding = 0;
927 /* If we're not supposed to wait before getting the address,
930 @@ -875,6 +925,132 @@ main(int argc, char **argv) {
932 /* Start dispatching packets and timeouts... */
935 + if (libdhcp_control) {
936 + if (libdhcp_control->timeout)
937 + libdhcp_control->now = time(NULL);
939 + libdhcp_control->now = 0;
942 + libdhcp_dispatch();
944 + /* libdhcp is finished with us. */
946 + /* close all file descriptors: */
947 + for (ip = interfaces; ip; ip = ip->next) {
948 + shutdown(ip->wfdesc, SHUT_RDWR);
951 + if (ip->rfdesc != ip->wfdesc)
955 + if (fallback_interface != 0) {
956 + ip = fallback_interface;
957 + shutdown(ip->wfdesc, SHUT_RDWR);
960 + if (ip->rfdesc != ip->wfdesc)
965 + fclose (leaseFile);
969 + char *current_pid_file = _PATH_DHCLIENT_PID;
971 + /* Free ALL allocated memory: */
972 + omapi_free_all_pointers();
974 + /* Re-Initialize globals: */
976 + client_env_count = 0;
977 + default_lease_time = 43200;
979 + dhcp_max_agent_option_packet_length = 0;
981 + memset(&(iaddr_any.iabuf[0]), '\0', 4);
982 + iaddr_broadcast.len = 4;
983 + memset(&(iaddr_broadcast.iabuf[0]), 0xff, 4);
984 + interfaces_requested = 0;
987 + libdhcp_control = 0;
994 + max_lease_time = 86400;
995 + path_dhclient_conf = _PATH_DHCLIENT_CONF;
996 + path_dhclient_db = _PATH_DHCLIENT_DB;
997 + path_dhclient_pid = _PATH_DHCLIENT_PID;
998 + strcpy(&(path_dhclient_script_array[0]), _PATH_DHCLIENT_SCRIPT);
999 + path_dhclient_script = path_dhclient_script_array;
1001 + resolver_inited = 0;
1003 + global_scope = NULL;
1004 + root_group = NULL;
1005 + group_name_hash = NULL;
1006 + interfaces = NULL;
1007 + dummy_interfaces = NULL;
1008 + fallback_interface = NULL;
1009 + extern int have_setup_fallback;
1010 + have_setup_fallback = 0;
1011 + quiet_interface_discovery = 1;
1015 + dhcp_type_interface = NULL;
1016 + interface_vector = NULL;
1017 + interface_count = 0;
1018 + interface_max = 0;
1021 + dhcp_type_interface = NULL;
1022 + dhcp_type_group = NULL;
1023 + dhcp_type_shared_network = NULL;
1024 + dhcp_type_control = NULL;
1025 + memset(&dhcp_universe, '\0', sizeof(struct universe));
1026 + memset(&dhcpv6_universe, '\0', sizeof(struct universe));
1027 + memset(&nwip_universe, '\0', sizeof(struct universe));
1028 + memset(&fqdn_universe, '\0', sizeof(struct universe));
1029 + memset(&vendor_class_universe, '\0', sizeof(struct universe));
1030 + memset(&vendor_universe, '\0', sizeof(struct universe));
1031 + memset(&vsio_universe, '\0', sizeof(struct universe));
1032 + memset(&isc_universe, '\0', sizeof(struct universe));
1033 + memset(&isc6_universe, '\0', sizeof(struct universe));
1034 + universe_hash = 0;
1036 + universe_count = 0;
1038 + config_universe = 0;
1039 + extern struct hash_bucket *free_hash_buckets;
1040 + free_hash_buckets = NULL;
1041 + extern struct dhcp_packet *dhcp_free_list;
1042 + dhcp_free_list = NULL;
1043 + extern struct packet *packet_free_list;
1044 + packet_free_list = NULL;
1045 + extern struct binding_value *free_binding_values;
1046 + free_binding_values = NULL;
1047 + extern struct expression *free_expressions;
1048 + free_expressions = NULL;
1049 + extern struct option_cache *free_option_caches;
1050 + free_option_caches = NULL;
1051 + extern struct packet *free_packets;
1052 + free_packets = NULL;
1053 + extern pair free_pairs;
1054 + free_pairs = NULL;
1055 + extern omapi_io_object_t omapi_io_states;
1056 + memset(&omapi_io_states, '\0', sizeof(omapi_io_states));
1057 + dhcp_control_object = NULL;
1058 + unlink(current_pid_file);
1063 @@ -1270,7 +1446,20 @@ void dhcpack (packet)
1064 if (client -> new -> rebind < cur_time)
1065 client -> new -> rebind = TIME_MAX;
1068 + /* We need the server's siaddr for the 'bootServer'
1071 + u_int32_t set_siaddr = 0;
1072 + set_siaddr = client->packet.siaddr.s_addr;
1073 + client->packet.siaddr.s_addr = packet->raw->siaddr.s_addr;
1076 bind_lease (client);
1079 + client->packet.siaddr.s_addr = set_siaddr;
1083 void bind_lease (client)
1084 @@ -1306,6 +1495,9 @@ void bind_lease (client)
1089 + if (libdhcp_control && (libdhcp_control->capability & DHCP_USE_LEASE_DATABASE))
1091 /* Write out the new lease. */
1092 write_client_lease (client, client -> new, 0, 0);
1094 @@ -1398,10 +1590,12 @@ void state_stop (cpp)
1099 int commit_leases ()
1105 int write_lease (lease)
1106 struct lease *lease;
1107 @@ -2074,6 +2268,10 @@ void state_panic (cpp)
1108 tell the shell script that we failed to allocate an address,
1109 and try again later. */
1112 + script_init (client, "FAIL", (struct string_list *)0);
1116 log_info ("Unable to obtain a lease on first try.%s",
1118 @@ -2691,7 +2889,9 @@ void destroy_client_lease (lease)
1119 free_client_lease (lease, MDL);
1123 FILE *leaseFile = NULL;
1125 int leases_written = 0;
1127 void rewrite_client_leases ()
1128 @@ -3218,6 +3418,54 @@ void script_write_params (client, prefix
1129 int script_go (client)
1130 struct client_state *client;
1133 + struct string_list *sp;
1135 + if (libdhcp_control && libdhcp_control->callback) {
1139 + for (sp = client->env; sp; sp = sp->next)
1140 + if (strncmp(sp->string, "reason=", 7) == 0) {
1141 + reason = sp->string + 7;
1145 + if (strcmp(reason,"NBI") == 0)
1146 + dhcmsg = DHC4_NBI;
1147 + else if (strcmp(reason,"PREINIT") == 0)
1148 + dhcmsg = DHC4_PREINIT;
1149 + else if (strcmp(reason,"BOUND") == 0)
1150 + dhcmsg = DHC4_BOUND;
1151 + else if (strcmp(reason,"RENEW") == 0)
1152 + dhcmsg = DHC4_RENEW;
1153 + else if (strcmp(reason,"REBOOT") == 0)
1154 + dhcmsg = DHC4_REBOOT;
1155 + else if (strcmp(reason,"REBIND") == 0)
1156 + dhcmsg = DHC4_REBIND;
1157 + else if (strcmp(reason,"STOP") == 0)
1158 + dhcmsg = DHC4_STOP;
1159 + else if (strcmp(reason,"MEDIUM") == 0)
1160 + dhcmsg = DHC4_MEDIUM;
1161 + else if (strcmp(reason,"TIMEOUT") == 0)
1162 + dhcmsg = DHC4_TIMEOUT;
1163 + else if (strcmp(reason,"FAIL") == 0)
1164 + dhcmsg = DHC4_FAIL;
1165 + else if (strcmp(reason,"EXPIRE") == 0)
1166 + dhcmsg = DHC4_EXPIRE;
1167 + else if (strcmp(reason,"RELEASE") == 0)
1168 + dhcmsg = DHC4_RELEASE;
1170 + dhcmsg = DHC4_NBI;
1172 + (*libdhcp_control->callback) (libdhcp_control, dhcmsg, client);
1174 + if (libdhcp_control->decline)
1183 @@ -3294,6 +3542,7 @@ int script_go (client)
1185 return (WIFEXITED (wstatus) ?
1186 WEXITSTATUS (wstatus) : -WTERMSIG (wstatus));
1190 void client_envadd (struct client_state *client,
1191 @@ -3376,6 +3625,9 @@ void go_daemon ()
1193 /* Don't become a daemon if the user requested otherwise. */
1196 + if (libdhcp_control && (libdhcp_control->capability & DHCP_USE_PID_FILE))
1198 write_client_pid_file ();
1201 @@ -3385,6 +3637,10 @@ void go_daemon ()
1209 /* Stop logging to stderr... */