The FreeRADIUS server
$Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
|
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"
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 [] |
IP population tool.
Definition in file rlm_redis_ippool_tool.c.
struct ippool_tool_lease_t |
Definition at line 70 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_t |
A single pool operation.
Definition at line 54 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 ippool_tool_owner_t |
Definition at line 111 of file rlm_redis_ippool_tool.c.
Data Fields | ||
---|---|---|
char const * | owner |
struct ippool_tool_stats_t |
Definition at line 81 of file rlm_redis_ippool_tool.c.
struct ippool_tool_t |
Definition at line 106 of file rlm_redis_ippool_tool.c.
Data Fields | ||
---|---|---|
CONF_SECTION * | cs | |
void * | driver |
struct redis_driver_conf_t |
Definition at line 101 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 EOL "\n" |
Definition at line 154 of file rlm_redis_ippool_tool.c.
#define IPPOOL_BUILD_IP_KEY_FROM_STR | ( | _buff, | |
_p, | |||
_key, | |||
_key_len, | |||
_ip_str | |||
) |
Definition at line 122 of file rlm_redis_ippool_tool.c.
#define MAX_PIPELINED 100000 |
Definition at line 35 of file rlm_redis_ippool_tool.c.
#define STATS_COMMANDS_TOTAL 14 |
typedef enum ippool_tool_action ippool_tool_action_t |
Pool management actions.
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.
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.
enum ippool_tool_action |
Pool management actions.
Definition at line 40 of file rlm_redis_ippool_tool.c.
|
static |
Enqueue lease addition commands.
Definition at line 735 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 716 of file rlm_redis_ippool_tool.c.
|
static |
Enqueue static lease assignment commands.
Definition at line 851 of file rlm_redis_ippool_tool.c.
|
static |
|
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.
|
static |
Count the number of leases we modified.
Definition at line 784 of file rlm_redis_ippool_tool.c.
|
static |
Release a lease by setting its score back to zero.
Definition at line 638 of file rlm_redis_ippool_tool.c.
|
static |
Count the number of leases we released.
Definition at line 620 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 687 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 667 of file rlm_redis_ippool_tool.c.
|
static |
Enqueue commands to retrieve lease information.
Definition at line 581 of file rlm_redis_ippool_tool.c.
|
static |
Enqueue commands to retrieve lease information.
Definition at line 535 of file rlm_redis_ippool_tool.c.
|
static |
Enqueue static lease un-assignment commands.
Definition at line 896 of file rlm_redis_ippool_tool.c.
|
static |
|
static |
Add a range of prefixes.
Definition at line 777 of file rlm_redis_ippool_tool.c.
|
static |
Add static lease assignments.
Definition at line 873 of file rlm_redis_ippool_tool.c.
|
static |
Add a net to the pool.
Definition at line 456 of file rlm_redis_ippool_tool.c.
Return the pools available across the cluster.
[in] | ctx | to allocate range names in. |
[out] | out | Array of pool names. |
[in] | instance | Driver specific instance data. |
Definition at line 952 of file rlm_redis_ippool_tool.c.
|
static |
Definition at line 1129 of file rlm_redis_ippool_tool.c.
|
static |
Driver initialization function.
Definition at line 1249 of file rlm_redis_ippool_tool.c.
|
static |
Remove a range of leases.
Definition at line 833 of file rlm_redis_ippool_tool.c.
|
inlinestatic |
Release a range of leases.
Definition at line 656 of file rlm_redis_ippool_tool.c.
|
static |
Remove a range of leases.
Definition at line 705 of file rlm_redis_ippool_tool.c.
|
inlinestatic |
Show information about leases.
Definition at line 612 of file rlm_redis_ippool_tool.c.
|
static |
Unassign static lease assignments.
Definition at line 917 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 401 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 1288 of file rlm_redis_ippool_tool.c.
|
static |
Compare two pool names.
Definition at line 927 of file rlm_redis_ippool_tool.c.
|
static |
|
static |
Lua script for assigning a static lease.
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
Definition at line 212 of file rlm_redis_ippool_tool.c.
|
static |
Lua script for releasing a lease.
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
Definition at line 171 of file rlm_redis_ippool_tool.c.
|
static |
Lua script for removing a lease.
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
Definition at line 326 of file rlm_redis_ippool_tool.c.
|
static |
Lua script for un-assigning a static lease.
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
Definition at line 272 of file rlm_redis_ippool_tool.c.
|
static |
Definition at line 156 of file rlm_redis_ippool_tool.c.
|
static |
Definition at line 96 of file rlm_redis_ippool_tool.c.