]> git.pld-linux.org Git - packages/dhcp.git/blame - dhcp-libdhcp4client.patch
- enable timeouts without debugging
[packages/dhcp.git] / dhcp-libdhcp4client.patch
CommitLineData
c494ae74
PZ
1diff -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,
13diff -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
133diff -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) || \
191diff -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
203diff -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));
291diff -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) {
333diff -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;
353diff -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,
364diff -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,11 +338,16 @@ void cancel_timeout (where, what)
600 q -> next = free_timeouts;
601 free_timeouts = q;
602 }
603+#endif
604 }
605
606 #if defined (DEBUG_MEMORY_LEAKAGE_ON_EXIT)
607 void cancel_all_timeouts ()
608 {
609+#ifdef LIBDHCP
610+ cur_time = TIME_MAX;
611+ process_outstanding_timeouts(NULL);
612+#else
613 struct timeout *t, *n;
614 for (t = timeouts; t; t = n) {
615 n = t -> next;
616@@ -205,13 +355,20 @@ void cancel_all_timeouts ()
617 t -> next = free_timeouts;
618 free_timeouts = t;
619 }
620+#endif
621 }
622
623+__attribute__ ((visibility ("default")))
624 void relinquish_timeouts ()
625 {
626+#ifdef LIBDHCP
627+ while (ntimeouts)
628+ cancel_timeout(timeouts[0].func, timeouts[0].what);
629+#else
630 struct timeout *t, *n;
631 for (t = free_timeouts; t; t = n) {
632 n = t -> next;
633 dfree (t, MDL);
634 }
635+#endif
636 }
637diff -up dhcp-3.1.0/common/alloc.c.libdhcp4client dhcp-3.1.0/common/alloc.c
638--- dhcp-3.1.0/common/alloc.c.libdhcp4client 2006-06-01 16:23:17.000000000 -0400
639+++ dhcp-3.1.0/common/alloc.c 2007-10-24 14:55:56.000000000 -0400
640@@ -1013,7 +1013,11 @@ int executable_statement_reference (ptr,
641 return 1;
642 }
643
644+#ifdef LIBDHCP
645+struct packet *free_packets;
646+#else
647 static struct packet *free_packets;
648+#endif
649
650 #if defined (DEBUG_MEMORY_LEAKAGE) || \
651 defined (DEBUG_MEMORY_LEAKAGE_ON_EXIT)
652diff -up dhcp-3.1.0/includes/dhcpd.h.libdhcp4client dhcp-3.1.0/includes/dhcpd.h
653--- dhcp-3.1.0/includes/dhcpd.h.libdhcp4client 2007-10-24 14:55:56.000000000 -0400
654+++ dhcp-3.1.0/includes/dhcpd.h 2007-10-24 14:55:56.000000000 -0400
655@@ -1000,14 +1000,6 @@ struct hardware_link {
656
657 typedef void (*tvref_t)(void *, void *, const char *, int);
658 typedef void (*tvunref_t)(void *, const char *, int);
659-struct timeout {
660- struct timeout *next;
661- TIME when;
662- void (*func) PROTO ((void *));
663- void *what;
664- tvref_t ref;
665- tvunref_t unref;
666-};
667
668 struct protocol {
669 struct protocol *next;
670@@ -1960,7 +1952,6 @@ extern void (*bootp_packet_handler) PROT
671 struct dhcp_packet *, unsigned,
672 unsigned int,
673 struct iaddr, struct hardware *));
674-extern struct timeout *timeouts;
675 extern omapi_object_type_t *dhcp_type_interface;
676 #if defined (TRACING)
677 trace_type_t *interface_trace;
678diff -up dhcp-3.1.0/client/dhclient.c.libdhcp4client dhcp-3.1.0/client/dhclient.c
679--- dhcp-3.1.0/client/dhclient.c.libdhcp4client 2007-10-24 14:55:56.000000000 -0400
680+++ dhcp-3.1.0/client/dhclient.c 2007-10-24 14:56:20.000000000 -0400
681@@ -82,16 +82,52 @@ int quiet=0;
682 int nowait=0;
683 int bootp_broadcast_always = 0;
684
685+#ifdef LIBDHCP
686+FILE *leaseFile = NULL;
687+#endif
688+
689 extern u_int32_t default_requested_options[];
690 #ifdef EXTENDED_NEW_OPTION_INFO
691 int extended_option_environment = 0;
692 #endif
693 static void usage PROTO ((void));
694
695+#ifdef LIBDHCP
696+#include "isc-dhcp/libdhcp_control.h"
697+LIBDHCP_Control *libdhcp_control;
698+static void libdhcp_dispatch(void)
699+{
700+ struct timeval tv = { 0, 0 }, *tvp;
701+ isc_result_t status;
702+
703+ /* Wait for a packet, or a timeout, or libdhcp being finished */
704+ do {
705+ tvp = process_outstanding_timeouts(&tv);
706+ status = omapi_one_dispatch(0, tvp);
707+
708+ if (libdhcp_control && ((status == ISC_R_TIMEDOUT) || (libdhcp_control->timeout && (time(NULL) >= (libdhcp_control->timeout + libdhcp_control->now))))) {
709+ if (libdhcp_control->callback)
710+ libdhcp_control->callback(libdhcp_control, DHC_TIMEDOUT, NULL);
711+
712+ break;
713+ }
714+ } while ((status != ISC_R_TIMEDOUT) && ((!libdhcp_control) || (!(libdhcp_control->finished))));
715+}
716+
717+extern void omapi_free_all_pointers(void);
718+
719+__attribute__ ((visibility ("default")))
720+int dhcpv4_client (libdhcp_ctl, argc, argv, envp)
721+ LIBDHCP_Control *libdhcp_ctl;
722+#else
723 int main (argc, argv, envp)
724+#endif
725 int argc;
726 char **argv, **envp;
727 {
728+#ifdef LIBDHCP
729+ libdhcp_control = libdhcp_ctl;
730+#endif
731 int fd;
732 int i;
733 struct servent *ent;
734@@ -120,6 +156,7 @@ int main (argc, argv, envp)
735 char *arg_conf = NULL;
736 int arg_conf_len = 0;
737
738+#ifndef LIBDHCP
739 /* Make sure that file descriptors 0 (stdin), 1, (stdout), and
740 2 (stderr) are open. To do this, we assume that when we
741 open a file the lowest available file decriptor is used. */
742@@ -143,6 +180,7 @@ int main (argc, argv, envp)
743 #if !(defined (DEBUG) || defined (SYSLOG_4_2) || defined (__CYGWIN32__))
744 setlogmask (LOG_UPTO (LOG_INFO));
745 #endif
746+#endif
747
748 /* Set up the OMAPI. */
749 status = omapi_init ();
750@@ -439,6 +477,10 @@ int main (argc, argv, envp)
751 }
752 }
753
754+#ifdef LIBDHCP
755+ if (libdhcp_control && (libdhcp_control->capability & DHCP_USE_PID_FILE))
756+#endif
757+#ifndef LIBDHCP
758 if (!quiet) {
759 log_info ("%s %s", message, DHCP_VERSION);
760 log_info (copyright);
761@@ -449,6 +491,7 @@ int main (argc, argv, envp)
762 log_info ("%s", "");
763 } else
764 log_perror = 0;
765+#endif
766
767 /* If we're given a relay agent address to insert, for testing
768 purposes, figure out what it is. */
769@@ -680,11 +723,17 @@ int main (argc, argv, envp)
770 arg_conf_len = 0;
771 }
772
773+#ifdef LIBDHCP
774+ if (libdhcp_control && (libdhcp_control->capability & DHCP_USE_LEASE_DATABASE)) {
775+#endif
776 /* Parse the lease database. */
777 read_client_leases ();
778
779 /* Rewrite the lease database... */
780 rewrite_client_leases ();
781+#ifdef LIBDHCP
782+ }
783+#endif
784
785 /* XXX */
786 /* config_counter(&snd_counter, &rcv_counter); */
787@@ -703,7 +752,7 @@ int main (argc, argv, envp)
788 if (!persist) {
789 /* Nothing more to do. */
790 log_info ("No broadcast interfaces found - exiting.");
791- exit (0);
792+ return (0);
793 }
794 } else if (!release_mode && !exit_mode) {
795 /* Call the script with the list of interfaces. */
796@@ -799,6 +848,7 @@ int main (argc, argv, envp)
797 dmalloc_outstanding = 0;
798 #endif
799
800+#ifndef LIBDHCP
801 /* If we're not supposed to wait before getting the address,
802 don't. */
803 if (nowait)
804@@ -811,6 +861,126 @@ int main (argc, argv, envp)
805
806 /* Start dispatching packets and timeouts... */
807 dispatch ();
808+#else
809+ if (libdhcp_control) {
810+ if (libdhcp_control->timeout)
811+ libdhcp_control->now = time(NULL);
812+ else
813+ libdhcp_control->now = 0;
814+ }
815+
816+ libdhcp_dispatch();
817+
818+ /* libdhcp is finished with us. */
819+
820+ /* close all file descriptors: */
821+ for (ip = interfaces; ip; ip = ip->next) {
822+ shutdown(ip->wfdesc, SHUT_RDWR);
823+ close(ip->wfdesc);
824+
825+ if (ip->rfdesc != ip->wfdesc)
826+ close(ip->rfdesc);
827+ }
828+
829+ if (fallback_interface != 0) {
830+ ip = fallback_interface;
831+ shutdown(ip->wfdesc, SHUT_RDWR);
832+ close(ip->wfdesc);
833+
834+ if (ip->rfdesc != ip->wfdesc)
835+ close(ip->rfdesc);
836+ }
837+
838+ if (leaseFile)
839+ fclose (leaseFile);
840+
841+ closelog();
842+
843+ char *current_pid_file = _PATH_DHCLIENT_PID;
844+
845+ /* Free ALL allocated memory: */
846+ omapi_free_all_pointers();
847+
848+ /* Re-Initialize globals: */
849+ client_env = 0;
850+ client_env_count = 0;
851+ default_lease_time = 43200;
852+
853+ dhcp_max_agent_option_packet_length = 0;
854+ iaddr_any.len = 4;
855+ memset(&(iaddr_any.iabuf[0]), '\0', 4);
856+ iaddr_broadcast.len = 4;
857+ memset(&(iaddr_broadcast.iabuf[0]), 0xff, 4);
858+ interfaces_requested = 0;
859+ leaseFile = 0;
860+
861+ libdhcp_control = 0;
862+
863+ local_port = 0;
864+ no_daemon = 0;
865+ nowait = 0;
866+ onetry = 0;
867+ quiet = 0;
868+ max_lease_time = 86400;
869+ path_dhclient_conf = _PATH_DHCLIENT_CONF;
870+ path_dhclient_db = _PATH_DHCLIENT_DB;
871+ path_dhclient_pid = _PATH_DHCLIENT_PID;
872+ strcpy(&(path_dhclient_script_array[0]), _PATH_DHCLIENT_SCRIPT);
873+ path_dhclient_script = path_dhclient_script_array;
874+ remote_port = 0;
875+ resolver_inited = 0;
876+ log_perror = 1;
877+ global_scope = NULL;
878+ root_group = NULL;
879+ group_name_hash = NULL;
880+ interfaces = NULL;
881+ dummy_interfaces = NULL;
882+ fallback_interface = NULL;
883+ extern int have_setup_fallback;
884+ have_setup_fallback = 0;
885+ quiet_interface_discovery = 1;
886+#ifndef LIBDHCP
887+ timeouts = NULL;
888+#endif
889+ dhcp_type_interface = NULL;
890+ interface_vector = NULL;
891+ interface_count = 0;
892+ interface_max = 0;
893+ name_servers = 0;
894+ domains = 0;
895+ dhcp_type_interface = NULL;
896+ dhcp_type_group = NULL;
897+ dhcp_type_shared_network = NULL;
898+ dhcp_type_control = NULL;
899+ memset(&dhcp_universe, '\0', sizeof(struct universe));
900+ memset(&nwip_universe, '\0', sizeof(struct universe));
901+ memset(&fqdn_universe, '\0', sizeof(struct universe));
902+ universe_hash = 0;
903+ universes = 0;
904+ universe_count = 0;
905+ universe_max = 0;
906+ config_universe = 0;
907+ extern struct hash_bucket *free_hash_buckets;
908+ free_hash_buckets = NULL;
909+ extern struct dhcp_packet *dhcp_free_list;
910+ dhcp_free_list = NULL;
911+ extern struct packet *packet_free_list;
912+ packet_free_list = NULL;
913+ extern struct binding_value *free_binding_values;
914+ free_binding_values = NULL;
915+ extern struct expression *free_expressions;
916+ free_expressions = NULL;
917+ extern struct option_cache *free_option_caches;
918+ free_option_caches = NULL;
919+ extern struct packet *free_packets;
920+ free_packets = NULL;
921+ extern pair free_pairs;
922+ free_pairs = NULL;
923+ extern omapi_io_object_t omapi_io_states;
924+ memset(&omapi_io_states, '\0', sizeof(omapi_io_states));
925+ dhcp_control_object = NULL;
926+ unlink(current_pid_file);
927+#endif
928
929 /*NOTREACHED*/
930 return 0;
931@@ -1203,7 +1373,20 @@ void dhcpack (packet)
932 if (client -> new -> rebind < cur_time)
933 client -> new -> rebind = TIME_MAX;
934
935+#ifdef LIBDHCP
936+ /* We need the server's siaddr for the 'bootServer'
937+ * pump option
938+ */
939+ u_int32_t set_siaddr = 0;
940+ set_siaddr = client->packet.siaddr.s_addr;
941+ client->packet.siaddr.s_addr = packet->raw->siaddr.s_addr;
942+#endif
943+
944 bind_lease (client);
945+
946+#ifdef LIBDHCP
947+ client->packet.siaddr.s_addr = set_siaddr;
948+#endif
949 }
950
951 void bind_lease (client)
952@@ -1241,6 +1424,9 @@ void bind_lease (client)
953 return;
954 }
955
956+#ifdef LIBDHCP
957+ if (libdhcp_control && (libdhcp_control->capability & DHCP_USE_LEASE_DATABASE))
958+#endif
959 /* Write out the new lease. */
960 write_client_lease (client, client -> new, 0, 0);
961
962@@ -1343,11 +1529,13 @@ int commit_leases ()
963 return 0;
964 }
965
966+#ifndef LIBDHCP
967 int write_lease (lease)
968 struct lease *lease;
969 {
970 return 0;
971 }
972+#endif
973
974 int write_host (host)
975 struct host_decl *host;
976@@ -1957,6 +2145,10 @@ void state_panic (cpp)
977 tell the shell script that we failed to allocate an address,
978 and try again later. */
979 if (onetry) {
980+#ifdef LIBDHCP
981+ script_init (client, "FAIL", (struct string_list *)0);
982+ return;
983+#endif
984 if (!quiet)
985 log_info ("Unable to obtain a lease on first try.%s",
986 " Exiting.");
987@@ -2579,7 +2771,9 @@ void destroy_client_lease (lease)
988 free_client_lease (lease, MDL);
989 }
990
991+#ifndef LIBDHCP
992 FILE *leaseFile;
993+#endif
994
995 void rewrite_client_leases ()
996 {
997@@ -2960,6 +3154,54 @@ void script_write_params (client, prefix
998 int script_go (client)
999 struct client_state *client;
1000 {
1001+#ifdef LIBDHCP
1002+ struct string_list *sp;
1003+
1004+ if (libdhcp_control && libdhcp_control->callback) {
1005+ int dhcmsg;
1006+ char *reason="";
1007+
1008+ for (sp = client->env; sp; sp = sp->next)
1009+ if (strncmp(sp->string, "reason=", 7) == 0) {
1010+ reason = sp->string + 7;
1011+ break;
1012+ }
1013+
1014+ if (strcmp(reason,"NBI") == 0)
1015+ dhcmsg = DHC4_NBI;
1016+ else if (strcmp(reason,"PREINIT") == 0)
1017+ dhcmsg = DHC4_PREINIT;
1018+ else if (strcmp(reason,"BOUND") == 0)
1019+ dhcmsg = DHC4_BOUND;
1020+ else if (strcmp(reason,"RENEW") == 0)
1021+ dhcmsg = DHC4_RENEW;
1022+ else if (strcmp(reason,"REBOOT") == 0)
1023+ dhcmsg = DHC4_REBOOT;
1024+ else if (strcmp(reason,"REBIND") == 0)
1025+ dhcmsg = DHC4_REBIND;
1026+ else if (strcmp(reason,"STOP") == 0)
1027+ dhcmsg = DHC4_STOP;
1028+ else if (strcmp(reason,"MEDIUM") == 0)
1029+ dhcmsg = DHC4_MEDIUM;
1030+ else if (strcmp(reason,"TIMEOUT") == 0)
1031+ dhcmsg = DHC4_TIMEOUT;
1032+ else if (strcmp(reason,"FAIL") == 0)
1033+ dhcmsg = DHC4_FAIL;
1034+ else if (strcmp(reason,"EXPIRE") == 0)
1035+ dhcmsg = DHC4_EXPIRE;
1036+ else if (strcmp(reason,"RELEASE") == 0)
1037+ dhcmsg = DHC4_RELEASE;
1038+ else
1039+ dhcmsg = DHC4_NBI;
1040+
1041+ (*libdhcp_control->callback) (libdhcp_control, dhcmsg, client);
1042+
1043+ if (libdhcp_control->decline)
1044+ return 1;
1045+ }
1046+
1047+ return 0;
1048+#else
1049 int rval;
1050 char *scriptName;
1051 char *argv [2];
1052@@ -3038,6 +3280,7 @@ int script_go (client)
1053 GET_TIME (&cur_time);
1054 return (WIFEXITED (wstatus) ?
1055 WEXITSTATUS (wstatus) : -WTERMSIG (wstatus));
1056+#endif
1057 }
1058
1059 void client_envadd (struct client_state *client,
1060@@ -3120,6 +3363,9 @@ void go_daemon ()
1061
1062 /* Don't become a daemon if the user requested otherwise. */
1063 if (no_daemon) {
1064+#ifdef LIBDHCP
1065+ if (libdhcp_control && (libdhcp_control->capability & DHCP_USE_PID_FILE ))
1066+#endif
1067 write_client_pid_file ();
1068 return;
1069 }
1070@@ -3129,6 +3375,10 @@ void go_daemon ()
1071 return;
1072 state = 1;
1073
1074+#ifdef LIBDHCP
1075+ return;
1076+#endif
1077+
1078 /* Stop logging to stderr... */
1079 log_perror = 0;
1080
1081diff -up dhcp-3.1.0/Makefile.dist.libdhcp4client dhcp-3.1.0/Makefile.dist
1082--- dhcp-3.1.0/Makefile.dist.libdhcp4client 2005-03-17 15:14:54.000000000 -0500
1083+++ dhcp-3.1.0/Makefile.dist 2007-10-24 14:55:56.000000000 -0400
1084@@ -22,7 +22,7 @@
1085 # http://www.isc.org/
1086
1087
1088-SUBDIRS= common $(MINIRES) dst omapip server client relay dhcpctl
1089+SUBDIRS= common $(MINIRES) dst omapip server client relay dhcpctl libdhcp4client
1090
1091 all:
1092 @for dir in ${SUBDIRS}; do \
This page took 0.167151 seconds and 4 git commands to generate.