IP population tool. More...
#include <freeradius-devel/libradius.h>
#include <freeradius-devel/rad_assert.h>
#include "redis.h"
#include "cluster.h"
#include "redis_ippool.h"
#include <sys/wait.h>
Go to the source code of this file.
Data Structures | |
struct | ippool_tool |
struct | ippool_tool_lease |
struct | ippool_tool_operation |
A single pool operation. More... | |
struct | redis_driver_conf |
Macros | |
#define | ADD_ACTION(_action) |
#define | IPPOOL_BUILD_IP_KEY_FROM_STR(_buff, _p, _key, _key_len, _ip_str) |
#define | MAX_PIPELINED 1000 |
Typedefs | |
typedef enum ippool_tool_action | ippool_tool_action_t |
Pool management actions. More... | |
typedef struct ippool_tool_lease | ippool_tool_lease_t |
typedef struct ippool_tool_operation | ippool_tool_operation_t |
A single pool operation. More... | |
typedef struct ippool_tool | ippool_tool_t |
typedef struct redis_driver_conf | redis_driver_conf_t |
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) |
Enumerations | |
enum | ippool_tool_action { IPPOOL_TOOL_NOOP = 0, IPPOOL_TOOL_ADD, IPPOOL_TOOL_REMOVE, IPPOOL_TOOL_RELEASE, IPPOOL_TOOL_SHOW } |
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) |
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_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) |
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) |
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) |
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_add_lease (void *out, void *instance, ippool_tool_operation_t const *op) |
Add a range of prefixes. 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) |
Add a net to the pool. More... | |
static int | driver_init (TALLOC_CTX *ctx, CONF_SECTION *conf, void **instance) |
Driver initialization function. 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 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... | |
pid_t | rad_fork (void) |
pid_t | rad_waitpid (pid_t pid, int *status) |
static uint128_t | uint128_add (uint128_t a, uint128_t b) |
Add two 128bit unsigned integers. More... | |
static uint128_t | uint128_band (uint128_t a, uint128_t b) |
Perform bitwise & of two 128bit unsigned integers. More... | |
static uint128_t | uint128_bor (uint128_t a, uint128_t b) |
Perform bitwise | of two 128bit unsigned integers. More... | |
static bool | uint128_eq (uint128_t a, uint128_t b) |
Return whether the integers are equal. More... | |
static uint128_t | uint128_gen_mask (uint8_t bits) |
Create a 128 bit integer value with n bits high. More... | |
static bool | uint128_gt (uint128_t a, uint128_t b) |
Return whether one integer is greater than the other. More... | |
static uint128_t | uint128_lshift (uint128_t num, uint8_t bits) |
Left shift 128 bit integer. More... | |
static uint128_t | uint128_new (uint64_t h, uint64_t l) |
Creates a new uint128_t from an uint64_t. More... | |
static uint128_t | uint128_sub (uint128_t a, uint128_t b) |
Subtract one 128bit integer from another. More... | |
static uint32_t | uint32_gen_mask (uint8_t bits) |
static void NEVER_RETURNS | usage (int ret) |
Variables | |
static char const * | name |
static CONF_PARSER | redis_config [] |
IP population tool.
Definition in file rlm_redis_ippool_tool.c.
struct ippool_tool |
Definition at line 101 of file rlm_redis_ippool_tool.c.
Data Fields | ||
---|---|---|
CONF_SECTION * | cs | |
void * | driver |
struct ippool_tool_lease |
Definition at line 80 of file rlm_redis_ippool_tool.c.
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 |
struct ippool_tool_operation |
A single pool operation.
Definition at line 64 of file rlm_redis_ippool_tool.c.
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. |
struct redis_driver_conf |
Definition at line 96 of file rlm_redis_ippool_tool.c.
Data Fields | ||
---|---|---|
fr_redis_cluster_t * | cluster | |
fr_redis_conf_t | conf | Connection parameters for the Redis server. |
#define ADD_ACTION | ( | _action | ) |
#define IPPOOL_BUILD_IP_KEY_FROM_STR | ( | _buff, | |
_p, | |||
_key, | |||
_key_len, | |||
_ip_str | |||
) |
Definition at line 113 of file rlm_redis_ippool_tool.c.
#define MAX_PIPELINED 1000 |
Definition at line 35 of file rlm_redis_ippool_tool.c.
typedef enum ippool_tool_action ippool_tool_action_t |
Pool management actions.
typedef struct ippool_tool_lease ippool_tool_lease_t |
typedef struct ippool_tool_operation ippool_tool_operation_t |
A single pool operation.
typedef struct ippool_tool ippool_tool_t |
typedef struct redis_driver_conf redis_driver_conf_t |
typedef int(* redis_ippool_process_t)(void *out, fr_ipaddr_t const *ipaddr, redisReply const *reply) |
Definition at line 111 of file rlm_redis_ippool_tool.c.
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) |
Definition at line 106 of file rlm_redis_ippool_tool.c.
enum ippool_tool_action |
Pool management actions.
Enumerator | |
---|---|
IPPOOL_TOOL_NOOP | |
IPPOOL_TOOL_ADD | |
IPPOOL_TOOL_REMOVE | |
IPPOOL_TOOL_RELEASE | |
IPPOOL_TOOL_SHOW |
Definition at line 53 of file rlm_redis_ippool_tool.c.
|
static |
Enqueue lease addition commands.
Definition at line 657 of file rlm_redis_ippool_tool.c.
|
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 638 of file rlm_redis_ippool_tool.c.
|
static |
Release a lease by setting its score back to zero.
Definition at line 547 of file rlm_redis_ippool_tool.c.
|
static |
Count the number of leases we released.
Definition at line 530 of file rlm_redis_ippool_tool.c.
|
static |
Enqueue lease removal commands.
This removes the lease from the expiry heap, and the data associated with the lease.
Definition at line 600 of file rlm_redis_ippool_tool.c.
|
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 579 of file rlm_redis_ippool_tool.c.
|
static |
Enqueue commands to retrieve lease information.
Definition at line 493 of file rlm_redis_ippool_tool.c.
|
static |
Enqueue commands to retrieve lease information.
Definition at line 452 of file rlm_redis_ippool_tool.c.
|
static |
Add a range of prefixes.
Definition at line 684 of file rlm_redis_ippool_tool.c.
|
static |
Add a net to the pool.
Definition at line 371 of file rlm_redis_ippool_tool.c.
|
static |
Driver initialization function.
Definition at line 692 of file rlm_redis_ippool_tool.c.
|
inlinestatic |
Release a range of leases.
Definition at line 568 of file rlm_redis_ippool_tool.c.
|
static |
Remove a range of leases.
Definition at line 627 of file rlm_redis_ippool_tool.c.
|
inlinestatic |
Show information about leases.
Definition at line 522 of file rlm_redis_ippool_tool.c.
|
static |
Iterate over range of IP addresses.
Mutates the ipaddr passed in, adding one to the prefix bits on each call.
[in,out] | ipaddr | to increment. |
[in] | end | ipaddr to stop at. |
[in] | prefix | Length of the prefix. |
Definition at line 316 of file rlm_redis_ippool_tool.c.
int main | ( | int | argc, |
char * | argv[] | ||
) |
|
static |
Convert an IP range or CIDR mask to a start and stop address.
[out] | start_out | Where to write the start address. |
[out] | end_out | Where to write the end address. |
[in] | ip_str | Unparsed IP string. |
[in] | prefix | length of prefixes we'll be allocating. |
Definition at line 728 of file rlm_redis_ippool_tool.c.
pid_t rad_fork | ( | void | ) |
Definition at line 40 of file rlm_redis_ippool_tool.c.
pid_t rad_waitpid | ( | pid_t | pid, |
int * | status | ||
) |
Definition at line 45 of file rlm_redis_ippool_tool.c.
|
static |
Add two 128bit unsigned integers.
Definition at line 214 of file rlm_redis_ippool_tool.c.
|
static |
Perform bitwise & of two 128bit unsigned integers.
Definition at line 243 of file rlm_redis_ippool_tool.c.
|
static |
Perform bitwise | of two 128bit unsigned integers.
Definition at line 254 of file rlm_redis_ippool_tool.c.
|
static |
Return whether the integers are equal.
Definition at line 265 of file rlm_redis_ippool_tool.c.
|
static |
Create a 128 bit integer value with n bits high.
Definition at line 172 of file rlm_redis_ippool_tool.c.
|
static |
Return whether one integer is greater than the other.
Definition at line 273 of file rlm_redis_ippool_tool.c.
|
static |
Left shift 128 bit integer.
Definition at line 194 of file rlm_redis_ippool_tool.c.
|
static |
Creates a new uint128_t from an uint64_t.
Definition at line 283 of file rlm_redis_ippool_tool.c.
|
static |
Subtract one 128bit integer from another.
Definition at line 228 of file rlm_redis_ippool_tool.c.
|
static |
|
static |
|
static |
Definition at line 129 of file rlm_redis_ippool_tool.c.
|
static |
Definition at line 91 of file rlm_redis_ippool_tool.c.