The FreeRADIUS server $Id: a4e7f8c94e8038b7627bcf52356b7ed15955c1d7 $
Loading...
Searching...
No Matches
Data Structures | Macros | Functions | Variables
network.c File Reference
#include <freeradius-devel/util/event.h>
#include <freeradius-devel/util/rand.h>
#include <freeradius-devel/util/rb.h>
#include <freeradius-devel/util/syserror.h>
#include <freeradius-devel/util/atexit.h>
#include <freeradius-devel/io/channel.h>
#include <freeradius-devel/io/listen.h>
#include <freeradius-devel/io/network.h>
#include <freeradius-devel/io/queue.h>
+ Include dependency graph for network.c:

Go to the source code of this file.

Data Structures

struct  fr_network_inject_t
 
struct  fr_network_s
 
struct  fr_network_socket_t
 
struct  fr_network_worker_t
 Associate a worker thread with a network thread. More...
 

Macros

#define IALPHA   (8)
 
#define LOG_DST   nr->log
 
#define LOG_PREFIX   nr->name
 
#define MAX_WORKERS   64
 
#define OUTSTANDING(_x)   ((_x)->stats.in - (_x)->stats.out)
 
#define RTT(_old, _new)   fr_time_delta_wrap((fr_time_delta_unwrap(_new) + (fr_time_delta_unwrap(_old) * (IALPHA - 1))) / IALPHA)
 

Functions

static int _fr_network_free (fr_network_t *nr)
 Free any resources associated with a network thread.
 
static int _network_socket_free (fr_network_socket_t *s)
 
static void _signal_pipe_read (UNUSED fr_event_list_t *el, int fd, UNUSED int flags, void *uctx)
 Read handler for signal pipe.
 
static int cmd_socket_list (FILE *fp, UNUSED FILE *fp_err, void *ctx, UNUSED fr_cmd_info_t const *info)
 
static int cmd_stats_self (FILE *fp, UNUSED FILE *fp_err, void *ctx, UNUSED fr_cmd_info_t const *info)
 
static int cmd_stats_socket (FILE *fp, FILE *fp_err, void *ctx, fr_cmd_info_t const *info)
 
void fr_network (fr_network_t *nr)
 
static void fr_network_channel_closed (fr_channel_t *ch, UNUSED fr_time_t now, void *uctx)
 A worker has finished closing a channel we asked it to close, remove it from the array.
 
void fr_network_close_event_delete (fr_network_t *nr)
 Remove "close" events from the event loop.
 
int fr_network_close_event_insert (fr_network_t *nr)
 Add events to the loop which will exit when the number of workers has reached zero.
 
fr_network_t * fr_network_create (TALLOC_CTX *ctx, fr_event_list_t *el, char const *name, fr_log_t const *logger, fr_log_lvl_t lvl, fr_network_config_t const *config)
 Create a network.
 
int fr_network_destroy (fr_network_t *nr)
 Stop a network thread in an orderly way.
 
int fr_network_directory_add (fr_network_t *nr, fr_listen_instance_t *li)
 Add a "watch directory" call to a network.
 
static void fr_network_directory_callback (void const *data, size_t data_size, UNUSED fr_time_t now, void *uctx)
 Handle a network control message callback for a new "watch directory".
 
static void fr_network_error (UNUSED fr_event_list_t *el, UNUSED int sockfd, int flags, int fd_errno, void *ctx)
 Handle errors for a socket.
 
int fr_network_exit (fr_network_t *nr)
 Signal a network thread to exit.
 
static void fr_network_inject_callback (void const *data, size_t data_size, UNUSED fr_time_t now, void *uctx)
 Handle a network control message callback for a packet sent to a socket.
 
static void fr_network_limit_ringbuffer (fr_network_socket_t *s, int *num_messages_p, size_t *size_p)
 
int fr_network_listen_add (fr_network_t *nr, fr_listen_instance_t *li)
 Add a fr_listen_instance_t to a network.
 
static int fr_network_listen_add_self (fr_network_t *nr, fr_listen_instance_t *listen)
 
static void fr_network_listen_callback (void const *data, size_t data_size, UNUSED fr_time_t now, void *uctx)
 Handle a network control message callback for a new listener.
 
int fr_network_listen_delete (fr_network_t *nr, fr_listen_instance_t *li)
 Delete a socket from a network.
 
