The FreeRADIUS server $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Loading...
Searching...
No Matches
Data Structures | Typedefs | Functions | Variables
module.c File Reference

Defines functions for module initialisation. More...

#include <freeradius-devel/server/base.h>
#include <freeradius-devel/server/module_rlm.h>
#include <freeradius-devel/server/radmin.h>
#include <freeradius-devel/unlang/xlat_func.h>
#include <sys/mman.h>
+ Include dependency graph for module.c:

Go to the source code of this file.

Data Structures

struct  mlg_module_instance_t
 
struct  mltl_module_instance_t
 A slightly larger module_instance structure to hold the module instance and thread instance. More...
 
struct  module_list_type_s
 Structure to hold callbacks for a module list type. More...
 
struct  module_list_type_s.thread
 Callbacks to manage thread-local data. More...
 

Typedefs

typedef int(* module_list_data_add_t) (module_instance_t *mi)
 Callback to add data for a module.
 
typedef void(* module_list_data_del_t) (module_instance_t *mi)
 Callback to del data for a module.
 
typedef void(* module_list_free_t) (module_list_t *ml)
 Callback to free any global structures associated with the module list.
 
typedef int(* module_list_init_t) (module_list_t *ml)
 Callback to initialise any global structures required for the module list.
 
typedef int(* module_list_thread_data_add_t) (module_thread_instance_t *ti)
 Callback to add thread-local data for a module.
 
typedef void(* module_list_thread_data_del_t) (module_thread_instance_t *ti)
 Callback to remove thread-local data for a module.
 
typedef void(* module_list_thread_free_t) (module_list_t *ml)
 Callback to free thread-local structures, called once per thread as the thread is being destroyed.
 
typedef int(* module_list_thread_init_t) (TALLOC_CTX **ctx, module_list_t const *ml)
 Callback to initialise a list for thread-local data, called once per thread.
 

Functions

static int _mlg_global_free (UNUSED void *uctx)
 Free the global module index.
 
static int _mlg_global_init (UNUSED void *uctx)
 Initialise the global module index.
 
static int8_t _mlg_module_instance_cmp (void const *one, void const *two)
 Sort module instance data first by list then by number.
 
static int _module_dl_loader_free (UNUSED void *uctx)
 
static int _module_dl_loader_init (void *uctx)
 
static int _module_instance_free (module_instance_t *mi)
 Free module's instance data, and any xlats or paircmps.
 
static int _module_list_free (module_list_t *ml)
 Free all modules loaded by the server.
 
static int _module_thread_inst_free (module_thread_instance_t *ti)
 Callback to free thread local data.
 
static int _module_thread_inst_list_free (void *tilp)
 Free the thread local heap on exit.
 
static int cmd_set_module_status (UNUSED FILE *fp, FILE *fp_err, void *ctx, fr_cmd_info_t const *info)
 
static int cmd_show_module_config (FILE *fp, UNUSED FILE *fp_err, void *ctx, UNUSED fr_cmd_info_t const *info)
 
static int cmd_show_module_list (FILE *fp, UNUSED FILE *fp_err, UNUSED void *uctx, UNUSED fr_cmd_info_t const *info)
 
static int cmd_show_module_status (FILE *fp, UNUSED FILE *fp_err, void *ctx, UNUSED fr_cmd_info_t const *info)
 
static int mlg_data_add (module_instance_t *mi)
 Add the unique index value so we can do thread local lookups.
 
static void mlg_data_del (module_instance_t *mi)
 
static int mlg_init (UNUSED module_list_t *ml)
 Global initialisation for index heap and module array.
 
static int mlg_thread_data_add (module_thread_instance_t *ti)
 
static void mlg_thread_data_del (module_thread_instance_t *ti)
 
static module_thread_instance_tmlg_thread_data_get (module_instance_t const *mi)
 Retrieve the thread-specific data for a module from the thread-local array of instance data.
 
static int mlg_thread_init (UNUSED TALLOC_CTX **ctx, UNUSED module_list_t const *ml)
 Allocate a thread-local array to hold thread data for each module thats been instantiated.
 
static void mltl_mlg_data_del (module_instance_t *mi)
 
static int mltl_thread_data_add (module_thread_instance_t *ti)
 
static void mltl_thread_data_del (module_thread_instance_t *ti)
 
static module_thread_instance_tmltl_thread_data_get (module_instance_t const *mi)
 
int module_bootstrap (module_instance_t *mi)
 Manually complete module bootstrap by calling its instantiate function.
 
static int module_data_protect (module_instance_t *mi, module_data_pool_t *pool)
 Protect module data.
 
static int module_data_unprotect (module_instance_t const *mi, module_data_pool_t const *pool)
 Unprotect module data.
 
static void module_detach_parent (module_instance_t *mi)
 Detach the shallowest parent first.
 
module_instance_tmodule_instance_alloc (module_list_t *ml, module_instance_t const *parent, dl_module_type_t type, char const *mod_name, char const *inst_name, module_instance_state_t init_state)
 Allocate a new module and add it to a module list for later bootstrap/instantiation.
 
