The FreeRADIUS server $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Loading...
Searching...
No Matches
rb_expire.c
Go to the documentation of this file.
1/*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
15 */
16
17/** Red/black expiry tree implementation
18 *
19 * @file src/lib/util/rb_expire.c
20 *
21 * @copyright 2024 Network RADIUS SAS (legal@networkradius.com)
22 */
23RCSID("$Id: f04eced2bbb595f01a1ea8080899f48242136449 $")
24
25#include <freeradius-devel/util/rb_expire.h>
26
27/** Attempt to find current data in the tree, if it does not exist insert it
28 *
29 * Any used node will be inserted into the tail of the expire list,
30 * and will expire at "now + expire->lifetime".
31 *
32 * @param[in] expire to search/insert into.
33 * @param[in] data to find.
34 * @param[in] now the current time
35 * @return
36 * - true if data was inserted.
37 * - false if data already existed and was not inserted.
38 */
40{
42 fr_rb_expire_node_t *re = (fr_rb_expire_node_t *) (((uintptr_t) entry) - offsetof(fr_rb_expire_node_t, entry));
43
44 if (!fr_rb_insert(&expire->tree, data)) {
45 fr_dlist_remove(&expire->head, entry);
46 }
47
49
50 re->when = fr_time_add_time_delta(now, expire->lifetime);
51
52 return true;
53}
54
56{
58 fr_rb_expire_node_t *re = (fr_rb_expire_node_t *) (((uintptr_t) entry) - offsetof(fr_rb_expire_node_t, entry));
59
60 fr_dlist_remove(&expire->head, data);
61
63 re->when = fr_time_add_time_delta(now, expire->lifetime);
64
65#if 0
66 /*
67 * Expire old entries.
68 */
70 re = (fr_rb_expire_node_t *) (((uintptr_t) old) - offsetof(fr_rb_expire_node_t, entry));
71
72 if (old->when > now) break;
73
74 fr_dlist_remove(&expire->head, &old->entry);
75
76 fr_rb_delete(&expire->tree, re);
77 }}
78#endif
79}
#define RCSID(id)
Definition build.h:483
static fr_dlist_t * fr_dlist_item_to_entry(size_t offset, void const *item)
Find the dlist pointers within a list item.
Definition dlist.h:122
unsigned int offset
Positive offset from start of structure to fr_dlist_t.
Definition dlist.h:55
static void * fr_dlist_remove(fr_dlist_head_t *list_head, void *ptr)
Remove an item from the list.
Definition dlist.h:638
static int fr_dlist_insert_tail(fr_dlist_head_t *list_head, void *ptr)
Insert an item into the tail of a list.
Definition dlist.h:378
fr_dlist_t entry
Struct holding the head and tail of the list.
Definition dlist.h:52
#define fr_dlist_foreach_safe(_list_head, _type, _iter)
Iterate over the contents of a list allowing for removals.
Definition dlist.h:108
Entry in a doubly linked list.
Definition dlist.h:41
bool fr_rb_insert(fr_rb_tree_t *tree, void const *data)
Insert data into a tree.
Definition rb.c:626
bool fr_rb_delete(fr_rb_tree_t *tree, void const *data)
Remove node and free data (if a free function was specified)
Definition rb.c:741
bool fr_rb_expire_insert(fr_rb_expire_t *expire, void *data, fr_time_t now)
Attempt to find current data in the tree, if it does not exist insert it.
Definition rb_expire.c:39
void fr_rb_expire_update(fr_rb_expire_t *expire, void *data, fr_time_t now)
Definition rb_expire.c:55
fr_dlist_head_t head
Definition rb_expire.h:35
fr_time_delta_t lifetime
Definition rb_expire.h:36
fr_rb_tree_t tree
Definition rb_expire.h:34
dlist for expiring old entries
Definition rb_expire.h:44
static fr_time_t fr_time_add_time_delta(fr_time_t a, fr_time_delta_t b)
Definition time.h:173
"server local" time.
Definition time.h:69
static fr_slen_t data
Definition value.h:1265