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