The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Data Structures | Functions | Variables
log.c File Reference

Logging functions used by the server core. More...

#include <freeradius-devel/server/base.h>
#include <freeradius-devel/util/debug.h>
#include <fcntl.h>
#include <sys/file.h>
#include <pthread.h>
+ Include dependency graph for log.c:

Go to the source code of this file.

Data Structures

struct  fr_log_src_t
 
struct  fr_log_track_t
 

Functions

static int _fr_log_request_oid_buff_free (void *arg)
 Cleanup the memory pool used by the OID sbuff. More...
 
static int _fr_vlog_request_pool_free (void *arg)
 Cleanup the memory pool used by vlog_request. More...
 
static int _log_free (fr_log_t *log)
 
static int8_t _log_track_filename_cmp (void const *two, void const *one)
 
static int8_t _log_track_name_cmp (void const *two, void const *one)
 
static void log_always (fr_log_t const *log, fr_log_type_t type, char const *file, int line, char const *fmt,...)
 Send a server log message to its destination without evaluating its debug level. More...
 
fr_log_tlog_dst_by_name (char const *name)
 Get a logging destination by name. More...
 
void log_fatal (fr_log_t const *log, char const *file, int line, char const *fmt,...)
 Log a fatal error, then exit. More...
 
void log_global_free (void)
 
int log_global_init (fr_log_t *log, bool daemonize)
 Initialises the server logging functionality, and the underlying libfreeradius log. More...
 
int log_parse_section (CONF_SECTION *cs)
 Parse a named logging section. More...
 
bool log_rdebug_enabled (fr_log_lvl_t lvl, request_t const *request)
 Whether a request specific debug message should be logged. More...
 
static void log_register_dst (char const *name, fr_log_t *log, CONF_SECTION *cs)
 Register a logging destination. More...
 
void log_request (fr_log_type_t type, fr_log_lvl_t lvl, request_t *request, char const *file, int line, char const *fmt,...)
 Marshal variadic log arguments into a va_list and pass to normal logging functions. More...
 
void log_request_error (fr_log_type_t type, fr_log_lvl_t lvl, request_t *request, char const *file, int line, char const *fmt,...)
 Marshal variadic log arguments into a va_list and pass to error logging functions. More...
 
void log_request_fd_event (UNUSED fr_event_list_t *el, int fd, UNUSED int flags, void *uctx)
 Function to provide as the readable callback to the event loop. More...
 
void log_request_hex (fr_log_type_t type, fr_log_lvl_t lvl, request_t *request, char const *file, int line, uint8_t const *data, size_t data_len)
 
void log_request_marker (fr_log_type_t type, fr_log_lvl_t lvl, request_t *request, char const *file, int line, char const *str, size_t str_len, ssize_t marker_idx, char const *marker_fmt,...)
 Write the string being parsed, and a marker showing where the parse error occurred. More...
 
static fr_sbuff_tlog_request_oid_buff (void)
 Allocate an extensible sbuff for printing OID strings. More...
 
void log_request_pair (fr_log_lvl_t lvl, request_t *request, fr_pair_t const *parent, fr_pair_t const *vp, char const *prefix)
 Print a fr_pair_t. More...
 
void log_request_pair_list (fr_log_lvl_t lvl, request_t *request, fr_pair_t const *parent, fr_pair_list_t const *vps, char const *prefix)
 Print a fr_pair_list_t. More...
 
void log_request_perror (fr_log_type_t type, fr_log_lvl_t lvl, request_t *request, char const *file, int line, char const *fmt,...)
 Drain any outstanding messages from the fr_strerror buffers. More...
 
void log_request_proto_pair_list (fr_log_lvl_t lvl, request_t *request, fr_pair_t const *parent, fr_pair_list_t const *vps, char const *prefix)
 Print a list of protocol fr_pair_ts. More...
 
static void vlog_module_failure_msg (request_t *request, char const *fmt, va_list ap)
 Add a module failure message fr_pair_t to the request. More...
 
void vlog_request (fr_log_type_t type, fr_log_lvl_t lvl, request_t *request, char const *file, int line, char const *fmt, va_list ap, void *uctx)
 Send a log message to its destination, possibly including fields from the request. More...
 

Variables

static fr_dict_attr_t const * attr_module_failure_message
 
static fr_dict_t const * dict_freeradius
 