int fr_network_listen_inject (fr_network_t *nr, fr_listen_instance_t *li, uint8_t const *packet, size_t packet_len, fr_time_t recv_time)
 Inject a packet for a listener to read.
 
ssize_t fr_network_listen_outstanding (fr_network_t *nr, fr_listen_instance_t *li)
 Get the number of outstanding packets.
 
void fr_network_listen_read (fr_network_t *nr, fr_listen_instance_t *li)
 Signal the network to read from a listener.
 
int fr_network_listen_send_packet (fr_network_t *nr, fr_listen_instance_t *parent, fr_listen_instance_t *li, const uint8_t *buffer, size_t buflen, fr_time_t recv_time, void *packet_ctx)
 Send a packet to the worker.
 
void fr_network_listen_write (fr_network_t *nr, fr_listen_instance_t *li, uint8_t const *packet, size_t packet_len, void *packet_ctx, fr_time_t request_time)
 Inject a packet for a listener to write.
 
static void fr_network_post_close_event (fr_event_list_t *el, UNUSED fr_time_t now, void *uctx)
 
static void fr_network_post_event (fr_event_list_t *el, fr_time_t now, void *uctx)
 
static void fr_network_post_event (UNUSED fr_event_list_t *el, UNUSED fr_time_t now, void *uctx)
 Handle replies after all FD and timer events have been serviced.
 
static int fr_network_pre_close_event (UNUSED fr_time_t now, UNUSED fr_time_delta_t wake, void *uctx)
 
static int fr_network_pre_event (fr_time_t now, fr_time_delta_t wake, void *uctx)
 
static int fr_network_pre_event (UNUSED fr_time_t now, UNUSED fr_time_delta_t wake, void *uctx)
 Run the event loop 'pre' callback.
 
static void fr_network_read (UNUSED fr_event_list_t *el, int sockfd, UNUSED int flags, void *ctx)
 Read a packet from the network.
 
static void fr_network_recv_reply (fr_channel_t *ch, fr_channel_data_t *cd, void *uctx)
 Callback which handles a message being received on the network side.
 
static int fr_network_send_request (fr_network_t *nr, fr_channel_data_t *cd)
 Send a message on the "best" channel.
 
int fr_network_sendto_worker (fr_network_t *nr, fr_listen_instance_t *li, void *packet_ctx, uint8_t const *data, size_t data_len, fr_time_t recv_time)
 
static void fr_network_socket_dead (fr_network_t *nr, fr_network_socket_t *s)
 
int fr_network_stats (fr_network_t const *nr, int num, uint64_t *stats)
 
void fr_network_stats_log (fr_network_t const *nr, fr_log_t const *log)
 
static void fr_network_suspend (fr_network_t *nr)
 
static void fr_network_unsuspend (fr_network_t *nr)
 
static void fr_network_vnode_extend (UNUSED fr_event_list_t *el, int sockfd, int fflags, void *ctx)
 Get a notification that a vnode changed.
 
int fr_network_worker_add (fr_network_t *nr, fr_worker_t *worker)
 Add a worker to a network in a different thread.
 
void fr_network_worker_add_self (fr_network_t *nr, fr_worker_t *worker)
 Add a worker to a network in the same thread.
 
static void fr_network_worker_started_callback (void const *data, size_t data_size, fr_time_t now, void *uctx)
 
static void fr_network_worker_started_callback (void const *data, size_t data_size, UNUSED fr_time_t now, void *uctx)
 Handle a network control message callback for a new worker.
 
static void fr_network_write (UNUSED fr_event_list_t *el, UNUSED int sockfd, UNUSED int flags, void *ctx)
 Write packets to the network.
 
static bool is_network_thread (fr_network_t const *nr)
 
static bool network_sleeping (fr_network_t *nr)
 The main network worker function.
 
static int network_socket_close (fr_network_socket_t *s)
 Stop a socket's I/O events and close its descriptor.
 
static fr_cmp_ret_t reply_cmp (void const *one, void const *two)
 
static fr_cmp_ret_t socket_listen_cmp (void const *one, void const *two)
 
static fr_cmp_ret_t socket_num_cmp (void const *one, void const *two)
 
static fr_cmp_ret_t waiting_cmp (void const *one, void const *two)
 

Variables

fr_cmd_table_t cmd_network_table []
 
static fr_channel_callbacks_t const fr_network_channel_callbacks
 Channel events the network handles.
 