module_instance_tmodule_instance_by_data (module_list_t const *ml, void const *data)
 Find an existing module instance by its private instance data.
 
module_instance_tmodule_instance_by_name (module_list_t const *ml, module_instance_t const *parent, char const *asked_name)
 Find an existing module instance by its name and parent.
 
int module_instance_conf_parse (module_instance_t *mi, CONF_SECTION *conf)
 Covert a CONF_SECTION into parsed module instance data.
 
module_instance_tmodule_instance_copy (module_list_t *dst, module_instance_t const *src, char const *inst_name)
 Duplicate a module instance, placing it in a new module list.
 
static void module_instance_data_alloc (TALLOC_CTX *ctx, module_data_pool_t *pool_out, void **out, module_instance_t *mi, size_t size, char const *type)
 Allocate module instance data.
 
static int8_t module_instance_data_cmp (void const *one, void const *two)
 Compare module's by their private instance data.
 
int module_instance_data_protect (module_instance_t *mi)
 Mark module data as read only.
 
int module_instance_data_unprotect (module_instance_t *mi)
 Mark module data as read/write.
 
void module_instance_debug (module_instance_t const *mi)
 Print debugging information for a module.
 
static fr_slen_t module_instance_name (TALLOC_CTX *ctx, char **out, module_instance_t const *parent, char const *inst_name)
 Generate a module name from the module's name and its parents.
 
static int8_t module_instance_name_cmp (void const *one, void const *two)
 Compare module instances by parent and name.
 
fr_slen_t module_instance_name_from_conf (char const **name, CONF_SECTION *conf)
 Avoid boilerplate when setting the module instance name.
 
fr_slen_t module_instance_name_valid (char const *inst_name)
 Check to see if a module instance name is valid.
 
module_instance_tmodule_instance_root (module_instance_t const *child)
 Find the module's shallowest parent.
 
char const * module_instance_root_prefix_str (module_instance_t const *mi)
 Return the prefix string for the deepest module.
 
bool module_instance_skip_bootstrap (module_instance_t *mi)
 Should we bootstrap this module instance?
 
bool module_instance_skip_instantiate (module_instance_t *mi)
 Should we instantiate this module instance?
 
bool module_instance_skip_thread_instantiate (module_instance_t *mi)
 Should we instantiate this module instance in a new thread?
 
void module_instance_uctx_set (module_instance_t *mi, void *uctx)
 Set the uctx pointer for a module instance.
 
int module_instantiate (module_instance_t *instance)
 Manually complete module setup by calling its instantiate function.
 
module_list_tmodule_list_alloc (TALLOC_CTX *ctx, module_list_type_t const *type, char const *name, bool write_protect)
 Allocate a new module list.
 
void module_list_debug (module_list_t const *ml)
 Print the contents of a module list.
 
void module_list_mask_set (module_list_t *ml, module_instance_state_t mask)
 Set a new bootstrap/instantiate state for a list.
 
static int module_name_tab_expand (UNUSED TALLOC_CTX *talloc_ctx, UNUSED void *uctx, fr_cmd_info_t *info, int max_expansions, char const **expansions)
 
int module_submodule_parse (UNUSED TALLOC_CTX *ctx, void *out, void *parent, CONF_ITEM *ci, conf_parser_t const *rule)
 Generic callback for conf_parser_t to load a submodule.
 
module_thread_instance_tmodule_thread_by_data (module_list_t const *ml, void const *data)
 Retrieve module/thread specific instance data for a module.
 
static void module_thread_detach (module_thread_instance_t *ti)
 
int module_thread_instantiate (TALLOC_CTX *ctx, module_instance_t *mi, fr_event_list_t *el)
 Allocate thread-local instance data for a module.
 
int modules_bootstrap (module_list_t const *ml)
 Bootstrap any modules which have not been bootstrapped already.
 
void modules_init (char const *lib_dir)
 Perform global initialisation for modules.
 
int modules_instantiate (module_list_t const *ml)
 Completes instantiation of modules.
 
void modules_thread_detach (module_list_t *ml)
 Remove thread-specific data for a given module list.
 
int modules_thread_instantiate (TALLOC_CTX *ctx, module_list_t const *ml, fr_event_list_t *el)
 Creates per-thread instance data for modules which need it.
 

Variables

return count
 
static dl_module_loader_tdl_modules = NULL
 dl module tracking
 
static fr_heap_tmlg_index
 Heap of all lists/modules used to get a common index with mlg_thread->inst_list.
 
static _Thread_local module_thread_instance_t ** mlg_thread_inst_list
 An array of thread-local module lists.
 
fr_cmd_table_t module_cmd_list_table []
 
fr_cmd_table_t module_cmd_table []
 
bool const module_instance_allowed_chars [UINT8_MAX+1]
 Chars that are allowed in a module instance name.
 
module_list_type_t const module_list_type_global
 Callbacks for a global module list.
 
module_list_type_t const module_list_type_thread_local
 Callbacks for a thread local list.
 
 return
 

Detailed Description

Defines functions for module initialisation.

Id
5f5424af6d1cb0fab72e7b7f4559c620006521e9

