The FreeRADIUS server $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Loading...
Searching...
No Matches
rlm_tacacs_tcp.c
Go to the documentation of this file.
1/*
2 * This program is 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 (at
5 * 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: 1cb71d4fc00e1cbe0b7ba79cc97061607b346d42 $
19 * @file rlm_tacacs_tcp.c
20 * @brief TACACS+ transport
21 *
22 * @copyright 2023 Network RADIUS SAS (legal@networkradius.com)
23 */
24RCSID("$Id: 1cb71d4fc00e1cbe0b7ba79cc97061607b346d42 $")
25
26#include <freeradius-devel/io/application.h>
27#include <freeradius-devel/io/listen.h>
28#include <freeradius-devel/io/pair.h>
29#include <freeradius-devel/missing.h>
30#include <freeradius-devel/server/connection.h>
31#include <freeradius-devel/util/debug.h>
32#include <freeradius-devel/util/heap.h>
33#include <freeradius-devel/util/udp.h>
34
35#include <sys/socket.h>
36#include <sys/uio.h>
37
38#include "rlm_tacacs.h"
39
40/** Static configuration for the module.
41 *
42 */
43typedef struct {
44 rlm_tacacs_t *parent; //!< rlm_tacacs instance.
46
47 fr_ipaddr_t dst_ipaddr; //!< IP of the home server.
48 fr_ipaddr_t src_ipaddr; //!< IP we open our socket on.
49 uint16_t dst_port; //!< Port of the home server.
50 char const *secret; //!< Shared secret.
51 size_t secretlen; //!< length of secret
52
53 char const *interface; //!< Interface to bind to.
54
55 uint32_t recv_buff; //!< How big the kernel's receive buffer should be.
56 uint32_t send_buff; //!< How big the kernel's send buffer should be.
57
58 uint32_t max_packet_size; //!< Maximum packet size.
59 uint16_t max_send_coalesce; //!< Maximum number of packets to coalesce into one mmsg call.
60
61 bool recv_buff_is_set; //!< Whether we were provided with a recv_buf
62 bool send_buff_is_set; //!< Whether we were provided with a send_buf
64
65typedef struct {
66 fr_event_list_t *el; //!< Event list.
67
68 rlm_tacacs_tcp_t const *inst; //!< our instance
69
70 trunk_conf_t trunk_conf; //!< trunk configuration
71 trunk_t *trunk; //!< trunk handler
73
74typedef struct {
76 rlm_rcode_t rcode; //!< from the transport
78
80
81typedef struct {
82 uint8_t *read; //!< where we read data from
83 uint8_t *write; //!< where we write data to
84 uint8_t *end; //!< end of the buffer
85 uint8_t *data; //!< actual data
87
88/** Track the handle, which is tightly correlated with the FD
89 *
90 */
91typedef struct {
92 char const *name; //!< From IP PORT to IP PORT.
93 char const *module_name; //!< the module that opened the connection
94
95 int fd; //!< File descriptor.
96
97 trunk_request_t **coalesced; //!< Outbound coalesced requests.
98
99 size_t send_buff_actual; //!< What we believe the maximum SO_SNDBUF size to be.
100 ///< We don't try and encode more packet data than this
101 ///< in one go.
102
103 rlm_tacacs_tcp_t const *inst; //!< Our module instance.
105
106 uint32_t session_id; //!< for TACACS+ "security".
107
108 uint32_t max_packet_size; //!< Our max packet size. may be different from the parent.
109
110 fr_ipaddr_t src_ipaddr; //!< Source IP address. May be altered on bind
111 //!< to be the actual IP address packets will be
112 //!< sent on. This is why we can't use the inst
113 //!< src_ipaddr field.
114 uint16_t src_port; //!< Source port specific to this connection.
115 //!< @todo - not set by socket_client_tcp()
116
117 tcp_buffer_t recv; //!< receive buffer
118 tcp_buffer_t send; //!< send buffer
119
120 int id; //!< starts at 1.
121 int active; //!< active packets
122 trunk_request_t *tracking[UINT8_MAX]; //!< all sequential!
123
124 fr_time_t mrs_time; //!< Most recent sent time which had a reply.
125 fr_time_t last_reply; //!< When we last received a reply.
126 fr_time_t first_sent; //!< first time we sent a packet since going idle
127 fr_time_t last_sent; //!< last time we sent a packet.
128 fr_time_t last_idle; //!< last time we had nothing to do
129
130 fr_timer_t *zombie_ev; //!< Zombie timeout.
131
132 trunk_connection_t *tconn; //!< trunk connection
134
135
136/** Connect request_t to local tracking structure
137 *
138 */
140 uint32_t priority; //!< copied from request->async->priority
141 fr_time_t recv_time; //!< copied from request->async->recv_time
142
143 uint8_t code; //!< Packet code.
144 uint8_t id; //!< Last ID assigned to this packet.
145 bool outstanding; //!< are we waiting for a reply?
146
147 uint8_t *packet; //!< Packet we write to the network.
148 size_t packet_len; //!< Length of the packet.
149
150 fr_timer_t *ev; //!< timer for retransmissions
151 fr_retry_t retry; //!< retransmission timers
152};
153
154static const conf_parser_t module_config[] = {
156 { FR_CONF_OFFSET_TYPE_FLAGS("ipv4addr", FR_TYPE_IPV4_ADDR, 0, rlm_tacacs_tcp_t, dst_ipaddr) },
157 { FR_CONF_OFFSET_TYPE_FLAGS("ipv6addr", FR_TYPE_IPV6_ADDR, 0, rlm_tacacs_tcp_t, dst_ipaddr) },
158
159 { FR_CONF_OFFSET("port", rlm_tacacs_tcp_t, dst_port) },
160
161 { FR_CONF_OFFSET("secret", rlm_tacacs_tcp_t, secret) }, /* can be NULL */
162
163 { FR_CONF_OFFSET("interface", rlm_tacacs_tcp_t, interface) },
164
165 { FR_CONF_OFFSET_IS_SET("recv_buff", FR_TYPE_UINT32, 0, rlm_tacacs_tcp_t, recv_buff) },
166 { FR_CONF_OFFSET_IS_SET("send_buff", FR_TYPE_UINT32, 0, rlm_tacacs_tcp_t, send_buff) },
167
168 { FR_CONF_OFFSET("max_packet_size", rlm_tacacs_tcp_t, max_packet_size), .dflt = STRINGIFY(FR_MAX_PACKET_SIZE) },
169 { FR_CONF_OFFSET("max_send_coalesce", rlm_tacacs_tcp_t, max_send_coalesce), .dflt = "1024" },
170
171 { FR_CONF_OFFSET_TYPE_FLAGS("src_ipaddr", FR_TYPE_COMBO_IP_ADDR, 0, rlm_tacacs_tcp_t, src_ipaddr) },
172 { FR_CONF_OFFSET_TYPE_FLAGS("src_ipv4addr", FR_TYPE_IPV4_ADDR, 0, rlm_tacacs_tcp_t, src_ipaddr) },
173 { FR_CONF_OFFSET_TYPE_FLAGS("src_ipv6addr", FR_TYPE_IPV6_ADDR, 0, rlm_tacacs_tcp_t, src_ipaddr) },
174
176};
177
178static fr_dict_t const *dict_tacacs;
179
182 { .out = &dict_tacacs, .proto = "tacacs" },
183 { NULL }
184};
185
189
192 { .out = &attr_packet_type, .name = "Packet-Type", .type = FR_TYPE_UINT32, .dict = &dict_tacacs },
193 { .out = &attr_packet_hdr, .name = "Packet", .type = FR_TYPE_STRUCT, .dict = &dict_tacacs },
194 { .out = &attr_session_id, .name = "Packet.Session-ID", .type = FR_TYPE_UINT32, .dict = &dict_tacacs },
195 { NULL }
196};
197
198/** Clear out any connection specific resources from a udp request
199 *
200 */
202{
203 u->packet = NULL;
204
205 fr_assert(h->active > 0);
206 fr_assert(h->tracking[u->id] != NULL);
207 fr_assert(h->tracking[u->id]->preq == u);
208
209 h->tracking[u->id] = NULL;
210 u->outstanding = false;
211 h->active--;
212
214
215 /*
216 * We've sent 255 packets, and received all replies. Shut the connection down.
217 *
218 * Welcome to the insanity that is TACACS+.
219 */
220 if ((h->active == 0) && (h->id > 255)) {
222 }
223}
224
225
226/** Free a connection handle, closing associated resources
227 *
228 */
230{
231 fr_assert(h->fd >= 0);
232
234
235 if (shutdown(h->fd, SHUT_RDWR) < 0) {
236 DEBUG3("%s - Failed shutting down connection %s: %s",
237 h->module_name, h->name, fr_syserror(errno));
238 }
239
240 if (close(h->fd) < 0) {
241 DEBUG3("%s - Failed closing connection %s: %s",
242 h->module_name, h->name, fr_syserror(errno));
243 }
244
245 h->fd = -1;
246
247 DEBUG("%s - Connection closed - %s", h->module_name, h->name);
248
249 return 0;
250}
251
252/** Initialise a new outbound connection
253 *
254 * @param[out] h_out Where to write the new file descriptor.
255 * @param[in] conn to initialise.
256 * @param[in] uctx A #udp_thread_t
257 */
258static connection_state_t conn_init(void **h_out, connection_t *conn, void *uctx)
259{
260 int fd;
261 udp_handle_t *h;
262 udp_thread_t *thread = talloc_get_type_abort(uctx, udp_thread_t);
263
264 MEM(h = talloc_zero(conn, udp_handle_t));
265 h->thread = thread;
266 h->inst = thread->inst;
267 h->module_name = h->inst->parent->name;
268 h->src_ipaddr = h->inst->src_ipaddr;
269 h->src_port = 0;
271 h->last_idle = fr_time();
272
273 h->id = 1; /* clients send odd sequence numbers */
274 h->session_id = fr_rand();
275
276 /*
277 * Initialize the buffer of coalesced packets we're doing to write.
278 */
279 h->coalesced = talloc_zero_array(h, trunk_request_t *, h->inst->max_send_coalesce);
280
281 /*
282 * Open the outgoing socket.
283 */
284 fd = fr_socket_client_tcp(NULL, &h->src_ipaddr, &h->inst->dst_ipaddr, h->inst->dst_port, true);
285 if (fd < 0) {
286 PERROR("%s - Failed opening socket", h->module_name);
287 talloc_free(h);
289 }
290
291 /*
292 * Set the connection name.
293 */
294 h->name = fr_asprintf(h, "proto tcp local %pV port %u remote %pV port %u",
297
298 talloc_set_destructor(h, _udp_handle_free);
299
300#ifdef SO_RCVBUF
301 if (h->inst->recv_buff_is_set) {
302 int opt;
303
304 opt = h->inst->recv_buff;
305 if (setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &opt, sizeof(int)) < 0) {
306 WARN("%s - Failed setting 'SO_RCVBUF': %s", h->module_name, fr_syserror(errno));
307 }
308 }
309#endif
310
311#ifdef SO_SNDBUF
312 {
313 int opt;
314 socklen_t socklen = sizeof(int);
315
316 if (h->inst->send_buff_is_set) {
317 opt = h->inst->send_buff;
318 if (setsockopt(fd, SOL_SOCKET, SO_SNDBUF, &opt, sizeof(int)) < 0) {
319 WARN("%s - Failed setting 'SO_SNDBUF', write performance may be sub-optimal: %s",
320 h->module_name, fr_syserror(errno));
321 }
322 }
323
324 if (getsockopt(fd, SOL_SOCKET, SO_SNDBUF, &opt, &socklen) < 0) {
325 WARN("%s - Failed getting 'SO_SNDBUF', write performance may be sub-optimal: %s",
326 h->module_name, fr_syserror(errno));
327
328 /*
329 * This controls how many packets we attempt
330 * to send at once. Nothing bad happens if
331 * we get it wrong, but the user may see
332 * ENOBUFS errors at high packet rates.
333 *
334 * Since this is TACACS, we have small
335 * packets and a maximum of 255 packets
336 * per connection. So don't set this too large.
337 */
338 if (h->inst->send_buff_is_set) {
340 } else {
342 if (h->send_buff_actual > 256*1024) h->send_buff_actual = 256*1024;
343 }
344
345 WARN("%s - Max coalesced outbound data will be %zu bytes", h->module_name,
347 } else {
348#ifdef __linux__
349 /*
350 * Linux doubles the buffer when you set it
351 * to account for "overhead".
352 */
353 h->send_buff_actual = ((size_t)opt) / 2;
354#else
355 h->send_buff_actual = (size_t)opt;
356#endif
357 }
358 }
359#else
361 h->inst_send_buff : h->max_packet_size * h->inst->max_send_coalesce;
362
363 WARN("%s - Modifying 'SO_SNDBUF' value is not supported on this system, "
364 "write performance may be sub-optimal", h->module_name);
365 WARN("%s - Max coalesced outbound data will be %zu bytes", h->module_name, h->inst->send_buff_actual);
366#endif
367
368 /*
369 * Allow receiving of 2 max-sized packets. In practice, most packets will be less than this.
370 */
371 MEM(h->recv.data = talloc_array(h, uint8_t, h->max_packet_size * 2));
372 h->recv.read = h->recv.write = h->recv.data;
373 h->recv.end = h->recv.data + h->max_packet_size * 2;
374
375 /*
376 * Use the system SO_SNDBUF for how many packets to send at once. In most circumstances the
377 * packets are small, and widely separated in time, and we really only need a very small buffer.
378 */
379 MEM(h->send.data = talloc_array(h, uint8_t, h->send_buff_actual));
380 h->send.read = h->send.write = h->send.data;
381 h->send.end = h->send.data + h->send_buff_actual;
382
383 h->fd = fd;
384
385 /*
386 * Signal the connection
387 * as open as soon as it becomes writable.
388 */
389 connection_signal_on_fd(conn, fd);
390
391 *h_out = h;
392
393 // @todo - initialize the tracking memory, etc.
394 // i.e. histograms (or hyperloglog) of packets, so we can see
395 // which connections / home servers are fast / slow.
396
398}
399
400/** Shutdown/close a file descriptor
401 *
402 */
403static void conn_close(UNUSED fr_event_list_t *el, void *handle, UNUSED void *uctx)
404{
405 udp_handle_t *h = talloc_get_type_abort(handle, udp_handle_t);
406
407 /*
408 * There's tracking entries still allocated
409 * this is bad, they should have all been
410 * released.
411 */
412 fr_assert(!h->active);
413
414 DEBUG4("Freeing rlm_tacacs_tcp handle %p", handle);
415
416 talloc_free(h);
417}
418
419CC_NO_UBSAN(function) /* UBSAN: false positive - public vs private connection_t trips --fsanitize=function*/
421 connection_conf_t const *conf,
422 char const *log_prefix, void *uctx)
423{
424 connection_t *conn;
425 udp_thread_t *thread = talloc_get_type_abort(uctx, udp_thread_t);
426
427 conn = connection_alloc(tconn, el,
429 .init = conn_init,
430 .close = conn_close,
431 },
432 conf,
433 log_prefix,
434 thread);
435 if (!conn) {
436 PERROR("%s - Failed allocating state handler for new connection", thread->inst->parent->name);
437 return NULL;
438 }
439
440 return conn;
441}
442
443/** Connection errored
444 *
445 * We were signalled by the event loop that a fatal error occurred on this connection.
446 *
447 * @param[in] el The event list signalling.
448 * @param[in] fd that errored.
449 * @param[in] flags El flags.
450 * @param[in] fd_errno The nature of the error.
451 * @param[in] uctx The trunk connection handle (tconn).
452 */
453static void conn_error(UNUSED fr_event_list_t *el, UNUSED int fd, UNUSED int flags, int fd_errno, void *uctx)
454{
455 trunk_connection_t *tconn = talloc_get_type_abort(uctx, trunk_connection_t);
456 connection_t *conn = tconn->conn;
457 udp_handle_t *h = talloc_get_type_abort(conn->h, udp_handle_t);
458
459 ERROR("%s - Connection %s failed: %s", h->module_name, h->name, fr_syserror(fd_errno));
460
462}
463
464CC_NO_UBSAN(function) /* UBSAN: false positive - public vs private connection_t trips --fsanitize=function*/
467 trunk_connection_event_t notify_on, UNUSED void *uctx)
468{
469 udp_handle_t *h = talloc_get_type_abort(conn->h, udp_handle_t);
470 fr_event_fd_cb_t read_fn = NULL;
471 fr_event_fd_cb_t write_fn = NULL;
472
473 switch (notify_on) {
475 return;
476
479 break;
480
483 break;
484
488 break;
489
490 }
491
492 if (fr_event_fd_insert(h, NULL, el, h->fd,
493 read_fn,
494 write_fn,
496 tconn) < 0) {
497 PERROR("%s - Failed inserting FD event", h->module_name);
498
499 /*
500 * May free the connection!
501 */
503 }
504}
505
506/*
507 * Return negative numbers to put 'a' at the top of the heap.
508 * Return positive numbers to put 'b' at the top of the heap.
509 *
510 * We want the value with the lowest timestamp to be prioritized at
511 * the top of the heap.
512 */
513static int8_t request_prioritise(void const *one, void const *two)
514{
515 udp_request_t const *a = one;
516 udp_request_t const *b = two;
517 int8_t ret;
518
519 /*
520 * Larger priority is more important.
521 */
522 ret = CMP(a->priority, b->priority);
523 if (ret != 0) return ret;
524
525 /*
526 * Smaller timestamp (i.e. earlier) is more important.
527 */
529}
530
531/** Decode response packet data, extracting relevant information and validating the packet
532 *
533 * @param[in] ctx to allocate pairs in.
534 * @param[out] reply Pointer to head of pair list to add reply attributes to.
535 * @param[out] response_code The type of response packet.
536 * @param[in] h connection handle.
537 * @param[in] request the request.
538 * @param[in] u UDP request.
539 * @param[in] data to decode.
540 * @param[in] data_len Length of input data.
541 * @return
542 * - <0 on error
543 * - >0 for how many bytes were decoded
544 */
545static ssize_t decode(TALLOC_CTX *ctx, fr_pair_list_t *reply, uint8_t *response_code,
546 udp_handle_t *h, request_t *request, udp_request_t *u,
547 uint8_t *data, size_t data_len)
548{
549 rlm_tacacs_tcp_t const *inst = h->thread->inst;
550 ssize_t packet_len;
551 int code;
552
553 *response_code = 0; /* Initialise to keep the rest of the code happy */
554
555 /*
556 * Check the session ID here, because we've lost the original packet.
557 */
558 if (h->session_id != fr_nbo_to_uint32(data + 4)) {
559 REDEBUG("Session ID %08x does not match expected number %08x",
561 }
562
563 /*
564 * Decode the attributes, in the context of the reply.
565 * This only fails if the packet is strangely malformed,
566 * or if we run out of memory.
567 */
568 packet_len = fr_tacacs_decode(ctx, reply, NULL, data, data_len, NULL, inst->secret, inst->secretlen, &code);
569 if (packet_len < 0) {
570 RPEDEBUG("Failed decoding TACACS+ reply packet");
571 fr_pair_list_free(reply);
572 return -1;
573 }
574
575 RDEBUG("Received %s ID %d length %ld reply packet on connection %s",
576 fr_tacacs_packet_names[code], code, packet_len, h->name);
577 log_request_pair_list(L_DBG_LVL_2, request, NULL, reply, NULL);
578
579 *response_code = code;
580
581 /*
582 * Fixup retry times
583 */
584 if (fr_time_gt(u->retry.start, h->mrs_time)) h->mrs_time = u->retry.start;
585
586 return packet_len;
587}
588
589static int encode(udp_handle_t *h, request_t *request, udp_request_t *u)
590{
591 ssize_t packet_len;
592 rlm_tacacs_tcp_t const *inst = h->inst;
593 fr_pair_t *hdr, *vp;
594
595 fr_assert(inst->parent->allowed[u->code]);
596 fr_assert(!u->packet);
598
599 /*
600 * Encode the packet in the outbound buffer.
601 */
602 u->packet = h->send.write;
603
604 /*
605 * Set the session ID, if it hasn't already been set.
606 */
607 hdr = fr_pair_find_by_da(&request->request_pairs, NULL, attr_packet_hdr);
608 if (!hdr) hdr = request->request_ctx;
609
610 vp = fr_pair_find_by_da_nested(&hdr->vp_group, NULL, attr_session_id);
611 if (!vp) {
613
614 vp->vp_uint32 = h->session_id;
615 fr_pair_append(&hdr->vp_group, vp);
617 }
618
619 /*
620 * Encode the packet.
621 */
622 packet_len = fr_tacacs_encode(&FR_DBUFF_TMP(u->packet, (size_t) inst->max_packet_size), NULL,
623 inst->secret, inst->secretlen, request->reply->code, &request->request_pairs);
624 if (packet_len < 0) {
625 RPERROR("Failed encoding packet");
626 return -1;
627 }
628
629 /*
630 * Update the ID and the actual packet length;
631 */
632 u->packet[1] = u->id;
633 u->packet_len = packet_len;
634 u->outstanding = true;
635
636// fr_tacacs_packet_log_hex(&default_log, u->packet);
637
638 return 0;
639}
640
641
642/** Revive a connection after "revive_interval"
643 *
644 */
645static void revive_timeout(UNUSED fr_timer_list_t *tl, UNUSED fr_time_t now, void *uctx)
646{
647 trunk_connection_t *tconn = talloc_get_type_abort(uctx, trunk_connection_t);
648 udp_handle_t *h = talloc_get_type_abort(tconn->conn->h, udp_handle_t);
649
650 INFO("%s - Reviving connection %s", h->module_name, h->name);
652}
653
654/** Mark a connection dead after "zombie_interval"
655 *
656 */
657static void zombie_timeout(fr_timer_list_t *tl, fr_time_t now, void *uctx)
658{
659 trunk_connection_t *tconn = talloc_get_type_abort(uctx, trunk_connection_t);
660 udp_handle_t *h = talloc_get_type_abort(tconn->conn->h, udp_handle_t);
661
662 INFO("%s - No replies during 'zombie_period', marking connection %s as dead", h->module_name, h->name);
663
664 /*
665 * Don't use this connection, and re-queue all of its
666 * requests onto other connections.
667 */
670
671 /*
672 * Revive the connection after a time.
673 */
674 if (fr_timer_at(h, tl, &h->zombie_ev,
675 fr_time_add(now, h->inst->parent->revive_interval), false, revive_timeout, h) < 0) {
676 ERROR("Failed inserting revive timeout for connection");
678 }
679}
680
681
682/** See if the connection is zombied.
683 *
684 * We check for zombie when major events happen:
685 *
686 * 1) request hits its final timeout
687 * 2) request timer hits, and it needs to be retransmitted
688 * 3) a DUP packet comes in, and the request needs to be retransmitted
689 * 4) we're sending a packet.
690 *
691 * There MIGHT not be retries configured, so we MUST check for zombie
692 * when any new packet comes in. Similarly, there MIGHT not be new
693 * packets, but retries are configured, so we have to check there,
694 * too.
695 *
696 * Also, the socket might not be writable for a while. There MIGHT
697 * be a long time between getting the timer / DUP signal, and the
698 * request finally being written to the socket. So we need to check
699 * for zombie at BOTH the timeout and the mux / write function.
700 *
701 * @return
702 * - true if the connection is zombie.
703 * - false if the connection is not zombie.
704 */
706{
707 udp_handle_t *h = talloc_get_type_abort(tconn->conn->h, udp_handle_t);
708
709 /*
710 * If we're already zombie, don't go to zombie
711 *
712 */
713 if (h->zombie_ev) return true;
714
715 if (fr_time_eq(now, fr_time_wrap(0))) now = fr_time();
716
717 /*
718 * We received a reply since this packet was sent, the connection isn't zombie.
719 */
720 if (fr_time_gteq(h->last_reply, last_sent)) return false;
721
722 /*
723 * If we've seen ANY response in the allowed window, then the connection is still alive.
724 */
725 if (fr_time_gt(last_sent, fr_time_wrap(0)) &&
726 (fr_time_lt(fr_time_add(last_sent, h->inst->parent->response_window), now))) return false;
727
728 /*
729 * Mark the connection as inactive, but keep sending
730 * packets on it.
731 */
732 WARN("%s - Entering Zombie state - connection %s", h->module_name, h->name);
734
735 if (fr_timer_at(h, tl, &h->zombie_ev, fr_time_add(now, h->inst->parent->zombie_period),
736 false, zombie_timeout, h) < 0) {
737 ERROR("Failed inserting zombie timeout for connection");
739 }
740
741 return true;
742}
743
744/** Handle retries.
745 *
746 * Note that with TCP we don't actually retry on this particular connection, but the retry timer allows us to
747 * fail over from one connection to another when a connection fails.
748 */
749static void request_retry(fr_timer_list_t *tl, fr_time_t now, void *uctx)
750{
751 trunk_request_t *treq = talloc_get_type_abort(uctx, trunk_request_t);
752 udp_request_t *u = talloc_get_type_abort(treq->preq, udp_request_t);
753 udp_result_t *r = talloc_get_type_abort(treq->rctx, udp_result_t);
754 request_t *request = treq->request;
755 trunk_connection_t *tconn = treq->tconn;
756
757 fr_assert(treq->state == TRUNK_REQUEST_STATE_SENT); /* No other states should be timing out */
758 fr_assert(treq->preq); /* Must still have a protocol request */
759 fr_assert(tconn);
760
761 switch (fr_retry_next(&u->retry, now)) {
762 /*
763 * Queue the request for retransmission.
764 *
765 * @todo - set up "next" timer here, instead of in
766 * request_mux() ? That way we can catch the case of
767 * packets sitting in the queue for extended periods of
768 * time, and still run the timers.
769 */
772 return;
773
774 case FR_RETRY_MRD:
775 REDEBUG("Reached maximum_retransmit_duration (%pVs > %pVs), failing request",
777 break;
778
779 case FR_RETRY_MRC:
780 REDEBUG("Reached maximum_retransmit_count (%u > %u), failing request",
781 u->retry.count, u->retry.config->mrc);
782 break;
783 }
784
787
788 check_for_zombie(tl, tconn, now, u->retry.start);
789}
790
791CC_NO_UBSAN(function) /* UBSAN: false positive - public vs private connection_t trips --fsanitize=function*/
793 trunk_connection_t *tconn, connection_t *conn, UNUSED void *uctx)
794{
795 udp_handle_t *h = talloc_get_type_abort(conn->h, udp_handle_t);
796 rlm_tacacs_tcp_t const *inst = h->inst;
797 ssize_t sent;
798 uint16_t i, queued;
799 uint8_t const *written;
800 uint8_t *partial;
801
802 /*
803 * Encode multiple packets in preparation for transmission with write()
804 */
805 for (i = 0, queued = 0; (i < inst->max_send_coalesce); i++) {
806 trunk_request_t *treq;
807 udp_request_t *u;
808 request_t *request;
809
810 if (unlikely(trunk_connection_pop_request(&treq, tconn) < 0)) return;
811
812 /*
813 * No more requests to send
814 */
815 if (!treq) break;
816
817 /*
818 * The partial write MUST be the first one popped off of the request list.
819 *
820 * If we have a partial packet, then we know that there's partial data in the output
821 * buffer. However, the request MAY still be freed or timed out before we can write the
822 * data. As a result, we ignore the udp_request_t, and just keep writing the data.
823 */
824 if (treq->state == TRUNK_REQUEST_STATE_PARTIAL) {
825 fr_assert(h->send.read == h->send.data);
826 fr_assert(h->send.write > h->send.read);
827
828 fr_assert(i == 0);
829
830 h->coalesced[0] = treq;
831 goto next;
832 }
833
834 /*
835 * The request must still be pending.
836 */
838
839 request = treq->request;
840 u = talloc_get_type_abort(treq->preq, udp_request_t);
841
842 /*
843 * We'd like to retransmit the packet on this connection, but it's TCP so we don't.
844 *
845 * The retransmission timers are really there to move the packet to a new connection if
846 * the current connection is dead.
847 */
848 if (u->outstanding) continue;
849
850 /*
851 * Not enough room for a full-sized packet, stop encoding packets
852 */
853 if ((h->send.end - h->send.write) < inst->max_packet_size) {
854 break;
855 }
856
857 /*
858 * Start retransmissions from when the socket is writable.
859 */
863
864 /*
865 * Set up the packet for encoding.
866 */
867 u->id = h->id;
868 h->tconn = tconn;
869
870 h->tracking[u->id] = treq;
871 h->id += 2;
872 h->active++;
873
874 RDEBUG("Sending %s ID %d length %ld over connection %s",
876
877 if (encode(h, request, u) < 0) {
878 /*
879 * Need to do this because request_conn_release
880 * may not be called.
881 */
882 udp_request_reset(h, u);
884 continue;
885 }
886 RHEXDUMP3(u->packet, u->packet_len, "Encoded packet");
887
888 log_request_pair_list(L_DBG_LVL_2, request, NULL, &request->request_pairs, NULL);
889
890 /*
891 * Remember that we've encoded this packet.
892 */
893 h->coalesced[queued] = treq;
894 h->send.write += u->packet_len;
895
896 fr_assert(h->send.write <= h->send.end);
897
898 /*
899 * If we just hit this limit, stop using the connection.
900 *
901 * When we've received all replies (or timeouts), we'll close the connections.
902 */
903 if (h->id > 255) {
905 }
906
907 next:
908 /*
909 * Tell the trunk API that this request is now in
910 * the "sent" state. And we don't want to see
911 * this request again. The request hasn't actually
912 * been sent, but it's the only way to get at the
913 * next entry in the heap.
914 */
916 queued++;
917 }
918
919 if (queued == 0) return;
920
921 /*
922 * Verify nothing accidentally freed the connection handle
923 */
924 (void)talloc_get_type_abort(h, udp_handle_t);
925
926 /*
927 * Send the packets as one system call.
928 */
929 sent = write(h->fd, h->send.read, h->send.write - h->send.read);
930 if (sent < 0) { /* Error means no messages were sent */
931 /*
932 * Temporary conditions
933 */
934 switch (errno) {
935#if defined(EWOULDBLOCK) && (EWOULDBLOCK != EAGAIN)
936 case EWOULDBLOCK: /* No outbound packet buffers, maybe? */
937#endif
938 case EAGAIN: /* No outbound packet buffers, maybe? */
939 case EINTR: /* Interrupted by signal */
940 case ENOBUFS: /* No outbound packet buffers, maybe? */
941 case ENOMEM: /* malloc failure in kernel? */
942 WARN("%s - Failed sending data over connection %s: %s",
943 h->module_name, h->name, fr_syserror(errno));
944 sent = 0;
945 break;
946
947 /*
948 * Will re-queue any 'sent' requests, so we don't
949 * have to do any cleanup.
950 */
951 default:
952 ERROR("%s - Failed sending data over connection %s: %s",
953 h->module_name, h->name, fr_syserror(errno));
955 return;
956 }
957 }
958
959 written = h->send.read + sent;
960 partial = h->send.read;
961
962 /*
963 * For all messages that were actually sent by writev()
964 * start the request timer.
965 */
966 for (i = 0; i < queued; i++) {
967 trunk_request_t *treq = h->coalesced[i];
968 udp_request_t *u;
969 request_t *request;
970
971 /*
972 * We *think* we sent this, but we might not had :(
973 */
974 fr_assert(treq->state == TRUNK_REQUEST_STATE_SENT);
975
976 request = treq->request;
977 u = talloc_get_type_abort(treq->preq, udp_request_t);
978
979 /*
980 * This packet ends before the piece we've
981 * written, so we've written all of it.
982 */
983 if (u->packet + u->packet_len <= written) {
984 h->last_sent = u->retry.start;
986
987 if (fr_timer_at(u, el->tl, &u->ev, u->retry.next, false, request_retry, treq) < 0) {
988 RERROR("Failed inserting retransmit timeout for connection");
990 }
991
992 /*
993 * If the packet doesn't get a response, then the timer will hit
994 * and will retransmit.
995 */
996 u->outstanding = true;
997 continue;
998 }
999
1000 /*
1001 * The packet starts before the piece we've written, BUT ends after the written piece.
1002 *
1003 * We only wrote part of this packet, remember the partial packet we wrote. Note that
1004 * we only track the packet data, and not the udp_request_t. The underlying request (and
1005 * u) may disappear at any time, even if there's still data in the buffer.
1006 *
1007 * Then, signal that isn't a partial packet, and stop processing the queue, as we know
1008 * that the next packet wasn't written.
1009 */
1010 if (u->packet < written) {
1011 size_t skip = written - u->packet;
1012 size_t left = u->packet_len - skip;
1013
1014 fr_assert(u->packet + u->packet_len > written);
1015
1016 memmove(h->send.data, u->packet, left);
1017
1018 fr_assert(h->send.read == h->send.data);
1019 partial = h->send.data + left;
1020 u->outstanding = true;
1021
1023 continue;
1024 }
1025
1026 /*
1027 * The packet starts after the piece we've written, so we haven't written any of it.
1028 *
1029 * Requests that weren't sent get re-enqueued. Which means that they get re-encoded, but
1030 * oh well.
1031 *
1032 * The cancel logic runs as per-normal and cleans up
1033 * the request ready for sending again...
1034 */
1036 fr_assert(!u->outstanding); /* must have called udp_request_requeue() */
1037 }
1038
1039 /*
1040 * Remember where to write the next packet. Either at the start of the buffer, or after the one
1041 * which was partially written.
1042 */
1043 h->send.write = partial;
1044}
1045
1047{
1048 udp_handle_t *h = talloc_get_type_abort(conn->h, udp_handle_t);
1049 bool do_read = true;
1050
1051 DEBUG3("%s - Reading data for connection %s", h->module_name, h->name);
1052
1053 while (true) {
1054 ssize_t slen;
1055 size_t available, used, packet_len;
1056
1057 trunk_request_t *treq;
1058 request_t *request;
1059 udp_request_t *u;
1060 udp_result_t *r;
1061 uint8_t code = 0;
1062 fr_pair_list_t reply;
1063
1064 /*
1065 * Ensure that we can read at least one max-sized packet.
1066 *
1067 * If not, move the trailing bytes to the start of the buffer, and reset the read/write
1068 * pointers to the start of the buffer. Note that the read buffer has to be at least 2x
1069 * max_packet_size.
1070 */
1071 available = h->recv.end - h->recv.read;
1072 if (available < h->inst->max_packet_size) {
1074
1075 used = h->recv.write - h->recv.read;
1076
1077 memcpy(h->recv.data, h->recv.read, used);
1078 h->recv.read = h->recv.data;
1079 h->recv.write = h->recv.read + used;
1080 }
1081
1082 /*
1083 * Read as much data as possible.
1084 *
1085 * We don't need to call read() on every round through the loop. Instead, we call it
1086 * only when this function first gets called, OR if the read stopped at the end of the
1087 * buffer.
1088 *
1089 * This allows us to read a large amount of data at once, and then process multiple
1090 * packets without calling read() too many times.
1091 */
1092 if (do_read) {
1093 slen = read(h->fd, h->recv.write, h->recv.end - h->recv.write);
1094 if (slen < 0) {
1095 if ((errno == EAGAIN) || (errno == EWOULDBLOCK)) return;
1096
1097 ERROR("%s - Failed reading response from socket: %s",
1098 h->module_name, fr_syserror(errno));
1100 return;
1101 }
1102
1103 h->recv.write += slen;
1104 do_read = (h->recv.write == h->recv.end);
1105 }
1106
1107 used = h->recv.write - h->recv.read;
1108
1109 /*
1110 * We haven't received a full header, read more or return.
1111 */
1112 if (used < sizeof(fr_tacacs_packet_hdr_t)) {
1113 if (do_read) continue;
1114 return;
1115 }
1116
1117 /*
1118 * The packet contains a 4 octet length in the
1119 * header, but the header bytes aren't included
1120 * in the 4 octet length field.
1121 */
1122 packet_len = fr_nbo_to_uint32(h->recv.read + 8) + FR_HEADER_LENGTH;
1123
1124 /*
1125 * The packet is too large, reject it.
1126 */
1127 if (packet_len > h->inst->max_packet_size) {
1128 ERROR("%s - Packet is larger than max_packet_size",
1129 h->module_name);
1131 return;
1132 }
1133
1134 /*
1135 * We haven't received the full packet, read more or return.
1136 */
1137 if (used < packet_len) {
1138 if (do_read) continue;
1139 return;
1140 }
1141
1142 fr_assert(h->recv.read + packet_len <= h->recv.end);
1143
1144 /*
1145 * TACACS+ doesn't care about packet codes. All packet of the codes share the same ID
1146 * space.
1147 */
1148 treq = h->tracking[h->recv.read[1]];
1149 if (!treq) {
1150 WARN("%s - Ignoring reply with ID %i that arrived too late",
1151 h->module_name, h->recv.data[1]);
1152
1153 h->recv.read += packet_len;
1154 continue;
1155 }
1156
1157 treq = talloc_get_type_abort(treq, trunk_request_t);
1158 request = treq->request;
1159 fr_assert(request != NULL);
1160 u = talloc_get_type_abort(treq->preq, udp_request_t);
1161 r = talloc_get_type_abort(treq->rctx, udp_result_t);
1162
1163 fr_pair_list_init(&reply);
1164
1165 /*
1166 * Validate and decode the incoming packet
1167 */
1168 slen = decode(request->reply_ctx, &reply, &code, h, request, u, h->recv.read, packet_len);
1169 if (slen < 0) {
1170 // @todo - give real decode error?
1172 return;
1173 }
1174 h->recv.read += packet_len;
1175
1176 /*
1177 * Only valid packets are processed.
1178 */
1179 h->last_reply = fr_time();
1180
1181 treq->request->reply->code = code;
1182
1183 // @todo - check various random locations for status of the reply: error, etc.
1184 r->rcode = RLM_MODULE_OK;
1185// r->rcode = radius_code_to_rcode[code];
1186 fr_pair_list_append(&request->reply_pairs, &reply);
1188 }
1189}
1190
1191/** Remove the request from any tracking structures
1192 *
1193 * Frees encoded packets if the request is being moved to a new connection
1194 */
1195static void request_cancel(connection_t *conn, void *preq_to_reset,
1196 trunk_cancel_reason_t reason, UNUSED void *uctx)
1197{
1198 udp_request_t *u = talloc_get_type_abort(preq_to_reset, udp_request_t);
1199
1200 /*
1201 * Request has been requeued on the same
1202 * connection due to timeout or DUP signal.
1203 */
1204 if (reason == TRUNK_CANCEL_REASON_REQUEUE) {
1205 udp_handle_t *h = talloc_get_type_abort(conn->h, udp_handle_t);
1206
1207 udp_request_reset(h, u);
1208 }
1209
1210 /*
1211 * Other cancellations are dealt with by
1212 * request_conn_release as the request is removed
1213 * from the trunk.
1214 */
1215}
1216
1217/** Clear out anything associated with the handle from the request
1218 *
1219 */
1220static void request_conn_release(connection_t *conn, void *preq_to_reset, UNUSED void *uctx)
1221{
1222 udp_request_t *u = talloc_get_type_abort(preq_to_reset, udp_request_t);
1223 udp_handle_t *h = talloc_get_type_abort(conn->h, udp_handle_t);
1224
1225 if (u->packet) udp_request_reset(h, u);
1226
1227 /*
1228 * If there are no outstanding tracking entries
1229 * allocated then the connection is "idle".
1230 *
1231 * @todo - enable idle timeout?
1232 */
1233 if (!h->active) h->last_idle = fr_time();
1234}
1235
1236/** Write out a canned failure
1237 *
1238 */
1239static void request_fail(request_t *request, NDEBUG_UNUSED void *preq, void *rctx,
1240 NDEBUG_UNUSED trunk_request_state_t state, UNUSED void *uctx)
1241{
1242 udp_result_t *r = talloc_get_type_abort(rctx, udp_result_t);
1243#ifndef NDEBUG
1244 udp_request_t *u = talloc_get_type_abort(preq, udp_request_t);
1245#endif
1246
1247 fr_assert(!u->ev); /* Dealt with by request_conn_release */
1248
1250
1252 r->treq = NULL;
1253
1255}
1256
1257/** Response has already been written to the rctx at this point
1258 *
1259 */
1260static void request_complete(request_t *request, NDEBUG_UNUSED void *preq, void *rctx, UNUSED void *uctx)
1261{
1262 udp_result_t *r = talloc_get_type_abort(rctx, udp_result_t);
1263#ifndef NDEBUG
1264 udp_request_t *u = talloc_get_type_abort(preq, udp_request_t);
1265#endif
1266
1267 fr_assert(!u->packet && !u->ev); /* Dealt with by request_conn_release */
1268
1269 r->treq = NULL;
1270
1272}
1273
1274/** Explicitly free resources associated with the protocol request
1275 *
1276 */
1277static void request_free(UNUSED request_t *request, void *preq_to_free, UNUSED void *uctx)
1278{
1279 udp_request_t *u = talloc_get_type_abort(preq_to_free, udp_request_t);
1280
1281 fr_assert(!u->packet && !u->ev); /* Dealt with by request_conn_release */
1282
1283 talloc_free(u);
1284}
1285
1286/** Resume execution of the request, returning the rcode set during trunk execution
1287 *
1288 */
1289static unlang_action_t mod_resume(rlm_rcode_t *p_result, module_ctx_t const *mctx, UNUSED request_t *request)
1290{
1291 udp_result_t *r = talloc_get_type_abort(mctx->rctx, udp_result_t);
1292 rlm_rcode_t rcode = r->rcode;
1293
1294 talloc_free(r);
1295
1296 RETURN_MODULE_RCODE(rcode);
1297}
1298
1299static void mod_signal(module_ctx_t const *mctx, UNUSED request_t *request, fr_signal_t action)
1300{
1301// udp_thread_t *t = talloc_get_type_abort(mctx->thread, udp_thread_t);
1302 udp_result_t *r = talloc_get_type_abort(mctx->rctx, udp_result_t);
1303
1304 /*
1305 * If we don't have a treq associated with the
1306 * rctx it's likely because the request was
1307 * scheduled, but hasn't yet been resumed, and
1308 * has received a signal, OR has been resumed
1309 * and immediately cancelled as the event loop
1310 * is exiting, in which case
1311 * unlang_request_is_scheduled will return false
1312 * (don't use it).
1313 */
1314 if (!r->treq) {
1315 talloc_free(r);
1316 return;
1317 }
1318
1319 switch (action) {
1320 /*
1321 * The request is being cancelled, tell the
1322 * trunk so it can clean up the treq.
1323 */
1324 case FR_SIGNAL_CANCEL:
1326 r->treq = NULL;
1327 talloc_free(r); /* Should be freed soon anyway, but better to be explicit */
1328 return;
1329
1330 /*
1331 * Requeue the request on the same connection
1332 * causing a "retransmission" if the request
1333 * has already been sent out.
1334 */
1335 case FR_SIGNAL_DUP:
1336 /*
1337 * Retransmit the current request on the same connection.
1338 *
1339 * If it's zombie, we still resend it. If the
1340 * connection is dead, then a callback will move
1341 * this request to a new connection.
1342 */
1344 return;
1345
1346 default:
1347 return;
1348 }
1349}
1350
1351#ifndef NDEBUG
1352/** Free a udp_result_t
1353 *
1354 * Allows us to set break points for debugging.
1355 */
1357{
1358 trunk_request_t *treq;
1359 udp_request_t *u;
1360
1361 if (!r->treq) return 0;
1362
1363 treq = talloc_get_type_abort(r->treq, trunk_request_t);
1364 u = talloc_get_type_abort(treq->preq, udp_request_t);
1365
1366 fr_assert_msg(!u->ev, "udp_result_t freed with active timer");
1367
1368 return 0;
1369}
1370#endif
1371
1372static unlang_action_t mod_enqueue(rlm_rcode_t *p_result, void **rctx_out, UNUSED void *instance, void *thread, request_t *request)
1373{
1374 udp_thread_t *t = talloc_get_type_abort(thread, udp_thread_t);
1375 udp_result_t *r;
1376 udp_request_t *u;
1377 trunk_request_t *treq;
1379
1380 fr_assert(FR_TACACS_PACKET_CODE_VALID(request->packet->code));
1381
1382 treq = trunk_request_alloc(t->trunk, request);
1383 if (!treq) RETURN_MODULE_FAIL;
1384
1385 MEM(r = talloc_zero(request, udp_result_t));
1386#ifndef NDEBUG
1387 talloc_set_destructor(r, _udp_result_free);
1388#endif
1389
1390 /*
1391 * Can't use compound literal - const issues.
1392 */
1393 MEM(u = talloc_zero(treq, udp_request_t));
1394 u->code = request->packet->code;
1395 u->priority = request->async->priority;
1396 u->recv_time = request->async->recv_time;
1397
1399
1400 q = trunk_request_enqueue(&treq, t->trunk, request, u, r);
1401 if (q < 0) {
1402 fr_assert(!u->packet); /* Should not have been fed to the muxer */
1403 trunk_request_free(&treq); /* Return to the free list */
1404 fail:
1405 talloc_free(r);
1407 }
1408
1409 /*
1410 * All destinations are down.
1411 */
1412 if (q == TRUNK_ENQUEUE_IN_BACKLOG) {
1413 RDEBUG("All destinations are down - cannot send packet");
1414 goto fail;
1415 }
1416
1417 r->treq = treq; /* Remember for signalling purposes */
1418
1419 *rctx_out = r;
1420
1421 return UNLANG_ACTION_YIELD;
1422}
1423
1424/** Instantiate thread data for the submodule.
1425 *
1426 */
1428{
1429 rlm_tacacs_tcp_t *inst = talloc_get_type_abort(mctx->mi->data, rlm_tacacs_tcp_t);
1430 udp_thread_t *thread = talloc_get_type_abort(mctx->thread, udp_thread_t);
1431
1432 static trunk_io_funcs_t io_funcs = {
1434 .connection_notify = thread_conn_notify,
1435 .request_prioritise = request_prioritise,
1436 .request_mux = request_mux,
1437 .request_demux = request_demux,
1438 .request_conn_release = request_conn_release,
1439 .request_complete = request_complete,
1440 .request_fail = request_fail,
1441 .request_cancel = request_cancel,
1442 .request_free = request_free
1443 };
1444
1445 thread->el = mctx->el;
1446 thread->inst = inst;
1447 thread->trunk = trunk_alloc(thread, mctx->el, &io_funcs,
1448 &inst->parent->trunk_conf, inst->parent->name, thread, false);
1449 if (!thread->trunk) return -1;
1450
1451 return 0;
1452}
1453
1454static int mod_instantiate(module_inst_ctx_t const *mctx)
1455{
1456 rlm_tacacs_t *parent = talloc_get_type_abort(mctx->mi->parent->data, rlm_tacacs_t);
1457 rlm_tacacs_tcp_t *inst = talloc_get_type_abort(mctx->mi->data, rlm_tacacs_tcp_t);
1458 CONF_SECTION *conf = mctx->mi->conf;
1459
1460 if (!parent) {
1461 ERROR("IO module cannot be instantiated directly");
1462 return -1;
1463 }
1464
1465 inst->parent = parent;
1466
1467 /*
1468 * Always need at least one mmsgvec
1469 */
1470 if (inst->max_send_coalesce == 0) inst->max_send_coalesce = 1;
1471
1472 /*
1473 * Ensure that we have a destination address.
1474 */
1475 if (inst->dst_ipaddr.af == AF_UNSPEC) {
1476 cf_log_err(conf, "A value must be given for 'ipaddr'");
1477 return -1;
1478 }
1479
1480 /*
1481 * If src_ipaddr isn't set, make sure it's INADDR_ANY, of
1482 * the same address family as dst_ipaddr.
1483 */
1484 if (inst->src_ipaddr.af == AF_UNSPEC) {
1485 memset(&inst->src_ipaddr, 0, sizeof(inst->src_ipaddr));
1486
1487 inst->src_ipaddr.af = inst->dst_ipaddr.af;
1488
1489 if (inst->src_ipaddr.af == AF_INET) {
1490 inst->src_ipaddr.prefix = 32;
1491 } else {
1492 inst->src_ipaddr.prefix = 128;
1493 }
1494 }
1495
1496 else if (inst->src_ipaddr.af != inst->dst_ipaddr.af) {
1497 cf_log_err(conf, "The 'ipaddr' and 'src_ipaddr' configuration items must "
1498 "be both of the same address family");
1499 return -1;
1500 }
1501
1502 if (!inst->dst_port) {
1503 cf_log_err(conf, "A value must be given for 'port'");
1504 return -1;
1505 }
1506
1507 /*
1508 * Clamp max_packet_size first before checking recv_buff and send_buff
1509 */
1510 FR_INTEGER_BOUND_CHECK("max_packet_size", inst->max_packet_size, >=, ((255 + (int) sizeof(fr_tacacs_packet_t)) & 0xffffff00));
1511 FR_INTEGER_BOUND_CHECK("max_packet_size", inst->max_packet_size, <=, 65535);
1512
1513
1514 if (inst->recv_buff_is_set) {
1515 FR_INTEGER_BOUND_CHECK("recv_buff", inst->recv_buff, >=, inst->max_packet_size);
1516 FR_INTEGER_BOUND_CHECK("recv_buff", inst->recv_buff, <=, (1 << 30));
1517 }
1518
1519 if (inst->send_buff_is_set) {
1520 FR_INTEGER_BOUND_CHECK("send_buff", inst->send_buff, >=, inst->max_packet_size);
1521 FR_INTEGER_BOUND_CHECK("send_buff", inst->send_buff, <=, (1 << 30));
1522 }
1523
1524
1525 /*
1526 * Empty secrets don't exist
1527 */
1528 if (inst->secret && !*inst->secret) {
1529 talloc_const_free(inst->secret);
1530 inst->secret = NULL;
1531 }
1532
1533 if (inst->secret) inst->secretlen = talloc_array_length(inst->secret) - 1;
1534
1535 return 0;
1536}
1537
1540 .common = {
1541 .magic = MODULE_MAGIC_INIT,
1542 .name = "tacacs_tcp",
1543 .inst_size = sizeof(rlm_tacacs_tcp_t),
1544
1545 .thread_inst_size = sizeof(udp_thread_t),
1546 .thread_inst_type = "udp_thread_t",
1547
1548 .config = module_config,
1549 .instantiate = mod_instantiate,
1550 .thread_instantiate = mod_thread_instantiate,
1551 },
1552 .enqueue = mod_enqueue,
1553 .signal = mod_signal,
1554 .resume = mod_resume,
1555};
unlang_action_t
Returned by unlang_op_t calls, determine the next action of the interpreter.
Definition action.h:35
@ UNLANG_ACTION_YIELD
Temporarily pause execution until an event occurs.
Definition action.h:42
#define RCSID(id)
Definition build.h:485
#define NDEBUG_UNUSED
Definition build.h:328
#define CMP_PREFER_SMALLER(_a, _b)
Evaluates to +1 for a > b, and -1 for a < b.
Definition build.h:104
#define STRINGIFY(x)
Definition build.h:197
#define CC_NO_UBSAN(_sanitize)
Definition build.h:428
#define CMP(_a, _b)
Same as CMP_PREFER_SMALLER use when you don't really care about ordering, you just want an ordering.
Definition build.h:112
#define unlikely(_x)
Definition build.h:383
#define UNUSED
Definition build.h:317
#define CONF_PARSER_TERMINATOR
Definition cf_parse.h:658
#define FR_INTEGER_BOUND_CHECK(_name, _var, _op, _bound)
Definition cf_parse.h:518
#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:284
#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:298
#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:241
Defines a CONF_PAIR to C data type mapping.
Definition cf_parse.h:595
A section grouping multiple CONF_PAIR.
Definition cf_priv.h:101
#define cf_log_err(_cf, _fmt,...)
Definition cf_util.h:289
connection_state_t
Definition connection.h:45
@ CONNECTION_STATE_FAILED
Connection has failed.
Definition connection.h:54
@ CONNECTION_STATE_CONNECTING
Waiting for connection to establish.
Definition connection.h:50
@ CONNECTION_EXPIRED
Connection is being reconnected because it's at the end of its life.
Definition connection.h:85
@ CONNECTION_FAILED
Connection is being reconnected because it failed.
Definition connection.h:84
Holds a complete set of functions for a connection.
Definition connection.h:186
#define FR_DBUFF_TMP(_start, _len_or_end)
Creates a compound literal to pass into functions which accept a dbuff.
Definition dbuff.h:514
#define fr_assert_msg(_x, _msg,...)
Calls panic_action ifndef NDEBUG, else logs error and causes the server to exit immediately with code...
Definition debug.h:210
#define MEM(x)
Definition debug.h:36
#define ERROR(fmt,...)
Definition dhcpclient.c:41
#define DEBUG(fmt,...)
Definition dhcpclient.c:39
fr_dict_attr_t const ** out
Where to write a pointer to the resolved fr_dict_attr_t.
Definition dict.h:272
fr_dict_t const ** out
Where to write a pointer to the loaded/resolved fr_dict_t.
Definition dict.h:285
Specifies an attribute which must be present for the module to function.
Definition dict.h:271
Specifies a dictionary which must be loaded/loadable for the module to function.
Definition dict.h:284
#define MODULE_MAGIC_INIT
Stop people using different module/library/server versions together.
Definition dl_module.h:63
#define fr_event_fd_insert(...)
Definition event.h:248
void(* fr_event_fd_cb_t)(fr_event_list_t *el, int fd, int flags, void *uctx)
Called when an IO event occurs on a file descriptor.
Definition event.h:151
@ FR_EVENT_FILTER_IO
Combined filter for read/write functions/.
Definition event.h:84
IPv4/6 prefix.
void unlang_interpret_mark_runnable(request_t *request)
Mark a request as resumable.
Definition interpret.c:1418
void log_request_pair_list(fr_log_lvl_t lvl, request_t *request, fr_pair_t const *parent, fr_pair_list_t const *vps, char const *prefix)
Print a fr_pair_list_t.
Definition log.c:828
#define PERROR(_fmt,...)
Definition log.h:228
#define DEBUG3(_fmt,...)
Definition log.h:266
#define RERROR(fmt,...)
Definition log.h:298
#define DEBUG4(_fmt,...)
Definition log.h:267
#define RPERROR(fmt,...)
Definition log.h:302
#define RPEDEBUG(fmt,...)
Definition log.h:376
#define RHEXDUMP3(_data, _len, _fmt,...)
Definition log.h:705
talloc_free(reap)
int fr_event_fd_delete(fr_event_list_t *el, int fd, fr_event_filter_t filter)
Remove a file descriptor from the event loop.
Definition event.c:1203
Stores all information relating to an event list.
Definition event.c:377
@ L_DBG_LVL_2
2nd highest priority debug messages (-xx | -X).
Definition log.h:71
unsigned short uint16_t
@ FR_TYPE_IPV4_ADDR
32 Bit IPv4 Address.
@ FR_TYPE_UINT32
32 Bit unsigned integer.
@ FR_TYPE_STRUCT
like TLV, but without T or L, and fixed-width children
@ 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
unsigned long int size_t
#define UINT8_MAX
static size_t used
void * rctx
Resume ctx that a module previously set.
Definition module_ctx.h:45
fr_event_list_t * el
Event list to register any IO handlers and timers against.
Definition module_ctx.h:68
void * thread
Thread instance data.
Definition module_ctx.h:67
module_instance_t const * mi
Instance of the module being instantiated.
Definition module_ctx.h:64
module_instance_t * mi
Instance of the module being instantiated.
Definition module_ctx.h:51
Temporary structure to hold arguments for module calls.
Definition module_ctx.h:41
Temporary structure to hold arguments for instantiation calls.
Definition module_ctx.h:50
Temporary structure to hold arguments for thread_instantiation calls.
Definition module_ctx.h:63
static const trunk_io_funcs_t io_funcs
Definition bio.c:2397
static uint32_t fr_nbo_to_uint32(uint8_t const data[static sizeof(uint32_t)])
Read an unsigned 32bit integer from wire format (big endian)
Definition nbo.h:167
fr_pair_t * fr_pair_find_by_da_nested(fr_pair_list_t const *list, fr_pair_t const *prev, fr_dict_attr_t const *da)
Find a pair with a matching fr_dict_attr_t, by walking the nested fr_dict_attr_t tree.
Definition pair.c:772
int8_t fr_pair_cmp_by_parent_num(void const *a, void const *b)
Order attributes by their parent(s), attribute number, and tag.
Definition pair.c:1923
fr_pair_t * fr_pair_find_by_da(fr_pair_list_t const *list, fr_pair_t const *prev, fr_dict_attr_t const *da)
Find the first pair with a matching da.
Definition pair.c:695
int fr_pair_append(fr_pair_list_t *list, fr_pair_t *to_add)
Add a VP to the end of the list.
Definition pair.c:1347
fr_pair_t * fr_pair_afrom_da(TALLOC_CTX *ctx, fr_dict_attr_t const *da)
Dynamically allocate a new attribute and assign a fr_dict_attr_t.
Definition pair.c:285
void fr_pair_list_init(fr_pair_list_t *list)
Initialise a pair list header.
Definition pair.c:46
char * fr_asprintf(TALLOC_CTX *ctx, char const *fmt,...)
Special version of asprintf which implements custom format specifiers.
Definition print.c:874
char const * fr_tacacs_packet_names[FR_TACACS_CODE_MAX]
Definition base.c:119
ssize_t fr_tacacs_decode(TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dict_attr_t const *vendor, uint8_t const *buffer, size_t buffer_len, const uint8_t *original, char const *const secret, size_t secret_len, int *code)
Decode a TACACS+ packet.
Definition decode.c:409
ssize_t fr_tacacs_encode(fr_dbuff_t *dbuff, uint8_t const *original_packet, char const *secret, size_t secret_len, unsigned int code, fr_pair_list_t *vps)
Encode VPS into a raw TACACS packet.
Definition encode.c:363
#define fr_assert(_expr)
Definition rad_assert.h:38
static char * secret
#define REDEBUG(fmt,...)
Definition radclient.h:52
#define RDEBUG(fmt,...)
Definition radclient.h:53
#define WARN(fmt,...)
Definition radclient.h:47
#define INFO(fmt,...)
Definition radict.c:54
static rs_t * conf
Definition radsniff.c:53
uint32_t fr_rand(void)
Return a 32-bit random number.
Definition rand.c:105
#define RETURN_MODULE_RCODE(_rcode)
Definition rcode.h:64
#define RETURN_MODULE_FAIL
Definition rcode.h:56
rlm_rcode_t
Return codes indicating the result of the module call.
Definition rcode.h:40
@ RLM_MODULE_OK
The module is OK, continue.
Definition rcode.h:43
@ RLM_MODULE_FAIL
Module failed, don't reply.
Definition rcode.h:42
module_t common
Common fields to all loadable modules.
Definition rlm_tacacs.h:74
fr_retry_config_t retry
retries shared by all packet types
Definition rlm_tacacs.h:57
char const * name
Definition rlm_tacacs.h:45
fr_time_delta_t revive_interval
Definition rlm_tacacs.h:51
fr_time_delta_t zombie_period
Definition rlm_tacacs.h:50
fr_time_delta_t response_window
Definition rlm_tacacs.h:49
Public structure describing an I/O path for an outgoing socket.
Definition rlm_tacacs.h:73
fr_time_t last_reply
When we last received a reply.
static int8_t request_prioritise(void const *one, void const *two)
uint16_t src_port
Source port specific to this connection.
rlm_rcode_t rcode
from the transport
uint8_t * write
where we write data to
static fr_dict_attr_t const * attr_packet_type
fr_time_t first_sent
first time we sent a packet since going idle
static bool check_for_zombie(fr_timer_list_t *tl, trunk_connection_t *tconn, fr_time_t now, fr_time_t last_sent)
See if the connection is zombied.
CONF_SECTION * config
bool send_buff_is_set
Whether we were provided with a send_buf.
fr_event_list_t * el
Event list.
static int _udp_result_free(udp_result_t *r)
Free a udp_result_t.
size_t secretlen
length of secret
static void request_demux(UNUSED fr_event_list_t *el, trunk_connection_t *tconn, connection_t *conn, UNUSED void *uctx)
char const * name
From IP PORT to IP PORT.
static fr_dict_attr_t const * attr_session_id
static void request_mux(fr_event_list_t *el, trunk_connection_t *tconn, connection_t *conn, UNUSED void *uctx)
char const * interface
Interface to bind to.
fr_timer_t * ev
timer for retransmissions
uint8_t * data
actual data
fr_time_t last_idle
last time we had nothing to do
size_t packet_len
Length of the packet.
static fr_dict_attr_t const * attr_packet_hdr
trunk_request_t * treq
trunk_t * trunk
trunk handler
char const * module_name
the module that opened the connection
static void udp_request_reset(udp_handle_t *h, udp_request_t *u)
Clear out any connection specific resources from a udp request.
trunk_connection_t * tconn
trunk connection
rlm_tacacs_tcp_t const * inst
our instance
fr_dict_autoload_t rlm_tacacs_tcp_dict[]
uint8_t id
Last ID assigned to this packet.
fr_ipaddr_t src_ipaddr
Source IP address.
static void conn_error(UNUSED fr_event_list_t *el, UNUSED int fd, UNUSED int flags, int fd_errno, void *uctx)
Connection errored.
static ssize_t decode(TALLOC_CTX *ctx, fr_pair_list_t *reply, uint8_t *response_code, udp_handle_t *h, request_t *request, udp_request_t *u, uint8_t *data, size_t data_len)
Decode response packet data, extracting relevant information and validating the packet.
static void mod_signal(module_ctx_t const *mctx, UNUSED request_t *request, fr_signal_t action)
static void conn_close(UNUSED fr_event_list_t *el, void *handle, UNUSED void *uctx)
Shutdown/close a file descriptor.
static void thread_conn_notify(trunk_connection_t *tconn, connection_t *conn, fr_event_list_t *el, trunk_connection_event_t notify_on, UNUSED void *uctx)
char const * secret
Shared secret.
static void request_conn_release(connection_t *conn, void *preq_to_reset, UNUSED void *uctx)
Clear out anything associated with the handle from the request.
udp_thread_t * thread
uint32_t session_id
for TACACS+ "security".
uint16_t dst_port
Port of the home server.
fr_time_t recv_time
copied from request->async->recv_time
static fr_dict_t const * dict_tacacs
uint32_t send_buff
How big the kernel's send buffer should be.
static void request_retry(fr_timer_list_t *tl, fr_time_t now, void *uctx)
Handle retries.
int id
starts at 1.
uint8_t * end
end of the buffer
uint8_t * packet
Packet we write to the network.
fr_time_t last_sent
last time we sent a packet.
static void request_free(UNUSED request_t *request, void *preq_to_free, UNUSED void *uctx)
Explicitly free resources associated with the protocol request.
uint32_t recv_buff
How big the kernel's receive buffer should be.
size_t send_buff_actual
What we believe the maximum SO_SNDBUF size to be.
rlm_tacacs_io_t rlm_tacacs_tcp
int fd
File descriptor.
tcp_buffer_t recv
receive buffer
fr_ipaddr_t src_ipaddr
IP we open our socket on.
static void request_fail(request_t *request, NDEBUG_UNUSED void *preq, void *rctx, NDEBUG_UNUSED trunk_request_state_t state, UNUSED void *uctx)
Write out a canned failure.
uint32_t max_packet_size
Our max packet size. may be different from the parent.
static unlang_action_t mod_enqueue(rlm_rcode_t *p_result, void **rctx_out, UNUSED void *instance, void *thread, request_t *request)
bool recv_buff_is_set
Whether we were provided with a recv_buf.
fr_timer_t * zombie_ev
Zombie timeout.
uint32_t max_packet_size
Maximum packet size.
fr_time_t mrs_time
Most recent sent time which had a reply.
trunk_request_t * tracking[UINT8_MAX]
all sequential!
static void zombie_timeout(fr_timer_list_t *tl, fr_time_t now, void *uctx)
Mark a connection dead after "zombie_interval".
uint8_t code
Packet code.
static int mod_thread_instantiate(module_thread_inst_ctx_t const *mctx)
Instantiate thread data for the submodule.
static unlang_action_t mod_resume(rlm_rcode_t *p_result, module_ctx_t const *mctx, UNUSED request_t *request)
Resume execution of the request, returning the rcode set during trunk execution.
trunk_request_t ** coalesced
Outbound coalesced requests.
static connection_t * thread_conn_alloc(trunk_connection_t *tconn, fr_event_list_t *el, connection_conf_t const *conf, char const *log_prefix, void *uctx)
rlm_tacacs_tcp_t const * inst
Our module instance.
uint8_t * read
where we read data from
tcp_buffer_t send
send buffer
static int _udp_handle_free(udp_handle_t *h)
Free a connection handle, closing associated resources.
int active
active packets
static connection_state_t conn_init(void **h_out, connection_t *conn, void *uctx)
Initialise a new outbound connection.
rlm_tacacs_t * parent
rlm_tacacs instance.
static void revive_timeout(UNUSED fr_timer_list_t *tl, UNUSED fr_time_t now, void *uctx)
Revive a connection after "revive_interval".
fr_dict_attr_autoload_t rlm_tacacs_tcp_dict_attr[]
static const conf_parser_t module_config[]
static int encode(udp_handle_t *h, request_t *request, udp_request_t *u)
bool outstanding
are we waiting for a reply?
fr_retry_t retry
retransmission timers
fr_ipaddr_t dst_ipaddr
IP of the home server.
static int mod_instantiate(module_inst_ctx_t const *mctx)
uint32_t priority
copied from request->async->priority
static void request_cancel(connection_t *conn, void *preq_to_reset, trunk_cancel_reason_t reason, UNUSED void *uctx)
Remove the request from any tracking structures.
trunk_conf_t trunk_conf
trunk configuration
static void request_complete(request_t *request, NDEBUG_UNUSED void *preq, void *rctx, UNUSED void *uctx)
Response has already been written to the rctx at this point.
uint16_t max_send_coalesce
Maximum number of packets to coalesce into one mmsg call.
Static configuration for the module.
Track the handle, which is tightly correlated with the FD.
Connect request_t to local tracking structure.
void connection_signal_reconnect(connection_t *conn, connection_reason_t reason)
Asynchronously signal the connection should be reconnected.
int connection_signal_on_fd(connection_t *conn, int fd)
Setup the connection to change states to connected or failed based on I/O events.
connection_t * connection_alloc(TALLOC_CTX *ctx, fr_event_list_t *el, connection_funcs_t const *funcs, connection_conf_t const *conf, char const *log_prefix, void const *uctx)
Allocate a new connection.
CONF_SECTION * conf
Module's instance configuration.
Definition module.h:330
size_t inst_size
Size of the module's instance data.
Definition module.h:204
void * data
Module's instance data.
Definition module.h:272
module_instance_t const * parent
Parent module's instance (if any).
Definition module.h:338
fr_signal_t
Signals that can be generated/processed by request signal handlers.
Definition signal.h:38
@ FR_SIGNAL_DUP
A duplicate request was received.
Definition signal.h:44
@ FR_SIGNAL_CANCEL
Request has been cancelled.
Definition signal.h:40
int fr_socket_client_tcp(char const *ifname, fr_ipaddr_t *src_ipaddr, fr_ipaddr_t const *dst_ipaddr, uint16_t dst_port, bool async)
Establish a connected TCP socket.
Definition socket.c:727
eap_aka_sim_process_conf_t * inst
fr_pair_t * vp
#define fr_time()
Allow us to arbitrarily manipulate time.
Definition state_test.c:8
Stores an attribute, a value and various bits of other data.
Definition pair.h:68
char const * fr_syserror(int num)
Guaranteed to be thread-safe version of strerror.
Definition syserror.c:243
#define FR_HEADER_LENGTH
Definition tacacs.h:26
#define FR_TACACS_PACKET_CODE_VALID(_code)
Definition tacacs.h:322
#define FR_MAX_PACKET_SIZE
Definition tacacs.h:27
static int talloc_const_free(void const *ptr)
Free const'd memory.
Definition talloc.h:224
#define fr_time_gteq(_a, _b)
Definition time.h:238
static int64_t fr_time_unwrap(fr_time_t time)
Definition time.h:146
#define fr_time_wrap(_time)
Definition time.h:145
#define fr_time_lteq(_a, _b)
Definition time.h:240
#define fr_time_delta_ispos(_a)
Definition time.h:290
#define fr_time_eq(_a, _b)
Definition time.h:241
#define fr_time_add(_a, _b)
Add a time/time delta together.
Definition time.h:196
#define fr_time_gt(_a, _b)
Definition time.h:237
#define fr_time_sub(_a, _b)
Subtract one time from another.
Definition time.h:229
#define fr_time_lt(_a, _b)
Definition time.h:239
"server local" time.
Definition time.h:69
An event timer list.
Definition timer.c:49
A timer event.
Definition timer.c:75
#define FR_TIMER_DISARM(_ev)
Definition timer.h:90
#define fr_timer_at(...)
Definition timer.h:80
void trunk_connection_callback_readable(UNUSED fr_event_list_t *el, UNUSED int fd, UNUSED int flags, void *uctx)
Standard I/O read function.
Definition trunk.c:4013
void trunk_connection_callback_writable(UNUSED fr_event_list_t *el, UNUSED int fd, UNUSED int flags, void *uctx)
Standard I/O write function.
Definition trunk.c:4030
void trunk_request_signal_partial(trunk_request_t *treq)
Signal a partial write.
Definition trunk.c:2028
void trunk_request_signal_fail(trunk_request_t *treq)
Signal that a trunk request failed.
Definition trunk.c:2131
trunk_request_t * trunk_request_alloc(trunk_t *trunk, request_t *request)
(Pre-)Allocate a new trunk request
Definition trunk.c:2473
trunk_t * trunk_alloc(TALLOC_CTX *ctx, fr_event_list_t *el, trunk_io_funcs_t const *funcs, trunk_conf_t const *conf, char const *log_prefix, void const *uctx, bool delay_start)
Allocate a new collection of connections.
Definition trunk.c:4945
uint64_t trunk_connection_requests_requeue(trunk_connection_t *tconn, int states, uint64_t max, bool fail_bound)
Move requests off of a connection and requeue elsewhere.
Definition trunk.c:2009
trunk_enqueue_t trunk_request_enqueue(trunk_request_t **treq_out, trunk_t *trunk, request_t *request, void *preq, void *rctx)
Enqueue a request that needs data written to the trunk.
Definition trunk.c:2586
trunk_enqueue_t trunk_request_requeue(trunk_request_t *treq)
Re-enqueue a request on the same connection.
Definition trunk.c:2675
int trunk_connection_pop_request(trunk_request_t **treq_out, trunk_connection_t *tconn)
Pop a request off a connection's pending queue.
Definition trunk.c:3882
void trunk_request_signal_cancel(trunk_request_t *treq)
Cancel a trunk request.
Definition trunk.c:2151
void trunk_request_free(trunk_request_t **treq_to_free)
If the trunk request is freed then update the target requests.
Definition trunk.c:2321
void trunk_connection_signal_inactive(trunk_connection_t *tconn)
Signal a trunk connection cannot accept more requests.
Definition trunk.c:3936
void trunk_request_signal_sent(trunk_request_t *treq)
Signal that the request was written to a connection successfully.
Definition trunk.c:2049
void trunk_request_signal_complete(trunk_request_t *treq)
Signal that a trunk request is complete.
Definition trunk.c:2093
void trunk_connection_signal_reconnect(trunk_connection_t *tconn, connection_reason_t reason)
Signal a trunk connection is no longer viable.
Definition trunk.c:3998
Associates request queues with a connection.
Definition trunk.c:133
Wraps a normal request.
Definition trunk.c:99
Main trunk management handle.
Definition trunk.c:197
#define TRUNK_REQUEST_STATE_ALL
All request states.
Definition trunk.h:195
trunk_connection_alloc_t connection_alloc
Allocate a new connection_t.
Definition trunk.h:733
trunk_connection_event_t
What type of I/O events the trunk connection is currently interested in receiving.
Definition trunk.h:72
@ TRUNK_CONN_EVENT_BOTH
Trunk should be notified if a connection is readable or writable.
Definition trunk.h:79
@ TRUNK_CONN_EVENT_WRITE
Trunk should be notified if a connection is writable.
Definition trunk.h:77
@ TRUNK_CONN_EVENT_NONE
Don't notify the trunk on connection state changes.
Definition trunk.h:73
@ TRUNK_CONN_EVENT_READ
Trunk should be notified if a connection is readable.
Definition trunk.h:75
trunk_cancel_reason_t
Reasons for a request being cancelled.
Definition trunk.h:55
@ TRUNK_CANCEL_REASON_REQUEUE
A previously sent request is being requeued.
Definition trunk.h:59
trunk_enqueue_t
Definition trunk.h:148
@ TRUNK_ENQUEUE_IN_BACKLOG
Request should be enqueued in backlog.
Definition trunk.h:149
trunk_request_state_t
Used for sanity checks and to simplify freeing.
Definition trunk.h:161
@ TRUNK_REQUEST_STATE_PARTIAL
Some of the request was written to the socket, more of it should be written later.
Definition trunk.h:170
@ TRUNK_REQUEST_STATE_INIT
Initial state.
Definition trunk.h:162
@ TRUNK_REQUEST_STATE_PENDING
In the queue of a connection and is pending writing.
Definition trunk.h:168
@ TRUNK_REQUEST_STATE_SENT
Was written to a socket. Waiting for a response.
Definition trunk.h:172
Common configuration parameters for a trunk.
Definition trunk.h:224
I/O functions to pass to trunk_alloc.
Definition trunk.h:732
close(uq->fd)
static fr_event_list_t * el
void fr_pair_list_sort(fr_pair_list_t *list, fr_cmp_t cmp)
Sort a doubly linked list of fr_pair_ts using merge sort.
void fr_pair_list_free(fr_pair_list_t *list)
Free memory used by a valuepair list.
void fr_pair_list_append(fr_pair_list_t *dst, fr_pair_list_t *src)
Appends a list of fr_pair_t from a temporary list to a destination list.
static fr_slen_t parent
Definition pair.h:845
fr_retry_state_t fr_retry_next(fr_retry_t *r, fr_time_t now)
Initialize a retransmission counter.
Definition retry.c:108
void fr_retry_init(fr_retry_t *r, fr_time_t now, fr_retry_config_t const *config)
Initialize a retransmission counter.
Definition retry.c:36
fr_time_t start
when we started the retransmission
Definition retry.h:53
fr_time_delta_t rt
retransmit interval
Definition retry.h:57
uint32_t mrc
Maximum retransmission count.
Definition retry.h:36
fr_retry_config_t const * config
master configuration
Definition retry.h:52
@ FR_RETRY_MRC
reached maximum retransmission count
Definition retry.h:47
@ FR_RETRY_CONTINUE
Definition retry.h:46
@ FR_RETRY_MRD
reached maximum retransmission duration
Definition retry.h:48
uint32_t count
number of sent packets
Definition retry.h:58
fr_time_delta_t mrd
Maximum retransmission duration.
Definition retry.h:35
fr_time_t next
when the next timer should be set
Definition retry.h:55
#define fr_box_ipaddr(_val)
Definition value.h:305
static fr_slen_t data
Definition value.h:1274
#define fr_box_time_delta(_val)
Definition value.h:354