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) {
1131 memset(&ds, 0,
sizeof(ds));
1134 for (; oc != NULL ; oc = oc->
next) {
1136 NULL, opt_state, NULL,
1152 struct option *encap_opt = NULL;
1153 unsigned int code_int =
code;
1155 option_code_hash_lookup(&encap_opt,
1158 if (encap_opt != NULL) {
1159 store_encap6(buf, buflen, &bufpos, opt_state,
1190 if (vs.bufpos > bufpos+8) {
1191 tmp = (
unsigned char *)buf +
1196 vs.bufpos-bufpos-4);
1215 unsigned char *
buffer,
unsigned index,
unsigned buflen,
1221 unsigned *priority_list,
int priority_len,
1222 unsigned first_cutoff,
int second_cutoff,
int terminate,
1225 int bufix = 0, six = 0, tix = 0;
1229 int bufend, sbufend;
1243 first_cutoff -= index;
1245 second_cutoff -= index;
1248 bufend = sbufend = buflen;
1250 if (first_cutoff >= buflen)
1251 log_fatal(
"%s:%d:store_options: Invalid first cutoff.",
MDL);
1252 bufend = first_cutoff;
1254 if (second_cutoff) {
1255 if (second_cutoff >= buflen)
1256 log_fatal(
"%s:%d:store_options: Invalid second cutoff.",
1258 sbufend = second_cutoff;
1260 }
else if (second_cutoff) {
1261 if (second_cutoff >= buflen)
1262 log_fatal(
"%s:%d:store_options: Invalid second cutoff.",
MDL);
1263 bufend = second_cutoff;
1266 memset (&od, 0,
sizeof od);
1271 for (i = 0; i < priority_len; i++) {
1274 for (ix = i + 1; ix < priority_len + tto; ix++) {
1276 priority_list [ix - tto] =
1278 if (priority_list [i] == priority_list [ix]) {
1296 for (ix = i - 1 ; ix >= 0 ; ix--) {
1309 for (i = 0; i < priority_len; i++) {
1313 int optstart, soptstart, toptstart;
1315 int have_encapsulation = 0;
1319 memset (&encapsulation, 0,
sizeof encapsulation);
1320 have_encapsulation = 0;
1326 code = priority_list [i];
1330 if (code >= cfg_options -> site_code_min)
1331 u =
universes [cfg_options -> site_universe];
1359 t = strchr (++s,
'.');
1361 memset (&name, 0,
sizeof name);
1377 }
else if (vuname) {
1378 name.
data = (
unsigned char *)s;
1379 name.
len = strlen (s);
1382 name.
data = (
unsigned char *)s;
1389 have_encapsulation =
1392 in_options, cfg_options, scope, &name));
1407 if (!oc && !have_encapsulation) {
1417 cfg_options, scope, oc,
MDL);
1436 if (have_encapsulation) {
1437 length += encapsulation.
len;
1492 unsigned incr = length;
1494 unsigned char *base;
1498 ((!six && !tix && (i == priority_len - 1) &&
1499 (bufix + 2 + length < bufend)) ||
1500 (bufix + 5 + length < bufend))) {
1504 }
else if (!splitup && first_cutoff &&
1505 (first_cutoff + six + 3 + length < sbufend)) {
1506 base = &
buffer[first_cutoff];
1509 }
else if (!splitup && second_cutoff &&
1510 (second_cutoff + tix + 3 + length < buflen)) {
1511 base = &
buffer[second_cutoff];
1518 if (bufix + 6 < bufend) {
1519 incr = bufend - bufix - 5;
1523 }
else if (first_cutoff &&
1524 (first_cutoff + six + 4 < sbufend)) {
1525 incr = sbufend - (first_cutoff + six) - 3;
1526 base = &
buffer[first_cutoff];
1529 }
else if (second_cutoff &&
1530 (second_cutoff + tix + 4 < buflen)) {
1531 incr = buflen - (second_cutoff + tix) - 3;
1532 base = &
buffer[second_cutoff];
1550 base [*pix + 1] = (
unsigned char)incr;
1551 if (tto && incr == length) {
1553 memcpy (base + *pix + 2,
1554 od.
data + ix, (
unsigned)(incr - 1));
1555 base [*pix + 2 + incr - 1] = 0;
1557 memcpy (base + *pix + 2,
1558 od.
data + ix, (
unsigned)incr);
1571 if (first_cutoff && six) {
1572 if ((first_cutoff + six + 1) < sbufend)
1574 sbufend - (first_cutoff + six + 1));
1575 else if (first_cutoff + six >= sbufend)
1576 log_fatal(
"Second buffer overflow in overloaded options.");
1583 if (second_cutoff && tix) {
1584 if (second_cutoff + tix + 1 < buflen) {
1586 buflen - (second_cutoff + tix + 1));
1587 }
else if (second_cutoff + tix >= buflen)
1588 log_fatal(
"Third buffer overflow in overloaded options.");
1595 if ((six || tix) && (bufix + 3 > bufend))
1596 log_fatal(
"Not enough space for option overload option.");
1612 while (*p !=
'\0') {
1636 log_error(
"format_has_text(%s): 'c' atoms are illegal " 1637 "except after 'D' atoms.", format);
1649 while ((*p !=
'\0') && (*p++ !=
'.'))
1672 const char *p, *name;
1678 while (*p !=
'\0') {
1704 log_fatal(
"Corrupt format: %s", format);
1707 if (espace == NULL) {
1708 log_error(
"Unknown enumeration: %s", format);
1713 min_len += espace->
width;
1714 last_size = espace->
width;
1728 min_len -= last_size;
1749 log_error(
"format_min_length(%s): 'c' atom is illegal " 1750 "except after 'D' atom.", format);
1755 log_error(
"format_min_length(%s): No safe value " 1756 "for unknown format symbols.", format);
1767 #define MAX_OUTPUT_SIZE 32*1024 1770 const unsigned char *data;
1785 char fmtbuf[32] =
"";
1789 const unsigned char *dp = data;
1792 isc_boolean_t a_array = ISC_FALSE;
1794 unsigned int octets = 0;
1801 memset (enumbuf, 0,
sizeof enumbuf);
1805 for (l = i = 0;
option -> format [i]; i++, l++) {
1806 if (l >=
sizeof(fmtbuf) - 1)
1807 log_fatal(
"Bounds failure on internal buffer at " 1811 log_error (
"%s: Extra codes in format string: %s",
1813 &(
option -> format [i]));
1817 fmtbuf [l] =
option -> format [i];
1818 switch (
option -> format [i]) {
1829 while (
option -> format [i] &&
1830 option -> format [i] !=
'.')
1834 for (k = 0; k < len; k++) {
1835 if (!isascii (data [k]) ||
1836 !isprint (data [k]))
1842 if (k == len || (k + 1 == len && data [k] == 0)) {
1857 log_error(
"'c' atom not following D atom in format " 1880 while (
option -> format [i] &&
1881 option -> format [i] !=
'.')
1886 if (enumbuf[l] == NULL) {
1890 hunksize += enumbuf[l]->
width;
1891 hunkinc = enumbuf[l]->
width;
1924 log_error (
"%s: garbage in format string: %s",
1926 &(
option -> format [i]));
1932 if (hunksize - opthunk > len) {
1933 log_error (
"%s: expecting at least %d bytes; got %d",
1939 if (numhunk == -1 && hunksize < len)
1946 if (a_array == ISC_TRUE) {
1958 log_error (
"%s: invalid 'a' format: %s",
1963 numhunk = ((len - hunksize) / hunkinc) + 1;
1964 len_used = hunksize + ((numhunk - 1) * hunkinc);
1973 if (hunksize == 0) {
1974 log_error (
"%s: invalid 'A' format: %s",
1979 numhunk = len / hunksize;
1980 len_used = numhunk * hunksize;
1984 if (len_used < len) {
1985 log_error (
"%s: %d extra bytes at end of array\n",
2008 fmtbuf[0]=
'R'; fmtbuf[1]=
'I'; fmtbuf[2]=0;
2009 for (i =0; i < len; i = i + octets + 5) {
2011 log_error (
"wrong subnet mask width in destination descriptor");
2015 octets = ((data[i]+7) / 8);
2018 log_error (
"classless static routes option has wrong size or " 2019 "there's some garbage in format");
2024 for (i = 0; i < numhunk; i++) {
2025 if ((a_array == ISC_TRUE) && (i != 0) && (numelem > 0)) {
2042 for (; j < numelem; j++) {
2043 switch (fmtbuf [j]) {
2046 k = pretty_text(&op, endbuf - 1, &dp,
2047 data + len, emit_quotes);
2055 for( ; dp < (data + len) ; dp += k) {
2057 const unsigned char *nbp, *nend;
2059 nend = &nbuff[
sizeof(nbuff)];
2069 if (op + 2 > endbuf)
2098 pretty_domain(&op, endbuf-1,
2138 switch (enumbuf[j]->
width) {
2154 return "<double impossible condition>";
2160 if (enumbuf [j] ->
values [i].value ==
2165 dp += enumbuf[j]->
width;
2169 sprintf(op,
"%lu", tval);
2183 log_error (
"wrong subnet mask width in destination descriptor");
2199 sprintf (op,
"%ld", (
long)
getLong (dp));
2205 sprintf (op,
"%s",
"infinite");
2207 sprintf(op,
"%lu", tval);
2215 sprintf (op,
"%d", (
int)
getShort (dp));
2219 sprintf(op,
"%u", (
unsigned)
getUShort(dp));
2223 sprintf (op,
"%d", *(
const char *)dp++);
2226 sprintf (op,
"%d", *dp++);
2230 sprintf (op,
"%x", *dp++);
2233 strcpy (op, *dp++ ?
"true" :
"false");
2236 strcpy (op,
"true");
2254 if (dp == data + len)
2256 if (j + 1 < numelem && comma !=
':')
2259 if (i + 1 < numhunk) {
2262 if (dp == data + len)
2269 in_options, cfg_options, options, scope, code,
file,
line)
2291 in_options, cfg_options, scope, oc,
2304 in_options, cfg_options, options, scope, code,
file,
line)
2332 memset(&d1, 0,
sizeof(d1));
2334 in_options, cfg_options, scope, oc,
2340 *result = d1.
data[0];
2352 enum statement_op op;
2359 case eval_statement:
2360 case break_statement:
2362 log_error (
"bogus statement type in set_option.");
2365 case default_option_statement:
2373 case supersede_option_statement:
2374 case send_option_statement:
2379 case append_option_statement:
2380 case prepend_option_statement:
2390 log_error (
"Can't allocate const expression.");
2402 if (op == append_option_statement) {
2423 switch (((memcmp(
option->option->
format,
"Dc", 2) == 0) +
2429 log_error (
"Both options must be Dc format");
2458 log_error (
"can't look up options in %s space.",
2480 for (bptr = hash [hashix]; bptr; bptr = bptr -> cdr) {
2491 struct buffer *bp,
unsigned char *
buffer,
unsigned length,
2492 unsigned code,
int terminatep)
2497 status = prepare_option_buffer(
universe, bp,
buffer, length, code,
2515 struct buffer *bp,
unsigned char *
buffer,
unsigned length,
2516 unsigned code,
int terminatep)
2521 status = prepare_option_buffer(
universe, bp,
buffer, length, code,
2539 unsigned char *
buffer,
unsigned length,
unsigned code,
2542 struct buffer *lbp = NULL;
2558 if (code > 0xffffffff)
2563 log_fatal(
"Inconsistent universe tag size at %s:%d.",
MDL);
2576 char nbuf[
sizeof(
"unknown-4294967295")];
2578 sprintf(nbuf,
"unknown-%u", code);
2594 log_error(
"No memory for option code %s.%s.",
2609 log_error (
"no memory for option buffer.");
2614 memcpy (lbp ->
data,
buffer, length + terminatep);
2625 op ->
data.len = length;
2634 op ->
data.terminated = 1;
2636 op ->
data.terminated = 0;
2646 while ((op->
data.
len > min_len) &&
2664 struct packet *dummy_packet,
2665 struct lease *dummy_lease,
2671 void *void_accumulator) {
2672 int *accumulator = (
int *)void_accumulator;
2679 struct packet *dummy_packet,
2680 struct lease *dummy_lease,
2729 memset(server_oro, 0,
sizeof(*server_oro));
2731 log_fatal(
"no memory to build server ORO");
2739 server_oro->
len = 0;
2749 tmp = server_oro->buffer->data;
2752 server_oro->len += 2;
2810 for (bptr = hash [hashix]; bptr; bptr = bptr -> cdr) {
2812 (bptr -> car)) ->
option -> code ==
2828 ocloc = &(*ocloc)->
next;
2829 }
while (*ocloc != NULL);
2842 log_error (
"No memory for option_cache reference.");
2845 bptr -> cdr = hash [hashix];
2848 hash [hashix] = bptr;
2859 log_error (
"can't delete options from %s space.",
2878 for (bptr = hash [hashix]; bptr; bptr = bptr -> cdr) {
2887 prev -> cdr = bptr -> cdr;
2889 hash [hashix] = bptr -> cdr;
2903 if (!ptr || !*ptr) {
2904 log_error (
"Null pointer in option_cache_dereference: %s(%d)",
2906 #if defined (POINTER_DEBUG) 2931 if ((*ptr) ->
refcnt < 0) {
2933 #if defined (DEBUG_RC_HISTORY) 2934 dump_rc_history (*ptr);
2936 #if defined (POINTER_DEBUG) 2966 for (cp = heads [i]; cp; cp = next) {
2994 memset(&tmp, 0,
sizeof(tmp));
3047 memset(&tmp, 0,
sizeof(tmp));
3050 in_options, cfg_options, scope, oc,
MDL)) {
3064 end = strchr(++start,
'.');
3069 if (
end == NULL || start ==
end)
3073 start,
end - start,
MDL);
3077 "refers to unknown " 3078 "option space '%.*s'.",
3080 (
int)(
end - start), start);
3092 cfg_options, scope, subu);
3095 }
while (ISC_FALSE);
3107 in_options, cfg_options, scope,
name)
3123 log_error(
"option_space_encapsulate: option space '%.*s' does " 3124 "not exist, but is configured.",
3131 in_options, cfg_options, scope, u))
3134 log_error(
"encapsulation requested for '%s' with no support.",
3167 memset(&sub, 0,
sizeof(sub));
3181 in_options, cfg_options,
3195 in_options, cfg_options, scope,
universe)
3222 for (p = hash [i]; p; p = p -> cdr) {
3231 in_options, cfg_options, scope,
universe))
3238 in_options, cfg_options, scope,
universe)
3262 for (ocp = head ->
first; ocp; ocp = ocp -> cdr) {
3275 static unsigned char nni [] = { 1, 0 };
3277 memset (&ds, 0,
sizeof ds);
3282 if (!option_code_hash_lookup(&no_nwip->
option,
3285 log_fatal(
"Nwip option hash does not contain " 3291 cfg_options, scope, no_nwip))
3295 memset (&ds, 0,
sizeof ds);
3304 ds.
buffer -> data [0] = 2;
3305 ds.
buffer -> data [1] = 0;
3306 memcpy (&ds.
buffer -> data [2], result -> data, result -> len);
3322 fqdn_encode(
unsigned char *dst,
int dstlen,
const unsigned char *src,
3326 int i, j, len, outlen=0;
3329 for (i = 0, j = 0 ; i < srclen ; i = j) {
3330 while ((j < srclen) && (src[j] !=
'.') && (src[j] !=
'\0'))
3334 if ((outlen + 1 + len) > dstlen)
3344 memcpy(out, src + i, len);
3352 if ((outlen + 1) > dstlen)
3363 in_options, cfg_options, scope,
universe)
3390 memset (results, 0,
sizeof results);
3391 for (ocp = head ->
first; ocp; ocp = ocp -> cdr) {
3398 in_options, cfg_options, scope,
3410 log_error (
"no memory for option buffer.");
3418 memset (&bp ->
data [0], 0, len);
3432 bp ->
data [0] |= 2;
3435 bp ->
data [0] |= 1;
3445 i = fqdn_encode(&bp->
data[3], len - 3,
3462 result -> terminated = 0;
3467 if (results [i].len)
3548 unsigned char *
data;
3549 int i, len, rval = 0, count;
3559 memset(results, 0,
sizeof(results));
3560 for (ocp = head->
first ; ocp != NULL ; ocp = ocp->
cdr) {
3567 cfg_options, scope, oc,
MDL);
3577 log_error(
"No memory for virtual option buffer.");
3610 count = fqdn_encode(
data + 1, len - 1,
3619 result->
len += count;
3638 const unsigned char *
buffer,
unsigned length,
3641 struct buffer *bp = NULL;
3642 unsigned char *first_dot;
3643 int len, hlen, dlen;
3658 unsigned bp_size = 3 + (length * 4);
3661 log_error(
"No memory for dhcp6.fqdn option buffer.");
3693 log_error(
"Unable to convert dhcp6.fqdn domain name to " 3700 unsigned char *fqdn_start = bp->
data + 3;
3706 first_dot = (
unsigned char *)strchr((
char *)fqdn_start,
'.');
3708 if (first_dot != NULL) {
3709 hlen = first_dot - fqdn_start;
3752 cfg_options, scope, u, stuff, func);
3775 in_options, cfg_options,
3798 if (cfg_options -> universe_count <= u -> index)
3801 hash = cfg_options ->
universes [u -> index];
3807 for (p = hash [i]; p; p = p -> cdr) {
3810 in_options, cfg_options, scope, u, stuff);
3837 for (tail = &head ->
first; *tail; tail = &((*tail) -> cdr)) {
3840 if (oc->
option->
code == (*ocloc)->option->code) {
3843 ocloc = &(*ocloc)->
next;
3844 }
while (*ocloc != NULL);
3853 *tail =
cons (0, 0);
3856 (&(*tail) -> car), oc,
MDL);
3861 in_options, cfg_options, scope,
universe)
3882 for (oc = head ->
first; oc; oc = oc -> cdr) {
3890 in_options, cfg_options, scope,
universe))
3911 for (tail = &head ->
first; *tail; tail = &((*tail) -> cdr)) {
3915 tmp = (*tail) -> cdr;
3917 (&(*tail) -> car),
MDL);
3940 for (oc = head ->
first; oc; oc = oc -> cdr) {
3985 for (car = head ->
first; car; car = car -> cdr) {
3988 in_options, cfg_options, scope, u, stuff);
3996 unsigned int from_port;
4001 struct packet *decoded_packet;
4002 #if defined (DEBUG_MEMORY_LEAKAGE) 4003 unsigned long previous_outstanding = dmalloc_outstanding;
4006 #if defined (TRACING) 4010 decoded_packet = NULL;
4012 log_error(
"do_packet: no memory for incoming packet!");
4020 decoded_packet->
haddr = hfrom;
4024 log_info(
"Discarding packet with bogus hlen.");
4047 memset(&dp, 0,
sizeof dp);
4049 decoded_packet->
options, NULL,
4061 dhcp(decoded_packet);
4063 bootp(decoded_packet);
4069 #if defined (DEBUG_MEMORY_LEAKAGE) 4070 log_info(
"generation %ld: %ld new, %ld outstanding, %ld long-term",
4072 dmalloc_outstanding - previous_outstanding,
4073 dmalloc_outstanding, dmalloc_longterm);
4074 dmalloc_dump_outstanding();
4076 #if defined (DEBUG_RC_HISTORY_EXHAUSTIVELY) 4105 int len,
int from_port,
const struct iaddr *from,
4106 isc_boolean_t was_unicast) {
4107 unsigned char msg_type;
4113 struct packet *decoded_packet;
4114 #if defined (DEBUG_MEMORY_LEAKAGE) 4115 unsigned long previous_outstanding = dmalloc_outstanding;
4120 "short packet from %s port %d, len %d, dropped",
4121 piaddr(*from), from_port, len);
4125 decoded_packet = NULL;
4127 log_error(
"do_packet6: no memory for incoming packet.");
4132 log_error(
"do_packet6: no memory for options.");
4148 interface_reference(&decoded_packet->
interface, interface,
MDL);
4150 decoded_packet->
unicast = was_unicast;
4167 relay->
options, len - relaylen,
4220 #if defined (DEBUG_MEMORY_LEAKAGE) 4221 log_info(
"generation %ld: %ld new, %ld outstanding, %ld long-term",
4223 dmalloc_outstanding - previous_outstanding,
4224 dmalloc_outstanding, dmalloc_longterm);
4225 dmalloc_dump_outstanding();
4227 #if defined (DEBUG_RC_HISTORY_EXHAUSTIVELY) 4235 const unsigned char *send)
4242 if (dst == NULL || dend == NULL || src == NULL || send == NULL ||
4243 *dst == NULL || *src == NULL || (*dst >= dend) || (*src > send) ||
4244 ((send - *src) > (dend - *dst)))
4247 for ( ; *src < send ; (*src)++) {
4248 if (!isascii (**src) || !isprint (**src)) {
4250 if ((*src + 1) != send || **src !=
'\0') {
4251 if (*dst + 4 > dend)
4254 sprintf(*dst,
"\\%03o",
4259 }
else if (**src ==
'"' || **src ==
'\'' || **src ==
'$' ||
4260 **src ==
'`' || **src ==
'\\' || **src ==
'|' ||
4262 if (*dst + 2 > dend)
4271 if (*dst + 1 > dend)
4284 pretty_text(
char **dst,
char *dend,
const unsigned char **src,
4285 const unsigned char *send,
int emit_quotes)
4289 if (dst == NULL || dend == NULL || src == NULL || send == NULL ||
4290 *dst == NULL || *src == NULL ||
4291 ((*dst + (emit_quotes ? 2 : 0)) > dend) || (*src > send))
4300 count =
pretty_escape(dst, dend - (emit_quotes ? 1 : 0), src, send);
4305 if (emit_quotes && (*dst < dend)) {
4317 pretty_domain(
char **dst,
char *dend,
const unsigned char **src,
4318 const unsigned char *send)
4320 const unsigned char *tend;
4324 if (dst == NULL || dend == NULL || src == NULL || send == NULL ||
4325 *dst == NULL || *src == NULL ||
4326 ((*dst + 2) > dend) || (*src >= send))
4345 tend = (*src) + tsiz;
4357 if ((status == -1) || ((*dst + 2) > dend))
4362 count += status + 1;
4378 unsigned int option_num,
4380 unsigned int data_len)
4390 &option_num, 0,
MDL)) {
4391 log_error(
"Attempting to add unknown option %d.", option_num);
4397 log_error(
"No memory for option cache adding %s (option %d).",
4408 log_error(
"No memory for constant data adding %s (option %d).",
4437 log_debug(
"Dropped DHCPv4 packet with zero-length client-id");
4440 }
else if (oc->
data.
len == 1) {
4447 log_debug(
"Accepted DHCPv4 packet with one-character client-id - " 4448 "a future version of ISC DHCP will reject this");
4458 log_debug(
"Dropped DHCPv4 packet with wrong " 4459 "(len == %d) pxe-client-id", oc->
data.
len);
4468 log_debug(
"Received DHCPv4 packet without client-id" 4469 " option and empty hlen field.");
4523 if ((
packet == NULL) || (in_options == NULL) || (out_options == NULL))
4538 in_options, out_options, scope, oc,
MDL);
4548 if ((oc == NULL) || (oc->
data.
len == 0)) {
4564 (
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)