static fr_event_update_t const pause_read []
 
static fr_event_update_t const pause_write []
 
static fr_event_update_t const resume_read []
 
static fr_event_update_t const resume_write []
 

Data Structure Documentation

◆ fr_network_inject_t

struct fr_network_inject_t

Definition at line 44 of file network.c.

+ Collaboration diagram for fr_network_inject_t:
Data Fields
fr_listen_instance_t * inst
uint8_t * packet
size_t packet_len
fr_time_t recv_time

◆ fr_network_s

struct fr_network_s

Definition at line 109 of file network.c.

+ Collaboration diagram for fr_network_s:
Data Fields
fr_network_config_t config configuration
fr_control_t * control the control plane
fr_event_list_t * el our event list
bool exiting are we exiting?
fr_log_t const * log log destination
fr_log_lvl_t lvl debug log level
unsigned int max_workers maximum number of allowed workers
char const * name Network ID for logging.
unsigned int num_blocked number of blocked workers
int num_pending_workers number of workers we're waiting to start.
int num_sockets actually a counter...
unsigned int num_workers number of active workers
fr_heap_t * replies replies from the worker, ordered by priority / origin time
int signal_pipe[2] Pipe for signalling the worker in an orderly way.

This is more deterministic than using async signals.

fr_rb_tree_t * sockets list of sockets we're managing, ordered by the listener
fr_rb_tree_t * sockets_by_num ordered by number;
fr_io_stats_t stats
bool suspended whether or not we're suspended.
pthread_t thread_id for self
fr_network_worker_t * workers[MAX_WORKERS] each worker

◆ fr_network_socket_t

struct fr_network_socket_t

Definition at line 67 of file network.c.

+ Collaboration diagram for fr_network_socket_t:
Data Fields
bool blocked is it blocked?
fr_channel_data_t * cd cached in case of allocation & read error
bool closed the descriptor has been closed.
bool dead is it dead?
fr_event_fd_t * ef the I/O event, if it was inserted.

Parented off this socket, so it cannot outlive it.

fr_event_filter_t filter what type of filter it is
fr_heap_index_t heap_id for the sockets_by_num heap
fr_listen_instance_t * inst I/O ctx and functions.
size_t leftover leftover data from a previous read
fr_rb_node_t listen_node rbtree node for looking up by listener.
fr_message_set_t * ms message buffers for this socket.
fr_network_t * nr O(N) issues in talloc.
fr_rb_node_t num_node rbtree node for looking up by number.
int number unique ID
unsigned int outstanding number of outstanding packets sent to the worker
fr_channel_data_t * pending the currently pending partial packet
fr_io_stats_t stats
fr_heap_t * waiting packets waiting to be written
size_t written however much we did in a partial write

◆ fr_network_worker_t

struct fr_network_worker_t

Associate a worker thread with a network thread.

Definition at line 54 of file network.c.

+ Collaboration diagram for fr_network_worker_t:
Data Fields
bool blocked is this worker blocked?
fr_channel_t * channel channel to the worker
fr_time_delta_t cpu_time how much CPU time this worker has spent
fr_heap_index_t heap_id workers are in a heap
fr_time_delta_t predicted predicted processing time for one packet
fr_message_set_t * reply_ms message set the worker will use to send reply data.
fr_io_stats_t stats
fr_worker_t * worker worker pointer

Macro Definition Documentation

◆ IALPHA

#define IALPHA   (8)

Definition at line 466 of file network.c.

◆ LOG_DST

#define LOG_DST   nr->log

Definition at line 29 of file network.c.

◆ LOG_PREFIX

#define LOG_PREFIX   nr->name

Definition at line 27 of file network.c.

◆ MAX_WORKERS

#define MAX_WORKERS   64

Definition at line 42 of file network.c.

◆ OUTSTANDING

#define OUTSTANDING (   _x)    ((_x)->stats.in - (_x)->stats.out)

Definition at line 549 of file network.c.

◆ RTT

#define RTT (   _old,
  _new 
)    fr_time_delta_wrap((fr_time_delta_unwrap(_new) + (fr_time_delta_unwrap(_old) * (IALPHA - 1))) / IALPHA)

Definition at line 467 of file network.c.

Function Documentation

◆ _fr_network_free()

static int _fr_network_free ( fr_network_t *  nr)
static

Free any resources associated with a network thread.

Definition at line 2047 of file network.c.

