The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Data Structures | Macros | Typedefs | Enumerations | Functions | Variables
rlm_redis_ippool_tool.c File Reference

IP population tool. More...

#include <freeradius-devel/server/cf_parse.h>
#include <freeradius-devel/util/debug.h>
#include "base.h"
#include "cluster.h"
#include "redis_ippool.h"
+ Include dependency graph for rlm_redis_ippool_tool.c:

Go to the source code of this file.

Data Structures

struct  ippool_tool_lease_t
 
struct  ippool_tool_operation_t
 A single pool operation. More...
 
struct  ippool_tool_owner_t
 
struct  ippool_tool_stats_t
 
struct  ippool_tool_t
 
struct  redis_driver_conf_t
 

Macros

#define ADD_ACTION(_action)
 
#define EOL   "\n"
 
#define IPPOOL_BUILD_IP_KEY_FROM_STR(_buff, _p, _key, _key_len, _ip_str)
 
#define MAX_PIPELINED   100000
 
#define STATS_COMMANDS_TOTAL   14
 

Typedefs

typedef enum ippool_tool_action ippool_tool_action_t
 Pool management actions. More...
 
typedef int(* redis_ippool_process_t) (void *out, fr_ipaddr_t const *ipaddr, redisReply const *reply)
 
typedef int(* redis_ippool_queue_t) (redis_driver_conf_t *inst, fr_redis_conn_t *conn, uint8_t const *key_prefix, size_t key_prefix_len, uint8_t const *range, size_t range_len, fr_ipaddr_t *ipaddr, uint8_t prefix, void *uctx)
 

Enumerations

enum  ippool_tool_action {
  IPPOOL_TOOL_NOOP = 0 ,
  IPPOOL_TOOL_ADD ,
  IPPOOL_TOOL_REMOVE ,
  IPPOOL_TOOL_RELEASE ,
  IPPOOL_TOOL_SHOW ,
  IPPOOL_TOOL_MODIFY ,
  IPPOOL_TOOL_ASSIGN ,
  IPPOOL_TOOL_UNASSIGN
}
 Pool management actions. More...
 

Functions

static int _driver_add_lease_enqueue (UNUSED redis_driver_conf_t *inst, fr_redis_conn_t *conn, uint8_t const *key_prefix, size_t key_prefix_len, uint8_t const *range, size_t range_len, fr_ipaddr_t *ipaddr, uint8_t prefix, UNUSED void *uctx)
 Enqueue lease addition commands. More...
 
static int _driver_add_lease_process (void *out, UNUSED fr_ipaddr_t const *ipaddr, redisReply const *reply)
 Count the number of leases we actually added. More...
 
static int _driver_assign_lease_enqueue (UNUSED redis_driver_conf_t *inst, fr_redis_conn_t *conn, uint8_t const *key_prefix, size_t key_prefix_len, uint8_t const *range, size_t range_len, fr_ipaddr_t *ipaddr, uint8_t prefix, void *uctx)
 Enqueue static lease assignment commands. More...
 
static int _driver_assign_lease_process (void *out, UNUSED fr_ipaddr_t const *ipaddr, redisReply const *reply)
 
static int _driver_modify_lease_enqueue (UNUSED redis_driver_conf_t *inst, fr_redis_conn_t *conn, uint8_t const *key_prefix, size_t key_prefix_len, uint8_t const *range, size_t range_len, fr_ipaddr_t *ipaddr, uint8_t prefix, UNUSED void *uctx)
 Enqueue lease removal commands. More...
 
static int _driver_modify_lease_process (void *out, UNUSED fr_ipaddr_t const *ipaddr, redisReply const *reply)
 Count the number of leases we modified. More...
 
static int _driver_release_lease_enqueue (UNUSED redis_driver_conf_t *inst, fr_redis_conn_t *conn, uint8_t const *key_prefix, size_t key_prefix_len, UNUSED uint8_t const *range, UNUSED size_t range_len, fr_ipaddr_t *ipaddr, uint8_t prefix, UNUSED void *uctx)
 Release a lease by setting its score back to zero. More...
 
