suricata
decode-icmpv6.c
Go to the documentation of this file.
1 /* Copyright (C) 2007-2010 Open Information Security Foundation
2  *
3  * You can copy, redistribute or modify this Program under the terms of
4  * the GNU General Public License version 2 as published by the Free
5  * Software Foundation.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * version 2 along with this program; if not, write to the Free Software
14  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
15  * 02110-1301, USA.
16  */
17 
18 /**
19  * \ingroup decode
20  *
21  * @{
22  */
23 
24 
25 /**
26  * \file
27  *
28  * \author Victor Julien <victor@inliniac.net>
29  *
30  * Decode ICMPv6
31  */
32 
33 #include "suricata-common.h"
34 #include "decode-icmpv6.h"
35 #include "decode.h"
36 #include "flow.h"
37 #include "util-print.h"
38 #include "util-validate.h"
39 
40 /**
41  * \brief Get variables and do some checks of the embedded IPV6 packet
42  *
43  * \param p Pointer to the packet we are filling
44  * \param partial_packet Pointer to the raw packet buffer
45  * \param len the len of the rest of the packet not processed yet
46  *
47  * \retval void No return value
48  */
49 static void DecodePartialIPV6(Packet *p, uint8_t *partial_packet, uint16_t len )
50 {
51  /** Check the sizes, the header must fit at least */
52  if (len < IPV6_HEADER_LEN) {
53  SCLogDebug("ICMPV6_IPV6_TRUNC_PKT");
55  return;
56  }
57 
58  IPV6Hdr *icmp6_ip6h = (IPV6Hdr*)partial_packet;
59 
60  /** Check the embedded version */
61  if(((icmp6_ip6h->s_ip6_vfc & 0xf0) >> 4) != 6)
62  {
63  SCLogDebug("ICMPv6 contains Unknown IPV6 version "
64  "ICMPV6_IPV6_UNKNOWN_VER");
66  return;
67  }
68 
69  /** We need to fill icmpv6vars */
70  p->icmpv6vars.emb_ipv6h = icmp6_ip6h;
71 
72  /** Get the IP6 address */
73  p->icmpv6vars.emb_ip6_src[0] = icmp6_ip6h->s_ip6_src[0];
74  p->icmpv6vars.emb_ip6_src[1] = icmp6_ip6h->s_ip6_src[1];
75  p->icmpv6vars.emb_ip6_src[2] = icmp6_ip6h->s_ip6_src[2];
76  p->icmpv6vars.emb_ip6_src[3] = icmp6_ip6h->s_ip6_src[3];
77 
78  p->icmpv6vars.emb_ip6_dst[0] = icmp6_ip6h->s_ip6_dst[0];
79  p->icmpv6vars.emb_ip6_dst[1] = icmp6_ip6h->s_ip6_dst[1];
80  p->icmpv6vars.emb_ip6_dst[2] = icmp6_ip6h->s_ip6_dst[2];
81  p->icmpv6vars.emb_ip6_dst[3] = icmp6_ip6h->s_ip6_dst[3];
82 
83  /** Get protocol and ports inside the embedded ipv6 packet and set the pointers */
84  p->icmpv6vars.emb_ip6_proto_next = icmp6_ip6h->s_ip6_nxt;
85 
86  switch (icmp6_ip6h->s_ip6_nxt) {
87  case IPPROTO_TCP:
89  p->icmpv6vars.emb_tcph = (TCPHdr*)(partial_packet + IPV6_HEADER_LEN);
92 
93  SCLogDebug("ICMPV6->IPV6->TCP header sport: "
94  "%"PRIu16" dport %"PRIu16"", p->icmpv6vars.emb_sport,
96  } else {
97  SCLogDebug("Warning, ICMPV6->IPV6->TCP "
98  "header Didn't fit in the packet!");
99  p->icmpv6vars.emb_sport = 0;
100  p->icmpv6vars.emb_dport = 0;
101  }
102 
103  break;
104  case IPPROTO_UDP:
105  if (len >= IPV6_HEADER_LEN + UDP_HEADER_LEN ) {
106  p->icmpv6vars.emb_udph = (UDPHdr*)(partial_packet + IPV6_HEADER_LEN);
109 
110  SCLogDebug("ICMPV6->IPV6->UDP header sport: "
111  "%"PRIu16" dport %"PRIu16"", p->icmpv6vars.emb_sport,
112  p->icmpv6vars.emb_dport);
113  } else {
114  SCLogDebug("Warning, ICMPV6->IPV6->UDP "
115  "header Didn't fit in the packet!");
116  p->icmpv6vars.emb_sport = 0;
117  p->icmpv6vars.emb_dport = 0;
118  }
119 
120  break;
121  case IPPROTO_ICMPV6:
122  p->icmpv6vars.emb_icmpv6h = (ICMPV6Hdr*)(partial_packet + IPV6_HEADER_LEN);
123  p->icmpv6vars.emb_sport = 0;
124  p->icmpv6vars.emb_dport = 0;
125 
126  SCLogDebug("ICMPV6->IPV6->ICMP header");
127 
128  break;
129  }
130 
131  /* debug print */
132 #ifdef DEBUG
133  char s[46], d[46];
134  PrintInet(AF_INET6, (const void *)p->icmpv6vars.emb_ip6_src, s, sizeof(s));
135  PrintInet(AF_INET6, (const void *)p->icmpv6vars.emb_ip6_dst, d, sizeof(d));
136  SCLogDebug("ICMPv6 embedding IPV6 %s->%s - CLASS: %" PRIu32 " FLOW: "
137  "%" PRIu32 " NH: %" PRIu32 " PLEN: %" PRIu32 " HLIM: %" PRIu32,
138  s, d, IPV6_GET_RAW_CLASS(icmp6_ip6h), IPV6_GET_RAW_FLOW(icmp6_ip6h),
139  IPV6_GET_RAW_NH(icmp6_ip6h), IPV6_GET_RAW_PLEN(icmp6_ip6h), IPV6_GET_RAW_HLIM(icmp6_ip6h));
140 #endif
141 
142  return;
143 }
144 
145 /** \retval type counterpart type or -1 */
147 {
148 #define CASE_CODE(t,r) case (t): return r; case (r): return t;
149  switch (type) {
156 
161  default:
162  return -1;
163  }
164 #undef CASE_CODE
165 }
166 
167 /**
168  * \brief Decode ICMPV6 packets and fill the Packet with the decoded info
169  *
170  * \param tv Pointer to the thread variables
171  * \param dtv Pointer to the decode thread variables
172  * \param p Pointer to the packet we are filling
173  * \param pkt Pointer to the raw packet buffer
174  * \param len the len of the rest of the packet not processed yet
175  *
176  * \retval void No return value
177  */
179  const uint8_t *pkt, uint32_t len)
180 {
181  int full_hdr = 0;
183 
184  if (len < ICMPV6_HEADER_LEN) {
185  SCLogDebug("ICMPV6_PKT_TOO_SMALL");
187  return TM_ECODE_FAILED;
188  }
189 
190  p->icmpv6h = (ICMPV6Hdr *)pkt;
191  p->proto = IPPROTO_ICMPV6;
192  p->icmp_s.type = p->icmpv6h->type;
193  p->icmp_s.code = p->icmpv6h->code;
195  p->payload_len = (uint16_t)(len - ICMPV6_HEADER_LEN);
196  p->payload = (uint8_t *)pkt + ICMPV6_HEADER_LEN;
197 
198  int ctype = ICMPv6GetCounterpart(p->icmp_s.type);
199  if (ctype != -1) {
200  p->icmp_d.type = (uint8_t)ctype;
201  }
202 
203  SCLogDebug("ICMPV6 TYPE %" PRIu32 " CODE %" PRIu32 "", p->icmpv6h->type,
204  p->icmpv6h->code);
205 
206  switch (ICMPV6_GET_TYPE(p)) {
207  case ICMP6_DST_UNREACH:
208  SCLogDebug("ICMP6_DST_UNREACH");
209 
212  } else {
213  if (unlikely(len > ICMPV6_HEADER_LEN + USHRT_MAX)) {
214  return TM_ECODE_FAILED;
215  }
216  DecodePartialIPV6(p, (uint8_t *)(pkt + ICMPV6_HEADER_LEN),
217  (uint16_t)(len - ICMPV6_HEADER_LEN));
218  full_hdr = 1;
219  }
220 
221  break;
223  SCLogDebug("ICMP6_PACKET_TOO_BIG");
224 
225  if (ICMPV6_GET_CODE(p) != 0) {
227  } else {
228  if (unlikely(len > ICMPV6_HEADER_LEN + USHRT_MAX)) {
229  return TM_ECODE_FAILED;
230  }
231  p->icmpv6vars.mtu = ICMPV6_GET_MTU(p);
232  DecodePartialIPV6(p, (uint8_t *)(pkt + ICMPV6_HEADER_LEN),
233  (uint16_t)(len - ICMPV6_HEADER_LEN));
234  full_hdr = 1;
235  }
236 
237  break;
238  case ICMP6_TIME_EXCEEDED:
239  SCLogDebug("ICMP6_TIME_EXCEEDED");
240 
243  } else {
244  if (unlikely(len > ICMPV6_HEADER_LEN + USHRT_MAX)) {
245  return TM_ECODE_FAILED;
246  }
247  DecodePartialIPV6(p, (uint8_t *)(pkt + ICMPV6_HEADER_LEN),
248  (uint16_t)(len - ICMPV6_HEADER_LEN));
249  full_hdr = 1;
250  }
251 
252  break;
253  case ICMP6_PARAM_PROB:
254  SCLogDebug("ICMP6_PARAM_PROB");
255 
258  } else {
259  if (unlikely(len > ICMPV6_HEADER_LEN + USHRT_MAX)) {
260  return TM_ECODE_FAILED;
261  }
263  DecodePartialIPV6(p, (uint8_t *)(pkt + ICMPV6_HEADER_LEN),
264  (uint16_t)(len - ICMPV6_HEADER_LEN));
265  full_hdr = 1;
266  }
267 
268  break;
269  case ICMP6_ECHO_REQUEST:
270  SCLogDebug("ICMP6_ECHO_REQUEST id: %u seq: %u",
272 
273  if (ICMPV6_GET_CODE(p) != 0) {
275  } else {
278  full_hdr = 1;
279  }
280 
281  break;
282  case ICMP6_ECHO_REPLY:
283  SCLogDebug("ICMP6_ECHO_REPLY id: %u seq: %u",
285 
286  if (ICMPV6_GET_CODE(p) != 0) {
288  } else {
291  full_hdr = 1;
292  }
293 
294  break;
295  case ND_ROUTER_SOLICIT:
296  SCLogDebug("ND_ROUTER_SOLICIT");
297  if (ICMPV6_GET_CODE(p) != 0) {
299  }
300  break;
301  case ND_ROUTER_ADVERT:
302  SCLogDebug("ND_ROUTER_ADVERT");
303  if (ICMPV6_GET_CODE(p) != 0) {
305  }
306  break;
307  case ND_NEIGHBOR_SOLICIT:
308  SCLogDebug("ND_NEIGHBOR_SOLICIT");
309  if (ICMPV6_GET_CODE(p) != 0) {
311  }
312  break;
313  case ND_NEIGHBOR_ADVERT:
314  SCLogDebug("ND_NEIGHBOR_ADVERT");
315  if (ICMPV6_GET_CODE(p) != 0) {
317  }
318  break;
319  case ND_REDIRECT:
320  SCLogDebug("ND_REDIRECT");
321  if (ICMPV6_GET_CODE(p) != 0) {
323  }
324  break;
325  case MLD_LISTENER_QUERY:
326  SCLogDebug("MLD_LISTENER_QUERY");
327  if (ICMPV6_GET_CODE(p) != 0) {
329  }
330  if (IPV6_GET_HLIM(p) != 1) {
332  }
333  break;
334  case MLD_LISTENER_REPORT:
335  SCLogDebug("MLD_LISTENER_REPORT");
336  if (ICMPV6_GET_CODE(p) != 0) {
338  }
339  if (IPV6_GET_HLIM(p) != 1) {
341  }
342  break;
344  SCLogDebug("MLD_LISTENER_REDUCTION");
345  if (ICMPV6_GET_CODE(p) != 0) {
347  }
348  if (IPV6_GET_HLIM(p) != 1) {
350  }
351  break;
352  case ICMP6_RR:
353  SCLogDebug("ICMP6_RR");
354  if (ICMPV6_GET_CODE(p) > 2 && ICMPV6_GET_CODE(p) != 255) {
356  }
357  break;
358  case ICMP6_NI_QUERY:
359  SCLogDebug("ICMP6_NI_QUERY");
360  if (ICMPV6_GET_CODE(p) > 2) {
362  }
363  break;
364  case ICMP6_NI_REPLY:
365  SCLogDebug("ICMP6_NI_REPLY");
366  if (ICMPV6_GET_CODE(p) > 2) {
368  }
369  break;
370  case ND_INVERSE_SOLICIT:
371  SCLogDebug("ND_INVERSE_SOLICIT");
372  if (ICMPV6_GET_CODE(p) != 0) {
374  }
375  break;
376  case ND_INVERSE_ADVERT:
377  SCLogDebug("ND_INVERSE_ADVERT");
378  if (ICMPV6_GET_CODE(p) != 0) {
380  }
381  break;
382  case MLD_V2_LIST_REPORT:
383  SCLogDebug("MLD_V2_LIST_REPORT");
384  if (ICMPV6_GET_CODE(p) != 0) {
386  }
387  break;
389  SCLogDebug("HOME_AGENT_AD_REQUEST");
390  if (ICMPV6_GET_CODE(p) != 0) {
392  }
393  break;
394  case HOME_AGENT_AD_REPLY:
395  SCLogDebug("HOME_AGENT_AD_REPLY");
396  if (ICMPV6_GET_CODE(p) != 0) {
398  }
399  break;
401  SCLogDebug("MOBILE_PREFIX_SOLICIT");
402  if (ICMPV6_GET_CODE(p) != 0) {
404  }
405  break;
407  SCLogDebug("MOBILE_PREFIX_ADVERT");
408  if (ICMPV6_GET_CODE(p) != 0) {
410  }
411  break;
412  case CERT_PATH_SOLICIT:
413  SCLogDebug("CERT_PATH_SOLICIT");
414  if (ICMPV6_GET_CODE(p) != 0) {
416  }
417  break;
418  case CERT_PATH_ADVERT:
419  SCLogDebug("CERT_PATH_ADVERT");
420  if (ICMPV6_GET_CODE(p) != 0) {
422  }
423  break;
425  SCLogDebug("ICMP6_MOBILE_EXPERIMENTAL");
426  break;
427  case MC_ROUTER_ADVERT:
428  SCLogDebug("MC_ROUTER_ADVERT");
429  break;
430  case MC_ROUTER_SOLICIT:
431  SCLogDebug("MC_ROUTER_SOLICIT");
432  break;
433  case MC_ROUTER_TERMINATE:
434  SCLogDebug("MC_ROUTER_TERMINATE");
435  break;
436  case FMIPV6_MSG:
437  SCLogDebug("FMIPV6_MSG");
438  if (ICMPV6_GET_CODE(p) != 0) {
440  }
441  break;
442  case RPL_CONTROL_MSG:
443  SCLogDebug("RPL_CONTROL_MSG");
444  if (ICMPV6_GET_CODE(p) > 3 && ICMPV6_GET_CODE(p) < 128) {
446  }
447  if (ICMPV6_GET_CODE(p) > 132) {
449  }
450  break;
451  case LOCATOR_UDATE_MSG:
452  SCLogDebug("LOCATOR_UDATE_MSG");
453  if (ICMPV6_GET_CODE(p) != 0) {
455  }
456  break;
457  case DUPL_ADDR_REQUEST:
458  SCLogDebug("DUPL_ADDR_REQUEST");
459  if (ICMPV6_GET_CODE(p) != 0) {
461  }
462  break;
463  case DUPL_ADDR_CONFIRM:
464  SCLogDebug("DUPL_ADDR_CONFIRM");
465  if (ICMPV6_GET_CODE(p) != 0) {
467  }
468  break;
469  case MPL_CONTROL_MSG:
470  SCLogDebug("MPL_CONTROL_MSG");
471  if (ICMPV6_GET_CODE(p) != 0) {
473  }
474  break;
475  default:
476  /* Various range taken from:
477  * http://www.iana.org/assignments/icmpv6-parameters/icmpv6-parameters.xhtml#icmpv6-parameters-2
478  */
479  if ((ICMPV6_GET_TYPE(p) > 4) && (ICMPV6_GET_TYPE(p) < 100)) {
481  } else if ((ICMPV6_GET_TYPE(p) >= 100) && (ICMPV6_GET_TYPE(p) < 102)) {
483  } else if ((ICMPV6_GET_TYPE(p) >= 102) && (ICMPV6_GET_TYPE(p) < 127)) {
485  } else if ((ICMPV6_GET_TYPE(p) >= 160) && (ICMPV6_GET_TYPE(p) < 200)) {
487  } else if ((ICMPV6_GET_TYPE(p) >= 200) && (ICMPV6_GET_TYPE(p) < 202)) {
489  } else if (ICMPV6_GET_TYPE(p) >= 202) {
491  } else {
492  SCLogDebug("ICMPV6 Message type %" PRIu8 " not "
493  "implemented yet", ICMPV6_GET_TYPE(p));
495  }
496  }
497 
498  /* for a info message the header is just 4 bytes */
499  if (!full_hdr) {
500  if (p->payload_len >= 4) {
501  p->payload_len -= 4;
502  p->payload = (uint8_t *)pkt + 4;
503  } else {
504  p->payload_len = 0;
505  p->payload = NULL;
506  }
507  }
508 
509 #ifdef DEBUG
511  SCLogDebug("Unknown Code, ICMPV6_UNKNOWN_CODE");
512 
514  SCLogDebug("Unknown Type, ICMPV6_UNKNOWN_TYPE");
515 #endif
516 
517  FlowSetupPacket(p);
518 
519  return TM_ECODE_OK;
520 }
521 
522 #ifdef UNITTESTS
523 #include "packet.h"
524 #include "util-unittest-helper.h"
525 
526 static int ICMPV6CalculateValidChecksumtest01(void)
527 {
528  uint16_t csum = 0;
529 
530  uint8_t raw_ipv6[] = {
531  0x00, 0x00, 0x86, 0x05, 0x80, 0xda, 0x00, 0x60,
532  0x97, 0x07, 0x69, 0xea, 0x86, 0xdd, 0x60, 0x00,
533  0x00, 0x00, 0x00, 0x44, 0x3a, 0x40, 0x3f, 0xfe,
534  0x05, 0x07, 0x00, 0x00, 0x00, 0x01, 0x02, 0x60,
535  0x97, 0xff, 0xfe, 0x07, 0x69, 0xea, 0x3f, 0xfe,
536  0x05, 0x07, 0x00, 0x00, 0x00, 0x01, 0x02, 0x00,
537  0x86, 0xff, 0xfe, 0x05, 0x80, 0xda, 0x03, 0x00,
538  0xf7, 0x52, 0x00, 0x00, 0x00, 0x00, 0x60, 0x00,
539  0x00, 0x00, 0x00, 0x14, 0x11, 0x01, 0x3f, 0xfe,
540  0x05, 0x07, 0x00, 0x00, 0x00, 0x01, 0x02, 0x00,
541  0x86, 0xff, 0xfe, 0x05, 0x80, 0xda, 0x3f, 0xfe,
542  0x05, 0x01, 0x04, 0x10, 0x00, 0x00, 0x02, 0xc0,
543  0xdf, 0xff, 0xfe, 0x47, 0x03, 0x3e, 0xa0, 0x75,
544  0x82, 0x9b, 0x00, 0x14, 0x82, 0x8b, 0x01, 0x01,
545  0x00, 0x00, 0xf9, 0xc8, 0xe7, 0x36, 0xf5, 0xed,
546  0x08, 0x00};
547 
548  csum = *( ((uint16_t *)(raw_ipv6 + 56)));
549 
550  FAIL_IF(csum != ICMPV6CalculateChecksum((uint16_t *)(raw_ipv6 + 14 + 8),
551  (uint16_t *)(raw_ipv6 + 54), 68));
552  PASS;
553 }
554 
555 static int ICMPV6CalculateInvalidChecksumtest02(void)
556 {
557  uint16_t csum = 0;
558 
559  uint8_t raw_ipv6[] = {
560  0x00, 0x00, 0x86, 0x05, 0x80, 0xda, 0x00, 0x60,
561  0x97, 0x07, 0x69, 0xea, 0x86, 0xdd, 0x60, 0x00,
562  0x00, 0x00, 0x00, 0x44, 0x3a, 0x40, 0x3f, 0xfe,
563  0x05, 0x07, 0x00, 0x00, 0x00, 0x01, 0x02, 0x60,
564  0x97, 0xff, 0xfe, 0x07, 0x69, 0xea, 0x3f, 0xfe,
565  0x05, 0x07, 0x00, 0x00, 0x00, 0x01, 0x02, 0x00,
566  0x86, 0xff, 0xfe, 0x05, 0x80, 0xda, 0x03, 0x00,
567  0xf7, 0x52, 0x00, 0x00, 0x00, 0x00, 0x60, 0x00,
568  0x00, 0x00, 0x00, 0x14, 0x11, 0x01, 0x3f, 0xfe,
569  0x05, 0x07, 0x00, 0x00, 0x00, 0x01, 0x02, 0x00,
570  0x86, 0xff, 0xfe, 0x05, 0x80, 0xda, 0x3f, 0xfe,
571  0x05, 0x01, 0x04, 0x10, 0x00, 0x00, 0x02, 0xc0,
572  0xdf, 0xff, 0xfe, 0x47, 0x03, 0x3e, 0xa0, 0x75,
573  0x82, 0x9b, 0x00, 0x14, 0x82, 0x8b, 0x01, 0x01,
574  0x00, 0x00, 0xf9, 0xc8, 0xe7, 0x36, 0xf5, 0xed,
575  0x08, 0x01};
576 
577  csum = *( ((uint16_t *)(raw_ipv6 + 56)));
578 
579  FAIL_IF(csum == ICMPV6CalculateChecksum((uint16_t *)(raw_ipv6 + 14 + 8),
580  (uint16_t *)(raw_ipv6 + 54), 68));
581  PASS;
582 }
583 
584 /** \test icmpv6 message type: parameter problem, valid packet
585  *
586  * \retval retval 0 = Error ; 1 = ok
587  */
588 static int ICMPV6ParamProbTest01(void)
589 {
590  static uint8_t raw_ipv6[] = {
591  0x60, 0x00, 0x00, 0x00, 0x00, 0x38, 0x3a, 0xff,
592  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
593  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
594  0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
595  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
596  0x04, 0x00, 0xcc, 0x2a, 0x6d, 0x93, 0x0b, 0xdf,
597  0x69, 0x70, 0x12, 0xb7, 0x00, 0x08, 0x3a, 0xff,
598  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
599  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
600  0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
601  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
602  0x80, 0x00, 0x08, 0xb5, 0x99, 0xc3, 0xde, 0x40 };
603 
604  Packet *p = PacketGetFromAlloc();
605  FAIL_IF_NULL(p);
606  IPV6Hdr ip6h;
607  ThreadVars tv;
609  uint32_t *ipv6src;
610  uint32_t *ipv6dst;
611  ipv6src = (uint32_t*) &raw_ipv6[8];
612  ipv6dst = (uint32_t*) &raw_ipv6[24];
613 
614  memset(&tv, 0, sizeof(ThreadVars));
615  memset(&dtv, 0, sizeof(DecodeThreadVars));
616  memset(&ip6h, 0, sizeof(IPV6Hdr));
617 
619  DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6));
620 
621  FAIL_IF(p->icmpv6h == NULL);
622 
623  /* ICMPv6 not processed at all? */
624  FAIL_IF(ICMPV6_GET_TYPE(p) != 4 || ICMPV6_GET_CODE(p) != 0 ||
625  ICMPV6_GET_EMB_PROTO(p) != IPPROTO_ICMPV6);
626 
627  /* Let's check if we retrieved the embedded ipv6 addresses correctly */
628  uint32_t i=0;
629  for (i = 0; i < 4; i++) {
630  FAIL_IF(p->icmpv6vars.emb_ip6_src[i] != ipv6src[i] ||
631  p->icmpv6vars.emb_ip6_dst[i] != ipv6dst[i]);
632  }
633 
634  PacketRecycle(p);
635  FlowShutdown();
636  SCFree(p);
637  PASS;
638 }
639 
640 /** \test icmpv6 message type: packet too big, valid packet
641  *
642  * \retval retval 0 = Error ; 1 = ok
643  */
644 static int ICMPV6PktTooBigTest01(void)
645 {
646  static uint8_t raw_ipv6[] = {
647  0x60, 0x00, 0x00, 0x00, 0x00, 0x30, 0x3a, 0xff,
648  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
649  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
650  0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
651  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
652  0x02, 0x00, 0x5c, 0x7a, 0x00, 0x00, 0x05, 0x00,
653  0x64, 0x14, 0xfd, 0xff, 0x00, 0x00, 0x3b, 0xff,
654  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
655  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
656  0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
657  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 };
658 
659  Packet *p = PacketGetFromAlloc();
660  FAIL_IF_NULL(p);
661  IPV6Hdr ip6h;
662  ThreadVars tv;
664  uint32_t *ipv6src;
665  uint32_t *ipv6dst;
666  ipv6src = (uint32_t*) &raw_ipv6[8];
667  ipv6dst = (uint32_t*) &raw_ipv6[24];
668 
669  memset(&tv, 0, sizeof(ThreadVars));
670  memset(&dtv, 0, sizeof(DecodeThreadVars));
671  memset(&ip6h, 0, sizeof(IPV6Hdr));
672 
674  DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6));
675 
676  FAIL_IF(p->icmpv6h == NULL);
677 
678  /* Note: it has an embedded ipv6 packet but no protocol after ipv6
679  * (IPPROTO_NONE) */
680  /* Check if ICMPv6 header was processed at all. */
681  FAIL_IF(ICMPV6_GET_TYPE(p) != 2 || ICMPV6_GET_CODE(p) != 0 );
682 
683  /* Let's check if we retrieved the embedded ipv6 addresses correctly */
684  uint32_t i=0;
685  for (i = 0; i < 4; i++) {
686  FAIL_IF(p->icmpv6vars.emb_ip6_src[i] != ipv6src[i] ||
687  p->icmpv6vars.emb_ip6_dst[i] != ipv6dst[i]);
688  }
689 
690  SCLogDebug("ICMPV6 IPV6 src and dst properly set");
691 
692  PacketRecycle(p);
693  FlowShutdown();
694  SCFree(p);
695  PASS;
696 }
697 
698 /** \test icmpv6 message type: time exceed, valid packet
699  *
700  * \retval retval 0 = Error ; 1 = ok
701  */
702 static int ICMPV6TimeExceedTest01(void)
703 {
704  static uint8_t raw_ipv6[] = {
705  0x60, 0x00, 0x00, 0x00, 0x00, 0x30, 0x3a, 0xff,
706  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
707  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
708  0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
709  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
710  0x03, 0x00, 0x56, 0x2d, 0x00, 0x00, 0x00, 0x00,
711  0x6d, 0x23, 0xff, 0x3d, 0x00, 0x00, 0x3b, 0xff,
712  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
713  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
714  0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
715  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 };
716 
717  Packet *p = PacketGetFromAlloc();
718  FAIL_IF_NULL(p);
719  IPV6Hdr ip6h;
720  ThreadVars tv;
722  uint32_t *ipv6src;
723  uint32_t *ipv6dst;
724  ipv6src = (uint32_t*) &raw_ipv6[8];
725  ipv6dst = (uint32_t*) &raw_ipv6[24];
726 
727  memset(&tv, 0, sizeof(ThreadVars));
728  memset(&dtv, 0, sizeof(DecodeThreadVars));
729  memset(&ip6h, 0, sizeof(IPV6Hdr));
730 
732  DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6));
733 
734  FAIL_IF_NULL(p->icmpv6h);
735 
736  /* Note: it has an embedded ipv6 packet but no protocol after ipv6 (IPPROTO_NONE) */
737  FAIL_IF(ICMPV6_GET_TYPE(p) != 3 || ICMPV6_GET_CODE(p) != 0 ||
738  ICMPV6_GET_EMB_IPV6(p) == NULL ||
739  ICMPV6_GET_EMB_PROTO(p) != IPPROTO_NONE);
740 
741  /* Let's check if we retrieved the embedded ipv6 addresses correctly */
742  uint32_t i=0;
743  for (i = 0; i < 4; i++) {
744  FAIL_IF(p->icmpv6vars.emb_ip6_src[i] != ipv6src[i] ||
745  p->icmpv6vars.emb_ip6_dst[i] != ipv6dst[i]);
746  }
747 
748  SCLogDebug("ICMPV6 IPV6 src and dst properly set");
749 
750  PacketRecycle(p);
751  FlowShutdown();
752  SCFree(p);
753  PASS;
754 }
755 
756 /** \test icmpv6 message type: destination unreach, valid packet
757  *
758  * \retval retval 0 = Error ; 1 = ok
759  */
760 static int ICMPV6DestUnreachTest01(void)
761 {
762  static uint8_t raw_ipv6[] = {
763  0x60, 0x00, 0x00, 0x00, 0x00, 0x30, 0x3a, 0xff,
764  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
765  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
766  0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
767  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
768  0x01, 0x00, 0x7b, 0x85, 0x00, 0x00, 0x00, 0x00,
769  0x60, 0x4b, 0xe8, 0xbd, 0x00, 0x00, 0x3b, 0xff,
770  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
771  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
772  0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
773  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 };
774 
775  Packet *p = PacketGetFromAlloc();
776  FAIL_IF_NULL(p);
777  IPV6Hdr ip6h;
778  ThreadVars tv;
780  uint32_t *ipv6src;
781  uint32_t *ipv6dst;
782  ipv6src = (uint32_t*) &raw_ipv6[8];
783  ipv6dst = (uint32_t*) &raw_ipv6[24];
784 
785  memset(&tv, 0, sizeof(ThreadVars));
786  memset(&dtv, 0, sizeof(DecodeThreadVars));
787  memset(&ip6h, 0, sizeof(IPV6Hdr));
788 
790  DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6));
791 
792  FAIL_IF_NULL(p->icmpv6h);
793 
794  /* Note: it has an embedded ipv6 packet but no protocol after ipv6 (IPPROTO_NONE) */
795  FAIL_IF(ICMPV6_GET_TYPE(p) != 1 || ICMPV6_GET_CODE(p) != 0 ||
796  ICMPV6_GET_EMB_IPV6(p) == NULL ||
797  ICMPV6_GET_EMB_PROTO(p) != IPPROTO_NONE);
798 
799  /* Let's check if we retrieved the embedded ipv6 addresses correctly */
800  uint32_t i=0;
801  for (i = 0; i < 4; i++) {
802  FAIL_IF(p->icmpv6vars.emb_ip6_src[i] != ipv6src[i] ||
803  p->icmpv6vars.emb_ip6_dst[i] != ipv6dst[i]);
804  }
805 
806  PacketRecycle(p);
807  FlowShutdown();
808  SCFree(p);
809  PASS;
810 }
811 
812 /**\test icmpv6 message type: echo request, valid packet
813  * \retval retval 0 = Error ; 1 = ok
814  */
815 static int ICMPV6EchoReqTest01(void)
816 {
817  static uint8_t raw_ipv6[] = {
818  0x60, 0x00, 0x00, 0x00, 0x00, 0x08, 0x3a, 0xff,
819  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
820  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
821  0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
822  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
823  0x80, 0x00, 0xe5, 0xa5, 0x25, 0xf0, 0x75, 0x23 };
824 
825  Packet *p = PacketGetFromAlloc();
826  FAIL_IF_NULL(p);
827  IPV6Hdr ip6h;
828  ThreadVars tv;
830 
831  memset(&tv, 0, sizeof(ThreadVars));
832  memset(&dtv, 0, sizeof(DecodeThreadVars));
833  memset(&ip6h, 0, sizeof(IPV6Hdr));
834 
836  DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6));
837 
838  FAIL_IF_NULL(p->icmpv6h);
839 
840  SCLogDebug("ID: %u seq: %u", ICMPV6_GET_ID(p), ICMPV6_GET_SEQ(p));
841 
842  if (ICMPV6_GET_TYPE(p) != 128 || ICMPV6_GET_CODE(p) != 0 ||
843  SCNtohs(ICMPV6_GET_ID(p)) != 9712 || SCNtohs(ICMPV6_GET_SEQ(p)) != 29987) {
844  printf("ICMPv6 Echo reply decode failed TYPE %u CODE %u ID %04x(%u) SEQ %04x(%u): ",
847  FAIL;
848  }
849 
850  PacketRecycle(p);
851  FlowShutdown();
852  SCFree(p);
853  PASS;
854 }
855 
856 /**\test icmpv6 message type: echo reply, valid packet
857  * \retval retval 0 = Error ; 1 = ok
858  */
859 static int ICMPV6EchoRepTest01(void)
860 {
861  static uint8_t raw_ipv6[] = {
862  0x60, 0x00, 0x00, 0x00, 0x00, 0x08, 0x3a,
863  0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
864  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
865  0x00, 0x00, 0x00, 0xff, 0x02, 0x00, 0x00,
866  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
867  0x00, 0x00, 0x00, 0x00, 0x01, 0x81, 0x00,
868  0xe5, 0xa5, 0x25, 0xf0, 0x75, 0x23 };
869 
870  Packet *p = PacketGetFromAlloc();
871  FAIL_IF_NULL(p);
872  IPV6Hdr ip6h;
873  ThreadVars tv;
875 
876  memset(&tv, 0, sizeof(ThreadVars));
877  memset(&dtv, 0, sizeof(DecodeThreadVars));
878  memset(&ip6h, 0, sizeof(IPV6Hdr));
879 
881  DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6));
882 
883  FAIL_IF_NULL(p->icmpv6h);
884 
885  SCLogDebug("type: %u code %u ID: %u seq: %u", ICMPV6_GET_TYPE(p),
887 
888  if (ICMPV6_GET_TYPE(p) != 129 || ICMPV6_GET_CODE(p) != 0 ||
889  SCNtohs(ICMPV6_GET_ID(p)) != 9712 || SCNtohs(ICMPV6_GET_SEQ(p)) != 29987) {
890  printf("ICMPv6 Echo reply decode failed TYPE %u CODE %u ID %04x(%u) SEQ %04x(%u): ",
893  FAIL;
894  }
895 
896  PacketRecycle(p);
897  FlowShutdown();
898  SCFree(p);
899  PASS;
900 }
901 
902 /** \test icmpv6 message type: parameter problem, invalid packet
903  * \brief set the event ICMPV6_IPV6_UNKNOWN_VER properly when the embedded packet has an unknown version
904  * \retval retval 0 = Error ; 1 = ok
905  */
906 static int ICMPV6ParamProbTest02(void)
907 {
908  static uint8_t raw_ipv6[] = {
909  0x60, 0x00, 0x00, 0x00, 0x00, 0x38, 0x3a, 0xff,
910  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
911  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
912  0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
913  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
914  0x04, 0x00, 0xcc, 0x2a, 0x6d, 0x93, 0x0b, 0xdf,
915  0x38, 0x70, 0x12, 0xb7, 0x00, 0x08, 0x3a, 0xff,
916  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
917  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
918  0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
919  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
920  0x80, 0x00, 0x08, 0xb5, 0x99, 0xc3, 0xde, 0x40 };
921 
922  Packet *p = PacketGetFromAlloc();
923  FAIL_IF_NULL(p);
924  IPV6Hdr ip6h;
925  ThreadVars tv;
927 
928  memset(&tv, 0, sizeof(ThreadVars));
929  memset(&dtv, 0, sizeof(DecodeThreadVars));
930  memset(&ip6h, 0, sizeof(IPV6Hdr));
931 
933  DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6));
934 
935  FAIL_IF_NULL(p->icmpv6h);
936  FAIL_IF(ICMPV6_GET_TYPE(p) != 4 || ICMPV6_GET_CODE(p) != 0);
938 
939  PacketRecycle(p);
940  FlowShutdown();
941  SCFree(p);
942  PASS;
943 }
944 
945 /** \test icmpv6 message type: packet too big, invalid packet
946  * \brief Set the event ICMPV6_UNKNOWN_CODE if code is invalid for this type
947  * \retval retval 0 = Error ; 1 = ok
948  */
949 static int ICMPV6PktTooBigTest02(void)
950 {
951  static uint8_t raw_ipv6[] = {
952  0x60, 0x00, 0x00, 0x00, 0x00, 0x30, 0x3a, 0xff,
953  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
954  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
955  0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
956  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
957  0x02, 0x10, 0x5c, 0x7a, 0x00, 0x00, 0x05, 0x00,
958  0x64, 0x14, 0xfd, 0xff, 0x00, 0x00, 0x3b, 0xff,
959  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
960  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
961  0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
962  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 };
963 
964  Packet *p = PacketGetFromAlloc();
965  FAIL_IF_NULL(p);
966  IPV6Hdr ip6h;
967  ThreadVars tv;
969 
970  memset(&tv, 0, sizeof(ThreadVars));
971  memset(&dtv, 0, sizeof(DecodeThreadVars));
972  memset(&ip6h, 0, sizeof(IPV6Hdr));
973 
975  DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6));
976 
977  FAIL_IF_NULL(p->icmpv6h);
979 
980  PacketRecycle(p);
981  FlowShutdown();
982  SCFree(p);
983  PASS;
984 }
985 
986 /** \test icmpv6 message type: time exceed, invalid packet
987  * \brief set the event ICMPV6_PKT_TOO_SMALL properly
988  * \retval retval 0 = Error ; 1 = ok
989  */
990 static int ICMPV6TimeExceedTest02(void)
991 {
992  static uint8_t raw_ipv6[] = {
993  0x60, 0x00, 0x00, 0x00, 0x00, 0x03, 0x3a, 0xff,
994  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
995  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
996  0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
997  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
998  0x02, 0x10, 0x5c };
999 
1000  /* The icmpv6 header is broken in the checksum (so we dont have a complete header) */
1001 
1002  Packet *p = PacketGetFromAlloc();
1003  FAIL_IF_NULL(p);
1004  IPV6Hdr ip6h;
1005  ThreadVars tv;
1007 
1008  memset(&tv, 0, sizeof(ThreadVars));
1009  memset(&dtv, 0, sizeof(DecodeThreadVars));
1010  memset(&ip6h, 0, sizeof(IPV6Hdr));
1011 
1013  DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6));
1014 
1016 
1017  PacketRecycle(p);
1018  FlowShutdown();
1019  SCFree(p);
1020  PASS;
1021 }
1022 
1023 /**\test icmpv6 message type: destination unreach, invalid packet
1024  * \brief The embedded packet header (ipv6) is truncated
1025  * \retval retval 0 = Error ; 1 = ok
1026  */
1027 static int ICMPV6DestUnreachTest02(void)
1028 {
1029  static uint8_t raw_ipv6[] = {
1030  0x60, 0x00, 0x00, 0x00, 0x00, 0x2d, 0x3a, 0xff,
1031  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1032  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1033  0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1034  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
1035  0x01, 0x00, 0x7b, 0x85, 0x00, 0x00, 0x00, 0x00,
1036  0x60, 0x4b, 0xe8, 0xbd, 0x00, 0x00, 0x3b, 0xff,
1037  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1038  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1039  0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1040  0x00, 0x00, 0x00, 0x00, 0x00 };
1041 
1042  Packet *p = PacketGetFromAlloc();
1043  FAIL_IF_NULL(p);
1044  IPV6Hdr ip6h;
1045  ThreadVars tv;
1047 
1048  memset(&tv, 0, sizeof(ThreadVars));
1049  memset(&dtv, 0, sizeof(DecodeThreadVars));
1050  memset(&ip6h, 0, sizeof(IPV6Hdr));
1051 
1053  DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6));
1054 
1056 
1057  PacketRecycle(p);
1058  FlowShutdown();
1059  SCFree(p);
1060  PASS;
1061 }
1062 
1063 /**\test icmpv6 message type: echo request, invalid packet
1064  * \brief unknown code
1065  * \retval retval 0 = Error ; 1 = ok
1066  */
1067 static int ICMPV6EchoReqTest02(void)
1068 {
1069  static uint8_t raw_ipv6[] = {
1070  0x60, 0x00, 0x00, 0x00, 0x00, 0x08, 0x3a,
1071  0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1072  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1073  0x00, 0x00, 0x00, 0xff, 0x02, 0x00, 0x00,
1074  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1075  0x00, 0x00, 0x00, 0x00, 0x01, 0x80, 0x01,
1076  0xe5, 0xa5, 0x25, 0xf0, 0x75, 0x23 };
1077 
1078  Packet *p = PacketGetFromAlloc();
1079  FAIL_IF_NULL(p);
1080  IPV6Hdr ip6h;
1081  ThreadVars tv;
1083 
1084  memset(&tv, 0, sizeof(ThreadVars));
1085  memset(&dtv, 0, sizeof(DecodeThreadVars));
1086  memset(&ip6h, 0, sizeof(IPV6Hdr));
1087 
1089  DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6));
1090 
1092 
1093  PacketRecycle(p);
1094  FlowShutdown();
1095  SCFree(p);
1096  PASS;
1097 }
1098 
1099 /**\test icmpv6 message type: echo reply, invalid packet
1100  * \brief unknown code
1101  * \retval retval 0 = Error ; 1 = ok
1102  */
1103 static int ICMPV6EchoRepTest02(void)
1104 {
1105  static uint8_t raw_ipv6[] = {
1106  0x60, 0x00, 0x00, 0x00, 0x00, 0x08, 0x3a,
1107  0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1108  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1109  0x00, 0x00, 0x00, 0xff, 0x02, 0x00, 0x00,
1110  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1111  0x00, 0x00, 0x00, 0x00, 0x01, 0x81, 0x01,
1112  0xe5, 0xa5, 0x25, 0xf0, 0x75, 0x23 };
1113 
1114  Packet *p = PacketGetFromAlloc();
1115  FAIL_IF_NULL(p);
1116  IPV6Hdr ip6h;
1117  ThreadVars tv;
1119 
1120  memset(&tv, 0, sizeof(ThreadVars));
1121  memset(&dtv, 0, sizeof(DecodeThreadVars));
1122  memset(&ip6h, 0, sizeof(IPV6Hdr));
1123 
1125  DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6));
1126 
1128 
1129  PacketRecycle(p);
1130  FlowShutdown();
1131  SCFree(p);
1132  PASS;
1133 }
1134 
1135 /**\test icmpv6 packet decoding and setting up of payload_len and payload buffer
1136  * \retval retval 0 = Error ; 1 = ok
1137  */
1138 static int ICMPV6PayloadTest01(void)
1139 {
1140  static uint8_t raw_ipv6[] = {
1141  0x60, 0x00, 0x00, 0x00, 0x00, 0x2d, 0x3a, 0xff,
1142  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1143  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1144  0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1145  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
1146  0x01, 0x00, 0x7b, 0x85, 0x00, 0x00, 0x00, 0x00,
1147  0x60, 0x4b, 0xe8, 0xbd, 0x00, 0x00, 0x3b, 0xff,
1148  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1149  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1150  0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1151  0x00, 0x00, 0x00, 0x00, 0x00 };
1152 
1153  Packet *p = PacketGetFromAlloc();
1154  FAIL_IF_NULL(p);
1155  IPV6Hdr ip6h;
1156  ThreadVars tv;
1158 
1159  memset(&tv, 0, sizeof(ThreadVars));
1160  memset(&dtv, 0, sizeof(DecodeThreadVars));
1161  memset(&ip6h, 0, sizeof(IPV6Hdr));
1162 
1164  DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6));
1165 
1166  FAIL_IF_NULL(p->payload);
1167  FAIL_IF(p->payload_len != 37);
1168 
1169  PacketRecycle(p);
1170  FlowShutdown();
1171  SCFree(p);
1172  PASS;
1173 }
1174 
1175 static int ICMPV6RouterSolicitTestKnownCode(void)
1176 {
1177  static uint8_t raw_ipv6[] = {
1178  0x60, 0x00, 0x00, 0x00, 0x00, 0x08, 0x3a, 0xff,
1179  0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1180  0x02, 0x24, 0x8c, 0xff, 0xfe, 0x0e, 0x31, 0x54,
1181  0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1182  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
1183  0x85, 0x00, 0xbe, 0xb0, 0x00, 0x00, 0x00, 0x00
1184  };
1185 
1186  Packet *p = PacketGetFromAlloc();
1187  FAIL_IF_NULL(p);
1188  IPV6Hdr ip6h;
1189  ThreadVars tv;
1191 
1192  memset(&tv, 0, sizeof(ThreadVars));
1193  memset(&dtv, 0, sizeof(DecodeThreadVars));
1194  memset(&ip6h, 0, sizeof(IPV6Hdr));
1195 
1197  DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6));
1198 
1200 
1201  PacketRecycle(p);
1202  FlowShutdown();
1203  SCFree(p);
1204  PASS;
1205 }
1206 
1207 static int ICMPV6RouterSolicitTestUnknownCode(void)
1208 {
1209  static uint8_t raw_ipv6[] = {
1210  0x60, 0x00, 0x00, 0x00, 0x00, 0x08, 0x3a, 0xff,
1211  0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1212  0x02, 0x24, 0x8c, 0xff, 0xfe, 0x0e, 0x31, 0x54,
1213  0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1214  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
1215  0x85, 0x01, 0xbe, 0xaf, 0x00, 0x00, 0x00, 0x00
1216  };
1217 
1218  Packet *p = PacketGetFromAlloc();
1219  FAIL_IF_NULL(p);
1220  IPV6Hdr ip6h;
1221  ThreadVars tv;
1223 
1224  memset(&tv, 0, sizeof(ThreadVars));
1225  memset(&dtv, 0, sizeof(DecodeThreadVars));
1226  memset(&ip6h, 0, sizeof(IPV6Hdr));
1227 
1229  DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6));
1230 
1232 
1233  PacketRecycle(p);
1234  FlowShutdown();
1235  SCFree(p);
1236  PASS;
1237 }
1238 
1239 static int ICMPV6RouterAdvertTestKnownCode(void)
1240 {
1241  static uint8_t raw_ipv6[] = {
1242  0x60, 0x00, 0x00, 0x00, 0x00, 0x08, 0x3a, 0xff,
1243  0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1244  0x02, 0x24, 0x8c, 0xff, 0xfe, 0x0e, 0x31, 0x54,
1245  0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1246  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
1247  0x86, 0x00, 0xbd, 0xb0, 0x00, 0x00, 0x00, 0x00
1248  };
1249 
1250  Packet *p = PacketGetFromAlloc();
1251  FAIL_IF_NULL(p);
1252  IPV6Hdr ip6h;
1253  ThreadVars tv;
1255 
1256  memset(&tv, 0, sizeof(ThreadVars));
1257  memset(&dtv, 0, sizeof(DecodeThreadVars));
1258  memset(&ip6h, 0, sizeof(IPV6Hdr));
1259 
1261  DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6));
1262 
1264 
1265  PacketRecycle(p);
1266  FlowShutdown();
1267  SCFree(p);
1268  PASS;
1269 }
1270 
1271 static int ICMPV6RouterAdvertTestUnknownCode(void)
1272 {
1273  static uint8_t raw_ipv6[] = {
1274  0x60, 0x00, 0x00, 0x00, 0x00, 0x08, 0x3a, 0xff,
1275  0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1276  0x02, 0x24, 0x8c, 0xff, 0xfe, 0x0e, 0x31, 0x54,
1277  0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1278  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
1279  0x86, 0x01, 0xbd, 0xaf, 0x00, 0x00, 0x00, 0x00
1280  };
1281 
1282  Packet *p = PacketGetFromAlloc();
1283  FAIL_IF_NULL(p);
1284  IPV6Hdr ip6h;
1285  ThreadVars tv;
1287 
1288  memset(&tv, 0, sizeof(ThreadVars));
1289  memset(&dtv, 0, sizeof(DecodeThreadVars));
1290  memset(&ip6h, 0, sizeof(IPV6Hdr));
1291 
1293  DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6));
1294 
1296 
1297  PacketRecycle(p);
1298  FlowShutdown();
1299  SCFree(p);
1300  PASS;
1301 }
1302 
1303 static int ICMPV6NeighbourSolicitTestKnownCode(void)
1304 {
1305  static uint8_t raw_ipv6[] = {
1306  0x60, 0x00, 0x00, 0x00, 0x00, 0x08, 0x3a, 0xff,
1307  0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1308  0x02, 0x24, 0x8c, 0xff, 0xfe, 0x0e, 0x31, 0x54,
1309  0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1310  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
1311  0x87, 0x00, 0xbc, 0xb0, 0x00, 0x00, 0x00, 0x00
1312  };
1313 
1314  Packet *p = PacketGetFromAlloc();
1315  FAIL_IF_NULL(p);
1316  IPV6Hdr ip6h;
1317  ThreadVars tv;
1319 
1320  memset(&tv, 0, sizeof(ThreadVars));
1321  memset(&dtv, 0, sizeof(DecodeThreadVars));
1322  memset(&ip6h, 0, sizeof(IPV6Hdr));
1323 
1325  DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6));
1326 
1328 
1329  PacketRecycle(p);
1330  FlowShutdown();
1331  SCFree(p);
1332  PASS;
1333 }
1334 
1335 static int ICMPV6NeighbourSolicitTestUnknownCode(void)
1336 {
1337  static uint8_t raw_ipv6[] = {
1338  0x60, 0x00, 0x00, 0x00, 0x00, 0x08, 0x3a, 0xff,
1339  0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1340  0x02, 0x24, 0x8c, 0xff, 0xfe, 0x0e, 0x31, 0x54,
1341  0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1342  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
1343  0x87, 0x01, 0xbc, 0xaf, 0x00, 0x00, 0x00, 0x00
1344  };
1345 
1346  Packet *p = PacketGetFromAlloc();
1347  FAIL_IF_NULL(p);
1348  IPV6Hdr ip6h;
1349  ThreadVars tv;
1351 
1352  memset(&tv, 0, sizeof(ThreadVars));
1353  memset(&dtv, 0, sizeof(DecodeThreadVars));
1354  memset(&ip6h, 0, sizeof(IPV6Hdr));
1355 
1357  DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6));
1358 
1360 
1361  PacketRecycle(p);
1362  FlowShutdown();
1363  SCFree(p);
1364  PASS;
1365 }
1366 
1367 static int ICMPV6NeighbourAdvertTestKnownCode(void)
1368 {
1369  static uint8_t raw_ipv6[] = {
1370  0x60, 0x00, 0x00, 0x00, 0x00, 0x08, 0x3a, 0xff,
1371  0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1372  0x02, 0x24, 0x8c, 0xff, 0xfe, 0x0e, 0x31, 0x54,
1373  0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1374  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
1375  0x88, 0x00, 0xbb, 0xb0, 0x00, 0x00, 0x00, 0x00
1376  };
1377 
1378  Packet *p = PacketGetFromAlloc();
1379  FAIL_IF_NULL(p);
1380  IPV6Hdr ip6h;
1381  ThreadVars tv;
1383 
1384  memset(&tv, 0, sizeof(ThreadVars));
1385  memset(&dtv, 0, sizeof(DecodeThreadVars));
1386  memset(&ip6h, 0, sizeof(IPV6Hdr));
1387 
1389  DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6));
1390 
1392 
1393  PacketRecycle(p);
1394  FlowShutdown();
1395  SCFree(p);
1396  PASS;
1397 }
1398 
1399 static int ICMPV6NeighbourAdvertTestUnknownCode(void)
1400 {
1401  static uint8_t raw_ipv6[] = {
1402  0x60, 0x00, 0x00, 0x00, 0x00, 0x08, 0x3a, 0xff,
1403  0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1404  0x02, 0x24, 0x8c, 0xff, 0xfe, 0x0e, 0x31, 0x54,
1405  0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1406  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
1407  0x88, 0x01, 0xbb, 0xaf, 0x00, 0x00, 0x00, 0x00
1408  };
1409 
1410  Packet *p = PacketGetFromAlloc();
1411  FAIL_IF_NULL(p);
1412  IPV6Hdr ip6h;
1413  ThreadVars tv;
1415 
1416  memset(&tv, 0, sizeof(ThreadVars));
1417  memset(&dtv, 0, sizeof(DecodeThreadVars));
1418  memset(&ip6h, 0, sizeof(IPV6Hdr));
1419 
1421  DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6));
1422 
1424 
1425  PacketRecycle(p);
1426  FlowShutdown();
1427  SCFree(p);
1428  PASS;
1429 }
1430 
1431 static int ICMPV6RedirectTestKnownCode(void)
1432 {
1433  static uint8_t raw_ipv6[] = {
1434  0x60, 0x00, 0x00, 0x00, 0x00, 0x08, 0x3a, 0xff,
1435  0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1436  0x02, 0x24, 0x8c, 0xff, 0xfe, 0x0e, 0x31, 0x54,
1437  0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1438  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
1439  0x89, 0x00, 0xba, 0xb0, 0x00, 0x00, 0x00, 0x00
1440  };
1441 
1442  Packet *p = PacketGetFromAlloc();
1443  FAIL_IF_NULL(p);
1444  IPV6Hdr ip6h;
1445  ThreadVars tv;
1447 
1448  memset(&tv, 0, sizeof(ThreadVars));
1449  memset(&dtv, 0, sizeof(DecodeThreadVars));
1450  memset(&ip6h, 0, sizeof(IPV6Hdr));
1451 
1453  DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6));
1454 
1456 
1457  PacketRecycle(p);
1458  FlowShutdown();
1459  SCFree(p);
1460  PASS;
1461 }
1462 
1463 static int ICMPV6RedirectTestUnknownCode(void)
1464 {
1465  static uint8_t raw_ipv6[] = {
1466  0x60, 0x00, 0x00, 0x00, 0x00, 0x08, 0x3a, 0xff,
1467  0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1468  0x02, 0x24, 0x8c, 0xff, 0xfe, 0x0e, 0x31, 0x54,
1469  0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1470  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
1471  0x89, 0x01, 0xba, 0xaf, 0x00, 0x00, 0x00, 0x00
1472  };
1473 
1474  Packet *p = PacketGetFromAlloc();
1475  FAIL_IF_NULL(p);
1476  IPV6Hdr ip6h;
1477  ThreadVars tv;
1479 
1480  memset(&tv, 0, sizeof(ThreadVars));
1481  memset(&dtv, 0, sizeof(DecodeThreadVars));
1482  memset(&ip6h, 0, sizeof(IPV6Hdr));
1483 
1485  DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6));
1486 
1488 
1489  PacketRecycle(p);
1490  FlowShutdown();
1491  SCFree(p);
1492  PASS;
1493 }
1494 
1495 /**
1496  * \test Test for valid ICMPv6 checksum when the FCS is still attached.
1497  *
1498  * Tests that the packet is decoded with sufficient info to verify the
1499  * checksum even if the packet has some trailing data like an ethernet
1500  * FCS.
1501  */
1502 static int ICMPV6CalculateValidChecksumWithFCS(void)
1503 {
1504  /* IPV6/ICMPv6 packet with ethernet header.
1505  * - IPv6 payload length: 36
1506  */
1507  uint8_t raw_ipv6[] = {
1508  0x33, 0x33, 0x00, 0x00, 0x00, 0x16, 0x00, 0x50,
1509  0x56, 0xa6, 0x6a, 0x7d, 0x86, 0xdd, 0x60, 0x00,
1510  0x00, 0x00, 0x00, 0x24, 0x00, 0x01, 0xfe, 0x80,
1511  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf5, 0x09,
1512  0xad, 0x44, 0x49, 0x38, 0x5f, 0xa9, 0xff, 0x02,
1513  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1514  0x00, 0x00, 0x00, 0x00, 0x00, 0x16, 0x3a, 0x00,
1515  0x05, 0x02, 0x00, 0x00, 0x01, 0x00, 0x8f, 0x00,
1516  0x24, 0xe0, 0x00, 0x00, 0x00, 0x01, 0x03, 0x00, /* Checksum: 0x24e0. */
1517  0x00, 0x00, 0xff, 0x02, 0x00, 0x00, 0x00, 0x00,
1518  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1519  0x00, 0xfb, 0x1f, 0x34, 0xf6, 0xa4
1520  };
1521  uint16_t csum = *(((uint16_t *)(raw_ipv6 + 64)));
1522 
1523  Packet *p = PacketGetFromAlloc();
1524  FAIL_IF_NULL(p);
1525  ThreadVars tv;
1527 
1528  memset(&tv, 0, sizeof(ThreadVars));
1529  memset(&dtv, 0, sizeof(DecodeThreadVars));
1530 
1532  DecodeIPV6(&tv, &dtv, p, raw_ipv6 + 14, sizeof(raw_ipv6) - 14);
1533  FAIL_IF_NULL(p->icmpv6h);
1534 
1535  uint16_t icmpv6_len = IPV6_GET_RAW_PLEN(p->ip6h) -
1536  ((uint8_t *)p->icmpv6h - (uint8_t *)p->ip6h - IPV6_HEADER_LEN);
1537  FAIL_IF(icmpv6_len != 28);
1538  FAIL_IF(ICMPV6CalculateChecksum(p->ip6h->s_ip6_addrs,
1539  (uint16_t *)p->icmpv6h, icmpv6_len) != csum);
1540 
1541  PacketRecycle(p);
1542  FlowShutdown();
1543  SCFree(p);
1544  PASS;
1545 }
1546 
1547 #endif /* UNITTESTS */
1548 /**
1549  * \brief Registers ICMPV6 unit tests
1550  * \todo More ICMPv6 tests
1551  */
1553 {
1554 #ifdef UNITTESTS
1555  UtRegisterTest("ICMPV6CalculateValidChecksumtest01",
1556  ICMPV6CalculateValidChecksumtest01);
1557  UtRegisterTest("ICMPV6CalculateInvalidChecksumtest02", ICMPV6CalculateInvalidChecksumtest02);
1558 
1559  UtRegisterTest("ICMPV6ParamProbTest01 (Valid)", ICMPV6ParamProbTest01);
1560  UtRegisterTest("ICMPV6DestUnreachTest01 (Valid)", ICMPV6DestUnreachTest01);
1561  UtRegisterTest("ICMPV6PktTooBigTest01 (Valid)", ICMPV6PktTooBigTest01);
1562  UtRegisterTest("ICMPV6TimeExceedTest01 (Valid)", ICMPV6TimeExceedTest01);
1563  UtRegisterTest("ICMPV6EchoReqTest01 (Valid)", ICMPV6EchoReqTest01);
1564  UtRegisterTest("ICMPV6EchoRepTest01 (Valid)", ICMPV6EchoRepTest01);
1565 
1566  UtRegisterTest("ICMPV6ParamProbTest02 (Invalid)", ICMPV6ParamProbTest02);
1567  UtRegisterTest("ICMPV6DestUnreachTest02 (Invalid)",
1568  ICMPV6DestUnreachTest02);
1569  UtRegisterTest("ICMPV6PktTooBigTest02 (Invalid)", ICMPV6PktTooBigTest02);
1570  UtRegisterTest("ICMPV6TimeExceedTest02 (Invalid)", ICMPV6TimeExceedTest02);
1571  UtRegisterTest("ICMPV6EchoReqTest02 (Invalid)", ICMPV6EchoReqTest02);
1572  UtRegisterTest("ICMPV6EchoRepTest02 (Invalid)", ICMPV6EchoRepTest02);
1573 
1574  UtRegisterTest("ICMPV6PayloadTest01", ICMPV6PayloadTest01);
1575 
1576  UtRegisterTest("ICMPV6RouterSolicitTestKnownCode",
1577  ICMPV6RouterSolicitTestKnownCode);
1578  UtRegisterTest("ICMPV6RouterSolicitTestUnknownCode",
1579  ICMPV6RouterSolicitTestUnknownCode);
1580  UtRegisterTest("ICMPV6RouterAdvertTestKnownCode",
1581  ICMPV6RouterAdvertTestKnownCode);
1582  UtRegisterTest("ICMPV6RouterAdvertTestUnknownCode",
1583  ICMPV6RouterAdvertTestUnknownCode);
1584 
1585  UtRegisterTest("ICMPV6NeighbourSolicitTestKnownCode",
1586  ICMPV6NeighbourSolicitTestKnownCode);
1587  UtRegisterTest("ICMPV6NeighbourSolicitTestUnknownCode",
1588  ICMPV6NeighbourSolicitTestUnknownCode);
1589  UtRegisterTest("ICMPV6NeighbourAdvertTestKnownCode",
1590  ICMPV6NeighbourAdvertTestKnownCode);
1591  UtRegisterTest("ICMPV6NeighbourAdvertTestUnknownCode",
1592  ICMPV6NeighbourAdvertTestUnknownCode);
1593 
1594  UtRegisterTest("ICMPV6RedirectTestKnownCode", ICMPV6RedirectTestKnownCode);
1595  UtRegisterTest("ICMPV6RedirectTestUnknownCode",
1596  ICMPV6RedirectTestUnknownCode);
1597  UtRegisterTest("ICMPV6CalculateValidChecksumWithFCS",
1598  ICMPV6CalculateValidChecksumWithFCS);
1599 #endif /* UNITTESTS */
1600 }
1601 /**
1602  * @}
1603  */
ICMPV6Vars_::emb_ip6_src
uint32_t emb_ip6_src[4]
Definition: decode-icmpv6.h:175
ENGINE_SET_EVENT
#define ENGINE_SET_EVENT(p, e)
Definition: decode.h:904
Packet_::proto
uint8_t proto
Definition: decode.h:459
MLD_LISTENER_QUERY
#define MLD_LISTENER_QUERY
Definition: decode-icmpv6.h:45
len
uint8_t len
Definition: app-layer-dnp3.h:2
TCPHdr_::th_dport
uint16_t th_dport
Definition: decode-tcp.h:144
FAIL_IF_NULL
#define FAIL_IF_NULL(expr)
Fail a test if expression evaluates to NULL.
Definition: util-unittest.h:89
HOME_AGENT_AD_REQUEST
#define HOME_AGENT_AD_REQUEST
Definition: decode-icmpv6.h:61
UDPHdr_::uh_dport
uint16_t uh_dport
Definition: decode-udp.h:44
Packet_::icmp_s
struct Packet_::@31::@41 icmp_s
IPV6_GET_RAW_PLEN
#define IPV6_GET_RAW_PLEN(ip6h)
Definition: decode-ipv6.h:66
ICMPV6Hdr_::type
uint8_t type
Definition: decode-icmpv6.h:145
StatsIncr
void StatsIncr(ThreadVars *tv, uint16_t id)
Increments the local counter.
Definition: counters.c:167
IPV6_GET_RAW_HLIM
#define IPV6_GET_RAW_HLIM(ip6h)
Definition: decode-ipv6.h:67
CERT_PATH_SOLICIT
#define CERT_PATH_SOLICIT
Definition: decode-icmpv6.h:65
IPV6_GET_RAW_NH
#define IPV6_GET_RAW_NH(ip6h)
Definition: decode-ipv6.h:65
ICMP6_PACKET_TOO_BIG
#define ICMP6_PACKET_TOO_BIG
Definition: decode-icmpv6.h:37
unlikely
#define unlikely(expr)
Definition: util-optimize.h:35
ICMPV6Vars_::emb_tcph
TCPHdr * emb_tcph
Definition: decode-icmpv6.h:170
UtRegisterTest
void UtRegisterTest(const char *name, int(*TestFn)(void))
Register unit test.
Definition: util-unittest.c:103
ICMPV6Info_::id
uint16_t id
Definition: decode-icmpv6.h:138
ENGINE_ISSET_EVENT
#define ENGINE_ISSET_EVENT(p, e)
Definition: decode.h:919
MLD_LISTENER_REPORT
#define MLD_LISTENER_REPORT
Definition: decode-icmpv6.h:46
ICMPv6GetCounterpart
int ICMPv6GetCounterpart(uint8_t type)
Definition: decode-icmpv6.c:146
SCLogDebug
#define SCLogDebug(...)
Definition: util-debug.h:269
MC_ROUTER_ADVERT
#define MC_ROUTER_ADVERT
Definition: decode-icmpv6.h:68
MC_ROUTER_TERMINATE
#define MC_ROUTER_TERMINATE
Definition: decode-icmpv6.h:70
HOME_AGENT_AD_REPLY
#define HOME_AGENT_AD_REPLY
Definition: decode-icmpv6.h:62
TCP_HEADER_LEN
#define TCP_HEADER_LEN
Definition: decode-tcp.h:28
ICMPV6_UNKNOWN_CODE
@ ICMPV6_UNKNOWN_CODE
Definition: decode-events.h:56
ICMP6_MOBILE_EXPERIMENTAL
#define ICMP6_MOBILE_EXPERIMENTAL
Definition: decode-icmpv6.h:67
DUPL_ADDR_REQUEST
#define DUPL_ADDR_REQUEST
Definition: decode-icmpv6.h:74
Packet_::payload
uint8_t * payload
Definition: decode.h:586
PacketRecycle
void PacketRecycle(Packet *p)
Definition: packet.c:169
ICMPV6_GET_SEQ
#define ICMPV6_GET_SEQ(p)
Definition: decode-icmpv6.h:112
IPV6_GET_RAW_CLASS
#define IPV6_GET_RAW_CLASS(ip6h)
Definition: decode-ipv6.h:63
Packet_::icmp_d
struct Packet_::@33::@42 icmp_d
MOBILE_PREFIX_ADVERT
#define MOBILE_PREFIX_ADVERT
Definition: decode-icmpv6.h:64
ICMPV6_GET_CODE
#define ICMPV6_GET_CODE(p)
Definition: decode-icmpv6.h:103
ICMP6_TIME_EXCEEDED
#define ICMP6_TIME_EXCEEDED
Definition: decode-icmpv6.h:38
ICMPV6_IPV6_UNKNOWN_VER
@ ICMPV6_IPV6_UNKNOWN_VER
Definition: decode-events.h:58
ICMP6_TIME_EXCEED_REASSEMBLY
#define ICMP6_TIME_EXCEED_REASSEMBLY
Definition: decode-icmpv6.h:92
ICMP6_DST_UNREACH_REJECTROUTE
#define ICMP6_DST_UNREACH_REJECTROUTE
Definition: decode-icmpv6.h:87
ICMPV6_GET_ID
#define ICMPV6_GET_ID(p)
Definition: decode-icmpv6.h:110
ICMP6_NI_QUERY
#define ICMP6_NI_QUERY
Definition: decode-icmpv6.h:56
DUPL_ADDR_CONFIRM
#define DUPL_ADDR_CONFIRM
Definition: decode-icmpv6.h:75
ICMPV6_UNKNOWN_TYPE
@ ICMPV6_UNKNOWN_TYPE
Definition: decode-events.h:55
TM_ECODE_FAILED
@ TM_ECODE_FAILED
Definition: tm-threads-common.h:85
Packet_::payload_len
uint16_t payload_len
Definition: decode.h:587
ICMPV6Vars_::emb_sport
uint16_t emb_sport
Definition: decode-icmpv6.h:180
ICMP6_PARAM_PROB
#define ICMP6_PARAM_PROB
Definition: decode-icmpv6.h:39
util-unittest-helper.h
ICMP6_ECHO_REQUEST
#define ICMP6_ECHO_REQUEST
Definition: decode-icmpv6.h:42
TM_ECODE_OK
@ TM_ECODE_OK
Definition: tm-threads-common.h:84
CERT_PATH_ADVERT
#define CERT_PATH_ADVERT
Definition: decode-icmpv6.h:66
ND_NEIGHBOR_SOLICIT
#define ND_NEIGHBOR_SOLICIT
Definition: decode-icmpv6.h:51
FMIPV6_MSG
#define FMIPV6_MSG
Definition: decode-icmpv6.h:71
ICMPV6_UNASSIGNED_TYPE
@ ICMPV6_UNASSIGNED_TYPE
Definition: decode-events.h:61
ND_REDIRECT
#define ND_REDIRECT
Definition: decode-icmpv6.h:53
FlowInitConfig
void FlowInitConfig(bool quiet)
initialize the configuration
Definition: flow.c:537
TCPHdr_::th_sport
uint16_t th_sport
Definition: decode-tcp.h:143
ND_INVERSE_SOLICIT
#define ND_INVERSE_SOLICIT
Definition: decode-icmpv6.h:58
decode.h
PASS
#define PASS
Pass the test.
Definition: util-unittest.h:105
ICMP6_ECHO_REPLY
#define ICMP6_ECHO_REPLY
Definition: decode-icmpv6.h:43
ICMPV6Vars_::error_ptr
uint32_t error_ptr
Definition: decode-icmpv6.h:166
ICMPV6Hdr_::icmpv6b
union ICMPV6Hdr_::@23 icmpv6b
MLD_LISTENER_REDUCTION
#define MLD_LISTENER_REDUCTION
Definition: decode-icmpv6.h:47
util-print.h
ThreadVars_
Per thread variable structure.
Definition: threadvars.h:57
PrintInet
const char * PrintInet(int af, const void *src, char *dst, socklen_t size)
Definition: util-print.c:241
ICMPV6_IPV6_TRUNC_PKT
@ ICMPV6_IPV6_TRUNC_PKT
Definition: decode-events.h:59
ICMPV6_GET_MTU
#define ICMPV6_GET_MTU(p)
Definition: decode-icmpv6.h:123
decode-icmpv6.h
ICMPV6Vars_::emb_ip6_proto_next
uint8_t emb_ip6_proto_next
Definition: decode-icmpv6.h:177
ICMPV6Hdr_::code
uint8_t code
Definition: decode-icmpv6.h:146
Packet_::icmpv6h
ICMPV6Hdr * icmpv6h
Definition: decode.h:577
ICMPV6Info_::seq
uint16_t seq
Definition: decode-icmpv6.h:139
ICMP6_DST_UNREACH
#define ICMP6_DST_UNREACH
Definition: decode-icmpv6.h:36
IPV6Hdr_
Definition: decode-ipv6.h:32
Packet_
Definition: decode.h:437
type
uint16_t type
Definition: decode-vlan.c:107
DecodeIPV6
int DecodeIPV6(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, const uint8_t *pkt, uint16_t len)
Definition: decode-ipv6.c:564
ICMP6_RR
#define ICMP6_RR
Definition: decode-icmpv6.h:55
DecodeICMPV6RegisterTests
void DecodeICMPV6RegisterTests(void)
Registers ICMPV6 unit tests.
Definition: decode-icmpv6.c:1552
LOCATOR_UDATE_MSG
#define LOCATOR_UDATE_MSG
Definition: decode-icmpv6.h:73
ICMPV6Vars_::emb_dport
uint16_t emb_dport
Definition: decode-icmpv6.h:181
RPL_CONTROL_MSG
#define RPL_CONTROL_MSG
Definition: decode-icmpv6.h:72
dtv
DecodeThreadVars * dtv
Definition: fuzz_decodepcapfile.c:33
ICMPV6Vars_::emb_udph
UDPHdr * emb_udph
Definition: decode-icmpv6.h:171
ICMPV6Hdr_
Definition: decode-icmpv6.h:144
ICMPV6_MLD_MESSAGE_WITH_INVALID_HL
@ ICMPV6_MLD_MESSAGE_WITH_INVALID_HL
Definition: decode-events.h:60
ND_INVERSE_ADVERT
#define ND_INVERSE_ADVERT
Definition: decode-icmpv6.h:59
FAIL_IF
#define FAIL_IF(expr)
Fail a test if expression evaluates to true.
Definition: util-unittest.h:71
ICMPV6_GET_ERROR_PTR
#define ICMPV6_GET_ERROR_PTR(p)
Definition: decode-icmpv6.h:118
ICMPV6_EXPERIMENTATION_TYPE
@ ICMPV6_EXPERIMENTATION_TYPE
Definition: decode-events.h:62
SCNtohs
#define SCNtohs(x)
Definition: suricata-common.h:414
DecodeICMPV6
int DecodeICMPV6(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, const uint8_t *pkt, uint32_t len)
Decode ICMPV6 packets and fill the Packet with the decoded info.
Definition: decode-icmpv6.c:178
suricata-common.h
FlowShutdown
void FlowShutdown(void)
shutdown the flow engine
Definition: flow.c:685
packet.h
MPL_CONTROL_MSG
#define MPL_CONTROL_MSG
Definition: decode-icmpv6.h:76
IPV6_GET_RAW_FLOW
#define IPV6_GET_RAW_FLOW(ip6h)
Definition: decode-ipv6.h:64
ND_NEIGHBOR_ADVERT
#define ND_NEIGHBOR_ADVERT
Definition: decode-icmpv6.h:52
UDPHdr_::uh_sport
uint16_t uh_sport
Definition: decode-udp.h:43
ICMPV6_HEADER_LEN
#define ICMPV6_HEADER_LEN
Definition: decode-icmpv6.h:31
UDPHdr_
Definition: decode-udp.h:42
ICMPV6Vars_::seq
uint16_t seq
Definition: decode-icmpv6.h:164
ICMPV6_PKT_TOO_SMALL
@ ICMPV6_PKT_TOO_SMALL
Definition: decode-events.h:57
tv
ThreadVars * tv
Definition: fuzz_decodepcapfile.c:32
util-validate.h
PacketGetFromAlloc
Packet * PacketGetFromAlloc(void)
Get a malloced packet.
Definition: decode.c:229
ICMPV6Vars_::emb_ip6_dst
uint32_t emb_ip6_dst[4]
Definition: decode-icmpv6.h:176
ND_ROUTER_SOLICIT
#define ND_ROUTER_SOLICIT
Definition: decode-icmpv6.h:49
SCFree
#define SCFree(p)
Definition: util-mem.h:61
DecodeThreadVars_
Structure to hold thread specific data for all decode modules.
Definition: decode.h:685
ICMP6_NI_REPLY
#define ICMP6_NI_REPLY
Definition: decode-icmpv6.h:57
FAIL
#define FAIL
Fail a test.
Definition: util-unittest.h:60
ICMPV6_GET_TYPE
#define ICMPV6_GET_TYPE(p)
Definition: decode-icmpv6.h:101
ND_ROUTER_ADVERT
#define ND_ROUTER_ADVERT
Definition: decode-icmpv6.h:50
IPV6_GET_HLIM
#define IPV6_GET_HLIM(p)
Definition: decode-ipv6.h:90
MLD_V2_LIST_REPORT
#define MLD_V2_LIST_REPORT
Definition: decode-icmpv6.h:60
DecodeThreadVars_::counter_icmpv6
uint16_t counter_icmpv6
Definition: decode.h:709
UDP_HEADER_LEN
#define UDP_HEADER_LEN
Definition: decode-udp.h:27
ENGINE_SET_INVALID_EVENT
#define ENGINE_SET_INVALID_EVENT(p, e)
Definition: decode.h:912
FLOW_QUIET
#define FLOW_QUIET
Definition: flow.h:42
IPV6_HEADER_LEN
#define IPV6_HEADER_LEN
Definition: decode-ipv6.h:27
ICMPV6Vars_::mtu
uint32_t mtu
Definition: decode-icmpv6.h:165
ICMPV6Vars_::id
uint16_t id
Definition: decode-icmpv6.h:163
Packet_::ip6h
IPV6Hdr * ip6h
Definition: decode.h:547
Packet_::icmpv6vars
ICMPV6Vars icmpv6vars
Definition: decode.h:561
CASE_CODE
#define CASE_CODE(t, r)
flow.h
ICMPV6_GET_EMB_IPV6
#define ICMPV6_GET_EMB_IPV6(p)
Definition: decode-icmpv6.h:128
ICMPV6Hdr_::icmpv6i
ICMPV6Info icmpv6i
Definition: decode-icmpv6.h:150
MOBILE_PREFIX_SOLICIT
#define MOBILE_PREFIX_SOLICIT
Definition: decode-icmpv6.h:63
DEBUG_VALIDATE_BUG_ON
#define DEBUG_VALIDATE_BUG_ON(exp)
Definition: util-validate.h:103
FlowSetupPacket
void FlowSetupPacket(Packet *p)
prepare packet for a life with flow Set PKT_WANTS_FLOW flag to indicate workers should do a flow look...
Definition: flow-hash.c:520
TCPHdr_
Definition: decode-tcp.h:142
ICMPV6Vars_::emb_ipv6h
IPV6Hdr * emb_ipv6h
Definition: decode-icmpv6.h:169
ICMPV6Vars_::emb_icmpv6h
ICMPV6Hdr * emb_icmpv6h
Definition: decode-icmpv6.h:172
MC_ROUTER_SOLICIT
#define MC_ROUTER_SOLICIT
Definition: decode-icmpv6.h:69
ICMPV6_GET_EMB_PROTO
#define ICMPV6_GET_EMB_PROTO(p)
Definition: decode-icmpv6.h:126
ICMP6_PARAMPROB_OPTION
#define ICMP6_PARAMPROB_OPTION
Definition: decode-icmpv6.h:97