static fr_rb_tree_tdst_tree = NULL
 
static fr_rb_tree_tfilename_tree = NULL
 
static _Thread_local fr_sbuff_tfr_log_request_oid_buff
 
static _Thread_local TALLOC_CTX * fr_vlog_request_pool
 
static const conf_parser_t log_config []
 
static char const * log_destination = NULL
 
fr_table_num_sorted_t const log_destination_table []
 
size_t log_destination_table_len = NUM_ELEMENTS(log_destination_table)
 
fr_dict_autoload_t log_dict []
 
fr_dict_attr_autoload_t log_dict_attr []
 
static bool log_timestamp
 
static bool log_timestamp_is_set
 
static char const spaces [] = " "
 
static fr_rb_tree_tsrc_tree = NULL
 
fr_table_num_sorted_t const syslog_facility_table []
 Syslog facility table. More...
 
size_t syslog_facility_table_len = NUM_ELEMENTS(syslog_facility_table)
 
fr_table_num_sorted_t const syslog_severity_table []
 Syslog severity table. More...
 
size_t syslog_severity_table_len = NUM_ELEMENTS(syslog_severity_table)
 

Detailed Description

Logging functions used by the server core.

Id
66def098fb2e293d9a6e82c24fe52646e75c67ff

Definition in file log.c.


Data Structure Documentation

◆ fr_log_src_t

struct fr_log_src_t

Definition at line 214 of file log.c.

+ Collaboration diagram for fr_log_src_t:
Data Fields
uint32_t id LOG_ID of this source.
fr_rb_node_t id_node tree by ID
fr_log_t ** log where the logs should go
char const * name name of this logging source
fr_rb_node_t name_node tree by name only
fr_log_t * original the original fr_log_t

◆ fr_log_track_t

struct fr_log_track_t

Definition at line 205 of file log.c.

+ Collaboration diagram for fr_log_track_t:
Data Fields
CONF_SECTION * cs where this log configuration came from
fr_rb_node_t filename_node tree by name
fr_log_t * log pointer to the log structure
char const * name name of this logging destination
fr_rb_node_t name_node tree by name

Function Documentation

◆ _fr_log_request_oid_buff_free()

static int _fr_log_request_oid_buff_free ( void *  arg)
static

Cleanup the memory pool used by the OID sbuff.

Definition at line 727 of file log.c.

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

◆ _fr_vlog_request_pool_free()

static int _fr_vlog_request_pool_free ( void *  arg)
static

Cleanup the memory pool used by vlog_request.

Definition at line 270 of file log.c.

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

◆ _log_free()

static int _log_free ( fr_log_t log)
static

Definition at line 1074 of file log.c.

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

◆ _log_track_filename_cmp()

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

Definition at line 1232 of file log.c.

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

◆ _log_track_name_cmp()

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

Definition at line 1224 of file log.c.

+ Here is the caller graph for this function:

◆ log_always()

static void log_always ( fr_log_t const *  log,
fr_log_type_t  type,
char const *  file,
int  line,
char const *  fmt,
  ... 
)
static

Send a server log message to its destination without evaluating its debug level.

Parameters
[in]logdestination.
[in]typeof log message.
[in]filesrc file the log message was generated in.
[in]linenumber the log message was generated on.
[in]fmtwith printf style substitution tokens.
[in]...Substitution arguments.

Definition at line 239 of file log.c.

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

◆ log_dst_by_name()

fr_log_t* log_dst_by_name ( char const *  name)

Get a logging destination by name.

Definition at line 1063 of file log.c.

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

◆ log_fatal()

void log_fatal ( fr_log_t const *  log,
char const *  file,
int  line,
char const *  fmt,
  ... 
)

Log a fatal error, then exit.

Definition at line 1030 of file log.c.

+ Here is the call graph for this function:

◆ log_global_free()

void log_global_free ( void  )

Definition at line 1292 of file log.c.

+ Here is the caller graph for this function:

◆ log_global_init()

int log_global_init ( fr_log_t log,
bool  daemonize 
)

Initialises the server logging functionality, and the underlying libfreeradius log.

Note
Call log free when the server is done to fix any spurious memory leaks.
Parameters
[in]logLogging parameters.
[in]daemonizeChanges what we do with stdout/stderr.
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 1256 of file log.c.

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

◆ log_parse_section()

int log_parse_section ( CONF_SECTION cs)

