27 RCSIDH(modules_h,
"$Id: e734bce8ab9d0a13fd5a24165aa89fe16b450308 $")
42 #include <freeradius-devel/server/module_ctx.h>
43 #include <freeradius-devel/server/rcode.h>
44 #include <freeradius-devel/server/request.h>
47 typedef enum CC_HINT(flag_enum) {
125 #include <freeradius-devel/features.h>
126 #include <freeradius-devel/io/schedule.h>
128 #include <freeradius-devel/server/cf_util.h>
129 #include <freeradius-devel/server/dl_module.h>
130 #include <freeradius-devel/server/exfile.h>
131 #include <freeradius-devel/server/pool.h>
132 #include <freeradius-devel/server/request.h>
133 #include <freeradius-devel/server/section.h>
135 #include <freeradius-devel/unlang/action.h>
136 #include <freeradius-devel/unlang/call_env.h>
137 #include <freeradius-devel/unlang/mod_action.h>
139 #include <freeradius-devel/util/event.h>
147 #define MODULE_INSTANCE_LEN_MAX 256
151 #define MODULE_BINDING_TERMINATOR { .section = NULL }
243 typedef enum CC_HINT(flag_enum) {
469 CC_HINT(
nonnull(1,3)) CC_HINT(warn_unused_result);
480 static inline CC_HINT(warn_unused_result) CC_HINT(always_inline)
483 return mi->ml->thread_data_get(mi);
496 CC_HINT(
nonnull) CC_HINT(warn_unused_result);
499 CC_HINT(
nonnull) CC_HINT(warn_unused_result);
514 CC_HINT(
nonnull(1,2)) CC_HINT(warn_unused_result);
520 CC_HINT(
nonnull(1)) CC_HINT(warn_unused_result);
553 char const *
name,
bool write_protect)
554 CC_HINT(
nonnull(2,3)) CC_HINT(warn_unused_result);
unlang_action_t
Returned by unlang_op_t calls, determine the next action of the interpreter.
Defines a CONF_PAIR to C data type mapping.
Common header for all CONF_* types.
A section grouping multiple CONF_PAIR.
fr_dcursor_eval_t void const * uctx
Head of a doubly linked list.
Entry in a doubly linked list.
unsigned int fr_heap_index_t
Stores all information relating to an event list.
static char const * mod_name(fr_listen_t *li)
Temporary structure to hold arguments for module calls.
Temporary structure to hold arguments for detach calls.
Temporary structure to hold arguments for instantiation calls.
Temporary structure to hold arguments for thread_instantiation calls.
The main red black tree structure.
rlm_rcode_t
Return codes indicating the result of the module call.
int module_instance_data_protect(module_instance_t const *mi)
Mark module data as read only.
void module_list_debug(module_list_t const *ml)
Print the contents of a module list.
module_list_type_t const module_list_type_thread_local
Initialise a thread-local module, which is only used in a single thread.
void modules_init(char const *lib_dir)
Perform global initialisation for modules.
bool module_instance_skip_thread_instantiate(module_instance_t *mi)
Should we instantiate this module instance in a new thread?
module_thread_instance_t *(* module_list_thread_data_get_t)(module_instance_t const *mi)
Callback to retrieve thread-local data for a module.
module_instance_t * mi
As opposed to the thread local inst.
char const * name
Instance name e.g. user_database.
@ MODULE_TYPE_DYNAMIC_UNSAFE
Instances of this module cannot be created at runtime.
@ MODULE_TYPE_THREAD_UNSAFE
Module is not threadsafe.
@ MODULE_TYPE_RETRY
can handle retries
module_flags_t flags
Flags that control how a module starts up and how a module is called.
static module_thread_instance_t * module_thread(module_instance_t const *mi)
Retrieve module/thread specific instance for a module.
char const * module_instance_root_prefix_str(module_instance_t const *mi)
Return the prefix string for the deepest module.
fr_rb_node_t name_node
Entry in the name tree.
module_method_group_t * next
Next group in the list.
uint64_t active_callers
total number of times we've been called
module_instance_t * module_instance_root(module_instance_t const *child)
Find the module's shallowest parent.
CONF_SECTION * conf
Module's instance configuration.
size_t inst_size
Size of the module's instance data.
module_detach_t detach
Clean up module resources from the instantiation pahses.
bool force
Force the module to return a specific code.
void module_list_mask_set(module_list_t *ml, module_instance_state_t mask)
Set a new bootstrap/instantiate state for a list.
void * data
Module's instance data.
module_instance_state_t state
What's been done with this module so far.
module_method_t func
State function.
module_instance_t const * parent
Parent module's instance (if any).
int module_submodule_parse(UNUSED TALLOC_CTX *ctx, void *out, void *parent, CONF_ITEM *ci, UNUSED conf_parser_t const *rule)
module_thread_instantiate_t thread_instantiate
Callback to populate a new module thread instance data.
fr_slen_t module_instance_name_from_conf(char const **name, CONF_SECTION *conf)
Avoid boilerplate when setting the module instance name.
void modules_thread_detach(module_list_t *ml)
Remove thread-specific data for a given module list.
module_instantiate_t instantiate
Callback to allow the module to register any per-instance resources like sockets and file handles.
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.
unlang_mod_actions_t actions
default actions and retries.
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.
bool module_instance_skip_instantiate(module_instance_t *mi)
Should we instantiate this module instance?
module_method_t method
Module method to call.
int modules_instantiate(module_list_t const *ml)
Completes instantiation of modules.
void * boot
Data allocated during the boostrap phase.
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.
TALLOC_CTX * ctx
ctx data is allocated in.
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.
module_instance_state_t mask
Prevent phases from being executed.
dl_module_t * module
Dynamic loader handle.
int(* module_instantiate_t)(module_inst_ctx_t const *mctx)
Module instantiation callback.
bool validated
Set to true by module_method_group_validate.
void module_instance_uctx_set(module_instance_t *mi, void *uctx)
Set the uctx pointer for a module instance.
fr_dlist_head_t same_name1
List of bindings with the same name1.
void * data
Thread specific instance data.
char const * name
String identifier for state.
module_data_pool_t inst_pool
Data to allow mprotect state toggling for instance data.
bool write_protect
If true, pages containing module boot or instance data will be write protected after bootstrapping an...
rlm_rcode_t code
Code module will return when 'force' has has been set to true.
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.
char const * boot_type
talloc type to assign to bootstrap data.
size_t len
How much data we need mprotect to protect.
call_env_method_t const * method_env
Method specific call_env.
fr_slen_t module_instance_name_valid(char const *inst_name)
Check to see if a module instance name is valid.
char const * inst_type
talloc type to assign to instance data.
module_data_pool_t boot_pool
Data to allow mprotect state toggling for bootstrap data.
module_detach_t unstrap
Clean up module resources from both the bootstrap phase.
int module_instance_data_unprotect(module_instance_t const *mi)
Mark module data as read/write.
module_instance_state_t
What state the module instance is currently in.
@ MODULE_INSTANCE_INSTANTIATED
Module instance has been bootstrapped and instantiated.
@ MODULE_INSTANCE_NO_THREAD_INSTANTIATE
Not set internally, but can be used to prevent thread instantiation for certain modules.
@ MODULE_INSTANCE_BOOTSTRAPPED
Module instance has been bootstrapped, but not yet instantiated.
int module_thread_instantiate(TALLOC_CTX *ctx, module_instance_t *mi, fr_event_list_t *el)
Allocate thread-local instance data for a module.
int(* module_thread_detach_t)(module_thread_inst_ctx_t const *mctx)
Module thread destruction callback.
fr_rb_tree_t * data_tree
Modules indexed by data.
module_list_type_t const module_list_type_global
Initialise a global module, with thread-specific data.
uint32_t number
Unique module number.
module_list_thread_data_get_t thread_data_get
Callback to get thread-specific data.
int module_instantiate(module_instance_t *mi)
Manually complete module setup by calling its instantiate function.
char const * thread_inst_type
talloc type to assign to thread instance data.
module_instantiate_t bootstrap
Callback to allow the module to register any global resources like xlat functions and attributes.
int modules_bootstrap(module_list_t const *ml)
Bootstrap any modules which have not been bootstrapped already.
fr_rb_node_t data_node
Entry in the data tree.
DL_MODULE_COMMON
Common fields for all loadable modules.
module_thread_detach_t thread_detach
Callback to free thread-specific resources associated < with a module.
void * uctx
Extra data passed to module_instance_alloc.
int(* module_thread_instantiate_t)(module_thread_inst_ctx_t const *mctx)
Module thread creation callback.
bool module_instance_skip_bootstrap(module_instance_t *mi)
Should we bootstrap this module instance?
void * start
Start address which may be passed to mprotect.
module_method_binding_t * bindings
named methods
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.
fr_dlist_t entry
Linked list of bindings with the same name1.
size_t boot_size
Size of the module's bootstrap data.
module_list_t * ml
Module list this instance belongs to.
size_t thread_inst_size
Size of the module's thread-specific instance data.
conf_parser_t const * config
How to convert a CONF_SECTION to a module instance.
bool const module_instance_allowed_chars[UINT8_MAX+1]
Chars that are allowed in a module instance name.
int module_instance_conf_parse(module_instance_t *mi, CONF_SECTION *conf)
Covert a CONF_SECTION into parsed module instance data.
fr_heap_t * inst_heap
Heap of module instances.
char const * name
Friendly list identifier.
fr_event_list_t * el
Event list associated with this thread.
fr_heap_index_t inst_idx
Entry in the thread-specific bootstrap heap.
int(* module_detach_t)(module_detach_ctx_t const *inst)
Module detach callback.
section_name_t const * section
Identifier for a section.
module_list_type_t const * type
Type of module list.
unlang_action_t(* module_method_t)(rlm_rcode_t *p_result, module_ctx_t const *mctx, request_t *request)
Module section callback.
uint32_t last_number
Last identifier assigned to a module instance.
fr_rb_tree_t * name_tree
Modules indexed by name.
module_t * exported
Public module structure.
pthread_mutex_t mutex
Used prevent multiple threads entering a thread unsafe module simultaneously.
int module_bootstrap(module_instance_t *mi)
Manually complete module bootstrap by calling its instantiate function.
void module_instance_debug(module_instance_t const *mi)
Print debugging information for a module.
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.
Named methods exported by a module.
A group of methods exported by a module or added as an overlay.
Struct exported by a rlm_* module.
Map string values to module state method.
Per thread per instance data.
Structure to hold callbacks for a module list type.
eap_aka_sim_process_conf_t * inst
fr_aka_sim_id_type_t type
static fr_event_list_t * el
static size_t char ** out