From: Victor Julien Date: Fri, 5 Apr 2024 11:25:31 +0000 (+0200) Subject: decode: refactor L3 checkum handling X-Git-Tag: suricata-8.0.0-beta1~1386 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c9ef85e620ea84c60545b3a300cb8e5a092240aa;p=thirdparty%2Fsuricata.git decode: refactor L3 checkum handling Use a flag to indicate a calculated csum is available. Allows packet reset to just use memset. --- diff --git a/src/decode.h b/src/decode.h index 417600b450..637cb28d40 100644 --- a/src/decode.h +++ b/src/decode.h @@ -421,7 +421,8 @@ enum PacketL3Types { struct PacketL3 { enum PacketL3Types type; /* Checksum for IP packets. */ - int32_t comp_csum; + bool csum_set; + uint16_t csum; union Hdrs { IPV4Hdr *ip4h; IPV6Hdr *ip6h; diff --git a/src/detect-csum.c b/src/detect-csum.c index 19c2e150b0..76f6902e5a 100644 --- a/src/detect-csum.c +++ b/src/detect-csum.c @@ -246,14 +246,15 @@ static int DetectIPV4CsumMatch(DetectEngineThreadCtx *det_ctx, return cd->valid; } - if (p->l3.comp_csum == -1) { + if (!p->l3.csum_set) { const IPV4Hdr *ip4h = PacketGetIPv4(p); - p->l3.comp_csum = IPV4Checksum((uint16_t *)ip4h, IPV4_GET_RAW_HLEN(ip4h), ip4h->ip_csum); + p->l3.csum = IPV4Checksum((uint16_t *)ip4h, IPV4_GET_RAW_HLEN(ip4h), ip4h->ip_csum); + p->l3.csum_set = true; } - if (p->l3.comp_csum == 0 && cd->valid == 1) + if (p->l3.csum == 0 && cd->valid == 1) return 1; - else if (p->l3.comp_csum != 0 && cd->valid == 0) + else if (p->l3.csum != 0 && cd->valid == 0) return 1; else return 0; diff --git a/src/packet.c b/src/packet.c index 57fb6be22f..9a9652404c 100644 --- a/src/packet.c +++ b/src/packet.c @@ -64,7 +64,6 @@ void PacketInit(Packet *p) SCSpinInit(&p->persistent.tunnel_lock, 0); p->alerts.alerts = PacketAlertCreate(); PACKET_RESET_CHECKSUMS(p); - p->l3.comp_csum = -1; p->livedev = NULL; } @@ -116,7 +115,6 @@ void PacketReinit(Packet *p) } p->ethh = NULL; PacketClearL3(p); - p->l3.comp_csum = -1; if (p->tcph != NULL) { CLEAR_TCP_PACKET(p); } diff --git a/src/source-dpdk.c b/src/source-dpdk.c index d4965c0e1c..df3fc71de4 100644 --- a/src/source-dpdk.c +++ b/src/source-dpdk.c @@ -494,7 +494,8 @@ static inline Packet *PacketInitFromMbuf(DPDKThreadVars *ptv, struct rte_mbuf *m if ((ol_flags & RTE_MBUF_F_RX_IP_CKSUM_MASK) == RTE_MBUF_F_RX_IP_CKSUM_BAD) { SCLogDebug("HW detected BAD IP checksum"); // chsum recalc will not be triggered but rule keyword check will be - p->l3.comp_csum = 0; + p->l3.csum_set = true; + p->l3.csum = 0; } if ((ol_flags & RTE_MBUF_F_RX_L4_CKSUM_MASK) == RTE_MBUF_F_RX_L4_CKSUM_BAD) { SCLogDebug("HW detected BAD L4 chsum");