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

Master IO handler. More...

#include <freeradius-devel/io/listen.h>
#include <freeradius-devel/io/master.h>
#include <freeradius-devel/server/base.h>
#include <freeradius-devel/server/module.h>
#include <freeradius-devel/util/debug.h>
#include <freeradius-devel/util/misc.h>
#include <freeradius-devel/util/syserror.h>
+ Include dependency graph for master.c:

Go to the source code of this file.

Data Structures

struct  fr_io_client_s
 Client definitions for master IO. More...
 
struct  fr_io_connection_s
 Track a connection. More...
 
struct  fr_io_pending_packet_t
 A saved packet. More...
 
struct  fr_io_thread_t
 

Macros

#define COPY_FIELD(_x)   c->_x = parent->_x
 
#define COPY_FIELD(_x)   client->radclient->_x = radclient->_x
 
#define DUP_FIELD(_x)   do { if (parent->_x) {c->_x = talloc_strdup(c, parent->_x); if (!c->_x) {goto error;}}} while (0)
 
#define DUP_FIELD(_x)   client->radclient->_x = talloc_strdup(client->radclient, radclient->_x)
 

Typedefs

typedef struct fr_io_connection_s fr_io_connection_t
 

Enumerations

enum  fr_io_client_state_t {
  PR_CLIENT_INVALID = 0 ,
  PR_CLIENT_STATIC ,
  PR_CLIENT_NAK ,
  PR_CLIENT_DYNAMIC ,
  PR_CLIENT_CONNECTED ,
  PR_CLIENT_PENDING
}
 Client states. More...
 

Functions

static int _client_free (fr_io_client_t *client)
 
static int _client_live_free (fr_io_client_t *client)
 
static int _thread_io_free (fr_io_thread_t *thread)
 
static int8_t address_cmp (void const *one, void const *two)
 
static int8_t alive_client_cmp (void const *one, void const *two)
 
static fr_io_client_tclient_alloc (TALLOC_CTX *ctx, fr_io_client_state_t state, fr_io_instance_t const *inst, fr_io_thread_t *thread, fr_client_t *radclient, fr_ipaddr_t const *network)
 
static void client_expiry_timer (fr_event_list_t *el, fr_time_t now, void *uctx)
 
static int8_t connection_cmp (void const *one, void const *two)
 
static int connection_free (fr_io_connection_t *connection)
 
static uint32_t connection_hash (void const *ctx)
 
static int count_connections (UNUSED uint8_t const *key, UNUSED size_t keylen, void *data, void *ctx)
 Count the number of connections used by active clients. More...
 
static fr_io_connection_tfr_io_connection_alloc (fr_io_instance_t const *inst, fr_io_thread_t *thread, fr_io_client_t *client, int fd, fr_io_address_t *address, fr_io_connection_t *nak)
 Create a new connection. More...
 
int fr_io_listen_free (fr_listen_t *li)
 
static fr_io_pending_packet_tfr_io_pending_alloc (fr_io_client_t *client, uint8_t const *buffer, size_t packet_len, fr_io_track_t *track, int priority)
 
static fr_io_track_tfr_io_track_add (fr_io_client_t *client, fr_io_address_t *address, uint8_t const *packet, size_t packet_len, fr_time_t recv_time, bool *is_dup)
 
int fr_master_io_listen (TALLOC_CTX *ctx, fr_io_instance_t *inst, fr_schedule_t *sc, size_t default_message_size, size_t num_messages)
 
fr_trie_tfr_master_io_network (TALLOC_CTX *ctx, int af, fr_ipaddr_t *allow, fr_ipaddr_t *deny)
 Create a trie from arrays of allow / deny IP addresses. More...
 
fr_io_track_tfr_master_io_track_alloc (fr_listen_t *li, fr_client_t *radclient, fr_ipaddr_t const *src_ipaddr, int src_port, fr_ipaddr_t const *dst_ipaddr, int dst_port)
 
static void get_inst (fr_listen_t *li, fr_io_instance_t const **inst, fr_io_thread_t **thread, fr_io_connection_t **connection, fr_listen_t **child)
 
static int mod_bootstrap (module_inst_ctx_t const *mctx)
 
static int mod_close (fr_listen_t *li)
 Close the socket. More...
 