Definition in file module.c.


Data Structure Documentation

◆ mlg_module_instance_t

struct mlg_module_instance_t

Definition at line 348 of file module.c.

+ Collaboration diagram for mlg_module_instance_t:
Data Fields
fr_heap_index_t inst_idx Entry in the bootstrap/instantiation heap.

should be an identical value to the thread-specific data for this module.

module_instance_t mi Common module instance fields. Must come first.

◆ mltl_module_instance_t

struct mltl_module_instance_t

A slightly larger module_instance structure to hold the module instance and thread instance.

Definition at line 549 of file module.c.

+ Collaboration diagram for mltl_module_instance_t:
Data Fields
module_instance_t mi Common module instance fields. Must come first.
module_thread_instance_t * ti Thread-specific data.

Still in its own structure for talloc reasons.

◆ module_list_type_s

struct module_list_type_s

Structure to hold callbacks for a module list type.

We care about performance for module lists, as they're used heavily at runtime.

As much as possible we try to avoid jumping through unecessary functions and unecessary switch statements.

This structure contains callbacks which change how the module list operates, making it either a global module list, or a thread-local module list, i.e. one which only be used by a single thread.

Instances of this structure are created in this compilation unit, and exported for the caller to pass into module_list_alloc().

Definition at line 323 of file module.c.

+ Collaboration diagram for module_list_type_s:
Data Fields
module_list_data_add_t data_add Record that module data has been added.
module_list_data_del_t data_del Record that module data has been removed.
module_list_free_t free Free any global structures required for thread-local lookups.
module_list_init_t init Initialise any global structures required for thread-local lookups.
size_t inst_size Size of talloc chunk to allocate for the module_instance_t.

allows over-allocation if list types want to append fields.

size_t list_size Size of talloc_chunk to allocate for the module_list_t.
struct module_list_type_s.thread thread Callbacks to manage thread-local data.

◆ module_list_type_s.thread

struct module_list_type_s.thread

Callbacks to manage thread-local data.

Definition at line 336 of file module.c.

Data Fields
void * data Pointer to hold any global resources for the thread-local implementation.
module_list_thread_data_add_t data_add Add thread-local data for a module.
module_list_thread_data_del_t data_del Remove (but not free) thread-local data for a module.
module_list_thread_data_get_t data_get Retrieve thread local-data for a module.
module_list_thread_free_t free Free any thread-local structures.
module_list_thread_init_t init Initialise any thread-local structures required for thread-local lookups.

Typedef Documentation

◆ module_list_data_add_t

typedef int(* module_list_data_add_t) (module_instance_t *mi)

Callback to add data for a module.

Parameters
[in]mito add data for. Use mi->ml for the module list. Use mi->data to access the data.
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 260 of file module.c.

◆ module_list_data_del_t

typedef void(* module_list_data_del_t) (module_instance_t *mi)

Callback to del data for a module.

Parameters
[in]mito add data to (use mi->ml for the module list).

Definition at line 267 of file module.c.

◆ module_list_free_t

typedef void(* module_list_free_t) (module_list_t *ml)

Callback to free any global structures associated with the module list.

Parameters
[in]mlto free.

Definition at line 249 of file module.c.

◆ module_list_init_t

typedef int(* module_list_init_t) (module_list_t *ml)

Callback to initialise any global structures required for the module list.

Parameters
[in]mlto initialise global data for.
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 243 of file module.c.

◆ module_list_thread_data_add_t

typedef int(* module_list_thread_data_add_t) (module_thread_instance_t *ti)

Callback to add thread-local data for a module.

Parameters
[in]tito add data for. Use ti->mi->ml for the module list. Use ti->mi for the module instance. Use ti->data for the thread specific data.
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 298 of file module.c.

◆ module_list_thread_data_del_t

typedef void(* module_list_thread_data_del_t) (module_thread_instance_t *ti)

Callback to remove thread-local data for a module.

Parameters
[in]tito del data for. Use ti->mi->ml for the module list. Use ti->mi for the module instance. Use ti->data for the thread specific data.

Definition at line 307 of file module.c.

◆ module_list_thread_free_t

typedef void(* module_list_thread_free_t) (module_list_t *ml)

Callback to free thread-local structures, called once per thread as the thread is being destroyed.

Parameters
[in]mlto free thread-local data for.

Definition at line 286 of file module.c.

◆ module_list_thread_init_t

typedef int(* module_list_thread_init_t) (TALLOC_CTX **ctx, module_list_t const *ml)

Callback to initialise a list for thread-local data, called once per thread.

Parameters
[in]ctxtalloc context for thread-local data. May be modified by the init function if the module_thread_instance_t need to be parented by another ctx.
[in]mlto initialise thread-local data for.
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 280 of file module.c.

Function Documentation

◆ _mlg_global_free()

static int _mlg_global_free ( UNUSED void *  uctx)
static

Free the global module index.

Definition at line 379 of file module.c.

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

◆ _mlg_global_init()

static int _mlg_global_init ( UNUSED void *  uctx)
static

Initialise the global module index.

Definition at line 387 of file module.c.

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

◆ _mlg_module_instance_cmp()

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

Sort module instance data first by list then by number.

The module's position in the global instance heap informs of us of its position in the thread-specific heap, which allows for O(1) lookups.

Definition at line 362 of file module.c.

+ Here is the caller graph for this function:

◆ _module_dl_loader_free()

static int _module_dl_loader_free ( UNUSED void *  uctx)
static

Definition at line 1898 of file module.c.

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

◆ _module_dl_loader_init()

static int _module_dl_loader_init ( void *  uctx)
static

Definition at line 1885 of file module.c.

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

◆ _module_instance_free()

static int _module_instance_free ( module_instance_t mi)
static

Free module's instance data, and any xlats or paircmps.

Parameters
[in]mito free.
Returns
0

Definition at line 1457 of file module.c.

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

◆ _module_list_free()

static int _module_list_free ( module_list_t ml)
static

Free all modules loaded by the server.

Parameters
[in]mlModule list being freed.
Returns
0

Definition at line 1771 of file module.c.

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

◆ _module_thread_inst_free()

static int _module_thread_inst_free ( module_thread_instance_t ti)
static

Callback to free thread local data.

ti->data is allocated in the context of ti, so will be freed too.

Calls the detach function for thread local data, and removes the data from the thread local list.

Parameters
[in]tito free.

Definition at line 1041 of file module.c.

+ Here is the caller graph for this function:

◆ _module_thread_inst_list_free()

static int _module_thread_inst_list_free ( void *  tilp)
static

Free the thread local heap on exit.

All thread local module lists should have been destroyed by this point

Definition at line 440 of file module.c.

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

◆ cmd_set_module_status()

static int cmd_set_module_status ( UNUSED FILE *  fp,
FILE *  fp_err,
void *  ctx,
fr_cmd_info_t const *  info 
)
static

Definition at line 183 of file module.c.

+ Here is the call graph for this function:

◆ cmd_show_module_config()

static int cmd_show_module_config ( FILE *  fp,
UNUSED FILE *  fp_err,
void *  ctx,
UNUSED fr_cmd_info_t const *  info 
)
static

Definition at line 121 of file module.c.

+ Here is the call graph for this function:

◆ cmd_show_module_list()

static int cmd_show_module_list ( FILE *  fp,
UNUSED FILE *  fp_err,
UNUSED void *  uctx,
UNUSED fr_cmd_info_t const *  info 
)
static

Definition at line 158 of file module.c.

◆ cmd_show_module_status()

static int cmd_show_module_status ( FILE *  fp,
UNUSED FILE *  fp_err,
void *  ctx,
UNUSED fr_cmd_info_t const *  info 
)
static

Definition at line 169 of file module.c.

◆ mlg_data_add()

static int mlg_data_add ( module_instance_t mi)
static

Add the unique index value so we can do thread local lookups.

Definition at line 411 of file module.c.

+ Here is the call graph for this function:

◆ mlg_data_del()

static void mlg_data_del ( module_instance_t mi)
static

Definition at line 425 of file module.c.

+ Here is the call graph for this function:

◆ mlg_init()

static int mlg_init ( UNUSED module_list_t ml)
static

Global initialisation for index heap and module array.

Definition at line 396 of file module.c.

+ Here is the call graph for this function:

◆ mlg_thread_data_add()

static int mlg_thread_data_add ( module_thread_instance_t ti)
static

Definition at line 517 of file module.c.

◆ mlg_thread_data_del()

static void mlg_thread_data_del ( module_thread_instance_t ti)
static

Definition at line 524 of file module.c.

◆ mlg_thread_data_get()

static module_thread_instance_t * mlg_thread_data_get ( module_instance_t const *  mi)
static

Retrieve the thread-specific data for a module from the thread-local array of instance data.

This looks complex, but it's just asserts for sanity. This is really only returning an array offset.

Parameters
[in]miModule instance to get the thread-specific data for.

Definition at line 488 of file module.c.

+ Here is the call graph for this function:

◆ mlg_thread_init()

static int mlg_thread_init ( UNUSED TALLOC_CTX **  ctx,
UNUSED module_list_t const *  ml 
)
static

Allocate a thread-local array to hold thread data for each module thats been instantiated.

Parameters
[in]ctxTalloc context for the thread-local data. Mutated by this function so that thread local data is allocated beneath the array.
[in]mlModule list to initialise the thread-local data for.

Definition at line 464 of file module.c.

+ Here is the call graph for this function:

◆ mltl_mlg_data_del()

static void mltl_mlg_data_del ( module_instance_t mi)
static

Definition at line 555 of file module.c.

+ Here is the call graph for this function:

◆ mltl_thread_data_add()

static int mltl_thread_data_add ( module_thread_instance_t ti)
static

Definition at line 571 of file module.c.

◆ mltl_thread_data_del()

static void mltl_thread_data_del ( module_thread_instance_t ti)
static

Definition at line 578 of file module.c.

◆ mltl_thread_data_get()

static module_thread_instance_t * mltl_thread_data_get ( module_instance_t const *  mi)
static

Definition at line 565 of file module.c.

◆ module_bootstrap()

int module_bootstrap ( module_instance_t mi)

Manually complete module bootstrap by calling its instantiate function.

  • Parse the module configuration.
  • Call the modules "bootstrap" method.
Parameters
[in]miModule instance to bootstrap.
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 1306 of file module.c.

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

◆ module_data_protect()

static int module_data_protect ( module_instance_t mi,
module_data_pool_t pool 
)
inlinestatic

Protect module data.

Parameters
[in]mimodule instance.
[in]poolto protect
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 651 of file module.c.

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

◆ module_data_unprotect()

static int module_data_unprotect ( module_instance_t const *  mi,
module_data_pool_t const *  pool 
)
inlinestatic

Unprotect module data.

Parameters
[in]mimodule instance.
[in]poolto protect
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 675 of file module.c.

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

◆ module_detach_parent()

static void module_detach_parent ( module_instance_t mi)
static

Detach the shallowest parent first.

This ensures that the module's parent is detached before it is.

Generally parents reach into their children and not the other way around. Calling the parent's detach method first ensures that there's no code that access the child module's instance data or reach into its symbol space if it's being unloaded.

Note
If you don't want to detach the parent, maybe because its children are ephemeral, consider using a seaprate thread-local module list to hold the children instead.
Parameters
[in]mito detach.

Definition at line 1431 of file module.c.

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

◆ module_instance_alloc()

module_instance_t * module_instance_alloc ( module_list_t ml,
module_instance_t const *  parent,
dl_module_type_t  type,
char const *  mod_name,
char const *  inst_name,
module_instance_state_t  init_state 
)

Allocate a new module and add it to a module list for later bootstrap/instantiation.

  • Load the module shared library.
  • Allocate instance data for it.
Parameters
[in]mlTo add module to.
[in]parentof the module being bootstrapped, if this is a submodule. If this is not a submodule parent must be NULL.
[in]typeWhat type of module we're loading. Determines the prefix added to the library name. Should be one of:
  • DL_MODULE_TYPE_MODULE - Standard backend module.
  • DL_MODULE_TYPE_SUBMODULE - Usually a driver for a backend module.
  • DL_MODULE_TYPE_PROTO - A module associated with a listen section.
  • DL_MODULE_TYPE_PROCESS - Protocol state machine bound to a virtual server.
[in]mod_nameThe name of this module, i.e. 'redis' for 'rlm_redis'.
[in]inst_nameInstance name for this module, i.e. "aws_redis_01". The notable exception is if this is a submodule, in which case inst_name is usually the mod_name.
[in]init_stateThe state the module "starts" in. Can be used to prevent bootstrapping, instantiation, or thread instantiation of the module, by passing one or more of the MODULE_INSTANCE_* flags. Should usually be 0, unless special behaviour is required.
Returns
  • A new module instance handle, containing the module's public interface, and private instance data.
  • NULL on error.

Definition at line 1649 of file module.c.

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

◆ module_instance_by_data()

module_instance_t * module_instance_by_data ( module_list_t const *  ml,
void const *  data 
)

Find an existing module instance by its private instance data.

Parameters
[in]mlto search in.
[in]datato resolve to module_instance_t.
Returns
  • Module instance matching data.
  • NULL if no such module exists.

Definition at line 955 of file module.c.

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

◆ module_instance_by_name()

module_instance_t * module_instance_by_name ( module_list_t const *  ml,
module_instance_t const *  parent,
char const *  asked_name 
)

Find an existing module instance by its name and parent.

Parameters
[in]mlto search in.
[in]parentto qualify search with.
[in]asked_nameThe name of the module we're attempting to find. May include '-' which indicates that it's ok for the module not to be loaded.
Returns
  • Module instance matching name.
  • NULL if no such module exists.

Definition at line 901 of file module.c.

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

◆ module_instance_conf_parse()

int module_instance_conf_parse ( module_instance_t mi,
CONF_SECTION conf 
)

Covert a CONF_SECTION into parsed module instance data.

Definition at line 762 of file module.c.

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

◆ module_instance_copy()

module_instance_t * module_instance_copy ( module_list_t dst,
module_instance_t const *  src,
char const *  inst_name 
)

Duplicate a module instance, placing it in a new module list.

Parameters
[in]dstlist to place the new module instance in.
[in]srcto duplicate.
[in]inst_namenew instance name. If null, src->name will be used.

Definition at line 1532 of file module.c.

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

◆ module_instance_data_alloc()

static void module_instance_data_alloc ( TALLOC_CTX *  ctx,
module_data_pool_t pool_out,
void **  out,
module_instance_t mi,
size_t  size,
char const *  type 
)
inlinestatic

Allocate module instance data.

Parameters
[in]ctxtalloc context to allocate data in.
[out]pool_outwhere to write pool details.
[out]outwhere to write data pointer.
[in]mimodule instance.
[in]sizeof data to allocate.
[in]typetalloc type to assign.

Definition at line 1552 of file module.c.

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

◆ module_instance_data_cmp()

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

Compare module's by their private instance data.

Definition at line 822 of file module.c.

+ Here is the caller graph for this function:

◆ module_instance_data_protect()

int module_instance_data_protect ( module_instance_t mi)

Mark module data as read only.

Parameters
[in]miInstance data to protect (mark as read only).
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 697 of file module.c.

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

◆ module_instance_data_unprotect()

int module_instance_data_unprotect ( module_instance_t mi)

Mark module data as read/write.

Parameters
[in]miInstance data to unprotect (mark as read/write).
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 709 of file module.c.

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

◆ module_instance_debug()

void module_instance_debug ( module_instance_t const *  mi)

Print debugging information for a module.

Parameters
[in]miModule instance to print.

Definition at line 601 of file module.c.

+ Here is the caller graph for this function:

◆ module_instance_name()

static fr_slen_t module_instance_name ( TALLOC_CTX *  ctx,
char **  out,
module_instance_t const *  parent,
char const *  inst_name 
)
static

Generate a module name from the module's name and its parents.

Parameters
[in]ctxWhere to allocate the module name.
[out]outWhere to write a pointer to the instance name.
[in]parentof the module.
[in]inst_namemodule's instance name.

Definition at line 1394 of file module.c.

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

◆ module_instance_name_cmp()

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

Compare module instances by parent and name.

The reason why we need parent, is because we could have submodules with names that conflict with their parent.

Definition at line 788 of file module.c.

+ Here is the caller graph for this function:

◆ module_instance_name_from_conf()

fr_slen_t module_instance_name_from_conf ( char const **  name,
CONF_SECTION conf 
)

Avoid boilerplate when setting the module instance name.

Definition at line 733 of file module.c.

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

◆ module_instance_name_valid()

fr_slen_t module_instance_name_valid ( char const *  inst_name)

Check to see if a module instance name is valid.

Note
On failure the error message may be retrieved with fr_strerror().
Parameters
[in]inst_nameto check.
Returns
  • 0 on success.
  • Negative value on error indicating the position of the bad char.

Definition at line 1589 of file module.c.

+ Here is the caller graph for this function:

◆ module_instance_root()

module_instance_t * module_instance_root ( module_instance_t const *  child)

Find the module's shallowest parent.

Parameters
[in]childto locate the root for.
Returns
  • The module's shallowest parent.
  • NULL on error.

Definition at line 933 of file module.c.

+ Here is the caller graph for this function:

◆ module_instance_root_prefix_str()

char const * module_instance_root_prefix_str ( module_instance_t const *  mi)

Return the prefix string for the deepest module.

This is useful for submodules which don't have a prefix of their own. In this case we need to use the prefix of the shallowest module, which will be a proto or rlm module.

Parameters
[in]miInstance to get the prefix for.
Returns
The prefix string for the shallowest module.

Definition at line 723 of file module.c.

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

◆ module_instance_skip_bootstrap()

bool module_instance_skip_bootstrap ( module_instance_t mi)

Should we bootstrap this module instance?

Parameters
[in]mito check.
Returns
  • true if the module instance should be bootstrapped.
  • false if the module instance has already been bootstrapped.

Definition at line 1799 of file module.c.

+ Here is the caller graph for this function:

◆ module_instance_skip_instantiate()

bool module_instance_skip_instantiate ( module_instance_t mi)

Should we instantiate this module instance?

Parameters
[in]mito check.
Returns
  • true if the module instance should be instantiated.
  • false if the module instance has already been instantiated.

Definition at line 1811 of file module.c.

+ Here is the caller graph for this function:

◆ module_instance_skip_thread_instantiate()

bool module_instance_skip_thread_instantiate ( module_instance_t mi)

Should we instantiate this module instance in a new thread?

Parameters
[in]mito check.
Returns
  • true if the module instance should be instantiated in a new thread.
  • false if the module instance has already been instantiated in a new thread.

Definition at line 1823 of file module.c.

+ Here is the caller graph for this function:

◆ module_instance_uctx_set()

void module_instance_uctx_set ( module_instance_t mi,
void *  uctx 
)

Set the uctx pointer for a module instance.

Parameters
[in]mito set the uctx for.
[in]uctxto set.

Definition at line 1617 of file module.c.

+ Here is the caller graph for this function:

◆ module_instantiate()

int module_instantiate ( module_instance_t instance)

Manually complete module setup by calling its instantiate function.

Parameters
[in]instanceof module to complete instantiation for.
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 1193 of file module.c.

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

◆ module_list_alloc()

module_list_t * module_list_alloc ( TALLOC_CTX *  ctx,
module_list_type_t const *  type,
char const *  name,
bool  write_protect 
)

Allocate a new module list.

This is used to instantiate and destroy modules in distinct phases for example, we may need to load all proto modules before rlm modules.

If the list is freed all module instance data will be freed. If no more instances of the module exist the module be unloaded.

Parameters
[in]ctxTo allocate the list in.
[in]typeof the list. Controls whether this is a global module list, or a per-thread list containing variants of an existing module.
[in]nameof the list. Used for debugging.
[in]write_protectWhether to write protect the module data after instantiation and bootstrapping.
Returns
A new module list.

