Skip to content

Commit

Permalink
move common code to function
Browse files Browse the repository at this point in the history
  • Loading branch information
alandekok committed Dec 26, 2024
1 parent 1a3fc96 commit 25852f4
Showing 1 changed file with 32 additions and 35 deletions.
67 changes: 32 additions & 35 deletions src/modules/rlm_radius/bio.c
Original file line number Diff line number Diff line change
Expand Up @@ -1395,6 +1395,36 @@ static bool check_for_zombie(fr_event_list_t *el, trunk_connection_t *tconn, fr_
return true;
}

static void mod_dup(request_t *request, bio_request_t *u)
{
bio_handle_t *h;

h = talloc_get_type_abort(u->treq->tconn->conn->h, bio_handle_t);

if (h->ctx.fd_config->socket_type != SOCK_DGRAM) {
RDEBUG("Using stream sockets - suppressing retransmission");
return;
}

/*
* Arguably this should never happen for UDP sockets.
*/
if (h->fd_info->write_blocked) {
RDEBUG("IO is blocked - suppressing retransmission");
return;
}
u->is_retry = true;

/*
* We are doing synchronous proxying, retransmit
* the current request on the same connection.
*
* If it's zombie, we still resend it. If the
* connection is dead, then a callback will move
* this request to a new connection.
*/
mod_write(request, u->treq, h);
}

/** Handle retries.
*
Expand All @@ -1408,8 +1438,6 @@ static void mod_retry(module_ctx_t const *mctx, request_t *request, fr_retry_t c
trunk_request_t *treq = talloc_get_type_abort(u->treq, trunk_request_t);
trunk_connection_t *tconn = treq->tconn;

bio_handle_t *h;

fr_assert(request == treq->request);
fr_assert(treq->preq); /* Must still have a protocol request */
fr_assert(treq->preq == u);
Expand Down Expand Up @@ -1439,20 +1467,7 @@ static void mod_retry(module_ctx_t const *mctx, request_t *request, fr_retry_t c
case TRUNK_REQUEST_STATE_SENT:
fr_assert(tconn);

h = talloc_get_type_abort(tconn->conn->h, bio_handle_t);

/*
* We only retry on datagram sockets.
*/
fr_assert(h->ctx.fd_config->socket_type == SOCK_DGRAM);

if (h->fd_info->write_blocked) {
RDEBUG("IO is blocked - suppressing retransmission");
return;
}

u->is_retry = true;
mod_write(request, treq, h);
mod_dup(request, u);
return;

case TRUNK_REQUEST_STATE_REAPABLE:
Expand Down Expand Up @@ -2180,8 +2195,6 @@ static void mod_signal(module_ctx_t const *mctx, UNUSED request_t *request, fr_s

static void do_signal(rlm_radius_t const *inst, bio_request_t *u, UNUSED request_t *request, fr_signal_t action)
{
bio_handle_t *h;

/*
* We received a duplicate packet, but we're not doing
* synchronous proxying. Ignore the dup, and rely on the
Expand Down Expand Up @@ -2217,23 +2230,7 @@ static void do_signal(rlm_radius_t const *inst, bio_request_t *u, UNUSED request
* has already been sent out.
*/
case FR_SIGNAL_DUP:
h = u->treq->tconn->conn->h;

if (h->fd_info->write_blocked) {
RDEBUG("IO is blocked - suppressing retransmission");
return;
}
u->is_retry = true;

/*
* We are doing synchronous proxying, retransmit
* the current request on the same connection.
*
* If it's zombie, we still resend it. If the
* connection is dead, then a callback will move
* this request to a new connection.
*/
mod_write(request, u->treq, h);
mod_dup(request, u);
return;

default:
Expand Down

0 comments on commit 25852f4

Please sign in to comment.