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

redis based cache. More...

#include <freeradius-devel/server/base.h>
#include <freeradius-devel/util/debug.h>
#include "../../rlm_cache.h"
#include <freeradius-devel/redis/base.h>
#include <freeradius-devel/redis/cluster_async.h>
#include <freeradius-devel/io/coord_pair.h>
+ Include dependency graph for rlm_cache_redis.c:

Go to the source code of this file.

Data Structures

struct  rlm_cache_redis_rctx_t
 
struct  rlm_cache_redis_t
 
struct  rlm_cache_redis_thread_t
 

Macros

#define LOG_PREFIX   "cache - redis"
 

Functions

static cache_status_t cache_entry_expire (UNUSED void **rctx_out, UNUSED rlm_cache_config_t const *config, void *instance, request_t *request, UNUSED void *handle, fr_value_box_t const *key)
 Call delete the cache entry from redis.
 
static void cache_entry_expire_results (request_t *request, UNUSED fr_redis_command_t *cmd, redisReply *reply, void *rctx)
 
static cache_status_t cache_entry_expire_resume (UNUSED rlm_cache_config_t const *config, void *instance, UNUSED request_t *request, UNUSED void *handle, void *rctx)
 
static cache_status_t cache_entry_find (UNUSED rlm_cache_entry_t **out, void **rctx_out, UNUSED rlm_cache_config_t const *config, void *instance, request_t *request, UNUSED void *handle, fr_value_box_t const *key)
 Locate a cache entry in redis.
 
static void cache_entry_find_results (request_t *request, UNUSED fr_redis_command_t *cmd, redisReply *reply, void *rctx)
 
static cache_status_t cache_entry_find_resume (rlm_cache_entry_t **out, UNUSED rlm_cache_config_t const *config, void *instance, UNUSED request_t *request, UNUSED void *handle, void *rctx)
 
static void cache_entry_free (rlm_cache_entry_t *c)
 
static cache_status_t cache_entry_insert (UNUSED void **rctx_out, UNUSED rlm_cache_config_t const *config, void *instance, request_t *request, UNUSED void *handle, const rlm_cache_entry_t *c)
 Insert a new entry into the data store.
 
static void cache_entry_insert_results (request_t *request, UNUSED fr_redis_command_t *cmd, redisReply *reply, void *rctx)
 
static cache_status_t cache_entry_insert_resume (rlm_cache_entry_t **out, UNUSED rlm_cache_config_t const *config, void *instance, UNUSED request_t *request, UNUSED void *handle, void *rctx)
 
static void cache_redis_cancel (UNUSED rlm_cache_config_t const *config, UNUSED void *instance, request_t *request, UNUSED void *handle, void *rctx)
 
static int cache_redis_rctx_free (rlm_cache_redis_rctx_t *rctx)
 
static cache_status_t cache_redis_results (request_t *request, rlm_cache_redis_t *inst, fr_redis_command_set_t *cmds, fr_redis_async_cmd_t *cmd, cache_status_t rcode)
 Process the results of Redis cache commands.
 
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)
 Create a new rlm_cache_redis instance.
 
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_cache_redis_thread_t)
 

Variables

static fr_dict_attr_t const * attr_cache_created
 
static fr_dict_attr_t const * attr_cache_expires
 
static fr_dict_t const * dict_freeradius
 
static fr_dict_t const * dict_redis
 
static conf_parser_t driver_config []
 
rlm_cache_driver_t rlm_cache_redis
 
fr_dict_autoload_t rlm_cache_redis_dict []
 
fr_dict_attr_autoload_t rlm_cache_redis_dict_attr []
 

Detailed Description

redis based cache.

Id
04341bcab49f6206b00a491175ea925d155f6d89

Definition in file rlm_cache_redis.c.


Data Structure Documentation

◆ rlm_cache_redis_rctx_t

struct rlm_cache_redis_rctx_t

Definition at line 60 of file rlm_cache_redis.c.

+ Collaboration diagram for rlm_cache_redis_rctx_t:
Data Fields
fr_redis_async_cmd_t * cmd
char ** cmd_str
fr_redis_command_set_t * cmds
rlm_cache_entry_t * entry
fr_value_box_t const * key
cache_status_t rcode

◆ rlm_cache_redis_t

struct rlm_cache_redis_t

Definition at line 39 of file rlm_cache_redis.c.

