29 RCSID(
"$Id: 1c8a9200957305b9d3be94ddf8a30077c6fad248 $")
31 #include <freeradius-devel/server/base.h>
32 #include <freeradius-devel/server/module_rlm.h>
33 #include <freeradius-devel/server/modpriv.h>
34 #include <freeradius-devel/util/debug.h>
36 #include <freeradius-devel/redis/base.h>
37 #include <freeradius-devel/redis/cluster.h>
107 redisReply *reply = NULL;
117 if (!
fmt || !*
fmt)
return 0;
133 key = (
uint8_t const *)argv[1];
134 key_len = strlen((
char const *)key);
140 reply = redisCommandArgv(conn->
handle, argc, argv, NULL);
144 RERROR(
"Failed inserting accounting data");
156 switch (reply->type) {
157 case REDIS_REPLY_ERROR:
160 case REDIS_REPLY_INTEGER:
161 if (reply->integer > 0) ret = reply->integer;
169 REDEBUG(
"Expected type \"integer\" got type \"%s\"",
189 if ((
inst->trim_count >= 0) && (ret >
inst->trim_count)) {
205 char const *insert, *trim, *expire;
209 RDEBUG2(
"Could not find account status type in packet");
215 RDEBUG2(
"Unknown Acct-Status-Type %u",
vp->vp_uint32);
238 if (!
inst->cluster)
return -1;
unlang_action_t
Returned by unlang_op_t calls, determine the next action of the interpreter.
static int const char * fmt
#define CONF_PARSER_TERMINATOR
#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_POINTER(_name, _type, _flags, _res_p)
conf_parser_t which parses a single CONF_PAIR producing a single global result
#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
@ CONF_FLAG_REQUIRED
Error out if no matching CONF_PAIR is found, and no dflt value is set.
@ CONF_FLAG_XLAT
string will be dynamically expanded.
@ CONF_FLAG_SUBSECTION
Instead of putting the information into a configuration structure, the configuration file routines MA...
Defines a CONF_PAIR to C data type mapping.
A section grouping multiple CONF_PAIR.
CONF_SECTION * cf_section_find(CONF_SECTION const *cs, char const *name1, char const *name2)
Find a CONF_SECTION with name1 and optionally name2.
CONF_PAIR * cf_pair_find(CONF_SECTION const *cs, char const *attr)
Search for a CONF_PAIR with a specific name.
char const * cf_pair_value(CONF_PAIR const *pair)
Return the value of a CONF_PAIR.
fr_redis_rcode_t fr_redis_cluster_state_next(fr_redis_cluster_state_t *state, fr_redis_conn_t **conn, fr_redis_cluster_t *cluster, request_t *request, fr_redis_rcode_t status, redisReply **reply)
Get the next connection to attempt a command against.
fr_redis_rcode_t fr_redis_cluster_state_init(fr_redis_cluster_state_t *state, fr_redis_conn_t **conn, fr_redis_cluster_t *cluster, request_t *request, uint8_t const *key, size_t key_len, bool read_only)
Resolve a key to a pool, and reserve a connection in that pool.
fr_redis_cluster_t * fr_redis_cluster_alloc(TALLOC_CTX *ctx, CONF_SECTION *module, fr_redis_conf_t *conf, bool triggers_enabled, char const *log_prefix, char const *trigger_prefix, fr_pair_list_t *trigger_args)
Allocate and initialise a new cluster structure.
Redis connection sequence state.
#define fr_cond_assert(_x)
Calls panic_action ifndef NDEBUG, else logs error and evaluates to value of _x.
fr_dict_enum_value_t * fr_dict_enum_by_value(fr_dict_attr_t const *da, fr_value_box_t const *value)
Lookup the structure representing an enum value in a fr_dict_attr_t.
fr_dict_attr_t const ** out
Where to write a pointer to the resolved fr_dict_attr_t.
fr_dict_t const ** out
Where to write a pointer to the loaded/resolved fr_dict_t.
char const * name
Enum name.
Specifies an attribute which must be present for the module to function.
Specifies a dictionary which must be loaded/loadable for the module to function.
Value of an enumerated attribute.
#define MODULE_MAGIC_INIT
Stop people using different module/library/server versions together.
#define RPEDEBUG(fmt,...)
int rad_expand_xlat(request_t *request, char const *cmd, int max_argc, char const *argv[], bool can_fail, size_t argv_buflen, char *argv_buf)
Split string into words and expand each one.
@ L_DBG_LVL_2
2nd highest priority debug messages (-xx | -X).
@ FR_TYPE_UINT32
32 Bit unsigned integer.
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 module calls.
Temporary structure to hold arguments for instantiation calls.
module_t common
Common fields presented by all modules.
fr_pair_t * fr_pair_find_by_da(fr_pair_list_t const *list, fr_pair_t const *prev, fr_dict_attr_t const *da)
Find the first pair with a matching da.
static const conf_parser_t config[]
#define RETURN_MODULE_NOOP
rlm_rcode_t
Return codes indicating the result of the module call.
#define MAX_REDIS_COMMAND_LEN
redisContext * handle
Hiredis context used when issuing commands.
#define REDIS_COMMON_CONFIG
void fr_redis_reply_print(fr_log_lvl_t lvl, redisReply *reply, request_t *request, int idx)
Print the response data in a useful treelike form.
static void fr_redis_reply_free(redisReply **reply)
Wrap freeReplyObject so we consistently check for NULL pointers.
void fr_redis_version_print(void)
Print the version of libhiredis the server was built against.
fr_redis_rcode_t fr_redis_command_status(fr_redis_conn_t *conn, redisReply *reply)
Check the reply for errors.
fr_table_num_sorted_t const redis_reply_types[]
fr_redis_rcode_t
Codes are ordered inversely by priority.
@ REDIS_RCODE_SUCCESS
Operation was successful.
@ REDIS_RCODE_TRY_AGAIN
Try the operation again.
Configuration parameters for a redis connection.
Connection handle, holding a redis context.
static int mod_load(void)
fr_dict_autoload_t rlm_rediswho_dict[]
fr_dict_attr_autoload_t rlm_rediswho_dict_attr[]
int trim_count
How many session updates to keep track of per user.
int expiry_time
Expiry time in seconds if no updates are received for a user.
fr_redis_conf_t conf
Connection parameters for the Redis server.
char const * insert
Command for inserting session data.
static fr_dict_t const * dict_radius
fr_redis_cluster_t * cluster
Pool O pools.
module_rlm_t rlm_rediswho
static unlang_action_t mod_accounting(rlm_rcode_t *p_result, module_ctx_t const *mctx, request_t *request)
static conf_parser_t section_config[]
static fr_dict_attr_t const * attr_acct_status_type
static int rediswho_command(rlm_rediswho_t const *inst, request_t *request, char const *fmt)
char const * expire
Command for expiring entries.
static int mod_instantiate(module_inst_ctx_t const *mctx)
char const * trim
Command for trimming the session list.
static conf_parser_t module_config[]
static unlang_action_t mod_accounting_all(rlm_rcode_t *p_result, rlm_rediswho_t const *inst, request_t *request, char const *insert, char const *trim, char const *expire)
static int instantiate(module_inst_ctx_t const *mctx)
#define SECTION_NAME(_name1, _name2)
Define a section name consisting of a verb and a noun.
CONF_SECTION * conf
Module's instance configuration.
void * data
Module's instance data.
#define MODULE_BINDING_TERMINATOR
Terminate a module binding list.
Named methods exported by a module.
eap_aka_sim_process_conf_t * inst
Stores an attribute, a value and various bits of other data.
fr_dict_attr_t const *_CONST da
Dictionary attribute defines the attribute number, vendor and type of the pair.
#define fr_table_str_by_value(_table, _number, _def)
Convert an integer to a string.
#define talloc_get_type_abort_const