static int _driver_release_lease_process (void *out, UNUSED fr_ipaddr_t const *ipaddr, redisReply const *reply)
 Count the number of leases we released. More...
 
static int _driver_remove_lease_enqueue (UNUSED redis_driver_conf_t *inst, fr_redis_conn_t *conn, uint8_t const *key_prefix, size_t key_prefix_len, UNUSED uint8_t const *range, UNUSED size_t range_len, fr_ipaddr_t *ipaddr, uint8_t prefix, UNUSED void *uctx)
 Enqueue lease removal commands. More...
 
static int _driver_remove_lease_process (void *out, UNUSED fr_ipaddr_t const *ipaddr, redisReply const *reply)
 Count the number of leases we removed. More...
 
static int _driver_show_lease_enqueue (UNUSED redis_driver_conf_t *inst, fr_redis_conn_t *conn, uint8_t const *key_prefix, size_t key_prefix_len, UNUSED uint8_t const *range, UNUSED size_t range_len, fr_ipaddr_t *ipaddr, uint8_t prefix, UNUSED void *uctx)
 Enqueue commands to retrieve lease information. More...
 
static int _driver_show_lease_process (void *out, fr_ipaddr_t const *ipaddr, redisReply const *reply)
 Enqueue commands to retrieve lease information. More...
 
static int _driver_unassign_lease_enqueue (UNUSED redis_driver_conf_t *inst, fr_redis_conn_t *conn, uint8_t const *key_prefix, size_t key_prefix_len, UNUSED uint8_t const *range, UNUSED size_t range_len, fr_ipaddr_t *ipaddr, uint8_t prefix, void *uctx)
 Enqueue static lease un-assignment commands. More...
 
static int _driver_unassign_lease_process (void *out, UNUSED fr_ipaddr_t const *ipaddr, redisReply const *reply)
 
static int driver_add_lease (void *out, void *instance, ippool_tool_operation_t const *op)
 Add a range of prefixes. More...
 
static int driver_assign_lease (void *out, void *instance, ippool_tool_operation_t const *op, char const *owner)
 Add static lease assignments. More...
 
static int driver_do_lease (void *out, void *instance, ippool_tool_operation_t const *op, redis_ippool_queue_t enqueue, redis_ippool_process_t process, void *uctx)
 Add a net to the pool. More...
 
static ssize_t driver_get_pools (TALLOC_CTX *ctx, uint8_t **out[], void *instance)
 Return the pools available across the cluster. More...
 
static int driver_get_stats (ippool_tool_stats_t *out, void *instance, uint8_t const *key_prefix, size_t key_prefix_len)
 
static int driver_init (TALLOC_CTX *ctx, CONF_SECTION *conf, void **instance)
 Driver initialization function. More...
 
static int driver_modify_lease (void *out, void *instance, ippool_tool_operation_t const *op)
 Remove a range of leases. More...
 
static int driver_release_lease (void *out, void *instance, ippool_tool_operation_t const *op)
 Release a range of leases. More...
 
static int driver_remove_lease (void *out, void *instance, ippool_tool_operation_t const *op)
 Remove a range of leases. More...
 
static int driver_show_lease (void *out, void *instance, ippool_tool_operation_t const *op)
 Show information about leases. More...
 
static int driver_unassign_lease (void *out, void *instance, ippool_tool_operation_t const *op, char const *owner)
 Unassign static lease assignments. More...
 
static bool ipaddr_next (fr_ipaddr_t *ipaddr, fr_ipaddr_t const *end, uint8_t prefix)
 Iterate over range of IP addresses. More...
 
int main (int argc, char *argv[])
 
static int parse_ip_range (fr_ipaddr_t *start_out, fr_ipaddr_t *end_out, char const *ip_str, uint8_t prefix)
 Convert an IP range or CIDR mask to a start and stop address. More...
 