+ Here is the caller graph for this function:

◆ _network_socket_free()

static int _network_socket_free ( fr_network_socket_t *  s)
static

Definition at line 1316 of file network.c.

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

◆ _signal_pipe_read()

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

Read handler for signal pipe.

Definition at line 1873 of file network.c.

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

◆ cmd_socket_list()

static int cmd_socket_list ( FILE *  fp,
UNUSED FILE *  fp_err,
void *  ctx,
UNUSED fr_cmd_info_t const *  info 
)
static

Definition at line 2226 of file network.c.

+ Here is the call graph for this function:

◆ cmd_stats_self()

static int cmd_stats_self ( FILE *  fp,
UNUSED FILE *  fp_err,
void *  ctx,
UNUSED fr_cmd_info_t const *  info 
)
static

Definition at line 2213 of file network.c.

+ Here is the call graph for this function:

◆ cmd_stats_socket()

static int cmd_stats_socket ( FILE *  fp,
FILE *  fp_err,
void *  ctx,
fr_cmd_info_t const *  info 
)
static

Definition at line 2246 of file network.c.

+ Here is the call graph for this function:

◆ fr_network()

void fr_network ( fr_network_t *  nr)

Definition at line 1936 of file network.c.

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

◆ fr_network_channel_closed()

static void fr_network_channel_closed ( fr_channel_t *  ch,
UNUSED fr_time_t  now,
void *  uctx 
)
static

A worker has finished closing a channel we asked it to close, remove it from the array.

Parameters
[in]chthe channel.
[in]nowthe current time
[in]uctxthe network

Definition at line 519 of file network.c.

+ Here is the call graph for this function:

◆ fr_network_close_event_delete()

void fr_network_close_event_delete ( fr_network_t *  nr)

Remove "close" events from the event loop.

Definition at line 1772 of file network.c.

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

◆ fr_network_close_event_insert()

int fr_network_close_event_insert ( fr_network_t *  nr)

Add events to the loop which will exit when the number of workers has reached zero.

Definition at line 1757 of file network.c.

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

◆ fr_network_create()

fr_network_t * fr_network_create ( TALLOC_CTX *  ctx,
fr_event_list_t *  el,
char const *  name,
fr_log_t const *  logger,
fr_log_lvl_t  lvl,
fr_network_config_t const *  config 
)

Create a network.

Parameters
[in]ctxThe talloc ctx
[in]elThe event list
[in]nameNetworker identifier.
[in]loggerThe destination for all logging messages
[in]lvlLog level
[in]configconfiguration structure.
Returns
  • NULL on error
  • fr_network_t on success

Definition at line 2067 of file network.c.

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

◆ fr_network_destroy()

int fr_network_destroy ( fr_network_t *  nr)

Stop a network thread in an orderly way.

Parameters
[in]nrthe network to stop

Definition at line 1782 of file network.c.

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

◆ fr_network_directory_add()

int fr_network_directory_add ( fr_network_t *  nr,
fr_listen_instance_t *  li 
)

Add a "watch directory" call to a network.

Parameters
nrthe network
lithe listener

Definition at line 249 of file network.c.

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

◆ fr_network_directory_callback()

static void fr_network_directory_callback ( void const *  data,
size_t  data_size,
UNUSED fr_time_t  now,
void *  uctx 
)
static

Handle a network control message callback for a new "watch directory".

Parameters
[in]datathe message
[in]data_sizesize of the data
[in]nowthe current time
[in]uctxthe network

Definition at line 1498 of file network.c.

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

◆ fr_network_error()

static void fr_network_error ( UNUSED fr_event_list_t *  el,
UNUSED int  sockfd,
int  flags,
int  fd_errno,
void *  ctx 
)
static

Handle errors for a socket.

Parameters
[in]elthe event list
[in]sockfdthe socket which has a fatal error.
[in]flagsreturned by kevent.
[in]fd_errnoreturned by kevent.
[in]ctxthe network socket context.

Definition at line 1100 of file network.c.

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

◆ fr_network_exit()

int fr_network_exit ( fr_network_t *  nr)

Signal a network thread to exit.

Note
Request to exit will be processed asynchronously.
Parameters
[in]nrthe network data structure to manage
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 2034 of file network.c.

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

◆ fr_network_inject_callback()

static void fr_network_inject_callback ( void const *  data,
size_t  data_size,
UNUSED fr_time_t  now,
void *  uctx 
)
static

