The FreeRADIUS server $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Loading...
Searching...
No Matches
Data Structures | Functions | Variables
trigger.c File Reference
#include <freeradius-devel/protocol/freeradius/freeradius.internal.h>
#include <freeradius-devel/server/cf_file.h>
#include <freeradius-devel/server/cf_parse.h>
#include <freeradius-devel/server/exec.h>
#include <freeradius-devel/server/main_loop.h>
#include <freeradius-devel/server/pair.h>
#include <freeradius-devel/server/request_data.h>
#include <freeradius-devel/server/trigger.h>
#include <freeradius-devel/unlang/function.h>
#include <freeradius-devel/unlang/subrequest.h>
#include <freeradius-devel/unlang/xlat.h>
#include <freeradius-devel/unlang/tmpl.h>
#include <sys/wait.h>
+ Include dependency graph for trigger.c:

Go to the source code of this file.

Data Structures

struct  fr_trigger_t
 
struct  trigger_last_fired_t
 Describes a rate limiting entry for a trigger. More...
 

Functions

static int _mutex_free (pthread_mutex_t *mutex)
 
static int _trigger_free (UNUSED void *uctx)
 Free trigger resources.
 
static int _trigger_init (void *cs_arg)
 Set the global trigger section trigger will search in, and register xlats.
 
static int8_t _trigger_last_fired_cmp (void const *one, void const *two)
 Compares two last fired structures.
 
static void _trigger_last_fired_free (void *data)
 
int trigger (unlang_interpret_t *intp, CONF_SECTION const *cs, char const *name, bool rate_limit, fr_pair_list_t *args)
 Execute a trigger - call an executable to process an event.
 
void trigger_args_afrom_server (TALLOC_CTX *ctx, fr_pair_list_t *list, char const *server, uint16_t port)
 Create trigger arguments to describe the server the pool connects to.
 
bool trigger_enabled (void)
 Return whether triggers are enabled.
 
int trigger_init (CONF_SECTION const *cs)
 

Variables

static fr_dict_attr_t const * attr_trigger_name
 
static fr_dict_t const * dict_freeradius
 
static CONF_SECTION const * trigger_cs
 Whether triggers are enabled globally.
 
fr_dict_autoload_t trigger_dict []
 
fr_dict_attr_autoload_t trigger_dict_attr []
 
static fr_rb_tree_ttrigger_last_fired_tree
 
static pthread_mutex_ttrigger_mutex
 

Data Structure Documentation

◆ fr_trigger_t

struct fr_trigger_t

Definition at line 99 of file trigger.c.

+ Collaboration diagram for fr_trigger_t:
Data Fields
int exec_status Result of the program (if the trigger is a tmpl)
fr_value_box_list_t out result of the xlap (which we ignore)
unlang_result_t result the result of expansion
tmpl_t * vpt the template to execute

◆ trigger_last_fired_t

struct trigger_last_fired_t

Describes a rate limiting entry for a trigger.

Definition at line 53 of file trigger.c.

+ Collaboration diagram for trigger_last_fired_t:
Data Fields
CONF_ITEM * ci Config item this rate limit counter is associated with.
fr_time_t last_fired When this trigger last fired.
fr_rb_node_t node Entry in the trigger last fired tree.

Function Documentation

◆ _mutex_free()

static int _mutex_free ( pthread_mutex_t mutex)
static

Definition at line 425 of file trigger.c.

+ Here is the caller graph for this function:

◆ _trigger_free()

static int _trigger_free ( UNUSED void *  uctx)
static

Free trigger resources.

Definition at line 434 of file trigger.c.

+ Here is the caller graph for this function:

◆ _trigger_init()

static int _trigger_init ( void *  cs_arg)
static

Set the global trigger section trigger will search in, and register xlats.

This function exists because triggers are used by the connection pool, which is used in the server library which may not have the mainconfig available. Additionally, utilities may want to set their own root config sections.

We don't register the trigger xlat here, as we may inadvertently initialise the xlat code, which is annoying when this is called from a utility.

Parameters
[in]cs_argto use as global trigger section.
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 457 of file trigger.c.

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

◆ _trigger_last_fired_cmp()

static int8_t _trigger_last_fired_cmp ( void const *  one,
void const *  two 
)
static

