The FreeRADIUS server $Id: f3670dba8951ca10eb4948feb3dc3db9423a334f $
Loading...
Searching...
No Matches
Data Structures | Macros | Functions | Variables
rlm_redis.c File Reference

Driver for the Redis noSQL key value store. More...

#include <assert.h>
#include <stdint.h>
#include <freeradius-devel/redis/base.h>
#include <freeradius-devel/redis/cluster_async.h>
#include <freeradius-devel/server/modpriv.h>
#include <freeradius-devel/server/module_rlm.h>
#include <freeradius-devel/io/coord_pair.h>
#include <freeradius-devel/unlang/xlat_func.h>
#include <freeradius-devel/util/base16.h>
#include <freeradius-devel/util/debug.h>
#include <freeradius-devel/util/types.h>
+ Include dependency graph for rlm_redis.c:

Go to the source code of this file.

Data Structures

struct  redis_lua_func_inst_t
 Instance of a redis lua func xlat. More...
 
struct  redis_lua_func_t
 A lua function or stored procedure we make available as an xlat. More...
 
struct  rlm_redis_lua_t
 
struct  rlm_redis_lua_xlat_rctx_t
 Resume context for redis lua xlat. More...
 
struct  rlm_redis_t
 rlm_redis module instance More...
 
struct  rlm_redis_thread_t
 
struct  rlm_redis_xlat_rctx_t
 Resume context for redis xlat. More...
 

Macros

#define REDIS_XLAT_CMD_SETUP(_cmds, _argc, _argv, _arg_len, _rctx, _read_only, _func)
 

Functions

static int lua_func_body_parse (TALLOC_CTX *ctx, void *out, void *parent, CONF_ITEM *ci, conf_parser_t const *rule)
 Do basic processing for a lua function body and compute its sha1 hash.
 
static void lua_script_load (fr_redis_trunk_t *rtrunk, void *uctx)
 
static void lua_script_load_results (UNUSED request_t *request, UNUSED fr_redis_command_t *cmd, UNUSED redisReply *reply, void *rctx)
 
static int mod_bootstrap (module_inst_ctx_t const *mctx)
 
static int mod_coord_attach (module_thread_inst_ctx_t const *mctx)
 
static int mod_detach (module_detach_ctx_t const *mctx)
 
static int mod_instantiate (module_inst_ctx_t const *mctx)
 
static int mod_load (void)
 
static int mod_thread_detach (module_thread_inst_ctx_t const *mctx)
 
static int mod_thread_instantiate (module_thread_inst_ctx_t const *mctx)
 
 REDIS_ASYNC_COORD_CALLBACKS (rlm_redis_thread_t)
 
static void redis_lua_cancel (xlat_ctx_t const *xctx, request_t *request, UNUSED fr_signal_t action)
 Cancellation of Redis Lua load / exec.
 
static int redis_lua_func_instantiate (xlat_inst_ctx_t const *xctx)
 Copies the function configuration into xlat function instance data.
 
static xlat_action_t redis_lua_func_resume (UNUSED TALLOC_CTX *ctx, fr_dcursor_t *out, xlat_ctx_t const *xctx, UNUSED request_t *request, UNUSED fr_value_box_list_t *in)
 Process the results from calling a lua script.
 
static xlat_action_t redis_lua_func_xlat (TALLOC_CTX *ctx, UNUSED fr_dcursor_t *out, xlat_ctx_t const *xctx, request_t *request, fr_value_box_list_t *in)
 Call a lua function on the redis server.
 
static void redis_lua_load_results (request_t *request, UNUSED fr_redis_command_t *cmd, redisReply *reply, void *rctx)
 Callback to verify reply to SCRIPT LOAD.
 
static xlat_action_t redis_lua_load_resume (UNUSED TALLOC_CTX *ctx, UNUSED fr_dcursor_t *out, xlat_ctx_t const *xctx, UNUSED request_t *request, UNUSED fr_value_box_list_t *in)
 Process the results of loading a lua script to a redis server.
 
