942 if (b->vb_ip.af != AF_INET)
goto fail_cmp_v4;
949 if (b->vb_ip.af != AF_INET)
goto fail_cmp_v4;
954 b->vb_ip.prefix, (
uint8_t const *) &b->vb_ip.addr.v4.s_addr);
966 if (b->vb_ip.af != AF_INET)
goto fail_cmp_v4;
971 (
uint8_t const *) &a->vb_ip.addr.v4.s_addr,
972 32, (
uint8_t const *) &b->vb_ip.addr.v4);
975 if (b->vb_ip.af != AF_INET)
goto fail_cmp_v4;
980 (
uint8_t const *) &a->vb_ip.addr.v4.s_addr,
981 b->vb_ip.prefix, (
uint8_t const *) &b->vb_ip.addr.v4.s_addr);
991 if (b->vb_ip.af != AF_INET6)
goto fail_cmp_v6;
998 if (b->vb_ip.af != AF_INET6)
goto fail_cmp_v6;
1003 b->vb_ip.prefix, (
uint8_t const *) &b->vb_ip.addr.v6);
1015 if (b->vb_ip.af != AF_INET6)
goto fail_cmp_v6;
1020 (
uint8_t const *) &a->vb_ip.addr.v6,
1021 128, (
uint8_t const *) &b->vb_ip.addr.v6);
1024 if (b->vb_ip.af != AF_INET6)
goto fail_cmp_v6;
1029 (
uint8_t const *) &a->vb_ip.addr.v6,
1030 b->vb_ip.prefix, (
uint8_t const *) &b->vb_ip.addr.v6);
1038 if (a->vb_ip.af != b->vb_ip.af)
goto fail_cmp_v4;
1043 if (a->vb_ip.af != b->vb_ip.af)
goto fail_cmp_v4;
1045 if (a->vb_ip.af == AF_INET)
goto cmp_prefix_v4;
1062 return (compare == 0);
1065 return (compare != 0);
1068 return (compare < 0);
1071 return (compare > 0);
1074 return (compare <= 0);
1077 return (compare >= 0);
1423 switch (
value->type) {
1426 max =
value->vb_length;
1433 if (
value->enumv->flags.length) {
1437 if (max < value->enumv->flags.length) {
1442 }
else if (max >
value->enumv->flags.length) {
1446 max =
value->enumv->flags.length;
1454 if (max > 255) max = 255;
1458 if (max > 65536) max = 65535;
1492 switch (
value->type) {
1497 sizeof(
value->vb_ip.addr.v4.s_addr));
1507 sizeof(
value->vb_ip.addr.v4.s_addr));
1528 switch (
value->vb_ip.af) {
1543 switch (
value->vb_ip.af) {
1598 if (!
value->enumv) {
1601 res =
value->enumv->flags.flag_time_res;
1605 if (!
value->enumv) {
1608 }
else switch (
value->enumv->flags.length) {
1610 if (date > UINT16_MAX) date = UINT16_MAX;
1616 if (date > UINT32_MAX) date = UINT32_MAX;
1635 if (
value->enumv) res =
value->enumv->flags.flag_time_res;
1639 if (!
value->enumv) {
1642 }
else if (!
value->enumv->flags.is_unsigned) {
1643 switch (
value->enumv->flags.length) {
1645 if (date < INT16_MIN) {
1647 }
else if (date > INT16_MAX) {
1655 if (date < INT32_MIN) {
1657 }
else if (date > INT32_MAX) {
1671 switch (
value->enumv->flags.length) {
1675 }
else if (date > UINT16_MAX) {
1684 }
else if (date > UINT32_MAX) {
1767 "Expected length >= %zu bytes, got %zu bytes",
1777 if (enumv && !enumv->flags.array) {
1779 "Expected length <= %zu bytes, got %zu bytes",
1792 size_t newlen = len;
1799 if (enumv->flags.length) {
1800 newlen = enumv->flags.length;
1831 if (newlen > len)
return -(newlen + offset);
1889 dst->vb_ip.scope_id = scope_id;
1905 dst->vb_ip.scope_id = scope_id;
1933 dst->datum.boolean = (val != 0);
1996 length = enumv->flags.length;
2004 if (len > length)
return -(length);
2026 length = enumv->flags.length;
2034 if (len > length)
return -(length);
2038 if (!enumv || !enumv->flags.is_unsigned) {
2050 if (tmp > INT64_MAX) tmp = INT64_MAX;
2262 switch (src->type) {
2268 (
uint8_t const *)src->vb_strvalue, src->vb_length, src->tainted) < 0) {
2275 dst,
UNCONST(fr_value_box_list_t *, &src->vb_group),
2284 (
uint8_t const *)&src->vb_ip.addr.v4.s_addr,
2285 sizeof(src->vb_ip.addr.v4.s_addr), src->tainted);
2295 sizeof(src->vb_ip.addr.v4.s_addr) + 1, src->tainted) < 0)
return -1;
2297 bin[0] = src->vb_ip.prefix;
2298 memcpy(&bin[1], (
uint8_t const *)&src->vb_ip.addr.v4.s_addr,
sizeof(src->vb_ip.addr.v4.s_addr));
2307 (
uint8_t const *)src->vb_ip.addr.v6.s6_addr,
2308 sizeof(src->vb_ip.addr.v6.s6_addr), src->tainted);
2318 sizeof(src->vb_ip.addr.v6.s6_addr) + 2, src->tainted) < 0)
return -1;
2319 bin[0] = src->vb_ip.scope_id;
2320 bin[1] = src->vb_ip.prefix;
2321 memcpy(&bin[2], src->vb_ip.addr.v6.s6_addr,
sizeof(src->vb_ip.addr.v6.s6_addr));
2389 src->vb_strvalue, src->vb_length,
2390 NULL, src->tainted);
2402 dst->vb_ip.af = AF_INET;
2403 dst->vb_ip.prefix = 32;
2404 dst->vb_ip.scope_id = 0;
2416 memcpy(&dst->vb_ip.addr.v4, &src->vb_ip.addr.v6.s6_addr[
sizeof(
v4_v6_map)],
2417 sizeof(dst->vb_ip.addr.v4));
2422 if (src->vb_ip.prefix != 32) {
2424 "cast to IP address types",
2433 memcpy(&dst->vb_ip.addr.v4, &src->vb_ip.addr.v4,
sizeof(dst->vb_ip.addr.v4));
2437 if (src->vb_ip.prefix != 128) {
2438 fr_strerror_printf(
"Invalid cast from %s to %s. Only /128 (not /%i) prefixes may be "
2439 "cast to IP address types",
2445 if (memcmp(&src->vb_ip.addr.v6.s6_addr,
v4_v6_map,
sizeof(
v4_v6_map)) != 0)
goto bad_v6_prefix_map;
2446 memcpy(&dst->vb_ip.addr.v4, &src->vb_ip.addr.v6.s6_addr[
sizeof(
v4_v6_map)],
2447 sizeof(dst->vb_ip.addr.v4));
2451 if (src->vb_length !=
sizeof(dst->vb_ip.addr.v4.s_addr)) {
2452 fr_strerror_printf(
"Invalid cast from %s to %s. Needed octet string of length %zu, got %zu",
2455 sizeof(dst->vb_ip.addr.v4.s_addr), src->vb_length);
2458 memcpy(&dst->vb_ip.addr.v4, src->vb_octets,
sizeof(dst->vb_ip.addr.v4.s_addr));
2465 net = ntohl(src->vb_uint32);
2466 memcpy(&dst->vb_ip.addr.v4, (
uint8_t *)&net,
sizeof(dst->vb_ip.addr.v4.s_addr));
2504 src->vb_strvalue, src->vb_length,
2505 NULL, src->tainted);
2517 dst->vb_ip.af = AF_INET;
2518 dst->vb_ip.scope_id = 0;
2522 dst->vb_ip.prefix = src->vb_ip.prefix;
2526 memcpy(&dst->vb_ip, &src->vb_ip,
sizeof(dst->vb_ip));
2540 memcpy(&dst->vb_ip.addr.v4.s_addr, &src->vb_ip.addr.v6.s6_addr[
sizeof(
v4_v6_map)],
2541 sizeof(dst->vb_ip.addr.v4.s_addr));
2542 dst->vb_ip.prefix = 32;
2546 if (memcmp(src->vb_ip.addr.v6.s6_addr,
v4_v6_map,
sizeof(
v4_v6_map)) != 0)
goto bad_v6_prefix_map;
2548 if (src->vb_ip.prefix < (
sizeof(
v4_v6_map) << 3)) {
2549 fr_strerror_printf(
"Invalid cast from %s to %s. Expected prefix >= %u bits got %u bits",
2552 (
unsigned int)(
sizeof(
v4_v6_map) << 3), src->vb_ip.prefix);
2555 memcpy(&dst->vb_ip.addr.v4.s_addr, &src->vb_ip.addr.v6.s6_addr[
sizeof(
v4_v6_map)],
2556 sizeof(dst->vb_ip.addr.v4.s_addr));
2561 dst->vb_ip.prefix = src->vb_ip.prefix - (
sizeof(
v4_v6_map) << 3);
2565 if (src->vb_length !=
sizeof(dst->vb_ip.addr.v4.s_addr) + 1) {
2566 fr_strerror_printf(
"Invalid cast from %s to %s. Needed octet string of length %zu, got %zu",
2569 sizeof(dst->vb_ip.addr.v4.s_addr) + 1, src->vb_length);
2572 dst->vb_ip.prefix = src->vb_octets[0];
2573 memcpy(&dst->vb_ip.addr.v4, &src->vb_octets[1],
sizeof(dst->vb_ip.addr.v4.s_addr));
2580 net = ntohl(src->vb_uint32);
2581 memcpy(&dst->vb_ip.addr.v4, (
uint8_t *)&net,
sizeof(dst->vb_ip.addr.v4.s_addr));
2582 dst->vb_ip.prefix = 32;
2616 static_assert((
sizeof(
v4_v6_map) +
sizeof(src->vb_ip.addr.v4)) <=
2617 sizeof(src->vb_ip.addr.v6),
"IPv6 storage too small");
2623 src->vb_strvalue, src->vb_length,
2624 NULL, src->tainted);
2636 dst->vb_ip.af = AF_INET6;
2637 dst->vb_ip.prefix = 128;
2642 uint8_t *p = dst->vb_ip.addr.v6.s6_addr;
2647 memcpy(p, (
uint8_t const *)&src->vb_ip.addr.v4.s_addr,
sizeof(src->vb_ip.addr.v4.s_addr));
2648 dst->vb_ip.scope_id = 0;
2654 uint8_t *p = dst->vb_ip.addr.v6.s6_addr;
2656 if (src->vb_ip.prefix != 32) {
2658 "cast to IP address types",
2668 memcpy(p, (
uint8_t const *)&src->vb_ip.addr.v4.s_addr,
sizeof(src->vb_ip.addr.v4.s_addr));
2669 dst->vb_ip.scope_id = 0;
2674 if (src->vb_ip.prefix != 128) {
2675 fr_strerror_printf(
"Invalid cast from %s to %s. Only /128 (not /%i) prefixes may be "
2676 "cast to IP address types",
2685 memcpy(dst->vb_ip.addr.v6.s6_addr, src->vb_ip.addr.v6.s6_addr,
2686 sizeof(dst->vb_ip.addr.v6.s6_addr));
2687 dst->vb_ip.scope_id = src->vb_ip.scope_id;
2691 if (src->vb_length !=
sizeof(dst->vb_ip.addr.v6.s6_addr)) {
2692 fr_strerror_printf(
"Invalid cast from %s to %s. Needed octet string of length %zu, got %zu",
2695 sizeof(dst->vb_ip.addr.v6.s6_addr), src->vb_length);
2698 memcpy(&dst->vb_ip.addr.v6.s6_addr, src->vb_octets,
sizeof(dst->vb_ip.addr.v6.s6_addr));
2736 src->vb_strvalue, src->vb_length,
2737 NULL, src->tainted);
2749 dst->vb_ip.af = AF_INET6;
2754 uint8_t *p = dst->vb_ip.addr.v6.s6_addr;
2759 memcpy(p, (
uint8_t const *)&src->vb_ip.addr.v4.s_addr,
sizeof(src->vb_ip.addr.v4.s_addr));
2760 dst->vb_ip.prefix = 128;
2761 dst->vb_ip.scope_id = 0;
2767 uint8_t *p = dst->vb_ip.addr.v6.s6_addr;
2772 memcpy(p, (
uint8_t const *)&src->vb_ip.addr.v4.s_addr,
sizeof(src->vb_ip.addr.v4.s_addr));
2773 dst->vb_ip.prefix = (
sizeof(
v4_v6_map) << 3) + src->vb_ip.prefix;
2774 dst->vb_ip.scope_id = 0;
2779 dst->vb_ip.prefix = src->vb_ip.prefix;
2783 dst->vb_ip.prefix = 128;
2785 memcpy(dst->vb_ip.addr.v6.s6_addr, src->vb_ip.addr.v6.s6_addr,
2786 sizeof(dst->vb_ip.addr.v6.s6_addr));
2787 dst->vb_ip.scope_id = src->vb_ip.scope_id;
2791 if (src->vb_length != (
sizeof(dst->vb_ip.addr.v6.s6_addr) + 2)) {
2792 fr_strerror_printf(
"Invalid cast from %s to %s. Needed octet string of length %zu, got %zu",
2795 sizeof(dst->vb_ip.addr.v6.s6_addr) + 2, src->vb_length);
2798 dst->vb_ip.scope_id = src->vb_octets[0];
2799 dst->vb_ip.prefix = src->vb_octets[1];
2800 memcpy(&dst->vb_ip.addr.v6.s6_addr, src->vb_octets,
sizeof(dst->vb_ip.addr.v6.s6_addr));
2831 switch (src->type) {
2834 src->vb_strvalue, src->vb_length,
2835 NULL, src->tainted);
2849 switch (src->type) {
2858 if ((array[0] != 0) || (array[1] != 0))
return -1;
2860 memcpy(dst->vb_ether, &array[2], 6);
2891 switch (src->type) {
2894 src->vb_strvalue, src->vb_length,
2895 NULL, src->tainted);
2912 switch (src->type) {
2914 dst->vb_bool = (src->vb_int8 != 0);
2918 dst->vb_bool = (src->vb_uint8 != 0);
2922 dst->vb_bool = (src->vb_int16 != 0);
2926 dst->vb_bool = (src->vb_uint16 != 0);
2930 dst->vb_bool = (src->vb_int32 != 0);
2934 dst->vb_bool = (src->vb_uint32 != 0);
2938 dst->vb_bool = (src->vb_int64 != 0);
2942 dst->vb_bool = (src->vb_uint64 != 0);
2946 dst->vb_bool = (src->vb_size != 0);
2954 dst->vb_bool = (fpclassify(src->vb_float32) == FP_ZERO);
2958 dst->vb_bool = (fpclassify(src->vb_float64) == FP_ZERO);
3133 switch (src->type) {
3136 src->vb_strvalue, src->vb_length,
3137 NULL, src->tainted);
3163 memcpy(&tmp.vb_uint32, &src->vb_ip.addr.v4,
sizeof(tmp.vb_uint32));
3184 memcpy(((
uint8_t *)&tmp.vb_uint64) + (
sizeof(tmp.vb_uint64) -
sizeof(src->vb_ether)),
3185 &src->vb_ether,
sizeof(src->vb_ether));
3186#ifndef WORDS_BIGENDIAN
3382 if (dst_type == src->type) {
3386 if (ret < 0)
return ret;
3388 dst->enumv = dst_enumv;
3443 dst->type = dst_type;
3444 dst->enumv = dst_enumv;
3460 if (when > INT64_MAX) {
3465 dst->type = dst_type;
3466 dst->enumv = dst_enumv;
3508 src->vb_strvalue, src->vb_length,
3509 NULL, src->tainted);
3515 fr_strerror_printf(
"Invalid cast from %s to %s. Source is length %zu is smaller than "
3516 "destination type size %zu",
3526 "destination type size %zu",
3541 tmp.type = dst_type;
3542 dst->enumv = dst_enumv;
3550 dst->type = dst_type;
3551 dst->enumv = dst_enumv;
4289 if (len == 0)
return 0;
4298 ptr = dst->datum.ptr;
4301 if (talloc_reference_count(ptr) > 0) {
4306 nlen = dst->vb_length + len + 1;
4307 nptr = talloc_realloc(ctx, ptr,
char, dst->vb_length + len + 1);
4310 __FUNCTION__, talloc_get_name(ptr), talloc_array_length(ptr), nlen);
4313 talloc_set_type(nptr,
char);
4316 memcpy(ptr + dst->vb_length, src, len);
4318 dst->tainted = dst->tainted || tainted;
4319 dst->datum.ptr = ptr;
4320 dst->vb_length += len;
4322 ptr[dst->vb_length] =
'\0';
4592 if (len == 0)
return 0;
4603 if (talloc_reference_count(dst->datum.ptr) > 0) {
4608 nlen = dst->vb_length + len;
4609 nptr = talloc_realloc(ctx, dst->datum.ptr,
uint8_t, dst->vb_length + len);
4613 talloc_get_name(dst->datum.ptr),
4614 talloc_array_length((
uint8_t const *)dst->datum.ptr), nlen);
4618 memcpy(nptr + dst->vb_length, src, len);
4620 dst->tainted = dst->tainted || tainted;
4621 dst->datum.ptr = nptr;
4622 dst->vb_length += len;
4652 vb->vb_uint8 = vb->vb_uint8 ==
UINT8_MAX ? 0 : vb->vb_uint8 + 1;
4656 vb->vb_uint16 = vb->vb_uint16 == UINT16_MAX ? 0 : vb->vb_uint16 + 1;
4660 vb->vb_uint32 = vb->vb_uint32 == UINT32_MAX ? 0 : vb->vb_uint32 + 1;
4664 vb->vb_uint64 = vb->vb_uint64 == UINT64_MAX ? 0 : vb->vb_uint64 + 1;
4668 vb->vb_int8 = vb->vb_int8 == INT8_MAX ? INT8_MIN : vb->vb_int8 + 1;
4672 vb->vb_int16 = vb->vb_int16 == INT16_MAX ? INT16_MIN : vb->vb_int16 + 1;
4676 vb->vb_int32 = vb->vb_int32 == INT32_MAX ? INT32_MIN : vb->vb_int32 + 1;
4680 vb->vb_int64 = vb->vb_int64 == INT64_MAX ? INT64_MIN : vb->vb_int64 + 1;
4804 fr_sbuff_t *
in, fr_sbuff_parse_rules_t
const *rules,
bool tainted)
4806 static fr_sbuff_parse_rules_t default_rules;
4813 if (!rules) rules = &default_rules;
4820 if (dst_enumv && dst_enumv->flags.has_value) {
4837 if (!rules->escapes) {
4841 fr_sbuff_marker(&m, &our_in);
4846 fr_sbuff_marker_release(&m);
4848 if (!len)
goto parse;
4882 rules->terminals, rules->escapes);
4884 fr_sbuff_set_to_start(&our_in);
4890 fr_sbuff_set_to_start(&our_in);
4913 if (!dst_enumv || !unescaped) {
4916 if (
unlikely(fr_sbuff_out_aunescape_until(ctx, &
buff, &our_in, SIZE_MAX,
4917 rules->terminals, rules->escapes) < 0)) {
4943 if (!dst_enumv || !unescaped) {
4948 fr_sbuff_out_aunescape_until(ctx, &
buff, &our_in, SIZE_MAX,
4949 rules->terminals, rules->escapes);
4951 if (talloc_array_length(
buff) == 1) {
4956 bin = talloc_realloc(ctx,
buff,
uint8_t, talloc_array_length(
buff) - 1);
4962 talloc_set_type(bin,
uint8_t);
4973 bin = talloc_zero_array(ctx,
uint8_t, 0);
4988 fr_sbuff_marker(&hex_start, &our_in);
5005 if ((hex_len & 0x01) != 0) {
5031 if (!name_len)
return 0;
5043 "for non-prefix types", addr.
prefix);
5047 memcpy(&dst->vb_ip, &addr,
sizeof(dst->vb_ip));
5054 if (!name_len)
return 0;
5064 if (!name_len)
return 0;
5080 if (addr.
prefix != 128) {
5083 "for non-prefix types", addr.
prefix);
5087 memcpy(&dst->vb_ip, &addr,
sizeof(dst->vb_ip));
5094 if (!name_len)
return 0;
5104 if (!name_len)
return 0;
5116 if ((addr.
af == AF_INET) && (addr.
prefix != 32)) {
5117 goto fail_ipv4_prefix;
5120 if ((addr.
af == AF_INET6) && (addr.
prefix != 128)) {
5121 goto fail_ipv6_prefix;
5124 memcpy(&dst->vb_ip, &addr,
sizeof(dst->vb_ip));
5131 if (!name_len)
return 0;
5161 if (slen >= 0)
return slen;
5167 if (!rules->escapes) {
5173 dst->vb_bool = (stmp != 0);
5179 dst->vb_bool = (utmp != 0);
5185 "\"yes\", \"no\", \"true\", \"false\" or any unquoted integer");
5225 fr_sbuff_set_to_start(&our_in);
5230 fr_sbuff_parse_error_to_strerror(
err);
5273 false, rules->terminals);
5274 if (slen < 0)
return slen;
5296 if (rules && rules->terminals) {
5300 rules->terminals, rules->escapes);
5301 if (len >=
sizeof(
buffer))
goto too_small;
5332 dst->enumv = dst_enumv;
5349 dst->type = dst_type;
5350 dst->tainted = tainted;
5355 dst->enumv = dst_enumv;
5356 fr_value_box_list_entry_init(dst);