Reduces direct pointer usage and reduces Packet size.
Ticket: #6938.
}
/** We need to fill icmpv4vars */
- p->l4.vars.icmpv4.emb_ipv4h = icmp4_ip4h;
+ const uint8_t *icmpv4_ptr = (const uint8_t *)p->l4.hdrs.icmpv4h;
+ DEBUG_VALIDATE_BUG_ON((ptrdiff_t)(partial_packet - icmpv4_ptr) > (ptrdiff_t)UINT16_MAX);
+ p->l4.vars.icmpv4.emb_ip4h_offset = (uint16_t)(partial_packet - icmpv4_ptr);
switch (IPV4_GET_RAW_IPPROTO(icmp4_ip4h)) {
case IPPROTO_TCP:
/* ICMPv4 vars */
typedef struct ICMPV4Vars_
{
- /** Pointers to the embedded packet headers */
- IPV4Hdr *emb_ipv4h;
+ uint16_t emb_ip4h_offset;
- uint16_t id;
- uint16_t seq;
+ uint16_t id;
+ uint16_t seq;
/** Actual header length **/
uint16_t hlen;
/** macro for icmpv4 embedded "protocol" access */
#define ICMPV4_GET_EMB_PROTO(p) (p)->l4.vars.icmpv4.emb_ip4_proto
-/** macro for icmpv4 embedded "ipv4h" header access */
-#define ICMPV4_GET_EMB_IPV4(p) (p)->l4.vars.icmpv4.emb_ipv4h
+
/** macro for icmpv4 header length */
#define ICMPV4_GET_HLEN_ICMPV4H(p) (p)->l4.vars.icmpv4.hlen
return p->l4.type == PACKET_L4_ICMPV4;
}
+static inline const IPV4Hdr *ICMPV4_GET_EMB_IPV4(const Packet *p)
+{
+ const uint8_t *start = (const uint8_t *)PacketGetICMPv4(p);
+ const uint8_t *ip = start + p->l4.vars.icmpv4.emb_ip4h_offset;
+ return (const IPV4Hdr *)ip;
+}
+
static inline ICMPV6Hdr *PacketSetICMPv6(Packet *p, const uint8_t *buf)
{
DEBUG_VALIDATE_BUG_ON(p->l4.type != PACKET_L4_UNKNOWN);