From 68a9da52ad8b3c99958ce531ed829641558b9551 Mon Sep 17 00:00:00 2001 From: Victor Julien Date: Fri, 21 Oct 2022 20:53:17 +0200 Subject: [PATCH] packetpool: remove PKT_ALLOC flag 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 | 7 +++---- src/decode.h | 4 ++-- src/packet.c | 2 +- src/tmqh-packetpool.c | 7 ++----- src/tmqh-simple.c | 2 +- 5 files changed, 9 insertions(+), 13 deletions(-) diff --git a/src/decode.c b/src/decode.c index c6a7574be5..102087b89f 100644 --- a/src/decode.c +++ b/src/decode.c @@ -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); } } diff --git a/src/decode.h b/src/decode.h index 4abbd9904b..84d2bdbaf9 100644 --- a/src/decode.h +++ b/src/decode.h @@ -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 */ diff --git a/src/packet.c b/src/packet.c index 436d367931..2c654879f0 100644 --- a/src/packet.c +++ b/src/packet.c @@ -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; diff --git a/src/tmqh-packetpool.c b/src/tmqh-packetpool.c index 169856abe5..fe0b016f16 100644 --- a/src/tmqh-packetpool.c +++ b/src/tmqh-packetpool.c @@ -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); diff --git a/src/tmqh-simple.c b/src/tmqh-simple.c index 2cc5ffbe7d..47faed5702 100644 --- a/src/tmqh-simple.c +++ b/src/tmqh-simple.c @@ -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; -- 2.47.2