Handle a network control message callback for a packet sent to a socket.

Parameters
[in]datathe message
[in]data_sizesize of the data
[in]nowthe current time
[in]uctxthe network

Definition at line 1619 of file network.c.

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

◆ fr_network_limit_ringbuffer()

static void fr_network_limit_ringbuffer ( fr_network_socket_t *  s,
int *  num_messages_p,
size_t *  size_p 
)
static

Definition at line 1371 of file network.c.

+ Here is the caller graph for this function:

◆ fr_network_listen_add()

int fr_network_listen_add ( fr_network_t *  nr,
fr_listen_instance_t *  li 
)

Add a fr_listen_instance_t to a network.

Parameters
nrthe network
lithe listener

Definition at line 199 of file network.c.

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

◆ fr_network_listen_add_self()

static int fr_network_listen_add_self ( fr_network_t *  nr,
fr_listen_instance_t *  listen 
)
static

Definition at line 1388 of file network.c.

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

◆ fr_network_listen_callback()

static void fr_network_listen_callback ( void const *  data,
size_t  data_size,
UNUSED fr_time_t  now,
void *  uctx 
)
static

Handle a network control message callback for a new listener.

Parameters
[in]datathe message
[in]data_sizesize of the data
[in]nowthe current time
[in]uctxthe network

Definition at line 1357 of file network.c.

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

◆ fr_network_listen_delete()

int fr_network_listen_delete ( fr_network_t *  nr,
fr_listen_instance_t *  li 
)

Delete a socket from a network.

MUST be called only by the listener itself!.

Parameters
nrthe network
lithe listener

Definition at line 230 of file network.c.

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

◆ fr_network_listen_inject()

int fr_network_listen_inject ( fr_network_t *  nr,
fr_listen_instance_t *  li,
uint8_t const *  packet,
size_t  packet_len,
fr_time_t  recv_time 
)

Inject a packet for a listener to read.

Parameters
nrthe network
lithe listener where the packet is being injected
packetthe packet to be injected
packet_lenthe length of the packet
recv_timewhen the packet was received.
Returns
  • <0 on error
  • 0 on success

Definition at line 361 of file network.c.

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

◆ fr_network_listen_outstanding()

ssize_t fr_network_listen_outstanding ( fr_network_t *  nr,
fr_listen_instance_t *  li 
)

Get the number of outstanding packets.

Parameters
nrthe network
lithe listener that the packet was "read" from
Returns
  • <0 on error
  • the number of outstanding packets

Definition at line 778 of file network.c.

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

◆ fr_network_listen_read()

void fr_network_listen_read ( fr_network_t *  nr,
fr_listen_instance_t *  li 
)

Signal the network to read from a listener.

Parameters
nrthe network
lithe listener to read from

Definition at line 287 of file network.c.

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

◆ fr_network_listen_send_packet()

int fr_network_listen_send_packet ( fr_network_t *  nr,
fr_listen_instance_t *  parent,
fr_listen_instance_t *  li,
const uint8_t *  buffer,
size_t  buflen,
fr_time_t  recv_time,
void *  packet_ctx 
)

Send a packet to the worker.

MUST only be called from the network thread.

Parameters
nrthe network
parentthe parent listener
lithe listener that the packet was "read" from. Can be "parent"
bufferthe packet to send
buflensize of the packet to send
recv_timeof the packet
packet_ctxfor the packet
Returns
  • <0 on error
  • 0 on success

Definition at line 736 of file network.c.

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

◆ fr_network_listen_write()

void fr_network_listen_write ( fr_network_t *  nr,
fr_listen_instance_t *  li,
uint8_t const *  packet,
size_t  packet_len,
void *  packet_ctx,
fr_time_t  request_time 
)

Inject a packet for a listener to write.

Parameters
nrthe network
lithe listener where the packet is being injected
packetthe packet to be written
packet_lenthe length of the packet
packet_ctxThe packet context to write
request_timewhen the packet was received.

Definition at line 313 of file network.c.

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

◆ fr_network_post_close_event()

static void fr_network_post_close_event ( fr_event_list_t *  el,
UNUSED fr_time_t  now,
void *  uctx 
)
static

Definition at line 1748 of file network.c.

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

◆ fr_network_post_event() [1/2]

