'compositing' using talloc structures
More...
#include <freeradius-devel/util/table.h>
#include <limits.h>
Go to the source code of this file.
|
typedef void *(* | fr_ext_alloc_t) (fr_ext_t const *def, TALLOC_CTX **dst_chunk_p, int ext, void *src_ext_ptr, size_t src_ext_len) |
| Function for pre-allocating extension memory for extensions before they're copied.
|
|
typedef int(* | fr_ext_copy_t) (int ext, TALLOC_CTX *dst_chunk, void *dst_ext_ptr, size_t dst_ext_len, TALLOC_CTX const *src_chunk, void *src_ext_ptr, size_t src_ext_len) |
| Function for re-populating extensions after they're copied.
|
|
typedef int(* | fr_ext_fixup_t) (int ext, TALLOC_CTX *chunk, void *ext_ptr, size_t ext_len) |
| Function for re-establishing internal consistency on realloc.
|
|
typedef struct fr_ext_s | fr_ext_t |
|
|
void * | fr_ext_alloc_size (fr_ext_t const *def, TALLOC_CTX **chunk_p, int ext, size_t ext_len) |
|
void * | fr_ext_copy (fr_ext_t const *def, TALLOC_CTX **chunk_out, TALLOC_CTX const *chunk_in, int ext) |
| Copy extension data from one attribute to another.
|
|
int | fr_ext_copy_all (fr_ext_t const *def, TALLOC_CTX **chunk_out, TALLOC_CTX const *chunk_in) |
| Copy all the extensions from one attribute to another.
|
|
void | fr_ext_debug (fr_ext_t const *def, char const *name, TALLOC_CTX const *chunk) |
|
size_t | fr_ext_len (fr_ext_t const *def, TALLOC_CTX const *chunk_in, int ext) |
| Return the length of an extension.
|
|
static uint8_t * | fr_ext_offsets (fr_ext_t const *def, TALLOC_CTX const *chunk) |
|
static void * | fr_ext_ptr (TALLOC_CTX const *chunk, size_t offset, bool has_hdr) |
| Return a pointer to an extension in a chunk.
|
|
'compositing' using talloc structures
These allow multiple variable length memory areas to be appended to talloced structures. Extensions can either contain a header in which case the exact length is recorded, or they can be of a fixed size.
The structure being extended must be padded to a multiple of FR_EXT_ALIGNMENT. i.e. ).
It is strongly recommended that extended structures are allocated in a talloc_pool() to avoid the overhead of multiple reallocs.
- Copyright
- 2020 The FreeRADIUS server project
-
2020 Arran Cudbard-Bell a.cud.nosp@m.bard.nosp@m.b@fre.nosp@m.erad.nosp@m.ius.o.nosp@m.rg
Definition in file ext.h.
◆ fr_ext_hdr_t
Optional extension header struct.
Definition at line 137 of file ext.h.
Data Fields |
uint8_t |
data[] |
Extension data. |
size_t |
len |
Length of extension data. |
◆ fr_ext_info_t
Additional information for a given extension.
Definition at line 111 of file ext.h.
Data Fields |
fr_ext_alloc_t |
alloc |
Override the normal alloc operation with a callback. |
bool |
can_copy |
Copying this extension between structs is allowed. |
fr_ext_copy_t |
copy |
Override the normal copy operation with a callback. |
fr_ext_fixup_t |
fixup |
Callback for fixing up internal consistency issues. |
bool |
has_hdr |
Additional metadata should be allocated before the extension data to record the exact length of the extension. |
size_t |
min |
Minimum size of extension. |
◆ fr_ext_s
Structure to define a set of extensions.
Definition at line 126 of file ext.h.
Data Fields |
fr_ext_info_t const * |
info |
Additional information about each extension. |
int |
max |
The highest extension value. |
fr_table_num_ordered_t const * |
name_table |
String identifiers for the extensions. |
size_t * |
name_table_len |
How many extensions there are in the table. |
size_t |
offset_of_exts |
Where in the extended struct the extensions array starts. |
◆ FR_EXT_ALIGNMENT
#define FR_EXT_ALIGNMENT sizeof(uint64_t) |
The alignment of object extension structures.
Definition at line 54 of file ext.h.
◆ fr_ext_alloc_t
typedef void *(* fr_ext_alloc_t) (fr_ext_t const *def, TALLOC_CTX **dst_chunk_p, int ext, void *src_ext_ptr, size_t src_ext_len) |
Function for pre-allocating extension memory for extensions before they're copied.
- Parameters
-
[in] | def | Extension definitions. |
[in,out] | dst_chunk_p | to add extensions to. |
[in] | ext | that's being copied. |
[in] | src_ext_ptr | Pointer for the src extension. |
[in] | src_ext_len | Length of the src extension. |
- Returns
- NULL on error.
- Pointer to the new extension on success.
Definition at line 70 of file ext.h.
◆ fr_ext_copy_t
typedef int(* fr_ext_copy_t) (int ext, TALLOC_CTX *dst_chunk, void *dst_ext_ptr, size_t dst_ext_len, TALLOC_CTX const *src_chunk, void *src_ext_ptr, size_t src_ext_len) |
Function for re-populating extensions after they're copied.
- Parameters
-
[in] | ext | that's being copied. |
[in] | dst_chunk | Talloc chunk we're copying to. |
[in] | dst_ext_ptr | Pointer to the dst extension to populate. |
[in] | dst_ext_len | The length of the dst extension. |
[in] | src_chunk | Talloc chunk we're copying from. |
[in] | src_ext_ptr | Pointer for the src extension. |
[in] | src_ext_len | Length of the src extension. |
- Returns
- NULL on error.
- Pointer to the new extension on success.
Definition at line 86 of file ext.h.
◆ fr_ext_fixup_t
typedef int(* fr_ext_fixup_t) (int ext, TALLOC_CTX *chunk, void *ext_ptr, size_t ext_len) |
Function for re-establishing internal consistency on realloc.
In some cases the chunk may cache a pointer to an extension. On realloc this pointer may be invalidated. This provides a callback to fixup consistency issues after a realloc.
- Parameters
-
[in] | ext | that's being copied. |
[in] | chunk | Talloc chunk. |
[in] | ext_ptr | Pointer to the extension to fixup. |
[in] | ext_len | The length of the extension to fixup. |
- Returns
- NULL on error.
- Pointer to the new extension on success.
Definition at line 106 of file ext.h.
◆ fr_ext_t
Definition at line 57 of file ext.h.
◆ fr_ext_alloc_size()
void * fr_ext_alloc_size |
( |
fr_ext_t const * |
def, |
|
|
TALLOC_CTX ** |
chunk_p, |
|
|
int |
ext, |
|
|
size_t |
ext_len |
|
) |
| |
◆ fr_ext_copy()
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.
- Parameters
-
[in] | def | Extension definitions. |
[in,out] | chunk_dst | to copy extension to. Under certain circumstances the value of *chunk_dst will be changed to point to a new memory block. All cached copies of the previous pointer should be updated. |
[in] | chunk_src | to copy extension from. |
[in] | ext | to copy. |
- Returns
- NULL if we failed to allocate an extension structure.
- A pointer to the offset of the extension in da_out.
Definition at line 160 of file ext.c.
◆ fr_ext_copy_all()
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.
- Parameters
-
[in] | def | Extension definitions. |
[in,out] | chunk_dst | to copy extensions to. Under certain circumstances the value of *chunk_dst will be changed to point to a new memory block. All cached copies of the previous pointer should be updated. |
[in] | chunk_src | to copy extensions from. |
- Returns
- 0 on success.
- -1 if a copy operation failed.
Definition at line 245 of file ext.c.
◆ fr_ext_debug()
void fr_ext_debug |
( |
fr_ext_t const * |
def, |
|
|
char const * |
name, |
|
|
TALLOC_CTX const * |
chunk |
|
) |
| |
◆ fr_ext_len()
size_t fr_ext_len |
( |
fr_ext_t const * |
def, |
|
|
TALLOC_CTX const * |
chunk, |
|
|
int |
ext |
|
) |
| |
Return the length of an extension.
- Parameters
-
[in] | def | Extension definitions. |
[in] | chunk | to return extension length for. |
[in] | ext | to return length for. |
- Returns
- 0 if no extension exists or is of zero length.
- >0 the length of the extension.
Definition at line 128 of file ext.c.
◆ fr_ext_offsets()
static uint8_t * fr_ext_offsets |
( |
fr_ext_t const * |
def, |
|
|
TALLOC_CTX const * |
chunk |
|
) |
| |
|
inlinestatic |
◆ fr_ext_ptr()
static void * fr_ext_ptr |
( |
TALLOC_CTX const * |
chunk, |
|
|
size_t |
offset, |
|
|
bool |
has_hdr |
|
) |
| |
|
inlinestatic |
Return a pointer to an extension in a chunk.
Definition at line 150 of file ext.h.