Compares two last fired structures.

Parameters
onefirst pointer to compare.
twosecond pointer to compare.
Returns
CMP(one, two)

Definition at line 84 of file trigger.c.

+ Here is the caller graph for this function:

◆ _trigger_last_fired_free()

static void _trigger_last_fired_free ( void *  data)
static

Definition at line 73 of file trigger.c.

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

◆ trigger()

int trigger ( unlang_interpret_t intp,
CONF_SECTION const *  cs,
char const *  name,
bool  rate_limit,
fr_pair_list_t args 
)

Execute a trigger - call an executable to process an event.

A trigger ties a state change (e.g. connection up) in a module to an action (e.g. send an SNMP trap) defined in raqddb/triggers.conf or in the trigger section of a module, and can be created with one call to trigger().

The trigger function expands the configuration item, and runs the given function (exec, sql insert, etc.) asynchronously, allowing the server to keep processing packets while the action is being taken.

The name of each trigger is based on the module or portion of the server which runs the trigger, and is usually taken from the state when the module has a state change.

Triggers are separate from logs, because log messages are generally informational, are not time sensitive, and usually require log files to be parsed and filtered in order to find relevant information.

In contrast, triggers are something specific which the administrator needs to be notified about immediately and can't wait to post-process a log file.

Note
Calls to this function will be ignored if trigger_init has not been called.
Parameters
[in]intpInterpreter to run the trigger with. If this is NULL the trigger will be executed synchronously.
[in]csto search for triggers in. If cs is not NULL, the portion after the last '.' in name is used for the trigger. If cs is NULL, the entire name is used to find the trigger in the global trigger section.
[in]namethe path relative to the global trigger section ending in the trigger name e.g. module.ldap.pool.start.
[in]rate_limitwhether to rate limit triggers.
[in]argsto make available via the
%trigger(<arg>) 
xlat.
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 143 of file trigger.c.

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

◆ trigger_args_afrom_server()

void trigger_args_afrom_server ( TALLOC_CTX *  ctx,
fr_pair_list_t list,
char const *  server,
uint16_t  port 
)

Create trigger arguments to describe the server the pool connects to.

Note
trigger_init must be called before calling this function, else it will return NULL.
Parameters
[in]ctxto allocate fr_pair_t s in.
[out]listto append Pool-Server and Pool-Port pairs to
[in]serverwe're connecting to.
[in]porton that server.

Definition at line 398 of file trigger.c.

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

◆ trigger_enabled()

bool trigger_enabled ( void  )

Return whether triggers are enabled.

Definition at line 94 of file trigger.c.

+ Here is the caller graph for this function:

◆ trigger_init()

int trigger_init ( CONF_SECTION const *  cs)

Definition at line 493 of file trigger.c.

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

Variable Documentation

◆ attr_trigger_name

fr_dict_attr_t const* attr_trigger_name
static

Definition at line 66 of file trigger.c.

◆ dict_freeradius

fr_dict_t const* dict_freeradius
static

Definition at line 59 of file trigger.c.

◆ trigger_cs

CONF_SECTION const* trigger_cs
static

Whether triggers are enabled globally.

Definition at line 46 of file trigger.c.

◆ trigger_dict

fr_dict_autoload_t trigger_dict
Initial value:
= {
{ .out = &dict_freeradius, .proto = "freeradius" },
{ NULL }
}
static fr_dict_t const * dict_freeradius
Definition trigger.c:59

Definition at line 61 of file trigger.c.

◆ trigger_dict_attr

fr_dict_attr_autoload_t trigger_dict_attr
Initial value:
= {
{ .out = &attr_trigger_name, .name = "Trigger-Name", .type = FR_TYPE_STRING, .dict = &dict_freeradius },
{ NULL }
}
@ FR_TYPE_STRING
String of printable characters.
static fr_dict_attr_t const * attr_trigger_name
Definition trigger.c:66

Definition at line 68 of file trigger.c.

◆ trigger_last_fired_tree

fr_rb_tree_t* trigger_last_fired_tree
static

Definition at line 47 of file trigger.c.

◆ trigger_mutex

pthread_mutex_t* trigger_mutex
static

Definition at line 48 of file trigger.c.