24 #include <freeradius-devel/radiusd.h>
25 #include <freeradius-devel/heap.h>
26 #include <freeradius-devel/rad_assert.h>
27 #include "../../rlm_cache.h"
30 # define PTHREAD_MUTEX_LOCK pthread_mutex_lock
31 # define PTHREAD_MUTEX_UNLOCK pthread_mutex_unlock
33 # define PTHREAD_MUTEX_LOCK(_x)
34 # define PTHREAD_MUTEX_UNLOCK(_x)
42 pthread_mutex_t mutex;
107 #ifdef HAVE_PTHREAD_H
127 if (!driver->
cache) {
128 ERROR(
"Failed to create cache");
138 ERROR(
"Failed to create heap for the cache");
142 #ifdef HAVE_PTHREAD_H
165 RERROR(
"Failed allocating cache entry");
180 REQUEST *request,
void *handle, uint8_t
const *key,
size_t key_len)
220 REQUEST *request,
void *handle,
221 uint8_t
const *key,
size_t key_len)
247 REQUEST *request,
void *handle,
257 memcpy(&my_c, &c,
sizeof(my_c));
267 RERROR(
"Failed adding entry");
275 RERROR(
"Failed adding entry to expiry heap");
299 RERROR(
"Entry not in heap");
305 RERROR(
"Failed updating entry TTL. Entry was forcefully expired");
318 REQUEST *request,
void *handle)
333 #ifdef HAVE_PTHREAD_H
341 #ifdef HAVE_PTHREAD_H
360 #ifdef HAVE_PTHREAD_H
368 #ifdef HAVE_PTHREAD_H
381 .
name =
"rlm_cache_rbtree",
cache_driver_t rlm_cache_rbtree
#define pthread_mutex_init(_x, _y)
void rbtree_free(rbtree_t *tree)
bool rbtree_deletebydata(rbtree_t *tree, void const *data)
Delete a node from the tree, based on given data, which MUST have come from rbtree_finddata().
static int cache_heap_cmp(void const *one, void const *two)
Compare two entries by expiry time.
static uint32_t cache_entry_count(UNUSED rlm_cache_config_t const *config, void *driver_inst, REQUEST *request, void *handle)
Return the number of entries in the cache.
void * rbtree_finddata(rbtree_t *tree, void const *data)
Find the user data.
int fr_heap_extract(fr_heap_t *hp, void *data)
void * fr_heap_peek(fr_heap_t *hp)
size_t key_len
Length of key data.
char const * fr_syserror(int num)
Guaranteed to be thread-safe version of strerror.
rbtree_t * cache
Tree for looking up cache keys.
int fr_heap_insert(fr_heap_t *hp, void *data)
time_t expires
When the entry expires.
rlm_cache_entry_t fields
Entry data.
static cache_status_t cache_entry_set_ttl(UNUSED rlm_cache_config_t const *config, void *driver_inst, REQUEST *request, UNUSED void *handle, rlm_cache_entry_t *c)
Update the TTL of an entry.
rbtree_t * rbtree_create(TALLOC_CTX *ctx, rb_comparator_t compare, rb_free_t node_free, int flags)
Create a new RED-BLACK tree.
int rbtree_walk(rbtree_t *tree, rb_order_t order, rb_walker_t compare, void *context)
void fr_heap_delete(fr_heap_t *hp)
static rlm_cache_entry_t * cache_entry_alloc(UNUSED rlm_cache_config_t const *config, UNUSED void *driver_inst, REQUEST *request)
Custom allocation function for the driver.
static void cache_release(UNUSED rlm_cache_config_t const *config, UNUSED void *driver_inst, REQUEST *request, rlm_cache_handle_t *handle)
Release an entry unlocking any mutexes.
#define PTHREAD_MUTEX_LOCK(_x)
static int _mod_detach(rlm_cache_rbtree_t *driver)
Cleanup a cache_rbtree instance.
static cache_status_t cache_entry_insert(rlm_cache_config_t const *config, void *driver_inst, REQUEST *request, void *handle, rlm_cache_entry_t const *c)
Insert a new entry into the data store.
fr_heap_t * heap
For managing entry expiry.
size_t offset
Offset used for heap.
static int cache_acquire(void **handle, UNUSED rlm_cache_config_t const *config, UNUSED void *driver_inst, REQUEST *request)
Lock the rbtree.
Cache entry found/updated.
struct timeval timestamp
When we started processing the request.
bool rbtree_insert(rbtree_t *tree, void *data)
struct rlm_cache_rbtree_entry rlm_cache_rbtree_entry_t
static int mod_instantiate(UNUSED CONF_SECTION *conf, UNUSED rlm_cache_config_t const *config, void *driver_inst)
Create a new cache_rbtree instance.
int fr_talloc_link_ctx(TALLOC_CTX *parent, TALLOC_CTX *child)
Link a parent and a child context, so the child is freed before the parent.
fr_heap_t * fr_heap_create(fr_heap_cmp_t cmp, size_t offset)
static cache_status_t cache_entry_expire(UNUSED rlm_cache_config_t const *config, void *driver_inst, REQUEST *request, void *handle, uint8_t const *key, size_t key_len)
Free an entry and remove it from the data store.
struct rlm_cache_rbtree rlm_cache_rbtree_t
char const * name
Driver name.
#define pthread_mutex_destroy(_x)
uint8_t const * key
Key used to identify entry.
static int cache_entry_cmp(void const *one, void const *two)
Compare two entries by key.
#define PTHREAD_MUTEX_UNLOCK(_x)
static cache_status_t cache_entry_find(rlm_cache_entry_t **out, UNUSED rlm_cache_config_t const *config, void *driver_inst, REQUEST *request, void *handle, uint8_t const *key, size_t key_len)
Locate a cache entry.
static int _cache_entry_free(UNUSED void *ctx, void *data)
Walk over the cache rbtree.
uint32_t rbtree_num_elements(rbtree_t *tree)
Configuration for the rlm_cache module.