1 diff -up dhcp-4.0.0/configure.ac.libdhcp4client dhcp-4.0.0/configure.ac
2 --- dhcp-4.0.0/configure.ac.libdhcp4client 2007-12-14 08:24:56.000000000 -1000
3 +++ dhcp-4.0.0/configure.ac 2008-01-22 17:04:28.000000000 -1000
5 AC_INIT([DHCP], [4.0.0], [dhcp-users@isc.org])
8 +dnl (from glib's configure.in ...)
10 +dnl DHCP_MICRO_VERSION += 1;
11 +dnl DHCP_INTERFACE_AGE += 1;
12 +dnl DHCP_BINARY_AGE += 1;
13 +dnl if any functions have been added, set DHCP_INTERFACE_AGE to 0.
14 +dnl if backwards compatibility has been broken (e.g., functions removed,
15 +dnl function signatures changed),
16 +dnl set DHCP_BINARY_AGE and DHCP_INTERFACE_AGE to 0.
23 +DHCP_VERSION=$DHCP_MAJOR_VERSION.$DHCP_MINOR_VERSION.$DHCP_MICRO_VERSION$DHCP_VERSION_SUFFIX
25 +LT_RELEASE=$DHCP_MAJOR_VERSION.$DHCP_MINOR_VERSION
26 +LT_CURRENT=`expr $DHCP_MICRO_VERSION - $DHCP_INTERFACE_AGE`
27 +LT_REVISION=$DHCP_INTERFACE_AGE
28 +AC_SUBST(DHCP_VERSION)
31 +AC_SUBST(LT_REVISION)
34 # we specify "foreign" to avoid having to have the GNU mandated files,
35 # like AUTHORS, COPYING, and such
36 AM_INIT_AUTOMAKE([foreign])
37 @@ -20,7 +47,8 @@ if test "$GCC" = "yes"; then
44 AC_CONFIG_HEADERS([includes/config.h])
46 # we sometimes need to know byte order for building packets
47 diff -up dhcp-4.0.0/omapip/Makefile.am.libdhcp4client dhcp-4.0.0/omapip/Makefile.am
48 --- dhcp-4.0.0/omapip/Makefile.am.libdhcp4client 2007-05-29 06:32:11.000000000 -1000
49 +++ dhcp-4.0.0/omapip/Makefile.am 2008-01-22 17:04:28.000000000 -1000
51 lib_LIBRARIES = libomapi.a
52 +noinst_LIBRARIES = libomapiLIBDHCP.a
53 noinst_PROGRAMS = svtest
55 libomapi_a_SOURCES = protocol.c buffer.c alloc.c result.c connection.c \
56 errwarn.c listener.c dispatch.c generic.c support.c \
57 handle.c message.c convert.c hash.c auth.c inet_addr.c \
58 array.c trace.c mrtrace.c toisc.c iscprint.c
60 +libomapiLIBDHCP_a_CFLAGS = -DLIBDHCP
61 +libomapiLIBDHCP_a_SOURCES = alloc.c array.c auth.c buffer.c connection.c \
62 + convert.c dispatch.c errwarn.c handle.c hash.c listener.c \
63 + mrtrace.c result.c support.c toisc.c trace.c generic.c message.c \
67 EXTRA_DIST = $(man_MANS)
69 diff -up dhcp-4.0.0/omapip/dispatch.c.libdhcp4client dhcp-4.0.0/omapip/dispatch.c
70 --- dhcp-4.0.0/omapip/dispatch.c.libdhcp4client 2007-11-30 11:51:43.000000000 -1000
71 +++ dhcp-4.0.0/omapip/dispatch.c 2008-01-22 17:04:28.000000000 -1000
73 #include <omapip/omapip_p.h>
76 -static omapi_io_object_t omapi_io_states;
77 +omapi_io_object_t omapi_io_states;
80 OMAPI_OBJECT_ALLOC (omapi_io,
81 diff -up dhcp-4.0.0/omapip/errwarn.c.libdhcp4client dhcp-4.0.0/omapip/errwarn.c
82 --- dhcp-4.0.0/omapip/errwarn.c.libdhcp4client 2008-01-22 17:04:28.000000000 -1000
83 +++ dhcp-4.0.0/omapip/errwarn.c 2008-01-22 17:04:28.000000000 -1000
89 +#include <isc-dhcp/libdhcp_control.h>
90 +extern LIBDHCP_Control *libdhcp_control;
96 @@ -46,7 +51,9 @@ int log_priority;
97 void (*log_cleanup) (void);
99 #define CVT_BUF_MAX 1023
101 static char mbuf [CVT_BUF_MAX + 1];
103 static char fbuf [CVT_BUF_MAX + 1];
105 /* Log an error message, then exit... */
106 @@ -56,6 +63,16 @@ void log_fatal (const char * fmt, ... )
109 do_percentm (fbuf, fmt);
112 + if (libdhcp_control && (libdhcp_control->eh)) {
113 + va_start (list, fmt);
114 + libdhcp_control->eh(libdhcp_control, LOG_FATAL, fbuf, list);
116 + libdhcp_control->finished = 1;
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.
123 @@ -89,6 +106,7 @@ void log_fatal (const char * fmt, ... )
130 /* Log an error message... */
131 @@ -99,6 +117,13 @@ int log_error (const char * fmt, ...)
133 do_percentm (fbuf, fmt);
136 + if (libdhcp_control && libdhcp_control->eh) {
137 + va_start (list, fmt);
138 + libdhcp_control->eh(libdhcp_control, LOG_ERR, fbuf, list);
142 /* %Audit% This is log output. %2004.06.17,Safe%
143 * If we truncate we hope the user can get a hint from the log.
145 @@ -114,7 +139,7 @@ int log_error (const char * fmt, ...)
146 write (STDERR_FILENO, mbuf, strlen (mbuf));
147 write (STDERR_FILENO, "\n", 1);
154 @@ -126,6 +151,13 @@ int log_info (const char *fmt, ...)
156 do_percentm (fbuf, fmt);
159 + if (libdhcp_control && libdhcp_control->eh) {
160 + va_start (list, fmt);
161 + libdhcp_control->eh(libdhcp_control, LOG_INFO, fbuf, list);
165 /* %Audit% This is log output. %2004.06.17,Safe%
166 * If we truncate we hope the user can get a hint from the log.
168 @@ -141,7 +173,7 @@ int log_info (const char *fmt, ...)
169 write (STDERR_FILENO, mbuf, strlen (mbuf));
170 write (STDERR_FILENO, "\n", 1);
177 @@ -152,7 +184,13 @@ int log_debug (const char *fmt, ...)
180 do_percentm (fbuf, fmt);
183 + if (libdhcp_control && libdhcp_control->eh) {
184 + va_start (list, fmt);
185 + libdhcp_control->eh(libdhcp_control, LOG_DEBUG, fbuf, list);
189 /* %Audit% This is log output. %2004.06.17,Safe%
190 * If we truncate we hope the user can get a hint from the log.
192 @@ -168,7 +206,7 @@ int log_debug (const char *fmt, ...)
193 write (STDERR_FILENO, mbuf, strlen (mbuf));
194 write (STDERR_FILENO, "\n", 1);
201 diff -up dhcp-4.0.0/omapip/alloc.c.libdhcp4client dhcp-4.0.0/omapip/alloc.c
202 --- dhcp-4.0.0/omapip/alloc.c.libdhcp4client 2007-07-12 20:43:42.000000000 -1000
203 +++ dhcp-4.0.0/omapip/alloc.c 2008-01-22 17:04:28.000000000 -1000
206 #include <omapip/omapip_p.h>
209 +/* OK, we need a quick and dirty way of freeing all memory used by libdhcp.
210 + All pointers will be stored in a glibc tree on alloc, and removed on free.
211 + This is not too expensive for light single-call library use.
214 +extern void tdestroy (void *root, void (*free_node)(void *nodep));
215 +static void *all_pointers=0L;
216 +static int ptr_comparator(const void *p1, const void *p2) {
217 + return ((p1 == p2) ? 0 : ((p1 > p2) ? 1 : -1));
220 +static void record_pointer(void *ptr) {
221 + tsearch(ptr, &(all_pointers), ptr_comparator);
224 +static void forget_pointer(void *ptr) {
225 + tdelete(ptr, &(all_pointers), ptr_comparator);
228 +void omapi_free_all_pointers(void) {
229 + if (all_pointers != NULL)
230 + tdestroy(all_pointers, free);
231 + all_pointers = NULL;
235 #if defined (DEBUG_MEMORY_LEAKAGE) || defined (DEBUG_MALLOC_POOL) || \
236 defined (DEBUG_MEMORY_LEAKAGE_ON_EXIT)
237 struct dmalloc_preamble *dmalloc_list;
238 @@ -72,7 +99,9 @@ dmalloc(unsigned size, const char *file,
244 + record_pointer(foo);
248 bar = (void *)(foo + DMDOFFSET);
249 @@ -191,6 +220,9 @@ dfree(void *ptr, const char *file, int l
250 0, (unsigned char *)ptr + DMDOFFSET, 0, 1, RC_MALLOC);
254 + forget_pointer(ptr);
258 #if defined (DEBUG_MEMORY_LEAKAGE) || defined (DEBUG_MALLOC_POOL) || \
259 diff -up dhcp-4.0.0/dst/Makefile.am.libdhcp4client dhcp-4.0.0/dst/Makefile.am
260 --- dhcp-4.0.0/dst/Makefile.am.libdhcp4client 2008-01-22 17:04:28.000000000 -1000
261 +++ dhcp-4.0.0/dst/Makefile.am 2008-01-22 17:04:28.000000000 -1000
262 @@ -2,7 +2,7 @@ AM_CPPFLAGS = -DMINIRES_LIB -DHMAC_MD5
264 lib_LIBRARIES = libdst.a
266 -noinst_LIBRARIES = libdstnomd5.a
267 +noinst_LIBRARIES = libdstnomd5.a libdstLIBDHCP.a
269 libdst_a_SOURCES = dst_support.c dst_api.c hmac_link.c md5_dgst.c \
271 @@ -10,4 +10,8 @@ libdst_a_SOURCES = dst_support.c dst_api
272 libdstnomd5_a_SOURCES = dst_support.c dst_api.c hmac_link.c \
275 +libdstLIBDHCP_a_CFLAGS = -DLIBDHCP
276 +libdstLIBDHCP_a_SOURCES = dst_support.c dst_api.c hmac_link.c md5_dgst.c \
279 EXTRA_DIST = dst_internal.h md5.h md5_locl.h
280 diff -up dhcp-4.0.0/dst/hmac_link.c.libdhcp4client dhcp-4.0.0/dst/hmac_link.c
281 --- dhcp-4.0.0/dst/hmac_link.c.libdhcp4client 2007-12-05 14:50:22.000000000 -1000
282 +++ dhcp-4.0.0/dst/hmac_link.c 2008-01-22 17:04:28.000000000 -1000
283 @@ -39,6 +39,10 @@ static const char rcsid[] = "$Header: /p
285 #include "dst_internal.h"
288 +extern void* dmalloc(size_t,char *,int);
294 @@ -87,7 +91,11 @@ dst_hmac_md5_sign(const int mode, DST_KE
297 if (mode & SIG_MODE_INIT)
299 + ctx = (MD5_CTX *) dmalloc(sizeof(*ctx),__FILE__,__LINE__);
301 ctx = (MD5_CTX *) malloc(sizeof(*ctx));
304 ctx = (MD5_CTX *) *context;
306 @@ -154,7 +162,11 @@ dst_hmac_md5_verify(const int mode, DST_
309 if (mode & SIG_MODE_INIT)
311 + ctx = (MD5_CTX *) dmalloc(sizeof(*ctx),__FILE__,__LINE__);
313 ctx = (MD5_CTX *) malloc(sizeof(*ctx));
316 ctx = (MD5_CTX *) *context;
318 @@ -218,8 +230,11 @@ dst_buffer_to_hmac_md5(DST_KEY *dkey, co
320 if (dkey == NULL || key == NULL || keylen < 0)
324 + if ((hkey = (HMAC_Key *) dmalloc(sizeof(HMAC_Key),__FILE__,__LINE__)) == NULL)
326 if ((hkey = (HMAC_Key *) malloc(sizeof(HMAC_Key))) == NULL)
330 memset(hkey->hk_ipad, 0, sizeof(hkey->hk_ipad));
331 @@ -348,7 +363,11 @@ dst_hmac_md5_key_from_file_format(DST_KE
336 + tmp = dmalloc(len + 2,__FILE__,__LINE__);
338 tmp = malloc(len + 2);
342 key_len = b64_pton((char *)tmp, key, HMAC_LEN+1); /* see above */
343 @@ -440,8 +459,11 @@ dst_hmac_md5_generate_key(DST_KEY *key,
346 len = size > 64 ? 64 : size;
348 + buff = dmalloc(len+8,__FILE__,__LINE__);
350 buff = malloc(len+8);
353 n = dst_random(DST_RAND_SEMI, len, buff);
354 n += dst_random(DST_RAND_KEY, len, buff);
355 if (n <= len) { /* failed getting anything */
356 @@ -464,7 +486,11 @@ dst_hmac_md5_init()
358 if (dst_t_func[KEY_HMAC_MD5] != NULL)
361 + dst_t_func[KEY_HMAC_MD5] = dmalloc(sizeof(struct dst_func),__FILE__,__LINE__);
363 dst_t_func[KEY_HMAC_MD5] = malloc(sizeof(struct dst_func));
365 if (dst_t_func[KEY_HMAC_MD5] == NULL)
367 memset(dst_t_func[KEY_HMAC_MD5], 0, sizeof(struct dst_func));
368 diff -up dhcp-4.0.0/common/Makefile.am.libdhcp4client dhcp-4.0.0/common/Makefile.am
369 --- dhcp-4.0.0/common/Makefile.am.libdhcp4client 2007-11-16 01:04:11.000000000 -1000
370 +++ dhcp-4.0.0/common/Makefile.am 2008-01-22 17:04:28.000000000 -1000
372 AM_CPPFLAGS = -I.. -DLOCALSTATEDIR='"@localstatedir@"'
374 -noinst_LIBRARIES = libdhcp.a
375 +noinst_LIBRARIES = libdhcp.a libdhcpLIBDHCP.a
376 libdhcp_a_SOURCES = alloc.c bpf.c comapi.c conflex.c ctrace.c discover.c \
377 dispatch.c dlpi.c dns.c ethernet.c execute.c fddi.c \
378 icmp.c inet.c lpf.c memory.c nit.c options.c packet.c \
379 parse.c print.c raw.c resolv.c socket.c tables.c tr.c \
381 +libdhcpLIBDHCP_a_CFLAGS = -DLIBDHCP
382 +libdhcpLIBDHCP_a_SOURCES = alloc.c bpf.c comapi.c conflex.c ctrace.c \
383 + discover.c dispatch.c dlpi.c dns.c ethernet.c \
384 + execute.c inet.c lpf.c memory.c nit.c options.c \
385 + packet.c parse.c print.c resolv.c socket.c \
386 + tables.c tr.c tree.c upf.c
387 man_MANS = dhcp-eval.5 dhcp-options.5
388 EXTRA_DIST = $(man_MANS)
390 diff -up dhcp-4.0.0/common/discover.c.libdhcp4client dhcp-4.0.0/common/discover.c
391 --- dhcp-4.0.0/common/discover.c.libdhcp4client 2007-10-05 12:29:51.000000000 -1000
392 +++ dhcp-4.0.0/common/discover.c 2008-01-22 17:04:28.000000000 -1000
393 @@ -883,6 +883,10 @@ add_ipv6_addr_to_interface(struct interf
394 register that interface with the network I/O software, figure out what
395 subnet it's on, and add it to the list of interfaces. */
398 +int have_setup_fallback = 0;
402 discover_interfaces(int state) {
403 struct iface_conf_list ifaces;
404 @@ -902,7 +906,9 @@ discover_interfaces(int state) {
409 static int setup_fallback = 0;
412 if (!begin_iface_scan(&ifaces)) {
413 log_fatal("Can't get list of interfaces.");
414 @@ -1242,10 +1248,17 @@ discover_interfaces(int state) {
415 log_fatal ("Not configured to listen on any interfaces!");
419 + if ((local_family == AF_INET) && !have_setup_fallback) {
420 + have_setup_fallback = 1;
421 + maybe_setup_fallback ();
424 if ((local_family == AF_INET) && !setup_fallback) {
426 maybe_setup_fallback();
430 #if defined (F_SETFD)
431 if (fallback_interface) {
432 diff -up dhcp-4.0.0/common/tree.c.libdhcp4client dhcp-4.0.0/common/tree.c
433 --- dhcp-4.0.0/common/tree.c.libdhcp4client 2007-08-22 03:41:37.000000000 -1000
434 +++ dhcp-4.0.0/common/tree.c 2008-01-22 17:04:28.000000000 -1000
439 -struct binding_scope *global_scope;
440 +struct binding_scope __attribute__ ((visibility ("default"))) *global_scope;
442 static int do_host_lookup PROTO ((struct data_string *,
443 struct dns_host_entry *));
444 @@ -2859,6 +2859,7 @@ int evaluate_numeric_expression (result,
445 result of that evaluation. There should never be both an expression
446 and a valid data_string. */
448 +__attribute__ ((visibility ("default")))
449 int evaluate_option_cache (result, packet, lease, client_state,
450 in_options, cfg_options, scope, oc, file, line)
451 struct data_string *result;
452 diff -up dhcp-4.0.0/common/options.c.libdhcp4client dhcp-4.0.0/common/options.c
453 --- dhcp-4.0.0/common/options.c.libdhcp4client 2007-11-30 11:51:43.000000000 -1000
454 +++ dhcp-4.0.0/common/options.c 2008-01-22 17:04:28.000000000 -1000
455 @@ -3392,6 +3392,7 @@ fqdn6_universe_decode(struct option_stat
459 +__attribute__ ((visibility ("default")))
460 void option_space_foreach (struct packet *packet, struct lease *lease,
461 struct client_state *client_state,
462 struct option_state *in_options,
463 diff -up dhcp-4.0.0/common/dispatch.c.libdhcp4client dhcp-4.0.0/common/dispatch.c
464 --- dhcp-4.0.0/common/dispatch.c.libdhcp4client 2008-01-22 17:04:28.000000000 -1000
465 +++ dhcp-4.0.0/common/dispatch.c 2008-01-22 17:04:28.000000000 -1000
470 -struct timeout *timeouts;
471 -static struct timeout *free_timeouts;
474 + struct timeout *next;
477 + void (*func) PROTO ((void *));
484 +static struct timeout *timeouts = NULL;
485 +static int ntimeouts = 0;
487 +static struct timeout *timeouts = NULL;
488 +static struct timeout *free_timeouts = NULL;
491 void set_time(TIME t)
493 @@ -48,9 +64,41 @@ void set_time(TIME t)
495 struct timeval *process_outstanding_timeouts (struct timeval *tvp)
499 + struct timeout t = { 0 };
501 /* Call any expired timeouts, and then if there's
502 still a timeout registered, time out the select
508 + for (i = 0; i < ntimeouts && timeouts[i].when <= cur_time;) {
509 + struct timeout *new_timeouts;
512 + memmove(&t, &timeouts[i], sizeof (t));
514 + n = (ntimeouts - i - 1) * sizeof (t);
515 + memmove(&timeouts[i+1], &timeouts[i], n);
517 + n = --ntimeouts * sizeof (t);
518 + new_timeouts = realloc(timeouts, n);
519 + /* XXX broken API, no way to return error here */
520 + if (new_timeouts || !n)
521 + timeouts = new_timeouts;
526 + t.unref(t.what, MDL);
528 + if (tvp && ntimeouts) {
529 + tvp->tv_sec = timeouts[0].when;
535 @@ -68,9 +116,15 @@ struct timeval *process_outstanding_time
536 tvp -> tv_sec = timeouts -> when;
546 return (struct timeval *)0;
550 /* Wait for packets to come in using select(). When one does, call
551 @@ -99,13 +153,28 @@ void add_timeout (when, where, what, ref
556 + struct timeout t = {
563 + struct timeout *new_timeouts;
566 struct timeout *t, *q;
569 /* See if this timeout supersedes an existing timeout. */
571 + for (i = 0; i < ntimeouts; i++) {
572 + struct timeout *q = &timeouts[i];
574 t = (struct timeout *)0;
575 for (q = timeouts; q; q = q -> next) {
576 - if ((where == NULL || q -> func == where) &&
577 - q -> what == what) {
578 + if ((where == NULL || q -> func == where) && q -> what == what) {
580 t -> next = q -> next;
582 @@ -114,7 +183,29 @@ void add_timeout (when, where, what, ref
589 + /* If this one is already in the list with a different time,
590 + * remove it and re-add */
591 + if ((where == NULL || q->func == where) &&
593 + size_t n = (--ntimeouts - i) * sizeof (*q);
594 + memmove(&t, q, sizeof (t));
597 + memmove(&timeouts[i], &timeouts[i+1], n);
600 + new_timeouts = realloc(timeouts, ntimeouts * sizeof (*q));
601 + /* XXX broken API, no way to return error here */
603 + timeouts = new_timeouts;
607 + add_timeout(when, where, what, ref, unref);
609 /* If we didn't supersede a timeout, allocate a timeout
612 @@ -123,7 +214,7 @@ void add_timeout (when, where, what, ref
613 free_timeouts = q -> next;
615 q = ((struct timeout *)
616 - dmalloc (sizeof (struct timeout), MDL));
617 + dmalloc (sizeof (struct timeout), MDL));
619 log_fatal ("add_timeout: no memory!");
621 @@ -153,22 +244,76 @@ void add_timeout (when, where, what, ref
622 if (t -> next -> when > q -> when) {
623 q -> next = t -> next;
628 + } else if (timeouts[i].when > when) {
635 + /* If we didn't supersede an existing timeout, then pos is set
636 + * to the timeout which will post after this one. Insert this
637 + * one before it. */
639 + new_timeouts = realloc(timeouts, sizeof (t) * (ntimeouts+1));
640 + /* XXX broken API, no way to return error here */
641 + if (new_timeouts) {
644 + * n = 10-3 * sizeof (t) = 7 * sizeof (t)
646 + size_t n = (ntimeouts - pos) * sizeof (t);
648 + timeouts = new_timeouts;
649 + memmove(&timeouts[pos+1], &timeouts[pos], n);
650 + memmove(&timeouts[pos], &t, sizeof (t));
656 q -> next = (struct timeout *)0;
660 void cancel_timeout (where, what)
661 void (*where) PROTO ((void *));
668 struct timeout *t, *q;
671 /* Look for this timeout on the list, and unlink it if we find it. */
673 + for (i = 0; i < ntimeouts; i++) {
674 + struct timeout *new_timeouts, *q = &timeouts[i];
676 + if (q->func == where && q->what == what) {
679 + memmove(&t, q, sizeof (t));
681 + n = (ntimeouts - i - 1) * sizeof (t);
682 + memmove(&timeouts[i+1], &timeouts[i], n);
684 + n = --ntimeouts * sizeof (t);
685 + new_timeouts = realloc(timeouts, n);
686 + /* XXX broken API, no way to return error here */
687 + if (new_timeouts || !n)
688 + timeouts = new_timeouts;
691 + t.unref(t.what, MDL);
695 t = (struct timeout *)0;
696 for (q = timeouts; q; q = q -> next) {
697 if (q -> func == where && q -> what == what) {
698 @@ -188,10 +333,15 @@ void cancel_timeout (where, what)
699 q -> next = free_timeouts;
705 void cancel_all_timeouts ()
708 + cur_time = TIME_MAX;
709 + process_outstanding_timeouts(NULL);
711 struct timeout *t, *n;
712 for (t = timeouts; t; t = n) {
714 @@ -200,13 +350,20 @@ void cancel_all_timeouts ()
715 t -> next = free_timeouts;
721 +__attribute__ ((visibility ("default")))
722 void relinquish_timeouts ()
726 + cancel_timeout(timeouts[0].func, timeouts[0].what);
728 struct timeout *t, *n;
729 for (t = free_timeouts; t; t = n) {
735 diff -up dhcp-4.0.0/common/alloc.c.libdhcp4client dhcp-4.0.0/common/alloc.c
736 --- dhcp-4.0.0/common/alloc.c.libdhcp4client 2007-10-23 14:54:11.000000000 -1000
737 +++ dhcp-4.0.0/common/alloc.c 2008-01-22 17:04:28.000000000 -1000
738 @@ -1004,7 +1004,11 @@ int executable_statement_reference (ptr,
743 +struct packet *free_packets;
745 static struct packet *free_packets;
748 #if defined (DEBUG_MEMORY_LEAKAGE) || \
749 defined (DEBUG_MEMORY_LEAKAGE_ON_EXIT)
750 diff -up dhcp-4.0.0/includes/dhcpd.h.libdhcp4client dhcp-4.0.0/includes/dhcpd.h
751 --- dhcp-4.0.0/includes/dhcpd.h.libdhcp4client 2008-01-22 17:04:28.000000000 -1000
752 +++ dhcp-4.0.0/includes/dhcpd.h 2008-01-22 17:05:02.000000000 -1000
753 @@ -1199,14 +1199,6 @@ struct hardware_link {
755 typedef void (*tvref_t)(void *, void *, const char *, int);
756 typedef void (*tvunref_t)(void *, const char *, int);
758 - struct timeout *next;
760 - void (*func) PROTO ((void *));
767 struct protocol *next;
768 @@ -1664,7 +1656,6 @@ extern const char *path_dhcpd_pid;
770 extern int dhcp_max_agent_option_packet_length;
772 -int main(int, char **);
773 void postconf_initialization(int);
774 void postdb_startup(void);
775 void cleanup PROTO ((void));
776 @@ -2337,7 +2328,6 @@ extern void (*bootp_packet_handler) PROT
777 extern void (*dhcpv6_packet_handler)(struct interface_info *,
779 int, const struct iaddr *, isc_boolean_t);
780 -extern struct timeout *timeouts;
781 extern omapi_object_type_t *dhcp_type_interface;
782 #if defined (TRACING)
783 extern trace_type_t *interface_trace;
784 @@ -2392,6 +2382,10 @@ extern struct universe dhcpv6_universe;
785 extern struct universe nwip_universe;
786 extern struct universe fqdn_universe;
787 extern struct universe vsio_universe;
788 +extern struct universe vendor_class_universe;
789 +extern struct universe vendor_universe;
790 +extern struct universe isc_universe;
791 +extern struct universe isc6_universe;
792 extern int dhcp_option_default_priority_list [];
793 extern int dhcp_option_default_priority_list_count;
794 extern const char *hardware_types [256];
795 diff -up dhcp-4.0.0/client/Makefile.am.libdhcp4client dhcp-4.0.0/client/Makefile.am
796 --- dhcp-4.0.0/client/Makefile.am.libdhcp4client 2007-12-12 09:23:42.000000000 -1000
797 +++ dhcp-4.0.0/client/Makefile.am 2008-01-22 17:04:28.000000000 -1000
799 dist_sysconf_DATA = dhclient.conf
800 sbin_PROGRAMS = dhclient
801 +lib_LTLIBRARIES = libdhcp4client.la
802 dhclient_SOURCES = clparse.c dhclient.c dhc6.c \
803 scripts/bsdos scripts/freebsd scripts/linux scripts/netbsd \
804 scripts/nextstep scripts/openbsd scripts/solaris
805 dhclient_LDADD = ../common/libdhcp.a ../minires/libres.a \
806 ../omapip/libomapi.a ../dst/libdst.a
807 +libdhcp4client_la_CFLAGS = -DLIBDHCP -DLOCALSTATEDIR='"@localstatedir@"'
808 +libdhcp4client_la_LDFLAGS = -version-info \
809 + $(LT_CURRENT):$(LT_REVISION):$(LT_AGE) \
810 + -release $(LT_RELEASE)
811 +libdhcp4client_la_SOURCES = clparse.c dhclient.c dhc6.c
812 +libdhcp4client_la_LIBADD = ../common/libdhcpLIBDHCP.a ../minires/libres.a \
813 + ../omapip/libomapiLIBDHCP.a ../dst/libdstLIBDHCP.a
814 man_MANS = dhclient.8 dhclient-script.8 dhclient.conf.5 dhclient.leases.5
815 EXTRA_DIST = $(man_MANS)
817 diff -up dhcp-4.0.0/client/dhclient.c.libdhcp4client dhcp-4.0.0/client/dhclient.c
818 --- dhcp-4.0.0/client/dhclient.c.libdhcp4client 2008-01-22 17:04:28.000000000 -1000
819 +++ dhcp-4.0.0/client/dhclient.c 2008-01-22 17:05:47.000000000 -1000
820 @@ -83,14 +83,50 @@ int nowait=0;
821 char *mockup_relay = NULL;
822 int bootp_broadcast_always = 0;
825 +FILE *leaseFile = NULL;
828 extern u_int32_t default_requested_options[];
830 static void usage PROTO ((void));
832 static isc_result_t write_duid(struct data_string *duid);
835 -main(int argc, char **argv) {
837 +#include "isc-dhcp/libdhcp_control.h"
838 +LIBDHCP_Control *libdhcp_control;
839 +static void libdhcp_dispatch(void)
841 + struct timeval tv = { 0, 0 }, *tvp;
842 + isc_result_t status;
844 + /* Wait for a packet, or a timeout, or libdhcp being finished */
846 + tvp = process_outstanding_timeouts(&tv);
847 + status = omapi_one_dispatch(0, tvp);
849 + if (libdhcp_control && ((status == ISC_R_TIMEDOUT) || (libdhcp_control->timeout && (time(NULL) >= (libdhcp_control->timeout + libdhcp_control->now))))) {
850 + if (libdhcp_control->callback)
851 + libdhcp_control->callback(libdhcp_control, DHC_TIMEDOUT, NULL);
855 + } while ((status != ISC_R_TIMEDOUT) && ((!libdhcp_control) || (!(libdhcp_control->finished))));
858 +extern void omapi_free_all_pointers(void);
860 +__attribute__ ((visibility ("default")))
861 +int dhcpv4_client (LIBDHCP_Control *libdhcp_ctl, int argc, char **argv,
864 +int main(int argc, char **argv, char **envp)
868 + libdhcp_control = libdhcp_ctl;
872 struct interface_info *ip;
873 @@ -122,6 +158,7 @@ main(int argc, char **argv) {
874 /* Initialize client globals. */
875 memset(&default_duid, 0, sizeof(default_duid));
878 /* Make sure that file descriptors 0 (stdin), 1, (stdout), and
879 2 (stderr) are open. To do this, we assume that when we
880 open a file the lowest available file descriptor is used. */
881 @@ -140,6 +177,7 @@ main(int argc, char **argv) {
882 #if !(defined (DEBUG) || defined (__CYGWIN32__))
883 setlogmask (LOG_UPTO (LOG_INFO));
887 /* Set up the OMAPI. */
888 status = omapi_init ();
889 @@ -485,8 +523,12 @@ main(int argc, char **argv) {
894 + if (libdhcp_control && (libdhcp_control->capability & DHCP_USE_PID_FILE))
896 write_client_pid_file();
900 log_info ("%s %s", message, PACKAGE_VERSION);
901 log_info (copyright);
902 @@ -497,6 +539,7 @@ main(int argc, char **argv) {
904 quiet_interface_discovery = 1;
908 /* If we're given a relay agent address to insert, for testing
909 purposes, figure out what it is. */
910 @@ -702,11 +745,17 @@ main(int argc, char **argv) {
915 + if (libdhcp_control && (libdhcp_control->capability & DHCP_USE_LEASE_DATABASE)) {
917 /* Parse the lease database. */
918 read_client_leases ();
920 /* Rewrite the lease database... */
921 rewrite_client_leases ();
927 /* config_counter(&snd_counter, &rcv_counter); */
928 @@ -725,7 +774,7 @@ main(int argc, char **argv) {
930 /* Nothing more to do. */
931 log_info ("No broadcast interfaces found - exiting.");
935 } else if (!release_mode && !exit_mode) {
936 /* Call the script with the list of interfaces. */
937 @@ -863,6 +912,7 @@ main(int argc, char **argv) {
938 dmalloc_outstanding = 0;
942 /* If we're not supposed to wait before getting the address,
945 @@ -875,6 +925,132 @@ main(int argc, char **argv) {
947 /* Start dispatching packets and timeouts... */
950 + if (libdhcp_control) {
951 + if (libdhcp_control->timeout)
952 + libdhcp_control->now = time(NULL);
954 + libdhcp_control->now = 0;
957 + libdhcp_dispatch();
959 + /* libdhcp is finished with us. */
961 + /* close all file descriptors: */
962 + for (ip = interfaces; ip; ip = ip->next) {
963 + shutdown(ip->wfdesc, SHUT_RDWR);
966 + if (ip->rfdesc != ip->wfdesc)
970 + if (fallback_interface != 0) {
971 + ip = fallback_interface;
972 + shutdown(ip->wfdesc, SHUT_RDWR);
975 + if (ip->rfdesc != ip->wfdesc)
980 + fclose (leaseFile);
984 + char *current_pid_file = _PATH_DHCLIENT_PID;
986 + /* Free ALL allocated memory: */
987 + omapi_free_all_pointers();
989 + /* Re-Initialize globals: */
991 + client_env_count = 0;
992 + default_lease_time = 43200;
994 + dhcp_max_agent_option_packet_length = 0;
996 + memset(&(iaddr_any.iabuf[0]), '\0', 4);
997 + iaddr_broadcast.len = 4;
998 + memset(&(iaddr_broadcast.iabuf[0]), 0xff, 4);
999 + interfaces_requested = 0;
1002 + libdhcp_control = 0;
1009 + max_lease_time = 86400;
1010 + path_dhclient_conf = _PATH_DHCLIENT_CONF;
1011 + path_dhclient_db = _PATH_DHCLIENT_DB;
1012 + path_dhclient_pid = _PATH_DHCLIENT_PID;
1013 + strcpy(&(path_dhclient_script_array[0]), _PATH_DHCLIENT_SCRIPT);
1014 + path_dhclient_script = path_dhclient_script_array;
1016 + resolver_inited = 0;
1018 + global_scope = NULL;
1019 + root_group = NULL;
1020 + group_name_hash = NULL;
1021 + interfaces = NULL;
1022 + dummy_interfaces = NULL;
1023 + fallback_interface = NULL;
1024 + extern int have_setup_fallback;
1025 + have_setup_fallback = 0;
1026 + quiet_interface_discovery = 1;
1030 + dhcp_type_interface = NULL;
1031 + interface_vector = NULL;
1032 + interface_count = 0;
1033 + interface_max = 0;
1036 + dhcp_type_interface = NULL;
1037 + dhcp_type_group = NULL;
1038 + dhcp_type_shared_network = NULL;
1039 + dhcp_type_control = NULL;
1040 + memset(&dhcp_universe, '\0', sizeof(struct universe));
1041 + memset(&dhcpv6_universe, '\0', sizeof(struct universe));
1042 + memset(&nwip_universe, '\0', sizeof(struct universe));
1043 + memset(&fqdn_universe, '\0', sizeof(struct universe));
1044 + memset(&vendor_class_universe, '\0', sizeof(struct universe));
1045 + memset(&vendor_universe, '\0', sizeof(struct universe));
1046 + memset(&vsio_universe, '\0', sizeof(struct universe));
1047 + memset(&isc_universe, '\0', sizeof(struct universe));
1048 + memset(&isc6_universe, '\0', sizeof(struct universe));
1049 + universe_hash = 0;
1051 + universe_count = 0;
1053 + config_universe = 0;
1054 + extern struct hash_bucket *free_hash_buckets;
1055 + free_hash_buckets = NULL;
1056 + extern struct dhcp_packet *dhcp_free_list;
1057 + dhcp_free_list = NULL;
1058 + extern struct packet *packet_free_list;
1059 + packet_free_list = NULL;
1060 + extern struct binding_value *free_binding_values;
1061 + free_binding_values = NULL;
1062 + extern struct expression *free_expressions;
1063 + free_expressions = NULL;
1064 + extern struct option_cache *free_option_caches;
1065 + free_option_caches = NULL;
1066 + extern struct packet *free_packets;
1067 + free_packets = NULL;
1068 + extern pair free_pairs;
1069 + free_pairs = NULL;
1070 + extern omapi_io_object_t omapi_io_states;
1071 + memset(&omapi_io_states, '\0', sizeof(omapi_io_states));
1072 + dhcp_control_object = NULL;
1073 + unlink(current_pid_file);
1078 @@ -1270,7 +1446,20 @@ void dhcpack (packet)
1079 if (client -> new -> rebind < cur_time)
1080 client -> new -> rebind = TIME_MAX;
1083 + /* We need the server's siaddr for the 'bootServer'
1086 + u_int32_t set_siaddr = 0;
1087 + set_siaddr = client->packet.siaddr.s_addr;
1088 + client->packet.siaddr.s_addr = packet->raw->siaddr.s_addr;
1091 bind_lease (client);
1094 + client->packet.siaddr.s_addr = set_siaddr;
1098 void bind_lease (client)
1099 @@ -1306,6 +1495,9 @@ void bind_lease (client)
1104 + if (libdhcp_control && (libdhcp_control->capability & DHCP_USE_LEASE_DATABASE))
1106 /* Write out the new lease. */
1107 write_client_lease (client, client -> new, 0, 0);
1109 @@ -1398,10 +1590,12 @@ void state_stop (cpp)
1114 int commit_leases ()
1120 int write_lease (lease)
1121 struct lease *lease;
1122 @@ -2074,6 +2268,10 @@ void state_panic (cpp)
1123 tell the shell script that we failed to allocate an address,
1124 and try again later. */
1127 + script_init (client, "FAIL", (struct string_list *)0);
1131 log_info ("Unable to obtain a lease on first try.%s",
1133 @@ -2691,7 +2889,9 @@ void destroy_client_lease (lease)
1134 free_client_lease (lease, MDL);
1138 FILE *leaseFile = NULL;
1140 int leases_written = 0;
1142 void rewrite_client_leases ()
1143 @@ -3218,6 +3418,54 @@ void script_write_params (client, prefix
1144 int script_go (client)
1145 struct client_state *client;
1148 + struct string_list *sp;
1150 + if (libdhcp_control && libdhcp_control->callback) {
1154 + for (sp = client->env; sp; sp = sp->next)
1155 + if (strncmp(sp->string, "reason=", 7) == 0) {
1156 + reason = sp->string + 7;
1160 + if (strcmp(reason,"NBI") == 0)
1161 + dhcmsg = DHC4_NBI;
1162 + else if (strcmp(reason,"PREINIT") == 0)
1163 + dhcmsg = DHC4_PREINIT;
1164 + else if (strcmp(reason,"BOUND") == 0)
1165 + dhcmsg = DHC4_BOUND;
1166 + else if (strcmp(reason,"RENEW") == 0)
1167 + dhcmsg = DHC4_RENEW;
1168 + else if (strcmp(reason,"REBOOT") == 0)
1169 + dhcmsg = DHC4_REBOOT;
1170 + else if (strcmp(reason,"REBIND") == 0)
1171 + dhcmsg = DHC4_REBIND;
1172 + else if (strcmp(reason,"STOP") == 0)
1173 + dhcmsg = DHC4_STOP;
1174 + else if (strcmp(reason,"MEDIUM") == 0)
1175 + dhcmsg = DHC4_MEDIUM;
1176 + else if (strcmp(reason,"TIMEOUT") == 0)
1177 + dhcmsg = DHC4_TIMEOUT;
1178 + else if (strcmp(reason,"FAIL") == 0)
1179 + dhcmsg = DHC4_FAIL;
1180 + else if (strcmp(reason,"EXPIRE") == 0)
1181 + dhcmsg = DHC4_EXPIRE;
1182 + else if (strcmp(reason,"RELEASE") == 0)
1183 + dhcmsg = DHC4_RELEASE;
1185 + dhcmsg = DHC4_NBI;
1187 + (*libdhcp_control->callback) (libdhcp_control, dhcmsg, client);
1189 + if (libdhcp_control->decline)
1198 @@ -3294,6 +3542,7 @@ int script_go (client)
1200 return (WIFEXITED (wstatus) ?
1201 WEXITSTATUS (wstatus) : -WTERMSIG (wstatus));
1205 void client_envadd (struct client_state *client,
1206 @@ -3376,6 +3625,9 @@ void go_daemon ()
1208 /* Don't become a daemon if the user requested otherwise. */
1211 + if (libdhcp_control && (libdhcp_control->capability & DHCP_USE_PID_FILE))
1213 write_client_pid_file ();
1216 @@ -3385,6 +3637,10 @@ void go_daemon ()
1224 /* Stop logging to stderr... */