static int8_t pool_cmp (void const *a, void const *b)
 Compare two pool names. More...
 
static uint32_t uint32_gen_mask (uint8_t bits)
 
static NEVER_RETURNS void usage (int ret)
 

Variables

static char lua_assign_cmd []
 Lua script for assigning a static lease. More...
 
static char lua_release_cmd []
 Lua script for releasing a lease. More...
 
static char lua_remove_cmd []
 Lua script for removing a lease. More...
 
static char lua_unassign_cmd []
 Lua script for un-assigning a static lease. More...
 
static char const * name
 
static conf_parser_t redis_config []
 

Detailed Description

IP population tool.

Id
d27f9a8a2ec250049f4577de32a8dea34a2dcadb
Author
Arran Cudbard-Bell

Definition in file rlm_redis_ippool_tool.c.


Data Structure Documentation

◆ ippool_tool_lease_t

struct ippool_tool_lease_t

Definition at line 70 of file rlm_redis_ippool_tool.c.

+ Collaboration diagram for ippool_tool_lease_t:
Data Fields
uint8_t const * device Last device id.
size_t device_len
uint8_t const * gateway Last gateway id.
size_t gateway_len
fr_ipaddr_t ipaddr Prefix or address.
time_t next_event Last state change.
uint8_t const * range Range the lease belongs to.
size_t range_len

◆ ippool_tool_operation_t

struct ippool_tool_operation_t

A single pool operation.

Definition at line 54 of file rlm_redis_ippool_tool.c.

+ Collaboration diagram for ippool_tool_operation_t:
Data Fields
ippool_tool_action_t action What to do to the leases described by net/prefix.
fr_ipaddr_t end End address.
char const * name Original range or CIDR string.
uint8_t const * pool Pool identifier.
size_t pool_len Length of the pool identifier.
uint8_t prefix Prefix - The bits between the address mask, and the prefix form the addresses to be modified in the pool.
uint8_t const * range Range identifier.
size_t range_len Length of the range identifier.
fr_ipaddr_t start Start address.

◆ ippool_tool_owner_t

struct ippool_tool_owner_t

Definition at line 111 of file rlm_redis_ippool_tool.c.

Data Fields
char const * owner

◆ ippool_tool_stats_t

struct ippool_tool_stats_t

Definition at line 81 of file rlm_redis_ippool_tool.c.

Data Fields
uint64_t expiring_1d Addresses that expire in the next day.
uint64_t expiring_1h Addresses that expire in the next hour.
uint64_t expiring_1m Addresses that expire in the next minute.
uint64_t expiring_30m Addresses that expire in the next 30 minutes.
uint64_t free Addresses in use.
uint64_t static_1d Static leases that should renew in the next day.
uint64_t static_1h Static leases that should renew in the next hour.
uint64_t static_1m Static leases that should renew in the next minute.
uint64_t static_30m Static leases that should renew in the next 30 minutes.
uint64_t static_free Static leases that have not been requested.
uint64_t static_tot Static assignments configured.
uint64_t total Addresses available.

◆ ippool_tool_t

struct ippool_tool_t

Definition at line 106 of file rlm_redis_ippool_tool.c.

+ Collaboration diagram for ippool_tool_t:
Data Fields
CONF_SECTION * cs
void * driver

◆ redis_driver_conf_t

struct redis_driver_conf_t

Definition at line 101 of file rlm_redis_ippool_tool.c.

+ Collaboration diagram for redis_driver_conf_t:
Data Fields
fr_redis_cluster_t * cluster
fr_redis_conf_t conf Connection parameters for the Redis server.

Macro Definition Documentation

◆ ADD_ACTION

#define ADD_ACTION (   _action)
Value:
do { \
if (p >= end) { \
ERROR("Too many actions, max is " STRINGIFY(sizeof(ops))); \
usage(64); \
} \
p->action = _action; \
p->name = optarg; \
p++; \
need_pool = true; \
} while (0)
#define STRINGIFY(x)
Definition: build.h:195

◆ EOL

