From: Alan T. DeKok Date: Thu, 17 Jul 2025 16:56:09 +0000 (-0400) Subject: use macro for common case X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1314bdd8ef92f4587bcbee18be1cc509344d535a;p=thirdparty%2Ffreeradius-server.git use macro for common case some instructions didn't return on timeout. So using a common initializer is beneficial --- diff --git a/src/lib/unlang/call.c b/src/lib/unlang/call.c index e024832139..756e959fa3 100644 --- a/src/lib/unlang/call.c +++ b/src/lib/unlang/call.c @@ -181,20 +181,7 @@ unlang_action_t unlang_call_push(unlang_result_t *p_result, request_t *request, .name = name, .debug_name = name, .ci = CF_TO_ITEM(server_cs), - .actions = { - .actions = { - [RLM_MODULE_REJECT] = 0, - [RLM_MODULE_FAIL] = MOD_ACTION_RETURN, /* Exit out of nested levels */ - [RLM_MODULE_OK] = 0, - [RLM_MODULE_HANDLED] = 0, - [RLM_MODULE_INVALID] = 0, - [RLM_MODULE_DISALLOW] = 0, - [RLM_MODULE_NOTFOUND] = 0, - [RLM_MODULE_NOOP] = 0, - [RLM_MODULE_UPDATED] = 0 - }, - .retry = RETRY_INIT, - }, + .actions = MOD_ACTIONS_FAIL_TIMEOUT_RETURN, }, .cs = server_cs, diff --git a/src/lib/unlang/finally.c b/src/lib/unlang/finally.c index 7c23b8ca43..ec4205bed0 100644 --- a/src/lib/unlang/finally.c +++ b/src/lib/unlang/finally.c @@ -134,21 +134,7 @@ int unlang_finally_push_instruction(request_t *request, void *instruction, fr_ti .type = UNLANG_TYPE_FINALLY, .name = "finally", .debug_name = "finally", - .actions = { - .actions = { - [RLM_MODULE_REJECT] = 0, - [RLM_MODULE_FAIL] = MOD_ACTION_RETURN, /* Exit out of nested levels */ - [RLM_MODULE_OK] = 0, - [RLM_MODULE_HANDLED] = 0, - [RLM_MODULE_INVALID] = 0, - [RLM_MODULE_DISALLOW] = 0, - [RLM_MODULE_NOTFOUND] = 0, - [RLM_MODULE_NOOP] = 0, - [RLM_MODULE_TIMEOUT] = MOD_ACTION_RETURN, /* Exit out of nested levels */ - [RLM_MODULE_UPDATED] = 0 - }, - .retry = RETRY_INIT, - }, + .actions = MOD_ACTIONS_FAIL_TIMEOUT_RETURN, }; unlang_frame_state_finally_t *state; diff --git a/src/lib/unlang/function.c b/src/lib/unlang/function.c index b4ea4a795d..7c8dc1174b 100644 --- a/src/lib/unlang/function.c +++ b/src/lib/unlang/function.c @@ -62,28 +62,7 @@ static unlang_t function_instruction = { .type = UNLANG_TYPE_FUNCTION, .name = "function", .debug_name = "function", - .actions = { - /* - * By default, functions don't change the section rcode. - * We can't make generalisations about what the intent - * of the function callbacks are, so isntead of having - * implicit, confusing behaviour, we always discard the - * rcode UNLESS the function explicitly sets it. - */ - .actions = { - [RLM_MODULE_REJECT] = MOD_ACTION_NOT_SET, - [RLM_MODULE_FAIL] = MOD_ACTION_NOT_SET, - [RLM_MODULE_OK] = MOD_ACTION_NOT_SET, - [RLM_MODULE_HANDLED] = MOD_ACTION_NOT_SET, - [RLM_MODULE_INVALID] = MOD_ACTION_NOT_SET, - [RLM_MODULE_DISALLOW] = MOD_ACTION_NOT_SET, - [RLM_MODULE_NOTFOUND] = MOD_ACTION_NOT_SET, - [RLM_MODULE_NOOP] = MOD_ACTION_NOT_SET, - [RLM_MODULE_UPDATED] = MOD_ACTION_NOT_SET, - [RLM_MODULE_TIMEOUT] = MOD_ACTION_NOT_SET - }, - .retry = RETRY_INIT, - } + .actions = DEFAULT_MOD_ACTIONS, }; /** Generic signal handler diff --git a/src/lib/unlang/interpret.c b/src/lib/unlang/interpret.c index 7048073f56..139408b67e 100644 --- a/src/lib/unlang/interpret.c +++ b/src/lib/unlang/interpret.c @@ -1212,28 +1212,7 @@ void *unlang_interpret_stack_alloc(TALLOC_CTX *ctx) */ static unlang_t unlang_instruction = { .debug_name = "top", - .actions = { - /* - * By default, functions don't change the section rcode. - * We can't make generalisations about what the intent - * of the function callbacks are, so isntead of having - * implicit, confusing behaviour, we always discard the - * rcode UNLESS the function explicitly sets it. - */ - .actions = { - [RLM_MODULE_REJECT] = MOD_ACTION_NOT_SET, - [RLM_MODULE_FAIL] = MOD_ACTION_NOT_SET, - [RLM_MODULE_OK] = MOD_ACTION_NOT_SET, - [RLM_MODULE_HANDLED] = MOD_ACTION_NOT_SET, - [RLM_MODULE_INVALID] = MOD_ACTION_NOT_SET, - [RLM_MODULE_DISALLOW] = MOD_ACTION_NOT_SET, - [RLM_MODULE_NOTFOUND] = MOD_ACTION_NOT_SET, - [RLM_MODULE_NOOP] = MOD_ACTION_NOT_SET, - [RLM_MODULE_UPDATED] = MOD_ACTION_NOT_SET, - [RLM_MODULE_TIMEOUT] = MOD_ACTION_NOT_SET - }, - .retry = RETRY_INIT - } + .actions = DEFAULT_MOD_ACTIONS, }; unlang_stack_t *stack; diff --git a/src/lib/unlang/mod_action.h b/src/lib/unlang/mod_action.h index 033ff29ca7..23fadd2f8d 100644 --- a/src/lib/unlang/mod_action.h +++ b/src/lib/unlang/mod_action.h @@ -66,6 +66,7 @@ typedef struct { } unlang_mod_actions_t; #define DEFAULT_MOD_ACTIONS { .actions = {}, .retry = RETRY_INIT } +#define MOD_ACTIONS_FAIL_TIMEOUT_RETURN { .actions = { [RLM_MODULE_FAIL] = MOD_ACTION_RETURN, [RLM_MODULE_TIMEOUT] = MOD_ACTION_RETURN,}, .retry = RETRY_INIT } extern unlang_mod_actions_t const mod_actions_authenticate; extern unlang_mod_actions_t const mod_actions_authorize; diff --git a/src/lib/unlang/module.c b/src/lib/unlang/module.c index 7b4bae2647..2cf5869044 100644 --- a/src/lib/unlang/module.c +++ b/src/lib/unlang/module.c @@ -66,21 +66,7 @@ int unlang_module_push(unlang_result_t *p_result, request_t *request, .type = UNLANG_TYPE_MODULE, .name = mi->name, .debug_name = mi->name, - .actions = { - .actions = { - [RLM_MODULE_REJECT] = 0, - [RLM_MODULE_FAIL] = MOD_ACTION_RETURN, /* Exit out of nested levels */ - [RLM_MODULE_OK] = 0, - [RLM_MODULE_HANDLED] = 0, - [RLM_MODULE_INVALID] = 0, - [RLM_MODULE_DISALLOW] = 0, - [RLM_MODULE_NOTFOUND] = 0, - [RLM_MODULE_NOOP] = 0, - [RLM_MODULE_UPDATED] = 0, - [RLM_MODULE_TIMEOUT] = MOD_ACTION_RETURN, /* Exit out of nested levels */ - }, - .retry = RETRY_INIT, - }, + .actions = MOD_ACTIONS_FAIL_TIMEOUT_RETURN, }, .mmc = { .mi = mi, diff --git a/src/lib/unlang/timeout.c b/src/lib/unlang/timeout.c index d7fcdb5074..2a85cb4636 100644 --- a/src/lib/unlang/timeout.c +++ b/src/lib/unlang/timeout.c @@ -203,21 +203,7 @@ int unlang_timeout_section_push(request_t *request, CONF_SECTION *cs, fr_time_de .type = UNLANG_TYPE_TIMEOUT, .name = "timeout", .debug_name = "timeout", - .actions = { - .actions = { - [RLM_MODULE_REJECT] = 0, - [RLM_MODULE_FAIL] = MOD_ACTION_RETURN, /* Exit out of nested levels */ - [RLM_MODULE_OK] = 0, - [RLM_MODULE_HANDLED] = 0, - [RLM_MODULE_INVALID] = 0, - [RLM_MODULE_DISALLOW] = 0, - [RLM_MODULE_NOTFOUND] = 0, - [RLM_MODULE_NOOP] = 0, - [RLM_MODULE_TIMEOUT] = MOD_ACTION_RETURN, /* Exit out of nested levels */ - [RLM_MODULE_UPDATED] = 0 - }, - .retry = RETRY_INIT, - }, + .actions = MOD_ACTIONS_FAIL_TIMEOUT_RETURN, }; unlang_frame_state_timeout_t *state; diff --git a/src/lib/unlang/tmpl.c b/src/lib/unlang/tmpl.c index c005709578..f16ff49da7 100644 --- a/src/lib/unlang/tmpl.c +++ b/src/lib/unlang/tmpl.c @@ -283,20 +283,7 @@ int unlang_tmpl_push(TALLOC_CTX *ctx, unlang_result_t *p_result, fr_value_box_li .type = UNLANG_TYPE_TMPL, .name = "tmpl", .debug_name = "tmpl", - .actions = { - .actions = { - [RLM_MODULE_REJECT] = 0, - [RLM_MODULE_FAIL] = MOD_ACTION_RETURN, - [RLM_MODULE_OK] = 0, - [RLM_MODULE_HANDLED] = 0, - [RLM_MODULE_INVALID] = 0, - [RLM_MODULE_DISALLOW] = 0, - [RLM_MODULE_NOTFOUND] = 0, - [RLM_MODULE_NOOP] = 0, - [RLM_MODULE_UPDATED] = 0 - }, - .retry = RETRY_INIT, - }, + .actions = MOD_ACTIONS_FAIL_TIMEOUT_RETURN, }; static const unlang_t tmpl_instruction_fail = { diff --git a/src/lib/unlang/xlat.c b/src/lib/unlang/xlat.c index ccdab7b434..6c18582583 100644 --- a/src/lib/unlang/xlat.c +++ b/src/lib/unlang/xlat.c @@ -208,20 +208,7 @@ static int unlang_xlat_push_internal(TALLOC_CTX *ctx, unlang_result_t *p_result, .type = UNLANG_TYPE_XLAT, .name = "xlat", .debug_name = "xlat", - .actions = { - .actions = { - [RLM_MODULE_REJECT] = 0, - [RLM_MODULE_FAIL] = MOD_ACTION_RETURN, /* Exit out of nested levels */ - [RLM_MODULE_OK] = 0, - [RLM_MODULE_HANDLED] = 0, - [RLM_MODULE_INVALID] = 0, - [RLM_MODULE_DISALLOW] = 0, - [RLM_MODULE_NOTFOUND] = 0, - [RLM_MODULE_NOOP] = 0, - [RLM_MODULE_UPDATED] = 0 - }, - .retry = RETRY_INIT, - }, + .actions = MOD_ACTIONS_FAIL_TIMEOUT_RETURN, }; unlang_frame_state_xlat_t *state;