static void fr_network_post_event ( fr_event_list_t *  el,
fr_time_t  now,
void *  uctx 
)
static
+ Here is the caller graph for this function:

◆ fr_network_post_event() [2/2]

static void fr_network_post_event ( UNUSED fr_event_list_t *  el,
UNUSED fr_time_t  now,
void *  uctx 
)
static

Handle replies after all FD and timer events have been serviced.

Parameters
elthe event loop
nowthe current time (mostly)
uctxthe fr_network_t

Definition at line 1671 of file network.c.

+ Here is the call graph for this function:

◆ fr_network_pre_close_event()

static int fr_network_pre_close_event ( UNUSED fr_time_t  now,
UNUSED fr_time_delta_t  wake,
void *  uctx 
)
static

Definition at line 1741 of file network.c.

+ Here is the caller graph for this function:

◆ fr_network_pre_event() [1/2]

static int fr_network_pre_event ( fr_time_t  now,
fr_time_delta_t  wake,
void *  uctx 
)
static
+ Here is the caller graph for this function:

◆ fr_network_pre_event() [2/2]

static int fr_network_pre_event ( UNUSED fr_time_t  now,
UNUSED fr_time_delta_t  wake,
void *  uctx 
)
static

Run the event loop 'pre' callback.

This function MUST DO NO WORK. All it does is check if there's work, and tell the event code to return to the main loop if there's work to do.

Parameters
[in]nowthe current time.
[in]wakethe time when the event loop will wake up.
[in]uctxthe network

Definition at line 1656 of file network.c.

+ Here is the call graph for this function:

◆ fr_network_read()

static void fr_network_read ( UNUSED fr_event_list_t *  el,
int  sockfd,
UNUSED int  flags,
void *  ctx 
)
static

Read a packet from the network.

Parameters
[in]elthe event list.
[in]sockfdthe socket which is ready to read.
[in]flagsfrom kevent.
[in]ctxthe network socket context.

Definition at line 839 of file network.c.

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

◆ fr_network_recv_reply()

static void fr_network_recv_reply ( fr_channel_t *  ch,
fr_channel_data_t *  cd,
void *  uctx 
)
static

Callback which handles a message being received on the network side.

Parameters
[in]chthe channel that the message is on.
[in]cdthe message (if any) to start with
[in]uctxthe network

Definition at line 475 of file network.c.

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

◆ fr_network_send_request()

static int fr_network_send_request ( fr_network_t *  nr,
fr_channel_data_t *  cd 
)
static

Send a message on the "best" channel.

Parameters
nrthe network
cdthe message we've received

Definition at line 556 of file network.c.

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

◆ fr_network_sendto_worker()

int fr_network_sendto_worker ( fr_network_t *  nr,
fr_listen_instance_t *  li,
void *  packet_ctx,
uint8_t const *  data,
size_t  data_len,
fr_time_t  recv_time 
)

Definition at line 1030 of file network.c.

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

◆ fr_network_socket_dead()

static void fr_network_socket_dead ( fr_network_t *  nr,
fr_network_socket_t *  s 
)
static

Definition at line 794 of file network.c.

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

◆ fr_network_stats()

int fr_network_stats ( fr_network_t const *  nr,
int  num,
uint64_t *  stats 
)

Definition at line 2183 of file network.c.

◆ fr_network_stats_log()

void fr_network_stats_log ( fr_network_t const *  nr,
fr_log_t const *  log 
)

Definition at line 2199 of file network.c.

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

◆ fr_network_suspend()

static void fr_network_suspend ( fr_network_t *  nr)
static

Definition at line 430 of file network.c.

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

◆ fr_network_unsuspend()

static void fr_network_unsuspend ( fr_network_t *  nr)
static

Definition at line 448 of file network.c.

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

◆ fr_network_vnode_extend()

static void fr_network_vnode_extend ( UNUSED fr_event_list_t *  el,
int  sockfd,
int  fflags,
void *  ctx 
)
static

Get a notification that a vnode changed.

Parameters
[in]elthe event list.
[in]sockfdthe socket which is ready to read.
[in]fflagsfrom kevent.
[in]ctxthe network socket context.

Definition at line 1075 of file network.c.

+ Here is the caller graph for this function:

◆ fr_network_worker_add()

int fr_network_worker_add ( fr_network_t *  nr,
fr_worker_t *  worker 
)

Add a worker to a network in a different thread.

Parameters
nrthe network
workerthe worker

