The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Data Structures | Macros | Typedefs | Functions
ext.h File Reference

'compositing' using talloc structures More...

#include <freeradius-devel/util/table.h>
#include <limits.h>
+ Include dependency graph for ext.h:

Go to the source code of this file.

Data Structures

struct  fr_ext_hdr_t
 Optional extension header struct. More...
 
struct  fr_ext_info_t
 Additional information for a given extension. More...
 
struct  fr_ext_s
 Structure to define a set of extensions. More...
 

Macros

#define FR_EXT_ALIGNMENT   sizeof(uint64_t)
 The alignment of object extension structures. More...
 

Typedefs

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. More...
 
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. More...
 
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. More...
 
typedef struct fr_ext_s fr_ext_t
 

Functions

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. More...
 
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. More...
 
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. More...
 
static uint8_tfr_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. More...
 

Detailed Description

'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.

Definition in file ext.h.


Data Structure Documentation

◆ fr_ext_hdr_t

struct 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

struct fr_ext_info_t

Additional information for a given extension.

Definition at line 111 of file ext.h.

+ Collaboration diagram for fr_ext_info_t:
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

struct fr_ext_s

Structure to define a set of extensions.

Definition at line 126 of file ext.h.

+ Collaboration diagram for fr_ext_s:
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.

Macro Definition Documentation

◆ FR_EXT_ALIGNMENT

#define FR_EXT_ALIGNMENT   sizeof(uint64_t)

The alignment of object extension structures.

Definition at line 54 of file ext.h.

Typedef Documentation

◆ 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]defExtension definitions.
[in,out]dst_chunk_pto add extensions to.
[in]extthat's being copied.
[in]src_ext_ptrPointer for the src extension.
[in]src_ext_lenLength 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]extthat's being copied.
[in]dst_chunkTalloc chunk we're copying to.
[in]dst_ext_ptrPointer to the dst extension to populate.
[in]dst_ext_lenThe length of the dst extension.
[in]src_chunkTalloc chunk we're copying from.
[in]src_ext_ptrPointer for the src extension.
[in]src_ext_lenLength 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]extthat's being copied.
[in]chunkTalloc chunk.
[in]ext_ptrPointer to the extension to fixup.
[in]ext_lenThe 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

typedef struct fr_ext_s fr_ext_t

Definition at line 1 of file ext.h.

Function Documentation

◆ 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]defExtension definitions.
[in,out]chunk_dstto 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_srcto copy extension from.
[in]extto 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.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ 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]defExtension definitions.
[in,out]chunk_dstto 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_srcto copy extensions from.
Returns
  • 0 on success.
  • -1 if a copy operation failed.

Definition at line 245 of file ext.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ 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]defExtension definitions.
[in]chunkto return extension length for.
[in]extto 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.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_ext_offsets()

static uint8_t* fr_ext_offsets ( fr_ext_t const *  def,
TALLOC_CTX const *  chunk 
)
inlinestatic

Definition at line 142 of file ext.h.

+ Here is the caller graph for this function:

◆ 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.

+ Here is the caller graph for this function: