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

Defines functions for module (re-)initialisation. More...

#include <freeradius-devel/server/base.h>
#include <freeradius-devel/server/cf_file.h>
#include <freeradius-devel/server/modpriv.h>
#include <freeradius-devel/server/module_rlm.h>
#include <freeradius-devel/server/radmin.h>
#include <freeradius-devel/server/request_data.h>
#include <freeradius-devel/server/module.h>
#include <freeradius-devel/util/strerror.h>
#include <freeradius-devel/unlang/xlat_func.h>
+ Include dependency graph for module.c:

Go to the source code of this file.

Functions

static int _module_global_list_free (UNUSED void *uctx)
 
static int _module_global_list_init (void *uctx)
 
static int _module_instance_free (module_instance_t *mi)
 Free module's instance data, and any xlats or paircmps. More...
 
static int8_t _module_instance_global_cmp (void const *one, void const *two)
 Sort module instance data first by list then by number. More...
 
static int _module_list_free (module_list_t *ml)
 Free all modules loaded by the server. More...
 
static int _module_thread_inst_free (module_thread_instance_t *ti)
 
static int _module_thread_inst_list_free (void *tilp)
 Free the thread local heap on exit. More...
 
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)
 
module_instance_tmodule_alloc (module_list_t *ml, module_instance_t const *parent, dl_module_type_t type, char const *mod_name, char const *inst_name)
 Allocate a new module and add it to a module list for later bootstrap/instantiation. More...
 
int module_bootstrap (module_instance_t *mi)
 Manually complete module bootstrap by calling its instantiate function. More...
 
module_instance_tmodule_by_data (module_list_t const *ml, void const *data)
 Find an existing module instance by its private instance data. More...
 
module_instance_tmodule_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. More...
 
int module_conf_parse (module_instance_t *mi, CONF_SECTION *mod_conf)
 Parse the configuration associated with a module. More...
 
void module_free (module_instance_t *mi)
 Explicitly free a module if a fatal error occurs during bootstrap. More...
 
static int8_t module_instance_data_cmp (void const *one, void const *two)
 Compare module's by their private instance data. More...
 
static fr_slen_t module_instance_name (TALLOC_CTX *ctx, char **out, module_list_t const *ml, module_instance_t const *parent, char const *inst_name)
 Generate a module name from the module's name and its parents. More...
 
static int8_t module_instance_name_cmp (void const *one, void const *two)
 Compare module instances by parent and name. More...
 
int module_instantiate (module_instance_t *instance)
 Manually complete module setup by calling its instantiate function. More...
 
module_list_tmodule_list_alloc (TALLOC_CTX *ctx, char const *name)
 Allocate a new module list. More...
 
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)
 
module_instance_tmodule_parent (module_instance_t const *child)
 Find the module's parent (if any) More...
 
module_instance_tmodule_root (module_instance_t const *child)
 Find the module's shallowest parent. More...
 
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. More...
 
module_thread_instance_tmodule_thread (module_instance_t *mi)
 Retrieve module/thread specific instance for a module. More...
 
module_thread_instance_tmodule_thread_by_data (module_list_t const *ml, void const *data)
 Retrieve module/thread specific instance data for a module. More...
 
static int module_thread_instantiate (TALLOC_CTX *ctx, module_thread_instance_t **out, module_list_t const *ml, module_instance_t *mi, fr_event_list_t *el)
 Allocate thread-local instance data for a module. More...
 
int modules_bootstrap (module_list_t const *ml)
 Bootstrap any modules which have not been bootstrapped already. More...
 
void modules_init (char const *lib_dir)
 Perform global initialisation for modules. More...
 
int modules_instantiate (module_list_t const *ml)
 Completes instantiation of modules. More...
 
void modules_thread_detach (module_list_t const *ml)
 Remove thread-specific data for a given module list. More...
 
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. More...
 

Variables

return count
 
static dl_module_loader_tdl_modules = NULL
 dl module tracking More...
 
fr_cmd_table_t module_cmd_list_table []
 
fr_cmd_table_t module_cmd_table []
 
static fr_heap_tmodule_global_inst_list
 Heap of all lists/modules used to get a common index with module_thread_inst_list. More...
 
static _Thread_local bool module_list_in_sync = true
 Toggle used to determine if it's safe to use index based lookups. More...
 
static _Thread_local module_thread_instance_t ** module_thread_inst_list
 An array of thread-local module lists. More...
 
 return
 