static void mod_event_list_set (fr_listen_t *li, fr_event_list_t *el, void *nr)
 Set the event list for a new socket. More...
 
static int mod_inject (fr_listen_t *li, uint8_t const *buffer, size_t buffer_len, fr_time_t recv_time)
 Inject a packet to a connection. More...
 
static int mod_instantiate (module_inst_ctx_t const *mctx)
 
static char const * mod_name (fr_listen_t *li)
 
static int mod_open (fr_listen_t *li)
 Open a new listener. More...
 
static ssize_t mod_read (fr_listen_t *li, void **packet_ctx, fr_time_t *recv_time_p, uint8_t *buffer, size_t buffer_len, size_t *leftover)
 Implement 99% of the read routines. More...
 
static ssize_t mod_write (fr_listen_t *li, void *packet_ctx, fr_time_t request_time, uint8_t *buffer, size_t buffer_len, size_t written)
 
static void packet_expiry_timer (fr_event_list_t *el, fr_time_t now, void *uctx)
 
static int8_t pending_client_cmp (void const *one, void const *two)
 
static int pending_free (fr_io_pending_packet_t *pending)
 
static int8_t pending_packet_cmp (void const *one, void const *two)
 
static fr_io_pending_packet_tpending_packet_pop (fr_io_thread_t *thread)
 
static fr_client_tradclient_alloc (TALLOC_CTX *ctx, int ipproto, fr_io_address_t *address)
 
static fr_client_tradclient_clone (TALLOC_CTX *ctx, fr_client_t const *parent)
 
static int8_t track_cmp (void const *one, void const *two)
 
static int8_t track_connected_cmp (void const *one, void const *two)
 
static int track_dedup_free (fr_io_track_t *track)
 
static int track_free (fr_io_track_t *track)
 

Variables

fr_app_io_t fr_master_app_io
 
static fr_event_update_t pause_read []
 
static fr_event_update_t resume_read []
 

Detailed Description

Master IO handler.

Id
df78db39dc9e6a28a002cf2e1d9754a8850e09dd

Definition in file master.c.


Data Structure Documentation

◆ fr_io_client_s

struct fr_io_client_s

Client definitions for master IO.

Definition at line 98 of file master.c.

+ Collaboration diagram for fr_io_client_s:
Data Fields
fr_hash_table_t * addresses list of src/dst addresses used by this client
fr_heap_index_t alive_id for all clients
fr_io_connection_t * connection parent connection
fr_event_timer_t const * ev when we clean up the client
fr_hash_table_t * ht for tracking connected sockets
bool in_trie is the client in the trie?
fr_io_instance_t const * inst parent instance for master IO handler
pthread_mutex_t mutex for parent / child signaling
fr_ipaddr_t network network for dynamic clients
int packets number of packets using this client
fr_heap_t * pending pending packets for this client
fr_heap_index_t pending_id for pending clients
fr_client_t * radclient old-style definition of this client
bool ready_to_delete are we ready to delete this client?
fr_ipaddr_t src_ipaddr packets come from this address
fr_io_client_state_t state state of this client
fr_rb_tree_t * table tracking table for packets
fr_io_thread_t * thread
bool use_connected does this client allow connected sub-sockets?

◆ fr_io_connection_s

struct fr_io_connection_s

Track a connection.

This structure contains information about the connection, a pointer to the library instance so that we can clean up on exit, and the listener.

It also points to a client structure which is for this connection, and only this connection.

Finally, a pointer to the parent client, so that the child can tell the parent it's alive, and the parent can push packets to the child.

Definition at line 138 of file master.c.

+ Collaboration diagram for fr_io_connection_s:
Data Fields
fr_io_address_t * address full information about the connection.
fr_listen_t * child child listener (app_io) for this socket
fr_io_client_t * client our local client (pending or connected).
bool dead roundabout way to get the network side to close a socket
dl_module_inst_t * dl_inst for submodule
fr_event_list_t * el event list for this connection
fr_listen_t * listen master listener for this socket
char const * name taken from proto_FOO_TRANSPORT
fr_network_t * nr network for this connection
int packets number of packets using this connection
fr_io_client_t * parent points to the parent client.
bool paused event filter doesn't like resuming something that isn't paused

