]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
lua_release_cmd: always reset expiry time (for static leases too)
authorMax Khon <fjoe@samodelkin.net>
Wed, 28 Jun 2023 04:35:48 +0000 (11:35 +0700)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Thu, 29 Jun 2023 14:27:13 +0000 (10:27 -0400)
src/modules/rlm_redis_ippool/rlm_redis_ippool.c

index 47adef56b562d472c655b80ed59f9ee61536414a..4196426ffb4c11710c1c8791f5ef20e90beb4fe2 100644 (file)
@@ -460,16 +460,17 @@ static char lua_release_cmd[] =
        "end" EOL                                                                       /* 14 */
 
        /*
-        *      Set expiry time to now() - 1 if it is not static
+        *      Set expiry time to now() - 1
         */
        "pool_key = '{' .. KEYS[1] .. '}:"IPPOOL_POOL_KEY"'" EOL                        /* 15 */
        "found = tonumber(redis.call('ZSCORE', pool_key, ARGV[2]))" EOL                 /* 16 */
-       "if found < " STRINGIFY(IPPOOL_STATIC_BIT) " then" EOL                          /* 17 */
-       "  redis.call('ZADD', pool_key, 'XX', ARGV[1] - 1, ARGV[2])" EOL                /* 18 */
+       "local static = found > " STRINGIFY(IPPOOL_STATIC_BIT) EOL                      /* 17 */
+       "redis.call('ZADD', pool_key, 'XX', ARGV[1] - 1 + (static and " STRINGIFY(IPPOOL_STATIC_BIT) " or 0), ARGV[2])" EOL             /* 18 */
 
        /*
         *      Remove the association between the device and a lease
         */
+       "if not static then" EOL                                                        /* 18 */
        "  owner_key = '{' .. KEYS[1] .. '}:"IPPOOL_OWNER_KEY":' .. ARGV[3]" EOL        /* 19 */
        "  redis.call('DEL', owner_key)" EOL                                            /* 20 */
        "end" EOL                                                                       /* 21 */