-- fixed Xcode warnings
-- fixed sflsq cursor
-- additional cleanup
+-- fixed --max-threads configuration
+-- fixed PKT_RESIZED bits
115
-- remove share.h
=== Logging
-* Don't output messages for the coder. Output messages that make
- sense to the user. The function name doesn't belong in the error
- message.
+* Messages intended for the user should not look like debug messages. Eg,
+ the function name should not be included.
+
+* Most debug messages should just be deleted.
=== Types
if ( !pmd->pattern_buf || !pmd->pattern_size )
return false;
- if ( pmd->relative )
- return false;
-
if ( cat <= CAT_SET_OTHER )
return false;
void Flow::clear(bool freeAppData)
{
- assert(flow_state < 3);
-
if ( freeAppData )
free_application_data();
Inspector* gadget;
const char* service;
- int flow_state;
+ int flow_state; // FIXIT-H wow - this is poorly encapsulated! did i do that? :(
FlowState s5_state; // FIXIT-L rename this (s5 not appropriate)
sfip_t client_ip; // FIXIT-L family and bits should be changed to uint16_t
// packet handler stuff
//-------------------------------------------------------------------------
-SO_PUBLIC unsigned Inspector::max_slots = 1;
SO_PUBLIC unsigned THREAD_LOCAL Inspector::slot = 0;
+unsigned Inspector::max_slots = 1;
SO_PUBLIC Inspector::Inspector()
{
- assert(slot < max_slots);
- ref_count = new unsigned[max_slots];
+ unsigned max = get_instance_max();
+ assert(slot < max);
+ ref_count = new unsigned[max];
- for ( unsigned i = 0; i < max_slots; ++i )
+ for ( unsigned i = 0; i < max; ++i )
ref_count[i] = 0;
}
{
unsigned total = 0;
- for (unsigned i = 0; i < max_slots; ++i )
+ for (unsigned i = 0; i < get_instance_max(); ++i )
total += ref_count[i];
assert(!total);
SO_PUBLIC bool Inspector::is_inactive()
{
- for (unsigned i = 0; i < max_slots; ++i )
+ for (unsigned i = 0; i < get_instance_max(); ++i )
if ( ref_count[i] )
return false;
{ name = s; };
CursorActionType get_cursor_type() const
- { return CAT_SET_OTHER; };
+ { return CAT_SET_HEADER; };
int eval(Cursor&, Packet*);
socket_init();
TimeStart();
- max_pigs = snort_conf->max_threads;
+ max_pigs = get_instance_max();
assert(max_pigs > 0);
pigs = new Pig[max_pigs];
}
else
{
+ Packet* p = &s_packet;
if ( s_packet.packet_flags & PKT_MODIFIED )
{
// this packet was normalized and/or has replacements
PacketManager::encode_update(&s_packet);
verdict = DAQ_VERDICT_REPLACE;
}
- else if ( s_packet.packet_flags & PKT_RESIZED )
+ else if ( p->packet_flags & PKT_RESIZED )
{
+ printf("packet flags = 0x%X\n", p->packet_flags);
// we never increase, only trim, but
// daq doesn't support resizing wire packet
if ( !DAQ_Inject(s_packet.pkth, 0, s_packet.pkt, s_packet.pkth->pktlen) )
#include "config.h"
#endif
-#include <thread>
-
#include "snort_types.h"
#include "detection/treenodes.h"
#include "events/event_queue.h"
sc->max_metadata_services = DEFAULT_MAX_METADATA_SERVICES;
sc->mpls_stack_depth = DEFAULT_LABELCHAIN_LENGTH;
- sc->max_threads = 1;
InspectorManager::new_config(sc);
sc->var_list = NULL;
- sc->state = (SnortState*)SnortAlloc(
- sizeof(SnortState)*sc->max_threads);
+ sc->state = (SnortState*)SnortAlloc(sizeof(SnortState)*get_instance_max());
sc->policy_map = new PolicyMap();
if (cmd_line->run_flags & RUN_FLAG__PROCESS_ALL_EVENTS)
config_file->event_queue_config->process_all_events = 1;
- if ( cmd_line->max_threads )
- config_file->max_threads = cmd_line->max_threads;
-
- if ( config_file->max_threads <= 0 )
- config_file->max_threads = std::thread::hardware_concurrency();
-
if ( cmd_line->remote_control )
config_file->remote_control = cmd_line->remote_control;
free(config_file->state);
config_file->state = (SnortState*)SnortAlloc(
- sizeof(SnortState)*config_file->max_threads);
+ sizeof(SnortState)*get_instance_max());
return config_file;
}
struct VarNode* var_list;
- int max_threads;
unsigned remote_control;
SnortState* state;
ConfigShowYear(sc, v.get_string());
else if ( v.is("-z") || v.is("--max-packet-threads") )
- {
- sc->max_threads = v.get_long();
- if ( !sc->max_threads )
- sc->max_threads = -1; // max
- }
+ set_instance_max(v.get_long());
+
else if ( v.is("--alert-before-pass") )
ConfigAlertBeforePass(sc, v.get_string());
#include "thread.h"
#include <sys/stat.h>
+#include <thread>
#include "snort.h"
//-------------------------------------------------------------------------
// works for now.
//-------------------------------------------------------------------------
+static unsigned instance_max = 1;
static THREAD_LOCAL unsigned instance_id = 0;
void set_instance_id(unsigned id)
instance_id = id;
}
+void set_instance_max(unsigned max)
+{
+ if ( max )
+ instance_max = max;
+ else
+ instance_max = std::thread::hardware_concurrency();
+}
+
unsigned get_instance_id()
{
return instance_id;
unsigned get_instance_max()
{
- return snort_conf->max_threads;
+ return instance_max;
}
//-------------------------------------------------------------------------
//#define THREAD_LOCAL thread_local
void set_instance_id(unsigned);
+void set_instance_max(unsigned);
+
unsigned get_instance_id();
unsigned get_instance_max();
+
const char* get_instance_file(std::string&, const char* name);
#endif
PHVector generic;
PHVector service;
+ Inspector* binder;
+ Inspector* wizard;
+
void vectorize();
};
break;
case IT_BINDER:
+ binder = p->handler;
+ break;
+
case IT_WIZARD:
+ wizard = p->handler;
+ break;
+
case IT_MAX:
break;
}
void InspectorManager::new_policy (InspectionPolicy* pi)
{
pi->framework_policy = new FrameworkPolicy;
+
+ pi->framework_policy->binder = nullptr;
+ pi->framework_policy->wizard = nullptr;
}
void InspectorManager::delete_policy (InspectionPolicy* pi)
delete p;
return NULL;
}
+
fp->ilist.push_back(p);
return p;
}
p->handler->meta(type, data);
}
+Inspector* InspectorManager::get_binder()
+{
+ InspectionPolicy* pi = get_inspection_policy();
+
+ if ( !pi || !pi->framework_policy )
+ return nullptr;
+
+ return pi->framework_policy->binder;
+}
+
+Inspector* InspectorManager::get_wizard()
+{
+ InspectionPolicy* pi = get_inspection_policy();
+
+ if ( !pi || !pi->framework_policy )
+ return nullptr;
+
+ return pi->framework_policy->wizard;
+}
+
Inspector* InspectorManager::get_inspector(const char* key)
{
InspectionPolicy* pi = get_inspection_policy();
{
Inspector::slot = get_instance_id();
- InspectionPolicy* pi = get_inspection_policy();
+ for ( auto* p : sc->framework_config->clist )
+ if ( p->api.tinit )
+ p->api.tinit();
- if ( !pi || !pi->framework_policy )
- return;
+ InspectionPolicy* pi = get_inspection_policy();
- for ( auto* p : pi->framework_policy->ilist )
- p->handler->tinit();
+ if ( pi && pi->framework_policy )
+ {
+ for ( auto* p : pi->framework_policy->ilist )
+ p->handler->tinit();
+ }
}
void InspectorManager::thread_term(SnortConfig* sc)
{
InspectionPolicy* pi = get_inspection_policy();
- if ( !pi || !pi->framework_policy )
- return;
-
- for ( auto* p : pi->framework_policy->ilist )
- p->handler->tterm();
+ if ( pi && pi->framework_policy )
+ {
+ for ( auto* p : pi->framework_policy->ilist )
+ p->handler->tterm();
+ }
for ( auto* p : sc->framework_config->clist )
if ( p->api.tterm )
bool InspectorManager::configure(SnortConfig *sc)
{
- Inspector::max_slots = sc->max_threads;
sort(s_handlers.begin(), s_handlers.end(), PHGlobal::comp);
FrameworkPolicy* fp = sc->policy_map->inspection_policy[0]->framework_policy;
if ( !flow->service )
return;
- Inspector* ins = get_inspector("binder");
+ Inspector* ins = get_binder();
if ( ins )
ins->exec(0, flow);
static void free_inspector(Inspector*);
static InspectSsnFunc get_session(const char* key);
+ static Inspector* get_binder();
+ static Inspector* get_wizard();
+
static bool configure(SnortConfig*);
static void print_config(SnortConfig*);
if ( !pb->type.size() || pb->type == "wizard" )
{
- ins = InspectorManager::get_inspector("wizard");
+ ins = InspectorManager::get_wizard();
flow->set_clouseau(ins);
}
else
#define PKT_PSEUDO 0x00080000 /* is a pseudo packet */
#define PKT_MODIFIED 0x00100000 /* packet had normalizations, etc. */
-#define PKT_RESIZED 0x00180000 /* packet has new size; must set modified too */
+#define PKT_RESIZED 0x00300000 /* packet has new size; must set modified too */
// neither of these flags will be set for (full) retransmissions or non-data segments
// a partial overlap results in out of sequence condition
// out of sequence condition is sticky
-#define PKT_STREAM_ORDER_OK 0x00200000 /* this segment is in order, w/o gaps */
-#define PKT_STREAM_ORDER_BAD 0x00400000 /* this stream had at least one gap */
+#define PKT_STREAM_ORDER_OK 0x00400000 /* this segment is in order, w/o gaps */
+#define PKT_STREAM_ORDER_BAD 0x00800000 /* this stream had at least one gap */
-#define PKT_FILE_EVENT_SET 0x00800000
+#define PKT_FILE_EVENT_SET 0x01000000
#define PKT_UNUSED_FLAGS 0xff000000
// 0x40000000 are available
void StreamBase::tinit()
{
assert(!flow_con);
- Inspector* pi = InspectorManager::get_inspector("binder");
+ Inspector* pi = InspectorManager::get_binder();
flow_con = new FlowControl(pi);
InspectSsnFunc f;