]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Pass arguments to push functions in a structure
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Sun, 11 May 2025 21:34:28 +0000 (15:34 -0600)
committerNick Porter <nick@portercomputing.co.uk>
Wed, 18 Jun 2025 12:52:55 +0000 (13:52 +0100)
Makes it easier to add or remove args

16 files changed:
src/lib/unlang/call.c
src/lib/unlang/child_request.c
src/lib/unlang/edit.c
src/lib/unlang/finally.c
src/lib/unlang/function.c
src/lib/unlang/interpret.c
src/lib/unlang/interpret.h
src/lib/unlang/load_balance.c
src/lib/unlang/module.c
src/lib/unlang/parallel.c
src/lib/unlang/subrequest.c
src/lib/unlang/switch.c
src/lib/unlang/timeout.c
src/lib/unlang/tmpl.c
src/lib/unlang/unlang_priv.h
src/lib/unlang/xlat.c

index d72b057d199bb29fcc435b406c89f3cce977e358..04d8b200c6ce864868dbbaf8f9c1dbb00326b274 100644 (file)
@@ -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;
        }
index c68c09a706eeee53b51ee981453ff6cc4f448096..f2e6e11aed65ae882b415c55d4d003f297301620 100644 (file)
@@ -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;
        }
 
index 8f16b47637515bc38fe2d7e2f2e8722dc4c27cac..10232f0b7070d7de39ae1e5b6eb81316e25762f7 100644 (file)
@@ -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);
index f172e99b72db4409325da757cddb7a7a66563fa7..49f3c6209ce10b601afaba57505a9037c7e3d4fa 100644 (file)
@@ -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];
 
        /*
index f7a696982349b0546bb798bb32e71736c15c7067..3467f3ba832dbd281d962dccedb425fdbff6e48a 100644 (file)
@@ -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];
 
index 28a76f345c44927fde9de6e8459c0efac3dc5917..52d50dfd77deb5a0e25562d23cc5f46f27df66a8 100644 (file)
@@ -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;
        }
 
index 676652643c5efd0ba1adb6cf64dc6225b9cda3ab..012dd33949e039d89517e9c958499a04bf2c452b 100644 (file)
@@ -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,
index 68fb0028a7fb2904ea81c4f0baf7857e75c3f78b..e3f49565a6f1f6ac3cbe584dd15eb0f58fb2ab2d 100644 (file)
@@ -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;
index 05f2c0d9811136c8ab0854a72613804fa546b9f2..8fe8ae0e26696ae0534578b143899bac8cd21ed7 100644 (file)
@@ -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;
 }
index 62269bcc77b2bb5b4bb170cfcb4e826e30262939..b3d29d58c7803ef3befffe29732ccd546193eaa3 100644 (file)
@@ -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;
        }
 
        /*
index 5fcb17451093c389630957ceffb41d872811c20b..da7a9521b15cbe8349f7b48e92a9044790f930c1 100644 (file)
@@ -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;
        }
 
index 2d1739eee36eca32ffa854ce16685ce7e238615c..3ed00e6f509ada0338fadf59ff5677a5ed853e1b 100644 (file)
@@ -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;
        }
 
index c4af970979b854c441c1b52685153435ae263af6..47de9b989b6e81120a1366bf82a54e637d2f2af0 100644 (file)
@@ -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];
 
        /*
index 9ae5faf76f1842748948c972cf2ee5ea98b65cc2..85986b3c0e10d6bbfd18d7a0ca2c6436102aa31c 100644 (file)
@@ -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);
index 617028d2f6ec73c5361fc7220752755b8dbaf69a..b09a3e49515cefde8567c55435fd6252af7bd08c 100644 (file)
@@ -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,
index 110c745769a243ae5923779ebbf2be4e7b5cada3..27a084c0a1d071bf60d1041f4a6470f75df0e42c 100644 (file)
@@ -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];
 
        /*