static void redis_lua_xlat_results (request_t *request, fr_redis_command_t *cmd, redisReply *reply, void *rctx)
 Callback to convert redis reply to value boxes.
 
static xlat_action_t redis_node_xlat (TALLOC_CTX *ctx, fr_dcursor_t *out, xlat_ctx_t const *xctx, request_t *request, fr_value_box_list_t *in)
 Return the node that is currently servicing a particular key.
 
static xlat_action_t redis_remap_xlat (TALLOC_CTX *ctx, UNUSED fr_dcursor_t *out, xlat_ctx_t const *xctx, request_t *request, UNUSED fr_value_box_list_t *in)
 Force a redis cluster remap.
 
static xlat_action_t redis_remap_xlat_resume (UNUSED TALLOC_CTX *ctx, fr_dcursor_t *out, xlat_ctx_t const *xctx, UNUSED request_t *request, UNUSED fr_value_box_list_t *in)
 
static xlat_action_t redis_xlat (TALLOC_CTX *ctx, UNUSED fr_dcursor_t *out, xlat_ctx_t const *xctx, request_t *request, fr_value_box_list_t *in)
 Xlat to make calls to redis.
 
static void redis_xlat_cancel (xlat_ctx_t const *xctx, request_t *request, UNUSED fr_signal_t action)
 Common cancellation for redis xlats.
 
static void redis_xlat_ping_check (request_t *request, fr_redis_command_t *cmd, redisReply *reply, void *rctx)
 Callback to check redis replied with "PONG" when expected.
 
static void redis_xlat_results (request_t *request, fr_redis_command_t *cmd, redisReply *reply, void *rctx)
 Callback to convert redis reply to value boxes.
 
static xlat_action_t redis_xlat_resume (UNUSED TALLOC_CTX *ctx, fr_dcursor_t *out, xlat_ctx_t const *xctx, request_t *request, UNUSED fr_value_box_list_t *in)
 
static void redis_xlat_status_check (request_t *request, fr_redis_command_t *cmd, redisReply *reply, void *rctx)
 Callback to check redis replied with "OK" when expected.
 

Variables

static fr_dict_t const * dict_redis
 
static conf_parser_t module_config []
 
static conf_parser_t module_lua []
 
static conf_parser_t module_lua_func []
 
static xlat_arg_parser_t const redis_args []
 
static xlat_arg_parser_t const redis_lua_func_args []
 
static xlat_arg_parser_t const redis_node_xlat_args []
 
module_rlm_t rlm_redis
 
fr_dict_autoload_t rlm_redis_dict []
 

Detailed Description

Driver for the Redis noSQL key value store.

Id
1945c0eb6b9ff24e7ddec69d0f23ed365bb7dc9f
Author
Gabriel Blanchard

Definition in file rlm_redis.c.


Data Structure Documentation

◆ redis_lua_func_inst_t

struct redis_lua_func_inst_t

Instance of a redis lua func xlat.

Definition at line 68 of file rlm_redis.c.

+ Collaboration diagram for redis_lua_func_inst_t:
Data Fields
redis_lua_func_t * func Function configuration.

◆ redis_lua_func_t

struct redis_lua_func_t

A lua function or stored procedure we make available as an xlat.

Definition at line 58 of file rlm_redis.c.

Data Fields
char const * body the actual lua code.
char digest[(SHA1_DIGEST_LENGTH *2)+1] pre-computed hash of lua code.
char const * name Friendly name for the function. Used to register the equivalent xlat.
bool read_only Function has no side effects.

◆ rlm_redis_lua_t

struct rlm_redis_lua_t

Definition at line 73 of file rlm_redis.c.

+ Collaboration diagram for rlm_redis_lua_t:
Data Fields
redis_lua_func_t ** funcs Array of functions to register.

◆ rlm_redis_lua_xlat_rctx_t

struct rlm_redis_lua_xlat_rctx_t

Resume context for redis lua xlat.

Definition at line 101 of file rlm_redis.c.

