The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Data Structures | Macros | Functions | Variables
rlm_sqlcounter.c File Reference

Tracks data usage and other counters using SQL. More...

#include <rlm_sql.h>
#include <freeradius-devel/server/base.h>
#include <freeradius-devel/server/module_rlm.h>
#include <freeradius-devel/util/debug.h>
#include <freeradius-devel/util/dict.h>
#include <freeradius-devel/unlang/function.h>
#include <ctype.h>
+ Include dependency graph for rlm_sqlcounter.c:

Go to the source code of this file.

Data Structures

struct  rlm_sqlcounter_t
 
struct  sqlcounter_call_env_t
 
struct  sqlcounter_rctx_t
 

Macros

#define LOG_PREFIX   "sqlcounter"
 

Functions

static int attr_check (CONF_SECTION *conf, tmpl_t *tmpl, char const *name, fr_dict_attr_flags_t *flags)
 
static int call_env_query_parse (TALLOC_CTX *ctx, void *out, tmpl_rules_t const *t_rules, CONF_ITEM *ci, call_env_ctx_t const *cec, UNUSED call_env_parser_t const *rule)
 Custom call_env parser to tokenize the SQL query xlat used for counter retrieval. More...
 
static int find_next_reset (rlm_sqlcounter_t *inst, fr_time_t now)
 
static int find_prev_reset (rlm_sqlcounter_t *inst, fr_time_t now)
 
static unlang_action_t mod_authorize (rlm_rcode_t *p_result, module_ctx_t const *mctx, request_t *request)
 Check the value of a counter retrieved from an SQL query with a limit More...
 
static unlang_action_t mod_authorize_resume (rlm_rcode_t *p_result, UNUSED int *priority, request_t *request, void *uctx)
 Handle the result of calling the SQL query to retrieve the counter value. More...
 
static int mod_bootstrap (module_inst_ctx_t const *mctx)
 
static int mod_instantiate (module_inst_ctx_t const *mctx)
 

Variables

static fr_dict_t const * dict_freeradius
 
static const conf_parser_t module_config []
 
module_rlm_t rlm_sqlcounter
 
fr_dict_autoload_t rlm_sqlcounter_dict []
 
static const call_env_method_t sqlcounter_call_env
 

Detailed Description

Tracks data usage and other counters using SQL.

Id
c0f1a6590cd92cd855d5d20af8818d2377042da0

Definition in file rlm_sqlcounter.c.


Data Structure Documentation

◆ rlm_sqlcounter_t

struct rlm_sqlcounter_t

Definition at line 63 of file rlm_sqlcounter.c.

+ Collaboration diagram for rlm_sqlcounter_t:
Data Fields
bool auto_extend If the remaining allowance is sufficient to reach the next period allow for that in setting the reply attribute.
tmpl_t * counter_attr Daily-Session-Time.
tmpl_t * end_attr &control.${.:instance}-End
tmpl_t * key User-Name.
fr_time_t last_reset
tmpl_t * limit_attr Max-Daily-Session.
char const * query SQL query to retrieve current session time.
char const * reset Daily, weekly, monthly, never or user defined.
fr_time_t reset_time
char const * sql_name Instance of SQL module to use, usually just 'sql'.
tmpl_t * start_attr &control.${.:instance}-Start
bool utc Use UTC time.

◆ sqlcounter_call_env_t

struct sqlcounter_call_env_t

Definition at line 105 of file rlm_sqlcounter.c.

+ Collaboration diagram for sqlcounter_call_env_t:
Data Fields
xlat_exp_head_t * query_xlat Tokenized xlat to run query.
tmpl_t * reply_attr Attribute to write timeout to.
tmpl_t * reply_msg_attr Attribute to write reply message to.

◆ sqlcounter_rctx_t

struct sqlcounter_rctx_t

Definition at line 251 of file rlm_sqlcounter.c.

+ Collaboration diagram for sqlcounter_rctx_t:
Data Fields
sqlcounter_call_env_t * env
rlm_sqlcounter_t * inst
bool last_success
fr_pair_t * limit
fr_value_box_list_t result

Macro Definition Documentation

◆ LOG_PREFIX

#define LOG_PREFIX   "sqlcounter"

