The FreeRADIUS server
$Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
|
#include <freeradius-devel/util/event.h>
#include <freeradius-devel/util/misc.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/util/talloc.h>
#include <freeradius-devel/io/channel.h>
#include <freeradius-devel/io/control.h>
#include <freeradius-devel/io/listen.h>
#include <freeradius-devel/io/network.h>
#include <freeradius-devel/io/queue.h>
#include <freeradius-devel/io/ring_buffer.h>
#include <freeradius-devel/io/worker.h>
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. More... | |
static int | _fr_network_rb_free (void *arg) |
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. More... | |
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) |
The main network worker function. More... | |
static void | fr_network_channel_callback (void *ctx, void const *data, size_t data_size, fr_time_t now) |
Handle a network control message callback for a channel. More... | |
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. More... | |
int | fr_network_destroy (fr_network_t *nr) |
Stop a network thread in an orderly way. More... | |
int | fr_network_directory_add (fr_network_t *nr, fr_listen_t *li) |
Add a "watch directory" call to a network. More... | |
static void | fr_network_directory_callback (void *ctx, void const *data, size_t data_size, UNUSED fr_time_t now) |
Handle a network control message callback for a new "watch directory". More... | |
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. More... | |
int | fr_network_exit (fr_network_t *nr) |
Signal a network thread to exit. More... | |
static void | fr_network_inject_callback (void *ctx, void const *data, size_t data_size, UNUSED fr_time_t now) |
Handle a network control message callback for a packet sent to a socket. More... | |
int | fr_network_listen_add (fr_network_t *nr, fr_listen_t *li) |
Add a fr_listen_t to a network. More... | |
static int | fr_network_listen_add_self (fr_network_t *nr, fr_listen_t *listen) |
static void | fr_network_listen_callback (void *ctx, void const *data, size_t data_size, UNUSED fr_time_t now) |
Handle a network control message callback for a new listener. More... | |
int | fr_network_listen_delete (fr_network_t *nr, fr_listen_t *li) |
Delete a socket from a network. More... | |
int | fr_network_listen_inject (fr_network_t *nr, fr_listen_t *li, uint8_t const *packet, size_t packet_len, fr_time_t recv_time) |
Inject a packet for a listener to read. More... | |
size_t | fr_network_listen_outstanding (fr_network_t *nr, fr_listen_t *li) |
Get the number of outstanding packets. More... | |
void | fr_network_listen_read (fr_network_t *nr, fr_listen_t *li) |
Signal the network to read from a listener. More... | |
int | fr_network_listen_send_packet (fr_network_t *nr, fr_listen_t *parent, fr_listen_t *li, const uint8_t *buffer, size_t buflen, fr_time_t recv_time, void *packet_ctx) |
Send a packet to the worker. More... | |
void | fr_network_listen_write (fr_network_t *nr, fr_listen_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. More... | |
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. More... | |
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. More... | |
static fr_ring_buffer_t * | fr_network_rb_init (void) |
Initialise thread local storage. More... | |
static void | fr_network_read (UNUSED fr_event_list_t *el, int sockfd, UNUSED int flags, void *ctx) |
Read a packet from the network. More... | |
static void | fr_network_recv_reply (void *ctx, fr_channel_t *ch, fr_channel_data_t *cd) |
Callback which handles a message being received on the network side. More... | |
static int | fr_network_send_request (fr_network_t *nr, fr_channel_data_t *cd) |
Send a message on the "best" channel. More... | |
int | fr_network_sendto_worker (fr_network_t *nr, fr_listen_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. More... | |
int | fr_network_worker_add (fr_network_t *nr, fr_worker_t *worker) |
Add a worker to a network in a different thread. More... | |
void | fr_network_worker_add_self (fr_network_t *nr, fr_worker_t *worker) |
Add a worker to a network in the same thread. More... | |
static void | fr_network_worker_started_callback (void *ctx, void const *data, size_t data_size, fr_time_t now) |
static void | fr_network_worker_started_callback (void *ctx, void const *data, size_t data_size, UNUSED fr_time_t now) |
Handle a network control message callback for a new worker. More... | |
static void | fr_network_write (UNUSED fr_event_list_t *el, UNUSED int sockfd, UNUSED int flags, void *ctx) |
Write packets to the network. More... | |
static bool | is_network_thread (fr_network_t const *nr) |
static int8_t | reply_cmp (void const *one, void const *two) |
static int8_t | socket_listen_cmp (void const *one, void const *two) |
static int8_t | socket_num_cmp (void const *one, void const *two) |
static int8_t | waiting_cmp (void const *one, void const *two) |
Variables | |
fr_cmd_table_t | cmd_network_table [] |
static _Thread_local fr_ring_buffer_t * | fr_network_rb |
static fr_event_update_t const | pause_write [] |
static fr_event_update_t const | resume_write [] |
struct fr_network_inject_t |
struct fr_network_s |
Data Fields | ||
---|---|---|
fr_atomic_queue_t * | aq_control | atomic queue for control messages sent to me |
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 |
int | max_workers | maximum number of allowed workers |
char const * | name | Network ID for logging. |
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... |
int | num_workers | number of active workers |
fr_ring_buffer_t * | rb | ring buffer for my control-plane messages |
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 |
struct fr_network_socket_t |
Data Fields | ||
---|---|---|
bool | blocked | is it blocked? |
fr_channel_data_t * | cd | cached in case of allocation & read error |
bool | dead | is it dead? |
fr_event_filter_t | filter | what type of filter it is |
fr_heap_index_t | heap_id | for the sockets_by_num heap |
size_t | leftover | leftover data from a previous read |
fr_listen_t * | listen | I/O ctx and functions. |
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 |
struct 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_io_stats_t | stats | |
fr_worker_t * | worker | worker pointer |
#define RTT | ( | _old, | |
_new | |||
) | fr_time_delta_wrap((fr_time_delta_unwrap(_new) + (fr_time_delta_unwrap(_old) * (IALPHA - 1))) / IALPHA) |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
void fr_network | ( | fr_network_t * | nr | ) |
|
static |
Handle a network control message callback for a channel.
This is called from the event loop when we get a notification from the event signalling pipe.
[in] | ctx | the network |
[in] | data | the message |
[in] | data_size | size of the data |
[in] | now | the current time |
Definition at line 534 of file network.c.
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.
[in] | ctx | The talloc ctx |
[in] | el | The event list |
[in] | name | Networker identifier. |
[in] | logger | The destination for all logging messages |
[in] | lvl | Log level |
[in] | config | configuration structure. |
Definition at line 1882 of file network.c.
int fr_network_destroy | ( | fr_network_t * | nr | ) |
int fr_network_directory_add | ( | fr_network_t * | nr, |
fr_listen_t * | li | ||
) |
|
static |
Handle a network control message callback for a new "watch directory".
[in] | ctx | the network |
[in] | data | the message |
[in] | data_size | size of the data |
[in] | now | the current time |
Definition at line 1434 of file network.c.
|
static |
Handle errors for a socket.
[in] | el | the event list |
[in] | sockfd | the socket which has a fatal error. |
[in] | flags | returned by kevent. |
[in] | fd_errno | returned by kevent. |
[in] | ctx | the network socket context. |
Definition at line 1100 of file network.c.
int fr_network_exit | ( | fr_network_t * | nr | ) |
Signal a network thread to exit.
[in] | nr | the network data structure to manage |
Definition at line 1849 of file network.c.
|
static |
Handle a network control message callback for a packet sent to a socket.
[in] | ctx | the network |
[in] | data | the message |
[in] | data_size | size of the data |
[in] | now | the current time |
Definition at line 1555 of file network.c.
int fr_network_listen_add | ( | fr_network_t * | nr, |
fr_listen_t * | li | ||
) |
|
static |
int fr_network_listen_delete | ( | fr_network_t * | nr, |
fr_listen_t * | li | ||
) |
int fr_network_listen_inject | ( | fr_network_t * | nr, |
fr_listen_t * | li, | ||
uint8_t const * | packet, | ||
size_t | packet_len, | ||
fr_time_t | recv_time | ||
) |
Inject a packet for a listener to read.
nr | the network |
li | the listener where the packet is being injected |
packet | the packet to be injected |
packet_len | the length of the packet |
recv_time | when the packet was received. |
Definition at line 398 of file network.c.
size_t fr_network_listen_outstanding | ( | fr_network_t * | nr, |
fr_listen_t * | li | ||
) |
void fr_network_listen_read | ( | fr_network_t * | nr, |
fr_listen_t * | li | ||
) |
int fr_network_listen_send_packet | ( | fr_network_t * | nr, |
fr_listen_t * | parent, | ||
fr_listen_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.
nr | the network |
parent | the parent listener |
li | the listener that the packet was "read" from. Can be "parent" |
buffer | the packet to send |
buflen | size of the packet to send |
recv_time | of the packet |
packet_ctx | for the packet |
Definition at line 763 of file network.c.
void fr_network_listen_write | ( | fr_network_t * | nr, |
fr_listen_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.
nr | the network |
li | the listener where the packet is being injected |
packet | the packet to be written |
packet_len | the length of the packet |
packet_ctx | The packet context to write |
request_time | when the packet was received. |
Definition at line 350 of file network.c.
|
static |
|
static |
|
static |
|
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.
[in] | now | the current time. |
[in] | wake | the time when the event loop will wake up. |
[in] | uctx | the network |
Definition at line 1591 of file network.c.
|
inlinestatic |
|
static |
|
static |
Callback which handles a message being received on the network side.
[in] | ctx | the network |
[in] | ch | the channel that the message is on. |
[in] | cd | the message (if any) to start with |
Definition at line 486 of file network.c.
|
static |
int fr_network_sendto_worker | ( | fr_network_t * | nr, |
fr_listen_t * | li, | ||
void * | packet_ctx, | ||
uint8_t const * | data, | ||
size_t | data_len, | ||
fr_time_t | recv_time | ||
) |
|
static |
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 |
|
static |
|
static |
int fr_network_worker_add | ( | fr_network_t * | nr, |
fr_worker_t * | worker | ||
) |
void fr_network_worker_add_self | ( | fr_network_t * | nr, |
fr_worker_t * | worker | ||
) |
|
static |
|
static |
|
inlinestatic |
|
static |
|
static |
|
static |
|
static |
fr_cmd_table_t cmd_network_table[] |
|
static |
|
static |
|
static |