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

Interface to the FreeRADIUS module system. More...

#include <freeradius-devel/server/cf_util.h>
#include <freeradius-devel/server/request.h>
#include <freeradius-devel/server/module_ctx.h>
#include <freeradius-devel/unlang/action.h>
#include <freeradius-devel/unlang/compile.h>
#include <freeradius-devel/unlang/call_env.h>
#include <freeradius-devel/util/event.h>
#include <freeradius-devel/server/components.h>
#include <freeradius-devel/server/dl_module.h>
#include <freeradius-devel/server/exfile.h>
#include <freeradius-devel/server/pool.h>
#include <freeradius-devel/server/rcode.h>
#include <freeradius-devel/io/schedule.h>
#include <freeradius-devel/features.h>
+ Include dependency graph for module.h:

Go to the source code of this file.

Data Structures

struct  module_instance_s
 Per instance data. More...
 
struct  module_list_t
 A list of modules. More...
 
struct  module_method_name_s
 Named methods exported by a module. More...
 
struct  module_s
 Struct exported by a rlm_* module. More...
 
struct  module_state_func_table_t
 Map string values to module state method. More...
 
struct  module_thread_instance_s
 Per thread per instance data. More...
 

Macros

#define MODULE_NAME_TERMINATOR   { NULL }
 

Typedefs

typedef struct module_instance_s module_instance_t
 
typedef int(* module_instantiate_t) (module_inst_ctx_t const *mctx)
 Module instantiation callback. More...
 
typedef struct module_list_t module_list_t
 
typedef struct module_method_name_s module_method_name_t
 
typedef unlang_action_t(* module_method_t) (rlm_rcode_t *p_result, module_ctx_t const *mctx, request_t *request)
 Module section callback. More...
 
typedef struct module_s module_t
 
typedef int(* module_thread_detach_t) (module_thread_inst_ctx_t const *mctx)
 Module thread destruction callback. More...
 
typedef struct module_thread_instance_s module_thread_instance_t
 
typedef int(* module_thread_instantiate_t) (module_thread_inst_ctx_t const *mctx)
 Module thread creation callback. More...
 

Enumerations

enum  module_flags_t {
  MODULE_TYPE_THREAD_SAFE = (0 << 0) ,
  MODULE_TYPE_THREAD_UNSAFE = (1 << 0) ,
  MODULE_TYPE_RESUMABLE = (1 << 2) ,
  MODULE_TYPE_RETRY = (1 << 3)
}
 
enum  module_instance_state_t {
  MODULE_INSTANCE_INIT = 0 ,
  MODULE_INSTANCE_BOOTSTRAPPED ,
  MODULE_INSTANCE_INSTANTIATED
}
 What state the module instance is currently in. More...
 

Callbacks for the conf_parser_t

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

Module and module thread lookup

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

Module and module thread initialisation and instantiation

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...
 
int module_conf_parse (module_instance_t *mi, CONF_SECTION *mod_cs)
 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...
 
int module_instantiate (module_instance_t *mi)
 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...
 
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...
 

Detailed Description

Interface to the FreeRADIUS module system.

Id
f725600b1b874e3e68e17303ff810ba5582adfe2

Definition in file module.h.


Data Structure Documentation

◆ module_instance_s

struct module_instance_s

Per instance data.

Per-instance data structure, to correlate the modules with the instance names (may NOT be the module names!), and the per-instance data structures.

Definition at line 169 of file module.h.

+ Collaboration diagram for module_instance_s:
Data Fields
unlang_actions_t actions default actions and retries.
rlm_rcode_t code Code module will return when 'force' has has been set to true.
fr_rb_node_t data_node Entry in the data tree.
dl_module_inst_t * dl_inst Structure containing the module's instance data, configuration, and dl handle.

This can be used to access the parsed configuration data for the module.

bool force Force the module to return a specific code.

Usually set via an administrative interface.

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_list_t * ml Module list this instance belongs to.
module_t const * module Public module structure.

Cached for convenience. This exports module methods, i.e. the functions which allow the module to perform actions.

pthread_mutex_t mutex Used prevent multiple threads entering a thread unsafe module simultaneously.
char const * name Instance name e.g. user_database.
fr_rb_node_t name_node Entry in the name tree.
uint32_t number Unique module number.
module_instance_state_t state What's been done with this module so far.

◆ module_list_t

struct module_list_t

A list of modules.

This allows modules to be instantiated and freed in phases, i.e. proto modules before rlm modules.

Definition at line 235 of file module.h.

+ Collaboration diagram for module_list_t:
Data Fields
fr_rb_tree_t * data_tree Modules indexed by data.
uint32_t last_number Last identifier assigned to a module instance.
char const * name Friendly list identifier.
fr_rb_tree_t * name_tree Modules indexed by name.

