From: Victor Julien Date: Thu, 11 Apr 2024 15:28:12 +0000 (+0200) Subject: decode/icmpv6: store embedded ip6h ptr as offset X-Git-Tag: suricata-8.0.0-beta1~1364 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6e23419665c59426df8cc17cd52b1d82072c92dd;p=thirdparty%2Fsuricata.git decode/icmpv6: store embedded ip6h ptr as offset Reduces direct pointer usage and reduces Packet size. Ticket: #6938. --- diff --git a/src/decode-icmpv6.c b/src/decode-icmpv6.c index d0075a939a..4c2a6836fc 100644 --- a/src/decode-icmpv6.c +++ b/src/decode-icmpv6.c @@ -41,7 +41,9 @@ static inline const IPV6Hdr *PacketGetICMPv6EmbIPv6(const Packet *p) { BUG_ON(p->l4.type != PACKET_L4_ICMPV6); - return p->l4.vars.icmpv6.emb_ipv6h; + const uint8_t *start = (const uint8_t *)PacketGetICMPv6(p); + const uint8_t *ip = start + p->l4.vars.icmpv6.emb_ip6h_offset; + return (const IPV6Hdr *)ip; } #endif @@ -75,7 +77,9 @@ static void DecodePartialIPV6(Packet *p, uint8_t *partial_packet, uint16_t len ) } /** We need to fill l4.vars.icmpv6 */ - p->l4.vars.icmpv6.emb_ipv6h = icmp6_ip6h; + const uint8_t *icmpv6_ptr = (const uint8_t *)p->l4.hdrs.icmpv6h; + DEBUG_VALIDATE_BUG_ON((ptrdiff_t)(partial_packet - icmpv6_ptr) > (ptrdiff_t)UINT16_MAX); + p->l4.vars.icmpv6.emb_ip6h_offset = (uint16_t)(partial_packet - icmpv6_ptr); /** Get protocol and ports inside the embedded ipv6 packet and set the pointers */ p->l4.vars.icmpv6.emb_ip6_proto_next = icmp6_ip6h->s_ip6_nxt; diff --git a/src/decode-icmpv6.h b/src/decode-icmpv6.h index 357f871d8d..406d174c39 100644 --- a/src/decode-icmpv6.h +++ b/src/decode-icmpv6.h @@ -156,8 +156,8 @@ typedef struct ICMPV6Vars_ { uint16_t emb_sport; uint16_t emb_dport; - /** Pointers to the embedded packet headers */ - IPV6Hdr *emb_ipv6h; + /** offset of the embedded packet header */ + uint16_t emb_ip6h_offset; } ICMPV6Vars; void DecodeICMPV6RegisterTests(void);