Definition at line 27 of file rlm_sqlcounter.c.

Function Documentation

◆ attr_check()

static int attr_check ( CONF_SECTION conf,
tmpl_t tmpl,
char const *  name,
fr_dict_attr_flags_t flags 
)
inlinestatic

Definition at line 542 of file rlm_sqlcounter.c.

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

◆ call_env_query_parse()

static int call_env_query_parse ( TALLOC_CTX *  ctx,
void *  out,
tmpl_rules_t const *  t_rules,
CONF_ITEM ci,
call_env_ctx_t const *  cec,
UNUSED call_env_parser_t const *  rule 
)
static

Custom call_env parser to tokenize the SQL query xlat used for counter retrieval.

Definition at line 446 of file rlm_sqlcounter.c.

+ Here is the call graph for this function:

◆ find_next_reset()

static int find_next_reset ( rlm_sqlcounter_t inst,
fr_time_t  now 
)
static

Definition at line 119 of file rlm_sqlcounter.c.

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

◆ find_prev_reset()

static int find_prev_reset ( rlm_sqlcounter_t inst,
fr_time_t  now 
)
static

Definition at line 187 of file rlm_sqlcounter.c.

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

◆ mod_authorize()

static unlang_action_t mod_authorize ( rlm_rcode_t p_result,
module_ctx_t const *  mctx,
request_t request 
)
static

Check the value of a counter retrieved from an SQL query with a limit

Module specific attributes containing the start / end times are created / updated, the query is tokenized as an xlat call to the relevant SQL module and then pushed on the stack for evaluation.

Definition at line 385 of file rlm_sqlcounter.c.

+ Here is the call graph for this function:

◆ mod_authorize_resume()

static unlang_action_t mod_authorize_resume ( rlm_rcode_t p_result,
UNUSED int *  priority,
request_t request,
void *  uctx 
)
static

Handle the result of calling the SQL query to retrieve the counter value.

Create / update the counter attribute in the control list If counter > limit, optionally populate a reply message and return RLM_MODULE_REJECT. Otherwise, optionally populate a reply attribute with the value of limit - counter and return RLM_MODULE_UPDATED. If no reply attribute is set, return RLM_MODULE_OK.

Definition at line 266 of file rlm_sqlcounter.c.

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

◆ mod_bootstrap()

static int mod_bootstrap ( module_inst_ctx_t const *  mctx)
static

Definition at line 560 of file rlm_sqlcounter.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 504 of file rlm_sqlcounter.c.

+ Here is the call graph for this function:

Variable Documentation

◆ dict_freeradius

fr_dict_t const* dict_freeradius
static

Definition at line 111 of file rlm_sqlcounter.c.

◆ module_config

const conf_parser_t module_config[]
static
Initial value:
= {
{ FR_CONF_OFFSET_FLAGS("sql_module_instance", CONF_FLAG_REQUIRED, rlm_sqlcounter_t, sql_name) },
{ FR_CONF_OFFSET_FLAGS("auto_extend", CONF_FLAG_OK_MISSING, rlm_sqlcounter_t, auto_extend) },
{ FR_CONF_OFFSET_FLAGS("key", CONF_FLAG_NOT_EMPTY, rlm_sqlcounter_t, key), .dflt = "%{%{Stripped-User-Name} || %{User-Name}}", .quote = T_DOUBLE_QUOTED_STRING },
{ FR_CONF_OFFSET_FLAGS("reset_period_start_name", CONF_FLAG_ATTRIBUTE, rlm_sqlcounter_t, start_attr),
.dflt = "&control.${.:instance}-Reset-Start", .quote = T_BARE_WORD },
{ FR_CONF_OFFSET_FLAGS("reset_period_end_name", CONF_FLAG_ATTRIBUTE, rlm_sqlcounter_t, end_attr),
.dflt = "&control.${.:instance}-Reset-End", .quote = T_BARE_WORD },
}
#define CONF_PARSER_TERMINATOR
Definition: cf_parse.h:627
#define FR_CONF_OFFSET_FLAGS(_name, _flags, _struct, _field)
conf_parser_t which parses a single CONF_PAIR, writing the result to a field in a struct
Definition: cf_parse.h:256
@ CONF_FLAG_REQUIRED
Error out if no matching CONF_PAIR is found, and no dflt value is set.
Definition: cf_parse.h:405
@ CONF_FLAG_ATTRIBUTE
Value must resolve to attribute in dict (deprecated, use CONF_FLAG_TMPL).
Definition: cf_parse.h:407
@ CONF_FLAG_NOT_EMPTY
CONF_PAIR is required to have a non zero length value.
Definition: cf_parse.h:420
@ CONF_FLAG_XLAT
string will be dynamically expanded.
Definition: cf_parse.h:416
@ CONF_FLAG_OK_MISSING
OK if it's missing.
Definition: cf_parse.h:427
@ T_BARE_WORD
Definition: token.h:120
@ T_DOUBLE_QUOTED_STRING
Definition: token.h:121