+ Collaboration diagram for rlm_cache_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.
tmpl_t * created_attr LHS of the Cache-Created map.
tmpl_t * expires_attr LHS of the Cache-Expires map.
module_instance_t const * mi Module instance.
CONF_SECTION * tls_conf TLS CONF_SECTION.

◆ rlm_cache_redis_thread_t

struct rlm_cache_redis_thread_t

Definition at line 54 of file rlm_cache_redis.c.

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

Macro Definition Documentation

◆ LOG_PREFIX

#define LOG_PREFIX   "cache - redis"

Definition at line 24 of file rlm_cache_redis.c.

Function Documentation

◆ cache_entry_expire()

static cache_status_t cache_entry_expire ( UNUSED void **  rctx_out,
UNUSED rlm_cache_config_t const *  config,
void *  instance,
request_t request,
UNUSED void *  handle,
fr_value_box_t const *  key 
)
static

Call delete the cache entry from redis.

Note
This callback is not optional.
Parameters
[out]rctx_outWhere to write a pointer to a resume context for async drivers.
[in]configfor this instance of the rlm_cache module.
[in]instanceDriver specific instance data.
[in]requestThe current request.
[in]handlethe driver gave us when we called cache_acquire_t, or NULL if no cache_acquire_t callback was provided.
[in]keyof entry to expire.
Returns
  • CACHE_RECONNECT - If handle needs to be reinitialised/reconnected.
  • CACHE_ERROR - If the entry couldn't be expired.
  • CACHE_OK - If the entry was expired.
  • CACHE_MISS - If the entry didn't exist, so couldn't be expired.
  • CACHE_YIELD - The driver has initiated an async expire and yielded.

Definition at line 659 of file rlm_cache_redis.c.

+ Here is the call graph for this function:

◆ cache_entry_expire_results()

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

Definition at line 640 of file rlm_cache_redis.c.

+ Here is the caller graph for this function:

◆ cache_entry_expire_resume()

static cache_status_t cache_entry_expire_resume ( UNUSED rlm_cache_config_t const *  config,
void *  instance,
UNUSED request_t request,
UNUSED void *  handle,
void *  rctx 
)
static

Definition at line 631 of file rlm_cache_redis.c.

+ Here is the call graph for this function:

◆ cache_entry_find()

static cache_status_t cache_entry_find ( UNUSED rlm_cache_entry_t **  out,
void **  rctx_out,
UNUSED rlm_cache_config_t const *  config,
void *  instance,
request_t request,
UNUSED void *  handle,
fr_value_box_t const *  key 
)
static

Locate a cache entry in redis.

If a cache entry is found, but the cache entry needs to be deserialized, the driver is expected to allocate an appropriately sized rlm_cache_entry_t, perform the deserialisation, and write a pointer to the new entry to out, returning CACHE_OK.

If the rlm_cache_handle_t is inviable, the driver should return CACHE_RECONNECT, to have it reinitialised/reconnected.

Parameters
[out]outWhere to write a pointer to the retrieved entry (if there was one).
[out]rctx_outWhere to write a pointer to a resume context for async drivers.
[in]configfor this instance of the rlm_cache module.
[in]instanceDriver specific instance data.
[in]requestThe current request.
[in]handlethe driver gave us when we called cache_acquire_t, or NULL if no cache_acquire_t callback was provided.
[in]keyto use to lookup cache entry
Returns

Definition at line 395 of file rlm_cache_redis.c.

+ Here is the call graph for this function:

◆ cache_entry_find_results()

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

Definition at line 296 of file rlm_cache_redis.c.

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

◆ cache_entry_find_resume()

static cache_status_t cache_entry_find_resume ( rlm_cache_entry_t **  out,
UNUSED rlm_cache_config_t const *  config,
void *  instance,
UNUSED request_t request,
UNUSED void *  handle,
void *  rctx 
)
static

Definition at line 285 of file rlm_cache_redis.c.

+ Here is the call graph for this function:

◆ cache_entry_free()

static void cache_entry_free ( rlm_cache_entry_t c)
static

Definition at line 222 of file rlm_cache_redis.c.

+ Here is the call graph for this function:

◆ cache_entry_insert()

static cache_status_t cache_entry_insert ( UNUSED void **  rctx_out,
UNUSED rlm_cache_config_t const *  config,
void *  instance,
request_t request,
UNUSED void *  handle,
const rlm_cache_entry_t c 
)
static

