24 RCSID(
"$Id: 4c28094fcf90c1f6056fcc1b0213c9a74a3be38d $")
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>
131 memcpy(final_stats,
stats->stats,
sizeof(
stats->stats));
144 if (other == t)
continue;
147 pthread_mutex_lock(&other->mutex);
151 pthread_mutex_unlock(&other->mutex);
154 memcpy(&local_stats,
stats->stats,
sizeof(
stats->stats));
157 final_stats[i] += local_stats[i];
160 pthread_mutex_unlock(&other->mutex);
191 int src_code, dst_code;
194 src_code = request->packet->code;
197 dst_code = request->reply->code;
200 pthread_mutex_lock(&t->
mutex);
201 t->
stats[src_code]++;
202 t->
stats[dst_code]++;
207 mydata.
ipaddr = request->packet->socket.inet.src_ipaddr;
212 stats->ipaddr = request->packet->socket.inet.src_ipaddr;
213 stats->created = request->async->recv_time;
218 stats->last_packet = request->async->recv_time;
219 stats->stats[src_code]++;
220 stats->stats[dst_code]++;
225 mydata.
ipaddr = request->packet->socket.inet.dst_ipaddr;
230 stats->ipaddr = request->packet->socket.inet.dst_ipaddr;
231 stats->created = request->async->recv_time;
236 stats->last_packet = request->async->recv_time;
237 stats->stats[src_code]++;
238 stats->stats[dst_code]++;
239 pthread_mutex_unlock(&t->
mutex);
251 pthread_mutex_lock(&
inst->mutable->mutex);
256 pthread_mutex_unlock(&
inst->mutable->mutex);
271 stats_type = FR_STATS4_TYPE_VALUE_GLOBAL;
273 stats_type =
vp->vp_uint32;
280 vp->vp_uint32 = stats_type;
282 switch (stats_type) {
283 case FR_STATS4_TYPE_VALUE_GLOBAL:
290 pthread_mutex_lock(&
inst->mutable->mutex);
295 memcpy(&local_stats,
inst->mutable->stats,
sizeof(
inst->mutable->stats));
296 pthread_mutex_unlock(&
inst->mutable->mutex);
300 case FR_STATS4_TYPE_VALUE_CLIENT:
309 case FR_STATS4_TYPE_VALUE_LISTENER:
319 REDEBUG(
"Invalid value '%d' for FreeRADIUS-Stats4-type", stats_type);
339 if (!local_stats[i])
continue;
346 vp->vp_uint64 = local_stats[i];
355 static int8_t
data_cmp(
const void *one,
const void *two)
384 pthread_mutex_lock(&
inst->mutable->mutex);
386 pthread_mutex_unlock(&
inst->mutable->mutex);
401 pthread_mutex_lock(&
inst->mutable->mutex);
406 pthread_mutex_unlock(&
inst->mutable->mutex);
407 pthread_mutex_destroy(&t->
mutex);
417 pthread_mutex_init(&
inst->mutable->mutex, NULL);
431 pthread_mutex_destroy(&
inst->mutable->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.
#define MODULE_MAGIC_INIT
Stop people using different module/library/server versions together.
#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.
module_instance_t const * mi
Instance of the module being instantiated.
void * thread
Thread specific instance data.
module_instance_t * mi
Module instance to detach.
void * thread
Thread instance data.
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 detach calls.
Temporary structure to hold arguments for instantiation calls.
Temporary structure to hold arguments for thread_instantiation calls.
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]
#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.
bool fr_rb_insert(fr_rb_tree_t *tree, void const *data)
void * fr_rb_find(fr_rb_tree_t const *tree, void const *data)
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_dlist_head_t list
for threads to know about each other
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)
rlm_stats_mutable_t * mutable
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 SECTION_NAME(_name1, _name2)
Define a section name consisting of a verb and a noun.
void * data
Module's instance data.
#define MODULE_BINDING_TERMINATOR
Terminate a module binding list.
Named methods exported by a module.
#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.