#define EOL   "\n"

Definition at line 154 of file rlm_redis_ippool_tool.c.

◆ IPPOOL_BUILD_IP_KEY_FROM_STR

#define IPPOOL_BUILD_IP_KEY_FROM_STR (   _buff,
  _p,
  _key,
  _key_len,
  _ip_str 
)
Value:
do { \
ssize_t _slen; \
*_p++ = '{'; \
memcpy(_p, _key, _key_len); \
_p += _key_len; \
_slen = strlcpy((char *)_p, "}:"IPPOOL_ADDRESS_KEY":", sizeof(_buff) - (_p - _buff)); \
if (is_truncated((size_t)_slen, sizeof(_buff) - (_p - _buff))) { \
ERROR("IP key too long"); \
return 0;\
} \
_p += (size_t)_slen;\
_p += strlcpy((char *)_p, _ip_str, sizeof(_buff) - (_p - _buff)); \
} while (0)
unsigned long int size_t
Definition: merged_model.c:25
#define is_truncated(_ret, _max)
Definition: print.h:48
#define IPPOOL_ADDRESS_KEY
Definition: redis_ippool.h:58
size_t strlcpy(char *dst, char const *src, size_t siz)
Definition: strlcpy.c:34

Definition at line 122 of file rlm_redis_ippool_tool.c.

◆ MAX_PIPELINED

#define MAX_PIPELINED   100000

Definition at line 35 of file rlm_redis_ippool_tool.c.

◆ STATS_COMMANDS_TOTAL

#define STATS_COMMANDS_TOTAL   14

Typedef Documentation

◆ ippool_tool_action_t

Pool management actions.

◆ redis_ippool_process_t

typedef int(* redis_ippool_process_t) (void *out, fr_ipaddr_t const *ipaddr, redisReply const *reply)

Definition at line 120 of file rlm_redis_ippool_tool.c.

◆ redis_ippool_queue_t

typedef int(* redis_ippool_queue_t) (redis_driver_conf_t *inst, fr_redis_conn_t *conn, uint8_t const *key_prefix, size_t key_prefix_len, uint8_t const *range, size_t range_len, fr_ipaddr_t *ipaddr, uint8_t prefix, void *uctx)

Definition at line 115 of file rlm_redis_ippool_tool.c.

Enumeration Type Documentation

◆ ippool_tool_action

Pool management actions.

Enumerator
IPPOOL_TOOL_NOOP 

Do nothing.

IPPOOL_TOOL_ADD 

Add one or more IP addresses.

IPPOOL_TOOL_REMOVE 

Remove one or more IP addresses.

IPPOOL_TOOL_RELEASE 

Release one or more IP addresses.

IPPOOL_TOOL_SHOW 

Show one or more IP addresses.

IPPOOL_TOOL_MODIFY 

Modify attributes of one or more IP addresses.

IPPOOL_TOOL_ASSIGN 

Assign a static IP address to a device.

IPPOOL_TOOL_UNASSIGN 

Remove static IP address assignment.

Definition at line 40 of file rlm_redis_ippool_tool.c.

Function Documentation

◆ _driver_add_lease_enqueue()

static int _driver_add_lease_enqueue ( UNUSED redis_driver_conf_t inst,
fr_redis_conn_t conn,
uint8_t const *  key_prefix,
size_t  key_prefix_len,
uint8_t const *  range,
size_t  range_len,
fr_ipaddr_t ipaddr,
uint8_t  prefix,
UNUSED void *  uctx 
)
static

Enqueue lease addition commands.

Definition at line 735 of file rlm_redis_ippool_tool.c.

+ Here is the caller graph for this function:

◆ _driver_add_lease_process()

static int _driver_add_lease_process ( void *  out,
UNUSED fr_ipaddr_t const *  ipaddr,
redisReply const *  reply 
)
static

Count the number of leases we actually added.

This isn't necessarily the same as the number of ZADDs, as leases may already exist.

Definition at line 716 of file rlm_redis_ippool_tool.c.

