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