#include <freeradius-devel/server/base.h>
#include <freeradius-devel/server/module.h>
#include <freeradius-devel/util/debug.h>
+#include <freeradius-devel/util/lst.h>
#include <freeradius-devel/unlang/base.h>
fr_network_t *nr; //!< network for the master socket
fr_trie_t *trie; //!< trie of clients
- fr_heap_t *pending_clients; //!< heap of pending clients
- fr_heap_t *alive_clients; //!< heap of active clients
+ fr_lst_t *pending_clients; //!< LST of pending clients
+ fr_lst_t *alive_clients; //!< LST of active clients
fr_listen_t *listen; //!< The master IO path
fr_listen_t *child; //!< The child (app_io) IO path
*
*/
typedef struct {
- int heap_id;
+ int lst_id;
uint32_t priority;
fr_time_t recv_time;
fr_io_track_t *track;
fr_event_timer_t const *ev; //!< when we clean up the client
fr_rb_tree_t *table; //!< tracking table for packets
- fr_heap_t *pending; //!< pending packets for this client
+ fr_lst_t *pending; //!< pending packets for this client
fr_hash_table_t *addresses; //!< list of src/dst addresses used by this client
pthread_mutex_t mutex; //!< for parent / child signaling
}
/*
- * Return negative numbers to put 'one' at the top of the heap.
- * Return positive numbers to put 'two' at the top of the heap.
+ * Return negative numbers to put 'one' at the top of the LST.
+ * Return positive numbers to put 'two' at the top of the LST.
*/
static int8_t pending_packet_cmp(void const *one, void const *two)
{
}
/*
- * Order clients in the pending_clients heap, based on the
+ * Order clients in the pending_clients LST, based on the
* packets that they contain.
*/
static int8_t pending_client_cmp(void const *one, void const *two)
fr_io_client_t const *c1 = talloc_get_type_abort_const(one, fr_io_client_t);
fr_io_client_t const *c2 = talloc_get_type_abort_const(two, fr_io_client_t);
- a = fr_heap_peek(c1->pending);
- b = fr_heap_peek(c2->pending);
+ a = fr_lst_peek(c1->pending);
+ b = fr_lst_peek(c2->pending);
fr_assert(a != NULL);
fr_assert(b != NULL);
fr_io_client_t *client;
fr_io_pending_packet_t *pending;
- client = fr_heap_pop(thread->pending_clients);
+ client = fr_lst_pop(thread->pending_clients);
if (!client) {
/*
* 99% of the time we don't have pending clients.
return NULL;
}
- pending = fr_heap_pop(client->pending);
+ pending = fr_lst_pop(client->pending);
fr_assert(pending != NULL);
/*
* If the client has more packets pending, add it back to
- * the heap.
+ * the LST.
*/
- if (fr_heap_num_elements(client->pending) > 0) {
- if (fr_heap_insert(thread->pending_clients, client) < 0) {
+ if (fr_lst_num_elements(client->pending) > 0) {
+ if (fr_lst_insert(thread->pending_clients, client) < 0) {
fr_assert(0 == 1);
}
}
connection->client->thread = thread;
/*
- * Create a heap for packets which are pending for this
+ * Create an LST for packets which are pending for this
* client.
*/
- MEM(connection->client->pending = fr_heap_alloc(connection->client, pending_packet_cmp,
- fr_io_pending_packet_t, heap_id));
+ MEM(connection->client->pending = fr_lst_alloc(connection->client, pending_packet_cmp,
+ fr_io_pending_packet_t, lst_id));
/*
* Clients for connected sockets are always a /32 or /128.
* Insert the pending packet for this client. If it
* fails, silently discard the packet.
*/
- if (fr_heap_insert(client->pending, pending) < 0) {
+ if (fr_lst_insert(client->pending, pending) < 0) {
talloc_free(pending);
return NULL;
}
{
fr_assert(client->in_trie);
fr_assert(!client->connection);
- fr_assert(fr_heap_num_elements(client->thread->alive_clients) > 0);
+ fr_assert(fr_lst_num_elements(client->thread->alive_clients) > 0);
if (client->pending) TALLOC_FREE(client->pending);
(void) fr_trie_remove_by_key(client->thread->trie, &client->src_ipaddr.addr, client->src_ipaddr.prefix);
- (void) fr_heap_extract(client->thread->alive_clients, client);
+ (void) fr_lst_extract(client->thread->alive_clients, client);
return 0;
}
return -1;
}
- pending = fr_heap_pop(connection->client->pending);
+ pending = fr_lst_pop(connection->client->pending);
} else if (thread->pending_clients) {
pending = pending_packet_pop(thread);
radclient->active = true;
} else if (inst->dynamic_clients) {
- if (inst->max_clients && (fr_heap_num_elements(thread->alive_clients) >= inst->max_clients)) {
+ if (inst->max_clients && ((uint32_t) fr_lst_num_elements(thread->alive_clients) >= inst->max_clients)) {
if (accept_fd < 0) {
DEBUG("proto_%s - ignoring packet from client IP address %pV - "
"too many dynamic clients are defined",
* Create the pending heap for pending clients.
*/
if (state == PR_CLIENT_PENDING) {
- MEM(client->pending = fr_heap_alloc(client, pending_packet_cmp,
- fr_io_pending_packet_t, heap_id));
+ MEM(client->pending = fr_lst_alloc(client, pending_packet_cmp,
+ fr_io_pending_packet_t, lst_id));
}
/*
* Track the live clients so that we can clean
* them up.
*/
- (void) fr_heap_insert(thread->alive_clients, client);
+ (void) fr_lst_insert(thread->alive_clients, client);
client->pending_id = -1;
/*
goto done;
}
- if (fr_heap_num_elements(client->pending) > 1) {
+ if (fr_lst_num_elements(client->pending) > 1) {
DEBUG("Client %pV is still being dynamically defined. "
"Caching this packet until the client has been defined",
fr_box_ipaddr(client->src_ipaddr));
* Count active packets AND pending packets.
*/
packets = client->packets;
- if (client->pending) packets += fr_heap_num_elements(client->pending);
+ if (client->pending) packets += fr_lst_num_elements(client->pending);
/*
* It's a negative cache entry. Just delete it.
fr_assert(inst->dynamic_clients);
fr_assert(client->pending != NULL);
- packets = client->packets + fr_heap_num_elements(client->pending);
+ packets = client->packets + fr_lst_num_elements(client->pending);
/*
*
*/
if (!thread->pending_clients) {
- MEM(thread->pending_clients = fr_heap_alloc(thread, pending_client_cmp,
+ MEM(thread->pending_clients = fr_lst_alloc(thread, pending_client_cmp,
fr_io_client_t, pending_id));
}
fr_assert(client->pending_id < 0);
- (void) fr_heap_insert(thread->pending_clients, client);
+ (void) fr_lst_insert(thread->pending_clients, client);
finish:
/*
* least one), tell the network socket to call our read()
* function again.
*/
- if (fr_heap_num_elements(client->pending) > 0) {
+ if (fr_lst_num_elements(client->pending) > 0) {
if (connection) {
fr_network_listen_read(connection->nr, connection->listen);
} else {
* Note that the clients *also* use thread->trie, so we
* have to free the clients *before* freeing thread->trie.
*/
- while ((client = fr_heap_peek(thread->alive_clients)) != NULL) {
+ while ((client = fr_lst_peek(thread->alive_clients)) != NULL) {
talloc_free(client);
}
* Create the trie of clients for this socket.
*/
MEM(thread->trie = fr_trie_alloc(thread, NULL, NULL));
- MEM(thread->alive_clients = fr_heap_alloc(thread, alive_client_cmp,
+ MEM(thread->alive_clients = fr_lst_alloc(thread, alive_client_cmp,
fr_io_client_t, alive_id));
/*