From: Alan T. DeKok Date: Thu, 26 Dec 2024 23:51:45 +0000 (-0500) Subject: save a copy of the packet only if we're going to resend it X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1a3fc96cf580123d8efdbaf2348abbf907b08c01;p=thirdparty%2Ffreeradius-server.git save a copy of the packet only if we're going to resend it --- diff --git a/src/modules/rlm_radius/bio.c b/src/modules/rlm_radius/bio.c index 43aaf2fca5c..cbd7e472e36 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 @@ do_write: 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 @@ do_write: */ 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