◆ fr_io_pending_packet_t

struct fr_io_pending_packet_t

A saved packet.

Definition at line 55 of file master.c.

+ Collaboration diagram for fr_io_pending_packet_t:
Data Fields
uint8_t * buffer
size_t buffer_len
fr_heap_index_t heap_id
uint32_t priority
fr_time_t recv_time
fr_io_track_t * track

◆ fr_io_thread_t

struct fr_io_thread_t

Definition at line 34 of file master.c.

+ Collaboration diagram for fr_io_thread_t:
Data Fields
fr_heap_t * alive_clients heap of active clients
fr_listen_t * child The child (app_io) IO path.
uint64_t client_id Unique client identifier.
fr_event_list_t * el event list, for the master socket.
fr_listen_t * listen The master IO path.
fr_network_t * nr network for the master socket
uint32_t num_connections number of dynamic connections
uint32_t num_pending_packets number of pending packets
fr_heap_t * pending_clients heap of pending clients
fr_schedule_t * sc the scheduler
fr_trie_t * trie trie of clients

Macro Definition Documentation

◆ COPY_FIELD [1/2]

#define COPY_FIELD (   _x)    c->_x = parent->_x

◆ COPY_FIELD [2/2]

#define COPY_FIELD (   _x)    client->radclient->_x = radclient->_x

◆ DUP_FIELD [1/2]

#define DUP_FIELD (   _x)    do { if (parent->_x) {c->_x = talloc_strdup(c, parent->_x); if (!c->_x) {goto error;}}} while (0)

◆ DUP_FIELD [2/2]

#define DUP_FIELD (   _x)    client->radclient->_x = talloc_strdup(client->radclient, radclient->_x)

Typedef Documentation

◆ fr_io_connection_t

Definition at line 1 of file master.c.

Enumeration Type Documentation

◆ fr_io_client_state_t

Client states.

Enumerator
PR_CLIENT_INVALID 
PR_CLIENT_STATIC 

static / global clients

PR_CLIENT_NAK 

negative cache entry

PR_CLIENT_DYNAMIC 

dynamically defined client

PR_CLIENT_CONNECTED 

dynamically defined client in a connected socket

PR_CLIENT_PENDING 

dynamic client pending definition

Definition at line 68 of file master.c.

Function Documentation

◆ _client_free()

static int _client_free ( fr_io_client_t client)
static

Definition at line 451 of file master.c.

+ Here is the caller graph for this function:

◆ _client_live_free()

static int _client_live_free ( fr_io_client_t client)
static

Definition at line 900 of file master.c.

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

◆ _thread_io_free()

static int _thread_io_free ( fr_io_thread_t thread)
static

Definition at line 2894 of file master.c.

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

◆ address_cmp()

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

Definition at line 240 of file master.c.

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

◆ alive_client_cmp()

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

Definition at line 1226 of file master.c.

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

◆ client_alloc()

static fr_io_client_t* client_alloc ( TALLOC_CTX *  ctx,
fr_io_client_state_t  state,
fr_io_instance_t const *  inst,
fr_io_thread_t thread,
fr_client_t radclient,
fr_ipaddr_t const *  network 
)
static

Definition at line 914 of file master.c.

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

◆ client_expiry_timer()

static void client_expiry_timer ( fr_event_list_t el,
fr_time_t  now,
void *  uctx 
)
static

Definition at line 1926 of file master.c.

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

◆ connection_cmp()

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

Definition at line 270 of file master.c.

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

◆ connection_free()

static int connection_free ( fr_io_connection_t connection)
static

Definition at line 458 of file master.c.

+ Here is the caller graph for this function:

◆ connection_hash()

static uint32_t connection_hash ( void const *  ctx)
static

Definition at line 256 of file master.c.

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

◆ count_connections()

static int count_connections ( UNUSED uint8_t const *  key,
UNUSED size_t  keylen,
void *  data,
void *  ctx 
)
static

Count the number of connections used by active clients.

Unfortunately, we also count NAK'd connections, too, even if they are closed. The alternative is to walk through all connections for each client, which would be a long time.

Definition at line 429 of file master.c.

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

◆ fr_io_connection_alloc()

