]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
don't block forever if we fail to enqueue a packet
authorAlan T. DeKok <aland@freeradius.org>
Tue, 21 Mar 2023 20:12:35 +0000 (16:12 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Tue, 21 Mar 2023 20:12:35 +0000 (16:12 -0400)
src/modules/rlm_radius/rlm_radius_udp.c
src/modules/rlm_tacacs/rlm_tacacs_tcp.c

index f7f57f02d229078829cf07011c635988408140db..dcee692ed443497b41f8d7a7a64496f4d0dcc59c 100644 (file)
@@ -2718,6 +2718,7 @@ static unlang_action_t mod_enqueue(rlm_rcode_t *p_result, void **rctx_out, void
        udp_result_t                    *r;
        udp_request_t                   *u;
        fr_trunk_request_t              *treq;
+       fr_trunk_enqueue_t              q;
 
        fr_assert(request->packet->code > 0);
        fr_assert(request->packet->code < FR_RADIUS_CODE_MAX);
@@ -2762,13 +2763,23 @@ static unlang_action_t mod_enqueue(rlm_rcode_t *p_result, void **rctx_out, void
                pair_delete_request(attr_message_authenticator);
        }
 
-       if (fr_trunk_request_enqueue(&treq, t->trunk, request, u, r) < 0) {
+       q = fr_trunk_request_enqueue(&treq, t->trunk, request, u, r);
+       if (q < 0) {
                fr_assert(!u->rr && !u->packet);        /* Should not have been fed to the muxer */
                fr_trunk_request_free(&treq);           /* Return to the free list */
+       fail:
                talloc_free(r);
                RETURN_MODULE_FAIL;
        }
 
+       /*
+        *      All destinations are down.
+        */
+       if (q == FR_TRUNK_ENQUEUE_IN_BACKLOG) {
+               RDEBUG("All destinations are down - cannot send packet");
+               goto fail;
+       }
+
        r->treq = treq; /* Remember for signalling purposes */
 
        talloc_set_destructor(u, _udp_request_free);
index c820987b3038bb14ed5457370a378b24e7e02bad..8e4877dfb7fcbda7d0d8bba2ec70cf31042f68fe 100644 (file)
@@ -1381,6 +1381,7 @@ static unlang_action_t mod_enqueue(rlm_rcode_t *p_result, void **rctx_out, UNUSE
        udp_result_t                    *r;
        udp_request_t                   *u;
        fr_trunk_request_t              *treq;
+       fr_trunk_enqueue_t              q;
 
        fr_assert(FR_TACACS_PACKET_CODE_VALID(request->packet->code));
 
@@ -1402,13 +1403,23 @@ static unlang_action_t mod_enqueue(rlm_rcode_t *p_result, void **rctx_out, UNUSE
 
        r->rcode = RLM_MODULE_FAIL;
 
-       if (fr_trunk_request_enqueue(&treq, t->trunk, request, u, r) < 0) {
+       q = fr_trunk_request_enqueue(&treq, t->trunk, request, u, r);
+       if (q < 0) {
                fr_assert(!u->packet);  /* Should not have been fed to the muxer */
                fr_trunk_request_free(&treq);           /* Return to the free list */
+       fail:
                talloc_free(r);
                RETURN_MODULE_FAIL;
        }
 
+       /*
+        *      All destinations are down.
+        */
+       if (q == FR_TRUNK_ENQUEUE_IN_BACKLOG) {
+               RDEBUG("All destinations are down - cannot send packet");
+               goto fail;
+       }
+
        r->treq = treq; /* Remember for signalling purposes */
 
        *rctx_out = r;