The FreeRADIUS server
$Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
|
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>
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_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. 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_t * | mltl_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_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. More... | |
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. More... | |
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. 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_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. 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_t * | module_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_t * | module_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_t * | module_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_t * | dl_modules = NULL |
dl module tracking More... | |
static fr_heap_t * | mlg_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 | |
Defines functions for module initialisation.
Definition in file module.c.
struct 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. |
struct mltl_module_instance_t |
A slightly larger module_instance structure to hold the module instance and thread instance.
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. |
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().
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. |
struct module_list_type_s.thread |
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 int(* module_list_data_add_t) (module_instance_t *mi) |
typedef void(* module_list_data_del_t) (module_instance_t *mi) |
typedef void(* module_list_free_t) (module_list_t *ml) |
typedef int(* module_list_init_t) (module_list_t *ml) |
typedef int(* module_list_thread_data_add_t) (module_thread_instance_t *ti) |
typedef void(* module_list_thread_data_del_t) (module_thread_instance_t *ti) |
typedef void(* module_list_thread_free_t) (module_list_t *ml) |
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.
[in] | ctx | talloc 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] | ml | to initialise thread-local data for. |
|
static |
|
static |
|
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.
|
static |
|
static |
|
static |
|
static |
|
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.
[in] | ti | to free. |
Definition at line 1043 of file module.c.
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
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.
[in] | mi | Module instance to get the thread-specific data for. |
Definition at line 492 of file module.c.
|
static |
Allocate a thread-local array to hold thread data for each module thats been instantiated.
[in] | ctx | Talloc context for the thread-local data. Mutated by this function so that thread local data is allocated beneath the array. |
[in] | ml | Module list to initialise the thread-local data for. |
Definition at line 468 of file module.c.
|
static |
|
static |
|
static |
|
static |
int module_bootstrap | ( | module_instance_t * | mi | ) |
Manually complete module bootstrap by calling its instantiate function.
[in] | mi | Module instance to bootstrap. |
Definition at line 1308 of file module.c.
|
inlinestatic |
|
inlinestatic |
|
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.
[in] | mi | to detach. |
Definition at line 1433 of file module.c.
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.
[in] | ml | To add module to. |
[in] | parent | of the module being bootstrapped, if this is a submodule. If this is not a submodule parent must be NULL. |
[in] | type | What type of module we're loading. Determines the prefix added to the library name. Should be one of:
|
[in] | mod_name | The name of this module, i.e. 'redis' for 'rlm_redis'. |
[in] | inst_name | Instance 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_state | The 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. |
Definition at line 1651 of file module.c.
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.
[in] | ml | to search in. |
[in] | data | to resolve to module_instance_t. |
Definition at line 957 of file module.c.
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.
[in] | ml | to search in. |
[in] | parent | to qualify search with. |
[in] | asked_name | The name of the module we're attempting to find. May include '-' which indicates that it's ok for the module not to be loaded. |
Definition at line 903 of file module.c.
int module_instance_conf_parse | ( | module_instance_t * | mi, |
CONF_SECTION * | conf | ||
) |
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.
[in] | dst | list to place the new module instance in. |
[in] | src | to duplicate. |
[in] | inst_name | new instance name. If null, src->name will be used. |
Definition at line 1534 of file module.c.
|
inlinestatic |
Allocate module instance data.
[in] | ctx | talloc context to allocate data in. |
[out] | pool_out | where to write pool details. |
[out] | out | where to write data pointer. |
[in] | mi | module instance. |
[in] | size | of data to allocate. |
[in] | type | talloc type to assign. |
Definition at line 1554 of file module.c.
|
static |
int module_instance_data_protect | ( | module_instance_t const * | mi | ) |
int module_instance_data_unprotect | ( | module_instance_t const * | mi | ) |
void module_instance_debug | ( | module_instance_t const * | mi | ) |
|
static |
Generate a module name from the module's name and its parents.
[in] | ctx | Where to allocate the module name. |
[out] | out | Where to write a pointer to the instance name. |
[in] | parent | of the module. |
[in] | inst_name | module's instance name. |
Definition at line 1396 of file module.c.
|
static |
fr_slen_t module_instance_name_from_conf | ( | char const ** | name, |
CONF_SECTION * | conf | ||
) |
fr_slen_t module_instance_name_valid | ( | char const * | inst_name | ) |
Check to see if a module instance name is valid.
[in] | inst_name | to check. |
Definition at line 1591 of file module.c.
module_instance_t* module_instance_root | ( | module_instance_t const * | child | ) |
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.
[in] | mi | Instance to get the prefix for. |
Definition at line 725 of file module.c.
bool module_instance_skip_bootstrap | ( | module_instance_t * | mi | ) |
bool module_instance_skip_instantiate | ( | module_instance_t * | mi | ) |
bool module_instance_skip_thread_instantiate | ( | module_instance_t * | mi | ) |
Should we instantiate this module instance in a new thread?
[in] | mi | to check. |
Definition at line 1825 of file module.c.
void module_instance_uctx_set | ( | module_instance_t * | mi, |
void * | uctx | ||
) |
int module_instantiate | ( | module_instance_t * | instance | ) |
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.
[in] | ctx | To allocate the list in. |
[in] | type | of the list. Controls whether this is a global module list, or a per-thread list containing variants of an existing module. |
[in] | name | of the list. Used for debugging. |
[in] | write_protect | Whether to write protect the module data after instantiation and bootstrapping. |
Definition at line 1857 of file module.c.
void module_list_debug | ( | module_list_t const * | ml | ) |
void module_list_mask_set | ( | module_list_t * | ml, |
module_instance_state_t | mask | ||
) |
|
static |
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
[in] | ctx | unused. |
[out] | out | A pointer to a pointer to a module_instance_t. |
[in] | parent | This must point to the instance data of the parent module. |
[in] | ci | The CONF_PAIR containing the name of the submodule to load. |
[in] | rule | uctx pointer must be a pointer to a module_list_t ** containing the list to search in. |
Definition at line 847 of file module.c.
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.
[in] | ml | Module list module belongs to. |
[in] | data | Private instance data of the module. Same as what would be provided by module_instance_by_data. |
Definition at line 980 of file module.c.
|
static |
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.
[in] | ctx | Talloc ctx to bind thread specific data to. |
[in] | mi | Module instance to perform thread instantiation for. |
[in] | el | Event list serviced by this thread. |
Definition at line 1083 of file module.c.
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.
[in] | ml | containing modules to bootstrap. |
Definition at line 1372 of file module.c.
void modules_init | ( | char const * | lib_dir | ) |
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.
[in] | ml | containing modules to instantiate. |
Definition at line 1281 of file module.c.
void modules_thread_detach | ( | module_list_t * | ml | ) |
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.
[in] | ctx | Talloc ctx to bind thread specific data to. |
[in] | ml | Module list to perform thread instantiation for. |
[in] | el | Event list serviced by this thread. |
Definition at line 1160 of file module.c.
|
static |
|
static |
|
static |
fr_cmd_table_t module_cmd_list_table[] |
fr_cmd_table_t module_cmd_table[] |
Chars that are allowed in a module instance name.
module_list_type_t const module_list_type_global |
Callbacks for a global module list.
Initialise a global module, with thread-specific data.
module_list_type_t const module_list_type_thread_local |
Callbacks for a thread local list.
Initialise a thread-local module, which is only used in a single thread.