Definition at line 260 of file network.c.

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

◆ fr_network_worker_add_self()

void fr_network_worker_add_self ( fr_network_t *  nr,
fr_worker_t *  worker 
)

Add a worker to a network in the same thread.

Parameters
nrthe network
workerthe worker

Definition at line 276 of file network.c.

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

◆ fr_network_worker_started_callback() [1/2]

static void fr_network_worker_started_callback ( void const *  data,
size_t  data_size,
fr_time_t  now,
void *  uctx 
)
static
+ Here is the caller graph for this function:

◆ fr_network_worker_started_callback() [2/2]

static void fr_network_worker_started_callback ( void const *  data,
size_t  data_size,
UNUSED fr_time_t  now,
void *  uctx 
)
static

Handle a network control message callback for a new worker.

Parameters
[in]datathe message
[in]data_sizesize of the data
[in]nowthe current time
[in]uctxthe network

Definition at line 1568 of file network.c.

+ Here is the call graph for this function:

◆ fr_network_write()

static void fr_network_write ( UNUSED fr_event_list_t *  el,
UNUSED int  sockfd,
UNUSED int  flags,
void *  ctx 
)
static

Write packets to the network.

Parameters
elthe event list
sockfdthe socket which is ready to write
flagsreturned by kevent.
ctxthe network socket context.

Definition at line 1127 of file network.c.

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

◆ is_network_thread()

static bool is_network_thread ( fr_network_t const *  nr)
inlinestatic

Definition at line 187 of file network.c.

+ Here is the caller graph for this function:

◆ network_sleeping()

static bool network_sleeping ( fr_network_t *  nr)
inlinestatic

The main network worker function.

Parameters
[in]nrthe network data structure to run. Announce we are about to block, then drain every channel one last time

The mirror of worker_sleeping(). See fr_control_sleeping() for the ordering this relies on.

Returns
  • true if a channel had replies, so the caller must not block.
  • false if every channel was empty.

Definition at line 1915 of file network.c.

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

◆ network_socket_close()

static int network_socket_close ( fr_network_socket_t *  s)
static

Stop a socket's I/O events and close its descriptor.

Separate from freeing the socket because freeing it also frees s->ms, and the workers hold messages allocated from that until they ack the channel close. The descriptor can go as soon as we are done with it; the memory cannot.

Idempotent, so it is safe to call on a socket that is already dead.

Parameters
[in]sto close.
Returns
  • 0 on success.
  • -1 if the I/O event could not be removed. The descriptor is closed either way, so this is worth reporting but not worth stopping for.

Definition at line 1290 of file network.c.

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

◆ reply_cmp()

static fr_cmp_ret_t reply_cmp ( void const *  one,
void const *  two 
)
static

Definition at line 151 of file network.c.

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

◆ socket_listen_cmp()

static fr_cmp_ret_t socket_listen_cmp ( void const *  one,
void const *  two 
)
static

Definition at line 173 of file network.c.

+ Here is the caller graph for this function:

◆ socket_num_cmp()

static fr_cmp_ret_t socket_num_cmp ( void const *  one,
void const *  two 
)
static

Definition at line 180 of file network.c.

+ Here is the caller graph for this function:

◆ waiting_cmp()

static fr_cmp_ret_t waiting_cmp ( void const *  one,
void const *  two 
)
static

Definition at line 162 of file network.c.

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

Variable Documentation

◆ cmd_network_table

fr_cmd_table_t cmd_network_table[]

Definition at line 2266 of file network.c.

◆ fr_network_channel_callbacks

fr_channel_callbacks_t const fr_network_channel_callbacks
static
Initial value:
= {
}
static void fr_network_channel_closed(fr_channel_t *ch, UNUSED fr_time_t now, void *uctx)
A worker has finished closing a channel we asked it to close, remove it from the array.
Definition network.c:519

Channel events the network handles.

As the requestor it is never sent an open or a close.

Definition at line 545 of file network.c.

◆ pause_read

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

Definition at line 410 of file network.c.

◆ pause_write

fr_event_update_t const pause_write[]
static
Initial value:
= {
{ 0 }
}

Definition at line 420 of file network.c.

◆ resume_read

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

Definition at line 415 of file network.c.

◆ resume_write

fr_event_update_t const resume_write[]
static
Initial value:
= {
{ 0 }
}

Definition at line 425 of file network.c.