static fr_io_connection_t* fr_io_connection_alloc ( fr_io_instance_t const *  inst,
fr_io_thread_t thread,
fr_io_client_t client,
int  fd,
fr_io_address_t address,
fr_io_connection_t nak 
)
static

Create a new connection.

Called ONLY from the master socket.

Definition at line 473 of file master.c.

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

◆ fr_io_listen_free()

int fr_io_listen_free ( fr_listen_t li)

Definition at line 2915 of file master.c.

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

◆ fr_io_pending_alloc()

static fr_io_pending_packet_t* fr_io_pending_alloc ( fr_io_client_t client,
uint8_t const *  buffer,
size_t  packet_len,
fr_io_track_t track,
int  priority 
)
static

Definition at line 1181 of file master.c.

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

◆ fr_io_track_add()

static fr_io_track_t* fr_io_track_add ( fr_io_client_t client,
fr_io_address_t address,
uint8_t const *  packet,
size_t  packet_len,
fr_time_t  recv_time,
bool is_dup 
)
static

Definition at line 1011 of file master.c.

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

◆ fr_master_io_listen()

int fr_master_io_listen ( TALLOC_CTX *  ctx,
fr_io_instance_t inst,
fr_schedule_t sc,
size_t  default_message_size,
size_t  num_messages 
)

Definition at line 2923 of file master.c.

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

◆ fr_master_io_network()

fr_trie_t* fr_master_io_network ( TALLOC_CTX *  ctx,
int  af,
fr_ipaddr_t allow,
fr_ipaddr_t deny 
)

Create a trie from arrays of allow / deny IP addresses.

Parameters
ctxthe talloc ctx
afthe address family to allow
allowthe array of IPs / networks to allow. MUST be talloc'd
denythe array of IPs / networks to deny. MAY be NULL, MUST be talloc'd
Returns
  • fr_trie_t on success
  • NULL on error

Definition at line 2744 of file master.c.

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

◆ fr_master_io_track_alloc()

fr_io_track_t* fr_master_io_track_alloc ( fr_listen_t li,
fr_client_t radclient,
fr_ipaddr_t const *  src_ipaddr,
int  src_port,
fr_ipaddr_t const *  dst_ipaddr,
int  dst_port 
)

Definition at line 3090 of file master.c.

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

◆ get_inst()

static void get_inst ( fr_listen_t li,
fr_io_instance_t const **  inst,
fr_io_thread_t **  thread,
fr_io_connection_t **  connection,
fr_listen_t **  child 
)
static

Definition at line 852 of file master.c.

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

◆ mod_bootstrap()

static int mod_bootstrap ( module_inst_ctx_t const *  mctx)
static

Definition at line 2628 of file master.c.

+ Here is the call graph for this function:

◆ mod_close()

static int mod_close ( fr_listen_t li)
static

Close the socket.

Definition at line 2579 of file master.c.

+ Here is the call graph for this function:

◆ mod_event_list_set()

static void mod_event_list_set ( fr_listen_t li,
fr_event_list_t el,
void *  nr 
)
static

Set the event list for a new socket.

Parameters
[in]lithe listener
[in]elthe event list
[in]nrcontext from the network side

Definition at line 1893 of file master.c.

+ Here is the call graph for this function:

◆ mod_inject()

static int mod_inject ( fr_listen_t li,
uint8_t const *  buffer,
size_t  buffer_len,
fr_time_t  recv_time 
)
static

Inject a packet to a connection.

Always called in the context of the network.

Definition at line 1803 of file master.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 2718 of file master.c.

+ Here is the call graph for this function:

◆ mod_name()

static char const* mod_name ( fr_listen_t li)
static

Definition at line 2704 of file master.c.

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

◆ mod_open()

static int mod_open ( fr_listen_t li)
static

Open a new listener.

Definition at line 1857 of file master.c.

◆ mod_read()

static ssize_t mod_read ( fr_listen_t li,
void **  packet_ctx,
fr_time_t recv_time_p,
uint8_t buffer,
size_t  buffer_len,
size_t leftover 
)
static

Implement 99% of the read routines.

The app_io->read does the transport-specific data read.

Definition at line 1238 of file master.c.

+ Here is the call graph for this function:

◆ mod_write()