+ Here is the caller graph for this function:

◆ _driver_assign_lease_enqueue()

static int _driver_assign_lease_enqueue ( UNUSED redis_driver_conf_t inst,
fr_redis_conn_t conn,
uint8_t const *  key_prefix,
size_t  key_prefix_len,
uint8_t const *  range,
size_t  range_len,
fr_ipaddr_t ipaddr,
uint8_t  prefix,
void *  uctx 
)
static

Enqueue static lease assignment commands.

Definition at line 851 of file rlm_redis_ippool_tool.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _driver_assign_lease_process()

static int _driver_assign_lease_process ( void *  out,
UNUSED fr_ipaddr_t const *  ipaddr,
redisReply const *  reply 
)
static

Definition at line 839 of file rlm_redis_ippool_tool.c.

+ Here is the caller graph for this function:

◆ _driver_modify_lease_enqueue()

static int _driver_modify_lease_enqueue ( UNUSED redis_driver_conf_t inst,
fr_redis_conn_t conn,
uint8_t const *  key_prefix,
size_t  key_prefix_len,
uint8_t const *  range,
size_t  range_len,
fr_ipaddr_t ipaddr,
uint8_t  prefix,
UNUSED void *  uctx 
)
static

Enqueue lease removal commands.

This modifys the lease from the expiry heap, and the data associated with the lease.

Definition at line 808 of file rlm_redis_ippool_tool.c.

+ Here is the caller graph for this function:

◆ _driver_modify_lease_process()

static int _driver_modify_lease_process ( void *  out,
UNUSED fr_ipaddr_t const *  ipaddr,
redisReply const *  reply 
)
static

Count the number of leases we modified.

Definition at line 784 of file rlm_redis_ippool_tool.c.

+ Here is the caller graph for this function:

◆ _driver_release_lease_enqueue()

static int _driver_release_lease_enqueue ( UNUSED redis_driver_conf_t inst,
fr_redis_conn_t conn,
uint8_t const *  key_prefix,
size_t  key_prefix_len,
UNUSED uint8_t const *  range,
UNUSED size_t  range_len,
fr_ipaddr_t ipaddr,
uint8_t  prefix,
UNUSED void *  uctx 
)
static

Release a lease by setting its score back to zero.

Definition at line 638 of file rlm_redis_ippool_tool.c.

+ Here is the caller graph for this function:

◆ _driver_release_lease_process()

static int _driver_release_lease_process ( void *  out,
UNUSED fr_ipaddr_t const *  ipaddr,
redisReply const *  reply 
)
static

Count the number of leases we released.

Definition at line 620 of file rlm_redis_ippool_tool.c.

+ Here is the caller graph for this function:

◆ _driver_remove_lease_enqueue()

static int _driver_remove_lease_enqueue ( UNUSED redis_driver_conf_t inst,
fr_redis_conn_t conn,
uint8_t const *  key_prefix,
size_t  key_prefix_len,
UNUSED uint8_t const *  range,
UNUSED size_t  range_len,
fr_ipaddr_t ipaddr,
uint8_t  prefix,
UNUSED void *  uctx 
)
static

Enqueue lease removal commands.

This removes the lease from the expiry heap, and the data associated with the lease.

Definition at line 687 of file rlm_redis_ippool_tool.c.

+ Here is the caller graph for this function:

◆ _driver_remove_lease_process()

static int _driver_remove_lease_process ( void *  out,
UNUSED fr_ipaddr_t const *  ipaddr,
redisReply const *  reply 
)
static

Count the number of leases we removed.

Because the ZREM and DEL have to occur in a transaction, we need some fancier processing to just count the number of ZREMs.

Definition at line 667 of file rlm_redis_ippool_tool.c.

+ Here is the caller graph for this function:

◆ _driver_show_lease_enqueue()