Detailed Description

Defines functions for module (re-)initialisation.

Id
dc6e1b1564c23e459d78892db29760fa35067731

Definition in file module.c.

Function Documentation

◆ _module_global_list_free()

static int _module_global_list_free ( UNUSED void *  uctx)
static

Definition at line 1146 of file module.c.

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

◆ _module_global_list_init()

static int _module_global_list_init ( void *  uctx)
static

Definition at line 1132 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 886 of file module.c.

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

◆ _module_instance_global_cmp()

static int8_t _module_instance_global_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 231 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 1087 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

Definition at line 535 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 563 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 203 of file module.c.

◆ 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 141 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 178 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 189 of file module.c.

◆ module_alloc()

module_instance_t* module_alloc ( module_list_t ml,
module_instance_t const *  parent,
dl_module_type_t  type,
char const *  mod_name,
char const *  inst_name 
)

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.
Returns
  • A new module instance handle, containing the module's public interface, and private instance data.
  • NULL on error.

Definition at line 976 of file module.c.

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

◆ 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 788 of file module.c.

+ Here is the caller graph for this function:

◆ module_by_data()

module_instance_t* module_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 438 of file module.c.

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

◆ module_by_name()

module_instance_t* module_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 367 of file module.c.

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

◆ module_conf_parse()

int module_conf_parse ( module_instance_t mi,
CONF_SECTION mod_conf 
)

Parse the configuration associated with a module.

Parameters
[in]miTo parse the configuration for.
[in]mod_confTo parse.
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 946 of file module.c.

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

◆ module_free()

void module_free ( module_instance_t mi)

Explicitly free a module if a fatal error occurs during bootstrap.

Parameters
[in]mito free.

Definition at line 507 of file module.c.

+ Here is the call 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 288 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_list_t const *  ml,
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]mlModule list in which to find the parent.
[in]parentof the module.
[in]inst_namemodule's instance name.

Definition at line 857 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 250 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 702 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,
char const *  name 
)

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]nameof the list.
Returns
A new module list.

Definition at line 1118 of file module.c.

+ Here is the call graph for this function:
+ 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 152 of file module.c.

+ Here is the call graph for this function:

◆ module_parent()

module_instance_t* module_parent ( module_instance_t const *  child)

Find the module's parent (if any)

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

Definition at line 399 of file module.c.

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

◆ module_root()

module_instance_t* module_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 416 of file module.c.

+ Here is the call graph for this function:
+ Here is the caller 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 311 of file module.c.

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

◆ module_thread()

module_thread_instance_t* module_thread ( module_instance_t mi)

Retrieve module/thread specific instance for a module.

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

Definition at line 459 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_by_data.
Returns
  • Thread specific instance data on success.
  • NULL if module has no thread instance data.

Definition at line 485 of file module.c.

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

◆ module_thread_instantiate()

static int module_thread_instantiate ( TALLOC_CTX *  ctx,
module_thread_instance_t **  out,
module_list_t const *  ml,
module_instance_t mi,
fr_event_list_t el 
)
static

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.
[out]outWhere to write the allocated module_thread_instance_t.
[in]mlModule list to perform thread instantiation for.
[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 597 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 830 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 1163 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 759 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 const *  ml)

Remove thread-specific data for a given module list.

Removes all module thread data for the

Definition at line 516 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 663 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 175 of file module.c.

◆ dl_modules

dl_module_loader_t* dl_modules = NULL
static

dl module tracking

Definition at line 70 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:178
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:152

Definition at line 111 of file module.c.

◆ module_cmd_table

fr_cmd_table_t module_cmd_table[]

Definition at line 78 of file module.c.

◆ module_global_inst_list

fr_heap_t* module_global_inst_list
static

Heap of all lists/modules used to get a common index with module_thread_inst_list.

Definition at line 44 of file module.c.

◆ module_list_in_sync

_Thread_local bool module_list_in_sync = true
static

Toggle used to determine if it's safe to use index based lookups.

Index based heap lookups are significantly more efficient than binary searches, but they can only be performed when all module data is inserted into both the global module list and the thread local module list.

When we start removing module lists or modules from the thread local heap those heaps no longer have a common index with the global module list so we need to revert back to doing binary searches instead of using common indexes.

Definition at line 65 of file module.c.

◆ module_thread_inst_list

_Thread_local module_thread_instance_t** module_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 52 of file module.c.

◆ return

return

Definition at line 186 of file module.c.