The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
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/cf_file.h>
#include <freeradius-devel/server/global_lib.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/util/talloc.h>
#include <freeradius-devel/unlang/xlat_func.h>
#include <talloc.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. More...
 
typedef void(* module_list_data_del_t) (module_instance_t *mi)
 Callback to del data for a module. More...
 
typedef void(* module_list_free_t) (module_list_t *ml)
 Callback to free any global structures associated with the module list. More...
 
typedef int(* module_list_init_t) (module_list_t *ml)
 Callback to initialise any global structures required for the module list. More...
 
typedef int(* module_list_thread_data_add_t) (module_thread_instance_t *ti)
 Callback to add thread-local data for a module. More...
 
typedef void(* module_list_thread_data_del_t) (module_thread_instance_t *ti)
 Callback to remove thread-local data for a module. More...
 
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. More...
 
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. More...
 

Functions

static int _mlg_global_free (UNUSED void *uctx)
 Free the global module index. More...
 
static int _mlg_global_init (UNUSED void *uctx)
 Initialise the global module index. More...
 
static int8_t _mlg_module_instance_cmp (void const *one, void const *two)
 Sort module instance data first by list then by number. More...
 
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. 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)
 Callback to free thread local data. More...
 
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)
 
static int mlg_data_add (module_instance_t *mi)
 Add the unique index value so we can do thread local lookups. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
static int module_data_protect (module_instance_t *mi, module_data_pool_t *pool)
 Protect module data. More...
 
static int module_data_unprotect (module_instance_t const *mi, module_data_pool_t const *pool)
 Unprotect module data. More...
 
static void module_detach_parent (module_instance_t *mi)
 Detach the shallowest parent first. More...
 
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. More...
 
module_instance_tmodule_instance_by_data (module_list_t const *ml, void const *data)
 Find an existing module instance by its private instance data. More...
 
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. More...
 
int module_instance_conf_parse (module_instance_t *mi, CONF_SECTION *conf)
 Covert a CONF_SECTION into parsed module instance data. More...
 
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. More...
 
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. More...
 
static int8_t module_instance_data_cmp (void const *one, void const *two)
 Compare module's by their private instance data. More...
 
int module_instance_data_protect (module_instance_t const *mi)
 Mark module data as read only. More...
 
int module_instance_data_unprotect (module_instance_t const *mi)
 Mark module data as read/write. More...
 
void module_instance_debug (module_instance_t const *mi)
 Print debugging information for a module. More...
 
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. More...
 
static int8_t module_instance_name_cmp (void const *one, void const *two)
 Compare module instances by parent and name. More...
 
fr_slen_t module_instance_name_from_conf (char const **name, CONF_SECTION *conf)
 Avoid boilerplate when setting the module instance name. More...
 
fr_slen_t module_instance_name_valid (char const *inst_name)
 Check to see if a module instance name is valid. More...
 
module_instance_tmodule_instance_root (module_instance_t const *child)
 Find the module's shallowest parent. More...
 
char const * module_instance_root_prefix_str (module_instance_t const *mi)
 Return the prefix string for the deepest module. More...
 
bool module_instance_skip_bootstrap (module_instance_t *mi)
 Should we bootstrap this module instance? More...
 
bool module_instance_skip_instantiate (module_instance_t *mi)
 Should we instantiate this module instance? More...
 
bool module_instance_skip_thread_instantiate (module_instance_t *mi)
 Should we instantiate this module instance in a new thread? More...
 
void module_instance_uctx_set (module_instance_t *mi, void *uctx)
 Set the uctx pointer for a module instance. 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, module_list_type_t const *type, char const *name, bool write_protect)
 Allocate a new module list. More...
 
void module_list_debug (module_list_t const *ml)
 Print the contents of a module list. More...
 
void module_list_mask_set (module_list_t *ml, module_instance_state_t mask)
 Set a new bootstrap/instantiate state for a 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)
 
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_by_data (module_list_t const *ml, void const *data)
 Retrieve module/thread specific instance data for a module. More...
 
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. 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 *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...
 
static fr_heap_tmlg_index
 Heap of all lists/modules used to get a common index with mlg_thread->inst_list. More...
 
static _Thread_local module_thread_instance_t ** mlg_thread_inst_list
 An array of thread-local module lists. More...
 
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. More...
 
module_list_type_t const module_list_type_global
 Callbacks for a global module list. More...
 
module_list_type_t const module_list_type_thread_local
 Callbacks for a thread local list. More...
 
 return
 

Detailed Description

Defines functions for module initialisation.

Id
a9150ac497fb48719805801cc2ce1d9e4898437e

Definition in file module.c.


Data Structure Documentation

◆ mlg_module_instance_t

struct mlg_module_instance_t

Definition at line 352 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 553 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 327 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 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 340 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 264 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 271 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 253 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 247 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 302 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 311 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 290 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 284 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 383 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 391 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 366 of file module.c.

+ Here is the call graph for this function:
+ 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 1900 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 1887 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 1459 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 1773 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 1043 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 444 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 191 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 129 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 166 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 177 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 415 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 429 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 400 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 521 of file module.c.

◆ mlg_thread_data_del()

static void mlg_thread_data_del ( module_thread_instance_t ti)
static

Definition at line 528 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 492 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 468 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 559 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 575 of file module.c.

◆ mltl_thread_data_del()

static void mltl_thread_data_del ( module_thread_instance_t ti)
static

Definition at line 582 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 569 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 1308 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]poolto protect
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 654 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]poolto protect
Returns
  • 0 on success.
  • -1 on failure.

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

+ 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 1651 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 957 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 903 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 764 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 1534 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 1554 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 824 of file module.c.

+ Here is the caller graph for this function:

◆ module_instance_data_protect()

int module_instance_data_protect ( module_instance_t const *  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 699 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 const *  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 711 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 605 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 1396 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 790 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 735 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 1591 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 935 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 725 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 1801 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 1813 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 1825 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 1619 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 1195 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 1857 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 623 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 1835 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 140 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 847 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 980 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 989 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 1083 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 1372 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 1910 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 1281 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 1009 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 1160 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 163 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 238 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 50 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 58 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:166
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:140

Definition at line 99 of file module.c.

◆ module_cmd_table

fr_cmd_table_t module_cmd_table[]

Definition at line 66 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 216 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:400
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:492
static int mlg_data_add(module_instance_t *mi)
Add the unique index value so we can do thread local lookups.
Definition: module.c:415
static void mlg_thread_data_del(module_thread_instance_t *ti)
Definition: module.c:528
static int mlg_thread_data_add(module_thread_instance_t *ti)
Definition: module.c:521
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:468
static void mlg_data_del(module_instance_t *mi)
Definition: module.c:429

Callbacks for a global module list.

Initialise a global module, with thread-specific data.

Definition at line 536 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:575
static module_thread_instance_t * mltl_thread_data_get(module_instance_t const *mi)
Definition: module.c:569
static void mltl_thread_data_del(module_thread_instance_t *ti)
Definition: module.c:582
static void mltl_mlg_data_del(module_instance_t *mi)
Definition: module.c:559
A slightly larger module_instance structure to hold the module instance and thread instance.
Definition: module.c:553

Callbacks for a thread local list.

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

Definition at line 590 of file module.c.

◆ return

return

Definition at line 174 of file module.c.