Parse a named logging section.

Todo:
  • we should probably allow for TCP sockets, too. But then those can block. So we then also need a way to buffer outbound log messages, and discard log messages if the buffer is full.

This should probably be done with a FILE*, and L_DST_FUNC.

Definition at line 1121 of file log.c.

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

◆ log_rdebug_enabled()

bool log_rdebug_enabled ( fr_log_lvl_t  lvl,
request_t const *  request 
)
inline

Whether a request specific debug message should be logged.

Parameters
lvlof debugging this message should be logged at.
requestThe current request.
Returns
  • true if message should be logged.
  • false if message shouldn't be logged.

Definition at line 258 of file log.c.

+ Here is the caller graph for this function:

◆ log_register_dst()

static void log_register_dst ( char const *  name,
fr_log_t log,
CONF_SECTION cs 
)
static

Register a logging destination.

Definition at line 1044 of file log.c.

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

◆ log_request()

void log_request ( fr_log_type_t  type,
fr_log_lvl_t  lvl,
request_t request,
char const *  file,
int  line,
char const *  fmt,
  ... 
)

Marshal variadic log arguments into a va_list and pass to normal logging functions.

See also
log_request_error for more details.
Parameters
[in]typethe log category.
[in]lvlof debugging this message should be logged at.
[in]requestThe current request.
[in]filesrc file the log message was generated in.
[in]linenumber the log message was generated on.
[in]fmtwith printf style substitution tokens.
[in]...Substitution arguments.

Definition at line 603 of file log.c.

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

◆ log_request_error()

void log_request_error ( fr_log_type_t  type,
fr_log_lvl_t  lvl,
request_t request,
char const *  file,
int  line,
char const *  fmt,
  ... 
)

Marshal variadic log arguments into a va_list and pass to error logging functions.

This could all be done in a macro, but it turns out some implementations of the variadic macros do not work at all well if the va_list being written to is further up the stack (which is required as you still need a function to convert the ellipsis into a va_list).

So, we use this small wrapper function instead, which will hopefully guarantee consistent behaviour.

Parameters
[in]typethe log category.
[in]lvlof debugging this message should be logged at.
[in]requestThe current request.
[in]filesrc file the log message was generated in.
[in]linenumber the log message was generated on.
[in]fmtwith printf style substitution tokens.
[in]...Substitution arguments.

Definition at line 638 of file log.c.

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

◆ log_request_fd_event()

void log_request_fd_event ( UNUSED fr_event_list_t el,
int  fd,
UNUSED int  flags,
void *  uctx 
)

Function to provide as the readable callback to the event loop.

Writes any data read from a file descriptor to the request log, tries very hard not to chop lines in the middle, but will split at 1024 byte boundaries if forced to.

Parameters
[in]elUNUSED
[in]fdUNUSED
[in]flagsUNUSED
[in]uctxPointer to a log_fd_event_ctx_t

Definition at line 947 of file log.c.

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

◆ log_request_hex()

void log_request_hex ( fr_log_type_t  type,
fr_log_lvl_t  lvl,
request_t request,
char const *  file,
int  line,
uint8_t const *  data,
size_t  data_len 
)

Definition at line 919 of file log.c.

+ Here is the call graph for this function:

◆ log_request_marker()

void log_request_marker ( fr_log_type_t  type,
fr_log_lvl_t  lvl,
request_t request,
char const *  file,
int  line,
char const *  str,
size_t  str_len,
ssize_t  marker_idx,
char const *  marker_fmt,
  ... 
)

Write the string being parsed, and a marker showing where the parse error occurred.

Parameters
[in]typethe log category.
[in]lvlof debugging this message should be logged at.
[in]requestThe current request.
[in]filesrc file the log message was generated in.
[in]linenumber the log message was generated on.
[in]strSubject string we're printing a marker for.
[in]str_lenSubject string length. Use SIZE_MAX for the length of the string.
[in]marker_idxThe position of the marker relative to the string.
[in]marker_fmtWhat the parse error was.
[in]...Arguments for fmt string.

Definition at line 877 of file log.c.

+ Here is the call graph for this function:

◆ log_request_oid_buff()

static fr_sbuff_t* log_request_oid_buff ( void  )
inlinestatic

Allocate an extensible sbuff for printing OID strings.

Definition at line 735 of file log.c.

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