+ Collaboration diagram for rlm_redis_lua_xlat_rctx_t:
Data Fields
xlat_action_t action Xlat action set in callback.
fr_redis_async_cmd_t * cmd Async command context.
fr_redis_command_set_t * cmds Command set for this xlat.
TALLOC_CTX * ctx Context to allocate boxes.
redis_lua_func_t const * func Lua function.
fr_value_box_list_t out List to store boxes in callback.

◆ rlm_redis_t

struct rlm_redis_t

rlm_redis module instance

Definition at line 81 of file rlm_redis.c.

+ Collaboration diagram for rlm_redis_t:
Data Fields
fr_redis_conf_t conf Connection parameters for the Redis server.

Must be first field in this struct.

fr_coord_pair_reg_t * coord_pair_reg Coord pair registration.
fr_coord_reg_t * coord_reg Coordinator registration.
rlm_redis_lua_t lua Array of functions to register.
CONF_SECTION * tls_conf TLS CONF_SECTION.

◆ rlm_redis_thread_t

struct rlm_redis_thread_t

Definition at line 93 of file rlm_redis.c.

+ Collaboration diagram for rlm_redis_thread_t:
Data Fields
fr_coord_worker_t * cw Coord-worker for fetching cluster map.
rlm_redis_t const * inst Module instance.
fr_redis_ct_t * rtcluster Per thread Redis cluster.

◆ rlm_redis_xlat_rctx_t

struct rlm_redis_xlat_rctx_t

Resume context for redis xlat.

Definition at line 112 of file rlm_redis.c.

+ Collaboration diagram for rlm_redis_xlat_rctx_t:
Data Fields
xlat_action_t action Xlat action set in callback.
fr_redis_async_cmd_t * cmd Async command context.
fr_redis_command_set_t * cmds Command set for this xlat.
TALLOC_CTX * ctx Context to allocate boxes.
bool forced_node Was the xlat called with a specific node.
fr_value_box_list_t out List to store boxes in callback.
bool read_only Should the xlat be run read only.

Macro Definition Documentation

◆ REDIS_XLAT_CMD_SETUP

