#include "framework/ips_option.h"
#include "framework/module.h"
#include "framework/range.h"
-#include "hash/sfhashfcn.h"
+#include "hash/hashfcn.h"
#include "profiler/profiler.h"
#include "protocols/packet.h"
#include "protocols/tcp.h"
#include "framework/ips_option.h"
#include "framework/module.h"
#include "framework/range.h"
-#include "hash/sfhashfcn.h"
+#include "hash/hashfcn.h"
#include "profiler/profiler.h"
static const char* s_name = "pkt_num";
#include "framework/ips_option.h"
#include "framework/module.h"
#include "framework/range.h"
-#include "hash/sfhashfcn.h"
+#include "hash/hashfcn.h"
#include "profiler/profiler.h"
#include "protocols/packet.h"
#include "protocols/tcp.h"
#include "framework/ips_option.h"
#include "framework/module.h"
#include "framework/range.h"
-#include "hash/sfhashfcn.h"
+#include "hash/hashfcn.h"
#include "profiler/profiler.h"
#include "protocols/packet.h"
#include "protocols/tcp.h"
#include "filters/detection_filter.h"
#include "framework/cursor.h"
-#include "hash/sfhashfcn.h"
-#include "hash/sfxhash.h"
+#include "hash/hashfcn.h"
+#include "hash/xhash.h"
#include "ips_options/extract.h"
#include "ips_options/ips_flowbits.h"
#include "latency/packet_latency.h"
static inline bool operator==(const struct timeval& a, const struct timeval& b)
{ return a.tv_sec == b.tv_sec && a.tv_usec == b.tv_usec; }
-static uint32_t detection_option_hash_func(SFHASHFCN*, const unsigned char* k, int)
+static uint32_t detection_option_hash_func(HashFnc*, const unsigned char* k, int)
{
const detection_option_key_t* key = (const detection_option_key_t*)k;
return 0;
}
-static SFXHASH* DetectionHashTableNew()
+static XHash* DetectionHashTableNew()
{
- SFXHASH* doht = sfxhash_new(HASH_RULE_OPTIONS,
+ XHash* doht = xhash_new(HASH_RULE_OPTIONS,
sizeof(detection_option_key_t),
0, /* Data size == 0, just store the ptr */
0, /* Memcap */
if (doht == nullptr)
FatalError("Failed to create rule detection option hash table");
- sfxhash_set_keyops(doht, detection_option_hash_func, detection_option_key_compare_func);
+ xhash_set_keyops(doht, detection_option_hash_func, detection_option_key_compare_func);
return doht;
}
-void DetectionHashTableFree(SFXHASH* doht)
+void DetectionHashTableFree(XHash* doht)
{
if (doht != nullptr)
- sfxhash_delete(doht);
+ xhash_delete(doht);
}
void* add_detection_option(SnortConfig* sc, option_type_t type, void* option_data)
key.option_type = type;
key.option_data = option_data;
- if ( void* p = sfxhash_find(sc->detection_option_hash_table, &key) )
+ if ( void* p = xhash_find(sc->detection_option_hash_table, &key) )
return p;
- sfxhash_add(sc->detection_option_hash_table, &key, option_data);
+ xhash_add(sc->detection_option_hash_table, &key, option_data);
return nullptr;
}
return c;
}
-static uint32_t detection_option_tree_hash_func(SFHASHFCN*, const unsigned char* k, int)
+static uint32_t detection_option_tree_hash_func(HashFnc*, const unsigned char* k, int)
{
const detection_option_key_t* key = (const detection_option_key_t*)k;
detection_option_tree_node_t* node;
return 0;
}
-void DetectionTreeHashTableFree(SFXHASH* dtht)
+void DetectionTreeHashTableFree(XHash* dtht)
{
if (dtht != nullptr)
- sfxhash_delete(dtht);
+ xhash_delete(dtht);
}
-static SFXHASH* DetectionTreeHashTableNew()
+static XHash* DetectionTreeHashTableNew()
{
- SFXHASH* dtht = sfxhash_new(
+ XHash* dtht = xhash_new(
HASH_RULE_TREE,
sizeof(detection_option_key_t),
0, /* Data size == 0, just store the ptr */
if (dtht == nullptr)
FatalError("Failed to create rule detection option hash table");
- sfxhash_set_keyops(dtht, detection_option_tree_hash_func, detection_option_tree_compare_func);
+ xhash_set_keyops(dtht, detection_option_tree_hash_func, detection_option_tree_compare_func);
return dtht;
}
key.option_data = (void*)option_tree;
key.option_type = RULE_OPTION_TYPE_LEAF_NODE;
- if ( void* p = sfxhash_find(sc->detection_option_tree_hash_table, &key) )
+ if ( void* p = xhash_find(sc->detection_option_tree_hash_table, &key) )
return p;
- sfxhash_add(sc->detection_option_tree_hash_table, &key, option_tree);
+ xhash_add(sc->detection_option_tree_hash_table, &key, option_tree);
return nullptr;
}
}
}
-void detection_option_tree_update_otn_stats(SFXHASH* doth)
+void detection_option_tree_update_otn_stats(XHash* doth)
{
if ( !doth )
return;
- for ( auto hnode = sfxhash_findfirst(doth); hnode; hnode = sfxhash_findnext(doth) )
+ for ( auto hnode = xhash_findfirst(doth); hnode; hnode = xhash_findnext(doth) )
{
auto* node = (detection_option_tree_node_t*)hnode->data;
assert(node);
struct Packet;
struct RuleLatencyState;
-struct SFXHASH;
+struct XHash;
typedef int (* eval_func_t)(void* option_data, class Cursor&, Packet*);
int detection_option_node_evaluate(
detection_option_tree_node_t*, detection_option_eval_data_t*, class Cursor&);
-void DetectionHashTableFree(SFXHASH*);
-void DetectionTreeHashTableFree(SFXHASH*);
+void DetectionHashTableFree(XHash*);
+void DetectionTreeHashTableFree(XHash*);
void print_option_tree(detection_option_tree_node_t*, int level);
-void detection_option_tree_update_otn_stats(SFXHASH*);
+void detection_option_tree_update_otn_stats(XHash*);
detection_option_tree_root_t* new_root(OptTreeNode*);
void free_detection_option_root(void** existing_tree);
#include "fp_create.h"
#include "framework/mpse.h"
-#include "hash/sfghash.h"
+#include "hash/ghash.h"
#include "log/messages.h"
#include "main/snort_config.h"
#include "managers/mpse_manager.h"
/* Process src PORT groups */
if ( src )
{
- for ( SFGHASH_NODE* node=sfghash_findfirst(src->pt_mpxo_hash);
+ for ( GHashNode* node=ghash_findfirst(src->pt_mpxo_hash);
node;
- node=sfghash_findnext(src->pt_mpxo_hash) )
+ node=ghash_findnext(src->pt_mpxo_hash) )
{
PortObject2* po = (PortObject2*)node->data;
/* process destination port groups */
if ( dst )
{
- for ( SFGHASH_NODE* node=sfghash_findfirst(dst->pt_mpxo_hash);
+ for ( GHashNode* node=ghash_findfirst(dst->pt_mpxo_hash);
node;
- node=sfghash_findnext(dst->pt_mpxo_hash) )
+ node=ghash_findnext(dst->pt_mpxo_hash) )
{
PortObject2* po = (PortObject2*)node->data;
static int fpCreatePortObject2PortGroup(
SnortConfig* sc, PortObject2* po, PortObject2* poaa)
{
- SFGHASH_NODE* node;
+ GHashNode* node;
unsigned sid, gid;
OptTreeNode* otn;
PortGroup* pg;
while (pox != nullptr)
{
- for (node = sfghash_findfirst(pox->rule_hash);
+ for (node = ghash_findfirst(pox->rule_hash);
node;
- node = sfghash_findnext(pox->rule_hash))
+ node = ghash_findnext(pox->rule_hash))
{
int* prindex = (int*)node->data;
static int fpCreatePortTablePortGroups(
SnortConfig* sc, PortTable* p, PortObject2* poaa)
{
- SFGHASH_NODE* node;
+ GHashNode* node;
int cnt=1;
FastPatternConfig* fp = sc->fast_pattern_config;
if (fp->get_debug_print_rule_group_build_details())
LogMessage("%d Port Groups in Port Table\n",p->pt_mpo_hash->count);
- for (node=sfghash_findfirst(p->pt_mpo_hash);
+ for (node=ghash_findfirst(p->pt_mpo_hash);
node;
- node=sfghash_findnext(p->pt_mpo_hash) )
+ node=ghash_findnext(p->pt_mpo_hash) )
{
PortObject2* po = (PortObject2*)node->data;
* list- list of otns for this service
*/
static void fpBuildServicePortGroupByServiceOtnList(
- SnortConfig* sc, SFGHASH* p, const char* srvc, SF_LIST* list, FastPatternConfig* fp)
+ SnortConfig* sc, GHash* p, const char* srvc, SF_LIST* list, FastPatternConfig* fp)
{
PortGroup* pg = PortGroup::alloc();
s_group = srvc;
return;
/* Add the port_group using it's service name */
- sfghash_add(p, srvc, pg);
+ ghash_add(p, srvc, pg);
}
/*
*
*/
static void fpBuildServicePortGroups(
- SnortConfig* sc, SFGHASH* spg, PortGroupVector& sopg, SFGHASH* srm, FastPatternConfig* fp)
+ SnortConfig* sc, GHash* spg, PortGroupVector& sopg, GHash* srm, FastPatternConfig* fp)
{
- for ( SFGHASH_NODE* n = sfghash_findfirst(srm);
+ for ( GHashNode* n = ghash_findfirst(srm);
n;
- n=sfghash_findnext(srm) )
+ n=ghash_findnext(srm) )
{
SF_LIST* list = (SF_LIST*)n->data;
const char* srvc = (const char*)n->key;
fpBuildServicePortGroupByServiceOtnList(sc, spg, srvc, list, fp);
/* Add this PortGroup to the protocol-ordinal -> port_group table */
- PortGroup* pg = (PortGroup*)sfghash_find(spg, srvc);
+ PortGroup* pg = (PortGroup*)ghash_find(spg, srvc);
if ( !pg )
{
ParseError("*** failed to create and find a port group for '%s'",srvc);
}
}
-static void fpPrintServiceRuleMapTable(SFGHASH* p, const char* proto, const char* dir)
+static void fpPrintServiceRuleMapTable(GHash* p, const char* proto, const char* dir)
{
- SFGHASH_NODE* n;
+ GHashNode* n;
if ( !p || !p->count )
return;
label += dir;
LogLabel(label.c_str());
- for ( n = sfghash_findfirst(p);
+ for ( n = ghash_findfirst(p);
n;
- n = sfghash_findnext(p) )
+ n = ghash_findnext(p) )
{
SF_LIST* list;
}
}
-static void fp_print_service_rules(SnortConfig* sc, SFGHASH* cli, SFGHASH* srv, const char* msg)
+static void fp_print_service_rules(SnortConfig* sc, GHash* cli, GHash* srv, const char* msg)
{
if ( !cli->count and !srv->count )
return;
while ( const char* svc = sc->proto_ref->get_name_sorted(idx++) )
{
- SF_LIST* clist = (SF_LIST*)sfghash_find(cli, svc);
- SF_LIST* slist = (SF_LIST*)sfghash_find(srv, svc);
+ SF_LIST* clist = (SF_LIST*)ghash_find(cli, svc);
+ SF_LIST* slist = (SF_LIST*)ghash_find(srv, svc);
if ( !clist and !slist )
continue;
c[i]++;
}
-static void fp_sum_service_groups(SFGHASH* h, unsigned c[PM_TYPE_MAX])
+static void fp_sum_service_groups(GHash* h, unsigned c[PM_TYPE_MAX])
{
- for ( SFGHASH_NODE* node=sfghash_findfirst(h);
- node; node=sfghash_findnext(h) )
+ for ( GHashNode* node=ghash_findfirst(h);
+ node; node=ghash_findnext(h) )
{
PortGroup* pg = (PortGroup*)node->data;
fp_sum_port_groups(pg, c);
static void fp_sum_port_groups(PortTable* tab, unsigned c[PM_TYPE_MAX])
{
- for ( SFGHASH_NODE* node=sfghash_findfirst(tab->pt_mpxo_hash);
- node; node=sfghash_findnext(tab->pt_mpxo_hash) )
+ for ( GHashNode* node=ghash_findfirst(tab->pt_mpxo_hash);
+ node; node=ghash_findnext(tab->pt_mpxo_hash) )
{
PortObject2* po = (PortObject2*)node->data;
fp_sum_port_groups(po->group, c);
#include <cassert>
-#include "hash/sfghash.h"
+#include "hash/ghash.h"
#include "ips_options/ips_flow.h"
#include "log/messages.h"
#include "main/snort_config.h"
// service map stuff
//-------------------------------------------------------------------------
-static SFGHASH* alloc_srvmap()
+static GHash* alloc_srvmap()
{
- // nodes are lists,free them in sfghash_delete
- SFGHASH* p = sfghash_new(1000, 0, 0, (void (*)(void*))sflist_free);
+ // nodes are lists,free them in ghash_delete
+ GHash* p = ghash_new(1000, 0, 0, (void (*)(void*))sflist_free);
return p;
}
-static void free_srvmap(SFGHASH* table)
+static void free_srvmap(GHash* table)
{
if ( table )
- sfghash_delete(table);
+ ghash_delete(table);
}
srmm_table_t* ServiceMapNew()
static void delete_pg(void* pv)
{ PortGroup::free((PortGroup*)pv); }
-static SFGHASH* alloc_spgmm()
+static GHash* alloc_spgmm()
{
// 1000 rows, ascii key
- SFGHASH* p = sfghash_new(1000, 0, 0, delete_pg);
+ GHash* p = ghash_new(1000, 0, 0, delete_pg);
return p;
}
-static void free_spgmm(SFGHASH* table)
+static void free_spgmm(GHash* table)
{
if ( !table )
return;
- sfghash_delete(table);
+ ghash_delete(table);
}
srmm_table_t* ServicePortGroupMapNew()
* otn - rule - may be content,-no-content, or uri-content
*
*/
-static void ServiceMapAddOtnRaw(SFGHASH* table, const char* servicename, OptTreeNode* otn)
+static void ServiceMapAddOtnRaw(GHash* table, const char* servicename, OptTreeNode* otn)
{
SF_LIST* list;
- list = (SF_LIST*)sfghash_find(table, servicename);
+ list = (SF_LIST*)ghash_find(table, servicename);
if ( !list )
{
FatalError("service_rule_map: could not create a service rule-list\n");
/* add the service list to the table */
- if ( sfghash_add(table, servicename, list) != SFGHASH_OK )
+ if ( ghash_add(table, servicename, list) != GHASH_OK )
{
FatalError("service_rule_map: could not add a rule to the rule-service-map\n");
}
if ( proto > SNORT_PROTO_USER )
proto = SNORT_PROTO_USER;
- SFGHASH* to_srv = srmm->to_srv[proto];
- SFGHASH* to_cli = srmm->to_cli[proto];
+ GHash* to_srv = srmm->to_srv[proto];
+ GHash* to_cli = srmm->to_cli[proto];
if ( !OtnFlowFromClient(otn) )
ServiceMapAddOtnRaw(to_cli, servicename, otn);
int fpCreateServiceMaps(SnortConfig* sc)
{
RuleTreeNode* rtn;
- SFGHASH_NODE* hashNode;
+ GHashNode* hashNode;
OptTreeNode* otn = nullptr;
PolicyId policyId = 0;
unsigned int svc_idx;
- for (hashNode = sfghash_findfirst(sc->otn_map);
+ for (hashNode = ghash_findfirst(sc->otn_map);
hashNode;
- hashNode = sfghash_findnext(sc->otn_map))
+ hashNode = ghash_findnext(sc->otn_map))
{
otn = (OptTreeNode*)hashNode->data;
for ( policyId = 0;
#include "target_based/snort_protocols.h"
struct PortGroup;
-struct SFGHASH;
+struct GHash;
struct SnortConfig;
// Service Rule Map Master Table
struct srmm_table_t
{
- SFGHASH* to_srv[SNORT_PROTO_MAX];
- SFGHASH* to_cli[SNORT_PROTO_MAX];
+ GHash* to_srv[SNORT_PROTO_MAX];
+ GHash* to_cli[SNORT_PROTO_MAX];
};
srmm_table_t* ServiceMapNew();
/***************** Otn Utilities ***********************/
-void OtnRemove(SFGHASH* otn_map, OptTreeNode* otn)
+void OtnRemove(GHash* otn_map, OptTreeNode* otn)
{
assert(otn_map and otn);
key.gid = otn->sigInfo.gid;
key.sid = otn->sigInfo.sid;
- sfghash_remove(otn_map, &key);
+ ghash_remove(otn_map, &key);
}
void OtnFree(void* data)
snort_free(otn);
}
-SFGHASH* OtnLookupNew()
+GHash* OtnLookupNew()
{
- return sfghash_new(10000, sizeof(OtnKey), 0, OtnFree);
+ return ghash_new(10000, sizeof(OtnKey), 0, OtnFree);
}
-void OtnLookupAdd(SFGHASH* otn_map, OptTreeNode* otn)
+void OtnLookupAdd(GHash* otn_map, OptTreeNode* otn)
{
assert(otn_map);
key.gid = otn->sigInfo.gid;
key.sid = otn->sigInfo.sid;
- int status = sfghash_add(otn_map, &key, otn);
+ int status = ghash_add(otn_map, &key, otn);
- if ( status == SFGHASH_OK )
+ if ( status == GHASH_OK )
return;
- assert(status == SFGHASH_INTABLE);
+ assert(status == GHASH_INTABLE);
ParseError("duplicate rule with same gid (%u) and sid (%u)", key.gid, key.sid);
}
-OptTreeNode* OtnLookup(SFGHASH* otn_map, uint32_t gid, uint32_t sid)
+OptTreeNode* OtnLookup(GHash* otn_map, uint32_t gid, uint32_t sid)
{
assert(otn_map);
key.gid = gid;
key.sid = sid;
- OptTreeNode* otn = (OptTreeNode*)sfghash_find(otn_map, &key);
+ OptTreeNode* otn = (OptTreeNode*)ghash_find(otn_map, &key);
return otn;
}
return otn;
}
-void OtnLookupFree(SFGHASH* otn_map)
+void OtnLookupFree(GHash* otn_map)
{
if ( otn_map )
- sfghash_delete(otn_map);
+ ghash_delete(otn_map);
}
struct SnortConfig;
struct OptTreeNode;
-struct SFGHASH;
+struct GHash;
/* this contains a list of the URLs for various reference systems */
struct ReferenceSystemNode
ClassType* ClassTypeLookupByType(SnortConfig*, const char*);
-struct ServiceInfo
+struct SignatureServiceInfo
{
char* service;
int16_t service_ordinal;
char* message;
ClassType* class_type;
ReferenceNode* refs;
- ServiceInfo* services;
+ SignatureServiceInfo* services;
uint32_t gid;
uint32_t sid;
Target target;
};
-SFGHASH* OtnLookupNew();
-void OtnLookupAdd(SFGHASH*, OptTreeNode*);
-OptTreeNode* OtnLookup(SFGHASH*, uint32_t gid, uint32_t sid);
-void OtnLookupFree(SFGHASH*);
-void OtnRemove(SFGHASH*, OptTreeNode*);
+GHash* OtnLookupNew();
+void OtnLookupAdd(GHash*, OptTreeNode*);
+OptTreeNode* OtnLookup(GHash*, uint32_t gid, uint32_t sid);
+void OtnLookupFree(GHash*);
+void OtnRemove(GHash*, OptTreeNode*);
void OtnDeleteData(void* data);
void OtnFree(void* data);
#include "tag.h"
#include "events/event.h"
-#include "hash/sfxhash.h"
+#include "hash/xhash.h"
#include "log/messages.h"
#include "main/snort_config.h"
#include "main/snort_debug.h"
};
/* G L O B A L S **************************************************/
-static THREAD_LOCAL SFXHASH* host_tag_cache_ptr = nullptr;
+static THREAD_LOCAL XHash* host_tag_cache_ptr = nullptr;
// FIXIT-M utilize Flow instead of separate cache
-static THREAD_LOCAL SFXHASH* ssn_tag_cache_ptr = nullptr;
+static THREAD_LOCAL XHash* ssn_tag_cache_ptr = nullptr;
static THREAD_LOCAL uint32_t last_prune_time = 0;
static THREAD_LOCAL uint32_t tag_alloc_faults = 0;
static const unsigned s_max_sessions = 1;
/* P R O T O T Y P E S ********************************************/
-static TagNode* TagAlloc(SFXHASH*);
-static void TagFree(SFXHASH*, TagNode*);
+static TagNode* TagAlloc(XHash*);
+static void TagFree(XHash*, TagNode*);
static int TagFreeSessionNodeFunc(void* key, void* data);
static int TagFreeHostNodeFunc(void* key, void* data);
static int PruneTagCache(uint32_t, int);
-static int PruneTime(SFXHASH* tree, uint32_t thetime);
+static int PruneTime(XHash* tree, uint32_t thetime);
static void TagSession(Packet*, TagData*, uint32_t, uint16_t, void*);
static void TagHost(Packet*, TagData*, uint32_t, uint16_t, void*);
static void AddTagNode(Packet*, TagData*, int, uint32_t, uint16_t, void*);
static inline void SwapTag(TagNode*);
/**Calculated memory needed per node insertion into respective cache. Its includes
- * memory needed for allocating TagNode, SFXHASH_NODE, and key size.
+ * memory needed for allocating TagNode, XHashNode, and key size.
*
- * @param hash - pointer to SFXHASH that should point to either ssn_tag_cache_ptr
+ * @param hash - pointer to XHash that should point to either ssn_tag_cache_ptr
* or host_tag_cache_ptr.
*
* @returns number of bytes needed
*/
static inline unsigned int memory_per_node(
- SFXHASH* hash
+ XHash* hash
)
{
if (hash == ssn_tag_cache_ptr)
{
- return sizeof(tTagFlowKey)+sizeof(SFXHASH_NODE)+sizeof(TagNode);
+ return sizeof(tTagFlowKey)+sizeof(XHashNode)+sizeof(TagNode);
}
else if (hash == host_tag_cache_ptr)
{
- return sizeof(SfIp)+sizeof(SFXHASH_NODE)+sizeof(TagNode);
+ return sizeof(SfIp)+sizeof(XHashNode)+sizeof(TagNode);
}
return 0;
* Least used nodes may be deleted from ssn_tag_cache and host_tag_cache to make space if
* the limit is being exceeded.
*
- * @param hash - pointer to SFXHASH that should point to either ssn_tag_cache_ptr
+ * @param hash - pointer to XHash that should point to either ssn_tag_cache_ptr
* or host_tag_cache_ptr.
*
* @returns a pointer to new TagNode or NULL if memory couldn't * be allocated
*/
static TagNode* TagAlloc(
- SFXHASH* hash
+ XHash* hash
)
{
TagNode* tag_node = nullptr;
/**Frees allocated TagNode.
*
- * @param hash - pointer to SFXHASH that should point to either ssn_tag_cache_ptr
+ * @param hash - pointer to XHash that should point to either ssn_tag_cache_ptr
* or host_tag_cache_ptr.
* @param node - pointer to node to be freed
*/
static void TagFree(
- SFXHASH* hash,
+ XHash* hash,
TagNode* node
)
{
{
unsigned int hashTableSize = TAG_MEMCAP/sizeof(TagNode);
- ssn_tag_cache_ptr = sfxhash_new(
+ ssn_tag_cache_ptr = xhash_new(
hashTableSize, /* number of hash buckets */
sizeof(tTagFlowKey), /* size of the key we're going to use */
0, /* size of the storage node */
TagFreeSessionNodeFunc, /* user free function */
0); /* recycle node flag */
- host_tag_cache_ptr = sfxhash_new(
+ host_tag_cache_ptr = xhash_new(
hashTableSize, /* number of hash buckets */
sizeof(SfIp), /* size of the key we're going to use */
0, /* size of the storage node */
{
if (ssn_tag_cache_ptr)
{
- sfxhash_delete(ssn_tag_cache_ptr);
+ xhash_delete(ssn_tag_cache_ptr);
}
if (host_tag_cache_ptr)
{
- sfxhash_delete(host_tag_cache_ptr);
+ xhash_delete(host_tag_cache_ptr);
}
}
{
TagNode* idx; /* index pointer */
TagNode* returned;
- SFXHASH* tag_cache_ptr = nullptr;
+ XHash* tag_cache_ptr = nullptr;
DebugMessage(DEBUG_FLOW, "Adding new Tag Head\n");
}
/* check for duplicates */
- returned = (TagNode*)sfxhash_find(tag_cache_ptr, idx);
+ returned = (TagNode*)xhash_find(tag_cache_ptr, idx);
if (returned == nullptr)
{
DebugMessage(DEBUG_FLOW,"Looking the other way!!\n");
SwapTag(idx);
- returned = (TagNode*)sfxhash_find(tag_cache_ptr, idx);
+ returned = (TagNode*)xhash_find(tag_cache_ptr, idx);
SwapTag(idx);
}
SwapTag(idx);
}
- if (sfxhash_add(tag_cache_ptr, idx, idx) != SFXHASH_OK)
+ if (xhash_add(tag_cache_ptr, idx, idx) != XHASH_OK)
{
DebugMessage(DEBUG_FLOW,
- "sfxhash_add failed, that's going to "
+ "xhash_add failed, that's going to "
"make life difficult\n");
TagFree(tag_cache_ptr, idx);
return;
{
TagNode idx;
TagNode* returned = nullptr;
- SFXHASH* taglist = nullptr;
+ XHash* taglist = nullptr;
char create_event = 1;
/* check for active tags */
- if (!sfxhash_count(host_tag_cache_ptr) && !sfxhash_count(ssn_tag_cache_ptr))
+ if (!xhash_count(host_tag_cache_ptr) && !xhash_count(ssn_tag_cache_ptr))
{
return 0;
}
}
DebugFormat(DEBUG_FLOW,"Host Tags Active: %u Session Tags Active: %u\n",
- sfxhash_count(host_tag_cache_ptr), sfxhash_count(ssn_tag_cache_ptr));
+ xhash_count(host_tag_cache_ptr), xhash_count(ssn_tag_cache_ptr));
DebugMessage(DEBUG_FLOW, "[*] Checking session tag list (forward)...\n");
idx.key.dp = p->ptrs.dp;
/* check for session tags... */
- returned = (TagNode*)sfxhash_find(ssn_tag_cache_ptr, &idx);
+ returned = (TagNode*)xhash_find(ssn_tag_cache_ptr, &idx);
if (returned == nullptr)
{
idx.key.sp = p->ptrs.dp;
DebugMessage(DEBUG_FLOW, " Checking session tag list (reverse)...\n");
- returned = (TagNode*)sfxhash_find(ssn_tag_cache_ptr, &idx);
+ returned = (TagNode*)xhash_find(ssn_tag_cache_ptr, &idx);
if (returned == nullptr)
{
DebugMessage(DEBUG_FLOW, " Checking host tag list "
"(forward)...\n");
- returned = (TagNode*)sfxhash_find(host_tag_cache_ptr, &idx);
+ returned = (TagNode*)xhash_find(host_tag_cache_ptr, &idx);
if (returned == nullptr)
{
*/
idx.key.sip.set(*p->ptrs.ip_api.get_src());
- returned = (TagNode*)sfxhash_find(host_tag_cache_ptr, &idx);
+ returned = (TagNode*)xhash_find(host_tag_cache_ptr, &idx);
}
if (returned != nullptr)
DebugMessage(DEBUG_FLOW,
" Prune condition met for tag, removing from list\n");
- if (sfxhash_remove(taglist, returned) != SFXHASH_OK)
+ if (xhash_remove(taglist, returned) != XHASH_OK)
{
LogMessage("WARNING: failed to remove tagNode from hash.\n");
}
if (mustdie == 0)
{
- if (sfxhash_count(ssn_tag_cache_ptr) != 0)
+ if (xhash_count(ssn_tag_cache_ptr) != 0)
{
pruned = PruneTime(ssn_tag_cache_ptr, thetime);
}
- if (sfxhash_count(host_tag_cache_ptr) != 0)
+ if (xhash_count(host_tag_cache_ptr) != 0)
{
pruned += PruneTime(host_tag_cache_ptr, thetime);
}
else
{
while (pruned < mustdie &&
- (sfxhash_count(ssn_tag_cache_ptr) > 0 || sfxhash_count(host_tag_cache_ptr) > 0))
+ (xhash_count(ssn_tag_cache_ptr) > 0 || xhash_count(host_tag_cache_ptr) > 0))
{
TagNode* lru_node;
- if ((lru_node = (TagNode*)sfxhash_lru(ssn_tag_cache_ptr)) != nullptr)
+ if ((lru_node = (TagNode*)xhash_lru(ssn_tag_cache_ptr)) != nullptr)
{
- if (sfxhash_remove(ssn_tag_cache_ptr, lru_node) != SFXHASH_OK)
+ if (xhash_remove(ssn_tag_cache_ptr, lru_node) != XHASH_OK)
{
LogMessage("WARNING: failed to remove tagNode from hash.\n");
}
pruned++;
}
- if ((lru_node = (TagNode*)sfxhash_lru(host_tag_cache_ptr)) != nullptr)
+ if ((lru_node = (TagNode*)xhash_lru(host_tag_cache_ptr)) != nullptr)
{
- if (sfxhash_remove(host_tag_cache_ptr, lru_node) != SFXHASH_OK)
+ if (xhash_remove(host_tag_cache_ptr, lru_node) != XHASH_OK)
{
LogMessage("WARNING: failed to remove tagNode from hash.\n");
}
return pruned;
}
-static int PruneTime(SFXHASH* tree, uint32_t thetime)
+static int PruneTime(XHash* tree, uint32_t thetime)
{
int pruned = 0;
TagNode* lru_node = nullptr;
- while ((lru_node = (TagNode*)sfxhash_lru(tree)) != nullptr)
+ while ((lru_node = (TagNode*)xhash_lru(tree)) != nullptr)
{
if ((lru_node->last_access + TAG_PRUNE_QUANTUM) < thetime)
{
- if (sfxhash_remove(tree, lru_node) != SFXHASH_OK)
+ if (xhash_remove(tree, lru_node) != XHASH_OK)
{
LogMessage("WARNING: failed to remove tagNode from hash.\n");
}
#include "file_cache.h"
-#include "hash/sfxhash.h"
+#include "hash/xhash.h"
#include "log/messages.h"
#include "main/snort_config.h"
#include "main/snort_debug.h"
FileCache::FileCache()
{
int max_files = SnortConfig::get_conf()->file_config.max_files_cached;
- fileHash = sfxhash_new(max_files, sizeof(FileHashKey), sizeof(FileNode),
+ fileHash = xhash_new(max_files, sizeof(FileHashKey), sizeof(FileNode),
0, 1, nullptr, file_cache_free_func, 1);
if (!fileHash)
FatalError("Failed to create the expected channel hash table.\n");
- sfxhash_set_max_nodes(fileHash, max_files);
+ xhash_set_max_nodes(fileHash, max_files);
}
FileCache::~FileCache()
{
if (fileHash)
{
- sfxhash_delete(fileHash);
+ xhash_delete(fileHash);
}
}
std::lock_guard<std::mutex> lock(cache_mutex);
- if (sfxhash_add(fileHash, (void*)&hashKey, &new_node) != SFXHASH_OK)
+ if (xhash_add(fileHash, (void*)&hashKey, &new_node) != XHASH_OK)
{
/* Uh, shouldn't get here...
* There is already a node or couldn't alloc space
std::lock_guard<std::mutex> lock(cache_mutex);
// No hash table, or its empty? Get out of dodge.
- if ((!fileHash) || (!sfxhash_count(fileHash)))
+ if ((!fileHash) || (!xhash_count(fileHash)))
{
DebugMessage(DEBUG_FILE, "No expected sessions\n");
return nullptr;
}
- SFXHASH_NODE* hash_node = sfxhash_find_node(fileHash, &hashKey);
+ XHashNode* hash_node = xhash_find_node(fileHash, &hashKey);
if (!hash_node)
return nullptr;
FileNode* node = (FileNode*)hash_node->data;
if (!node)
{
- sfxhash_free_node(fileHash, hash_node);
+ xhash_free_node(fileHash, hash_node);
return nullptr;
}
if (node->expires && now > node->expires)
{
DebugMessage(DEBUG_FILE, "File expired\n");
- sfxhash_free_node(fileHash, hash_node);
+ xhash_free_node(fileHash, hash_node);
return nullptr;
}
#include "file_config.h"
-struct SFXHASH;
+struct XHash;
class FileCache
{
private:
/* The hash table of expected files */
- SFXHASH* fileHash = nullptr;
+ XHash* fileHash = nullptr;
uint32_t timeout = DEFAULT_FILE_BLOCK_TIMEOUT;
std::mutex cache_mutex;
};
FileEnforcer::FileEnforcer()
{
- fileHash = sfxhash_new(MAX_FILES_TRACKED, sizeof(FileHashKey), sizeof(FileNode),
+ fileHash = xhash_new(MAX_FILES_TRACKED, sizeof(FileHashKey), sizeof(FileNode),
MAX_MEMORY_USED, 1, nullptr, file_node_free_func, 1);
if (!fileHash)
FatalError("Failed to create the expected channel hash table.\n");
{
if (fileHash)
{
- sfxhash_delete(fileHash);
+ xhash_delete(fileHash);
}
}
}
FileVerdict FileEnforcer::check_verdict(Flow* flow, FileNode* node,
- SFXHASH_NODE* hash_node, FilePolicy& inspect)
+ XHashNode* hash_node, FilePolicy& inspect)
{
assert(node->file);
if (verdict == FILE_VERDICT_LOG)
{
- sfxhash_free_node(fileHash, hash_node);
+ xhash_free_node(fileHash, hash_node);
}
return verdict;
hashKey.file_sig = file_sig;
FileNode* node;
- SFXHASH_NODE* hash_node = sfxhash_find_node(fileHash, &hashKey);
+ XHashNode* hash_node = xhash_find_node(fileHash, &hashKey);
if (hash_node)
{
if (!(node = (FileNode*)hash_node->data))
- sfxhash_free_node(fileHash, hash_node);
+ xhash_free_node(fileHash, hash_node);
}
else
node = nullptr;
new_node.expires = now + timeout;
/* Add it to the table */
- if (sfxhash_add(fileHash, &hashKey, &new_node) != SFXHASH_OK)
+ if (xhash_add(fileHash, &hashKey, &new_node) != XHASH_OK)
{
/* Uh, shouldn't get here...
* There is already a node or couldn't alloc space
FilePolicy& inspect)
{
FileVerdict verdict = FILE_VERDICT_UNKNOWN;
- SFXHASH_NODE* hash_node;
+ XHashNode* hash_node;
FileNode* node;
/* No hash table, or its empty? Get out of dodge. */
- if ((!fileHash) || (!sfxhash_count(fileHash)))
+ if ((!fileHash) || (!xhash_count(fileHash)))
{
DebugMessage(DEBUG_FILE, "No expected sessions\n");
return verdict;
hashKey.padding = 0;
hashKey.file_sig = file_sig;
- hash_node = sfxhash_find_node(fileHash, &hashKey);
+ hash_node = xhash_find_node(fileHash, &hashKey);
if (hash_node)
{
if (!(node = (FileNode*)hash_node->data))
- sfxhash_free_node(fileHash, hash_node);
+ xhash_free_node(fileHash, hash_node);
}
else
return verdict;
if (node->expires && packet_time() > node->expires)
{
DebugMessage(DEBUG_FILE, "File expired\n");
- sfxhash_free_node(fileHash, hash_node);
+ xhash_free_node(fileHash, hash_node);
return verdict;
}
/*Query the file policy in case verdict has been changed*/
// to request the file data left. To block the new session, we use URL and IPs
// to continue blocking the same file.
-#include "hash/sfxhash.h"
+#include "hash/xhash.h"
#include "sfip/sf_ip.h"
#include "utils/cpp_macros.h"
PADDING_GUARD_END
void update_file_node(FileNode*, FileInfo*);
- FileVerdict check_verdict(Flow*, FileNode*, SFXHASH_NODE*, FilePolicy&);
+ FileVerdict check_verdict(Flow*, FileNode*, XHashNode*, FilePolicy&);
int store_verdict(Flow*, FileInfo*);
/* The hash table of expected files */
- SFXHASH* fileHash = nullptr;
+ XHash* fileHash = nullptr;
uint32_t timeout = DEFAULT_FILE_BLOCK_TIMEOUT;
};
void FileIdentifier::init_merge_hash()
{
- identifier_merge_hash = sfghash_new(1000, sizeof(MergeNode), 0, nullptr);
+ identifier_merge_hash = ghash_new(1000, sizeof(MergeNode), 0, nullptr);
assert(identifier_merge_hash);
}
if (identifier_merge_hash != nullptr)
{
- sfghash_delete(identifier_merge_hash);
+ ghash_delete(identifier_merge_hash);
}
}
set_node_state_shared(append);
return false;
}
- else if ((result = (IdentifierNode*)sfghash_find(identifier_merge_hash, &merge_node)))
+ else if ((result = (IdentifierNode*)ghash_find(identifier_merge_hash, &merge_node)))
{
/*the same pointer has been processed, reuse it*/
*next_ptr = result;
set_node_state_shared(next);
next = node;
- sfghash_add(identifier_merge_hash, &merge_node, next);
+ ghash_add(identifier_merge_hash, &merge_node, next);
}
else if (next->state == ID_NODE_SHARED)
{
merge_node.append_node = append;
next = clone_node(current_next);
set_node_state_shared(next);
- sfghash_add(identifier_merge_hash, &merge_node, next);
+ ghash_add(identifier_merge_hash, &merge_node, next);
}
*next_ptr = next;
#include <list>
#include <vector>
-#include "hash/sfghash.h"
+#include "hash/ghash.h"
#include "file_lib.h"
/*properties*/
IdentifierNode* identifier_root = nullptr; /*Root of magic tries*/
uint32_t memory_used = 0; /*Track memory usage*/
- SFGHASH* identifier_merge_hash = nullptr;
+ GHash* identifier_merge_hash = nullptr;
FileMagicRule file_magic_rules[FILE_ID_MAX + 1];
IDMemoryBlocks id_memory_blocks;
};
#include "detection_filter.h"
-#include "hash/sfxhash.h"
+#include "hash/xhash.h"
#include "log/messages.h"
#include "main/thread.h"
#include "utils/util.h"
#include "sfthd.h"
-static THREAD_LOCAL SFXHASH* detection_filter_hash = nullptr;
+static THREAD_LOCAL XHash* detection_filter_hash = nullptr;
DetectionFilterConfig* DetectionFilterConfigNew()
{
if ( !detection_filter_hash )
return;
- sfxhash_delete(detection_filter_hash);
+ xhash_delete(detection_filter_hash);
detection_filter_hash = nullptr;
}
for (i = 0; i < SFRF_MAX_GENID; i++)
{
if (config->genHash[i] != nullptr)
- sfghash_delete(config->genHash[i]);
+ ghash_delete(config->genHash[i]);
}
snort_free(config);
for ( gid=0; gid < SFRF_MAX_GENID; gid++ )
{
- SFGHASH_NODE* item_hash_node;
- SFGHASH* sfrf_hash = config->genHash [ gid ];
+ GHashNode* item_hash_node;
+ GHash* sfrf_hash = config->genHash [ gid ];
if ( !sfrf_hash )
{
continue;
}
- for ( item_hash_node = sfghash_findfirst(sfrf_hash);
+ for ( item_hash_node = ghash_findfirst(sfrf_hash);
item_hash_node != 0;
- item_hash_node = sfghash_findnext(sfrf_hash) )
+ item_hash_node = ghash_findnext(sfrf_hash) )
{
tSFRFSidNode* sfrf_item;
tSFRFConfigNode* sfrf_node;
#include "sfrf.h"
#include "detection/rules.h"
-#include "hash/sfghash.h"
-#include "hash/sfxhash.h"
+#include "hash/ghash.h"
+#include "hash/xhash.h"
#include "sfip/sf_ip.h"
#include "sfip/sf_ipvar.h"
#include "utils/cpp_macros.h"
time_t revertTime;
} tSFRFTrackingNode;
-SFXHASH* rf_hash = nullptr;
+XHash* rf_hash = nullptr;
// private methods ...
static int _checkThreshold(
nrows = nbytes / (SFRF_BYTES);
/* Create global hash table for all of the IP Nodes */
- rf_hash = sfxhash_new(
+ rf_hash = xhash_new(
nrows, /* try one node per row - for speed */
sizeof(tSFRFTrackingNodeKey), /* keys size */
sizeof(tSFRFTrackingNode), /* data size */
if ( !rf_hash )
return;
- sfxhash_delete(rf_hash);
+ xhash_delete(rf_hash);
rf_hash = nullptr;
}
void SFRF_Flush()
{
if ( rf_hash )
- sfxhash_make_empty(rf_hash);
+ xhash_make_empty(rf_hash);
}
static void SFRF_ConfigNodeFree(void* item)
int SFRF_ConfigAdd(
SnortConfig*, RateFilterConfig* rf_config, tSFRFConfigNode* cfgNode)
{
- SFGHASH* genHash;
+ GHash* genHash;
tSFRFSidNode* pSidNode;
tSFRFConfigNode* pNewConfigNode;
tSFRFGenHashKey key = { 0,0 };
}
/* Create the hash table for this gid */
- genHash = sfghash_new(nrows, sizeof(tSFRFGenHashKey), 0, SFRF_SidNodeFree);
+ genHash = ghash_new(nrows, sizeof(tSFRFGenHashKey), 0, SFRF_SidNodeFree);
if ( !genHash )
return -2;
key.policyId = policy_id;
/* Check if sid is already in the table - if not allocate and add it */
- pSidNode = (tSFRFSidNode*)sfghash_find(genHash, (void*)&key);
+ pSidNode = (tSFRFSidNode*)ghash_find(genHash, (void*)&key);
if ( !pSidNode )
{
/* Create the pSidNode hash node data */
}
/* Add the pSidNode to the hash table */
- if ( sfghash_add(genHash, (void*)&key, pSidNode) )
+ if ( ghash_add(genHash, (void*)&key, pSidNode) )
{
sflist_free(pSidNode->configNodeList);
snort_free(pSidNode);
SFRF_COUNT_OPERATION op
)
{
- SFGHASH* genHash;
+ GHash* genHash;
tSFRFSidNode* pSidNode;
tSFRFConfigNode* cfgNode;
int newStatus = -1;
key.sid = sid;
key.policyId = policy_id;
- pSidNode = (tSFRFSidNode*)sfghash_find(genHash, (void*)&key);
+ pSidNode = (tSFRFSidNode*)ghash_find(genHash, (void*)&key);
if ( !pSidNode )
{
#ifdef SFRF_DEBUG
tSFRFSidNode* pSidnode;
tSFRFConfigNode* cfgNode;
unsigned int gid;
- SFGHASH_NODE* sidHashNode;
+ GHashNode* sidHashNode;
for ( gid=0; gid < SFRF_MAX_GENID; gid++ )
{
- SFGHASH* genHash = config->genHash [ gid ];
+ GHash* genHash = config->genHash [ gid ];
if ( !genHash )
continue;
printf("...GEN_ID = %u\n",gid);
- for ( sidHashNode = sfghash_findfirst(genHash);
+ for ( sidHashNode = ghash_findfirst(genHash);
sidHashNode != nullptr;
- sidHashNode = sfghash_findnext(genHash) )
+ sidHashNode = ghash_findnext(genHash) )
{
/* Check for any Permanent sid objects for this gid */
pSidnode = (tSFRFSidNode*)sidHashNode->data;
/*
* Check for any Permanent sid objects for this gid or add this one ...
*/
- SFXHASH_NODE* hnode = sfxhash_get_node(rf_hash, (void*)&key);
+ XHashNode* hnode = xhash_get_node(rf_hash, (void*)&key);
if ( hnode && hnode->data )
{
dynNode = (tSFRFTrackingNode*)hnode->data;
/* Array of hash, indexed by gid. Each array element is a hash, which
* is keyed on sid/policyId and data is a tSFRFSidNode node.
*/
- struct SFGHASH* genHash [SFRF_MAX_GENID];
+ struct GHash* genHash [SFRF_MAX_GENID];
// Number of DOS thresholds added.
int count;
#include <cassert>
-#include "hash/sfghash.h"
-#include "hash/sfxhash.h"
+#include "hash/ghash.h"
+#include "hash/xhash.h"
#include "sfip/sf_ipvar.h"
#include "utils/dyn_array.h"
#include "utils/sflsq.h"
// This disables adding and testing of Threshold objects
//#define CRIPPLE
-SFXHASH* sfthd_new_hash(unsigned nbytes, size_t key, size_t data)
+XHash* sfthd_new_hash(unsigned nbytes, size_t key, size_t data)
{
size_t size = key + data;
int nrows;
}
nrows = nbytes / (size);
- return sfxhash_new(
+ return xhash_new(
nrows, /* try one node per row - for speed */
key, /* keys size */
data, /* data size */
@retval !0 valid THD_STRUCT
*/
-SFXHASH* sfthd_local_new(unsigned bytes)
+XHash* sfthd_local_new(unsigned bytes)
{
- SFXHASH* local_hash =
+ XHash* local_hash =
sfthd_new_hash(bytes,
sizeof(THD_IP_NODE_KEY),
sizeof(THD_IP_NODE));
return local_hash;
}
-SFXHASH* sfthd_global_new(unsigned bytes)
+XHash* sfthd_global_new(unsigned bytes)
{
- SFXHASH* global_hash =
+ XHash* global_hash =
sfthd_new_hash(bytes,
sizeof(THD_IP_GNODE_KEY),
sizeof(THD_IP_NODE));
#ifdef THD_DEBUG
printf("Could not allocate the sfxhash table\n");
#endif
- sfxhash_delete(thd->ip_nodes);
+ xhash_delete(thd->ip_nodes);
snort_free(thd);
return nullptr;
}
for (i = 0; i < THD_MAX_GENID; i++)
{
if (thd_objs->sfthd_array[i])
- sfghash_delete(thd_objs->sfthd_array[i]);
+ ghash_delete(thd_objs->sfthd_array[i]);
}
for (policyId = 0; policyId < thd_objs->numPoliciesAllocated; policyId++)
#ifndef CRIPPLE
if (thd->ip_nodes != nullptr)
- sfxhash_delete(thd->ip_nodes);
+ xhash_delete(thd->ip_nodes);
if (thd->ip_gnodes != nullptr)
- sfxhash_delete(thd->ip_gnodes);
+ xhash_delete(thd->ip_gnodes);
#endif
snort_free(thd);
static int sfthd_create_threshold_local(
SnortConfig*, ThresholdObjects* thd_objs, THD_NODE* config)
{
- SFGHASH* sfthd_hash;
+ GHash* sfthd_hash;
THD_ITEM* sfthd_item;
THD_NODE* sfthd_node;
tThdItemKey key;
}
/* Create the hash table for this gen_id */
- sfthd_hash = sfghash_new(nrows, sizeof(tThdItemKey), 0, sfthd_item_free);
+ sfthd_hash = ghash_new(nrows, sizeof(tThdItemKey), 0, sfthd_item_free);
if ( !sfthd_hash )
{
return -2;
key.policyId = policy_id;
/* Check if sig_id is already in the table - if not allocate and add it */
- sfthd_item = (THD_ITEM*)sfghash_find(sfthd_hash, (void*)&key);
+ sfthd_item = (THD_ITEM*)ghash_find(sfthd_hash, (void*)&key);
if ( !sfthd_item )
{
/* Create the sfthd_item hash node data */
}
/* Add the sfthd_item to the hash table */
- if ( sfghash_add(sfthd_hash, (void*)&key, sfthd_item) )
+ if ( ghash_add(sfthd_hash, (void*)&key, sfthd_item) )
{
sflist_free(sfthd_item->sfthd_node_list);
snort_free(sfthd_item);
#endif
-int sfthd_test_rule(SFXHASH* rule_hash, THD_NODE* sfthd_node,
+int sfthd_test_rule(XHash* rule_hash, THD_NODE* sfthd_node,
const SfIp* sip, const SfIp* dip, long curtime)
{
int status;
*
*/
int sfthd_test_local(
- SFXHASH* local_hash,
+ XHash* local_hash,
THD_NODE* sfthd_node,
const SfIp* sip,
const SfIp* dip,
/*
* Check for any Permanent sig_id objects for this gen_id or add this one ...
*/
- status = sfxhash_add(local_hash, (void*)&key, &data);
- if (status == SFXHASH_INTABLE)
+ status = xhash_add(local_hash, (void*)&key, &data);
+ if (status == XHASH_INTABLE)
{
/* Already in the table */
sfthd_ip_node = (THD_IP_NODE*)local_hash->cnode->data;
/* Increment the event count */
sfthd_ip_node->count++;
}
- else if (status != SFXHASH_OK)
+ else if (status != XHASH_OK)
{
/* hash error */
return 1; /* check the next threshold object */
* Test a global thresholding object
*/
static inline int sfthd_test_global(
- SFXHASH* global_hash,
+ XHash* global_hash,
THD_NODE* sfthd_node,
unsigned sig_id, /* from current event */
const SfIp* sip, /* " */
data.tstart = data.tlast = curtime; /* Event time */
/* Check for any Permanent sig_id objects for this gen_id or add this one ... */
- status = sfxhash_add(global_hash, (void*)&key, &data);
- if (status == SFXHASH_INTABLE)
+ status = xhash_add(global_hash, (void*)&key, &data);
+ if (status == XHASH_INTABLE)
{
/* Already in the table */
sfthd_ip_node = (THD_IP_NODE*)global_hash->cnode->data;
/* Increment the event count */
sfthd_ip_node->count++;
}
- else if (status != SFXHASH_OK)
+ else if (status != XHASH_OK)
{
/* hash error */
return 1; /* check the next threshold object */
long curtime)
{
tThdItemKey key;
- SFGHASH* sfthd_hash;
+ GHash* sfthd_hash;
THD_ITEM* sfthd_item;
THD_NODE* sfthd_node;
THD_NODE* g_thd_node = nullptr;
/*
* Check for any Permanent sig_id objects for this gen_id
*/
- sfthd_item = (THD_ITEM*)sfghash_find(sfthd_hash, (void*)&key);
+ sfthd_item = (THD_ITEM*)ghash_find(sfthd_hash, (void*)&key);
if (sfthd_item == nullptr)
{
#ifdef THD_DEBUG
THD_ITEM* sfthd_item;
THD_NODE* sfthd_node;
unsigned gen_id;
- SFGHASH_NODE* item_hash_node;
+ GHashNode* item_hash_node;
for (gen_id=0; gen_id < THD_MAX_GENID; gen_id++ )
{
- SFGHASH* sfthd_hash = thd_objs->sfthd_array[gen_id];
+ GHash* sfthd_hash = thd_objs->sfthd_array[gen_id];
if ( !sfthd_hash )
continue;
printf("...GEN_ID = %u\n",gen_id);
- for (item_hash_node = sfghash_findfirst(sfthd_hash);
+ for (item_hash_node = ghash_findfirst(sfthd_hash);
item_hash_node != 0;
- item_hash_node = sfghash_findnext(sfthd_hash) )
+ item_hash_node = ghash_findnext(sfthd_hash) )
{
/* Check for any Permanent sig_id objects for this gen_id */
sfthd_item = (THD_ITEM*)item_hash_node->data;
#include "sfip/sf_ip.h"
#include "utils/cpp_macros.h"
-struct SFGHASH;
-struct SFXHASH;
+struct GHash;
+struct XHash;
typedef struct sf_list SF_LIST;
/*!
*/
struct THD_STRUCT
{
- SFXHASH* ip_nodes; /* Global hash of active IP's key=THD_IP_NODE_KEY, data=THD_IP_NODE */
- SFXHASH* ip_gnodes; /* Global hash of active IP's key=THD_IP_GNODE_KEY, data=THD_IP_GNODE */
+ XHash* ip_nodes; /* Global hash of active IP's key=THD_IP_NODE_KEY, data=THD_IP_NODE */
+ XHash* ip_gnodes; /* Global hash of active IP's key=THD_IP_GNODE_KEY, data=THD_IP_GNODE */
};
struct ThresholdObjects
{
int count; /* Total number of thresholding/suppression objects */
- SFGHASH* sfthd_array[THD_MAX_GENID]; /* Local Hash of THD_ITEM nodes, lookup by key=sig_id
+ GHash* sfthd_array[THD_MAX_GENID]; /* Local Hash of THD_ITEM nodes, lookup by key=sig_id
*/
/* Double array of THD_NODE pointers. First index is policyId and therefore variable length.
// lbytes = local threshold memcap
// gbytes = global threshold memcap (0 to disable global)
THD_STRUCT* sfthd_new(unsigned lbytes, unsigned gbytes);
-SFXHASH* sfthd_local_new(unsigned bytes);
-SFXHASH* sfthd_global_new(unsigned bytes);
+XHash* sfthd_local_new(unsigned bytes);
+XHash* sfthd_global_new(unsigned bytes);
void sfthd_free(THD_STRUCT*);
ThresholdObjects* sfthd_objs_new();
void sfthd_objs_free(ThresholdObjects*);
-int sfthd_test_rule(SFXHASH* rule_hash, THD_NODE* sfthd_node,
+int sfthd_test_rule(XHash* rule_hash, THD_NODE* sfthd_node,
const SfIp* sip, const SfIp* dip, long curtime);
THD_NODE* sfthd_create_rule_threshold(
const SfIp* dip,
long curtime);
-SFXHASH* sfthd_new_hash(unsigned, size_t, size_t);
+XHash* sfthd_new_hash(unsigned, size_t, size_t);
int sfthd_test_local(
- SFXHASH* local_hash,
+ XHash* local_hash,
THD_NODE* sfthd_node,
const SfIp* sip,
const SfIp* dip,
#endif
#include "catch/catch.hpp"
-#include "hash/sfxhash.h"
+#include "hash/xhash.h"
#include "main/snort_types.h"
#include "parser/parse_ip.h"
#include "sfip/sf_ip.h"
static THD_STRUCT* pThd = nullptr;
static ThresholdObjects* pThdObjs = nullptr;
-static SFXHASH* dThd = nullptr;
+static XHash* dThd = nullptr;
//---------------------------------------------------------------
p->rule = nullptr;
}
}
- sfxhash_delete(dThd);
+ xhash_delete(dThd);
}
static int SetupCheck(int i)
This file contains functions that glue the generic thresholding2 code to
snort.
- dependent files: sfthd sfxghash sfghash sflsq
+ dependent files: sfthd sfxghash ghash sflsq
util mstring
Marc Norton
#include "sfthreshold.h"
-#include "hash/sfxhash.h"
+#include "hash/xhash.h"
#include "main/snort_config.h"
#include "utils/util.h"
static int print_thd_local(ThresholdObjects* thd_objs, PrintFormat type, unsigned* prnMode)
{
- SFGHASH* sfthd_hash;
+ GHash* sfthd_hash;
THD_ITEM* sfthd_item;
THD_NODE* sfthd_node;
int gen_id;
- SFGHASH_NODE* item_hash_node;
+ GHashNode* item_hash_node;
int lcnt=0;
PolicyId policyId;
continue;
}
- for (item_hash_node = sfghash_findfirst(sfthd_hash);
+ for (item_hash_node = ghash_findfirst(sfthd_hash);
item_hash_node != 0;
- item_hash_node = sfghash_findnext(sfthd_hash) )
+ item_hash_node = ghash_findnext(sfthd_hash) )
{
/* Check for any Permanent sig_id objects for this gen_id */
sfthd_item = (THD_ITEM*)item_hash_node->data;
#include "flow/flow_key.h"
-#include "hash/sfhashfcn.h"
+#include "hash/hashfcn.h"
#include "main/snort_config.h"
#include "protocols/icmp4.h"
#include "protocols/icmp6.h"
// hash foo
//-------------------------------------------------------------------------
-uint32_t FlowKey::hash(SFHASHFCN* hf, const unsigned char* p, int)
+uint32_t FlowKey::hash(HashFnc* hf, const unsigned char* p, int)
{
uint32_t a, b, c;
a = b = c = hf->hardener;
#include "framework/decode_data.h"
#include "utils/cpp_macros.h"
-struct SFHASHFCN;
+struct HashFnc;
struct SfIp;
PADDING_GUARD_BEGIN
void init_address_space(uint16_t);
// XXX If this data structure changes size, compare must be updated!
- static uint32_t hash(SFHASHFCN*, const unsigned char* d, int);
+ static uint32_t hash(HashFnc*, const unsigned char* d, int);
static int compare(const void* s1, const void* s2, size_t);
private:
#include <cstring>
-#include "hash/sfhashfcn.h"
+#include "hash/hashfcn.h"
static const char* s_buffer = nullptr;
set (HASH_INCLUDES
hashes.h
- sfghash.h
- sfxhash.h
- sfhashfcn.h
+ ghash.h
+ xhash.h
+ hashfcn.h
)
set (HASH_SOURCES )
hashes.cc
lru_cache_shared.h
lru_cache_shared.cc
- sfghash.cc
- sfhashfcn.cc
- sfprimetable.cc
- sfprimetable.h
- sfxhash.cc
+ ghash.cc
+ hashfcn.cc
+ primetable.cc
+ primetable.h
+ xhash.cc
zhash.cc
zhash.h
)
x_include_HEADERS = \
hashes.h \
-sfghash.h \
-sfxhash.h \
-sfhashfcn.h
+ghash.h \
+xhash.h \
+hashfcn.h
libhash_a_SOURCES = \
hashes.cc \
lru_cache_shared.cc \
lru_cache_shared.h \
-sfghash.cc \
-sfhashfcn.cc \
-sfprimetable.cc sfprimetable.h \
-sfxhash.cc \
+ghash.cc \
+hashfcn.cc \
+primetable.cc primetable.h \
+xhash.cc \
zhash.cc zhash.h
if BUILD_CPPUTESTS
/*
*
-* sfghash.c
+* ghash.c
*
* Generic hash table library.
*
#include "config.h"
#endif
-#include "sfghash.h"
+#include "ghash.h"
#include <cassert>
#include "utils/util.h"
-#include "sfhashfcn.h"
-#include "sfprimetable.h"
+#include "hashfcn.h"
+#include "primetable.h"
/*
*
* save the pointer to the key.
* ==0 => we should copy the keys and manage them internally
* userfree : routine to free users data, null if we should not
-* free user data in sfghash_delete(). The routine
+* free user data in ghash_delete(). The routine
* should be of the form 'void userfree(void * userdata)',
* 'free' works for simple allocations.
*/
-SFGHASH* sfghash_new(int nrows, int keysize, int userkeys, SfgHashFree userfree)
+GHash* ghash_new(int nrows, int keysize, int userkeys, gHashFree userfree)
{
if ( nrows > 0 ) /* make sure we have a prime number */
{
- nrows = sf_nearest_prime(nrows);
+ nrows = nearest_prime(nrows);
}
else /* use the magnitude or nrows as is */
{
nrows = -nrows;
}
- SFGHASH* h = (SFGHASH*)snort_calloc(sizeof(SFGHASH));
+ GHash* h = (GHash*)snort_calloc(sizeof(GHash));
- h->sfhashfcn = sfhashfcn_new(nrows);
- h->table = (SFGHASH_NODE**)snort_calloc(nrows, sizeof(SFGHASH_NODE*));
+ h->hashfcn = hashfcn_new(nrows);
+ h->table = (GHashNode**)snort_calloc(nrows, sizeof(GHashNode*));
for ( int i = 0; i < nrows; i++ )
{
* free key's, free node's, and free the users data, if they
* supply a free function
*/
-void sfghash_delete(SFGHASH* h)
+void ghash_delete(GHash* h)
{
if ( !h )
return;
- sfhashfcn_free(h->sfhashfcn);
+ hashfcn_free(h->hashfcn);
if ( h->table )
{
for (int i=0; i<h->nrows; i++)
{
- for ( SFGHASH_NODE* node=h->table[i]; node; )
+ for ( GHashNode* node=h->table[i]; node; )
{
- SFGHASH_NODE* onode = node;
+ GHashNode* onode = node;
node = node->next;
if ( !h->userkey && onode->key )
* linked list of data items held by the node, or track a counter, or whatever.
*
*/
-int sfghash_add(SFGHASH* t, const void* const key, void* const data)
+int ghash_add(GHash* t, const void* const key, void* const data)
{
unsigned hashkey;
int klen;
int index;
- SFGHASH_NODE* hnode;
+ GHashNode* hnode;
if (t == nullptr || key == nullptr)
- return SFGHASH_ERR;
+ return GHASH_ERR;
/*
* Get proper Key Size
}
else
{
- /* need the null byte for strcmp() in sfghash_find() */
+ /* need the null byte for strcmp() in ghash_find() */
klen = strlen( (const char*)key) + 1;
}
- hashkey = t->sfhashfcn->hash_fcn(t->sfhashfcn, (const unsigned char*)key, klen);
+ hashkey = t->hashfcn->hash_fcn(t->hashfcn, (const unsigned char*)key, klen);
index = hashkey % t->nrows;
{
if ( t->keysize > 0 )
{
- if ( !t->sfhashfcn->keycmp_fcn(hnode->key,key,klen) )
+ if ( !t->hashfcn->keycmp_fcn(hnode->key,key,klen) )
{
t->cnode = hnode; /* save pointer to the node */
- return SFGHASH_INTABLE; /* found it */
+ return GHASH_INTABLE; /* found it */
}
}
else
if ( !strcmp((const char*)hnode->key,(const char*)key) )
{
t->cnode = hnode; /* save pointer to the node */
- return SFGHASH_INTABLE; /* found it */
+ return GHASH_INTABLE; /* found it */
}
}
}
/*
* Create new node
*/
- hnode = (SFGHASH_NODE*)snort_calloc(sizeof(SFGHASH_NODE));
+ hnode = (GHashNode*)snort_calloc(sizeof(GHashNode));
/* Add the Key */
if ( t->userkey )
t->count++;
- return SFGHASH_OK;
+ return GHASH_OK;
}
/*
* Find a Node based on the key, return users data.
*/
-static SFGHASH_NODE* sfghash_find_node(SFGHASH* t, const void* const key)
+static GHashNode* ghash_find_node(GHash* t, const void* const key)
{
unsigned hashkey;
int index, klen;
- SFGHASH_NODE* hnode;
+ GHashNode* hnode;
assert(t);
klen = strlen( (const char*)key) + 1;
}
- hashkey = t->sfhashfcn->hash_fcn(t->sfhashfcn, (const unsigned char*)key, klen);
+ hashkey = t->hashfcn->hash_fcn(t->hashfcn, (const unsigned char*)key, klen);
index = hashkey % t->nrows;
}
else
{
- if ( !t->sfhashfcn->keycmp_fcn(hnode->key,key,t->keysize) )
+ if ( !t->hashfcn->keycmp_fcn(hnode->key,key,t->keysize) )
{
return hnode;
}
/*
* Find a Node based on the key, return users data.
*/
-void* sfghash_find(SFGHASH* t, const void* const key)
+void* ghash_find(GHash* t, const void* const key)
{
- SFGHASH_NODE* hnode;
+ GHashNode* hnode;
assert(t);
- hnode = sfghash_find_node(t, key);
+ hnode = ghash_find_node(t, key);
if ( hnode )
return hnode->data;
/*
* Unlink and free the node
*/
-static int sfghash_free_node(SFGHASH* t, unsigned index, SFGHASH_NODE* hnode)
+static int ghash_free_node(GHash* t, unsigned index, GHashNode* hnode)
{
assert(t);
t->count--;
- return SFGHASH_OK;
+ return GHASH_OK;
}
/*
* returns : 0 - OK
* -1 - node not found
*/
-int sfghash_remove(SFGHASH* t, const void* const key)
+int ghash_remove(GHash* t, const void* const key)
{
- SFGHASH_NODE* hnode;
+ GHashNode* hnode;
int klen;
unsigned hashkey, index;
klen = strlen((const char*)key) + 1;
}
- hashkey = t->sfhashfcn->hash_fcn(t->sfhashfcn, (const unsigned char*)key, klen);
+ hashkey = t->hashfcn->hash_fcn(t->hashfcn, (const unsigned char*)key, klen);
index = hashkey % t->nrows;
{
if ( t->keysize > 0 )
{
- if ( !t->sfhashfcn->keycmp_fcn(hnode->key,key,klen) )
+ if ( !t->hashfcn->keycmp_fcn(hnode->key,key,klen) )
{
- return sfghash_free_node(t, index, hnode);
+ return ghash_free_node(t, index, hnode);
}
}
else
{
if ( !strcmp((const char*)hnode->key,(const char*)key) )
{
- return sfghash_free_node(t, index, hnode);
+ return ghash_free_node(t, index, hnode);
}
}
}
- return SFGHASH_ERR;
+ return GHASH_ERR;
}
/* Internal use only */
-static void sfghash_next(SFGHASH* t)
+static void ghash_next(GHash* t)
{
assert(t and t->cnode);
/*
* Get First Hash Table Node
*/
-SFGHASH_NODE* sfghash_findfirst(SFGHASH* t)
+GHashNode* ghash_findfirst(GHash* t)
{
- SFGHASH_NODE* n;
+ GHashNode* n;
assert(t);
/* Start with 1st row */
{
n = t->cnode;
- sfghash_next(t); // load t->cnode with the next entry
+ ghash_next(t); // load t->cnode with the next entry
return n;
}
/*
* Get Next Hash Table Node
*/
-SFGHASH_NODE* sfghash_findnext(SFGHASH* t)
+GHashNode* ghash_findnext(GHash* t)
{
- SFGHASH_NODE* n;
+ GHashNode* n;
assert(t);
/*
Preload next node into current node
*/
- sfghash_next(t);
+ ghash_next(t);
return n;
}
/**
- * Make sfhashfcn use a separate set of opcodes for the backend.
+ * Make hashfcn use a separate set of opcodes for the backend.
*
- * @param h sfhashfcn ptr
+ * @param h hashfcn ptr
* @param hash_fcn user specified hash function
* @param keycmp_fcn user specified key comparison function
*/
-int sfghash_set_keyops(SFGHASH* h,
- unsigned (* hash_fcn)(SFHASHFCN* p, const unsigned char* d, int n),
+int ghash_set_keyops(GHash* h,
+ unsigned (* hash_fcn)(HashFnc* p, const unsigned char* d, int n),
int (* keycmp_fcn)(const void* s1, const void* s2, size_t n))
{
assert(h && hash_fcn && keycmp_fcn);
- return sfhashfcn_set_keyops(h->sfhashfcn, hash_fcn, keycmp_fcn);
+ return hashfcn_set_keyops(h->hashfcn, hash_fcn, keycmp_fcn);
}
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//--------------------------------------------------------------------------
-// sfghash.h author Marc Norton
+// ghash.h author Marc Norton
-#ifndef SFGHASH_H
-#define SFGHASH_H
+#ifndef GHASH_H
+#define GHASH_H
// generic hash table - stores and maps key + data pairs
#include "main/snort_types.h"
-struct SFHASHFCN;
+struct HashFnc;
-#define SFGHASH_NOMEM (-2)
-#define SFGHASH_ERR (-1)
-#define SFGHASH_OK 0
-#define SFGHASH_INTABLE 1
+#define GHASH_NOMEM (-2)
+#define GHASH_ERR (-1)
+#define GHASH_OK 0
+#define GHASH_INTABLE 1
// Flags for ghash_new: userkeys
#define GH_COPYKEYS 0
#define GH_USERKEYS 1
-struct SFGHASH_NODE
+struct GHashNode
{
- struct SFGHASH_NODE* next, * prev;
+ struct GHashNode* next, * prev;
const void* key; /* Copy of, or Pointer to, the Users key */
void* data; /* The users data, this is never copied! */
};
-typedef void (* SfgHashFree)(void*);
+typedef void (* gHashFree)(void*);
-struct SFGHASH
+struct GHash
{
- SFHASHFCN* sfhashfcn;
+ HashFnc* hashfcn;
int keysize; /* bytes in key, if < 0 -> keys are strings */
int userkey; /* user owns the key */
- SFGHASH_NODE** table; /* array of node ptr's */
+ GHashNode** table; /* array of node ptr's */
int nrows; /* # rows int the hash table use a prime number 211, 9871 */
unsigned count; /* total # nodes in table */
- SfgHashFree userfree;
+ gHashFree userfree;
int crow; /* findfirst/next row in table */
- SFGHASH_NODE* cnode; /* findfirst/next node ptr */
+ GHashNode* cnode; /* findfirst/next node ptr */
};
-SO_PUBLIC SFGHASH* sfghash_new(int nrows, int keysize, int userkeys, SfgHashFree);
-SO_PUBLIC void sfghash_delete(SFGHASH*);
-SO_PUBLIC int sfghash_add(SFGHASH*, const void* const key, void* const data);
-SO_PUBLIC int sfghash_remove(SFGHASH*, const void* const key);
-SO_PUBLIC void* sfghash_find(SFGHASH*, const void* const key);
-SO_PUBLIC SFGHASH_NODE* sfghash_findfirst(SFGHASH*);
-SO_PUBLIC SFGHASH_NODE* sfghash_findnext(SFGHASH*);
-SO_PUBLIC int sfghash_set_keyops(SFGHASH*,
- unsigned (* hash_fcn)(SFHASHFCN* p, const unsigned char* d, int n),
- int (* keycmp_fcn)(const void* s1, const void* s2, size_t n));
+SO_PUBLIC GHash* ghash_new(int nrows, int keysize, int userkeys, gHashFree);
+SO_PUBLIC void ghash_delete(GHash*);
+SO_PUBLIC int ghash_add(GHash*, const void* const key, void* const data);
+SO_PUBLIC int ghash_remove(GHash*, const void* const key);
+SO_PUBLIC void* ghash_find(GHash*, const void* const key);
+SO_PUBLIC GHashNode* ghash_findfirst(GHash*);
+SO_PUBLIC GHashNode* ghash_findnext(GHash*);
+SO_PUBLIC int ghash_set_keyops(GHash*,
+unsigned (* hash_fcn)(HashFnc* p, const unsigned char* d, int n),
+int (* keycmp_fcn)(const void* s1, const void* s2, size_t n));
#endif
//--------------------------------------------------------------------------
/*
- sfhashfcn.c
+ hashfcn.c
- Each hash table must allocate it's own SFGHASH struct, this is because
- sfghash_new uses the number of rows in the hash table to modulo the random
+ Each hash table must allocate it's own GHash struct, this is because
+ ghash_new uses the number of rows in the hash table to modulo the random
values.
Updates:
#include "config.h"
#endif
-#include "sfhashfcn.h"
+#include "hashfcn.h"
#include "main/snort_config.h"
#include "utils/util.h"
-#include "sfprimetable.h"
+#include "primetable.h"
-SFHASHFCN* sfhashfcn_new(int m)
+HashFnc* hashfcn_new(int m)
{
- SFHASHFCN* p;
+ HashFnc* p;
static int one=1;
if ( one ) /* one time init */
one = 0;
}
- p = (SFHASHFCN*)snort_calloc(sizeof(*p));
+ p = (HashFnc*)snort_calloc(sizeof(*p));
if ( SnortConfig::static_hash() )
{
}
else
{
- p->seed = sf_nearest_prime( (rand()%m)+3191);
- p->scale = sf_nearest_prime( (rand()%m)+709);
+ p->seed = nearest_prime( (rand()%m)+3191);
+ p->scale = nearest_prime( (rand()%m)+709);
p->hardener = (rand()*rand()) + 133824503;
}
- p->hash_fcn = &sfhashfcn_hash;
+ p->hash_fcn = &hashfcn_hash;
p->keycmp_fcn = &memcmp;
return p;
}
-void sfhashfcn_free(SFHASHFCN* p)
+void hashfcn_free(HashFnc* p)
{
if ( p )
{
}
}
-unsigned sfhashfcn_hash(SFHASHFCN* p, const unsigned char* d, int n)
+unsigned hashfcn_hash(HashFnc* p, const unsigned char* d, int n)
{
unsigned hash = p->seed;
while ( n )
}
/**
- * Make sfhashfcn use a separate set of opcodes for the backend.
+ * Make hashfcn use a separate set of opcodes for the backend.
*
- * @param h sfhashfcn ptr
+ * @param h hashfcn ptr
* @param hash_fcn user specified hash function
* @param keycmp_fcn user specified key comparison function
*/
-int sfhashfcn_set_keyops(SFHASHFCN* h,
- unsigned (* hash_fcn)(SFHASHFCN* p, const unsigned char* d, int n),
+int hashfcn_set_keyops(HashFnc* h,
+ unsigned (* hash_fcn)(HashFnc* p, const unsigned char* d, int n),
int (* keycmp_fcn)(const void* s1, const void* s2, size_t n))
{
if (h && hash_fcn && keycmp_fcn)
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//--------------------------------------------------------------------------
-#ifndef SFHASHFCN_H
-#define SFHASHFCN_H
+#ifndef HashFnc_H
+#define HashFnc_H
#include "main/snort_types.h"
SO_PUBLIC size_t str_to_hash(const uint8_t *str, int length);
-struct SFHASHFCN
+struct HashFnc
{
unsigned seed;
unsigned scale;
unsigned hardener;
// FIXIT-H use types for these callbacks
- unsigned (* hash_fcn)(SFHASHFCN*, const unsigned char* d, int n);
+ unsigned (* hash_fcn)(HashFnc*, const unsigned char* d, int n);
int (* keycmp_fcn)(const void* s1, const void* s2, size_t n);
};
-SFHASHFCN* sfhashfcn_new(int nrows);
-void sfhashfcn_free(SFHASHFCN*);
+HashFnc* hashfcn_new(int nrows);
+void hashfcn_free(HashFnc*);
-unsigned sfhashfcn_hash(SFHASHFCN*, const unsigned char* d, int n);
+unsigned hashfcn_hash(HashFnc*, const unsigned char* d, int n);
-int sfhashfcn_set_keyops(
- SFHASHFCN*,
+int hashfcn_set_keyops(
+ HashFnc*,
// FIXIT-H use types for these callbacks
- unsigned (* hash_fcn)(SFHASHFCN* p, const unsigned char* d, int n),
+ unsigned (* hash_fcn)(HashFnc* p, const unsigned char* d, int n),
int (* keycmp_fcn)(const void* s1, const void* s2, size_t n) );
#endif
* Prime number calculation via Table lookups.
*
* This was implemented for use with the hashing functions
-* in sfghash, and sfxhash.
+* in ghash, and sfxhash.
*
*/
#include "config.h"
#endif
-#include "sfprimetable.h"
+#include "primetable.h"
/* 0-8K, increments=8 */
static unsigned prime_table0[1024]=
134086639, /* 134086656 */ 134217689, /* 134217728 */
};
-int sf_nearest_prime(int n)
+int nearest_prime(int n)
{
if ( n < 0 )
n = -n;
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//--------------------------------------------------------------------------
-#ifndef SFPRIMETABLE_H
-#define SFPRIMETABLE_H
+#ifndef PRIMETABLE_H
+#define PRIMETABLE_H
-int sf_nearest_prime(int n);
+int nearest_prime(int n);
#endif
add_cpputest(lru_cache_shared_test hash)
-add_cpputest(sfghash_test hash)
+add_cpputest(ghash_test hash)
check_PROGRAMS = \
lru_cache_shared_test \
-sfghash_test
+ghash_test
TESTS = $(check_PROGRAMS)
lru_cache_shared_test_CPPFLAGS = $(AM_CPPFLAGS) @CPPUTEST_CPPFLAGS@
lru_cache_shared_test_LDADD = ../lru_cache_shared.o @CPPUTEST_LDFLAGS@
-sfghash_test_CPPFLAGS = $(AM_CPPFLAGS) @CPPUTEST_CPPFLAGS@
-sfghash_test_LDADD = ../libhash.a @CPPUTEST_LDFLAGS@
+ghash_test_CPPFLAGS = $(AM_CPPFLAGS) @CPPUTEST_CPPFLAGS@
+ghash_test_LDADD = ../libhash.a @CPPUTEST_LDFLAGS@
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//--------------------------------------------------------------------------
-// sfg_hash_test.cc author Steven Baigal <sbaigal@cisco.com>
-// unit tests for sfghash utility functions
+// ghash_test.cc author Steven Baigal <sbaigal@cisco.com>
+// unit tests for ghash utility functions
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
-#include "hash/sfghash.h"
+#include "hash/ghash.h"
#include "main/snort_config.h"
THREAD_LOCAL SnortConfig *snort_conf = &my_config;
SnortConfig::SnortConfig(SnortConfig*)
-{ snort_conf->run_flags = 0;} // run_flags is used indirectly from SFHASHFCN class by calling SnortConfig::static_hash()
+{ snort_conf->run_flags = 0;} // run_flags is used indirectly from HashFnc class by calling SnortConfig::static_hash()
SnortConfig::~SnortConfig() = default;
snort_free(p);
}
-TEST_GROUP(sfghash)
+TEST_GROUP(ghash)
{
};
// Test create a hash table, add nodes, find and delete.
-TEST(sfghash, create_find_delete_test)
+TEST(ghash, create_find_delete_test)
{
int i;
char str[256];
int num=100;
// Create a Hash Table
- SFGHASH* t = sfghash_new(1000, 0, GH_COPYKEYS, nullptr);
+ GHash* t = ghash_new(1000, 0, GH_COPYKEYS, nullptr);
// Add Nodes to the Hash Table
for (i=0; i<num; i++)
{
snprintf(str, sizeof(str), "KeyWord%d",i+1);
str[sizeof(str) - 1] = '\0';
- sfghash_add(t, str, (void *)(str + (i+1)));
+ ghash_add(t, str, (void *)(str + (i+1)));
}
// find those nodes
snprintf(str, sizeof(str), "KeyWord%d",i+1);
str[sizeof(str) - 1] = '\0';
- char* p = (char*)sfghash_find(t, str);
+ char* p = (char*)ghash_find(t, str);
CHECK(p != nullptr);
CHECK(p == (void *)(str + (i+1)));
}
- for (SFGHASH_NODE* n = sfghash_findfirst(t); n; n = sfghash_findnext(t) )
+ for (GHashNode* n = ghash_findfirst(t); n; n = ghash_findnext(t) )
{
- i = sfghash_remove(t,n->key);
+ i = ghash_remove(t,n->key);
CHECK(i==0);
}
- sfghash_delete(t);
+ ghash_delete(t);
}
// test to generate collisions and increase test code coverage
-TEST(sfghash, collision_test)
+TEST(ghash, collision_test)
{
int i;
char str[256];
int num=100;
// Create a Hash Table with smaller entries
- SFGHASH* t = sfghash_new(-10, 0, GH_COPYKEYS, nullptr);
+ GHash* t = ghash_new(-10, 0, GH_COPYKEYS, nullptr);
CHECK(t != nullptr);
{
snprintf(str, sizeof(str), "KeyWord%d",i+1);
str[sizeof(str) - 1] = '\0';
- sfghash_add(t, str, (void *)(str + (i+1)));
+ ghash_add(t, str, (void *)(str + (i+1)));
}
// try to add an existed entry
snprintf(str, sizeof(str), "KeyWord%d",1);
str[sizeof(str) - 1] = '\0';
- i = sfghash_add(t, str, (void *)(str + (1)));
- CHECK(i == SFGHASH_INTABLE);
+ i = ghash_add(t, str, (void *)(str + (1)));
+ CHECK(i == GHASH_INTABLE);
// find those nodes
for (i=num-1; i>=0; i--)
snprintf(str, sizeof(str), "KeyWord%d",i+1);
str[sizeof(str) - 1] = '\0';
- char* p = (char*)sfghash_find(t, str);
+ char* p = (char*)ghash_find(t, str);
CHECK(p != nullptr);
CHECK(p == (void *)(str + (i+1)));
}
// remove one node
- SFGHASH_NODE* n = sfghash_findfirst(t);
+ GHashNode* n = ghash_findfirst(t);
if (n)
{
- n = sfghash_findnext(t);
- i = sfghash_remove(t,n->key);
+ n = ghash_findnext(t);
+ i = ghash_remove(t,n->key);
CHECK(i==0);
}
// remove rest of nodes
- for ( n = sfghash_findfirst(t); n; n = sfghash_findnext(t) )
+ for ( n = ghash_findfirst(t); n; n = ghash_findnext(t) )
{
- i = sfghash_remove(t,n->key);
+ i = ghash_remove(t,n->key);
CHECK(i==0);
}
- sfghash_delete(t);
+ ghash_delete(t);
}
-TEST(sfghash, userfree_test)
+TEST(ghash, userfree_test)
{
char str[256];
int i;
// Create a small Hash Table with user free
- SFGHASH* t = sfghash_new(-5, 0, GH_COPYKEYS, myfree);
+ GHash* t = ghash_new(-5, 0, GH_COPYKEYS, myfree);
// add 5 nodes
for (i=0; i<5; i++)
{
char* p = (char*)snort_alloc(32);
p[0] = (char)(i+1);
p[1] = '\0';
- sfghash_add(t, str, (void *)p);
+ ghash_add(t, str, (void *)p);
}
// find those nodes
snprintf(str, sizeof(str), "KeyWord%d",i+1);
str[sizeof(str) - 1] = '\0';
- char *p = (char*)sfghash_find(t, str);
+ char *p = (char*)ghash_find(t, str);
CHECK(p != nullptr);
CHECK(p[0] == (i+1));
str[sizeof(str) - 1] = '\0';
// it should not be found
- CHECK(sfghash_find(t, str) == nullptr);
+ CHECK(ghash_find(t, str) == nullptr);
// try to remove a node that is not in the table
- CHECK(sfghash_remove(t, str) == SFGHASH_ERR);
+ CHECK(ghash_remove(t, str) == GHASH_ERR);
- for ( SFGHASH_NODE* n = sfghash_findfirst(t); n; n = sfghash_findnext(t) )
+ for ( GHashNode* n = ghash_findfirst(t); n; n = ghash_findnext(t) )
{
// user free should be called here, no memory leak should be detected
- i = sfghash_remove(t,n->key);
+ i = ghash_remove(t,n->key);
CHECK(i==0);
}
- sfghash_delete(t);
+ ghash_delete(t);
}
-TEST(sfghash, nullptr_test)
+TEST(ghash, nullptr_test)
{
- CHECK(SFGHASH_ERR == sfghash_add(nullptr, nullptr, nullptr));
- sfghash_delete(nullptr);
+ CHECK(GHASH_ERR == ghash_add(nullptr, nullptr, nullptr));
+ ghash_delete(nullptr);
}
int main(int argc, char** argv)
*
* Per Node Memory Usage:
* ----------------------
- * SFXHASH_NODE bytes
+ * XHashNode bytes
* KEYSIZE bytes
- * [DATASIZE bytes] if datasize > 0 during call to sfxhash_new.
+ * [DATASIZE bytes] if datasize > 0 during call to xhash_new.
*
- * The hash node memory (sfxhash_node,key,and data) is allocated with
+ * The hash node memory (xhash_node,key,and data) is allocated with
* one call to s_alloc/memcap_alloc.
*
* Author: Marc Norton
*
- * 2003-06-03: cmg - added sfxhash_{l,m}ru to return {least,most}
+ * 2003-06-03: cmg - added xhash_{l,m}ru to return {least,most}
* recently used node from the global list
*
* - added _anrcount 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.
+ * 2005-11-15: modified xhash_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.
* 8/31/2006: man - changed to use prime table lookup.
#include "config.h"
#endif
-#include "sfxhash.h"
+#include "xhash.h"
#include <cassert>
#include "utils/util.h"
-#include "sfhashfcn.h"
+#include "hashfcn.h"
/*
- * Implements SFXHASH as specialized hash container
+ * Implements XHash as specialized hash container
*/
/*
* Private Malloc - abstract the memory system
*/
-static inline void* s_alloc(SFXHASH* t, int n)
+static inline void* s_alloc(XHash* t, int n)
{
return sfmemcap_alloc(&t->mc, n);
}
-static inline void s_free(SFXHASH* t, void* p)
+static inline void s_free(XHash* t, void* p)
{
sfmemcap_free(&t->mc, p);
}
-static int sfxhash_nearest_powerof2(int nrows)
+static int xhash_nearest_powerof2(int nrows)
{
nrows -= 1;
for (unsigned i=1; i<sizeof(nrows) * 8; i <<= 1)
* anrfree users Automatic Node Recovery memory release function
* usrfree users standard memory release function
*
- * return SFXHASH*
+ * return XHash*
* retval 0 out of memory
- * retval !0 Valid SFXHASH pointer
+ * retval !0 Valid XHash pointer
*/
/*
Notes:
maxmem of 0 indicates no memory limits.
*/
-SFXHASH* sfxhash_new(int nrows, int keysize, int datasize, unsigned long maxmem,
+XHash* xhash_new(int nrows, int keysize, int datasize, unsigned long maxmem,
int anr_flag,
- SFXHASH_FREE_FCN anrfree,
- SFXHASH_FREE_FCN usrfree,
+ XHash_FREE_FCN anrfree,
+ XHash_FREE_FCN usrfree,
int recycle_flag)
{
if ( nrows > 0 ) /* make sure we have a prime number */
{
/* If nrows is not a power of two, need to find the
* next highest power of two */
- nrows = sfxhash_nearest_powerof2(nrows);
+ nrows = xhash_nearest_powerof2(nrows);
}
else /* use the magnitude of nrows as is */
{
}
/* Allocate the table structure from general memory */
- SFXHASH* h = (SFXHASH*)snort_calloc(sizeof(SFXHASH));
+ XHash* h = (XHash*)snort_calloc(sizeof(XHash));
/* this has a default hashing function */
- h->sfhashfcn = sfhashfcn_new(nrows);
+ h->hashfcn = hashfcn_new(nrows);
sfmemcap_init(&h->mc, maxmem);
/* Allocate the array of node ptrs */
- h->table = (SFXHASH_NODE**)s_alloc(h, sizeof(SFXHASH_NODE*) * nrows);
+ h->table = (XHashNode**)s_alloc(h, sizeof(XHashNode*) * nrows);
if ( !h->table )
{
- snort_free(h->sfhashfcn);
+ snort_free(h->hashfcn);
snort_free(h);
return nullptr;
}
* Set the maximum nodes used in this hash table.
* Specifying 0 is unlimited (or otherwise limited by memcap).
*
- * h SFXHASH table pointer
+ * h XHash table pointer
* max_nodes maximum nodes to allow.
*
*/
-void sfxhash_set_max_nodes(SFXHASH* h, int max_nodes)
+void xhash_set_max_nodes(XHash* h, int max_nodes)
{
if (h)
{
* No need to call the user free, since that should've been
* done when those nodes were put back in the free list.
*
- * h SFXHASH table pointer
+ * h XHash table pointer
*/
-static void sfxhash_delete_free_list(SFXHASH* t)
+static void xhash_delete_free_list(XHash* t)
{
if (t == nullptr || t->fhead == nullptr)
return;
- SFXHASH_NODE* cur = t->fhead;
+ XHashNode* cur = t->fhead;
while (cur != nullptr)
{
- SFXHASH_NODE* next = cur->gnext;
+ XHashNode* next = cur->gnext;
s_free(t, (void*)cur);
cur = next;
}
*
* free key's, free node's, and free the users data.
*
- * h SFXHASH table pointer
+ * h XHash table pointer
*
*/
-void sfxhash_delete(SFXHASH* h)
+void xhash_delete(XHash* h)
{
if ( !h )
return;
- if ( h->sfhashfcn )
- sfhashfcn_free(h->sfhashfcn);
+ if ( h->hashfcn )
+ hashfcn_free(h->hashfcn);
if ( h->table )
{
for (unsigned i = 0; i < h->nrows; i++)
{
- for ( SFXHASH_NODE* node = h->table[i]; node; )
+ for ( XHashNode* node = h->table[i]; node; )
{
- SFXHASH_NODE* onode = node;
+ XHashNode* onode = node;
node = node->next;
/* Notify user that we are about to free this node function */
h->table = nullptr;
}
- sfxhash_delete_free_list(h);
+ xhash_delete_free_list(h);
snort_free(h); /* free the table from general memory */
}
/*!
* Empty out the hash table
*
- * h SFXHASH table pointer
+ * h XHash table pointer
*
* return -1 on error
*/
-int sfxhash_make_empty(SFXHASH* h)
+int xhash_make_empty(XHash* h)
{
- SFXHASH_NODE* tmp = nullptr;
+ XHashNode* tmp = nullptr;
if (h == nullptr)
return -1;
for (unsigned i = 0; i < h->nrows; i++)
{
- for (SFXHASH_NODE* n = h->table[i]; n != nullptr; n = tmp)
+ for (XHashNode* n = h->table[i]; n != nullptr; n = tmp)
{
tmp = n->next;
- if (sfxhash_free_node(h, n) != SFXHASH_OK)
+ if (xhash_free_node(h, n) != XHASH_OK)
{
return -1;
}
/** Save the freed node for later use (recylcing).
* Free List - uses the NODE gnext/gprev fields
*/
-static void sfxhash_save_free_node(SFXHASH* t, SFXHASH_NODE* hnode)
+static void xhash_save_free_node(XHash* t, XHashNode* hnode)
{
/* Add A Node to the Free Node List */
if ( t->fhead ) /* add the node to head of the the existing list */
/**Get a previously freed node for reuse.
*/
-static SFXHASH_NODE* sfxhash_get_free_node(SFXHASH* t)
+static XHashNode* xhash_get_free_node(XHash* t)
{
- SFXHASH_NODE* node = t->fhead;
+ XHashNode* node = t->fhead;
/* Remove A Node from the Free Node List - remove the head node */
if ( t->fhead )
return node;
}
-static void sfxhash_glink_node(SFXHASH* t, SFXHASH_NODE* hnode)
+static void xhash_glink_node(XHash* t, XHashNode* hnode)
{
/* Add The Node */
if ( t->ghead ) /* add the node to head of the the existing list */
}
}
-static void sfxhash_gunlink_node(SFXHASH* t, SFXHASH_NODE* hnode)
+static void xhash_gunlink_node(XHash* t, XHashNode* hnode)
{
if ( t->gnode == hnode ) /* if this was the global next node */
{
/**Move node to the front of global list. Node movement is application specific.
*/
-void sfxhash_gmovetofront(SFXHASH* t, SFXHASH_NODE* hnode)
+void xhash_gmovetofront(XHash* t, XHashNode* hnode)
{
if ( hnode != t->ghead )
{
- sfxhash_gunlink_node(t, hnode);
- sfxhash_glink_node(t, hnode);
+ xhash_gunlink_node(t, hnode);
+ xhash_glink_node(t, hnode);
}
}
/*
*
*/
-static void sfxhash_link_node(SFXHASH* t, SFXHASH_NODE* hnode)
+static void xhash_link_node(XHash* t, XHashNode* hnode)
{
/* Add The Node to the Hash Table Row List */
if ( t->table[hnode->rindex] ) /* add the node to the existing list */
}
}
-static void sfxhash_unlink_node(SFXHASH* t, SFXHASH_NODE* hnode)
+static void xhash_unlink_node(XHash* t, XHashNode* hnode)
{
if ( hnode->prev ) // definitely not the 1st node in the list
{
/*
* move a node to the front of the row list at row = 'index'
*/
-static void movetofront(SFXHASH* t, SFXHASH_NODE* n)
+static void movetofront(XHash* t, XHashNode* n)
{
/* Modify Hash Node Row List */
if ( t->table[n->rindex] != n ) // if not at front of list already...
{
/* Unlink the node */
- sfxhash_unlink_node(t, n);
+ xhash_unlink_node(t, n);
/* Link at front of list */
- sfxhash_link_node(t, n);
+ xhash_link_node(t, n);
}
/* Move node in the global hash node list to the front */
if (n == t->gnode)
t->gnode = n->gnext;
- sfxhash_gmovetofront(t, n);
+ xhash_gmovetofront(t, n);
}
/*
* to the front of the list. The oldest node is just the tail node.
*
*/
-static SFXHASH_NODE* sfxhash_newnode(SFXHASH* t)
+static XHashNode* xhash_newnode(XHash* t)
{
/* Recycle Old Nodes - if any */
- SFXHASH_NODE* hnode = sfxhash_get_free_node(t);
+ XHashNode* hnode = xhash_get_free_node(t);
/* Allocate memory for a node */
if ( !hnode )
{
if ((t->max_nodes == 0) || (t->count < t->max_nodes))
{
- hnode = (SFXHASH_NODE*)s_alloc(t, sizeof(SFXHASH_NODE) + t->pad +
+ hnode = (XHashNode*)s_alloc(t, sizeof(XHashNode) + t->pad +
t->keysize + t->datasize);
}
}
/* YES, user said we can recycle this node */
}
- sfxhash_gunlink_node(t, hnode); /* unlink from the global list */
- sfxhash_unlink_node(t, hnode); /* unlink from the row list */
+ xhash_gunlink_node(t, hnode); /* unlink from the global list */
+ xhash_unlink_node(t, hnode); /* unlink from the row list */
t->count--;
t->anr_count++; /* count # of ANR operations */
break;
#define hashsize(n) ((uint32_t)1<<(n))
#define hashmask(n) (hashsize(n)-1)
-static SFXHASH_NODE* sfxhash_find_node_row(SFXHASH* t, const void* key, int* rindex)
+static XHashNode* xhash_find_node_row(XHash* t, const void* key, int* rindex)
{
- unsigned hashkey = t->sfhashfcn->hash_fcn(t->sfhashfcn, (const unsigned char*)key, t->keysize);
+ unsigned hashkey = t->hashfcn->hash_fcn(t->hashfcn, (const unsigned char*)key, t->keysize);
/* printf("hashkey: %u t->keysize: %d\n", hashkey, t->keysize);
flowkey_fprint(stdout, key);
int index = hashkey & (t->nrows - 1);
*rindex = index;
- for (SFXHASH_NODE* hnode = t->table[index]; hnode; hnode = hnode->next )
+ for (XHashNode* hnode = t->table[index]; hnode; hnode = hnode->next )
{
- if ( !t->sfhashfcn->keycmp_fcn(hnode->key, key, t->keysize) )
+ if ( !t->hashfcn->keycmp_fcn(hnode->key, key, t->keysize) )
{
if ( t->splay > 0 )
movetofront(t, hnode);
*
* This is done because of the successful find.
*
- * t SFXHASH table pointer
+ * t XHash table pointer
* key users key pointer
* data users data pointer
*
* return integer
- * retval SFXHASH_OK success
- * retval SFXHASH_INTABLE already in the table, t->cnode points to the node
- * retval SFXHASH_NOMEM not enough memory
+ * retval XHASH_OK success
+ * retval XHASH_INTABLE already in the table, t->cnode points to the node
+ * retval XHASH_NOMEM not enough memory
*/
-static int sfxhash_add_ex(SFXHASH* t, const void* key, void* data, void** data_ptr)
+static int xhash_add_ex(XHash* t, const void* key, void* data, void** data_ptr)
{
int index = 0;
/* Enforce uniqueness: Check for the key in the table */
- SFXHASH_NODE* hnode = sfxhash_find_node_row(t, key, &index);
+ XHashNode* hnode = xhash_find_node_row(t, key, &index);
if ( hnode )
{
t->cnode = hnode;
if (data_ptr)
*data_ptr = hnode->data;
- return SFXHASH_INTABLE; /* found it - return it. */
+ return XHASH_INTABLE; /* found it - return it. */
}
/*
* Alloc new hash node - allocate key space and data space at the same time.
*/
- hnode = sfxhash_newnode(t);
+ hnode = xhash_newnode(t);
if ( !hnode )
{
- return SFXHASH_NOMEM;
+ return XHASH_NOMEM;
}
/* Set up the new key pointer */
- hnode->key = (char*)hnode + sizeof(SFXHASH_NODE);
+ hnode->key = (char*)hnode + sizeof(XHashNode);
/* Copy the key */
memcpy(hnode->key,key,t->keysize);
if ( t->datasize )
{
/* Set up the new data pointer */
- hnode->data= (char*)hnode + sizeof(SFXHASH_NODE) + t->pad + t->keysize;
+ hnode->data= (char*)hnode + sizeof(XHashNode) + t->pad + t->keysize;
if (data)
{
}
/* Link the node into the table row list */
- sfxhash_link_node (t, hnode);
+ xhash_link_node (t, hnode);
/* Link at the front of the global node list */
- sfxhash_glink_node(t, hnode);
+ xhash_glink_node(t, hnode);
/* Track # active nodes */
t->count++;
- return SFXHASH_OK;
+ return XHASH_OK;
}
-int sfxhash_add(SFXHASH* t, void* key, void* data)
+int xhash_add(XHash* t, void* key, void* data)
{
- return sfxhash_add_ex(t, key, data, nullptr);
+ return xhash_add_ex(t, key, data, nullptr);
}
/*!
*
* This is done because of the successful find.
*
- * t SFXHASH table pointer
+ * t XHash table pointer
* key users key pointer
*
* return integer
- * retval SFXHASH_OK success
- * retval SFXHASH_INTABLE already in the table, t->cnode points to the node
- * retval SFXHASH_NOMEM not enough memory
+ * retval XHASH_OK success
+ * retval XHASH_INTABLE already in the table, t->cnode points to the node
+ * retval XHASH_NOMEM not enough memory
*/
-SFXHASH_NODE* sfxhash_get_node(SFXHASH* t, const void* key)
+XHashNode* xhash_get_node(XHash* t, const void* key)
{
int index = 0;
/* Enforce uniqueness: Check for the key in the table */
- SFXHASH_NODE* hnode = sfxhash_find_node_row(t, key, &index);
+ XHashNode* hnode = xhash_find_node_row(t, key, &index);
if ( hnode )
{
t->cnode = hnode;
/*
* Alloc new hash node - allocate key space and data space at the same time.
*/
- hnode = sfxhash_newnode(t);
+ hnode = xhash_newnode(t);
if ( !hnode )
{
return nullptr;
}
/* Set up the new key pointer */
- hnode->key = (char*)hnode + sizeof(SFXHASH_NODE);
+ hnode->key = (char*)hnode + sizeof(XHashNode);
/* Copy the key */
memcpy(hnode->key,key,t->keysize);
if ( t->datasize )
{
/* Set up the new data pointer */
- hnode->data = (char*)hnode + sizeof(SFXHASH_NODE) + t->pad + t->keysize;
+ hnode->data = (char*)hnode + sizeof(XHashNode) + t->pad + t->keysize;
}
else
{
}
/* Link the node into the table row list */
- sfxhash_link_node (t, hnode);
+ xhash_link_node (t, hnode);
/* Link at the front of the global node list */
- sfxhash_glink_node(t, hnode);
+ xhash_glink_node(t, hnode);
/* Track # active nodes */
t->count++;
/*!
* Find a Node based on the key
*
- * t SFXHASH table pointer
+ * t XHash table pointer
* key users key pointer
*
- * return SFXHASH_NODE* valid pointer to the hash node
+ * return XHashNode* valid pointer to the hash node
* retval 0 node not found
*
*/
-SFXHASH_NODE* sfxhash_find_node(SFXHASH* t, const void* key)
+XHashNode* xhash_find_node(XHash* t, const void* key)
{
int rindex = 0;
- return sfxhash_find_node_row(t, key, &rindex);
+ return xhash_find_node_row(t, key, &rindex);
}
/*!
* Find the users data based associated with the key
*
- * t SFXHASH table pointer
+ * t XHash table pointer
* key users key pointer
*
* return void* valid pointer to the users data
* retval 0 node not found
*
*/
-void* sfxhash_find(SFXHASH* t, void* key)
+void* xhash_find(XHash* t, void* key)
{
int rindex = 0;
- SFXHASH_NODE* hnode = sfxhash_find_node_row(t, key, &rindex);
+ XHashNode* hnode = xhash_find_node_row(t, key, &rindex);
if ( hnode )
return hnode->data;
*
* return the head of the list or nullptr
*/
-SFXHASH_NODE* sfxhash_ghead(SFXHASH* t)
+XHashNode* xhash_ghead(XHash* t)
{
if (t)
{
*
* return the next node in the list or nullptr when at the end
*/
-SFXHASH_NODE* sfxhash_gfindnext(SFXHASH* t)
+XHashNode* xhash_gfindnext(XHash* t)
{
- SFXHASH_NODE* n = t->gnode;
+ XHashNode* n = t->gnode;
if (n)
t->gnode = n->gnext;
return n;
*
* return the head of the list or nullptr
*/
-SFXHASH_NODE* sfxhash_gfindfirst(SFXHASH* t)
+XHashNode* xhash_gfindfirst(XHash* t)
{
if (t)
{
/*!
* Return the most recently used data from the global list
*
- * t SFXHASH table pointer
+ * t XHash table pointer
*
* return void* valid pointer to the users data
* retval 0 node not found
*
*/
-void* sfxhash_mru(SFXHASH* t)
+void* xhash_mru(XHash* t)
{
- SFXHASH_NODE* hnode = sfxhash_ghead(t);
+ XHashNode* hnode = xhash_ghead(t);
if ( hnode )
return hnode->data;
/*!
* Return the least recently used data from the global list
*
- * t SFXHASH table pointer
+ * t XHash table pointer
*
* return void* valid pointer to the users data
* retval 0 node not found
*
*/
-void* sfxhash_lru(SFXHASH* t)
+void* xhash_lru(XHash* t)
{
- SFXHASH_NODE* hnode = t->gtail;
+ XHashNode* hnode = t->gtail;
if ( hnode )
return hnode->data;
/*
* Unlink and free the node
*/
-int sfxhash_free_node(SFXHASH* t, SFXHASH_NODE* hnode)
+int xhash_free_node(XHash* t, XHashNode* hnode)
{
- sfxhash_unlink_node(t, hnode); /* unlink from the hash table row list */
+ xhash_unlink_node(t, hnode); /* unlink from the hash table row list */
- sfxhash_gunlink_node(t, hnode); /* unlink from global-hash-node list */
+ xhash_gunlink_node(t, hnode); /* unlink from global-hash-node list */
t->count--;
if ( t->recycle_nodes )
{
- sfxhash_save_free_node(t, hnode);
+ xhash_save_free_node(t, hnode);
}
else
{
s_free(t, hnode);
}
- return SFXHASH_OK;
+ return XHASH_OK;
}
/*!
* Remove a Key + Data Pair from the table.
*
- * t SFXHASH table pointer
+ * t XHash table pointer
* key users key pointer
*
* return 0 success
* retval !0 failed
*
*/
-int sfxhash_remove(SFXHASH* t, void* key)
+int xhash_remove(XHash* t, void* key)
{
- unsigned hashkey = t->sfhashfcn->hash_fcn(t->sfhashfcn, (unsigned char*)key, t->keysize);
+ unsigned hashkey = t->hashfcn->hash_fcn(t->hashfcn, (unsigned char*)key, t->keysize);
// index = hashkey % t->nrows;
/* Modulus is slow */
unsigned index = hashkey & (t->nrows - 1);
- for ( SFXHASH_NODE* hnode = t->table[index]; hnode; hnode = hnode->next )
+ for ( XHashNode* hnode = t->table[index]; hnode; hnode = hnode->next )
{
- if ( !t->sfhashfcn->keycmp_fcn(hnode->key, key, t->keysize) )
+ if ( !t->hashfcn->keycmp_fcn(hnode->key, key, t->keysize) )
{
- return sfxhash_free_node(t, hnode);
+ return xhash_free_node(t, hnode);
}
}
- return SFXHASH_ERR;
+ return XHASH_ERR;
}
/*
Internal use only
*/
-static void sfxhash_next(SFXHASH* t)
+static void xhash_next(XHash* t)
{
if ( !t->cnode )
return;
/*!
* Find and return the first hash table node
*
- * t SFXHASH table pointer
+ * t XHash table pointer
*
* return 0 failed
- * retval !0 valid SFXHASH_NODE *
+ * retval !0 valid XHashNode *
*
*/
-SFXHASH_NODE* sfxhash_findfirst(SFXHASH* t)
+XHashNode* xhash_findfirst(XHash* t)
{
if (!t)
return nullptr;
t->cnode = t->table[ t->crow ];
if ( t->cnode )
{
- SFXHASH_NODE* n = t->cnode;
- sfxhash_next(t); // load t->cnode with the next entry
+ XHashNode* n = t->cnode;
+ xhash_next(t); // load t->cnode with the next entry
return n;
}
}
/*!
* Find and return the next hash table node
*
- * t SFXHASH table pointer
+ * t XHash table pointer
*
* return 0 failed
- * retval !0 valid SFXHASH_NODE *
+ * retval !0 valid XHashNode *
*
*/
-SFXHASH_NODE* sfxhash_findnext(SFXHASH* t)
+XHashNode* xhash_findnext(XHash* t)
{
- SFXHASH_NODE* n = t->cnode;
+ XHashNode* n = t->cnode;
if ( !n ) /* Done, no more entries */
{
return nullptr;
/*
Preload next node into current node
*/
- sfxhash_next(t);
+ xhash_next(t);
return n;
}
-// Make sfhashfcn use a separate set of opcodes for the backend.
+// Make hashfcn use a separate set of opcodes for the backend.
-void sfxhash_set_keyops(SFXHASH* h, hash_func hash_fcn, keycmp_func keycmp_fcn)
+void xhash_set_keyops(XHash* h, hash_func hash_fcn, keycmp_func keycmp_fcn)
{
assert(h and hash_fcn and keycmp_fcn);
- sfhashfcn_set_keyops(h->sfhashfcn, hash_fcn, keycmp_fcn);
+ hashfcn_set_keyops(h->hashfcn, hash_fcn, keycmp_fcn);
}
/*
* Test Driver for Hashing
* -----------------------------------------------------------------------------------------
*/
-#ifdef SFXHASH_MAIN
+#ifdef XHash_MAIN
/*
This is called when the user releases a node or kills the table
int main(int argc, char** argv)
{
int i;
- SFXHASH* t;
- SFXHASH_NODE* n;
+ XHash* t;
+ XHashNode* n;
char strkey[256], strdata[256];
int num = 100;
int mem = 0;
}
/* Create a Hash Table */
- t = sfxhash_new(100, /* one row per element in table, when possible */
+ t = xhash_new(100, /* one row per element in table, when possible */
20, /* key size : padded with zeros */
20, /* data size: padded with zeros */
mem, /* max bytes, 0=no max */
snprintf(strdata, sizeof(strdata), "KeyWord%5.5d",i+1);
strdata[sizeof(strdata) - 1] = '\0';
//strupr(strdata);
- sfxhash_add(t, strkey /* user key */, strdata /* user data */);
+ xhash_add(t, strkey /* user key */, strdata /* user data */);
}
/* Find and Display Nodes in the Hash Table */
snprintf(strkey, sizeof(strkey) - 1, "KeyWord%5.5d",i+1);
strkey[sizeof(strkey) - 1] = '\0';
- if ( char* p = (char*)sfxhash_find(t, strkey) )
+ if ( char* p = (char*)xhash_find(t, strkey) )
printf("Hash-key=%*s, data=%*s\n", strlen(strkey),strkey, strlen(strkey), p);
}
/* Display All Nodes in the Hash Table findfirst/findnext */
printf("\n...FINDFIRST / FINDNEXT TEST\n");
- for ( n = sfxhash_findfirst(t);
+ for ( n = xhash_findfirst(t);
n != 0;
- n = sfxhash_findnext(t) )
+ n = xhash_findnext(t) )
{
printf("hash-findfirst/next: n=%p, key=%s, data=%s\n", n, n->key, n->data);
/*
remove node we are looking at, this is first/next safe.
*/
- if ( sfxhash_remove(t,n->key) )
+ if ( xhash_remove(t,n->key) )
{
printf("...ERROR: Could not remove the key node\n");
}
t->anr_count);
/* Free the table and it's user data */
- printf("...sfxhash_delete\n");
+ printf("...xhash_delete\n");
- sfxhash_delete(t);
+ xhash_delete(t);
printf("\nnormal pgm finish\n\n");
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//--------------------------------------------------------------------------
-// sfxhash.h author Marc Norton
+// xhash.h author Marc Norton
-#ifndef SFXHASH_H
-#define SFXHASH_H
+#ifndef XHASH_H
+#define XHASH_H
// generic hash table - stores and maps key + data pairs
// (supports memcap and automatic memory recovery when out of memory)
#include "utils/sfmemcap.h"
#include "main/snort_types.h"
-struct SFHASHFCN;
+struct HashFnc;
-#define SFXHASH_NOMEM (-2)
-#define SFXHASH_ERR (-1)
-#define SFXHASH_OK 0
-#define SFXHASH_INTABLE 1
+#define XHASH_NOMEM (-2)
+#define XHASH_ERR (-1)
+#define XHASH_OK 0
+#define XHASH_INTABLE 1
-struct SFXHASH_NODE
+struct XHashNode
{
- struct SFXHASH_NODE* gnext; // global node list - used for aging nodes
- struct SFXHASH_NODE* gprev;
- struct SFXHASH_NODE* next; // row node list
- struct SFXHASH_NODE* prev;
+ struct XHashNode* gnext; // global node list - used for aging nodes
+ struct XHashNode* gprev;
+ struct XHashNode* next; // row node list
+ struct XHashNode* prev;
int rindex; // row index of table this node belongs to.
void* data; // Pointer to the users data, this is not copied !
};
-typedef int (* SFXHASH_FREE_FCN)(void* key, void* data);
+typedef int (* XHash_FREE_FCN)(void* key, void* data);
-struct SFXHASH
+struct XHash
{
- SFHASHFCN* sfhashfcn; // hash function
+ HashFnc* hashfcn; // hash function
int keysize; // bytes in key, if <= 0 -> keys are strings
int datasize; // bytes in key, if == 0 -> user data
- SFXHASH_NODE** table; // array of node ptr's */
+ XHashNode** table; // array of node ptr's */
unsigned nrows; // # rows int the hash table use a prime number 211, 9871
unsigned count; // total # nodes in table
unsigned crow; // findfirst/next row in table
unsigned pad;
- SFXHASH_NODE* cnode; // findfirst/next node ptr
+ XHashNode* cnode; // findfirst/next node ptr
int splay; // whether to splay nodes with same hash bucket
unsigned max_nodes; // maximum # of nodes within a hash
unsigned find_fail;
unsigned find_success;
- SFXHASH_NODE* ghead, * gtail; // global - root of all nodes allocated in table
- SFXHASH_NODE* fhead, * ftail; // list of free nodes, which are recycled
- SFXHASH_NODE* gnode; // gfirst/gnext node ptr */
+ XHashNode* ghead, * gtail; // global - root of all nodes allocated in table
+ XHashNode* fhead, * ftail; // list of free nodes, which are recycled
+ XHashNode* gnode; // gfirst/gnext node ptr */
int recycle_nodes; // recycle nodes. Nodes are not freed, but are used for
// subsequent new nodes
unsigned anr_count; // # ANR ops performed
int anr_flag; // 0=off, !0=on
- SFXHASH_FREE_FCN anrfree;
- SFXHASH_FREE_FCN usrfree;
+ XHash_FREE_FCN anrfree;
+ XHash_FREE_FCN usrfree;
};
-SO_PUBLIC SFXHASH* sfxhash_new(int nrows, int keysize, int datasize, unsigned long memcap,
+SO_PUBLIC XHash* xhash_new(int nrows, int keysize, int datasize, unsigned long memcap,
int anr_flag,
- SFXHASH_FREE_FCN anrfunc,
- SFXHASH_FREE_FCN usrfunc,
+ XHash_FREE_FCN anrfunc,
+ XHash_FREE_FCN usrfunc,
int recycle_flag);
-SO_PUBLIC void sfxhash_set_max_nodes(SFXHASH* h, int max_nodes);
+SO_PUBLIC void xhash_set_max_nodes(XHash* h, int max_nodes);
-SO_PUBLIC void sfxhash_delete(SFXHASH* h);
-SO_PUBLIC int sfxhash_make_empty(SFXHASH*);
+SO_PUBLIC void xhash_delete(XHash* h);
+SO_PUBLIC int xhash_make_empty(XHash*);
-SO_PUBLIC int sfxhash_add(SFXHASH* h, void* key, void* data);
-SO_PUBLIC SFXHASH_NODE* sfxhash_get_node(SFXHASH* t, const void* key);
-SO_PUBLIC int sfxhash_remove(SFXHASH* h, void* key);
+SO_PUBLIC int xhash_add(XHash* h, void* key, void* data);
+SO_PUBLIC XHashNode* xhash_get_node(XHash* t, const void* key);
+SO_PUBLIC int xhash_remove(XHash* h, void* key);
// Get the # of Nodes in HASH the table
-inline unsigned sfxhash_count(SFXHASH* t)
+inline unsigned xhash_count(XHash* t)
{ return t->count; }
// Get the # auto recovery
-inline unsigned sfxhash_anr_count(SFXHASH* t)
+inline unsigned xhash_anr_count(XHash* t)
{ return t->anr_count; }
// Get the # finds
-inline unsigned sfxhash_find_total(SFXHASH* t)
+inline unsigned xhash_find_total(XHash* t)
{ return t->find_success + t->find_fail; }
// Get the # unsuccessful finds
-inline unsigned sfxhash_find_fail(SFXHASH* t)
+inline unsigned xhash_find_fail(XHash* t)
{ return t->find_fail; }
// Get the # successful finds
-inline unsigned sfxhash_find_success(SFXHASH* t)
+inline unsigned xhash_find_success(XHash* t)
{ return t->find_success; }
// Get the # of overhead bytes
-inline unsigned sfxhash_overhead_bytes(SFXHASH* t)
+inline unsigned xhash_overhead_bytes(XHash* t)
{ return t->overhead_bytes; }
// Get the # of overhead blocks
-inline unsigned sfxhash_overhead_blocks(SFXHASH* t)
+inline unsigned xhash_overhead_blocks(XHash* t)
{ return t->overhead_blocks; }
-SO_PUBLIC void* sfxhash_mru(SFXHASH* t);
-SO_PUBLIC void* sfxhash_lru(SFXHASH* t);
-SO_PUBLIC void* sfxhash_find(SFXHASH* h, void* key);
-SO_PUBLIC SFXHASH_NODE* sfxhash_find_node(SFXHASH* t, const void* key);
+SO_PUBLIC void* xhash_mru(XHash* t);
+SO_PUBLIC void* xhash_lru(XHash* t);
+SO_PUBLIC void* xhash_find(XHash* h, void* key);
+SO_PUBLIC XHashNode* xhash_find_node(XHash* t, const void* key);
-SO_PUBLIC SFXHASH_NODE* sfxhash_findfirst(SFXHASH* h);
-SO_PUBLIC SFXHASH_NODE* sfxhash_findnext(SFXHASH* h);
+SO_PUBLIC XHashNode* xhash_findfirst(XHash* h);
+SO_PUBLIC XHashNode* xhash_findnext(XHash* h);
-SO_PUBLIC SFXHASH_NODE* sfxhash_ghead(SFXHASH* h);
-SO_PUBLIC void sfxhash_gmovetofront(SFXHASH* t, SFXHASH_NODE* hnode);
+SO_PUBLIC XHashNode* xhash_ghead(XHash* h);
+SO_PUBLIC void xhash_gmovetofront(XHash* t, XHashNode* hnode);
-SO_PUBLIC int sfxhash_free_node(SFXHASH* t, SFXHASH_NODE* node);
+SO_PUBLIC int xhash_free_node(XHash* t, XHashNode* node);
-typedef uint32_t (* hash_func)(SFHASHFCN*, const unsigned char* d, int n);
+typedef uint32_t (* hash_func)(HashFnc*, const unsigned char* d, int n);
// return 0 for ==, 1 for != ; FIXIT-L convert to bool
typedef int (* keycmp_func)(const void* s1, const void* s2, size_t n);
-SO_PUBLIC void sfxhash_set_keyops(SFXHASH* h, hash_func, keycmp_func);
+SO_PUBLIC void xhash_set_keyops(XHash* h, hash_func, keycmp_func);
-SO_PUBLIC SFXHASH_NODE* sfxhash_gfindfirst(SFXHASH* t);
-SO_PUBLIC SFXHASH_NODE* sfxhash_gfindnext(SFXHASH* t);
+SO_PUBLIC XHashNode* xhash_gfindfirst(XHash* t);
+SO_PUBLIC XHashNode* xhash_gfindnext(XHash* t);
#endif
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//--------------------------------------------------------------------------
-// zhash is based on sfxhash - see sfxhash.cc for details
+// zhash is based on sfxhash - see xhash.cc for details
#ifdef HAVE_CONFIG_H
#include "config.h"
#include <cstring>
-#include "sfhashfcn.h"
+#include "hashfcn.h"
//-------------------------------------------------------------------------
// private stuff
ZHashNode* ZHash::find_node_row(const void* key, int* rindex)
{
- unsigned hashkey = sfhashfcn->hash_fcn(
- sfhashfcn, (const unsigned char*)key, keysize);
+ unsigned hashkey = hashfcn->hash_fcn(
+ hashfcn, (const unsigned char*)key, keysize);
// Modulus is slow; use a table size that is a power of 2.
int index = hashkey & (nrows - 1);
for ( ZHashNode* node=table[index]; node; node=node->next ) // UNINITUSE
{
- if ( !sfhashfcn->keycmp_fcn(node->key,key,keysize) )
+ if ( !hashfcn->keycmp_fcn(node->key,key,keysize) )
{
move_to_front(node);
find_success++;
if ( rows > 0 )
{
// make sure we have a prime number
- // rows = sf_nearest_prime(rows);
+ // rows = nearest_prime(rows);
/* If rows is not a power of two, need to find the
* next highest power of two */
}
/* this has a default hashing function */
- sfhashfcn = sfhashfcn_new(rows);
+ hashfcn = hashfcn_new(rows);
/* Allocate the array of node ptrs */
table = new ZHashNode*[rows]();
ZHash::~ZHash()
{
- if ( sfhashfcn )
- sfhashfcn_free(sfhashfcn);
+ if ( hashfcn )
+ hashfcn_free(hashfcn);
if ( table )
{
}
int ZHash::set_keyops(
- unsigned (* hash_fcn)(SFHASHFCN* p, const unsigned char* d, int n),
+ unsigned (* hash_fcn)(HashFnc* p, const unsigned char* d, int n),
int (* keycmp_fcn)(const void* s1, const void* s2, size_t n))
{
if ( hash_fcn && keycmp_fcn )
- return sfhashfcn_set_keyops(sfhashfcn, hash_fcn, keycmp_fcn);
+ return hashfcn_set_keyops(hashfcn, hash_fcn, keycmp_fcn);
return -1;
}
#include <cstddef>
-struct SFHASHFCN;
+struct HashFnc;
struct ZHashNode;
class ZHash
inline unsigned get_count() { return count; }
int set_keyops(
- unsigned (* hash_fcn)(SFHASHFCN* p, const unsigned char* d, int n),
+ unsigned (* hash_fcn)(HashFnc* p, const unsigned char* d, int n),
int (* keycmp_fcn)(const void* s1, const void* s2, size_t n));
private:
int nearest_powerof2(int nrows);
private:
- SFHASHFCN* sfhashfcn;
+ HashFnc* hashfcn;
int keysize;
unsigned nrows;
#include "framework/ips_option.h"
#include "framework/module.h"
#include "framework/range.h"
-#include "hash/sfhashfcn.h"
+#include "hash/hashfcn.h"
#include "profiler/profiler_defs.h"
#include "protocols/packet.h"
#include "protocols/tcp.h"
#include "framework/cursor.h"
#include "framework/ips_option.h"
#include "framework/module.h"
-#include "hash/sfhashfcn.h"
+#include "hash/hashfcn.h"
#include "profiler/profiler.h"
#include "protocols/packet.h"
#include "detection/detection_util.h"
#include "detection/treenodes.h"
-#include "hash/sfhashfcn.h"
+#include "hash/hashfcn.h"
#include "framework/cursor.h"
#include "framework/ips_option.h"
#include "framework/module.h"
#include "framework/ips_option.h"
#include "framework/module.h"
#include "framework/range.h"
-#include "hash/sfhashfcn.h"
+#include "hash/hashfcn.h"
#include "profiler/profiler.h"
#define s_name "bufferlen"
#include "framework/endianness.h"
#include "framework/ips_option.h"
#include "framework/module.h"
-#include "hash/sfhashfcn.h"
+#include "hash/hashfcn.h"
#include "log/messages.h"
#include "protocols/packet.h"
#include "profiler/profiler.h"
#include "framework/endianness.h"
#include "framework/ips_option.h"
#include "framework/module.h"
-#include "hash/sfhashfcn.h"
+#include "hash/hashfcn.h"
#include "log/messages.h"
#include "profiler/profiler.h"
#include "protocols/packet.h"
#include "framework/endianness.h"
#include "framework/ips_option.h"
#include "framework/module.h"
-#include "hash/sfhashfcn.h"
+#include "hash/hashfcn.h"
#include "log/messages.h"
#include "profiler/profiler.h"
#include "protocols/packet.h"
#include "framework/endianness.h"
#include "framework/ips_option.h"
#include "framework/module.h"
-#include "hash/sfhashfcn.h"
+#include "hash/hashfcn.h"
#include "log/messages.h"
#include "profiler/profiler.h"
#include "protocols/packet.h"
#include "framework/cursor.h"
#include "framework/ips_option.h"
#include "framework/module.h"
-#include "hash/sfhashfcn.h"
+#include "hash/hashfcn.h"
#include "log/messages.h"
#include "parser/parse_utils.h"
#include "profiler/profiler.h"
#include "framework/ips_option.h"
#include "framework/module.h"
-#include "hash/sfhashfcn.h"
+#include "hash/hashfcn.h"
#include "profiler/profiler.h"
#include "protocols/packet.h"
#include "framework/ips_option.h"
#include "framework/module.h"
#include "framework/range.h"
-#include "hash/sfhashfcn.h"
+#include "hash/hashfcn.h"
#include "profiler/profiler.h"
#include "protocols/packet.h"
#include "framework/ips_option.h"
#include "framework/module.h"
-#include "hash/sfhashfcn.h"
+#include "hash/hashfcn.h"
#include "log/messages.h"
#include "profiler/profiler.h"
#include "protocols/packet.h"
#include "detection/treenodes.h"
#include "framework/ips_option.h"
#include "framework/module.h"
-#include "hash/sfhashfcn.h"
+#include "hash/hashfcn.h"
#include "log/messages.h"
#include "profiler/profiler.h"
#include "protocols/packet.h"
#include "framework/ips_option.h"
#include "framework/module.h"
-#include "hash/sfghash.h"
-#include "hash/sfhashfcn.h"
+#include "hash/ghash.h"
+#include "hash/hashfcn.h"
#include "log/messages.h"
#include "parser/mstring.h"
#include "protocols/packet.h"
static std::forward_list<const FLOWBITS_OP*> op_list;
-static SFGHASH* flowbits_hash = nullptr;
-static SFGHASH* flowbits_grp_hash = nullptr;
+static GHash* flowbits_hash = nullptr;
+static GHash* flowbits_grp_hash = nullptr;
static SF_QUEUE* flowbits_bit_queue = nullptr;
static unsigned flowbits_count = 0;
// FIXIT-M why is the hash lookup done at runtime for flowbits groups?
// a pointer to flowbis_grp should be in flowbits config data
// this *should* be safe but iff splay mode is disabled
- auto flowbits_grp = (FLOWBITS_GRP*)sfghash_find(flowbits_grp_hash, group);
+ auto flowbits_grp = (FLOWBITS_GRP*)ghash_find(flowbits_grp_hash, group);
if ( !flowbits_grp )
return 0;
if ( !group )
return 0;
- auto flowbits_grp = (FLOWBITS_GRP*)sfghash_find(flowbits_grp_hash, group);
+ auto flowbits_grp = (FLOWBITS_GRP*)ghash_find(flowbits_grp_hash, group);
if ( !flowbits_grp )
return 0;
return 0;
case FLOWBITS_ALL:
- flowbits_grp = (FLOWBITS_GRP*)sfghash_find(flowbits_grp_hash, group);
+ flowbits_grp = (FLOWBITS_GRP*)ghash_find(flowbits_grp_hash, group);
if ( flowbits_grp == nullptr )
return 0;
for ( i = 0; i <= (unsigned int)(flowbits_grp->max_id >>3); i++ )
return 1;
case FLOWBITS_ANY:
- flowbits_grp = (FLOWBITS_GRP*)sfghash_find(flowbits_grp_hash, group);
+ flowbits_grp = (FLOWBITS_GRP*)ghash_find(flowbits_grp_hash, group);
if ( flowbits_grp == nullptr )
return 0;
for ( i = 0; i <= (unsigned int)(flowbits_grp->max_id >>3); i++ )
if ( !flowbits_hash )
return;
- for (SFGHASH_NODE* n = sfghash_findfirst(flowbits_hash);
+ for (GHashNode* n = ghash_findfirst(flowbits_hash);
n != nullptr;
- n = sfghash_findnext(flowbits_hash))
+ n = ghash_findnext(flowbits_hash))
{
FLOWBITS_OBJECT* fb = (FLOWBITS_OBJECT*)n->data;
fb->set = 0;
s_name, ALLOWED_SPECIAL_CHARS);
}
- flowbits_item = (FLOWBITS_OBJECT*)sfghash_find(flowbits_hash, flowbitName);
+ flowbits_item = (FLOWBITS_OBJECT*)ghash_find(flowbits_hash, flowbitName);
if (flowbits_item == nullptr)
{
}
}
- int hstatus = sfghash_add(flowbits_hash, flowbitName, flowbits_item);
+ int hstatus = ghash_add(flowbits_hash, flowbitName, flowbits_item);
- if (hstatus != SFGHASH_OK)
+ if (hstatus != GHASH_OK)
ParseError("Could not add flowbits key (%s) to hash.",flowbitName);
}
flowbits_item->toggle = flowbits_toggle;
s_name, ALLOWED_SPECIAL_CHARS);
}
- flowbits_grp = (FLOWBITS_GRP*)sfghash_find(flowbits_grp_hash, groupName);
+ flowbits_grp = (FLOWBITS_GRP*)ghash_find(flowbits_grp_hash, groupName);
if ( !flowbits_grp )
{
// new group defined, add (bitop set later once we know size)
flowbits_grp = (FLOWBITS_GRP*)snort_calloc(sizeof(*flowbits_grp));
- int hstatus = sfghash_add(flowbits_grp_hash, groupName, flowbits_grp);
+ int hstatus = ghash_add(flowbits_grp_hash, groupName, flowbits_grp);
- if (hstatus != SFGHASH_OK)
+ if (hstatus != GHASH_OK)
ParseAbort("Could not add flowbits group (%s) to hash.\n",groupName);
flowbits_grp_count++;
if ( !flowbits_hash or !flowbits_grp_hash )
return;
- for ( SFGHASH_NODE* n = sfghash_findfirst(flowbits_grp_hash);
+ for ( GHashNode* n = ghash_findfirst(flowbits_grp_hash);
n != nullptr;
- n= sfghash_findnext(flowbits_grp_hash) )
+ n= ghash_findnext(flowbits_grp_hash) )
{
FLOWBITS_GRP* fbg = (FLOWBITS_GRP*)n->data;
fbg->GrpBitOp = new BitOp(flowbits_count);
while ( !op_list.empty() )
{
const FLOWBITS_OP* fbop = op_list.front();
- FLOWBITS_GRP* fbg = (FLOWBITS_GRP*)sfghash_find(flowbits_grp_hash, fbop->group);
+ FLOWBITS_GRP* fbg = (FLOWBITS_GRP*)ghash_find(flowbits_grp_hash, fbop->group);
assert(fbg);
for ( int i = 0; i < fbop->num_ids; ++i )
static void FlowBitsVerify()
{
- SFGHASH_NODE* n;
+ GHashNode* n;
unsigned num_flowbits = 0;
unsigned unchecked = 0, unset = 0;
if (flowbits_hash == nullptr)
return;
- for (n = sfghash_findfirst(flowbits_hash);
+ for (n = ghash_findfirst(flowbits_hash);
n != nullptr;
- n= sfghash_findnext(flowbits_hash))
+ n= ghash_findnext(flowbits_hash))
{
FLOWBITS_OBJECT* fb = (FLOWBITS_OBJECT*)n->data;
if (fb->toggle != flowbits_toggle)
{
sfqueue_add(flowbits_bit_queue, (NODE_DATA)(uintptr_t)fb->id);
- sfghash_remove(flowbits_hash, n->key);
+ ghash_remove(flowbits_hash, n->key);
continue;
}
static void flowbits_ginit(SnortConfig*)
{
- flowbits_hash = sfghash_new(10000, 0, 0, FlowItemFree);
+ flowbits_hash = ghash_new(10000, 0, 0, FlowItemFree);
if ( !flowbits_hash )
FatalError("Could not create flowbits hash.\n");
// this is used during parse time and runtime so do NOT
// enable splay mode (which is NOT useful here anyway)
- flowbits_grp_hash = sfghash_new(10000, 0, 0, FlowBitsGrpFree);
+ flowbits_grp_hash = ghash_new(10000, 0, 0, FlowBitsGrpFree);
if ( !flowbits_grp_hash )
FatalError("could not create flowbits group hash.\n");
{
if ( flowbits_hash )
{
- sfghash_delete(flowbits_hash);
+ ghash_delete(flowbits_hash);
flowbits_hash = nullptr;
}
if ( flowbits_grp_hash )
{
- sfghash_delete(flowbits_grp_hash);
+ ghash_delete(flowbits_grp_hash);
flowbits_grp_hash = nullptr;
}
#include "framework/ips_option.h"
#include "framework/module.h"
-#include "hash/sfhashfcn.h"
+#include "hash/hashfcn.h"
#include "log/messages.h"
#include "profiler/profiler.h"
#include "protocols/packet.h"
#include "framework/ips_option.h"
#include "framework/module.h"
#include "framework/range.h"
-#include "hash/sfhashfcn.h"
+#include "hash/hashfcn.h"
#include "profiler/profiler.h"
#include "protocols/packet.h"
#include "framework/ips_option.h"
#include "framework/module.h"
#include "hash/hashes.h"
-#include "hash/sfhashfcn.h"
+#include "hash/hashfcn.h"
#include "log/messages.h"
#include "parser/parse_utils.h"
#include "profiler/profiler.h"
#include "framework/ips_option.h"
#include "framework/module.h"
#include "framework/range.h"
-#include "hash/sfhashfcn.h"
+#include "hash/hashfcn.h"
#include "profiler/profiler.h"
#include "protocols/icmp4.h"
#include "protocols/icmp6.h"
#include "framework/ips_option.h"
#include "framework/module.h"
#include "framework/range.h"
-#include "hash/sfhashfcn.h"
+#include "hash/hashfcn.h"
#include "profiler/profiler.h"
#include "protocols/icmp4.h"
#include "protocols/icmp6.h"
#include "framework/ips_option.h"
#include "framework/module.h"
#include "framework/range.h"
-#include "hash/sfhashfcn.h"
+#include "hash/hashfcn.h"
#include "profiler/profiler.h"
#include "protocols/icmp4.h"
#include "protocols/packet.h"
#include "framework/ips_option.h"
#include "framework/module.h"
#include "framework/range.h"
-#include "hash/sfhashfcn.h"
+#include "hash/hashfcn.h"
#include "profiler/profiler.h"
#include "protocols/packet.h"
#include "framework/ips_option.h"
#include "framework/module.h"
-#include "hash/sfhashfcn.h"
+#include "hash/hashfcn.h"
#include "log/messages.h"
#include "profiler/profiler.h"
#include "protocols/packet.h"
#include "framework/ips_option.h"
#include "framework/module.h"
-#include "hash/sfhashfcn.h"
+#include "hash/hashfcn.h"
#include "profiler/profiler.h"
#include "protocols/ipv4_options.h"
#include "protocols/packet.h"
#include "framework/cursor.h"
#include "framework/ips_option.h"
#include "framework/module.h"
-#include "hash/sfhashfcn.h"
+#include "hash/hashfcn.h"
#include "log/messages.h"
#include "parser/mstring.h"
#include "profiler/profiler.h"
#include "framework/ips_option.h"
#include "framework/module.h"
#include "framework/range.h"
-#include "hash/sfhashfcn.h"
+#include "hash/hashfcn.h"
#include "profiler/profiler.h"
#include "protocols/icmp4.h"
#include "protocols/packet.h"
#include "framework/cursor.h"
#include "framework/decode_data.h"
#include "framework/module.h"
-#include "hash/sfhashfcn.h"
+#include "hash/hashfcn.h"
#include "helpers/chunk.h"
#include "lua/lua.h"
#include "log/messages.h"
#include "framework/cursor.h"
#include "framework/ips_option.h"
#include "framework/module.h"
-#include "hash/sfhashfcn.h"
+#include "hash/hashfcn.h"
#include "log/messages.h"
#include "main/snort_config.h"
#include "profiler/profiler.h"
#include "framework/cursor.h"
#include "framework/ips_option.h"
#include "framework/module.h"
-#include "hash/sfhashfcn.h"
+#include "hash/hashfcn.h"
#include "log/messages.h"
#include "main/snort_config.h"
#include "profiler/profiler.h"
#include "framework/cursor.h"
#include "framework/ips_option.h"
#include "framework/module.h"
-#include "hash/sfhashfcn.h"
+#include "hash/hashfcn.h"
#include "log/messages.h"
#include "main/snort_config.h"
#include "main/thread_config.h"
#include "framework/ips_option.h"
#include "framework/module.h"
-#include "hash/sfhashfcn.h"
+#include "hash/hashfcn.h"
#include "profiler/profiler.h"
#include "protocols/packet.h"
#include "framework/cursor.h"
#include "framework/ips_option.h"
#include "framework/module.h"
-#include "hash/sfhashfcn.h"
+#include "hash/hashfcn.h"
#include "log/messages.h"
#include "log/obfuscator.h"
#include "main/snort_config.h"
#include "framework/ips_option.h"
#include "framework/module.h"
#include "framework/range.h"
-#include "hash/sfhashfcn.h"
+#include "hash/hashfcn.h"
#include "profiler/profiler.h"
#include "protocols/packet.h"
#include "protocols/tcp.h"
#include "framework/ips_option.h"
#include "framework/module.h"
-#include "hash/sfhashfcn.h"
+#include "hash/hashfcn.h"
#include "log/messages.h"
#include "main/snort_config.h"
#include "profiler/profiler.h"
#include "framework/ips_option.h"
#include "framework/module.h"
#include "framework/so_rule.h"
-#include "hash/sfhashfcn.h"
+#include "hash/hashfcn.h"
#include "log/messages.h"
#include "managers/so_manager.h"
#include "profiler/profiler.h"
#include "framework/ips_option.h"
#include "framework/module.h"
#include "framework/range.h"
-#include "hash/sfhashfcn.h"
+#include "hash/hashfcn.h"
#include "profiler/profiler.h"
#include "protocols/packet.h"
#include "framework/ips_option.h"
#include "framework/module.h"
#include "framework/range.h"
-#include "hash/sfhashfcn.h"
+#include "hash/hashfcn.h"
#include "profiler/profiler.h"
#include "protocols/packet.h"
#include "framework/ips_option.h"
#include "framework/module.h"
#include "framework/range.h"
-#include "hash/sfhashfcn.h"
+#include "hash/hashfcn.h"
#include "profiler/profiler.h"
#include "protocols/packet.h"
#include "protocols/tcp.h"
// (actually, the whole reason for doing this needs to be rethought)
static OptTreeNode* OptTreeNode_Search(uint32_t, uint32_t sid)
{
- SFGHASH_NODE* hashNode;
+ GHashNode* hashNode;
if (sid == 0)
return nullptr;
- for (hashNode = sfghash_findfirst(SnortConfig::get_conf()->otn_map);
+ for (hashNode = ghash_findfirst(SnortConfig::get_conf()->otn_map);
hashNode;
- hashNode = sfghash_findnext(SnortConfig::get_conf()->otn_map))
+ hashNode = ghash_findnext(SnortConfig::get_conf()->otn_map))
{
OptTreeNode* otn = (OptTreeNode*)hashNode->data;
RuleTreeNode* rtn = getRuntimeRtnFromOtn(otn);
struct sfip_var_t;
typedef unsigned int PolicyId;
-typedef struct SFGHASH PortVarTable;
+typedef struct GHash PortVarTable;
enum PolicyMode
{
#include "filters/rate_filter.h"
#include "filters/sfrf.h"
#include "filters/sfthreshold.h"
-#include "hash/sfxhash.h"
+#include "hash/xhash.h"
#include "helpers/process.h"
#include "ips_options/ips_pcre.h"
#include "latency/latency_config.h"
fpDeleteFastPacketDetection(this);
if (rtn_hash_table)
- sfxhash_delete(rtn_hash_table);
+ xhash_delete(rtn_hash_table);
if (eth_dst )
snort_free(eth_dst);
struct srmm_table_t;
struct sopg_table_t;
struct PORT_RULE_MAP;
-struct SFXHASH;
+struct XHash;
struct ProfilerConfig;
struct MemoryConfig;
struct LatencyConfig;
struct RuleState* rule_state_list = nullptr;
struct ClassType* classifications = nullptr;
struct ReferenceSystemNode* references = nullptr;
- struct SFGHASH* otn_map = nullptr;
+ struct GHash* otn_map = nullptr;
class ProtocolReference* proto_ref = nullptr;
srmm_table_t* spgmmTable = nullptr; /* srvc port_group map master table */
sopg_table_t* sopgTable = nullptr; /* service-ordinal to port_group table */
- SFXHASH* detection_option_hash_table = nullptr;
- SFXHASH* detection_option_tree_hash_table = nullptr;
- SFXHASH* rtn_hash_table = nullptr;
+ XHash* detection_option_hash_table = nullptr;
+ XHash* detection_option_tree_hash_table = nullptr;
+ XHash* rtn_hash_table = nullptr;
PolicyMap* policy_map = nullptr;
struct VarNode* var_list = nullptr;
#include "app_forecast.h"
-#include "hash/sfxhash.h"
+#include "hash/xhash.h"
#include "log/messages.h"
#include "protocols/packet.h"
#include "time/packet_time.h"
#include "appid_session.h"
static THREAD_LOCAL AFActKey master_key;
-static THREAD_LOCAL SFXHASH* AF_indicators = nullptr; // list of "indicator apps"
-static THREAD_LOCAL SFXHASH* AF_actives = nullptr; // list of hosts to watch
+static THREAD_LOCAL XHash* AF_indicators = nullptr; // list of "indicator apps"
+static THREAD_LOCAL XHash* AF_actives = nullptr; // list of hosts to watch
int init_appid_forecast()
{
- if (!(AF_indicators = sfxhash_new(1024, sizeof(AppId), sizeof(AFElement),
+ if (!(AF_indicators = xhash_new(1024, sizeof(AppId), sizeof(AFElement),
0, 0, nullptr, nullptr, 0)))
{
ErrorMessage("Config: failed to allocate memory for an AF Indicators hash.");
return 0;
}
- if (!(AF_actives = sfxhash_new(1024, sizeof(AFActKey), sizeof(AFActVal),
- (sizeof(SFXHASH_NODE)*2048), 1, nullptr, nullptr, 1)))
+ if (!(AF_actives = xhash_new(1024, sizeof(AFActKey), sizeof(AFActVal),
+ (sizeof(XHashNode)*2048), 1, nullptr, nullptr, 1)))
{
- sfxhash_delete(AF_indicators);
+ xhash_delete(AF_indicators);
ErrorMessage("Config: failed to allocate memory for an AF Actives hash.");
return 0;
}
{
if (AF_indicators)
{
- sfxhash_delete(AF_indicators);
+ xhash_delete(AF_indicators);
AF_indicators = nullptr;
}
if (AF_actives)
{
- sfxhash_delete(AF_actives);
+ xhash_delete(AF_actives);
AF_actives = nullptr;
}
}
void add_af_indicator(AppId indicator, AppId forecast, AppId target)
{
- if (sfxhash_find(AF_indicators, &indicator))
+ if (xhash_find(AF_indicators, &indicator))
{
ErrorMessage("LuaDetectorApi:Attempt to add more than one AFElement per appId %d",
indicator);
val.indicator = indicator;
val.forecast = forecast;
val.target = target;
- if (sfxhash_add(AF_indicators, &indicator, &val))
+ if (xhash_add(AF_indicators, &indicator, &val))
ErrorMessage("LuaDetectorApi:Failed to add AFElement for appId %d", indicator);
}
void check_session_for_AF_indicator(Packet* p, int dir, AppId indicator)
{
AFElement* ind_element;
- if (!(ind_element = (AFElement*)sfxhash_find(AF_indicators, &indicator)))
+ if (!(ind_element = (AFElement*)xhash_find(AF_indicators, &indicator)))
return;
rekey_master_AF_key(p, dir, ind_element->forecast);
AFActVal* test_active_value;
- if ((test_active_value = (AFActVal*)sfxhash_find(AF_actives, &master_key)))
+ if ((test_active_value = (AFActVal*)xhash_find(AF_actives, &master_key)))
{
test_active_value->last = packet_time();
test_active_value->target = ind_element->target;
new_active_value.target = ind_element->target;
new_active_value.last = packet_time();
- sfxhash_add(AF_actives, &master_key, &new_active_value);
+ xhash_add(AF_actives, &master_key, &new_active_value);
}
AppId check_session_for_AF_forecast(AppIdSession* asd, Packet* p, int dir, AppId forecast)
rekey_master_AF_key(p, dir, forecast);
//get out if there is no value
- if (!(check_act_val = (AFActVal*)sfxhash_find(AF_actives, &master_key)))
+ if (!(check_act_val = (AFActVal*)xhash_find(AF_actives, &master_key)))
return APP_ID_UNKNOWN;
//if the value is older than 5 minutes, remove it and get out
age = packet_time() - check_act_val->last;
if (age < 0 || age > 300)
{
- sfxhash_remove(AF_actives, &master_key);
+ xhash_remove(AF_actives, &master_key);
return APP_ID_UNKNOWN;
}
NetworkSet* tmp = (NetworkSet*)snort_calloc(sizeof(NetworkSet));
sflist_init(&tmp->networks);
- tmp->ids = sfxhash_new(64, sizeof(unsigned), 0, 0, 0, nullptr, nullptr, 1);
+ tmp->ids = xhash_new(64, sizeof(unsigned), 0, 0, 0, nullptr, nullptr, 1);
if (tmp->ids == nullptr)
{
ErrorMessage("NetworkSet:Out of memory (wanted %zu bytes)", sizeof(NetworkSet));
}
sflist_init(&tmp->networks6);
- tmp->ids6 = sfxhash_new(64, sizeof(unsigned), 0, 0, 0, nullptr, nullptr, 1);
+ tmp->ids6 = xhash_new(64, sizeof(unsigned), 0, 0, 0, nullptr, nullptr, 1);
if (tmp->ids6 == nullptr)
{
ErrorMessage("NetworkSet:Out of memory (wanted %zu bytes)", sizeof(NetworkSet));
network_set->pnetwork = nullptr;
}
sflist_static_free_all(&network_set->networks, &snort_free);
- sfxhash_delete(network_set->ids);
+ xhash_delete(network_set->ids);
if (network_set->pnetwork6)
{
snort_free(network_set->pnetwork6);
network_set->pnetwork6 = nullptr;
}
sflist_static_free_all(&network_set->networks6, &snort_free);
- sfxhash_delete(network_set->ids6);
+ xhash_delete(network_set->ids6);
snort_free(network_set);
return 0;
}
sflist_add_tail(&network_set->networks, (void*)network);
- int rval = sfxhash_add(network_set->ids, &network->info.id, &network->info.id);
- if (rval != SFXHASH_OK && rval != SFXHASH_INTABLE)
+ int rval = xhash_add(network_set->ids, &network->info.id, &network->info.id);
+ if (rval != XHASH_OK && rval != XHASH_INTABLE)
{
ErrorMessage("NetworkSet:Out of memory");
snort_free(network);
}
sflist_add_tail(&network_set->networks6, (void*)network);
- int rval = sfxhash_add(network_set->ids6, &network->info.id, &network->info.id);
- if (rval != SFXHASH_OK && rval != SFXHASH_INTABLE)
+ int rval = xhash_add(network_set->ids6, &network->info.id, &network->info.id);
+ if (rval != XHASH_OK && rval != XHASH_INTABLE)
{
ErrorMessage("NetworkSet:Out of memory");
snort_free(network);
int NetworkSetManager::reduce(NetworkSet* network_set)
{
- SFXHASH_NODE* hnode;
+ XHashNode* hnode;
unsigned id;
int rval;
SF_LIST ordered_networks;
if (!network_set)
return -1;
- for (hnode = sfxhash_gfindfirst(network_set->ids);
+ for (hnode = xhash_gfindfirst(network_set->ids);
hnode;
- hnode=sfxhash_gfindnext(network_set->ids))
+ hnode=xhash_gfindnext(network_set->ids))
{
id = *(unsigned*)(hnode->data);
if ((rval = order_by_netmask(&ordered_networks, &network_set->networks, id)) != 0)
}
}
- for (hnode = sfxhash_gfindfirst(network_set->ids6); hnode; hnode=sfxhash_gfindnext(
+ for (hnode = xhash_gfindfirst(network_set->ids6); hnode; hnode=xhash_gfindnext(
network_set->ids6))
{
id = *(unsigned*)(hnode->data);
#include <cstdio>
-#include "hash/sfxhash.h"
+#include "hash/xhash.h"
#include "protocols/ipv6.h"
#include "utils/sflsq.h"
{
NetworkSet* next;
SF_LIST networks;
- SFXHASH* ids;
+ XHash* ids;
Network** pnetwork;
unsigned count;
SF_LIST networks6;
- SFXHASH* ids6;
+ XHash* ids6;
Network6** pnetwork6;
unsigned count6;
};
#include "framework/ips_option.h"
#include "framework/module.h"
-#include "hash/sfhashfcn.h"
+#include "hash/hashfcn.h"
#include "profiler/profiler.h"
#include "protocols/packet.h"
#include "utils/util.h"
#include "length_app_cache.h"
#include "application_ids.h"
-#include "hash/sfxhash.h"
+#include "hash/xhash.h"
#include "log/messages.h"
#include "main/thread.h"
#define HASH_NUM_ROWS (1024)
-static THREAD_LOCAL SFXHASH* lengthCache = nullptr;
+static THREAD_LOCAL XHash* lengthCache = nullptr;
void init_length_app_cache()
{
- if (!(lengthCache = sfxhash_new(HASH_NUM_ROWS, sizeof(LengthKey), sizeof(AppId),
+ if (!(lengthCache = xhash_new(HASH_NUM_ROWS, sizeof(LengthKey), sizeof(AppId),
0, 0, nullptr, nullptr, 0)))
{
ErrorMessage("lengthAppCache: Failed to allocate length cache!");
{
if (lengthCache)
{
- sfxhash_delete(lengthCache);
+ xhash_delete(lengthCache);
lengthCache = nullptr;
}
}
AppId find_length_app_cache(const LengthKey* key)
{
- AppId* val = (AppId*)sfxhash_find(lengthCache, (void*)key);
+ AppId* val = (AppId*)xhash_find(lengthCache, (void*)key);
if (val == nullptr)
return APP_ID_NONE; /* no match */
else
bool add_length_app_cache(const LengthKey* key, AppId val)
{
- if (sfxhash_add(lengthCache, (void*)key, (void*)&val))
+ if (xhash_add(lengthCache, (void*)key, (void*)&val))
{
return false;
}
#include "detector_plugins/http_url_patterns.h"
#include "detector_plugins/detector_sip.h"
#include "detector_plugins/detector_pattern.h"
-#include "hash/sfxhash.h"
+#include "hash/xhash.h"
#include "log/messages.h"
#include "main/snort_debug.h"
#include "main/snort_types.h"
ProfileStats luaCiscoPerfStats;
ProfileStats luaCustomPerfStats;
-static THREAD_LOCAL SFXHASH* CHP_glossary = nullptr; // keep track of http multipatterns here
+static THREAD_LOCAL XHash* CHP_glossary = nullptr; // keep track of http multipatterns here
static int free_chp_data(void* /* key */, void* data)
{
int init_chp_glossary()
{
- if (!(CHP_glossary = sfxhash_new(1024, sizeof(AppId), 0, 0, 0, nullptr, &free_chp_data, 0)))
+ if (!(CHP_glossary = xhash_new(1024, sizeof(AppId), 0, 0, 0, nullptr, &free_chp_data, 0)))
{
ErrorMessage("Config: failed to allocate memory for an sfxhash.");
return 0;
void free_chp_glossary()
{
if (CHP_glossary)
- sfxhash_delete(CHP_glossary);
+ xhash_delete(CHP_glossary);
CHP_glossary = nullptr;
}
new_app->app_type_flags = app_type_flags;
new_app->num_matches = num_matches;
- if (sfxhash_add(CHP_glossary, &(new_app->appIdInstance), new_app))
+ if (xhash_add(CHP_glossary, &(new_app->appIdInstance), new_app))
{
ErrorMessage("LuaDetectorApi:Failed to add CHP for appId %d, instance %d",
CHP_APPIDINSTANCE_TO_ID(appIdInstance), CHP_APPIDINSTANCE_TO_INSTANCE(appIdInstance));
int num_matches = lua_tointeger(L, ++index);
// We only want one of these for each appId.
- if (sfxhash_find(CHP_glossary, &appIdInstance))
+ if (xhash_find(CHP_glossary, &appIdInstance))
{
ErrorMessage(
"LuaDetectorApi:Attempt to add more than one CHP for appId %d - use CHPMultiCreateApp",
AppInfoManager& app_info_mgr = AppInfoManager::get_instance();
//find the CHP App for this
- if (!(chpapp = (decltype(chpapp))sfxhash_find(CHP_glossary, &appIdInstance)))
+ if (!(chpapp = (decltype(chpapp))xhash_find(CHP_glossary, &appIdInstance)))
{
ErrorMessage(
"LuaDetectorApi:Invalid attempt to add a CHP action for unknown appId %d, instance %d. - pattern:\"%s\" - action \"%s\"\n",
for (instance=0; instance < CHP_APPID_INSTANCE_MAX; instance++ )
{
appIdInstance = (appId << CHP_APPID_BITS_FOR_INSTANCE) + instance;
- if ( sfxhash_find(CHP_glossary, &appIdInstance) )
+ if ( xhash_find(CHP_glossary, &appIdInstance) )
continue;
break;
}
LogMessage("Service State:\n");
if (serviceStateCache4)
{
- LogMessage(" IPv4 Count: %u\n", sfxhash_count(serviceStateCache4));
+ LogMessage(" IPv4 Count: %u\n", xhash_count(serviceStateCache4));
LogMessage(" IPv4 Memory Limit: %lu\n", serviceStateCache4->mc.memcap);
LogMessage(" IPv4 Memory Used: %lu\n", serviceStateCache4->mc.memused);
}
if (serviceStateCache6)
{
- LogMessage(" IPv6 Count: %u\n", sfxhash_count(serviceStateCache6));
+ LogMessage(" IPv6 Count: %u\n", xhash_count(serviceStateCache6));
LogMessage(" IPv6 Memory Limit: %lu\n", serviceStateCache6->mc.memcap);
LogMessage(" IPv6 Memory Used: %lu\n", serviceStateCache6->mc.memused);
}
*swapped = 1;
}
- value = (FlowStateValue*)sfxhash_find(ip_map, &key);
+ value = (FlowStateValue*)xhash_find(ip_map, &key);
if (!value)
{
- SFXHASH_NODE* node = sfxhash_get_node(ip_map, &key);
+ XHashNode* node = xhash_get_node(ip_map, &key);
if (!node)
{
&stats.state_changes[SFS_STATE_UDP_CREATED]);
formatter->finalize_fields();
- ip_map = sfxhash_new(1021, sizeof(FlowStateKey), sizeof(FlowStateValue),
+ ip_map = xhash_new(1021, sizeof(FlowStateKey), sizeof(FlowStateValue),
perfmon_config->flowip_memcap, 1, nullptr, nullptr, 1);
if (!ip_map)
FlowIPTracker::~FlowIPTracker()
{
if (ip_map)
- sfxhash_delete(ip_map);
+ xhash_delete(ip_map);
}
void FlowIPTracker::reset()
{
- sfxhash_make_empty(ip_map);
+ xhash_make_empty(ip_map);
}
void FlowIPTracker::update(Packet* p)
void FlowIPTracker::process(bool)
{
- for (auto node = sfxhash_findfirst(ip_map); node; node = sfxhash_findnext(ip_map))
+ for (auto node = xhash_findfirst(ip_map); node; node = xhash_findnext(ip_map))
{
FlowStateKey* key = (FlowStateKey*)node->key;
FlowStateValue* cur_stats = (FlowStateValue*)node->data;
#define FLOW_IP_TRACKER_H
#include "perf_tracker.h"
-#include "hash/sfxhash.h"
+#include "hash/xhash.h"
enum FlowState
{
private:
FlowStateValue stats;
- SFXHASH* ip_map;
+ XHash* ip_map;
char ip_a[41], ip_b[41];
FlowStateValue* find_stats(const SfIp* src_addr, const SfIp* dst_addr, int* swapped);
#include "ps_detect.h"
-#include "hash/sfxhash.h"
+#include "hash/xhash.h"
#include "log/messages.h"
#include "protocols/icmp4.h"
#include "protocols/packet.h"
};
PADDING_GUARD_END
-static THREAD_LOCAL SFXHASH* portscan_hash = nullptr;
+static THREAD_LOCAL XHash* portscan_hash = nullptr;
PortscanConfig::PortscanConfig()
{
{
if ( portscan_hash )
{
- sfxhash_delete(portscan_hash);
+ xhash_delete(portscan_hash);
portscan_hash = nullptr;
}
}
int rows = memcap / ps_node_size();
- portscan_hash = sfxhash_new(rows, sizeof(PS_HASH_KEY), sizeof(PS_TRACKER),
+ portscan_hash = xhash_new(rows, sizeof(PS_HASH_KEY), sizeof(PS_TRACKER),
memcap, 1, ps_tracker_free, nullptr, 1);
if ( !portscan_hash )
void ps_reset()
{
if ( portscan_hash )
- sfxhash_make_empty(portscan_hash);
+ xhash_make_empty(portscan_hash);
}
// Check scanner and scanned ips to see if we can filter them out.
*/
static PS_TRACKER* ps_tracker_get(PS_HASH_KEY* key)
{
- PS_TRACKER* ht = (PS_TRACKER*)sfxhash_find(portscan_hash, (void*)key);
+ PS_TRACKER* ht = (PS_TRACKER*)xhash_find(portscan_hash, (void*)key);
if ( ht )
return ht;
- if ( sfxhash_add(portscan_hash, (void*)key, nullptr) != SFXHASH_OK )
+ if ( xhash_add(portscan_hash, (void*)key, nullptr) != XHASH_OK )
return nullptr;
- ht = (PS_TRACKER*)sfxhash_mru(portscan_hash);
+ ht = (PS_TRACKER*)xhash_mru(portscan_hash);
if ( ht )
memset(ht, 0x00, sizeof(PS_TRACKER));
if ( !otn->sigInfo.services )
otn->sigInfo.services =
- (ServiceInfo*)snort_calloc(sc->max_metadata_services, sizeof(ServiceInfo));
+ (SignatureServiceInfo*)snort_calloc(sc->max_metadata_services, sizeof(SignatureServiceInfo));
int idx = otn->sigInfo.num_services++;
#include "detection/rtn_checks.h"
#include "detection/treenodes.h"
#include "framework/decode_data.h"
-#include "hash/sfxhash.h"
+#include "hash/xhash.h"
#include "log/messages.h"
#include "main/snort_config.h"
#include "main/snort_debug.h"
if ( sc->rtn_hash_table )
{
RuleTreeNodeKey key { testNode, policyId };
- return (RuleTreeNode*)sfxhash_find(sc->rtn_hash_table, &key);
+ return (RuleTreeNode*)xhash_find(sc->rtn_hash_table, &key);
}
return nullptr;
#include "filters/detection_filter.h"
#include "filters/rate_filter.h"
#include "filters/sfthreshold.h"
-#include "hash/sfhashfcn.h"
-#include "hash/sfxhash.h"
+#include "hash/hashfcn.h"
+#include "hash/xhash.h"
#include "log/messages.h"
#include "main/shell.h"
#include "main/snort_config.h"
{
RuleTreeNode* rtn;
PolicyId policyId;
- SFGHASH_NODE* hashNode;
+ GHashNode* hashNode;
if (sc->otn_map == nullptr)
return;
- for (hashNode = sfghash_findfirst(sc->otn_map);
+ for (hashNode = ghash_findfirst(sc->otn_map);
hashNode;
- hashNode = sfghash_findnext(sc->otn_map))
+ hashNode = ghash_findnext(sc->otn_map))
{
OptTreeNode* otn = (OptTreeNode*)hashNode->data;
/* Init sid-gid -> otn map */
sc->otn_map = OtnLookupNew();
if (sc->otn_map == nullptr)
- ParseAbort("ParseRulesFile otn_map sfghash_new failed.");
+ ParseAbort("ParseRulesFile otn_map ghash_new failed.");
}
#define IFACE_VARS_MAX 128
{
RuleTreeNodeKey key{ rtn, policyId };
if ( sc && sc->rtn_hash_table )
- sfxhash_remove(sc->rtn_hash_table, &key);
+ xhash_remove(sc->rtn_hash_table, &key);
}
return rtn;
return deleteRtnFromOtn(otn, get_ips_policy()->policy_id, sc);
}
-static uint32_t rtn_hash_func(SFHASHFCN*, const unsigned char *k, int)
+static uint32_t rtn_hash_func(HashFnc*, const unsigned char *k, int)
{
uint32_t a,b,c;
const RuleTreeNodeKey* rtnk = (const RuleTreeNodeKey*)k;
if (!sc->rtn_hash_table)
{
- sc->rtn_hash_table = sfxhash_new(10000, sizeof(RuleTreeNodeKey), 0, 0, 0, nullptr, nullptr, 1);
+ sc->rtn_hash_table = xhash_new(10000, sizeof(RuleTreeNodeKey), 0, 0, 0, nullptr, nullptr, 1);
if (sc->rtn_hash_table == nullptr)
FatalError("Failed to create rule tree node hash table\n");
- sfxhash_set_keyops(sc->rtn_hash_table, rtn_hash_func, rtn_compare_func);
+ xhash_set_keyops(sc->rtn_hash_table, rtn_hash_func, rtn_compare_func);
}
RuleTreeNodeKey key;
memset(&key, 0, sizeof(key));
key.rtn = rtn;
key.policyId = policyId;
- sfxhash_add(sc->rtn_hash_table, &key, rtn);
+ xhash_add(sc->rtn_hash_table, &key, rtn);
return 0; //success
}
#include "port_object2.h"
-#include "hash/sfhashfcn.h"
+#include "hash/hashfcn.h"
#include "log/messages.h"
#include "main/snort_debug.h"
#include "parser/parser.h"
#define SWAP_BYTES(a)
#endif
-static unsigned po_rule_hash_func(SFHASHFCN* p, const unsigned char* k, int n)
+static unsigned po_rule_hash_func(HashFnc* p, const unsigned char* k, int n)
{
unsigned char* key;
int ikey = *(const int*)k;
/* Set a pointer to the key to pass to the hashing function */
key = (unsigned char*)&ikey;
- return sfhashfcn_hash(p, key, n);
+ return hashfcn_hash(p, key, n);
}
-static int* RuleHashToSortedArray(SFGHASH* rh)
+static int* RuleHashToSortedArray(GHash* rh)
{
if ( !rh or !rh->count )
return nullptr;
int* ra = (int*)snort_calloc(rh->count, sizeof(int));
int k = 0;
- for ( SFGHASH_NODE* node = sfghash_findfirst(rh);
+ for ( GHashNode* node = ghash_findfirst(rh);
node != nullptr && k < (int)rh->count;
- node = sfghash_findnext(rh) )
+ node = ghash_findnext(rh) )
{
if ( int* prid = (int*)node->data )
ra[k++] = *prid;
return nullptr;
}
- po->rule_hash =(SFGHASH*)sfghash_new(nrules,sizeof(int), 0,
+ po->rule_hash =(GHash*)ghash_new(nrules,sizeof(int), 0,
snort_free /* frees data - should be rule id ptrs == (int*) */);
if ( !po->rule_hash )
{
}
/* Use hash function defined above for hashing the key as an int. */
- sfghash_set_keyops(po->rule_hash, po_rule_hash_func, memcmp);
+ ghash_set_keyops(po->rule_hash, po_rule_hash_func, memcmp);
return po;
}
sflist_free_all(po->item_list, snort_free);
if ( po->rule_hash)
- sfghash_delete(po->rule_hash);
+ ghash_delete(po->rule_hash);
if (po->port_list)
delete po->port_list;
sflist_free_all(po->item_list, snort_free);
po->item_list = nullptr;
- sfghash_delete(po->rule_hash);
+ ghash_delete(po->rule_hash);
po->rule_hash = nullptr;
}
prule = (int*)snort_calloc(sizeof(int));
*prule = *prid;
- if ( sfghash_add(ponew->rule_hash, prule, prule) != SFGHASH_OK )
+ if ( ghash_add(ponew->rule_hash, prule, prule) != GHASH_OK )
{
snort_free(prule);
}
int* prid2 = (int*)snort_calloc(sizeof(int));
*prid2 = *prid;
- if ( sfghash_add(poa->rule_hash,prid2,prid2) != SFGHASH_OK )
+ if ( ghash_add(poa->rule_hash,prid2,prid2) != GHASH_OK )
snort_free(prid2);
}
return poa;
/* Dup and append rule list numbers from pob to poa */
PortObject2* PortObject2AppendPortObject2(PortObject2* poa, PortObject2* pob)
{
- for (SFGHASH_NODE* node = sfghash_findfirst(pob->rule_hash);
+ for (GHashNode* node = ghash_findfirst(pob->rule_hash);
node!= nullptr;
- node = sfghash_findnext(pob->rule_hash) )
+ node = ghash_findnext(pob->rule_hash) )
{
int* prid = (int*)node->data;
int* prid2 = (int*)snort_calloc(sizeof(int));
*prid2 = *prid;
- if ( sfghash_add(poa->rule_hash,prid2,prid2) != SFGHASH_OK )
+ if ( ghash_add(poa->rule_hash,prid2,prid2) != GHASH_OK )
snort_free(prid2);
}
return poa;
#define PORT_OBJECT2_H
#include "framework/bits.h"
-#include "hash/sfghash.h"
+#include "hash/ghash.h"
#include "utils/sflsq.h"
//-------------------------------------------------------------------------
int id; /* internal tracking - compiling sets this value */
SF_LIST* item_list; /* list of port and port-range items */
- SFGHASH* rule_hash; /* hash of rule (rule-indexes) in use */
+ GHash* rule_hash; /* hash of rule (rule-indexes) in use */
PortBitSet* port_list; /* for collecting ports that use this object */
struct PortGroup* group; /* PortGroup based on rule_hash */
#include <memory>
-#include "hash/sfhashfcn.h"
+#include "hash/hashfcn.h"
#include "log/messages.h"
#include "main/snort_debug.h"
#include "utils/util.h"
}
#endif
-static unsigned plx_hash(SFHASHFCN* p, const unsigned char* d, int)
+static unsigned plx_hash(HashFnc* p, const unsigned char* d, int)
{
unsigned hash = p->seed;
const plx_t* plx = *(plx_t* const*)d;
/*
Hash routine for hashing PortObjects as Keys
- p - SFHASHFCN *
+ p - HashFnc *
d - PortObject *
n = 4 bytes (sizeof*) - not used
Don't use this for type=ANY port objects
*/
-static unsigned PortObject_hash(SFHASHFCN* p, const unsigned char* d, int)
+static unsigned PortObject_hash(HashFnc* p, const unsigned char* d, int)
{
unsigned hash = p->seed;
const PortObject* po = *(PortObject* const*)d;
* lookup.
*/
static PortObject2* _merge_N_pol(
- SFGHASH* mhash, SFGHASH* mhashx,
+ GHash* mhash, GHash* mhashx,
SF_LIST* plx_list, void** pol,
int pol_cnt, plx_t* plx)
{
/*
* Check for the merged port object in the plx table
*/
- DebugFormat(DEBUG_PORTLISTS, "++++n=%d sfghash_find-mhashx\n", pol_cnt);
- ponew = (PortObject2*)sfghash_find(mhashx, &plx);
+ DebugFormat(DEBUG_PORTLISTS, "++++n=%d ghash_find-mhashx\n", pol_cnt);
+ ponew = (PortObject2*)ghash_find(mhashx, &plx);
if ( ponew )
{
* Add the Merged PortObject2 to the PortObject2 hash table
* keyed by ports.
*/
- DebugFormat(DEBUG_PORTLISTS, "n=%d sfghash_add-mhash\n", pol_cnt);
- stat =sfghash_add(mhash, &ponew, ponew);
- if ( stat != SFGHASH_OK )
+ DebugFormat(DEBUG_PORTLISTS, "n=%d ghash_add-mhash\n", pol_cnt);
+ stat =ghash_add(mhash, &ponew, ponew);
+ if ( stat != GHASH_OK )
{
/* This is possible since PLX hash on a different key */
- if ( stat == SFGHASH_INTABLE )
+ if ( stat == GHASH_INTABLE )
{
- DebugFormat(DEBUG_PORTLISTS, "n=%d sfghash_add-mhash ponew in table\n", pol_cnt);
- DebugFormat(DEBUG_PORTLISTS, "n=%d sfghash_find-mhash ponew\n", pol_cnt);
- pox = (PortObject2*)sfghash_find(mhash, &ponew);
+ DebugFormat(DEBUG_PORTLISTS, "n=%d ghash_add-mhash ponew in table\n", pol_cnt);
+ DebugFormat(DEBUG_PORTLISTS, "n=%d ghash_find-mhash ponew\n", pol_cnt);
+ pox = (PortObject2*)ghash_find(mhash, &ponew);
if ( pox )
{
PortObject2AppendPortObject2(pox, ponew);
- DebugMessage(DEBUG_PORTLISTS, "sfportobject.c: merge_N_pol() SFGHASH_INTABLE\n");
+ DebugMessage(DEBUG_PORTLISTS, "sfportobject.c: merge_N_pol() GHASH_INTABLE\n");
PortObject2Free(ponew);
ponew = pox;
DebugFormat(DEBUG_PORTLISTS,
- "n=%d sfghash_find-mhash ponew found, new rules merged\n", pol_cnt);
+ "n=%d ghash_find-mhash ponew found, new rules merged\n", pol_cnt);
}
else
{
/*
* Add the plx node to the PLX hash table
*/
- DebugFormat(DEBUG_PORTLISTS, "n=%d sfghash_add-mhashx\n", pol_cnt);
- stat = sfghash_add(mhashx, &plx_tmp, ponew);
- if ( stat != SFGHASH_OK )
+ DebugFormat(DEBUG_PORTLISTS, "n=%d ghash_add-mhashx\n", pol_cnt);
+ stat = ghash_add(mhashx, &plx_tmp, ponew);
+ if ( stat != GHASH_OK )
{
- if ( stat == SFGHASH_INTABLE )
+ if ( stat == GHASH_INTABLE )
{
FatalError("Could not add merged plx to PLX HASH table-INTABLE\n");
}
/*
* Validate hash table entry
*/
- if ( sfghash_find(mhashx, &plx_tmp) != ponew )
+ if ( ghash_find(mhashx, &plx_tmp) != ponew )
{
FatalError("Find after add failed on PLX HASH table key\n");
}
*
*/
static PortObject2* PortTableCompileMergePortObjectList2(
- SFGHASH* mhash, SFGHASH* mhashx, SF_LIST* plx_list,
+ GHash* mhash, GHash* mhashx, SF_LIST* plx_list,
PortObject* pol[], int pol_cnt, unsigned int lcnt)
{
std::unique_ptr<void*[]> upA(new void*[SFPO_MAX_LPORTS]);
PortObject** pol = upA.get();
// Create a Merged Port Object Table - hash by ports, no user keys, don't free data
- SFGHASH* mhash = sfghash_new(PO_HASH_TBL_ROWS, sizeof(PortObject*), 0, nullptr);
+ GHash* mhash = ghash_new(PO_HASH_TBL_ROWS, sizeof(PortObject*), 0, nullptr);
/* Setup hashing function and key comparison function */
- sfhashfcn_set_keyops(mhash->sfhashfcn, PortObject_hash, PortObject_keycmp);
+ hashfcn_set_keyops(mhash->hashfcn, PortObject_hash, PortObject_keycmp);
p->pt_mpo_hash = mhash;
// Create a Merged Port Object Table - hash by pointers, no user keys, don't free data
- SFGHASH* mhashx = sfghash_new(PO_HASH_TBL_ROWS, sizeof(plx_t*), 0, nullptr);
+ GHash* mhashx = ghash_new(PO_HASH_TBL_ROWS, sizeof(plx_t*), 0, nullptr);
/* Setup hashing function and key comparison function */
- sfhashfcn_set_keyops(mhashx->sfhashfcn, plx_hash, plx_keycmp);
+ hashfcn_set_keyops(mhashx->hashfcn, plx_hash, plx_keycmp);
p->pt_mpxo_hash = mhashx;
*/
/* 1st- Setup bitmasks for collecting ports */
- for (SFGHASH_NODE* node=sfghash_findfirst(mhashx);
+ for (GHashNode* node=ghash_findfirst(mhashx);
node;
- node=sfghash_findnext(mhashx) )
+ node=ghash_findnext(mhashx) )
{
PortObject2* poa = (PortObject2*)node->data;
}
/* Process Port map and print final port-object usage stats */
- for (SFGHASH_NODE* node=sfghash_findfirst(mhashx);
+ for (GHashNode* node=ghash_findfirst(mhashx);
node;
- node=sfghash_findnext(mhashx) )
+ node=ghash_findnext(mhashx) )
{
PortObject2* po = (PortObject2*)node->data;
pid = (int*)sflist_next(&rpos) )
{
/* find it in po2 */
- int* id = (int*)sfghash_find(po2->rule_hash, pid);
+ int* id = (int*)ghash_find(po2->rule_hash, pid);
/* make sure it's in po2 */
if ( !id )
char* parray = upA.get();
memset(parray, 0, SFPO_MAX_PORTS);
- for ( SFGHASH_NODE* node=sfghash_findfirst(p->pt_mpo_hash);
+ for ( GHashNode* node=ghash_findfirst(p->pt_mpo_hash);
node;
- node=sfghash_findnext(p->pt_mpo_hash) )
+ node=ghash_findnext(p->pt_mpo_hash) )
{
PortObject2* po = (PortObject2*)node->data;
if (p->pt_mpo_hash)
{
- for ( SFGHASH_NODE* node = sfghash_findfirst(p->pt_mpo_hash);
+ for ( GHashNode* node = ghash_findfirst(p->pt_mpo_hash);
node;
- node = sfghash_findnext(p->pt_mpo_hash) )
+ node = ghash_findnext(p->pt_mpo_hash) )
{
PortObject2* po = (PortObject2*)node->data;
PortObject2Free(po);
}
- sfghash_delete(p->pt_mpo_hash);
+ ghash_delete(p->pt_mpo_hash);
}
if (p->pt_mpxo_hash)
{
- sfghash_delete(p->pt_mpxo_hash);
+ ghash_delete(p->pt_mpxo_hash);
}
snort_free(p);
// FIXIT-P we should be able to free pt_mpo_hash early too
void PortTableFinalize(PortTable* p)
{
- sfghash_delete(p->pt_mpxo_hash);
+ ghash_delete(p->pt_mpxo_hash);
p->pt_mpxo_hash = nullptr;
}
LogMessage(" *** PortTableCompiled [ %d compiled port groups ] \n\n",
p->pt_mpo_hash->count);
- for ( SFGHASH_NODE* node = sfghash_findfirst(p->pt_mpo_hash);
+ for ( GHashNode* node = ghash_findfirst(p->pt_mpo_hash);
node!= nullptr;
- node = sfghash_findnext(p->pt_mpo_hash) )
+ node = ghash_findnext(p->pt_mpo_hash) )
{
PortObject2* po = (PortObject2*)node->data;
PortObject2PrintEx(po, print_index_map);
LogMessage(">>>PortTable - Compiled Port Groups\n");
LogMessage(" [ %d port groups ] \n\n", p->pt_mpo_hash->count);
- for ( SFGHASH_NODE* ponode = sfghash_findfirst(p->pt_mpo_hash);
+ for ( GHashNode* ponode = ghash_findfirst(p->pt_mpo_hash);
ponode!= nullptr;
- ponode = sfghash_findnext(p->pt_mpo_hash) )
+ ponode = ghash_findnext(p->pt_mpo_hash) )
{
PortObject2* po = (PortObject2*)ponode->data;
PortObject2Print(po);
#ifndef PORT_TABLE_H
#define PORT_TABLE_H
-#include "hash/sfghash.h"
+#include "hash/ghash.h"
#include "ports/port_item.h"
#include "ports/port_object.h"
#include "ports/port_object2.h"
int pt_poid;
/* Compiled / merged port object hash table */
- SFGHASH* pt_mpo_hash;
- SFGHASH* pt_mpxo_hash;
+ GHash* pt_mpo_hash;
+ GHash* pt_mpxo_hash;
/*
* Final Port/Rule Groupings, one port object per port, or null
PortVarTable* PortVarTableCreate()
{
PortObject* po;
- SFGHASH* h;
+ GHash* h;
/*
* This is used during parsing of config,
* so 1000 entries is ok, worst that happens is somewhat slower
* config/rule processing.
*/
- h = sfghash_new(1000,0,0,PortObjectFree);
+ h = ghash_new(1000,0,0,PortObjectFree);
if ( !h )
return nullptr;
{
if ( pvt )
{
- sfghash_delete(pvt);
+ ghash_delete(pvt);
}
return 0;
}
int PortVarTableAdd(PortVarTable* h, PortObject* po)
{
int stat;
- stat = sfghash_add(h,po->name,po);
- if ( stat == SFGHASH_INTABLE )
+ stat = ghash_add(h,po->name,po);
+ if ( stat == GHASH_INTABLE )
return 1;
- if ( stat == SFGHASH_OK )
+ if ( stat == GHASH_OK )
return 0;
return -1;
}
if (!h || !name)
return nullptr;
- return (PortObject*)sfghash_find(h,name);
+ return (PortObject*)ghash_find(h,name);
}
#ifndef PORT_VAR_TABLE_H
#define PORT_VAR_TABLE_H
-#include "hash/sfghash.h"
+#include "hash/ghash.h"
#include "ports/port_object.h"
#include "ports/port_table.h"
// PortVars are internally stored in PortObjects
//-------------------------------------------------------------------------
-typedef SFGHASH PortVarTable;
+typedef GHash PortVarTable;
PortVarTable* PortVarTableCreate();
int PortVarTableFree(PortVarTable* pvt);
std::vector<View> entries;
- for ( auto* h = sfghash_findfirst(otn_map); h; h = sfghash_findnext(otn_map) )
+ for ( auto* h = ghash_findfirst(otn_map); h; h = ghash_findnext(otn_map) )
{
auto* otn = static_cast<OptTreeNode*>(h->data);
assert(otn);
assert(SnortConfig::get_conf());
auto* otn_map = SnortConfig::get_conf()->otn_map;
- for ( auto* h = sfghash_findfirst(otn_map); h; h = sfghash_findnext(otn_map) )
+ for ( auto* h = ghash_findfirst(otn_map); h; h = ghash_findnext(otn_map) )
{
auto* otn = static_cast<OptTreeNode*>(h->data);
assert(otn);
#include "framework/module.h"
#include "framework/ips_option.h"
#include "framework/range.h"
-#include "hash/sfhashfcn.h"
+#include "hash/hashfcn.h"
#include "profiler/profiler.h"
#include "target_based/snort_protocols.h"
#include "utils/util.h"
#include "framework/ips_option.h"
#include "framework/module.h"
-#include "hash/sfhashfcn.h"
+#include "hash/hashfcn.h"
#include "profiler/profiler.h"
#include "utils/util.h"
#include "framework/cursor.h"
#include "framework/ips_option.h"
#include "framework/module.h"
-#include "hash/sfhashfcn.h"
+#include "hash/hashfcn.h"
#include "profiler/profiler.h"
#include "dce_common.h"
#include "framework/cursor.h"
#include "framework/ips_option.h"
#include "framework/module.h"
-#include "hash/sfhashfcn.h"
+#include "hash/hashfcn.h"
#include "protocols/packet.h"
#include "profiler/profiler.h"
#include "framework/ips_option.h"
#include "framework/module.h"
-#include "hash/sfhashfcn.h"
+#include "hash/hashfcn.h"
#include "profiler/profiler.h"
#include "protocols/packet.h"
#include "framework/ips_option.h"
#include "framework/module.h"
-#include "hash/sfhashfcn.h"
+#include "hash/hashfcn.h"
#include "profiler/profiler.h"
#include "protocols/packet.h"
#include "framework/ips_option.h"
#include "framework/module.h"
-#include "hash/sfhashfcn.h"
+#include "hash/hashfcn.h"
#include "profiler/profiler.h"
#include "protocols/packet.h"
// gtp_info rule option implementation
-#include "hash/sfhashfcn.h"
+#include "hash/hashfcn.h"
#include "framework/cursor.h"
#include "framework/ips_option.h"
#include "framework/module.h"
#include "framework/ips_option.h"
#include "framework/module.h"
-#include "hash/sfhashfcn.h"
+#include "hash/hashfcn.h"
#include "protocols/packet.h"
#include "profiler/profiler.h"
#include "framework/ips_option.h"
#include "framework/module.h"
-#include "hash/sfhashfcn.h"
+#include "hash/hashfcn.h"
#include "protocols/packet.h"
#include "profiler/profiler.h"
#include "http_uri.h"
-#include "hash/sfhashfcn.h"
+#include "hash/hashfcn.h"
using namespace HttpEnums;
#include "ips_http.h"
#include "framework/cursor.h"
-#include "hash/sfhashfcn.h"
+#include "hash/hashfcn.h"
#include "log/messages.h"
#include "protocols/packet.h"
#include "framework/cursor.h"
#include "framework/ips_option.h"
#include "framework/module.h"
-#include "hash/sfhashfcn.h"
+#include "hash/hashfcn.h"
#include "profiler/profiler.h"
#include "protocols/packet.h"
#include "framework/ips_option.h"
#include "framework/module.h"
-#include "hash/sfhashfcn.h"
+#include "hash/hashfcn.h"
#include "protocols/packet.h"
#include "profiler/profiler.h"
#include "framework/ips_option.h"
#include "framework/module.h"
-#include "hash/sfhashfcn.h"
+#include "hash/hashfcn.h"
#include "protocols/packet.h"
#include "profiler/profiler.h"
#include "framework/ips_option.h"
#include "framework/module.h"
-#include "hash/sfhashfcn.h"
+#include "hash/hashfcn.h"
#include "log/messages.h"
#include "profiler/profiler.h"
#include "protocols/packet.h"
#include "framework/ips_option.h"
#include "framework/module.h"
-#include "hash/sfhashfcn.h"
+#include "hash/hashfcn.h"
#include "log/messages.h"
#include "profiler/profiler.h"
#include "protocols/packet.h"
#include <cstring>
-#include "hash/sfhashfcn.h"
+#include "hash/hashfcn.h"
/*
* Trim spaces non-destructively on both sides of string : '', \t, \n, \r
#include "framework/ips_option.h"
#include "framework/module.h"
-#include "hash/sfhashfcn.h"
+#include "hash/hashfcn.h"
#include "profiler/profiler.h"
#include "protocols/packet.h"
#include "protocols/ssl.h"
#include "framework/ips_option.h"
#include "framework/module.h"
-#include "hash/sfhashfcn.h"
+#include "hash/hashfcn.h"
#include "profiler/profiler.h"
#include "protocols/packet.h"
#include "protocols/ssl.h"
#include "detection/detection_engine.h"
#include "framework/ips_option.h"
#include "framework/module.h"
-#include "hash/sfhashfcn.h"
+#include "hash/hashfcn.h"
#include "main/snort_config.h"
#include "profiler/profiler.h"
#include "framework/ips_option.h"
#include "framework/module.h"
#include "framework/range.h"
-#include "hash/sfhashfcn.h"
+#include "hash/hashfcn.h"
#include "profiler/profiler_defs.h"
#include "tcp_session.h"
}
static int ProcessUdp(
- Flow* lwssn, Packet* p, StreamUdpConfig*, SFXHASH_NODE*)
+ Flow* lwssn, Packet* p, StreamUdpConfig*, XHashNode*)
{
assert(lwssn->pkt_type == PktType::UDP);