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