29 #define DHCP_OPTION_DATA 36 static int pretty_text(
char **,
char *,
const unsigned char **,
37 const unsigned char *,
int);
38 static int pretty_domain(
char **,
char *,
const unsigned char **,
39 const unsigned char *);
41 unsigned char *
buffer,
unsigned length,
42 unsigned code,
int terminatep,
54 packet -> options_valid = 0;
61 &
packet -> raw -> options [4],
104 (
unsigned char *)
packet -> raw -> sname,
105 sizeof packet -> raw -> sname,
110 packet -> options_valid = 1;
119 const unsigned char *
buffer;
123 unsigned len, offset;
128 char *reason =
"general failure";
131 log_error (
"no memory for option buffer.");
134 memcpy (bp -> data,
buffer, length);
147 reason =
"code tag at end of buffer - missing " 164 log_fatal(
"Improperly configured option space(%s): " 165 "may not have a nonzero length size " 166 "AND a NULL get_length function.",
179 if (offset + len > length) {
182 reason =
"option length exceeds option buffer length";
184 log_error(
"parse_option_buffer: malformed option " 200 bp->
data + offset, len,
206 memset(&
new, 0,
sizeof new);
222 new.data =
new.buffer->data;
227 }
else if (op != NULL) {
231 while (op->
next != NULL)
243 nop->data.buffer = NULL;
245 nop->data.data = bp->
data + offset;
255 "save_option_buffer failed");
280 s = strchr (eopt -> format,
'E');
282 log_error (
"internal encapsulation format error 1.");
286 t = strchr (++s,
'.');
290 log_error (
"internal encapsulation format error 2.");
293 if (t == s && uname) {
304 s, (
unsigned)(t - s))) {
320 const unsigned char *
buffer,
341 if (eopt -> format [0] !=
'E')
348 const unsigned char *
buffer,
349 unsigned length,
struct universe *u)
359 log_error (
"no memory for option buffer.");
362 memcpy (&bp ->
data [3],
buffer + 1, length - 1);
391 if (!bp ->
data [0]) {
395 if (
buffer [length - 1] == 0) {
403 for (i = 3; i < length &&
buffer [i] !=
'.'; i++);
414 if (length > 4 + i &&
416 &bp ->
data[6 + i], length - 4 - i,
422 &bp ->
data [5], length - 3,
428 unsigned total_len = 0;
429 unsigned first_len = 0;
435 while (s < &bp ->
data[0] + length + 2) {
438 log_info (
"fancy bits in fqdn option");
445 if (s + len > &bp ->
data [0] + length + 3) {
446 log_info (
"fqdn tag longer than buffer");
450 if (first_len == 0) {
456 total_len += len + 1;
467 first_len = total_len;
472 &bp ->
data[6], first_len,
475 if (total_len > 0 && first_len != total_len) {
477 &bp->
data[6 + first_len],
478 total_len - first_len,
484 &bp ->
data [6], total_len,
524 int overload_avail,
int terminate,
int bootpp,
527 #define PRIORITY_COUNT 300 530 unsigned char buffer[4096], agentopts[1024];
532 unsigned mb_size = 0, mb_max = 0;
533 unsigned option_size = 0, agent_size = 0;
539 int overload_used = 0;
540 int of1 = 0, of2 = 0;
542 memset(&ds, 0,
sizeof ds);
556 cfg_options, scope, op,
MDL) != 0)) {
557 if (ds.
len >= sizeof (u_int16_t)) {
559 if(!mms || (i < mms))
591 if (inpacket != NULL &&
609 in_options, cfg_options, scope,
610 priority_list, priority_len,
613 mb_size += agent_size;
622 if (mb_size > agent_size)
623 mb_max = mb_size - agent_size;
627 if (overload_avail & 1) {
632 if (overload_avail & 2) {
653 if (prl != NULL && prl->
len > 0) {
657 priority_list[priority_len++] =
666 priority_list[priority_len++] =
676 for (i = 0; i < prl->
len; i++) {
682 priority_list[priority_len++] = prl->
data[i];
694 priority_list[priority_len++] =
DHO_FQDN;
725 priority_list[priority_len++] =
DHO_FQDN;
740 for (pp = hash[i]; pp; pp = pp->cdr) {
746 priority_list[priority_len++] =
761 for (pp = hash[i]; pp; pp = pp->cdr) {
767 priority_list[priority_len++] =
782 priority_list[priority_len++] =
792 priority_list[priority_len++] =
803 in_options, cfg_options, scope,
804 priority_list, priority_len,
805 of1, of2, terminate, vuname);
808 if (option_size == 0)
812 index += option_size;
819 if (mb_size - agent_size - index < 3)
824 buffer[index++] = overload_used;
826 if (overload_used & 1)
829 if (overload_used & 2)
835 if (mb_size - index >= agent_size) {
836 memcpy(&
buffer[index], agentopts, agent_size);
839 log_error(
"Unable to store relay agent information " 873 struct lease *dummy_lease,
879 void *void_vsio_state) {
884 memset(&ds, 0,
sizeof(ds));
886 NULL, opt_state, NULL,
915 log_debug(
"No space for option %d in VSIO space %s.",
920 log_error(
"Error evaluating option %d in VSIO space %s.",
943 add_option6_data(
char *buf,
int buflen,
int* bufpos, uint16_t code,
945 if ((ds->
len + 4) > (buflen - *bufpos)) {
946 log_debug(
"No space for option %d", code);
948 unsigned char* tmp = (
unsigned char *)buf + *bufpos;
954 memcpy(tmp+4, ds->
data, ds->
len);
956 *bufpos += 4 + ds->
len;
987 store_encap6 (
char *buf,
int buflen,
int* bufpos,
989 struct option* encap_opt, uint16_t code) {
995 char* s = (
char*)encap_opt->
format;
997 if ((s == NULL) || (*s !=
'E') || (strlen(s) <= 2)) {
1001 t = strchr(++s,
'.');
1002 if ((t == NULL) || (t == s)) {
1006 memset(&ds, 0,
sizeof(ds));
1007 memset(&name, 0,
sizeof(name));
1008 name.data = (
unsigned char *)s;
1016 add_option6_data(buf, buflen, bufpos, code, &ds);
1032 const int *required_opts,
1041 int in_required_opts;
1042 int vsio_option_code;
1053 vsio_option_code = 0;
1057 vsio_option_code = o->
code;
1062 if (vsio_option_code == 0) {
1063 log_fatal(
"No VSIO option code found.");
1066 if (required_opts != NULL) {
1067 for (i=0; required_opts[i] != 0; i++) {
1068 if (required_opts[i] == vsio_option_code) {
1073 opt_state, required_opts[i]);
1077 memset(&ds, 0,
sizeof(ds));
1078 for (; oc != NULL ; oc = oc->
next) {
1084 (uint16_t)required_opts[i], &ds);
1097 oro_size = oro->
len / 2;
1099 for (i=0; i<oro_size; i++) {
1100 memcpy(&code, oro->
data+(i*2), 2);
1107 in_required_opts = 0;
1108 if (required_opts != NULL) {
1109 for (j=0; required_opts[j] != 0; j++) {
1110 if (required_opts[j] == code) {
1111 in_required_opts = 1;
1116 if (in_required_opts) {
1123 if (code == vsio_option_code) {
1132 memset(&ds, 0,
sizeof(ds));
1135 for (; oc != NULL ; oc = oc->
next) {
1137 NULL, opt_state, NULL,
1153 struct option *encap_opt = NULL;
1154 unsigned int code_int =
code;
1156 option_code_hash_lookup(&encap_opt,
1159 if (encap_opt != NULL) {
1160 store_encap6(buf, buflen, &bufpos, opt_state,
1191 if (vs.bufpos > bufpos+8) {
1192 tmp = (
unsigned char *)buf +
1197 vs.bufpos-bufpos-4);
1216 unsigned char *
buffer,
unsigned index,
unsigned buflen,
1222 unsigned *priority_list,
int priority_len,
1223 unsigned first_cutoff,
int second_cutoff,
int terminate,
1226 int bufix = 0, six = 0, tix = 0;
1230 int bufend, sbufend;
1244 first_cutoff -= index;
1246 second_cutoff -= index;
1249 bufend = sbufend = buflen;
1251 if (first_cutoff >= buflen)
1252 log_fatal(
"%s:%d:store_options: Invalid first cutoff.",
MDL);
1253 bufend = first_cutoff;
1255 if (second_cutoff) {
1256 if (second_cutoff >= buflen)
1257 log_fatal(
"%s:%d:store_options: Invalid second cutoff.",
1259 sbufend = second_cutoff;
1261 }
else if (second_cutoff) {
1262 if (second_cutoff >= buflen)
1263 log_fatal(
"%s:%d:store_options: Invalid second cutoff.",
MDL);
1264 bufend = second_cutoff;
1267 memset (&od, 0,
sizeof od);
1272 for (i = 0; i < priority_len; i++) {
1275 for (ix = i + 1; ix < priority_len + tto; ix++) {
1277 priority_list [ix - tto] =
1279 if (priority_list [i] == priority_list [ix]) {
1297 for (ix = i - 1 ; ix >= 0 ; ix--) {
1310 for (i = 0; i < priority_len; i++) {
1314 int optstart, soptstart, toptstart;
1316 int have_encapsulation = 0;
1320 memset (&encapsulation, 0,
sizeof encapsulation);
1321 have_encapsulation = 0;
1327 code = priority_list [i];
1331 if (code >= cfg_options -> site_code_min)
1332 u =
universes [cfg_options -> site_universe];
1360 t = strchr (++s,
'.');
1362 memset (&name, 0,
sizeof name);
1378 }
else if (vuname) {
1379 name.
data = (
unsigned char *)s;
1380 name.
len = strlen (s);
1383 name.
data = (
unsigned char *)s;
1390 have_encapsulation =
1393 in_options, cfg_options, scope, &name));
1408 if (!oc && !have_encapsulation) {
1418 cfg_options, scope, oc,
MDL);
1437 if (have_encapsulation) {
1438 length += encapsulation.
len;
1493 unsigned incr = length;
1495 unsigned char *base;
1499 ((!six && !tix && (i == priority_len - 1) &&
1500 (bufix + 2 + length < bufend)) ||
1501 (bufix + 5 + length < bufend))) {
1505 }
else if (!splitup && first_cutoff &&
1506 (first_cutoff + six + 3 + length < sbufend)) {
1507 base = &
buffer[first_cutoff];
1510 }
else if (!splitup && second_cutoff &&
1511 (second_cutoff + tix + 3 + length < buflen)) {
1512 base = &
buffer[second_cutoff];
1519 if (bufix + 6 < bufend) {
1520 incr = bufend - bufix - 5;
1524 }
else if (first_cutoff &&
1525 (first_cutoff + six + 4 < sbufend)) {
1526 incr = sbufend - (first_cutoff + six) - 3;
1527 base = &
buffer[first_cutoff];
1530 }
else if (second_cutoff &&
1531 (second_cutoff + tix + 4 < buflen)) {
1532 incr = buflen - (second_cutoff + tix) - 3;
1533 base = &
buffer[second_cutoff];
1551 base [*pix + 1] = (
unsigned char)incr;
1552 if (tto && incr == length) {
1554 memcpy (base + *pix + 2,
1555 od.
data + ix, (
unsigned)(incr - 1));
1556 base [*pix + 2 + incr - 1] = 0;
1558 memcpy (base + *pix + 2,
1559 od.
data + ix, (
unsigned)incr);
1572 if (first_cutoff && six) {
1573 if ((first_cutoff + six + 1) < sbufend)
1575 sbufend - (first_cutoff + six + 1));
1576 else if (first_cutoff + six >= sbufend)
1577 log_fatal(
"Second buffer overflow in overloaded options.");
1584 if (second_cutoff && tix) {
1585 if (second_cutoff + tix + 1 < buflen) {
1587 buflen - (second_cutoff + tix + 1));
1588 }
else if (second_cutoff + tix >= buflen)
1589 log_fatal(
"Third buffer overflow in overloaded options.");
1596 if ((six || tix) && (bufix + 3 > bufend))
1597 log_fatal(
"Not enough space for option overload option.");
1613 while (*p !=
'\0') {
1637 log_error(
"format_has_text(%s): 'c' atoms are illegal " 1638 "except after 'D' atoms.", format);
1650 while ((*p !=
'\0') && (*p++ !=
'.'))
1673 const char *p, *name;
1679 while (*p !=
'\0') {
1705 log_fatal(
"Corrupt format: %s", format);
1708 if (espace == NULL) {
1709 log_error(
"Unknown enumeration: %s", format);
1714 min_len += espace->
width;
1715 last_size = espace->
width;
1729 min_len -= last_size;
1750 log_error(
"format_min_length(%s): 'c' atom is illegal " 1751 "except after 'D' atom.", format);
1756 log_error(
"format_min_length(%s): No safe value " 1757 "for unknown format symbols.", format);
1768 #define MAX_OUTPUT_SIZE 32*1024 1771 const unsigned char *data;
1786 char fmtbuf[32] =
"";
1790 const unsigned char *dp = data;
1793 isc_boolean_t a_array = ISC_FALSE;
1795 unsigned int octets = 0;
1802 memset (enumbuf, 0,
sizeof enumbuf);
1806 for (l = i = 0;
option -> format [i]; i++, l++) {
1807 if (l >=
sizeof(fmtbuf) - 1)
1808 log_fatal(
"Bounds failure on internal buffer at " 1812 log_error (
"%s: Extra codes in format string: %s",
1814 &(
option -> format [i]));
1818 fmtbuf [l] =
option -> format [i];
1819 switch (
option -> format [i]) {
1830 while (
option -> format [i] &&
1831 option -> format [i] !=
'.')
1835 for (k = 0; k < len; k++) {
1836 if (!isascii (data [k]) ||
1837 !isprint (data [k]))
1843 if (k == len || (k + 1 == len && data [k] == 0)) {
1858 log_error(
"'c' atom not following D atom in format " 1881 while (
option -> format [i] &&
1882 option -> format [i] !=
'.')
1887 if (enumbuf[l] == NULL) {
1891 hunksize += enumbuf[l]->
width;
1892 hunkinc = enumbuf[l]->
width;
1925 log_error (
"%s: garbage in format string: %s",
1927 &(
option -> format [i]));
1933 if (hunksize - opthunk > len) {
1934 log_error (
"%s: expecting at least %d bytes; got %d",
1940 if (numhunk == -1 && hunksize < len)
1947 if (a_array == ISC_TRUE) {
1959 log_error (
"%s: invalid 'a' format: %s",
1964 numhunk = ((len - hunksize) / hunkinc) + 1;
1965 len_used = hunksize + ((numhunk - 1) * hunkinc);
1974 if (hunksize == 0) {
1975 log_error (
"%s: invalid 'A' format: %s",
1980 numhunk = len / hunksize;
1981 len_used = numhunk * hunksize;
1985 if (len_used < len) {
1986 log_error (
"%s: %d extra bytes at end of array\n",
2009 fmtbuf[0]=
'R'; fmtbuf[1]=
'I'; fmtbuf[2]=0;
2010 for (i =0; i < len; i = i + octets + 5) {
2012 log_error (
"wrong subnet mask width in destination descriptor");
2016 octets = ((data[i]+7) / 8);
2019 log_error (
"classless static routes option has wrong size or " 2020 "there's some garbage in format");
2025 for (i = 0; i < numhunk; i++) {
2026 if ((a_array == ISC_TRUE) && (i != 0) && (numelem > 0)) {
2043 for (; j < numelem; j++) {
2044 switch (fmtbuf [j]) {
2047 k = pretty_text(&op, endbuf - 1, &dp,
2048 data + len, emit_quotes);
2056 for( ; dp < (data + len) ; dp += k) {
2058 const unsigned char *nbp, *nend;
2060 nend = &nbuff[
sizeof(nbuff)];
2070 if (op + 2 > endbuf)
2099 pretty_domain(&op, endbuf-1,
2139 switch (enumbuf[j]->
width) {
2155 return "<double impossible condition>";
2161 if (enumbuf [j] ->
values [i].value ==
2166 dp += enumbuf[j]->
width;
2170 sprintf(op,
"%lu", tval);
2184 log_error (
"wrong subnet mask width in destination descriptor");
2200 sprintf (op,
"%ld", (
long)
getLong (dp));
2206 sprintf (op,
"%s",
"infinite");
2208 sprintf(op,
"%lu", tval);
2216 sprintf (op,
"%d", (
int)
getShort (dp));
2220 sprintf(op,
"%u", (
unsigned)
getUShort(dp));
2224 sprintf (op,
"%d", *(
const char *)dp++);
2227 sprintf (op,
"%d", *dp++);
2231 sprintf (op,
"%x", *dp++);
2234 strcpy (op, *dp++ ?
"true" :
"false");
2237 strcpy (op,
"true");
2255 if (dp == data + len)
2257 if (j + 1 < numelem && comma !=
':')
2260 if (i + 1 < numhunk) {
2263 if (dp == data + len)
2270 in_options, cfg_options, options, scope, code,
file,
line)
2292 in_options, cfg_options, scope, oc,
2305 in_options, cfg_options, options, scope, code,
file,
line)
2333 memset(&d1, 0,
sizeof(d1));
2335 in_options, cfg_options, scope, oc,
2341 *result = d1.
data[0];
2353 enum statement_op op;
2360 case eval_statement:
2361 case break_statement:
2363 log_error (
"bogus statement type in set_option.");
2366 case default_option_statement:
2374 case supersede_option_statement:
2375 case send_option_statement:
2380 case append_option_statement:
2381 case prepend_option_statement:
2391 log_error (
"Can't allocate const expression.");
2403 if (op == append_option_statement) {
2424 switch (((memcmp(
option->option->
format,
"Dc", 2) == 0) +
2430 log_error (
"Both options must be Dc format");
2459 log_error (
"can't look up options in %s space.",
2481 for (bptr = hash [hashix]; bptr; bptr = bptr -> cdr) {
2492 struct buffer *bp,
unsigned char *
buffer,
unsigned length,
2493 unsigned code,
int terminatep)
2498 status = prepare_option_buffer(
universe, bp,
buffer, length, code,
2516 struct buffer *bp,
unsigned char *
buffer,
unsigned length,
2517 unsigned code,
int terminatep)
2522 status = prepare_option_buffer(
universe, bp,
buffer, length, code,
2540 unsigned char *
buffer,
unsigned length,
unsigned code,
2543 struct buffer *lbp = NULL;
2559 if (code > 0xffffffff)
2564 log_fatal(
"Inconsistent universe tag size at %s:%d.",
MDL);
2577 char nbuf[
sizeof(
"unknown-4294967295")];
2579 sprintf(nbuf,
"unknown-%u", code);
2595 log_error(
"No memory for option code %s.%s.",
2610 log_error (
"no memory for option buffer.");
2615 memcpy (lbp ->
data,
buffer, length + terminatep);
2626 op ->
data.len = length;
2635 op ->
data.terminated = 1;
2637 op ->
data.terminated = 0;
2647 while ((op->
data.
len > min_len) &&
2665 struct packet *dummy_packet,
2666 struct lease *dummy_lease,
2672 void *void_accumulator) {
2673 int *accumulator = (
int *)void_accumulator;
2680 struct packet *dummy_packet,
2681 struct lease *dummy_lease,
2730 memset(server_oro, 0,
sizeof(*server_oro));
2732 log_fatal(
"no memory to build server ORO");
2740 server_oro->
len = 0;
2750 tmp = server_oro->buffer->data;
2753 server_oro->len += 2;
2811 for (bptr = hash [hashix]; bptr; bptr = bptr -> cdr) {
2813 (bptr -> car)) ->
option -> code ==
2829 ocloc = &(*ocloc)->
next;
2830 }
while (*ocloc != NULL);
2843 log_error (
"No memory for option_cache reference.");
2846 bptr -> cdr = hash [hashix];
2849 hash [hashix] = bptr;
2860 log_error (
"can't delete options from %s space.",
2879 for (bptr = hash [hashix]; bptr; bptr = bptr -> cdr) {
2888 prev -> cdr = bptr -> cdr;
2890 hash [hashix] = bptr -> cdr;
2904 if (!ptr || !*ptr) {
2905 log_error (
"Null pointer in option_cache_dereference: %s(%d)",
2907 #if defined (POINTER_DEBUG) 2932 if ((*ptr) ->
refcnt < 0) {
2934 #if defined (DEBUG_RC_HISTORY) 2935 dump_rc_history (*ptr);
2937 #if defined (POINTER_DEBUG) 2967 for (cp = heads [i]; cp; cp = next) {
2995 memset(&tmp, 0,
sizeof(tmp));
3048 memset(&tmp, 0,
sizeof(tmp));
3051 in_options, cfg_options, scope, oc,
MDL)) {
3065 end = strchr(++start,
'.');
3070 if (
end == NULL || start ==
end)
3074 start,
end - start,
MDL);
3078 "refers to unknown " 3079 "option space '%.*s'.",
3081 (
int)(
end - start), start);
3093 cfg_options, scope, subu);
3096 }
while (ISC_FALSE);
3108 in_options, cfg_options, scope,
name)
3124 log_error(
"option_space_encapsulate: option space '%.*s' does " 3125 "not exist, but is configured.",
3132 in_options, cfg_options, scope, u))
3135 log_error(
"encapsulation requested for '%s' with no support.",
3168 memset(&sub, 0,
sizeof(sub));
3182 in_options, cfg_options,
3196 in_options, cfg_options, scope,
universe)
3223 for (p = hash [i]; p; p = p -> cdr) {
3232 in_options, cfg_options, scope,
universe))
3239 in_options, cfg_options, scope,
universe)
3263 for (ocp = head ->
first; ocp; ocp = ocp -> cdr) {
3276 static unsigned char nni [] = { 1, 0 };
3278 memset (&ds, 0,
sizeof ds);
3283 if (!option_code_hash_lookup(&no_nwip->
option,
3286 log_fatal(
"Nwip option hash does not contain " 3292 cfg_options, scope, no_nwip))
3296 memset (&ds, 0,
sizeof ds);
3305 ds.
buffer -> data [0] = 2;
3306 ds.
buffer -> data [1] = 0;
3307 memcpy (&ds.
buffer -> data [2], result -> data, result -> len);
3323 fqdn_encode(
unsigned char *dst,
int dstlen,
const unsigned char *src,
3327 int i, j, len, outlen=0;
3330 for (i = 0, j = 0 ; i < srclen ; i = j) {
3331 while ((j < srclen) && (src[j] !=
'.') && (src[j] !=
'\0'))
3335 if ((outlen + 1 + len) > dstlen)
3345 memcpy(out, src + i, len);
3353 if ((outlen + 1) > dstlen)
3364 in_options, cfg_options, scope,
universe)
3391 memset (results, 0,
sizeof results);
3392 for (ocp = head ->
first; ocp; ocp = ocp -> cdr) {
3399 in_options, cfg_options, scope,
3411 log_error (
"no memory for option buffer.");
3419 memset (&bp ->
data [0], 0, len);
3433 bp ->
data [0] |= 2;
3436 bp ->
data [0] |= 1;
3446 i = fqdn_encode(&bp->
data[3], len - 3,
3463 result -> terminated = 0;
3468 if (results [i].len)
3549 unsigned char *
data;
3550 int i, len, rval = 0, count;
3560 memset(results, 0,
sizeof(results));
3561 for (ocp = head->
first ; ocp != NULL ; ocp = ocp->
cdr) {
3568 cfg_options, scope, oc,
MDL);
3578 log_error(
"No memory for virtual option buffer.");
3611 count = fqdn_encode(
data + 1, len - 1,
3620 result->
len += count;
3639 const unsigned char *
buffer,
unsigned length,
3642 struct buffer *bp = NULL;
3643 unsigned char *first_dot;
3644 int len, hlen, dlen;
3659 unsigned bp_size = 3 + (length * 4);
3662 log_error(
"No memory for dhcp6.fqdn option buffer.");
3694 log_error(
"Unable to convert dhcp6.fqdn domain name to " 3701 unsigned char *fqdn_start = bp->
data + 3;
3707 first_dot = (
unsigned char *)strchr((
char *)fqdn_start,
'.');
3709 if (first_dot != NULL) {
3710 hlen = first_dot - fqdn_start;
3753 cfg_options, scope, u, stuff, func);
3776 in_options, cfg_options,
3799 if (cfg_options -> universe_count <= u -> index)
3802 hash = cfg_options ->
universes [u -> index];
3808 for (p = hash [i]; p; p = p -> cdr) {
3811 in_options, cfg_options, scope, u, stuff);
3838 for (tail = &head ->
first; *tail; tail = &((*tail) -> cdr)) {
3841 if (oc->
option->
code == (*ocloc)->option->code) {
3844 ocloc = &(*ocloc)->
next;
3845 }
while (*ocloc != NULL);
3854 *tail =
cons (0, 0);
3857 (&(*tail) -> car), oc,
MDL);
3862 in_options, cfg_options, scope,
universe)
3883 for (oc = head ->
first; oc; oc = oc -> cdr) {
3891 in_options, cfg_options, scope,
universe))
3912 for (tail = &head ->
first; *tail; tail = &((*tail) -> cdr)) {
3916 tmp = (*tail) -> cdr;
3918 (&(*tail) -> car),
MDL);
3941 for (oc = head ->
first; oc; oc = oc -> cdr) {
3986 for (car = head ->
first; car; car = car -> cdr) {
3989 in_options, cfg_options, scope, u, stuff);
3997 unsigned int from_port;
4002 struct packet *decoded_packet;
4003 #if defined (DEBUG_MEMORY_LEAKAGE) 4004 unsigned long previous_outstanding = dmalloc_outstanding;
4007 #if defined (TRACING) 4011 decoded_packet = NULL;
4013 log_error(
"do_packet: no memory for incoming packet!");
4021 decoded_packet->
haddr = hfrom;
4025 log_info(
"Discarding packet with bogus hlen.");
4048 memset(&dp, 0,
sizeof dp);
4050 decoded_packet->
options, NULL,
4062 dhcp(decoded_packet);
4064 bootp(decoded_packet);
4070 #if defined (DEBUG_MEMORY_LEAKAGE) 4071 log_info(
"generation %ld: %ld new, %ld outstanding, %ld long-term",
4073 dmalloc_outstanding - previous_outstanding,
4074 dmalloc_outstanding, dmalloc_longterm);
4075 dmalloc_dump_outstanding();
4077 #if defined (DEBUG_RC_HISTORY_EXHAUSTIVELY) 4106 int len,
int from_port,
const struct iaddr *from,
4107 isc_boolean_t was_unicast) {
4108 unsigned char msg_type;
4114 struct packet *decoded_packet;
4115 #if defined (DEBUG_MEMORY_LEAKAGE) 4116 unsigned long previous_outstanding = dmalloc_outstanding;
4121 "short packet from %s port %d, len %d, dropped",
4122 piaddr(*from), from_port, len);
4126 decoded_packet = NULL;
4128 log_error(
"do_packet6: no memory for incoming packet.");
4133 log_error(
"do_packet6: no memory for options.");
4149 interface_reference(&decoded_packet->
interface, interface,
MDL);
4151 decoded_packet->
unicast = was_unicast;
4168 relay->
options, len - relaylen,
4221 #if defined (DEBUG_MEMORY_LEAKAGE) 4222 log_info(
"generation %ld: %ld new, %ld outstanding, %ld long-term",
4224 dmalloc_outstanding - previous_outstanding,
4225 dmalloc_outstanding, dmalloc_longterm);
4226 dmalloc_dump_outstanding();
4228 #if defined (DEBUG_RC_HISTORY_EXHAUSTIVELY) 4236 const unsigned char *send)
4243 if (dst == NULL || dend == NULL || src == NULL || send == NULL ||
4244 *dst == NULL || *src == NULL || (*dst >= dend) || (*src > send) ||
4245 ((send - *src) > (dend - *dst)))
4248 for ( ; *src < send ; (*src)++) {
4249 if (!isascii (**src) || !isprint (**src)) {
4251 if ((*src + 1) != send || **src !=
'\0') {
4252 if (*dst + 4 > dend)
4255 sprintf(*dst,
"\\%03o",
4260 }
else if (**src ==
'"' || **src ==
'\'' || **src ==
'$' ||
4261 **src ==
'`' || **src ==
'\\' || **src ==
'|' ||
4263 if (*dst + 2 > dend)
4272 if (*dst + 1 > dend)
4285 pretty_text(
char **dst,
char *dend,
const unsigned char **src,
4286 const unsigned char *send,
int emit_quotes)
4290 if (dst == NULL || dend == NULL || src == NULL || send == NULL ||
4291 *dst == NULL || *src == NULL ||
4292 ((*dst + (emit_quotes ? 2 : 0)) > dend) || (*src > send))
4301 count =
pretty_escape(dst, dend - (emit_quotes ? 1 : 0), src, send);
4306 if (emit_quotes && (*dst < dend)) {
4318 pretty_domain(
char **dst,
char *dend,
const unsigned char **src,
4319 const unsigned char *send)
4321 const unsigned char *tend;
4325 if (dst == NULL || dend == NULL || src == NULL || send == NULL ||
4326 *dst == NULL || *src == NULL ||
4327 ((*dst + 2) > dend) || (*src >= send))
4346 tend = (*src) + tsiz;
4358 if ((status == -1) || ((*dst + 2) > dend))
4363 count += status + 1;
4379 unsigned int option_num,
4381 unsigned int data_len)
4391 &option_num, 0,
MDL)) {
4392 log_error(
"Attempting to add unknown option %d.", option_num);
4398 log_error(
"No memory for option cache adding %s (option %d).",
4409 log_error(
"No memory for constant data adding %s (option %d).",
4438 log_debug(
"Dropped DHCPv4 packet with zero-length client-id");
4441 }
else if (oc->
data.
len == 1) {
4448 log_debug(
"Accepted DHCPv4 packet with one-character client-id - " 4449 "a future version of ISC DHCP will reject this");
4459 log_debug(
"Dropped DHCPv4 packet with wrong " 4460 "(len == %d) pxe-client-id", oc->
data.
len);
4469 log_debug(
"Received DHCPv4 packet without client-id" 4470 " option and empty hlen field.");
4524 if ((
packet == NULL) || (in_options == NULL) || (out_options == NULL))
4539 in_options, out_options, scope, oc,
MDL);
4549 if ((oc == NULL) || (oc->
data.
len == 0)) {
4565 (
const char *)
name.data);
struct option_cache * lookup_hashed_option(struct universe *universe, struct option_state *options, unsigned code)
void do_packet6(struct interface_info *, const char *, int, int, const struct iaddr *, isc_boolean_t)
#define rc_register(file, line, reference, addr, refcnt, d, f)
#define DHCP_FIXED_NON_UDP
int parse_encapsulated_suboptions(struct option_state *options, struct option *eopt, const unsigned char *buffer, unsigned len, struct universe *eu, const char *uname)
unsigned char peer_address[16]
int fqdn_option_space_encapsulate(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 universe *universe)
void set_option(struct universe *universe, struct option_state *options, struct option_cache *option, enum statement_op op)
#define DHO_DHCP_AGENT_OPTIONS
char sname[DHCP_SNAME_LEN]
struct binding_scope * global_scope
void save_linked_option(struct universe *universe, struct option_state *options, struct option_cache *oc, isc_boolean_t appendp)
void(* save_func)(struct universe *, struct option_state *, struct option_cache *, isc_boolean_t)
struct universe * universe
void save_option(struct universe *universe, struct option_state *options, struct option_cache *oc)
u_int32_t(* get_length)(const unsigned char *)
const char * piaddr(const struct iaddr addr)
int MRns_name_ntop(const u_char *src, char *dst, size_t dstsiz)
#define FQDN_NO_CLIENT_UPDATE
#define DHCP_MIN_OPTION_LEN
#define DHO_PXE_CLIENT_ID
unsigned char dhcpv6_transaction_id[3]
int append_option(struct data_string *dst, struct universe *universe, struct option *option, struct data_string *src)
unsigned char options[FLEXIBLE_ARRAY_MEMBER]
int format_has_text(char *format) const
void delete_linked_option(struct universe *universe, struct option_state *options, int code)
int hashed_option_space_encapsulate(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 universe *universe)
int option_cache_dereference(struct option_cache **ptr, const char *file, int line)
int expression_allocate(struct expression **cptr, const char *file, int line)
int store_option(struct data_string *result, struct universe *universe, 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)
struct enumeration * find_enumeration(const char *name, int length)
int int int log_debug(const char *,...) __attribute__((__format__(__printf__
struct option_cache * free_option_caches
void parse_vendor_option(struct packet *packet, struct lease *lease, struct client_state *client_state, struct option_state *in_options, struct option_state *out_options, struct binding_scope **scope)
Parse a vendor option (option 43)
pair new_pair(char *file, int line) const
#define DHO_DHCP_LEASE_TIME
int option_reference(struct option **dest, struct option *src, const char *file, int line)
struct universe dhcp_universe
int fqdn_universe_decode(struct option_state *options, const unsigned char *buffer, unsigned length, struct universe *u)
struct universe * find_option_universe(struct option *eopt, const char *uname)
void data_string_forget(struct data_string *data, const char *file, int line)
struct option_cache * next
void bootp(struct packet *packet)
const char * pretty_print_option(struct option *option, const unsigned char *data, unsigned len, int emit_commas, int emit_quotes)
#define FQDN_SUBOPTION_COUNT
int option_cache_reference(struct option_cache **ptr, struct option_cache *src, const char *file, int line)
void also_save_option(struct universe *universe, struct option_state *options, struct option_cache *oc)
void delete_option(struct universe *universe, struct option_state *options, int code)
int log_error(const char *,...) __attribute__((__format__(__printf__
struct option_cache *(* lookup_func)(struct universe *, struct option_state *, unsigned)
#define DHO_DHCP_REBINDING_TIME
#define DHCPV6_DHCPV4_QUERY
#define DHO_DOMAIN_NAME_SERVERS
int option_space_encapsulate(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 data_string *name)
int fqdn6_universe_decode(struct option_state *options, const unsigned char *buffer, unsigned length, struct universe *u)
const char * pdestdesc(const struct iaddr addr)
struct expression * expression
void build_server_oro(struct data_string *server_oro, struct option_state *options, const char *file, int line)
int(* decode)(struct option_state *, const unsigned char *, unsigned, struct universe *)
#define DHO_ASSOCIATED_IP
struct option_state * options
unsigned char dhcpv6_hop_count
void do_packet(struct interface_info *interface, struct dhcp_packet *packet, unsigned len, unsigned int from_port, struct iaddr from, struct hardware *hfrom)
unsigned char link_address[16]
void expression_dereference(struct expression **eptr, const char *file, int line)
unsigned char dhcpv6_msg_type
void data_string_truncate(struct data_string *dp, int len)
#define DHO_DHCP_SERVER_IDENTIFIER
void log_fatal(const char *,...) __attribute__((__format__(__printf__
#define DHCPV6_RELAY_REPL
int parse_option_buffer(struct option_state *options, const unsigned char *buffer, unsigned length, struct universe *universe)
int buffer_reference(struct buffer **ptr, struct buffer *bp, const char *file, int line)
int option_cache_allocate(struct option_cache **cptr, const char *file, int line)
struct universe vsio_universe
universe_hash_t * universe_hash
int linked_option_state_dereference(struct universe *universe, struct option_state *state, const char *file, int line)
int option_state_allocate(struct option_state **ptr, const char *file, int line)
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)
struct option_cache * lookup_fqdn6_option(struct universe *universe, struct option_state *options, unsigned code)
#define DHCPV6_DHCPV4_RESPONSE
int32_t getShort(const unsigned char *)
int option_chain_head_dereference(struct option_chain_head **ptr, const char *file, int line)
int32_t getLong(const unsigned char *)
#define DHCP_MAX_OPTION_LEN
void delete_hashed_option(struct universe *universe, struct option_state *options, int code)
void(* store_length)(unsigned char *, u_int32_t)
void linked_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 *))
int fqdn6_option_space_encapsulate(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 universe *universe)
int buffer_allocate(struct buffer **ptr, unsigned len, const char *file, int line)
char * default_option_format
struct interface_info * interface
struct enumeration_value * values
void putULong(unsigned char *, u_int32_t)
void delete_fqdn6_option(struct universe *universe, struct option_state *options, int code)
void save_hashed_option(struct universe *universe, struct option_state *options, struct option_cache *oc, isc_boolean_t appendp)
int linked_option_space_encapsulate(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 universe *universe)
int make_concat(struct expression **expr, struct expression *left, struct expression *right)
#define DHCPV6_RELAY_FORW
int pretty_escape(char **dst, char *dend, const unsigned char **src, const unsigned char *send)
int cons_options(struct packet *inpacket, struct dhcp_packet *outpacket, struct lease *lease, struct client_state *client_state, int mms, struct option_state *in_options, struct option_state *cfg_options, struct binding_scope **scope, int overload_avail, int terminate, int bootpp, struct data_string *prl, const char *vuname)
int save_option_buffer(struct universe *universe, struct option_state *options, struct buffer *bp, unsigned char *buffer, unsigned length, unsigned code, int terminatep)
u_int32_t getUShort(const unsigned char *)
int hashed_option_state_dereference(struct universe *universe, struct option_state *state, const char *file, int line)
struct option * new_option(char *name, const char *file, int line) const
void dfree(void *, const char *, int)
int add_option(struct option_state *options, unsigned int option_num, void *data, unsigned int data_len)
#define DHO_CLASSLESS_STATIC_ROUTES
int store_options(int *ocount, unsigned char *buffer, unsigned index, unsigned buflen, 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, unsigned *priority_list, int priority_len, unsigned first_cutoff, int second_cutoff, int terminate, const char *vuname)
struct option_cache * lookup_option(struct universe *universe, struct option_state *options, unsigned code)
int int log_info(const char *,...) __attribute__((__format__(__printf__
int packet6_len_okay(const char *packet, int len)
void * dmalloc(size_t, const char *, int)
int parse_options(struct packet *packet)
unsigned char dhcp4o6_flags[3]
u_int32_t getULong(const unsigned char *)
#define DHO_SUBNET_SELECTION
int validate_packet(struct packet *packet)
#define DHO_DHCP_MAX_MESSAGE_SIZE
int get_option(struct data_string *result, struct universe *universe, struct packet *packet, struct lease *lease, struct client_state *client_state, struct option_state *in_options, struct option_state *cfg_options, struct option_state *options, struct binding_scope **scope, unsigned code, const char *file, int line)
void fqdn6_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 *))
struct universe ** universes
int store_options6(char *buf, int buflen, struct option_state *opt_state, struct packet *packet, const int *required_opts, struct data_string *oro)
int append_option_buffer(struct universe *universe, struct option_state *options, struct buffer *bp, unsigned char *buffer, unsigned length, unsigned code, int terminatep)
u_int32_t getUChar(const unsigned char *)
void suboption_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 *), struct option_cache *oc, const char *vsname)
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 *))
void dhcpv6(struct packet *)
struct universe dhcpv6_universe
int format_min_length(char *format, struct option_cache *oc) const
int make_const_data(struct expression **expr, const unsigned char *data, unsigned len, int terminated, int allocate, const char *file, int line)
void free_pair(pair foo, const char *file, int line)
int packet_dereference(struct packet **ptr, const char *file, int line)
int packet_allocate(struct packet **ptr, const char *file, int line)
int option_chain_head_allocate(struct option_chain_head **ptr, const char *file, int line)
#define FQDN_SERVER_UPDATE
#define dmalloc_reuse(x, y, l, z)
unsigned char transaction_id[3]
int(* encapsulate)(struct data_string *, struct packet *, struct lease *, struct client_state *, struct option_state *, struct option_state *, struct binding_scope **, struct universe *)
u_int32_t(* get_tag)(const unsigned char *)
void save_fqdn6_option(struct universe *universe, struct option_state *options, struct option_cache *oc, isc_boolean_t appendp)
int MRns_name_unpack(const u_char *msg, const u_char *eom, const u_char *src, u_char *dst, size_t dstsiz)
void hashed_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 *))
struct universe fqdn_universe
void dhcp(struct packet *packet)
int nwip_option_space_encapsulate(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 universe *universe)
#define DHO_DHCP_OPTION_OVERLOAD
option_code_hash_t * code_hash
pair cons(caddr_t car, pair cdr)
#define DHO_DHCP_RENEWAL_TIME
struct in6_addr dhcpv6_peer_address
#define DHO_DHCP_CLIENT_IDENTIFIER
void trace_inpacket_stash(struct interface_info *, struct dhcp_packet *, unsigned, unsigned int, struct iaddr, struct hardware *)
void putUShort(unsigned char *, u_int32_t)
struct universe nwip_universe
unsigned char options[FLEXIBLE_ARRAY_MEMBER]
const unsigned char * data
int get_option_int(int *result, struct universe *universe, struct packet *packet, struct lease *lease, struct client_state *client_state, struct option_state *in_options, struct option_state *cfg_options, struct option_state *options, struct binding_scope **scope, unsigned code, const char *file, int line)
#define DHO_DHCP_MESSAGE_TYPE
struct option * vendor_cfg_option
void data_string_copy(struct data_string *dest, const struct data_string *src, const char *file, int line)
void(* store_tag)(unsigned char *, u_int32_t)
struct in6_addr dhcpv6_link_address
unsigned char options[FLEXIBLE_ARRAY_MEMBER]
#define DHCP_OPTIONS_COOKIE
int option_dereference(struct option **dest, const char *file, int line)
#define DHO_VENDOR_ENCAPSULATED_OPTIONS
unsigned char options[DHCP_MAX_OPTION_LEN]
#define DHO_DHCP_REQUESTED_ADDRESS
int buffer_dereference(struct buffer **ptr, const char *file, int line)
struct option_cache * lookup_linked_option(struct universe *universe, struct option_state *options, unsigned code)
#define compute_option_hash(x)