]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Remove IP-Pool.Action and use module methods instead
authorNick Porter <nick@portercomputing.co.uk>
Thu, 29 Jun 2023 08:43:16 +0000 (09:43 +0100)
committerNick Porter <nick@portercomputing.co.uk>
Thu, 29 Jun 2023 09:46:47 +0000 (10:46 +0100)
share/dictionary/freeradius/dictionary.freeradius.internal.ippool
src/modules/rlm_redis_ippool/rlm_redis_ippool.c
src/tests/modules/redis_ippool/release.unlang
src/tests/modules/redis_ippool/static.unlang
src/tests/modules/redis_ippool/static_unassign.unlang
src/tests/modules/redis_ippool/update.unlang
src/tests/modules/redis_ippool/update_alloc.unlang

index 7743656fdc2f2010fa69bb77c2143b897bfd3d8a..2996375f9df04d6ee2792f064a0b75587d2e1a6e 100644 (file)
@@ -20,14 +20,6 @@ ATTRIBUTE    Name                                    1       string  # Generic identifier for the IP pool to allocate fro
 ATTRIBUTE      Name-NA                                 2       string  # DHCPv6 - Non-Temporary association pool
 ATTRIBUTE      Name-PD                                 3       string  # DHCPv6 - Prefix-deligation pool
 ATTRIBUTE      Name-TA                                 4       string  # DHCPv6 - Temporary association pool
-ATTRIBUTE      Action                                  5       integer
-
-VALUE  Action                          Allocate                1
-# Renew == Update (they're the same action)
-VALUE  Action                          Renew                   2
-VALUE  Action                          Update                  2
-VALUE  Action                          Release                 3
-VALUE  Action                          Bulk-Release            4
 
 ATTRIBUTE      Range                                   6       string
 END-TLV                IP-Pool
index 1e9cee97c79787a7647a4074016e4ebc8ac165d2..1425ad3652b02c8b3fd38371f1237aa163e29022 100644 (file)
@@ -156,42 +156,6 @@ static const call_method_env_t redis_ippool_method_env = {
        .env = redis_ippool_call_env
 };
 
