The FreeRADIUS server $Id: a4e7f8c94e8038b7627bcf52356b7ed15955c1d7 $
Loading...
Searching...
No Matches
proto_radius_tcp.c
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
17/**
18 * $Id: 89a0b9c2271858c69b67954fd119c321c6448326 $
19 * @file proto_radius_tcp.c
20 * @brief RADIUS handler for TCP.
21 *
22 * @copyright 2016 The FreeRADIUS server project.
23 * @copyright 2016 Alan DeKok (aland@deployingradius.com)
24 */
25#include <netdb.h>
26#include <freeradius-devel/radius/tcp.h>
27#include <freeradius-devel/util/trie.h>
28#include <freeradius-devel/radius/radius.h>
29#include <freeradius-devel/io/application.h>
30#include <freeradius-devel/io/listen.h>
31#include <freeradius-devel/io/schedule.h>
32#include "proto_radius.h"
33
35
37
38typedef struct {
39 CONF_SECTION *cs; //!< our configuration
40
41 fr_ipaddr_t ipaddr; //!< IP address to listen on.
42
43 char const *interface; //!< Interface to bind to.
44 char const *port_name; //!< Name of the port for getservent().
45
46 uint32_t recv_buff; //!< How big the kernel's receive buffer should be.
47
48 uint32_t max_packet_size; //!< for message ring buffer.
49 uint32_t max_attributes; //!< Limit maximum decodable attributes.
50
51 uint16_t port; //!< Port to listen on.
52
53 bool recv_buff_is_set; //!< Whether we were provided with a recv_buff
54 bool dynamic_clients; //!< whether we have dynamic clients
55
56 fr_client_list_t *clients; //!< local clients
57
58 fr_trie_t *trie; //!< for parsed networks
59 fr_ipaddr_t *allow; //!< allowed networks for dynamic clients
60 fr_ipaddr_t *deny; //!< denied networks for dynamic clients
61
62 bool read_hexdump; //!< Do we debug hexdump read packets.
63 bool write_hexdump; //!< Do we debug hexdump write packets.
65
66
73
74
79
80 { FR_CONF_OFFSET("interface", proto_radius_tcp_t, interface) },
81 { FR_CONF_OFFSET("port_name", proto_radius_tcp_t, port_name) },
82
83 { FR_CONF_OFFSET("port", proto_radius_tcp_t, port) },
84 { FR_CONF_OFFSET_IS_SET("recv_buff", FR_TYPE_UINT32, 0, proto_radius_tcp_t, recv_buff) },
85
86 { FR_CONF_OFFSET("dynamic_clients", proto_radius_tcp_t, dynamic_clients) } ,
87 { FR_CONF_POINTER("networks", 0, CONF_FLAG_SUBSECTION, NULL), .subcs = (void const *) networks_config },
88
89 { FR_CONF_OFFSET("max_packet_size", proto_radius_tcp_t, max_packet_size), .dflt = "4096" } ,
90 { FR_CONF_OFFSET("max_attributes", proto_radius_tcp_t, max_attributes), .dflt = STRINGIFY(RADIUS_MAX_ATTRIBUTES) } ,
91
92 { FR_CONF_OFFSET("read_hexdump", proto_radius_tcp_t, read_hexdump) },
93 { FR_CONF_OFFSET("write_hexdump", proto_radius_tcp_t, write_hexdump) },
94
96};
97
98
100 size_t buffer_len, size_t *leftover)
101{
104 proto_radius_tcp_thread_t *thread = talloc_get_type_abort(li->thread_instance, proto_radius_tcp_thread_t);
105 ssize_t data_size;
106 size_t packet_len, in_buffer;
107 uint8_t code;
109
110 /*
111 * We may have read multiple packets in the previous read. In which case the buffer may already
112 * have packets remaining. In that case, we can return packets directly from the buffer, and
113 * skip the read().
114 */
115 if (*leftover >= RADIUS_HEADER_LENGTH) {
116 packet_len = fr_nbo_to_uint16(buffer + 2);
117
118 if (packet_len <= *leftover) {
119 data_size = 0;
120 goto have_packet;
121 }
122
123 /*
124 * Else we don't have a full packet, try to read more data from the network.
125 */
126 }
127
128 /*
129 * Read data into the buffer.
130 */
131 data_size = read(thread->sockfd, buffer + *leftover, buffer_len - *leftover);
132 if (data_size < 0) {
133 switch (errno) {
134#if defined(EWOULDBLOCK) && (EWOULDBLOCK != EAGAIN)
135 case EWOULDBLOCK:
136#endif
137 case EAGAIN:
138 /*
139 * We didn't read any data; leave the buffers alone.
140 *
141 * i.e. if we had a partial packet in the buffer and we didn't read any data,
142 * then the partial packet is still left in the buffer.
143 */
144 return 0;
145
146 default:
147 break;
148 }
149
151 "%s", fr_strerror());
152 return data_size;
153 }
154
155 /*
156 * Note that we return ERROR for all bad packets, as
157 * there's no point in reading RADIUS packets from a TCP
158 * connection which isn't sending us RADIUS packets.
159 */
160
161 /*
162 * TCP read of zero means the socket is dead.
163 */
164 if (!data_size) {
166 "Client closed the connection");
167 return -1;
168 }
169
170have_packet:
171 /*
172 * We MUST always start with a known RADIUS packet. Check
173 * and index with the same copy of the code.
174 */
175 code = buffer[0];
176 if ((code == 0) || (code >= FR_RADIUS_CODE_MAX)) {
178 "Received packet code %u", code);
179 thread->stats.total_unknown_types++;
180 return -1;
181 }
182
183 in_buffer = data_size + *leftover;
184
185 /*
186 * Not enough for one packet. Tell the caller that we need to read more.
187 */
188 if (in_buffer < RADIUS_HEADER_LENGTH) {
189 *leftover = in_buffer;
190 return 0;
191 }
192
193 /*
194 * Figure out how large the RADIUS packet is.
195 */
196 packet_len = fr_nbo_to_uint16(buffer + 2);
197
198 /*
199 * Invalid packet lengths cause the socket to be closed.
200 */
201 if (packet_len < RADIUS_HEADER_LENGTH) {
203 "Received packet length %zu", packet_len);
205 return -1;
206 }
207
208 if (packet_len > inst->max_packet_size) {
210 "Received packet length %zu", packet_len);
212 return -1;
213 }
214
215 /*
216 * We don't have a complete RADIUS packet. Tell the
217 * caller that we need to read more.
218 */
219 if (in_buffer < packet_len) {
220 *leftover = in_buffer;
221 return 0;
222 }
223
224 /*
225 * We've read at least one packet. Tell the caller that
226 * there's more data available, and return only one packet.
227 */
228 *leftover = in_buffer - packet_len;
229
230 /*
231 * If it's not a RADIUS packet, ignore it.
232 */
233 if (!fr_radius_ok(buffer, &packet_len, inst->max_attributes, false, &reason)) {
234 proto_radius_log(li, reason, NULL, "Received invalid packet");
236 return -1;
237 }
238
239 *recv_time_p = fr_time();
240 thread->stats.total_requests++;
241
242 /*
243 * proto_radius sets the priority
244 */
245
246 /*
247 * Print out what we received.
248 */
249 DEBUG2("proto_radius_tcp - Received %s ID %d length %d %s",
251 (int) packet_len, thread->name);
252
253 return packet_len;
254}
255
256
258 size_t buffer_len, size_t written)
259{
260 proto_radius_tcp_thread_t *thread = talloc_get_type_abort(li->thread_instance, proto_radius_tcp_thread_t);
261 fr_io_track_t *track = talloc_get_type_abort(packet_ctx, fr_io_track_t);
262 ssize_t data_size;
263 ssize_t total;
264
265 /*
266 * @todo - share a stats interface with the parent? or
267 * put the stats in the listener, so that proto_radius
268 * can update them, too.. <sigh>
269 */
270 if (!written) thread->stats.total_responses++;
271
272 /*
273 * This handles the race condition where we get a DUP,
274 * but the original packet replies before we're run.
275 * i.e. this packet isn't marked DUP, so we have to
276 * discover it's a dup later...
277 *
278 * As such, if there's already a reply, then we ignore
279 * the encoded reply (which is probably going to be a
280 * NAK), and instead just ignore the DUP and don't reply.
281 */
282 if (track->reply_len) {
283 return buffer_len;
284 }
285
286 /*
287 * We only write RADIUS packets.
288 */
289 fr_assert(buffer_len >= 20);
290 fr_assert(written < buffer_len);
291
292 /*
293 * Only write replies if they're RADIUS packets.
294 * sometimes we want to NOT send a reply...
295 */
296 data_size = write(thread->sockfd, buffer + written, buffer_len - written);
297
298 /*
299 * This socket is dead. That's an error...
300 */
301 if (data_size <= 0) return data_size;
302
303 /*
304 * The total never exceeds buffer_len, which is far below
305 * SSIZE_MAX.
306 */
307 if (!fr_cond_assert(fr_add(&total, data_size, written))) return -1;
308
309#if 0
310 /*
311 * If we're not tracking duplicates, then track->packet is NULL.
312 *
313 * There's no reason to fix this now, as all of this will
314 * be rewritten when the bio stuff works. Since this
315 * code doesn't do anything anyways, it's best to just
316 * comment it out.
317 */
318
319 /*
320 * Root through the reply to determine any
321 * connection-level negotiation data, but only the first
322 * time the packet is being written.
323 */
324 if ((written == 0) && (track->packet[0] == FR_RADIUS_CODE_STATUS_SERVER)) {
325// status_check_reply(inst, buffer, buffer_len);
326 }
327#endif
328
329 /*
330 * Add in previously written data to the response.
331 */
332 return total;
333}
334
335
337{
338 proto_radius_tcp_thread_t *thread = talloc_get_type_abort(li->thread_instance, proto_radius_tcp_thread_t);
339
340 thread->connection = connection;
341 return 0;
342}
343
344
345static void mod_network_get(int *ipproto, bool *dynamic_clients, fr_trie_t const **trie, void *instance)
346{
347 proto_radius_tcp_t *inst = talloc_get_type_abort(instance, proto_radius_tcp_t);
348
349 *ipproto = IPPROTO_TCP;
350 *dynamic_clients = inst->dynamic_clients;
351 *trie = inst->trie;
352}
353
354
355/** Open a TCP listener for RADIUS
356 *
357 */
359{
362 proto_radius_tcp_thread_t *thread = talloc_get_type_abort(li->thread_instance, proto_radius_tcp_thread_t);
363
364 int sockfd;
365 fr_ipaddr_t ipaddr = inst->ipaddr;
366 uint16_t port = inst->port;
367
368 fr_assert(!thread->connection);
369
370 li->fd = sockfd = fr_socket_server_tcp(&inst->ipaddr, &port, inst->port_name, true);
371 if (sockfd < 0) {
372 cf_log_err(li->listen->cs, "Failed opening TCP socket - %s", fr_strerror());
373 error:
374 return -1;
375 }
376
377 (void) fr_nonblock(sockfd);
378
379 if (fr_socket_bind(sockfd, inst->interface, &ipaddr, &port) < 0) {
380 close(sockfd);
381 cf_log_err(li->listen->cs, "Failed binding to socket - %s", fr_strerror());
382 cf_log_err(li->listen->cs, DOC_ROOT_REF(troubleshooting/network/bind));
383 goto error;
384 }
385
386 if (listen(sockfd, SOMAXCONN) < 0) {
387 close(sockfd);
388 cf_log_err(li->listen->cs, "Failed listening on socket - %s", fr_syserror(errno));
389 goto error;
390 }
391
392 thread->sockfd = sockfd;
393
394 fr_assert((cf_parent(inst->cs) != NULL) && (cf_parent(cf_parent(inst->cs)) != NULL)); /* listen { ... } */
395 li->app_io_addr = fr_socket_addr_alloc_inet_src(li, IPPROTO_TCP, 0, &ipaddr, port);
396
398 NULL, 0,
399 &ipaddr, port,
400 inst->interface);
401
402 return 0;
403}
404
405
406/** Set the file descriptor for this socket.
407 */
408static int mod_fd_set(fr_listen_instance_t *li, int fd)
409{
411 proto_radius_tcp_thread_t *thread = talloc_get_type_abort(li->thread_instance, proto_radius_tcp_thread_t);
412
413 thread->sockfd = fd;
414
416 &thread->connection->socket.inet.src_ipaddr, thread->connection->socket.inet.src_port,
417 &inst->ipaddr, inst->port,
418 inst->interface);
419
420 return 0;
421}
422
423static int mod_track_compare(UNUSED void const *instance, UNUSED void *thread_instance, UNUSED fr_client_t *client,
424 void const *one, void const *two)
425{
426 int ret;
427 uint8_t const *a = one;
428 uint8_t const *b = two;
429
430 /*
431 * The tree is ordered by IDs, which are (hopefully)
432 * pseudo-randomly distributed.
433 */
434 ret = (a[1] < b[1]) - (a[1] > b[1]);
435 if (ret != 0) return ret;
436
437 /*
438 * Then ordered by code, which is usually the same.
439 */
440 return (a[0] < b[0]) - (a[0] > b[0]);
441}
442
443
444static char const *mod_name(fr_listen_instance_t *li)
445{
446 proto_radius_tcp_thread_t *thread = talloc_get_type_abort(li->thread_instance, proto_radius_tcp_thread_t);
447
448 return thread->name;
449}
450
452{
453 proto_radius_tcp_t *inst = talloc_get_type_abort(data, proto_radius_tcp_t);
454 li->listen->read_hexdump = inst->read_hexdump;
455 li->listen->write_hexdump = inst->write_hexdump;
456}
457
458static int mod_instantiate(module_inst_ctx_t const *mctx)
459{
460 proto_radius_tcp_t *inst = talloc_get_type_abort(mctx->mi->data, proto_radius_tcp_t);
461 CONF_SECTION *conf = mctx->mi->conf;
462 size_t num;
463 CONF_ITEM *ci;
464 CONF_SECTION *server_cs;
465
466 inst->cs = conf;
467
468 /*
469 * Complain if no "ipaddr" is set.
470 */
471 if (inst->ipaddr.af == AF_UNSPEC) {
472 cf_log_err(conf, "No 'ipaddr' was specified in the 'tcp' section");
473 return -1;
474 }
475
476 if (inst->recv_buff_is_set) {
477 FR_INTEGER_BOUND_CHECK("recv_buff", inst->recv_buff, >=, 32);
478 FR_INTEGER_BOUND_CHECK("recv_buff", inst->recv_buff, <=, INT_MAX);
479 }
480
481 FR_INTEGER_BOUND_CHECK("max_packet_size", inst->max_packet_size, >=, 20);
482 FR_INTEGER_BOUND_CHECK("max_packet_size", inst->max_packet_size, <=, 65536);
483
484 if (!inst->port) {
485 struct servent *s;
486
487 if (!inst->port_name) {
488 cf_log_err(conf, "No 'port' was specified in the 'tcp' section");
489 return -1;
490 }
491
492 s = getservbyname(inst->port_name, "tcp");
493 if (!s) {
494 cf_log_err(conf, "Unknown value for 'port_name = %s'", inst->port_name);
495 return -1;
496 }
497
498 inst->port = ntohs(s->s_port);
499 }
500
501 /*
502 * Parse and create the trie for dynamic clients, even if
503 * there's no dynamic clients.
504 *
505 * @todo - we could use this for source IP filtering?
506 * e.g. allow clients from a /16, but not from a /24
507 * within that /16.
508 */
509 num = talloc_array_length(inst->allow);
510 if (!num) {
511 if (inst->dynamic_clients) {
512 cf_log_err(conf, "The 'allow' subsection MUST contain at least one 'network' entry when 'dynamic_clients = true'.");
513 return -1;
514 }
515 } else {
516 inst->trie = fr_master_io_network(inst, inst->ipaddr.af, inst->allow, inst->deny);
517 if (!inst->trie) {
518 cf_log_perr(conf, "Failed creating list of networks");
519 return -1;
520 }
521 }
522
523 ci = cf_section_to_item(mctx->mi->parent->conf); /* listen { ... } */
524 fr_assert(ci != NULL);
525 ci = cf_parent(ci);
526 fr_assert(ci != NULL);
527
528 server_cs = cf_item_to_section(ci);
529
530 /*
531 * Look up local clients, if they exist.
532 */
533 if (cf_section_find_next(server_cs, NULL, "client", CF_IDENT_ANY)) {
534 inst->clients = client_list_parse_section(server_cs, IPPROTO_TCP, false);
535 if (!inst->clients) {
536 cf_log_err(conf, "Failed creating local clients");
537 return -1;
538 }
539 }
540
541 return 0;
542}
543
545{
548
549 /*
550 * Prefer local clients.
551 */
552 if (inst->clients) {
553 fr_client_t *client;
554
555 client = client_find(inst->clients, ipaddr, ipproto);
556 if (client) return client;
557 }
558
559 return client_find(NULL, ipaddr, ipproto);
560}
561
563 .common = {
564 .magic = MODULE_MAGIC_INIT,
565 .name = "radius_tcp",
567 .inst_size = sizeof(proto_radius_tcp_t),
568 .thread_inst_size = sizeof(proto_radius_tcp_thread_t),
569 .instantiate = mod_instantiate,
570 },
571 .default_message_size = 4096,
572
573 .open = mod_open,
574 .read = mod_read,
575 .write = mod_write,
576 .fd_set = mod_fd_set,
577 .track_compare = mod_track_compare,
578 .connection_set = mod_connection_set,
579 .network_get = mod_network_get,
580 .client_find = mod_client_find,
581 .get_name = mod_name,
582 .hexdump_set = mod_hexdump_set,
583};
static int const char char buffer[256]
Definition acutest.h:641
char const * fr_app_io_socket_name(TALLOC_CTX *ctx, fr_app_io_t const *app_io, fr_ipaddr_t const *src_ipaddr, uint16_t src_port, fr_ipaddr_t const *dst_ipaddr, uint16_t dst_port, char const *interface)
Definition app_io.c:32
module_t common
Common fields to all loadable modules.
Definition app_io.h:34
Public structure describing an I/O path for a protocol.
Definition app_io.h:33
static int packet_ctx
the tests pass only the address of packet_ctx
#define STRINGIFY(x)
Definition build.h:233
#define UNUSED
Definition build.h:415
#define CONF_PARSER_TERMINATOR
Definition cf_parse.h:722
#define FR_INTEGER_BOUND_CHECK(_name, _var, _op, _bound)
Definition cf_parse.h:572
#define FR_CONF_OFFSET(_name, _struct, _field)
conf_parser_t which parses a single CONF_PAIR, writing the result to a field in a struct
Definition cf_parse.h:280
@ CONF_FLAG_MULTI
CONF_PAIR can have multiple copies.
Definition cf_parse.h:483
@ CONF_FLAG_SUBSECTION
Instead of putting the information into a configuration structure, the configuration file routines MA...
Definition cf_parse.h:460
#define FR_CONF_POINTER(_name, _type, _flags, _res_p)
conf_parser_t which parses a single CONF_PAIR producing a single global result
Definition cf_parse.h:350
#define FR_CONF_OFFSET_IS_SET(_name, _type, _flags, _struct, _field)
conf_parser_t which parses a single CONF_PAIR, writing the result to a field in a struct,...
Definition cf_parse.h:294
#define FR_CONF_OFFSET_TYPE_FLAGS(_name, _type, _flags, _struct, _field)
conf_parser_t which parses a single CONF_PAIR, writing the result to a field in a struct
Definition cf_parse.h:238
Defines a CONF_PAIR to C data type mapping.
Definition cf_parse.h:649
Common header for all CONF_* types.
Definition cf_priv.h:54
A section grouping multiple CONF_PAIR.
Definition cf_priv.h:106
CONF_ITEM * cf_section_to_item(CONF_SECTION const *cs)
Cast a CONF_SECTION to a CONF_ITEM.
Definition cf_util.c:725
CONF_SECTION * cf_item_to_section(CONF_ITEM const *ci)
Cast a CONF_ITEM to a CONF_SECTION.
Definition cf_util.c:671
CONF_SECTION * cf_section_find_next(CONF_SECTION const *cs, CONF_SECTION const *prev, char const *name1, char const *name2)
Return the next matching section.
Definition cf_util.c:1268
#define cf_log_err(_cf, _fmt,...)
Definition cf_util.h:340
#define cf_parent(_cf)
Definition cf_util.h:115
#define cf_log_perr(_cf, _fmt,...)
Definition cf_util.h:347
#define CF_IDENT_ANY
Definition cf_util.h:80
#define fr_cond_assert(_x)
Calls panic_action ifndef NDEBUG, else logs error and evaluates to value of _x.
Definition debug.h:177
@ FR_RADIUS_CODE_MAX
Maximum possible protocol code.
Definition defs.h:53
@ FR_RADIUS_CODE_STATUS_SERVER
RFC2865/RFC5997 - Status Server (request)
Definition defs.h:44
static int sockfd
Definition dhcpclient.c:55
#define MODULE_MAGIC_INIT
Stop people using different module/library/server versions together.
Definition dl_module.h:63
IPv4/6 prefix.
fr_socket_t socket
src/dst ip and port.
Definition base.h:342
Describes a host allowed to send packets to the server.
Definition client.h:80
uint64_t total_responses
Definition stats.h:38
uint64_t total_unknown_types
Definition stats.h:46
uint64_t total_requests
Definition stats.h:35
uint64_t total_malformed_requests
Definition stats.h:42
#define fr_time()
Definition event.c:58
fr_listen_t * listen
the listener this is a socket of.
Definition listen.h:65
int fd
file descriptor for this socket - set by open
Definition listen.h:67
bool write_hexdump
Do we debug hexdump packets as they're written.
Definition listen.h:51
void const * app_io_instance
I/O path configuration context.
Definition listen.h:34
CONF_SECTION * cs
of this listener
Definition listen.h:39
fr_socket_t * app_io_addr
for tracking duplicate sockets
Definition listen.h:71
void * thread_instance
thread / socket context
Definition listen.h:69
bool read_hexdump
Do we debug hexdump packets as they're read.
Definition listen.h:50
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:3221
uint8_t * packet
really a tracking structure, not a packet
Definition master.h:57
size_t reply_len
length of reply, or 1 for "do not reply"
Definition master.h:48
#define fr_add(_out, _a, _b)
Adds two integers.
Definition math.h:190
bool fr_radius_ok(uint8_t const *packet, size_t *packet_len_p, uint32_t max_attributes, bool require_message_authenticator, decode_fail_t *reason)
unsigned short uint16_t
@ FR_TYPE_IPV4_ADDR
32 Bit IPv4 Address.
@ FR_TYPE_COMBO_IP_PREFIX
IPv4 or IPv6 address prefix depending on length.
@ FR_TYPE_UINT32
32 Bit unsigned integer.
@ FR_TYPE_IPV6_ADDR
128 Bit IPv6 Address.
@ FR_TYPE_COMBO_IP_ADDR
IPv4 or IPv6 address depending on length.
unsigned int uint32_t
long int ssize_t
unsigned char uint8_t
int fr_nonblock(UNUSED int fd)
Definition misc.c:293
module_instance_t * mi
Instance of the module being instantiated.
Definition module_ctx.h:51
Temporary structure to hold arguments for instantiation calls.
Definition module_ctx.h:50
static uint16_t fr_nbo_to_uint16(uint8_t const data[static sizeof(uint16_t)])
Read an unsigned 16bit integer from wire format (big endian)
Definition nbo.h:146
#define RADIUS_HEADER_LENGTH
Definition net.h:80
void proto_radius_log(fr_listen_instance_t const *li, fr_radius_decode_fail_t reason, fr_socket_t const *sock, char const *fmt,...)
Log a message in a canonical format.
fr_stats_t stats
statistics for this socket
char const * name
socket name
fr_io_address_t * connection
for connected sockets.
fr_app_io_t proto_radius_tcp
static fr_client_t * mod_client_find(fr_listen_instance_t *li, fr_ipaddr_t const *ipaddr, int ipproto)
fr_client_list_t * clients
local clients
char const * interface
Interface to bind to.
fr_ipaddr_t * allow
allowed networks for dynamic clients
static void mod_hexdump_set(fr_listen_instance_t *li, void *data)
uint16_t port
Port to listen on.
fr_trie_t * trie
for parsed networks
static int mod_open(fr_listen_instance_t *li)
Open a TCP listener for RADIUS.
bool write_hexdump
Do we debug hexdump write packets.
bool dynamic_clients
whether we have dynamic clients
static void mod_network_get(int *ipproto, bool *dynamic_clients, fr_trie_t const **trie, void *instance)
uint32_t max_packet_size
for message ring buffer.
fr_ipaddr_t * deny
denied networks for dynamic clients
static const conf_parser_t networks_config[]
static int mod_fd_set(fr_listen_instance_t *li, int fd)
Set the file descriptor for this socket.
static char const * mod_name(fr_listen_instance_t *li)
char const * port_name
Name of the port for getservent().
fr_ipaddr_t ipaddr
IP address to listen on.
static int mod_connection_set(fr_listen_instance_t *li, fr_io_address_t *connection)
static int mod_track_compare(UNUSED void const *instance, UNUSED void *thread_instance, UNUSED fr_client_t *client, void const *one, void const *two)
static ssize_t mod_write(fr_listen_instance_t *li, void *packet_ctx, UNUSED fr_time_t request_time, uint8_t *buffer, size_t buffer_len, size_t written)
static ssize_t mod_read(fr_listen_instance_t *li, UNUSED void **packet_ctx, fr_time_t *recv_time_p, uint8_t *buffer, size_t buffer_len, size_t *leftover)
uint32_t max_attributes
Limit maximum decodable attributes.
uint32_t recv_buff
How big the kernel's receive buffer should be.
bool recv_buff_is_set
Whether we were provided with a recv_buff.
CONF_SECTION * cs
our configuration
static int mod_instantiate(module_inst_ctx_t const *mctx)
static const conf_parser_t tcp_listen_config[]
bool read_hexdump
Do we debug hexdump read packets.
char const * fr_radius_packet_name[FR_RADIUS_CODE_MAX]
Definition base.c:115
#define fr_assert(_expr)
Definition rad_assert.h:37
#define DEBUG2(fmt,...)
static int ipproto
Definition radclient.c:91
fr_radius_decode_fail_t
Failure reasons.
Definition radius.h:89
@ FR_RADIUS_FAIL_IO_ERROR
Definition radius.h:115
@ FR_RADIUS_FAIL_MAX_LENGTH_PACKET
Definition radius.h:92
@ FR_RADIUS_FAIL_UNKNOWN_PACKET_CODE
Definition radius.h:95
@ FR_RADIUS_FAIL_MIN_LENGTH_PACKET
Definition radius.h:91
#define RADIUS_MAX_ATTRIBUTES
Definition radius.h:39
static rs_t * conf
Definition radsniff.c:52
CONF_SECTION * conf
Module's instance configuration.
Definition module.h:355
void * data
Module's instance data.
Definition module.h:297
module_instance_t const * parent
Parent module's instance (if any).
Definition module.h:363
conf_parser_t const * config
How to convert a CONF_SECTION to a module instance.
Definition module.h:207
int fr_socket_server_tcp(fr_ipaddr_t const *src_ipaddr, uint16_t *src_port, char const *port_name, bool async)
Open an IPv4/IPv6 TCP socket.
Definition socket.c:943
int fr_socket_bind(int sockfd, char const *ifname, fr_ipaddr_t *src_ipaddr, uint16_t *src_port)
Bind a UDP/TCP v4/v6 socket to a given ipaddr src port, and interface.
Definition socket.c:200
fr_client_t * client_find(fr_client_list_t const *clients, fr_ipaddr_t const *ipaddr, int proto)
Definition client.c:370
fr_client_list_t * client_list_parse_section(CONF_SECTION *section, int proto, TLS_UNUSED bool tls_required)
Definition client.c:475
Group of clients.
Definition client.c:50
eap_aka_sim_process_conf_t * inst
char const * fr_syserror(int num)
Guaranteed to be thread-safe version of strerror.
Definition syserror.c:243
#define talloc_get_type_abort_const
Definition talloc.h:117
"server local" time.
Definition time.h:69
static fr_socket_t * fr_socket_addr_alloc_inet_src(TALLOC_CTX *ctx, int proto, int ifindex, fr_ipaddr_t const *ipaddr, int port)
A variant of fr_socket_addr_init_inet_src will also allocates a fr_socket_t.
Definition socket.h:249
char const * fr_strerror(void)
Get the last library error.
Definition strerror.c:558
#define DOC_ROOT_REF(_x)
Definition version.h:90
static fr_slen_t data
Definition value.h:1366