Skip to content

Commit

Permalink
save a copy of the packet only if we're going to resend it
Browse files Browse the repository at this point in the history
  • Loading branch information
alandekok committed Dec 26, 2024
1 parent f7c71cc commit 1a3fc96
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions src/modules/rlm_radius/bio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 1a3fc96

Please sign in to comment.