24 RCSID(
"$Id: 5d9f42778cf8c7611622a9f3055fd4ed392a568d $")
26 #include <freeradius-devel/server/base.h>
27 #include <freeradius-devel/server/module_rlm.h>
28 #include <freeradius-devel/io/listen.h>
29 #include <freeradius-devel/util/dlist.h>
30 #include <freeradius-devel/util/debug.h>
31 #include <freeradius-devel/radius/radius.h>
33 #include <freeradius-devel/protocol/radius/freeradius.h>
126 memcpy(final_stats,
stats->stats,
sizeof(
stats->stats));
139 if (other == t)
continue;
142 pthread_mutex_lock(&other->mutex);
146 pthread_mutex_unlock(&other->mutex);
149 memcpy(&local_stats,
stats->stats,
sizeof(
stats->stats));
152 final_stats[i] += local_stats[i];
155 pthread_mutex_unlock(&other->mutex);
186 int src_code, dst_code;
189 src_code = request->packet->code;
192 dst_code = request->reply->code;
195 pthread_mutex_lock(&t->
mutex);
196 t->
stats[src_code]++;
197 t->
stats[dst_code]++;
202 mydata.
ipaddr = request->packet->socket.inet.src_ipaddr;
207 stats->ipaddr = request->packet->socket.inet.src_ipaddr;
208 stats->created = request->async->recv_time;
213 stats->last_packet = request->async->recv_time;
214 stats->stats[src_code]++;
215 stats->stats[dst_code]++;
220 mydata.
ipaddr = request->packet->socket.inet.dst_ipaddr;
225 stats->ipaddr = request->packet->socket.inet.dst_ipaddr;
226 stats->created = request->async->recv_time;
231 stats->last_packet = request->async->recv_time;
232 stats->stats[src_code]++;
233 stats->stats[dst_code]++;
234 pthread_mutex_unlock(&t->
mutex);
246 pthread_mutex_lock(&
inst->mutex);
251 pthread_mutex_unlock(&
inst->mutex);
266 stats_type = FR_STATS4_TYPE_VALUE_GLOBAL;
268 stats_type =
vp->vp_uint32;
275 vp->vp_uint32 = stats_type;
277 switch (stats_type) {
278 case FR_STATS4_TYPE_VALUE_GLOBAL:
285 pthread_mutex_lock(&
inst->mutex);
290 memcpy(&local_stats,
inst->stats,
sizeof(
inst->stats));
291 pthread_mutex_unlock(&
inst->mutex);
295 case FR_STATS4_TYPE_VALUE_CLIENT:
304 case FR_STATS4_TYPE_VALUE_LISTENER:
314 REDEBUG(
"Invalid value '%d' for FreeRADIUS-Stats4-type", stats_type);
334 if (!local_stats[i])
continue;
341 vp->vp_uint64 = local_stats[i];
350 static int8_t
data_cmp(
const void *one,
const void *two)
378 pthread_mutex_init(&t->
mutex, 0);
380 pthread_mutex_lock(&
inst->mutex);
382 pthread_mutex_unlock(&
inst->mutex);
397 pthread_mutex_lock(&
inst->mutex);
402 pthread_mutex_unlock(&
inst->mutex);
403 pthread_mutex_destroy(&t->
mutex);
412 pthread_mutex_init(&
inst->mutex, NULL);
426 pthread_mutex_destroy(&
inst->mutex);
unlang_action_t
Returned by unlang_op_t calls, determine the next action of the interpreter.
static int const char char buffer[256]
strcpy(log_entry->msg, buffer)
#define CONF_PARSER_TERMINATOR
Defines a CONF_PAIR to C data type mapping.
@ FR_RADIUS_CODE_MAX
Maximum possible protocol code.
@ FR_RADIUS_CODE_STATUS_SERVER
RFC2865/RFC5997 - Status Server (request)
fr_dict_attr_t const * fr_dict_attr_by_name(fr_dict_attr_err_t *err, fr_dict_attr_t const *parent, char const *attr))
Locate a fr_dict_attr_t by its name.
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.
fr_dict_attr_t const * fr_dict_root(fr_dict_t const *dict)
Return the root attribute of a dictionary.
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.
void *_CONST data
Module instance's parsed configuration.
#define MODULE_MAGIC_INIT
Stop people using different module/library/server versions together.
dl_module_inst_t const * inst
#define fr_dlist_init(_head, _type, _field)
Initialise the head structure of a doubly linked list.
static void * fr_dlist_next(fr_dlist_head_t const *list_head, void const *ptr)
Get the next item in a list.
static void * fr_dlist_head(fr_dlist_head_t const *list_head)
Return the HEAD item of a list or NULL if the list is empty.
static void * fr_dlist_remove(fr_dlist_head_t *list_head, void *ptr)
Remove an item from the list.
static int fr_dlist_insert_head(fr_dlist_head_t *list_head, void *ptr)
Insert an item into the head of a list.
Head of a doubly linked list.
Entry in a doubly linked list.
int8_t fr_ipaddr_cmp(fr_ipaddr_t const *a, fr_ipaddr_t const *b)
Compare two ip addresses.
@ FR_TYPE_IPV4_ADDR
32 Bit IPv4 Address.
@ FR_TYPE_UINT32
32 Bit unsigned integer.
@ FR_TYPE_IPV6_ADDR
128 Bit IPv6 Address.
void * thread
Thread specific instance data.
dl_module_inst_t const * inst
Dynamic loader API handle for the module.
void * thread
Thread instance data.
dl_module_inst_t const * inst
Dynamic loader API handle for the module.
dl_module_inst_t const * inst
Dynamic loader API handle for the module.
Temporary structure to hold arguments for module calls.
Temporary structure to hold arguments for instantiation calls.
Temporary structure to hold arguments for thread_instantiation calls.
Specifies a module method identifier.
module_t common
Common fields presented by all modules.
fr_pair_t * fr_pair_afrom_da(TALLOC_CTX *ctx, fr_dict_attr_t const *da)
Dynamically allocate a new attribute and assign a fr_dict_attr_t.
int fr_pair_append(fr_pair_list_t *list, fr_pair_t *to_add)
Add a VP to the end of the list.
fr_pair_t * fr_pair_copy(TALLOC_CTX *ctx, fr_pair_t const *vp)
Copy a single valuepair.
fr_pair_t * fr_pair_find_by_da_nested(fr_pair_list_t const *list, fr_pair_t const *prev, fr_dict_attr_t const *da)
Find a pair with a matching fr_dict_attr_t, by walking the nested fr_dict_attr_t tree.
char const * fr_radius_packet_name[FR_RADIUS_CODE_MAX]
bool fr_rb_insert(fr_rb_tree_t *tree, void const *data)
Insert data into a tree.
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.
#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.
#define RETURN_MODULE_NOOP
#define RETURN_MODULE_UPDATED
rlm_rcode_t
Return codes indicating the result of the module call.
fr_rb_tree_t * dst
stats by destination
static int mod_detach(module_detach_ctx_t const *mctx)
fr_dict_attr_autoload_t rlm_stats_dict_attr[]
fr_dict_attr_t const * ipv4_da
FreeRADIUS-Stats4-IPv4-Address.
fr_time_t created
when it was created
static int8_t data_cmp(const void *one, const void *two)
fr_dict_attr_t const * type_da
FreeRADIUS-Stats4-Type.
fr_dict_autoload_t rlm_stats_dict[]
fr_time_t last_packet
when we last saw a packet
uint64_t stats[FR_RADIUS_CODE_MAX]
static void coalesce(uint64_t final_stats[FR_RADIUS_CODE_MAX], rlm_stats_thread_t *t, size_t tree_offset, rlm_stats_data_t *mydata)
static fr_dict_attr_t const * attr_freeradius_stats4_ipv4_address
static fr_dict_t const * dict_radius
fr_ipaddr_t ipaddr
IP address of this thing.
static fr_dict_attr_t const * attr_freeradius_stats4_ipv6_address
static int mod_thread_instantiate(module_thread_inst_ctx_t const *mctx)
Instantiate thread data for the submodule.
fr_dict_attr_t const * ipv6_da
FreeRADIUS-Stats4-IPv6-Address.
fr_dlist_t entry
for threads to know about each other
fr_rb_tree_t * src
stats by source
fr_time_t last_global_update
static fr_dict_attr_t const * attr_freeradius_stats4_type
static const conf_parser_t module_config[]
static int mod_thread_detach(module_thread_inst_ctx_t const *mctx)
Destroy thread data for the submodule.
static int mod_instantiate(module_inst_ctx_t const *mctx)
fr_dlist_head_t list
for threads to know about each other
static unlang_action_t mod_stats(rlm_rcode_t *p_result, module_ctx_t const *mctx, request_t *request)
fr_time_t last_manage
when we deleted old things
#define MODULE_NAME_TERMINATOR
#define pair_update_reply(_attr, _da)
Return or allocate a fr_pair_t in the reply list.
MEM(pair_append_request(&vp, attr_eap_aka_sim_identity) >=0)
eap_aka_sim_process_conf_t * inst
size_t strlcpy(char *dst, char const *src, size_t siz)
Stores an attribute, a value and various bits of other data.