43 #define DS_SPRINTF_SIZE 128
68 if (ds->
data == NULL) {
75 *((
char *)ds->
data) =
'\0';
82 cur_strlen = strlen((
char *)ds->
data);
83 max = ds->
len - cur_strlen;
90 vsnprintf_ret = vsnprintf((
char *)ds->
data+cur_strlen, max, fmt, args);
97 if (vsnprintf_ret >= max) {
101 new_len = ds->
len * 2;
102 while (new_len <= cur_strlen + vsnprintf_ret) {
115 *((
char *)ds->
data+cur_strlen) =
'\0';
119 memcpy(tmp_buffer->
data, ds->
data, cur_strlen);
123 vsprintf((
char *)tmp_buffer->
data + cur_strlen, fmt, args);
165 bp = (
struct buffer *)0;
167 log_error (
"%s(%d): can't allocate buffer.",
174 log_error (
"%s(%d): can't allocate option cache.", file, line);
179 (*oc) -> data.len = len;
180 (*oc) -> data.buffer = bp;
181 (*oc) -> data.
data = &bp -> data [0];
182 (*oc) -> data.terminated = 0;
184 memcpy (&bp -> data [0], data, len);
194 log_error (
"No memory for host lookup tree node.");
214 log_error (
"Can't allocate space for new host.");
221 unsigned len,
int terminated,
int allocate,
227 log_error (
"No memory for make_const_data tree node.");
235 len + terminated, file, line)) {
236 log_error (
"Can't allocate const_data buffer");
240 nt -> data.const_data.
data =
241 &nt -> data.const_data.buffer -> data [0];
242 memcpy (nt -> data.const_data.buffer -> data,
243 data, len + terminated);
246 nt -> data.const_data.terminated = terminated;
248 nt -> data.const_data.
data = 0;
251 nt -> data.const_data.len = len;
260 log_error (
"No memory for make_const_int tree node.");
289 log_error (
"No memory for concatenation expression node.");
305 log_error (
"No memory for encapsulation expression node.");
322 log_error (
"no memory for substring expression.");
339 log_error (
"no memory for limit expression");
345 log_error (
"no memory for limit offset expression");
354 log_error (
"no memory for limit length expression");
385 (*result) ->
op = let_statement;
391 strcpy ((*result) ->
data.let.
name, name);
395 static int do_host_lookup (result, dns)
404 log_debug (
"time: now = %d dns = %d diff = %d",
409 if (cur_time <= dns ->
timeout) {
414 ? inet_ntoa (*(
struct in_addr *)(dns -> data.
data))
421 log_debug (
"Looking up %s", dns -> hostname);
425 h = gethostbyname (dns -> hostname);
431 log_error (
"%s: host unknown.", dns -> hostname);
435 log_error (
"%s: temporary name server failure",
439 log_error (
"%s: name server failed", dns -> hostname);
442 log_error (
"%s: no A record associated with address",
454 log_debug (
"Lookup succeeded; first address is %s",
455 inet_ntoa (h -> h_addr_list [0]));
459 for (count = 0; h -> h_addr_list [count]; count++)
466 new_len = count * h -> h_length;
469 log_error (
"No memory for %s.", dns -> hostname);
473 dns -> data.
data = &dns -> data.buffer -> data [0];
474 dns -> data.len = new_len;
475 dns -> data.terminated = 0;
479 for (i = 0; i < count; i++) {
480 memcpy (&dns -> data.buffer -> data [h -> h_length * i],
481 h -> h_addr_list [i], (
unsigned)(h -> h_length));
484 log_debug (
"dns -> data: %x h -> h_addr_list [0]: %x",
485 *(
int *)(dns ->
buffer), h -> h_addr_list [0]);
493 log_debug (
"hard copy: %d %s", dns -> data.len,
495 ? inet_ntoa (*(
struct in_addr *)(dns -> data.
data)) : 0));
502 in_options, cfg_options, scope, expr,
file,
line)
521 if (!scope || !*scope)
526 if (binding && binding ->
value) {
540 if (!scope || !*scope) {
542 expr -> data.funcall.name);
546 binding =
find_binding (*scope, expr -> data.funcall.name);
548 if (!binding || !binding ->
value) {
550 expr -> data.funcall.name);
553 if (binding ->
value -> type != binding_function) {
555 expr -> data.funcall.name);
563 log_error (
"%s: can't allocate argument scope.",
564 expr -> data.funcall.name);
568 arg = expr -> data.funcall.arglist;
569 s = binding -> value -> value.fundef -> args;
577 memset (nb, 0,
sizeof *nb);
578 nb -> name =
dmalloc (strlen (s ->
string) + 1,
581 strcpy (nb -> name, s ->
string);
589 in_options, cfg_options, scope,
590 arg -> data.arg.val, file, line);
593 arg = arg -> data.arg.next;
598 expr -> data.funcall.name);
604 expr -> data.funcall.name);
614 lease, client_state, in_options, cfg_options, &ns,
623 bv -> type = binding_boolean;
625 (&bv -> value.boolean, packet, lease, client_state,
626 in_options, cfg_options, scope, expr));
630 bv -> type = binding_numeric;
632 (&bv -> value.intval, packet, lease, client_state,
633 in_options, cfg_options, scope, expr));
637 bv -> type = binding_data;
639 (&bv -> value.data, packet, lease, client_state,
640 in_options, cfg_options, scope, expr,
MDL));
642 log_error (
"%s: invalid expression type: %d",
643 "evaluate_expression", expr -> op);
646 if (result && status)
667 log_error (
"%s(%d): negative refcnt!", file, line);
668 #if defined (DEBUG_RC_HISTORY)
669 dump_rc_history (bv);
671 #if defined (POINTER_DEBUG)
678 switch (bv ->
type) {
687 log_error (
"%s(%d): invalid binding type: %d",
688 file, line, bv ->
type);
696 in_options, cfg_options, scope, expr)
712 int regflags = REG_EXTENDED | REG_NOSUB;
716 switch (expr -> op) {
720 #if defined (DEBUG_EXPRESSIONS)
721 log_debug (
"bool: check (%s) returns %s",
722 expr -> data.check -> name,
723 *result ?
"true" :
"false");
731 in_options, cfg_options, scope,
732 expr -> data.equal [0],
MDL);
734 client_state, in_options,
736 expr -> data.equal [1],
MDL);
737 if (sleft && sright) {
741 switch (obv ->
type) {
778 }
else if (!sleft && !sright)
783 #if defined (DEBUG_EXPRESSIONS)
786 (*result ?
"true" :
"false"));
796 regflags |= REG_ICASE;
801 memset(&left, 0,
sizeof left);
804 in_options, cfg_options,
807 memset(&right, 0,
sizeof right);
810 in_options, cfg_options,
815 memset(&re, 0,
sizeof(re));
816 if (bleft && bright &&
817 (left.
data != NULL) && (right.
data != NULL) &&
818 (regcomp(&re, (
char *)right.
data, regflags) == 0) &&
819 (regexec(&re, (
char *)left.
data, (
size_t)0, NULL, 0) == 0))
822 #if defined (DEBUG_EXPRESSIONS)
828 *result ?
"true" :
"false");
845 return bleft && bright;
857 in_options, cfg_options,
859 expr -> data.and [0]);
862 (&bright, packet, lease, client_state,
863 in_options, cfg_options,
864 scope, expr -> data.and [1]);
868 #if defined (DEBUG_EXPRESSIONS)
870 sleft ? (bleft ?
"true" :
"false") :
"NULL",
871 sright ? (bright ?
"true" :
"false") :
"NULL",
873 ? (bleft && bright ?
"true" :
"false") :
"NULL"));
875 if (sleft && sright) {
876 *result = bleft && bright;
885 in_options, cfg_options,
887 expr -> data.or [0]);
888 if (!sleft || !bleft)
890 (&bright, packet, lease, client_state,
891 in_options, cfg_options,
892 scope, expr -> data.or [1]);
895 #if defined (DEBUG_EXPRESSIONS)
897 sleft ? (bleft ?
"true" :
"false") :
"NULL",
898 sright ? (bright ?
"true" :
"false") :
"NULL",
900 ? (bleft || bright ?
"true" :
"false") :
"NULL"));
902 if (sleft || sright) {
903 *result = bleft || bright;
911 in_options, cfg_options,
914 #if defined (DEBUG_EXPRESSIONS)
916 sleft ? (bleft ?
"true" :
"false") :
"NULL",
917 sleft ? (!bleft ?
"true" :
"false") :
"NULL");
926 memset (&left, 0,
sizeof left);
929 packet, lease, client_state,
930 in_options, cfg_options, in_options,
931 scope, expr -> data.exists -> code,
MDL))
937 #if defined (DEBUG_EXPRESSIONS)
939 expr -> data.option ->
universe -> name,
940 expr -> data.option -> name,
941 *result ?
"true" :
"false");
947 #if defined (DEBUG_EXPRESSIONS)
952 #if defined (DEBUG_EXPRESSIONS)
954 packet -> known ?
"true" :
"false");
956 *result = packet -> known;
961 #if defined (DEBUG_EXPRESSIONS)
962 log_debug (
"bool: static = false (%s %s %s %d)",
964 (lease && (lease -> flags & STATIC_LEASE)
967 lease ? lease -> flags : 0);
972 #if defined (DEBUG_EXPRESSIONS)
979 if (scope && *scope) {
983 if (binding ->
value)
991 #if defined (DEBUG_EXPRESSIONS)
992 log_debug (
"boolean: %s? = %s", expr -> data.variable,
993 *result ?
"true" :
"false");
998 if (scope && *scope) {
1001 if (binding && binding ->
value) {
1009 "evaluate_boolean_expression");
1016 #if defined (DEBUG_EXPRESSIONS)
1017 log_debug (
"boolean: %s = %s", expr -> data.variable,
1018 sleft ? (*result ?
"true" :
"false") :
"NULL");
1025 in_options, cfg_options,
1029 log_error (
"%s() returned type %d in %s.",
1030 expr -> data.funcall.name,
1032 "evaluate_boolean_expression");
1037 #if defined (DEBUG_EXPRESSIONS)
1038 log_debug (
"boolean: %s() = %s", expr -> data.funcall.name,
1039 sleft ? (*result ?
"true" :
"false") :
"NULL");
1071 log_error (
"Data opcode in evaluate_boolean_expression: %d",
1090 log_error (
"Numeric opcode in evaluate_boolean_expression: %d",
1098 log_error (
"dns opcode in evaluate_boolean_expression: %d",
1103 log_error (
"function definition in evaluate_boolean_expr");
1110 log_error (
"Bogus opcode in evaluate_boolean_expression: %d",
1116 in_options, cfg_options, scope, expr,
file,
line)
1129 unsigned long offset,
len, i;
1135 struct packet *relay_packet;
1138 switch (expr -> op) {
1141 memset (&data, 0,
sizeof data);
1144 in_options, cfg_options, scope,
1145 expr -> data.substring.expr,
1150 (&offset, packet, lease, client_state, in_options,
1151 cfg_options, scope, expr -> data.substring.offset);
1154 in_options, cfg_options,
1156 expr -> data.substring.
len);
1158 if (s0 && s1 && s2) {
1162 if (data.
len > offset) {
1164 result -> len -= offset;
1165 if (result -> len > len) {
1166 result -> len = len;
1167 result -> terminated = 0;
1169 result -> data += offset;
1175 #if defined (DEBUG_EXPRESSIONS)
1176 log_debug (
"data: substring (%s, %s, %s) = %s",
1180 (s3 ?
print_hex_2 (result -> len, result -> data, 30)
1191 memset (&data, 0,
sizeof data);
1194 in_options, cfg_options, scope,
1195 expr -> data.suffix.expr,
MDL);
1199 in_options, cfg_options,
1201 expr -> data.suffix.
len);
1210 if (data.
len > len) {
1211 result -> data += data.
len - len;
1212 result -> len = len;
1218 #if defined (DEBUG_EXPRESSIONS)
1219 log_debug (
"data: suffix (%s, %s) = %s",
1231 memset(&data, 0,
sizeof data);
1234 in_options, cfg_options, scope,
1238 result->len = data.
len;
1242 result->data = &result->buffer->data[0];
1243 memcpy(result->buffer->data, data.
data,
1246 s = (
unsigned char *)result->data;
1247 for (i = 0; i < result->len; i++, s++)
1251 log_error(
"data: lcase: no buffer memory.");
1255 #if defined (DEBUG_EXPRESSIONS)
1267 memset(&data, 0,
sizeof data);
1270 in_options, cfg_options, scope,
1274 result->len = data.
len;
1278 result->data = &result->buffer->data[0];
1279 memcpy(result->buffer->data, data.
data,
1282 s = (
unsigned char *)result->data;
1283 for (i = 0; i < result->len; i++, s++)
1287 log_error(
"data: lcase: no buffer memory.");
1291 #if defined (DEBUG_EXPRESSIONS)
1307 packet, lease, client_state,
1308 in_options, cfg_options, in_options,
1309 scope, expr -> data.option -> code,
1314 #if defined (DEBUG_EXPRESSIONS)
1316 expr -> data.option ->
universe -> name,
1317 expr -> data.option -> name,
1318 s0 ?
print_hex_1 (result -> len, result -> data, 60)
1327 packet, lease, client_state,
1328 in_options, cfg_options, cfg_options,
1329 scope, expr -> data.option -> code,
1334 #if defined (DEBUG_EXPRESSIONS)
1335 log_debug (
"data: config-option %s.%s = %s",
1336 expr -> data.option ->
universe -> name,
1337 expr -> data.option -> name,
1338 s0 ?
print_hex_1 (result -> len, result -> data, 60)
1347 memset(result, 0,
sizeof(*result));
1350 #if defined (DEBUG_EXPRESSIONS)
1361 if (packet != NULL && packet->
raw != NULL) {
1363 log_error(
"data: hardware: invalid hlen (%d)\n",
1367 result->len = packet->
raw->
hlen + 1;
1369 result->data = &result->buffer->data[0];
1370 result->buffer->data[0] = packet->
raw->
htype;
1371 memcpy(&result->buffer->data[1],
1373 result->terminated = 0;
1376 "no memory for buffer.");
1379 }
else if (lease != NULL) {
1382 result->data = &result->buffer->data[0];
1383 memcpy(result->buffer->data,
1385 result->terminated = 0;
1388 "no memory for buffer.");
1392 log_error(
"data: hardware: no raw packet or lease "
1397 #if defined (DEBUG_EXPRESSIONS)
1405 if (!packet || !packet -> raw) {
1406 log_error (
"data: packet: raw packet not available");
1412 in_options, cfg_options,
1414 expr -> data.packet.offset);
1416 packet, lease, client_state,
1417 in_options, cfg_options,
1419 expr -> data.packet.
len);
1420 if (s0 && s1 && offset < packet -> packet_length) {
1421 if (offset + len > packet -> packet_length)
1423 packet -> packet_length - offset;
1425 result -> len = len;
1427 result -> len, file, line)) {
1428 result -> data = &result ->
buffer -> data [0];
1429 memcpy (result ->
buffer -> data,
1430 (((
unsigned char *)(packet -> raw))
1431 + offset), result -> len);
1432 result -> terminated = 0;
1434 log_error (
"data: packet: no buffer memory.");
1440 #if defined (DEBUG_EXPRESSIONS)
1441 log_debug (
"data: packet (%ld, %ld) = %s",
1444 result -> data, 60) : NULL);
1453 (result, packet, lease, client_state,
1454 in_options, cfg_options, scope,
1455 &expr -> data.encapsulate);
1459 #if defined (DEBUG_EXPRESSIONS)
1460 log_debug (
"data: encapsulate (%s) = %s",
1461 expr -> data.encapsulate.
data,
1463 result -> data, 60) :
"NULL");
1469 #if defined (DEBUG_EXPRESSIONS)
1472 expr -> data.const_data.
data, 60));
1475 &expr -> data.const_data, file, line);
1480 s0 = do_host_lookup (result, expr -> data.host_lookup);
1481 #if defined (DEBUG_EXPRESSIONS)
1482 log_debug (
"data: DNS lookup (%s) = %s",
1483 expr -> data.host_lookup -> hostname,
1492 memset (&data, 0,
sizeof data);
1495 in_options, cfg_options, scope,
1496 expr -> data.concat [0],
MDL);
1497 memset (&other, 0,
sizeof other);
1500 in_options, cfg_options, scope,
1501 expr -> data.concat [1],
MDL);
1504 result -> len = data.
len + other.
len;
1514 result -> data = &result ->
buffer -> data [0];
1516 memcpy (&result ->
buffer -> data [data.
len],
1524 #if defined (DEBUG_EXPRESSIONS)
1525 log_debug (
"data: concat (%s, %s) = %s",
1537 in_options, cfg_options,
1539 expr -> data.encode_int);
1544 log_error (
"data: encode_int8: no memory");
1548 result -> data = &result ->
buffer -> data [0];
1549 result ->
buffer -> data [0] = len;
1554 #if defined (DEBUG_EXPRESSIONS)
1556 log_debug (
"data: encode_int8 (NULL) = NULL");
1558 log_debug (
"data: encode_int8 (%ld) = %s", len,
1560 result -> data, 20));
1568 in_options, cfg_options,
1570 expr -> data.encode_int);
1575 log_error (
"data: encode_int16: no memory");
1579 result -> data = &result ->
buffer -> data [0];
1585 #if defined (DEBUG_EXPRESSIONS)
1587 log_debug (
"data: encode_int16 (NULL) = NULL");
1589 log_debug (
"data: encode_int16 (%ld) = %s", len,
1591 result -> data, 20));
1598 in_options, cfg_options,
1600 expr -> data.encode_int);
1605 log_error (
"data: encode_int32: no memory");
1609 result -> data = &result ->
buffer -> data [0];
1615 #if defined (DEBUG_EXPRESSIONS)
1617 log_debug (
"data: encode_int32 (NULL) = NULL");
1619 log_debug (
"data: encode_int32 (%ld) = %s", len,
1621 result -> data, 20));
1628 (&offset, packet, lease, client_state, in_options,
1629 cfg_options, scope, expr -> data.b2a.base);
1632 in_options, cfg_options,
1634 expr -> data.b2a.width);
1637 memset (&data, 0,
sizeof data);
1640 in_options, cfg_options, scope,
1641 expr -> data.b2a.separator,
1645 memset (&other, 0,
sizeof other);
1648 in_options, cfg_options, scope,
1651 if (s0 && s1 && s2 && s3) {
1654 if (len != 8 && len != 16 && len != 32) {
1655 log_info (
"binary_to_ascii: %s %ld!",
1656 "invalid width", len);
1664 if (other.
len % len) {
1665 log_info (
"binary-to-ascii: %s %d %s %ld!",
1666 "length of buffer", other.
len,
1667 "not a multiple of width", len);
1674 for (i = 0; i < other.
len; i += len) {
1677 if (other.
data [i] < 8)
1679 else if (other.
data [i] < 64)
1683 }
else if (offset == 10) {
1684 if (other.
data [i] < 10)
1686 else if (other.
data [i] < 100)
1690 }
else if (offset == 16) {
1691 if (other.
data [i] < 16)
1703 if (i + len != other.
len)
1708 buflen + 1, file, line)) {
1709 log_error (
"data: binary-to-ascii: no memory");
1713 result -> data = &result ->
buffer -> data [0];
1714 result -> len = buflen;
1715 result -> terminated = 1;
1718 for (i = 0; i < other.
len; i += len) {
1720 (&result ->
buffer -> data [buflen],
1721 &other.
data [i], offset, len));
1722 if (i + len != other.
len) {
1730 result ->
buffer -> data [buflen] = 0;
1736 #if defined (DEBUG_EXPRESSIONS)
1737 log_debug (
"data: binary-to-ascii (%s, %s, %s, %s) = %s",
1742 (status ?
print_hex_3 (result -> len, result -> data, 30)
1756 (&len, packet, lease, client_state, in_options,
1757 cfg_options, scope, expr -> data.reverse.width);
1760 memset (&data, 0,
sizeof data);
1763 in_options, cfg_options, scope,
1764 expr -> data.reverse.
buffer,
1772 if (data.
len % len) {
1773 log_info (
"reverse: %s %d %s %ld!",
1774 "length of buffer", data.
len,
1775 "not a multiple of width", len);
1782 data.
len, file, line)) {
1787 result -> data = &result ->
buffer -> data [0];
1788 result -> len = data.
len;
1789 result -> terminated = 0;
1791 for (i = 0; i < data.
len; i += len) {
1792 memcpy (&result ->
buffer -> data [i],
1793 &data.
data [data.
len - i - len], len);
1800 #if defined (DEBUG_EXPRESSIONS)
1801 log_debug (
"data: reverse (%s, %s) = %s",
1804 (status ?
print_hex_3 (result -> len, result -> data, 30)
1815 log_debug(
"data: \"leased-address\" configuration "
1816 "directive: there is no lease associated "
1817 "with this client.");
1823 result -> data = &result ->
buffer -> data [0];
1824 memcpy (&result ->
buffer -> data [0],
1826 result -> terminated = 0;
1828 log_error (
"data: leased-address: no memory.");
1831 #if defined (DEBUG_EXPRESSIONS)
1838 memset (&data, 0,
sizeof data);
1841 lease, client_state, in_options, cfg_options,
1842 scope, expr -> data.pick_first_value.car,
MDL))) {
1843 #if defined (DEBUG_EXPRESSIONS)
1844 log_debug (
"data: pick_first_value (%s, xxx)",
1846 result -> data, 40));
1851 if (expr -> data.pick_first_value.cdr &&
1854 lease, client_state, in_options, cfg_options,
1855 scope, expr -> data.pick_first_value.cdr,
MDL))) {
1856 #if defined (DEBUG_EXPRESSIONS)
1857 log_debug (
"data: pick_first_value (NULL, %s)",
1859 result -> data, 40));
1864 #if defined (DEBUG_EXPRESSIONS)
1865 log_debug (
"data: pick_first_value (NULL, NULL) = NULL");
1870 if (!lease || !lease -> host) {
1871 log_error (
"data: host_decl_name: not available");
1874 result -> len = strlen (lease -> host -> name);
1876 result -> len + 1, file, line)) {
1877 result -> data = &result ->
buffer -> data [0];
1878 strcpy ((
char *)&result ->
buffer -> data [0],
1879 lease -> host -> name);
1880 result -> terminated = 1;
1882 log_error (
"data: host-decl-name: no memory.");
1885 #if defined (DEBUG_EXPRESSIONS)
1886 log_debug (
"data: host-decl-name = %s", lease -> host -> name);
1891 #if defined (DEBUG_EXPRESSIONS)
1897 if (scope && *scope) {
1898 binding =
find_binding (*scope, expr -> data.variable);
1900 if (binding && binding -> value) {
1901 if (binding -> value -> type == binding_data) {
1903 &binding -> value -> value.data,
1906 }
else if (binding -> value -> type != binding_data) {
1908 binding -> value -> type,
1909 "evaluate_data_expression");
1917 #if defined (DEBUG_EXPRESSIONS)
1918 log_debug (
"data: %s = %s", expr -> data.variable,
1920 result -> data, 50) :
"NULL");
1927 in_options, cfg_options,
1931 log_error (
"%s() returned type %d in %s.",
1932 expr -> data.funcall.name,
1934 "evaluate_data_expression");
1940 #if defined (DEBUG_EXPRESSIONS)
1941 log_debug (
"data: %s = %s", expr -> data.funcall.name,
1943 result -> data, 50) :
"NULL");
1949 if (packet && packet -> raw -> file [0]) {
1951 memchr (packet -> raw -> file, 0,
1952 sizeof packet -> raw -> file);
1954 fn = ((
char *)packet -> raw -> file +
1955 sizeof packet -> raw -> file);
1956 result -> len = fn - &(packet -> raw -> file [0]);
1958 result -> len + 1, file, line)) {
1959 result -> data = &result ->
buffer -> data [0];
1960 memcpy (&result ->
buffer -> data [0],
1961 packet -> raw -> file,
1963 result ->
buffer -> data [result -> len] = 0;
1964 result -> terminated = 1;
1967 log_error (
"data: filename: no memory.");
1973 #if defined (DEBUG_EXPRESSIONS)
1974 log_info (
"data: filename = \"%s\"",
1975 s0 ? (
const char *)(result -> data) :
"NULL");
1981 if (packet && packet -> raw -> sname [0]) {
1983 memchr (packet -> raw -> sname, 0,
1984 sizeof packet -> raw -> sname);
1986 fn = ((
char *)packet -> raw -> sname +
1987 sizeof packet -> raw -> sname);
1988 result -> len = fn - &packet -> raw -> sname [0];
1990 result -> len + 1, file, line)) {
1991 result -> data = &result ->
buffer -> data [0];
1992 memcpy (&result ->
buffer -> data [0],
1993 packet -> raw -> sname,
1995 result ->
buffer -> data [result -> len] = 0;
1996 result -> terminated = 1;
2005 #if defined (DEBUG_EXPRESSIONS)
2007 s0 ? (
const char *)(result -> data) :
"NULL");
2020 memset(result, 0,
sizeof(*result));
2022 log_error(
"data: gethostname(): no memory for buffer");
2025 result->data = result->buffer->data;
2032 if (!gethostname((
char *)result->buffer->data, 255)) {
2033 if (result->buffer->data[255] ==
'\0')
2035 strlen((
char *)result->buffer->data);
2061 memset (&data, 0,
sizeof data);
2066 in_options, cfg_options,
2073 ((packet == NULL) ||
2075 #if defined (DEBUG_EXPRESSIONS)
2076 log_debug(
"data: v6relay(%lu) = NULL", len);
2083 relay_packet = packet;
2084 relay_options = in_options;
2088 relay_options = relay_packet->
options;
2093 #if defined (DEBUG_EXPRESSIONS)
2094 log_debug(
"data: v6relay(%lu) = NULL", len);
2100 client_state, relay_options,
2110 #if defined (DEBUG_EXPRESSIONS)
2111 log_debug(
"data: v6relay(%lu) = %s", len,
2121 memset(&data, 0,
sizeof data);
2125 in_options, cfg_options, scope,
2128 memset (&other, 0,
sizeof other);
2131 in_options, cfg_options, scope,
2137 log_error (
"data: concat_dclist failed");
2141 #if defined (DEBUG_EXPRESSIONS)
2142 log_debug (
"data: concat_dclists (%s, %s) = %s",
2147 (((s0 && s1) && result->len > 0)
2148 ?
print_hex_3 (result->len, result->data, result->len)
2174 log_error (
"Boolean opcode in evaluate_data_expression: %d",
2193 log_error (
"Numeric opcode in evaluate_data_expression: %d",
2201 log_error (
"dns opcode in evaluate_boolean_expression: %d",
2206 log_error (
"function definition in evaluate_data_expression");
2214 log_error (
"Bogus opcode in evaluate_data_expression: %d", expr -> op);
2219 in_options, cfg_options, scope, expr)
2220 unsigned
long *result;
2230 int status, sleft, sright;
2234 unsigned long ileft, iright;
2237 switch (expr -> op) {
2252 log_error (
"Boolean opcode in evaluate_numeric_expression: %d",
2281 log_error (
"Data opcode in evaluate_numeric_expression: %d",
2286 memset (&data, 0,
sizeof data);
2288 (&data, packet, lease, client_state, in_options,
2289 cfg_options, scope, expr -> data.extract_int,
MDL);
2291 *result = data.
data [0];
2292 #if defined (DEBUG_EXPRESSIONS)
2293 log_debug (
"num: extract_int8 (%s) = %s",
2301 memset(&data, 0,
sizeof(data));
2303 (&data, packet, lease, client_state, in_options,
2305 if (status && data.
len >= 2) {
2309 #if defined (DEBUG_EXPRESSIONS)
2311 log_debug(
"num: extract_int16 (%s) = %ld",
2315 log_debug(
"num: extract_int16 (NULL) = NULL");
2324 memset (&data, 0,
sizeof data);
2326 (&data, packet, lease, client_state, in_options,
2327 cfg_options, scope, expr -> data.extract_int,
MDL));
2328 if (status && data.
len >= 4) {
2332 #if defined (DEBUG_EXPRESSIONS)
2334 log_debug (
"num: extract_int32 (%s) = %ld",
2338 log_debug (
"num: extract_int32 (NULL) = NULL");
2345 *result = expr -> data.const_int;
2346 #if defined (DEBUG_EXPRESSIONS)
2347 log_debug (
"number: CONSTANT = %ld", *result);
2353 log_error(
"data: leased_lease: not available");
2358 "data: lease_time: lease ends at",
2363 #if defined (DEBUG_EXPRESSIONS)
2364 log_debug(
"number: lease-time = (%lu - %lu) = %ld",
2365 (
long unsigned)lease->
ends,
2371 if (scope && *scope) {
2372 binding =
find_binding (*scope, expr -> data.variable);
2374 if (binding && binding ->
value) {
2381 "evaluate_numeric_expression");
2388 #if defined (DEBUG_EXPRESSIONS)
2391 expr -> data.variable, *result);
2394 expr -> data.variable);
2402 in_options, cfg_options,
2406 log_error (
"%s() returned type %d in %s.",
2407 expr -> data.funcall.name,
2409 "evaluate_numeric_expression");
2414 #if defined (DEBUG_EXPRESSIONS)
2415 log_debug (
"data: %s = %ld", expr -> data.funcall.name,
2416 status ? *result : 0);
2423 in_options, cfg_options,
2425 expr -> data.and [0]);
2428 in_options, cfg_options,
2430 expr -> data.and [1]);
2432 #if defined (DEBUG_EXPRESSIONS)
2433 if (sleft && sright)
2435 ileft, iright, ileft + iright);
2437 log_debug (
"num: %ld + NULL = NULL", ileft);
2439 log_debug (
"num: NULL + %ld = NULL", iright);
2441 if (sleft && sright) {
2442 *result = ileft + iright;
2450 in_options, cfg_options,
2452 expr -> data.and [0]);
2455 in_options, cfg_options,
2457 expr -> data.and [1]);
2459 #if defined (DEBUG_EXPRESSIONS)
2460 if (sleft && sright)
2462 ileft, iright, ileft - iright);
2464 log_debug (
"num: %ld - NULL = NULL", ileft);
2466 log_debug (
"num: NULL - %ld = NULL", iright);
2468 if (sleft && sright) {
2469 *result = ileft - iright;
2477 in_options, cfg_options,
2479 expr -> data.and [0]);
2482 in_options, cfg_options,
2484 expr -> data.and [1]);
2486 #if defined (DEBUG_EXPRESSIONS)
2487 if (sleft && sright)
2489 ileft, iright, ileft * iright);
2491 log_debug (
"num: %ld * NULL = NULL", ileft);
2493 log_debug (
"num: NULL * %ld = NULL", iright);
2495 if (sleft && sright) {
2496 *result = ileft * iright;
2504 in_options, cfg_options,
2506 expr -> data.and [0]);
2509 in_options, cfg_options,
2511 expr -> data.and [1]);
2513 #if defined (DEBUG_EXPRESSIONS)
2514 if (sleft && sright) {
2517 ileft, iright, ileft / iright);
2522 log_debug (
"num: %ld / NULL = NULL", ileft);
2524 log_debug (
"num: NULL / %ld = NULL", iright);
2526 if (sleft && sright && iright) {
2527 *result = ileft / iright;
2535 in_options, cfg_options,
2537 expr -> data.and [0]);
2540 in_options, cfg_options,
2542 expr -> data.and [1]);
2544 #if defined (DEBUG_EXPRESSIONS)
2545 if (sleft && sright) {
2548 ileft, iright, ileft % iright);
2553 log_debug (
"num: %ld %% NULL = NULL", ileft);
2555 log_debug (
"num: NULL %% %ld = NULL", iright);
2557 if (sleft && sright && iright) {
2558 *result = ileft % iright;
2566 in_options, cfg_options,
2568 expr -> data.and [0]);
2571 in_options, cfg_options,
2573 expr -> data.and [1]);
2575 #if defined (DEBUG_EXPRESSIONS)
2576 if (sleft && sright)
2578 ileft, iright, ileft & iright);
2580 log_debug (
"num: %ld & NULL = NULL", ileft);
2582 log_debug (
"num: NULL & %ld = NULL", iright);
2584 if (sleft && sright) {
2585 *result = ileft & iright;
2593 in_options, cfg_options,
2595 expr -> data.and [0]);
2598 in_options, cfg_options,
2600 expr -> data.and [1]);
2602 #if defined (DEBUG_EXPRESSIONS)
2603 if (sleft && sright)
2605 ileft, iright, ileft | iright);
2607 log_debug (
"num: %ld | NULL = NULL", ileft);
2609 log_debug (
"num: NULL | %ld = NULL", iright);
2611 if (sleft && sright) {
2612 *result = ileft | iright;
2620 in_options, cfg_options,
2622 expr -> data.and [0]);
2625 in_options, cfg_options,
2627 expr -> data.and [1]);
2629 #if defined (DEBUG_EXPRESSIONS)
2630 if (sleft && sright)
2632 ileft, iright, ileft ^ iright);
2634 log_debug (
"num: %ld ^ NULL = NULL", ileft);
2636 log_debug (
"num: NULL ^ %ld = NULL", iright);
2638 if (sleft && sright) {
2639 *result = ileft ^ iright;
2646 #if defined (DEBUG_EXPRESSIONS)
2648 client_state -> state);
2650 *result = client_state -> state;
2653 #if defined (DEBUG_EXPRESSIONS)
2660 log_error (
"function definition in evaluate_numeric_expr");
2667 log_fatal(
"Impossible case at %s:%d. Undefined operator "
2668 "%d.",
MDL, expr->
op);
2672 log_error (
"evaluate_numeric_expression: bogus opcode %d", expr -> op);
2689 in_options, cfg_options, scope, oc,
file,
line)
2708 in_options, cfg_options, scope,
2724 cfg_options, scope, oc,
file,
line)
2742 if (oc && in_options) {
2745 memset(&ds, 0,
sizeof ds);
2747 lease, client_state, in_options,
2748 cfg_options, scope, oc, file,
2753 if (ds.
data[0] == 1)
2755 else if ((ds.
data[0] == 2) && (ignorep != NULL))
2770 in_options, cfg_options, scope, expr)
2787 in_options, cfg_options,
2818 if (expr ->
refcnt < 0) {
2819 log_error (
"%s(%d): negative refcnt!", file, line);
2820 #if defined (DEBUG_RC_HISTORY)
2821 dump_rc_history (expr);
2823 #if defined (POINTER_DEBUG)
2831 switch (expr ->
op) {
3106 static int op_val (
enum expr_op);
3108 static int op_val (
op)
3192 return op_val (op1) - op_val (op2);
3306 switch (expr -> op) {
3338 col, indent + 2, 0);
3414 (file, col, indent,
"",
"",
3463 expr ->
data.
not, col, indent + 2, 1);
3520 sprintf (obuf,
"%d", width);
3543 sprintf (obuf,
"%d", width);
3564 goto print_option_name;
3626 s =
"config-option";
3627 goto print_option_name;
3738 log_fatal (
"invalid expression type in print_expression: %d",
3749 for (s = scope; s; s = s ->
outer) {
3750 for (bp = s ->
bindings; bp; bp = bp -> next) {
3751 if (!strcasecmp (name, bp -> name)) {
3763 for (bp = scope -> bindings; bp; bp =
next) {
3769 dfree (bp, file, line);
3771 scope -> bindings = (
struct binding *)0;
3782 if (!ptr || !*ptr) {
3783 log_error (
"%s(%d): null pointer", file, line);
3784 #if defined (POINTER_DEBUG)
3791 binding_scope = *ptr;
3792 *ptr = (
struct binding_scope *)0;
3793 --binding_scope ->
refcnt;
3796 if (binding_scope ->
refcnt > 0)
3799 if (binding_scope ->
refcnt < 0) {
3800 log_error (
"%s(%d): negative refcnt!", file, line);
3801 #if defined (DEBUG_RC_HISTORY)
3802 dump_rc_history (binding_scope);
3804 #if defined (POINTER_DEBUG)
3812 if (binding_scope ->
outer)
3814 dfree (binding_scope, file, line);
3826 if ((ptr == NULL) || (*ptr == NULL)) {
3827 log_error (
"%s(%d): null pointer", file, line);
3828 #if defined (POINTER_DEBUG)
3838 if (bp -> refcnt < 0) {
3839 log_error (
"%s(%d): negative refcnt!", file, line);
3840 #if defined (DEBUG_RC_HISTORY)
3841 dump_rc_history (bp);
3843 #if defined (POINTER_DEBUG)
3849 if (!bp -> refcnt) {
3850 for (sp = bp -> args; sp; sp =
next) {
3852 dfree (sp, file, line);
3854 if (bp -> statements)
3857 dfree (bp, file, line);
3859 *ptr = (
struct fundef *)0;
3863 #if defined (NOTYET)
3867 int crhs, clhs, llhs, lrhs;
3868 switch (expr -> op) {
3870 if (expr -> data.substring.len &&
3873 (
int)expr -> data.substring.len -> data.const_int);
3880 if (expr -> data.suffix.len &&
3883 (
int)expr -> data.suffix.len -> data.const_int);
3896 expr -> data.concat [0]);
3898 expr -> data.concat [1]);
3899 if (crhs == 0 || clhs == 0)
3909 *rv = expr -> data.const_data.len;
3914 expr -> data.reverse.buffer);
3923 expr -> data.concat [0]);
3925 expr -> data.concat [1]);
3926 if (crhs == 0 || clhs == 0)
3936 expr -> data.v6relay.relay);
3938 expr -> data.v6relay.roption);
3939 if (crhs == 0 || clhs == 0)
4044 return (
struct binding *)0;
4051 return (
struct binding *)0;
4053 memset (binding, 0,
sizeof *binding);
4054 binding -> name =
dmalloc (strlen (name) + 1,
MDL);
4055 if (!binding -> name) {
4057 return (
struct binding *)0;
4059 strcpy (binding -> name, name);
4061 binding ->
next = (*scope) -> bindings;
4062 (*scope) -> bindings = binding;
4079 if (binding -> value)
4086 binding -> value -> type = binding_data;
4100 !binding -> value ||
4101 binding -> value -> type != binding_data)
4104 if (binding -> value -> value.
data.terminated) {
4113 memcpy (value ->
buffer -> data,
4114 binding -> value -> value.
data.data,
4115 binding -> value -> value.
data.len);
4116 value -> data = value ->
buffer -> data;
4117 value -> len = binding -> value -> value.
data.len;
4129 if (binding ->
value)
4171 char *uncomp = uncompbuf;
4173 int compbuf_max = 0;
4178 if (list1 && (list1->
data) && (list1->
len)) {
4184 " error decompressing domain list 1");
4188 uncomp_len = list_len;
4193 if (list2 && (list2->
data) && (list2->
len)) {
4195 if (uncomp_len > 0) {
4201 uncomp, (
sizeof(uncompbuf)
4205 " error decompressing domain list 2");
4209 uncomp_len += list_len;
4214 if (uncomp_len == 0) {
4216 log_error (
"concat_dclists: empty list allocate fail");
4232 compbuf_max = uncomp_len + 3;
4234 for (i = 0; i < uncomp_len; i++)
4235 if (*uncomp++ ==
',')
4240 log_error (
"concat_dclists: No memory for result");
4249 if (list_len <= 0) {
4250 log_error (
"concat_dlists: error compressing result");
4257 result->
len = list_len;
#define rc_register(file, line, reference, addr, refcnt, d, f)
int executable_statement_allocate(struct executable_statement **ptr, const char *file, int line)
char * print_dotted_quads(unsigned len, const u_int8_t *data)
struct binding_scope * global_scope
int token_indent_data_string(FILE *file, int col, int indent, const char *prefix, const char *suffix, struct data_string *data)
int binding_value_dereference(struct binding_value **v, const char *file, int line)
int executable_statement_dereference(struct executable_statement **ptr, const char *file, int line)
int free_bindings(struct binding_scope *scope, const char *file, int line)
const char * piaddr(const struct iaddr addr)
int make_const_option_cache(struct option_cache **oc, struct buffer **buffer, u_int8_t *data, unsigned len, struct option *option, const char *file, int line)
struct expression::expr_union::@25 arg
struct expression * equal[2]
struct binding_scope * outer
struct data_string encapsulate
void * dmalloc(unsigned, const char *, int)
struct expression::expr_union::@21 pick_first_value
int expression_allocate(struct expression **cptr, const char *file, int line)
int data_string_sprintfa(struct data_string *ds, const char *fmt,...)
int execute_statements(struct binding_value **result, 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, struct executable_statement *statements, struct on_star *on_star)
struct iaddr ip_addr(struct iaddr subnet, struct iaddr mask, u_int32_t host_address)
int binding_value_reference(struct binding_value **ptr, struct binding_value *src, const char *file, int line)
#define print_hex_1(len, data, limit)
struct executable_statement * statements
enum expression_context expression_context(struct expression *expr)
struct expression * lcase
int int int log_debug(const char *,...) __attribute__((__format__(__printf__
struct expression * arglist
struct expression::expr_union::@16 substring
char * print_dec_2(unsigned long val)
int is_numeric_expression(struct expression *expr)
int option_reference(struct option **dest, struct option *src, const char *file, int line)
int find_bound_string(struct data_string *value, struct binding_scope *scope, const char *name)
struct universe dhcp_universe
char * print_dec_1(unsigned long val)
void data_string_forget(struct data_string *data, const char *file, int line)
struct expression * concat[2]
int evaluate_numeric_expression(unsigned long *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 expression *expr)
enum binding_value::@15 type
int log_error(const char *,...) __attribute__((__format__(__printf__
int is_compound_expression(struct expression *expr)
struct expression * offset
int binding_scope_dereference(struct binding_scope **ptr, const char *file, int line)
enum expression_context op_context(enum expr_op op)
int evaluate_expression(struct binding_value **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 expression *expr, const char *file, int line)
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)
void indent_spaces(FILE *file, int indent)
int make_substring(struct expression **new, struct expression *expr, struct expression *offset, struct expression *length)
struct option_state * options
struct expression::expr_union::@17 suffix
int is_boolean_expression(struct expression *expr)
void expression_dereference(struct expression **eptr, const char *file, int line)
void log_fatal(const char *,...) __attribute__((__format__(__printf__
int evaluate_boolean_expression_result(int *ignorep, 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 expression *expr)
int binding_value_allocate(struct binding_value **cptr, const char *file, int line)
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)
union expression::expr_union data
struct hardware hardware_addr
int unset(struct binding_scope *scope, const char *name)
struct expression * encode_int
int make_host_lookup(struct expression **expr, const char *name)
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 expression::expr_union::@20 reverse
struct expression * width
struct expression * roption
int buffer_allocate(struct buffer **ptr, unsigned len, const char *file, int line)
int binding_scope_allocate(struct binding_scope **ptr, const char *file, int line)
void putULong(unsigned char *, u_int32_t)
int binary_to_ascii(unsigned char *, const unsigned char *, unsigned int, unsigned int)
int make_concat(struct expression **expr, struct expression *left, struct expression *right)
int MRns_name_compress_list(const char *buf, int buflen, unsigned char *compbuf, size_t compbuf_size)
Creates a compressed list from a string of comma-separated domain-names.
u_int32_t getUShort(const unsigned char *)
void dfree(void *, const char *, int)
struct expression * buffer
int concat_dclists(struct data_string *result, struct data_string *list1, struct data_string *list2)
Adds two Dc-formatted lists into a single Dc-formatted list.
int make_let(struct executable_statement **result, const char *name)
struct hardware hw_address
#define print_hex_3(len, data, limit)
int int log_info(const char *,...) __attribute__((__format__(__printf__
struct expression * relay
int fundef_dereference(struct fundef **ptr, const char *file, int line)
struct expression::expr_union::@19 b2a
int evaluate_data_expression(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 expression *expr, const char *file, int line)
int option_cache(struct option_cache **oc, struct data_string *dp, struct expression *expr, struct option *option, const char *file, int line)
struct expression * extract_int
u_int32_t getULong(const unsigned char *)
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)
int check_collection(struct packet *packet, struct lease *lease, struct collection *collection)
union binding_value::value value
int MRns_name_uncompress_list(const unsigned char *buf, int buflen, char *dst_buf, size_t dst_size)
Creates a string of comma-separated domain-names from a compressed list.
struct data_string const_data
struct binding * bindings
int binding_scope_reference(struct binding_scope **ptr, struct binding_scope *bp, const char *file, int line)
int token_print_indent_concat(FILE *file, int col, int indent, const char *prefix, const char *suffix,...)
int evaluate_boolean_option_cache(int *ignorep, 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)
#define print_hex_2(len, data, limit)
int make_const_data(struct expression **expr, const unsigned char *data, unsigned len, int terminated, int allocate, const char *file, int line)
int enter_dns_host(struct dns_host_entry **dh, const char *name)
struct string_list * next
int is_data_expression(struct expression *expr)
struct binding_value * value
int make_limit(struct expression **new, struct expression *expr, int limit)
struct binding * create_binding(struct binding_scope **scope, const char *name)
struct expression * ucase
void free_expression(struct expression *expr, const char *file, int line)
struct collection * check
int make_encapsulation(struct expression **expr, struct data_string *name)
int expression_reference(struct expression **ptr, struct expression *src, const char *file, int line)
int dns_host_entry_allocate(struct dns_host_entry **ptr, const char *hostname, const char *file, int line)
int converted_length(const unsigned char *, unsigned int, unsigned int)
u_int8_t hbuf[HARDWARE_ADDR_LEN+1]
int evaluate_boolean_expression(int *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 expression *expr)
int op_precedence(enum expr_op op1, enum expr_op op2)
int token_print_indent(FILE *file, int col, int indent, const char *prefix, const char *suffix, const char *buf)
int dns_host_entry_dereference(struct dns_host_entry **ptr, const char *file, int line)
int make_const_int(struct expression **expr, unsigned long val)
struct expression::expr_union::@27 v6relay
struct dns_host_entry * host_lookup
pair cons(caddr_t car, pair cdr)
int write_expression(FILE *file, struct expression *expr, int col, int indent, int firstp)
struct binding * find_binding(struct binding_scope *scope, const char *name)
void putUShort(unsigned char *, u_int32_t)
const unsigned char * data
struct interface_info * interface
int bind_ds_value(struct binding_scope **scope, const char *name, struct data_string *value)
void data_string_copy(struct data_string *dest, const struct data_string *src, const char *file, int line)
void free_binding_value(struct binding_value *bv, const char *file, int line)
struct expression::expr_union::@26 funcall
int data_subexpression_length(int *, struct expression *)
int expr_valid_for_context(struct expression *, enum expression_context)
struct expression::expr_union::@18 packet
struct expression * separator
int buffer_dereference(struct buffer **ptr, const char *file, int line)
struct packet * dhcpv6_container_packet