◆ module_method_name_s

struct module_method_name_s

Named methods exported by a module.

Definition at line 127 of file module.h.

+ Collaboration diagram for module_method_name_s:
Data Fields
module_method_t method Module method to call.
call_env_method_t const * method_env Call specific conf parsing.
char const * name1 i.e. "recv", "send", "process"
char const * name2 The packet type i.e Access-Request, Access-Reject.

◆ module_s

struct module_s

Struct exported by a rlm_* module.

Determines the capabilities of the module, and maps internal functions within the module to different sections.

Definition at line 142 of file module.h.

+ Collaboration diagram for module_s:
Data Fields
module_instantiate_t bootstrap
DL_MODULE_COMMON Common fields for all loadable modules.
int flags
module_instantiate_t instantiate
module_thread_detach_t thread_detach
size_t thread_inst_size
char const * thread_inst_type
module_thread_instantiate_t thread_instantiate

◆ module_state_func_table_t

struct module_state_func_table_t

Map string values to module state method.

Definition at line 245 of file module.h.

+ Collaboration diagram for module_state_func_table_t:
Data Fields
module_method_t func State function.
char const * name String identifier for state.

◆ module_thread_instance_s

struct module_thread_instance_s

Per thread per instance data.

Stores module and thread specific data.

Definition at line 215 of file module.h.

+ Collaboration diagram for module_thread_instance_s:
Data Fields
uint64_t active_callers total number of times we've been called
void * data Thread specific instance data.
fr_event_list_t * el Event list associated with this thread.
fr_heap_index_t inst_idx Entry in the thread-specific bootstrap heap.

Should be an identical value to the global instance data for the same module.

module_instance_t const * mi As opposed to the thread local inst.
uint64_t total_calls

Macro Definition Documentation

◆ MODULE_NAME_TERMINATOR

#define MODULE_NAME_TERMINATOR   { NULL }

Definition at line 135 of file module.h.

Typedef Documentation

◆ module_instance_t

Definition at line 1 of file module.h.

◆ module_instantiate_t

typedef int(* module_instantiate_t) (module_inst_ctx_t const *mctx)

Module instantiation callback.

Is called once per module instance. Is not called when new threads are spawned. See module_thread_instantiate_t for that.

Parameters
[in]mctxHolds global instance data.
Returns
  • 0 on success.
  • -1 if instantiation failed.

Definition at line 81 of file module.h.

◆ module_list_t

typedef struct module_list_t module_list_t

Definition at line 1 of file module.h.

◆ module_method_name_t

Definition at line 1 of file module.h.

◆ module_method_t

typedef unlang_action_t(* module_method_t) (rlm_rcode_t *p_result, module_ctx_t const *mctx, request_t *request)

Module section callback.

Is called when the module is listed in a particular section of a virtual server, and the request has reached the module call.

Parameters
[out]p_resultResult code of the module method.
[in]mctxHolds global instance data, thread instance data and call specific instance data.
[in]requestto process.
Returns
the appropriate rcode.

Definition at line 69 of file module.h.

◆ module_t

typedef struct module_s module_t

Definition at line 1 of file module.h.

◆ module_thread_detach_t

typedef int(* module_thread_detach_t) (module_thread_inst_ctx_t const *mctx)

Module thread destruction callback.

Destroy a module/thread instance.

Parameters
[in]mctxHolds global instance data, thread instance data, and the thread-specific event list.
Returns
  • 0 on success.
  • -1 if instantiation failed.

Definition at line 105 of file module.h.

◆ module_thread_instance_t

Definition at line 1 of file module.h.

◆ module_thread_instantiate_t

typedef int(* module_thread_instantiate_t) (module_thread_inst_ctx_t const *mctx)

Module thread creation callback.

Called whenever a new thread is created.

Parameters
[in]mctxHolds global instance data, thread instance data, and the thread-specific event list.
Returns
  • 0 on success.
  • -1 if instantiation failed.

Definition at line 93 of file module.h.

Enumeration Type Documentation

◆ module_flags_t

Enumerator
MODULE_TYPE_THREAD_SAFE 

Module is threadsafe.

MODULE_TYPE_THREAD_UNSAFE 

Module is not threadsafe.

Server will protect calls with mutex.

MODULE_TYPE_RESUMABLE 

does yield / resume

MODULE_TYPE_RETRY 

can handle retries

Definition at line 48 of file module.h.

◆ module_instance_state_t

What state the module instance is currently in.

Enumerator
MODULE_INSTANCE_INIT 
MODULE_INSTANCE_BOOTSTRAPPED 
MODULE_INSTANCE_INSTANTIATED 

Definition at line 157 of file module.h.

Function Documentation

◆ 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_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_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,
UNUSED conf_parser_t const *  rule 
)

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

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