case Flow::FlowState::INSPECT:
assert(flow->ssn_client);
assert(flow->ssn_server);
- flow->session->process(p);
break;
case Flow::FlowState::ALLOW:
tcp_count += process(flow, p);
+ // FIXIT-M refactor to unlink_uni immediately after session
+ // is processed by inspector manager (all flows)
if ( flow->next && is_bidirectional(flow) )
tcp_cache->unlink_uni(flow);
}
sort(fp->ilist.begin(), fp->ilist.end(), PHInstance::comp);
fp->vectorize();
- if ( fp->session.num && !fp->binder )
+ // FIXIT-M checking for wizard here would avoid fatals for
+ // can't bind wizard but this exposes other issues that must
+ // be fixed first.
+ if ( fp->session.num and !fp->binder /*and fp->wizard*/ )
instantiate_binder(sc, fp);
return ok;
}
}
-// FIXIT-M split stream base processing out of it_session so that flow lookup
-// can be done first to avoid executing it_packet on disabled flows. also
-// leverage knowledge of flow creation so that reputation (possibly a new
-// it_xxx) is run just once per flow (and all non-flow packets).
+void InspectorManager::execute_control(Packet* p)
+{
+ SnortConfig* sc = SnortConfig::get_conf();
+ FrameworkPolicy* fp = get_default_inspection_policy(sc)->framework_policy;
+ ::execute(p, fp->control.vec, fp->control.num);
+}
+
+// FIXIT-M leverage knowledge of flow creation so that reputation (possibly a
+// new it_xxx) is run just once per flow (and all non-flow packets).
void InspectorManager::execute(Packet* p)
{
FrameworkPolicy* fp = get_inspection_policy()->framework_policy;
assert(fp);
- if ( !p->is_cooked() )
- ::execute(p, fp->packet.vec, fp->packet.num);
-
if ( !p->has_paf_payload() )
+ {
+ // FIXIT-L there is at most one in session; stream_base should
+ // be elevated from inspector to framework component (it is just
+ // a flow control wrapper) and use eval() instead of process()
+ // for stream_*.
::execute(p, fp->session.vec, fp->session.num);
-
+ fp = get_inspection_policy()->framework_policy;
+ }
// must check between each ::execute()
if ( p->disable_inspect )
return;
+ if ( !p->is_cooked() )
+ ::execute(p, fp->packet.vec, fp->packet.num);
+
+ if ( p->disable_inspect )
+ return;
+
if ( !p->flow )
{
::execute(p, fp->network.vec, fp->network.num);
if ( p->disable_inspect )
return;
- ::execute(p, fp->control.vec, fp->control.num);
+ execute_control(p);
}
else
{
+ if ( !p->has_paf_payload() and p->flow->flow_state == Flow::FlowState::INSPECT )
+ p->flow->session->process(p);
+
if ( !p->flow->service )
::execute(p, fp->network.vec, fp->network.num);
full_inspection(p);
if ( !p->disable_inspect and !p->flow->is_inspection_disabled() )
- ::execute(p, fp->control.vec, fp->control.num);
+ execute_control(p);
}
}
private:
static void bumble(Packet*);
static void full_inspection(Packet*);
+ static void execute_control(Packet*);
};
#endif
#include "managers/inspector_manager.h"
#include "profiler/profiler.h"
#include "protocols/packet.h"
+#include "stream/stream_splitter.h"
#include "sip_module.h"
#include "sip_utils.h"
void eval(Packet*) override;
bool get_buf(InspectionBuffer::Type, Packet*, InspectionBuffer&) override;
+ // FIXIT-M implement a sip aware splitter
+ // this will work for single segment PDUs only
+ class StreamSplitter* get_splitter(bool to_server) override
+ { return new LogSplitter(to_server); }
+
private:
SIP_PROTO_CONF* config;
};
CurseBook* get_curse_book();
Usage get_usage() const override
- { return GLOBAL; }
+ { return INSPECT; }
private:
void add_spells(MagicBook*, std::string&);
void TcpSession::flush_server(Packet* p)
{
+ if ( !tcp_init )
+ return;
+
server->set_tf_flags(TF_FORCE_FLUSH);
// If rebuilt packet, don't flush now because we'll overwrite the packet being processed.
void TcpSession::flush_client(Packet* p)
{
+ if ( !tcp_init )
+ return;
+
client->set_tf_flags(TF_FORCE_FLUSH);
// If rebuilt packet, don't flush now because we'll overwrite the packet being processed.
client->clear_tf_flags(TF_FORCE_FLUSH);
}
-void TcpSession::flush_tracker(TcpStreamTracker* tracker, Packet* p, uint32_t dir, bool final_flush)
+void TcpSession::flush_tracker(
+ TcpStreamTracker* tracker, Packet* p, uint32_t dir, bool final_flush)
{
- if( final_flush && ( !tracker->splitter || !tracker->splitter->finish(flow) ) )
+ if ( final_flush && ( !tracker->splitter || !tracker->splitter->finish(flow) ) )
return;
DebugFormat(DEBUG_STREAM_STATE, "Flushing tracker on packet from %s\n",
this->depth = depth;
}
-Variable::Variable(const std::string& name)
-{
- this->name = name;
- this->depth = 0;
-}
-
Variable::~Variable()
{
for (VarData* v : vars)
return variable;
}
+void Variable::set_value(std::string val, bool quoted)
+{
+ VarData* vd = new VarData();
+ vd->type = quoted ? VarType::STRING : VarType::VARIABLE;
+ vd->data = val;
+ vars.push_back(vd);
+}
+
// does this need a new variable?
bool Variable::add_value(std::string elem)
{
class Variable
{
public:
- Variable(const std::string& name, int depth);
- Variable(const std::string& name);
+ Variable(const std::string& name, int depth = 0);
virtual ~Variable();
inline const std::string& get_name() { return name; }
std::string get_value(DataApi*);
bool add_value(std::string);
+ void set_value(std::string, bool quoted);
void set_print_whitespace(bool w)
{ print_whitespace = w; }
errors->add_text("^^^^ unknown_syntax=" + unknown_option);
}
+void DataApi::set_variable(const std::string& name, const std::string& value, bool quoted)
+{
+ Variable* var = new Variable(name);
+ vars.push_back(var);
+ var->set_value(value, quoted);
+}
+
bool DataApi::add_variable(const std::string& name, const std::string& value)
{
for (auto v : vars)
// FILE CREATION AND ADDITIONS
// add a variable to this file
+ void set_variable(const std::string& name, const std::string& value, bool quoted);
bool add_variable(const std::string& name, const std::string& value);
// add a Snort style include file
bool add_include_file(const std::string& name);
bool Converter::empty_args = false;
bool Converter::convert_rules_mult_files = true;
bool Converter::convert_conf_mult_files = true;
+bool Converter::bind_wizard = false;
Converter::Converter()
: table_api(&top_table_api, table_delegation),
}
auto b = result->second;
- b->print_binding(false); //FIXIT-M is it desired to keep this around? it isn't for nap case
+ b->print_binding(false); // FIXIT-M is it desired to keep this around? not for nap case
// FIXIT-M as of writing, this assumes pending is only for nap rules
pb.second->set_use_file(b->get_use_file().first, Binder::IT_INSPECTION);
rc = parse_file(input);
+ if ( bind_wizard )
+ {
+ // FIXIT-H this should create wizard = { } but need wizard = default_wizard
+ //table_api.open_top_level_table("wizard");
+ //table_api.close_table();
+ data_api.set_variable("wizard", "default_wizard", false);
+
+ auto& wiz = make_binder();
+ wiz.set_use_type("wizard");
+ }
+
add_bindings();
if (rule_file.empty())
inline static std::string get_ips_pattern()
{ return ips_pattern; }
+ inline static void set_bind_wizard(bool val)
+ { bind_wizard = val; }
+
+ inline static bool get_bind_wizard()
+ { return bind_wizard; }
+
Binder& make_binder(Binder&);
Binder& make_binder();
Binder& make_pending_binder(int ips_policy_id);
static bool convert_rules_mult_files;
static bool convert_conf_mult_files;
static bool empty_args;
+ static bool bind_wizard;
DataApi data_api;
static void add_remark(const char* /*key*/, const char* val)
{ RuleApi::set_remark(val); }
+static void bind_wizard(const char* /*key*/, const char* /*val*/)
+{ Converter::set_bind_wizard(true); }
+
static void print_all(const char* /*key*/, const char* /*val*/)
{ DataApi::set_default_print(); }
{ "V", print_version, "",
"Print the current Snort2Lua version" },
+ { "bind-wizard", bind_wizard, "",
+ "Add default wizard to bindings" },
+
{ "conf-file", parse_config_file, "",
"Same as '-c'. A Snort <snort_conf> file which will be converted" },
bool ports_set = false;
auto& bind = cv.make_binder();
- bind.set_when_proto("udp");
bind.set_use_type("sip");
-
table_api.open_table("sip");
-
// parse the file configuration
while (util::get_string(data_stream, keyword, ",;"))
{