]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
save a copy of the packet only if we're going to resend it
authorAlan T. DeKok <aland@freeradius.org>
Thu, 26 Dec 2024 23:51:45 +0000 (18:51 -0500)
committerAlan T. DeKok <aland@freeradius.org>
Thu, 26 Dec 2024 23:51:45 +0000 (18:51 -0500)
src/modules/rlm_radius/bio.c

index 43aaf2fca5cc0b5b318b426380b98f01571c5df0..cbd7e472e3666528b739863e1e55813bd6f708be 100644 (file)
@@ -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