]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
use macro to set p_result
authorAlan T. DeKok <aland@freeradius.org>
Tue, 15 Jul 2025 10:23:40 +0000 (06:23 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Tue, 15 Jul 2025 10:23:40 +0000 (06:23 -0400)
which lets us initialize the structure with the correct values

src/lib/unlang/interpret.c
src/lib/unlang/interpret.h
src/lib/unlang/module.c
src/lib/unlang/parallel.c
src/lib/unlang/xlat.c

index d6b39f7dc48ee15d0130f8ba11dcf06417ce78d3..97a027689651906fc6f3fd47caa179920a7fa046 100644 (file)
@@ -270,8 +270,7 @@ void stack_dump_with_actions(request_t *request)
  * @param[in] request          to push the frame onto.
  * @param[in] instruction      One or more unlang_t nodes describing the operations to execute.
  * @param[in] conf             Configuration for the frame.  If NULL, the following values areused:
- *                             - default_rcode = RLM_MODULE_NOT_SET
- *                             - default_priority = MOD_ACTION_NOT_SET
+ *                             - default result = UNLANG_RESULT_NOT_SET
  *                             - top_frame = UNLANG_SUB_FRAME
  *                             - no_rcode = false
  * @param[in] do_next_sibling  Whether to only execute the first node in the #unlang_t program
@@ -287,8 +286,7 @@ int unlang_interpret_push(unlang_result_t *result_p, request_t *request,
        unlang_stack_frame_t    *frame;
 
        static unlang_frame_conf_t default_conf = {
-               .default_rcode = RLM_MODULE_NOT_SET,
-               .default_priority = MOD_ACTION_NOT_SET,
+               .default_result = UNLANG_RESULT_NOT_SET,
                .top_frame = UNLANG_SUB_FRAME
        };
 
@@ -333,8 +331,7 @@ int unlang_interpret_push(unlang_result_t *result_p, request_t *request,
        if (conf->top_frame) top_frame_set(frame);
 
        frame->result_p = result_p ? result_p : &frame->section_result;
-       frame->result_p->rcode = conf->default_rcode;
-       frame->result_p->priority = conf->default_priority;
+       *frame->result_p = conf->default_result;
 
        frame->indent = request->log.indent;
 
@@ -520,8 +517,7 @@ unlang_frame_action_t result_calculate(request_t *request, unlang_stack_frame_t
                        fr_table_str_by_value(mod_rcode_table, result->rcode, "<invalid>"),
                        result->priority);
 
-               frame_result->priority = 0;
-               frame_result->rcode = result->rcode;
+               *frame_result = UNLANG_RESULT_RCODE(result->rcode);
                return UNLANG_FRAME_ACTION_POP;
 
        /*
@@ -539,8 +535,7 @@ unlang_frame_action_t result_calculate(request_t *request, unlang_stack_frame_t
                        fr_table_str_by_value(mod_rcode_table, RLM_MODULE_REJECT, "<invalid>"),
                        result->priority);
 
-               frame_result->priority = 0;
-               frame_result->rcode = RLM_MODULE_REJECT;
+               *frame_result = UNLANG_RESULT_RCODE(RLM_MODULE_REJECT);
                return UNLANG_FRAME_ACTION_POP;
 
        case MOD_ACTION_RETRY:
@@ -573,7 +568,7 @@ unlang_frame_action_t result_calculate(request_t *request, unlang_stack_frame_t
                                if (fr_timer_in(retry, unlang_interpret_event_list(request)->tl, &retry->ev, instruction->actions.retry.mrd,
                                                false, instruction_retry_handler, request) < 0) {
                                        RPEDEBUG("Failed inserting retry event");
-                                       frame_result->rcode = RLM_MODULE_FAIL;
+                                       *frame_result = UNLANG_RESULT_RCODE(RLM_MODULE_FAIL);
                                        goto finalize;
                                }
                        }
@@ -597,7 +592,7 @@ unlang_frame_action_t result_calculate(request_t *request, unlang_stack_frame_t
                                        REDEBUG("Retries hit max_rtx_count (%u) - returning 'timeout'", instruction->actions.retry.mrc);
 
                                timeout:
-                                       frame_result->rcode = RLM_MODULE_TIMEOUT;
+                                       *frame_result = UNLANG_RESULT_RCODE(RLM_MODULE_TIMEOUT);
                                        goto finalize;
                                }
                        }
index 9a9496afda12b17e5c58647293ce50336cf0c6c9..bb21edf698e7869743fdabd01a1b3761e2b2b9ca 100644 (file)
@@ -136,17 +136,14 @@ typedef struct {
        unlang_mod_action_t             priority;               //!< The priority or action for that rcode.
 } unlang_result_t;
 
-#define UNLANG_RESULT_NOT_SET ((unlang_result_t){ .rcode =  RLM_MODULE_NOT_SET, .priority = MOD_ACTION_NOT_SET })
+#define UNLANG_RESULT_NOT_SET ((unlang_result_t) { .rcode =  RLM_MODULE_NOT_SET, .priority = MOD_ACTION_NOT_SET })
+#define UNLANG_RESULT_RCODE(_x) ((unlang_result_t) { .rcode = (_x), .priority = MOD_ACTION_NOT_SET })
 
 /** 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?
-       rlm_rcode_t                     default_rcode;          //!< The default return code for the frame.
-                                                               ///< This needs to be specified separately
-                                                               ///< from p_result, because we may be passing
-                                                               ///< in NULL for p_result.
-       unlang_mod_action_t             default_priority;       //!< The default priority for the frame.
+       unlang_result_t                 default_result;         //!< The default result for the frame.
                                                                ///< This needs to be specified separately
                                                                ///< from p_result, because we may be passing
                                                                ///< in NULL for p_result.
@@ -155,15 +152,13 @@ typedef struct {
 #define FRAME_CONF(_default_rcode, _top_frame)         \
        &(unlang_frame_conf_t){                         \
                .top_frame = (_top_frame),              \
-               .default_rcode = (_default_rcode),      \
-               .default_priority = MOD_ACTION_NOT_SET  \
+               .default_result = UNLANG_RESULT_RCODE(_default_rcode),  \
        }
 
 #define FRAME_CONF_NO_RCODE(_default_rcode, _top_frame)        \
        &(unlang_frame_conf_t){                         \
                .top_frame = (_top_frame),              \
-               .default_rcode = (_default_rcode),      \
-               .default_priority = MOD_ACTION_NOT_SET  \
+               .default_result = UNLANG_RESULT_RCODE(_default_rcode),  \
        }
 
 
index 545ddb186cf2c1d18f113cb3802ba78ad52daf24..7b4bae2647393118ce226b05434b54002f86ec73 100644 (file)
@@ -273,7 +273,7 @@ unlang_action_t unlang_module_yield_to_section(unlang_result_t *p_result,
                 *      Pretend as if we called the section
                 *      and used the default rcode value.
                 */
-               frame->scratch_result.rcode = default_rcode;
+               frame->scratch_result = (unlang_result_t) {.rcode = default_rcode, .priority = MOD_ACTION_NOT_SET };
 
                state = talloc_get_type_abort(frame->state, unlang_frame_state_module_t);
 
index d9b279192341e0d10943b1cf9c0321e90b9eb199..f80d77c119d28c9aa9411c4ef6a19b45b6e1ed66 100644 (file)
@@ -152,16 +152,18 @@ static unlang_action_t unlang_parallel_resume(unlang_result_t *p_result, request
                state->children[i].state = CHILD_DONE;
 
                /*
-                *      Return isn't allowed to make it back
-                *      to the parent... Not sure this is
-                *      the correct behaviour, but it's what
-                *      was there before.
+                *      Over-ride "return" and "reject".  A "return"
+                *      in a child of a parallel just stops the child.
+                *      It doesn't stop the parent.
                 */
                if (cr->result.priority == MOD_ACTION_RETURN) {
-                       cr->result.priority = 0;
+                       cr->result.priority = MOD_ACTION_NOT_SET;
+
                } else if (cr->result.priority == MOD_ACTION_REJECT) {
-                       cr->result.rcode = RLM_MODULE_REJECT;
-                       cr->result.priority = 0;
+                       cr->result = UNLANG_RESULT_RCODE(RLM_MODULE_REJECT);
+
+               } else {
+                       fr_assert(cr->result.priority != MOD_ACTION_RETRY);
                }
 
                /*
@@ -174,8 +176,7 @@ static unlang_action_t unlang_parallel_resume(unlang_result_t *p_result, request
                                p_result->priority,
                                fr_table_str_by_value(mod_rcode_table, cr->result.rcode, "<invalid>"),
                                cr->result.priority);
-                       p_result->rcode = cr->result.rcode;
-                       p_result->priority = cr->result.priority;
+                       *p_result = cr->result;
                }
        }
 
index e8f2e7ae046243448286b16fcdeff74d2e79cd2a..ccdab7b4344b8dca37df8bb3fe4c6bd5d751d1c4 100644 (file)
@@ -364,13 +364,13 @@ static unlang_action_t unlang_xlat_repeat(unlang_result_t *p_result, request_t *
                return UNLANG_ACTION_YIELD;
 
        case XLAT_ACTION_DONE:
-               p_result->rcode = RLM_MODULE_OK;
+               *p_result = UNLANG_RESULT_RCODE(RLM_MODULE_OK);
                REXDENT();
                return UNLANG_ACTION_CALCULATE_RESULT;
 
        case XLAT_ACTION_FAIL:
        fail:
-               p_result->rcode = RLM_MODULE_FAIL;
+               *p_result = UNLANG_RESULT_RCODE(RLM_MODULE_FAIL);
                REXDENT();
                return UNLANG_ACTION_CALCULATE_RESULT;
 
@@ -426,13 +426,13 @@ static unlang_action_t unlang_xlat(UNUSED unlang_result_t *p_result, request_t *
                return UNLANG_ACTION_YIELD;
 
        case XLAT_ACTION_DONE:
-               p_result->rcode = RLM_MODULE_OK;
+               *p_result = UNLANG_RESULT_RCODE(RLM_MODULE_OK);
                RINDENT_RESTORE(request, state);
                return UNLANG_ACTION_CALCULATE_RESULT;
 
        case XLAT_ACTION_FAIL:
        fail:
-               p_result->rcode = RLM_MODULE_FAIL;
+               *p_result = UNLANG_RESULT_RCODE(RLM_MODULE_FAIL);
                RINDENT_RESTORE(request, state);
                return UNLANG_ACTION_CALCULATE_RESULT;
 
@@ -502,7 +502,7 @@ static unlang_action_t unlang_xlat_resume(unlang_result_t *p_result, request_t *
                return UNLANG_ACTION_YIELD;
 
        case XLAT_ACTION_DONE:
-               p_result->rcode = RLM_MODULE_OK;
+               *p_result = UNLANG_RESULT_RCODE(RLM_MODULE_OK);
                RINDENT_RESTORE(request, state);
                return UNLANG_ACTION_CALCULATE_RESULT;
 
@@ -528,7 +528,7 @@ static unlang_action_t unlang_xlat_resume(unlang_result_t *p_result, request_t *
                return UNLANG_ACTION_PUSHED_CHILD;
 
        case XLAT_ACTION_FAIL:
-               p_result->rcode = RLM_MODULE_FAIL;
+               *p_result = UNLANG_RESULT_RCODE(RLM_MODULE_FAIL);
                RINDENT_RESTORE(request, state);
                return UNLANG_ACTION_CALCULATE_RESULT;
        /* DON'T SET DEFAULT */
@@ -536,7 +536,7 @@ static unlang_action_t unlang_xlat_resume(unlang_result_t *p_result, request_t *
 
        fr_assert(0);           /* Garbage xlat action */
 
-       p_result->rcode = RLM_MODULE_FAIL;
+       *p_result = UNLANG_RESULT_RCODE(RLM_MODULE_FAIL);
        RINDENT_RESTORE(request, state);
        return UNLANG_ACTION_CALCULATE_RESULT;
 }