#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "sfxhash.h"
Go to the source code of this file.
|
Definition at line 142 of file sfxhash.c. References isPrime(). |
|
|
|
Definition at line 513 of file sfxhash.c. References _sfxhash_node::rindex, sfxhash_gmovetofront(), sfxhash_link_node(), sfxhash_unlink_node(), and _sfxhash::table. |
|
Definition at line 87 of file sfxhash.c. References _sfxhash::mc, and sfmemcap_free(). |
|
A Customized hash table library for storing and accessing key + data pairs. This table incorporates a memory manager (memcap.c) to provide a memory cap, and an automatic node recovery system for out of memory management. Keys and Data are copied into the hash table during the add operation. The data may be allocated and free'd by the user (by setting the datasize to zero ). A user callback is provided to allow the user to do cleanup whenever a node is released, by either the ANR system or the relase() function. Users can and should delete nodes when they know they are not needed anymore, but this custom table is designed for the case where nodes are allocated permanently, we have to limit memory, and we wish to recycle old nodes. Many problems have a natural node ageing paradigm working in our favor, so automated node aging makes sense. i.e. thresholding, tcp state. This hash table maps keys to data. All keys must be unique. Uniqueness is enforcedby the code. Features: 1) Keys must be fixed length (per table) binary byte sequences. keys are copied during the add function 2) Data must be fixed length (per table) binary byte sequences. data is copied during the add function - if datasize > 0 Data may be managed by the user as well. 3) Table row sizes can be automatically adjusted to the nearest prime number size during table initialization/creation. 4) Memory management includes tracking the size of each allocation, number of allocations, enforcing a memory cap, and automatic node recovery - when memory is low the oldest untouched node is unlinked and recycled for use as a new node. Per Node Memory Usage: ---------------------- SFXHASH_NODE bytes KEYSIZE bytes [DATASIZE bytes] if datasize > 0 during call to sfxhash_new. The hash node memory (sfxhash_node,key,and data) is allocated with one call to s_malloc/memcap_alloc. Copyright (C) 2001 Marc A Norton. Copyright (C) 2003 Sourcefire,Inc. 2003-06-03: cmg - added sfxhash_{l,m}ru to return {least,most} recently used node from the global list
2003-06-11: cmg added overhead_bytes + blocks to separate out the memcap constraints from the hash table itself find success v fail 2003-06-19: cmg added ability to set own hash function ability to set own key cmp function 2003-06-30: rdempster fixed bug in that would anr from the freelist 2005-11-15: modified sfxhash_add to check if 'data' is zero before memcpy'ing. this allows user to pass null for data, and set up the data area themselves after the call - this is much more flexible. Definition at line 82 of file sfxhash.c. References _sfxhash::mc, and sfmemcap_alloc(). |
|
Add a key + data pair to the hash table 2003-06-06:
This is done because of the successful find.
Definition at line 654 of file sfxhash.c. References _sfxhash::cnode, _sfxhash::count, _sfxhash_node::data, _sfxhash::datasize, index, _sfxhash_node::key, _sfxhash::keysize, memcpy, _sfxhash_node::rindex, sfxhash_find_node_row(), sfxhash_glink_node(), SFXHASH_INTABLE, sfxhash_link_node(), sfxhash_newnode(), SFXHASH_NOMEM, and SFXHASH_OK. Referenced by flowcache_newflow(), Frag3NewTracker(), ps_tracker_get(), scoreboard_add(), server_stats_add_ipv4(), server_stats_load(), sfthd_test_gobject(), sfthd_test_object(), and ut_check(). |
|
Definition at line 95 of file sfxhash.c. References s_malloc(). |
|
Get the # auto recovery
Definition at line 318 of file sfxhash.c. References _sfxhash::anr_count. Referenced by flowcache_stats(), scoreboard_stats(), server_stats(), and ut_stats(). |
|
Get the # of Nodes in HASH the table
Definition at line 307 of file sfxhash.c. References _sfxhash::count. Referenced by CleanHashTable(), flowcache_stats(), Frag3Defrag(), Frag3GetTracker(), PrintSessionCache(), scoreboard_stats(), server_stats(), and ut_stats(). |
|
Delete the hash Table free key's, free node's, and free the users data.
Definition at line 269 of file sfxhash.c. References _sfxhash_node::data, _sfxhash_node::key, _sfxhash_node::next, _sfxhash::nrows, s_free(), _sfxhash::sfhashfcn, sfhashfcn_free(), _sfxhash::table, and _sfxhash::usrfree. Referenced by flowcache_destroy(), flowcache_init(), scoreboard_destroy(), server_stats_destroy(), server_stats_init(), and ut_destroy(). |
|
Find the users data based associated with the key
Definition at line 817 of file sfxhash.c. References _sfxhash_node::data, NULL, and sfxhash_find_node_row(). Referenced by flowcache_find(), Frag3GetTracker(), ps_tracker_get(), scoreboard_find(), and server_stats_hitcount_ipv4(). |
|
Get the # unsucessful finds
Definition at line 340 of file sfxhash.c. References _sfxhash::find_fail. Referenced by scoreboard_stats(), server_stats(), and ut_stats(). |
|
Find a Node based on the key
Definition at line 800 of file sfxhash.c. References sfxhash_find_node_row(). Referenced by GetSessionFromHashTable(). |
|
Definition at line 600 of file sfxhash.c. References _sfxhash::find_fail, _sfxhash::find_success, _SFHASHFCN::hash_fcn, index, _sfxhash_node::key, _SFHASHFCN::keycmp_fcn, _sfxhash::keysize, movetofront(), _sfxhash_node::next, _sfxhash::nrows, NULL, _sfxhash::sfhashfcn, _sfxhash::splay, and _sfxhash::table. Referenced by sfxhash_add(), sfxhash_find(), sfxhash_find_node(), and sfxhash_get_node(). |
|
Get the # sucessful finds
Definition at line 351 of file sfxhash.c. References _sfxhash::find_success. Referenced by scoreboard_stats(), server_stats(), and ut_stats(). |
|
Get the # finds
Definition at line 329 of file sfxhash.c. References _sfxhash::find_fail, and _sfxhash::find_success. Referenced by scoreboard_stats(), server_stats(), and ut_stats(). |
|
Find and return the first hash table node
Definition at line 1079 of file sfxhash.c. References _sfxhash::cnode, _sfxhash::crow, _sfxhash::nrows, NULL, sfxhash_next(), and _sfxhash::table. |
|
Find and return the next hash table node
Definition at line 1108 of file sfxhash.c. References _sfxhash::cnode, NULL, and sfxhash_next(). |
|
Definition at line 99 of file sfxhash.c. References s_free(). |
|
Definition at line 984 of file sfxhash.c. References _sfxhash::count, _sfxhash_node::data, _sfxhash_node::key, _sfxhash::recycle_nodes, s_free(), sfxhash_gunlink_node(), SFXHASH_OK, sfxhash_save_free_node(), sfxhash_unlink_node(), and _sfxhash::usrfree. Referenced by Frag3Expire(), and sfxhash_remove(). |
|
Definition at line 405 of file sfxhash.c. References _sfxhash::fhead, _sfxhash::ftail, _sfxhash_node::gnext, and _sfxhash_node::gprev. Referenced by sfxhash_newnode(). |
|
Add a key to the hash table, return the hash node 2003-06-06:
This is done because of the successful find.
Definition at line 733 of file sfxhash.c. References _sfxhash::cnode, _sfxhash::count, _sfxhash_node::data, _sfxhash::datasize, index, _sfxhash_node::key, _sfxhash::keysize, memcpy, NULL, _sfxhash_node::rindex, sfxhash_find_node_row(), sfxhash_glink_node(), sfxhash_link_node(), and sfxhash_newnode(). Referenced by flowcache_newflow(), Frag3NewTracker(), and GetNewSession(). |
|
Get the HEAD of the in use list
Definition at line 837 of file sfxhash.c. References _sfxhash::ghead, and NULL. Referenced by scoreboard_dump(), server_stats_dump(), server_stats_save(), sfxhash_mru(), sfxhash_mru_node(), and unique_tracker_dump(). |
|
Definition at line 424 of file sfxhash.c. References _sfxhash::ghead, _sfxhash_node::gnext, _sfxhash_node::gprev, and _sfxhash::gtail. Referenced by sfxhash_add(), sfxhash_get_node(), and sfxhash_gmovetofront(). |
|
Definition at line 462 of file sfxhash.c. References _sfxhash::ghead, sfxhash_glink_node(), and sfxhash_gunlink_node(). Referenced by CleanHashTable(), Frag3Prune(), and movetofront(). |
|
Walk the global list
Definition at line 855 of file sfxhash.c. References _sfxhash_node::gnext, and NULL. Referenced by scoreboard_dump(), server_stats_dump(), server_stats_save(), and unique_tracker_dump(). |
|
Definition at line 445 of file sfxhash.c. References _sfxhash::ghead, _sfxhash_node::gnext, _sfxhash_node::gprev, and _sfxhash::gtail. Referenced by sfxhash_free_node(), sfxhash_gmovetofront(), and sfxhash_newnode(). |
|
Definition at line 475 of file sfxhash.c. References _sfxhash_node::next, _sfxhash_node::prev, _sfxhash_node::rindex, and _sfxhash::table. Referenced by movetofront(), sfxhash_add(), and sfxhash_get_node(). |
|
Return the least recently used data from the global list
Definition at line 896 of file sfxhash.c. References _sfxhash_node::data, _sfxhash::gtail, and NULL. Referenced by CleanHashTable(), flowcache_lru(), Frag3Expire(), and scoreboard_lru(). |
|
Return the least recently used node from the global list
Definition at line 937 of file sfxhash.c. References _sfxhash::gtail, and NULL. Referenced by CleanHashTable(), Frag3Expire(), and Frag3Prune(). |
|
Get some hash table statistics. NOT FOR REAL TIME USE.
Definition at line 958 of file sfxhash.c. References _sfxhash_node::next, _sfxhash::nrows, NULL, and _sfxhash::table. Referenced by flowcache_stats(). |
|
Return the most recently used data from the global list
Definition at line 875 of file sfxhash.c. References _sfxhash_node::data, NULL, and sfxhash_ghead(). Referenced by flowcache_mru(), ps_tracker_get(), PurgeSessionCache(), scoreboard_mru(), and server_stats_add_ipv4(). |
|
Return the most recently used node from the global list
Definition at line 916 of file sfxhash.c. References NULL, and sfxhash_ghead(). |
|
Create a new hash table By default, this will "splay" nodes to the top of a free list.
Definition at line 175 of file sfxhash.c. References _sfxhash::anr_count, _sfxhash::anr_flag, _sfxhash::anr_tries, _sfxhash::anrfree, calcNextPrime(), _sfxhash::cnode, _sfxhash::count, _sfxhash::crow, _sfxhash::datasize, _sfxhash::find_fail, _sfxhash::find_success, _sfxhash::ghead, _sfxhash::gtail, _sfxhash::keysize, _sfxhash::mc, MEMCAP::memused, MEMCAP::nblocks, _sfxhash::nrows, _sfxhash::overhead_blocks, _sfxhash::overhead_bytes, _sfxhash::recycle_nodes, s_malloc(), _sfxhash::sfhashfcn, sfhashfcn_new(), sfmemcap_init(), _sfxhash::splay, _sfxhash::table, and _sfxhash::usrfree. Referenced by flowcache_init(), Frag3GlobalInit(), InitSessionCache(), ps_init(), scoreboard_init(), server_stats_init(), sfthd_new(), and ut_init(). |
|
Definition at line 540 of file sfxhash.c. References _sfxhash::anr_count, _sfxhash::anr_flag, _sfxhash::anr_tries, _sfxhash::anrfree, _sfxhash::count, _sfxhash_node::data, _sfxhash::datasize, _sfxhash_node::gprev, _sfxhash::gtail, _sfxhash_node::key, _sfxhash::keysize, s_malloc(), sfxhash_get_free_node(), sfxhash_gunlink_node(), and sfxhash_unlink_node(). Referenced by sfxhash_add(), and sfxhash_get_node(). |
|
Definition at line 1047 of file sfxhash.c. References _sfxhash::cnode, _sfxhash::crow, _sfxhash_node::next, _sfxhash::nrows, and _sfxhash::table. Referenced by sfxhash_findfirst(), and sfxhash_findnext(). |
|
Get the # of overhead blocks
Definition at line 376 of file sfxhash.c. References _sfxhash::overhead_blocks. Referenced by flowcache_overhead_blocks(). |
|
Get the # of overhead bytes
Definition at line 365 of file sfxhash.c. References _sfxhash::overhead_bytes. Referenced by flowcache_overhead_bytes(), scoreboard_overhead_bytes(), scoreboard_stats(), server_stats_overhead_bytes(), and ut_overhead_bytes(). |
|
Remove a Key + Data Pair from the table.
Definition at line 1019 of file sfxhash.c. References _SFHASHFCN::hash_fcn, index, _sfxhash_node::key, _SFHASHFCN::keycmp_fcn, _sfxhash::keysize, _sfxhash_node::next, _sfxhash::nrows, _sfxhash::sfhashfcn, SFXHASH_ERR, sfxhash_free_node(), and _sfxhash::table. Referenced by flowcache_releaseflow(), Frag3RemoveTracker(), RemoveSessionFromHashTable(), scoreboard_remove(), and server_stats_remove_ipv4(). |
|
Definition at line 385 of file sfxhash.c. References _sfxhash::fhead, _sfxhash::ftail, _sfxhash_node::gnext, and _sfxhash_node::gprev. Referenced by sfxhash_free_node(). |
|
Make sfhashfcn use a separate set of operators for the backend.
Definition at line 1135 of file sfxhash.c. References _sfxhash::sfhashfcn, and sfhashfcn_set_keyops(). Referenced by flowcache_init(). |
|
Set Splay mode : Splays nodes to front of list on each access
Definition at line 255 of file sfxhash.c. References _sfxhash::splay. |
|
Definition at line 494 of file sfxhash.c. References _sfxhash_node::next, _sfxhash_node::prev, _sfxhash_node::rindex, and _sfxhash::table. Referenced by movetofront(), sfxhash_free_node(), and sfxhash_newnode(). |