All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
listen.h
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation; either version 2 of the License, or
5  * (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software
14  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
15  */
16 #ifndef _FR_LISTEN_H
17 #define _FR_LISTEN_H
18 #include <freeradius-devel/pcap.h>
19 /**
20  * $Id: d627624eedf6ac3ddeaaddd3eef59f5d13f5bf8b $
21  *
22  * @file include/listen.h
23  * @brief Listener API. Binds sockets to protocol encoders/decoders.
24  *
25  * @copyright 2015 The FreeRADIUS server project
26  */
27 RCSIDH(listen_h, "$Id: d627624eedf6ac3ddeaaddd3eef59f5d13f5bf8b $")
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
33 /*
34  * Types of listeners.
35  *
36  * Ordered by priority!
37  */
38 typedef enum RAD_LISTEN_TYPE {
50 
51 typedef enum RAD_LISTEN_STATUS {
58 
59 typedef struct rad_listen rad_listen_t;
61 
62 typedef int (*rad_listen_recv_t)(rad_listen_t *);
63 typedef int (*rad_listen_send_t)(rad_listen_t *, REQUEST *);
64 typedef int (*rad_listen_print_t)(rad_listen_t const *, char *, size_t);
65 typedef void (*rad_listen_debug_t)(REQUEST *, RADIUS_PACKET *, bool received);
66 typedef int (*rad_listen_encode_t)(rad_listen_t *, REQUEST *);
67 typedef int (*rad_listen_decode_t)(rad_listen_t *, REQUEST *);
68 
69 struct rad_listen {
70  rad_listen_t *next; /* should be rbtree stuff */
72 
73  /*
74  * For normal sockets.
75  */
77  int fd;
78  char const *server;
79  int status;
80 
81 #ifdef WITH_TCP
82  int count;
83  bool dual;
85  rad_listen_t *parent;
86 #endif
87  bool nodup;
89  uint32_t workers;
90 
91 #ifdef WITH_TLS
92  fr_tls_server_conf_t *tls;
93 #endif
94 
101 
102  CONF_SECTION const *cs;
103  void *data;
104 
105 #ifdef WITH_STATS
107 #endif
108 };
109 
110 #ifdef HAVE_LIBPCAP
111 typedef const char* (*rad_pcap_filter_builder)(rad_listen_t *);
112 #endif
113 
114 /*
115  * This shouldn't really be exposed...
116  */
117 typedef struct listen_socket_t {
118  /*
119  * For normal sockets.
120  */
122  uint16_t my_port;
123 
124  char const *interface;
125 
126 #ifdef HAVE_LIBPCAP
127  fr_pcap_t *pcap;
128  fr_pcap_type_t pcap_type;
129  rad_pcap_filter_builder pcap_filter_builder;
130 #endif
131 
133  time_t rate_time;
134  uint32_t rate_pps_old;
135  uint32_t rate_pps_now;
136  uint32_t max_rate;
137 
138  /* for outgoing sockets */
141  uint16_t other_port;
142 
143  int proto;
144 
145 
146  uint32_t recv_buff; //!< Socket receive buffer size we only allow
147  //!< configuration of SO_RCVBUF, as SO_SNDBUF
148  //!< controls the maximum datagram size.
149 
150 #ifdef WITH_TCP
151  /* for a proxy connecting to home servers */
152  time_t last_packet;
153  time_t opened;
155 
159 
160  RADIUS_PACKET *packet; /* for reading partial packets */
161 #endif
162 
163 #ifdef WITH_TLS
164  tls_session_t *tls_session;
165  REQUEST *request; /* horrible hacks */
166  VALUE_PAIR *cert_vps;
167 #ifdef HAVE_PTHREAD_H
168  pthread_mutex_t mutex;
169 #endif
170  uint8_t *data;
171  size_t partial;
172 #endif
173 
176 
177 int listen_bootstrap(CONF_SECTION *server, CONF_SECTION *cs, char const *server_name);
178 void listen_free(rad_listen_t **head);
179 int listen_init(rad_listen_t **head, bool spawn_flag);
180 rad_listen_t *proxy_new_listener(TALLOC_CTX *ctx, home_server_t *home, uint16_t src_port);
181 RADCLIENT *client_listener_find(rad_listen_t *listener, fr_ipaddr_t const *ipaddr, uint16_t src_port);
182 
183 #ifdef __cplusplus
184 }
185 #endif
186 #endif /* _FR_LISTEN_H */
#define RCSIDH(h, id)
Definition: build.h:136
uint32_t rate_pps_now
Definition: listen.h:135
char const * interface
Definition: listen.h:124
int count
Definition: listen.h:82
RADCLIENT * client
Definition: listen.h:158
RAD_LISTEN_TYPE type
Definition: listen.h:76
home_server_t * home
Definition: listen.h:139
uint16_t other_port
Definition: listen.h:141
uint32_t max_rate
Definition: listen.h:136
RAD_LISTEN_TYPE
Definition: listen.h:38
uint16_t my_port
Definition: listen.h:122
rad_listen_t * next
Definition: listen.h:70
int listen_bootstrap(CONF_SECTION *server, CONF_SECTION *cs, char const *server_name)
Definition: listen.c:109
fr_ipaddr_t other_ipaddr
Definition: listen.h:140
int fd
Definition: listen.h:77
void(* rad_listen_debug_t)(REQUEST *, RADIUS_PACKET *, bool received)
Definition: listen.h:65
struct listen_socket_t listen_socket_t
bool synchronous
Definition: listen.h:88
rad_listen_send_t send
Definition: listen.h:96
rad_listen_debug_t debug
Definition: listen.h:99
fr_ipaddr_t my_ipaddr
Definition: listen.h:121
fr_socket_limit_t limit
Definition: listen.h:156
int(* rad_listen_encode_t)(rad_listen_t *, REQUEST *)
Definition: listen.h:66
int(* rad_listen_decode_t)(rad_listen_t *, REQUEST *)
Definition: listen.h:67
int(* rad_listen_print_t)(rad_listen_t const *, char *, size_t)
Definition: listen.h:64
rad_listen_t * parent
Definition: listen.h:85
fr_stats_t stats
Definition: listen.h:106
Stores an attribute, a value and various bits of other data.
Definition: pair.h:112
rad_listen_t * proxy_new_listener(TALLOC_CTX *ctx, home_server_t *home, uint16_t src_port)
Definition: listen.c:2927
bool dual
Definition: listen.h:83
time_t rate_time
Definition: listen.h:133
CONF_SECTION const * cs
Definition: listen.h:102
rad_listen_print_t print
Definition: listen.h:100
fr_event_t * ev
Definition: listen.h:154
time_t last_packet
Definition: listen.h:152
Describes a host allowed to send packets to the server.
Definition: clients.h:35
rbtree_t * children
Definition: listen.h:84
struct listen_socket_t * parent
Definition: listen.h:157
uint8_t data[]
Definition: eap_pwd.h:625
rad_listen_decode_t decode
Definition: listen.h:98
uint32_t rate_pps_old
Definition: listen.h:134
RADCLIENT_LIST * clients
Definition: listen.h:174
int status
Definition: listen.h:79
void listen_free(rad_listen_t **head)
Free a linked list of listeners.
Definition: listen.c:3233
RADIUS_PACKET * packet
Definition: listen.h:160
uint32_t workers
Definition: listen.h:89
time_t opened
Definition: listen.h:153
RADCLIENT * client_listener_find(rad_listen_t *listener, fr_ipaddr_t const *ipaddr, uint16_t src_port)
Definition: listen.c:344
rad_listen_recv_t recv
Definition: listen.h:95
uint32_t recv_buff
Socket receive buffer size we only allow configuration of SO_RCVBUF, as SO_SNDBUF controls the maximu...
Definition: listen.h:146
IPv4/6 prefix.
Definition: inet.h:41
int(* rad_listen_recv_t)(rad_listen_t *)
Definition: listen.h:62
int(* rad_listen_send_t)(rad_listen_t *, REQUEST *)
Definition: listen.h:63
int listen_init(rad_listen_t **head, bool spawn_flag)
Search for listeners in the server.
Definition: listen.c:3123
void * data
Definition: listen.h:103
bool nodup
Definition: listen.h:87
fr_protocol_t * proto
Definition: listen.h:71
rad_listen_encode_t encode
Definition: listen.h:97
char const * server
Definition: listen.h:78
RAD_LISTEN_STATUS
Definition: listen.h:51