Insert a new entry into the data store.

Serialize (if necessary) the entry passed to us, and write it to the cache with the key c->key.

The cache entry should not be freed by the driver, irrespective of success or failure. If the entry needs to be freed after insertion because a local copy should not be kept, the driver should provide a cache_entry_free_t callback.

If the rlm_cache_handle_t is inviable, the driver should return CACHE_RECONNECT, to have it reinitialised/reconnected.

Note
This callback is not optional.
This callback must overwrite existing cache entries on insert.
Parameters
rctx_outWhere to write a pointer to a resume context for async drivers.
configfor this instance of the rlm_cache module.
instanceDriver specific instance data.
requestThe current request.
handlethe driver gave us when we called cache_acquire_t, or NULL if no cache_acquire_t callback was provided.
cto insert.
Returns
  • CACHE_RECONNECT - If handle needs to be reinitialised/reconnected.
  • CACHE_ERROR - If the insert couldn't be completed.
  • CACHE_OK - If the insert was successful.
  • CACHE_YIELD - The driver has initiated an async insert and yielded.

Definition at line 461 of file rlm_cache_redis.c.

+ Here is the call graph for this function:

◆ cache_entry_insert_results()

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

Definition at line 445 of file rlm_cache_redis.c.

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

◆ cache_entry_insert_resume()

static cache_status_t cache_entry_insert_resume ( rlm_cache_entry_t **  out,
UNUSED rlm_cache_config_t const *  config,
void *  instance,
UNUSED request_t request,
UNUSED void *  handle,
void *  rctx 
)
static

Definition at line 433 of file rlm_cache_redis.c.

+ Here is the call graph for this function:

◆ cache_redis_cancel()

static void cache_redis_cancel ( UNUSED rlm_cache_config_t const *  config,
UNUSED void *  instance,
request_t request,
UNUSED void *  handle,
void *  rctx 
)
static

Definition at line 276 of file rlm_cache_redis.c.

+ Here is the call graph for this function:

◆ cache_redis_rctx_free()

static int cache_redis_rctx_free ( rlm_cache_redis_rctx_t rctx)
static

Definition at line 227 of file rlm_cache_redis.c.

+ Here is the caller graph for this function:

◆ cache_redis_results()

static cache_status_t cache_redis_results ( request_t request,
rlm_cache_redis_t inst,
fr_redis_command_set_t cmds,
fr_redis_async_cmd_t cmd,
cache_status_t  rcode 
)
static

Process the results of Redis cache commands.

Initiating a cluster remap and query redirection if needed.

Definition at line 242 of file rlm_cache_redis.c.

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

◆ mod_coord_attach()

static int mod_coord_attach ( module_thread_inst_ctx_t const *  mctx)
static

Definition at line 175 of file rlm_cache_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 205 of file rlm_cache_redis.c.

+ Here is the call graph for this function:

◆ mod_instantiate()

static int mod_instantiate ( module_inst_ctx_t const *  mctx)
static

Create a new rlm_cache_redis instance.

Parameters
[in]mctxData required for instantiation.
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 98 of file rlm_cache_redis.c.

+ Here is the call graph for this function:

◆ mod_load()

static int mod_load ( void  )
static

Definition at line 216 of file rlm_cache_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 194 of file rlm_cache_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 163 of file rlm_cache_redis.c.

+ Here is the call graph for this function:

◆ REDIS_ASYNC_COORD_CALLBACKS()

REDIS_ASYNC_COORD_CALLBACKS ( rlm_cache_redis_thread_t  )

Variable Documentation

◆ attr_cache_created

fr_dict_attr_t const* attr_cache_created
static

Definition at line 79 of file rlm_cache_redis.c.

◆ attr_cache_expires

fr_dict_attr_t const* attr_cache_expires
static

Definition at line 80 of file rlm_cache_redis.c.

◆ dict_freeradius

fr_dict_t const* dict_freeradius
static

Definition at line 69 of file rlm_cache_redis.c.

◆ dict_redis

fr_dict_t const* dict_redis
static

Definition at line 70 of file rlm_cache_redis.c.

◆ driver_config

conf_parser_t driver_config[]
static
Initial value:
= {
}
#define CONF_PARSER_TERMINATOR
Definition cf_parse.h:669
#define REDIS_COMMON_CONFIG
Definition base.h:143

