The FreeRADIUS server $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Loading...
Searching...
No Matches
Data Structures | Enumerations | Functions | Variables
rlm_interval.c File Reference

Interval limiting module providing an xlat function. More...

#include <freeradius-devel/server/base.h>
#include <freeradius-devel/server/main_loop.h>
#include <freeradius-devel/server/module_rlm.h>
#include <freeradius-devel/unlang/xlat_func.h>
#include <freeradius-devel/util/rb.h>
#include <freeradius-devel/util/slab.h>
#include <freeradius-devel/util/timer.h>
#include <freeradius-devel/util/debug.h>
#include <freeradius-devel/util/strerror.h>
#include <pthread.h>
+ Include dependency graph for rlm_interval.c:

Go to the source code of this file.

Data Structures

struct  rlm_interval_entry_t
 RBTree entry for keyed lookups. More...
 
struct  rlm_interval_mutable_t
 Mutable data for global scope (allocated outside mprotected instance data) More...
 
struct  rlm_interval_t
 Module instance data. More...
 
struct  rlm_interval_thread_t
 Module thread instance data. More...
 
struct  rlm_interval_xlat_inst_t
 Xlat instance data - stores the xlat expression pointer for keyless lookups. More...
 
struct  rlm_interval_xlat_thread_inst_t
 Xlat thread instance data - stores last_used for keyless thread-scope lookups. More...
 

Enumerations

enum  rlm_interval_scope_t {
  INTERVAL_SCOPE_GLOBAL = 0 ,
  INTERVAL_SCOPE_THREAD
}
 

Functions

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.
 
static int8_t interval_entry_cmp (void const *one, void const *two)
 
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)
 
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 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 interval_xlat_instantiate (xlat_inst_ctx_t const *xctx)
 
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.
 
static int interval_xlat_thread_instantiate (xlat_thread_inst_ctx_t const *xctx)
 
static int mod_bootstrap (module_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)
 
static int mod_thread_instantiate (module_thread_inst_ctx_t const *mctx)
 

Variables

static fr_table_num_sorted_t const interval_scope_table []
 
static size_t interval_scope_table_len = NUM_ELEMENTS(interval_scope_table)
 
static xlat_arg_parser_t const interval_xlat_args []
 
static const conf_parser_t module_config []
 
static conf_parser_t reuse_config []
 
module_rlm_t rlm_interval
 

Detailed Description

Interval limiting module providing an xlat function.

Id
1a042ab5071847a64ce19818a0748b60dcb2dfad

Definition in file rlm_interval.c.


Data Structure Documentation

◆ rlm_interval_entry_t

struct rlm_interval_entry_t

RBTree entry for keyed lookups.

Definition at line 53 of file rlm_interval.c.

+ Collaboration diagram for rlm_interval_entry_t:
Data Fields
fr_timer_t * ev Expiry timer.
fr_value_box_t key Key stored in value box.
fr_rb_node_t node RBTree node.
void * owner Back-pointer to mutable_t or thread_t.

◆ rlm_interval_mutable_t

struct rlm_interval_mutable_t

Mutable data for global scope (allocated outside mprotected instance data)

Definition at line 65 of file rlm_interval.c.

+ Collaboration diagram for rlm_interval_mutable_t:
Data Fields
pthread_mutex_t mutex Mutex for thread safety.
fr_rb_tree_t * tree RBTree for keyed lookups.

◆ rlm_interval_t

struct rlm_interval_t

Module instance data.

Definition at line 72 of file rlm_interval.c.

+ Collaboration diagram for rlm_interval_t:
Data Fields
rlm_interval_mutable_t * mutable Mutable data for global scope.
fr_slab_config_t reuse Slab allocator configuration.
rlm_interval_scope_t scope Global or thread-local scope.

◆ rlm_interval_thread_t

struct rlm_interval_thread_t

Module thread instance data.

Definition at line 80 of file rlm_interval.c.

+ Collaboration diagram for rlm_interval_thread_t:
Data Fields
interval_slab_list_t * slab Slab allocator for entries.
fr_timer_list_t * tl Timer list for entry expiry.
fr_rb_tree_t * tree RBTree for keyed lookups (thread scope only).

◆ rlm_interval_xlat_inst_t

struct rlm_interval_xlat_inst_t

Xlat instance data - stores the xlat expression pointer for keyless lookups.

Definition at line 88 of file rlm_interval.c.

+ Collaboration diagram for rlm_interval_xlat_inst_t:
Data Fields
xlat_exp_t const * ex Cached for keyless lookups.

◆ rlm_interval_xlat_thread_inst_t

struct rlm_interval_xlat_thread_inst_t

Xlat thread instance data - stores last_used for keyless thread-scope lookups.

Definition at line 94 of file rlm_interval.c.

+ Collaboration diagram for rlm_interval_xlat_thread_inst_t:
Data Fields
fr_time_t last_used Last used time for this call site.

Enumeration Type Documentation

◆ rlm_interval_scope_t

Enumerator
INTERVAL_SCOPE_GLOBAL 
INTERVAL_SCOPE_THREAD 

Definition at line 40 of file rlm_interval.c.

Function Documentation

◆ interval_check()

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 
)
static

Check interval limit.

