Skip to content

Commit 4e777e0

Browse files
authored
Merge pull request #2382 from MorganaFuture/morgana/fix/LRU-list-in-get_fingerprint_rates-is-not-updated-for-existing-entries
fix: LRU list in get_fingerprint_rates is not updated for existing en…
2 parents d8e5920 + 1a323cb commit 4e777e0

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

fw/ja5_filter.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -120,21 +120,21 @@ get_fingerprint_rates(Storage *storage, u64 fingerprint)
120120

121121
/* Try to remove DB_RECS_TO_FREE_CNT records from DB if it's full */
122122
while (!(rec = tdb_rec_get_alloc(storage->tdb, key, &get_alloc_ctx))) {
123-
struct list_head *pos, *tmp, tail_to_delete;
123+
struct list_head *pos, *tmp, head_to_delete;
124124
u32 cnt = DB_RECS_TO_FREE_CNT;
125125

126-
INIT_LIST_HEAD(&tail_to_delete);
126+
INIT_LIST_HEAD(&head_to_delete);
127127

128128
/* Cut off DB_RECS_TO_FREE_CNT entries from the LRU list */
129129
spin_lock(&storage->lru_list_lock);
130-
list_for_each_prev_safe(pos, tmp, &storage->lru_list) {
131-
list_move(pos, &tail_to_delete);
130+
list_for_each_safe(pos, tmp, &storage->lru_list) {
131+
list_move(pos, &head_to_delete);
132132
if (!--cnt)
133133
break;
134134
}
135135
spin_unlock(&storage->lru_list_lock);
136136

137-
list_for_each_safe(pos, tmp, &tail_to_delete) {
137+
list_for_each_safe(pos, tmp, &head_to_delete) {
138138
u64 key = ((TdbRec *)pos - 1)->key;
139139
/* TODO: remove directly by record bypassing search by key */
140140
tdb_entry_remove(storage->tdb, key, NULL, NULL, true);
@@ -150,9 +150,13 @@ get_fingerprint_rates(Storage *storage, u64 fingerprint)
150150
rates = (Rates *)rec->data;
151151

152152
spin_lock(&storage->lru_list_lock);
153-
/* The record still was not added to the LRU list */
154-
if (list_empty(&rates->list_node))
153+
if (list_empty(&rates->list_node)) {
154+
/* Entry is new or was somehow removed from list, add it to tail (MRU) */
155155
list_add_tail(&rates->list_node, &storage->lru_list);
156+
} else {
157+
/* Entry already exists and is in the list, move it to tail (MRU) */
158+
list_move_tail(&rates->list_node, &storage->lru_list);
159+
}
156160
spin_unlock(&storage->lru_list_lock);
157161

158162
return rates;

0 commit comments

Comments
 (0)