From d2f7e89d11f5c72c09bae4ea342520fe82fae103 Mon Sep 17 00:00:00 2001 From: Victor Julien Date: Mon, 4 Dec 2023 10:46:34 +0100 Subject: [PATCH] decode/tunnel: split verdict logic Allows caller to take their own lock. --- src/decode.h | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/src/decode.h b/src/decode.h index 34ae84aa8b55..1388e24efb24 100644 --- a/src/decode.h +++ b/src/decode.h @@ -1123,6 +1123,26 @@ static inline bool PacketIsNotTunnel(const Packet *p) return (p->ttype == PacketTunnelNone); } +static inline bool VerdictTunnelPacketInternal(const Packet *p) +{ + const uint16_t outstanding = TUNNEL_PKT_TPR(p) - TUNNEL_PKT_RTV(p); + SCLogDebug("tunnel: outstanding %u", outstanding); + + /* if there are packets outstanding, we won't verdict this one */ + if (PacketIsTunnelRoot(p) && !PacketTunnelIsVerdicted(p) && !outstanding) { + SCLogDebug("root %p: verdict", p); + return true; + + } else if (PacketIsTunnelChild(p) && outstanding == 1 && p->root && + PacketTunnelIsVerdicted(p->root)) { + SCLogDebug("tunnel %p: verdict", p); + return true; + + } else { + return false; + } +} + /** \brief return true if *this* packet needs to trigger a verdict. * * If we have the root packet, and we have none outstanding, @@ -1135,23 +1155,10 @@ static inline bool PacketIsNotTunnel(const Packet *p) */ static inline bool VerdictTunnelPacket(Packet *p) { - bool verdict = true; + bool verdict; SCSpinlock *lock = p->root ? &p->root->persistent.tunnel_lock : &p->persistent.tunnel_lock; SCSpinLock(lock); - const uint16_t outstanding = TUNNEL_PKT_TPR(p) - TUNNEL_PKT_RTV(p); - SCLogDebug("tunnel: outstanding %u", outstanding); - - /* if there are packets outstanding, we won't verdict this one */ - if (PacketIsTunnelRoot(p) && !PacketTunnelIsVerdicted(p) && !outstanding) { - // verdict - SCLogDebug("root %p: verdict", p); - } else if (PacketIsTunnelChild(p) && outstanding == 1 && p->root && - PacketTunnelIsVerdicted(p->root)) { - // verdict - SCLogDebug("tunnel %p: verdict", p); - } else { - verdict = false; - } + verdict = VerdictTunnelPacketInternal(p); SCSpinUnlock(lock); return verdict; }