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