The FreeRADIUS server
$Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
|
Defines functions for calling modules asynchronously. More...
#include <freeradius-devel/server/modpriv.h>
#include <freeradius-devel/server/request_data.h>
#include <freeradius-devel/server/rcode.h>
#include <freeradius-devel/unlang/call_env.h>
#include "module_priv.h"
#include "subrequest_priv.h"
#include "tmpl.h"
Go to the source code of this file.
Data Structures | |
struct | unlang_module_event_t |
Wrap an fr_event_timer_t providing data needed for unlang events. More... | |
Functions | |
static int | _unlang_event_free (unlang_module_event_t *ev) |
Frees an unlang event, removing it from the request's event loop. More... | |
static void | safe_lock (module_instance_t *mi) |
static void | safe_unlock (module_instance_t *mi) |
static void | unlang_event_fd_error_handler (UNUSED fr_event_list_t *el, int fd, UNUSED int flags, UNUSED int fd_errno, void *ctx) |
Call the callback registered for an I/O error event. More... | |
static void | unlang_event_fd_read_handler (UNUSED fr_event_list_t *el, int fd, UNUSED int flags, void *ctx) |
Call the callback registered for a read I/O event. More... | |
static void | unlang_event_fd_write_handler (UNUSED fr_event_list_t *el, int fd, UNUSED int flags, void *ctx) |
Call the callback registered for a write I/O event. More... | |
static unlang_action_t | unlang_module (rlm_rcode_t *p_result, request_t *request, unlang_stack_frame_t *frame) |
static unlang_action_t | unlang_module_done (rlm_rcode_t *p_result, request_t *request, unlang_stack_frame_t *frame) |
Cleanup after a module completes. More... | |
static void | unlang_module_event_retry_handler (UNUSED fr_event_list_t *el, fr_time_t now, void *ctx) |
Call the callback registered for a retry event. More... | |
static void | unlang_module_event_timeout_handler (UNUSED fr_event_list_t *el, fr_time_t now, void *ctx) |
Call the callback registered for a timeout event. More... | |
int | unlang_module_fd_add (request_t *request, unlang_module_fd_event_t read, unlang_module_fd_event_t write, unlang_module_fd_event_t error, void const *rctx, int fd) |
Set a callback for the request. More... | |
int | unlang_module_fd_delete (request_t *request, void const *ctx, int fd) |
Delete a previously set file descriptor callback. More... | |
void | unlang_module_init (void) |
int | unlang_module_push (rlm_rcode_t *p_result, request_t *request, module_instance_t *module_instance, module_method_t method, bool top_frame) |
Push a module or submodule onto the stack for evaluation. More... | |
static unlang_action_t | unlang_module_resume (rlm_rcode_t *p_result, request_t *request, unlang_stack_frame_t *frame) |
Wrapper to call a module's resumption function. More... | |
static unlang_action_t | unlang_module_resume_done (rlm_rcode_t *p_result, request_t *request, unlang_stack_frame_t *frame) |
Cleanup after a yielded module completes. More... | |
int | unlang_module_set_resume (request_t *request, module_method_t resume) |
Change the resume function of a module. More... | |
static void | unlang_module_signal (request_t *request, unlang_stack_frame_t *frame, fr_signal_t action) |
Send a signal (usually stop) to a request. More... | |
int | unlang_module_timeout_add (request_t *request, unlang_module_timeout_t callback, void const *rctx, fr_time_t when) |
Set a timeout for the request. More... | |
int | unlang_module_timeout_delete (request_t *request, void const *ctx) |
Delete a previously set timeout callback. More... | |
unlang_action_t | unlang_module_yield (request_t *request, module_method_t resume, unlang_module_signal_t signal, fr_signal_t sigmask, void *rctx) |
Yield a request back to the interpreter from within a module. More... | |
unlang_action_t | unlang_module_yield_to_section (rlm_rcode_t *p_result, request_t *request, CONF_SECTION *subcs, rlm_rcode_t default_rcode, module_method_t resume, unlang_module_signal_t signal, fr_signal_t sigmask, void *rctx) |
unlang_action_t | unlang_module_yield_to_tmpl (TALLOC_CTX *ctx, fr_value_box_list_t *out, request_t *request, tmpl_t const *vpt, unlang_tmpl_args_t *args, module_method_t resume, unlang_module_signal_t signal, fr_signal_t sigmask, void *rctx) |
Push a pre-compiled tmpl and resumption state onto the stack for evaluation. More... | |
unlang_action_t | unlang_module_yield_to_xlat (TALLOC_CTX *ctx, bool *p_success, fr_value_box_list_t *out, request_t *request, xlat_exp_head_t const *exp, module_method_t resume, unlang_module_signal_t signal, fr_signal_t sigmask, void *rctx) |
Push a pre-compiled xlat and resumption state onto the stack for evaluation. More... | |
Defines functions for calling modules asynchronously.
Definition in file module.c.
struct unlang_module_event_t |
Wrap an fr_event_timer_t providing data needed for unlang events.
Data Fields | ||
---|---|---|
dl_module_inst_t * | dl_inst |
Module instance to pass to callbacks. Use dl_inst->data to get instance data. |
void * | env_data | Per call environment data. |
fr_event_timer_t const * | ev | Event in this worker's event heap. |
int | fd | File descriptor to wait on. |
unlang_module_fd_event_t | fd_error | Function to call when FD has errored. |
unlang_module_fd_event_t | fd_read | Function to call when FD is readable. |
unlang_module_fd_event_t | fd_write | Function to call when FD is writable. |
void const * | rctx | rctx data to pass to callbacks. |
request_t * | request | Request this event pertains to. |
void * | thread | Thread specific module instance. |
unlang_module_timeout_t | timeout | Function to call on timeout. |
|
static |
|
inlinestatic |
|
inlinestatic |
|
static |
Call the callback registered for an I/O error event.
[in] | el | containing the event (not passed to the callback). |
[in] | fd | the I/O event occurred on. |
[in] | flags | from kevent. |
[in] | fd_errno | from kevent. |
[in] | ctx | unlang_module_event_t structure holding callbacks. |
Definition at line 210 of file module.c.
|
static |
Call the callback registered for a read I/O event.
[in] | el | containing the event (not passed to the callback). |
[in] | fd | the I/O event occurred on. |
[in] | flags | from kevent. |
[in] | ctx | unlang_module_event_t structure holding callbacks. |
Definition at line 66 of file module.c.
|
static |
Call the callback registered for a write I/O event.
[in] | el | containing the event (not passed to the callback). |
[in] | fd | the I/O event occurred on. |
[in] | flags | from kevent. |
[in] | ctx | unlang_module_event_t structure holding callbacks. |
Definition at line 194 of file module.c.
|
static |
|
static |
|
static |
Call the callback registered for a retry event.
[in] | el | the event timer was inserted into. |
[in] | now | The current time, as held by the event_list. |
[in] | ctx | the stack frame |
Definition at line 822 of file module.c.
|
static |
Call the callback registered for a timeout event.
[in] | el | the event timer was inserted into. |
[in] | now | The current time, as held by the event_list. |
[in] | ctx | unlang_module_event_t structure holding callbacks. |
Definition at line 105 of file module.c.
int unlang_module_fd_add | ( | request_t * | request, |
unlang_module_fd_event_t | read, | ||
unlang_module_fd_event_t | write, | ||
unlang_module_fd_event_t | error, | ||
void const * | rctx, | ||
int | fd | ||
) |
Set a callback for the request.
Used when a module needs to read from an FD. Typically the callback is set, and then the module returns unlang_module_yield().
[in] | request | The current request. |
[in] | read | callback. Used for receiving and demuxing/decoding data. |
[in] | write | callback. Used for writing and encoding data. Where a 3rd party library is used, this should be the function issuing queries, and writing data to the socket. This should not be done in the module itself. This allows write operations to be retried in some instances, and means if the write buffer is full, the request is kept in a suspended state. |
[in] | error | callback. If the fd enters an error state. Should cleanup any handles wrapping the file descriptor, and any outstanding requests. |
[in] | rctx | for the callback. |
[in] | fd | to watch. |
Definition at line 245 of file module.c.
int unlang_module_fd_delete | ( | request_t * | request, |
void const * | ctx, | ||
int | fd | ||
) |
void unlang_module_init | ( | void | ) |
int unlang_module_push | ( | rlm_rcode_t * | p_result, |
request_t * | request, | ||
module_instance_t * | module_instance, | ||
module_method_t | method, | ||
bool | top_frame | ||
) |
Push a module or submodule onto the stack for evaluation.
[out] | p_result | Where to write the result of calling the module. |
[in] | request | The current request. |
[in] | module_instance | Instance of the module to call. |
[in] | method | to call. |
[in] | top_frame | Set to UNLANG_TOP_FRAME if the interpreter should return. Set to UNLANG_SUB_FRAME if the interprer should continue. |
Definition at line 325 of file module.c.
|
static |
|
static |
int unlang_module_set_resume | ( | request_t * | request, |
module_method_t | resume | ||
) |
Change the resume function of a module.
[in] | request | The current request. |
[in] | resume | function to call when the XLAT expansion is complete. |
Definition at line 400 of file module.c.
|
static |
Send a signal (usually stop) to a request.
This is typically called via an "async" action, i.e. an action outside of the normal processing of the request.
If there is no unlang_module_signal_t callback defined, the action is ignored.
[in] | request | The current request. |
[in] | frame | current stack frame. |
[in] | action | to signal. |
Definition at line 626 of file module.c.
int unlang_module_timeout_add | ( | request_t * | request, |
unlang_module_timeout_t | callback, | ||
void const * | rctx, | ||
fr_time_t | when | ||
) |
Set a timeout for the request.
Used when a module needs wait for an event. Typically the callback is set, and then the module returns unlang_module_yield().
param[in] request the current request. param[in] callback to call. param[in] rctx to pass to the callback. param[in] timeout when to call the timeout (i.e. now + timeout).
Definition at line 128 of file module.c.
int unlang_module_timeout_delete | ( | request_t * | request, |
void const * | ctx | ||
) |
unlang_action_t unlang_module_yield | ( | request_t * | request, |
module_method_t | resume, | ||
unlang_module_signal_t | signal, | ||
fr_signal_t | sigmask, | ||
void * | rctx | ||
) |
Yield a request back to the interpreter from within a module.
This passes control of the request back to the unlang interpreter, setting callbacks to execute when the request is 'signalled' asynchronously, or whatever timer or I/O event the module was waiting for occurs.
return unlang_module_yield(...)
.[in] | request | The current request. |
[in] | resume | Called on unlang_interpret_mark_runnable(). |
[in] | signal | Called on unlang_action(). |
[in] | sigmask | Set of signals to block. |
[in] | rctx | to pass to the callbacks. |
Definition at line 575 of file module.c.
unlang_action_t unlang_module_yield_to_section | ( | rlm_rcode_t * | p_result, |
request_t * | request, | ||
CONF_SECTION * | subcs, | ||
rlm_rcode_t | default_rcode, | ||
module_method_t | resume, | ||
unlang_module_signal_t | signal, | ||
fr_signal_t | sigmask, | ||
void * | rctx | ||
) |
unlang_action_t unlang_module_yield_to_tmpl | ( | TALLOC_CTX * | ctx, |
fr_value_box_list_t * | out, | ||
request_t * | request, | ||
tmpl_t const * | vpt, | ||
unlang_tmpl_args_t * | args, | ||
module_method_t | resume, | ||
unlang_module_signal_t | signal, | ||
fr_signal_t | sigmask, | ||
void * | rctx | ||
) |
Push a pre-compiled tmpl and resumption state onto the stack for evaluation.
In order to use the async unlang processor the calling module needs to establish a resumption point, as the call to an xlat function may require yielding control back to the interpreter.
To simplify the calling conventions, this function is provided to first push a resumption stack frame for the module, and then push a tmpl stack frame.
After pushing those frames the function updates the stack pointer to jump over the resumption frame and execute the tmpl expansion.
When the tmpl interpreter finishes, and pops the tmpl frame, the unlang interpreter will then call the module resumption frame, allowing the module to continue execution.
[in] | ctx | To allocate talloc value boxes and values in. |
[out] | out | Where to write the result of the expansion. |
[in] | request | The current request. |
[in] | vpt | the tmpl to expand |
[in] | args | Arguments which control how to evaluate the various types of xlats. |
[in] | resume | function to call when the XLAT expansion is complete. |
[in] | signal | function to call if a signal is received. |
[in] | sigmask | Signals to block. |
[in] | rctx | to pass to the resume() and signal() callbacks. |
Definition at line 496 of file module.c.
unlang_action_t unlang_module_yield_to_xlat | ( | TALLOC_CTX * | ctx, |
bool * | p_success, | ||
fr_value_box_list_t * | out, | ||
request_t * | request, | ||
xlat_exp_head_t const * | exp, | ||
module_method_t | resume, | ||
unlang_module_signal_t | signal, | ||
fr_signal_t | sigmask, | ||
void * | rctx | ||
) |
Push a pre-compiled xlat and resumption state onto the stack for evaluation.
In order to use the async unlang processor the calling module needs to establish a resumption point, as the call to an xlat function may require yielding control back to the interpreter.
To simplify the calling conventions, this function is provided to first push a resumption stack frame for the module, and then push an xlat stack frame.
After pushing those frames the function updates the stack pointer to jump over the resumption frame and execute the xlat interpreter.
When the xlat interpreter finishes, and pops the xlat frame, the unlang interpreter will then call the module resumption frame, allowing the module to continue execution.
[in] | ctx | To allocate talloc value boxes and values in. |
[out] | p_success | Whether xlat evaluation was successful. |
[out] | out | Where to write the result of the expansion. |
[in] | request | The current request. |
[in] | exp | XLAT expansion to evaluate. |
[in] | resume | function to call when the XLAT expansion is complete. |
[in] | signal | function to call if a signal is received. |
[in] | sigmask | Signals to block. |
[in] | rctx | to pass to the resume() and signal() callbacks. |
Definition at line 449 of file module.c.