uint8_t *buffer; //!< Receive buffer.
size_t buflen; //!< Receive buffer length.
- rlm_radius_id_t *id; //!< RADIUS ID tracking structure.
+ radius_track_t *tt; //!< RADIUS ID tracking structure.
fr_time_t mrs_time; //!< Most recent sent time which had a reply.
fr_time_t last_reply; //!< When we last received a reply.
size_t packet_len; //!< Length of the packet.
udp_connection_t *c; //!< The outbound connection
- rlm_radius_request_t *rr; //!< ID tracking, resend count, etc.
+ radius_track_entry_t *rr; //!< ID tracking, resend count, etc.
fr_event_timer_t const *ev; //!< timer for retransmissions
fr_retry_t retry; //!< retransmission timers
};
MEM(h->buffer = talloc_array(h, uint8_t, h->max_packet_size));
h->buflen = h->max_packet_size;
- MEM(h->id = rr_track_create(h));
+ MEM(h->tt = radius_track_alloc(h));
/*
* Open the outgoing socket.
* demand. If the proxied packets use all of the
* IDs, then we can't send a Status-Server check.
*/
- u->rr = rr_track_alloc(h->id, request, u->code, u);
+ u->rr = radius_track_entry_alloc(h->tt, request, u->code, u);
if (!u->rr) {
ERROR("%s - Failed allocating status_check ID for connection %s",
h->module_name, h->name);
* Remember the authentication vector, which now has the
* packet signature.
*/
- (void) rr_track_update(h->id, u->rr, h->buffer + 4);
+ (void) radius_track_update(h->tt, u->rr, h->buffer + 4);
RDEBUG("Sending %s ID %d length %ld over connection %s",
fr_packet_codes[u->code], u->rr->id, packet_len, h->name);
{
if (!now) now = fr_time();
- if (u->rr) (void) rr_track_delete(h->id, u->rr);
- if (h->id->num_free == (h->status_u != NULL)) h->last_idle = now;
+ if (u->rr) (void) radius_track_delete(h->tt, u->rr);
+ if (h->tt->num_free == (h->status_u != NULL)) h->last_idle = now;
u->rr = NULL;
fr_pair_list_free(&u->extra);
}
* If it's an initial packet, allocate the ID.
*/
if (!u->rr) {
- u->rr = rr_track_alloc(h->id, request, u->code, treq);
+ u->rr = radius_track_entry_alloc(h->tt, request, u->code, treq);
if (!u->rr) {
fail:
u->c = NULL;
* calling a complex API.
*/
if (inst->replicate) {
- (void) rr_track_delete(h->id, u->rr); /* don't set last_idle, we're not checking for zombie */
+ (void) radius_track_delete(h->tt, u->rr); /* don't set last_idle, we're not checking for zombie */
u->rr = NULL;
r->rcode = RLM_MODULE_OK;
fr_trunk_request_signal_complete(treq);
REQUEST *request;
ssize_t data_len;
size_t packet_len;
- rlm_radius_request_t *rr;
+ radius_track_entry_t *rr;
decode_fail_t reason;
int code;
VALUE_PAIR *reply, *vp;
* Note that we don't care about packet codes. All
* packet codes share the same ID space.
*/
- rr = rr_track_find(h->id, h->buffer[1], NULL);
+ rr = radius_track_find(h->tt, h->buffer[1], NULL);
if (!rr) {
WARN("%s - Ignoring reply which arrived too late", h->module_name);
return NULL;
#include "track.h"
#include "rlm_radius.h"
-/** Create an rlm_radius_id_t
+/** Create an radius_track_t
*
* @param ctx the talloc ctx
* @return
* - NULL on error
- * - rlm_radius_id_t on success
+ * - radius_track_t on success
*/
-rlm_radius_id_t *rr_track_create(TALLOC_CTX *ctx)
+radius_track_t *radius_track_alloc(TALLOC_CTX *ctx)
{
int i;
- rlm_radius_id_t *id;
+ radius_track_t *tt;
- id = talloc_zero(ctx, rlm_radius_id_t);
- if (!id) return NULL;
+ MEM(tt = talloc_zero(ctx, radius_track_t));
- fr_dlist_init(&id->free_list, rlm_radius_request_t, entry);
+ fr_dlist_init(&tt->free_list, radius_track_entry_t, entry);
for (i = 0; i < 256; i++) {
- id->id[i].id = i;
- fr_dlist_insert_tail(&id->free_list, &id->id[i]);
- id->num_free++;
+ tt->id[i].id = i;
+ fr_dlist_insert_tail(&tt->free_list, &tt->id[i]);
+ tt->num_free++;
}
- id->next_id = fr_rand() & 0xff;
+ tt->next_id = fr_rand() & 0xff;
- return id;
+ return tt;
}
-/** Compare two rlm_radius_request_t
+/** Compare two radius_track_entry_t
*
*/
-static int rr_cmp(void const *one, void const *two)
+static int te_cmp(void const *one, void const *two)
{
- rlm_radius_request_t const *a = one;
- rlm_radius_request_t const *b = two;
+ radius_track_entry_t const *a = one;
+ radius_track_entry_t const *b = two;
return memcmp(a->vector, b->vector, sizeof(a->vector));
}
/** Allocate a tracking entry.
*
- * @param[in] id The rlm_radius_id_t tracking table.
+ * @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
* @return
* - NULL on error
- * - rlm_radius_request_t on success
+ * - radius_track_entry_t on success
*/
-rlm_radius_request_t *rr_track_alloc(rlm_radius_id_t *id, REQUEST *request, int code,
- void *rctx)
+radius_track_entry_t *radius_track_entry_alloc(radius_track_t *tt, REQUEST *request, uint8_t code, void *rctx)
{
- rlm_radius_request_t *rr;
+ radius_track_entry_t *te;
retry:
- rr = fr_dlist_head(&id->free_list);
- if (rr) {
- rad_assert(id->num_free > 0);
+ te = fr_dlist_head(&tt->free_list);
+ if (te) {
+ rad_assert(tt->num_free > 0);
- rad_assert(rr->request == NULL);
+ rad_assert(te->request == NULL);
/*
* Mark it as used, and remove it from the free list.
*/
- fr_dlist_remove(&id->free_list, rr);
- id->num_free--;
+ fr_dlist_remove(&tt->free_list, te);
+ tt->num_free--;
/*
* We've transitioned from "use it", to "oops,
* don't use it". Ensure that we only return IDs
* which are in the static array.
*/
- if (!id->use_authenticator &&
- (rr != &id->id[rr->id])) {
- talloc_free(rr);
+ if (!tt->use_authenticator &&
+ (te != &tt->id[te->id])) {
+ talloc_free(te);
goto retry;
}
* There are no free entries, and we can't use the
* Request Authenticator. Oh well...
*/
- if (!id->use_authenticator) return NULL;
+ if (!tt->use_authenticator) return NULL;
/*
* Get a new ID. It's value doesn't matter at this
* point.
*/
- id->next_id++;
- id->next_id &= 0xff;
+ tt->next_id++;
+ tt->next_id &= 0xff;
/*
* If needed, allocate a subtree.
*/
- if (!id->subtree[id->next_id]) {
- id->subtree[id->next_id] = rbtree_talloc_create(id, rr_cmp, rlm_radius_request_t,
+ 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 (!id->subtree[id->next_id]) return NULL;
+ if (!tt->subtree[tt->next_id]) return NULL;
}
/*
* Allocate a new one, and insert it into the appropriate subtree.
*/
- rr = talloc_zero(id, rlm_radius_request_t);
- rr->id = id->next_id;
+ te = talloc_zero(tt, radius_track_entry_t);
+ te->id = tt->next_id;
done:
- rr->request = request;
- rr->rctx = rctx;
+ te->request = request;
+ te->rctx = rctx;
- rr->code = code;
+ te->code = code;
/*
- * rr->id is already allocated
+ * te->id is already allocated
*/
- id->num_requests++;
- return rr;
+ tt->num_requests++;
+ return te;
}
/** Update a tracking entry with the authentication vector
*
- * @param id The rlm_radius_id_t tracking table
- * @param rr The rlm_radius_request_t, via rr_track_alloc()
+ * @param tt The radius_track_t tracking table
+ * @param te The radius_track_entry_t, via radius_track_entry_alloc()
* @param vector The authentication vector for the packet we're sending
* @return
* - <0 on error
* - 0 on success
*/
-int rr_track_update(rlm_radius_id_t *id, rlm_radius_request_t *rr, uint8_t *vector)
+int radius_track_update(radius_track_t *tt, radius_track_entry_t *te, uint8_t *vector)
{
/*
* The authentication vector may have changed.
*/
- if (id->subtree[rr->id]) (void) rbtree_deletebydata(id->subtree[rr->id], rr);
+ if (tt->subtree[te->id]) (void) rbtree_deletebydata(tt->subtree[te->id], te);
- memcpy(rr->vector, vector, sizeof(rr->vector));
+ memcpy(te->vector, vector, sizeof(te->vector));
/*
* If we're not using the Request Authenticator, the
*
* @todo - gracefully handle fallback if the server screws up.
*/
- if (!id->use_authenticator) {
- rad_assert(rr == &id->id[rr->id]);
+ if (!tt->use_authenticator) {
+ rad_assert(te == &tt->id[te->id]);
return 0;
}
* array. That way if the server responds with
* Original-Request-Authenticator, we can easily find it.
*/
- if (!rbtree_insert(id->subtree[rr->id], rr)) {
- return -1;
- }
+ if (!rbtree_insert(tt->subtree[te->id], te)) return -1;
return 0;
}
/** Delete a tracking entry
*
- * @param id The rlm_radius_id_t tracking table
- * @param rr The rlm_radius_request_t, via rr_track_alloc()
+ * @param tt The radius_track_t tracking table
+ * @param te The radius_track_entry_t, via radius_track_entry_alloc()
* @return
* - <0 on error
* - 0 on success
*/
-int rr_track_delete(rlm_radius_id_t *id, rlm_radius_request_t *rr)
+int radius_track_delete(radius_track_t *tt, radius_track_entry_t *te)
{
- (void) talloc_get_type_abort(id, rlm_radius_id_t);
+ (void) talloc_get_type_abort(tt, radius_track_t);
- rr->request = NULL;
+ te->request = NULL;
- rad_assert(id->num_requests > 0);
- id->num_requests--;
+ rad_assert(tt->num_requests > 0);
+ tt->num_requests--;
/*
* We're freeing a static ID, just go do that...
*/
- if (rr == &id->id[rr->id]) {
+ if (te == &tt->id[te->id]) {
/*
* This entry MAY be in a subtree. If so, delete
* it.
*/
- if (id->subtree[rr->id]) (void) rbtree_deletebydata(id->subtree[rr->id], rr);
+ if (tt->subtree[te->id]) (void) rbtree_deletebydata(tt->subtree[te->id], te);
goto done;
}
/*
* At this point, it MUST be talloc'd.
*/
- (void) talloc_get_type_abort(rr, rlm_radius_request_t);
+ (void) talloc_get_type_abort(te, radius_track_entry_t);
/*
* Delete it from the tracking subtree.
*/
- rad_assert(id->subtree[rr->id] != NULL);
- (void) rbtree_deletebydata(id->subtree[rr->id], rr);
+ rad_assert(tt->subtree[te->id] != NULL);
+ (void) rbtree_deletebydata(tt->subtree[te->id], te);
/*
* Try to free memory if the system gets idle. If the
* free list. If the system becomes completely idle, we
* will clear the free list.
*/
- if (id->num_free > id->num_requests) {
- talloc_free(rr);
+ if (tt->num_free > tt->num_requests) {
+ talloc_free(te);
return 0;
}
* Otherwise put it back on the free list.
*/
done:
- fr_dlist_insert_tail(&id->free_list, rr);
- id->num_free++;
+ fr_dlist_insert_tail(&tt->free_list, te);
+ tt->num_free++;
return 0;
}
/** Find a tracking entry from a request authenticator
*
- * @param id The rlm_radius_id_t tracking table
+ * @param tt The radius_track_t tracking table
* @param packet_id The ID from the RADIUS header
* @param vector The Request Authenticator (may be NULL)
* @return
* - NULL on "not found"
- * - rlm_radius_request_t on success
+ * - radius_track_entry_t on success
*/
-rlm_radius_request_t *rr_track_find(rlm_radius_id_t *id, int packet_id, uint8_t *vector)
+radius_track_entry_t *radius_track_find(radius_track_t *tt, uint8_t packet_id, uint8_t *vector)
{
- rlm_radius_request_t my_rr, *rr;
-
- (void) talloc_get_type_abort(id, rlm_radius_id_t);
+ radius_track_entry_t my_te, *te;
- /*
- * Screw you guys, I'm going home!
- */
- if (packet_id > 255) return NULL;
+ (void) talloc_get_type_abort(tt, radius_track_t);
/*
* Just use the static array.
*/
- if (!id->use_authenticator || !vector) {
- rr = &id->id[packet_id];
+ if (!tt->use_authenticator || !vector) {
+ te = &tt->id[packet_id];
/*
* Not in use, die.
*/
- if (!rr->request) return NULL;
+ if (!te->request) return NULL;
/*
* Ignore the Request Authenticator, as the
* caller doesn't have it.
*/
- return rr;
+ return te;
}
/*
* The entry MAY be in the subtree!
*/
- memcpy(&my_rr.vector, vector, sizeof(my_rr.vector));
+ memcpy(&my_te.vector, vector, sizeof(my_te.vector));
- rr = rbtree_finddata(id->subtree[packet_id], &my_rr);
+ te = rbtree_finddata(tt->subtree[packet_id], &my_te);
/*
* Not found, the packet MAY have been allocated in the
* old-style method prior to negotiation of
* Original-Request-Identifier.
*/
- if (!rr) {
- rr = &id->id[packet_id];
+ if (!te) {
+ te = &tt->id[packet_id];
/*
* Not in use, die.
*/
- if (!rr->request) return NULL;
+ if (!te->request) return NULL;
// @todo - add a "generation" count for packets, so we can skip this after all outstanding packets
// are using the new method. Hmm... probably just a timer "last sent packet with old-style"
- // and then compare it to rr->start
+ // and then compare it to te->start
/*
* We have the vector, so we need to check it.
*/
- if (memcmp(rr->vector, vector, sizeof(rr->vector)) != 0) {
+ if (memcmp(te->vector, vector, sizeof(te->vector)) != 0) {
return NULL;
}
- return rr;
+ return te;
}
- (void) talloc_get_type_abort(rr, rlm_radius_request_t);
- rad_assert(rr->request != NULL);
+ (void) talloc_get_type_abort(te, radius_track_entry_t);
+ rad_assert(te->request != NULL);
- return rr;
+ return te;
}
/** Use Request Authenticator (or not) as an Identifier
*
- * @param id The rlm_radius_id_t tracking table
+ * @param tt The radius_track_t tracking table
* @param flag Whether or not to use it.
*/
-void rr_track_use_authenticator(rlm_radius_id_t *id, bool flag)
+void radius_track_use_authenticator(radius_track_t *tt, bool flag)
{
- (void) talloc_get_type_abort(id, rlm_radius_id_t);
+ (void) talloc_get_type_abort(tt, radius_track_t);
- id->use_authenticator = flag;
+ tt->use_authenticator = flag;
}
*
*/
typedef struct {
- REQUEST *request; //!< as always...
- void *rctx;
+ REQUEST *request; //!< as always...
+ void *rctx; //!< Result/resumption context.
- int code; //!< packet code (sigh)
- int id; //!< our ID
+ uint8_t code; //!< packet code (sigh)
+ uint8_t id; //!< our ID
union {
fr_dlist_t entry; //!< for free chain
uint8_t vector[16]; //!< copy of the authentication vector
};
-} rlm_radius_request_t;
+} radius_track_entry_t;
typedef struct {
- int num_requests; //!< number of requests in the allocation
- int num_free; //!< number of entries in the free list
+ int num_requests; //!< number of requests in the allocation
+ int num_free; //!< number of entries in the free list
- fr_dlist_head_t free_list; //!< so we allocate by least recently used
+ fr_dlist_head_t free_list; //!< so we allocate by least recently used
- bool use_authenticator; //!< whether to use the request authenticator as an ID
- int next_id; //!< next ID to allocate
+ bool use_authenticator; //!< whether to use the request authenticator as an ID
+ int next_id; //!< next ID to allocate
- rlm_radius_request_t id[256]; //!< which ID was used
+ radius_track_entry_t id[256]; //!< which ID was used
- rbtree_t *subtree[256]; //!< for Original-Request-Authenticator
-} rlm_radius_id_t;
+ rbtree_t *subtree[256]; //!< for Original-Request-Authenticator
+} radius_track_t;
-rlm_radius_id_t *rr_track_create(TALLOC_CTX *ctx);
-rlm_radius_request_t *rr_track_alloc(rlm_radius_id_t *id, REQUEST *request, int code,
- void *rctx) CC_HINT(nonnull);
-int rr_track_update(rlm_radius_id_t *id, rlm_radius_request_t *rr, uint8_t *vector) CC_HINT(nonnull);
-rlm_radius_request_t *rr_track_find(rlm_radius_id_t *id, int packet_id, uint8_t *vector) CC_HINT(nonnull(1));
-int rr_track_delete(rlm_radius_id_t *id, rlm_radius_request_t *rr) CC_HINT(nonnull);
-void rr_track_use_authenticator(rlm_radius_id_t *id, bool flag) CC_HINT(nonnull);
+radius_track_t *radius_track_alloc(TALLOC_CTX *ctx);
+
+radius_track_entry_t *radius_track_entry_alloc(radius_track_t *id, REQUEST *request, uint8_t code, void *rctx) CC_HINT(nonnull);
+
+int radius_track_update(radius_track_t *id, radius_track_entry_t *rr, uint8_t *vector) CC_HINT(nonnull);
+
+radius_track_entry_t *radius_track_find(radius_track_t *id, uint8_t packet_id, uint8_t *vector) CC_HINT(nonnull(1));
+
+int radius_track_delete(radius_track_t *id, radius_track_entry_t *rr) CC_HINT(nonnull);
+
+void radius_track_use_authenticator(radius_track_t *id, bool flag) CC_HINT(nonnull);