#include "sfrf.h"
+#include "main/thread.h"
#include "detection/rules.h"
#include "hash/ghash.h"
#include "hash/xhash.h"
time_t revertTime;
} tSFRFTrackingNode;
-XHash* rf_hash = nullptr;
+static THREAD_LOCAL XHash* rf_hash = nullptr;
// private methods ...
static int _checkThreshold(
snort_free(pSidnode);
}
+int SFRF_Alloc(unsigned int memcap)
+{
+ if ( rf_hash == nullptr )
+ {
+ SFRF_New(memcap);
+
+ if ( rf_hash == nullptr )
+ return -1;
+ }
+ return 0;
+}
+
+
/* Add a permanent threshold object to the threshold table. Multiple
* objects may be defined for each gid and sid pair. Internally
* a unique threshold id is generated for each pair.
PolicyId policy_id = snort::get_ips_policy()->policy_id;
- // Auto init - memcap must be set 1st, which is not really a problem
- if ( rf_hash == nullptr )
- {
- SFRF_New(rf_config->memcap);
-
- if ( rf_hash == nullptr )
- return -1;
- }
-
if ((rf_config == nullptr) || (cfgNode == nullptr))
return -1;
return (config->internal_event_mask & (1 << sid));
}
-#endif
+int SFRF_Alloc(unsigned int memcap);
+
+#endif
rfc = RateFilter_ConfigNew();
rfc->memcap = cap;
+ SFRF_Alloc(rfc->memcap);
+
for ( unsigned i = 0; i < NUM_NODES; i++ )
{
RateData* p = rfData + i;
}
Term();
}
-
#endif
/* Don't log, and stop looking( event's to this address
* for this gen_id+sig_id) */
- sfthd_node->filtered++;
return -1;
}
return 1; /* Keep looking for other suppressors */
/* Don't Log yet, don't keep looking:
* already logged our limit, don't log this sid */
- sfthd_node->filtered++;
return -2;
}
if ( sfthd_node->type == THD_TYPE_LIMIT )
/* Don't Log yet, don't keep looking:
* already logged our limit, don't log this sid */
- sfthd_node->filtered++;
return -2;
}
else if ( sfthd_node->type == THD_TYPE_THRESHOLD )
sfthd_ip_node->tstart= curtime;
return 0; /* Log it, stop looking */
}
- sfthd_node->filtered++;
return -2; /* don't log yet */
}
else if ( sfthd_node->type == THD_TYPE_BOTH )
/* Don't Log yet, keep looking:
* only log after we reach count, which must be > '1' */
- sfthd_node->filtered++;
return -2;
}
else
{
/* don't log it, stop looking:
* log once per time interval - than block it */
- sfthd_node->filtered++;
return -2;
}
/* Log it, stop looking:
{
/* don't log it, stop looking:
* we must see at least count events 1st */
- sfthd_node->filtered++;
return -2;
}
}
}
#endif // THD_DEBUG
-
int priority;
int count;
unsigned seconds;
- uint64_t filtered;
sfip_var_t* ip_address;
};
#endif
#endif
-
#include "sfthd.h"
/* Data */
-THD_STRUCT* thd_runtime = nullptr;
+static THREAD_LOCAL THD_STRUCT* thd_runtime = nullptr;
static THREAD_LOCAL int thd_checked = 0; // per packet
static THREAD_LOCAL int thd_answer = 0; // per packet
thd_runtime = nullptr;
}
+int sfthreshold_alloc(unsigned int l_memcap, unsigned int g_memcap)
+{
+ if (thd_runtime == nullptr)
+ {
+ thd_runtime = sfthd_new(l_memcap, g_memcap);
+ if (thd_runtime == nullptr)
+ return -1;
+ }
+ return 0;
+}
+
+
int sfthreshold_create(
snort::SnortConfig* sc, ThresholdConfig* thd_config, THDX_STRUCT* thdx)
{
if (!thd_config->enabled)
return 0;
- /* Auto init - memcap must be set 1st, which is not really a problem */
- if (thd_runtime == nullptr)
- {
- thd_runtime = sfthd_new(thd_config->memcap, thd_config->memcap);
- if (thd_runtime == nullptr)
- return -1;
- }
-
/* print_thdx( thdx ); */
/* Add the object to the table - */
{
thd_checked = 0;
}
-
unsigned int, unsigned int, const snort::SfIp*, const snort::SfIp*, long curtime);
void sfthreshold_free();
-#endif
+int sfthreshold_alloc(unsigned int l_memcap, unsigned int g_memcap);
+#endif
#include "detection/tag.h"
#include "file_api/file_service.h"
#include "filters/detection_filter.h"
+#include "filters/rate_filter.h"
+#include "filters/sfrf.h"
#include "filters/sfthreshold.h"
#include "flow/ha.h"
#include "framework/data_bus.h"
// in case there are HA messages waiting, process them first
HighAvailabilityManager::process_receive();
PacketManager::thread_init();
+
+ // init filters hash tables that depend on alerts
+ sfthreshold_alloc(sc->threshold_config->memcap, sc->threshold_config->memcap);
+ SFRF_Alloc(sc->rate_filter_config->memcap);
}
void Analyzer::reinit(SnortConfig* sc)
Active::thread_term();
delete switcher;
+
+ sfthreshold_free();
+ RateFilter_Cleanup();
}
Analyzer::Analyzer(SFDAQInstance* instance, unsigned i, const char* s, uint64_t msg_cnt)
{
DataBus::publish(THREAD_ROTATE_EVENT, nullptr);
}
-
#include "detection/fp_detect.h"
#include "file_api/file_service.h"
#include "filters/rate_filter.h"
+#include "filters/sfrf.h"
#include "filters/sfthreshold.h"
#include "flow/ha.h"
#include "framework/mpse.h"
//MpseManager::print_search_engine_stats();
- sfthreshold_free(); // FIXDAQ etc.
- RateFilter_Cleanup();
-
Periodic::unregister_all();
LogMessage("%s Snort exiting\n", get_prompt());
reloading = false;
return sc;
}
-