From: Arran Cudbard-Bell Date: Thu, 4 Apr 2019 22:05:47 +0000 (-0400) Subject: Extend lease if it's less than expires_in and we're re-using the one currently assign... X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2b8795c3d3d44bbf4e794de2d28f4bb93c5d9859;p=thirdparty%2Ffreeradius-server.git Extend lease if it's less than expires_in and we're re-using the one currently assigned to the device --- diff --git a/src/modules/rlm_redis_ippool/rlm_redis_ippool.c b/src/modules/rlm_redis_ippool/rlm_redis_ippool.c index a53d38bed87..f1118ae99bc 100644 --- a/src/modules/rlm_redis_ippool/rlm_redis_ippool.c +++ b/src/modules/rlm_redis_ippool/rlm_redis_ippool.c @@ -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