static int _driver_show_lease_enqueue ( UNUSED redis_driver_conf_t inst,
fr_redis_conn_t conn,
uint8_t const *  key_prefix,
size_t  key_prefix_len,
UNUSED uint8_t const *  range,
UNUSED size_t  range_len,
fr_ipaddr_t ipaddr,
uint8_t  prefix,
UNUSED void *  uctx 
)
static

Enqueue commands to retrieve lease information.

Definition at line 581 of file rlm_redis_ippool_tool.c.

+ Here is the caller graph for this function:

◆ _driver_show_lease_process()

static int _driver_show_lease_process ( void *  out,
fr_ipaddr_t const *  ipaddr,
redisReply const *  reply 
)
static

Enqueue commands to retrieve lease information.

Definition at line 535 of file rlm_redis_ippool_tool.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _driver_unassign_lease_enqueue()

static int _driver_unassign_lease_enqueue ( UNUSED redis_driver_conf_t inst,
fr_redis_conn_t conn,
uint8_t const *  key_prefix,
size_t  key_prefix_len,
UNUSED uint8_t const *  range,
UNUSED size_t  range_len,
fr_ipaddr_t ipaddr,
uint8_t  prefix,
void *  uctx 
)
static

Enqueue static lease un-assignment commands.

Definition at line 896 of file rlm_redis_ippool_tool.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _driver_unassign_lease_process()

static int _driver_unassign_lease_process ( void *  out,
UNUSED fr_ipaddr_t const *  ipaddr,
redisReply const *  reply 
)
static

Definition at line 880 of file rlm_redis_ippool_tool.c.

+ Here is the caller graph for this function:

◆ driver_add_lease()

static int driver_add_lease ( void *  out,
void *  instance,
ippool_tool_operation_t const *  op 
)
static

Add a range of prefixes.

Definition at line 777 of file rlm_redis_ippool_tool.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ driver_assign_lease()

static int driver_assign_lease ( void *  out,
void *  instance,
ippool_tool_operation_t const *  op,
char const *  owner 
)
static

Add static lease assignments.

Definition at line 873 of file rlm_redis_ippool_tool.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ driver_do_lease()

static int driver_do_lease ( void *  out,
void *  instance,
ippool_tool_operation_t const *  op,
redis_ippool_queue_t  enqueue,
redis_ippool_process_t  process,
void *  uctx 
)
static

Add a net to the pool.

Returns
the number of new addresses added.

Definition at line 456 of file rlm_redis_ippool_tool.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ driver_get_pools()

static ssize_t driver_get_pools ( TALLOC_CTX *  ctx,
uint8_t **  out[],
void *  instance 
)
static

Return the pools available across the cluster.

Parameters
[in]ctxto allocate range names in.
[out]outArray of pool names.
[in]instanceDriver specific instance data.
Returns
  • < 0 on failure.
  • >= 0 the number of ranges in the array we allocated.

Definition at line 952 of file rlm_redis_ippool_tool.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ driver_get_stats()

static int driver_get_stats ( ippool_tool_stats_t out,
void *  instance,
uint8_t const *  key_prefix,
size_t  key_prefix_len 
)
static

Definition at line 1129 of file rlm_redis_ippool_tool.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ driver_init()

static int driver_init ( TALLOC_CTX *  ctx,
CONF_SECTION conf,
void **  instance 
)
static

Driver initialization function.

Definition at line 1249 of file rlm_redis_ippool_tool.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ driver_modify_lease()

static int driver_modify_lease ( void *  out,
void *  instance,
ippool_tool_operation_t const *  op 
)
static

Remove a range of leases.

Definition at line 833 of file rlm_redis_ippool_tool.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ driver_release_lease()

static int driver_release_lease ( void *  out,
void *  instance,
ippool_tool_operation_t const *  op 
)
inlinestatic

Release a range of leases.

Definition at line 656 of file rlm_redis_ippool_tool.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ driver_remove_lease()

static int driver_remove_lease ( void *  out,
void *  instance,
ippool_tool_operation_t const *  op 
)
static

Remove a range of leases.

Definition at line 705 of file rlm_redis_ippool_tool.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ driver_show_lease()

