All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Functions | Variables
rlm_cache.c File Reference

Cache values and merge them back into future requests. More...

#include <freeradius-devel/radiusd.h>
#include <freeradius-devel/modules.h>
#include <freeradius-devel/modpriv.h>
#include <freeradius-devel/modcall.h>
#include <freeradius-devel/rad_assert.h>
#include "rlm_cache.h"
+ Include dependency graph for rlm_cache.c:

Go to the source code of this file.

Functions

static int cache_acquire (rlm_cache_handle_t **out, rlm_cache_t const *inst, REQUEST *request)
 Get exclusive use of a handle to access the cache. More...
 
static rlm_cache_entry_tcache_alloc (rlm_cache_t const *inst, REQUEST *request)
 Allocate a cache entry. More...
 
static rlm_rcode_t cache_expire (rlm_cache_t const *inst, REQUEST *request, rlm_cache_handle_t **handle, uint8_t const *key, size_t key_len)
 Expire a cache entry (removing it from the datastore) More...
 
static rlm_rcode_t cache_find (rlm_cache_entry_t **out, rlm_cache_t const *inst, REQUEST *request, rlm_cache_handle_t **handle, uint8_t const *key, size_t key_len)
 Find a cached entry. More...
 
static void cache_free (rlm_cache_t const *inst, rlm_cache_entry_t **c)
 Free memory associated with a cache entry. More...
 
static rlm_rcode_t cache_insert (rlm_cache_t const *inst, REQUEST *request, rlm_cache_handle_t **handle, uint8_t const *key, size_t key_len, int ttl)
 Create and insert a cache entry. More...
 
static rlm_rcode_t cache_merge (rlm_cache_t const *inst, REQUEST *request, rlm_cache_entry_t *c) CC_HINT(nonnull)
 Merge a cached entry into a REQUEST. More...
 
static int cache_reconnect (rlm_cache_handle_t **handle, rlm_cache_t const *inst, REQUEST *request)
 Reconnect an suspected inviable handle. More...
 
static void cache_release (rlm_cache_t const *inst, REQUEST *request, rlm_cache_handle_t **handle)
 Release a handle we previously acquired. More...
 
static rlm_rcode_t cache_set_ttl (rlm_cache_t const *inst, REQUEST *request, rlm_cache_handle_t **handle, rlm_cache_entry_t *c)
 Update the TTL of an entry. More...
 
static int cache_verify (vp_map_t *map, void *ctx)
 Verify that a map in the cache section makes sense. More...
 
static ssize_t cache_xlat (char **out, UNUSED size_t freespace, void const *mod_inst, UNUSED void const *xlat_inst, REQUEST *request, char const *fmt) CC_HINT(nonnull)
 Allow single attribute values to be retrieved from the cache. More...
 
static int mod_bootstrap (CONF_SECTION *conf, void *instance)
 Register module xlats. More...
 
static rlm_rcode_t mod_cache_it (void *instance, REQUEST *request) CC_HINT(nonnull)
 Do caching checks. More...
 
static int mod_detach (void *instance)
 Free any memory allocated under the instance. More...
 
static int mod_instantiate (CONF_SECTION *conf, void *instance)
 Create a new rlm_cache_instance. More...
 

Variables

static const CONF_PARSER module_config []
 
module_t rlm_cache
 

Detailed Description

Cache values and merge them back into future requests.

Id:
e856bf912afe470b43e46a6472460fdd1de18c83

Definition in file rlm_cache.c.

Function Documentation

static int cache_acquire ( rlm_cache_handle_t **  out,
rlm_cache_t const *  inst,
REQUEST request 
)
static

Get exclusive use of a handle to access the cache.

Definition at line 58 of file rlm_cache.c.

+ Here is the caller graph for this function:

static rlm_cache_entry_t* cache_alloc ( rlm_cache_t const *  inst,
REQUEST request 
)
static

Allocate a cache entry.

This is used so that drivers may use their own allocation functions to allocate structures larger than the normal rlm_cache_entry_t.

If the driver doesn't specify a custom allocation function, the cache entry is talloced in the NULL ctx.

Definition at line 95 of file rlm_cache.c.

+ Here is the caller graph for this function:

static rlm_rcode_t cache_expire ( rlm_cache_t const *  inst,
REQUEST request,
rlm_cache_handle_t **  handle,
uint8_t const *  key,
size_t  key_len 
)
static

Expire a cache entry (removing it from the datastore)

Returns

Definition at line 261 of file rlm_cache.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static rlm_rcode_t cache_find ( rlm_cache_entry_t **  out,
rlm_cache_t const *  inst,
REQUEST request,
rlm_cache_handle_t **  handle,
uint8_t const *  key,
size_t  key_len 
)
static

Find a cached entry.

Returns

Definition at line 182 of file rlm_cache.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void cache_free ( rlm_cache_t const *  inst,
rlm_cache_entry_t **  c 
)
static

Free memory associated with a cache entry.

This does not necessarily remove the entry from the cache, cache_expire should be used for that.

This function should be called when an entry that is known to have been retrieved or inserted into a data store successfully, is no longer needed.

Some drivers (like rlm_cache_rbtree) don't register a free function. This means that the cache entry never needs to be explicitly freed.

Parameters
[in]instModule instance.
[in,out]cCache entry to free.

Definition at line 116 of file rlm_cache.c.

+ Here is the caller graph for this function:

static rlm_rcode_t cache_insert ( rlm_cache_t const *  inst,
REQUEST request,
rlm_cache_handle_t **  handle,
uint8_t const *  key,
size_t  key_len,
int  ttl 
)
static