#define REDIS_XLAT_CMD_SETUP (   _cmds,
  _argc,
  _argv,
  _arg_len,
  _rctx,
  _read_only,
  _func 
)
Value:
if (_read_only && \
return XLAT_ACTION_FAIL; \
if (fr_redis_command_argv_add(_cmds, _argc, _argv, _arg_len, _func, _rctx) != FR_REDIS_PIPELINE_OK) \
return XLAT_ACTION_FAIL; \
if (_read_only && \
fr_redis_pipeline_status_t fr_redis_command_argv_add(fr_redis_command_set_t *cmds, size_t argc, char const **argv, size_t *argv_len, fr_redis_command_complete_t complete, void *rctx)
Add a command with arguments to the command set.
Definition pipeline.c:436
fr_redis_pipeline_status_t fr_redis_command_literal_add(fr_redis_command_set_t *cmds, char const *cmd_str, fr_redis_command_complete_t complete, void *rctx)
Add a literal command to the command set.
Definition pipeline.c:401
@ FR_REDIS_PIPELINE_OK
No failure.
Definition pipeline.h:44
static void redis_xlat_status_check(request_t *request, fr_redis_command_t *cmd, redisReply *reply, void *rctx)
Callback to check redis replied with "OK" when expected.
Definition rlm_redis.c:192
@ XLAT_ACTION_FAIL
An xlat function failed.
Definition xlat.h:44

Definition at line 122 of file rlm_redis.c.

Function Documentation

◆ lua_func_body_parse()

static int lua_func_body_parse ( TALLOC_CTX *  ctx,
void *  out,
void *  parent,
CONF_ITEM ci,
conf_parser_t const *  rule 
)
static

Do basic processing for a lua function body and compute its sha1 hash.

Definition at line 156 of file rlm_redis.c.

+ Here is the call graph for this function:

◆ lua_script_load()

static void lua_script_load ( fr_redis_trunk_t rtrunk,
void *  uctx 
)
static

Definition at line 845 of file rlm_redis.c.

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

◆ lua_script_load_results()

static void lua_script_load_results ( UNUSED request_t request,
UNUSED fr_redis_command_t cmd,
UNUSED redisReply *  reply,
void *  rctx 
)
static

Definition at line 838 of file rlm_redis.c.

+ Here is the caller graph for this function:

◆ mod_bootstrap()

static int mod_bootstrap ( module_inst_ctx_t const *  mctx)
static

Definition at line 987 of file rlm_redis.c.

+ Here is the call graph for this function:

◆ mod_coord_attach()

static int mod_coord_attach ( module_thread_inst_ctx_t const *  mctx)
static

Definition at line 896 of file rlm_redis.c.

+ Here is the call graph for this function:

◆ mod_detach()

static int mod_detach ( module_detach_ctx_t const *  mctx)
static

Definition at line 976 of file rlm_redis.c.

+ Here is the call graph for this function:

◆ mod_instantiate()

static int mod_instantiate ( module_inst_ctx_t const *  mctx)
static

Definition at line 917 of file rlm_redis.c.

+ Here is the call graph for this function:

◆ mod_load()

static int mod_load ( void  )
static

Definition at line 1018 of file rlm_redis.c.

+ Here is the call graph for this function:

◆ mod_thread_detach()

static int mod_thread_detach ( module_thread_inst_ctx_t const *  mctx)
static

Definition at line 965 of file rlm_redis.c.

+ Here is the call graph for this function:

◆ mod_thread_instantiate()

static int mod_thread_instantiate ( module_thread_inst_ctx_t const *  mctx)
static

Definition at line 880 of file rlm_redis.c.

+ Here is the call graph for this function:

◆ REDIS_ASYNC_COORD_CALLBACKS()

REDIS_ASYNC_COORD_CALLBACKS ( rlm_redis_thread_t  )

◆ redis_lua_cancel()

static void redis_lua_cancel ( xlat_ctx_t const *  xctx,
request_t request,
UNUSED fr_signal_t  action 
)
static

Cancellation of Redis Lua load / exec.

Definition at line 385 of file rlm_redis.c.

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

◆ redis_lua_func_instantiate()

static int redis_lua_func_instantiate ( xlat_inst_ctx_t const *  xctx)
static

Copies the function configuration into xlat function instance data.

Definition at line 641 of file rlm_redis.c.

+ Here is the caller graph for this function:

◆ redis_lua_func_resume()

static xlat_action_t redis_lua_func_resume ( UNUSED TALLOC_CTX *  ctx,
fr_dcursor_t out,
xlat_ctx_t const *  xctx,
UNUSED request_t request,
UNUSED fr_value_box_list_t *  in 
)
static

Process the results from calling a lua script.

Enqueuing SCRIPT LOAD ... if the server reports that the script is missing

Definition at line 468 of file rlm_redis.c.

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

◆ redis_lua_func_xlat()

static xlat_action_t redis_lua_func_xlat ( TALLOC_CTX *  ctx,
UNUSED fr_dcursor_t out,
xlat_ctx_t const *  xctx,
request_t request,
fr_value_box_list_t *  in 
)
static

Call a lua function on the redis server.

Lua functions either get uploaded when the trunk connection becomes active or the first time they get executed.

Definition at line 541 of file rlm_redis.c.

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

◆ redis_lua_load_results()

static void redis_lua_load_results ( request_t request,
UNUSED fr_redis_command_t cmd,
redisReply *  reply,
void *  rctx 
)
static

Callback to verify reply to SCRIPT LOAD.

Definition at line 423 of file rlm_redis.c.

+ Here is the caller graph for this function:

◆ redis_lua_load_resume()

static xlat_action_t redis_lua_load_resume ( UNUSED TALLOC_CTX *  ctx,
UNUSED fr_dcursor_t out,
xlat_ctx_t const *  xctx,
UNUSED request_t request,
UNUSED fr_value_box_list_t *  in 
)
static

Process the results of loading a lua script to a redis server.

If the load succeeds, re-enqueue the original EVALSHA command.

Definition at line 400 of file rlm_redis.c.

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

◆ redis_lua_xlat_results()

static void redis_lua_xlat_results ( request_t request,
fr_redis_command_t cmd,
redisReply *  reply,
void *  rctx 
)
static

Callback to convert redis reply to value boxes.

Definition at line 443 of file rlm_redis.c.

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

◆ redis_remap_xlat_resume()

static xlat_action_t redis_remap_xlat_resume ( UNUSED TALLOC_CTX *  ctx,
fr_dcursor_t out,
xlat_ctx_t const *  xctx,
UNUSED request_t request,
UNUSED fr_value_box_list_t *  in 
)
static

Definition at line 237 of file rlm_redis.c.

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

◆ redis_xlat_cancel()

static void redis_xlat_cancel ( xlat_ctx_t const *  xctx,
request_t request,
UNUSED fr_signal_t  action 
)
static

Common cancellation for redis xlats.

Definition at line 229 of file rlm_redis.c.

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

◆ redis_xlat_ping_check()

static void redis_xlat_ping_check ( request_t request,
fr_redis_command_t cmd,
redisReply *  reply,
void *  rctx 
)
static

Callback to check redis replied with "PONG" when expected.

Definition at line 210 of file rlm_redis.c.

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

◆ redis_xlat_results()

static void redis_xlat_results ( request_t request,
fr_redis_command_t cmd,
redisReply *  reply,
void *  rctx 
)
static

Callback to convert redis reply to value boxes.

Definition at line 658 of file rlm_redis.c.

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

◆ redis_xlat_resume()

static xlat_action_t redis_xlat_resume ( UNUSED TALLOC_CTX *  ctx,
fr_dcursor_t out,
xlat_ctx_t const *  xctx,
request_t request,
UNUSED fr_value_box_list_t *  in 
)
static

Definition at line 679 of file rlm_redis.c.

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

◆ redis_xlat_status_check()

static void redis_xlat_status_check ( request_t request,
fr_redis_command_t cmd,
redisReply *  reply,
void *  rctx 
)
static

Callback to check redis replied with "OK" when expected.

Definition at line 192 of file rlm_redis.c.

+ Here is the call graph for this function:

Variable Documentation

◆ dict_redis

fr_dict_t const* dict_redis
static

Definition at line 47 of file rlm_redis.c.

◆ module_config

conf_parser_t module_config[]
static
Initial value:
= {
}
#define CONF_PARSER_TERMINATOR
Definition cf_parse.h:669
#define FR_CONF_OFFSET_SUBSECTION(_name, _flags, _struct, _field, _subcs)
conf_parser_t which populates a sub-struct using a CONF_SECTION
Definition cf_parse.h:309
#define REDIS_COMMON_CONFIG
Definition base.h:143
static conf_parser_t module_lua[]
Definition rlm_redis.c:140
rlm_redis module instance
Definition rlm_redis.c:81

Definition at line 147 of file rlm_redis.c.

◆ module_lua

conf_parser_t module_lua[]
static
Initial value:
= {
.subcs_type = "redis_lua_func_t", .name2 = CF_IDENT_ANY },
}
#define FR_CONF_SUBSECTION_ALLOC(_name, _type, _flags, _struct, _field, _subcs)
A conf_parser_t multi-subsection.
Definition cf_parse.h:369
@ CONF_FLAG_MULTI
CONF_PAIR can have multiple copies.
Definition cf_parse.h:446
@ CONF_FLAG_OK_MISSING
OK if it's missing.
Definition cf_parse.h:454
@ CONF_FLAG_SUBSECTION
Instead of putting the information into a configuration structure, the configuration file routines MA...
Definition cf_parse.h:423
#define CF_IDENT_ANY
Definition cf_util.h:80
static conf_parser_t module_lua_func[]
Definition rlm_redis.c:134

Definition at line 140 of file rlm_redis.c.

◆ module_lua_func

conf_parser_t module_lua_func[]
static
Initial value:
= {
{ FR_CONF_OFFSET("read_only", redis_lua_func_t, read_only) },
}
#define FR_CONF_OFFSET(_name, _struct, _field)
conf_parser_t which parses a single CONF_PAIR, writing the result to a field in a struct
Definition cf_parse.h:280
static int lua_func_body_parse(TALLOC_CTX *ctx, void *out, void *parent, CONF_ITEM *ci, conf_parser_t const *rule)
Do basic processing for a lua function body and compute its sha1 hash.
Definition rlm_redis.c:156
A lua function or stored procedure we make available as an xlat.
Definition rlm_redis.c:58

Definition at line 134 of file rlm_redis.c.

◆ redis_args

xlat_arg_parser_t const redis_args[]
static
Initial value:
= {
{ .required = true, .concat = true, .type = FR_TYPE_STRING },
{ .variadic = XLAT_ARG_VARIADIC_EMPTY_KEEP, .concat = true, .type = FR_TYPE_STRING },
}
@ FR_TYPE_STRING
String of printable characters.
@ XLAT_ARG_VARIADIC_EMPTY_KEEP
Empty argument groups are left alone, and either passed through as empty groups or null boxes.
Definition xlat.h:138
#define XLAT_ARG_PARSER_TERMINATOR
Definition xlat.h:171

Definition at line 650 of file rlm_redis.c.

◆ redis_lua_func_args

xlat_arg_parser_t const redis_lua_func_args[]
static
Initial value:
= {
{ .required = true, .single = true, .type = FR_TYPE_UINT64 },
{ .variadic = XLAT_ARG_VARIADIC_EMPTY_KEEP, .concat = true, .type = FR_TYPE_STRING },
}
@ FR_TYPE_UINT64
64 Bit unsigned integer.

Definition at line 376 of file rlm_redis.c.

◆ redis_node_xlat_args

xlat_arg_parser_t const redis_node_xlat_args[]
static
Initial value:
= {
{ .required = true, .single = true, .type = FR_TYPE_STRING },
{ .single = true, .type = FR_TYPE_UINT32 },
}
@ FR_TYPE_UINT32
32 Bit unsigned integer.

Definition at line 319 of file rlm_redis.c.

◆ rlm_redis

module_rlm_t rlm_redis
Initial value:
= {
.common = {
.name = "redis",
.inst_size = sizeof(rlm_redis_t),
.onload = mod_load,
.bootstrap = mod_bootstrap,
.instantiate = mod_instantiate,
.coord_attach = mod_coord_attach,
.detach = mod_detach,
.thread_instantiate = mod_thread_instantiate,
.thread_detach = mod_thread_detach,
}
}
#define MODULE_MAGIC_INIT
Stop people using different module/library/server versions together.
Definition dl_module.h:63
static const conf_parser_t config[]
Definition base.c:162
static int mod_detach(module_detach_ctx_t const *mctx)
Definition rlm_redis.c:976
static int mod_load(void)
Definition rlm_redis.c:1018
static int mod_coord_attach(module_thread_inst_ctx_t const *mctx)
Definition rlm_redis.c:896
static int mod_bootstrap(module_inst_ctx_t const *mctx)
Definition rlm_redis.c:987
static int mod_thread_instantiate(module_thread_inst_ctx_t const *mctx)
Definition rlm_redis.c:880
static int mod_thread_detach(module_thread_inst_ctx_t const *mctx)
Definition rlm_redis.c:965
static int mod_instantiate(module_inst_ctx_t const *mctx)
Definition rlm_redis.c:917
static conf_parser_t module_config[]
Definition rlm_redis.c:147
#define MODULE_THREAD_INST(_ctype)
Definition module.h:258

Definition at line 1026 of file rlm_redis.c.

◆ rlm_redis_dict

fr_dict_autoload_t rlm_redis_dict
Initial value:
= {
{ .out = &dict_redis, .proto = "redis" },
}
#define DICT_AUTOLOAD_TERMINATOR
Definition dict.h:311
static fr_dict_t const * dict_redis
Definition rlm_redis.c:47

Definition at line 50 of file rlm_redis.c.