static int driver_show_lease ( void *  out,
void *  instance,
ippool_tool_operation_t const *  op 
)
inlinestatic

Show information about leases.

Definition at line 612 of file rlm_redis_ippool_tool.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ driver_unassign_lease()

static int driver_unassign_lease ( void *  out,
void *  instance,
ippool_tool_operation_t const *  op,
char const *  owner 
)
static

Unassign static lease assignments.

Definition at line 917 of file rlm_redis_ippool_tool.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ipaddr_next()

static bool ipaddr_next ( fr_ipaddr_t ipaddr,
fr_ipaddr_t const *  end,
uint8_t  prefix 
)
static

Iterate over range of IP addresses.

Mutates the ipaddr passed in, adding one to the prefix bits on each call.

Parameters
[in,out]ipaddrto increment.
[in]endipaddr to stop at.
[in]prefixLength of the prefix.
Returns
  • true if the prefix bits are not high (continue).
  • false if the prefix bits are high (stop).

Definition at line 401 of file rlm_redis_ippool_tool.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 1451 of file rlm_redis_ippool_tool.c.

+ Here is the call graph for this function:

◆ parse_ip_range()

static int parse_ip_range ( fr_ipaddr_t start_out,
fr_ipaddr_t end_out,
char const *  ip_str,
uint8_t  prefix 
)
static

Convert an IP range or CIDR mask to a start and stop address.

Parameters
[out]start_outWhere to write the start address.
[out]end_outWhere to write the end address.
[in]ip_strUnparsed IP string.
[in]prefixlength of prefixes we'll be allocating.
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 1288 of file rlm_redis_ippool_tool.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ pool_cmp()

static int8_t pool_cmp ( void const *  a,
void const *  b 
)
static

Compare two pool names.

Definition at line 927 of file rlm_redis_ippool_tool.c.

+ Here is the caller graph for this function:

◆ uint32_gen_mask()

static uint32_t uint32_gen_mask ( uint8_t  bits)
static

Definition at line 384 of file rlm_redis_ippool_tool.c.

+ Here is the caller graph for this function:

◆ usage()

static NEVER_RETURNS void usage ( int  ret)
static

Definition at line 345 of file rlm_redis_ippool_tool.c.

+ Here is the caller graph for this function:

Variable Documentation

◆ lua_assign_cmd

char lua_assign_cmd[]
static

Lua script for assigning a static lease.

  • KEYS[1] The pool name.
  • ARGV[1] THE ip address to create a static assignment for.
  • ARGV[2] The owner to assign the static lease to.
  • ARGV[3] The range identifier.
  • ARGV[4] Wall time (seconds since epoch)

Checks whether the IP already has a static assignment, and whether the owner is already associated with a different IP.

If check pass, sets the static flag on the IP entry in the ZSET and creates the association between the IP and the owner.

Returns

  • 0 if no assignment is made.
  • 1 if the IP assignment is made.

Definition at line 212 of file rlm_redis_ippool_tool.c.

◆ lua_release_cmd

char lua_release_cmd[]
static
Initial value:
=
"local found" EOL
"local ret" EOL
"ret = redis.call('ZADD', '{' .. KEYS[1] .. '}:"IPPOOL_POOL_KEY"', 'XX', 'CH', 0, ARGV[1])" EOL
"if ret == 0 then" EOL
" return 0" EOL
"end" EOL
"found = redis.call('HGET', '{' .. KEYS[1] .. '}:"IPPOOL_ADDRESS_KEY":'"
" .. ARGV[1], 'device')" EOL
"if not found then" EOL
" return ret" EOL
"end" EOL
"redis.call('DEL', '{' .. KEYS[1] .. '}:"IPPOOL_OWNER_KEY":' .. found)" EOL
"return 1"
#define IPPOOL_OWNER_KEY
Definition: redis_ippool.h:59
#define IPPOOL_POOL_KEY
Definition: redis_ippool.h:57
#define EOL