-static fr_dict_t const *dict_freeradius;
-static fr_dict_t const *dict_radius;
-
-extern fr_dict_autoload_t rlm_redis_ippool_dict[];
-fr_dict_autoload_t rlm_redis_ippool_dict[] = {
-       { .out = &dict_freeradius, .proto = "freeradius" },
-       { .out = &dict_radius, .proto = "radius" },
-       { NULL }
-};
-
-static fr_dict_attr_t const *attr_pool_action;
-static fr_dict_attr_t const *attr_acct_status_type;
-
-extern fr_dict_attr_autoload_t rlm_redis_ippool_dict_attr[];
-fr_dict_attr_autoload_t rlm_redis_ippool_dict_attr[] = {
-       { .out = &attr_pool_action, .name = "IP-Pool.Action", .type = FR_TYPE_UINT32, .dict = &dict_freeradius },
-       { .out = &attr_acct_status_type, .name = "Acct-Status-Type", .type = FR_TYPE_UINT32, .dict = &dict_radius },
-       { NULL }
-};
-
-static fr_value_box_t const    *enum_acct_status_type_start;
-static fr_value_box_t const    *enum_acct_status_type_interim_update;
-static fr_value_box_t const    *enum_acct_status_type_stop;
-static fr_value_box_t const    *enum_acct_status_type_on;
-static fr_value_box_t const    *enum_acct_status_type_off;
-
-extern fr_dict_enum_autoload_t rlm_redis_ippool_dict_enum[];
-fr_dict_enum_autoload_t rlm_redis_ippool_dict_enum[] = {
-       { .out = &enum_acct_status_type_start, .name = "Start", .attr = &attr_acct_status_type },
-       { .out = &enum_acct_status_type_interim_update, .name = "Interim-Update", .attr = &attr_acct_status_type },
-       { .out = &enum_acct_status_type_interim_update, .name = "Stop", .attr = &attr_acct_status_type},
-       { .out = &enum_acct_status_type_on, .name = "Accounting-On", .attr = &attr_acct_status_type },
-       { .out = &enum_acct_status_type_off, .name = "Accounting-Off", .attr = &attr_acct_status_type},
-       { NULL }
-};
-
 #define EOL "\n"
 
 /** Lua script for allocating new leases
@@ -1187,100 +1151,24 @@ static unlang_action_t mod_action(rlm_rcode_t *p_result, module_ctx_t const *mct
        }
 }
 
-static unlang_action_t CC_HINT(nonnull) mod_accounting(rlm_rcode_t *p_result, module_ctx_t const *mctx, request_t *request)
-{
-       fr_pair_t       *vp;
-
-       /*
-        *      IP-Pool.Action override
-        */
-       vp = fr_pair_find_by_da(&request->control_pairs, NULL, attr_pool_action);
-       if (vp) return mod_action(p_result, mctx, request, vp->vp_uint32);
-
-       /*
-        *      Otherwise, guess the action by Acct-Status-Type
-        */
-       vp = fr_pair_find_by_da(&request->request_pairs, NULL, attr_acct_status_type);
-       if (!vp) {
-               RDEBUG2("Couldn't find &request.Acct-Status-Type or &control.IP-Pool.Action, doing nothing...");
-               RETURN_MODULE_NOOP;
-       }
-
-       if ((vp->vp_uint32 == enum_acct_status_type_start->vb_uint32) ||
-           (vp->vp_uint32 == enum_acct_status_type_interim_update->vb_uint32)) {
-               return mod_action(p_result, mctx, request, POOL_ACTION_UPDATE);
-
-       } else if (vp->vp_uint32 == enum_acct_status_type_stop->vb_uint32) {
-               return mod_action(p_result, mctx, request, POOL_ACTION_RELEASE);
-
-       } else if ((vp->vp_uint32 == enum_acct_status_type_on->vb_uint32) ||
-                  (vp->vp_uint32 == enum_acct_status_type_off->vb_uint32)) {
-               return mod_action(p_result, mctx, request, POOL_ACTION_BULK_RELEASE);
-
-       }
-
-       RETURN_MODULE_NOOP;
-}
-
 static unlang_action_t CC_HINT(nonnull) mod_alloc(rlm_rcode_t *p_result, module_ctx_t const *mctx, request_t *request)
 {
-       fr_pair_t       *vp;
-
-       /*
-        *      Unless it's overridden the default action is to allocate
-        *      when called in Post-Auth.
-        */
-       vp = fr_pair_find_by_da(&request->control_pairs, NULL, attr_pool_action);
-       return mod_action(p_result, mctx, request, vp ? vp->vp_uint32 : POOL_ACTION_ALLOCATE);
-}
-
-static unlang_action_t CC_HINT(nonnull) mod_post_auth(rlm_rcode_t *p_result, module_ctx_t const *mctx, request_t *request)
-{
-       fr_pair_t       *vp;
-       ippool_action_t action = POOL_ACTION_ALLOCATE;
-
-       /*
-        *      Unless it's overridden the default action is to allocate
-        *      when called in Post-Auth.
-        */
-       vp = fr_pair_find_by_da(&request->control_pairs, NULL, attr_pool_action);
-       if (vp) {
-               if ((vp->vp_uint32 > 0) && (vp->vp_uint32 <= POOL_ACTION_BULK_RELEASE)) {
-                       action = vp->vp_uint32;
-
-               } else {
-                       RWDEBUG("Ignoring invalid action %d", vp->vp_uint32);
-                       RETURN_MODULE_NOOP;
-               }
-       }
-
-       return mod_action(p_result, mctx, request, action);
+       return mod_action(p_result, mctx, request, POOL_ACTION_ALLOCATE);
 }
 
 static unlang_action_t CC_HINT(nonnull) mod_update(rlm_rcode_t *p_result, module_ctx_t const *mctx, request_t *request)
 {
-       fr_pair_t       *vp;
-
-       /*
-        *      Unless it's overridden the default action is to update
-        *      when called by DHCP request
-        */
-
-       vp = fr_pair_find_by_da(&request->control_pairs, NULL, attr_pool_action);
-       return mod_action(p_result, mctx, request, vp ? vp->vp_uint32 : POOL_ACTION_UPDATE);
+       return mod_action(p_result, mctx, request, POOL_ACTION_UPDATE);
 }
 
 static unlang_action_t CC_HINT(nonnull) mod_release(rlm_rcode_t *p_result, module_ctx_t const *mctx, request_t *request)
 {
-       fr_pair_t       *vp;
-
-       /*
-        *      Unless it's overridden the default action is to release
-        *      when called by DHCP release
-        */
+       return mod_action(p_result, mctx, request, POOL_ACTION_RELEASE);
+}
 
