24RCSID(
"$Id: 4cc429de6c78ee53b86cb96e349e6f4be0031d04 $")
26#include <freeradius-devel/util/debug.h>
27#include <freeradius-devel/util/ext.h>
28#include <freeradius-devel/util/misc.h>
29#include <freeradius-devel/util/syserror.h>
64 void *n_chunk, *chunk = *chunk_p;
73 if (ext_offsets[ext])
return fr_ext_ptr(*chunk_p, ext_offsets[ext], info->
has_hdr);
83 chunk_len = talloc_get_size(chunk);
95 type = talloc_get_name(chunk);
96 n_chunk = talloc_realloc_size(NULL, chunk, (offset *
FR_EXT_ALIGNMENT) + hdr_len + aligned_len);
98 fr_strerror_printf(
"Failed reallocing %s (%s). Tried to realloc %zu bytes -> %zu bytes",
102 talloc_set_name_const(n_chunk,
type);
105 ext_offsets[ext] = (
uint8_t)offset;
107 ext_ptr = ((
uint8_t *)n_chunk) + chunk_len;
108 memset(ext_ptr, 0, hdr_len + aligned_len);
115 ext_hdr->
len = ext_len;
116 return &ext_hdr->
data;
139 offset = ext_offsets[ext];
140 if (!offset)
return 0;
142 info = &def->
info[ext];
168 void *ext_src_ptr, *ext_dst_ptr;
176 if (!ext_src_offsets[ext])
return NULL;
184 if (!ext_dst_offsets[ext]) {
186 ext_dst_ptr = info->
alloc(def, chunk_dst, ext,
205 ext_dst_ptr,
fr_ext_len(def, *chunk_dst, ext),
207 ext_src_ptr,
fr_ext_len(def, chunk_src, ext));
214 memcpy(ext_dst_ptr, ext_src_ptr,
fr_ext_len(def, *chunk_dst, ext));
221 for (i = 0; i < def->
max; i++) {
222 if (i == ext)
continue;
224 if (!ext_dst_offsets[i])
continue;
227 info->
fixup(i, *chunk_dst,
229 fr_ext_len(def, *chunk_dst, i)) < 0)
return NULL;
253 bool ext_new_alloc[def->
max];
260 for (i = 0; i < def->
max; i++) {
263 if (!ext_src_offsets[i] || !info->
can_copy) {
265 ext_new_alloc[i] =
false;
270 if (!info->
alloc(def, chunk_dst, i,
281 ext_new_alloc[i] =
true;
292 for (i = 0; i < def->
max; i++) {
295 if (!ext_src_offsets[i] || !ext_dst_offsets[i])
continue;
297 if (!ext_new_alloc[i]) {
299 info->
fixup(i, *chunk_dst,
301 fr_ext_len(def, *chunk_dst, i)) < 0)
return -1;
313 fr_ext_len(def, chunk_src, i)) < 0)
return -1;
344 for (i = 0; i < (int)def->
max; i++) {
347 if (ext_offsets[i]) {
354 if (ext_len > 1024) {
355 FR_FAULT_LOG(
"%s ext id=%s - possibly bad length %zu - limiting dump to 1024",
356 name, ext_name, ext_len);
361 name, ext_name, ext, ((
uint8_t *)ext) + ext_len, ext_len);
#define FR_FAULT_LOG_HEX(_data, _data_len)
#define FR_FAULT_LOG(_fmt,...)
void * fr_ext_copy(fr_ext_t const *def, TALLOC_CTX **chunk_dst, TALLOC_CTX const *chunk_src, int ext)
Copy extension data from one attribute to another.
size_t fr_ext_len(fr_ext_t const *def, TALLOC_CTX const *chunk, int ext)
Return the length of an extension.
void fr_ext_debug(fr_ext_t const *def, char const *name, void const *chunk)
Print out all extensions and hexdump their contents.
int fr_ext_copy_all(fr_ext_t const *def, TALLOC_CTX **chunk_dst, TALLOC_CTX const *chunk_src)
Copy all the extensions from one attribute to another.
void * fr_ext_alloc_size(fr_ext_t const *def, void **chunk_p, int ext, size_t ext_len)
Add a variable length extension to a talloc chunk.
bool can_copy
Copying this extension between structs is allowed.
int max
The highest extension value.
uint8_t data[]
Extension data.
bool has_hdr
Additional metadata should be allocated before the extension data to record the exact length of the e...
size_t * name_table_len
How many extensions there are in the table.
static void * fr_ext_ptr(TALLOC_CTX const *chunk, size_t offset, bool has_hdr)
Return a pointer to an extension in a chunk.
fr_table_num_ordered_t const * name_table
String identifiers for the extensions.
size_t len
Length of extension data.
fr_ext_copy_t copy
Override the normal copy operation with a callback.
fr_ext_alloc_t alloc
Override the normal alloc operation with a callback.
fr_ext_fixup_t fixup
Callback for fixing up internal consistency issues.
#define FR_EXT_ALIGNMENT
The alignment of object extension structures.
size_t min
Minimum size of extension.
static uint8_t * fr_ext_offsets(fr_ext_t const *def, TALLOC_CTX const *chunk)
fr_ext_info_t const * info
Additional information about each extension.
Optional extension header struct.
Additional information for a given extension.
Structure to define a set of extensions.
#define ROUND_UP_POW2(_num, _mul)
Round up - Only works if _mul is a power of 2 but avoids division.
#define ROUND_UP_DIV(_x, _y)
Get the ceiling value of integer division.
fr_aka_sim_id_type_t type
char const * fr_syserror(int num)
Guaranteed to be thread-safe version of strerror.
char const * fr_table_ordered_str_by_num(fr_table_num_ordered_t const *table, size_t table_len, int number, char const *def)
#define fr_strerror_printf(_fmt,...)
Log to thread local error buffer.
#define fr_strerror_const(_msg)