The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Functions | Variables
xlat_inst.c File Reference

Create instance data for xlat function calls. More...

#include <freeradius-devel/io/schedule.h>
#include <freeradius-devel/server/base.h>
#include <freeradius-devel/unlang/xlat_priv.h>
#include <freeradius-devel/util/debug.h>
#include <freeradius-devel/util/heap.h>
+ Include dependency graph for xlat_inst.c:

Go to the source code of this file.

Functions

static int8_t _xlat_inst_cmp (void const *one, void const *two)
 Compare two xlat instances based on node pointer. More...
 
static int _xlat_inst_detach (xlat_inst_t *xi)
 Destructor for xlat_inst_t. More...
 
static int _xlat_inst_walker (xlat_exp_t *node, UNUSED void *uctx)
 
static int _xlat_instantiate_ephemeral_walker (xlat_exp_t *node, void *uctx)
 Callback for creating "ephemeral" instance data for a xlat_exp_t. More...
 
static int8_t _xlat_thread_inst_cmp (void const *one, void const *two)
 Compare two thread instances based on node pointer. More...
 
static int _xlat_thread_inst_detach (xlat_thread_inst_t *xt)
 Destructor for xlat_thread_inst_t. More...
 
int xlat_finalize (xlat_exp_head_t *head, fr_event_list_t *runtime_el)
 Bootstrap static xlats, or instantiate ephemeral ones. More...
 
static xlat_inst_txlat_inst_alloc (xlat_exp_t *node)
 Allocate instance data for an xlat expansion. More...
 
static int xlat_instance_register (xlat_exp_head_t *head)
 Create instance data for "permanent" xlats. More...
 
int xlat_instance_register_func (xlat_exp_t *node)
 Callback for creating "permanent" instance data for a xlat_exp_t. More...
 
int xlat_instance_unregister_func (xlat_exp_t *node)
 Remove a node from the list of xlat instance data. More...
 
void xlat_instances_free (void)
 Walk over all registered instance data and free them explicitly. More...
 
int xlat_instantiate (void)
 Call instantiation functions for all registered, "permanent" xlats. More...
 
static int xlat_instantiate_ephemeral (xlat_exp_head_t *head, fr_event_list_t *el)
 Create instance data for "ephemeral" xlats. More...
 
static int xlat_instantiate_init (void)
 Initialise the xlat instance data code. More...
 
void xlat_thread_detach (void)
 Destroy any thread specific xlat instances. More...
 
static xlat_thread_inst_txlat_thread_inst_alloc (TALLOC_CTX *ctx, fr_event_list_t *el, xlat_inst_t *xi)
 Create thread instances where needed. More...
 
xlat_thread_inst_txlat_thread_instance_find (xlat_exp_t const *node)
 Retrieve xlat/thread specific instance data. More...
 
int xlat_thread_instantiate (TALLOC_CTX *ctx, fr_event_list_t *el)
 Create thread specific instance tree and create thread instances. More...
 

Variables

 return
 
static fr_heap_txlat_inst_tree
 Holds instance data created by xlat_instantiate. More...
 
static _Thread_local fr_heap_txlat_thread_inst_tree
 Holds thread specific instance data created by xlat_instantiate. More...
 

Detailed Description

Create instance data for xlat function calls.

Id
9c531711a718636d58251b8fa0c7804d57537b44

Definition in file xlat_inst.c.

Function Documentation

◆ _xlat_inst_cmp()

static int8_t _xlat_inst_cmp ( void const *  one,
void const *  two 
)
static

Compare two xlat instances based on node pointer.

Parameters
[in]oneFirst xlat expansion instance.
[in]twoSecond xlat expansion instance.
Returns
CMP(one, two)

Definition at line 48 of file xlat_inst.c.

+ Here is the caller graph for this function:

◆ _xlat_inst_detach()

static int _xlat_inst_detach ( xlat_inst_t xi)
static

Destructor for xlat_inst_t.

Calls detach method if provided by xlat expansion

Note
This cannot be converted to a talloc destructor, as we need to call thread_detach before any of the children of the talloc ctx are freed.

Definition at line 179 of file xlat_inst.c.

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

◆ _xlat_inst_walker()

static int _xlat_inst_walker ( xlat_exp_t node,
UNUSED void *  uctx 
)
static

Definition at line 626 of file xlat_inst.c.

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

◆ _xlat_instantiate_ephemeral_walker()

static int _xlat_instantiate_ephemeral_walker ( xlat_exp_t node,
void *  uctx 
)
static

Callback for creating "ephemeral" instance data for a xlat_exp_t.

Note
Epehemeral xlats must not be shared between requests.
Parameters
[in]nodeto create "ephemeral" instance data for.
[in]uctxevent list passed to xlat thread instantiation functions.
Returns
  • 0 if instantiation functions were successful.
  • -1 if either instantiation function failed.

Definition at line 295 of file xlat_inst.c.

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

◆ _xlat_thread_inst_cmp()

static int8_t _xlat_thread_inst_cmp ( void const *  one,
void const *  two 
)
static

Compare two thread instances based on node pointer.

Parameters
[in]oneFirst thread specific xlat expansion instance.
[in]twoSecond thread specific xlat expansion instance.
Returns
CMP(one, two)

Definition at line 61 of file xlat_inst.c.

+ Here is the caller graph for this function:

◆ _xlat_thread_inst_detach()

static int _xlat_thread_inst_detach ( xlat_thread_inst_t xt)
static

Destructor for xlat_thread_inst_t.

Calls thread_detach method if provided by xlat expansion

Note
This cannot be converted to a talloc destructor, as we need to call thread_detach before any of the children of the talloc ctx are freed.

Definition at line 76 of file xlat_inst.c.

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

◆ xlat_finalize()

