The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Data Structures | 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.h>
#include <freeradius-devel/server/base.h>
#include <freeradius-devel/server/cf_util.h>
#include <freeradius-devel/server/modpriv.h>
#include <freeradius-devel/server/module_rlm.h>
#include <freeradius-devel/server/pool.h>
#include <freeradius-devel/unlang/xlat.h>
#include <freeradius-devel/unlang/xlat_func.h>
#include <freeradius-devel/util/base16.h>
#include <freeradius-devel/util/debug.h>
#include <freeradius-devel/util/log.h>
#include <freeradius-devel/util/talloc.h>
#include <freeradius-devel/util/types.h>
#include <freeradius-devel/util/value.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_t
 rlm_redis module instance More...
 

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. More...
 
static int mod_bootstrap (module_inst_ctx_t const *mctx)
 
static int mod_instantiate (module_inst_ctx_t const *mctx)
 
static int mod_load (void)
 
static int redis_command (fr_redis_rcode_t *status_out, redisReply **reply_out, request_t *request, fr_redis_conn_t *conn, bool read_only, int argc, char const **argv, size_t arg_len[])
 Issue a command against redis and get a response. More...
 
static int redis_lua_func_instantiate (xlat_inst_ctx_t const *xctx)
 Copies the function configuration into xlat function instance data. More...
 
static xlat_action_t redis_lua_func_xlat (TALLOC_CTX *ctx, 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. More...
 
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. More...
 
static xlat_action_t redis_remap_xlat (TALLOC_CTX *ctx, fr_dcursor_t *out, xlat_ctx_t const *xctx, request_t *request, fr_value_box_list_t *in)
 Force a redis cluster remap. More...
 
static xlat_action_t redis_xlat (TALLOC_CTX *ctx, fr_dcursor_t *out, xlat_ctx_t const *xctx, request_t *request, fr_value_box_list_t *in)
 Xlat to make calls to redis. More...
 

Variables

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 []
 
static xlat_arg_parser_t const redis_remap_xlat_args []
 
module_rlm_t rlm_redis
 

Detailed Description

Driver for the Redis noSQL key value store.

Id
1c0adf88680f7432a6adfb72a399b9f190354733
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 66 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 56 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 71 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_t

struct rlm_redis_t

rlm_redis module instance

Definition at line 79 of file rlm_redis.c.

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

Must be first field in this struct.

rlm_redis_lua_t lua Array of functions to register.

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 112 of file rlm_redis.c.

+ Here is the call graph for this function:

◆ mod_bootstrap()

static int mod_bootstrap ( module_inst_ctx_t const *  mctx)
static

Definition at line 861 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 778 of file rlm_redis.c.

+ Here is the call graph for this function:

◆ mod_load()

static int mod_load ( void  )
static

Definition at line 891 of file rlm_redis.c.

+ Here is the call graph for this function:

◆ redis_command()

static int redis_command ( fr_redis_rcode_t status_out,
redisReply **  reply_out,
request_t request,
fr_redis_conn_t conn,
bool  read_only,
int  argc,
char const **  argv,
size_t  arg_len[] 
)
static

Issue a command against redis and get a response.

This is a convenience function for dealing with commands which made need to execute against an ldap replica. It temporarily places the connection in readonly mode to allow commands to be run against ldap replicas, then reverts back to readwrite mode.

Parameters
[out]status_outWhere to write the status from the command.
[out]reply_outWhere to write the reply associated with the highest priority status.
[in]requestThe current request.
[in]connto issue commands with.
[in]read_onlywrap command in READONLY/READWRITE.
[in]argcRedis command argument count.
[in]argvRedis command arguments.
[in]arg_lenOptional array of redis command argument length.
Returns
  • 0 success.
  • -1 normal failure.
  • -2 failure that may leave the connection in a READONLY state.

Definition at line 165 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 566 of file rlm_redis.c.

+ Here is the caller graph for this function:

◆ redis_lua_func_xlat()

static xlat_action_t redis_lua_func_xlat ( TALLOC_CTX *  ctx,
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 module is instantiated or the first time they get executed.

Definition at line 379 of file rlm_redis.c.

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

Variable Documentation

◆ module_config

conf_parser_t module_config[]
static
Initial value:
= {
}
#define CONF_PARSER_TERMINATOR
Definition: cf_parse.h:626
#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:297
#define REDIS_COMMON_CONFIG
Definition: base.h:133
static conf_parser_t module_lua[]
Definition: rlm_redis.c:96
rlm_redis module instance
Definition: rlm_redis.c:79

Definition at line 103 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:345
@ CONF_FLAG_MULTI
CONF_PAIR can have multiple copies.
Definition: cf_parse.h:420
@ CONF_FLAG_OK_MISSING
OK if it's missing.
Definition: cf_parse.h:428
@ CONF_FLAG_SUBSECTION
Instead of putting the information into a configuration structure, the configuration file routines MA...
Definition: cf_parse.h:400
#define CF_IDENT_ANY
Definition: cf_util.h:78
static conf_parser_t module_lua_func[]
Definition: rlm_redis.c:90

Definition at line 96 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:268
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:112
A lua function or stored procedure we make available as an xlat.
Definition: rlm_redis.c:56

Definition at line 90 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.
Definition: merged_model.c:83
@ XLAT_ARG_VARIADIC_EMPTY_KEEP
Empty argument groups are left alone, and either passed through as empty groups or null boxes.
Definition: xlat.h:137
#define XLAT_ARG_PARSER_TERMINATOR
Definition: xlat.h:166

Definition at line 575 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: merged_model.c:100

Definition at line 368 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: merged_model.c:99

Definition at line 311 of file rlm_redis.c.

◆ redis_remap_xlat_args

xlat_arg_parser_t const redis_remap_xlat_args[]
static
Initial value:
= {
{ .required = true, .concat = true, .type = FR_TYPE_STRING },
}

Definition at line 250 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,
}
}
#define MODULE_MAGIC_INIT
Stop people using different module/library/server versions together.
Definition: dl_module.h:65
static const conf_parser_t config[]
Definition: base.c:188
static int mod_load(void)
Definition: rlm_redis.c:891
static int mod_bootstrap(module_inst_ctx_t const *mctx)
Definition: rlm_redis.c:861
static int mod_instantiate(module_inst_ctx_t const *mctx)
Definition: rlm_redis.c:778
static conf_parser_t module_config[]
Definition: rlm_redis.c:103
static int instantiate(module_inst_ctx_t const *mctx)
Definition: rlm_rest.c:1312
@ MODULE_TYPE_THREAD_SAFE
Module is threadsafe.
Definition: module.h:49

Definition at line 899 of file rlm_redis.c.