Definition at line 1855 of file module.c.

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

◆ module_list_debug()

void module_list_debug ( module_list_t const *  ml)

Print the contents of a module list.

Definition at line 619 of file module.c.

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

◆ module_list_mask_set()

void module_list_mask_set ( module_list_t ml,
module_instance_state_t  mask 
)

Set a new bootstrap/instantiate state for a list.

Parameters
[in]mlTo set the state for.
[in]maskNew state.

Definition at line 1833 of file module.c.

+ Here is the caller graph for this function:

◆ module_name_tab_expand()

static int module_name_tab_expand ( UNUSED TALLOC_CTX *  talloc_ctx,
UNUSED void *  uctx,
fr_cmd_info_t info,
int  max_expansions,
char const **  expansions 
)
static

Definition at line 132 of file module.c.

+ Here is the call graph for this function:

◆ module_submodule_parse()

int module_submodule_parse ( UNUSED TALLOC_CTX *  ctx,
void *  out,
void *  parent,
CONF_ITEM ci,
conf_parser_t const *  rule 
)

Generic callback for conf_parser_t to load a submodule.

conf_parser_t entry should point to a module_instance_t field in the instance data

Parameters
[in]ctxunused.
[out]outA pointer to a pointer to a module_instance_t.
[in]parentThis must point to the instance data of the parent module.
[in]ciThe CONF_PAIR containing the name of the submodule to load.
[in]ruleuctx pointer must be a pointer to a module_list_t ** containing the list to search in.
Returns
  • 0 on success.
  • -1 if we failed to load the submodule.

Definition at line 845 of file module.c.

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

◆ module_thread_by_data()

module_thread_instance_t * module_thread_by_data ( module_list_t const *  ml,
void const *  data 
)

Retrieve module/thread specific instance data for a module.

Parameters
[in]mlModule list module belongs to.
[in]dataPrivate instance data of the module. Same as what would be provided by module_instance_by_data.
Returns
  • Thread specific instance data on success.
  • NULL if module has no thread instance data.

Definition at line 978 of file module.c.

+ Here is the call graph for this function:

◆ module_thread_detach()

static void module_thread_detach ( module_thread_instance_t ti)
static

Definition at line 987 of file module.c.

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

◆ module_thread_instantiate()

int module_thread_instantiate ( TALLOC_CTX *  ctx,
module_instance_t mi,
fr_event_list_t el 
)

Allocate thread-local instance data for a module.

The majority of modules will have a single set of thread-specific instance data.

An exception is dynamic modules, which may have multiple sets of thread-specific instance data tied to a specific dynamic use of that module.

Parameters
[in]ctxTalloc ctx to bind thread specific data to.
[in]miModule instance to perform thread instantiation for.
[in]elEvent list serviced by this thread.
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 1081 of file module.c.

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

◆ modules_bootstrap()

int modules_bootstrap ( module_list_t const *  ml)

Bootstrap any modules which have not been bootstrapped already.

Allows the module to initialise connection pools, and complete any registrations that depend on attributes created during the bootstrap phase.

Parameters
[in]mlcontaining modules to bootstrap.
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 1370 of file module.c.

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

◆ modules_init()

void modules_init ( char const *  lib_dir)

Perform global initialisation for modules.

Definition at line 1908 of file module.c.

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

◆ modules_instantiate()

int modules_instantiate ( module_list_t const *  ml)

Completes instantiation of modules.

Allows the module to initialise connection pools, and complete any registrations that depend on attributes created during the bootstrap phase.

Parameters
[in]mlcontaining modules to instantiate.
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 1279 of file module.c.

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

◆ modules_thread_detach()

void modules_thread_detach ( module_list_t ml)

Remove thread-specific data for a given module list.

Removes all module thread data for the

Definition at line 1007 of file module.c.

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

◆ modules_thread_instantiate()

int modules_thread_instantiate ( TALLOC_CTX *  ctx,
module_list_t const *  ml,
fr_event_list_t el 
)

Creates per-thread instance data for modules which need it.

Must be called by any new threads before attempting to execute unlang sections.

Parameters
[in]ctxTalloc ctx to bind thread specific data to.
[in]mlModule list to perform thread instantiation for.
[in]elEvent list serviced by this thread.
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 1158 of file module.c.

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

Variable Documentation

◆ count

return count

Definition at line 155 of file module.c.

◆ dl_modules

dl_module_loader_t* dl_modules = NULL
static

dl module tracking

This is used by all module lists, irrespecitve of their type, and is thread safe.

Definition at line 234 of file module.c.

◆ mlg_index

fr_heap_t* mlg_index
static

Heap of all lists/modules used to get a common index with mlg_thread->inst_list.

Definition at line 42 of file module.c.

◆ mlg_thread_inst_list

_Thread_local module_thread_instance_t** mlg_thread_inst_list
static

An array of thread-local module lists.

The indexes in this array are identical to module_list_global, allowing O(1) lookups. Arrays are used here as there's no performance penalty once they're populated.

