Skip to content

Commit

Permalink
track: We don't need to track num_free now the dlists have counters
Browse files Browse the repository at this point in the history
  • Loading branch information
arr2036 committed Apr 7, 2020
1 parent 277e69a commit f1dcefa
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/modules/rlm_radius/rlm_radius_udp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
19 changes: 8 additions & 11 deletions src/modules/rlm_radius/track.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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,
Expand All @@ -116,7 +112,10 @@ radius_track_entry_t *radius_track_entry_alloc(radius_track_t *tt, REQUEST *requ
* 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
Expand All @@ -129,9 +128,8 @@ radius_track_entry_t *radius_track_entry_alloc(radius_track_t *tt, REQUEST *requ
* 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));
}

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

Expand Down
3 changes: 1 addition & 2 deletions src/modules/rlm_radius/track.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit f1dcefa

Please sign in to comment.