]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
add comments and macros for mod_action
authorAlan T. DeKok <aland@freeradius.org>
Fri, 11 Jul 2025 11:48:20 +0000 (07:48 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Fri, 11 Jul 2025 12:07:47 +0000 (08:07 -0400)
src/lib/server/virtual_servers.c
src/lib/unlang/child_request.c
src/lib/unlang/edit.c
src/lib/unlang/mod_action.c
src/lib/unlang/mod_action.h
src/lib/unlang/subrequest.c

index 4f341df3228205a827529f322d1df40ef948aa5c..633ebdce44fea5df6e9a712a70508794b21f0a3f 100644 (file)
@@ -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,
        };
index 2236e48d67ec059263e88d7f2ae21f6f7ae61beb..6ab51f316d56dfee4eedd2e9fa2a6b3c099de815 100644 (file)
@@ -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 */
index 5449f18bb46f9f1a19c8194723256a8a8280b3db..4abe1e624e483ebf07f354f8ac3af98cc7d284b7 100644 (file)
@@ -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));
index 303961fdaa561a92b971b120eead824295076a97..a719741d594652f197bafdc8550ffdf41ab0aa86 100644 (file)
@@ -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
 };
index a9df7162a5cc218f059d11214801c622a9bc1d25..0c3292e3d7791d7140bd5896787e830033f35707 100644 (file)
@@ -31,23 +31,19 @@ extern "C" {
 #include <freeradius-devel/server/rcode.h>
 #include <freeradius-devel/util/retry.h>
 
-/* 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;
index 5cfa9ba0b8f13e52287a24e1057817d49bdad142..6e5fb5b11cecccd91ca94967511bfa63d6f51e26 100644 (file)
@@ -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");