Create and insert a cache entry.

Returns

Definition at line 289 of file rlm_cache.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static rlm_rcode_t cache_merge ( rlm_cache_t const *  inst,
REQUEST request,
rlm_cache_entry_t c 
)
static

Merge a cached entry into a REQUEST.

Returns

Definition at line 131 of file rlm_cache.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static int cache_reconnect ( rlm_cache_handle_t **  handle,
rlm_cache_t const *  inst,
REQUEST request 
)
static

Reconnect an suspected inviable handle.

Definition at line 80 of file rlm_cache.c.

+ Here is the caller graph for this function:

static void cache_release ( rlm_cache_t const *  inst,
REQUEST request,
rlm_cache_handle_t **  handle 
)
static

Release a handle we previously acquired.

Definition at line 68 of file rlm_cache.c.

+ Here is the caller graph for this function:

static rlm_rcode_t cache_set_ttl ( rlm_cache_t const *  inst,
REQUEST request,
rlm_cache_handle_t **  handle,
rlm_cache_entry_t c 
)
static

Update the TTL of an entry.

Returns

Definition at line 472 of file rlm_cache.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static int cache_verify ( vp_map_t map,
void *  ctx 
)
static

Verify that a map in the cache section makes sense.

Definition at line 522 of file rlm_cache.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static ssize_t cache_xlat ( char **  out,
UNUSED size_t  freespace,
void const *  mod_inst,
UNUSED void const *  xlat_inst,
REQUEST request,
char const *  fmt 
)
static

Allow single attribute values to be retrieved from the cache.

Definition at line 783 of file rlm_cache.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static int mod_bootstrap ( CONF_SECTION conf,
void *  instance 
)
static

Register module xlats.

Definition at line 877 of file rlm_cache.c.

+ Here is the call graph for this function:

static rlm_rcode_t mod_cache_it ( void *  instance,
REQUEST request 
)
static

Do caching checks.

Since we can update ANY VP list, we do exactly the same thing for all sections (autz / auth / etc.)

If you want to cache something different in different sections, configure another cache module.

Definition at line 544 of file rlm_cache.c.

+ Here is the call graph for this function:

static int mod_detach ( void *  instance)
static

Free any memory allocated under the instance.

Definition at line 849 of file rlm_cache.c.

static int mod_instantiate ( CONF_SECTION conf,
void *  instance 
)
static

Create a new rlm_cache_instance.

Definition at line 897 of file rlm_cache.c.

+ Here is the call graph for this function:

Variable Documentation

const CONF_PARSER module_config[]
static
Initial value:
= {
{ FR_CONF_OFFSET("driver", PW_TYPE_STRING, rlm_cache_config_t, driver_name), .dflt = "rlm_cache_rbtree" },
{ FR_CONF_OFFSET("ttl", PW_TYPE_INTEGER, rlm_cache_config_t, ttl), .dflt = "500" },
{ FR_CONF_OFFSET("max_entries", PW_TYPE_INTEGER, rlm_cache_config_t, max_entries), .dflt = "0" },
{ FR_CONF_OFFSET("epoch", PW_TYPE_SIGNED, rlm_cache_config_t, epoch), .dflt = "0" },
{ FR_CONF_OFFSET("add_stats", PW_TYPE_BOOLEAN, rlm_cache_config_t, stats), .dflt = "no" },
}
32 Bit signed integer.
Definition: radius.h:45
#define CONF_PARSER_TERMINATOR
Definition: conffile.h:289
static rc_stats_t stats
Definition: radclient.c:47
A truth value.
Definition: radius.h:56
32 Bit unsigned integer.
Definition: radius.h:34
#define FR_CONF_OFFSET(_n, _t, _s, _f)
Definition: conffile.h:168
#define PW_TYPE_REQUIRED
Error out if no matching CONF_PAIR is found, and no dflt value is set.
Definition: conffile.h:200
String of printable characters.
Definition: radius.h:33
#define PW_TYPE_TMPL
CONF_PAIR should be parsed as a template.
Definition: conffile.h:208
Configuration for the rlm_cache module.
Definition: rlm_cache.h:47

Definition at line 43 of file rlm_cache.c.

module_t rlm_cache
Initial value:
= {
.magic = RLM_MODULE_INIT,
.name = "cache",
.inst_size = sizeof(rlm_cache_t),
.config = module_config,
.bootstrap = mod_bootstrap,
.instantiate = mod_instantiate,
.detach = mod_detach,
.methods = {
},
}
5 methods index for preproxy section.
Definition: modules.h:46
static const CONF_PARSER module_config[]
Definition: rlm_cache.c:43
7 methods index for postauth section.
Definition: modules.h:48
#define RLM_MODULE_INIT
Definition: modules.h:86
struct rlm_cache_t rlm_cache_t
static rlm_rcode_t mod_cache_it(void *instance, REQUEST *request) CC_HINT(nonnull)
Do caching checks.
Definition: rlm_cache.c:544
3 methods index for accounting section.
Definition: modules.h:44
6 methods index for postproxy section.
Definition: modules.h:47
2 methods index for preacct section.
Definition: modules.h:43
static int mod_detach(void *instance)
Free any memory allocated under the instance.
Definition: rlm_cache.c:849
1 methods index for authorize section.
Definition: modules.h:42
static int mod_instantiate(CONF_SECTION *conf, void *instance)
Create a new rlm_cache_instance.
Definition: rlm_cache.c:897
static int mod_bootstrap(CONF_SECTION *conf, void *instance)
Register module xlats.
Definition: rlm_cache.c:877

Definition at line 1012 of file rlm_cache.c.