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

Add an additional log destination for any given request. More...

#include <freeradius-devel/server/base.h>
#include <freeradius-devel/server/module_rlm.h>
#include <freeradius-devel/util/debug.h>
#include <freeradius-devel/server/connection.h>
#include <sys/uio.h>
+ Include dependency graph for rlm_logtee.c:

Go to the source code of this file.

Data Structures

struct  logtee_net_t
 
struct  rlm_logtee_t
 logtee module instance More...
 
struct  rlm_logtee_t.file
 
struct  rlm_logtee_t.unix_sock
 
struct  rlm_logtee_thread_t
 Per-thread instance data. More...
 

Enumerations

enum  logtee_dst_t {
  LOGTEE_DST_INVALID = 0 ,
  LOGTEE_DST_FILE ,
  LOGTEE_DST_UNIX ,
  LOGTEE_DST_UDP ,
  LOGTEE_DST_TCP
}
 

Functions

static void _logtee_conn_close (UNUSED fr_event_list_t *el, void *h, UNUSED void *uctx)
 Shutdown/close a file descriptor. More...
 
static void _logtee_conn_error (UNUSED fr_event_list_t *el, int sock, UNUSED int flags, int fd_errno, void *uctx)
 Connection errored. More...
 
static connection_state_t _logtee_conn_open (UNUSED fr_event_list_t *el, UNUSED void *h, void *uctx)
 Process notification that fd is open. More...
 
static void _logtee_conn_read (UNUSED fr_event_list_t *el, int sock, UNUSED int flags, void *uctx)
 Drain any data we received. More...
 
static void _logtee_conn_writable (UNUSED fr_event_list_t *el, int sock, UNUSED int flags, void *uctx)
 There's space available to write data, so do that... More...
 
 CC_NO_UBSAN (function)
 Initialise a new outbound connection. More...
 
static void logtee_fd_active (rlm_logtee_thread_t *t)
 Set the socket to active. More...
 
static void logtee_fd_idle (rlm_logtee_thread_t *t)
 Set the socket to idle. More...
 
static void logtee_it (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))
 
static void logtee_it (fr_log_type_t type, fr_log_lvl_t lvl, request_t *request, UNUSED char const *file, UNUSED int line, char const *fmt, va_list ap, void *uctx)
 Logging callback to write log messages to a destination. More...
 
