24 RCSID(
"$Id: bfa07ef9869f78205a6787ffcccfde5008e593ce $")
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;
70 if (ext_offsets[ext])
return fr_ext_ptr(*chunk_p, ext_offsets[ext], info->
has_hdr);
80 chunk_len = talloc_get_size(chunk);
92 type = talloc_get_name(chunk);
93 n_chunk = talloc_realloc_size(NULL, chunk, (offset *
FR_EXT_ALIGNMENT) + hdr_len + aligned_len);
95 fr_strerror_printf(
"Failed reallocing %s (%s). Tried to realloc %zu bytes -> %zu bytes",
99 talloc_set_name_const(n_chunk,
type);
102 ext_offsets[ext] = (
uint8_t)offset;
104 ext_ptr = ((
uint8_t *)n_chunk) + chunk_len;
105 memset(ext_ptr, 0, hdr_len + aligned_len);
112 ext_hdr->
len = ext_len;
113 return &ext_hdr->
data;
136 offset = ext_offsets[ext];
137 if (!offset)
return 0;
139 info = &def->
info[ext];
165 void *ext_src_ptr, *ext_dst_ptr;
173 if (!ext_src_offsets[ext])
return NULL;
181 if (!ext_dst_offsets[ext]) {
183 ext_dst_ptr = info->
alloc(def, chunk_dst, ext,
202 ext_dst_ptr,
fr_ext_len(def, *chunk_dst, ext),
204 ext_src_ptr,
fr_ext_len(def, chunk_src, ext));
211 memcpy(ext_dst_ptr, ext_src_ptr,
fr_ext_len(def, *chunk_dst, ext));
218 for (i = 0; i < def->
max; i++) {
219 if (i == ext)
continue;
221 if (!ext_dst_offsets[i])
continue;
224 info->
fixup(i, *chunk_dst,
226 fr_ext_len(def, *chunk_dst, i)) < 0)
return NULL;
250 bool ext_new_alloc[def->
max];
257 for (i = 0; i < def->
max; i++) {
260 if (!ext_src_offsets[i] || !info->
can_copy) {
262 ext_new_alloc[i] =
false;
267 if (!info->
alloc(def, chunk_dst, i,
278 ext_new_alloc[i] =
true;
289 for (i = 0; i < def->
max; i++) {
292 if (!ext_src_offsets[i] || !ext_dst_offsets[i])
continue;
294 if (!ext_new_alloc[i]) {
296 info->
fixup(i, *chunk_dst,
298 fr_ext_len(def, *chunk_dst, i)) < 0)
return -1;
310 fr_ext_len(def, chunk_src, i)) < 0)
return -1;
341 for (i = 0; i < (int)def->
max; i++) {
344 if (ext_offsets[i]) {
351 if (ext_len > 1024) {
352 FR_FAULT_LOG(
"%s ext id=%s - possibly bad length %zu - limiting dump to 1024",
353 name, ext_name, ext_len);
358 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_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.
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.
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.
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.
bool can_copy
Copying this extension between structs is allowed.
static void * fr_ext_ptr(TALLOC_CTX const *chunk, size_t offset, bool has_hdr)
Return a pointer to an extension in a chunk.
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.
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)