From 6401895addf7a8042cf815362679d71220c9c82a Mon Sep 17 00:00:00 2001 From: "Alan T. DeKok" Date: Tue, 15 Jul 2025 06:23:40 -0400 Subject: [PATCH] use macro to set p_result which lets us initialize the structure with the correct values --- src/lib/unlang/interpret.c | 19 +++++++------------ src/lib/unlang/interpret.h | 15 +++++---------- src/lib/unlang/module.c | 2 +- src/lib/unlang/parallel.c | 19 ++++++++++--------- src/lib/unlang/xlat.c | 14 +++++++------- 5 files changed, 30 insertions(+), 39 deletions(-) diff --git a/src/lib/unlang/interpret.c b/src/lib/unlang/interpret.c index d6b39f7dc4..97a0276896 100644 --- a/src/lib/unlang/interpret.c +++ b/src/lib/unlang/interpret.c @@ -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, ""), 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, ""), 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; } } diff --git a/src/lib/unlang/interpret.h b/src/lib/unlang/interpret.h index 9a9496afda..bb21edf698 100644 --- a/src/lib/unlang/interpret.h +++ b/src/lib/unlang/interpret.h @@ -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), \ } diff --git a/src/lib/unlang/module.c b/src/lib/unlang/module.c index 545ddb186c..7b4bae2647 100644 --- a/src/lib/unlang/module.c +++ b/src/lib/unlang/module.c @@ -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); diff --git a/src/lib/unlang/parallel.c b/src/lib/unlang/parallel.c index d9b2791923..f80d77c119 100644 --- a/src/lib/unlang/parallel.c +++ b/src/lib/unlang/parallel.c @@ -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, ""), cr->result.priority); - p_result->rcode = cr->result.rcode; - p_result->priority = cr->result.priority; + *p_result = cr->result; } } diff --git a/src/lib/unlang/xlat.c b/src/lib/unlang/xlat.c index e8f2e7ae04..ccdab7b434 100644 --- a/src/lib/unlang/xlat.c +++ b/src/lib/unlang/xlat.c @@ -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; } -- 2.47.2