The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
master.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: 43a83604ab6bd6ad442dfee5f1c0194dada07465 $
20  *
21  * @file io/master.h
22  * @brief Master IO handler
23  *
24  * @copyright 2018 Alan DeKok (aland@freeradius.org)
25  */
26 RCSIDH(master_h, "$Id: 43a83604ab6bd6ad442dfee5f1c0194dada07465 $")
27 
28 #include <freeradius-devel/server/base.h>
29 #include <freeradius-devel/io/schedule.h>
30 #include <freeradius-devel/io/application.h>
31 #include <freeradius-devel/util/trie.h>
32 #include <freeradius-devel/util/talloc.h>
33 
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
37 
38 typedef struct fr_io_client_s fr_io_client_t;
39 
40 typedef struct fr_io_track_s {
41  fr_rb_node_t node; //!< rbtree node in the tracking tree.
42  fr_event_timer_t const *ev; //!< when we clean up this tracking entry
43  fr_time_t timestamp; //!< when this packet was received
44  fr_time_t expires; //!< when this packet expires
45  int packets; //!< number of packets using this entry
46  uint8_t *reply; //!< reply packet (if any)
47  size_t reply_len; //!< length of reply, or 1 for "do not reply"
48 
49  bool discard; //!< whether or not we discard the packet
50  bool do_not_respond; //!< don't respond
51  bool finished; //!< are we finished the request?
52 
53  fr_time_t dynamic; //!< timestamp for packet doing dynamic client definition
54  fr_io_address_t const *address; //!< of this packet.. shared between multiple packets
55  fr_io_client_t *client; //!< client handling this packet.
56  uint8_t *packet; //!< really a tracking structure, not a packet
58 
59 /** The master IO instance
60  *
61  * This structure is the instance data for the "master" IO handler.
62  * The structure is exposed for simplicity right now. It may be
63  * made private in the future.
64  *
65  * The fr_master_io_listen() should be used to create a listener from
66  * this structure.
67  *
68  * Note that most entries of this structure MUST be initialized
69  * before fr_master_io_listen() is called. That function only
70  * creates the listener, and adds it to the scheduler.
71  */
72 typedef struct {
73  dl_module_inst_t const *dl_inst; //!< our parent dl_inst
74 
75  uint32_t max_connections; //!< maximum number of connections to allow
76  uint32_t max_clients; //!< maximum number of dynamic clients to allow
77  uint32_t max_pending_packets; //!< maximum number of pending packets
78 
79  fr_time_delta_t cleanup_delay; //!< for Access-Request packets
80  fr_time_delta_t idle_timeout; //!< for dynamic clients
81  fr_time_delta_t nak_lifetime; //!< lifetime of NAKed clients
82  fr_time_delta_t check_interval; //!< polling for closed sockets
83 
84  bool dynamic_clients; //!< do we have dynamic clients.
85 
86  CONF_SECTION *server_cs; //!< server CS for this listener
87 
88  dl_module_inst_t *submodule; //!< As provided by the transport_parse
89  ///< callback. Broken out into the
90  ///< app_io_* fields below for convenience.
91  fr_app_t *app; //!< main protocol handler
92  void *app_instance; //!< instance data for main protocol handler
93 
94  fr_app_io_t const *app_io; //!< Easy access to the app_io handle.
95  void *app_io_instance; //!< Easy access to the app_io instance.
96  CONF_SECTION *app_io_conf; //!< Easy access to the app_io's config section.
97 
98  int ipproto; //!< IP proto by number
99  char const *transport; //!< transport, typically name of IP proto
100 
101  fr_trie_t const *networks; //!< trie of allowed networks
103 
105 
106 fr_trie_t *fr_master_io_network(TALLOC_CTX *ctx, int af, fr_ipaddr_t *allow, fr_ipaddr_t *deny);
107 int fr_master_io_listen(TALLOC_CTX *ctx, fr_io_instance_t *io, fr_schedule_t *sc,
108  size_t default_message_size, size_t num_messages) CC_HINT(nonnull);
109 fr_io_track_t *fr_master_io_track_alloc(fr_listen_t *li, fr_client_t *client, fr_ipaddr_t const *src_ipaddr, int src_port,
110  fr_ipaddr_t const *dst_ipaddr, int dst_port);
111 
112 #ifdef __cplusplus
113 }
114 #endif
Public structure describing an I/O path for a protocol.
Definition: app_io.h:33
Describes a new application (protocol)
Definition: application.h:71
#define RCSIDH(h, id)
Definition: build.h:445
A section grouping multiple CONF_PAIR.
Definition: cf_priv.h:89
A module/inst tuple.
Definition: dl_module.h:162
IPv4/6 prefix.
Definition: merged_model.c:272
Describes a host allowed to send packets to the server.
Definition: client.h:77
A timer event.
Definition: event.c:102
Client definitions for master IO.
Definition: master.c:98
fr_time_delta_t cleanup_delay
for Access-Request packets
Definition: master.h:79
uint8_t * reply
reply packet (if any)
Definition: master.h:46
uint32_t max_connections
maximum number of connections to allow
Definition: master.h:75
int fr_master_io_listen(TALLOC_CTX *ctx, fr_io_instance_t *io, fr_schedule_t *sc, size_t default_message_size, size_t num_messages)
Definition: master.c:2923
fr_event_timer_t const * ev
when we clean up this tracking entry
Definition: master.h:42
uint32_t max_clients
maximum number of dynamic clients to allow
Definition: master.h:76
fr_io_track_t * fr_master_io_track_alloc(fr_listen_t *li, fr_client_t *client, fr_ipaddr_t const *src_ipaddr, int src_port, fr_ipaddr_t const *dst_ipaddr, int dst_port)
Definition: master.c:3090
int packets
number of packets using this entry
Definition: master.h:45
fr_time_t dynamic
timestamp for packet doing dynamic client definition
Definition: master.h:53
fr_time_delta_t idle_timeout
for dynamic clients
Definition: master.h:80
fr_rb_node_t node
rbtree node in the tracking tree.
Definition: master.h:41
void * app_io_instance
Easy access to the app_io instance.
Definition: master.h:95
fr_app_io_t fr_master_app_io
Definition: master.c:3131
fr_app_io_t const * app_io
Easy access to the app_io handle.
Definition: master.h:94
fr_io_address_t const * address
of this packet.. shared between multiple packets
Definition: master.h:54
fr_time_delta_t check_interval
polling for closed sockets
Definition: master.h:82
fr_app_t * app
main protocol handler
Definition: master.h:91
int ipproto
IP proto by number.
Definition: master.h:98
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.
Definition: master.c:2744
dl_module_inst_t const * dl_inst
our parent dl_inst
Definition: master.h:73
bool dynamic_clients
do we have dynamic clients.
Definition: master.h:84
bool do_not_respond
don't respond
Definition: master.h:50
bool discard
whether or not we discard the packet
Definition: master.h:49
fr_time_t timestamp
when this packet was received
Definition: master.h:43
fr_time_delta_t nak_lifetime
lifetime of NAKed clients
Definition: master.h:81
void * app_instance
instance data for main protocol handler
Definition: master.h:92
dl_module_inst_t * submodule
As provided by the transport_parse callback.
Definition: master.h:88
fr_trie_t const * networks
trie of allowed networks
Definition: master.h:101
bool finished
are we finished the request?
Definition: master.h:51
uint8_t * packet
really a tracking structure, not a packet
Definition: master.h:56
size_t reply_len
length of reply, or 1 for "do not reply"
Definition: master.h:47
CONF_SECTION * server_cs
server CS for this listener
Definition: master.h:86
CONF_SECTION * app_io_conf
Easy access to the app_io's config section.
Definition: master.h:96
fr_io_client_t * client
client handling this packet.
Definition: master.h:55
char const * transport
transport, typically name of IP proto
Definition: master.h:99
fr_time_t expires
when this packet expires
Definition: master.h:44
uint32_t max_pending_packets
maximum number of pending packets
Definition: master.h:77
struct fr_io_track_s fr_io_track_t
The master IO instance.
Definition: master.h:72
unsigned int uint32_t
Definition: merged_model.c:33
unsigned char uint8_t
Definition: merged_model.c:30
The scheduler.
Definition: schedule.c:125
static const uchar sc[16]
Definition: smbdes.c:115
A time delta, a difference in time measured in nanoseconds.
Definition: time.h:80
"server local" time.
Definition: time.h:69
int nonnull(2, 5))