static unlang_action_t mod_insert_logtee (rlm_rcode_t *p_result, module_ctx_t const *mctx, request_t *request)
 Add our logging destination to the linked list of logging destinations (if it doesn't already exist) More...
 
static int mod_instantiate (module_inst_ctx_t const *mctx)
 
static int mod_thread_instantiate (module_thread_inst_ctx_t const *mctx)
 Create thread-specific connections and buffers. More...
 

Variables

static fr_dict_attr_t const * attr_log_level
 
static fr_dict_attr_t const * attr_log_message
 
static fr_dict_attr_t const * attr_log_type
 
static fr_dict_t const * dict_freeradius
 
static const conf_parser_t file_config []
 
static fr_table_num_sorted_t const logtee_dst_table []
 
static size_t logtee_dst_table_len = NUM_ELEMENTS(logtee_dst_table)
 
static const conf_parser_t module_config []
 
module_rlm_t rlm_logtee
 
fr_dict_autoload_t rlm_logtee_dict []
 
fr_dict_attr_autoload_t rlm_logtee_dict_attr []
 
static const conf_parser_t tcp_config []
 
static const conf_parser_t udp_config []
 
static const conf_parser_t unix_config []
 

Detailed Description

Add an additional log destination for any given request.

Id
6893a40d066975062bf3ea885e90d3b7659add3d
Author
Arran Cudbard-Bell (a.cud.nosp@m.bard.nosp@m.b@fre.nosp@m.erad.nosp@m.ius.o.nosp@m.rg)

Definition in file rlm_logtee.c.


Data Structure Documentation

◆ logtee_net_t

struct logtee_net_t

Definition at line 70 of file rlm_logtee.c.

+ Collaboration diagram for logtee_net_t:
Data Fields
fr_ipaddr_t dst_ipaddr Network server.
uint16_t port Network port.
fr_ipaddr_t src_ipaddr Send requests from a given src_ipaddr.

◆ rlm_logtee_t

struct rlm_logtee_t

logtee module instance

Definition at line 78 of file rlm_logtee.c.

+ Collaboration diagram for rlm_logtee_t:
Data Fields
size_t buffer_depth How big our circular buffer should be.
fr_time_delta_t connection_timeout How long to wait to open a socket.
char const * delimiter Line termination string (usually
).
size_t delimiter_len Length of line termination string.
struct rlm_logtee_t file
logtee_dst_t log_dst Logging destination.
char const * log_dst_str Logging destination string.
tmpl_t * log_fmt Source of log messages.
char const * name Module instance name.
fr_time_delta_t reconnection_delay How long to wait to retry.
logtee_net_t tcp TCP server.
logtee_net_t udp UDP server.
struct rlm_logtee_t unix_sock

◆ rlm_logtee_t.file

struct rlm_logtee_t.file

Definition at line 91 of file rlm_logtee.c.

Data Fields
bool escape Do filename escaping, yes / no.
xlat_escape_legacy_t escape_func Escape function.
gid_t group Resolved gid.
char const * group_str Group to set on new files.
char const * name File to write to.
uint32_t permissions Permissions to use when creating new files.

◆ rlm_logtee_t.unix_sock

struct rlm_logtee_t.unix_sock

Definition at line 100 of file rlm_logtee.c.

Data Fields
char const * path Where the UNIX socket lives.

◆ rlm_logtee_thread_t

struct rlm_logtee_thread_t

Per-thread instance data.

Contains buffers and connection handles specific to the thread.

Definition at line 115 of file rlm_logtee.c.

+ Collaboration diagram for rlm_logtee_thread_t:
Data Fields
connection_t * conn Connection to our log destination.
fr_event_list_t * el This thread's event list.
fr_fring_t * fring Circular buffer used to batch up messages.
rlm_logtee_t const * inst Instance of logtee.
fr_pair_t * lvl Temporary value pair holding the log lvl.
fr_pair_t * msg Temporary value pair holding the message value.
TALLOC_CTX * msg_pool A 1k talloc pool to hold the log message whilst it's being expanded.
bool pending We have pending messages to write.
fr_pair_t * type Temporary value pair holding the message type.

Enumeration Type Documentation

◆ logtee_dst_t

Enumerator
LOGTEE_DST_INVALID 
LOGTEE_DST_FILE 

Log to a file.

LOGTEE_DST_UNIX 

Log via Unix socket.

LOGTEE_DST_UDP 

Log via UDP.

LOGTEE_DST_TCP 

Log via TCP.

Definition at line 54 of file rlm_logtee.c.

Function Documentation

◆ _logtee_conn_close()

static void _logtee_conn_close ( UNUSED fr_event_list_t el,
void *  h,
UNUSED void *  uctx 
)
static

Shutdown/close a file descriptor.

Definition at line 354 of file rlm_logtee.c.

+ Here is the call graph for this function:

◆ _logtee_conn_error()

static void _logtee_conn_error ( UNUSED fr_event_list_t el,
int  sock,
UNUSED int  flags,
int  fd_errno,
void *  uctx 
)
static

Connection errored.

Definition at line 213 of file rlm_logtee.c.

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

◆ _logtee_conn_open()

static connection_state_t _logtee_conn_open ( UNUSED fr_event_list_t el,
UNUSED void *  h,
void *  uctx 
)
static

Process notification that fd is open.

Definition at line 366 of file rlm_logtee.c.

+ Here is the call graph for this function:

◆ _logtee_conn_read()

static void _logtee_conn_read ( UNUSED fr_event_list_t el,
int  sock,
UNUSED int  flags,
void *  uctx 
)
static

Drain any data we received.

We don't care about this data, we just don't want the kernel to signal the other side that our read buffer's full.

Definition at line 230 of file rlm_logtee.c.

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

◆ _logtee_conn_writable()

static void _logtee_conn_writable ( UNUSED fr_event_list_t el,
int  sock,
UNUSED int  flags,
void *  uctx 
)
static

There's space available to write data, so do that...

Definition at line 263 of file rlm_logtee.c.

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

◆ CC_NO_UBSAN()

CC_NO_UBSAN ( function  )

Initialise a new outbound connection.

Parameters
[out]h_outWhere to write the new file descriptor.
[in]connbeing initialised.
[in]uctxA rlm_logtee_thread_t.

Definition at line 390 of file rlm_logtee.c.

+ Here is the call graph for this function:

◆ logtee_fd_active()

static void logtee_fd_active ( rlm_logtee_thread_t t)
static

Set the socket to active.

We have messages we want to send, so need to know when the socket is writable.

Parameters
[in]tThread instance containing the connection.

Definition at line 337 of file rlm_logtee.c.

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

◆ logtee_fd_idle()

static void logtee_fd_idle ( rlm_logtee_thread_t t)
static

Set the socket to idle.

If the other side is sending back garbage, we want to drain it so our buffer doesn't fill up.

Parameters
[in]tThread instance containing the connection.

Definition at line 317 of file rlm_logtee.c.

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

◆ logtee_it() [1/2]

static void logtee_it ( 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 
)
static
+ Here is the caller graph for this function:

◆ logtee_it() [2/2]

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

Logging callback to write log messages to a destination.

This allows the logging destination to be customised on a per request basis.

Note
Function does not write log output immediately
Parameters
[in]typeWhat type of message this is (error, warn, info, debug).
[in]lvlAt what logging level this message should be output.
[in]requestThe current request.
[in]filesrc file the log message was generated in.
[in]linenumber the log message was generated on.
[in]fmtsprintf style fmt string.
[in]apArguments for the fmt string.
[in]uctxContext data for the log function.

Definition at line 455 of file rlm_logtee.c.

+ Here is the call graph for this function:

◆ mod_insert_logtee()

static unlang_action_t mod_insert_logtee ( rlm_rcode_t p_result,
module_ctx_t const *  mctx,
request_t request 
)
static

Add our logging destination to the linked list of logging destinations (if it doesn't already exist)

Parameters
[in]p_resultthe result of the module call:
[in]mctxModule calling ctx.
[in]requestrequest to add our log destination to.

Definition at line 526 of file rlm_logtee.c.

+ Here is the call graph for this function:

◆ mod_instantiate()

static int mod_instantiate ( module_inst_ctx_t const *  mctx)
static

Definition at line 598 of file rlm_logtee.c.

+ Here is the call graph for this function:

◆ mod_thread_instantiate()

static int mod_thread_instantiate ( module_thread_inst_ctx_t const *  mctx)
static

Create thread-specific connections and buffers.

Parameters
[in]mctxspecific data.
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 556 of file rlm_logtee.c.

+ Here is the call graph for this function:

Variable Documentation

◆ attr_log_level

fr_dict_attr_t const* attr_log_level
static

Definition at line 187 of file rlm_logtee.c.

◆ attr_log_message

fr_dict_attr_t const* attr_log_message
static

Definition at line 188 of file rlm_logtee.c.

◆ attr_log_type

fr_dict_attr_t const* attr_log_type
static

Definition at line 189 of file rlm_logtee.c.

◆ dict_freeradius

fr_dict_t const* dict_freeradius
static

Definition at line 179 of file rlm_logtee.c.

◆ file_config

const conf_parser_t file_config[]
static
Initial value:
= {
{ FR_CONF_OFFSET("permissions", rlm_logtee_t, file.permissions), .dflt = "0600" },
{ FR_CONF_OFFSET("group", rlm_logtee_t, file.group_str) },
{ FR_CONF_OFFSET("escape_filenames", rlm_logtee_t, file.escape), .dflt = "no" },
}
int const char * file
Definition: acutest.h:702
#define CONF_PARSER_TERMINATOR
Definition: cf_parse.h:627
#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_OFFSET_FLAGS(_name, _flags, _struct, _field)
conf_parser_t which parses a single CONF_PAIR, writing the result to a field in a struct
Definition: cf_parse.h:256
@ CONF_FLAG_FILE_OUTPUT
File matching value must exist, and must be writable.
Definition: cf_parse.h:413
@ CONF_FLAG_XLAT
string will be dynamically expanded.
Definition: cf_parse.h:416
logtee module instance
Definition: rlm_logtee.c:78

Definition at line 132 of file rlm_logtee.c.

◆ logtee_dst_table

fr_table_num_sorted_t const logtee_dst_table[]
static
Initial value:
= {
{ L("file"), LOGTEE_DST_FILE },
{ L("tcp"), LOGTEE_DST_TCP },
{ L("udp"), LOGTEE_DST_UDP },
{ L("unix"), LOGTEE_DST_UNIX }
}
#define L(_str)
Helper for initialising arrays of string literals.
Definition: build.h:207
@ LOGTEE_DST_FILE
Log to a file.
Definition: rlm_logtee.c:56
@ LOGTEE_DST_TCP
Log via TCP.
Definition: rlm_logtee.c:59
@ LOGTEE_DST_UNIX
Log via Unix socket.
Definition: rlm_logtee.c:57
@ LOGTEE_DST_UDP
Log via UDP.
Definition: rlm_logtee.c:58

Definition at line 62 of file rlm_logtee.c.

◆ logtee_dst_table_len

size_t logtee_dst_table_len = NUM_ELEMENTS(logtee_dst_table)
static

Definition at line 68 of file rlm_logtee.c.

◆ module_config

const conf_parser_t module_config[]
static
Initial value:
= {
{ FR_CONF_OFFSET_FLAGS("destination", CONF_FLAG_REQUIRED, rlm_logtee_t, log_dst_str) },
{ FR_CONF_OFFSET_TYPE_FLAGS("buffer_depth", FR_TYPE_SIZE, 0, rlm_logtee_t, buffer_depth), .dflt = "10000" },
{ FR_CONF_OFFSET("delimiter", rlm_logtee_t, delimiter), .dflt = "\n" },
{ FR_CONF_OFFSET("format", rlm_logtee_t, log_fmt), .dflt = "%n - %s", .quote = T_DOUBLE_QUOTED_STRING },
{ FR_CONF_POINTER("file", 0, CONF_FLAG_SUBSECTION, NULL), .subcs = (void const *) file_config },
{ FR_CONF_POINTER("unix", 0, CONF_FLAG_SUBSECTION, NULL), .subcs = (void const *) unix_config },
{ FR_CONF_OFFSET("connection_timeout", rlm_logtee_t, connection_timeout), .dflt = "1.0" },
{ FR_CONF_OFFSET("reconnection_delay", rlm_logtee_t, reconnection_delay), .dflt = "1.0" },
}
#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
#define FR_CONF_OFFSET_SUBSECTION(_name, _flags, _struct, _field, _subcs)
conf_parser_t which populates a sub-struct using a CONF_SECTION
Definition: cf_parse.h:297
@ CONF_FLAG_REQUIRED
Error out if no matching CONF_PAIR is found, and no dflt value is set.
Definition: cf_parse.h:405
@ CONF_FLAG_SUBSECTION
Instead of putting the information into a configuration structure, the configuration file routines MA...
Definition: cf_parse.h:399
#define FR_CONF_OFFSET_TYPE_FLAGS(_name, _type, _flags, _struct, _field)
conf_parser_t which parses a single CONF_PAIR, writing the result to a field in a struct
Definition: cf_parse.h:241
@ FR_TYPE_SIZE
Unsigned integer capable of representing any memory address on the local system.
Definition: merged_model.c:115
static const conf_parser_t file_config[]
Definition: rlm_logtee.c:132
static const conf_parser_t udp_config[]
Definition: rlm_logtee.c:145
static const conf_parser_t unix_config[]
Definition: rlm_logtee.c:140
static const conf_parser_t tcp_config[]
Definition: rlm_logtee.c:151
@ T_DOUBLE_QUOTED_STRING
Definition: token.h:121

Definition at line 158 of file rlm_logtee.c.

◆ rlm_logtee

module_rlm_t rlm_logtee
Initial value:
= {
.common = {
.name = "logtee",
.inst_size = sizeof(rlm_logtee_t),
.thread_inst_size = sizeof(rlm_logtee_thread_t),
.config = module_config,
.instantiate = mod_instantiate,
.thread_instantiate = mod_thread_instantiate,
},
.method_group = {
.bindings = (module_method_binding_t[]){
}
}
}
#define CF_IDENT_ANY
Definition: cf_util.h:78
#define MODULE_MAGIC_INIT
Stop people using different module/library/server versions together.
Definition: dl_module.h:63
static int mod_thread_instantiate(module_thread_inst_ctx_t const *mctx)
Create thread-specific connections and buffers.
Definition: rlm_logtee.c:556
static unlang_action_t mod_insert_logtee(rlm_rcode_t *p_result, module_ctx_t const *mctx, request_t *request)
Add our logging destination to the linked list of logging destinations (if it doesn't already exist)
Definition: rlm_logtee.c:526
static const conf_parser_t module_config[]
Definition: rlm_logtee.c:158
static int mod_instantiate(module_inst_ctx_t const *mctx)
Definition: rlm_logtee.c:598
Per-thread instance data.
Definition: rlm_logtee.c:115
#define SECTION_NAME(_name1, _name2)
Define a section name consisting of a verb and a noun.
Definition: section.h:40
#define MODULE_BINDING_TERMINATOR
Terminate a module binding list.
Definition: module.h:151
Named methods exported by a module.
Definition: module.h:173

Definition at line 659 of file rlm_logtee.c.

◆ rlm_logtee_dict

fr_dict_autoload_t rlm_logtee_dict
Initial value:
= {
{ .out = &dict_freeradius, .proto = "freeradius" },
{ NULL }
}
static fr_dict_t const * dict_freeradius
Definition: rlm_logtee.c:179

Definition at line 182 of file rlm_logtee.c.

◆ rlm_logtee_dict_attr

fr_dict_attr_autoload_t rlm_logtee_dict_attr
Initial value:
= {
{ .out = &attr_log_level, .name = "Log-Level", .type = FR_TYPE_UINT32, .dict = &dict_freeradius },
{ .out = &attr_log_message, .name = "Log-Message", .type = FR_TYPE_STRING, .dict = &dict_freeradius },
{ .out = &attr_log_type, .name = "Log-Type", .type = FR_TYPE_UINT32, .dict = &dict_freeradius },
{ NULL }
}
@ FR_TYPE_STRING
String of printable characters.
Definition: merged_model.c:83
@ FR_TYPE_UINT32
32 Bit unsigned integer.
Definition: merged_model.c:99
static fr_dict_attr_t const * attr_log_type
Definition: rlm_logtee.c:189
static fr_dict_attr_t const * attr_log_message
Definition: rlm_logtee.c:188
static fr_dict_attr_t const * attr_log_level
Definition: rlm_logtee.c:187

Definition at line 192 of file rlm_logtee.c.

◆ tcp_config

const conf_parser_t tcp_config[]
static
Initial value:
= {
{ FR_CONF_OFFSET("port", logtee_net_t, port) },
}
@ FR_TYPE_COMBO_IP_ADDR
IPv4 or IPv6 address depending on length.
Definition: merged_model.c:91

Definition at line 151 of file rlm_logtee.c.

◆ udp_config

const conf_parser_t udp_config[]
static
Initial value:

Definition at line 145 of file rlm_logtee.c.

◆ unix_config

const conf_parser_t unix_config[]
static
Initial value:
= {
{ FR_CONF_OFFSET_FLAGS("filename", CONF_FLAG_FILE_INPUT, rlm_logtee_t, unix_sock.path) },
}
@ CONF_FLAG_FILE_INPUT
File matching value must exist, and must be readable.
Definition: cf_parse.h:411

Definition at line 140 of file rlm_logtee.c.