The FreeRADIUS server
$Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
|
Wrappers around dlopen to manage loading modules at runtime. More...
#include <freeradius-devel/server/dl_module.h>
#include <freeradius-devel/server/log.h>
#include <freeradius-devel/server/global_lib.h>
#include <freeradius-devel/util/debug.h>
#include <freeradius-devel/util/dl.h>
#include <freeradius-devel/util/syserror.h>
#include <ctype.h>
#include <unistd.h>
Go to the source code of this file.
Data Structures | |
struct | dl_module_inst_cache_t |
Make data to instance name resolution more efficient. More... | |
struct | dl_module_loader_s |
Wrapper struct around dl_loader_t. More... | |
Macros | |
#define | _DL_MODULE_PRIVATE 1 |
#define | DL_INIT_CHECK fr_assert(dl_module_loader) |
Functions | |
static int | _dl_module_free (dl_module_t *dl_module) |
Decrement the reference count of the dl, eventually freeing it. More... | |
static int | _dl_module_instance_data_free (void *data) |
static int | _dl_module_instance_free (dl_module_inst_t *dl_inst) |
Free a module instance, removing it from the instance tree. More... | |
static int | _dl_module_loader_free (dl_module_loader_t *dl_module_l) |
static int | dl_dict_attr_autoload (dl_t const *module, void *symbol, void *user_ctx) |
Wrapper to log errors. More... | |
static int | dl_dict_autoload (dl_t const *module, void *symbol, void *user_ctx) |
Wrapper to log errors. More... | |
static int | dl_dict_enum_autoload (dl_t const *module, void *symbol, void *user_ctx) |
Wrapper to log errors. More... | |
dl_loader_t * | dl_loader_from_module_loader (dl_module_loader_t *dl_module_l) |
dl_module_t const * | dl_module (dl_module_t const *parent, char const *name, dl_module_type_t type) |
Load a module library using dlopen() or return a previously loaded module from the cache. More... | |
static int8_t | dl_module_cmp (void const *one, void const *two) |
int | dl_module_conf_parse (dl_module_inst_t *dl_inst, CONF_SECTION *conf) |
static void | dl_module_detach_parent (dl_module_inst_t *dl_inst) |
Detach the shallowest parent first. More... | |
static int8_t | dl_module_inst_data_cmp (void const *one, void const *two) |
char const * | dl_module_inst_name_from_conf (CONF_SECTION *conf) |
Avoid boilerplate when setting the module instance name. More... | |
int | dl_module_instance (TALLOC_CTX *ctx, dl_module_inst_t **out, dl_module_inst_t const *parent, dl_module_type_t type, char const *mod_name, char const *inst_name) |
Load a module and parse its CONF_SECTION in one operation. More... | |
dl_module_inst_t const * | dl_module_instance_by_cs (CONF_SECTION const *cs) |
Lookup a dl_module_inst_t via a config section. More... | |
dl_module_inst_t const * | dl_module_instance_by_data (void const *data) |
Lookup a dl_module_inst_t via instance data. More... | |
static void | dl_module_instance_data_alloc (dl_module_inst_t *dl_inst, dl_module_t const *module) |
Allocate module instance data, and parse the module's configuration. More... | |
char const * | dl_module_instance_name_by_data (void const *data) |
Lookup instance name via instance data. More... | |
void * | dl_module_instance_symbol (dl_module_inst_t const *dl_inst, char const *sym_name) |
Retrieve a public symbol from a module using dlsym. More... | |
dl_module_loader_t * | dl_module_loader_init (char const *lib_dir) |
Initialise structures needed by the dynamic linker. More... | |
static int | dl_module_magic_verify (dl_module_common_t const *module) |
Check if the magic number in the module matches the one in the library. More... | |
static int | dl_module_onload_func (dl_t const *dl, UNUSED void *symbol, UNUSED void *ctx) |
Call the load() function in a module's exported structure. More... | |
void * | dl_module_parent_data_by_child_data (void const *data) |
A convenience function for returning a parent's private data. More... | |
dl_module_inst_t const * | dl_module_parent_instance (dl_module_inst_t const *child) |
Lookup a module's parent. More... | |
char const * | dl_module_search_path (void) |
static void | dl_module_unload_func (dl_t const *dl, UNUSED void *symbol, UNUSED void *ctx) |
Call the unload() function in a module's exported structure. More... | |
Variables | |
static _Thread_local dl_module_inst_cache_t | dl_inst_cache |
static dl_module_loader_t * | dl_module_loader |
fr_table_num_sorted_t const | dl_module_type_prefix [] |
Name prefixes matching the types of loadable module. More... | |
size_t | dl_module_type_prefix_len = NUM_ELEMENTS(dl_module_type_prefix) |
Wrappers around dlopen to manage loading modules at runtime.
Definition in file dl_module.c.
struct dl_module_inst_cache_t |
Make data to instance name resolution more efficient.
Definition at line 57 of file dl_module.c.
Data Fields | ||
---|---|---|
void * | data | Module's data. |
dl_module_inst_t * | inst | Instance wrapper struct. |
struct dl_module_loader_s |
Wrapper struct around dl_loader_t.
Provides space to store instance data.
Definition at line 46 of file dl_module.c.
Data Fields | ||
---|---|---|
dl_loader_t * | dl_loader | |
fr_rb_tree_t * | inst_data_tree | |
fr_rb_tree_t * | module_tree |
#define _DL_MODULE_PRIVATE 1 |
Definition at line 27 of file dl_module.c.
#define DL_INIT_CHECK fr_assert(dl_module_loader) |
Definition at line 40 of file dl_module.c.
|
static |
Decrement the reference count of the dl, eventually freeing it.
Definition at line 341 of file dl_module.c.
|
static |
Definition at line 281 of file dl_module.c.
|
static |
Free a module instance, removing it from the instance tree.
Also decrements the reference count of the module potentially unloading it.
[in] | dl_inst | to free. |
Definition at line 483 of file dl_module.c.
|
static |
Definition at line 615 of file dl_module.c.
|
static |
Wrapper to log errors.
Definition at line 681 of file dl_module.c.
|
static |
Wrapper to log errors.
Definition at line 693 of file dl_module.c.
|
static |
Wrapper to log errors.
Definition at line 669 of file dl_module.c.
dl_loader_t* dl_loader_from_module_loader | ( | dl_module_loader_t * | dl_module_l | ) |
Definition at line 662 of file dl_module.c.
dl_module_t const* dl_module | ( | dl_module_t const * | parent, |
char const * | name, | ||
dl_module_type_t | type | ||
) |
Load a module library using dlopen() or return a previously loaded module from the cache.
When the dl_module_t is no longer used, talloc_free() may be used to free it.
When all references to the original dlhandle are freed, dlclose() will be called on the dlhandle to unload the module.
[in] | parent | The dl_module_t of the parent module, e.g. rlm_sql for rlm_sql_postgresql. |
[in] | name | of the module e.g. sql for rlm_sql. |
[in] | type | Used to determine module name prefixes. Must be one of:
|
Definition at line 382 of file dl_module.c.
|
static |
Definition at line 84 of file dl_module.c.
int dl_module_conf_parse | ( | dl_module_inst_t * | dl_inst, |
CONF_SECTION * | conf | ||
) |
Definition at line 594 of file dl_module.c.
|
static |
Detach the shallowest parent first.
Definition at line 269 of file dl_module.c.
|
static |
Definition at line 74 of file dl_module.c.
char const* dl_module_inst_name_from_conf | ( | CONF_SECTION * | conf | ) |
Avoid boilerplate when setting the module instance name.
Definition at line 584 of file dl_module.c.
int dl_module_instance | ( | TALLOC_CTX * | ctx, |
dl_module_inst_t ** | out, | ||
dl_module_inst_t const * | parent, | ||
dl_module_type_t | type, | ||
char const * | mod_name, | ||
char const * | inst_name | ||
) |
Load a module and parse its CONF_SECTION in one operation.
When this instance is no longer needed, it should be freed with talloc_free(). When all instances of a particular module are unloaded, the dl handle will be closed, unloading the module.
[in] | ctx | to allocate structures in. |
[out] | out | where to write our dl_module_inst_t containing the module handle and instance. |
[in] | parent | of module instance. |
[in] | type | of module to load. |
[in] | mod_name | of the module to load .e.g. 'udp' for 'proto_radius_udp' if the parent were 'proto_radius'. |
[in] | inst_name | The name of the instance .e.g. 'sql_aws_dc01' |
Definition at line 552 of file dl_module.c.
dl_module_inst_t const* dl_module_instance_by_cs | ( | CONF_SECTION const * | cs | ) |
Lookup a dl_module_inst_t via a config section.
Definition at line 227 of file dl_module.c.
dl_module_inst_t const* dl_module_instance_by_data | ( | void const * | data | ) |
Lookup a dl_module_inst_t via instance data.
Definition at line 215 of file dl_module.c.
|
static |
Allocate module instance data, and parse the module's configuration.
[in] | dl_inst | to allocate this instance data in. |
[in] | module | to alloc instance data for. |
Definition at line 305 of file dl_module.c.
char const* dl_module_instance_name_by_data | ( | void const * | data | ) |
Lookup instance name via instance data.
Definition at line 235 of file dl_module.c.
void* dl_module_instance_symbol | ( | dl_module_inst_t const * | dl_inst, |
char const * | sym_name | ||
) |
Retrieve a public symbol from a module using dlsym.
Convenience function to lookup/return public symbols from modules loaded with dl_module_instance.
[in] | dl_inst | Instance who's module we're looking for the symbol in. |
[in] | sym_name | to lookup. |
Definition at line 526 of file dl_module.c.
dl_module_loader_t* dl_module_loader_init | ( | char const * | lib_dir | ) |
Initialise structures needed by the dynamic linker.
Definition at line 706 of file dl_module.c.
|
static |
Check if the magic number in the module matches the one in the library.
This is used to detect potential ABI issues caused by running with modules which were built for a different version of the server.
[in] | module | Common fields from module's exported interface struct. |
Definition at line 161 of file dl_module.c.
|
static |
Call the load() function in a module's exported structure.
[in] | dl | to call the load function for. |
[in] | symbol | UNUSED. |
[in] | ctx | UNUSED. |
Definition at line 105 of file dl_module.c.
void* dl_module_parent_data_by_child_data | ( | void const * | data | ) |
A convenience function for returning a parent's private data.
[in] | data | Private instance data for child. |
Definition at line 252 of file dl_module.c.
dl_module_inst_t const* dl_module_parent_instance | ( | dl_module_inst_t const * | child | ) |
Lookup a module's parent.
Definition at line 207 of file dl_module.c.
char const* dl_module_search_path | ( | void | ) |
Definition at line 657 of file dl_module.c.
|
static |
Call the unload() function in a module's exported structure.
[in] | dl | to call the unload function for. |
[in] | symbol | UNUSED. |
[in] | ctx | UNUSED. |
Definition at line 138 of file dl_module.c.
|
static |
Definition at line 62 of file dl_module.c.
|
static |
Definition at line 52 of file dl_module.c.
fr_table_num_sorted_t const dl_module_type_prefix[] |
Name prefixes matching the types of loadable module.
Definition at line 66 of file dl_module.c.
size_t dl_module_type_prefix_len = NUM_ELEMENTS(dl_module_type_prefix) |
Definition at line 72 of file dl_module.c.