The FreeRADIUS server $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Loading...
Searching...
No Matches
module.h
Go to the documentation of this file.
1#pragma once
2/*
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
16 */
17
18/**
19 * $Id: 4f93d3fc2c2dad4d28f791d504c80be53189508b $
20 *
21 * @file lib/server/module.h
22 * @brief Interface to the FreeRADIUS module system.
23 *
24 * @copyright 2022 Arran Cudbard-Bell <a.cudbardb@freeradius.org>
25 * @copyright 2013 The FreeRADIUS server project
26 */
27RCSIDH(modules_h, "$Id: 4f93d3fc2c2dad4d28f791d504c80be53189508b $")
28
29#ifdef __cplusplus
30extern "C" {
31#endif
32
33typedef struct module_s module_t;
41
42#include <freeradius-devel/server/module_ctx.h>
43#include <freeradius-devel/server/rcode.h>
44#include <freeradius-devel/server/request.h>
45#include <freeradius-devel/unlang/interpret.h>
46
47DIAG_OFF(attributes)
48typedef enum CC_HINT(flag_enum) {
49 MODULE_TYPE_THREAD_UNSAFE = (1 << 0), //!< Module is not threadsafe.
50 //!< Server will protect calls with mutex.
51 MODULE_TYPE_RETRY = (1 << 2), //!< can handle retries
52
53 MODULE_TYPE_DYNAMIC_UNSAFE = (1 << 3) //!< Instances of this module cannot be
54 ///< created at runtime.
56DIAG_ON(attributes)
57
58/** Module section callback
59 *
60 * Is called when the module is listed in a particular section of a virtual
61 * server, and the request has reached the module call.
62 *
63 * @param[out] p_result Result code of the module method.
64 * @param[in] mctx Holds global instance data, thread instance
65 * data and call specific instance data.
66 * @param[in] request to process.
67 * @return the appropriate rcode.
68 */
69typedef unlang_action_t (*module_method_t)(unlang_result_t *p_result, module_ctx_t const *mctx, request_t *request);
70
71/** Module instantiation callback
72 *
73 * Is called once per module instance. Is not called when new threads are
74 * spawned. See module_thread_instantiate_t for that.
75 *
76 * @param[in] mctx Holds global instance data.
77 * @return
78 * - 0 on success.
79 * - -1 if instantiation failed.
80 */
81typedef int (*module_instantiate_t)(module_inst_ctx_t const *mctx);
82
83/** Module detach callback
84 *
85 * Is called just before the server exits, and after re-instantiation on HUP,
86 * to free the old module instance.
87 *
88 * Detach should close all handles associated with the module instance, and
89 * free any memory allocated during instantiate.
90 *
91 * @param[in] inst to free.
92 * @return
93 * - 0 on success.
94 * - -1 if detach failed.
95 */
97
98/** Module thread creation callback
99 *
100 * Called whenever a new thread is created.
101 *
102 * @param[in] mctx Holds global instance data, thread instance
103 * data, and the thread-specific event list.
104 * @return
105 * - 0 on success.
106 * - -1 if instantiation failed.
107 */
109
110/** Module thread destruction callback
111 *
112 * Destroy a module/thread instance.
113 *
114 * @param[in] mctx Holds global instance data, thread instance
115 * data, and the thread-specific event list.
116 * @return
117 * - 0 on success.
118 * - -1 if instantiation failed.
119 */
121
122#ifdef __cplusplus
123}
124#endif
125
126#include <freeradius-devel/features.h>
127#include <freeradius-devel/io/schedule.h>
128
129#include <freeradius-devel/server/cf_util.h>
130#include <freeradius-devel/server/dl_module.h>
131#include <freeradius-devel/server/exfile.h>
132#include <freeradius-devel/server/pool.h>
133#include <freeradius-devel/server/request.h>
134#include <freeradius-devel/server/section.h>
135
136#include <freeradius-devel/unlang/action.h>
137#include <freeradius-devel/unlang/call_env.h>
138#include <freeradius-devel/unlang/mod_action.h>
139
140#include <freeradius-devel/util/event.h>
141
142#ifdef __cplusplus
143extern "C" {
144#endif
145
146/** The maximum size of a module instance
147 */
148#define MODULE_INSTANCE_LEN_MAX 256
149
150/** Terminate a module binding list
151 */
152#define MODULE_BINDING_TERMINATOR { .section = NULL }
153
154/** A group of methods exported by a module or added as an overlay
155 *
156 * Module method groups are organised into a linked list, with each group
157 * containing a list of named methods. This allows common collections of
158 * methods to be added to a module.
159 *
160 * One common use case is adding the `instantiate`, `exists`, and `detach`
161 * methods which are added to dynamic modules, and allow dynamic module
162 * instances to be created and destroyed at runtime.
163 */
166
167 bool validated; //!< Set to true by #module_method_group_validate.
168 module_method_group_t *next; //!< Next group in the list.
169};
170
171/** Named methods exported by a module
172 *
173 */
175 section_name_t const *section; //!< Identifier for a section.
176
177 module_method_t method; //!< Module method to call
178 call_env_method_t const *method_env; //!< Method specific call_env.
179
180 size_t rctx_size; //!< If set, this overrides the module_t rctx_size.
181 ///< Instructs the module instruction to pre-allocate
182 ///< an rctx (available in mctx->rctx) before the module
183 ///< method is called.
184 char const *rctx_type; //!< If rctx_size is used from the mmb, this sets the
185 ///< type of the rctx.
186
187 fr_dlist_head_t same_name1; //!< List of bindings with the same name1. Only initialised
188 ///< for the the first name1 binding.
189 ///< DO NOT INITIALISE IN THE MODULE.
190 fr_dlist_t entry; //!< Linked list of bindings with the same name1.
191 ///< Allows us to more quickly iterate over all
192 ///< name2 entries after finding a matching name1.
193 ///< This is also temporarily used to verify the ordering
194 ///< of name bindings.
195 ///< DO NOT INITIALISE IN THE MODULE.
196};
197
198/** Struct exported by a rlm_* module
199 *
200 * Determines the capabilities of the module, and maps internal functions
201 * within the module to different sections.
202 */
203struct module_s {
204 DL_MODULE_COMMON; //!< Common fields for all loadable modules.
205
206 conf_parser_t const *config; //!< How to convert a CONF_SECTION to a module instance.
207 fr_dict_t const **dict; //!< _required_ dictionary for this module.
208
209 size_t boot_size; //!< Size of the module's bootstrap data.
210 char const *boot_type; //!< talloc type to assign to bootstrap data.
211
212 size_t inst_size; //!< Size of the module's instance data.
213 char const *inst_type; //!< talloc type to assign to instance data.
214
215 module_instantiate_t bootstrap; //!< Callback to allow the module to register any global
216 ///< resources like xlat functions and attributes.
217 ///< Instance data is read only during the bootstrap phase
218 ///< and MUST NOT be modified.
219 ///< Any attributes added during this phase that the module
220 ///< need to be re-resolved during the instantiation phase
221 ///< so that dynamic modules (which don't run bootstrap)
222 ///< work correctly.
223 ///< @note Not modifying the instance data is not just a
224 ///< suggestion, if you try, you'll generate a SIGBUS
225 ///< or SIGSEGV and it won't be obvious why.
226
227 module_instantiate_t instantiate; //!< Callback to allow the module to register any
228 ///< per-instance resources like sockets and file handles.
229 ///< After instantiate completes the module instance data
230 ///< is mprotected to prevent modification.
231
232 module_detach_t detach; //!< Clean up module resources from the instantiation pahses.
233
234 module_detach_t unstrap; //!< Clean up module resources from both the bootstrap phase.
235
236 module_flags_t flags; //!< Flags that control how a module starts up and how
237 ///< a module is called.
238
239 module_thread_instantiate_t thread_instantiate; //!< Callback to populate a new module thread instance data.
240 ///< Called once per thread.
241 module_thread_detach_t thread_detach; //!< Callback to free thread-specific resources associated
242 ///!< with a module.
243
244 size_t thread_inst_size; //!< Size of the module's thread-specific instance data.
245 char const *thread_inst_type; //!< talloc type to assign to thread instance data.
246
247 size_t rctx_size; //!< Size of the module's thread-specific data.
248 char const *rctx_type; //!< talloc type to assign to thread instance data.
249};
250
251#define TALLOCED_TYPE(_field, _ctype) \
252 ._field##_size = sizeof(_ctype), ._field##_type = #_ctype
253
254#define MODULE_BOOT(_ctype) TALLOCED_TYPE(boot, _ctype)
255#define MODULE_INST(_ctype) TALLOCED_TYPE(inst, _ctype)
256#define MODULE_THREAD_INST(_ctype) TALLOCED_TYPE(thread_inst, _ctype)
257#define MODULE_RCTX(_ctype) TALLOCED_TYPE(rctx, _ctype)
258
259/** What state the module instance is currently in
260 *
261 */
262DIAG_OFF(attributes)
263typedef enum CC_HINT(flag_enum) {
264 MODULE_INSTANCE_BOOTSTRAPPED = (1 << 1), //!< Module instance has been bootstrapped, but not
265 ///< yet instantiated.
266 MODULE_INSTANCE_INSTANTIATED = (1 << 2), //!< Module instance has been bootstrapped and
267 ///< instantiated.
268 MODULE_INSTANCE_NO_THREAD_INSTANTIATE = (1 << 3) //!< Not set internally, but can be used to prevent
269 ///< thread instantiation for certain modules.
271DIAG_ON(attributes)
272
273typedef struct {
274 TALLOC_CTX *ctx; //!< ctx data is allocated in.
275 void *start; //!< Start address which may be passed to mprotect.
276 size_t len; //!< How much data we need mprotect to protect.
278
279/** Module instance data
280 *
281 * Per-module-instance data structure to correlate the modules with the
282 * instance names (may NOT be the module names!), and the per-instance
283 * data structures.
284 */
286 /** @name Fields that are most frequently accessed at runtime
287 *
288 * Putting them first gives us the greatest chance of the pointers being prefetched.
289 * @{
290 */
291 void *data; //!< Module's instance data. This is most
292 ///< frequently accessed, so comes first.
293
294 void *boot; //!< Data allocated during the boostrap phase
295
296 module_t *exported; //!< Public module structure. Cached for convenience.
297 ///< This exports module methods, i.e. the functions
298 ///< which allow the module to perform actions.
299 ///< This is an identical address to module->common,
300 ///< but with a different type, containing additional
301 ///< instance callbacks to make it easier to use.
302
303 pthread_mutex_t mutex; //!< Used prevent multiple threads entering a thread
304 ///< unsafe module simultaneously.
305
306 dl_module_t *module; //!< Dynamic loader handle. Contains the module's
307 ///< dlhandle, and the functions it exports.
308 ///< The dl_module is reference counted so that it
309 ///< can be freed automatically when the last instance
310 ///< is freed. This will also (usually) unload the
311 ///< .so or .dylib.
312 /** @} */
313
314 /** @name Return code overrides
315 * @{
316 */
317 bool force; //!< Force the module to return a specific code.
318 //!< Usually set via an administrative interface.
319
320 rlm_rcode_t code; //!< Code module will return when 'force' has
321 //!< has been set to true.
322
323 unlang_mod_actions_t actions; //!< default actions and retries.
324 /** @} */
325
326 /** @name Allow module instance data to be resolved by name or data, and to get back to the module list
327 * @{
328 */
329 module_list_t *ml; //!< Module list this instance belongs to.
330 fr_rb_node_t name_node; //!< Entry in the name tree.
331 fr_rb_node_t data_node; //!< Entry in the data tree.
332 uint32_t number; //!< Unique module number. Used to assign a stable
333 ///< number to each module instance.
334 /** @} */
335
336 /** @name These structures allow mprotect to protect/unprotest bootstrap and instance data
337 * @{
338 */
339 module_data_pool_t inst_pool; //!< Data to allow mprotect state toggling
340 ///< for instance data.
341 module_data_pool_t boot_pool; //!< Data to allow mprotect state toggling
342 ///< for bootstrap data.
343 /** @} */
344
345 /** @name Module instance state
346 * @{
347 */
348 module_instance_state_t state; //!< What's been done with this module so far.
349 CONF_SECTION *conf; //!< Module's instance configuration.
350 /** @} */
351
352 /** @name Misc fields
353 * @{
354 */
355 char const *name; //!< Instance name e.g. user_database.
356
357 module_instance_t const *parent; //!< Parent module's instance (if any).
358
359 void *uctx; //!< Extra data passed to module_instance_alloc.
360 /** @} */
361};
362
363/** Per thread per instance data
364 *
365 * Stores module and thread specific data.
366 */
368 fr_heap_index_t inst_idx; //!< Entry in the thread-specific bootstrap heap.
369 ///< Should be an identical value to the global
370 ///< instance data for the same module.
371
372 void *data; //!< Thread specific instance data.
373
374 fr_event_list_t *el; //!< Event list associated with this thread.
375
376 module_instance_t *mi; //!< As opposed to the thread local inst.
377
378 uint64_t total_calls; //! total number of times we've been called
379 uint64_t active_callers; //! number of active callers. i.e. number of current yields
380};
381
382/** Callback to retrieve thread-local data for a module
383 *
384 * This is public for performance reasons, and should be called through
385 * #module_thread.
386 *
387 * @param[in] mi to add data to (use mi->ml for the module list).
388 * @return
389 * - NULL if no data exists.
390 * - Pointer to the data on success.
391 */
392typedef module_thread_instance_t *(*module_list_thread_data_get_t)(module_instance_t const *mi);
393
394/** A list of modules
395 *
396 * This used to be a global structure, but was move to a struct.
397 *
398 * Module lists allow collections of modules to be created. The module lists themselves can be configured
399 * to be thread-local or global, with optional runtime write protection.
400 *
401 * Thread-local module lists are used for dynamic modules, i.e. those created at runtime, where as the
402 * global module lists are used for backend modules, listeners, and process state machines.
403 */
405{
406 char const *name; //!< Friendly list identifier.
407 module_instance_state_t mask; //!< Prevent phases from being executed.
408
409 uint32_t last_number; //!< Last identifier assigned to a module instance.
410 fr_rb_tree_t *name_tree; //!< Modules indexed by name.
411 fr_rb_tree_t *data_tree; //!< Modules indexed by data.
412 fr_heap_t *inst_heap; //!< Heap of module instances.
413
414 bool write_protect; //!< If true, pages containing module boot or
415 ///< instance data will be write protected after
416 ///< bootstrapping and instantiation is complete,
417 ///< to prevent accidental modification.
418
419 /** @name Callbacks to manage thread-specific data
420 *
421 * In "child" lists, which are only operating in a single thread, we don't need
422 * to use true thread-local data, because the module list itself is thread-local.
423 *
424 * In that case these callbacks hang memory off of the list itself.
425 *
426 * In the main module list, which is shared between threads, these callbacks
427 * do use true thread-local data, to manage the module_thread_instance_t
428 * on a per thread-basis.
429 *
430 * @{
431 */
432 module_list_type_t const *type; //!< Type of module list.
433 module_list_thread_data_get_t thread_data_get; //!< Callback to get thread-specific data.
434 ///< Copy of type->thread_data_get.
435 /** @} */
436};
437
438/** Map string values to module state method
439 *
440 */
442 char const *name; //!< String identifier for state.
443 module_method_t func; //!< State function.
444};
445
446/** @name Callbacks for the conf_parser_t
447 *
448 * @{
449 */
450int module_submodule_parse(UNUSED TALLOC_CTX *ctx, void *out, void *parent,
451 CONF_ITEM *ci, UNUSED conf_parser_t const *rule) CC_HINT(warn_unused_result);
452/** @} */
453
454/** @name Debugging functions
455 *
456 * @{
457 */
458void module_instance_debug(module_instance_t const *mi) CC_HINT(nonnull);
459
460void module_list_debug(module_list_t const *ml) CC_HINT(nonnull);
461 /** @} */
462
463/** @name Toggle protection on module instance data
464 *
465 * This is used for module lists which implement additional instantiation phases
466 * (like li->open). It should NOT be used by modules to hack around instance
467 * data being read-only after instantiation completes.
468 *
469 * @{
470 */
472
474 /** @} */
475
476/** @name Module and module thread lookup
477 *
478 * @{
479 */
481
483
484char const *module_instance_root_prefix_str(module_instance_t const *mi) CC_HINT(nonnull) CC_HINT(warn_unused_result);
485
486module_instance_t *module_instance_root(module_instance_t const *child); CC_HINT(warn_unused_result)
487
488module_instance_t *module_instance_by_name(module_list_t const *ml, module_instance_t const *parent, char const *asked_name)
489 CC_HINT(nonnull(1,3)) CC_HINT(warn_unused_result);
490
491module_instance_t *module_instance_by_data(module_list_t const *ml, void const *data) CC_HINT(warn_unused_result);
492
493/** Retrieve module/thread specific instance for a module
494 *
495 * @param[in] mi to find thread specific data for.
496 * @return
497 * - Thread specific instance data on success.
498 * - NULL if module has no thread instance data.
499 */
500static inline CC_HINT(warn_unused_result) CC_HINT(always_inline)
502{
503 return mi->ml->thread_data_get(mi);
504}
505
506module_thread_instance_t *module_thread_by_data(module_list_t const *ml, void const *data) CC_HINT(warn_unused_result);
507/** @} */
508
509/** @name Module and module thread initialisation and instantiation
510 *
511 * @{
512 */
514
516 CC_HINT(nonnull) CC_HINT(warn_unused_result);
517
518int modules_thread_instantiate(TALLOC_CTX *ctx, module_list_t const *ml, fr_event_list_t *el)
519 CC_HINT(nonnull) CC_HINT(warn_unused_result);
520
521int module_instantiate(module_instance_t *mi) CC_HINT(nonnull) CC_HINT(warn_unused_result);
522
523int modules_instantiate(module_list_t const *ml) CC_HINT(nonnull) CC_HINT(warn_unused_result);
524
525int module_bootstrap(module_instance_t *mi) CC_HINT(nonnull) CC_HINT(warn_unused_result);
526
527int modules_bootstrap(module_list_t const *ml) CC_HINT(nonnull) CC_HINT(warn_unused_result);
528
529extern bool const module_instance_allowed_chars[UINT8_MAX + 1];
530
531fr_slen_t module_instance_name_valid(char const *inst_name) CC_HINT(nonnull);
532
533module_instance_t *module_instance_copy(module_list_t *dst, module_instance_t const *src, char const *inst_name)
534 CC_HINT(nonnull(1,2)) CC_HINT(warn_unused_result);
535
538 dl_module_type_t type, char const *mod_name, char const *inst_name,
539 module_instance_state_t init_state)
540 CC_HINT(nonnull(1)) CC_HINT(warn_unused_result);
541
542void module_instance_uctx_set(module_instance_t *mi, void *uctx);
543
544/** @name Module list variants
545 *
546 * These are passed to the module_list_alloc function to allocate lists of different types
547 *
548 * Global module lists are used for backend modules, listeners, and process state machines.
549 *
550 * Thread-local lists are usually runtime instantiated variants of modules, or modules that represent client connections.
551 *
552 * One major difference (from the module's perspective) is that bootstrap is not called for thread-local modules.
553 *
554 * @{
555 */
556extern module_list_type_t const module_list_type_global; //!< Initialise a global module, with thread-specific data.
557extern module_list_type_t const module_list_type_thread_local; //!< Initialise a thread-local module, which is only used in a single thread.
558/** @} */
559
560/** @name Control which phases are skipped (if any)
561 * @{
562 */
564
566
568
570/** @} */
571
573 char const *name, bool write_protect)
574 CC_HINT(nonnull(2,3)) CC_HINT(warn_unused_result);
575
576void modules_init(char const *lib_dir);
577/** @} */
578
579#ifdef __cplusplus
580}
581#endif
unlang_action_t
Returned by unlang_op_t calls, determine the next action of the interpreter.
Definition action.h:35
#define DIAG_ON(_x)
Definition build.h:460
#define RCSIDH(h, id)
Definition build.h:486
#define UNUSED
Definition build.h:317
#define DIAG_OFF(_x)
Definition build.h:459
Defines a CONF_PAIR to C data type mapping.
Definition cf_parse.h:595
Common header for all CONF_* types.
Definition cf_priv.h:49
A section grouping multiple CONF_PAIR.
Definition cf_priv.h:101
dl_module_type_t
Definition dl_module.h:65
Head of a doubly linked list.
Definition dlist.h:51
Entry in a doubly linked list.
Definition dlist.h:41
unsigned int fr_heap_index_t
Definition heap.h:80
The main heap structure.
Definition heap.h:66
Stores all information relating to an event list.
Definition event.c:377
static char const * mod_name(fr_listen_t *li)
Definition master.c:2889
unsigned int uint32_t
ssize_t fr_slen_t
#define UINT8_MAX
Temporary structure to hold arguments for module calls.
Definition module_ctx.h:41
Temporary structure to hold arguments for detach calls.
Definition module_ctx.h:56
Temporary structure to hold arguments for instantiation calls.
Definition module_ctx.h:50
Temporary structure to hold arguments for thread_instantiation calls.
Definition module_ctx.h:63
static rs_t * conf
Definition radsniff.c:53
The main red black tree structure.
Definition rb.h:73
static uint32_t mask
Definition rbmonkey.c:39
rlm_rcode_t
Return codes indicating the result of the module call.
Definition rcode.h:40
static char const * name
Section name identifier.
Definition section.h:44
size_t rctx_size
Size of the module's thread-specific data.
Definition module.h:247
int module_instance_data_protect(module_instance_t const *mi)
Mark module data as read only.
Definition module.c:693
void module_list_debug(module_list_t const *ml)
Print the contents of a module list.
Definition module.c:615
module_list_type_t const module_list_type_thread_local
Initialise a thread-local module, which is only used in a single thread.
Definition module.c:582
void modules_init(char const *lib_dir)
Perform global initialisation for modules.
Definition module.c:1904
bool module_instance_skip_thread_instantiate(module_instance_t *mi)
Should we instantiate this module instance in a new thread?
Definition module.c:1819
module_instance_t * mi
As opposed to the thread local inst.
Definition module.h:376
char const * name
Instance name e.g. user_database.
Definition module.h:355
module_flags_t
Definition module.h:48
@ MODULE_TYPE_DYNAMIC_UNSAFE
Instances of this module cannot be created at runtime.
Definition module.h:53
@ MODULE_TYPE_THREAD_UNSAFE
Module is not threadsafe.
Definition module.h:49
@ MODULE_TYPE_RETRY
can handle retries
Definition module.h:51
module_flags_t flags
Flags that control how a module starts up and how a module is called.
Definition module.h:236
fr_rb_node_t name_node
Entry in the name tree.
Definition module.h:330
module_method_group_t * next
Next group in the list.
Definition module.h:168
uint64_t active_callers
total number of times we've been called
Definition module.h:379
CONF_SECTION * conf
Module's instance configuration.
Definition module.h:349
size_t inst_size
Size of the module's instance data.
Definition module.h:212
module_detach_t detach
Clean up module resources from the instantiation pahses.
Definition module.h:232
bool force
Force the module to return a specific code.
Definition module.h:317
void module_list_mask_set(module_list_t *ml, module_instance_state_t mask)
Set a new bootstrap/instantiate state for a list.
Definition module.c:1829
void * data
Module's instance data.
Definition module.h:291
module_instance_state_t state
What's been done with this module so far.
Definition module.h:348
module_method_t func
State function.
Definition module.h:443
module_instance_t const * parent
Parent module's instance (if any).
Definition module.h:357
unlang_action_t(* module_method_t)(unlang_result_t *p_result, module_ctx_t const *mctx, request_t *request)
Module section callback.
Definition module.h:69
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.
Definition module.h:239
fr_slen_t module_instance_name_from_conf(char const **name, CONF_SECTION *conf)
Avoid boilerplate when setting the module instance name.
Definition module.c:729
void modules_thread_detach(module_list_t *ml)
Remove thread-specific data for a given module list.
Definition module.c:1003
module_instantiate_t instantiate
Callback to allow the module to register any per-instance resources like sockets and file handles.
Definition module.h:227
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.
Definition module.c:1154
unlang_mod_actions_t actions
default actions and retries.
Definition module.h:323
char const * rctx_type
talloc type to assign to thread instance data.
Definition module.h:248
bool module_instance_skip_instantiate(module_instance_t *mi)
Should we instantiate this module instance?
Definition module.c:1807
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.
Definition module.c:1528
module_method_t method
Module method to call.
Definition module.h:177
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.
Definition module.c:951
int modules_instantiate(module_list_t const *ml)
Completes instantiation of modules.
Definition module.c:1275
void * boot
Data allocated during the boostrap phase.
Definition module.h:294
TALLOC_CTX * ctx
ctx data is allocated in.
Definition module.h:274
fr_dict_t const ** dict
required dictionary for this module.
Definition module.h:207
module_instance_state_t mask
Prevent phases from being executed.
Definition module.h:407
int(* module_instantiate_t)(module_inst_ctx_t const *mctx)
Module instantiation callback.
Definition module.h:81
module_thread_instance_t *(* module_list_thread_data_get_t)(module_instance_t const *mi)
Callback to retrieve thread-local data for a module.
Definition module.h:392
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.
Definition module.c:1645
bool validated
Set to true by module_method_group_validate.
Definition module.h:167
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.
Definition module.c:1851
void module_instance_uctx_set(module_instance_t *mi, void *uctx)
Set the uctx pointer for a module instance.
Definition module.c:1613
fr_dlist_head_t same_name1
List of bindings with the same name1.
Definition module.h:187
void * data
Thread specific instance data.
Definition module.h:372
char const * name
String identifier for state.
Definition module.h:442
module_data_pool_t inst_pool
Data to allow mprotect state toggling for instance data.
Definition module.h:339
bool write_protect
If true, pages containing module boot or instance data will be write protected after bootstrapping an...
Definition module.h:414
rlm_rcode_t code
Code module will return when 'force' has has been set to true.
Definition module.h:320
char const * boot_type
talloc type to assign to bootstrap data.
Definition module.h:210
size_t len
How much data we need mprotect to protect.
Definition module.h:276
call_env_method_t const * method_env
Method specific call_env.
Definition module.h:178
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.
Definition module.c:897
fr_slen_t module_instance_name_valid(char const *inst_name)
Check to see if a module instance name is valid.
Definition module.c:1585
char const * inst_type
talloc type to assign to instance data.
Definition module.h:213
module_data_pool_t boot_pool
Data to allow mprotect state toggling for bootstrap data.
Definition module.h:341
module_detach_t unstrap
Clean up module resources from both the bootstrap phase.
Definition module.h:234
int module_instance_data_unprotect(module_instance_t const *mi)
Mark module data as read/write.
Definition module.c:705
static module_thread_instance_t * module_thread(module_instance_t const *mi)
Retrieve module/thread specific instance for a module.
Definition module.h:501
module_instance_state_t
What state the module instance is currently in.
Definition module.h:263
@ MODULE_INSTANCE_INSTANTIATED
Module instance has been bootstrapped and instantiated.
Definition module.h:266
@ MODULE_INSTANCE_NO_THREAD_INSTANTIATE
Not set internally, but can be used to prevent thread instantiation for certain modules.
Definition module.h:268
@ MODULE_INSTANCE_BOOTSTRAPPED
Module instance has been bootstrapped, but not yet instantiated.
Definition module.h:264
int module_thread_instantiate(TALLOC_CTX *ctx, module_instance_t *mi, fr_event_list_t *el)
Allocate thread-local instance data for a module.
Definition module.c:1077
int(* module_thread_detach_t)(module_thread_inst_ctx_t const *mctx)
Module thread destruction callback.
Definition module.h:120
fr_rb_tree_t * data_tree
Modules indexed by data.
Definition module.h:411
module_list_type_t const module_list_type_global
Initialise a global module, with thread-specific data.
Definition module.c:528
uint32_t number
Unique module number.
Definition module.h:332
module_list_thread_data_get_t thread_data_get
Callback to get thread-specific data.
Definition module.h:433
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.
Definition module.c:974
int module_instantiate(module_instance_t *mi)
Manually complete module setup by calling its instantiate function.
Definition module.c:1189
size_t rctx_size
If set, this overrides the module_t rctx_size.
Definition module.h:180
char const * rctx_type
If rctx_size is used from the mmb, this sets the type of the rctx.
Definition module.h:184
char const * thread_inst_type
talloc type to assign to thread instance data.
Definition module.h:245
module_instantiate_t bootstrap
Callback to allow the module to register any global resources like xlat functions and attributes.
Definition module.h:215
int modules_bootstrap(module_list_t const *ml)
Bootstrap any modules which have not been bootstrapped already.
Definition module.c:1366
fr_rb_node_t data_node
Entry in the data tree.
Definition module.h:331
DL_MODULE_COMMON
Common fields for all loadable modules.
Definition module.h:204
module_thread_detach_t thread_detach
Callback to free thread-specific resources associated < with a module.
Definition module.h:241
void * uctx
Extra data passed to module_instance_alloc.
Definition module.h:359
int(* module_thread_instantiate_t)(module_thread_inst_ctx_t const *mctx)
Module thread creation callback.
Definition module.h:108
bool module_instance_skip_bootstrap(module_instance_t *mi)
Should we bootstrap this module instance?
Definition module.c:1795
void * start
Start address which may be passed to mprotect.
Definition module.h:275
module_method_binding_t * bindings
named methods
Definition module.h:165
fr_dlist_t entry
Linked list of bindings with the same name1.
Definition module.h:190
size_t boot_size
Size of the module's bootstrap data.
Definition module.h:209
module_list_t * ml
Module list this instance belongs to.
Definition module.h:329
size_t thread_inst_size
Size of the module's thread-specific instance data.
Definition module.h:244
conf_parser_t const * config
How to convert a CONF_SECTION to a module instance.
Definition module.h:206
module_instance_t * module_instance_root(module_instance_t const *child)
Find the module's shallowest parent.
Definition module.c:929
bool const module_instance_allowed_chars[UINT8_MAX+1]
Chars that are allowed in a module instance name.
Definition module.c:208
int module_instance_conf_parse(module_instance_t *mi, CONF_SECTION *conf)
Covert a CONF_SECTION into parsed module instance data.
Definition module.c:758
fr_heap_t * inst_heap
Heap of module instances.
Definition module.h:412
char const * name
Friendly list identifier.
Definition module.h:406
fr_event_list_t * el
Event list associated with this thread.
Definition module.h:374
char const * module_instance_root_prefix_str(module_instance_t const *mi)
Return the prefix string for the deepest module.
Definition module.c:719
fr_heap_index_t inst_idx
Entry in the thread-specific bootstrap heap.
Definition module.h:368
int(* module_detach_t)(module_detach_ctx_t const *inst)
Module detach callback.
Definition module.h:96
section_name_t const * section
Identifier for a section.
Definition module.h:175
module_list_type_t const * type
Type of module list.
Definition module.h:432
uint32_t last_number
Last identifier assigned to a module instance.
Definition module.h:409
fr_rb_tree_t * name_tree
Modules indexed by name.
Definition module.h:410
module_t * exported
Public module structure.
Definition module.h:296
pthread_mutex_t mutex
Used prevent multiple threads entering a thread unsafe module simultaneously.
Definition module.h:303
int module_bootstrap(module_instance_t *mi)
Manually complete module bootstrap by calling its instantiate function.
Definition module.c:1302
void module_instance_debug(module_instance_t const *mi)
Print debugging information for a module.
Definition module.c:597
Module instance data.
Definition module.h:285
A list of modules.
Definition module.h:405
Named methods exported by a module.
Definition module.h:174
A group of methods exported by a module or added as an overlay.
Definition module.h:164
Struct exported by a rlm_* module.
Definition module.h:203
Map string values to module state method.
Definition module.h:441
Per thread per instance data.
Definition module.h:367
Structure to hold callbacks for a module list type.
Definition module.c:319
eap_aka_sim_process_conf_t * inst
fr_aka_sim_id_type_t type
static fr_event_list_t * el
static fr_slen_t parent
Definition pair.h:839
static fr_slen_t data
Definition value.h:1288
int nonnull(2, 5))
static size_t char ** out
Definition value.h:1020