◆ log_request_pair()

void log_request_pair ( fr_log_lvl_t  lvl,
request_t request,
fr_pair_t const *  parent,
fr_pair_t const *  vp,
char const *  prefix 
)

Print a fr_pair_t.

Parameters
[in]lvlDebug lvl (1-4).
[in]requestto read logging params from.
[in]parentof pair to print, may be NULL.
[in]vpto print.
[in]prefix(optional).

Definition at line 772 of file log.c.

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

◆ log_request_pair_list()

void log_request_pair_list ( fr_log_lvl_t  lvl,
request_t request,
fr_pair_t const *  parent,
fr_pair_list_t const *  vps,
char const *  prefix 
)

Print a fr_pair_list_t.

Parameters
[in]lvlDebug lvl (1-4).
[in]requestto read logging params from.
[in]parentof vps to print, may be NULL.
[in]vpsto print.
[in]prefix(optional).

Definition at line 821 of file log.c.

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

◆ log_request_perror()

void log_request_perror ( fr_log_type_t  type,
fr_log_lvl_t  lvl,
request_t request,
char const *  file,
int  line,
char const *  fmt,
  ... 
)

Drain any outstanding messages from the fr_strerror buffers.

This function drains any messages from fr_strerror buffer adding a prefix (fmt) to the first message.

Parameters
[in]typethe log category.
[in]lvlof debugging this message should be logged at.
[in]requestThe current request.
[in]filesrc file the log message was generated in.
[in]linenumber the log message was generated on.
[in]fmtwith printf style substitution tokens.
[in]...Substitution arguments.

Definition at line 670 of file log.c.

+ Here is the call graph for this function:

◆ log_request_proto_pair_list()

void log_request_proto_pair_list ( fr_log_lvl_t  lvl,
request_t request,
fr_pair_t const *  parent,
fr_pair_list_t const *  vps,
char const *  prefix 
)

Print a list of protocol fr_pair_ts.

Parameters
[in]lvlDebug lvl (1-4).
[in]requestto read logging params from.
[in]parentof vps to print, may be NULL.
[in]vpsto print.
[in]prefix(optional).

Definition at line 845 of file log.c.

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

◆ vlog_module_failure_msg()

static void vlog_module_failure_msg ( request_t request,
char const *  fmt,
va_list  ap 
)
static

Add a module failure message fr_pair_t to the request.

Parameters
[in]requestThe current request.
[in]fmtwith printf style substitution tokens.
[in]apSubstitution arguments.

Definition at line 558 of file log.c.

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

◆ vlog_request()

void vlog_request ( fr_log_type_t  type,
fr_log_lvl_t  lvl,
request_t request,
char const *  file,
int  line,
char const *  fmt,
va_list  ap,
void *  uctx 
)

Send a log message to its destination, possibly including fields from the request.

Parameters
[in]typeof log message, L_ERR, L_WARN, L_INFO, L_DBG.
[in]lvlMinimum required server or request level to output this message.
[in]requestThe current request.
[in]filesrc file the log message was generated in.
[in]linenumber the log message was generated on.
[in]fmtwith printf style substitution tokens.
[in]apSubstitution arguments.
[in]uctxThe fr_log_t specifying the destination for log messages.

Definition at line 286 of file log.c.

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

Variable Documentation

◆ attr_module_failure_message

fr_dict_attr_t const* attr_module_failure_message
static

Definition at line 197 of file log.c.

◆ dict_freeradius

fr_dict_t const* dict_freeradius
static

Definition at line 189 of file log.c.

◆ dst_tree

fr_rb_tree_t* dst_tree = NULL
static

Definition at line 224 of file log.c.

◆ filename_tree

fr_rb_tree_t* filename_tree = NULL
static

Definition at line 225 of file log.c.

◆ fr_log_request_oid_buff

_Thread_local fr_sbuff_t* fr_log_request_oid_buff
static

Definition at line 47 of file log.c.

◆ fr_vlog_request_pool

_Thread_local TALLOC_CTX* fr_vlog_request_pool
static

Definition at line 46 of file log.c.

◆ log_config

