29 #include <freeradius-devel/internal/internal.h>
30 #include <freeradius-devel/io/pair.h>
31 #include <freeradius-devel/io/test_point.h>
32 #include <freeradius-devel/util/proto.h>
33 #include <freeradius-devel/util/types.h>
43 bool tainted,
UNUSED void *decode_ctx)
104 uint8_t enc_byte = 0, ext_byte = 0, type_field_size, len_field_size;
106 uint64_t len = 0,
type = 0;
107 size_t remaining, needed;
108 bool tainted, extended, unknown =
false,
internal =
false;
131 __FUNCTION__, 3 - remaining);
146 needed = type_field_size + len_field_size + extended;
148 if (remaining < needed) {
150 "%zu byte(s) remaining, need %zu byte(s)",
151 __FUNCTION__, remaining, needed);
195 if (remaining < len) {
197 "%zu byte(s) remaining, need %zu byte(s)",
198 __FUNCTION__, remaining, (
size_t) len);
207 if (!parent_da->flags.is_root && !(parent_da->type ==
FR_TYPE_GROUP)) {
208 fr_strerror_printf(
"%s: Internal flag can only be set on top level attribute", __FUNCTION__);
214 if (unknown || parent_da->flags.is_unknown) {
227 FR_PROTO_TRACE(
"decode context changed %s -> %s", da->parent->name, da->name);
255 if (slen <= 0)
goto error;
264 if (slen < 0)
goto error;
274 uint8_t const *
data,
size_t data_len,
void *decode_ctx)
317 if (ret < 0)
return ret;
#define fr_dbuff_used(_dbuff_or_marker)
Return the number of bytes remaining between the start of the dbuff or marker and the current positio...
#define FR_DBUFF_OUT_UINT64V_RETURN(_num, _dbuff_or_marker, _len)
Read bytes from a dbuff or marker and interpret them as a network order unsigned integer.
#define fr_dbuff_len(_dbuff_or_marker)
The length of the underlying buffer.
struct fr_dbuff_marker_s fr_dbuff_marker_t
A position marker associated with a dbuff.
#define fr_dbuff_current(_dbuff_or_marker)
Return the 'current' position of a dbuff or marker.
#define fr_dbuff_start(_dbuff_or_marker)
Return the 'start' position of a dbuff or marker.
#define fr_dbuff_extend_lowat(_status, _dbuff_or_marker, _lowat)
Extend if we're below _lowat.
#define fr_dbuff_extend(_dbuff)
Extend if no space remains.
#define fr_dbuff_remaining(_dbuff_or_marker)
Return the number of bytes remaining between the dbuff or marker and the end of the buffer.
#define FR_DBUFF(_dbuff_or_marker)
Create a new dbuff pointing to the same underlying buffer.
static uint8_t * fr_dbuff_marker(fr_dbuff_marker_t *m, fr_dbuff_t *dbuff)
Initialises a new marker pointing to the 'current' position of the dbuff.
#define FR_DBUFF_OUT_RETURN(_out, _dbuff_or_marker)
Copy data from a dbuff or marker to a fixed sized C type returning if there is insufficient data.
#define fr_dbuff_set_end(_dst, _end)
Set a new 'end' position in a dbuff or marker.
#define FR_DBUFF_TMP(_start, _len_or_end)
Creates a compound literal to pass into functions which accept a dbuff.
fr_dict_attr_t const * fr_dict_root(fr_dict_t const *dict)
Return the root attribute of a dictionary.
void fr_dict_attr_unknown_free(fr_dict_attr_t const **da)
Free dynamically allocated (unknown attributes)
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_t const * fr_dict_internal(void)
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.
#define FR_INTERNAL_FLAG_INTERNAL
#define FR_INTERNAL_MASK_TYPE
#define FR_INTERNAL_FLAG_EXTENDED
#define FR_INTERNAL_MASK_LEN
#define FR_INTERNAL_FLAG_UNKNOWN
#define FR_INTERNAL_FLAG_TAINTED
#define PAIR_DECODE_OOM
Fatal error - Out of memory.
#define PAIR_DECODE_FATAL_ERROR
Fatal error - Failed decoding the packet.
static ssize_t fr_pair_decode_slen(ssize_t slen, uint8_t const *start, uint8_t const *p)
Return the correct adjusted slen for errors.
@ FR_TYPE_GROUP
A grouping of other attributes.
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.
void fr_pair_list_init(fr_pair_list_t *list)
Initialise a pair list header.
ssize_t fr_internal_decode_list_dbuff(TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dict_attr_t const *parent, fr_dbuff_t *dbuff, void *decode_ctx)
Retrieve all pairs from the dbuff.
static ssize_t internal_decode_pair_value(TALLOC_CTX *ctx, fr_pair_list_t *head, fr_dict_attr_t const *parent_da, fr_dbuff_t *dbuff, bool tainted, UNUSED void *decode_ctx)
Decodes the value of an attribute, potentially producing a pair (added to the cursor)
ssize_t fr_internal_decode_pair_dbuff(TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dict_attr_t const *parent, fr_dbuff_t *dbuff, void *decode_ctx)
ssize_t fr_internal_decode_pair(TALLOC_CTX *ctx, fr_pair_list_t *list, fr_dict_attr_t const *parent, uint8_t const *data, size_t data_len, void *decode_ctx)
Create a single fr_pair_t and all its nesting.
fr_test_point_pair_decode_t internal_tp_decode_pair
static ssize_t internal_decode_structural(TALLOC_CTX *ctx, fr_pair_list_t *head, fr_dict_attr_t const *parent_da, fr_dbuff_t *dbuff, void *decode_ctx)
Decode a group.
static ssize_t internal_decode_pair(TALLOC_CTX *ctx, fr_pair_list_t *head, fr_dict_attr_t const *parent_da, fr_dbuff_t *dbuff, void *decode_ctx)
fr_aka_sim_id_type_t type
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.
Entry point for pair decoders.
void fr_pair_list_free(fr_pair_list_t *list)
Free memory used by a valuepair list.
void fr_pair_list_append(fr_pair_list_t *dst, fr_pair_list_t *src)
Appends a list of fr_pair_t from a temporary list to a destination list.
#define FR_PROTO_TRACE(_fmt,...)
#define FR_PROTO_HEX_MARKER(_data, _data_len, _slen, _fmt,...)
#define fr_strerror_printf(_fmt,...)
Log to thread local error buffer.
static char const * fr_type_to_str(fr_type_t type)
Return a static string containing the type name.
#define fr_type_is_vsa(_x)
#define FR_TYPE_STRUCTURAL
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.
return fr_dbuff_set(dbuff, &our_dbuff)
static size_t char ** out