From: Arran Cudbard-Bell Date: Sat, 20 Jan 2018 18:42:51 +0000 (-0700) Subject: General reshuffling of unlang/xlat things into their proper places X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=58f670ede0764ee5bc607b31ecf71fa6c6e3218c;p=thirdparty%2Ffreeradius-server.git General reshuffling of unlang/xlat things into their proper places The signal enum needs to be in its own header, because it's used by the proto module state machines and the unlang interpreter, but the two really shouldn't know about each other. --- diff --git a/src/include/modules.h b/src/include/modules.h index 3e30ffd925a..46245641018 100644 --- a/src/include/modules.h +++ b/src/include/modules.h @@ -136,6 +136,67 @@ typedef int (*module_thread_t)(CONF_SECTION const *mod_cs, void *instance, fr_ev */ typedef int (*module_thread_detach_t)(void *thread); + +/** A callback when the the timeout occurs + * + * Used when a module needs wait for an event. + * Typically the callback is set, and then the module returns unlang_module_yield(). + * + * @note The callback is automatically removed on unlang_resumable(), i.e. if an event + * on a registered FD occurs before the timeout event fires. + * + * @param[in] request the request. + * @param[in] instance the module instance. + * @param[in] thread data specific to this module instance. + * @param[in] rctx a local context for the callback. + * @param[in] fired the time the timeout event actually fired. + */ +typedef void (*fr_unlang_module_timeout_t)(REQUEST *request, void *instance, void *thread, void *rctx, + struct timeval *fired); + +/** A callback when the FD is ready for reading + * + * Used when a module needs to read from an FD. Typically the callback is set, and then the + * module returns unlang_module_yield(). + * + * @note The callback is automatically removed on unlang_resumable(), so + * + * @param[in] request the current request. + * @param[in] instance the module instance. + * @param[in] thread data specific to this module instance. + * @param[in] rctx a local context for the callback. + * @param[in] fd the file descriptor. + */ +typedef void (*fr_unlang_module_fd_event_t)(REQUEST *request, void *instance, void *thread, void *rctx, int fd); + +/** A callback for when the request is resumed. + * + * The resumed request cannot call the normal "authorize", etc. method. It needs a separate callback. + * + * @param[in] request the current request. + * @param[in] instance The module instance. + * @param[in] thread data specific to this module instance. + * @param[in] rctx a local context for the callback. + * @return a normal rlm_rcode_t. + */ +typedef rlm_rcode_t (*fr_unlang_module_resume_t)(REQUEST *request, void *instance, void *thread, void *rctx); + +/** A callback when the request gets a fr_state_signal_t. + * + * A module may call unlang_yeild(), but still need to do something on FR_SIGNAL_DUP. If so, it's + * set here. + * + * @note The callback is automatically removed on unlang_resumable(). + * + * @param[in] request The current request. + * @param[in] instance The module instance. + * @param[in] thread data specific to this module instance. + * @param[in] rctx Resume ctx for the callback. + * @param[in] action which is signalling the request. + */ +typedef void (*fr_unlang_module_signal_t)(REQUEST *request, void *instance, void *thread, + void *rctx, fr_state_signal_t action); + /** Struct exported by a rlm_* module * * Determines the capabilities of the module, and maps internal functions @@ -249,6 +310,14 @@ int virtual_servers_bootstrap(CONF_SECTION *config); CONF_SECTION *virtual_server_find(char const *name); void fr_request_async_bootstrap(REQUEST *request, fr_event_list_t *el); /* for unit_test_module */ +/* + * modules_unlang.c + */ + +rlm_rcode_t module_unlang_push_xlat(TALLOC_CTX *ctx, fr_value_box_t **out, + REQUEST *request, xlat_exp_t const *xlat, + fr_unlang_module_resume_t callback, + fr_unlang_module_signal_t signal_callback, void *uctx); #ifdef __cplusplus } #endif diff --git a/src/include/process.h b/src/include/process.h index 2b4ded5897d..c1b9ba09802 100644 --- a/src/include/process.h +++ b/src/include/process.h @@ -29,24 +29,16 @@ RCSIDH(process_h, "$Id$") #include #include +#include #ifdef __cplusplus extern "C" { #endif -typedef enum fr_state_action_t { /* server action */ - FR_ACTION_INVALID = 0, - FR_ACTION_RUN, - FR_ACTION_DONE, //!< Request is completed. If a module is signalled - ///< with this, the module should stop processing - ///< the request and cleanup. - FR_ACTION_DUP, //!< A duplicate request was received. -} fr_state_action_t; - /* * Function handler for requests. */ -typedef void (*fr_request_process_t)(REQUEST *, fr_state_action_t); +typedef void (*fr_request_process_t)(REQUEST *, fr_state_signal_t); extern time_t fr_start_time; @@ -55,7 +47,6 @@ extern time_t fr_start_time; */ void request_delete(REQUEST *request); - #ifdef __cplusplus } #endif diff --git a/src/include/signal.h b/src/include/signal.h new file mode 100644 index 00000000000..6dc6e9e195d --- /dev/null +++ b/src/include/signal.h @@ -0,0 +1,49 @@ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ +#ifndef _FR_SIGNAL_H +#define _FR_SIGNAL_H +/** + * $Id$ + * + * @file include/signal.h + * @brief Signals that can be sent to a request. + * + * @copyright 2018 The FreeRADIUS server project + * @copyright 2018 Arran Cudbard-Bell + */ +RCSIDH(signal_h, "$Id$") + + +#ifdef __cplusplus +extern "C" { +#endif + +/** Signals that can be generated/processed by request signal handlers + * + */ +typedef enum fr_state_signal_t { /* server action */ + FR_SIGNAL_INVALID = 0, + FR_SIGNAL_RUN, + FR_SIGNAL_DONE, //!< Request is completed. If a module is signalled + ///< with this, the module should stop processing + ///< the request and cleanup. + FR_SIGNAL_DUP, //!< A duplicate request was received. +} fr_state_signal_t; + +#ifdef __cplusplus +} +#endif +#endif /* _FR_SIGNAL_H */ diff --git a/src/include/unlang.h b/src/include/unlang.h index 2520311208f..a3c7168a1c4 100644 --- a/src/include/unlang.h +++ b/src/include/unlang.h @@ -24,6 +24,7 @@ */ #include #include +#include /** Returned by #unlang_op_t calls, determine the next action of the interpreter * @@ -46,20 +47,20 @@ typedef enum { * @param[in,out] priority Pointer to the current priority, may be modified by the function. * @return an action for the interpreter to perform. */ -typedef unlang_action_t (*unlang_op_func_t)(REQUEST *request, rlm_rcode_t *presult, int *priority); +typedef unlang_action_t (*unlang_op_call_t)(REQUEST *request, rlm_rcode_t *presult, int *priority); /** Function to call if the initial function yielded and the request was signalled * * This is the operation specific cancellation function. This function will usually * either call a more specialised cancellation function set when something like a module yielded, - * or just cleanup the state of the original #unlang_op_func_t. + * or just cleanup the state of the original #unlang_op_call_t. * * @param[in] request The current request. - * @param[in] resume_ctx A structure allocated by the initial #unlang_op_func_t to store + * @param[in] rctx A structure allocated by the initial #unlang_op_call_t to store * the result of the async execution. * @param[in] action We're being signalled with. */ -typedef void (*unlang_op_func_signal_t)(REQUEST *request, void *resume_ctx, fr_state_action_t action); +typedef void (*unlang_op_signal_t)(REQUEST *request, void *rctx, fr_state_signal_t action); /** Function to call when a request becomes resumable * @@ -68,81 +69,21 @@ typedef void (*unlang_op_func_signal_t)(REQUEST *request, void *resume_ctx, fr_s * descriptors, and generally cleanup after the yielding function. * * @param[in] request The current request. - * @param[in] resume_ctx A structure allocated by the initial #unlang_op_func_t to store + * @param[in] rctx A structure allocated by the initial #unlang_op_call_t to store * the result of the async execution. * @param[in] action We're being signalled with. */ -typedef void (*unlang_op_func_resumable_t)(REQUEST *request, void *resume_ctx); +typedef void (*unlang_op_resumable_t)(REQUEST *request, void *rctx); /** Function to call if the initial function yielded and the request is resumable * * @param[in] request The current request. * @param[in,out] presult Pointer to the current rcode, may be modified by the function. - * @param[in] resume_ctx A structure allocated by the initial #unlang_op_func_t to store + * @param[in] rctx A structure allocated by the initial #unlang_op_call_t to store * the result of the async execution. * @return an action for the interpreter to perform. */ -typedef unlang_action_t (*unlang_op_func_resume_t)(REQUEST *request, rlm_rcode_t *presult, void *resume_ctx); - -/** A callback when the the timeout occurs - * - * Used when a module needs wait for an event. - * Typically the callback is set, and then the module returns unlang_module_yield(). - * - * @note The callback is automatically removed on unlang_resumable(), i.e. if an event - * on a registered FD occurs before the timeout event fires. - * - * @param[in] request the request. - * @param[in] instance the module instance. - * @param[in] thread data specific to this module instance. - * @param[in] rctx a local context for the callback. - * @param[in] fired the time the timeout event actually fired. - */ -typedef void (*fr_unlang_module_timeout_t)(REQUEST *request, void *instance, void *thread, void *rctx, - struct timeval *fired); - -/** A callback when the FD is ready for reading - * - * Used when a module needs to read from an FD. Typically the callback is set, and then the - * module returns unlang_module_yield(). - * - * @note The callback is automatically removed on unlang_resumable(), so - * - * @param[in] request the current request. - * @param[in] instance the module instance. - * @param[in] thread data specific to this module instance. - * @param[in] rctx a local context for the callback. - * @param[in] fd the file descriptor. - */ -typedef void (*fr_unlang_module_fd_event_t)(REQUEST *request, void *instance, void *thread, void *rctx, int fd); - -/** A callback for when the request is resumed. - * - * The resumed request cannot call the normal "authorize", etc. method. It needs a separate callback. - * - * @param[in] request the current request. - * @param[in] instance The module instance. - * @param[in] thread data specific to this module instance. - * @param[in] rctx a local context for the callback. - * @return a normal rlm_rcode_t. - */ -typedef rlm_rcode_t (*fr_unlang_module_resume_t)(REQUEST *request, void *instance, void *thread, void *rctx); - -/** A callback when the request gets a fr_state_action_t. - * - * A module may call unlang_yeild(), but still need to do something on FR_ACTION_DUP. If so, it's - * set here. - * - * @note The callback is automatically removed on unlang_resumable(). - * - * @param[in] request The current request. - * @param[in] instance The module instance. - * @param[in] thread data specific to this module instance. - * @param[in] rctx Resume ctx for the callback. - * @param[in] action which is signalling the request. - */ -typedef void (*fr_unlang_module_signal_t)(REQUEST *request, void *instance, void *thread, - void *rctx, fr_state_action_t action); +typedef unlang_action_t (*unlang_op_resume_t)(REQUEST *request, rlm_rcode_t *presult, void *rctx); /** An unlang operation * @@ -151,27 +92,24 @@ typedef void (*fr_unlang_module_signal_t)(REQUEST *request, void *instance, void */ typedef struct { char const *name; //!< Name of the operation. - unlang_op_func_t func; //!< Called when we start the operation. - unlang_op_func_signal_t signal; //!< Called if the request is to be destroyed + unlang_op_call_t func; //!< Called when we start the operation. + + unlang_op_signal_t signal; //!< Called if the request is to be destroyed ///< and we need to cleanup any residual state. - unlang_op_func_resumable_t resumable; //!< Called as soon as the interpreter is informed + unlang_op_resumable_t resumable; //!< Called as soon as the interpreter is informed ///< that a request is resumable. - unlang_op_func_resume_t resume; //!< Called if we're continuing processing + unlang_op_resume_t resume; //!< Called if we're continuing processing ///< a request. + bool debug_braces; //!< Whether the operation needs to print braces ///< in debug mode. } unlang_op_t; void unlang_push_section(REQUEST *request, CONF_SECTION *cs, rlm_rcode_t default_action); -rlm_rcode_t unlang_push_module_xlat(TALLOC_CTX *ctx, fr_value_box_t **out, - REQUEST *request, xlat_exp_t const *xlat, - fr_unlang_module_resume_t callback, - fr_unlang_module_signal_t signal_callback, void *uctx); - rlm_rcode_t unlang_interpret_continue(REQUEST *request); rlm_rcode_t unlang_interpret(REQUEST *request, CONF_SECTION *cs, rlm_rcode_t default_action); @@ -203,14 +141,13 @@ int unlang_event_fd_delete(REQUEST *request, void const *ctx, int fd); void unlang_resumable(REQUEST *request); -void unlang_signal(REQUEST *request, fr_state_action_t action); +void unlang_signal(REQUEST *request, fr_state_signal_t action); int unlang_stack_depth(REQUEST *request); rlm_rcode_t unlang_module_yield(REQUEST *request, fr_unlang_module_resume_t callback, fr_unlang_module_signal_t signal_callback, void *ctx); -xlat_action_t unlang_xlat_yield(REQUEST *request, xlat_resume_callback_t callback, - fr_unlang_module_signal_t signal_callback, void *rctx); + int unlang_initialize(void); #endif /* _FR_UNLANG_H */ diff --git a/src/include/xlat.h b/src/include/xlat.h index 3dd1ff3716e..7198f165442 100644 --- a/src/include/xlat.h +++ b/src/include/xlat.h @@ -125,9 +125,22 @@ typedef xlat_action_t (*xlat_func_async_t)(TALLOC_CTX *ctx, fr_cursor_t *out, * mean it turned a result. * - XLAT_ACTION_FAIL the xlat function failed. */ -typedef xlat_action_t (*xlat_resume_callback_t)(TALLOC_CTX *ctx, fr_cursor_t *out, - REQUEST *request, void const *xlat_inst, void *xlat_thread_inst, - fr_cursor_t *in, void *rctx); +typedef xlat_action_t (*xlat_func_resume_t)(TALLOC_CTX *ctx, fr_cursor_t *out, + REQUEST *request, void const *xlat_inst, void *xlat_thread_inst, + fr_cursor_t *in, void *rctx); + +/** A callback when the request gets a fr_state_signal_t. + * + * @note The callback is automatically removed on unlang_resumable(). + * + * @param[in] request The current request. + * @param[in] instance The module instance. + * @param[in] thread data specific to this module instance. + * @param[in] rctx Resume ctx for the callback. + * @param[in] action which is signalling the request. + */ +typedef void (*xlat_func_signal_t)(REQUEST *request, void *instance, void *thread, + void *rctx, int action); /** Allocate new instance data for an xlat instance * @@ -239,6 +252,15 @@ int xlat_bootstrap(xlat_exp_t *root); void xlat_instances_free(void); +/* + * xlat_unlang.c + */ +void xlat_unlang_push(TALLOC_CTX *ctx, fr_value_box_t **out, + REQUEST *request, xlat_exp_t const *exp, bool top_frame); + +xlat_action_t xlat_unlang_yield(REQUEST *request, + xlat_func_resume_t callback, xlat_func_signal_t signal, + void *rctx); #ifdef __cplusplus } #endif diff --git a/src/main/libfreeradius-server.mk b/src/main/libfreeradius-server.mk index 460c06db06a..803f4abab83 100644 --- a/src/main/libfreeradius-server.mk +++ b/src/main/libfreeradius-server.mk @@ -14,6 +14,7 @@ SOURCES := cond_eval.c \ map_proc.c \ map.c \ modules.c \ + modules_unlang.c \ regex.c \ request.c \ trigger.c \ diff --git a/src/main/modules_unlang.c b/src/main/modules_unlang.c new file mode 100644 index 00000000000..5b7a71d5afb --- /dev/null +++ b/src/main/modules_unlang.c @@ -0,0 +1,81 @@ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +/** + * $Id$ + * + * @file modules_unlang.c + * @brief Defines functions for calling modules asynchronously + * + * @copyright 2018 The FreeRADIUS server project + * @copyright 2018 Arran Cudbard-Bell + */ + +RCSID("$Id$") + +#include +#include +#include +#include +#include +#include "unlang_priv.h" + +/** 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 exectuion. + * + * @param[in] ctx To allocate value boxes and values in. + * @param[out] out Where to write the result of the expansion. + * @param[in] request The current request. + * @param[in] xlat to evaluate. + * @param[in] callback to call on unlang_resumable(). + * @param[in] signal to call on unlang_action(). + * @param[in] uctx to pass to the callbacks. + * @return + * - RLM_MODULE_YIELD if the xlat would perform blocking I/O + * - A return code representing the result of the xla + */ +rlm_rcode_t module_unlang_push_xlat(TALLOC_CTX *ctx, fr_value_box_t **out, + REQUEST *request, xlat_exp_t const *xlat, + fr_unlang_module_resume_t callback, + fr_unlang_module_signal_t signal, void *uctx) +{ + /* + * Push the resumption point + */ + (void) unlang_module_yield(request, callback, signal, uctx); + + /* + * Push the xlat function + */ + xlat_unlang_push(ctx, out, request, xlat, true); + + /* + * Execute the xlat frame we just pushed onto the stack. + */ + return unlang_run(request); +} diff --git a/src/main/unlang_compile.c b/src/main/unlang_compile.c index 5e51e301150..c685bbe10ac 100644 --- a/src/main/unlang_compile.c +++ b/src/main/unlang_compile.c @@ -2157,11 +2157,11 @@ static unlang_t *compile_xlat_inline(unlang_t *parent, unlang_compile_t *unlang_ctx, CONF_PAIR const *cp) { unlang_t *c; - unlang_xlat_inline_t *mx; + xlat_unlang_inline_t *mx; - mx = talloc_zero(parent, unlang_xlat_inline_t); + mx = talloc_zero(parent, xlat_unlang_inline_t); - c = unlang_xlat_inline_to_generic(mx); + c = xlat_unlang_inline_to_generic(mx); c->parent = parent; c->next = NULL; c->name = "expand"; diff --git a/src/main/unlang_interpret.c b/src/main/unlang_interpret.c index da535866c92..318186c2478 100644 --- a/src/main/unlang_interpret.c +++ b/src/main/unlang_interpret.c @@ -105,14 +105,12 @@ unlang_op_t unlang_ops[UNLANG_TYPE_MAX]; * @param[in] request The current request. * @param[in] callback to call on unlang_resumable(). * @param[in] signal call on unlang_action(). - * @param[in] resume_ctx to pass to the callbacks. + * @param[in] rctx to pass to the callbacks. * @return * unlang_resume_t on success * NULL on error */ -static unlang_resume_t *unlang_resume_alloc(REQUEST *request, - void *callback, - fr_unlang_module_signal_t signal, void *resume_ctx) +unlang_resume_t *unlang_resume_alloc(REQUEST *request, void *callback, void *signal, void *rctx) { unlang_resume_t *mr; unlang_stack_t *stack = request->stack; @@ -142,7 +140,7 @@ static unlang_resume_t *unlang_resume_alloc(REQUEST *request, */ mr->callback = callback; mr->signal = signal; - mr->resume_ctx = resume_ctx; + mr->rctx = rctx; /* * Replaces the current stack frame with a RESUME frame. @@ -1117,7 +1115,7 @@ int unlang_event_fd_delete(REQUEST *request, void const *ctx, int fd) * @param[in] request The current request. * @param[in] action to signal. */ -void unlang_signal(REQUEST *request, fr_state_action_t action) +void unlang_signal(REQUEST *request, fr_state_signal_t action) { unlang_stack_frame_t *frame; unlang_stack_t *stack = request->stack; @@ -1139,7 +1137,7 @@ void unlang_signal(REQUEST *request, fr_state_action_t action) */ if (!unlang_ops[mr->parent->type].signal) return; - unlang_ops[mr->parent->type].signal(request, mr->resume_ctx, action); + unlang_ops[mr->parent->type].signal(request, mr->rctx, action); } int unlang_stack_depth(REQUEST *request) @@ -1245,7 +1243,7 @@ void unlang_resumable(REQUEST *request) if (mr->parent->type != UNLANG_TYPE_PARALLEL) goto next; - state = mr->resume_ctx; + state = mr->rctx; /* * Find the child and mark it resumable @@ -1324,7 +1322,7 @@ static unlang_action_t unlang_resume(REQUEST *request, rlm_rcode_t *presult, int * the original frame which was used to * create this resumption frame. */ - action = unlang_ops[mr->parent->type].resume(request, presult, mr->resume_ctx); + action = unlang_ops[mr->parent->type].resume(request, presult, mr->rctx); /* * Leave mr alone, it will be freed when the request is done. @@ -1360,14 +1358,14 @@ static unlang_action_t unlang_resume(REQUEST *request, rlm_rcode_t *presult, int * @param[in] request The current request. * @param[in] callback to call on unlang_resumable(). * @param[in] cancel to call on unlang_action(). - * @param[in] resume_ctx to pass to the callbacks. + * @param[in] rctx to pass to the callbacks. * @return * - RLM_MODULE_YIELD on success. * - RLM_MODULE_FAIL (or asserts) if the current frame is not a module call or * resume frame. */ rlm_rcode_t unlang_module_yield(REQUEST *request, fr_unlang_module_resume_t callback, - fr_unlang_module_signal_t cancel, void *resume_ctx) + fr_unlang_module_signal_t cancel, void *rctx) { unlang_stack_t *stack = request->stack; unlang_stack_frame_t *frame = &stack->frame[stack->depth]; @@ -1377,7 +1375,7 @@ rlm_rcode_t unlang_module_yield(REQUEST *request, fr_unlang_module_resume_t call switch (frame->instruction->type) { case UNLANG_TYPE_MODULE_CALL: - mr = unlang_resume_alloc(request, callback, cancel, resume_ctx); + mr = unlang_resume_alloc(request, callback, cancel, rctx); if (!fr_cond_assert(mr)) { return RLM_MODULE_FAIL; } @@ -1393,7 +1391,7 @@ rlm_rcode_t unlang_module_yield(REQUEST *request, fr_unlang_module_resume_t call */ mr->callback = callback; mr->signal = signal; - mr->resume_ctx = resume_ctx; + mr->rctx = rctx; return RLM_MODULE_YIELD; @@ -1403,61 +1401,6 @@ rlm_rcode_t unlang_module_yield(REQUEST *request, fr_unlang_module_resume_t call } } -/** 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. - * - * @note The module function which calls #unlang_module_yield should return control - * of the C stack to the unlang interpreter immediately after calling #unlang_module_yield. - * A common pattern is to use ``return unlang_module_yield(...)``. - * - * @param[in] request The current request. - * @param[in] callback to call on unlang_resumable(). - * @param[in] signal to call on unlang_action(). - * @param[in] resume_ctx to pass to the callbacks. - * @return always returns RLM_MODULE_YIELD. - */ -xlat_action_t unlang_xlat_yield(REQUEST *request, - xlat_resume_callback_t callback, fr_unlang_module_signal_t signal, - void *resume_ctx) -{ - unlang_stack_t *stack = request->stack; - unlang_stack_frame_t *frame = &stack->frame[stack->depth]; - unlang_resume_t *mr; - - rad_assert(stack->depth > 0); - - switch (frame->instruction->type) { - case UNLANG_TYPE_XLAT: - { - mr = unlang_resume_alloc(request, callback, signal, resume_ctx); - if (!fr_cond_assert(mr)) { - return XLAT_ACTION_FAIL; - } - } - return XLAT_ACTION_YIELD; - - case UNLANG_TYPE_RESUME: - mr = talloc_get_type_abort(frame->instruction, unlang_resume_t); - rad_assert(mr->parent->type == UNLANG_TYPE_XLAT); - - /* - * Re-use the current RESUME frame, but override - * the callbacks and context. - */ - mr->callback = callback; - mr->signal = signal; - mr->resume_ctx = resume_ctx; - return XLAT_ACTION_YIELD; - - default: - rad_assert(0); - return XLAT_ACTION_FAIL; - } -} - /** Get information about the interpreter state * */ diff --git a/src/main/unlang_op.c b/src/main/unlang_op.c index 2c01b061f44..db1560510f7 100644 --- a/src/main/unlang_op.c +++ b/src/main/unlang_op.c @@ -342,58 +342,6 @@ static unlang_action_t unlang_group(REQUEST *request, return UNLANG_ACTION_PUSHED_CHILD; } -/** Allocates and initializes an unlang_resume_t - * - * @param[in] request The current request. - * @param[in] callback to call on unlang_resumable(). - * @param[in] signal call on unlang_action(). - * @param[in] resume_ctx to pass to the callbacks. - * @return - * unlang_resume_t on success - * NULL on error - */ -static unlang_resume_t *unlang_resume_alloc(REQUEST *request, - void *callback, - fr_unlang_module_signal_t signal, void *resume_ctx) -{ - unlang_resume_t *mr; - unlang_stack_t *stack = request->stack; - unlang_stack_frame_t *frame = &stack->frame[stack->depth]; - - mr = talloc_zero(request, unlang_resume_t); - if (!mr) return NULL; - - /* - * Remember the parent. - */ - mr->parent = frame->instruction; - - /* - * Initialize parent ptr, next ptr, name, debug_name, - * type, actions, etc. - */ - memcpy(&mr->self, frame->instruction, sizeof(mr->self)); - - /* - * But note that we're of type RESUME - */ - mr->self.type = UNLANG_TYPE_RESUME; - - /* - * Fill in the signal handlers and resumption ctx - */ - mr->callback = callback; - mr->signal = signal; - mr->resume_ctx = resume_ctx; - - /* - * Replaces the current stack frame with a RESUME frame. - */ - frame->instruction = unlang_resume_to_generic(mr); - - return mr; -} - /** Continue after creating a subrequest. * * Just run some "unlang", but don't do anything else. @@ -409,7 +357,7 @@ static fr_io_final_t unlang_process_continue(REQUEST *request, fr_io_action_t ac * is waiting for something to happen. */ if (action != FR_IO_ACTION_RUN) { - unlang_signal(request, (fr_state_action_t) action); + unlang_signal(request, (fr_state_signal_t) action); return FR_IO_DONE; } @@ -494,7 +442,7 @@ static REQUEST *unlang_child_alloc(REQUEST *request, unlang_t *instruction, rlm_ /** Send a signal from parent request to subrequest * */ -static void unlang_subrequest_signal(UNUSED REQUEST *request, void *ctx, fr_state_action_t action) +static void unlang_subrequest_signal(UNUSED REQUEST *request, void *ctx, fr_state_signal_t action) { REQUEST *child = talloc_get_type_abort(ctx, REQUEST); @@ -505,9 +453,9 @@ static void unlang_subrequest_signal(UNUSED REQUEST *request, void *ctx, fr_stat /** Resume a subrequest * */ -static unlang_action_t unlang_subrequest_resume(UNUSED REQUEST *request, rlm_rcode_t *presult, void *resume_ctx) +static unlang_action_t unlang_subrequest_resume(UNUSED REQUEST *request, rlm_rcode_t *presult, void *rctx) { - REQUEST *child = talloc_get_type_abort(resume_ctx, REQUEST); + REQUEST *child = talloc_get_type_abort(rctx, REQUEST); unlang_stack_t *stack = request->stack; unlang_stack_frame_t *frame; #ifndef NDEBUG @@ -537,7 +485,7 @@ static unlang_action_t unlang_subrequest_resume(UNUSED REQUEST *request, rlm_rco (void) talloc_get_type_abort(mr, unlang_resume_t); rad_assert(mr->callback == NULL); - rad_assert(mr->resume_ctx == child); + rad_assert(mr->rctx == child); #endif /* @@ -1011,7 +959,7 @@ static rlm_rcode_t unlang_parallel_run(REQUEST *request, unlang_parallel_t *stat * stopped. This tells any child modules * to clean up timers, etc. */ - unlang_signal(state->children[i].child, FR_ACTION_DONE); + unlang_signal(state->children[i].child, FR_SIGNAL_DONE); TALLOC_FREE(state->children[i].child); /* FALL-THROUGH */ @@ -1034,10 +982,10 @@ static rlm_rcode_t unlang_parallel_run(REQUEST *request, unlang_parallel_t *stat /** Send a signal from parent request to all of it's children * */ -static void unlang_parallel_signal(UNUSED REQUEST *request, void *resume_ctx, fr_state_action_t action) +static void unlang_parallel_signal(UNUSED REQUEST *request, void *rctx, fr_state_signal_t action) { int i; - unlang_parallel_t *state = talloc_get_type_abort(resume_ctx, unlang_parallel_t); + unlang_parallel_t *state = talloc_get_type_abort(rctx, unlang_parallel_t); /* * Signal all of the children, if they exist. @@ -1057,7 +1005,7 @@ static void unlang_parallel_signal(UNUSED REQUEST *request, void *resume_ctx, fr } } -static void unlang_parallel_resumable(REQUEST *request, UNUSED void *resume_ctx) +static void unlang_parallel_resumable(REQUEST *request, UNUSED void *rctx) { unlang_stack_t *stack; unlang_stack_frame_t *frame; @@ -1089,7 +1037,7 @@ static void unlang_parallel_resumable(REQUEST *request, UNUSED void *resume_ctx) mr = unlang_generic_to_resume(frame->instruction); (void) talloc_get_type_abort(mr, unlang_resume_t); - state = mr->resume_ctx; + state = mr->rctx; /* * Find the child and mark it resumable @@ -1107,9 +1055,9 @@ static void unlang_parallel_resumable(REQUEST *request, UNUSED void *resume_ctx) rad_assert(found); } -static unlang_action_t unlang_parallel_resume(REQUEST *request, rlm_rcode_t *presult, void *resume_ctx) +static unlang_action_t unlang_parallel_resume(REQUEST *request, rlm_rcode_t *presult, void *rctx) { - unlang_parallel_t *state = talloc_get_type_abort(resume_ctx, unlang_parallel_t); + unlang_parallel_t *state = talloc_get_type_abort(rctx, unlang_parallel_t); unlang_stack_t *stack = request->stack; unlang_stack_frame_t *frame = &stack->frame[stack->depth]; @@ -1136,7 +1084,7 @@ static unlang_action_t unlang_parallel_resume(REQUEST *request, rlm_rcode_t *pre (void) talloc_get_type_abort(mr, unlang_resume_t); rad_assert(mr->callback == NULL); - rad_assert(mr->resume_ctx == state); + rad_assert(mr->rctx == state); #endif /* @@ -1667,10 +1615,10 @@ done: * If there is no #fr_unlang_module_signal_t callback defined, the action is ignored. * * @param[in] request The current request. - * @param[in] resume_ctx createed by #unlang_module_call. + * @param[in] rctx createed by #unlang_module_call. * @param[in] action to signal. */ -static void unlang_module_signal(REQUEST *request, void *resume_ctx, fr_state_action_t action) +static void unlang_module_signal(REQUEST *request, void *rctx, fr_state_signal_t action) { unlang_stack_frame_t *frame; unlang_stack_t *stack = request->stack; @@ -1691,10 +1639,10 @@ static void unlang_module_signal(REQUEST *request, void *resume_ctx, fr_state_ac ((fr_unlang_module_signal_t)mr->signal)(request, mc->module_instance->dl_inst->data, ms->thread->data, - resume_ctx, action); + rctx, action); } -static unlang_action_t unlang_module_resume(REQUEST *request, rlm_rcode_t *presult, UNUSED void *resume_ctx) +static unlang_action_t unlang_module_resume(REQUEST *request, rlm_rcode_t *presult, UNUSED void *rctx) { unlang_stack_t *stack = request->stack; unlang_stack_frame_t *frame = &stack->frame[stack->depth]; @@ -1714,7 +1662,7 @@ static unlang_action_t unlang_module_resume(REQUEST *request, rlm_rcode_t *presu safe_lock(mc->module_instance); *presult = request->rcode = ((fr_unlang_module_resume_t)mr->callback)(request, mc->module_instance->dl_inst->data, - ms->thread->data, mr->resume_ctx); + ms->thread->data, mr->rctx); safe_unlock(mc->module_instance); if (*presult != RLM_MODULE_YIELD) ms->thread->active_callers--; diff --git a/src/main/unlang_priv.h b/src/main/unlang_priv.h index b5032a84e97..35f082616a9 100644 --- a/src/main/unlang_priv.h +++ b/src/main/unlang_priv.h @@ -192,6 +192,7 @@ typedef struct { */ typedef struct { unlang_t self; + unlang_t *parent; //!< The original instruction. void *callback; //!< Function the yielding code indicated should @@ -201,7 +202,7 @@ typedef struct { ///< be called if the request is destroyed in ///< the middle of an async operation. - void *resume_ctx; //!< Context data for the callback. Usually represents + void *rctx; //!< Context data for the callback. Usually represents ///< the function's internal state at the time of ///< yielding. } unlang_resume_t; @@ -215,7 +216,7 @@ typedef struct { int exec; char *xlat_name; xlat_exp_t *exp; //!< First xlat node to execute. -} unlang_xlat_inline_t; +} xlat_unlang_inline_t; /** A module stack entry * @@ -341,13 +342,13 @@ static inline unlang_t *unlang_group_to_generic(unlang_group_t *p) return (unlang_t *)p; } -static inline unlang_xlat_inline_t *unlang_generic_to_xlat_inline(unlang_t *p) +static inline xlat_unlang_inline_t *unlang_generic_to_xlat_inline(unlang_t *p) { rad_assert(p->type == UNLANG_TYPE_XLAT_INLINE); - return talloc_get_type_abort(p, unlang_xlat_inline_t); + return talloc_get_type_abort(p, xlat_unlang_inline_t); } -static inline unlang_t *unlang_xlat_inline_to_generic(unlang_xlat_inline_t *p) +static inline unlang_t *xlat_unlang_inline_to_generic(xlat_unlang_inline_t *p) { return (unlang_t *)p; } @@ -371,6 +372,8 @@ void unlang_push(unlang_stack_t *stack, unlang_t *program, rlm_rcode_t result, bool do_next_sibling, bool top_frame); rlm_rcode_t unlang_run(REQUEST *request); +unlang_resume_t *unlang_resume_alloc(REQUEST *request, void *callback, void *signal, void *rctx); + void unlang_op_initialize(void); #ifdef __cplusplus diff --git a/src/main/xlat_eval.c b/src/main/xlat_eval.c index 91e13f45626..a068ea8cd6e 100644 --- a/src/main/xlat_eval.c +++ b/src/main/xlat_eval.c @@ -495,7 +495,7 @@ static const char xlat_spaces[] = " * when it yielded. */ xlat_action_t xlat_frame_eval_resume(TALLOC_CTX *ctx, fr_cursor_t *out, - xlat_resume_callback_t resume, xlat_exp_t const *exp, + xlat_func_resume_t resume, xlat_exp_t const *exp, REQUEST *request, fr_cursor_t *result, void *rctx) { xlat_thread_inst_t *thread_inst = xlat_thread_instance_find(exp); diff --git a/src/main/xlat_priv.h b/src/main/xlat_priv.h index 9693b2eaba5..986b0adb3b2 100644 --- a/src/main/xlat_priv.h +++ b/src/main/xlat_priv.h @@ -153,7 +153,7 @@ xlat_t *xlat_func_find(char const *name); * xlat_eval.c */ xlat_action_t xlat_frame_eval_resume(TALLOC_CTX *ctx, fr_cursor_t *out, - xlat_resume_callback_t resume, xlat_exp_t const *exp, + xlat_func_resume_t resume, xlat_exp_t const *exp, REQUEST *request, fr_cursor_t *result, void *rctx); xlat_action_t xlat_frame_eval_repeat(TALLOC_CTX *ctx, fr_cursor_t *out, diff --git a/src/main/xlat_unlang.c b/src/main/xlat_unlang.c index b8c265772b9..fecfb579a7f 100644 --- a/src/main/xlat_unlang.c +++ b/src/main/xlat_unlang.c @@ -89,8 +89,8 @@ static unlang_t xlat_instruction = { * @param[in] top_frame Set to UNLANG_TOP_FRAME if this is the shallowest nesting level. * Set to UNLANG_SUB_FRAME if this is a nested expansion. */ -static void unlang_push_xlat(TALLOC_CTX *ctx, fr_value_box_t **out, - REQUEST *request, xlat_exp_t const *exp, bool top_frame) +void xlat_unlang_push(TALLOC_CTX *ctx, fr_value_box_t **out, + REQUEST *request, xlat_exp_t const *exp, bool top_frame) { unlang_stack_state_xlat_t *state; @@ -114,59 +114,12 @@ static void unlang_push_xlat(TALLOC_CTX *ctx, fr_value_box_t **out, state->ctx = ctx; } -/** 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 exectuion. - * - * @param[in] ctx To allocate value boxes and values in. - * @param[out] out Where to write the result of the expansion. - * @param[in] request The current request. - * @param[in] xlat to evaluate. - * @param[in] callback to call on unlang_resumable(). - * @param[in] signal to call on unlang_action(). - * @param[in] uctx to pass to the callbacks. - * @return - * - RLM_MODULE_YIELD if the xlat would perform blocking I/O - * - A return code representing the result of the xla - */ -rlm_rcode_t unlang_push_module_xlat(TALLOC_CTX *ctx, fr_value_box_t **out, - REQUEST *request, xlat_exp_t const *xlat, - fr_unlang_module_resume_t callback, - fr_unlang_module_signal_t signal, void *uctx) -{ - /* - * Push the resumption point - */ - (void) unlang_module_yield(request, callback, signal, uctx); - - /* - * Push the xlat function - */ - unlang_push_xlat(ctx, out, request, xlat, true); - - /* - * Execute the xlat frame we just pushed onto the stack. - */ - return unlang_run(request); -} - /** Stub function for calling the xlat interpreter * * Calls the xlat interpreter and translates its wants and needs into * unlang_action_t codes. */ -static unlang_action_t unlang_xlat(REQUEST *request, +static unlang_action_t xlat_unlang(REQUEST *request, rlm_rcode_t *presult, UNUSED int *priority) { unlang_stack_t *stack = request->stack; @@ -177,10 +130,8 @@ static unlang_action_t unlang_xlat(REQUEST *request, if (frame->repeat) { fr_cursor_init(&xs->result, &xs->rhead); - xa = xlat_frame_eval_repeat(xs->ctx, &xs->values, - &child, &xs->alternate, - request, &xs->exp, - &xs->result); + xa = xlat_frame_eval_repeat(xs->ctx, &xs->values, &child, + &xs->alternate, request, &xs->exp, &xs->result); } else { xa = xlat_frame_eval(xs->ctx, &xs->values, &child, request, &xs->exp); } @@ -190,7 +141,7 @@ static unlang_action_t unlang_xlat(REQUEST *request, rad_assert(child); frame->repeat = true; - unlang_push_xlat(xs->ctx, &xs->rhead, request, child, false); + xlat_unlang_push(xs->ctx, &xs->rhead, request, child, false); return UNLANG_ACTION_PUSHED_CHILD; case XLAT_ACTION_YIELD: @@ -208,6 +159,61 @@ static unlang_action_t unlang_xlat(REQUEST *request, return UNLANG_ACTION_CALCULATE_RESULT; } +/** 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. + * + * @note The module function which calls #unlang_module_yield should return control + * of the C stack to the unlang interpreter immediately after calling #unlang_module_yield. + * A common pattern is to use ``return unlang_module_yield(...)``. + * + * @param[in] request The current request. + * @param[in] callback to call on unlang_resumable(). + * @param[in] signal to call on unlang_action(). + * @param[in] rctx to pass to the callbacks. + * @return always returns RLM_MODULE_YIELD. + */ +xlat_action_t xlat_unlang_yield(REQUEST *request, + xlat_func_resume_t callback, xlat_func_signal_t signal, + void *rctx) +{ + unlang_stack_t *stack = request->stack; + unlang_stack_frame_t *frame = &stack->frame[stack->depth]; + unlang_resume_t *mr; + + rad_assert(stack->depth > 0); + + switch (frame->instruction->type) { + case UNLANG_TYPE_XLAT: + { + mr = unlang_resume_alloc(request, callback, signal, rctx); + if (!fr_cond_assert(mr)) { + return XLAT_ACTION_FAIL; + } + } + return XLAT_ACTION_YIELD; + + case UNLANG_TYPE_RESUME: + mr = talloc_get_type_abort(frame->instruction, unlang_resume_t); + rad_assert(mr->parent->type == UNLANG_TYPE_XLAT); + + /* + * Re-use the current RESUME frame, but override + * the callbacks and context. + */ + mr->callback = callback; + mr->signal = signal; + mr->rctx = rctx; + return XLAT_ACTION_YIELD; + + default: + rad_assert(0); + return XLAT_ACTION_FAIL; + } +} + /** Called when we're ready to resume processing the request * * @param[in] request to resume processing. @@ -216,12 +222,12 @@ static unlang_action_t unlang_xlat(REQUEST *request, * - RLM_MODULE_FAIL on failure. * - RLM_MODULE_YIELD if additional asynchronous operations * need to be performed. - * @param[in] resume_ctx provided by xlat function. + * @param[in] rctx provided by xlat function. * @return * - UNLANG_ACTION_YIELD if yielding. * - UNLANG_ACTION_CALCULATE_RESULT if done. */ -static unlang_action_t unlang_xlat_resume(REQUEST *request, rlm_rcode_t *presult, void *resume_ctx) +static unlang_action_t xlat_unlang_resume(REQUEST *request, rlm_rcode_t *presult, void *rctx) { unlang_stack_t *stack = request->stack; unlang_stack_frame_t *frame = &stack->frame[stack->depth]; @@ -230,7 +236,7 @@ static unlang_action_t unlang_xlat_resume(REQUEST *request, rlm_rcode_t *presult unlang_stack_state_xlat_t *xs = talloc_get_type_abort(frame->state, unlang_stack_state_xlat_t); xlat_action_t xa; - xa = xlat_frame_eval_resume(xs->ctx, &xs->values, mr->callback, xs->exp, request, &xs->result, resume_ctx); + xa = xlat_frame_eval_resume(xs->ctx, &xs->values, mr->callback, xs->exp, request, &xs->result, rctx); switch (xa) { case XLAT_ACTION_YIELD: *presult = RLM_MODULE_YIELD; @@ -258,13 +264,13 @@ static unlang_action_t unlang_xlat_resume(REQUEST *request, rlm_rcode_t *presult /** Evaluates "naked" xlats in the config * */ -static unlang_action_t unlang_xlat_inline(REQUEST *request, +static unlang_action_t xlat_unlang_inline(REQUEST *request, UNUSED rlm_rcode_t *presult, UNUSED int *priority) { unlang_stack_t *stack = request->stack; unlang_stack_frame_t *frame = &stack->frame[stack->depth]; unlang_t *instruction = frame->instruction; - unlang_xlat_inline_t *mx = unlang_generic_to_xlat_inline(instruction); + xlat_unlang_inline_t *mx = unlang_generic_to_xlat_inline(instruction); if (!mx->exec) { TALLOC_CTX *pool; @@ -273,7 +279,7 @@ static unlang_action_t unlang_xlat_inline(REQUEST *request, MEM(frame->state = state = talloc_zero(stack, unlang_stack_state_xlat_inline_t)); MEM(pool = talloc_pool(frame->state, 1024)); /* Pool to absorb some allocs */ - unlang_push_xlat(pool, &state->result, request, mx->exp, false); + xlat_unlang_push(pool, &state->result, request, mx->exp, false); return UNLANG_ACTION_PUSHED_CHILD; } else { RDEBUG("`%s`", mx->xlat_name); @@ -291,8 +297,8 @@ void xlat_unlang_init(void) unlang_op_register(UNLANG_TYPE_XLAT, &(unlang_op_t){ .name = "xlat_eval", - .func = unlang_xlat, - .resume = unlang_xlat_resume, + .func = xlat_unlang, + .resume = xlat_unlang_resume, .debug_braces = false }); @@ -300,7 +306,7 @@ void xlat_unlang_init(void) unlang_op_register(UNLANG_TYPE_XLAT_INLINE, &(unlang_op_t){ .name = "xlat_inline", - .func = unlang_xlat_inline, + .func = xlat_unlang_inline, .debug_braces = false }); } diff --git a/src/modules/proto_detail/proto_detail_process.c b/src/modules/proto_detail/proto_detail_process.c index bdf79d48dba..8e1c0cb4667 100644 --- a/src/modules/proto_detail/proto_detail_process.c +++ b/src/modules/proto_detail/proto_detail_process.c @@ -48,7 +48,7 @@ static fr_io_final_t mod_process(REQUEST *request, fr_io_action_t action) * is waiting for something to happen. */ if (action != FR_IO_ACTION_RUN) { - unlang_signal(request, (fr_state_action_t) action); + unlang_signal(request, (fr_state_signal_t) action); return FR_IO_DONE; } diff --git a/src/modules/proto_ldap_sync/proto_ldap_sync.c b/src/modules/proto_ldap_sync/proto_ldap_sync.c index 9aaee0f4cb1..6d17a379531 100644 --- a/src/modules/proto_ldap_sync/proto_ldap_sync.c +++ b/src/modules/proto_ldap_sync/proto_ldap_sync.c @@ -300,7 +300,7 @@ static void proto_ldap_packet_debug(REQUEST *request, RADIUS_PACKET *packet, boo * @param[in] action If something has signalled that the request should stop * being processed. */ -static void request_running(REQUEST *request, fr_state_action_t action) +static void request_running(REQUEST *request, fr_state_signal_t action) { CONF_SECTION *unlang; char const *verb; @@ -312,12 +312,12 @@ static void request_running(REQUEST *request, fr_state_action_t action) /* * Async (in the same thread, tho) signal to be done. */ - if (action == FR_ACTION_DONE) goto done; + if (action == FR_SIGNAL_DONE) goto done; /* * We ignore all other actions. */ - if (action != FR_ACTION_RUN) return; + if (action != FR_SIGNAL_RUN) return; switch (request->request_state) { case REQUEST_INIT: @@ -418,17 +418,17 @@ static void request_running(REQUEST *request, fr_state_action_t action) * @param[in] action If something has signalled that the request should stop * being processed. */ -static void request_queued(REQUEST *request, fr_state_action_t action) +static void request_queued(REQUEST *request, fr_state_signal_t action) { REQUEST_VERIFY(request); switch (action) { - case FR_ACTION_RUN: + case FR_SIGNAL_RUN: request->process = request_running; request->process(request, action); break; - case FR_ACTION_DONE: + case FR_SIGNAL_DONE: (void) fr_heap_extract(request->backlog, request); request_delete(request); break; diff --git a/src/modules/proto_radius/proto_radius_acct.c b/src/modules/proto_radius/proto_radius_acct.c index ba5e9d5c82c..d725ebb3b87 100644 --- a/src/modules/proto_radius/proto_radius_acct.c +++ b/src/modules/proto_radius/proto_radius_acct.c @@ -45,7 +45,7 @@ static fr_io_final_t mod_process(REQUEST *request, fr_io_action_t action) * is waiting for something to happen. */ if (action != FR_IO_ACTION_RUN) { - unlang_signal(request, (fr_state_action_t) action); + unlang_signal(request, (fr_state_signal_t) action); return FR_IO_DONE; } diff --git a/src/modules/proto_radius/proto_radius_auth.c b/src/modules/proto_radius/proto_radius_auth.c index 0c73b915e61..aeacf54ae75 100644 --- a/src/modules/proto_radius/proto_radius_auth.c +++ b/src/modules/proto_radius/proto_radius_auth.c @@ -132,7 +132,7 @@ static fr_io_final_t mod_process(REQUEST *request, fr_io_action_t action) * is waiting for something to happen. */ if (action != FR_IO_ACTION_RUN) { - unlang_signal(request, (fr_state_action_t) action); + unlang_signal(request, (fr_state_signal_t) action); return FR_IO_DONE; } diff --git a/src/modules/proto_radius/proto_radius_coa.c b/src/modules/proto_radius/proto_radius_coa.c index 98a6bd6da22..2793c2f3f3a 100644 --- a/src/modules/proto_radius/proto_radius_coa.c +++ b/src/modules/proto_radius/proto_radius_coa.c @@ -44,7 +44,7 @@ static fr_io_final_t mod_process(REQUEST *request, fr_io_action_t action) * is waiting for something to happen. */ if (action != FR_IO_ACTION_RUN) { - unlang_signal(request, (fr_state_action_t) action); + unlang_signal(request, (fr_state_signal_t) action); return FR_IO_DONE; } diff --git a/src/modules/proto_radius/proto_radius_dynamic_client.c b/src/modules/proto_radius/proto_radius_dynamic_client.c index 41e27c3a532..d0ad96b85d6 100644 --- a/src/modules/proto_radius/proto_radius_dynamic_client.c +++ b/src/modules/proto_radius/proto_radius_dynamic_client.c @@ -41,7 +41,7 @@ static fr_io_final_t mod_process(REQUEST *request, fr_io_action_t action) * is waiting for something to happen. */ if (action != FR_IO_ACTION_RUN) { - unlang_signal(request, (fr_state_action_t) action); + unlang_signal(request, (fr_state_signal_t) action); return FR_IO_DONE; } diff --git a/src/modules/proto_radius/proto_radius_status.c b/src/modules/proto_radius/proto_radius_status.c index b396a2aa375..8b9317329e0 100644 --- a/src/modules/proto_radius/proto_radius_status.c +++ b/src/modules/proto_radius/proto_radius_status.c @@ -44,7 +44,7 @@ static fr_io_final_t mod_process(REQUEST *request, fr_io_action_t action) * is waiting for something to happen. */ if (action != FR_IO_ACTION_RUN) { - unlang_signal(request, (fr_state_action_t) action); + unlang_signal(request, (fr_state_signal_t) action); return FR_IO_DONE; } diff --git a/src/modules/proto_tacacs/proto_tacacs.c b/src/modules/proto_tacacs/proto_tacacs.c index e4d5a68c5e7..c87aad70eb9 100644 --- a/src/modules/proto_tacacs/proto_tacacs.c +++ b/src/modules/proto_tacacs/proto_tacacs.c @@ -146,7 +146,7 @@ static void state_add(REQUEST *request, RADIUS_PACKET *packet) fr_pair_add(&packet->vps, vp); } -static void tacacs_running(REQUEST *request, fr_state_action_t action) +static void tacacs_running(REQUEST *request, fr_state_signal_t action) { rlm_rcode_t rcode; CONF_SECTION *unlang; @@ -159,7 +159,7 @@ static void tacacs_running(REQUEST *request, fr_state_action_t action) REQUEST_VERIFY(request); switch (action) { - case FR_ACTION_DONE: + case FR_SIGNAL_DONE: goto done; default: @@ -417,17 +417,17 @@ done: } } -static void tacacs_queued(REQUEST *request, fr_state_action_t action) +static void tacacs_queued(REQUEST *request, fr_state_signal_t action) { REQUEST_VERIFY(request); switch (action) { - case FR_ACTION_RUN: + case FR_SIGNAL_RUN: request->process = tacacs_running; request->process(request, action); break; - case FR_ACTION_DONE: + case FR_SIGNAL_DONE: (void) fr_heap_extract(request->backlog, request); request_delete(request); break; diff --git a/src/modules/rlm_delay/rlm_delay.c b/src/modules/rlm_delay/rlm_delay.c index 91482d70a32..b8ff6b18532 100644 --- a/src/modules/rlm_delay/rlm_delay.c +++ b/src/modules/rlm_delay/rlm_delay.c @@ -144,9 +144,9 @@ static rlm_rcode_t delay_add(rlm_delay_t const *inst, REQUEST *request) } static void delay_cancel(REQUEST *request, UNUSED void *instance, UNUSED void *thread, void *ctx, - fr_state_action_t action) + fr_state_signal_t action) { - if (action != FR_ACTION_DONE) return; + if (action != FR_SIGNAL_DONE) return; RDEBUG2("Cancelling delay"); diff --git a/src/modules/rlm_radius/rlm_radius.c b/src/modules/rlm_radius/rlm_radius.c index 85233e14d34..44a30d90c18 100644 --- a/src/modules/rlm_radius/rlm_radius.c +++ b/src/modules/rlm_radius/rlm_radius.c @@ -377,7 +377,7 @@ static int mod_link_free(rlm_radius_link_t *link) } static void mod_radius_signal(REQUEST *request, void *instance, void *thread, void *ctx, - fr_state_action_t action) + fr_state_signal_t action) { rlm_radius_t const *inst = talloc_get_type_abort_const(instance, rlm_radius_t); rlm_radius_thread_t *t = talloc_get_type_abort(thread, rlm_radius_thread_t); @@ -392,7 +392,7 @@ static void mod_radius_signal(REQUEST *request, void *instance, void *thread, vo * the IO modules to do additional debugging if * necessary. */ - if (action == FR_ACTION_DONE) { + if (action == FR_SIGNAL_DONE) { talloc_free(link); return; } @@ -402,7 +402,7 @@ static void mod_radius_signal(REQUEST *request, void *instance, void *thread, vo * synchronous proxying. Ignore the dup, and rely on the * IO submodule to time it's own retransmissions. */ - if ((action == FR_ACTION_DUP) && !inst->synchronous) return; + if ((action == FR_SIGNAL_DUP) && !inst->synchronous) return; if (!inst->io->signal) return; diff --git a/src/modules/rlm_radius/rlm_radius.h b/src/modules/rlm_radius/rlm_radius.h index 6fbee1cddd3..62a072abaa1 100644 --- a/src/modules/rlm_radius/rlm_radius.h +++ b/src/modules/rlm_radius/rlm_radius.h @@ -53,7 +53,7 @@ typedef struct rlm_radius_link_t rlm_radius_link_t; * */ typedef rlm_rcode_t (*fr_radius_io_push_t)(void *instance, REQUEST *request, rlm_radius_link_t *link, void *thread); -typedef void (*fr_radius_io_signal_t)(REQUEST *request, void *instance, void *thread, rlm_radius_link_t *link, fr_state_action_t action); +typedef void (*fr_radius_io_signal_t)(REQUEST *request, void *instance, void *thread, rlm_radius_link_t *link, fr_state_signal_t action); typedef int (*fr_radius_io_instantiate_t)(rlm_radius_t *inst, void *io_instance, CONF_SECTION *cs); diff --git a/src/modules/rlm_radius/rlm_radius_udp.c b/src/modules/rlm_radius/rlm_radius_udp.c index 2af8083ad80..e32f1959593 100644 --- a/src/modules/rlm_radius/rlm_radius_udp.c +++ b/src/modules/rlm_radius/rlm_radius_udp.c @@ -2470,12 +2470,12 @@ static rlm_rcode_t mod_push(void *instance, REQUEST *request, rlm_radius_link_t } -static void mod_signal(REQUEST *request, UNUSED void *instance, UNUSED void *thread, rlm_radius_link_t *link, fr_state_action_t action) +static void mod_signal(REQUEST *request, UNUSED void *instance, UNUSED void *thread, rlm_radius_link_t *link, fr_state_signal_t action) { rlm_radius_udp_request_t *u = link->request_io_ctx; struct timeval now; - if (action != FR_ACTION_DUP) return; + if (action != FR_SIGNAL_DUP) return; /* * Sychronous mode means that we don't do any diff --git a/src/modules/rlm_rest/io.c b/src/modules/rlm_rest/io.c index f8aec4828e6..ab22a61d455 100644 --- a/src/modules/rlm_rest/io.c +++ b/src/modules/rlm_rest/io.c @@ -324,7 +324,7 @@ static int _rest_io_event_modify(UNUSED CURL *easy, curl_socket_t fd, int what, /** Handle asynchronous cancellation of a request * - * If we're signalled that the request has been cancelled (FR_ACTION_DONE). + * If we're signalled that the request has been cancelled (FR_SIGNAL_DONE). * Cleanup any pending state and release the connection handle back into the pool. * * @param[in] request being cancelled. @@ -333,13 +333,13 @@ static int _rest_io_event_modify(UNUSED CURL *easy, curl_socket_t fd, int what, * @param[in] ctx rlm_rest_handle_t currently used by the request. * @param[in] action What happened. */ -void rest_io_action(REQUEST *request, void *instance, void *thread, void *ctx, fr_state_action_t action) +void rest_io_action(REQUEST *request, void *instance, void *thread, void *ctx, fr_state_signal_t action) { rlm_rest_handle_t *randle = talloc_get_type_abort(ctx, rlm_rest_handle_t); rlm_rest_thread_t *t = thread; CURLMcode ret; - if (action != FR_ACTION_DONE) return; + if (action != FR_SIGNAL_DONE) return; RDEBUG("Forcefully cancelling pending REST request"); diff --git a/src/modules/rlm_rest/rest.h b/src/modules/rlm_rest/rest.h index f47e48c6f67..4b2248dbff0 100644 --- a/src/modules/rlm_rest/rest.h +++ b/src/modules/rlm_rest/rest.h @@ -304,7 +304,7 @@ ssize_t rest_uri_host_unescape(char **out, UNUSED rlm_rest_t const *mod_inst, RE /* * Async IO helpers */ -void rest_io_action(REQUEST *request, void *instance, void *thread, void *ctx, fr_state_action_t action); +void rest_io_action(REQUEST *request, void *instance, void *thread, void *ctx, fr_state_signal_t action); int rest_io_request_enqueue(rlm_rest_thread_t *thread, REQUEST *request, void *handle); int rest_io_init(rlm_rest_thread_t *thread); diff --git a/src/modules/rlm_rest/rlm_rest.c b/src/modules/rlm_rest/rlm_rest.c index 402d069989a..1d432cca6d9 100644 --- a/src/modules/rlm_rest/rlm_rest.c +++ b/src/modules/rlm_rest/rlm_rest.c @@ -373,7 +373,7 @@ static xlat_action_t rest_xlat(UNUSED TALLOC_CTX *ctx, UNUSED fr_cursor_t *out, ret = rest_io_request_enqueue(t, request, handle); if (ret < 0) goto error; - return unlang_xlat_yield(request, rest_xlat_resume, NULL, rctx); + return xlat_unlang_yield(request, rest_xlat_resume, NULL, rctx); } static rlm_rcode_t mod_authorize_result(REQUEST *request, void *instance, void *thread, void *ctx)