]> git.pld-linux.org Git - packages/dhcp.git/blob - dhcp-libdhcp4client.patch
8bc329a2b6bdc08512a785f6c909d7c71477e8bb
[packages/dhcp.git] / dhcp-libdhcp4client.patch
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
3 @@ -1,5 +1,32 @@
4  AC_INIT([DHCP], [4.0.0], [dhcp-users@isc.org])
5  
6 +dnl Versioning
7 +dnl (from glib's configure.in ...)
8 +dnl Making releases:
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.
16 +DHCP_MAJOR_VERSION=4
17 +DHCP_MINOR_VERSION=0
18 +DHCP_MICRO_VERSION=0
19 +DHCP_INTERFACE_AGE=0
20 +DHCP_BINARY_AGE=0
21 +DHCP_VERSION_SUFFIX=
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)
28 +AC_SUBST(LT_RELEASE)
29 +AC_SUBST(LT_CURRENT)
30 +AC_SUBST(LT_REVISION)
31 +AC_SUBST(LT_AGE)
32 +
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
37         fi
38  fi
39  
40 -AC_PROG_RANLIB
41 +AC_PROG_LIBTOOL
42 +
43  AC_CONFIG_HEADERS([includes/config.h])
44  
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
48 @@ -1,10 +1,18 @@
49  lib_LIBRARIES = libomapi.a
50 +noinst_LIBRARIES = libomapiLIBDHCP.a
51  noinst_PROGRAMS = svtest
52  
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
57 +
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 \
62 +                    protocol.c
63 +
64  man_MANS = omapi.3
65  EXTRA_DIST = $(man_MANS)
66  
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
69 @@ -37,7 +37,7 @@
70  #include <omapip/omapip_p.h>
71  #include <sys/time.h>
72  
73 -static omapi_io_object_t omapi_io_states;
74 +omapi_io_object_t omapi_io_states;
75  struct timeval cur_tv;
76  
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
81 @@ -37,6 +37,11 @@
82  #include <errno.h>
83  #include <syslog.h>
84  
85 +#ifdef LIBDHCP
86 +#include <isc-dhcp/libdhcp_control.h>
87 +extern LIBDHCP_Control *libdhcp_control;
88 +#endif
89 +
90  #ifdef DEBUG
91  int log_perror = -1;
92  #else
93 @@ -46,7 +51,9 @@ int log_priority;
94  void (*log_cleanup) (void);
95  
96  #define CVT_BUF_MAX 1023
97 +#ifndef LIBDHCP
98  static char mbuf [CVT_BUF_MAX + 1];
99 +#endif
100  static char fbuf [CVT_BUF_MAX + 1];
101  
102  /* Log an error message, then exit... */
103 @@ -56,6 +63,16 @@ void log_fatal (const char * fmt, ... )
104    va_list list;
105  
106    do_percentm (fbuf, fmt);
107 +  
108 +#ifdef LIBDHCP
109 +  if (libdhcp_control && (libdhcp_control->eh)) {
110 +      va_start (list, fmt);
111 +      libdhcp_control->eh(libdhcp_control, LOG_FATAL, fbuf, list);
112 +      va_end(list);
113 +      libdhcp_control->finished = 1;
114 +      return;
115 +  }
116 +#else
117  
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, ... )
121    if (log_cleanup)
122           (*log_cleanup) ();
123    exit (1);
124 +#endif
125  }
126  
127  /* Log an error message... */
128 @@ -99,6 +117,13 @@ int log_error (const char * fmt, ...)
129  
130    do_percentm (fbuf, fmt);
131  
132 +#ifdef LIBDHCP
133 +  if (libdhcp_control && libdhcp_control->eh) {
134 +      va_start (list, fmt);
135 +      libdhcp_control->eh(libdhcp_control, LOG_ERR, fbuf, list);
136 +      va_end(list);
137 +  }
138 +#else
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.
141     */
142 @@ -114,7 +139,7 @@ int log_error (const char * fmt, ...)
143           write (STDERR_FILENO, mbuf, strlen (mbuf));
144           write (STDERR_FILENO, "\n", 1);
145    }
146 -
147 +#endif
148    return 0;
149  }
150  
151 @@ -126,6 +151,13 @@ int log_info (const char *fmt, ...)
152  
153    do_percentm (fbuf, fmt);
154  
155 +#ifdef LIBDHCP
156 +  if (libdhcp_control && libdhcp_control->eh) {
157 +      va_start (list, fmt);
158 +      libdhcp_control->eh(libdhcp_control, LOG_INFO, fbuf, list);
159 +      va_end(list);
160 +  }
161 +#else
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.
164     */
165 @@ -141,7 +173,7 @@ int log_info (const char *fmt, ...)
166           write (STDERR_FILENO, mbuf, strlen (mbuf));
167           write (STDERR_FILENO, "\n", 1);
168    }
169 -
170 +#endif
171    return 0;
172  }
173  
174 @@ -152,7 +184,13 @@ int log_debug (const char *fmt, ...)
175    va_list list;
176  
177    do_percentm (fbuf, fmt);
178 -
179 +#ifdef LIBDHCP
180 +  if (libdhcp_control && libdhcp_control->eh) {
181 +      va_start (list, fmt);
182 +      libdhcp_control->eh(libdhcp_control, LOG_DEBUG, fbuf, list);
183 +      va_end(list);
184 +  }
185 +#else
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.
188     */
189 @@ -168,7 +206,7 @@ int log_debug (const char *fmt, ...)
190           write (STDERR_FILENO, mbuf, strlen (mbuf));
191           write (STDERR_FILENO, "\n", 1);
192    }
193 -
194 +#endif
195    return 0;
196  }
197  
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
200 @@ -37,6 +37,33 @@
201  
202  #include <omapip/omapip_p.h>
203  
204 +#ifdef LIBDHCP
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.
208 +*/
209 +#include <search.h>  
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));
214 +}
215 +
216 +static void record_pointer(void *ptr) {
217 +    tsearch(ptr, &(all_pointers), ptr_comparator);
218 +}
219 +
220 +static void forget_pointer(void *ptr) {
221 +    tdelete(ptr, &(all_pointers), ptr_comparator);
222 +}
223 +
224 +void omapi_free_all_pointers(void) {
225 +    if (all_pointers != NULL)
226 +               tdestroy(all_pointers, free);
227 +    all_pointers = NULL;
228 +}
229 +#endif
230 +
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,
235                 return NULL;
236  
237         foo = malloc(len);
238 -
239 +#ifdef LIBDHCP
240 +       record_pointer(foo);
241 +#endif
242         if (!foo)
243                 return NULL;
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);
247  #endif
248         free (ptr);
249 +#ifdef LIBDHCP
250 +       forget_pointer(ptr);
251 +#endif
252  }
253  
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
258  
259  lib_LIBRARIES = libdst.a
260  
261 -noinst_LIBRARIES = libdstnomd5.a
262 +noinst_LIBRARIES = libdstnomd5.a libdstLIBDHCP.a
263  
264  libdst_a_SOURCES = dst_support.c dst_api.c hmac_link.c md5_dgst.c \
265                    base64.c prandom.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 \
268                    base64.c prandom.c
269  
270 +libdstLIBDHCP_a_CFLAGS = -DLIBDHCP
271 +libdstLIBDHCP_a_SOURCES = dst_support.c dst_api.c hmac_link.c md5_dgst.c \
272 +                  base64.c prandom.c
273 +
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
278  
279  #include "dst_internal.h"
280  
281 +#ifdef LIBDHCP
282 +extern void* dmalloc(size_t,char *,int);
283 +#endif
284 +
285  #ifdef USE_MD5
286  # include "md5.h"
287  # ifndef _MD5_H_
288 @@ -87,7 +91,11 @@ dst_hmac_md5_sign(const int mode, DST_KE
289         MD5_CTX *ctx = NULL;
290  
291         if (mode & SIG_MODE_INIT) 
292 +#ifdef LIBDHCP
293 +               ctx = (MD5_CTX *) dmalloc(sizeof(*ctx),__FILE__,__LINE__);
294 +#else
295                 ctx = (MD5_CTX *) malloc(sizeof(*ctx));
296 +#endif
297         else if (context)
298                 ctx = (MD5_CTX *) *context;
299         if (ctx == NULL) 
300 @@ -154,7 +162,11 @@ dst_hmac_md5_verify(const int mode, DST_
301         MD5_CTX *ctx = NULL;
302  
303         if (mode & SIG_MODE_INIT) 
304 +#ifdef LIBDHCP
305 +               ctx = (MD5_CTX *) dmalloc(sizeof(*ctx),__FILE__,__LINE__);
306 +#else
307                 ctx = (MD5_CTX *) malloc(sizeof(*ctx));
308 +#endif
309         else if (context)
310                 ctx = (MD5_CTX *) *context;
311         if (ctx == NULL) 
312 @@ -218,8 +230,11 @@ dst_buffer_to_hmac_md5(DST_KEY *dkey, co
313  
314         if (dkey == NULL || key == NULL || keylen < 0)
315                 return (-1);
316 -
317 +#ifdef  LIBDHCP
318 +       if ((hkey = (HMAC_Key *) dmalloc(sizeof(HMAC_Key),__FILE__,__LINE__)) == NULL)
319 +#else
320         if ((hkey = (HMAC_Key *) malloc(sizeof(HMAC_Key))) == NULL)
321 +#endif
322                   return (-2);
323  
324         memset(hkey->hk_ipad, 0, sizeof(hkey->hk_ipad));
325 @@ -348,7 +363,11 @@ dst_hmac_md5_key_from_file_format(DST_KE
326         if (eol == NULL)
327                 return (-4);
328         len = eol - p;
329 +#ifdef LIBDHCP
330 +       tmp = dmalloc(len + 2,__FILE__,__LINE__);
331 +#else
332         tmp = malloc(len + 2);
333 +#endif
334         memcpy(tmp, p, len);
335         *(tmp + len) = 0x0;
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, 
338                 return(0);
339         
340         len = size > 64 ? 64 : size;
341 +#ifdef LIBDHCP
342 +       buff = dmalloc(len+8,__FILE__,__LINE__);
343 +#else
344         buff = malloc(len+8);
345 -
346 +#endif
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()
351  {
352         if (dst_t_func[KEY_HMAC_MD5] != NULL)
353                 return (1);
354 +#ifdef LIBDHCP
355 +       dst_t_func[KEY_HMAC_MD5] = dmalloc(sizeof(struct dst_func),__FILE__,__LINE__);
356 +#else
357         dst_t_func[KEY_HMAC_MD5] = malloc(sizeof(struct dst_func));
358 +#endif
359         if (dst_t_func[KEY_HMAC_MD5] == NULL)
360                 return (0);
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
364 @@ -1,11 +1,17 @@
365  AM_CPPFLAGS = -I.. -DLOCALSTATEDIR='"@localstatedir@"'
366  
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 \
373                     tree.c upf.c heap.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)
382  
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. */
388  
389 +#ifdef LIBDHCP
390 +int have_setup_fallback = 0;
391 +#endif
392 +
393  void 
394  discover_interfaces(int state) {
395         struct iface_conf_list ifaces;
396 @@ -902,7 +906,9 @@ discover_interfaces(int state) {
397         isc_result_t status;
398         int wifcount = 0;
399  
400 +#ifndef LIBDHCP
401         static int setup_fallback = 0;
402 +#endif
403  
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!");
408         }
409  
410 +#ifdef LIBDHCP
411 +       if ((local_family == AF_INET) && !have_setup_fallback) {
412 +               have_setup_fallback = 1;
413 +               maybe_setup_fallback ();
414 +       }
415 +#else
416         if ((local_family == AF_INET) && !setup_fallback) {
417                 setup_fallback = 1;
418                 maybe_setup_fallback();
419         }
420 +#endif
421  
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
426 @@ -41,7 +41,7 @@
427  # include <regex.h>
428  #endif
429  
430 -struct binding_scope *global_scope;
431 +struct binding_scope __attribute__ ((visibility ("default"))) *global_scope;
432  
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. */
438  
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
446         return 0;
447  }
448  
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
455 @@ -34,8 +34,24 @@
456  
457  #include "dhcpd.h"
458  
459 -struct timeout *timeouts;
460 -static struct timeout *free_timeouts;
461 +struct timeout {
462 +#ifndef LIBDHCP
463 +       struct timeout *next;
464 +#endif
465 +       TIME when;
466 +       void (*func) PROTO ((void *));
467 +       void *what;
468 +       tvref_t ref;
469 +       tvunref_t unref;
470 +};
471 +
472 +#ifdef LIBDHCP
473 +static struct timeout *timeouts = NULL;
474 +static int ntimeouts = 0;
475 +#else
476 +static struct timeout *timeouts = NULL;
477 +static struct timeout *free_timeouts = NULL;
478 +#endif
479  
480  void set_time(TIME t)
481  {
482 @@ -48,9 +64,41 @@ void set_time(TIME t)
483  
484  struct timeval *process_outstanding_timeouts (struct timeval *tvp)
485  {
486 +#ifdef LIBDHCP
487 +       int i;
488 +       struct timeout t = { 0 };
489 +#endif
490         /* Call any expired timeouts, and then if there's
491            still a timeout registered, time out the select
492            call then. */
493 +#ifdef LIBDHCP
494 +       if (!ntimeouts)
495 +               return NULL;
496 +
497 +       for (i = 0; i < ntimeouts && timeouts[i].when <= cur_time;) {
498 +               struct timeout *new_timeouts;
499 +               size_t n;
500 +
501 +               memmove(&t, &timeouts[i], sizeof (t));
502 +
503 +               n = (ntimeouts - i - 1) * sizeof (t);
504 +               memmove(&timeouts[i+1], &timeouts[i], n);
505 +
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;
511 +
512 +               if (t.func)
513 +                       t.func(t.what);
514 +               if (t.unref)
515 +                       t.unref(t.what, MDL);
516 +       }
517 +       if (tvp && ntimeouts) {
518 +               tvp->tv_sec = timeouts[0].when;
519 +               tvp->tv_usec = 0;
520 +#else
521        another:
522         if (timeouts) {
523                 struct timeout *t;
524 @@ -68,9 +116,15 @@ struct timeval *process_outstanding_time
525                         tvp -> tv_sec = timeouts -> when;
526                         tvp -> tv_usec = 0;
527                 }
528 +#endif
529                 return tvp;
530 +#ifdef LIBDHCP
531 +       }
532 +       return NULL;
533 +#else
534         } else
535                 return (struct timeval *)0;
536 +#endif
537  }
538  
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
541         tvref_t ref;
542         tvunref_t unref;
543  {
544 +#ifdef LIBDHCP
545 +       struct timeout t = {
546 +               .when = when,
547 +               .func = where,
548 +               .what = what,
549 +               .ref = ref,
550 +               .unref = unref
551 +       };
552 +       struct timeout *new_timeouts;
553 +       int i, pos = 0;
554 +#else
555         struct timeout *t, *q;
556 +#endif
557  
558         /* See if this timeout supersedes an existing timeout. */
559 +#ifdef LIBDHCP
560 +       for (i = 0; i < ntimeouts; i++) {
561 +               struct timeout *q = &timeouts[i];
562 +#else
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) {
568                         if (t)
569                                 t -> next = q -> next;
570                         else
571 @@ -114,7 +183,29 @@ void add_timeout (when, where, what, ref
572                 }
573                 t = q;
574         }
575 +#endif
576  
577 +#ifdef LIBDHCP
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) &&
581 +                               q->what == what) {
582 +                       size_t n = (--ntimeouts - i) * sizeof (*q);
583 +                       memmove(&t, q, sizeof (t));
584 +
585 +                       if (n)
586 +                               memmove(&timeouts[i], &timeouts[i+1], n);
587 +
588 +                       if (ntimeouts) {
589 +                               new_timeouts = realloc(timeouts, ntimeouts * sizeof (*q));
590 +                               /* XXX broken API, no way to return error here */
591 +                               if (new_timeouts)
592 +                                       timeouts = new_timeouts;
593 +                       } else {
594 +                               timeouts = NULL;
595 +                       }
596 +                       add_timeout(when, where, what, ref, unref);
597 +#else
598         /* If we didn't supersede a timeout, allocate a timeout
599            structure now. */
600         if (!q) {
601 @@ -123,7 +214,7 @@ void add_timeout (when, where, what, ref
602                         free_timeouts = q -> next;
603                 } else {
604                         q = ((struct timeout *)
605 -                            dmalloc (sizeof (struct timeout), MDL));
606 +                               dmalloc (sizeof (struct timeout), MDL));
607                         if (!q)
608                                 log_fatal ("add_timeout: no memory!");
609                 }
610 @@ -153,22 +244,76 @@ void add_timeout (when, where, what, ref
611                 if (t -> next -> when > q -> when) {
612                         q -> next = t -> next;
613                         t -> next = q;
614 +#endif
615                         return;
616 +#ifdef LIBDHCP
617 +               } else if (timeouts[i].when > when) {
618 +                       pos = i;
619 +#endif
620                 }
621         }
622  
623 +#ifdef LIBDHCP
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. */
627 +
628 +       new_timeouts = realloc(timeouts, sizeof (t) * (ntimeouts+1));
629 +       /* XXX broken API, no way to return error here */
630 +       if (new_timeouts) {
631 +               /* ntimeouts = 10
632 +                * pos = 3;
633 +                * n = 10-3 * sizeof (t) = 7 * sizeof (t) 
634 +                */
635 +               size_t n = (ntimeouts - pos) * sizeof (t);
636 +
637 +               timeouts = new_timeouts;
638 +               memmove(&timeouts[pos+1], &timeouts[pos], n);
639 +               memmove(&timeouts[pos], &t, sizeof (t));
640 +               ntimeouts++;
641 +       }
642 +#else
643         /* End of list. */
644         t -> next = q;
645         q -> next = (struct timeout *)0;
646 +#endif
647  }
648  
649  void cancel_timeout (where, what)
650         void (*where) PROTO ((void *));
651         void *what;
652  {
653 +#ifdef LIBDHCP
654 +       struct timeout t;
655 +       int i = 0;
656 +#else
657         struct timeout *t, *q;
658 +#endif
659  
660         /* Look for this timeout on the list, and unlink it if we find it. */
661 +#ifdef LIBDHCP
662 +       for (i = 0; i < ntimeouts; i++) {
663 +               struct timeout *new_timeouts, *q = &timeouts[i];
664 +
665 +               if (q->func == where && q->what == what) {
666 +                       size_t n;
667 +
668 +                       memmove(&t, q, sizeof (t));
669 +
670 +                       n = (ntimeouts - i - 1) * sizeof (t);
671 +                       memmove(&timeouts[i+1], &timeouts[i], n);
672 +
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;
678 +
679 +                       if (t.unref)
680 +                               t.unref(t.what, MDL);
681 +               }
682 +       }
683 +#else
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;
689                 free_timeouts = q;
690         }
691 +#endif
692  }
693  
694  void cancel_all_timeouts ()
695  {
696 +#ifdef LIBDHCP
697 +       cur_time = TIME_MAX;
698 +       process_outstanding_timeouts(NULL);
699 +#else
700         struct timeout *t, *n;
701         for (t = timeouts; t; t = n) {
702                 n = t -> next;
703 @@ -200,13 +350,20 @@ void cancel_all_timeouts ()
704                 t -> next = free_timeouts;
705                 free_timeouts = t;
706         }
707 +#endif
708  }
709  
710 +__attribute__ ((visibility ("default")))
711  void relinquish_timeouts ()
712  {
713 +#ifdef LIBDHCP
714 +       while (ntimeouts)
715 +               cancel_timeout(timeouts[0].func, timeouts[0].what);
716 +#else
717         struct timeout *t, *n;
718         for (t = free_timeouts; t; t = n) {
719                 n = t -> next;
720                 dfree (t, MDL);
721         }
722 +#endif
723  }
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,
727         return 1;
728  }
729  
730 +#ifdef LIBDHCP
731 +struct packet *free_packets;
732 +#else
733  static struct packet *free_packets;
734 +#endif
735  
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 @@
741  
742  typedef void (*tvref_t)(void *, void *, const char *, int);
743  typedef void (*tvunref_t)(void *, const char *, int);
744 -struct timeout {
745 -       struct timeout *next;
746 -       struct timeval when;
747 -       void (*func) PROTO ((void *));
748 -       void *what;
749 -       tvref_t ref;
750 -       tvunref_t unref;
751 -};
752  
753  struct eventqueue {
754         struct eventqueue *next;
755 @@ -1664,7 +1656,6 @@ extern const char *path_dhcpd_pid;
756  
757  extern int dhcp_max_agent_option_packet_length;
758  
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 *,
765                                      const char *, int,
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
784 @@ -1,10 +1,18 @@
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)
802  
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;
808  
809 +#ifdef LIBDHCP
810 +FILE *leaseFile = NULL;
811 +#endif
812 +
813  extern u_int32_t default_requested_options[];
814  
815  static void usage PROTO ((void));
816  
817  static isc_result_t write_duid(struct data_string *duid);
818  
819 -int 
820 -main(int argc, char **argv) {
821 +#ifdef LIBDHCP
822 +#include "isc-dhcp/libdhcp_control.h"
823 +LIBDHCP_Control *libdhcp_control;
824 +static void libdhcp_dispatch(void)
825 +{
826 +       struct timeval tv = { 0, 0 }, *tvp;
827 +       isc_result_t status;
828 +
829 +       /* Wait for a packet, or a timeout, or libdhcp being finished */
830 +       do {
831 +               tvp = process_outstanding_timeouts(&tv);
832 +               status = omapi_one_dispatch(0, tvp);
833 +
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);
837 +
838 +                       break;
839 +               }
840 +       } while ((status != ISC_R_TIMEDOUT) && ((!libdhcp_control) || (!(libdhcp_control->finished))));
841 +}
842 +
843 +extern void omapi_free_all_pointers(void);
844 +
845 +__attribute__ ((visibility ("default")))
846 +int dhcpv4_client (LIBDHCP_Control *libdhcp_ctl, int argc, char **argv,
847 +                   char **envp)
848 +#else
849 +int main(int argc, char **argv, char **envp)
850 +#endif
851 +{
852 +#ifdef LIBDHCP
853 +       libdhcp_control = libdhcp_ctl;
854 +#endif
855         int fd;
856         int i;
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));
861  
862 +#ifndef LIBDHCP
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));
869  #endif 
870 +#endif
871  
872         /* Set up the OMAPI. */
873         status = omapi_init ();
874 @@ -485,8 +523,12 @@ main(int argc, char **argv) {
875                 }
876         }
877  
878 +#ifdef LIBDHCP
879 +       if (libdhcp_control && (libdhcp_control->capability & DHCP_USE_PID_FILE))
880 +#endif
881         write_client_pid_file();
882  
883 +#ifndef LIBDHCP
884         if (!quiet) {
885                 log_info ("%s %s", message, PACKAGE_VERSION);
886                 log_info (copyright);
887 @@ -497,6 +539,7 @@ main(int argc, char **argv) {
888                 log_perror = 0;
889                 quiet_interface_discovery = 1;
890         }
891 +#endif
892  
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) {
896                 arg_conf_len = 0;
897         }
898  
899 +#ifdef LIBDHCP
900 +       if (libdhcp_control && (libdhcp_control->capability & DHCP_USE_LEASE_DATABASE)) {
901 +#endif
902         /* Parse the lease database. */
903         read_client_leases ();
904  
905         /* Rewrite the lease database... */
906         rewrite_client_leases ();
907 +#ifdef LIBDHCP
908 +       }
909 +#endif
910  
911         /* XXX */
912  /*     config_counter(&snd_counter, &rcv_counter); */
913 @@ -725,7 +774,7 @@ main(int argc, char **argv) {
914                 if (!persist) {
915                         /* Nothing more to do. */
916                         log_info ("No broadcast interfaces found - exiting.");
917 -                       exit (0);
918 +                       return (0);
919                 }
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;
924  #endif
925  
926 +#ifndef LIBDHCP
927         /* If we're not supposed to wait before getting the address,
928            don't. */
929         if (nowait)
930 @@ -875,6 +925,132 @@ main(int argc, char **argv) {
931  
932         /* Start dispatching packets and timeouts... */
933         dispatch ();
934 +#else
935 +       if (libdhcp_control) {
936 +               if (libdhcp_control->timeout)
937 +                       libdhcp_control->now = time(NULL);
938 +               else
939 +                       libdhcp_control->now = 0;
940 +       }
941 +
942 +       libdhcp_dispatch();
943 +
944 +       /* libdhcp is finished with us. */
945 +
946 +       /* close all file descriptors:  */
947 +       for (ip = interfaces; ip; ip = ip->next) {
948 +               shutdown(ip->wfdesc, SHUT_RDWR);
949 +               close(ip->wfdesc);
950 +
951 +               if (ip->rfdesc != ip->wfdesc)
952 +                       close(ip->rfdesc);
953 +       }
954 +
955 +       if (fallback_interface != 0) {
956 +               ip = fallback_interface;
957 +               shutdown(ip->wfdesc, SHUT_RDWR);
958 +               close(ip->wfdesc);
959 +
960 +               if (ip->rfdesc != ip->wfdesc)
961 +                       close(ip->rfdesc);
962 +       }
963 +
964 +       if (leaseFile)
965 +               fclose (leaseFile);
966 +
967 +       closelog();
968 +
969 +       char *current_pid_file = _PATH_DHCLIENT_PID;
970 +
971 +       /* Free ALL allocated memory: */
972 +       omapi_free_all_pointers();
973 +
974 +       /* Re-Initialize globals: */
975 +       client_env = 0;
976 +       client_env_count = 0;
977 +       default_lease_time = 43200;
978 +
979 +       dhcp_max_agent_option_packet_length = 0;
980 +       iaddr_any.len = 4;
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;
985 +       leaseFile = 0;
986 +
987 +       libdhcp_control = 0;
988 +
989 +       local_port = 0;
990 +       no_daemon = 0;
991 +       nowait = 0;
992 +       onetry = 0;
993 +       quiet = 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;
1000 +       remote_port = 0;
1001 +       resolver_inited = 0;
1002 +       log_perror = 1;
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;
1012 +#ifndef LIBDHCP
1013 +       timeouts = NULL;
1014 +#endif
1015 +       dhcp_type_interface = NULL;
1016 +       interface_vector = NULL;
1017 +       interface_count = 0;
1018 +       interface_max = 0;
1019 +       name_servers = 0;
1020 +       domains = 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;
1035 +       universes = 0;
1036 +       universe_count = 0;
1037 +       universe_max = 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);
1059 +#endif
1060  
1061         /*NOTREACHED*/
1062         return 0;
1063 @@ -1270,7 +1446,20 @@ void dhcpack (packet)
1064         if (client -> new -> rebind < cur_time)
1065                 client -> new -> rebind = TIME_MAX;
1066  
1067 +#ifdef LIBDHCP
1068 +       /* We need the server's siaddr for the 'bootServer'
1069 +        * pump option
1070 +        */
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;
1074 +#endif
1075 +
1076         bind_lease (client);
1077 +
1078 +#ifdef LIBDHCP
1079 +       client->packet.siaddr.s_addr = set_siaddr;
1080 +#endif
1081  }
1082  
1083  void bind_lease (client)
1084 @@ -1306,6 +1495,9 @@ void bind_lease (client)
1085                 return;
1086         }
1087  
1088 +#ifdef LIBDHCP
1089 +       if (libdhcp_control && (libdhcp_control->capability & DHCP_USE_LEASE_DATABASE))
1090 +#endif
1091         /* Write out the new lease. */
1092         write_client_lease (client, client -> new, 0, 0);
1093  
1094 @@ -1398,10 +1590,12 @@ void state_stop (cpp)
1095         }
1096  }  
1097  
1098 +#ifndef LIBDHCP
1099  int commit_leases ()
1100  {
1101         return 0;
1102  }
1103 +#endif
1104  
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. */
1110         if (onetry) {
1111 +#ifdef LIBDHCP
1112 +               script_init (client, "FAIL", (struct string_list *)0);
1113 +               return;
1114 +#endif
1115                 if (!quiet)
1116                         log_info ("Unable to obtain a lease on first try.%s",
1117                                   "  Exiting.");
1118 @@ -2691,7 +2889,9 @@ void destroy_client_lease (lease)
1119         free_client_lease (lease, MDL);
1120  }
1121  
1122 +#ifndef LIBDHCP
1123  FILE *leaseFile = NULL;
1124 +#endif
1125  int leases_written = 0;
1126  
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;
1131  {
1132 +#ifdef LIBDHCP
1133 +       struct string_list *sp;
1134 +
1135 +       if (libdhcp_control && libdhcp_control->callback) {
1136 +               int dhcmsg;
1137 +               char *reason="";
1138 +
1139 +               for (sp = client->env; sp; sp = sp->next)
1140 +                       if (strncmp(sp->string, "reason=", 7) == 0) {
1141 +                               reason = sp->string + 7;
1142 +                               break;
1143 +                       }
1144 +
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;
1169 +               else
1170 +                       dhcmsg = DHC4_NBI;
1171 +
1172 +               (*libdhcp_control->callback) (libdhcp_control, dhcmsg, client);
1173 +
1174 +               if (libdhcp_control->decline)
1175 +                       return 1;
1176 +       }
1177 +
1178 +       return 0;
1179 +#else
1180         char *scriptName;
1181         char *argv [2];
1182         char **envp;
1183 @@ -3294,6 +3542,7 @@ int script_go (client)
1184         time(&cur_time);
1185         return (WIFEXITED (wstatus) ?
1186                 WEXITSTATUS (wstatus) : -WTERMSIG (wstatus));
1187 +#endif
1188  }
1189  
1190  void client_envadd (struct client_state *client,
1191 @@ -3376,6 +3625,9 @@ void go_daemon ()
1192  
1193         /* Don't become a daemon if the user requested otherwise. */
1194         if (no_daemon) {
1195 +#ifdef LIBDHCP
1196 +               if (libdhcp_control && (libdhcp_control->capability & DHCP_USE_PID_FILE))
1197 +#endif
1198                 write_client_pid_file ();
1199                 return;
1200         }
1201 @@ -3385,6 +3637,10 @@ void go_daemon ()
1202                 return;
1203         state = 1;
1204  
1205 +#ifdef LIBDHCP
1206 +       return;
1207 +#endif
1208 +
1209         /* Stop logging to stderr... */
1210         log_perror = 0;
1211  
This page took 0.148223 seconds and 2 git commands to generate.