]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
packetpool: remove PKT_ALLOC flag
authorVictor Julien <vjulien@oisf.net>
Fri, 21 Oct 2022 18:53:17 +0000 (20:53 +0200)
committerVictor Julien <vjulien@oisf.net>
Tue, 25 Oct 2022 08:39:10 +0000 (10:39 +0200)
Use Packet::pool instead. If Packet::pool is non-NULL the packet is
owned by a pool. Otherwise it is allocated and should be freed after
use.

src/decode.c
src/decode.h
src/packet.c
src/tmqh-packetpool.c
src/tmqh-simple.c

index c6a7574be5d56669cae151371d04dbab1097f9b5..102087b89f1d450bfc218254b8a99493e25e4345 100644 (file)
@@ -179,7 +179,6 @@ Packet *PacketGetFromAlloc(void)
     memset(p, 0, SIZE_OF_PACKET);
     PacketInit(p);
     p->ReleasePacket = PacketFree;
-    p->flags |= PKT_ALLOC;
 
     SCLogDebug("allocated a new packet only using alloc...");
 
@@ -192,11 +191,11 @@ Packet *PacketGetFromAlloc(void)
  */
 void PacketFreeOrRelease(Packet *p)
 {
-    if (p->flags & PKT_ALLOC)
-        PacketFree(p);
-    else {
+    if (likely(p->pool != NULL)) {
         p->ReleasePacket = PacketPoolReturnPacket;
         PacketPoolReturnPacket(p);
+    } else {
+        PacketFree(p);
     }
 }
 
index 4abbd9904bef09f9fdaed8e85c8b01f1111725fe..84d2bdbaf949ba692b4ac20eb1361c965b89166a 100644 (file)
@@ -978,8 +978,8 @@ void DecodeUnregisterCounters(void);
 
 /** Flag to indicate that packet contents should not be inspected */
 #define PKT_NOPAYLOAD_INSPECTION BIT_U32(2)
-/** Packet was alloc'd this run, needs to be freed */
-#define PKT_ALLOC BIT_U32(3)
+// vacancy
+
 /** Packet has matched a tag */
 #define PKT_HAS_TAG BIT_U32(4)
 /** Packet payload was added to reassembled stream */
index 436d367931e0a49912f3e490a6241cc1bbdf466c..2c654879f0ed4239e2b66269cdf3e62d0059e0eb 100644 (file)
@@ -95,7 +95,7 @@ void PacketReinit(Packet *p)
     p->proto = 0;
     p->recursion_level = 0;
     PACKET_FREE_EXTDATA(p);
-    p->flags = p->flags & PKT_ALLOC;
+    p->flags = 0;
     p->flowflags = 0;
     p->pkt_src = 0;
     p->vlan_id[0] = 0;
index 169856abe5e328b1535622cbbd83e84b3b0760c9..fe0b016f16d09c87e091e15add5e74f914fcb599 100644 (file)
@@ -142,9 +142,6 @@ void PacketPoolWaitForN(int n)
  */
 static void PacketPoolStorePacket(Packet *p)
 {
-    /* Clear the PKT_ALLOC flag, since that indicates to push back
-     * onto the ring buffer. */
-    p->flags &= ~PKT_ALLOC;
     p->pool = GetThreadPacketPool();
     p->ReleasePacket = PacketPoolReturnPacket;
     PacketPoolReturnPacket(p);
@@ -361,7 +358,7 @@ void TmqhOutputPacketpool(ThreadVars *t, Packet *p)
     bool proot = false;
 
     SCEnter();
-    SCLogDebug("Packet %p, p->root %p, alloced %s", p, p->root, p->flags & PKT_ALLOC ? "true" : "false");
+    SCLogDebug("Packet %p, p->root %p, alloced %s", p, p->root, BOOL2STR(p->pool == NULL));
 
     if (IS_TUNNEL_PKT(p)) {
         SCLogDebug("Packet %p is a tunnel packet: %s",
@@ -441,7 +438,7 @@ void TmqhOutputPacketpool(ThreadVars *t, Packet *p)
 
     /* we're done with the tunnel root now as well */
     if (proot == true) {
-        SCLogDebug("getting rid of root pkt... alloc'd %s", p->root->flags & PKT_ALLOC ? "true" : "false");
+        SCLogDebug("getting rid of root pkt... alloc'd %s", BOOL2STR(p->root->pool == NULL));
 
         PacketReleaseRefs(p->root);
         p->root->ReleasePacket(p->root);
index 2cc5ffbe7df77d74dca2c623dd9f49b562f84521..47faed5702c5d0b37ff0236e7eca5b4f213e3a8a 100644 (file)
@@ -82,7 +82,7 @@ void TmqhInputSimpleShutdownHandler(ThreadVars *tv)
 
 void TmqhOutputSimple(ThreadVars *t, Packet *p)
 {
-    SCLogDebug("Packet %p, p->root %p, alloced %s", p, p->root, p->flags & PKT_ALLOC ? "true":"false");
+    SCLogDebug("Packet %p, p->root %p, alloced %s", p, p->root, BOOL2STR(p->pool == NULL));
 
     PacketQueue *q = t->outq->pq;