Definition at line 50 of file module.c.

◆ module_cmd_list_table

fr_cmd_table_t module_cmd_list_table[]
Initial value:
= {
{
.parent = "show",
.name = "module",
.help = "Show information about modules.",
.tab_expand = module_name_tab_expand,
.read_only = true,
},
{
.parent = "show module",
.name = "list",
.help = "Show the list of modules loaded in the server.",
.read_only = true,
},
{
.parent = "set",
.name = "module",
.help = "Change module settings.",
.tab_expand = module_name_tab_expand,
.read_only = false,
},
}
#define CMD_TABLE_END
Definition command.h:62
static int cmd_show_module_list(FILE *fp, UNUSED FILE *fp_err, UNUSED void *uctx, UNUSED fr_cmd_info_t const *info)
Definition module.c:158
static int module_name_tab_expand(UNUSED TALLOC_CTX *talloc_ctx, UNUSED void *uctx, fr_cmd_info_t *info, int max_expansions, char const **expansions)
Definition module.c:132

Definition at line 91 of file module.c.

◆ module_cmd_table

fr_cmd_table_t module_cmd_table[]

Definition at line 58 of file module.c.

◆ module_instance_allowed_chars

bool const module_instance_allowed_chars[UINT8_MAX+1]
Initial value:
= {
['-'] = true, ['/'] = true, ['_'] = true, ['.'] = true,
['0'] = true, ['1'] = true, ['2'] = true, ['3'] = true, ['4'] = true,
['5'] = true, ['6'] = true, ['7'] = true, ['8'] = true, ['9'] = true,
['A'] = true, ['B'] = true, ['C'] = true, ['D'] = true, ['E'] = true,
['F'] = true, ['G'] = true, ['H'] = true, ['I'] = true, ['J'] = true,
['K'] = true, ['L'] = true, ['M'] = true, ['N'] = true, ['O'] = true,
['P'] = true, ['Q'] = true, ['R'] = true, ['S'] = true, ['T'] = true,
['U'] = true, ['V'] = true, ['W'] = true, ['X'] = true, ['Y'] = true,
['Z'] = true,
['a'] = true, ['b'] = true, ['c'] = true, ['d'] = true, ['e'] = true,
['f'] = true, ['g'] = true, ['h'] = true, ['i'] = true, ['j'] = true,
['k'] = true, ['l'] = true, ['m'] = true, ['n'] = true, ['o'] = true,
['p'] = true, ['q'] = true, ['r'] = true, ['s'] = true, ['t'] = true,
['u'] = true, ['v'] = true, ['w'] = true, ['x'] = true, ['y'] = true,
['z'] = true
}

Chars that are allowed in a module instance name.

Definition at line 212 of file module.c.

◆ module_list_type_global

module_list_type_t const module_list_type_global
Initial value:
= {
.init = mlg_init,
.inst_size = sizeof(mlg_module_instance_t),
.data_add = mlg_data_add,
.data_del = mlg_data_del,
.thread = {
.init = mlg_thread_init,
.data_add = mlg_thread_data_add,
.data_get = mlg_thread_data_get,
.data_del = mlg_thread_data_del
}
}
static int mlg_init(UNUSED module_list_t *ml)
Global initialisation for index heap and module array.
Definition module.c:396
static int mlg_data_add(module_instance_t *mi)
Add the unique index value so we can do thread local lookups.
Definition module.c:411
static void mlg_thread_data_del(module_thread_instance_t *ti)
Definition module.c:524
static int mlg_thread_data_add(module_thread_instance_t *ti)
Definition module.c:517
static module_thread_instance_t * mlg_thread_data_get(module_instance_t const *mi)
Retrieve the thread-specific data for a module from the thread-local array of instance data.
Definition module.c:488
static int mlg_thread_init(UNUSED TALLOC_CTX **ctx, UNUSED module_list_t const *ml)
Allocate a thread-local array to hold thread data for each module thats been instantiated.
Definition module.c:464
static void mlg_data_del(module_instance_t *mi)
Definition module.c:425

Callbacks for a global module list.

Initialise a global module, with thread-specific data.

Definition at line 532 of file module.c.

◆ module_list_type_thread_local

module_list_type_t const module_list_type_thread_local
Initial value:
= {
.inst_size = sizeof(mltl_module_instance_t),
.data_del = mltl_mlg_data_del,
.thread = {
.data_add = mltl_thread_data_add,
.data_get = mltl_thread_data_get,
}
}
static int mltl_thread_data_add(module_thread_instance_t *ti)
Definition module.c:571
static module_thread_instance_t * mltl_thread_data_get(module_instance_t const *mi)
Definition module.c:565
static void mltl_thread_data_del(module_thread_instance_t *ti)
Definition module.c:578
static void mltl_mlg_data_del(module_instance_t *mi)
Definition module.c:555
A slightly larger module_instance structure to hold the module instance and thread instance.
Definition module.c:549

Callbacks for a thread local list.

Initialise a thread-local module, which is only used in a single thread.

Definition at line 586 of file module.c.

◆ return

return

Definition at line 166 of file module.c.