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