31 #include <freeradius-devel/io/test_point.h>
32 #include <freeradius-devel/util/dns.h>
33 #include <freeradius-devel/util/proto.h>
34 #include <freeradius-devel/util/struct.h>
41 uint8_t const *
data,
size_t const data_len,
void *decode_ctx);
45 uint8_t const *
data,
size_t const data_len,
void *decode_ctx)
52 uint8_t const *
data,
size_t const data_len,
void *decode_ctx);
59 uint8_t const *
data,
size_t const data_len,
void *decode_ctx)
71 uint8_t const *
data,
size_t const data_len,
void *decode_ctx)
95 if (data_len != (1 +
sizeof(
vp->vp_ipv6addr))) {
102 vp->vp_ip.af = AF_INET6;
103 vp->vp_ip.scope_id = 0;
104 vp->vp_ip.prefix =
data[0];
105 memcpy(&
vp->vp_ipv6addr,
data + 1,
sizeof(
vp->vp_ipv6addr));
106 slen = 1 +
sizeof(
vp->vp_ipv6addr);
114 if (
data[0] != 0)
goto raw;
119 vp->vp_ip.af = AF_INET6;
124 prefix_len =
data[0];
131 if ((
size_t) slen > (data_len - 1)) {
138 vp->vp_ip.af = AF_INET6;
139 vp->vp_ip.prefix = prefix_len;
140 memcpy(&
vp->vp_ipv6addr,
data + 1, slen);
151 if (data_len != 0)
goto raw;
181 if (slen < 0)
goto raw;
183 if (
parent->flags.array)
return slen;
197 if (!
proto->decode) {
204 if (slen < 0)
goto raw_free;
206 vp->vp_tainted =
true;
214 if (slen < 0)
goto raw_free;
227 if (data_len <
sizeof(
vp->vp_ipv6addr))
goto raw;
231 if (slen < 0)
goto raw_free;
240 if (slen < 0)
goto raw_free;
247 if (!
parent->flags.array && ((
size_t) slen < data_len)) {
254 vp->vp_tainted =
true;
257 if (
parent->flags.array)
return slen;
265 uint8_t const *
data,
size_t const data_len,
void *decode_ctx)
275 "%s: Internal sanity check failed, attribute \"%s\" is not of type 'vsa'",
283 memcpy(&pen,
data,
sizeof(pen));
315 uint8_t const *
data,
size_t const data_len,
void *decode_ctx)
323 #ifdef STATIC_ANALYZER
337 if (len > (data_len - 4)) {
339 "Optional length must be less than %zu bytes, got %zu bytes",
340 __FUNCTION__, data_len - 4, len);
349 FR_PROTO_TRACE(
"decode context changed %s -> %s",da->parent->name, da->name);
366 if (slen < 0)
return slen;
374 if (slen < 0)
return slen;
376 }
else if (da->flags.array) {
407 if (slen < 0)
goto raw;
422 uint8_t const *
data,
size_t data_len,
void *decode_ctx)
449 end =
data + data_len;
464 return -slen - (attr -
data);
468 talloc_free_children(decode_ctx.
tmp_ctx);
480 if (!test_ctx)
return -1;
491 size_t packet_len = data_len;
501 uint8_t const *
data,
size_t data_len,
void *decode_ctx)
#define FR_DBUFF_TMP(_start, _len_or_end)
Creates a compound literal to pass into functions which accept a dbuff.
#define fr_cond_assert(_x)
Calls panic_action ifndef NDEBUG, else logs error and evaluates to value of _x.
#define fr_cond_assert_msg(_x, _fmt,...)
Calls panic_action ifndef NDEBUG, else logs error and evaluates to value of _x.
Implementation of the DHCPv6 protocol.
#define DHCPV6_GET_OPTION_NUM(_x)
#define DHCPV6_GET_OPTION_LEN(_x)
static bool fr_dhcpv6_flag_any_dns_label(fr_dict_attr_t const *da)
#define DHCPV6_DATE_OFFSET
TALLOC_CTX * tmp_ctx
for temporary things cleaned up during decoding
static fr_dict_attr_t * fr_dict_attr_unknown_vendor_afrom_num(TALLOC_CTX *ctx, fr_dict_attr_t const *parent, unsigned int vendor)
fr_dict_attr_t const * fr_dict_root(fr_dict_t const *dict)
Return the root attribute of a dictionary.
static fr_dict_attr_t * fr_dict_attr_unknown_raw_afrom_num(TALLOC_CTX *ctx, fr_dict_attr_t const *parent, unsigned int attr)
fr_dict_attr_t const * fr_dict_attr_child_by_num(fr_dict_attr_t const *parent, unsigned int attr)
Check if a child attribute exists in a parent using an attribute number.
fr_dict_protocol_t const * fr_dict_protocol(fr_dict_t const *dict)
Return the protocol descriptor for the dictionary.
Protocol-specific callbacks in libfreeradius-PROTOCOL.
static fr_dict_attr_t const * fr_dict_attr_ref(fr_dict_attr_t const *da)
Return the reference associated with a group type attribute.
#define PAIR_DECODE_OOM
Fatal error - Out of memory.
#define PAIR_DECODE_FATAL_ERROR
Fatal error - Failed decoding the packet.
ssize_t fr_pair_tlvs_from_network(TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dict_attr_t const *parent, uint8_t const *data, size_t const data_len, void *decode_ctx, fr_pair_decode_value_t decode_tlv, fr_pair_tlvs_verify_t verify_tlvs, bool nested)
Decode a list of pairs from the network.
ssize_t fr_pair_dns_labels_from_network(TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dict_attr_t const *parent, uint8_t const *start, uint8_t const *data, size_t const data_len, fr_dns_labels_t *lb, bool exact)
Decode a DNS label or a list of DNS labels from the network.
ssize_t fr_pair_array_from_network(TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dict_attr_t const *parent, uint8_t const *data, size_t data_len, void *decode_ctx, fr_pair_decode_value_t decode_value)
Decode an array of values from the network.
ssize_t fr_pair_raw_from_network(TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dict_attr_t const *parent, uint8_t const *data, size_t data_len)
Create a "raw" pair from the network data.
@ FR_TYPE_TLV
Contains nested attributes.
@ FR_TYPE_IPV6_PREFIX
IPv6 Prefix.
@ FR_TYPE_STRING
String of printable characters.
@ FR_TYPE_DATE
Unix time stamp, always has value >2^31.
@ FR_TYPE_STRUCT
like TLV, but without T or L, and fixed-width children
@ FR_TYPE_IPV6_ADDR
128 Bit IPv6 Address.
@ FR_TYPE_BOOL
A truth value.
@ FR_TYPE_VSA
Vendor-Specific, for RADIUS attribute 26.
@ FR_TYPE_GROUP
A grouping of other attributes.
static unsigned int fr_bytes_from_bits(unsigned int bits)
Convert bits (as in prefix length) to bytes, rounding up.
fr_pair_t * fr_pair_find_by_da(fr_pair_list_t const *list, fr_pair_t const *prev, fr_dict_attr_t const *da)
Find the first pair with a matching da.
fr_pair_t * fr_pair_afrom_da(TALLOC_CTX *ctx, fr_dict_attr_t const *da)
Dynamically allocate a new attribute and assign a fr_dict_attr_t.
int fr_pair_append(fr_pair_list_t *list, fr_pair_t *to_add)
Add a VP to the end of the list.
static fr_dict_t const * dict_dhcpv6
static fr_dict_attr_t const * attr_relay_message
bool fr_dhcpv6_ok(uint8_t const *packet, size_t packet_len, uint32_t max_attributes)
See if the data pointed to by PTR is a valid DHCPv6 packet.
ssize_t fr_dhcpv6_decode(TALLOC_CTX *ctx, fr_pair_list_t *out, uint8_t const *packet, size_t packet_len)
Decode a DHCPv6 packet.
static ssize_t decode_option(TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dict_attr_t const *parent, uint8_t const *data, size_t const data_len, void *decode_ctx)
ssize_t fr_dhcpv6_decode_option(TALLOC_CTX *ctx, fr_pair_list_t *out, uint8_t const *data, size_t data_len, void *decode_ctx)
Create a "normal" fr_pair_t from the given data.
fr_test_point_pair_decode_t dhcpv6_tp_decode_pair
static int decode_test_ctx(void **out, TALLOC_CTX *ctx)
fr_test_point_proto_decode_t dhcpv6_tp_decode_proto
static ssize_t decode_value(TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dict_attr_t const *parent, uint8_t const *data, size_t const data_len, void *decode_ctx)
static ssize_t decode_value_trampoline(TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dict_attr_t const *parent, uint8_t const *data, size_t const data_len, void *decode_ctx)
Handle arrays of DNS labels for fr_struct_from_network()
static ssize_t decode_vsa(TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dict_attr_t const *parent, uint8_t const *data, size_t const data_len, void *decode_ctx)
static ssize_t decode_tlv_trampoline(TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dict_attr_t const *parent, uint8_t const *data, size_t const data_len, void *decode_ctx)
ssize_t fr_dhcpv6_decode_foreign(TALLOC_CTX *ctx, fr_pair_list_t *out, uint8_t const *data, size_t data_len)
static ssize_t fr_dhcpv6_decode_proto(TALLOC_CTX *ctx, fr_pair_list_t *out, uint8_t const *data, size_t data_len, UNUSED void *proto_ctx)
static ssize_t decode_pair(TALLOC_CTX *ctx, fr_pair_list_t *out, NDEBUG_UNUSED fr_dict_attr_t const *parent, uint8_t const *data, size_t data_len, void *decode_ctx)
static char const * proto(int id, int porttype)
ssize_t fr_struct_from_network(TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dict_attr_t const *parent, uint8_t const *data, size_t data_len, void *decode_ctx, fr_pair_decode_value_t decode_value, fr_pair_decode_value_t decode_tlv)
Convert a STRUCT to one or more VPs.
Stores an attribute, a value and various bits of other data.
fr_dict_attr_t const *_CONST da
Dictionary attribute defines the attribute number, vendor and type of the pair.
fr_test_point_ctx_alloc_t test_ctx
Allocate a test ctx for the encoder.
fr_test_point_ctx_alloc_t test_ctx
Allocate a test ctx for the encoder.
Entry point for pair decoders.
Entry point for protocol decoders.
static fr_time_delta_t fr_time_delta_from_sec(int64_t sec)
#define fr_unix_time_add(_a, _b)
Add a time/time delta together.
#define FR_PROTO_HEX_DUMP(_data, _data_len, _fmt,...)
#define FR_PROTO_TRACE(_fmt,...)
#define fr_strerror_printf(_fmt,...)
Log to thread local error buffer.
ssize_t fr_value_box_from_network(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_type_t type, fr_dict_attr_t const *enumv, fr_dbuff_t *dbuff, size_t len, bool tainted)
Decode a fr_value_box_t from serialized binary data.
static size_t char ** out