Definition at line 82 of file rlm_sqlcounter.c.

◆ rlm_sqlcounter

module_rlm_t rlm_sqlcounter
Initial value:
= {
.common = {
.name = "sqlcounter",
.inst_size = sizeof(rlm_sqlcounter_t),
.bootstrap = mod_bootstrap,
},
.method_group = {
.bindings = (module_method_binding_t[]){
{ .section = SECTION_NAME(CF_IDENT_ANY, CF_IDENT_ANY), .method = mod_authorize, .method_env = &sqlcounter_call_env },
}
}
}
#define CF_IDENT_ANY
Definition: cf_util.h:78
#define MODULE_MAGIC_INIT
Stop people using different module/library/server versions together.
Definition: dl_module.h:63
static const conf_parser_t config[]
Definition: base.c:183
static int instantiate(module_inst_ctx_t const *mctx)
Definition: rlm_rest.c:1302
static int mod_bootstrap(module_inst_ctx_t const *mctx)
static unlang_action_t mod_authorize(rlm_rcode_t *p_result, module_ctx_t const *mctx, request_t *request)
Check the value of a counter retrieved from an SQL query with a limit
static const call_env_method_t sqlcounter_call_env
static const conf_parser_t module_config[]
static int mod_instantiate(module_inst_ctx_t const *mctx)
#define SECTION_NAME(_name1, _name2)
Define a section name consisting of a verb and a noun.
Definition: section.h:40
#define MODULE_BINDING_TERMINATOR
Terminate a module binding list.
Definition: module.h:151
Named methods exported by a module.
Definition: module.h:173

Definition at line 584 of file rlm_sqlcounter.c.

◆ rlm_sqlcounter_dict

fr_dict_autoload_t rlm_sqlcounter_dict
Initial value:
= {
{ .out = &dict_freeradius, .proto = "freeradius" },
{ NULL }
}
static fr_dict_t const * dict_freeradius

Definition at line 114 of file rlm_sqlcounter.c.

◆ sqlcounter_call_env

const call_env_method_t sqlcounter_call_env
static
Initial value:
= {
.env = (call_env_parser_t[]){
.pair.func = call_env_query_parse },
}
}
#define CALL_ENV_TERMINATOR
Definition: call_env.h:231
#define FR_CALL_ENV_METHOD_OUT(_inst)
Helper macro for populating the size/type fields of a call_env_method_t from the output structure typ...
Definition: call_env.h:235
@ CALL_ENV_FLAG_PARSE_ONLY
The result of parsing will not be evaluated at runtime.
Definition: call_env.h:85
@ CALL_ENV_FLAG_REQUIRED
Associated conf pair or section is required.
Definition: call_env.h:75
#define FR_CALL_ENV_PARSE_ONLY_OFFSET(_name, _cast_type, _flags, _struct, _parse_field)
Specify a call_env_parser_t which writes out the result of the parsing phase to the field specified.
Definition: call_env.h:384
Per method call config.
Definition: call_env.h:175
@ FR_TYPE_VOID
User data.
Definition: merged_model.c:127
static int call_env_query_parse(TALLOC_CTX *ctx, void *out, tmpl_rules_t const *t_rules, CONF_ITEM *ci, call_env_ctx_t const *cec, UNUSED call_env_parser_t const *rule)
Custom call_env parser to tokenize the SQL query xlat used for counter retrieval.

Definition at line 482 of file rlm_sqlcounter.c.