-       vp = fr_pair_find_by_da(&request->control_pairs, NULL, attr_pool_action);
-       return mod_action(p_result, mctx, request, vp ? vp->vp_uint32 : POOL_ACTION_RELEASE);
+static unlang_action_t CC_HINT(nonnull) mod_bulk_release(rlm_rcode_t *p_result, module_ctx_t const *mctx, request_t *request)
+{
+       return mod_action(p_result, mctx, request, POOL_ACTION_BULK_RELEASE);
 }
 
 static int mod_instantiate(module_inst_ctx_t const *mctx)
@@ -1350,8 +1238,16 @@ module_rlm_t rlm_redis_ippool = {
                 */
                { .name1 = "recv",              .name2 = "access-request",      .method = mod_alloc,
                  .method_env = &redis_ippool_method_env },
+               { .name1 = "accounting",        .name2 = "start",               .method = mod_update,
+                 .method_env = &redis_ippool_method_env },
+               { .name1 = "accounting",        .name2 = "alive",               .method = mod_update,
+                 .method_env = &redis_ippool_method_env },
                { .name1 = "accounting",        .name2 = "stop",                .method = mod_release,
                  .method_env = &redis_ippool_method_env },
+               { .name1 = "accounting",        .name2 = "accounting-on",       .method = mod_bulk_release,
+                 .method_env = &redis_ippool_method_env },
+               { .name1 = "accounting",        .name2 = "accounting-off",      .method = mod_bulk_release,
+                 .method_env = &redis_ippool_method_env },
 
                /*
                 *      DHCPv4
@@ -1374,9 +1270,21 @@ module_rlm_t rlm_redis_ippool = {
                 */
                { .name1 = "recv",              .name2 = CF_IDENT_ANY,          .method = mod_update,
                  .method_env = &redis_ippool_method_env },
-               { .name1 = "accounting",        .name2 = CF_IDENT_ANY,          .method = mod_accounting,
+               { .name1 = "send",              .name2 = CF_IDENT_ANY,          .method = mod_alloc,
+                 .method_env = &redis_ippool_method_env },
+
+               /*
+                *      Named methods matching module operations
+                */
+               { .name1 = "allocate",          .name2 = CF_IDENT_ANY,          .method = mod_alloc,
+                 .method_env = &redis_ippool_method_env },
+               { .name1 = "update",            .name2 = CF_IDENT_ANY,          .method = mod_update,
+                 .method_env = &redis_ippool_method_env },
+               { .name1 = "renew",             .name2 = CF_IDENT_ANY,          .method = mod_update,
+                 .method_env = &redis_ippool_method_env },
+               { .name1 = "release",           .name2 = CF_IDENT_ANY,          .method = mod_release,
                  .method_env = &redis_ippool_method_env },
-               { .name1 = "send",              .name2 = CF_IDENT_ANY,          .method = mod_post_auth,
+               { .name1 = "bulk-release",      .name2 = CF_IDENT_ANY,          .method = mod_bulk_release,
                  .method_env = &redis_ippool_method_env },
                MODULE_NAME_TERMINATOR
        }
index 04482434b1f95425e5dbade47e4278e84301199a..7a6c6ba5956ff26bf2eaec5fb508474890952b2e 100644 (file)
@@ -28,9 +28,8 @@ if (!(&reply.Framed-IP-Address == 192.168.0.1)) {
 #  Release the IP address
 #
 &Framed-IP-Address := &reply.Framed-IP-Address
-&control.IP-Pool.Action := Release
 
-redis_ippool {
+redis_ippool.release {
        invalid = 1
 }
 if (!(updated)) {
@@ -74,9 +73,8 @@ if (%(integer:%{Tmp-Date-0}) - %(redis:ZSCORE {%{control.IP-Pool.Name}}:pool %{r
 #  Release the IP address again (should still be fine)
 #
 &Framed-IP-Address := &reply.Framed-IP-Address
-&control.IP-Pool.Action := Release
 
-redis_ippool {
+redis_ippool.release {
        invalid = 1
 }
 if (updated) {
index a9cf8a0c0a976a63aac0b7bec50419b09b386aa5..3b44b896e8ea27715b32eac4db9cca0bf71d0297 100644 (file)
@@ -41,9 +41,8 @@ if (!(&reply.Session-Timeout == 30)) {
 #  Check that renewal does not mess with static IP
 #
 &Framed-IP-Address := &reply.Framed-IP-Address
-&control.IP-Pool.Action := Renew
 
-redis_ippool {
+redis_ippool.renew {
        invalid = 1
 }
 
@@ -64,9 +63,7 @@ if (!(&reply.Session-Timeout == 60)) {
 #
 #  Check that releasing does not mess with static IP
 #
-&control.IP-Pool.Action := Release
-
-redis_ippool {
+redis_ippool.release {
        invalid = 1
 }
 if (!(updated)) {
index 42812366baea9fca2e9f9252e369666928c1f3aa..078f6369d14d7bb6092057c58fd70b24f597b193 100644 (file)
@@ -62,18 +62,15 @@ if ("%(redis:TTL {%{control.IP-Pool.Name}}:device:%{Calling-Station-Id})" < 20)
 #  Check that renewal still works as we are within the exipiry time
 #
 &Framed-IP-Address := &reply.Framed-IP-Address
-&control.IP-Pool.Action := Renew
 
-redis_ippool {
+redis_ippool.renew {
        invalid = 1
 }
 
 #
 #  Check that releasing now frees
 #
-&control.IP-Pool.Action := Release
-
-redis_ippool {
+redis_ippool.release {
        invalid = 1
 }
 if (!updated) {
@@ -106,8 +103,7 @@ if ("%(redis:ZSCORE {%{control.IP-Pool.Name}%}:pool %{reply.Framed-IP-Address})"
 &request -= &Framed-IP-Address[*]
 &Calling-Station-Id := '00:11:22:33:44:55'
 
-&control.IP-Pool.Action := Allocate
-redis_ippool {
+redis_ippool.allocate {
        invalid = 1
 }
 
index b627afbb6efb30a88f9047febf1c872d81288767..99a7a8764c54fb047d62c441ddd45078dd65f516 100644 (file)
@@ -37,9 +37,8 @@ if !("%(redis:HGET {%{control.IP-Pool.Name}}:ip:%{reply.Framed-IP-Address} gatew
 # 6. Verify that the lease time is extended
 &Framed-IP-Address := &reply.Framed-IP-Address
 &NAS-IP-Address := 127.0.0.2
-&control.IP-Pool.Action := Renew
 
-redis_ippool
+redis_ippool.renew
 if (!updated) {
        test_fail
 }
@@ -84,7 +83,7 @@ if !(&reply.IP-Pool.Range && (&reply.IP-Pool.Range == '192.168.0.0')) {
 # Change the ip address to one that doesn't exist in the pool and check we *can't* update it
 &Framed-IP-Address := 192.168.3.1
 
-redis_ippool {
+redis_ippool.renew {
        invalid = 1
 }
 # 14.
@@ -96,7 +95,7 @@ if (!notfound) {
 # 15. Now change the calling station ID and check that we *can't* update the lease
 &Calling-Station-ID := 'naughty'
 
-redis_ippool {
+redis_ippool.renew {
        invalid = 1
 }
 if (!invalid) {
index 042ebf0aca3d78a9aa595ff1a06e7df0478300a4..f91a7dada54968ef0e844f92a38d53deebcdaf66 100644 (file)
@@ -21,9 +21,8 @@ if (!updated) {
 #
 &Framed-IP-Address := 192.168.0.1
 &NAS-IP-Address := 127.0.0.1
-&control.IP-Pool.Action := Renew
 
-redis_ippool
+redis_ippool.renew
 
 # 3. Check the expiry attribute is present and correct
 if !(&reply.Session-Timeout == 60) {