The FreeRADIUS server
$Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
|
Common functions for interacting with Redis via hiredis. More...
#include <freeradius-devel/server/base.h>
#include <freeradius-devel/server/map.h>
#include <freeradius-devel/server/module.h>
#include <hiredis/hiredis.h>
Go to the source code of this file.
Data Structures | |
struct | fr_redis_conf_t |
Configuration parameters for a redis connection. More... | |
struct | fr_redis_conn_t |
Connection handle, holding a redis context. More... | |
Macros | |
#define | MAX_REDIS_ARGS 256 |
#define | MAX_REDIS_COMMAND_LEN 4096 |
#define | REDIS_COMMON_CONFIG |
#define | REDIS_DEFAULT_PORT 6379 |
#define | REDIS_ERROR_ASK_STR "ASK" |
#define | REDIS_ERROR_MOVED_STR "MOVED" |
#define | REDIS_ERROR_NO_SCRIPT_STR "NOSCRIPT" |
#define | REDIS_ERROR_TRY_AGAIN_STR "TRYAGAIN" |
Typedefs | |
typedef struct fr_redis_cluster_node_s | fr_redis_cluster_node_t |
Enumerations | |
enum | fr_redis_rcode_t { REDIS_RCODE_SUCCESS = 0 , REDIS_RCODE_ERROR = -1 , REDIS_RCODE_TRY_AGAIN = -2 , REDIS_RCODE_RECONNECT = -3 , REDIS_RCODE_ASK = -4 , REDIS_RCODE_MOVE = -5 , REDIS_RCODE_NO_SCRIPT = -6 } |
Codes are ordered inversely by priority. More... | |
Functions | |
fr_redis_rcode_t | fr_redis_command_status (fr_redis_conn_t *conn, redisReply *reply) |
Check the reply for errors. More... | |
fr_redis_rcode_t | fr_redis_get_version (char *out, size_t out_len, fr_redis_conn_t *conn) |
Get the version of Redis running on the remote server. More... | |
static void | fr_redis_pipeline_free (redisReply *reply[], size_t num) |
fr_redis_rcode_t | fr_redis_pipeline_result (unsigned int *pipelined, fr_redis_rcode_t *rcode, redisReply *out[], size_t out_len, fr_redis_conn_t *conn) |
Simplifies handling of pipelined commands with Redis cluster. More... | |
static void | fr_redis_reply_free (redisReply **reply) |
Wrap freeReplyObject so we consistently check for NULL pointers. More... | |
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. More... | |
int | fr_redis_reply_to_map (TALLOC_CTX *ctx, map_list_t *out, request_t *request, redisReply *key, redisReply *op, redisReply *value) |
Convert a pair of redis reply objects to a map. More... | |
int | fr_redis_reply_to_value_box (TALLOC_CTX *ctx, fr_value_box_t *out, redisReply *reply, fr_type_t dst_type, fr_dict_attr_t const *dst_enumv, bool box_error, bool shallow)) |
Convert a string or integer type to fr_value_box_t of specified type. More... | |
int | fr_redis_tuple_from_map (TALLOC_CTX *pool, char const *out[], size_t out_len[], map_t *map) |
Add a single map pair to an existing command string as three elements. More... | |
uint32_t | fr_redis_version_num (char const *version) |
Convert version string into a 32bit unsigned integer for comparisons. More... | |
void | fr_redis_version_print (void) |
Print the version of libhiredis the server was built against. More... | |
Variables | |
fr_table_num_sorted_t const | redis_rcodes [] |
size_t | redis_rcodes_len |
fr_table_num_sorted_t const | redis_reply_types [] |
size_t | redis_reply_types_len |
Common functions for interacting with Redis via hiredis.
Definition in file base.h.
struct fr_redis_conf_t |
Configuration parameters for a redis connection.
Data Fields | ||
---|---|---|
fr_time_delta_t | connection_timeout | |
uint32_t | database | number on Redis server. |
char const ** | hostname | of Redis server. |
char const * | log_prefix | |
uint32_t | max_alt | Maximum alternative nodes to try. |
uint8_t | max_nodes | Maximum number of cluster nodes to connect to. |
uint32_t | max_redirects | Maximum number of times we can be redirected. |
uint32_t | max_retries | Maximum number of times we attempt a command when receiving successive -TRYAGAIN messages. |
char const * | password | to authenticate to Redis. |
uint16_t | port | of Redis daemon. |
fr_time_delta_t | reconnection_delay | |
fr_time_delta_t | retry_delay | How long to wait when we received a -TRYAGAIN message. |
bool | use_cluster_map | use cluster map. |
bool | use_tls | use TLS. |
char const * | username | for acls. |
struct fr_redis_conn_t |
Data Fields | ||
---|---|---|
redisContext * | handle | Hiredis context used when issuing commands. |
fr_redis_cluster_node_t * | node | Node this connection is to. |
#define REDIS_COMMON_CONFIG |
typedef struct fr_redis_cluster_node_s fr_redis_cluster_node_t |
enum fr_redis_rcode_t |
Codes are ordered inversely by priority.
To simplify handling the return codes from pipelined commands, the lowest status code, and the reply which accompanies it should be returned to the redis cluster code.
fr_redis_rcode_t fr_redis_command_status | ( | fr_redis_conn_t * | conn, |
redisReply * | reply | ||
) |
Check the reply for errors.
[in] | conn | used to issue the command. |
[in] | reply | to process. |
Definition at line 71 of file redis.c.
fr_redis_rcode_t fr_redis_get_version | ( | char * | out, |
size_t | out_len, | ||
fr_redis_conn_t * | conn | ||
) |
Get the version of Redis running on the remote server.
This can be useful for some modules, as it allows adaptive behaviour, or early termination.
[out] | out | Where to write the version string. |
[in] | out_len | Length of the version string buffer. |
[in] | conn | Used to query the version string. |
Definition at line 638 of file redis.c.
|
inlinestatic |
fr_redis_rcode_t fr_redis_pipeline_result | ( | unsigned int * | pipelined, |
fr_redis_rcode_t * | rcode, | ||
redisReply * | out[], | ||
size_t | out_len, | ||
fr_redis_conn_t * | conn | ||
) |
Simplifies handling of pipelined commands with Redis cluster.
Retrieve all available pipelined responses, and write them to the array.
On encountering an error, all previously retrieved responses are freed, and the reply containing the error is written to the first element of out. All responses after the error are also freed.
If the number of responses != pipelined, that's also an error, a very serious one, in libhiredis or Redis. We can't really do much here apart from error out.
[out] | pipelined | Number of pipelined commands we sent to the server. |
[out] | rcode | Status of the first errored response, or REDIS_RCODE_SUCCESS if all responses were processed. |
[out] | out | Where to write the replies from pipelined commands. Will contain exactly 1 element on error WHICH MUST BE FREED, else the number passed in pipelined. |
[in] | out_len | number of elements in out. |
[in] | conn | the pipelined commands were issued on. |
Definition at line 535 of file redis.c.
|
inlinestatic |
Wrap freeReplyObject so we consistently check for NULL pointers.
Older versions such as 0.10 (which ship with Ubuntu <= 14.10) don't check for NULL pointer before attempting to free, so we get a NULL pointer dereference in some cases.
Rather than go back through the many calls to freeReplyObject and attempt to determine code paths that may result in it being called on a NULL pointer, we use this to always check.
Definition at line 64 of file base.h.
void fr_redis_reply_print | ( | fr_log_lvl_t | lvl, |
redisReply * | reply, | ||
request_t * | request, | ||
int | idx | ||
) |
int fr_redis_reply_to_map | ( | TALLOC_CTX * | ctx, |
map_list_t * | out, | ||
request_t * | request, | ||
redisReply * | key, | ||
redisReply * | op, | ||
redisReply * | value | ||
) |
Convert a pair of redis reply objects to a map.
The maps can then be applied using map_to_request.
[in,out] | ctx | to allocate maps in. |
[out] | out | Where to write the head of the new maps list. |
[in] | request | The current request. |
[in] | key | to process. |
[in] | op | to process. |
[in] | value | to process. |
Definition at line 365 of file redis.c.
int fr_redis_reply_to_value_box | ( | TALLOC_CTX * | ctx, |
fr_value_box_t * | out, | ||
redisReply * | reply, | ||
fr_type_t | dst_type, | ||
fr_dict_attr_t const * | dst_enumv, | ||
bool | box_error, | ||
bool | shallow | ||
) |
Convert a string or integer type to fr_value_box_t of specified type.
Will work with REDIS_REPLY_STRING (which is converted to FR_TYPE_STRING then cast to dst_type), or REDIS_REPLY_INTEGER (which is converted to FR_TYPE_UINT64, then cast to dst_type).
[in,out] | ctx | to allocate any buffers in. |
[out] | out | Where to write the cast type. |
[in] | reply | to process. |
[in] | dst_type | to convert to. May be FR_TYPE_VOID to infer type. |
[in] | dst_enumv | Used to convert string types to integers for attribute with enumerated values. |
[in] | box_error | If true then REDIS_REPLY_ERROR will be copied to a box, otherwise we'll return and error with the contents of the error available on the thread local error stack. |
[in] | shallow | If true, we shallow copy strings. |
Definition at line 206 of file redis.c.
int fr_redis_tuple_from_map | ( | TALLOC_CTX * | pool, |
char const * | out[], | ||
size_t | out_len[], | ||
map_t * | map | ||
) |
Add a single map pair to an existing command string as three elements.
pool | to allocate any buffers in. |
out | Where to write pointers to the member of the tuple. Unused elements should be a multiple of three, and it should have at least three unused elements. |
out_len | Where to write the size of the data pointed to by the equivalent index in the out array. |
map | to convert. |
Definition at line 459 of file redis.c.
uint32_t fr_redis_version_num | ( | char const * | version | ) |
void fr_redis_version_print | ( | void | ) |
|
extern |
|
extern |