ISC DHCP  4.4.2b1
A reference DHCPv4 and DHCPv6 implementation
print.c
Go to the documentation of this file.
1 /* print.c
2 
3  Turn data structures into printable text. */
4 
5 /*
6  * Copyright (c) 2004-2018 by Internet Systems Consortium, Inc. ("ISC")
7  * Copyright (c) 1995-2003 by Internet Software Consortium
8  *
9  * This Source Code Form is subject to the terms of the Mozilla Public
10  * License, v. 2.0. If a copy of the MPL was not distributed with this
11  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
12  *
13  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
14  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
15  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
16  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
17  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
18  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
19  * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20  *
21  * Internet Systems Consortium, Inc.
22  * 950 Charter Street
23  * Redwood City, CA 94063
24  * <info@isc.org>
25  * https://www.isc.org/
26  *
27  */
28 
29 #include "dhcpd.h"
30 
32 
33 char *quotify_string (const char *s, const char *file, int line)
34 {
35  unsigned len = 0;
36  const char *sp;
37  char *buf, *nsp;
38 
39  for (sp = s; sp && *sp; sp++) {
40  if (*sp == ' ')
41  len++;
42  else if (!isascii ((int)*sp) || !isprint ((int)*sp))
43  len += 4;
44  else if (*sp == '"' || *sp == '\\')
45  len += 2;
46  else
47  len++;
48  }
49 
50  buf = dmalloc (len + 1, file, line);
51  if (buf) {
52  nsp = buf;
53  for (sp = s; sp && *sp; sp++) {
54  if (*sp == ' ')
55  *nsp++ = ' ';
56  else if (!isascii ((int)*sp) || !isprint ((int)*sp)) {
57  sprintf (nsp, "\\%03o",
58  *(const unsigned char *)sp);
59  nsp += 4;
60  } else if (*sp == '"' || *sp == '\\') {
61  *nsp++ = '\\';
62  *nsp++ = *sp;
63  } else
64  *nsp++ = *sp;
65  }
66  *nsp++ = 0;
67  }
68  return buf;
69 }
70 
71 char *quotify_buf (const unsigned char *s, unsigned len, char enclose_char,
72  const char *file, int line)
73 {
74  unsigned nulen = 0;
75  char *buf, *nsp;
76  int i;
77 
78  for (i = 0; i < len; i++) {
79  if (s [i] == ' ')
80  nulen++;
81  else if (!isascii (s [i]) || !isprint (s [i]))
82  nulen += 4;
83  else if (s [i] == '"' || s [i] == '\\')
84  nulen += 2;
85  else
86  nulen++;
87  }
88 
89  if (enclose_char) {
90  nulen +=2 ;
91  }
92 
93  buf = dmalloc (nulen + 1, MDL);
94  if (buf) {
95  nsp = buf;
96  if (enclose_char) {
97  *nsp++ = enclose_char;
98  }
99 
100  for (i = 0; i < len; i++) {
101  if (s [i] == ' ')
102  *nsp++ = ' ';
103  else if (!isascii (s [i]) || !isprint (s [i])) {
104  sprintf (nsp, "\\%03o", s [i]);
105  nsp += 4;
106  } else if (s [i] == '"' || s [i] == '\\') {
107  *nsp++ = '\\';
108  *nsp++ = s [i];
109  } else
110  *nsp++ = s [i];
111  }
112 
113  if (enclose_char) {
114  *nsp++ = enclose_char;
115  }
116  *nsp++ = 0;
117  }
118  return buf;
119 }
120 
121 char *print_base64 (const unsigned char *buf, unsigned len,
122  const char *file, int line)
123 {
124  char *s, *b;
125  unsigned bl;
126  int i;
127  unsigned val, extra;
128  static char to64 [] =
129  "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
130 
131  bl = ((len * 4 + 2) / 3) + 1;
132  b = dmalloc (bl + 1, file, line);
133  if (!b)
134  return (char *)0;
135 
136  i = 0;
137  s = b;
138  while (i != len) {
139  val = buf [i++];
140  extra = val & 3;
141  val = val >> 2;
142  *s++ = to64 [val];
143  if (i == len) {
144  *s++ = to64 [extra << 4];
145  *s++ = '=';
146  break;
147  }
148  val = (extra << 8) + buf [i++];
149  extra = val & 15;
150  val = val >> 4;
151  *s++ = to64 [val];
152  if (i == len) {
153  *s++ = to64 [extra << 2];
154  *s++ = '=';
155  break;
156  }
157  val = (extra << 8) + buf [i++];
158  extra = val & 0x3f;
159  val = val >> 6;
160  *s++ = to64 [val];
161  *s++ = to64 [extra];
162  }
163  if (!len)
164  *s++ = '=';
165  *s++ = 0;
166  if (s > b + bl + 1)
167  abort ();
168  return b;
169 }
170 
171 char *print_hw_addr (htype, hlen, data)
172  const int htype;
173  int hlen;
174  const unsigned char *data;
175 {
176  /* Buffer sized for InfiniBand (20 bytes): 20 * 3 = 60 chars
177  * Each byte needs 3 chars "xx:", last ':' replaced by 0 */
178  static char habuf [60];
179  int max_bytes = sizeof(habuf) / 3;
180  char *s;
181  int i;
182 
183  if (hlen <= 0 || data == NULL)
184  habuf [0] = 0;
185  else {
186  int orig_hlen = 0;
187  if (hlen > max_bytes) {
188  orig_hlen = hlen;
189  hlen = max_bytes;
190  }
191 
192  s = habuf;
193  for (i = 0; i < hlen; i++) {
194  sprintf (s, "%02x", data [i]);
195  s += 2;
196  *s++ = ':';
197  }
198  *--s = 0;
199 
200  if (orig_hlen) {
201  log_error("Hardware address %s truncated from %d to %d bytes",
202  habuf, orig_hlen, max_bytes);
203  }
204  }
205  return habuf;
206 }
207 
209  struct lease *lease;
210 {
211  struct tm *t;
212  char tbuf [32];
213 
214  log_debug (" Lease %s",
215  piaddr (lease -> ip_addr));
216 
217  t = gmtime (&lease -> starts);
218  strftime (tbuf, sizeof tbuf, "%Y/%m/%d %H:%M:%S", t);
219  log_debug (" start %s", tbuf);
220 
221  t = gmtime (&lease -> ends);
222  strftime (tbuf, sizeof tbuf, "%Y/%m/%d %H:%M:%S", t);
223  log_debug (" end %s", tbuf);
224 
225  if (lease -> hardware_addr.hlen)
226  log_debug (" hardware addr = %s",
227  print_hw_addr (lease -> hardware_addr.hbuf [0],
228  lease -> hardware_addr.hlen - 1,
229  &lease -> hardware_addr.hbuf [1]));
230  log_debug (" host %s ",
231  lease -> host ? lease -> host -> name : "<none>");
232 }
233 
234 #if defined (DEBUG_PACKET)
235 void dump_packet_option (struct option_cache *oc,
236  struct packet *packet,
237  struct lease *lease,
238  struct client_state *client,
239  struct option_state *in_options,
240  struct option_state *cfg_options,
241  struct binding_scope **scope,
242  struct universe *u, void *foo)
243 {
244  const char *name, *dot;
245  struct data_string ds;
246  memset (&ds, 0, sizeof ds);
247 
248  if (u != &dhcp_universe) {
249  name = u -> name;
250  dot = ".";
251  } else {
252  name = "";
253  dot = "";
254  }
255  if (evaluate_option_cache (&ds, packet, lease, client,
256  in_options, cfg_options, scope, oc, MDL)) {
257  log_debug (" option %s%s%s %s;\n",
258  name, dot, oc -> option -> name,
260  ds.data, ds.len, 1, 1));
261  data_string_forget (&ds, MDL);
262  }
263 }
264 
265 void dump_packet (tp)
266  struct packet *tp;
267 {
268  struct dhcp_packet *tdp = tp -> raw;
269 
270  log_debug ("packet length %d", tp -> packet_length);
271  log_debug ("op = %d htype = %d hlen = %d hops = %d",
272  tdp -> op, tdp -> htype, tdp -> hlen, tdp -> hops);
273  log_debug ("xid = %x secs = %ld flags = %x",
274  tdp -> xid, (unsigned long)tdp -> secs, tdp -> flags);
275  log_debug ("ciaddr = %s", inet_ntoa (tdp -> ciaddr));
276  log_debug ("yiaddr = %s", inet_ntoa (tdp -> yiaddr));
277  log_debug ("siaddr = %s", inet_ntoa (tdp -> siaddr));
278  log_debug ("giaddr = %s", inet_ntoa (tdp -> giaddr));
279  log_debug ("chaddr = %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x",
280  ((unsigned char *)(tdp -> chaddr)) [0],
281  ((unsigned char *)(tdp -> chaddr)) [1],
282  ((unsigned char *)(tdp -> chaddr)) [2],
283  ((unsigned char *)(tdp -> chaddr)) [3],
284  ((unsigned char *)(tdp -> chaddr)) [4],
285  ((unsigned char *)(tdp -> chaddr)) [5]);
286  log_debug ("filename = %s", tdp -> file);
287  log_debug ("server_name = %s", tdp -> sname);
288  if (tp -> options_valid) {
289  int i;
290 
291  for (i = 0; i < tp -> options -> universe_count; i++) {
292  if (tp -> options -> universes [i]) {
293  option_space_foreach (tp, (struct lease *)0,
294  (struct client_state *)0,
295  (struct option_state *)0,
296  tp -> options,
297  &global_scope,
298  universes [i], 0,
300  }
301  }
302  }
303  log_debug ("%s", "");
304 }
305 #endif
306 
307 void dump_raw (buf, len)
308  const unsigned char *buf;
309  unsigned len;
310 {
311  int i;
312  char lbuf [80];
313  int lbix = 0;
314 
315 /*
316  1 2 3 4 5 6 7
317 01234567890123456789012345678901234567890123456789012345678901234567890123
318 280: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .................
319 */
320 
321  memset(lbuf, ' ', 79);
322  lbuf [79] = 0;
323 
324  for (i = 0; i < len; i++) {
325  if ((i & 15) == 0) {
326  if (lbix) {
327  lbuf[53]=' ';
328  lbuf[54]=' ';
329  lbuf[55]=' ';
330  lbuf[73]='\0';
331  log_info ("%s", lbuf);
332  }
333  memset(lbuf, ' ', 79);
334  lbuf [79] = 0;
335  sprintf (lbuf, "%03x:", i);
336  lbix = 4;
337  } else if ((i & 7) == 0)
338  lbuf [lbix++] = ' ';
339 
340  if(isprint(buf[i])) {
341  lbuf[56+(i%16)]=buf[i];
342  } else {
343  lbuf[56+(i%16)]='.';
344  }
345 
346  sprintf (&lbuf [lbix], " %02x", buf [i]);
347  lbix += 3;
348  lbuf[lbix]=' ';
349 
350  }
351  lbuf[53]=' ';
352  lbuf[54]=' ';
353  lbuf[55]=' ';
354  lbuf[73]='\0';
355  log_info ("%s", lbuf);
356 }
357 
358 void hash_dump (table)
359  struct hash_table *table;
360 {
361  int i;
362  struct hash_bucket *bp;
363 
364  if (!table)
365  return;
366 
367  for (i = 0; i < table -> hash_count; i++) {
368  if (!table -> buckets [i])
369  continue;
370  log_info ("hash bucket %d:", i);
371  for (bp = table -> buckets [i]; bp; bp = bp -> next) {
372  if (bp -> len)
373  dump_raw (bp -> name, bp -> len);
374  else
375  log_info ("%s", (const char *)bp -> name);
376  }
377  }
378 }
379 
380 /*
381  * print a string as hex. This only outputs
382  * colon separated hex list no matter what
383  * the input looks like. See print_hex
384  * for a function that prints either cshl
385  * or a string if all bytes are printible
386  * It only uses limit characters from buf
387  * and doesn't do anything if buf == NULL
388  *
389  * len - length of data
390  * data - input data
391  * limit - length of buf to use
392  * buf - output buffer
393  */
394 void print_hex_only (len, data, limit, buf)
395  unsigned len;
396  const u_int8_t *data;
397  unsigned limit;
398  char *buf;
399 {
400  char *bufptr = buf;
401  int byte = 0;
402 
403  if (data == NULL || bufptr == NULL || limit == 0) {
404  return;
405  }
406 
407  if (((len == 0) || ((len * 3) > limit))) {
408  *bufptr = 0x0;
409  return;
410  }
411 
412  for ( ; byte < len; ++byte) {
413  if (byte > 0) {
414  *bufptr++ = ':';
415  }
416 
417  sprintf(bufptr, "%02x", data[byte]);
418  bufptr += 2;
419  }
420 
421  return;
422 }
423 
424 /*
425  * print a string as either text if all the characters
426  * are printable or colon separated hex if they aren't
427  *
428  * len - length of data
429  * data - input data
430  * limit - length of buf to use
431  * buf - output buffer
432  */
433 void print_hex_or_string (len, data, limit, buf)
434  unsigned len;
435  const u_int8_t *data;
436  unsigned limit;
437  char *buf;
438 {
439  unsigned i;
440  if ((buf == NULL) || (limit < 3))
441  return;
442 
443  for (i = 0; (i < (limit - 3)) && (i < len); i++) {
444  if (!isascii(data[i]) || !isprint(data[i])) {
445  print_hex_only(len, data, limit, buf);
446  return;
447  }
448  }
449 
450  buf[0] = '"';
451  i = len;
452  if (i > (limit - 3))
453  i = limit - 3;
454  memcpy(&buf[1], data, i);
455  buf[i + 1] = '"';
456  buf[i + 2] = 0;
457  return;
458 }
459 
460 /*
461  * print a string as either hex or text
462  * using static buffers to hold the output
463  *
464  * len - length of data
465  * data - input data
466  * limit - length of buf
467  * buf_num - the output buffer to use
468  */
469 #define HBLEN 1024
470 char *print_hex(len, data, limit, buf_num)
471  unsigned len;
472  const u_int8_t *data;
473  unsigned limit;
474  unsigned buf_num;
475 {
476  static char hex_buf_1[HBLEN + 1];
477  static char hex_buf_2[HBLEN + 1];
478  static char hex_buf_3[HBLEN + 1];
479  char *hex_buf;
480 
481  switch(buf_num) {
482  case 0:
483  hex_buf = hex_buf_1;
484  if (limit >= sizeof(hex_buf_1))
485  limit = sizeof(hex_buf_1);
486  break;
487  case 1:
488  hex_buf = hex_buf_2;
489  if (limit >= sizeof(hex_buf_2))
490  limit = sizeof(hex_buf_2);
491  break;
492  case 2:
493  hex_buf = hex_buf_3;
494  if (limit >= sizeof(hex_buf_3))
495  limit = sizeof(hex_buf_3);
496  break;
497  default:
498  return(NULL);
499  }
500 
501  print_hex_or_string(len, data, limit, hex_buf);
502  return(hex_buf);
503 }
504 
505 #define DQLEN 80
506 
507 char *print_dotted_quads (len, data)
508  unsigned len;
509  const u_int8_t *data;
510 {
511  static char dq_buf [DQLEN + 1];
512  int i;
513  char *s;
514 
515  s = &dq_buf [0];
516 
517  i = 0;
518 
519  /* %Audit% Loop bounds checks to 21 bytes. %2004.06.17,Safe%
520  * The sprintf can't exceed 18 bytes, and since the loop enforces
521  * 21 bytes of space per iteration at no time can we exit the
522  * loop without at least 3 bytes spare.
523  */
524  do {
525  sprintf (s, "%u.%u.%u.%u, ",
526  data [i], data [i + 1], data [i + 2], data [i + 3]);
527  s += strlen (s);
528  i += 4;
529  } while ((s - &dq_buf [0] > DQLEN - 21) &&
530  i + 3 < len);
531  if (i == len)
532  s [-2] = 0;
533  else
534  strcpy (s, "...");
535  return dq_buf;
536 }
537 
538 char *print_dec_1 (val)
539  unsigned long val;
540 {
541  static char vbuf [32];
542  sprintf (vbuf, "%lu", val);
543  return vbuf;
544 }
545 
546 char *print_dec_2 (val)
547  unsigned long val;
548 {
549  static char vbuf [32];
550  sprintf (vbuf, "%lu", val);
551  return vbuf;
552 }
553 
554 static unsigned print_subexpression (struct expression *, char *, unsigned);
555 
556 static unsigned print_subexpression (expr, buf, len)
557  struct expression *expr;
558  char *buf;
559  unsigned len;
560 {
561  unsigned rv, left;
562  const char *s;
563 
564  switch (expr -> op) {
565  case expr_none:
566  if (len > 3) {
567  strcpy (buf, "nil");
568  return 3;
569  }
570  break;
571 
572  case expr_match:
573  if (len > 7) {
574  strcpy (buf, "(match)");
575  return 7;
576  }
577  break;
578 
579  case expr_check:
580  rv = 10 + strlen (expr -> data.check -> name);
581  if (len > rv) {
582  sprintf (buf, "(check %s)",
583  expr -> data.check -> name);
584  return rv;
585  }
586  break;
587 
588  case expr_equal:
589  if (len > 6) {
590  rv = 4;
591  strcpy (buf, "(eq ");
592  rv += print_subexpression (expr -> data.equal [0],
593  buf + rv, len - rv - 2);
594  buf [rv++] = ' ';
595  rv += print_subexpression (expr -> data.equal [1],
596  buf + rv, len - rv - 1);
597  buf [rv++] = ')';
598  buf [rv] = 0;
599  return rv;
600  }
601  break;
602 
603  case expr_not_equal:
604  if (len > 7) {
605  rv = 5;
606  strcpy (buf, "(neq ");
607  rv += print_subexpression (expr -> data.equal [0],
608  buf + rv, len - rv - 2);
609  buf [rv++] = ' ';
610  rv += print_subexpression (expr -> data.equal [1],
611  buf + rv, len - rv - 1);
612  buf [rv++] = ')';
613  buf [rv] = 0;
614  return rv;
615  }
616  break;
617 
618  case expr_regex_match:
619  if (len > 10) {
620  rv = 4;
621  strcpy(buf, "(regex ");
622  rv += print_subexpression(expr->data.equal[0],
623  buf + rv, len - rv - 2);
624  buf[rv++] = ' ';
625  rv += print_subexpression(expr->data.equal[1],
626  buf + rv, len - rv - 1);
627  buf[rv++] = ')';
628  buf[rv] = 0;
629  return rv;
630  }
631  break;
632 
633  case expr_substring:
634  if (len > 11) {
635  rv = 8;
636  strcpy (buf, "(substr ");
637  rv += print_subexpression (expr -> data.substring.expr,
638  buf + rv, len - rv - 3);
639  buf [rv++] = ' ';
640  rv += print_subexpression
641  (expr -> data.substring.offset,
642  buf + rv, len - rv - 2);
643  buf [rv++] = ' ';
644  rv += print_subexpression (expr -> data.substring.len,
645  buf + rv, len - rv - 1);
646  buf [rv++] = ')';
647  buf [rv] = 0;
648  return rv;
649  }
650  break;
651 
652  case expr_suffix:
653  if (len > 10) {
654  rv = 8;
655  strcpy (buf, "(suffix ");
656  rv += print_subexpression (expr -> data.suffix.expr,
657  buf + rv, len - rv - 2);
658  if (len > rv)
659  buf [rv++] = ' ';
660  rv += print_subexpression (expr -> data.suffix.len,
661  buf + rv, len - rv - 1);
662  if (len > rv)
663  buf [rv++] = ')';
664  buf [rv] = 0;
665  return rv;
666  }
667  break;
668 
669  case expr_lcase:
670  if (len > 9) {
671  rv = 7;
672  strcpy(buf, "(lcase ");
673  rv += print_subexpression(expr->data.lcase,
674  buf + rv, len - rv - 1);
675  buf[rv++] = ')';
676  buf[rv] = 0;
677  return rv;
678  }
679  break;
680 
681  case expr_ucase:
682  if (len > 9) {
683  rv = 7;
684  strcpy(buf, "(ucase ");
685  rv += print_subexpression(expr->data.ucase,
686  buf + rv, len - rv - 1);
687  buf[rv++] = ')';
688  buf[rv] = 0;
689  return rv;
690  }
691  break;
692 
693  case expr_concat:
694  if (len > 10) {
695  rv = 8;
696  strcpy (buf, "(concat ");
697  rv += print_subexpression (expr -> data.concat [0],
698  buf + rv, len - rv - 2);
699  buf [rv++] = ' ';
700  rv += print_subexpression (expr -> data.concat [1],
701  buf + rv, len - rv - 1);
702  buf [rv++] = ')';
703  buf [rv] = 0;
704  return rv;
705  }
706  break;
707 
709  if (len > 8) {
710  rv = 6;
711  strcpy (buf, "(pick1st ");
712  rv += print_subexpression
713  (expr -> data.pick_first_value.car,
714  buf + rv, len - rv - 2);
715  buf [rv++] = ' ';
716  rv += print_subexpression
717  (expr -> data.pick_first_value.cdr,
718  buf + rv, len - rv - 1);
719  buf [rv++] = ')';
720  buf [rv] = 0;
721  return rv;
722  }
723  break;
724 
725  case expr_host_lookup:
726  rv = 15 + strlen (expr -> data.host_lookup -> hostname);
727  if (len > rv) {
728  sprintf (buf, "(dns-lookup %s)",
729  expr -> data.host_lookup -> hostname);
730  return rv;
731  }
732  break;
733 
734  case expr_and:
735  s = "and";
736  binop:
737  rv = strlen (s);
738  if (len > rv + 4) {
739  buf [0] = '(';
740  strcpy (&buf [1], s);
741  rv += 1;
742  buf [rv++] = ' ';
743  rv += print_subexpression (expr -> data.and [0],
744  buf + rv, len - rv - 2);
745  buf [rv++] = ' ';
746  rv += print_subexpression (expr -> data.and [1],
747  buf + rv, len - rv - 1);
748  buf [rv++] = ')';
749  buf [rv] = 0;
750  return rv;
751  }
752  break;
753 
754  case expr_or:
755  s = "or";
756  goto binop;
757 
758  case expr_add:
759  s = "+";
760  goto binop;
761 
762  case expr_subtract:
763  s = "-";
764  goto binop;
765 
766  case expr_multiply:
767  s = "*";
768  goto binop;
769 
770  case expr_divide:
771  s = "/";
772  goto binop;
773 
774  case expr_remainder:
775  s = "%";
776  goto binop;
777 
778  case expr_binary_and:
779  s = "&";
780  goto binop;
781 
782  case expr_binary_or:
783  s = "|";
784  goto binop;
785 
786  case expr_binary_xor:
787  s = "^";
788  goto binop;
789 
790  case expr_not:
791  if (len > 6) {
792  rv = 5;
793  strcpy (buf, "(not ");
794  rv += print_subexpression (expr -> data.not,
795  buf + rv, len - rv - 1);
796  buf [rv++] = ')';
797  buf [rv] = 0;
798  return rv;
799  }
800  break;
801 
802  case expr_config_option:
803  s = "cfg-option";
804  goto dooption;
805 
806  case expr_option:
807  s = "option";
808  dooption:
809  rv = strlen (s) + 2 + (strlen (expr -> data.option -> name) +
810  strlen (expr -> data.option -> universe -> name));
811  if (len > rv) {
812  sprintf (buf, "(option %s.%s)",
813  expr -> data.option -> universe -> name,
814  expr -> data.option -> name);
815  return rv;
816  }
817  break;
818 
819  case expr_hardware:
820  if (len > 10) {
821  strcpy (buf, "(hardware)");
822  return 10;
823  }
824  break;
825 
826  case expr_packet:
827  if (len > 10) {
828  rv = 8;
829  strcpy (buf, "(substr ");
830  rv += print_subexpression (expr -> data.packet.offset,
831  buf + rv, len - rv - 2);
832  buf [rv++] = ' ';
833  rv += print_subexpression (expr -> data.packet.len,
834  buf + rv, len - rv - 1);
835  buf [rv++] = ')';
836  buf [rv] = 0;
837  return rv;
838  }
839  break;
840 
841  case expr_const_data:
842  s = print_hex_1 (expr -> data.const_data.len,
843  expr -> data.const_data.data, len);
844  rv = strlen (s);
845  if (rv >= len)
846  rv = len - 1;
847  strncpy (buf, s, rv);
848  buf [rv] = 0;
849  return rv;
850 
851  case expr_encapsulate:
852  rv = 13;
853  strcpy (buf, "(encapsulate ");
854  rv += expr -> data.encapsulate.len;
855  if (rv + 2 > len)
856  rv = len - 2;
857  strncpy (buf,
858  (const char *)expr -> data.encapsulate.data, rv - 13);
859  buf [rv++] = ')';
860  buf [rv++] = 0;
861  break;
862 
863  case expr_extract_int8:
864  if (len > 7) {
865  rv = 6;
866  strcpy (buf, "(int8 ");
867  rv += print_subexpression (expr -> data.extract_int,
868  buf + rv, len - rv - 1);
869  buf [rv++] = ')';
870  buf [rv] = 0;
871  return rv;
872  }
873  break;
874 
875  case expr_extract_int16:
876  if (len > 8) {
877  rv = 7;
878  strcpy (buf, "(int16 ");
879  rv += print_subexpression (expr -> data.extract_int,
880  buf + rv, len - rv - 1);
881  buf [rv++] = ')';
882  buf [rv] = 0;
883  return rv;
884  }
885  break;
886 
887  case expr_extract_int32:
888  if (len > 8) {
889  rv = 7;
890  strcpy (buf, "(int32 ");
891  rv += print_subexpression (expr -> data.extract_int,
892  buf + rv, len - rv - 1);
893  buf [rv++] = ')';
894  buf [rv] = 0;
895  return rv;
896  }
897  break;
898 
899  case expr_encode_int8:
900  if (len > 7) {
901  rv = 6;
902  strcpy (buf, "(to-int8 ");
903  rv += print_subexpression (expr -> data.encode_int,
904  buf + rv, len - rv - 1);
905  buf [rv++] = ')';
906  buf [rv] = 0;
907  return rv;
908  }
909  break;
910 
911  case expr_encode_int16:
912  if (len > 8) {
913  rv = 7;
914  strcpy (buf, "(to-int16 ");
915  rv += print_subexpression (expr -> data.encode_int,
916  buf + rv, len - rv - 1);
917  buf [rv++] = ')';
918  buf [rv] = 0;
919  return rv;
920  }
921  break;
922 
923  case expr_encode_int32:
924  if (len > 8) {
925  rv = 7;
926  strcpy (buf, "(to-int32 ");
927  rv += print_subexpression (expr -> data.encode_int,
928  buf + rv, len - rv - 1);
929  buf [rv++] = ')';
930  buf [rv] = 0;
931  return rv;
932  }
933  break;
934 
935  case expr_const_int:
936  s = print_dec_1 (expr -> data.const_int);
937  rv = strlen (s);
938  if (len > rv) {
939  strcpy (buf, s);
940  return rv;
941  }
942  break;
943 
944  case expr_exists:
945  rv = 10 + (strlen (expr -> data.option -> name) +
946  strlen (expr -> data.option -> universe -> name));
947  if (len > rv) {
948  sprintf (buf, "(exists %s.%s)",
949  expr -> data.option -> universe -> name,
950  expr -> data.option -> name);
951  return rv;
952  }
953  break;
954 
956  rv = 10 + strlen (expr -> data.variable);
957  if (len > rv) {
958  sprintf (buf, "(defined %s)", expr -> data.variable);
959  return rv;
960  }
961  break;
962 
964  rv = strlen (expr -> data.variable);
965  if (len > rv) {
966  sprintf (buf, "%s", expr -> data.variable);
967  return rv;
968  }
969  break;
970 
971  case expr_known:
972  s = "known";
973  astring:
974  rv = strlen (s);
975  if (len > rv) {
976  strcpy (buf, s);
977  return rv;
978  }
979  break;
980 
981  case expr_leased_address:
982  s = "leased-address";
983  goto astring;
984 
985  case expr_client_state:
986  s = "client-state";
987  goto astring;
988 
989  case expr_host_decl_name:
990  s = "host-decl-name";
991  goto astring;
992 
993  case expr_lease_time:
994  s = "lease-time";
995  goto astring;
996 
997  case expr_static:
998  s = "static";
999  goto astring;
1000 
1001  case expr_filename:
1002  s = "filename";
1003  goto astring;
1004 
1005  case expr_sname:
1006  s = "server-name";
1007  goto astring;
1008 
1009  case expr_reverse:
1010  if (len > 11) {
1011  rv = 13;
1012  strcpy (buf, "(reverse ");
1013  rv += print_subexpression (expr -> data.reverse.width,
1014  buf + rv, len - rv - 2);
1015  buf [rv++] = ' ';
1016  rv += print_subexpression (expr -> data.reverse.buffer,
1017  buf + rv, len - rv - 1);
1018  buf [rv++] = ')';
1019  buf [rv] = 0;
1020  return rv;
1021  }
1022  break;
1023 
1024  case expr_binary_to_ascii:
1025  if (len > 5) {
1026  rv = 9;
1027  strcpy (buf, "(b2a ");
1028  rv += print_subexpression (expr -> data.b2a.base,
1029  buf + rv, len - rv - 4);
1030  buf [rv++] = ' ';
1031  rv += print_subexpression (expr -> data.b2a.width,
1032  buf + rv, len - rv - 3);
1033  buf [rv++] = ' ';
1034  rv += print_subexpression (expr -> data.b2a.separator,
1035  buf + rv, len - rv - 2);
1036  buf [rv++] = ' ';
1037  rv += print_subexpression (expr -> data.b2a.buffer,
1038  buf + rv, len - rv - 1);
1039  buf [rv++] = ')';
1040  buf [rv] = 0;
1041  return rv;
1042  }
1043  break;
1044 
1045  case expr_dns_transaction:
1046  rv = 10;
1047  if (len < rv + 2) {
1048  buf [0] = '(';
1049  strcpy (&buf [1], "ns-update ");
1050  while (len < rv + 2) {
1051  rv += print_subexpression
1052  (expr -> data.dns_transaction.car,
1053  buf + rv, len - rv - 2);
1054  buf [rv++] = ' ';
1055  expr = expr -> data.dns_transaction.cdr;
1056  }
1057  buf [rv - 1] = ')';
1058  buf [rv] = 0;
1059  return rv;
1060  }
1061  return 0;
1062 
1063  case expr_ns_delete:
1064  s = "delete";
1065  left = 4;
1066  goto dodnsupd;
1067  case expr_ns_exists:
1068  s = "exists";
1069  left = 4;
1070  goto dodnsupd;
1071  case expr_ns_not_exists:
1072  s = "not_exists";
1073  left = 4;
1074  goto dodnsupd;
1075  case expr_ns_add:
1076  s = "update";
1077  left = 5;
1078  dodnsupd:
1079  rv = strlen (s);
1080  if (len > strlen (s) + 1) {
1081  buf [0] = '(';
1082  strcpy (buf + 1, s);
1083  rv++;
1084  buf [rv++] = ' ';
1085  s = print_dec_1 (expr -> data.ns_add.rrclass);
1086  if (len > rv + strlen (s) + left) {
1087  strcpy (&buf [rv], s);
1088  rv += strlen (&buf [rv]);
1089  }
1090  buf [rv++] = ' ';
1091  left--;
1092  s = print_dec_1 (expr -> data.ns_add.rrtype);
1093  if (len > rv + strlen (s) + left) {
1094  strcpy (&buf [rv], s);
1095  rv += strlen (&buf [rv]);
1096  }
1097  buf [rv++] = ' ';
1098  left--;
1099  rv += print_subexpression
1100  (expr -> data.ns_add.rrname,
1101  buf + rv, len - rv - left);
1102  buf [rv++] = ' ';
1103  left--;
1104  rv += print_subexpression
1105  (expr -> data.ns_add.rrdata,
1106  buf + rv, len - rv - left);
1107  buf [rv++] = ' ';
1108  left--;
1109  rv += print_subexpression
1110  (expr -> data.ns_add.ttl,
1111  buf + rv, len - rv - left);
1112  buf [rv++] = ')';
1113  buf [rv] = 0;
1114  return rv;
1115  }
1116  break;
1117 
1118  case expr_null:
1119  if (len > 6) {
1120  strcpy (buf, "(null)");
1121  return 6;
1122  }
1123  break;
1124  case expr_funcall:
1125  rv = 12 + strlen (expr -> data.funcall.name);
1126  if (len > rv + 1) {
1127  strcpy (buf, "(funcall ");
1128  strcpy (buf + 9, expr -> data.funcall.name);
1129  buf [rv++] = ' ';
1130  rv += print_subexpression
1131  (expr -> data.funcall.arglist, buf + rv,
1132  len - rv - 1);
1133  buf [rv++] = ')';
1134  buf [rv] = 0;
1135  return rv;
1136  }
1137  break;
1138 
1139  case expr_arg:
1140  rv = print_subexpression (expr -> data.arg.val, buf, len);
1141  if (expr -> data.arg.next && rv + 2 < len) {
1142  buf [rv++] = ' ';
1143  rv += print_subexpression (expr -> data.arg.next,
1144  buf, len);
1145  if (rv + 1 < len)
1146  buf [rv++] = 0;
1147  return rv;
1148  }
1149  break;
1150 
1151  case expr_function:
1152  rv = 9;
1153  if (len > rv + 1) {
1154  struct string_list *foo;
1155  strcpy (buf, "(function");
1156  for (foo = expr -> data.func -> args;
1157  foo; foo = foo -> next) {
1158  if (len > rv + 2 + strlen (foo -> string)) {
1159  buf [rv - 1] = ' ';
1160  strcpy (&buf [rv], foo -> string);
1161  rv += strlen (foo -> string);
1162  }
1163  }
1164  buf [rv++] = ')';
1165  buf [rv] = 0;
1166  return rv;
1167  }
1168  break;
1169 
1170  case expr_gethostname:
1171  if (len > 13) {
1172  strcpy(buf, "(gethostname)");
1173  return 13;
1174  }
1175  break;
1176 
1177  default:
1178  log_fatal("Impossible case at %s:%d (undefined expression "
1179  "%d).", MDL, expr->op);
1180  break;
1181  }
1182  return 0;
1183 }
1184 
1185 void print_expression (name, expr)
1186  const char *name;
1187  struct expression *expr;
1188 {
1189  char buf [1024];
1190 
1191  print_subexpression (expr, buf, sizeof buf);
1192  log_info ("%s: %s", name, buf);
1193 }
1194 
1195 int token_print_indent_concat (FILE *file, int col, int indent,
1196  const char *prefix,
1197  const char *suffix, ...)
1198 {
1199  va_list list;
1200  unsigned len;
1201  char *s, *t, *u;
1202 
1203  va_start (list, suffix);
1204  s = va_arg (list, char *);
1205  len = 0;
1206  while (s) {
1207  len += strlen (s);
1208  s = va_arg (list, char *);
1209  }
1210  va_end (list);
1211 
1212  t = dmalloc (len + 1, MDL);
1213  if (!t)
1214  log_fatal ("token_print_indent: no memory for copy buffer");
1215 
1216  va_start (list, suffix);
1217  s = va_arg (list, char *);
1218  u = t;
1219  while (s) {
1220  len = strlen (s);
1221  strcpy (u, s);
1222  u += len;
1223  s = va_arg (list, char *);
1224  }
1225  va_end (list);
1226 
1227  col = token_print_indent (file, col, indent,
1228  prefix, suffix, t);
1229  dfree (t, MDL);
1230  return col;
1231 }
1232 
1233 int token_indent_data_string (FILE *file, int col, int indent,
1234  const char *prefix, const char *suffix,
1235  struct data_string *data)
1236 {
1237  int i;
1238  char *buf;
1239  char obuf [3];
1240 
1241  /* See if this is just ASCII. */
1242  for (i = 0; i < data -> len; i++)
1243  if (!isascii (data -> data [i]) ||
1244  !isprint (data -> data [i]))
1245  break;
1246 
1247  /* If we have a purely ASCII string, output it as text. */
1248  if (i == data -> len) {
1249  buf = dmalloc (data -> len + 3, MDL);
1250  if (buf) {
1251  buf [0] = '"';
1252  memcpy (buf + 1, data -> data, data -> len);
1253  buf [data -> len + 1] = '"';
1254  buf [data -> len + 2] = 0;
1255  i = token_print_indent (file, col, indent,
1256  prefix, suffix, buf);
1257  dfree (buf, MDL);
1258  return i;
1259  }
1260  }
1261 
1262  for (i = 0; i < data -> len; i++) {
1263  sprintf (obuf, "%2.2x", data -> data [i]);
1264  col = token_print_indent (file, col, indent,
1265  i == 0 ? prefix : "",
1266  (i + 1 == data -> len
1267  ? suffix
1268  : ""), obuf);
1269  if (i + 1 != data -> len)
1270  col = token_print_indent (file, col, indent,
1271  prefix, suffix, ":");
1272  }
1273  return col;
1274 }
1275 
1276 int token_print_indent (FILE *file, int col, int indent,
1277  const char *prefix,
1278  const char *suffix, const char *buf)
1279 {
1280  int len = 0;
1281  if (prefix != NULL)
1282  len += strlen (prefix);
1283  if (buf != NULL)
1284  len += strlen (buf);
1285 
1286  if (col + len > 79) {
1287  if (indent + len < 79) {
1289  col = indent;
1290  } else {
1291  indent_spaces (file, col);
1292  col = len > 79 ? 0 : 79 - len - 1;
1293  }
1294  } else if (prefix && *prefix) {
1295  fputs (prefix, file);
1296  col += strlen (prefix);
1297  }
1298  if ((buf != NULL) && (*buf != 0)) {
1299  fputs (buf, file);
1300  col += strlen(buf);
1301  }
1302  if (suffix && *suffix) {
1303  if (col + strlen (suffix) > 79) {
1305  col = indent;
1306  } else {
1307  fputs (suffix, file);
1308  col += strlen (suffix);
1309  }
1310  }
1311  return col;
1312 }
1313 
1314 void indent_spaces (FILE *file, int indent)
1315 {
1316  int i;
1317  fputc ('\n', file);
1318  for (i = 0; i < indent; i++)
1319  fputc (' ', file);
1320 }
1321 
1322 /* Format the given time as "A; # B", where A is the format
1323  * used by the parser, and B is the local time, for humans.
1324  */
1325 const char *
1327 {
1328  static char buf[sizeof("epoch 9223372036854775807; "
1329  "# Wed Jun 30 21:49:08 2147483647")];
1330  static char buf1[sizeof("# Wed Jun 30 21:49:08 2147483647")];
1331  time_t since_epoch;
1332  /* The string: "6 2147483647/12/31 23:59:60;"
1333  * is smaller than the other, used to declare the buffer size, so
1334  * we can use one buffer for both.
1335  */
1336 
1337  if (t == MAX_TIME)
1338  return "never;";
1339 
1340  if (t < 0)
1341  return NULL;
1342 
1343  /* For those lucky enough to have a 128-bit time_t, ensure that
1344  * whatever (corrupt) value we're given doesn't exceed the static
1345  * buffer.
1346  */
1347 #if (MAX_TIME > 0x7fffffffffffffff)
1348  if (t > 0x7fffffffffffffff)
1349  return NULL;
1350 #endif
1351 
1353  since_epoch = mktime(localtime(&t));
1354  if ((strftime(buf1, sizeof(buf1),
1355  "# %a %b %d %H:%M:%S %Y",
1356  localtime(&t)) == 0) ||
1357  (snprintf(buf, sizeof(buf), "epoch %lu; %s",
1358  (unsigned long)since_epoch, buf1) >= sizeof(buf)))
1359  return NULL;
1360 
1361  } else {
1362  /* No bounds check for the year is necessary - in this case,
1363  * strftime() will run out of space and assert an error.
1364  */
1365  if (strftime(buf, sizeof(buf), "%w %Y/%m/%d %H:%M:%S;",
1366  gmtime(&t)) == 0)
1367  return NULL;
1368  }
1369 
1370  return buf;
1371 }
1372 
1373 /* !brief Return the given data as a string of hex digits "xx:xx:xx ..."
1374  *
1375  * Converts the given data into a null-terminated, string of hex digits,
1376  * stored in an allocated buffer. It is the caller's responsiblity to free
1377  * the buffer.
1378  *
1379  * \param s - pointer to the data to convert
1380  * \param len - length of the data to convert
1381  * \param file - source file of invocation
1382  * \param line - line number of invocation
1383  *
1384  * \return Returns an allocated buffer containing the hex string
1385 */
1386 char *buf_to_hex (const unsigned char *s, unsigned len,
1387  const char *file, int line)
1388 {
1389  unsigned nulen = 0;
1390  char *buf;
1391 
1392  /* If somebody hands us length of zero, we'll give them
1393  * back an empty string */
1394  if (!len) {
1395  buf = dmalloc (1, MDL);
1396  if (buf) {
1397  *buf = 0x0;
1398  }
1399 
1400  return (buf);
1401  }
1402 
1403 
1404  /* Figure out how big it needs to be. print_to_hex uses
1405  * "%02x:" per character. Note since there's no trailing colon
1406  * we'll have room for the null */
1407  nulen = (len * 3);
1408 
1409  /* Allocate our buffer */
1410  buf = dmalloc (nulen, MDL);
1411 
1412  /* Hex-ify it */
1413  if (buf) {
1414  print_hex_only (len, s, nulen, buf);
1415  }
1416 
1417  return buf;
1418 }
1419 
1420 /* !brief Formats data into a string based on a lease id format
1421  *
1422  * Takes the given data and returns an allocated string whose contents are
1423  * the string version of that data, formatted according to the output lease
1424  * id format. Note it is the caller's responsiblity to delete the string.
1425  *
1426  * Currently two formats are supported:
1427  *
1428  * OCTAL - Default or "legacy" CSL format enclosed in quotes '"'.
1429  *
1430  * HEX - Bytes represented as string colon seperated of hex digit pairs
1431  * (xx:xx:xx...)
1432  *
1433  * \param s - data to convert
1434  * \param len - length of the data to convert
1435  * \param format - desired format of the result
1436  * \param file - source file of invocation
1437  * \param line - line number of invocation
1438  *
1439  * \return A pointer to the allocated, null-terminated string
1440 */
1441 char *format_lease_id(const unsigned char *s, unsigned len,
1442  int format, const char *file, int line) {
1443  char *idstr = NULL;
1444 
1445  switch (format) {
1446  case TOKEN_HEX:
1447  idstr = buf_to_hex(s, len, MDL);
1448  break;
1449  case TOKEN_OCTAL:
1450  default:
1451  idstr = quotify_buf(s, len, '"', MDL);
1452  break;
1453  }
1454  return (idstr);
1455 }
1456 
1457 /*
1458  * Convert a relative path name to an absolute path name
1459  *
1460  * Not all versions of realpath() support NULL for
1461  * the second parameter and PATH_MAX isn't defined
1462  * on all systems. For the latter, we'll make what
1463  * ought to be a big enough buffer and let it fly.
1464  * If passed an absolute path it should return it
1465  * an allocated buffer.
1466  */
1467 char *absolute_path(const char *orgpath) {
1468  char *abspath = NULL;
1469  if (orgpath) {
1470 #ifdef PATH_MAX
1471  char buf[PATH_MAX];
1472 #else
1473  char buf[2048];
1474 #endif
1475  errno = 0;
1476  if (realpath(orgpath, buf) == NULL) {
1477  const char* errmsg = strerror(errno);
1478  log_fatal("Failed to get realpath for %s: %s",
1479  orgpath, errmsg);
1480  }
1481 
1482  /* dup the result into an allocated buffer */
1483  abspath = dmalloc(strlen(buf) + 1, MDL);
1484  if (abspath == NULL) {
1485  log_fatal("No memory for filename:%s\n",
1486  buf);
1487  }
1488 
1489  memcpy (abspath, buf, strlen(buf));
1490  abspath[strlen(buf)] = 0x0;
1491  }
1492 
1493  return (abspath);
1494 }
void data_string_forget(struct data_string *data, const char *file, int line)
Definition: alloc.c:1339
const char * pretty_print_option(struct option *option, const unsigned char *data, unsigned len, int emit_commas, int emit_quotes)
Definition: options.c:1793
void option_space_foreach(struct packet *packet, struct lease *lease, struct client_state *client_state, struct option_state *in_options, struct option_state *cfg_options, struct binding_scope **scope, struct universe *u, void *stuff, void(*func)(struct option_cache *, struct packet *, struct lease *, struct client_state *, struct option_state *, struct option_state *, struct binding_scope **, struct universe *, void *))
Definition: options.c:3789
char * quotify_buf(const unsigned char *s, unsigned len, char enclose_char, const char *file, int line)
Definition: print.c:71
int token_indent_data_string(FILE *file, int col, int indent, const char *prefix, const char *suffix, struct data_string *data)
Definition: print.c:1233
int token_print_indent_concat(FILE *file, int col, int indent, const char *prefix, const char *suffix,...)
Definition: print.c:1195
void print_expression(char *name, struct expression *expr) const
Definition: print.c:1185
char * quotify_string(const char *s, const char *file, int line)
Definition: print.c:33
char * print_dec_2(unsigned long val)
Definition: print.c:546
const char * print_time(TIME t)
Definition: print.c:1326
char * print_dec_1(unsigned long val)
Definition: print.c:538
char * print_hw_addr(int htype, int hlen, const unsigned char *data) const
Definition: print.c:171
#define DQLEN
Definition: print.c:505
void indent_spaces(FILE *file, int indent)
Definition: print.c:1314
void hash_dump(struct hash_table *table)
Definition: print.c:358
char * format_lease_id(const unsigned char *s, unsigned len, int format, const char *file, int line)
Definition: print.c:1441
char * print_hex(unsigned len, const u_int8_t *data, unsigned limit, unsigned buf_num)
Definition: print.c:470
void print_lease(struct lease *lease)
Definition: print.c:208
void print_hex_or_string(unsigned len, const u_int8_t *data, unsigned limit, char *buf)
Definition: print.c:433
#define HBLEN
Definition: print.c:469
char * print_dotted_quads(unsigned len, const u_int8_t *data)
Definition: print.c:507
char * buf_to_hex(const unsigned char *s, unsigned len, const char *file, int line)
Definition: print.c:1386
char * absolute_path(const char *orgpath)
Definition: print.c:1467
int token_print_indent(FILE *file, int col, int indent, const char *prefix, const char *suffix, const char *buf)
Definition: print.c:1276
int db_time_format
Definition: print.c:31
void print_hex_only(unsigned len, const u_int8_t *data, unsigned limit, char *buf)
Definition: print.c:394
void dump_raw(unsigned char *buf, unsigned len) const
Definition: print.c:307
char * print_base64(const unsigned char *buf, unsigned len, const char *file, int line)
Definition: print.c:121
struct in_addr giaddr
Definition: dhclient.c:77
#define DEFAULT_TIME_FORMAT
Definition: dhcpd.h:2614
time_t TIME
Definition: dhcpd.h:85
void indent(int)
void dump_packet_option(struct option_cache *, struct packet *, struct lease *, struct client_state *, struct option_state *, struct option_state *, struct binding_scope **, struct universe *, void *)
void dump_packet(struct packet *)
#define MAX_TIME
Definition: dhcpd.h:1626
#define LOCAL_TIME_FORMAT
Definition: dhcpd.h:2615
struct universe dhcp_universe
const char int line
Definition: dhcpd.h:3793
const char * file
Definition: dhcpd.h:3793
#define print_hex_1(len, data, limit)
Definition: dhcpd.h:2633
@ TOKEN_OCTAL
Definition: dhctoken.h:378
@ TOKEN_HEX
Definition: dhctoken.h:377
struct iaddr ip_addr(struct iaddr subnet, struct iaddr mask, u_int32_t host_address)
Definition: inet.c:63
const char * piaddr(const struct iaddr addr)
Definition: inet.c:579
#define MDL
Definition: omapip.h:567
void * dmalloc(size_t, const char *, int)
Definition: alloc.c:57
void dfree(void *, const char *, int)
Definition: alloc.c:145
int log_error(const char *,...) __attribute__((__format__(__printf__
int int int log_debug(const char *,...) __attribute__((__format__(__printf__
void log_fatal(const char *,...) __attribute__((__format__(__printf__
int int log_info(const char *,...) __attribute__((__format__(__printf__
const unsigned char * data
Definition: tree.h:78
unsigned len
Definition: tree.h:79
struct in_addr siaddr
Definition: dhcp.h:57
u_int16_t flags
Definition: dhcp.h:54
u_int32_t xid
Definition: dhcp.h:52
struct in_addr ciaddr
Definition: dhcp.h:55
unsigned char options[DHCP_MAX_OPTION_LEN]
Definition: dhcp.h:62
u_int8_t op
Definition: dhcp.h:48
u_int8_t htype
Definition: dhcp.h:49
struct in_addr yiaddr
Definition: dhcp.h:56
u_int16_t secs
Definition: dhcp.h:53
u_int8_t hlen
Definition: dhcp.h:50
unsigned char chaddr[16]
Definition: dhcp.h:59
char sname[DHCP_SNAME_LEN]
Definition: dhcp.h:60
u_int8_t hops
Definition: dhcp.h:51
union expression::expr_union data
enum expr_op op
Definition: tree.h:199
unsigned len
Definition: hash.h:53
struct hash_bucket * next
Definition: hash.h:51
const unsigned char * name
Definition: hash.h:52
Definition: dhcpd.h:560
Definition: tree.h:345
Definition: dhcpd.h:405
struct string_list * next
Definition: dhcpd.h:348
Definition: tree.h:301
int universe_count
Definition: tables.c:973
struct universe ** universes
Definition: tables.c:972
int evaluate_option_cache(struct data_string *result, struct packet *packet, struct lease *lease, struct client_state *client_state, struct option_state *in_options, struct option_state *cfg_options, struct binding_scope **scope, struct option_cache *oc, const char *file, int line)
Definition: tree.c:2699
struct binding_scope * global_scope
Definition: tree.c:38
@ expr_ucase
Definition: tree.h:188
@ expr_funcall
Definition: tree.h:177
@ expr_gethostname
Definition: tree.h:192
@ expr_extract_int8
Definition: tree.h:147
@ expr_ns_not_exists
Definition: tree.h:169
@ expr_host_lookup
Definition: tree.h:139
@ expr_option
Definition: tree.h:143
@ expr_encode_int32
Definition: tree.h:152
@ expr_static
Definition: tree.h:165
@ expr_binary_and
Definition: tree.h:184
@ expr_encode_int16
Definition: tree.h:151
@ expr_regex_match
Definition: tree.h:190
@ expr_equal
Definition: tree.h:135
@ expr_check
Definition: tree.h:134
@ expr_none
Definition: tree.h:132
@ expr_lease_time
Definition: tree.h:163
@ expr_extract_int16
Definition: tree.h:148
@ expr_filename
Definition: tree.h:174
@ expr_binary_or
Definition: tree.h:185
@ expr_pick_first_value
Definition: tree.h:162
@ expr_encapsulate
Definition: tree.h:155
@ expr_ns_add
Definition: tree.h:166
@ expr_remainder
Definition: tree.h:183
@ expr_config_option
Definition: tree.h:160
@ expr_not
Definition: tree.h:142
@ expr_add
Definition: tree.h:179
@ expr_const_int
Definition: tree.h:153
@ expr_sname
Definition: tree.h:175
@ expr_divide
Definition: tree.h:182
@ expr_hardware
Definition: tree.h:144
@ expr_concat
Definition: tree.h:138
@ expr_or
Definition: tree.h:141
@ expr_and
Definition: tree.h:140
@ expr_null
Definition: tree.h:171
@ expr_dns_transaction
Definition: tree.h:164
@ expr_host_decl_name
Definition: tree.h:161
@ expr_known
Definition: tree.h:156
@ expr_leased_address
Definition: tree.h:158
@ expr_lcase
Definition: tree.h:189
@ expr_exists
Definition: tree.h:154
@ expr_const_data
Definition: tree.h:146
@ expr_binary_to_ascii
Definition: tree.h:159
@ expr_ns_delete
Definition: tree.h:167
@ expr_extract_int32
Definition: tree.h:149
@ expr_substring
Definition: tree.h:136
@ expr_multiply
Definition: tree.h:181
@ expr_suffix
Definition: tree.h:137
@ expr_function
Definition: tree.h:178
@ expr_packet
Definition: tree.h:145
@ expr_encode_int8
Definition: tree.h:150
@ expr_variable_exists
Definition: tree.h:172
@ expr_match
Definition: tree.h:133
@ expr_subtract
Definition: tree.h:180
@ expr_binary_xor
Definition: tree.h:186
@ expr_arg
Definition: tree.h:176
@ expr_not_equal
Definition: tree.h:170
@ expr_client_state
Definition: tree.h:187
@ expr_reverse
Definition: tree.h:157
@ expr_variable_reference
Definition: tree.h:173
@ expr_ns_exists
Definition: tree.h:168
unsigned rrclass
Definition: tree.h:255
struct expression * cdr
Definition: tree.h:248
unsigned long const_int
Definition: tree.h:231
struct expression * rrname
Definition: tree.h:257
struct dns_host_entry * host_lookup
Definition: tree.h:233
struct expression::expr_union::@22 dns_transaction
struct expression * next
Definition: tree.h:270
struct expression * not
Definition: tree.h:209
struct expression * extract_int
Definition: tree.h:229
struct expression * ucase
Definition: tree.h:221
struct expression::expr_union::@25 arg
struct expression * rrdata
Definition: tree.h:258
struct collection * check
Definition: tree.h:215
struct expression * arglist
Definition: tree.h:274
struct expression * len
Definition: tree.h:204
struct expression::expr_union::@19 b2a
struct expression * encode_int
Definition: tree.h:230
struct expression * val
Definition: tree.h:269
struct expression::expr_union::@20 reverse
struct data_string encapsulate
Definition: tree.h:235
struct expression * and[2]
Definition: tree.h:207
struct expression * separator
Definition: tree.h:239
struct expression * expr
Definition: tree.h:202
struct expression * ttl
Definition: tree.h:259
struct option * option
Definition: tree.h:222
struct expression::expr_union::@17 suffix
struct expression * base
Definition: tree.h:237
unsigned rrtype
Definition: tree.h:256
struct expression::expr_union::@16 substring
struct expression * lcase
Definition: tree.h:220
struct expression::expr_union::@18 packet
struct expression::expr_union::@21 pick_first_value
struct data_string const_data
Definition: tree.h:228
struct expression::expr_union::@23 ns_add
struct expression * offset
Definition: tree.h:203
struct expression * width
Definition: tree.h:238
struct expression * buffer
Definition: tree.h:240
struct expression * concat[2]
Definition: tree.h:232
struct expression * car
Definition: tree.h:247
struct expression * equal[2]
Definition: tree.h:206
struct expression::expr_union::@26 funcall