From 1a3fc96cf580123d8efdbaf2348abbf907b08c01 Mon Sep 17 00:00:00 2001 From: "Alan T. DeKok" Date: Thu, 26 Dec 2024 18:51:45 -0500 Subject: [PATCH] save a copy of the packet only if we're going to resend it --- src/modules/rlm_radius/bio.c | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/src/modules/rlm_radius/bio.c b/src/modules/rlm_radius/bio.c index 43aaf2fca5cc0..cbd7e472e3666 100644 --- a/src/modules/rlm_radius/bio.c +++ b/src/modules/rlm_radius/bio.c @@ -614,6 +614,11 @@ static void conn_init_writable(fr_event_list_t *el, UNUSED int fd, UNUSED int fl PERROR("%s - Failed inserting timer event", h->ctx.module_name); goto fail; } + + /* + * Save a copy of the header + Authentication Vector for checking the response. + */ + MEM(u->packet = talloc_memdup(u, u->packet, RADIUS_HEADER_LENGTH)); } /** Free a connection handle, closing associated resources @@ -1255,13 +1260,6 @@ static int encode(bio_handle_t *h, request_t *request, bio_request_t *u, uint8_t goto error; } - /* - * Keep a copy of the packet for potential retransmission. - * - * @todo - do this only for UDP. - */ - MEM(u->packet = talloc_memdup(u, h->buffer, packet_len)); - return 0; } @@ -1657,6 +1655,11 @@ static void mod_write(request_t *request, trunk_request_t *treq, bio_handle_t *h packet_len += slen; if (packet_len < u->packet_len) { + /* + * The first time around, save a copy of the packet for later writing. + */ + if (!u->partial) MEM(u->packet = talloc_memdup(u, u->packet, u->packet_len)); + u->partial = packet_len; trunk_request_signal_partial(treq); return; @@ -1710,6 +1713,18 @@ static void mod_write(request_t *request, trunk_request_t *treq, bio_handle_t *h */ RDEBUG("%s request. Relying on NAS to perform more retransmissions", action); } + + /* + * We don't retransmit over TCP. + */ + if (h->ctx.fd_config->type != SOCK_DGRAM) return; + + /* + * If we only send one datagram packet, then don't bother saving it. + */ + if (u->retry.config && u->retry.config->mrc == 1) return; + + MEM(u->packet = talloc_memdup(u, u->packet, u->packet_len)); } /** Deal with Protocol-Error replies, and possible negotiation