+118
+-- fixed bind action
+
117
-- added --stdin-rules
-- added #begin / #end comments for rules
void set_ttl(Packet*, bool client);
- bool was_blocked()
+ void block()
+ { s5_state.session_flags |= SSNFLAG_BLOCK; };
+
+ bool was_blocked() const
{ return (s5_state.session_flags & SSNFLAG_BLOCK) != 0; };
void set_client(Inspector* ins)
switch ( flow->flow_state )
{
case 1: // block
+ // FIXIT-H this clears flow state!
stream.drop_packet(p);
break;
#include "binder.h"
#include "protocols/packet.h"
-THREAD_LOCAL SimpleStats bstats;
+THREAD_LOCAL BindStats bstats;
+
+static const char* bind_pegs[] =
+{
+ "packets",
+ "blocks",
+ "allows",
+ "inspects",
+ nullptr
+};
//-------------------------------------------------------------------------
// binder module
static const Parameter binder_use_params[] =
{
- { "action", Parameter::PT_ENUM, "inspect | allow | block", "inspect",
+ { "action", Parameter::PT_ENUM, "block | allow | inspect", "inspect",
"what to do with matching traffic" },
{ "file", Parameter::PT_STRING, nullptr, nullptr,
// use
else if ( v.is("action") )
- work->action = (BindAction)v.get_long();
+ work->action = (BindAction)(v.get_long() + 1);
else if ( v.is("file") )
work->file = v.get_string();
}
const char** BinderModule::get_pegs() const
-{ return simple_pegs; }
+{ return bind_pegs; }
PegCount* BinderModule::get_counts() const
{ return (PegCount*)&bstats; }
#include "framework/module.h"
#include "main/thread.h"
-extern THREAD_LOCAL SimpleStats bstats;
+struct BindStats
+{
+ PegCount packets;
+ PegCount verdicts[3];
+};
+
+extern THREAD_LOCAL BindStats bstats;
extern THREAD_LOCAL ProfileStats bindPerfStats;
struct Binding;
{ bindings.push_back(b); };
private:
- int check_rules(Flow*, Packet*);
+ Binding* get_binding(Flow*, Packet*);
+ BindAction apply(Flow*, Binding*);
void init_flow(Flow*);
private:
void Binder::eval(Packet* p)
{
Flow* flow = p->flow;
- flow->flow_state = check_rules(flow, p);
- ++bstats.total_packets;
+
+ Binding* pb = get_binding(flow, p);
+ flow->flow_state = apply(flow, pb);
+
+ ++bstats.verdicts[flow->flow_state - 1];
+ ++bstats.packets;
}
// FIXIT-H implement inspector lookup from policy / bindings
// FIXIT-H bind services - this is a temporary hack that just looks at ports,
// need to examine all key fields for matching. ultimately need a routing
// table, scapegoat tree, etc.
-int Binder::check_rules(Flow* flow, Packet* p)
+Binding* Binder::get_binding(Flow* flow, Packet* p)
{
Binding* pb;
unsigned i, sz = bindings.size();
if ( pb->ports.test(port) )
break;
}
-
+
+ // absent a specific rule, we must choose a course of action
+ // so we act as if binder wasn't configured at all
if ( i == sz )
- return BA_ALLOW; // default action FIXIT-H make configurable
+ return nullptr;
+
+ return pb;
+}
+
+BindAction Binder::apply(Flow* flow, Binding* pb)
+{
+ if ( !pb )
+ return BA_ALLOW;
if ( pb->action != BA_INSPECT )
+ {
+ if ( pb->action == BA_BLOCK )
+ stream.drop_traffic(flow, SSN_DIR_BOTH);
return pb->action;
+ }
init_flow(flow);
Inspector* ins;
return (p->packet_flags & (PKT_FROM_SERVER|PKT_FROM_CLIENT));
}
-void Stream::drop_traffic(
- Packet*, Flow* flow, char dir)
+void Stream::drop_traffic(Flow* flow, char dir)
{
if (!flow)
return;
flow->session->clear();
if (!(p->packet_flags & PKT_STATELESS))
- drop_traffic(p, flow, SSN_DIR_BOTH);
+ drop_traffic(flow, SSN_DIR_BOTH);
}
uint32_t Stream::set_session_flags(Flow* flow, uint32_t flags)
/* Drop traffic arriving on session.
*/
- static void drop_traffic(Packet*, Flow*, char dir);
+ static void drop_traffic(Flow*, char dir);
/* Drop retransmitted packet arriving on session.
*/