static ssize_t mod_write ( fr_listen_t li,
void *  packet_ctx,
fr_time_t  request_time,
uint8_t buffer,
size_t  buffer_len,
size_t  written 
)
static

Definition at line 2202 of file master.c.

+ Here is the call graph for this function:

◆ packet_expiry_timer()

static void packet_expiry_timer ( fr_event_list_t el,
fr_time_t  now,
void *  uctx 
)
static

Definition at line 2137 of file master.c.

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

◆ pending_client_cmp()

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

Definition at line 222 of file master.c.

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

◆ pending_free()

static int pending_free ( fr_io_pending_packet_t pending)
static

Definition at line 1157 of file master.c.

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

◆ pending_packet_cmp()

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

Definition at line 192 of file master.c.

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

◆ pending_packet_pop()

static fr_io_pending_packet_t* pending_packet_pop ( fr_io_thread_t thread)
static

Definition at line 335 of file master.c.

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

◆ radclient_alloc()

static fr_client_t* radclient_alloc ( TALLOC_CTX *  ctx,
int  ipproto,
fr_io_address_t address 
)
static

Definition at line 872 of file master.c.

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

◆ radclient_clone()

static fr_client_t* radclient_clone ( TALLOC_CTX *  ctx,
fr_client_t const *  parent 
)
static

Definition at line 371 of file master.c.

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

◆ track_cmp()

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

Definition at line 279 of file master.c.

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

◆ track_connected_cmp()

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

Definition at line 309 of file master.c.

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

◆ track_dedup_free()

static int track_dedup_free ( fr_io_track_t track)
static

Definition at line 176 of file master.c.

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

◆ track_free()

static int track_free ( fr_io_track_t track)
static

Definition at line 164 of file master.c.

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

Variable Documentation

◆ fr_master_app_io

fr_app_io_t fr_master_app_io
Initial value:
= {
.common = {
.name = "radius_master_io",
.bootstrap = mod_bootstrap,
.instantiate = mod_instantiate,
},
.default_message_size = 4096,
.track_duplicates = true,
.read = mod_read,
.write = mod_write,
.inject = mod_inject,
.open = mod_open,
.close = mod_close,
.event_list_set = mod_event_list_set,
.get_name = mod_name,
}
#define MODULE_MAGIC_INIT
Stop people using different module/library/server versions together.
Definition: dl_module.h:65
static ssize_t mod_read(fr_listen_t *li, void **packet_ctx, fr_time_t *recv_time_p, uint8_t *buffer, size_t buffer_len, size_t *leftover)
Implement 99% of the read routines.
Definition: master.c:1238
static int mod_bootstrap(module_inst_ctx_t const *mctx)
Definition: master.c:2628
static void mod_event_list_set(fr_listen_t *li, fr_event_list_t *el, void *nr)
Set the event list for a new socket.
Definition: master.c:1893
static int mod_open(fr_listen_t *li)
Open a new listener.
Definition: master.c:1857
static char const * mod_name(fr_listen_t *li)
Definition: master.c:2704
static ssize_t mod_write(fr_listen_t *li, void *packet_ctx, fr_time_t request_time, uint8_t *buffer, size_t buffer_len, size_t written)
Definition: master.c:2202
static int mod_close(fr_listen_t *li)
Close the socket.
Definition: master.c:2579
static int mod_instantiate(module_inst_ctx_t const *mctx)
Definition: master.c:2718
static int mod_inject(fr_listen_t *li, uint8_t const *buffer, size_t buffer_len, fr_time_t recv_time)
Inject a packet to a connection.
Definition: master.c:1803

Definition at line 3131 of file master.c.

◆ pause_read

fr_event_update_t pause_read[]
static
Initial value:
= {
{ 0 }
}
#define FR_EVENT_SUSPEND(_s, _f)
Temporarily remove the filter for a func from kevent.
Definition: event.h:94
Callbacks for the FR_EVENT_FILTER_IO filter.
Definition: event.h:173

Definition at line 154 of file master.c.

◆ resume_read

fr_event_update_t resume_read[]
static
Initial value:
= {
{ 0 }
}
#define FR_EVENT_RESUME(_s, _f)
Re-add the filter for a func from kevent.
Definition: event.h:110

Definition at line 159 of file master.c.