]> git.pld-linux.org Git - packages/dhcp.git/blob - dhcp-libdhcp4client.patch
- added try-restart and force-reload options
[packages/dhcp.git] / dhcp-libdhcp4client.patch
1 diff -up dhcp-3.1.0/omapip/dispatch.c.libdhcp4client dhcp-3.1.0/omapip/dispatch.c
2 --- dhcp-3.1.0/omapip/dispatch.c.libdhcp4client 2005-03-17 15:15:21.000000000 -0500
3 +++ dhcp-3.1.0/omapip/dispatch.c        2007-10-24 14:55:56.000000000 -0400
4 @@ -34,7 +34,7 @@
5  
6  #include <omapip/omapip_p.h>
7  
8 -static omapi_io_object_t omapi_io_states;
9 +omapi_io_object_t omapi_io_states;
10  TIME cur_time;
11  
12  OMAPI_OBJECT_ALLOC (omapi_io,
13 diff -up dhcp-3.1.0/omapip/errwarn.c.libdhcp4client dhcp-3.1.0/omapip/errwarn.c
14 --- dhcp-3.1.0/omapip/errwarn.c.libdhcp4client  2007-10-24 14:55:56.000000000 -0400
15 +++ dhcp-3.1.0/omapip/errwarn.c 2007-10-24 14:57:16.000000000 -0400
16 @@ -39,6 +39,11 @@ static char copyright[] =
17  #include <omapip/omapip_p.h>
18  #include <errno.h>
19  
20 +#ifdef LIBDHCP
21 +#include <isc-dhcp/libdhcp_control.h>
22 +extern LIBDHCP_Control *libdhcp_control;
23 +#endif
24 +
25  #ifdef DEBUG
26  int log_perror = -1;
27  #else
28 @@ -48,7 +53,9 @@ int log_priority;
29  void (*log_cleanup) (void);
30  
31  #define CVT_BUF_MAX 1023
32 +#ifndef LIBDHCP
33  static char mbuf [CVT_BUF_MAX + 1];
34 +#endif
35  static char fbuf [CVT_BUF_MAX + 1];
36  
37  /* Log an error message, then exit... */
38 @@ -58,6 +65,16 @@ void log_fatal (const char * fmt, ... )
39    va_list list;
40  
41    do_percentm (fbuf, fmt);
42 +  
43 +#ifdef LIBDHCP
44 +  if (libdhcp_control && (libdhcp_control->eh)) {
45 +      va_start (list, fmt);
46 +      libdhcp_control->eh(libdhcp_control, LOG_FATAL, fbuf, list);
47 +      va_end(list);
48 +      libdhcp_control->finished = 1;
49 +      return;
50 +  }
51 +#else
52  
53    /* %Audit% This is log output. %2004.06.17,Safe%
54     * If we truncate we hope the user can get a hint from the log.
55 @@ -91,6 +108,7 @@ void log_fatal (const char * fmt, ... )
56    if (log_cleanup)
57           (*log_cleanup) ();
58    exit (1);
59 +#endif
60  }
61  
62  /* Log an error message... */
63 @@ -101,6 +119,13 @@ int log_error (const char * fmt, ...)
64  
65    do_percentm (fbuf, fmt);
66  
67 +#ifdef LIBDHCP
68 +  if (libdhcp_control && libdhcp_control->eh) {
69 +      va_start (list, fmt);
70 +      libdhcp_control->eh(libdhcp_control, LOG_ERR, fbuf, list);
71 +      va_end(list);
72 +  }
73 +#else
74    /* %Audit% This is log output. %2004.06.17,Safe%
75     * If we truncate we hope the user can get a hint from the log.
76     */
77 @@ -116,7 +141,7 @@ int log_error (const char * fmt, ...)
78           write (STDERR_FILENO, mbuf, strlen (mbuf));
79           write (STDERR_FILENO, "\n", 1);
80    }
81 -
82 +#endif
83    return 0;
84  }
85  
86 @@ -128,6 +153,13 @@ int log_info (const char *fmt, ...)
87  
88    do_percentm (fbuf, fmt);
89  
90 +#ifdef LIBDHCP
91 +  if (libdhcp_control && libdhcp_control->eh) {
92 +      va_start (list, fmt);
93 +      libdhcp_control->eh(libdhcp_control, LOG_INFO, fbuf, list);
94 +      va_end(list);
95 +  }
96 +#else
97    /* %Audit% This is log output. %2004.06.17,Safe%
98     * If we truncate we hope the user can get a hint from the log.
99     */
100 @@ -143,7 +175,7 @@ int log_info (const char *fmt, ...)
101           write (STDERR_FILENO, mbuf, strlen (mbuf));
102           write (STDERR_FILENO, "\n", 1);
103    }
104 -
105 +#endif
106    return 0;
107  }
108  
109 @@ -154,7 +186,13 @@ int log_debug (const char *fmt, ...)
110    va_list list;
111  
112    do_percentm (fbuf, fmt);
113 -
114 +#ifdef LIBDHCP
115 +  if (libdhcp_control && libdhcp_control->eh) {
116 +      va_start (list, fmt);
117 +      libdhcp_control->eh(libdhcp_control, LOG_DEBUG, fbuf, list);
118 +      va_end(list);
119 +  }
120 +#else
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     */
124 @@ -170,7 +208,7 @@ int log_debug (const char *fmt, ...)
125           write (STDERR_FILENO, mbuf, strlen (mbuf));
126           write (STDERR_FILENO, "\n", 1);
127    }
128 -
129 +#endif
130    return 0;
131  }
132  
133 diff -up dhcp-3.1.0/omapip/alloc.c.libdhcp4client dhcp-3.1.0/omapip/alloc.c
134 --- dhcp-3.1.0/omapip/alloc.c.libdhcp4client    2006-02-24 18:16:30.000000000 -0500
135 +++ dhcp-3.1.0/omapip/alloc.c   2007-10-24 14:55:56.000000000 -0400
136 @@ -40,6 +40,33 @@ static char copyright[] =
137  
138  #include <omapip/omapip_p.h>
139  
140 +#ifdef LIBDHCP
141 +/* OK, we need a quick and dirty way of freeing all memory used by libdhcp. 
142 +   All pointers will be stored in a glibc tree on alloc, and removed on free.
143 +   This is not too expensive for light single-call library use.
144 +*/
145 +#include <search.h>  
146 +extern void tdestroy (void *root, void (*free_node)(void *nodep));
147 +static void *all_pointers=0L;
148 +static int ptr_comparator(const void *p1, const void *p2) {
149 +    return ((p1 == p2) ? 0 : ((p1 > p2) ? 1 : -1));
150 +}
151 +
152 +static void record_pointer(void *ptr) {
153 +    tsearch(ptr, &(all_pointers), ptr_comparator);
154 +}
155 +
156 +static void forget_pointer(void *ptr) {
157 +    tdelete(ptr, &(all_pointers), ptr_comparator);
158 +}
159 +
160 +void omapi_free_all_pointers(void) {
161 +    if (all_pointers != NULL)
162 +               tdestroy(all_pointers, free);
163 +    all_pointers = NULL;
164 +}
165 +#endif
166 +
167  #if defined (DEBUG_MEMORY_LEAKAGE) || defined (DEBUG_MALLOC_POOL) || \
168                 defined (DEBUG_MEMORY_LEAKAGE_ON_EXIT)
169  struct dmalloc_preamble *dmalloc_list;
170 @@ -78,7 +105,9 @@ VOIDPTR dmalloc (size, file, line)
171                 return (VOIDPTR)0;
172  
173         foo = malloc(len);
174 -
175 +#ifdef LIBDHCP
176 +       record_pointer(foo);
177 +#endif
178         if (!foo)
179                 return (VOIDPTR)0;
180         bar = (VOIDPTR)(foo + DMDOFFSET);
181 @@ -200,6 +229,9 @@ void dfree (ptr, file, line)
182                      0, (unsigned char *)ptr + DMDOFFSET, 0, 1, RC_MALLOC);
183  #endif
184         free (ptr);
185 +#ifdef LIBDHCP
186 +       forget_pointer(ptr);
187 +#endif
188  }
189  
190  #if defined (DEBUG_MEMORY_LEAKAGE) || defined (DEBUG_MALLOC_POOL) || \
191 diff -up dhcp-3.1.0/configure.libdhcp4client dhcp-3.1.0/configure
192 --- dhcp-3.1.0/configure.libdhcp4client 2005-03-17 15:14:55.000000000 -0500
193 +++ dhcp-3.1.0/configure        2007-10-24 14:55:56.000000000 -0400
194 @@ -246,7 +246,7 @@ if [ ! -d $workname ]; then
195  fi
196  
197  if [ x"$dirs" = x ]; then
198 -  dirs=". client server relay common omapip dhcpctl minires dst"
199 +  dirs=". client server relay common omapip dhcpctl minires dst libdhcp4client"
200  fi
201  
202  for foo in $dirs; do
203 diff -up dhcp-3.1.0/dst/hmac_link.c.libdhcp4client dhcp-3.1.0/dst/hmac_link.c
204 --- dhcp-3.1.0/dst/hmac_link.c.libdhcp4client   2001-02-22 02:22:08.000000000 -0500
205 +++ dhcp-3.1.0/dst/hmac_link.c  2007-10-24 14:55:56.000000000 -0400
206 @@ -38,6 +38,10 @@ static const char rcsid[] = "$Header: /p
207  
208  #include "dst_internal.h"
209  
210 +#ifdef LIBDHCP
211 +extern void* dmalloc(size_t,char *,int);
212 +#endif
213 +
214  #ifdef USE_MD5
215  # include "md5.h"
216  # ifndef _MD5_H_
217 @@ -86,7 +90,11 @@ dst_hmac_md5_sign(const int mode, DST_KE
218         MD5_CTX *ctx = NULL;
219  
220         if (mode & SIG_MODE_INIT) 
221 +#ifdef LIBDHCP
222 +               ctx = (MD5_CTX *) dmalloc(sizeof(*ctx),__FILE__,__LINE__);
223 +#else
224                 ctx = (MD5_CTX *) malloc(sizeof(*ctx));
225 +#endif
226         else if (context)
227                 ctx = (MD5_CTX *) *context;
228         if (ctx == NULL) 
229 @@ -153,7 +161,11 @@ dst_hmac_md5_verify(const int mode, DST_
230         MD5_CTX *ctx = NULL;
231  
232         if (mode & SIG_MODE_INIT) 
233 +#ifdef LIBDHCP
234 +               ctx = (MD5_CTX *) dmalloc(sizeof(*ctx),__FILE__,__LINE__);
235 +#else
236                 ctx = (MD5_CTX *) malloc(sizeof(*ctx));
237 +#endif
238         else if (context)
239                 ctx = (MD5_CTX *) *context;
240         if (ctx == NULL) 
241 @@ -217,8 +229,11 @@ dst_buffer_to_hmac_md5(DST_KEY *dkey, co
242  
243         if (dkey == NULL || key == NULL || keylen < 0)
244                 return (-1);
245 -
246 +#ifdef  LIBDHCP
247 +       if ((hkey = (HMAC_Key *) dmalloc(sizeof(HMAC_Key),__FILE__,__LINE__)) == NULL)
248 +#else
249         if ((hkey = (HMAC_Key *) malloc(sizeof(HMAC_Key))) == NULL)
250 +#endif
251                   return (-2);
252  
253         memset(hkey->hk_ipad, 0, sizeof(hkey->hk_ipad));
254 @@ -347,7 +362,11 @@ dst_hmac_md5_key_from_file_format(DST_KE
255         if (eol == NULL)
256                 return (-4);
257         len = eol - p;
258 +#ifdef LIBDHCP
259 +       tmp = dmalloc(len + 2,__FILE__,__LINE__);
260 +#else
261         tmp = malloc(len + 2);
262 +#endif
263         memcpy(tmp, p, len);
264         *(tmp + len) = 0x0;
265         key_len = b64_pton((char *)tmp, key, HMAC_LEN+1);       /* see above */
266 @@ -439,8 +458,11 @@ dst_hmac_md5_generate_key(DST_KEY *key, 
267                 return(0);
268         
269         len = size > 64 ? 64 : size;
270 +#ifdef LIBDHCP
271 +       buff = dmalloc(len+8,__FILE__,__LINE__);
272 +#else
273         buff = malloc(len+8);
274 -
275 +#endif
276         n = dst_random(DST_RAND_SEMI, len, buff);
277         n += dst_random(DST_RAND_KEY, len, buff);
278         if (n <= len) { /* failed getting anything */
279 @@ -463,7 +485,11 @@ dst_hmac_md5_init()
280  {
281         if (dst_t_func[KEY_HMAC_MD5] != NULL)
282                 return (1);
283 +#ifdef LIBDHCP
284 +       dst_t_func[KEY_HMAC_MD5] = dmalloc(sizeof(struct dst_func),__FILE__,__LINE__);
285 +#else
286         dst_t_func[KEY_HMAC_MD5] = malloc(sizeof(struct dst_func));
287 +#endif
288         if (dst_t_func[KEY_HMAC_MD5] == NULL)
289                 return (0);
290         memset(dst_t_func[KEY_HMAC_MD5], 0, sizeof(struct dst_func));
291 diff -up dhcp-3.1.0/common/discover.c.libdhcp4client dhcp-3.1.0/common/discover.c
292 --- dhcp-3.1.0/common/discover.c.libdhcp4client 2006-11-07 18:41:39.000000000 -0500
293 +++ dhcp-3.1.0/common/discover.c        2007-10-24 14:55:56.000000000 -0400
294 @@ -121,6 +121,10 @@ isc_result_t interface_initialize (omapi
295     register that interface with the network I/O software, figure out what
296     subnet it's on, and add it to the list of interfaces. */
297  
298 +#ifdef LIBDHCP
299 +int have_setup_fallback = 0;
300 +#endif
301 +
302  void discover_interfaces (state)
303         int state;
304  {
305 @@ -141,7 +145,9 @@ void discover_interfaces (state)
306         char *s;
307  #endif
308         isc_result_t status;
309 +#ifndef LIBDHCP
310         static int setup_fallback = 0;
311 +#endif
312         int wifcount = 0;
313  
314         /* Create an unbound datagram socket to do the SIOCGIFADDR ioctl on. */
315 @@ -695,10 +701,17 @@ void discover_interfaces (state)
316                 log_fatal ("Not configured to listen on any interfaces!");
317         }
318  
319 +#ifdef LIBDHCP
320 +       if (!have_setup_fallback) {
321 +               have_setup_fallback = 1;
322 +               maybe_setup_fallback ();
323 +       }
324 +#else
325         if (!setup_fallback) {
326                 setup_fallback = 1;
327                 maybe_setup_fallback ();
328         }
329 +#endif
330  
331  #if defined (HAVE_SETFD)
332         if (fallback_interface) {
333 diff -up dhcp-3.1.0/common/tree.c.libdhcp4client dhcp-3.1.0/common/tree.c
334 --- dhcp-3.1.0/common/tree.c.libdhcp4client     2007-02-14 17:41:22.000000000 -0500
335 +++ dhcp-3.1.0/common/tree.c    2007-10-24 14:55:56.000000000 -0400
336 @@ -41,7 +41,7 @@ static char copyright[] =
337  #include <omapip/omapip_p.h>
338  #include <ctype.h>
339  
340 -struct binding_scope *global_scope;
341 +struct binding_scope __attribute__ ((visibility ("default"))) *global_scope;
342  
343  static int do_host_lookup PROTO ((struct data_string *,
344                                   struct dns_host_entry *));
345 @@ -2761,6 +2761,7 @@ int evaluate_numeric_expression (result,
346     result of that evaluation.   There should never be both an expression
347     and a valid data_string. */
348  
349 +__attribute__ ((visibility ("default")))
350  int evaluate_option_cache (result, packet, lease, client_state,
351                            in_options, cfg_options, scope, oc, file, line)
352         struct data_string *result;
353 diff -up dhcp-3.1.0/common/options.c.libdhcp4client dhcp-3.1.0/common/options.c
354 --- dhcp-3.1.0/common/options.c.libdhcp4client  2007-05-23 15:26:22.000000000 -0400
355 +++ dhcp-3.1.0/common/options.c 2007-10-24 14:55:56.000000000 -0400
356 @@ -2501,6 +2501,7 @@ int fqdn_option_space_encapsulate (resul
357         return 1;
358  }
359  
360 +__attribute__ ((visibility ("default")))
361  void option_space_foreach (struct packet *packet, struct lease *lease,
362                            struct client_state *client_state,
363                            struct option_state *in_options,
364 diff -up dhcp-3.1.0/common/dispatch.c.libdhcp4client dhcp-3.1.0/common/dispatch.c
365 --- dhcp-3.1.0/common/dispatch.c.libdhcp4client 2007-10-24 14:55:56.000000000 -0400
366 +++ dhcp-3.1.0/common/dispatch.c        2007-10-24 14:55:56.000000000 -0400
367 @@ -39,8 +39,24 @@ static char copyright[] =
368  
369  #include "dhcpd.h"
370  
371 -struct timeout *timeouts;
372 -static struct timeout *free_timeouts;
373 +struct timeout {
374 +#ifndef LIBDHCP
375 +       struct timeout *next;
376 +#endif
377 +       TIME when;
378 +       void (*func) PROTO ((void *));
379 +       void *what;
380 +       tvref_t ref;
381 +       tvunref_t unref;
382 +};
383 +
384 +#ifdef LIBDHCP
385 +static struct timeout *timeouts = NULL;
386 +static int ntimeouts = 0;
387 +#else
388 +static struct timeout *timeouts = NULL;
389 +static struct timeout *free_timeouts = NULL;
390 +#endif
391  
392  void set_time(TIME t)
393  {
394 @@ -53,9 +69,41 @@ void set_time(TIME t)
395  
396  struct timeval *process_outstanding_timeouts (struct timeval *tvp)
397  {
398 +#ifdef LIBDHCP
399 +       int i;
400 +       struct timeout t = { 0 };
401 +#endif
402         /* Call any expired timeouts, and then if there's
403            still a timeout registered, time out the select
404            call then. */
405 +#ifdef LIBDHCP
406 +       if (!ntimeouts)
407 +               return NULL;
408 +
409 +       for (i = 0; i < ntimeouts && timeouts[i].when <= cur_time;) {
410 +               struct timeout *new_timeouts;
411 +               size_t n;
412 +
413 +               memmove(&t, &timeouts[i], sizeof (t));
414 +
415 +               n = (ntimeouts - i - 1) * sizeof (t);
416 +               memmove(&timeouts[i+1], &timeouts[i], n);
417 +
418 +               n = --ntimeouts * sizeof (t);
419 +               new_timeouts = realloc(timeouts, n);
420 +               /* XXX broken API, no way to return error here */
421 +               if (new_timeouts || !n)
422 +                       timeouts = new_timeouts;
423 +
424 +               if (t.func)
425 +                       t.func(t.what);
426 +               if (t.unref)
427 +                       t.unref(t.what, MDL);
428 +       }
429 +       if (tvp && ntimeouts) {
430 +               tvp->tv_sec = timeouts[0].when;
431 +               tvp->tv_usec = 0;
432 +#else
433        another:
434         if (timeouts) {
435                 struct timeout *t;
436 @@ -73,9 +121,15 @@ struct timeval *process_outstanding_time
437                         tvp -> tv_sec = timeouts -> when;
438                         tvp -> tv_usec = 0;
439                 }
440 +#endif
441                 return tvp;
442 +#ifdef LIBDHCP
443 +       }
444 +       return NULL;
445 +#else
446         } else
447                 return (struct timeval *)0;
448 +#endif
449  }
450  
451  /* Wait for packets to come in using select().   When one does, call
452 @@ -104,13 +158,28 @@ void add_timeout (when, where, what, ref
453         tvref_t ref;
454         tvunref_t unref;
455  {
456 +#ifdef LIBDHCP
457 +       struct timeout t = {
458 +               .when = when,
459 +               .func = where,
460 +               .what = what,
461 +               .ref = ref,
462 +               .unref = unref
463 +       };
464 +       struct timeout *new_timeouts;
465 +       int i, pos = 0;
466 +#else
467         struct timeout *t, *q;
468 +#endif
469  
470         /* See if this timeout supersedes an existing timeout. */
471 +#ifdef LIBDHCP
472 +       for (i = 0; i < ntimeouts; i++) {
473 +               struct timeout *q = &timeouts[i];
474 +#else
475         t = (struct timeout *)0;
476         for (q = timeouts; q; q = q -> next) {
477 -               if ((where == NULL || q -> func == where) &&
478 -                   q -> what == what) {
479 +               if ((where == NULL || q -> func == where) && q -> what == what) {
480                         if (t)
481                                 t -> next = q -> next;
482                         else
483 @@ -119,7 +188,29 @@ void add_timeout (when, where, what, ref
484                 }
485                 t = q;
486         }
487 +#endif
488  
489 +#ifdef LIBDHCP
490 +               /* If this one is already in the list with a different time,
491 +                * remove it and re-add */
492 +               if ((where == NULL || q->func == where) &&
493 +                               q->what == what) {
494 +                       size_t n = (--ntimeouts - i) * sizeof (*q);
495 +                       memmove(&t, q, sizeof (t));
496 +
497 +                       if (n)
498 +                               memmove(&timeouts[i], &timeouts[i+1], n);
499 +
500 +                       if (ntimeouts) {
501 +                               new_timeouts = realloc(timeouts, ntimeouts * sizeof (*q));
502 +                               /* XXX broken API, no way to return error here */
503 +                               if (new_timeouts)
504 +                                       timeouts = new_timeouts;
505 +                       } else {
506 +                               timeouts = NULL;
507 +                       }
508 +                       add_timeout(when, where, what, ref, unref);
509 +#else
510         /* If we didn't supersede a timeout, allocate a timeout
511            structure now. */
512         if (!q) {
513 @@ -128,7 +219,7 @@ void add_timeout (when, where, what, ref
514                         free_timeouts = q -> next;
515                 } else {
516                         q = ((struct timeout *)
517 -                            dmalloc (sizeof (struct timeout), MDL));
518 +                               dmalloc (sizeof (struct timeout), MDL));
519                         if (!q)
520                                 log_fatal ("add_timeout: no memory!");
521                 }
522 @@ -158,22 +249,76 @@ void add_timeout (when, where, what, ref
523                 if (t -> next -> when > q -> when) {
524                         q -> next = t -> next;
525                         t -> next = q;
526 +#endif
527                         return;
528 +#ifdef LIBDHCP
529 +               } else if (timeouts[i].when > when) {
530 +                       pos = i;
531 +#endif
532                 }
533         }
534  
535 +#ifdef LIBDHCP
536 +       /* If we didn't supersede an existing timeout, then pos is set
537 +        * to the timeout which will post after this one.  Insert this
538 +        * one before it. */
539 +
540 +       new_timeouts = realloc(timeouts, sizeof (t) * (ntimeouts+1));
541 +       /* XXX broken API, no way to return error here */
542 +       if (new_timeouts) {
543 +               /* ntimeouts = 10
544 +                * pos = 3;
545 +                * n = 10-3 * sizeof (t) = 7 * sizeof (t) 
546 +                */
547 +               size_t n = (ntimeouts - pos) * sizeof (t);
548 +
549 +               timeouts = new_timeouts;
550 +               memmove(&timeouts[pos+1], &timeouts[pos], n);
551 +               memmove(&timeouts[pos], &t, sizeof (t));
552 +               ntimeouts++;
553 +       }
554 +#else
555         /* End of list. */
556         t -> next = q;
557         q -> next = (struct timeout *)0;
558 +#endif
559  }
560  
561  void cancel_timeout (where, what)
562         void (*where) PROTO ((void *));
563         void *what;
564  {
565 +#ifdef LIBDHCP
566 +       struct timeout t;
567 +       int i = 0;
568 +#else
569         struct timeout *t, *q;
570 +#endif
571  
572         /* Look for this timeout on the list, and unlink it if we find it. */
573 +#ifdef LIBDHCP
574 +       for (i = 0; i < ntimeouts; i++) {
575 +               struct timeout *new_timeouts, *q = &timeouts[i];
576 +
577 +               if (q->func == where && q->what == what) {
578 +                       size_t n;
579 +
580 +                       memmove(&t, q, sizeof (t));
581 +
582 +                       n = (ntimeouts - i - 1) * sizeof (t);
583 +                       memmove(&timeouts[i+1], &timeouts[i], n);
584 +
585 +                       n = --ntimeouts * sizeof (t);
586 +                       new_timeouts = realloc(timeouts, n);
587 +                       /* XXX broken API, no way to return error here */
588 +                       if (new_timeouts || !n)
589 +                               timeouts = new_timeouts;
590 +
591 +                       if (t.unref)
592 +                               t.unref(t.what, MDL);
593 +               }
594 +       }
595 +#else
596         t = (struct timeout *)0;
597         for (q = timeouts; q; q = q -> next) {
598                 if (q -> func == where && q -> what == what) {
599 @@ -193,10 +338,15 @@ void cancel_timeout (where, what)
600                 q -> next = free_timeouts;
601                 free_timeouts = q;
602         }
603 +#endif
604  }
605  
606  void cancel_all_timeouts ()
607  {
608 +#ifdef LIBDHCP
609 +       cur_time = TIME_MAX;
610 +       process_outstanding_timeouts(NULL);
611 +#else
612         struct timeout *t, *n;
613         for (t = timeouts; t; t = n) {
614                 n = t -> next;
615 @@ -205,13 +355,20 @@ void cancel_all_timeouts ()
616                 t -> next = free_timeouts;
617                 free_timeouts = t;
618         }
619 +#endif
620  }
621  
622 +__attribute__ ((visibility ("default")))
623  void relinquish_timeouts ()
624  {
625 +#ifdef LIBDHCP
626 +       while (ntimeouts)
627 +               cancel_timeout(timeouts[0].func, timeouts[0].what);
628 +#else
629         struct timeout *t, *n;
630         for (t = free_timeouts; t; t = n) {
631                 n = t -> next;
632                 dfree (t, MDL);
633         }
634 +#endif
635  }
636 diff -up dhcp-3.1.0/common/alloc.c.libdhcp4client dhcp-3.1.0/common/alloc.c
637 --- dhcp-3.1.0/common/alloc.c.libdhcp4client    2006-06-01 16:23:17.000000000 -0400
638 +++ dhcp-3.1.0/common/alloc.c   2007-10-24 14:55:56.000000000 -0400
639 @@ -1013,7 +1013,11 @@ int executable_statement_reference (ptr,
640         return 1;
641  }
642  
643 +#ifdef LIBDHCP
644 +struct packet *free_packets;
645 +#else
646  static struct packet *free_packets;
647 +#endif
648  
649  #if defined (DEBUG_MEMORY_LEAKAGE) || \
650                 defined (DEBUG_MEMORY_LEAKAGE_ON_EXIT)
651 diff -up dhcp-3.1.0/includes/dhcpd.h.libdhcp4client dhcp-3.1.0/includes/dhcpd.h
652 --- dhcp-3.1.0/includes/dhcpd.h.libdhcp4client  2007-10-24 14:55:56.000000000 -0400
653 +++ dhcp-3.1.0/includes/dhcpd.h 2007-10-24 14:55:56.000000000 -0400
654 @@ -1000,14 +1000,6 @@ struct hardware_link {
655  
656  typedef void (*tvref_t)(void *, void *, const char *, int);
657  typedef void (*tvunref_t)(void *, const char *, int);
658 -struct timeout {
659 -       struct timeout *next;
660 -       TIME when;
661 -       void (*func) PROTO ((void *));
662 -       void *what;
663 -       tvref_t ref;
664 -       tvunref_t unref;
665 -};
666  
667  struct protocol {
668         struct protocol *next;
669 @@ -1960,7 +1952,6 @@ extern void (*bootp_packet_handler) PROT
670                                             struct dhcp_packet *, unsigned,
671                                             unsigned int,
672                                             struct iaddr, struct hardware *));
673 -extern struct timeout *timeouts;
674  extern omapi_object_type_t *dhcp_type_interface;
675  #if defined (TRACING)
676  trace_type_t *interface_trace;
677 diff -up dhcp-3.1.0/client/dhclient.c.libdhcp4client dhcp-3.1.0/client/dhclient.c
678 --- dhcp-3.1.0/client/dhclient.c.libdhcp4client 2007-10-24 14:55:56.000000000 -0400
679 +++ dhcp-3.1.0/client/dhclient.c        2007-10-24 14:56:20.000000000 -0400
680 @@ -82,16 +82,52 @@ int quiet=0;
681  int nowait=0;
682  int bootp_broadcast_always = 0;
683  
684 +#ifdef LIBDHCP
685 +FILE *leaseFile = NULL;
686 +#endif
687 +
688  extern u_int32_t default_requested_options[];
689  #ifdef EXTENDED_NEW_OPTION_INFO
690  int extended_option_environment = 0;
691  #endif
692  static void usage PROTO ((void));
693  
694 +#ifdef LIBDHCP
695 +#include "isc-dhcp/libdhcp_control.h"
696 +LIBDHCP_Control *libdhcp_control;
697 +static void libdhcp_dispatch(void)
698 +{
699 +       struct timeval tv = { 0, 0 }, *tvp;
700 +       isc_result_t status;
701 +
702 +       /* Wait for a packet, or a timeout, or libdhcp being finished */
703 +       do {
704 +               tvp = process_outstanding_timeouts(&tv);
705 +               status = omapi_one_dispatch(0, tvp);
706 +
707 +               if (libdhcp_control && ((status == ISC_R_TIMEDOUT) || (libdhcp_control->timeout && (time(NULL) >= (libdhcp_control->timeout + libdhcp_control->now))))) {
708 +                       if (libdhcp_control->callback)
709 +                               libdhcp_control->callback(libdhcp_control, DHC_TIMEDOUT, NULL);
710 +
711 +                       break;
712 +               }
713 +       } while ((status != ISC_R_TIMEDOUT) && ((!libdhcp_control) || (!(libdhcp_control->finished))));
714 +}
715 +
716 +extern void omapi_free_all_pointers(void);
717 +
718 +__attribute__ ((visibility ("default")))
719 +int dhcpv4_client (libdhcp_ctl, argc, argv, envp)
720 +       LIBDHCP_Control *libdhcp_ctl;
721 +#else
722  int main (argc, argv, envp)
723 +#endif
724         int argc;
725         char **argv, **envp;
726  {
727 +#ifdef LIBDHCP
728 +       libdhcp_control = libdhcp_ctl;
729 +#endif
730         int fd;
731         int i;
732         struct servent *ent;
733 @@ -120,6 +156,7 @@ int main (argc, argv, envp)
734         char *arg_conf = NULL;
735         int arg_conf_len = 0;
736  
737 +#ifndef LIBDHCP
738          /* Make sure that file descriptors 0 (stdin), 1, (stdout), and
739             2 (stderr) are open. To do this, we assume that when we
740             open a file the lowest available file decriptor is used. */
741 @@ -143,6 +180,7 @@ int main (argc, argv, envp)
742  #if !(defined (DEBUG) || defined (SYSLOG_4_2) || defined (__CYGWIN32__))
743         setlogmask (LOG_UPTO (LOG_INFO));
744  #endif 
745 +#endif
746  
747         /* Set up the OMAPI. */
748         status = omapi_init ();
749 @@ -439,6 +477,10 @@ int main (argc, argv, envp)
750                 }
751         }
752  
753 +#ifdef LIBDHCP
754 +       if (libdhcp_control && (libdhcp_control->capability & DHCP_USE_PID_FILE))
755 +#endif
756 +#ifndef LIBDHCP
757         if (!quiet) {
758                 log_info ("%s %s", message, DHCP_VERSION);
759                 log_info (copyright);
760 @@ -449,6 +491,7 @@ int main (argc, argv, envp)
761                 log_info ("%s", "");
762         } else
763                 log_perror = 0;
764 +#endif
765  
766         /* If we're given a relay agent address to insert, for testing
767            purposes, figure out what it is. */
768 @@ -680,11 +723,17 @@ int main (argc, argv, envp)
769                 arg_conf_len = 0;
770         }
771  
772 +#ifdef LIBDHCP
773 +       if (libdhcp_control && (libdhcp_control->capability & DHCP_USE_LEASE_DATABASE)) {
774 +#endif
775         /* Parse the lease database. */
776         read_client_leases ();
777  
778         /* Rewrite the lease database... */
779         rewrite_client_leases ();
780 +#ifdef LIBDHCP
781 +       }
782 +#endif
783  
784         /* XXX */
785  /*     config_counter(&snd_counter, &rcv_counter); */
786 @@ -703,7 +752,7 @@ int main (argc, argv, envp)
787                 if (!persist) {
788                         /* Nothing more to do. */
789                         log_info ("No broadcast interfaces found - exiting.");
790 -                       exit (0);
791 +                       return (0);
792                 }
793         } else if (!release_mode && !exit_mode) {
794                 /* Call the script with the list of interfaces. */
795 @@ -799,6 +848,7 @@ int main (argc, argv, envp)
796         dmalloc_outstanding = 0;
797  #endif
798  
799 +#ifndef LIBDHCP
800         /* If we're not supposed to wait before getting the address,
801            don't. */
802         if (nowait)
803 @@ -811,6 +861,126 @@ int main (argc, argv, envp)
804  
805         /* Start dispatching packets and timeouts... */
806         dispatch ();
807 +#else
808 +       if (libdhcp_control) {
809 +               if (libdhcp_control->timeout)
810 +                       libdhcp_control->now = time(NULL);
811 +               else
812 +                       libdhcp_control->now = 0;
813 +       }
814 +
815 +       libdhcp_dispatch();
816 +
817 +       /* libdhcp is finished with us. */
818 +
819 +       /* close all file descriptors:  */
820 +       for (ip = interfaces; ip; ip = ip->next) {
821 +               shutdown(ip->wfdesc, SHUT_RDWR);
822 +               close(ip->wfdesc);
823 +
824 +               if (ip->rfdesc != ip->wfdesc)
825 +                       close(ip->rfdesc);
826 +       }
827 +
828 +       if (fallback_interface != 0) {
829 +               ip = fallback_interface;
830 +               shutdown(ip->wfdesc, SHUT_RDWR);
831 +               close(ip->wfdesc);
832 +
833 +               if (ip->rfdesc != ip->wfdesc)
834 +                       close(ip->rfdesc);
835 +       }
836 +
837 +       if (leaseFile)
838 +               fclose (leaseFile);
839 +
840 +       closelog();
841 +
842 +       char *current_pid_file = _PATH_DHCLIENT_PID;
843 +
844 +       /* Free ALL allocated memory: */
845 +       omapi_free_all_pointers();
846 +
847 +       /* Re-Initialize globals: */
848 +       client_env = 0;
849 +       client_env_count = 0;
850 +       default_lease_time = 43200;
851 +
852 +       dhcp_max_agent_option_packet_length = 0;
853 +       iaddr_any.len = 4;
854 +       memset(&(iaddr_any.iabuf[0]), '\0', 4);
855 +       iaddr_broadcast.len = 4;
856 +       memset(&(iaddr_broadcast.iabuf[0]), 0xff, 4);
857 +       interfaces_requested = 0;
858 +       leaseFile = 0;
859 +
860 +       libdhcp_control = 0;
861 +
862 +       local_port = 0;
863 +       no_daemon = 0;
864 +       nowait = 0;
865 +       onetry = 0;
866 +       quiet = 0;
867 +       max_lease_time = 86400;
868 +       path_dhclient_conf = _PATH_DHCLIENT_CONF;
869 +       path_dhclient_db = _PATH_DHCLIENT_DB;
870 +       path_dhclient_pid = _PATH_DHCLIENT_PID;
871 +       strcpy(&(path_dhclient_script_array[0]), _PATH_DHCLIENT_SCRIPT);
872 +       path_dhclient_script = path_dhclient_script_array;
873 +       remote_port = 0;
874 +       resolver_inited = 0;
875 +       log_perror = 1;
876 +       global_scope = NULL;
877 +       root_group = NULL;
878 +       group_name_hash = NULL;
879 +       interfaces = NULL;
880 +       dummy_interfaces = NULL;
881 +       fallback_interface = NULL;
882 +       extern int have_setup_fallback;
883 +       have_setup_fallback = 0;
884 +       quiet_interface_discovery = 1;
885 +#ifndef LIBDHCP
886 +       timeouts = NULL;
887 +#endif
888 +       dhcp_type_interface = NULL;
889 +       interface_vector = NULL;
890 +       interface_count = 0;
891 +       interface_max = 0;
892 +       name_servers = 0;
893 +       domains = 0;
894 +       dhcp_type_interface = NULL;
895 +       dhcp_type_group = NULL;
896 +       dhcp_type_shared_network = NULL;
897 +       dhcp_type_control = NULL;
898 +       memset(&dhcp_universe, '\0', sizeof(struct universe));
899 +       memset(&nwip_universe, '\0', sizeof(struct universe));
900 +       memset(&fqdn_universe, '\0', sizeof(struct universe));
901 +       universe_hash = 0;
902 +       universes = 0;
903 +       universe_count = 0;
904 +       universe_max = 0;
905 +       config_universe = 0; 
906 +       extern struct hash_bucket *free_hash_buckets;
907 +       free_hash_buckets = NULL;
908 +       extern struct dhcp_packet *dhcp_free_list;
909 +       dhcp_free_list = NULL;
910 +       extern struct packet *packet_free_list;
911 +       packet_free_list = NULL;
912 +       extern struct binding_value *free_binding_values;
913 +       free_binding_values = NULL;
914 +       extern struct expression *free_expressions;
915 +       free_expressions = NULL;
916 +       extern struct option_cache *free_option_caches;
917 +       free_option_caches = NULL;
918 +       extern  struct packet *free_packets;
919 +       free_packets = NULL;
920 +       extern  pair free_pairs;
921 +       free_pairs = NULL;
922 +       extern omapi_io_object_t omapi_io_states;
923 +       memset(&omapi_io_states, '\0', sizeof(omapi_io_states));
924 +       dhcp_control_object = NULL;
925 +       unlink(current_pid_file);
926 +#endif
927  
928         /*NOTREACHED*/
929         return 0;
930 @@ -1203,7 +1373,20 @@ void dhcpack (packet)
931         if (client -> new -> rebind < cur_time)
932                 client -> new -> rebind = TIME_MAX;
933  
934 +#ifdef LIBDHCP
935 +       /* We need the server's siaddr for the 'bootServer'
936 +        * pump option
937 +        */
938 +       u_int32_t set_siaddr = 0;
939 +       set_siaddr = client->packet.siaddr.s_addr;
940 +       client->packet.siaddr.s_addr = packet->raw->siaddr.s_addr;
941 +#endif
942 +
943         bind_lease (client);
944 +
945 +#ifdef LIBDHCP
946 +       client->packet.siaddr.s_addr = set_siaddr;
947 +#endif
948  }
949  
950  void bind_lease (client)
951 @@ -1241,6 +1424,9 @@ void bind_lease (client)
952                 return;
953         }
954  
955 +#ifdef LIBDHCP
956 +       if (libdhcp_control && (libdhcp_control->capability & DHCP_USE_LEASE_DATABASE))
957 +#endif
958         /* Write out the new lease. */
959         write_client_lease (client, client -> new, 0, 0);
960  
961 @@ -1343,11 +1529,13 @@ int commit_leases ()
962         return 0;
963  }
964  
965 +#ifndef LIBDHCP
966  int write_lease (lease)
967         struct lease *lease;
968  {
969         return 0;
970  }
971 +#endif
972  
973  int write_host (host)
974         struct host_decl *host;
975 @@ -1957,6 +2145,10 @@ void state_panic (cpp)
976            tell the shell script that we failed to allocate an address,
977            and try again later. */
978         if (onetry) {
979 +#ifdef LIBDHCP
980 +               script_init (client, "FAIL", (struct string_list *)0);
981 +               return;
982 +#endif
983                 if (!quiet)
984                         log_info ("Unable to obtain a lease on first try.%s",
985                                   "  Exiting.");
986 @@ -2579,7 +2771,9 @@ void destroy_client_lease (lease)
987         free_client_lease (lease, MDL);
988  }
989  
990 +#ifndef LIBDHCP
991  FILE *leaseFile;
992 +#endif
993  
994  void rewrite_client_leases ()
995  {
996 @@ -2960,6 +3154,54 @@ void script_write_params (client, prefix
997  int script_go (client)
998         struct client_state *client;
999  {
1000 +#ifdef LIBDHCP
1001 +       struct string_list *sp;
1002 +
1003 +       if (libdhcp_control && libdhcp_control->callback) {
1004 +               int dhcmsg;
1005 +               char *reason="";
1006 +
1007 +               for (sp = client->env; sp; sp = sp->next)
1008 +                       if (strncmp(sp->string, "reason=", 7) == 0) {
1009 +                               reason = sp->string + 7;
1010 +                               break;
1011 +                       }
1012 +
1013 +               if (strcmp(reason,"NBI") == 0)
1014 +                       dhcmsg = DHC4_NBI;
1015 +               else if (strcmp(reason,"PREINIT") == 0)
1016 +                       dhcmsg = DHC4_PREINIT;
1017 +               else if (strcmp(reason,"BOUND") == 0)
1018 +                       dhcmsg = DHC4_BOUND;
1019 +               else if (strcmp(reason,"RENEW") == 0)
1020 +                       dhcmsg = DHC4_RENEW;
1021 +               else if (strcmp(reason,"REBOOT") == 0)
1022 +                       dhcmsg = DHC4_REBOOT;
1023 +               else if (strcmp(reason,"REBIND") == 0)
1024 +                       dhcmsg = DHC4_REBIND;
1025 +               else if (strcmp(reason,"STOP") == 0)
1026 +                       dhcmsg = DHC4_STOP;
1027 +               else if (strcmp(reason,"MEDIUM") == 0)
1028 +                       dhcmsg = DHC4_MEDIUM;
1029 +               else if (strcmp(reason,"TIMEOUT") == 0)
1030 +                       dhcmsg = DHC4_TIMEOUT;
1031 +               else if (strcmp(reason,"FAIL") == 0)
1032 +                       dhcmsg = DHC4_FAIL;
1033 +               else if (strcmp(reason,"EXPIRE") == 0)
1034 +                       dhcmsg = DHC4_EXPIRE;
1035 +               else if (strcmp(reason,"RELEASE") == 0)
1036 +                       dhcmsg = DHC4_RELEASE;
1037 +               else
1038 +                       dhcmsg = DHC4_NBI;
1039 +
1040 +               (*libdhcp_control->callback) (libdhcp_control, dhcmsg, client);
1041 +
1042 +               if (libdhcp_control->decline)
1043 +                       return 1;
1044 +       }
1045 +
1046 +       return 0;
1047 +#else
1048         int rval;
1049         char *scriptName;
1050         char *argv [2];
1051 @@ -3038,6 +3280,7 @@ int script_go (client)
1052         GET_TIME (&cur_time);
1053         return (WIFEXITED (wstatus) ?
1054                 WEXITSTATUS (wstatus) : -WTERMSIG (wstatus));
1055 +#endif
1056  }
1057  
1058  void client_envadd (struct client_state *client,
1059 @@ -3120,6 +3363,9 @@ void go_daemon ()
1060  
1061         /* Don't become a daemon if the user requested otherwise. */
1062         if (no_daemon) {
1063 +#ifdef LIBDHCP
1064 +               if (libdhcp_control && (libdhcp_control->capability & DHCP_USE_PID_FILE ))
1065 +#endif
1066                 write_client_pid_file ();
1067                 return;
1068         }
1069 @@ -3129,6 +3375,10 @@ void go_daemon ()
1070                 return;
1071         state = 1;
1072  
1073 +#ifdef LIBDHCP
1074 +       return;
1075 +#endif
1076 +
1077         /* Stop logging to stderr... */
1078         log_perror = 0;
1079  
1080 diff -up dhcp-3.1.0/Makefile.dist.libdhcp4client dhcp-3.1.0/Makefile.dist
1081 --- dhcp-3.1.0/Makefile.dist.libdhcp4client     2005-03-17 15:14:54.000000000 -0500
1082 +++ dhcp-3.1.0/Makefile.dist    2007-10-24 14:55:56.000000000 -0400
1083 @@ -22,7 +22,7 @@
1084  #   http://www.isc.org/
1085  
1086  
1087 -SUBDIRS=       common $(MINIRES) dst omapip server client relay dhcpctl
1088 +SUBDIRS=       common $(MINIRES) dst omapip server client relay dhcpctl libdhcp4client
1089  
1090  all:
1091         @for dir in ${SUBDIRS}; do \
1092 --- dhcp-3.1.0/minires/Makefile.dist.orig       2007-12-25 12:41:11.744624000 +0100
1093 +++ dhcp-3.1.0/minires/Makefile.dist    2007-12-25 12:54:35.448726491 +0100
1094 @@ -32,7 +32,7 @@
1095          ns_date.o ns_parse.o ns_sign.o ns_name.o ns_samedomain.o ns_verify.o
1096  
1097  INCLUDES = $(BINDINC) -I$(TOP)/includes
1098 -CFLAGS = $(DEBUG) $(PREDEFINES) $(INCLUDES) $(COPTS) -DHMAC_MD5 -DMINIRES_LIB
1099 +CFLAGS = $(DEBUG) $(PREDEFINES) $(INCLUDES) $(COPTS) -DHMAC_MD5 -DMINIRES_LIB -fPIC
1100  
1101  all:   libres.a
1102  
This page took 0.264104 seconds and 3 git commands to generate.