26RCSID(
"$Id: 1a042ab5071847a64ce19818a0748b60dcb2dfad $")
28#include <freeradius-devel/server/base.h>
29#include <freeradius-devel/server/main_loop.h>
30#include <freeradius-devel/server/module_rlm.h>
31#include <freeradius-devel/unlang/xlat_func.h>
32#include <freeradius-devel/util/rb.h>
33#include <freeradius-devel/util/slab.h>
34#include <freeradius-devel/util/timer.h>
35#include <freeradius-devel/util/debug.h>
36#include <freeradius-devel/util/strerror.h>
83 interval_slab_list_t *
slab;
125 if (ret != 0)
return ret;
138 interval_slab_release(entry);
148 pthread_mutex_lock(&mutable->mutex);
150 pthread_mutex_unlock(&mutable->mutex);
152 interval_slab_release(entry);
180 entry = interval_slab_reserve(thread->
slab);
181 if (!entry)
return -1;
185 entry->
owner = owner;
190 interval_slab_release(entry);
241 pthread_mutex_lock(&
inst->mutable->mutex);
243 &find, interval->vb_time_delta);
244 pthread_mutex_unlock(&
inst->mutable->mutex);
250 result->vb_bool =
true;
255 result->vb_bool =
false;
260 result->vb_bool =
true;
303 &find, interval->vb_time_delta);
311 result->vb_bool =
true;
316 result->vb_bool =
false;
321 result->vb_bool =
true;
333 xlat_inst->
ex = xctx->
ex;
363 ERROR(
"Failed to create thread-local timer list");
367 t->
slab = interval_slab_list_alloc(t, mctx->
el, &
inst->reuse,
371 ERROR(
"Failed to create thread-local slab allocator");
379 ERROR(
"Failed to create thread-local rbtree");
392 pthread_mutex_destroy(&
inst->mutable->mutex);
408 if (!
inst->mutable->tree) {
409 ERROR(
"Failed to create rbtree");
414 MEM(pthread_mutex_init(&
inst->mutable->mutex, NULL) == 0);
428 switch (
inst->scope) {
433 ERROR(
"Failed to register xlat function");
440 if (!xlat)
goto registration_error;
#define L(_str)
Helper for initialising arrays of string literals.
#define CMP(_a, _b)
Same as CMP_PREFER_SMALLER use when you don't really care about ordering, you just want an ordering.
int cf_table_parse_int(UNUSED TALLOC_CTX *ctx, void *out, UNUSED void *parent, CONF_ITEM *ci, conf_parser_t const *rule)
Generic function for parsing conf pair values as int.
#define CONF_PARSER_TERMINATOR
cf_parse_t func
Override default parsing behaviour for the specified type with a custom parsing function.
#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
#define FR_CONF_OFFSET_SUBSECTION(_name, _flags, _struct, _field, _subcs)
conf_parser_t which populates a sub-struct using a CONF_SECTION
Defines a CONF_PAIR to C data type mapping.
static int fr_dcursor_append(fr_dcursor_t *cursor, void *v)
Insert a single item at the end of the list.
#define fr_assert_msg(_x, _msg,...)
Calls panic_action ifndef NDEBUG, else logs error and causes the server to exit immediately with code...
#define MODULE_MAGIC_INIT
Stop people using different module/library/server versions together.
@ FR_TYPE_TIME_DELTA
A period of time measured in nanoseconds.
@ FR_TYPE_STRING
String of printable characters.
@ FR_TYPE_BOOL
A truth value.
module_instance_t const * mi
Instance of the module being instantiated.
void * thread
Thread specific instance data.
fr_event_list_t * el
Event list to register any IO handlers and timers against.
module_instance_t * mi
Module instance to detach.
void * thread
Thread instance data.
module_instance_t const * mi
Instance of the module being instantiated.
module_instance_t * mi
Instance of the module being instantiated.
Temporary structure to hold arguments for detach calls.
Temporary structure to hold arguments for instantiation calls.
Temporary structure to hold arguments for thread_instantiation calls.
xlat_t * module_rlm_xlat_register(TALLOC_CTX *ctx, module_inst_ctx_t const *mctx, char const *name, xlat_func_t func, fr_type_t return_type)
module_t common
Common fields presented by all modules.
bool fr_rb_delete_by_inline_node(fr_rb_tree_t *tree, fr_rb_node_t *node)
Remove node and free data (if a free function was specified)
void * fr_rb_find(fr_rb_tree_t const *tree, void const *data)
Find an element in the tree, returning the data, not the node.
bool fr_rb_insert(fr_rb_tree_t *tree, void const *data)
Insert data into a tree.
bool fr_rb_delete(fr_rb_tree_t *tree, void const *data)
Remove node and free data (if a free function was specified)
#define fr_rb_inline_talloc_alloc(_ctx, _type, _field, _data_cmp, _data_free)
Allocs a red black that verifies elements are of a specific talloc type.
The main red black tree structure.
static void interval_expire_thread(UNUSED fr_timer_list_t *tl, UNUSED fr_time_t now, void *uctx)
Timer callback to expire entries (thread scope)
static int mod_detach(module_detach_ctx_t const *mctx)
static xlat_arg_parser_t const interval_xlat_args[]
fr_rb_tree_t * tree
RBTree for keyed lookups (thread scope only).
interval_slab_list_t * slab
Slab allocator for entries.
xlat_exp_t const * ex
Cached for keyless lookups.
static int interval_xlat_instantiate(xlat_inst_ctx_t const *xctx)
fr_value_box_t key
Key stored in value box.
module_rlm_t rlm_interval
fr_time_t last_used
Last used time for this call site.
rlm_interval_scope_t scope
Global or thread-local scope.
static xlat_action_t interval_xlat_global(TALLOC_CTX *ctx, fr_dcursor_t *out, xlat_ctx_t const *xctx, request_t *request, fr_value_box_list_t *in)
Global scope xlat - always uses mutex-protected tree.
static int mod_bootstrap(module_inst_ctx_t const *mctx)
fr_timer_t * ev
Expiry timer.
fr_timer_list_t * tl
Timer list for entry expiry.
static conf_parser_t reuse_config[]
static int mod_thread_instantiate(module_thread_inst_ctx_t const *mctx)
static fr_table_num_sorted_t const interval_scope_table[]
static void interval_expire_global(UNUSED fr_timer_list_t *tl, UNUSED fr_time_t now, void *uctx)
Timer callback to expire entries (global scope)
fr_rb_tree_t * tree
RBTree for keyed lookups.
pthread_mutex_t mutex
Mutex for thread safety.
static int8_t interval_entry_cmp(void const *one, void const *two)
static const conf_parser_t module_config[]
static size_t interval_scope_table_len
static xlat_action_t interval_xlat_thread(TALLOC_CTX *ctx, fr_dcursor_t *out, xlat_ctx_t const *xctx, request_t *request, fr_value_box_list_t *in)
Thread scope xlat - uses thread-local tree or module thread instance.
fr_slab_config_t reuse
Slab allocator configuration.
fr_rb_node_t node
RBTree node.
static int mod_instantiate(module_inst_ctx_t const *mctx)
static int interval_xlat_thread_instantiate(xlat_thread_inst_ctx_t const *xctx)
void * owner
Back-pointer to mutable_t or thread_t.
static int interval_check(fr_rb_tree_t *tree, rlm_interval_thread_t *thread, void *owner, fr_timer_cb_t expire, rlm_interval_entry_t *find, fr_time_delta_t interval)
Check interval limit.
RBTree entry for keyed lookups.
Mutable data for global scope (allocated outside mprotected instance data)
Module thread instance data.
Xlat instance data - stores the xlat expression pointer for keyless lookups.
Xlat thread instance data - stores last_used for keyless thread-scope lookups.
size_t inst_size
Size of the module's instance data.
void * data
Module's instance data.
void * boot
Data allocated during the boostrap phase.
#define FR_SLAB_FUNCS(_name, _type)
Define type specific wrapper functions for slabs and slab elements.
#define FR_SLAB_TYPES(_name, _type)
Define type specific wrapper structs for slabs and slab elements.
#define FR_SLAB_CONFIG_CONF_PARSER
conf_parser_t entries to populate user configurable slab values
Tuneable parameters for slabs.
eap_aka_sim_process_conf_t * inst
#define fr_time()
Allow us to arbitrarily manipulate time.
An element in a lexicographically sorted array of name to num mappings.
#define talloc_get_type_abort_const
#define fr_time_add(_a, _b)
Add a time/time delta together.
#define fr_time_gt(_a, _b)
A time delta, a difference in time measured in nanoseconds.
fr_time_t fr_timer_when(fr_timer_t *ev)
Internal timestamp representing when the timer should fire.
fr_timer_list_t * fr_timer_list_lst_alloc(TALLOC_CTX *ctx, fr_timer_list_t *parent)
Allocate a new lst based timer list.
void(* fr_timer_cb_t)(fr_timer_list_t *tl, fr_time_t now, void *uctx)
Called when a timer event fires.
static bool fr_timer_armed(fr_timer_t *ev)
#define XLAT_ARGS(_list,...)
Populate local variables with value boxes from the input list.
unsigned int required
Argument must be present, and non-empty.
#define XLAT_ARG_PARSER_TERMINATOR
@ XLAT_ACTION_DONE
We're done evaluating this level of nesting.
Definition for a single argument consumend by an xlat function.
char const * fr_strerror(void)
Get the last library error.
#define fr_strerror_const(_msg)
void fr_value_box_set_void_shallow(fr_value_box_t *dst, void const *ptr)
Assign a void pointer to a box.
int8_t fr_value_box_cmp(fr_value_box_t const *a, fr_value_box_t const *b)
Compare two values.
void fr_value_box_copy_shallow(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_value_box_t const *src)
Perform a shallow copy of a value_box.
#define fr_value_box_alloc(_ctx, _type, _enumv)
Allocate a value box of a specific type.
static size_t char ** out
void * thread
xlat threadinstance data.
xlat_exp_t * ex
Tokenized expression to use in expansion.
void const * inst
xlat instance data.
void * thread
xlat thread instance data to populate.
module_ctx_t const * mctx
Synthesised module calling ctx.
void * inst
xlat instance data to populate.
An xlat instantiation ctx.
An xlat thread instantiation ctx.
int xlat_func_args_set(xlat_t *x, xlat_arg_parser_t const args[])
Register the arguments of an xlat.
#define xlat_func_instantiate_set(_xlat, _instantiate, _inst_struct, _detach, _uctx)
Set a callback for global instantiation of xlat functions.
#define xlat_func_thread_instantiate_set(_xlat, _instantiate, _inst_struct, _detach, _uctx)
Set a callback for thread-specific instantiation of xlat functions.