int xlat_finalize ( xlat_exp_head_t head,
fr_event_list_t runtime_el 
)

Bootstrap static xlats, or instantiate ephemeral ones.

Parameters
[in]headof xlat tree to create instance data for.
[in]runtime_eldetermines whether we do ephemeral or static instantiation. If NULL, we perform static instantiation, otherwise will perform ephemeral instantiation passing the el to the instantiation functions.

Definition at line 690 of file xlat_inst.c.

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

◆ xlat_inst_alloc()

static xlat_inst_t* xlat_inst_alloc ( xlat_exp_t node)
static

Allocate instance data for an xlat expansion.

Parameters
[in]nodeto allocate instance data for.

Definition at line 213 of file xlat_inst.c.

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

◆ xlat_instance_register()

static int xlat_instance_register ( xlat_exp_head_t head)
inlinestatic

Create instance data for "permanent" xlats.

Note
This must only be used for xlats which are read from the configuration files. IF THIS IS CALLED FOR XLATS TOKENIZED AT RUNTIME YOU WILL LEAK LARGE AMOUNTS OF MEMORY. If the caller has a tmpl_rules_t, it should call xlat_finalize() instead.
Parameters
[in]headof xlat tree to create instance data for. Will walk the entire tree registering all the xlat function calls for later instantiation.

Definition at line 651 of file xlat_inst.c.

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

◆ xlat_instance_register_func()

int xlat_instance_register_func ( xlat_exp_t node)

Callback for creating "permanent" instance data for a xlat_exp_t.

This function records the xlat_exp_t requiring instantiation but does not call the instantiation function. This is to allow for a clear separation between the module instantiation phase and the xlat instantiation phase.

Note
This is very similar to xlat_instance_register but does not walk the children of the node. This is primarily used to register individual nodes for instantiation and when an xlat function is resolved in a subsequent resolution pass and needs to be registered for instantiation.
Parameters
[in]nodeto create "permanent" instance data for.
Returns
  • 0 if instantiation functions were successful.
  • -1 if either instantiation function failed.

Definition at line 590 of file xlat_inst.c.

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

◆ xlat_instance_unregister_func()

int xlat_instance_unregister_func ( xlat_exp_t node)

Remove a node from the list of xlat instance data.

Note
This is primarily used during "purification", to remove xlats which are no longer used.
Parameters
[in]nodeto remove instance data for.

Definition at line 545 of file xlat_inst.c.

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

◆ xlat_instances_free()

void xlat_instances_free ( void  )

Walk over all registered instance data and free them explicitly.

This must be called before any modules or xlats are deregistered/unloaded and before the mainconfig is freed, as the xlat_t need to still exist in order to call the detach functions within them.

Definition at line 704 of file xlat_inst.c.

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

◆ xlat_instantiate()

int xlat_instantiate ( void  )

Call instantiation functions for all registered, "permanent" xlats.

Should be called after all the permanent xlats have been tokenised/bootstrapped.

Definition at line 508 of file xlat_inst.c.

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

◆ xlat_instantiate_ephemeral()

static int xlat_instantiate_ephemeral ( xlat_exp_head_t head,
fr_event_list_t el 
)
inlinestatic

Create instance data for "ephemeral" xlats.

Note
This function should only be called from routines which get passed a request_t.
Parameters
[in]headof xlat tree to create instance data for.
[in]elevent list used to run any instantiate data

Definition at line 372 of file xlat_inst.c.

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

◆ xlat_instantiate_init()

static int xlat_instantiate_init ( void  )
static

Initialise the xlat instance data code.

Definition at line 494 of file xlat_inst.c.

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

◆ xlat_thread_detach()

void xlat_thread_detach ( void  )

Destroy any thread specific xlat instances.

Definition at line 484 of file xlat_inst.c.

+ Here is the caller graph for this function:

◆ xlat_thread_inst_alloc()

static xlat_thread_inst_t* xlat_thread_inst_alloc ( TALLOC_CTX *  ctx,
fr_event_list_t el,
xlat_inst_t xi 
)
static

Create thread instances where needed.

Parameters
[in]ctxto allocate thread instance data in.
[in]elevent list to register I/O handlers against.
[in]xito allocate thread-instance data for.
Returns
  • 0 on success. The node/thread specific data will be inserted into xlat_thread_inst_tree.
  • -1 on failure.

Definition at line 104 of file xlat_inst.c.

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

◆ xlat_thread_instance_find()

xlat_thread_inst_t* xlat_thread_instance_find ( xlat_exp_t const *  node)

Retrieve xlat/thread specific instance data.

Parameters
[in]nodeto find thread specific data for.
Returns
  • Thread specific data on success.
  • NULL if the xlat has no thread instance data.

Definition at line 402 of file xlat_inst.c.

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

◆ xlat_thread_instantiate()

int xlat_thread_instantiate ( TALLOC_CTX *  ctx,
fr_event_list_t el 
)

Create thread specific instance tree and create thread instances.

This should be called directly after the modules_thread_instantiate() function.

Memory will be freed automatically when the thread exits.

Parameters
[in]ctxto bind instance tree lifetime to. Must not be shared between multiple threads.
[in]elEvent list to pass to all thread instantiation functions.
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 439 of file xlat_inst.c.

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

Variable Documentation

◆ return

return

Definition at line 478 of file xlat_inst.c.

◆ xlat_inst_tree

fr_heap_t* xlat_inst_tree
static

Holds instance data created by xlat_instantiate.

Definition at line 36 of file xlat_inst.c.

◆ xlat_thread_inst_tree

_Thread_local fr_heap_t* xlat_thread_inst_tree
static

Holds thread specific instance data created by xlat_instantiate.

Definition at line 40 of file xlat_inst.c.