]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
decode/icmpv6: store embedded ip6h ptr as offset
authorVictor Julien <vjulien@oisf.net>
Thu, 11 Apr 2024 15:28:12 +0000 (17:28 +0200)
committerVictor Julien <victor@inliniac.net>
Fri, 26 Apr 2024 18:59:45 +0000 (20:59 +0200)
Reduces direct pointer usage and reduces Packet size.

Ticket: #6938.

src/decode-icmpv6.c
src/decode-icmpv6.h

index d0075a939a92bd575e8481b1bea2f2010ddb039c..4c2a6836fc54a426bb2a24fc2b8e73160b6d0820 100644 (file)
@@ -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;
 
index 357f871d8da1a1b03ecbaeea7fc30d9138fd502b..406d174c3955fd6b7a9cc9d400f7d85e0915bc1d 100644 (file)
@@ -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);