Definition at line 34 of file rlm_cache_redis.c.

◆ rlm_cache_redis

rlm_cache_driver_t rlm_cache_redis
Initial value:
= {
.common = {
.name = "cache_redis",
.onload = mod_load,
.instantiate = mod_instantiate,
.coord_attach = mod_coord_attach,
.detach = mod_detach,
.inst_size = sizeof(rlm_cache_redis_t),
.thread_instantiate = mod_thread_instantiate,
.thread_detach = mod_thread_detach,
.config = driver_config,
},
.find_resume = cache_entry_find_resume,
.find_cancel = cache_redis_cancel,
.insert = cache_entry_insert,
.insert_resume = cache_entry_insert_resume,
.insert_cancel = cache_redis_cancel,
.expire = cache_entry_expire,
.expire_resume = cache_entry_expire_resume,
.expire_cancel = cache_redis_cancel,
}
#define MODULE_MAGIC_INIT
Stop people using different module/library/server versions together.
Definition dl_module.h:63
static cache_status_t cache_entry_find_resume(rlm_cache_entry_t **out, UNUSED rlm_cache_config_t const *config, void *instance, UNUSED request_t *request, UNUSED void *handle, void *rctx)
static int mod_detach(module_detach_ctx_t const *mctx)
static int mod_load(void)
static cache_status_t cache_entry_expire_resume(UNUSED rlm_cache_config_t const *config, void *instance, UNUSED request_t *request, UNUSED void *handle, void *rctx)
static int mod_coord_attach(module_thread_inst_ctx_t const *mctx)
static cache_status_t cache_entry_expire(UNUSED void **rctx_out, UNUSED rlm_cache_config_t const *config, void *instance, request_t *request, UNUSED void *handle, fr_value_box_t const *key)
Call delete the cache entry from redis.
static void cache_entry_free(rlm_cache_entry_t *c)
static conf_parser_t driver_config[]
static cache_status_t cache_entry_insert_resume(rlm_cache_entry_t **out, UNUSED rlm_cache_config_t const *config, void *instance, UNUSED request_t *request, UNUSED void *handle, void *rctx)
static int mod_thread_instantiate(module_thread_inst_ctx_t const *mctx)
static void cache_redis_cancel(UNUSED rlm_cache_config_t const *config, UNUSED void *instance, request_t *request, UNUSED void *handle, void *rctx)
static cache_status_t cache_entry_find(UNUSED rlm_cache_entry_t **out, void **rctx_out, UNUSED rlm_cache_config_t const *config, void *instance, request_t *request, UNUSED void *handle, fr_value_box_t const *key)
Locate a cache entry in redis.
static int mod_thread_detach(module_thread_inst_ctx_t const *mctx)
static cache_status_t cache_entry_insert(UNUSED void **rctx_out, UNUSED rlm_cache_config_t const *config, void *instance, request_t *request, UNUSED void *handle, const rlm_cache_entry_t *c)
Insert a new entry into the data store.
static int mod_instantiate(module_inst_ctx_t const *mctx)
Create a new rlm_cache_redis instance.
#define MODULE_THREAD_INST(_ctype)
Definition module.h:258

Definition at line 696 of file rlm_cache_redis.c.

◆ rlm_cache_redis_dict

fr_dict_autoload_t rlm_cache_redis_dict
Initial value:
= {
{ .out = &dict_freeradius, .proto = "freeradius" },
{ .out = &dict_redis, .proto = "redis" },
}
#define DICT_AUTOLOAD_TERMINATOR
Definition dict.h:311
static fr_dict_t const * dict_freeradius
static fr_dict_t const * dict_redis

Definition at line 73 of file rlm_cache_redis.c.

◆ rlm_cache_redis_dict_attr

fr_dict_attr_autoload_t rlm_cache_redis_dict_attr
Initial value:
= {
{ .out = &attr_cache_created, .name = "Cache-Created", .type = FR_TYPE_DATE, .dict = &dict_freeradius },
{ .out = &attr_cache_expires, .name = "Cache-Expires", .type = FR_TYPE_DATE, .dict = &dict_freeradius },
}
@ FR_TYPE_DATE
Unix time stamp, always has value >2^31.
static fr_dict_attr_t const * attr_cache_created
static fr_dict_attr_t const * attr_cache_expires

Definition at line 83 of file rlm_cache_redis.c.