* \retval 1 has state
* \retval 0 has no state
*/
-int DeStateFlowHasState(DetectEngineCtx *de_ctx, Flow *f, uint8_t flags, uint16_t alversion) {
+int DeStateFlowHasState(Flow *f, uint8_t flags, uint16_t alversion) {
SCEnter();
int r = 0;
* the last SigMatch that didn't match */
if (f->de_state == NULL) {
f->de_state = DetectEngineStateAlloc();
- f->de_state->de_ctx_id = de_ctx->id;
- } else {
- if (f->de_state->de_ctx_id != de_ctx->id) {
- DetectEngineStateReset(f->de_state);
- f->de_state = DetectEngineStateAlloc();
- f->de_state->de_ctx_id = de_ctx->id;
- }
}
-
if (f->de_state != NULL) {
/* \todo shift to an array to transfer these match values*/
DeStateSignatureAppend(f->de_state, s, sm, match_flags);
if (f->de_state == NULL || f->de_state->cnt == 0)
goto end;
- if (f->de_state->de_ctx_id != de_ctx->id) {
- DetectEngineStateReset(f->de_state);
- f->de_state = NULL;
- SCMutexUnlock(&f->de_state_m);
- SCReturnInt(0);
- }
-
DeStateResetFileInspection(f, alproto, alstate);
/* loop through the stores */
* cannot match in to client direction. */
uint16_t toserver_filestore_cnt;/**< number of sigs with filestore that
* cannot match in to server direction. */
-
- /* the de_ctx id that the state belongs to */
- uint32_t de_ctx_id;
-
uint16_t flags;
} DetectEngineState;
DetectEngineState *DetectEngineStateAlloc(void);
void DetectEngineStateFree(DetectEngineState *);
-int DeStateFlowHasState(DetectEngineCtx *, Flow *, uint8_t, uint16_t);
+int DeStateFlowHasState(Flow *, uint8_t, uint16_t);
int DeStateDetectStartDetection(ThreadVars *, DetectEngineCtx *,
DetectEngineThreadCtx *, Signature *, Flow *, uint8_t, void *,
Signature *s = NULL;
SigMatch *sm = NULL;
uint16_t alversion = 0;
+ int reset_de_state = 0;
SCEnter();
FLOWLOCK_WRLOCK(p->flow);
{
+ /* live ruleswap check for flow updates */
+ if (p->flow->de_ctx_id == 0) {
+ /* first time this flow is inspected, set id */
+ p->flow->de_ctx_id = de_ctx->id;
+ } else if (p->flow->de_ctx_id != de_ctx->id) {
+ /* first time we inspect flow with this de_ctx, reset */
+ p->flow->flags &= ~FLOW_SGH_TOSERVER;
+ p->flow->flags &= ~FLOW_SGH_TOCLIENT;
+ p->flow->sgh_toserver = NULL;
+ p->flow->sgh_toclient = NULL;
+ reset_de_state = 1;
+
+ p->flow->de_ctx_id = de_ctx->id;
+ }
+
/* set the iponly stuff */
if (p->flow->flags & FLOW_TOCLIENT_IPONLY_SET)
p->flowflags |= FLOW_PKT_TOCLIENT_IPONLY_SET;
if (IP_GET_IPPROTO(p) == p->flow->proto) { /* filter out icmp */
PACKET_PROFILING_DETECT_START(p, PROF_DETECT_GETSGH);
if (p->flowflags & FLOW_PKT_TOSERVER && p->flow->flags & FLOW_SGH_TOSERVER) {
- if (p->flow->sgh_toserver_de_ctx_id != de_ctx->id) {
- p->flow->flags &= ~FLOW_SGH_TOSERVER;
- } else {
- det_ctx->sgh = p->flow->sgh_toserver;
- sms_runflags |= SMS_USE_FLOW_SGH;
- }
+ det_ctx->sgh = p->flow->sgh_toserver;
+ sms_runflags |= SMS_USE_FLOW_SGH;
} else if (p->flowflags & FLOW_PKT_TOCLIENT && p->flow->flags & FLOW_SGH_TOCLIENT) {
- if (p->flow->sgh_toclient_de_ctx_id != de_ctx->id) {
- p->flow->flags &= ~FLOW_SGH_TOCLIENT;
- } else {
- det_ctx->sgh = p->flow->sgh_toclient;
- sms_runflags |= SMS_USE_FLOW_SGH;
- }
+ det_ctx->sgh = p->flow->sgh_toclient;
+ sms_runflags |= SMS_USE_FLOW_SGH;
}
PACKET_PROFILING_DETECT_END(p, PROF_DETECT_GETSGH);
}
SCLogDebug("p->flowflags 0x%02x", p->flowflags);
+ /* reset because of ruleswap */
+ if (reset_de_state) {
+ SCMutexLock(&p->flow->de_state_m);
+ DetectEngineStateReset(p->flow->de_state);
+ SCMutexUnlock(&p->flow->de_state_m);
/* see if we need to increment the inspect_id and reset the de_state */
- if (alstate != NULL && alproto == ALPROTO_HTTP) {
+ } else if (alstate != NULL && alproto == ALPROTO_HTTP) {
PACKET_PROFILING_DETECT_START(p, PROF_DETECT_STATEFUL);
SCLogDebug("getting de_state_status");
int de_state_status = DeStateUpdateInspectTransactionId(p->flow,
memset(det_ctx->de_state_sig_array, 0x00, det_ctx->de_state_sig_array_len);
/* if applicable, continue stateful detection */
- int state = DeStateFlowHasState(de_ctx, p->flow, flags, alversion);
+ int state = DeStateFlowHasState(p->flow, flags, alversion);
if (state == 1) {
DeStateDetectContinueDetection(th_v, de_ctx, det_ctx, p->flow,
flags, alstate, alproto, alversion);
if (p->flowflags & FLOW_PKT_TOSERVER && !(p->flow->flags & FLOW_SGH_TOSERVER)) {
/* first time we see this toserver sgh, store it */
p->flow->sgh_toserver = det_ctx->sgh;
- p->flow->sgh_toserver_de_ctx_id = de_ctx->id;
p->flow->flags |= FLOW_SGH_TOSERVER;
/* see if this sgh requires us to consider file storing */
}
} else if (p->flowflags & FLOW_PKT_TOCLIENT && !(p->flow->flags & FLOW_SGH_TOCLIENT)) {
p->flow->sgh_toclient = det_ctx->sgh;
- p->flow->sgh_toclient_de_ctx_id = de_ctx->id;
p->flow->flags |= FLOW_SGH_TOCLIENT;
if (p->flow->sgh_toclient == NULL || p->flow->sgh_toclient->filestore_cnt == 0) {