]> git.pld-linux.org Git - packages/dhcp.git/blob - dhcp-libdhcp4client.patch
- patch no-ipv6 - don't require ipv6 support in kernel
[packages/dhcp.git] / dhcp-libdhcp4client.patch
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
4 @@ -1,5 +1,32 @@
5  AC_INIT([DHCP], [4.0.0], [dhcp-users@isc.org])
6  
7 +dnl Versioning
8 +dnl (from glib's configure.in ...)
9 +dnl Making releases:
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.
17 +DHCP_MAJOR_VERSION=4
18 +DHCP_MINOR_VERSION=0
19 +DHCP_MICRO_VERSION=0
20 +DHCP_INTERFACE_AGE=0
21 +DHCP_BINARY_AGE=0
22 +DHCP_VERSION_SUFFIX=
23 +DHCP_VERSION=$DHCP_MAJOR_VERSION.$DHCP_MINOR_VERSION.$DHCP_MICRO_VERSION$DHCP_VERSION_SUFFIX
24 +LT_RELEASE=$DHCP_MAJOR_VERSION.$DHCP_MINOR_VERSION
25 +LT_CURRENT=`expr $DHCP_MICRO_VERSION - $DHCP_INTERFACE_AGE`
26 +LT_REVISION=$DHCP_INTERFACE_AGE
27 +LT_AGE=`expr $DHCP_BINARY_AGE - $DHCP_INTERFACE_AGE`
28 +AC_SUBST(DHCP_VERSION)
29 +AC_SUBST(LT_RELEASE)
30 +AC_SUBST(LT_CURRENT)
31 +AC_SUBST(LT_REVISION)
32 +AC_SUBST(LT_AGE)
33 +
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
38         fi
39  fi
40  
41 -AC_PROG_RANLIB
42 +AC_PROG_LIBTOOL
43 +
44  AC_CONFIG_HEADERS([includes/config.h])
45  
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
50 @@ -1,10 +1,18 @@
51  lib_LIBRARIES = libomapi.a
52 +noinst_LIBRARIES = libomapiLIBDHCP.a
53  noinst_PROGRAMS = svtest
54  
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
59 +
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 \
64 +                    protocol.c
65 +
66  man_MANS = omapi.3
67  EXTRA_DIST = $(man_MANS)
68  
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
72 @@ -37,7 +37,7 @@
73  #include <omapip/omapip_p.h>
74  #include <sys/time.h>
75  
76 -static omapi_io_object_t omapi_io_states;
77 +omapi_io_object_t omapi_io_states;
78  time_t cur_time;
79  
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
84 @@ -37,6 +37,11 @@
85  #include <errno.h>
86  #include <syslog.h>
87  
88 +#ifdef LIBDHCP
89 +#include <isc-dhcp/libdhcp_control.h>
90 +extern LIBDHCP_Control *libdhcp_control;
91 +#endif
92 +
93  #ifdef DEBUG
94  int log_perror = -1;
95  #else
96 @@ -46,7 +51,9 @@ int log_priority;
97  void (*log_cleanup) (void);
98  
99  #define CVT_BUF_MAX 1023
100 +#ifndef LIBDHCP
101  static char mbuf [CVT_BUF_MAX + 1];
102 +#endif
103  static char fbuf [CVT_BUF_MAX + 1];
104  
105  /* Log an error message, then exit... */
106 @@ -56,6 +63,16 @@ void log_fatal (const char * fmt, ... )
107    va_list list;
108  
109    do_percentm (fbuf, fmt);
110 +  
111 +#ifdef LIBDHCP
112 +  if (libdhcp_control && (libdhcp_control->eh)) {
113 +      va_start (list, fmt);
114 +      libdhcp_control->eh(libdhcp_control, LOG_FATAL, fbuf, list);
115 +      va_end(list);
116 +      libdhcp_control->finished = 1;
117 +      return;
118 +  }
119 +#else
120  
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, ... )
124    if (log_cleanup)
125           (*log_cleanup) ();
126    exit (1);
127 +#endif
128  }
129  
130  /* Log an error message... */
131 @@ -99,6 +117,13 @@ int log_error (const char * fmt, ...)
132  
133    do_percentm (fbuf, fmt);
134  
135 +#ifdef LIBDHCP
136 +  if (libdhcp_control && libdhcp_control->eh) {
137 +      va_start (list, fmt);
138 +      libdhcp_control->eh(libdhcp_control, LOG_ERR, fbuf, list);
139 +      va_end(list);
140 +  }
141 +#else
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.
144     */
145 @@ -114,7 +139,7 @@ int log_error (const char * fmt, ...)
146           write (STDERR_FILENO, mbuf, strlen (mbuf));
147           write (STDERR_FILENO, "\n", 1);
148    }
149 -
150 +#endif
151    return 0;
152  }
153  
154 @@ -126,6 +151,13 @@ int log_info (const char *fmt, ...)
155  
156    do_percentm (fbuf, fmt);
157  
158 +#ifdef LIBDHCP
159 +  if (libdhcp_control && libdhcp_control->eh) {
160 +      va_start (list, fmt);
161 +      libdhcp_control->eh(libdhcp_control, LOG_INFO, fbuf, list);
162 +      va_end(list);
163 +  }
164 +#else
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.
167     */
168 @@ -141,7 +173,7 @@ int log_info (const char *fmt, ...)
169           write (STDERR_FILENO, mbuf, strlen (mbuf));
170           write (STDERR_FILENO, "\n", 1);
171    }
172 -
173 +#endif
174    return 0;
175  }
176  
177 @@ -152,7 +184,13 @@ int log_debug (const char *fmt, ...)
178    va_list list;
179  
180    do_percentm (fbuf, fmt);
181 -
182 +#ifdef LIBDHCP
183 +  if (libdhcp_control && libdhcp_control->eh) {
184 +      va_start (list, fmt);
185 +      libdhcp_control->eh(libdhcp_control, LOG_DEBUG, fbuf, list);
186 +      va_end(list);
187 +  }
188 +#else
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.
191     */
192 @@ -168,7 +206,7 @@ int log_debug (const char *fmt, ...)
193           write (STDERR_FILENO, mbuf, strlen (mbuf));
194           write (STDERR_FILENO, "\n", 1);
195    }
196 -
197 +#endif
198    return 0;
199  }
200  
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
204 @@ -37,6 +37,33 @@
205  
206  #include <omapip/omapip_p.h>
207  
208 +#ifdef LIBDHCP
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.
212 +*/
213 +#include <search.h>  
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));
218 +}
219 +
220 +static void record_pointer(void *ptr) {
221 +    tsearch(ptr, &(all_pointers), ptr_comparator);
222 +}
223 +
224 +static void forget_pointer(void *ptr) {
225 +    tdelete(ptr, &(all_pointers), ptr_comparator);
226 +}
227 +
228 +void omapi_free_all_pointers(void) {
229 +    if (all_pointers != NULL)
230 +               tdestroy(all_pointers, free);
231 +    all_pointers = NULL;
232 +}
233 +#endif
234 +
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,
239                 return NULL;
240  
241         foo = malloc(len);
242 -
243 +#ifdef LIBDHCP
244 +       record_pointer(foo);
245 +#endif
246         if (!foo)
247                 return NULL;
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);
251  #endif
252         free (ptr);
253 +#ifdef LIBDHCP
254 +       forget_pointer(ptr);
255 +#endif
256  }
257  
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
263  
264  lib_LIBRARIES = libdst.a
265  
266 -noinst_LIBRARIES = libdstnomd5.a
267 +noinst_LIBRARIES = libdstnomd5.a libdstLIBDHCP.a
268  
269  libdst_a_SOURCES = dst_support.c dst_api.c hmac_link.c md5_dgst.c \
270                    base64.c prandom.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 \
273                    base64.c prandom.c
274  
275 +libdstLIBDHCP_a_CFLAGS = -DLIBDHCP
276 +libdstLIBDHCP_a_SOURCES = dst_support.c dst_api.c hmac_link.c md5_dgst.c \
277 +                  base64.c prandom.c
278 +
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
284  
285  #include "dst_internal.h"
286  
287 +#ifdef LIBDHCP
288 +extern void* dmalloc(size_t,char *,int);
289 +#endif
290 +
291  #ifdef USE_MD5
292  # include "md5.h"
293  # ifndef _MD5_H_
294 @@ -87,7 +91,11 @@ dst_hmac_md5_sign(const int mode, DST_KE
295         MD5_CTX *ctx = NULL;
296  
297         if (mode & SIG_MODE_INIT) 
298 +#ifdef LIBDHCP
299 +               ctx = (MD5_CTX *) dmalloc(sizeof(*ctx),__FILE__,__LINE__);
300 +#else
301                 ctx = (MD5_CTX *) malloc(sizeof(*ctx));
302 +#endif
303         else if (context)
304                 ctx = (MD5_CTX *) *context;
305         if (ctx == NULL) 
306 @@ -154,7 +162,11 @@ dst_hmac_md5_verify(const int mode, DST_
307         MD5_CTX *ctx = NULL;
308  
309         if (mode & SIG_MODE_INIT) 
310 +#ifdef LIBDHCP
311 +               ctx = (MD5_CTX *) dmalloc(sizeof(*ctx),__FILE__,__LINE__);
312 +#else
313                 ctx = (MD5_CTX *) malloc(sizeof(*ctx));
314 +#endif
315         else if (context)
316                 ctx = (MD5_CTX *) *context;
317         if (ctx == NULL) 
318 @@ -218,8 +230,11 @@ dst_buffer_to_hmac_md5(DST_KEY *dkey, co
319  
320         if (dkey == NULL || key == NULL || keylen < 0)
321                 return (-1);
322 -
323 +#ifdef  LIBDHCP
324 +       if ((hkey = (HMAC_Key *) dmalloc(sizeof(HMAC_Key),__FILE__,__LINE__)) == NULL)
325 +#else
326         if ((hkey = (HMAC_Key *) malloc(sizeof(HMAC_Key))) == NULL)
327 +#endif
328                   return (-2);
329  
330         memset(hkey->hk_ipad, 0, sizeof(hkey->hk_ipad));
331 @@ -348,7 +363,11 @@ dst_hmac_md5_key_from_file_format(DST_KE
332         if (eol == NULL)
333                 return (-4);
334         len = eol - p;
335 +#ifdef LIBDHCP
336 +       tmp = dmalloc(len + 2,__FILE__,__LINE__);
337 +#else
338         tmp = malloc(len + 2);
339 +#endif
340         memcpy(tmp, p, len);
341         *(tmp + len) = 0x0;
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, 
344                 return(0);
345         
346         len = size > 64 ? 64 : size;
347 +#ifdef LIBDHCP
348 +       buff = dmalloc(len+8,__FILE__,__LINE__);
349 +#else
350         buff = malloc(len+8);
351 -
352 +#endif
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()
357  {
358         if (dst_t_func[KEY_HMAC_MD5] != NULL)
359                 return (1);
360 +#ifdef LIBDHCP
361 +       dst_t_func[KEY_HMAC_MD5] = dmalloc(sizeof(struct dst_func),__FILE__,__LINE__);
362 +#else
363         dst_t_func[KEY_HMAC_MD5] = malloc(sizeof(struct dst_func));
364 +#endif
365         if (dst_t_func[KEY_HMAC_MD5] == NULL)
366                 return (0);
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
371 @@ -1,11 +1,17 @@
372  AM_CPPFLAGS = -I.. -DLOCALSTATEDIR='"@localstatedir@"'
373  
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 \
380                     tree.c upf.c heap.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)
389  
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. */
396  
397 +#ifdef LIBDHCP
398 +int have_setup_fallback = 0;
399 +#endif
400 +
401  void 
402  discover_interfaces(int state) {
403         struct iface_conf_list ifaces;
404 @@ -902,7 +906,9 @@ discover_interfaces(int state) {
405         isc_result_t status;
406         int wifcount = 0;
407  
408 +#ifndef LIBDHCP
409         static int setup_fallback = 0;
410 +#endif
411  
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!");
416         }
417  
418 +#ifdef LIBDHCP
419 +       if ((local_family == AF_INET) && !have_setup_fallback) {
420 +               have_setup_fallback = 1;
421 +               maybe_setup_fallback ();
422 +       }
423 +#else
424         if ((local_family == AF_INET) && !setup_fallback) {
425                 setup_fallback = 1;
426                 maybe_setup_fallback();
427         }
428 +#endif
429  
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
435 @@ -41,7 +41,7 @@
436  # include <regex.h>
437  #endif
438  
439 -struct binding_scope *global_scope;
440 +struct binding_scope __attribute__ ((visibility ("default"))) *global_scope;
441  
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. */
447  
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
456         return 0;
457  }
458  
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
466 @@ -34,8 +34,24 @@
467  
468  #include "dhcpd.h"
469  
470 -struct timeout *timeouts;
471 -static struct timeout *free_timeouts;
472 +struct timeout {
473 +#ifndef LIBDHCP
474 +       struct timeout *next;
475 +#endif
476 +       TIME when;
477 +       void (*func) PROTO ((void *));
478 +       void *what;
479 +       tvref_t ref;
480 +       tvunref_t unref;
481 +};
482 +
483 +#ifdef LIBDHCP
484 +static struct timeout *timeouts = NULL;
485 +static int ntimeouts = 0;
486 +#else
487 +static struct timeout *timeouts = NULL;
488 +static struct timeout *free_timeouts = NULL;
489 +#endif
490  
491  void set_time(TIME t)
492  {
493 @@ -48,9 +64,41 @@ void set_time(TIME t)
494  
495  struct timeval *process_outstanding_timeouts (struct timeval *tvp)
496  {
497 +#ifdef LIBDHCP
498 +       int i;
499 +       struct timeout t = { 0 };
500 +#endif
501         /* Call any expired timeouts, and then if there's
502            still a timeout registered, time out the select
503            call then. */
504 +#ifdef LIBDHCP
505 +       if (!ntimeouts)
506 +               return NULL;
507 +
508 +       for (i = 0; i < ntimeouts && timeouts[i].when <= cur_time;) {
509 +               struct timeout *new_timeouts;
510 +               size_t n;
511 +
512 +               memmove(&t, &timeouts[i], sizeof (t));
513 +
514 +               n = (ntimeouts - i - 1) * sizeof (t);
515 +               memmove(&timeouts[i+1], &timeouts[i], n);
516 +
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;
522 +
523 +               if (t.func)
524 +                       t.func(t.what);
525 +               if (t.unref)
526 +                       t.unref(t.what, MDL);
527 +       }
528 +       if (tvp && ntimeouts) {
529 +               tvp->tv_sec = timeouts[0].when;
530 +               tvp->tv_usec = 0;
531 +#else
532        another:
533         if (timeouts) {
534                 struct timeout *t;
535 @@ -68,9 +116,15 @@ struct timeval *process_outstanding_time
536                         tvp -> tv_sec = timeouts -> when;
537                         tvp -> tv_usec = 0;
538                 }
539 +#endif
540                 return tvp;
541 +#ifdef LIBDHCP
542 +       }
543 +       return NULL;
544 +#else
545         } else
546                 return (struct timeval *)0;
547 +#endif
548  }
549  
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
552         tvref_t ref;
553         tvunref_t unref;
554  {
555 +#ifdef LIBDHCP
556 +       struct timeout t = {
557 +               .when = when,
558 +               .func = where,
559 +               .what = what,
560 +               .ref = ref,
561 +               .unref = unref
562 +       };
563 +       struct timeout *new_timeouts;
564 +       int i, pos = 0;
565 +#else
566         struct timeout *t, *q;
567 +#endif
568  
569         /* See if this timeout supersedes an existing timeout. */
570 +#ifdef LIBDHCP
571 +       for (i = 0; i < ntimeouts; i++) {
572 +               struct timeout *q = &timeouts[i];
573 +#else
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) {
579                         if (t)
580                                 t -> next = q -> next;
581                         else
582 @@ -114,7 +183,29 @@ void add_timeout (when, where, what, ref
583                 }
584                 t = q;
585         }
586 +#endif
587  
588 +#ifdef LIBDHCP
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) &&
592 +                               q->what == what) {
593 +                       size_t n = (--ntimeouts - i) * sizeof (*q);
594 +                       memmove(&t, q, sizeof (t));
595 +
596 +                       if (n)
597 +                               memmove(&timeouts[i], &timeouts[i+1], n);
598 +
599 +                       if (ntimeouts) {
600 +                               new_timeouts = realloc(timeouts, ntimeouts * sizeof (*q));
601 +                               /* XXX broken API, no way to return error here */
602 +                               if (new_timeouts)
603 +                                       timeouts = new_timeouts;
604 +                       } else {
605 +                               timeouts = NULL;
606 +                       }
607 +                       add_timeout(when, where, what, ref, unref);
608 +#else
609         /* If we didn't supersede a timeout, allocate a timeout
610            structure now. */
611         if (!q) {
612 @@ -123,7 +214,7 @@ void add_timeout (when, where, what, ref
613                         free_timeouts = q -> next;
614                 } else {
615                         q = ((struct timeout *)
616 -                            dmalloc (sizeof (struct timeout), MDL));
617 +                               dmalloc (sizeof (struct timeout), MDL));
618                         if (!q)
619                                 log_fatal ("add_timeout: no memory!");
620                 }
621 @@ -153,22 +244,76 @@ void add_timeout (when, where, what, ref
622                 if (t -> next -> when > q -> when) {
623                         q -> next = t -> next;
624                         t -> next = q;
625 +#endif
626                         return;
627 +#ifdef LIBDHCP
628 +               } else if (timeouts[i].when > when) {
629 +                       pos = i;
630 +#endif
631                 }
632         }
633  
634 +#ifdef LIBDHCP
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. */
638 +
639 +       new_timeouts = realloc(timeouts, sizeof (t) * (ntimeouts+1));
640 +       /* XXX broken API, no way to return error here */
641 +       if (new_timeouts) {
642 +               /* ntimeouts = 10
643 +                * pos = 3;
644 +                * n = 10-3 * sizeof (t) = 7 * sizeof (t) 
645 +                */
646 +               size_t n = (ntimeouts - pos) * sizeof (t);
647 +
648 +               timeouts = new_timeouts;
649 +               memmove(&timeouts[pos+1], &timeouts[pos], n);
650 +               memmove(&timeouts[pos], &t, sizeof (t));
651 +               ntimeouts++;
652 +       }
653 +#else
654         /* End of list. */
655         t -> next = q;
656         q -> next = (struct timeout *)0;
657 +#endif
658  }
659  
660  void cancel_timeout (where, what)
661         void (*where) PROTO ((void *));
662         void *what;
663  {
664 +#ifdef LIBDHCP
665 +       struct timeout t;
666 +       int i = 0;
667 +#else
668         struct timeout *t, *q;
669 +#endif
670  
671         /* Look for this timeout on the list, and unlink it if we find it. */
672 +#ifdef LIBDHCP
673 +       for (i = 0; i < ntimeouts; i++) {
674 +               struct timeout *new_timeouts, *q = &timeouts[i];
675 +
676 +               if (q->func == where && q->what == what) {
677 +                       size_t n;
678 +
679 +                       memmove(&t, q, sizeof (t));
680 +
681 +                       n = (ntimeouts - i - 1) * sizeof (t);
682 +                       memmove(&timeouts[i+1], &timeouts[i], n);
683 +
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;
689 +
690 +                       if (t.unref)
691 +                               t.unref(t.what, MDL);
692 +               }
693 +       }
694 +#else
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;
700                 free_timeouts = q;
701         }
702 +#endif
703  }
704  
705  void cancel_all_timeouts ()
706  {
707 +#ifdef LIBDHCP
708 +       cur_time = TIME_MAX;
709 +       process_outstanding_timeouts(NULL);
710 +#else
711         struct timeout *t, *n;
712         for (t = timeouts; t; t = n) {
713                 n = t -> next;
714 @@ -200,13 +350,20 @@ void cancel_all_timeouts ()
715                 t -> next = free_timeouts;
716                 free_timeouts = t;
717         }
718 +#endif
719  }
720  
721 +__attribute__ ((visibility ("default")))
722  void relinquish_timeouts ()
723  {
724 +#ifdef LIBDHCP
725 +       while (ntimeouts)
726 +               cancel_timeout(timeouts[0].func, timeouts[0].what);
727 +#else
728         struct timeout *t, *n;
729         for (t = free_timeouts; t; t = n) {
730                 n = t -> next;
731                 dfree (t, MDL);
732         }
733 +#endif
734  }
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,
739         return 1;
740  }
741  
742 +#ifdef LIBDHCP
743 +struct packet *free_packets;
744 +#else
745  static struct packet *free_packets;
746 +#endif
747  
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 {
754  
755  typedef void (*tvref_t)(void *, void *, const char *, int);
756  typedef void (*tvunref_t)(void *, const char *, int);
757 -struct timeout {
758 -       struct timeout *next;
759 -       TIME when;
760 -       void (*func) PROTO ((void *));
761 -       void *what;
762 -       tvref_t ref;
763 -       tvunref_t unref;
764 -};
765  
766  struct protocol {
767         struct protocol *next;
768 @@ -1664,7 +1656,6 @@ extern const char *path_dhcpd_pid;
769  
770  extern int dhcp_max_agent_option_packet_length;
771  
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 *,
778                                      const char *, int,
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
798 @@ -1,10 +1,18 @@
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)
816  
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;
823  
824 +#ifdef LIBDHCP
825 +FILE *leaseFile = NULL;
826 +#endif
827 +
828  extern u_int32_t default_requested_options[];
829  
830  static void usage PROTO ((void));
831  
832  static isc_result_t write_duid(struct data_string *duid);
833  
834 -int 
835 -main(int argc, char **argv) {
836 +#ifdef LIBDHCP
837 +#include "isc-dhcp/libdhcp_control.h"
838 +LIBDHCP_Control *libdhcp_control;
839 +static void libdhcp_dispatch(void)
840 +{
841 +       struct timeval tv = { 0, 0 }, *tvp;
842 +       isc_result_t status;
843 +
844 +       /* Wait for a packet, or a timeout, or libdhcp being finished */
845 +       do {
846 +               tvp = process_outstanding_timeouts(&tv);
847 +               status = omapi_one_dispatch(0, tvp);
848 +
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);
852 +
853 +                       break;
854 +               }
855 +       } while ((status != ISC_R_TIMEDOUT) && ((!libdhcp_control) || (!(libdhcp_control->finished))));
856 +}
857 +
858 +extern void omapi_free_all_pointers(void);
859 +
860 +__attribute__ ((visibility ("default")))
861 +int dhcpv4_client (LIBDHCP_Control *libdhcp_ctl, int argc, char **argv,
862 +                   char **envp)
863 +#else
864 +int main(int argc, char **argv, char **envp)
865 +#endif
866 +{
867 +#ifdef LIBDHCP
868 +       libdhcp_control = libdhcp_ctl;
869 +#endif
870         int fd;
871         int i;
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));
876  
877 +#ifndef LIBDHCP
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));
884  #endif 
885 +#endif
886  
887         /* Set up the OMAPI. */
888         status = omapi_init ();
889 @@ -485,8 +523,12 @@ main(int argc, char **argv) {
890                 }
891         }
892  
893 +#ifdef LIBDHCP
894 +       if (libdhcp_control && (libdhcp_control->capability & DHCP_USE_PID_FILE))
895 +#endif
896         write_client_pid_file();
897  
898 +#ifndef LIBDHCP
899         if (!quiet) {
900                 log_info ("%s %s", message, PACKAGE_VERSION);
901                 log_info (copyright);
902 @@ -497,6 +539,7 @@ main(int argc, char **argv) {
903                 log_perror = 0;
904                 quiet_interface_discovery = 1;
905         }
906 +#endif
907  
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) {
911                 arg_conf_len = 0;
912         }
913  
914 +#ifdef LIBDHCP
915 +       if (libdhcp_control && (libdhcp_control->capability & DHCP_USE_LEASE_DATABASE)) {
916 +#endif
917         /* Parse the lease database. */
918         read_client_leases ();
919  
920         /* Rewrite the lease database... */
921         rewrite_client_leases ();
922 +#ifdef LIBDHCP
923 +       }
924 +#endif
925  
926         /* XXX */
927  /*     config_counter(&snd_counter, &rcv_counter); */
928 @@ -725,7 +774,7 @@ main(int argc, char **argv) {
929                 if (!persist) {
930                         /* Nothing more to do. */
931                         log_info ("No broadcast interfaces found - exiting.");
932 -                       exit (0);
933 +                       return (0);
934                 }
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;
939  #endif
940  
941 +#ifndef LIBDHCP
942         /* If we're not supposed to wait before getting the address,
943            don't. */
944         if (nowait)
945 @@ -875,6 +925,132 @@ main(int argc, char **argv) {
946  
947         /* Start dispatching packets and timeouts... */
948         dispatch ();
949 +#else
950 +       if (libdhcp_control) {
951 +               if (libdhcp_control->timeout)
952 +                       libdhcp_control->now = time(NULL);
953 +               else
954 +                       libdhcp_control->now = 0;
955 +       }
956 +
957 +       libdhcp_dispatch();
958 +
959 +       /* libdhcp is finished with us. */
960 +
961 +       /* close all file descriptors:  */
962 +       for (ip = interfaces; ip; ip = ip->next) {
963 +               shutdown(ip->wfdesc, SHUT_RDWR);
964 +               close(ip->wfdesc);
965 +
966 +               if (ip->rfdesc != ip->wfdesc)
967 +                       close(ip->rfdesc);
968 +       }
969 +
970 +       if (fallback_interface != 0) {
971 +               ip = fallback_interface;
972 +               shutdown(ip->wfdesc, SHUT_RDWR);
973 +               close(ip->wfdesc);
974 +
975 +               if (ip->rfdesc != ip->wfdesc)
976 +                       close(ip->rfdesc);
977 +       }
978 +
979 +       if (leaseFile)
980 +               fclose (leaseFile);
981 +
982 +       closelog();
983 +
984 +       char *current_pid_file = _PATH_DHCLIENT_PID;
985 +
986 +       /* Free ALL allocated memory: */
987 +       omapi_free_all_pointers();
988 +
989 +       /* Re-Initialize globals: */
990 +       client_env = 0;
991 +       client_env_count = 0;
992 +       default_lease_time = 43200;
993 +
994 +       dhcp_max_agent_option_packet_length = 0;
995 +       iaddr_any.len = 4;
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;
1000 +       leaseFile = 0;
1001 +
1002 +       libdhcp_control = 0;
1003 +
1004 +       local_port = 0;
1005 +       no_daemon = 0;
1006 +       nowait = 0;
1007 +       onetry = 0;
1008 +       quiet = 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;
1015 +       remote_port = 0;
1016 +       resolver_inited = 0;
1017 +       log_perror = 1;
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;
1027 +#ifndef LIBDHCP
1028 +       timeouts = NULL;
1029 +#endif
1030 +       dhcp_type_interface = NULL;
1031 +       interface_vector = NULL;
1032 +       interface_count = 0;
1033 +       interface_max = 0;
1034 +       name_servers = 0;
1035 +       domains = 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;
1050 +       universes = 0;
1051 +       universe_count = 0;
1052 +       universe_max = 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);
1074 +#endif
1075  
1076         /*NOTREACHED*/
1077         return 0;
1078 @@ -1270,7 +1446,20 @@ void dhcpack (packet)
1079         if (client -> new -> rebind < cur_time)
1080                 client -> new -> rebind = TIME_MAX;
1081  
1082 +#ifdef LIBDHCP
1083 +       /* We need the server's siaddr for the 'bootServer'
1084 +        * pump option
1085 +        */
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;
1089 +#endif
1090 +
1091         bind_lease (client);
1092 +
1093 +#ifdef LIBDHCP
1094 +       client->packet.siaddr.s_addr = set_siaddr;
1095 +#endif
1096  }
1097  
1098  void bind_lease (client)
1099 @@ -1306,6 +1495,9 @@ void bind_lease (client)
1100                 return;
1101         }
1102  
1103 +#ifdef LIBDHCP
1104 +       if (libdhcp_control && (libdhcp_control->capability & DHCP_USE_LEASE_DATABASE))
1105 +#endif
1106         /* Write out the new lease. */
1107         write_client_lease (client, client -> new, 0, 0);
1108  
1109 @@ -1398,10 +1590,12 @@ void state_stop (cpp)
1110         }
1111  }  
1112  
1113 +#ifndef LIBDHCP
1114  int commit_leases ()
1115  {
1116         return 0;
1117  }
1118 +#endif
1119  
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. */
1125         if (onetry) {
1126 +#ifdef LIBDHCP
1127 +               script_init (client, "FAIL", (struct string_list *)0);
1128 +               return;
1129 +#endif
1130                 if (!quiet)
1131                         log_info ("Unable to obtain a lease on first try.%s",
1132                                   "  Exiting.");
1133 @@ -2691,7 +2889,9 @@ void destroy_client_lease (lease)
1134         free_client_lease (lease, MDL);
1135  }
1136  
1137 +#ifndef LIBDHCP
1138  FILE *leaseFile = NULL;
1139 +#endif
1140  int leases_written = 0;
1141  
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;
1146  {
1147 +#ifdef LIBDHCP
1148 +       struct string_list *sp;
1149 +
1150 +       if (libdhcp_control && libdhcp_control->callback) {
1151 +               int dhcmsg;
1152 +               char *reason="";
1153 +
1154 +               for (sp = client->env; sp; sp = sp->next)
1155 +                       if (strncmp(sp->string, "reason=", 7) == 0) {
1156 +                               reason = sp->string + 7;
1157 +                               break;
1158 +                       }
1159 +
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;
1184 +               else
1185 +                       dhcmsg = DHC4_NBI;
1186 +
1187 +               (*libdhcp_control->callback) (libdhcp_control, dhcmsg, client);
1188 +
1189 +               if (libdhcp_control->decline)
1190 +                       return 1;
1191 +       }
1192 +
1193 +       return 0;
1194 +#else
1195         char *scriptName;
1196         char *argv [2];
1197         char **envp;
1198 @@ -3294,6 +3542,7 @@ int script_go (client)
1199         time(&cur_time);
1200         return (WIFEXITED (wstatus) ?
1201                 WEXITSTATUS (wstatus) : -WTERMSIG (wstatus));
1202 +#endif
1203  }
1204  
1205  void client_envadd (struct client_state *client,
1206 @@ -3376,6 +3625,9 @@ void go_daemon ()
1207  
1208         /* Don't become a daemon if the user requested otherwise. */
1209         if (no_daemon) {
1210 +#ifdef LIBDHCP
1211 +               if (libdhcp_control && (libdhcp_control->capability & DHCP_USE_PID_FILE))
1212 +#endif
1213                 write_client_pid_file ();
1214                 return;
1215         }
1216 @@ -3385,6 +3637,10 @@ void go_daemon ()
1217                 return;
1218         state = 1;
1219  
1220 +#ifdef LIBDHCP
1221 +       return;
1222 +#endif
1223 +
1224         /* Stop logging to stderr... */
1225         log_perror = 0;
1226  
This page took 0.267918 seconds and 3 git commands to generate.