From: Alan T. DeKok Date: Fri, 11 Jul 2025 11:48:20 +0000 (-0400) Subject: add comments and macros for mod_action X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=041c48464ed30c87f4367cdcccda24da12f6fe9c;p=thirdparty%2Ffreeradius-server.git add comments and macros for mod_action --- diff --git a/src/lib/server/virtual_servers.c b/src/lib/server/virtual_servers.c index 4f341df3228..633ebdce44f 100644 --- a/src/lib/server/virtual_servers.c +++ b/src/lib/server/virtual_servers.c @@ -1023,15 +1023,15 @@ static inline CC_HINT(always_inline) int virtual_server_compile_finally_sections { static unlang_mod_actions_t const mod_actions_finally = { .actions = { - [RLM_MODULE_REJECT] = 3, - [RLM_MODULE_FAIL] = 1, - [RLM_MODULE_OK] = 4, + [RLM_MODULE_REJECT] = MOD_PRIORITY(3), + [RLM_MODULE_FAIL] = MOD_PRIORITY(1), + [RLM_MODULE_OK] = MOD_PRIORITY(4), [RLM_MODULE_HANDLED] = MOD_ACTION_RETURN, - [RLM_MODULE_INVALID] = 2, - [RLM_MODULE_DISALLOW] = 5, - [RLM_MODULE_NOTFOUND] = 6, - [RLM_MODULE_NOOP] = 8, - [RLM_MODULE_UPDATED] = 7 + [RLM_MODULE_INVALID] = MOD_PRIORITY(2), + [RLM_MODULE_DISALLOW] = MOD_PRIORITY(5), + [RLM_MODULE_NOTFOUND] = MOD_PRIORITY(6), + [RLM_MODULE_NOOP] = MOD_PRIORITY(8), + [RLM_MODULE_UPDATED] = MOD_PRIORITY(7) }, .retry = RETRY_INIT, }; diff --git a/src/lib/unlang/child_request.c b/src/lib/unlang/child_request.c index 2236e48d67e..6ab51f316d5 100644 --- a/src/lib/unlang/child_request.c +++ b/src/lib/unlang/child_request.c @@ -208,20 +208,7 @@ static int unlang_child_request_stack_init(unlang_child_request_t *cr) .type = UNLANG_TYPE_CHILD_REQUEST, .name = "child-request", .debug_name = "child-request-resume", - .actions = { - .actions = { - [RLM_MODULE_REJECT] = 0, - [RLM_MODULE_FAIL] = 0, - [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 = DEFAULT_MOD_ACTIONS, }; /* Sets up the frame for us to use immediately */ diff --git a/src/lib/unlang/edit.c b/src/lib/unlang/edit.c index 5449f18bb46..4abe1e624e4 100644 --- a/src/lib/unlang/edit.c +++ b/src/lib/unlang/edit.c @@ -1721,20 +1721,7 @@ int unlang_edit_push(request_t *request, bool *success, fr_edit_list_t *el, map_ .type = UNLANG_TYPE_EDIT, .name = "edit", .debug_name = "edit", - .actions = { - .actions = { - [RLM_MODULE_REJECT] = 0, - [RLM_MODULE_FAIL] = 0, - [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 = DEFAULT_MOD_ACTIONS, }; MEM(edit = talloc(stack, unlang_edit_t)); diff --git a/src/lib/unlang/mod_action.c b/src/lib/unlang/mod_action.c index 303961fdaa5..a719741d594 100644 --- a/src/lib/unlang/mod_action.c +++ b/src/lib/unlang/mod_action.c @@ -31,14 +31,14 @@ unlang_mod_actions_t const mod_actions_authenticate = { .actions = { [RLM_MODULE_REJECT] = MOD_ACTION_RETURN, [RLM_MODULE_FAIL] = MOD_ACTION_RETURN, - [RLM_MODULE_OK] = 4, + [RLM_MODULE_OK] = MOD_PRIORITY(4), [RLM_MODULE_HANDLED] = MOD_ACTION_RETURN, [RLM_MODULE_INVALID] = MOD_ACTION_RETURN, [RLM_MODULE_DISALLOW] = MOD_ACTION_RETURN, - [RLM_MODULE_NOTFOUND] = 1, - [RLM_MODULE_NOOP] = 2, + [RLM_MODULE_NOTFOUND] = MOD_PRIORITY(1), + [RLM_MODULE_NOOP] = MOD_PRIORITY(2), [RLM_MODULE_TIMEOUT] = MOD_ACTION_RETURN, - [RLM_MODULE_UPDATED] = 4 + [RLM_MODULE_UPDATED] = MOD_PRIORITY(4) }, .retry = RETRY_INIT }; @@ -47,14 +47,14 @@ unlang_mod_actions_t const mod_actions_authorize = { .actions = { [RLM_MODULE_REJECT] = MOD_ACTION_RETURN, [RLM_MODULE_FAIL] = MOD_ACTION_RETURN, - [RLM_MODULE_OK] = 3, + [RLM_MODULE_OK] = MOD_PRIORITY(3), [RLM_MODULE_HANDLED] = MOD_ACTION_RETURN, [RLM_MODULE_INVALID] = MOD_ACTION_RETURN, [RLM_MODULE_DISALLOW] = MOD_ACTION_RETURN, - [RLM_MODULE_NOTFOUND] = 1, - [RLM_MODULE_NOOP] = 2, + [RLM_MODULE_NOTFOUND] = MOD_PRIORITY(1), + [RLM_MODULE_NOOP] = MOD_PRIORITY(2), [RLM_MODULE_TIMEOUT] = MOD_ACTION_RETURN, - [RLM_MODULE_UPDATED] = 4 + [RLM_MODULE_UPDATED] = MOD_PRIORITY(4) }, .retry = RETRY_INIT, }; @@ -63,14 +63,14 @@ unlang_mod_actions_t const mod_actions_preacct = { .actions = { [RLM_MODULE_REJECT] = MOD_ACTION_RETURN, [RLM_MODULE_FAIL] = MOD_ACTION_RETURN, - [RLM_MODULE_OK] = 3, + [RLM_MODULE_OK] = MOD_PRIORITY(3), [RLM_MODULE_HANDLED] = MOD_ACTION_RETURN, [RLM_MODULE_INVALID] = MOD_ACTION_RETURN, [RLM_MODULE_DISALLOW] = MOD_ACTION_RETURN, - [RLM_MODULE_NOTFOUND] = 1, - [RLM_MODULE_NOOP] = 2, + [RLM_MODULE_NOTFOUND] = MOD_PRIORITY(1), + [RLM_MODULE_NOOP] = MOD_PRIORITY(2), [RLM_MODULE_TIMEOUT] = MOD_ACTION_RETURN, - [RLM_MODULE_UPDATED] = 4 + [RLM_MODULE_UPDATED] = MOD_PRIORITY(4) }, .retry = RETRY_INIT, }; @@ -79,14 +79,14 @@ unlang_mod_actions_t const mod_actions_accounting = { .actions = { [RLM_MODULE_REJECT] = MOD_ACTION_RETURN, [RLM_MODULE_FAIL] = MOD_ACTION_RETURN, - [RLM_MODULE_OK] = 3, + [RLM_MODULE_OK] = MOD_PRIORITY(3), [RLM_MODULE_HANDLED] = MOD_ACTION_RETURN, [RLM_MODULE_INVALID] = MOD_ACTION_RETURN, [RLM_MODULE_DISALLOW] = MOD_ACTION_RETURN, - [RLM_MODULE_NOTFOUND] = 1, - [RLM_MODULE_NOOP] = 2, + [RLM_MODULE_NOTFOUND] = MOD_PRIORITY(1), + [RLM_MODULE_NOOP] = MOD_PRIORITY(2), [RLM_MODULE_TIMEOUT] = MOD_ACTION_RETURN, - [RLM_MODULE_UPDATED] = 4 + [RLM_MODULE_UPDATED] = MOD_PRIORITY(4) }, }; @@ -94,14 +94,14 @@ unlang_mod_actions_t const mod_actions_postauth = { .actions = { [RLM_MODULE_REJECT] = MOD_ACTION_RETURN, [RLM_MODULE_FAIL] = MOD_ACTION_RETURN, - [RLM_MODULE_OK] = 3, + [RLM_MODULE_OK] = MOD_PRIORITY(3), [RLM_MODULE_HANDLED] = MOD_ACTION_RETURN, [RLM_MODULE_INVALID] = MOD_ACTION_RETURN, [RLM_MODULE_DISALLOW] = MOD_ACTION_RETURN, - [RLM_MODULE_NOTFOUND] = 1, - [RLM_MODULE_NOOP] = 2, + [RLM_MODULE_NOTFOUND] = MOD_PRIORITY(1), + [RLM_MODULE_NOOP] = MOD_PRIORITY(2), [RLM_MODULE_TIMEOUT] = MOD_ACTION_RETURN, - [RLM_MODULE_UPDATED] = 4 + [RLM_MODULE_UPDATED] = MOD_PRIORITY(4) }, .retry = RETRY_INIT }; diff --git a/src/lib/unlang/mod_action.h b/src/lib/unlang/mod_action.h index a9df7162a5c..0c3292e3d77 100644 --- a/src/lib/unlang/mod_action.h +++ b/src/lib/unlang/mod_action.h @@ -31,23 +31,19 @@ extern "C" { #include #include -/* Actions may be a positive integer (the highest one returned in the group - * will be returned), or the keyword "return", represented here by - * MOD_ACTION_RETURN, to cause an immediate return. - * There's also the keyword "reject", represented here by MOD_ACTION_REJECT - * to cause an immediate reject. */ -typedef enum { - MOD_ACTION_NOT_SET = -4, - MOD_ACTION_RETRY = -3, - MOD_ACTION_REJECT = -2, - MOD_ACTION_RETURN = -1, +#define MOD_PRIORITY(_x) (_x) +typedef enum { + MOD_ACTION_NOT_SET = -4, //!< default "not set by anything" + MOD_ACTION_RETRY = -3, //!< retry the instruction, MUST also set a retry config + MOD_ACTION_REJECT = -2, //!< change the rcode to REJECT, with unset priority + MOD_ACTION_RETURN = -1, //!< stop processing the section, + //!< and return the rcode with unset priority - MOD_PRIORITY_MIN = 0, - MOD_PRIORITY_1 = 1, - MOD_PRIORITY_2 = 2, - MOD_PRIORITY_3 = 3, - MOD_PRIORITY_4 = 4, + MOD_PRIORITY_1 = MOD_PRIORITY(1), + MOD_PRIORITY_2 = MOD_PRIORITY(2), + MOD_PRIORITY_3 = MOD_PRIORITY(3), + MOD_PRIORITY_4 = MOD_PRIORITY(4), /* * If ubsan or the compiler complains @@ -57,14 +53,18 @@ typedef enum { * Defining MOD_PRIORITY_MAX ensures the * enum will always be large enough. */ - MOD_PRIORITY_MAX = 64 + MOD_PRIORITY_MAX = MOD_PRIORITY(64) } unlang_mod_action_t; +#define MOD_PRIORITY_MIN MOD_PRIORITY_1 + typedef struct { unlang_mod_action_t actions[RLM_MODULE_NUMCODES]; fr_retry_config_t retry; } unlang_mod_actions_t; +#define DEFAULT_MOD_ACTIONS { .actions = {}, .retry = RETRY_INIT } + extern unlang_mod_actions_t const mod_actions_authenticate; extern unlang_mod_actions_t const mod_actions_authorize; extern unlang_mod_actions_t const mod_actions_preacct; diff --git a/src/lib/unlang/subrequest.c b/src/lib/unlang/subrequest.c index 5cfa9ba0b8f..6e5fb5b11ce 100644 --- a/src/lib/unlang/subrequest.c +++ b/src/lib/unlang/subrequest.c @@ -434,20 +434,7 @@ int unlang_subrequest_child_push(unlang_result_t *p_result, request_t *child, vo .type = UNLANG_TYPE_SUBREQUEST, .name = "subrequest", .debug_name = "subrequest", - .actions = { - .actions = { - [RLM_MODULE_REJECT] = 0, - [RLM_MODULE_FAIL] = 0, - [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 = DEFAULT_MOD_ACTIONS, }; fr_assert_msg(free_child || child->parent, "Child's request pointer must not be NULL when calling subrequest_child_push");