Note
Don't be tempted to move mutex handling in here. Yes you could probably reduce the size of the critical region, but you're going to break something and miss interaction effects. Just don't do it.
Parameters
[in]treeRBTree for lookups.
[in]threadThread instance (for timer list and slab).
[in]ownerBack-pointer to store in new entries (for expiry callback).
[in]expireExpiry callback function.
[in]findEntry with key to search for.
[in]intervalInterval limit interval.
Returns
  • 1 if allowed.
  • 0 if interval limited.
  • -1 on error.

Definition at line 172 of file rlm_interval.c.

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

◆ interval_entry_cmp()

static int8_t interval_entry_cmp ( void const *  one,
void const *  two 
)
static

Definition at line 118 of file rlm_interval.c.

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

◆ interval_expire_global()

static void interval_expire_global ( UNUSED fr_timer_list_t tl,
UNUSED fr_time_t  now,
void *  uctx 
)
static

Timer callback to expire entries (global scope)

Definition at line 143 of file rlm_interval.c.

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

◆ interval_expire_thread()

static void interval_expire_thread ( UNUSED fr_timer_list_t tl,
UNUSED fr_time_t  now,
void *  uctx 
)
static

Timer callback to expire entries (thread scope)

Definition at line 132 of file rlm_interval.c.

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

◆ interval_xlat_global()

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 
)
static

Global scope xlat - always uses mutex-protected tree.

Definition at line 218 of file rlm_interval.c.

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

◆ interval_xlat_instantiate()

static int interval_xlat_instantiate ( xlat_inst_ctx_t const *  xctx)
static

Definition at line 329 of file rlm_interval.c.

+ Here is the caller graph for this function:

◆ interval_xlat_thread()

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 
)
static

Thread scope xlat - uses thread-local tree or module thread instance.

Definition at line 270 of file rlm_interval.c.

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

◆ interval_xlat_thread_instantiate()

static int interval_xlat_thread_instantiate ( xlat_thread_inst_ctx_t const *  xctx)
static

Definition at line 337 of file rlm_interval.c.

+ Here is the caller graph for this function:

◆ mod_bootstrap()

static int mod_bootstrap ( module_inst_ctx_t const *  mctx)
static

Definition at line 420 of file rlm_interval.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 387 of file rlm_interval.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 399 of file rlm_interval.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 349 of file rlm_interval.c.

+ Here is the call graph for this function:

Variable Documentation

◆ interval_scope_table

fr_table_num_sorted_t const interval_scope_table[]
static
Initial value:
= {
{ L("global"), INTERVAL_SCOPE_GLOBAL },
{ L("thread"), INTERVAL_SCOPE_THREAD }
}
#define L(_str)
Helper for initialising arrays of string literals.
Definition build.h:209
@ INTERVAL_SCOPE_GLOBAL
@ INTERVAL_SCOPE_THREAD

Definition at line 45 of file rlm_interval.c.

◆ interval_scope_table_len

size_t interval_scope_table_len = NUM_ELEMENTS(interval_scope_table)
static

Definition at line 49 of file rlm_interval.c.

◆ interval_xlat_args

xlat_arg_parser_t const interval_xlat_args[]
static
Initial value:
= {
{ .required = true, .single = true, .type = FR_TYPE_TIME_DELTA },
{ .single = true, .type = FR_TYPE_STRING },
}
@ FR_TYPE_TIME_DELTA
A period of time measured in nanoseconds.
@ FR_TYPE_STRING
String of printable characters.
#define XLAT_ARG_PARSER_TERMINATOR
Definition xlat.h:170

Definition at line 112 of file rlm_interval.c.

◆ module_config

const conf_parser_t module_config[]
static
Initial value:
= {
{ FR_CONF_OFFSET("scope", rlm_interval_t, scope),
.dflt = "global" },
}
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.
Definition cf_parse.c:1624
#define CONF_PARSER_TERMINATOR
Definition cf_parse.h:660
#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:283
#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:312
static conf_parser_t reuse_config[]
static fr_table_num_sorted_t const interval_scope_table[]
static size_t interval_scope_table_len
Module instance data.

Definition at line 103 of file rlm_interval.c.

◆ reuse_config

conf_parser_t reuse_config[]
static
Initial value:
= {
}
#define FR_SLAB_CONFIG_CONF_PARSER
conf_parser_t entries to populate user configurable slab values
Definition slab.h:35

Definition at line 98 of file rlm_interval.c.

◆ rlm_interval

module_rlm_t rlm_interval
Initial value:
= {
.common = {
.name = "interval",
.inst_size = sizeof(rlm_interval_t),
.thread_inst_size = sizeof(rlm_interval_thread_t),
.config = module_config,
.bootstrap = mod_bootstrap,
.instantiate = mod_instantiate,
.detach = mod_detach,
.thread_instantiate = mod_thread_instantiate,
}
}
#define MODULE_MAGIC_INIT
Stop people using different module/library/server versions together.
Definition dl_module.h:63
static int mod_detach(module_detach_ctx_t const *mctx)
static int mod_bootstrap(module_inst_ctx_t const *mctx)
static int mod_thread_instantiate(module_thread_inst_ctx_t const *mctx)
static const conf_parser_t module_config[]
static int mod_instantiate(module_inst_ctx_t const *mctx)
Module thread instance data.

Definition at line 455 of file rlm_interval.c.