From c9756caeefab7961c981201e540d9f38e9d15168 Mon Sep 17 00:00:00 2001 From: Victor Julien Date: Tue, 16 Aug 2016 13:34:38 +0200 Subject: [PATCH] packet: make tcp/udp/icmp vars union non-anonymous Clean the whole thing after use. --- src/decode-icmpv4.h | 17 +++-------------- src/decode-icmpv6.h | 20 +++----------------- src/decode-tcp.h | 12 +++--------- src/decode.h | 10 +++++++++- 4 files changed, 18 insertions(+), 41 deletions(-) diff --git a/src/decode-icmpv4.h b/src/decode-icmpv4.h index 2f5862d389..b28dd259a6 100644 --- a/src/decode-icmpv4.h +++ b/src/decode-icmpv4.h @@ -198,20 +198,9 @@ typedef struct ICMPV4Vars_ } ICMPV4Vars; #define CLEAR_ICMPV4_PACKET(p) do { \ - (p)->level4_comp_csum = -1; \ - (p)->icmpv4vars.id = 0; \ - (p)->icmpv4vars.seq = 0; \ - (p)->icmpv4vars.emb_ipv4h = NULL; \ - (p)->icmpv4vars.emb_tcph = NULL; \ - (p)->icmpv4vars.emb_udph = NULL; \ - (p)->icmpv4vars.emb_icmpv4h = NULL; \ - (p)->icmpv4vars.emb_ip4_src.s_addr = 0; \ - (p)->icmpv4vars.emb_ip4_dst.s_addr = 0; \ - (p)->icmpv4vars.emb_sport = 0; \ - (p)->icmpv4vars.emb_ip4_proto = 0; \ - (p)->icmpv4vars.emb_sport = 0; \ - (p)->icmpv4vars.emb_dport = 0; \ - (p)->icmpv4h = NULL; \ + (p)->level4_comp_csum = -1; \ + PACKET_CLEAR_L4VARS((p)); \ + (p)->icmpv4h = NULL; \ } while(0) #define ICMPV4_HEADER_PKT_OFFSET 8 diff --git a/src/decode-icmpv6.h b/src/decode-icmpv6.h index af97500607..a9a15ff72b 100644 --- a/src/decode-icmpv6.h +++ b/src/decode-icmpv6.h @@ -158,23 +158,9 @@ typedef struct ICMPV6Vars_ { #define CLEAR_ICMPV6_PACKET(p) do { \ - (p)->level4_comp_csum = -1; \ - (p)->icmpv6vars.id = 0; \ - (p)->icmpv6vars.seq = 0; \ - (p)->icmpv6vars.mtu = 0; \ - (p)->icmpv6vars.error_ptr = 0; \ - (p)->icmpv6vars.emb_ipv6h = NULL; \ - (p)->icmpv6vars.emb_tcph = NULL; \ - (p)->icmpv6vars.emb_udph = NULL; \ - (p)->icmpv6vars.emb_icmpv6h = NULL; \ - (p)->icmpv6vars.emb_ip6_src[0] = 0; \ - (p)->icmpv6vars.emb_ip6_src[1] = 0; \ - (p)->icmpv6vars.emb_ip6_src[2] = 0; \ - (p)->icmpv6vars.emb_ip6_src[3] = 0; \ - (p)->icmpv6vars.emb_ip6_proto_next = 0; \ - (p)->icmpv6vars.emb_sport = 0; \ - (p)->icmpv6vars.emb_dport = 0; \ - (p)->icmpv6h = NULL; \ + (p)->level4_comp_csum = -1; \ + PACKET_CLEAR_L4VARS((p)); \ + (p)->icmpv6h = NULL; \ } while(0) void DecodeICMPV6RegisterTests(void); diff --git a/src/decode-tcp.h b/src/decode-tcp.h index 72ed817974..f9611e723d 100644 --- a/src/decode-tcp.h +++ b/src/decode-tcp.h @@ -151,16 +151,10 @@ typedef struct TCPVars_ TCPOpt mss; } TCPVars; -#define CLEAR_TCP_PACKET(p) { \ - (p)->tcph = NULL; \ +#define CLEAR_TCP_PACKET(p) { \ (p)->level4_comp_csum = -1; \ - (p)->tcpvars.ts_set = FALSE; \ - (p)->tcpvars.ts_val = 0; \ - (p)->tcpvars.ts_ecr = 0; \ - (p)->tcpvars.sack.type = 0; \ - (p)->tcpvars.sackok.type = 0; \ - (p)->tcpvars.ws.type = 0; \ - (p)->tcpvars.mss.type = 0; \ + PACKET_CLEAR_L4VARS((p)); \ + (p)->tcph = NULL; \ } void DecodeTCPRegisterTests(void); diff --git a/src/decode.h b/src/decode.h index 886ca2fa1e..ff221a6876 100644 --- a/src/decode.h +++ b/src/decode.h @@ -470,7 +470,11 @@ typedef struct Packet_ UDPVars udpvars; ICMPV4Vars icmpv4vars; ICMPV6Vars icmpv6vars; - }; + } l4vars; +#define tcpvars l4vars.tcpvars +#define udpvars l4vars.udpvars +#define icmpv4vars l4vars.icmpv4vars +#define icmpv6vars l4vars.icmpv6vars TCPHdr *tcph; @@ -659,6 +663,10 @@ typedef struct CaptureStats_ { void CaptureStatsUpdate(ThreadVars *tv, CaptureStats *s, const Packet *p); void CaptureStatsSetup(ThreadVars *tv, CaptureStats *s); +#define PACKET_CLEAR_L4VARS(p) do { \ + memset(&(p)->l4vars, 0x00, sizeof((p)->l4vars)); \ + } while (0) + /** * \brief reset these to -1(indicates that the packet is fresh from the queue) */