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: b5abd1fb7f945c2c113d66b8a8e43126a270b19a $
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: b5abd1fb7f945c2c113d66b8a8e43126a270b19a $")
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 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 phases.
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 module_thread_instantiate_t coord_attach; //!< Callback to attach a worker to a coordinator.
245
246 size_t thread_inst_size; //!< Size of the module's thread-specific instance data.
247 char const *thread_inst_type; //!< talloc type to assign to thread instance data.
248
249 size_t rctx_size; //!< Size of the module's thread-specific data.
250 char const *rctx_type; //!< talloc type to assign to thread instance data.
251};
252
253#define TALLOCED_TYPE(_field, _ctype) \
254 ._field##_size = sizeof(_ctype), ._field##_type = #_ctype
255
256#define MODULE_BOOT(_ctype) TALLOCED_TYPE(boot, _ctype)
257#define MODULE_INST(_ctype) TALLOCED_TYPE(inst, _ctype)
258#define MODULE_THREAD_INST(_ctype) TALLOCED_TYPE(thread_inst, _ctype)
259#define MODULE_RCTX(_ctype) TALLOCED_TYPE(rctx, _ctype)
260
261/** What state the module instance is currently in
262 *
263 */
264DIAG_OFF(attributes)
265typedef enum CC_HINT(flag_enum) {
266 MODULE_INSTANCE_BOOTSTRAPPED = (1 << 1), //!< Module instance has been bootstrapped, but not
267 ///< yet instantiated.
268 MODULE_INSTANCE_INSTANTIATED = (1 << 2), //!< Module instance has been bootstrapped and
269 ///< instantiated.
270 MODULE_INSTANCE_NO_THREAD_INSTANTIATE = (1 << 3) //!< Not set internally, but can be used to prevent
271 ///< thread instantiation for certain modules.
273DIAG_ON(attributes)
274
275typedef struct {
276 TALLOC_CTX *ctx; //!< ctx data is allocated in.
277 void *start; //!< Start address which may be passed to mprotect.
278 size_t len; //!< How much data we need mprotect to protect.
280
281/** Module instance data
282 *
283 * Per-module-instance data structure to correlate the modules with the
284 * instance names (may NOT be the module names!), and the per-instance
285 * data structures.
286 */
288 /** @name Fields that are most frequently accessed at runtime
289 *
290 * Putting them first gives us the greatest chance of the pointers being prefetched.
291 * @{
292 */
293 void *data; //!< Module's instance data. This is most
294 ///< frequently accessed, so comes first.
295
296 void *boot; //!< Data allocated during the boostrap phase
297
298 module_t *exported; //!< Public module structure. Cached for convenience.
299 ///< This exports module methods, i.e. the functions
300 ///< which allow the module to perform actions.
301 ///< This is an identical address to module->common,
302 ///< but with a different type, containing additional
303 ///< instance callbacks to make it easier to use.
304
305 pthread_mutex_t mutex; //!< Used prevent multiple threads entering a thread
306 ///< unsafe module simultaneously.
307
308 dl_module_t *module; //!< Dynamic loader handle. Contains the module's
309 ///< dlhandle, and the functions it exports.
310 ///< The dl_module is reference counted so that it
311 ///< can be freed automatically when the last instance
312 ///< is freed. This will also (usually) unload the
313 ///< .so or .dylib.
314 /** @} */
315
316 /** @name Return code overrides
317 * @{
318 */
319 bool force; //!< Force the module to return a specific code.
320 //!< Usually set via an administrative interface.
321
322 rlm_rcode_t code; //!< Code module will return when 'force' has
323 //!< has been set to true.
324
325 unlang_mod_actions_t actions; //!< default actions and retries.
326 /** @} */
327
328 /** @name Allow module instance data to be resolved by name or data, and to get back to the module list
329 * @{
330 */
331 module_list_t *ml; //!< Module list this instance belongs to.
332 fr_rb_node_t name_node; //!< Entry in the name tree.
333 fr_rb_node_t data_node; //!< Entry in the data tree.
334 uint32_t number; //!< Unique module number. Used to assign a stable
335 ///< number to each module instance.
336 /** @} */
337
338 /** @name These structures allow mprotect to protect/unprotest bootstrap and instance data
339 * @{
340 */
341 module_data_pool_t inst_pool; //!< Data to allow mprotect state toggling
342 ///< for instance data.
343 module_data_pool_t boot_pool; //!< Data to allow mprotect state toggling
344 ///< for bootstrap data.
345 /** @} */
346
347 /** @name Module instance state
348 * @{
349 */
350 module_instance_state_t state; //!< What's been done with this module so far.
351 CONF_SECTION *conf; //!< Module's instance configuration.
352 /** @} */
353
354 /** @name Misc fields
355 * @{
356 */
357 char const *name; //!< Instance name e.g. user_database.
358
359 module_instance_t const *parent; //!< Parent module's instance (if any).
360
361 void *uctx; //!< Extra data passed to module_instance_alloc.
362 /** @} */
363};
364
365/** Per thread per instance data
366 *
367 * Stores module and thread specific data.
368 */
370 fr_heap_index_t inst_idx; //!< Entry in the thread-specific bootstrap heap.
371 ///< Should be an identical value to the global
372 ///< instance data for the same module.
373
374 void *data; //!< Thread specific instance data.
375
376 fr_event_list_t *el; //!< Event list associated with this thread.
377
378 module_instance_t *mi; //!< As opposed to the thread local inst.
379
380 uint64_t total_calls; //! total number of times we've been called
381 uint64_t active_callers; //! number of active callers. i.e. number of current yields
382};
383
384/** Callback to retrieve thread-local data for a module
385 *
386 * This is public for performance reasons, and should be called through
387 * #module_thread.
388 *
389 * @param[in] mi to add data to (use mi->ml for the module list).
390 * @return
391 * - NULL if no data exists.
392 * - Pointer to the data on success.
393 */
394typedef module_thread_instance_t *(*module_list_thread_data_get_t)(module_instance_t const *mi);
395
396/** A list of modules
397 *
398 * This used to be a global structure, but was move to a struct.
399 *
400 * Module lists allow collections of modules to be created. The module lists themselves can be configured
401 * to be thread-local or global, with optional runtime write protection.
402 *
403 * Thread-local module lists are used for dynamic modules, i.e. those created at runtime, where as the
404 * global module lists are used for backend modules, listeners, and process state machines.
405 */
407{
408 char const *name; //!< Friendly list identifier.
409 module_instance_state_t mask; //!< Prevent phases from being executed.
410
411 uint32_t last_number; //!< Last identifier assigned to a module instance.
412 fr_rb_tree_t *name_tree; //!< Modules indexed by name.
413 fr_rb_tree_t *data_tree; //!< Modules indexed by data.
414 fr_heap_t *inst_heap; //!< Heap of module instances.
415
416 bool write_protect; //!< If true, pages containing module boot or
417 ///< instance data will be write protected after
418 ///< bootstrapping and instantiation is complete,
419 ///< to prevent accidental modification.
420
421 /** @name Callbacks to manage thread-specific data
422 *
423 * In "child" lists, which are only operating in a single thread, we don't need
424 * to use true thread-local data, because the module list itself is thread-local.
425 *
426 * In that case these callbacks hang memory off of the list itself.
427 *
428 * In the main module list, which is shared between threads, these callbacks
429 * do use true thread-local data, to manage the module_thread_instance_t
430 * on a per thread-basis.
431 *
432 * @{
433 */
434 module_list_type_t const *type; //!< Type of module list.
435 module_list_thread_data_get_t thread_data_get; //!< Callback to get thread-specific data.
436 ///< Copy of type->thread_data_get.
437 /** @} */
438};
439
440/** Map string values to module state method
441 *
442 */
444 char const *name; //!< String identifier for state.
445 module_method_t func; //!< State function.
446};
447
448/** @name Callbacks for the conf_parser_t
449 *
450 * @{
451 */
452int module_submodule_parse(UNUSED TALLOC_CTX *ctx, void *out, void *parent,
453 CONF_ITEM *ci, UNUSED conf_parser_t const *rule) CC_HINT(warn_unused_result);
454/** @} */
455
456/** @name Debugging functions
457 *
458 * @{
459 */
460void module_instance_debug(module_instance_t const *mi) CC_HINT(nonnull);
461
462void module_list_debug(module_list_t const *ml) CC_HINT(nonnull);
463 /** @} */
464
465/** @name Toggle protection on module instance data
466 *
467 * This is used for module lists which implement additional instantiation phases
468 * (like li->open). It should NOT be used by modules to hack around instance
469 * data being read-only after instantiation completes.
470 *
471 * @{
472 */
474
476 /** @} */
477
478/** @name Module and module thread lookup
479 *
480 * @{
481 */
483
485
486char const *module_instance_root_prefix_str(module_instance_t const *mi) CC_HINT(nonnull) CC_HINT(warn_unused_result);
487
488module_instance_t *module_instance_root(module_instance_t const *child); CC_HINT(warn_unused_result)
489
490module_instance_t *module_instance_by_name(module_list_t const *ml, module_instance_t const *parent, char const *asked_name)
491 CC_HINT(nonnull(1,3)) CC_HINT(warn_unused_result);
492
493module_instance_t *module_instance_by_data(module_list_t const *ml, void const *data) CC_HINT(warn_unused_result);
494
495/** Retrieve module/thread specific instance for a module
496 *
497 * @param[in] mi to find thread specific data for.
498 * @return
499 * - Thread specific instance data on success.
500 * - NULL if module has no thread instance data.
501 */
502static inline CC_HINT(warn_unused_result) CC_HINT(always_inline)
504{
505 return mi->ml->thread_data_get(mi);
506}
507
508module_thread_instance_t *module_thread_by_data(module_list_t const *ml, void const *data) CC_HINT(warn_unused_result);
509/** @} */
510
511/** @name Module and module thread initialisation and instantiation
512 *
513 * @{
514 */
516
518 CC_HINT(nonnull) CC_HINT(warn_unused_result);
519
520int modules_thread_instantiate(TALLOC_CTX *ctx, module_list_t const *ml, fr_event_list_t *el)
521 CC_HINT(nonnull) CC_HINT(warn_unused_result);
522
524 CC_HINT(nonnull) CC_HINT(warn_unused_result);
525
526int module_instantiate(module_instance_t *mi) CC_HINT(nonnull) CC_HINT(warn_unused_result);
527
528int modules_instantiate(module_list_t const *ml) CC_HINT(nonnull) CC_HINT(warn_unused_result);
529
530int module_bootstrap(module_instance_t *mi) CC_HINT(nonnull) CC_HINT(warn_unused_result);
531
532int modules_bootstrap(module_list_t const *ml) CC_HINT(nonnull) CC_HINT(warn_unused_result);
533
535
536fr_slen_t module_instance_name_valid(char const *inst_name) CC_HINT(nonnull);
537
538module_instance_t *module_instance_copy(module_list_t *dst, module_instance_t const *src, char const *inst_name)
539 CC_HINT(nonnull(1,2)) CC_HINT(warn_unused_result);
540
543 dl_module_type_t type, char const *mod_name, char const *inst_name,
544 module_instance_state_t init_state)
545 CC_HINT(nonnull(1)) CC_HINT(warn_unused_result);
546
547void module_instance_uctx_set(module_instance_t *mi, void *uctx);
548
549/** @name Module list variants
550 *
551 * These are passed to the module_list_alloc function to allocate lists of different types
552 *
553 * Global module lists are used for backend modules, listeners, and process state machines.
554 *
555 * Thread-local lists are usually runtime instantiated variants of modules, or modules that represent client connections.
556 *
557 * One major difference (from the module's perspective) is that bootstrap is not called for thread-local modules.
558 *
559 * @{
560 */
561extern module_list_type_t const module_list_type_global; //!< Initialise a global module, with thread-specific data.
562extern module_list_type_t const module_list_type_thread_local; //!< Initialise a thread-local module, which is only used in a single thread.
563/** @} */
564
565/** @name Control which phases are skipped (if any)
566 * @{
567 */
569
571
573
575/** @} */
576
578 char const *name, bool write_protect)
579 CC_HINT(nonnull(2,3)) CC_HINT(warn_unused_result);
580
581void modules_init(char const *lib_dir);
582/** @} */
583
584#ifdef __cplusplus
585}
586#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:481
#define RCSIDH(h, id)
Definition build.h:507
#define UNUSED
Definition build.h:336
#define DIAG_OFF(_x)
Definition build.h:480
Defines a CONF_PAIR to C data type mapping.
Definition cf_parse.h:594
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:2948
unsigned int uint32_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
static char const * name
#define SBUFF_CHAR_CLASS
Definition sbuff.h:203
Section name identifier.
Definition section.h:43
module_thread_instantiate_t coord_attach
Callback to attach a worker to a coordinator.
Definition module.h:244
size_t rctx_size
Size of the module's thread-specific data.
Definition module.h:249
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:1939
bool module_instance_skip_thread_instantiate(module_instance_t *mi)
Should we instantiate this module instance in a new thread?
Definition module.c:1854
module_instance_t * mi
As opposed to the thread local inst.
Definition module.h:378
char const * name
Instance name e.g. user_database.
Definition module.h:357
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:332
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:381
CONF_SECTION * conf
Module's instance configuration.
Definition module.h:351
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 phases.
Definition module.h:232
bool force
Force the module to return a specific code.
Definition module.h:319
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:1864
void * data
Module's instance data.
Definition module.h:293
module_instance_state_t state
What's been done with this module so far.
Definition module.h:350
module_method_t func
State function.
Definition module.h:445
module_instance_t const * parent
Parent module's instance (if any).
Definition module.h:359
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: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: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:1159
unlang_mod_actions_t actions
default actions and retries.
Definition module.h:325
char const * rctx_type
talloc type to assign to thread instance data.
Definition module.h:250
bool module_instance_skip_instantiate(module_instance_t *mi)
Should we instantiate this module instance?
Definition module.c:1842
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:1563
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: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:1310
void * boot
Data allocated during the boostrap phase.
Definition module.h:296
TALLOC_CTX * ctx
ctx data is allocated in.
Definition module.h:276
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:409
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:394
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:1680
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:1886
void module_instance_uctx_set(module_instance_t *mi, void *uctx)
Set the uctx pointer for a module instance.
Definition module.c:1648
fr_dlist_head_t same_name1
List of bindings with the same name1.
Definition module.h:187
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:374
char const * name
String identifier for state.
Definition module.h:444
module_data_pool_t inst_pool
Data to allow mprotect state toggling for instance data.
Definition module.h:341
bool write_protect
If true, pages containing module boot or instance data will be write protected after bootstrapping an...
Definition module.h:416
rlm_rcode_t code
Code module will return when 'force' has has been set to true.
Definition module.h:322
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:278
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: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:1620
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:343
module_detach_t unstrap
Clean up module resources from both the bootstrap phase.
Definition module.h:234
static module_thread_instance_t * module_thread(module_instance_t const *mi)
Retrieve module/thread specific instance for a module.
Definition module.h:503
module_instance_state_t
What state the module instance is currently in.
Definition module.h:265
@ MODULE_INSTANCE_INSTANTIATED
Module instance has been bootstrapped and instantiated.
Definition module.h:268
@ MODULE_INSTANCE_NO_THREAD_INSTANTIATE
Not set internally, but can be used to prevent thread instantiation for certain modules.
Definition module.h:270
@ MODULE_INSTANCE_BOOTSTRAPPED
Module instance has been bootstrapped, but not yet instantiated.
Definition module.h:266
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
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:413
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:334
module_list_thread_data_get_t thread_data_get
Callback to get thread-specific data.
Definition module.h:435
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:1224
size_t rctx_size
If set, this overrides the module_t rctx_size.
Definition module.h:180
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:184
char const * thread_inst_type
talloc type to assign to thread instance data.
Definition module.h:247
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:1401
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:333
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:361
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:1830
void * start
Start address which may be passed to mprotect.
Definition module.h:277
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:331
size_t thread_inst_size
Size of the module's thread-specific instance data.
Definition module.h:246
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: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:414
char const * name
Friendly list identifier.
Definition module.h:408
fr_event_list_t * el
Event list associated with this thread.
Definition module.h:376
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:370
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:434
uint32_t last_number
Last identifier assigned to a module instance.
Definition module.h:411
fr_rb_tree_t * name_tree
Modules indexed by name.
Definition module.h:412
module_t * exported
Public module structure.
Definition module.h:298
pthread_mutex_t mutex
Used prevent multiple threads entering a thread unsafe module simultaneously.
Definition module.h:305
int module_bootstrap(module_instance_t *mi)
Manually complete module bootstrap by calling its instantiate function.
Definition module.c:1337
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:287
A list of modules.
Definition module.h:407
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:443
Per thread per instance data.
Definition module.h:369
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:858
static fr_slen_t data
Definition value.h:1340
int nonnull(2, 5))
static size_t char ** out
Definition value.h:1030