-- ip defrag fixes
-- refactored splitter fallback
-- fix binder.use.service
+-- refactored flow state
125
-- discovered can't catch exceptions thrown from Lua to C++; need to
expire_time = 0;
}
+//static const char* fsxlt[] =
+//{
+// "setup", "inspect", "allow", "block"
+//};
+
void Flow::clear(bool freeAppData)
{
restart(freeAppData);
- flow_state = 0;
+ set_state(SETUP);
if ( ssn_client )
{
unsigned id;
};
-struct FlowState
+struct LwState
{
uint32_t session_flags;
char ignore_direction; /* flag to ignore traffic on this session */
};
-typedef enum {
+enum Stream_Event
+{
SE_REXMIT,
SE_EOF,
SE_MAX
-} Stream_Event;
+};
// this struct is organized by member size for compactness
class Flow
{
public:
+ enum FlowState
+ {
+ SETUP,
+ INSPECT,
+ BLOCK,
+ ALLOW
+ };
Flow();
Flow(PktType);
~Flow();
bool was_blocked() const
{ return (s5_state.session_flags & SSNFLAG_BLOCK) != 0; };
+ void set_state(FlowState fs)
+ { flow_state = fs; };
+
void set_client(Inspector* ins)
{
ssn_client = ins;
unsigned policy_id;
- int flow_state; // FIXIT-H wow - this is poorly encapsulated! did i do that? :(
- FlowState s5_state; // FIXIT-L rename this (s5 not appropriate)
+ FlowState flow_state;
+ LwState s5_state; // FIXIT-L rename this (s5 not appropriate)
// FIXIT-L can client and server ip and port be removed from flow?
sfip_t client_ip; // FIXIT-L family and bits should be changed to uint16_t
{
init_roles(p, flow);
Inspector* b = InspectorManager::get_binder();
+
if ( b )
b->eval(p);
+
+ if ( !flow->ssn_client || !flow->session->setup(p) )
+ flow->set_state(Flow::ALLOW);
+
++news;
}
switch ( flow->flow_state )
{
- case 1: // block
- stream.drop_packet(p);
- flow->flow_state = 1;
- break;
-
- case 2: // allow
- stream.stop_inspection(flow, p, SSN_DIR_BOTH, -1, 0);
+ case Flow::SETUP:
+ flow->set_state(Flow::ALLOW);
break;
- case 3: // setup
- if ( !flow->ssn_client || !flow->session->setup(p) )
- {
- flow->flow_state = 2;
- break;
- }
- flow->flow_state = 4;
- // now process
-
- case 4: // inspect
+ case Flow::INSPECT:
assert(flow->ssn_client);
assert(flow->ssn_server);
flow->session->process(p);
break;
+
+ case Flow::ALLOW:
+ stream.stop_inspection(flow, p, SSN_DIR_BOTH, -1, 0);
+ break;
+
+ case Flow::BLOCK:
+ stream.drop_packet(p);
+ break;
}
if ( flow->next && is_bidirectional(flow) )
// use
else if ( v.is("action") )
- work->use.action = (BindAction)(v.get_long() + 1);
+ work->use.action = (BindAction)(v.get_long());
else if ( v.is("file") )
{
flow->iface_out = p->pkth->egress_index;
Binding* pb = get_binding(flow);
- flow->flow_state = apply(flow, pb);
+ BindAction action = apply(flow, pb);
- ++bstats.verdicts[flow->flow_state - 1];
+ switch ( action )
+ {
+ case BA_BLOCK: flow->set_state(Flow::BLOCK); break;
+ case BA_ALLOW: flow->set_state(Flow::ALLOW); break;
+ case BA_INSPECT: flow->set_state(Flow::INSPECT); break;
+ }
+
+ ++bstats.verdicts[action];
++bstats.packets;
}
enum BindAction
{
- BA_BLOCK = 1,
+ BA_BLOCK,
BA_ALLOW,
BA_INSPECT
};
/* TODO: Handle bytes/response parameters */
DisableInspection(p);
- flow->flow_state = 2;
+ flow->set_state(Flow::ALLOW);
}
void Stream::resume_inspection(Flow* flow, char dir)
if (!flow)
return;
- flow->flow_state = 1;
+ flow->set_state(Flow::BLOCK);
flow->session->clear();
if (!(p->packet_flags & PKT_STATELESS))