Lua script for releasing a lease.

  • KEYS[1] The pool name.
  • ARGV[1] IP address to release.

Removes the IP entry in the ZSET, then removes the address hash, and the device key if one exists.

Will do nothing if the lease is not found in the ZSET.

Returns

  • 0 if no ip addresses were removed.
  • 1 if an ip address was removed.

Definition at line 171 of file rlm_redis_ippool_tool.c.

◆ lua_remove_cmd

char lua_remove_cmd[]
static
Initial value:
=
"local found" EOL
"local ret" EOL
"local address_key" EOL
"ret = redis.call('ZREM', '{' .. KEYS[1] .. '}:"IPPOOL_POOL_KEY"', ARGV[1])" EOL
"address_key = '{' .. KEYS[1] .. '}:"IPPOOL_ADDRESS_KEY":' .. ARGV[1]" EOL
"found = redis.call('HGET', address_key, 'device')" EOL
"redis.call('DEL', address_key)" EOL
"if not found then" EOL
" return ret" EOL
"end" EOL
"redis.call('DEL', '{' .. KEYS[1] .. '}:"IPPOOL_OWNER_KEY":' .. found)" EOL
"return 1" EOL

Lua script for removing a lease.

  • KEYS[1] The pool name.
  • ARGV[1] IP address to remove.

Removes the IP entry in the ZSET, then removes the address hash, and the device key if one exists.

Will work with partially removed IP addresses (where the ZSET entry is absent but other elements weren't cleaned up).

Returns

  • 0 if no ip addresses were removed.
  • 1 if an ip address was removed.

Definition at line 326 of file rlm_redis_ippool_tool.c.

◆ lua_unassign_cmd

char lua_unassign_cmd[]
static
Initial value:
=
"local found" EOL
"local pool_key = '{' .. KEYS[1] .. '}:"IPPOOL_POOL_KEY"'" EOL
"local owner_key = '{' .. KEYS[1] .. '}:"IPPOOL_OWNER_KEY":' .. ARGV[2]" EOL
"found = redis.call('GET', owner_key)" EOL
"if not found or found ~= ARGV[1] then" EOL
" return 0" EOL
"end" EOL
"local expires = tonumber(redis.call('ZSCORE', pool_key, ARGV[1]))" EOL
"local static = expires >= " STRINGIFY(IPPOOL_STATIC_BIT) EOL
"if not static then" EOL
" return 0" EOL
"end" EOL
"expires = expires - " STRINGIFY(IPPOOL_STATIC_BIT) EOL
"redis.call('ZADD', pool_key, 'XX', expires, ARGV[1])" EOL
"if expires > tonumber(ARGV[3]) then" EOL
" redis.call('EXPIRE', owner_key, expires - tonumber(ARGV[3]))" EOL
"else" EOL
" redis.call('DEL', owner_key)" EOL
"end" EOL
"return 1"
#define IPPOOL_STATIC_BIT
Definition: redis_ippool.h:60

Lua script for un-assigning a static lease.

  • KEYS[1] The pool name.
  • ARGV[1] IP address to remove static lease from.
  • ARGV[2] The owner the static lease should be removed from.
  • ARGV[3] Wall time (seconds since epoch).

Removes the static flag from the IP entry in the ZSET, then, depending on the remaining time determined by the ZSCORE removes the address hash, and the device key.

Will do nothing if the static assignment does not exist or the IP and device do not match.

Returns

  • 0 if no ip addresses were unassigned.
  • 1 if an ip address was unassigned.

Definition at line 272 of file rlm_redis_ippool_tool.c.

◆ name

char const* name
static

Definition at line 156 of file rlm_redis_ippool_tool.c.

◆ redis_config

conf_parser_t redis_config[]
static
Initial value:
= {
}
#define CONF_PARSER_TERMINATOR
Definition: cf_parse.h:626
#define REDIS_COMMON_CONFIG
Definition: base.h:133

Definition at line 96 of file rlm_redis_ippool_tool.c.