]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
tcp reuse: unify autofp and single/workers check
authorVictor Julien <victor@inliniac.net>
Tue, 3 Feb 2015 11:06:49 +0000 (12:06 +0100)
committerVictor Julien <victor@inliniac.net>
Wed, 18 Feb 2015 08:18:43 +0000 (09:18 +0100)
src/flow-hash.c
src/flow.c
src/flow.h
src/stream-tcp.c

index 47e7711a231004463d7af37a096a94932a12c5c8..ea3b13408125ee265f2a1ac4d538576d9c9cd10a 100644 (file)
@@ -390,7 +390,7 @@ static inline int FlowCompareICMPv4(Flow *f, const Packet *p)
     return 0;
 }
 
-int TcpSessionPacketSsnReuse(const Packet *p, void *tcp_ssn);
+int TcpSessionPacketSsnReuse(const Packet *p, const Flow *f, void *tcp_ssn);
 
 static inline int FlowCompare(Flow *f, const Packet *p)
 {
@@ -405,20 +405,13 @@ static inline int FlowCompare(Flow *f, const Packet *p)
         if (f->flags & FLOW_TCP_REUSED)
             return 0;
 
-        /* lets see if we need to consider the existing session for
-         * reuse: only considering SYN packets. */
-        int syn = (p->tcph && ((p->tcph->th_flags & TH_SYN) == TH_SYN));
-        int has_protoctx = ((f->protoctx != NULL));
-
-        /* syn on existing state, need to see if we need to 'reuse' */
-        if (unlikely(syn && has_protoctx && FlowGetPacketDirection(f,p) == TOSERVER)) {
-            if (unlikely(TcpSessionPacketSsnReuse(p, f->protoctx) == 1)) {
-                /* okay, we need to setup a new flow for this packet.
-                 * Flag the flow that it's been replaced by a new one */
-                f->flags |= FLOW_TCP_REUSED;
-                SCLogDebug("flow obsolete: TCP reuse will use a new flow");
-                return 0;
-            }
+        /* lets see if we need to consider the existing session reuse */
+        if (unlikely(TcpSessionPacketSsnReuse(p, f, f->protoctx) == 1)) {
+            /* okay, we need to setup a new flow for this packet.
+             * Flag the flow that it's been replaced by a new one */
+            f->flags |= FLOW_TCP_REUSED;
+            SCLogDebug("flow obsolete: TCP reuse will use a new flow");
+            return 0;
         }
         return 1;
     } else {
index 5ef5abeb79f5bdf5e8059376e47e517d917e382c..f6287952018498a1b919c2f0686f0ecfa00eca82 100644 (file)
@@ -178,7 +178,7 @@ void FlowSetIPOnlyFlagNoLock(Flow *f, char direction)
  *  \retval 0 to_server
  *  \retval 1 to_client
  */
-int FlowGetPacketDirection(Flow *f, const Packet *p)
+int FlowGetPacketDirection(const Flow *f, const Packet *p)
 {
     if (p->proto == IPPROTO_TCP || p->proto == IPPROTO_UDP || p->proto == IPPROTO_SCTP) {
         if (!(CMP_PORT(p->sp,p->dp))) {
index 66df3561f7e3070e9a9f35c6f5aeb86f645d5028..89f0a32b150323dfe215832c2b323bbb4a120cca 100644 (file)
@@ -444,7 +444,7 @@ static inline void FlowLockSetNoPayloadInspectionFlag(Flow *);
 static inline void FlowSetNoPayloadInspectionFlag(Flow *);
 static inline void FlowSetSessionNoApplayerInspectionFlag(Flow *);
 
-int FlowGetPacketDirection(Flow *, const Packet *);
+int FlowGetPacketDirection(const Flow *, const Packet *);
 
 void FlowCleanupAppLayer(Flow *);
 
index a24c86543fb8b18d58af024e84ea692b6870bc3c..46359a4614f752cdcd63b5db6fcdaa526da08d78 100644 (file)
@@ -4386,18 +4386,6 @@ static int StreamTcpPacketIsBadWindowUpdate(TcpSession *ssn, Packet *p)
     return 0;
 }
 
-int TcpSessionPacketSsnReuse(const Packet *p, void *tcp_ssn)
-{
-    TcpSession *ssn = tcp_ssn;
-    if (ssn->state == TCP_CLOSED) {
-        if(!(SEQ_EQ(ssn->client.isn, TCP_GET_SEQ(p))))
-        {
-            return 1;
-        }
-    }
-    return 0;
-}
-
 /* flow is and stays locked */
 int StreamTcpPacket (ThreadVars *tv, Packet *p, StreamTcpThread *stt,
                      PacketQueue *pq)
@@ -4706,9 +4694,9 @@ static int TcpSessionPacketIsStreamStarter(const Packet *p)
 /** \internal
  *  \brief Check if Flow and TCP SSN allow this flow/tuple to be reused
  *  \retval bool true yes reuse, false no keep tracking old ssn */
-int TcpSessionReuseDoneEnough(Packet *p, const TcpSession *ssn)
+int TcpSessionReuseDoneEnough(const Packet *p, const Flow *f, const TcpSession *ssn)
 {
-    if (FlowGetPacketDirection(p->flow, p) == TOSERVER) {
+    if (FlowGetPacketDirection(f, p) == TOSERVER) {
         if (ssn == NULL) {
             SCLogDebug("steam starter packet %"PRIu64", ssn %p null. No reuse.", p->pcap_cnt, ssn);
             return 0;
@@ -4749,11 +4737,22 @@ int TcpSessionReuseDoneEnough(Packet *p, const TcpSession *ssn)
         }
     }
 
-
     SCLogDebug("default: how did we get here?");
     return 0;
 }
 
+int TcpSessionPacketSsnReuse(const Packet *p, const Flow *f, const void *tcp_ssn)
+{
+    if (p->proto == IPPROTO_TCP && p->tcph != NULL) {
+        if (TcpSessionPacketIsStreamStarter(p) == 1) {
+            if (TcpSessionReuseDoneEnough(p, f, tcp_ssn) == 1) {
+                return 1;
+            }
+        }
+    }
+    return 0;
+}
+
 /** \brief Handle TCP reuse of tuple
  *
  *  Logic:
@@ -4779,7 +4778,7 @@ static void TcpSessionReuseHandle(Packet *p) {
 
     int reuse = 0;
     FLOWLOCK_RDLOCK(p->flow);
-    reuse = TcpSessionReuseDoneEnough(p, p->flow->protoctx);
+    reuse = TcpSessionReuseDoneEnough(p, p->flow, p->flow->protoctx);
     if (!reuse) {
         SCLogDebug("steam starter packet %"PRIu64", but state not "
                    "ready to be reused", p->pcap_cnt);