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");
1070 log_error (
"Data opcode in evaluate_boolean_expression: %d",
1089 log_error (
"Numeric opcode in evaluate_boolean_expression: %d",
1097 log_error (
"dns opcode in evaluate_boolean_expression: %d",
1102 log_error (
"function definition in evaluate_boolean_expr");
1109 log_error (
"Bogus opcode in evaluate_boolean_expression: %d",
1115 in_options, cfg_options, scope, expr,
file,
line)
1128 unsigned long offset,
len, i;
1134 struct packet *relay_packet;
1137 switch (expr -> op) {
1140 memset (&data, 0,
sizeof data);
1143 in_options, cfg_options, scope,
1144 expr -> data.substring.expr,
1149 (&offset, packet, lease, client_state, in_options,
1150 cfg_options, scope, expr -> data.substring.offset);
1153 in_options, cfg_options,
1155 expr -> data.substring.
len);
1157 if (s0 && s1 && s2) {
1161 if (data.
len > offset) {
1163 result -> len -= offset;
1164 if (result -> len > len) {
1165 result -> len = len;
1166 result -> terminated = 0;
1168 result -> data += offset;
1174 #if defined (DEBUG_EXPRESSIONS)
1175 log_debug (
"data: substring (%s, %s, %s) = %s",
1179 (s3 ?
print_hex_2 (result -> len, result -> data, 30)
1190 memset (&data, 0,
sizeof data);
1193 in_options, cfg_options, scope,
1194 expr -> data.suffix.expr,
MDL);
1198 in_options, cfg_options,
1200 expr -> data.suffix.
len);
1209 if (data.
len > len) {
1210 result -> data += data.
len - len;
1211 result -> len = len;
1217 #if defined (DEBUG_EXPRESSIONS)
1218 log_debug (
"data: suffix (%s, %s) = %s",
1230 memset(&data, 0,
sizeof data);
1233 in_options, cfg_options, scope,
1237 result->len = data.
len;
1241 result->data = &result->buffer->data[0];
1242 memcpy(result->buffer->data, data.
data,
1245 s = (
unsigned char *)result->data;
1246 for (i = 0; i < result->len; i++, s++)
1250 log_error(
"data: lcase: no buffer memory.");
1254 #if defined (DEBUG_EXPRESSIONS)
1266 memset(&data, 0,
sizeof data);
1269 in_options, cfg_options, scope,
1273 result->len = data.
len;
1277 result->data = &result->buffer->data[0];
1278 memcpy(result->buffer->data, data.
data,
1281 s = (
unsigned char *)result->data;
1282 for (i = 0; i < result->len; i++, s++)
1286 log_error(
"data: lcase: no buffer memory.");
1290 #if defined (DEBUG_EXPRESSIONS)
1306 packet, lease, client_state,
1307 in_options, cfg_options, in_options,
1308 scope, expr -> data.option -> code,
1313 #if defined (DEBUG_EXPRESSIONS)
1315 expr -> data.option ->
universe -> name,
1316 expr -> data.option -> name,
1317 s0 ?
print_hex_1 (result -> len, result -> data, 60)
1326 packet, lease, client_state,
1327 in_options, cfg_options, cfg_options,
1328 scope, expr -> data.option -> code,
1333 #if defined (DEBUG_EXPRESSIONS)
1334 log_debug (
"data: config-option %s.%s = %s",
1335 expr -> data.option ->
universe -> name,
1336 expr -> data.option -> name,
1337 s0 ?
print_hex_1 (result -> len, result -> data, 60)
1346 memset(result, 0,
sizeof(*result));
1349 #if defined (DEBUG_EXPRESSIONS)
1360 if (packet != NULL && packet->
raw != NULL) {
1362 log_error(
"data: hardware: invalid hlen (%d)\n",
1366 result->len = packet->
raw->
hlen + 1;
1368 result->data = &result->buffer->data[0];
1369 result->buffer->data[0] = packet->
raw->
htype;
1370 memcpy(&result->buffer->data[1],
1372 result->terminated = 0;
1375 "no memory for buffer.");
1378 }
else if (lease != NULL) {
1381 result->data = &result->buffer->data[0];
1382 memcpy(result->buffer->data,
1384 result->terminated = 0;
1387 "no memory for buffer.");
1391 log_error(
"data: hardware: no raw packet or lease "
1396 #if defined (DEBUG_EXPRESSIONS)
1404 if (!packet || !packet -> raw) {
1405 log_error (
"data: packet: raw packet not available");
1411 in_options, cfg_options,
1413 expr -> data.packet.offset);
1415 packet, lease, client_state,
1416 in_options, cfg_options,
1418 expr -> data.packet.
len);
1419 if (s0 && s1 && offset < packet -> packet_length) {
1420 if (offset + len > packet -> packet_length)
1422 packet -> packet_length - offset;
1424 result -> len = len;
1426 result -> len, file, line)) {
1427 result -> data = &result ->
buffer -> data [0];
1428 memcpy (result ->
buffer -> data,
1429 (((
unsigned char *)(packet -> raw))
1430 + offset), result -> len);
1431 result -> terminated = 0;
1433 log_error (
"data: packet: no buffer memory.");
1439 #if defined (DEBUG_EXPRESSIONS)
1440 log_debug (
"data: packet (%ld, %ld) = %s",
1443 result -> data, 60) : NULL);
1452 (result, packet, lease, client_state,
1453 in_options, cfg_options, scope,
1454 &expr -> data.encapsulate);
1458 #if defined (DEBUG_EXPRESSIONS)
1459 log_debug (
"data: encapsulate (%s) = %s",
1460 expr -> data.encapsulate.
data,
1462 result -> data, 60) :
"NULL");
1468 #if defined (DEBUG_EXPRESSIONS)
1471 expr -> data.const_data.
data, 60));
1474 &expr -> data.const_data, file, line);
1479 s0 = do_host_lookup (result, expr -> data.host_lookup);
1480 #if defined (DEBUG_EXPRESSIONS)
1481 log_debug (
"data: DNS lookup (%s) = %s",
1482 expr -> data.host_lookup -> hostname,
1491 memset (&data, 0,
sizeof data);
1494 in_options, cfg_options, scope,
1495 expr -> data.concat [0],
MDL);
1496 memset (&other, 0,
sizeof other);
1499 in_options, cfg_options, scope,
1500 expr -> data.concat [1],
MDL);
1503 result -> len = data.
len + other.
len;
1513 result -> data = &result ->
buffer -> data [0];
1515 memcpy (&result ->
buffer -> data [data.
len],
1523 #if defined (DEBUG_EXPRESSIONS)
1524 log_debug (
"data: concat (%s, %s) = %s",
1536 in_options, cfg_options,
1538 expr -> data.encode_int);
1543 log_error (
"data: encode_int8: no memory");
1547 result -> data = &result ->
buffer -> data [0];
1548 result ->
buffer -> data [0] = len;
1553 #if defined (DEBUG_EXPRESSIONS)
1555 log_debug (
"data: encode_int8 (NULL) = NULL");
1557 log_debug (
"data: encode_int8 (%ld) = %s", len,
1559 result -> data, 20));
1567 in_options, cfg_options,
1569 expr -> data.encode_int);
1574 log_error (
"data: encode_int16: no memory");
1578 result -> data = &result ->
buffer -> data [0];
1584 #if defined (DEBUG_EXPRESSIONS)
1586 log_debug (
"data: encode_int16 (NULL) = NULL");
1588 log_debug (
"data: encode_int16 (%ld) = %s", len,
1590 result -> data, 20));
1597 in_options, cfg_options,
1599 expr -> data.encode_int);
1604 log_error (
"data: encode_int32: no memory");
1608 result -> data = &result ->
buffer -> data [0];
1614 #if defined (DEBUG_EXPRESSIONS)
1616 log_debug (
"data: encode_int32 (NULL) = NULL");
1618 log_debug (
"data: encode_int32 (%ld) = %s", len,
1620 result -> data, 20));
1627 (&offset, packet, lease, client_state, in_options,
1628 cfg_options, scope, expr -> data.b2a.base);
1631 in_options, cfg_options,
1633 expr -> data.b2a.width);
1636 memset (&data, 0,
sizeof data);
1639 in_options, cfg_options, scope,
1640 expr -> data.b2a.separator,
1644 memset (&other, 0,
sizeof other);
1647 in_options, cfg_options, scope,
1650 if (s0 && s1 && s2 && s3) {
1653 if (len != 8 && len != 16 && len != 32) {
1654 log_info (
"binary_to_ascii: %s %ld!",
1655 "invalid width", len);
1663 if (other.
len % len) {
1664 log_info (
"binary-to-ascii: %s %d %s %ld!",
1665 "length of buffer", other.
len,
1666 "not a multiple of width", len);
1673 for (i = 0; i < other.
len; i += len) {
1676 if (other.
data [i] < 8)
1678 else if (other.
data [i] < 64)
1682 }
else if (offset == 10) {
1683 if (other.
data [i] < 10)
1685 else if (other.
data [i] < 100)
1689 }
else if (offset == 16) {
1690 if (other.
data [i] < 16)
1702 if (i + len != other.
len)
1707 buflen + 1, file, line)) {
1708 log_error (
"data: binary-to-ascii: no memory");
1712 result -> data = &result ->
buffer -> data [0];
1713 result -> len = buflen;
1714 result -> terminated = 1;
1717 for (i = 0; i < other.
len; i += len) {
1719 (&result ->
buffer -> data [buflen],
1720 &other.
data [i], offset, len));
1721 if (i + len != other.
len) {
1729 result ->
buffer -> data [buflen] = 0;
1735 #if defined (DEBUG_EXPRESSIONS)
1736 log_debug (
"data: binary-to-ascii (%s, %s, %s, %s) = %s",
1741 (status ?
print_hex_3 (result -> len, result -> data, 30)
1755 (&len, packet, lease, client_state, in_options,
1756 cfg_options, scope, expr -> data.reverse.width);
1759 memset (&data, 0,
sizeof data);
1762 in_options, cfg_options, scope,
1763 expr -> data.reverse.
buffer,
1771 if (data.
len % len) {
1772 log_info (
"reverse: %s %d %s %ld!",
1773 "length of buffer", data.
len,
1774 "not a multiple of width", len);
1781 data.
len, file, line)) {
1786 result -> data = &result ->
buffer -> data [0];
1787 result -> len = data.
len;
1788 result -> terminated = 0;
1790 for (i = 0; i < data.
len; i += len) {
1791 memcpy (&result ->
buffer -> data [i],
1792 &data.
data [data.
len - i - len], len);
1799 #if defined (DEBUG_EXPRESSIONS)
1800 log_debug (
"data: reverse (%s, %s) = %s",
1803 (status ?
print_hex_3 (result -> len, result -> data, 30)
1814 log_debug(
"data: \"leased-address\" configuration "
1815 "directive: there is no lease associated "
1816 "with this client.");
1822 result -> data = &result ->
buffer -> data [0];
1823 memcpy (&result ->
buffer -> data [0],
1825 result -> terminated = 0;
1827 log_error (
"data: leased-address: no memory.");
1830 #if defined (DEBUG_EXPRESSIONS)
1837 memset (&data, 0,
sizeof data);
1840 lease, client_state, in_options, cfg_options,
1841 scope, expr -> data.pick_first_value.car,
MDL))) {
1842 #if defined (DEBUG_EXPRESSIONS)
1843 log_debug (
"data: pick_first_value (%s, xxx)",
1845 result -> data, 40));
1850 if (expr -> data.pick_first_value.cdr &&
1853 lease, client_state, in_options, cfg_options,
1854 scope, expr -> data.pick_first_value.cdr,
MDL))) {
1855 #if defined (DEBUG_EXPRESSIONS)
1856 log_debug (
"data: pick_first_value (NULL, %s)",
1858 result -> data, 40));
1863 #if defined (DEBUG_EXPRESSIONS)
1864 log_debug (
"data: pick_first_value (NULL, NULL) = NULL");
1869 if (!lease || !lease -> host) {
1870 log_error (
"data: host_decl_name: not available");
1873 result -> len = strlen (lease -> host -> name);
1875 result -> len + 1, file, line)) {
1876 result -> data = &result ->
buffer -> data [0];
1877 strcpy ((
char *)&result ->
buffer -> data [0],
1878 lease -> host -> name);
1879 result -> terminated = 1;
1881 log_error (
"data: host-decl-name: no memory.");
1884 #if defined (DEBUG_EXPRESSIONS)
1885 log_debug (
"data: host-decl-name = %s", lease -> host -> name);
1890 #if defined (DEBUG_EXPRESSIONS)
1896 if (scope && *scope) {
1897 binding =
find_binding (*scope, expr -> data.variable);
1899 if (binding && binding -> value) {
1900 if (binding -> value -> type == binding_data) {
1902 &binding -> value -> value.data,
1905 }
else if (binding -> value -> type != binding_data) {
1907 binding -> value -> type,
1908 "evaluate_data_expression");
1916 #if defined (DEBUG_EXPRESSIONS)
1917 log_debug (
"data: %s = %s", expr -> data.variable,
1919 result -> data, 50) :
"NULL");
1926 in_options, cfg_options,
1930 log_error (
"%s() returned type %d in %s.",
1931 expr -> data.funcall.name,
1933 "evaluate_data_expression");
1939 #if defined (DEBUG_EXPRESSIONS)
1940 log_debug (
"data: %s = %s", expr -> data.funcall.name,
1942 result -> data, 50) :
"NULL");
1948 if (packet && packet -> raw -> file [0]) {
1950 memchr (packet -> raw -> file, 0,
1951 sizeof packet -> raw -> file);
1953 fn = ((
char *)packet -> raw -> file +
1954 sizeof packet -> raw -> file);
1955 result -> len = fn - &(packet -> raw -> file [0]);
1957 result -> len + 1, file, line)) {
1958 result -> data = &result ->
buffer -> data [0];
1959 memcpy (&result ->
buffer -> data [0],
1960 packet -> raw -> file,
1962 result ->
buffer -> data [result -> len] = 0;
1963 result -> terminated = 1;
1966 log_error (
"data: filename: no memory.");
1972 #if defined (DEBUG_EXPRESSIONS)
1973 log_info (
"data: filename = \"%s\"",
1974 s0 ? (
const char *)(result -> data) :
"NULL");
1980 if (packet && packet -> raw -> sname [0]) {
1982 memchr (packet -> raw -> sname, 0,
1983 sizeof packet -> raw -> sname);
1985 fn = ((
char *)packet -> raw -> sname +
1986 sizeof packet -> raw -> sname);
1987 result -> len = fn - &packet -> raw -> sname [0];
1989 result -> len + 1, file, line)) {
1990 result -> data = &result ->
buffer -> data [0];
1991 memcpy (&result ->
buffer -> data [0],
1992 packet -> raw -> sname,
1994 result ->
buffer -> data [result -> len] = 0;
1995 result -> terminated = 1;
2004 #if defined (DEBUG_EXPRESSIONS)
2006 s0 ? (
const char *)(result -> data) :
"NULL");
2019 memset(result, 0,
sizeof(*result));
2021 log_error(
"data: gethostname(): no memory for buffer");
2024 result->data = result->buffer->data;
2031 if (!gethostname((
char *)result->buffer->data, 255)) {
2032 if (result->buffer->data[255] ==
'\0')
2034 strlen((
char *)result->buffer->data);
2060 memset (&data, 0,
sizeof data);
2065 in_options, cfg_options,
2072 ((packet == NULL) ||
2074 #if defined (DEBUG_EXPRESSIONS)
2075 log_debug(
"data: v6relay(%d) = NULL", len);
2082 relay_packet = packet;
2083 relay_options = in_options;
2087 relay_options = relay_packet->
options;
2092 #if defined (DEBUG_EXPRESSIONS)
2093 log_debug(
"data: v6relay(%d) = NULL", len);
2099 client_state, relay_options,
2109 #if defined (DEBUG_EXPRESSIONS)
2110 log_debug(
"data: v6relay(%d) = %s", len,
2130 log_error (
"Boolean opcode in evaluate_data_expression: %d",
2149 log_error (
"Numeric opcode in evaluate_data_expression: %d",
2157 log_error (
"dns opcode in evaluate_boolean_expression: %d",
2162 log_error (
"function definition in evaluate_data_expression");
2169 log_error (
"Bogus opcode in evaluate_data_expression: %d", expr -> op);
2174 in_options, cfg_options, scope, expr)
2175 unsigned
long *result;
2185 int status, sleft, sright;
2189 unsigned long ileft, iright;
2192 switch (expr -> op) {
2207 log_error (
"Boolean opcode in evaluate_numeric_expression: %d",
2236 log_error (
"Data opcode in evaluate_numeric_expression: %d",
2241 memset (&data, 0,
sizeof data);
2243 (&data, packet, lease, client_state, in_options,
2244 cfg_options, scope, expr -> data.extract_int,
MDL);
2246 *result = data.
data [0];
2247 #if defined (DEBUG_EXPRESSIONS)
2248 log_debug (
"num: extract_int8 (%s) = %s",
2256 memset(&data, 0,
sizeof(data));
2258 (&data, packet, lease, client_state, in_options,
2260 if (status && data.
len >= 2) {
2264 #if defined (DEBUG_EXPRESSIONS)
2266 log_debug(
"num: extract_int16 (%s) = %ld",
2270 log_debug(
"num: extract_int16 (NULL) = NULL");
2279 memset (&data, 0,
sizeof data);
2281 (&data, packet, lease, client_state, in_options,
2282 cfg_options, scope, expr -> data.extract_int,
MDL));
2283 if (status && data.
len >= 4) {
2287 #if defined (DEBUG_EXPRESSIONS)
2289 log_debug (
"num: extract_int32 (%s) = %ld",
2293 log_debug (
"num: extract_int32 (NULL) = NULL");
2300 *result = expr -> data.const_int;
2301 #if defined (DEBUG_EXPRESSIONS)
2302 log_debug (
"number: CONSTANT = %ld", *result);
2308 log_error(
"data: leased_lease: not available");
2313 "data: lease_time: lease ends at",
2318 #if defined (DEBUG_EXPRESSIONS)
2319 log_debug(
"number: lease-time = (%lu - %lu) = %ld",
2320 (
long unsigned)lease->
ends,
2326 if (scope && *scope) {
2327 binding =
find_binding (*scope, expr -> data.variable);
2329 if (binding && binding ->
value) {
2336 "evaluate_numeric_expression");
2343 #if defined (DEBUG_EXPRESSIONS)
2346 expr -> data.variable, *result);
2349 expr -> data.variable);
2357 in_options, cfg_options,
2361 log_error (
"%s() returned type %d in %s.",
2362 expr -> data.funcall.name,
2364 "evaluate_numeric_expression");
2369 #if defined (DEBUG_EXPRESSIONS)
2370 log_debug (
"data: %s = %ld", expr -> data.funcall.name,
2371 status ? *result : 0);
2378 in_options, cfg_options,
2380 expr -> data.and [0]);
2383 in_options, cfg_options,
2385 expr -> data.and [1]);
2387 #if defined (DEBUG_EXPRESSIONS)
2388 if (sleft && sright)
2390 ileft, iright, ileft + iright);
2392 log_debug (
"num: %ld + NULL = NULL", ileft);
2394 log_debug (
"num: NULL + %ld = NULL", iright);
2396 if (sleft && sright) {
2397 *result = ileft + iright;
2405 in_options, cfg_options,
2407 expr -> data.and [0]);
2410 in_options, cfg_options,
2412 expr -> data.and [1]);
2414 #if defined (DEBUG_EXPRESSIONS)
2415 if (sleft && sright)
2417 ileft, iright, ileft - iright);
2419 log_debug (
"num: %ld - NULL = NULL", ileft);
2421 log_debug (
"num: NULL - %ld = NULL", iright);
2423 if (sleft && sright) {
2424 *result = ileft - iright;
2432 in_options, cfg_options,
2434 expr -> data.and [0]);
2437 in_options, cfg_options,
2439 expr -> data.and [1]);
2441 #if defined (DEBUG_EXPRESSIONS)
2442 if (sleft && sright)
2444 ileft, iright, ileft * iright);
2446 log_debug (
"num: %ld * NULL = NULL", ileft);
2448 log_debug (
"num: NULL * %ld = NULL", iright);
2450 if (sleft && sright) {
2451 *result = ileft * iright;
2459 in_options, cfg_options,
2461 expr -> data.and [0]);
2464 in_options, cfg_options,
2466 expr -> data.and [1]);
2468 #if defined (DEBUG_EXPRESSIONS)
2469 if (sleft && sright) {
2472 ileft, iright, ileft / iright);
2477 log_debug (
"num: %ld / NULL = NULL", ileft);
2479 log_debug (
"num: NULL / %ld = NULL", iright);
2481 if (sleft && sright && iright) {
2482 *result = ileft / iright;
2490 in_options, cfg_options,
2492 expr -> data.and [0]);
2495 in_options, cfg_options,
2497 expr -> data.and [1]);
2499 #if defined (DEBUG_EXPRESSIONS)
2500 if (sleft && sright) {
2503 ileft, iright, ileft % iright);
2508 log_debug (
"num: %ld %% NULL = NULL", ileft);
2510 log_debug (
"num: NULL %% %ld = NULL", iright);
2512 if (sleft && sright && iright) {
2513 *result = ileft % iright;
2521 in_options, cfg_options,
2523 expr -> data.and [0]);
2526 in_options, cfg_options,
2528 expr -> data.and [1]);
2530 #if defined (DEBUG_EXPRESSIONS)
2531 if (sleft && sright)
2533 ileft, iright, ileft & iright);
2535 log_debug (
"num: %ld & NULL = NULL", ileft);
2537 log_debug (
"num: NULL & %ld = NULL", iright);
2539 if (sleft && sright) {
2540 *result = ileft & iright;
2548 in_options, cfg_options,
2550 expr -> data.and [0]);
2553 in_options, cfg_options,
2555 expr -> data.and [1]);
2557 #if defined (DEBUG_EXPRESSIONS)
2558 if (sleft && sright)
2560 ileft, iright, ileft | iright);
2562 log_debug (
"num: %ld | NULL = NULL", ileft);
2564 log_debug (
"num: NULL | %ld = NULL", iright);
2566 if (sleft && sright) {
2567 *result = ileft | iright;
2575 in_options, cfg_options,
2577 expr -> data.and [0]);
2580 in_options, cfg_options,
2582 expr -> data.and [1]);
2584 #if defined (DEBUG_EXPRESSIONS)
2585 if (sleft && sright)
2587 ileft, iright, ileft ^ iright);
2589 log_debug (
"num: %ld ^ NULL = NULL", ileft);
2591 log_debug (
"num: NULL ^ %ld = NULL", iright);
2593 if (sleft && sright) {
2594 *result = ileft ^ iright;
2601 #if defined (DEBUG_EXPRESSIONS)
2603 client_state -> state);
2605 *result = client_state -> state;
2608 #if defined (DEBUG_EXPRESSIONS)
2615 log_error (
"function definition in evaluate_numeric_expr");
2622 log_fatal(
"Impossible case at %s:%d. Undefined operator "
2623 "%d.",
MDL, expr->
op);
2627 log_error (
"evaluate_numeric_expression: bogus opcode %d", expr -> op);
2644 in_options, cfg_options, scope, oc,
file,
line)
2663 in_options, cfg_options, scope,
2672 cfg_options, scope, oc,
file,
line)
2688 if (!oc || !in_options)
2691 memset (&ds, 0,
sizeof ds);
2693 lease, client_state, in_options,
2694 cfg_options, scope, oc, file, line))
2701 result = ds.
data [0];
2704 if (ignorep != NULL)
2706 }
else if (ignorep != NULL)
2719 in_options, cfg_options, scope, expr)
2736 in_options, cfg_options,
2767 if (expr ->
refcnt < 0) {
2768 log_error (
"%s(%d): negative refcnt!", file, line);
2769 #if defined (DEBUG_RC_HISTORY)
2770 dump_rc_history (expr);
2772 #if defined (POINTER_DEBUG)
2780 switch (expr ->
op) {
3055 static int op_val (
enum expr_op);
3057 static int op_val (
op)
3140 return op_val (op1) - op_val (op2);
3253 switch (expr -> op) {
3285 col, indent + 2, 0);
3361 (file, col, indent,
"",
"",
3410 expr ->
data.
not, col, indent + 2, 1);
3467 sprintf (obuf,
"%d", width);
3490 sprintf (obuf,
"%d", width);
3511 goto print_option_name;
3573 s =
"config-option";
3574 goto print_option_name;
3685 log_fatal (
"invalid expression type in print_expression: %d",
3696 for (s = scope; s; s = s ->
outer) {
3697 for (bp = s ->
bindings; bp; bp = bp -> next) {
3698 if (!strcasecmp (name, bp -> name)) {
3710 for (bp = scope -> bindings; bp; bp =
next) {
3716 dfree (bp, file, line);
3718 scope -> bindings = (
struct binding *)0;
3729 if (!ptr || !*ptr) {
3730 log_error (
"%s(%d): null pointer", file, line);
3731 #if defined (POINTER_DEBUG)
3738 binding_scope = *ptr;
3739 *ptr = (
struct binding_scope *)0;
3740 --binding_scope ->
refcnt;
3743 if (binding_scope ->
refcnt > 0)
3746 if (binding_scope ->
refcnt < 0) {
3747 log_error (
"%s(%d): negative refcnt!", file, line);
3748 #if defined (DEBUG_RC_HISTORY)
3749 dump_rc_history (binding_scope);
3751 #if defined (POINTER_DEBUG)
3759 if (binding_scope ->
outer)
3761 dfree (binding_scope, file, line);
3773 if ((ptr == NULL) || (*ptr == NULL)) {
3774 log_error (
"%s(%d): null pointer", file, line);
3775 #if defined (POINTER_DEBUG)
3785 if (bp -> refcnt < 0) {
3786 log_error (
"%s(%d): negative refcnt!", file, line);
3787 #if defined (DEBUG_RC_HISTORY)
3788 dump_rc_history (bp);
3790 #if defined (POINTER_DEBUG)
3796 if (!bp -> refcnt) {
3797 for (sp = bp -> args; sp; sp =
next) {
3799 dfree (sp, file, line);
3801 if (bp -> statements)
3804 dfree (bp, file, line);
3806 *ptr = (
struct fundef *)0;
3810 #if defined (NOTYET)
3814 int crhs, clhs, llhs, lrhs;
3815 switch (expr -> op) {
3817 if (expr -> data.substring.len &&
3820 (
int)expr -> data.substring.len -> data.const_int);
3827 if (expr -> data.suffix.len &&
3830 (
int)expr -> data.suffix.len -> data.const_int);
3843 expr -> data.concat [0]);
3845 expr -> data.concat [1]);
3846 if (crhs == 0 || clhs == 0)
3856 *rv = expr -> data.const_data.len;
3861 expr -> data.reverse.buffer);
3870 expr -> data.concat [0]);
3872 expr -> data.concat [1]);
3873 if (crhs == 0 || clhs == 0)
3883 expr -> data.v6relay.relay);
3885 expr -> data.v6relay.roption);
3886 if (crhs == 0 || clhs == 0)
3991 return (
struct binding *)0;
3998 return (
struct binding *)0;
4000 memset (binding, 0,
sizeof *binding);
4001 binding -> name =
dmalloc (strlen (name) + 1,
MDL);
4002 if (!binding -> name) {
4004 return (
struct binding *)0;
4006 strcpy (binding -> name, name);
4008 binding ->
next = (*scope) -> bindings;
4009 (*scope) -> bindings = binding;
4026 if (binding -> value)
4033 binding -> value -> type = binding_data;
4047 !binding -> value ||
4048 binding -> value -> type != binding_data)
4051 if (binding -> value -> value.
data.terminated) {
4060 memcpy (value ->
buffer -> data,
4061 binding -> value -> value.
data.data,
4062 binding -> value -> value.
data.len);
4063 value -> data = value ->
buffer -> data;
4064 value -> len = binding -> value -> value.
data.len;
4076 if (binding ->
value)
#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)
u_int32_t getUShort(const unsigned char *)
void dfree(void *, const char *, int)
struct expression * buffer
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
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