The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
app_io.h
Go to the documentation of this file.
1 #pragma once
2 /*
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License as published by
5  * the Free Software Foundation; either version 2 of the License, or
6  * (at your option) any later version.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
16  */
17 
18 /**
19  * $Id: 16d0a9c7908acf98ba574962ecf79249fde23316 $
20  *
21  * @file io/app_io.h
22  * @brief Application IO interfaces.
23  *
24  * @copyright 2018 The FreeRADIUS project
25  */
26 
27 #include <freeradius-devel/util/socket.h>
28 
29 /** Public structure describing an I/O path for a protocol
30  *
31  * This structure is exported by I/O modules e.g. proto_radius_udp.
32  */
33 typedef struct {
34  module_t common; //!< Common fields to all loadable modules.
35 
36  fr_app_event_list_set_t event_list_set; //!< Called by the network thread to pass an event list
37  //!< for use by the app_io_t.
38 
39  size_t default_message_size; //!< Usually maximum message size
40  size_t default_reply_size; //!< same for replies
41  bool track_duplicates; //!< track duplicate packets
42 
43  fr_io_open_t open; //!< Open a new socket for listening, or accept/connect a new
44  //!< connection.
45  fr_io_set_fd_t fd_set; //!< Set the file descriptor to the instance.
46 
47  fr_io_data_read_t read; //!< Read from a socket to a data buffer
48  fr_io_data_write_t write; //!< Write from a data buffer to a socket
49 
50  fr_io_data_inject_t inject; //!< Inject a packet into a socket.
51 
52  fr_io_data_vnode_t vnode; //!< Handle notifications that the VNODE has changed
53 
54  fr_io_decode_t decode; //!< Translate raw bytes into fr_pair_ts and metadata.
55  fr_io_encode_t encode; //!< Pack fr_pair_ts back into a byte array.
56 
57  fr_io_signal_t flush; //!< Flush the data when the socket is ready for writing.
58 
59  fr_io_signal_t error; //!< There was an error on the socket.
60  fr_io_close_t close; //!< Close the transport.
61 
62  fr_io_nak_t nak; //!< Function to send a NAK.
63 
64  fr_io_track_create_t track_create; //!< create a tracking structure
65  fr_io_track_cmp_t track_compare; //!< compare two tracking structures
66 
67  fr_io_connection_set_t connection_set; //!< set src/dst IP/port of a connection
68  fr_io_network_get_t network_get; //!< get dynamic network information
69  fr_io_client_find_t client_find; //!< find radclient
70  fr_io_name_t get_name; //!< get the socket name
71 
72  void *private; //!< any private APIs it needs to export.
73 } fr_app_io_t;
74 
75 /*
76  * A common function to get a humanly readable socket name.
77  */
78 char const *fr_app_io_socket_name(TALLOC_CTX *ctx, fr_app_io_t const *app_io,
79  fr_ipaddr_t const *src_ipaddr, int src_port,
80  fr_ipaddr_t const *dst_ipaddr, int dst_port,
81  char const *interface);
fr_io_network_get_t network_get
get dynamic network information
Definition: app_io.h:68
fr_io_close_t close
Close the transport.
Definition: app_io.h:60
fr_io_open_t open
Open a new socket for listening, or accept/connect a new connection.
Definition: app_io.h:43
fr_io_data_read_t read
Read from a socket to a data buffer.
Definition: app_io.h:47
module_t common
Common fields to all loadable modules.
Definition: app_io.h:34
fr_io_connection_set_t connection_set
set src/dst IP/port of a connection
Definition: app_io.h:67
fr_io_signal_t error
There was an error on the socket.
Definition: app_io.h:59
fr_app_event_list_set_t event_list_set
Called by the network thread to pass an event list for use by the app_io_t.
Definition: app_io.h:36
fr_io_data_inject_t inject
Inject a packet into a socket.
Definition: app_io.h:50
fr_io_client_find_t client_find
find radclient
Definition: app_io.h:69
fr_io_encode_t encode
Pack fr_pair_ts back into a byte array.
Definition: app_io.h:55
size_t default_reply_size
same for replies
Definition: app_io.h:40
size_t default_message_size
Usually maximum message size.
Definition: app_io.h:39
fr_io_data_vnode_t vnode
Handle notifications that the VNODE has changed.
Definition: app_io.h:52
fr_io_data_write_t write
Write from a data buffer to a socket.
Definition: app_io.h:48
fr_io_set_fd_t fd_set
Set the file descriptor to the instance.
Definition: app_io.h:45
char const * fr_app_io_socket_name(TALLOC_CTX *ctx, fr_app_io_t const *app_io, fr_ipaddr_t const *src_ipaddr, int src_port, fr_ipaddr_t const *dst_ipaddr, int dst_port, char const *interface)
Definition: app_io.c:32
fr_io_track_create_t track_create
create a tracking structure
Definition: app_io.h:64
bool track_duplicates
track duplicate packets
Definition: app_io.h:41
fr_io_name_t get_name
get the socket name
Definition: app_io.h:70
fr_io_nak_t nak
Function to send a NAK.
Definition: app_io.h:62
fr_io_decode_t decode
Translate raw bytes into fr_pair_ts and metadata.
Definition: app_io.h:54
fr_io_track_cmp_t track_compare
compare two tracking structures
Definition: app_io.h:65
fr_io_signal_t flush
Flush the data when the socket is ready for writing.
Definition: app_io.h:57
Public structure describing an I/O path for a protocol.
Definition: app_io.h:33
void(* fr_app_event_list_set_t)(fr_listen_t *li, fr_event_list_t *el, void *nr)
Called by the network thread to pass an event list for the module to use for timer events.
Definition: application.h:61
IPv4/6 prefix.
Definition: merged_model.c:272
int(* fr_io_open_t)(fr_listen_t *li)
Open an I/O path.
Definition: base.h:67
ssize_t(* fr_io_data_read_t)(fr_listen_t *li, void **packet_ctx, fr_time_t *recv_time, uint8_t *buffer, size_t buffer_len, size_t *leftover)
Read from a socket.
Definition: base.h:176
int(* fr_io_track_cmp_t)(void const *instance, void *thread_instance, fr_client_t *client, void const *one, void const *two)
Compare two tracking structures for storing in a duplicate detection tree.
Definition: base.h:302
void(* fr_io_data_vnode_t)(fr_listen_t *li, uint32_t fflags)
Tell the IO handler that a VNODE has changed.
Definition: base.h:256
int(* fr_io_decode_t)(void const *instance, request_t *request, uint8_t *const data, size_t data_len)
Decode a raw packet and convert it into a request.
Definition: base.h:103
char const *(* fr_io_name_t)(fr_listen_t *li)
Definition: base.h:356
ssize_t(* fr_io_data_write_t)(fr_listen_t *li, void *packet_ctx, fr_time_t request_time, uint8_t *buffer, size_t buffer_len, size_t written)
Write a socket.
Definition: base.h:218
int(* fr_io_set_fd_t)(fr_listen_t *li, int fd)
Set a selectable file descriptor for this I/O path.
Definition: base.h:83
int(* fr_io_connection_set_t)(fr_listen_t *li, fr_io_address_t *connection)
Definition: base.h:341
size_t(* fr_io_nak_t)(fr_listen_t *li, void *packet_ctx, uint8_t *const packet, size_t packet_len, uint8_t *reply, size_t reply_len)
NAK a packet.
Definition: base.h:148
ssize_t(* fr_io_encode_t)(void const *instance, request_t *request, uint8_t *buffer, size_t buffer_len)
Encode data from a request_t into a raw packet.
Definition: base.h:123
int(* fr_io_data_inject_t)(fr_listen_t *li, uint8_t const *buffer, size_t buffer_len, fr_time_t recv_time)
Inject data into a socket.
Definition: base.h:249
fr_client_t *(* fr_io_client_find_t)(fr_listen_t *li, fr_ipaddr_t const *ipaddr, int ipproto)
Definition: base.h:345
void(* fr_io_network_get_t)(int *ipproto, bool *dynamic_clients, fr_trie_t const **trie, void *instance)
Callback to return network properties.
Definition: base.h:354
int(* fr_io_close_t)(fr_listen_t *li)
Handle a close on the socket.
Definition: base.h:330
int(* fr_io_signal_t)(fr_listen_t *li)
Handle an error on the socket.
Definition: base.h:316
void *(* fr_io_track_create_t)(void const *instance, void *thread_instance, fr_client_t *client, fr_io_track_t *track, uint8_t const *packet, size_t packet_len)
Convert a raw packet to a tracking structure.
Definition: base.h:274
static fr_app_io_t app_io
Definition: radius1_test.c:146
Struct exported by a rlm_* module.
Definition: module.h:195