From: Victor Julien Date: Wed, 15 Nov 2023 18:18:08 +0000 (+0100) Subject: detect/tag: reuse result of previous host lookup X-Git-Tag: suricata-8.0.0-beta1~2073 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3b826fff6840b24e54a086606a14185745b6d3a3;p=thirdparty%2Fsuricata.git detect/tag: reuse result of previous host lookup Minor optimization that could lead to a reduction in host table lookups if more than one host feature is in use. --- diff --git a/src/detect-engine-tag.c b/src/detect-engine-tag.c index aceb5f10c6..e6a4134048 100644 --- a/src/detect-engine-tag.c +++ b/src/detect-engine-tag.c @@ -493,6 +493,26 @@ static void TagHandlePacketHost(Host *host, Packet *p) } } +static Host *GetLockedSrcHost(Packet *p) +{ + if (p->host_src == NULL) { + p->host_src = HostLookupHostFromHash(&p->src); + } else { + HostLock(p->host_src); + } + return p->host_src; +} + +static Host *GetLockedDstHost(Packet *p) +{ + if (p->host_dst == NULL) { + p->host_dst = HostLookupHostFromHash(&p->dst); + } else { + HostLock(p->host_dst); + } + return p->host_dst; +} + /** * \brief Search tags for src and dst. Update entries of the tag, remove if necessary * @@ -516,20 +536,22 @@ void TagHandlePacket(DetectEngineCtx *de_ctx, TagHandlePacketFlow(p->flow, p); } - Host *src = HostLookupHostFromHash(&p->src); - if (src) { + Host *src = GetLockedSrcHost(p); + if (src != NULL) { if (TagHostHasTag(src)) { - TagHandlePacketHost(src,p); + TagHandlePacketHost(src, p); } - HostRelease(src); + HostUnlock(src); } - Host *dst = HostLookupHostFromHash(&p->dst); - if (dst) { + + Host *dst = GetLockedDstHost(p); + if (dst != NULL) { if (TagHostHasTag(dst)) { - TagHandlePacketHost(dst,p); + TagHandlePacketHost(dst, p); } - HostRelease(dst); + HostUnlock(dst); } + SCReturn; }