]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
tcp: use bool wherever possible
authorShivani Bhardwaj <shivani@oisf.net>
Tue, 21 May 2024 11:50:19 +0000 (17:20 +0530)
committerVictor Julien <victor@inliniac.net>
Wed, 22 May 2024 04:45:11 +0000 (06:45 +0200)
src/flow-hash.c
src/stream-tcp.c
src/stream-tcp.h

index 02f084374258f3f5b2217bc8f792c0068bea9070..ddab01cd5b697f10f5dffe02711688f24d363edc 100644 (file)
@@ -915,7 +915,7 @@ Flow *FlowGetFlowFromHash(ThreadVars *tv, FlowLookupStruct *fls, Packet *p, Flow
         } else if (FlowCompare(f, p) != 0) {
             FLOWLOCK_WRLOCK(f);
             /* found a matching flow that is not timed out */
-            if (unlikely(TcpSessionPacketSsnReuse(p, f, f->protoctx) == 1)) {
+            if (unlikely(TcpSessionPacketSsnReuse(p, f, f->protoctx))) {
                 Flow *new_f = TcpReuseReplace(tv, fls, fb, f, hash, p);
                 if (prev_f == NULL) /* if we have no prev it means new_f is now our prev */
                     prev_f = new_f;
index 641a59cfaca48efdc23fbc35c696349f443582f4..f89b565381f1490b09127daf5c2333f859e5eba4 100644 (file)
@@ -5761,7 +5761,7 @@ 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 */
-static int TcpSessionReuseDoneEnoughSyn(const Packet *p, const Flow *f, const TcpSession *ssn)
+static bool TcpSessionReuseDoneEnoughSyn(const Packet *p, const Flow *f, const TcpSession *ssn)
 {
     const TCPHdr *tcph = PacketGetTCP(p);
     if (FlowGetPacketDirection(f, p) == TOSERVER) {
@@ -5769,96 +5769,96 @@ static int TcpSessionReuseDoneEnoughSyn(const Packet *p, const Flow *f, const Tc
             /* most likely a flow that was picked up after the 3whs, or a flow that
              * does not have a session due to memcap issues. */
             SCLogDebug("steam starter packet %" PRIu64 ", ssn %p null. Reuse.", p->pcap_cnt, ssn);
-            return 1;
+            return true;
         }
         if (ssn->flags & STREAMTCP_FLAG_TFO_DATA_IGNORED) {
             SCLogDebug("steam starter packet %" PRIu64
                        ", ssn %p. STREAMTCP_FLAG_TFO_DATA_IGNORED set. Reuse.",
                     p->pcap_cnt, ssn);
-            return 1;
+            return true;
         }
         if (SEQ_EQ(ssn->client.isn, TCP_GET_RAW_SEQ(tcph))) {
             SCLogDebug("steam starter packet %"PRIu64", ssn %p. Packet SEQ == Stream ISN. Retransmission. Don't reuse.", p->pcap_cnt, ssn);
-            return 0;
+            return false;
         }
         if (ssn->state >= TCP_LAST_ACK) {
             SCLogDebug("steam starter packet %"PRIu64", ssn %p state >= TCP_LAST_ACK (%u). Reuse.", p->pcap_cnt, ssn, ssn->state);
-            return 1;
+            return true;
         } else if (ssn->state == TCP_NONE) {
             SCLogDebug("steam starter packet %"PRIu64", ssn %p state == TCP_NONE (%u). Reuse.", p->pcap_cnt, ssn, ssn->state);
-            return 1;
+            return true;
         } else { // < TCP_LAST_ACK
             SCLogDebug("steam starter packet %"PRIu64", ssn %p state < TCP_LAST_ACK (%u). Don't reuse.", p->pcap_cnt, ssn, ssn->state);
-            return 0;
+            return false;
         }
 
     } else {
         if (ssn == NULL) {
             SCLogDebug("steam starter packet %"PRIu64", ssn %p null. Reuse.", p->pcap_cnt, ssn);
-            return 1;
+            return true;
         }
         if (ssn->state >= TCP_LAST_ACK) {
             SCLogDebug("steam starter packet %"PRIu64", ssn %p state >= TCP_LAST_ACK (%u). Reuse.", p->pcap_cnt, ssn, ssn->state);
-            return 1;
+            return true;
         } else if (ssn->state == TCP_NONE) {
             SCLogDebug("steam starter packet %"PRIu64", ssn %p state == TCP_NONE (%u). Reuse.", p->pcap_cnt, ssn, ssn->state);
-            return 1;
+            return true;
         } else { // < TCP_LAST_ACK
             SCLogDebug("steam starter packet %"PRIu64", ssn %p state < TCP_LAST_ACK (%u). Don't reuse.", p->pcap_cnt, ssn, ssn->state);
-            return 0;
+            return false;
         }
     }
 
     SCLogDebug("default: how did we get here?");
-    return 0;
+    return false;
 }
 
 /** \internal
  *  \brief check if ssn is done enough for reuse by syn/ack
  *  \note should only be called if midstream is enabled
  */
-static int TcpSessionReuseDoneEnoughSynAck(const Packet *p, const Flow *f, const TcpSession *ssn)
+static bool TcpSessionReuseDoneEnoughSynAck(const Packet *p, const Flow *f, const TcpSession *ssn)
 {
     const TCPHdr *tcph = PacketGetTCP(p);
     if (FlowGetPacketDirection(f, p) == TOCLIENT) {
         if (ssn == NULL) {
             SCLogDebug("steam starter packet %"PRIu64", ssn %p null. No reuse.", p->pcap_cnt, ssn);
-            return 0;
+            return false;
         }
         if (SEQ_EQ(ssn->server.isn, TCP_GET_RAW_SEQ(tcph))) {
             SCLogDebug("steam starter packet %"PRIu64", ssn %p. Packet SEQ == Stream ISN. Retransmission. Don't reuse.", p->pcap_cnt, ssn);
-            return 0;
+            return false;
         }
         if (ssn->state >= TCP_LAST_ACK) {
             SCLogDebug("steam starter packet %"PRIu64", ssn %p state >= TCP_LAST_ACK (%u). Reuse.", p->pcap_cnt, ssn, ssn->state);
-            return 1;
+            return true;
         } else if (ssn->state == TCP_NONE) {
             SCLogDebug("steam starter packet %"PRIu64", ssn %p state == TCP_NONE (%u). Reuse.", p->pcap_cnt, ssn, ssn->state);
-            return 1;
+            return true;
         } else { // < TCP_LAST_ACK
             SCLogDebug("steam starter packet %"PRIu64", ssn %p state < TCP_LAST_ACK (%u). Don't reuse.", p->pcap_cnt, ssn, ssn->state);
-            return 0;
+            return false;
         }
 
     } else {
         if (ssn == NULL) {
             SCLogDebug("steam starter packet %"PRIu64", ssn %p null. Reuse.", p->pcap_cnt, ssn);
-            return 1;
+            return true;
         }
         if (ssn->state >= TCP_LAST_ACK) {
             SCLogDebug("steam starter packet %"PRIu64", ssn %p state >= TCP_LAST_ACK (%u). Reuse.", p->pcap_cnt, ssn, ssn->state);
-            return 1;
+            return true;
         } else if (ssn->state == TCP_NONE) {
             SCLogDebug("steam starter packet %"PRIu64", ssn %p state == TCP_NONE (%u). Reuse.", p->pcap_cnt, ssn, ssn->state);
-            return 1;
+            return true;
         } else { // < TCP_LAST_ACK
             SCLogDebug("steam starter packet %"PRIu64", ssn %p state < TCP_LAST_ACK (%u). Don't reuse.", p->pcap_cnt, ssn, ssn->state);
-            return 0;
+            return false;
         }
     }
 
     SCLogDebug("default: how did we get here?");
-    return 0;
+    return false;
 }
 
 /** \brief Check if SSN is done enough for reuse
@@ -5866,7 +5866,7 @@ static int TcpSessionReuseDoneEnoughSynAck(const Packet *p, const Flow *f, const
  *  Reuse means a new TCP session reuses the tuple (flow in suri)
  *
  *  \retval bool true if ssn can be reused, false if not */
-static int TcpSessionReuseDoneEnough(const Packet *p, const Flow *f, const TcpSession *ssn)
+static bool TcpSessionReuseDoneEnough(const Packet *p, const Flow *f, const TcpSession *ssn)
 {
     const TCPHdr *tcph = PacketGetTCP(p);
     if ((tcph->th_flags & (TH_SYN | TH_ACK)) == TH_SYN) {
@@ -5879,19 +5879,19 @@ static int TcpSessionReuseDoneEnough(const Packet *p, const Flow *f, const TcpSe
         }
     }
 
-    return 0;
+    return false;
 }
 
-int TcpSessionPacketSsnReuse(const Packet *p, const Flow *f, const void *tcp_ssn)
+bool TcpSessionPacketSsnReuse(const Packet *p, const Flow *f, const void *tcp_ssn)
 {
     if (p->proto == IPPROTO_TCP && PacketIsTCP(p)) {
         if (TcpSessionPacketIsStreamStarter(p) == 1) {
             if (TcpSessionReuseDoneEnough(p, f, tcp_ssn) == 1) {
-                return 1;
+                return true;
             }
         }
     }
-    return 0;
+    return false;
 }
 
 TmEcode StreamTcp (ThreadVars *tv, Packet *p, void *data, PacketQueueNoLock *pq)
index 065db5f6e837f547183413914acb9244ea9c8a99..006cbb5aa16e9275008c2ae5711c0a0ea98d907d 100644 (file)
@@ -197,7 +197,7 @@ void StreamTcpStreamCleanup(TcpStream *stream);
 int StreamTcpBypassEnabled(void);
 bool StreamTcpInlineMode(void);
 
-int TcpSessionPacketSsnReuse(const Packet *p, const Flow *f, const void *tcp_ssn);
+bool TcpSessionPacketSsnReuse(const Packet *p, const Flow *f, const void *tcp_ssn);
 
 void StreamTcpUpdateAppLayerProgress(TcpSession *ssn, char direction,
         const uint32_t progress);