From: Arran Cudbard-Bell Date: Sun, 11 May 2025 21:34:28 +0000 (-0600) Subject: Pass arguments to push functions in a structure X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=65bfa1606a2fe247a0ca9e6c4f3b2479feca3224;p=thirdparty%2Ffreeradius-server.git Pass arguments to push functions in a structure Makes it easier to add or remove args --- diff --git a/src/lib/unlang/call.c b/src/lib/unlang/call.c index d72b057d199..04d8b200c6c 100644 --- a/src/lib/unlang/call.c +++ b/src/lib/unlang/call.c @@ -208,7 +208,7 @@ unlang_action_t unlang_call_push(request_t *request, CONF_SECTION *server_cs, bo * Push a new call frame onto the stack */ if (unlang_interpret_push(request, unlang_call_to_generic(c), - RLM_MODULE_NOT_SET, UNLANG_NEXT_STOP, top_frame) < 0) { + FRAME_CONF(RLM_MODULE_NOT_SET, top_frame), UNLANG_NEXT_STOP) < 0) { talloc_free(c); return UNLANG_ACTION_FAIL; } diff --git a/src/lib/unlang/child_request.c b/src/lib/unlang/child_request.c index c68c09a706e..f2e6e11aed6 100644 --- a/src/lib/unlang/child_request.c +++ b/src/lib/unlang/child_request.c @@ -231,7 +231,8 @@ static int unlang_child_request_stack_init(unlang_child_request_t *cr) }; /* Sets up the frame for us to use immediately */ - if (unlikely(unlang_interpret_push_instruction(child, &inform_parent, RLM_MODULE_NOOP, true) < 0)) { + if (unlikely(unlang_interpret_push_instruction(child, &inform_parent, + FRAME_CONF(RLM_MODULE_NOOP, true)) < 0)) { return -1; } diff --git a/src/lib/unlang/edit.c b/src/lib/unlang/edit.c index 8f16b476375..10232f0b707 100644 --- a/src/lib/unlang/edit.c +++ b/src/lib/unlang/edit.c @@ -1748,7 +1748,7 @@ int unlang_edit_push(request_t *request, bool *success, fr_edit_list_t *el, map_ * Push a new edit frame onto the stack */ if (unlang_interpret_push(request, unlang_edit_to_generic(edit), - RLM_MODULE_NOT_SET, UNLANG_NEXT_STOP, false) < 0) return -1; + FRAME_CONF(RLM_MODULE_NOT_SET, UNLANG_SUB_FRAME), UNLANG_NEXT_STOP) < 0) return -1; frame = &stack->frame[stack->depth]; state = talloc_get_type_abort(frame->state, unlang_frame_state_edit_t); diff --git a/src/lib/unlang/finally.c b/src/lib/unlang/finally.c index f172e99b72d..49f3c6209ce 100644 --- a/src/lib/unlang/finally.c +++ b/src/lib/unlang/finally.c @@ -71,7 +71,8 @@ static unlang_action_t unlang_finally(UNUSED rlm_rcode_t *p_result, request_t *r } } - if (unlikely(unlang_interpret_push_instruction(request, state->instruction, RLM_MODULE_NOOP, UNLANG_SUB_FRAME) < 0)) { + if (unlikely(unlang_interpret_push_instruction(request, state->instruction, + FRAME_CONF(RLM_MODULE_NOOP, UNLANG_SUB_FRAME)) < 0)) { unlang_interpret_signal(request, FR_SIGNAL_CANCEL); /* also stops the request and does cleanups */ } @@ -139,7 +140,7 @@ int unlang_finally_push_instruction(request_t *request, void *instruction, fr_ti * timer expires. */ if (unlang_interpret_push(request, &finally_instruction, - RLM_MODULE_NOT_SET, UNLANG_NEXT_STOP, top_frame) < 0) return -1; + FRAME_CONF(RLM_MODULE_NOT_SET, top_frame), UNLANG_NEXT_STOP) < 0) return -1; frame = &stack->frame[stack->depth]; /* diff --git a/src/lib/unlang/function.c b/src/lib/unlang/function.c index f7a69698234..3467f3ba832 100644 --- a/src/lib/unlang/function.c +++ b/src/lib/unlang/function.c @@ -295,7 +295,7 @@ unlang_action_t _unlang_function_push(request_t *request, * Push module's function */ if (unlang_interpret_push(request, &function_instruction, - RLM_MODULE_NOOP, UNLANG_NEXT_STOP, top_frame) < 0) return UNLANG_ACTION_FAIL; + FRAME_CONF(RLM_MODULE_NOOP, top_frame), UNLANG_NEXT_STOP) < 0) return UNLANG_ACTION_FAIL; frame = &stack->frame[stack->depth]; diff --git a/src/lib/unlang/interpret.c b/src/lib/unlang/interpret.c index 28a76f345c4..52d50dfd77d 100644 --- a/src/lib/unlang/interpret.c +++ b/src/lib/unlang/interpret.c @@ -260,7 +260,7 @@ unlang_action_t unlang_interpret_push_children(UNUSED rlm_rcode_t *p_result, req return UNLANG_ACTION_EXECUTE_NEXT; } - if (unlang_interpret_push(request, g->children, default_rcode, do_next_sibling, UNLANG_SUB_FRAME) < 0) { + if (unlang_interpret_push(request, g->children, FRAME_CONF(default_rcode, UNLANG_SUB_FRAME), do_next_sibling) < 0) { return UNLANG_ACTION_STOP_PROCESSING; } @@ -971,7 +971,7 @@ static unlang_group_t empty_group = { /** Push a configuration section onto the request stack for later interpretation. * */ -int unlang_interpret_push_section(request_t *request, CONF_SECTION *cs, rlm_rcode_t default_rcode, bool top_frame) +int unlang_interpret_push_section(request_t *request, CONF_SECTION *cs, unlang_frame_conf_t const *conf) { unlang_t *instruction = NULL; @@ -988,13 +988,13 @@ int unlang_interpret_push_section(request_t *request, CONF_SECTION *cs, rlm_rcod } } - return unlang_interpret_push_instruction(request, instruction, default_rcode, top_frame); + return unlang_interpret_push_instruction(request, instruction, conf); } /** Push an instruction onto the request stack for later interpretation. * */ -int unlang_interpret_push_instruction(request_t *request, void *instruction, rlm_rcode_t default_rcode, bool top_frame) +int unlang_interpret_push_instruction(request_t *request, void *instruction, unlang_frame_conf_t const *conf) { unlang_stack_t *stack = request->stack; @@ -1006,8 +1006,7 @@ int unlang_interpret_push_instruction(request_t *request, void *instruction, rlm * Push the default action, and the instruction which has * no action. */ - if (unlang_interpret_push(request, - instruction, default_rcode, UNLANG_NEXT_SIBLING, top_frame) < 0) { + if (unlang_interpret_push(request, instruction, conf, UNLANG_NEXT_SIBLING) < 0) { return -1; } diff --git a/src/lib/unlang/interpret.h b/src/lib/unlang/interpret.h index 676652643c5..012dd33949e 100644 --- a/src/lib/unlang/interpret.h +++ b/src/lib/unlang/interpret.h @@ -129,12 +129,27 @@ typedef struct { ///< runnable queue. } unlang_request_func_t; -int unlang_interpret_push_section(request_t *request, CONF_SECTION *cs, - rlm_rcode_t default_action, bool top_frame) +/** Configuration structure to make it easier to pass configuration options to initialise the frame with + */ +typedef struct { + bool top_frame; //!< Is this the top frame? + bool no_rcode; //!< Don't set the rcode when the frame is popped. + rlm_rcode_t default_rcode; //!< The default return code for the frame. + unlang_mod_action_t default_priority; //!< The default priority for the frame. +} unlang_frame_conf_t; + +#define FRAME_CONF(_default_rcode, _top_frame) \ + &(unlang_frame_conf_t){ \ + .top_frame = (_top_frame), \ + .no_rcode = false, \ + .default_rcode = (_default_rcode), \ + .default_priority = MOD_ACTION_NOT_SET \ + } + +int unlang_interpret_push_section(request_t *request, CONF_SECTION *cs, unlang_frame_conf_t const *conf) CC_HINT(warn_unused_result); -int unlang_interpret_push_instruction(request_t *request, void *instruction, - rlm_rcode_t default_rcode, bool top_frame) +int unlang_interpret_push_instruction(request_t *request, void *instruction, unlang_frame_conf_t const *conf) CC_HINT(warn_unused_result); unlang_interpret_t *unlang_interpret_init(TALLOC_CTX *ctx, diff --git a/src/lib/unlang/load_balance.c b/src/lib/unlang/load_balance.c index 68fb0028a7f..e3f49565a6f 100644 --- a/src/lib/unlang/load_balance.c +++ b/src/lib/unlang/load_balance.c @@ -82,7 +82,7 @@ static unlang_action_t unlang_load_balance_next(rlm_rcode_t *p_result, request_t /* * Push the child, and yield for a later return. */ - if (unlang_interpret_push(request, redundant->child, RLM_MODULE_NOT_SET, UNLANG_NEXT_STOP, UNLANG_SUB_FRAME) < 0) { + if (unlang_interpret_push(request, redundant->child, FRAME_CONF(RLM_MODULE_NOT_SET, UNLANG_SUB_FRAME), UNLANG_NEXT_STOP) < 0) { return UNLANG_ACTION_STOP_PROCESSING; } @@ -229,7 +229,7 @@ static unlang_action_t unlang_load_balance(rlm_rcode_t *p_result, request_t *req */ if (frame->instruction->type == UNLANG_TYPE_LOAD_BALANCE) { if (unlang_interpret_push(request, redundant->found, - RLM_MODULE_NOT_SET, UNLANG_NEXT_STOP, UNLANG_SUB_FRAME) < 0) { + FRAME_CONF(RLM_MODULE_NOT_SET, UNLANG_SUB_FRAME), UNLANG_NEXT_STOP) < 0) { return UNLANG_ACTION_STOP_PROCESSING; } return UNLANG_ACTION_PUSHED_CHILD; diff --git a/src/lib/unlang/module.c b/src/lib/unlang/module.c index 05f2c0d9811..8fe8ae0e266 100644 --- a/src/lib/unlang/module.c +++ b/src/lib/unlang/module.c @@ -95,7 +95,7 @@ int unlang_module_push(rlm_rcode_t *p_result, request_t *request, * Push a new module frame onto the stack */ if (unlang_interpret_push(request, unlang_module_to_generic(mc), - RLM_MODULE_NOT_SET, UNLANG_NEXT_STOP, top_frame) < 0) { + FRAME_CONF(RLM_MODULE_NOT_SET, top_frame), UNLANG_NEXT_STOP) < 0) { return -1; } @@ -280,7 +280,7 @@ unlang_action_t unlang_module_yield_to_section(rlm_rcode_t *p_result, (void) unlang_module_yield(request, resume, signal, sigmask, rctx); if (unlang_interpret_push_section(request, subcs, - default_rcode, UNLANG_SUB_FRAME) < 0) return UNLANG_ACTION_STOP_PROCESSING; + FRAME_CONF(default_rcode, UNLANG_SUB_FRAME)) < 0) return UNLANG_ACTION_STOP_PROCESSING; return UNLANG_ACTION_PUSHED_CHILD; } diff --git a/src/lib/unlang/parallel.c b/src/lib/unlang/parallel.c index 62269bcc77b..b3d29d58c78 100644 --- a/src/lib/unlang/parallel.c +++ b/src/lib/unlang/parallel.c @@ -311,9 +311,9 @@ static unlang_action_t unlang_parallel(rlm_rcode_t *p_result, request_t *request * subsection within the parallel block. */ if (unlang_interpret_push(child, - instruction, RLM_MODULE_FAIL, - UNLANG_NEXT_STOP, - state->detach ? UNLANG_TOP_FRAME : UNLANG_SUB_FRAME) < 0) goto error; + instruction, + FRAME_CONF(RLM_MODULE_FAIL, state->detach ? UNLANG_TOP_FRAME : UNLANG_SUB_FRAME), + UNLANG_NEXT_STOP) < 0) goto error; } /* diff --git a/src/lib/unlang/subrequest.c b/src/lib/unlang/subrequest.c index 5fcb1745109..da7a9521b15 100644 --- a/src/lib/unlang/subrequest.c +++ b/src/lib/unlang/subrequest.c @@ -267,8 +267,9 @@ static unlang_action_t unlang_subrequest_init(rlm_rcode_t *p_result, request_t * * Push the first instruction the child's * going to run. */ - if (unlang_interpret_push(child, g->children, RLM_MODULE_NOT_SET, - UNLANG_NEXT_SIBLING, UNLANG_SUB_FRAME) < 0) goto fail; + if (unlang_interpret_push(child, g->children, + FRAME_CONF(RLM_MODULE_NOT_SET, UNLANG_SUB_FRAME), + UNLANG_NEXT_SIBLING) < 0) goto fail; /* * Finally, setup the function that will be @@ -466,7 +467,7 @@ int unlang_subrequest_child_push(request_t *child, * completed. */ if (unlang_interpret_push(child->parent, &subrequest_instruction, - RLM_MODULE_NOT_SET, UNLANG_NEXT_STOP, top_frame) < 0) { + FRAME_CONF(RLM_MODULE_NOT_SET, top_frame), UNLANG_NEXT_STOP) < 0) { return -1; } diff --git a/src/lib/unlang/switch.c b/src/lib/unlang/switch.c index 2d1739eee36..3ed00e6f509 100644 --- a/src/lib/unlang/switch.c +++ b/src/lib/unlang/switch.c @@ -111,7 +111,7 @@ do_null_case: */ if (!found) return UNLANG_ACTION_EXECUTE_NEXT; - if (unlang_interpret_push(request, found, RLM_MODULE_NOT_SET, UNLANG_NEXT_STOP, UNLANG_SUB_FRAME) < 0) { + if (unlang_interpret_push(request, found, FRAME_CONF(RLM_MODULE_NOT_SET, UNLANG_SUB_FRAME), UNLANG_NEXT_STOP) < 0) { return UNLANG_ACTION_STOP_PROCESSING; } diff --git a/src/lib/unlang/timeout.c b/src/lib/unlang/timeout.c index c4af970979b..47de9b989b6 100644 --- a/src/lib/unlang/timeout.c +++ b/src/lib/unlang/timeout.c @@ -98,7 +98,8 @@ static void unlang_timeout_handler(UNUSED fr_timer_list_t *tl, UNUSED fr_time_t /* * Push something else onto the stack to execute. */ - if (unlikely(unlang_interpret_push_instruction(request, state->instruction, RLM_MODULE_TIMEOUT, true) < 0)) { + if (unlikely(unlang_interpret_push_instruction(request, state->instruction, + FRAME_CONF(RLM_MODULE_TIMEOUT, true)) < 0)) { unlang_interpret_signal(request, FR_SIGNAL_CANCEL); /* also stops the request and does cleanups */ } } @@ -238,7 +239,7 @@ int unlang_timeout_section_push(request_t *request, CONF_SECTION *cs, fr_time_de * Push a new timeout frame onto the stack */ if (unlang_interpret_push(request, &timeout_instruction, - RLM_MODULE_NOT_SET, UNLANG_NEXT_STOP, top_frame) < 0) return -1; + FRAME_CONF(RLM_MODULE_NOT_SET, top_frame), UNLANG_NEXT_STOP) < 0) return -1; frame = &stack->frame[stack->depth]; /* diff --git a/src/lib/unlang/tmpl.c b/src/lib/unlang/tmpl.c index 9ae5faf76f1..85986b3c0e1 100644 --- a/src/lib/unlang/tmpl.c +++ b/src/lib/unlang/tmpl.c @@ -303,7 +303,7 @@ int unlang_tmpl_push(TALLOC_CTX *ctx, fr_value_box_list_t *out, request_t *reque * Push a new tmpl frame onto the stack */ if (unlang_interpret_push(request, unlang_tmpl_to_generic(ut), - RLM_MODULE_NOT_SET, UNLANG_NEXT_STOP, false) < 0) return -1; + FRAME_CONF(RLM_MODULE_NOT_SET, false), UNLANG_NEXT_STOP) < 0) return -1; frame = &stack->frame[stack->depth]; state = talloc_get_type_abort(frame->state, unlang_frame_state_tmpl_t); diff --git a/src/lib/unlang/unlang_priv.h b/src/lib/unlang/unlang_priv.h index 617028d2f6e..b09a3e49515 100644 --- a/src/lib/unlang/unlang_priv.h +++ b/src/lib/unlang/unlang_priv.h @@ -716,7 +716,7 @@ static inline unlang_t *unlang_tmpl_to_generic(unlang_tmpl_t const *p) * @{ */ int unlang_interpret_push(request_t *request, unlang_t const *instruction, - rlm_rcode_t default_rcode, bool do_next_sibling, bool top_frame) + unlang_frame_conf_t const *conf, bool do_next_sibling) CC_HINT(warn_unused_result); unlang_action_t unlang_interpret_push_children(rlm_rcode_t *p_result, request_t *request, diff --git a/src/lib/unlang/xlat.c b/src/lib/unlang/xlat.c index 110c745769a..27a084c0a1d 100644 --- a/src/lib/unlang/xlat.c +++ b/src/lib/unlang/xlat.c @@ -231,7 +231,7 @@ static int unlang_xlat_push_internal(TALLOC_CTX *ctx, bool *p_success, fr_value_ * Push a new xlat eval frame onto the stack */ if (unlang_interpret_push(request, &xlat_instruction, - RLM_MODULE_NOT_SET, UNLANG_NEXT_STOP, top_frame) < 0) return -1; + FRAME_CONF(RLM_MODULE_NOT_SET, top_frame), UNLANG_NEXT_STOP) < 0) return -1; frame = &stack->frame[stack->depth]; /*