decode/icmpv6: store embedded ip6h ptr as offset

Reduces direct pointer usage and reduces Packet size.

Ticket: #6938.
pull/10971/head
Victor Julien 1 year ago committed by Victor Julien
parent f2288ee39b
commit 6e23419665

@ -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;

@ -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);

Loading…
Cancel
Save