From: Victor Julien Date: Sun, 30 Jun 2019 09:07:05 +0000 (+0200) Subject: decode/ipv6: track length of ext hdrs X-Git-Tag: suricata-5.0.0-rc1~225 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3c9a55781098e13e6609ca3d69aa7ac7c9bb623f;p=thirdparty%2Fsuricata.git decode/ipv6: track length of ext hdrs --- diff --git a/src/decode-ipv6.c b/src/decode-ipv6.c index bb00449ac0..5f9c748887 100644 --- a/src/decode-ipv6.c +++ b/src/decode-ipv6.c @@ -159,6 +159,8 @@ DecodeIPV6ExtHdrs(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, uint8_t *pkt while(1) { + IPV6_SET_EXTHDRS_LEN(p, (len - plen)); + if (nh == IPPROTO_NONE) { if (plen > 0) { /* No upper layer, but we do have data. Suspicious. */ diff --git a/src/decode-ipv6.h b/src/decode-ipv6.h index 17b79babd4..0598f0743d 100644 --- a/src/decode-ipv6.h +++ b/src/decode-ipv6.h @@ -69,7 +69,8 @@ typedef struct IPV6Hdr_ #define IPV6_SET_RAW_VER(ip6h, value) ((ip6h)->s_ip6_vfc = (((ip6h)->s_ip6_vfc & 0x0f) | (value << 4))) #define IPV6_SET_RAW_NH(ip6h, value) ((ip6h)->s_ip6_nxt = (value)) -#define IPV6_SET_L4PROTO(p,proto) (p)->ip6vars.l4proto = proto +#define IPV6_SET_L4PROTO(p,proto) (p)->ip6vars.l4proto = (proto) +#define IPV6_SET_EXTHDRS_LEN(p,len) (p)->ip6vars.exthdrs_len = (len) /* ONLY call these functions after making sure that: @@ -88,9 +89,11 @@ typedef struct IPV6Hdr_ IPV6_GET_RAW_PLEN((p)->ip6h) #define IPV6_GET_HLIM(p) \ (IPV6_GET_RAW_HLIM((p)->ip6h)) -/* XXX */ + #define IPV6_GET_L4PROTO(p) \ ((p)->ip6vars.l4proto) +#define IPV6_GET_EXTHDRS_LEN(p) \ + ((p)->ip6vars.exthdrs_len) /** \brief get the highest proto/next header field we know */ //#define IPV6_GET_UPPER_PROTO(p) (p)->ip6eh.ip6_exthdrs_cnt ? @@ -99,14 +102,16 @@ typedef struct IPV6Hdr_ /* helper structure with parsed ipv6 info */ typedef struct IPV6Vars_ { - uint8_t l4proto; /* the proto after the extension headers - * store while decoding so we don't have - * to loop through the exthdrs all the time */ + uint8_t l4proto; /**< the proto after the extension headers + * store while decoding so we don't have + * to loop through the exthdrs all the time */ + uint16_t exthdrs_len; /**< length of the exthdrs */ } IPV6Vars; #define CLEAR_IPV6_PACKET(p) do { \ (p)->ip6h = NULL; \ (p)->ip6vars.l4proto = 0; \ + (p)->ip6vars.exthdrs_len = 0; \ memset(&(p)->ip6eh, 0x00, sizeof((p)->ip6eh)); \ } while (0)