]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
track: We don't need to track num_free now the dlists have counters
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Tue, 7 Apr 2020 22:18:10 +0000 (17:18 -0500)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Tue, 7 Apr 2020 22:18:10 +0000 (17:18 -0500)
src/modules/rlm_radius/rlm_radius_udp.c
src/modules/rlm_radius/track.c
src/modules/rlm_radius/track.h

index 6d2c0a4675932f9d44b7ce41adf8540408de307d..4fc3b42c92c05db6c6e570dc06464a5090541495 100644 (file)
@@ -277,7 +277,7 @@ static void udp_request_clear(udp_handle_t *h, udp_request_t *u, fr_time_t now)
        if (u->rr) (void) radius_track_delete(&u->rr);
 
        /* Now wrong - We don't keep an entry reserved for the status check */
-       if (h && (h->tt->num_free == (h->status_u != NULL))) h->last_idle = now;
+       if (h && (fr_dlist_num_elements(&h->tt->free_list) == (h->status_u != NULL))) h->last_idle = now;
 
        fr_pair_list_free(&u->extra);
 }
index 1ca2f6824e445987a958ef98111d6b0914740e35..c9cedf9de4060fa643d10bb35d89ce9987cfac81 100644 (file)
@@ -51,7 +51,6 @@ radius_track_t *radius_track_alloc(TALLOC_CTX *ctx)
        for (i = 0; i < 256; i++) {
                tt->id[i].id = i;
                fr_dlist_insert_tail(&tt->free_list, &tt->id[i]);
-               tt->num_free++;
        }
 
        tt->next_id = fr_rand() & 0xff;
@@ -76,7 +75,7 @@ static int te_cmp(void const *one, void const *two)
  * @param[in] tt               The radius_track_t tracking table.
  * @param[in] request          The request which will send the proxied packet.
  * @param[in] code             Of the outbound request.
- * @param rctx The context to associate with the request
+ * @param[in] rctx             The context to associate with the request
  * @return
  *     - NULL on error
  *     - radius_track_entry_t on success
@@ -88,15 +87,12 @@ radius_track_entry_t *radius_track_entry_alloc(radius_track_t *tt, REQUEST *requ
 retry:
        te = fr_dlist_head(&tt->free_list);
        if (te) {
-               rad_assert(tt->num_free > 0);
-
                rad_assert(te->request == NULL);
 
                /*
                 *      Mark it as used, and remove it from the free list.
                 */
                fr_dlist_remove(&tt->free_list, te);
-               tt->num_free--;
 
                /*
                 *      We've transitioned from "use it", to "oops,
@@ -116,7 +112,10 @@ retry:
         *      There are no free entries, and we can't use the
         *      Request Authenticator.  Oh well...
         */
-       if (!tt->use_authenticator) return NULL;
+       if (!tt->use_authenticator) {
+               fr_strerror_printf("No free entries");
+               return NULL;
+       }
 
        /*
         *      Get a new ID.  It's value doesn't matter at this
@@ -129,9 +128,8 @@ retry:
         *      If needed, allocate a subtree.
         */
        if (!tt->subtree[tt->next_id]) {
-               tt->subtree[tt->next_id] = rbtree_talloc_create(tt, te_cmp, radius_track_entry_t,
-                                                               NULL, RBTREE_FLAG_NONE);
-               if (!tt->subtree[tt->next_id]) return NULL;
+               MEM(tt->subtree[tt->next_id] = rbtree_talloc_create(tt, te_cmp, radius_track_entry_t,
+                                                                   NULL, RBTREE_FLAG_NONE));
        }
 
        /*
@@ -245,7 +243,7 @@ int radius_track_delete(radius_track_entry_t **te_to_free)
         *      free list.  If the system becomes completely idle, we
         *      will clear the free list.
         */
-       if (tt->num_free > tt->num_requests) {
+       if (fr_dlist_num_elements(&tt->free_list) > tt->num_requests) {
                talloc_free(te);
                *te_to_free = NULL;
                return 0;
@@ -256,7 +254,6 @@ int radius_track_delete(radius_track_entry_t **te_to_free)
         */
 done:
        fr_dlist_insert_tail(&tt->free_list, te);
-       tt->num_free++;
 
        *te_to_free = NULL;
 
index d86383b5776d8dc1cfc929293d4416220d03791a..24873c79a6a191d9dd42c153449ef80295830ab8 100644 (file)
@@ -48,8 +48,7 @@ struct radius_track_entry_s {
 };
 
 struct radius_track_s {
-       int             num_requests;           //!< number of requests in the allocation
-       int             num_free;               //!< number of entries in the free list
+       unsigned int    num_requests;           //!< number of requests in the allocation
 
        fr_dlist_head_t free_list;              //!< so we allocate by least recently used