#endif
void DecodeIPV6FragHeader(Packet *p, uint8_t *pkt,
uint16_t hdrextlen, uint16_t plen,
- uint16_t ip6_exthdrs_cnt, IPV6GenOptHdr *ip6_exthdrs)
+ uint16_t prev_hdrextlen)
{
uint16_t frag_offset = (*(pkt + 2) << 8 | *(pkt + 3)) & 0xFFF8;
int frag_morefrags = (*(pkt + 2) << 8 | *(pkt + 3)) & 0x0001;
p->ip6eh.fh_data_len = data_len;
/* if we have a prev hdr, store the type and offset of it */
- if (ip6_exthdrs_cnt > 1) {
- p->ip6eh.fh_prev_hdr_offset = frag_hdr_offset - ip6_exthdrs[ip6_exthdrs_cnt - 1].len;
+ if (prev_hdrextlen) {
+ p->ip6eh.fh_prev_hdr_offset = frag_hdr_offset - prev_hdrextlen;
}
SCLogDebug("IPV6 FH: frag_hdr_offset %u, data_offset %u, data_len %u",
uint8_t *orig_pkt = pkt;
uint8_t nh = 0; /* careful, 0 is actually a real type */
- uint16_t hdrextlen;
+ uint16_t hdrextlen = 0;
uint16_t plen;
char dstopts = 0;
char exthdr_fh_done = 0;
-
- uint8_t ip6_exthdrs_cnt = 0;
- IPV6GenOptHdr ip6_exthdrs[IPV6_MAX_OPT];
-
int hh = 0;
int rh = 0;
int eh = 0;
SCReturn;
}
- if (ip6_exthdrs_cnt < IPV6_MAX_OPT)
- {
- ip6_exthdrs[ip6_exthdrs_cnt].type = nh;
- ip6_exthdrs[ip6_exthdrs_cnt].next = *pkt;
- ip6_exthdrs[ip6_exthdrs_cnt].len = hdrextlen;
- ip6_exthdrs[ip6_exthdrs_cnt].data = pkt+2;
- ip6_exthdrs_cnt++;
- }
-
if (rh) {
ENGINE_SET_EVENT(p, IPV6_EXTHDR_DUPL_RH);
/* skip past this extension so we can continue parsing the rest
SCReturn;
}
- if (ip6_exthdrs_cnt < IPV6_MAX_OPT)
- {
- ip6_exthdrs[ip6_exthdrs_cnt].type = nh;
- ip6_exthdrs[ip6_exthdrs_cnt].next = *pkt;
- ip6_exthdrs[ip6_exthdrs_cnt].len = hdrextlen;
- ip6_exthdrs[ip6_exthdrs_cnt].data = pkt+2;
- ip6_exthdrs_cnt++;
- }
-
uint8_t *ptr = pkt + 2; /* +2 to go past nxthdr and len */
/* point the pointers to right structures
}
case IPPROTO_FRAGMENT:
+ {
IPV6_SET_L4PROTO(p,nh);
/* store the offset of this extension into the packet
* past the ipv6 header. We use it in defrag for creating
exthdr_fh_done = 1;
}
+ uint16_t prev_hdrextlen = hdrextlen;
hdrextlen = sizeof(IPV6FragHdr);
if (hdrextlen > plen) {
ENGINE_SET_EVENT(p, IPV6_TRUNC_EXTHDR);
/* non fatal, lets try to continue */
}
- if(ip6_exthdrs_cnt<IPV6_MAX_OPT)
- {
- ip6_exthdrs[ip6_exthdrs_cnt].type = nh;
- ip6_exthdrs[ip6_exthdrs_cnt].next = *pkt;
- ip6_exthdrs[ip6_exthdrs_cnt].len = hdrextlen;
- ip6_exthdrs[ip6_exthdrs_cnt].data = pkt+2;
- ip6_exthdrs_cnt++;
- }
-
if (IPV6_EXTHDR_ISSET_FH(p)) {
ENGINE_SET_EVENT(p, IPV6_EXTHDR_DUPL_FH);
nh = *pkt;
IPV6_EXTHDR_SET_FH(p);
/* parse the header and setup the vars */
- DecodeIPV6FragHeader(p, pkt, hdrextlen, plen,
- ip6_exthdrs_cnt, ip6_exthdrs);
+ DecodeIPV6FragHeader(p, pkt, hdrextlen, plen, prev_hdrextlen);
/* if FH has offset 0 and no more fragments are coming, we
* parse this packet further right away, no defrag will be
/* the rest is parsed upon reassembly */
p->flags |= PKT_IS_FRAGMENT;
SCReturn;
-
+ }
case IPPROTO_ESP:
{
IPV6_SET_L4PROTO(p,nh);
SCReturn;
}
- if(ip6_exthdrs_cnt<IPV6_MAX_OPT)
- {
- ip6_exthdrs[ip6_exthdrs_cnt].type = nh;
- ip6_exthdrs[ip6_exthdrs_cnt].next = IPPROTO_NONE;
- ip6_exthdrs[ip6_exthdrs_cnt].len = hdrextlen;
- ip6_exthdrs[ip6_exthdrs_cnt].data = pkt+2;
- ip6_exthdrs_cnt++;
- }
-
if (eh) {
ENGINE_SET_EVENT(p, IPV6_EXTHDR_DUPL_EH);
SCReturn;
ENGINE_SET_EVENT(p, IPV6_EXTHDR_AH_RES_NOT_NULL);
}
- if(ip6_exthdrs_cnt < IPV6_MAX_OPT)
- {
- ip6_exthdrs[ip6_exthdrs_cnt].type = nh;
- ip6_exthdrs[ip6_exthdrs_cnt].next = *pkt;
- ip6_exthdrs[ip6_exthdrs_cnt].len = hdrextlen;
- ip6_exthdrs[ip6_exthdrs_cnt].data = pkt+2;
- ip6_exthdrs_cnt++;
- }
-
if (ah) {
ENGINE_SET_EVENT(p, IPV6_EXTHDR_DUPL_AH);
nh = *pkt;
void DecodeIPV6FragHeader(Packet *p, uint8_t *pkt,
uint16_t hdrextlen, uint16_t plen,
- uint16_t ip6_exthdrs_cnt, IPV6GenOptHdr *ip6_exthdrs);
+ uint16_t prev_hdrextlen);
static Packet *
IPV6BuildTestPacket(uint32_t id, uint16_t off, int mf, const char content,
fh->ip6fh_ident = htonl(id);
fh->ip6fh_offlg = htons((off << 3) | mf);
- DecodeIPV6FragHeader(p, (uint8_t *)fh, 8, 8 + content_len, 0, NULL);
+ DecodeIPV6FragHeader(p, (uint8_t *)fh, 8, 8 + content_len, 0);
pcontent = SCCalloc(1, content_len);
if (unlikely(pcontent == NULL))