]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Extend lease if it's less than expires_in and we're re-using the one currently assign...
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Thu, 4 Apr 2019 22:05:47 +0000 (18:05 -0400)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Thu, 4 Apr 2019 22:07:40 +0000 (18:07 -0400)
src/modules/rlm_redis_ippool/rlm_redis_ippool.c

index a53d38bed871c69979740aaecc7682c43e0b7634..f1118ae99bc7fd0e7395e760355c2fe7f4bc6a98 100644 (file)
@@ -191,37 +191,40 @@ static char lua_alloc_cmd[] =
        "  if expires_in > 0 then" EOL                                                                  /* 11 */
        "    ip = redis.call('HMGET', '{' .. KEYS[1] .. '}:"IPPOOL_ADDRESS_KEY":' .. exists, 'device', 'range', 'counter')" EOL /* 12 */
        "    if ip and (ip[1] == ARGV[3]) then" EOL                                                     /* 13 */
-       "      return {" STRINGIFY(_IPPOOL_RCODE_SUCCESS) ", exists, ip[2], expires_in, ip[3] }" EOL    /* 14 */
-       "    end" EOL                                                                                   /* 15 */
-       "  end" EOL                                                                                     /* 16 */
-       "end" EOL                                                                                       /* 17 */
+       "      if expires_in < ARGV[2] then" EOL                                                        /* 14 */
+       "        redis.call('ZADD', pool_key, ARGV[1] + ARGV[2], ip[1])" EOL                            /* 15 */
+       "      end" EOL                                                                                 /* 16 */
+       "      return {" STRINGIFY(_IPPOOL_RCODE_SUCCESS) ", exists, ip[2], expires_in, ip[3] }" EOL    /* 17 */
+       "    end" EOL                                                                                   /* 18 */
+       "  end" EOL                                                                                     /* 19 */
+       "end" EOL                                                                                       /* 20 */
 
        /*
         *      Else, get the IP address which expired the longest time ago.
         */
-       "ip = redis.call('ZREVRANGE', pool_key, -1, -1, 'WITHSCORES')" EOL                              /* 18 */
-       "if not ip or not ip[1] then" EOL                                                               /* 19 */
-       "  return {" STRINGIFY(_IPPOOL_RCODE_POOL_EMPTY) "}" EOL                                        /* 20 */
-       "end" EOL                                                                                       /* 21 */
-       "if ip[2] >= ARGV[1] then" EOL                                                                  /* 22 */
+       "ip = redis.call('ZREVRANGE', pool_key, -1, -1, 'WITHSCORES')" EOL                              /* 21 */
+       "if not ip or not ip[1] then" EOL                                                               /* 22 */
        "  return {" STRINGIFY(_IPPOOL_RCODE_POOL_EMPTY) "}" EOL                                        /* 23 */
        "end" EOL                                                                                       /* 24 */
-       "redis.call('ZADD', pool_key, ARGV[1] + ARGV[2], ip[1])" EOL                                    /* 25 */
+       "if ip[2] >= ARGV[1] then" EOL                                                                  /* 25 */
+       "  return {" STRINGIFY(_IPPOOL_RCODE_POOL_EMPTY) "}" EOL                                        /* 26 */
+       "end" EOL                                                                                       /* 27 */
+       "redis.call('ZADD', pool_key, ARGV[1] + ARGV[2], ip[1])" EOL                                    /* 28 */
 
        /*
         *      Set the device/gateway keys
         */
-       "address_key = '{' .. KEYS[1] .. '}:"IPPOOL_ADDRESS_KEY":' .. ip[1]" EOL                        /* 26 */
-       "redis.call('HMSET', address_key, 'device', ARGV[3], 'gateway', ARGV[4])" EOL                   /* 27 */
-       "redis.call('SET', device_key, ip[1])" EOL                                                      /* 28 */
-       "redis.call('EXPIRE', device_key, ARGV[2])" EOL                                                 /* 29 */
-       "return { " EOL                                                                                 /* 30 */
-       "  " STRINGIFY(_IPPOOL_RCODE_SUCCESS) "," EOL                                                   /* 31 */
-       "  ip[1], " EOL                                                                                 /* 32 */
-       "  redis.call('HGET', address_key, 'range'), " EOL                                              /* 33 */
-       "  tonumber(ARGV[2]), " EOL                                                                     /* 34 */
-       "  redis.call('HINCRBY', address_key, 'counter', 1)" EOL                                        /* 35 */
-       "}" EOL;                                                                                        /* 36 */
+       "address_key = '{' .. KEYS[1] .. '}:"IPPOOL_ADDRESS_KEY":' .. ip[1]" EOL                        /* 29 */
+       "redis.call('HMSET', address_key, 'device', ARGV[3], 'gateway', ARGV[4])" EOL                   /* 30 */
+       "redis.call('SET', device_key, ip[1])" EOL                                                      /* 31 */
+       "redis.call('EXPIRE', device_key, ARGV[2])" EOL                                                 /* 32 */
+       "return { " EOL                                                                                 /* 33 */
+       "  " STRINGIFY(_IPPOOL_RCODE_SUCCESS) "," EOL                                                   /* 34 */
+       "  ip[1], " EOL                                                                                 /* 35 */
+       "  redis.call('HGET', address_key, 'range'), " EOL                                              /* 36 */
+       "  tonumber(ARGV[2]), " EOL                                                                     /* 37 */
+       "  redis.call('HINCRBY', address_key, 'counter', 1)" EOL                                        /* 38 */
+       "}" EOL;                                                                                        /* 39 */
 static char lua_alloc_digest[(SHA1_DIGEST_LENGTH * 2) + 1];
 
 /** Lua script for updating leases