const conf_parser_t log_config[]
static
Initial value:
= {
{ FR_CONF_POINTER("destination", FR_TYPE_STRING, 0, &log_destination), .dflt = "file" },
{ FR_CONF_OFFSET("file", fr_log_t, file), },
{ FR_CONF_OFFSET("colourise", fr_log_t, colourise) },
{ FR_CONF_OFFSET("line_number", fr_log_t, line_number) },
{ FR_CONF_OFFSET("use_utc", fr_log_t, dates_utc) },
{ FR_CONF_OFFSET("print_level", fr_log_t, print_level) },
}
int const char * file
Definition: acutest.h:702
#define CONF_PARSER_TERMINATOR
Definition: cf_parse.h:626
#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
Definition: cf_parse.h:268
#define FR_CONF_POINTER_IS_SET(_name, _type, _flags, _res_p)
conf_parser_t which parses a single CONF_PAIR producing a single global result, recording if a defaul...
Definition: cf_parse.h:325
#define FR_CONF_POINTER(_name, _type, _flags, _res_p)
conf_parser_t which parses a single CONF_PAIR producing a single global result
Definition: cf_parse.h:310
static bool log_timestamp
Definition: log.c:1083
static char const * log_destination
Definition: log.c:1082
@ FR_TYPE_STRING
String of printable characters.
Definition: merged_model.c:83
@ FR_TYPE_BOOL
A truth value.
Definition: merged_model.c:95
Definition: log.h:96

Definition at line 1089 of file log.c.

◆ log_destination

char const* log_destination = NULL
static

Definition at line 1082 of file log.c.

◆ log_destination_table

fr_table_num_sorted_t const log_destination_table[]
Initial value:
= {
{ L("file"), L_DST_FILES },
{ L("files"), L_DST_FILES },
{ L("null"), L_DST_NULL },
{ L("stderr"), L_DST_STDERR },
{ L("stdout"), L_DST_STDOUT },
{ L("syslog"), L_DST_SYSLOG },
}
#define L(_str)
Helper for initialising arrays of string literals.
Definition: build.h:207
@ L_DST_NULL
Discard log messages.
Definition: log.h:83
@ L_DST_STDERR
Log to stderr.
Definition: log.h:81
@ L_DST_FILES
Log to a file on disk.
Definition: log.h:79
@ L_DST_STDOUT
Log to stdout.
Definition: log.h:78
@ L_DST_SYSLOG
Log to syslog.
Definition: log.h:80

Definition at line 177 of file log.c.

◆ log_destination_table_len

size_t log_destination_table_len = NUM_ELEMENTS(log_destination_table)

Definition at line 185 of file log.c.

◆ log_dict

Initial value:
= {
{ .out = &dict_freeradius, .proto = "freeradius" },
{ NULL }
}
static fr_dict_t const * dict_freeradius
Definition: log.c:189

Definition at line 192 of file log.c.

◆ log_dict_attr

fr_dict_attr_autoload_t log_dict_attr
Initial value:
= {
{ .out = &attr_module_failure_message, .name = "Module-Failure-Message", .type = FR_TYPE_STRING, .dict = &dict_freeradius },
{ NULL }
}
static fr_dict_attr_t const * attr_module_failure_message
Definition: log.c:197

Definition at line 200 of file log.c.

◆ log_timestamp

bool log_timestamp
static

Definition at line 1083 of file log.c.

◆ log_timestamp_is_set

bool log_timestamp_is_set
static

Definition at line 1084 of file log.c.

◆ spaces

char const spaces[] = " "
static

Definition at line 187 of file log.c.

◆ src_tree

fr_rb_tree_t* src_tree = NULL
static

Definition at line 226 of file log.c.

◆ syslog_facility_table

fr_table_num_sorted_t const syslog_facility_table[]

Syslog facility table.

Maps syslog facility keywords, to the syslog facility macros defined in the system's syslog.h.

Note
Not all facilities are supported by every operating system. If a facility is unavailable it will not appear in the table.

Definition at line 57 of file log.c.

◆ syslog_facility_table_len

size_t syslog_facility_table_len = NUM_ELEMENTS(syslog_facility_table)

Definition at line 134 of file log.c.

◆ syslog_severity_table

fr_table_num_sorted_t const syslog_severity_table[]

Syslog severity table.

Maps syslog severity keywords, to the syslog severity macros defined in the system's syslog.h file.

Definition at line 142 of file log.c.

◆ syslog_severity_table_len

size_t syslog_severity_table_len = NUM_ELEMENTS(syslog_severity_table)

Definition at line 175 of file log.c.