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  PacketFree(p);
633  FlowShutdown();
634  PASS;
635 }
636 
637 /** \test icmpv6 message type: packet too big, valid packet
638  *
639  * \retval retval 0 = Error ; 1 = ok
640  */
641 static int ICMPV6PktTooBigTest01(void)
642 {
643  static uint8_t raw_ipv6[] = {
644  0x60, 0x00, 0x00, 0x00, 0x00, 0x30, 0x3a, 0xff,
645  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
646  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
647  0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
648  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
649  0x02, 0x00, 0x5c, 0x7a, 0x00, 0x00, 0x05, 0x00,
650  0x64, 0x14, 0xfd, 0xff, 0x00, 0x00, 0x3b, 0xff,
651  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
652  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
653  0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
654  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 };
655 
656  Packet *p = PacketGetFromAlloc();
657  FAIL_IF_NULL(p);
658  IPV6Hdr ip6h;
659  ThreadVars tv;
661  uint32_t *ipv6src;
662  uint32_t *ipv6dst;
663  ipv6src = (uint32_t*) &raw_ipv6[8];
664  ipv6dst = (uint32_t*) &raw_ipv6[24];
665 
666  memset(&tv, 0, sizeof(ThreadVars));
667  memset(&dtv, 0, sizeof(DecodeThreadVars));
668  memset(&ip6h, 0, sizeof(IPV6Hdr));
669 
671  DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6));
672  FAIL_IF(!PacketIsICMPv6(p));
673 
674  /* Note: it has an embedded ipv6 packet but no protocol after ipv6
675  * (IPPROTO_NONE) */
676  /* Check if ICMPv6 header was processed at all. */
677  FAIL_IF(ICMPV6_GET_TYPE(PacketGetICMPv6(p)) != 2);
678  FAIL_IF(ICMPV6_GET_CODE(PacketGetICMPv6(p)) != 0);
679 
680  /* Let's check if we retrieved the embedded ipv6 addresses correctly */
681  for (int i = 0; i < 4; i++) {
682  FAIL_IF(PacketGetICMPv6EmbIPv6(p)->s_ip6_src[i] != ipv6src[i] ||
683  PacketGetICMPv6EmbIPv6(p)->s_ip6_dst[i] != ipv6dst[i]);
684  }
685 
686  SCLogDebug("ICMPV6 IPV6 src and dst properly set");
687 
688  PacketFree(p);
689  FlowShutdown();
690  PASS;
691 }
692 
693 /** \test icmpv6 message type: time exceed, valid packet
694  *
695  * \retval retval 0 = Error ; 1 = ok
696  */
697 static int ICMPV6TimeExceedTest01(void)
698 {
699  static uint8_t raw_ipv6[] = {
700  0x60, 0x00, 0x00, 0x00, 0x00, 0x30, 0x3a, 0xff,
701  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
702  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
703  0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
704  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
705  0x03, 0x00, 0x56, 0x2d, 0x00, 0x00, 0x00, 0x00,
706  0x6d, 0x23, 0xff, 0x3d, 0x00, 0x00, 0x3b, 0xff,
707  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
708  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
709  0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
710  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 };
711 
712  Packet *p = PacketGetFromAlloc();
713  FAIL_IF_NULL(p);
714  IPV6Hdr ip6h;
715  ThreadVars tv;
717  uint32_t *ipv6src;
718  uint32_t *ipv6dst;
719  ipv6src = (uint32_t*) &raw_ipv6[8];
720  ipv6dst = (uint32_t*) &raw_ipv6[24];
721 
722  memset(&tv, 0, sizeof(ThreadVars));
723  memset(&dtv, 0, sizeof(DecodeThreadVars));
724  memset(&ip6h, 0, sizeof(IPV6Hdr));
725 
727  DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6));
728  FAIL_IF(!PacketIsICMPv6(p));
729 
730  /* Note: it has an embedded ipv6 packet but no protocol after ipv6 (IPPROTO_NONE) */
731  FAIL_IF(ICMPV6_GET_TYPE(PacketGetICMPv6(p)) != 3);
732  FAIL_IF(ICMPV6_GET_CODE(PacketGetICMPv6(p)) != 0);
733  FAIL_IF_NULL(PacketGetICMPv6EmbIPv6(p));
734  FAIL_IF(ICMPV6_GET_EMB_PROTO(p) != IPPROTO_NONE);
735 
736  /* Let's check if we retrieved the embedded ipv6 addresses correctly */
737  for (int i = 0; i < 4; i++) {
738  FAIL_IF(PacketGetICMPv6EmbIPv6(p)->s_ip6_src[i] != ipv6src[i] ||
739  PacketGetICMPv6EmbIPv6(p)->s_ip6_dst[i] != ipv6dst[i]);
740  }
741 
742  SCLogDebug("ICMPV6 IPV6 src and dst properly set");
743 
744  PacketFree(p);
745  FlowShutdown();
746  PASS;
747 }
748 
749 /** \test icmpv6 message type: destination unreach, valid packet
750  *
751  * \retval retval 0 = Error ; 1 = ok
752  */
753 static int ICMPV6DestUnreachTest01(void)
754 {
755  static uint8_t raw_ipv6[] = {
756  0x60, 0x00, 0x00, 0x00, 0x00, 0x30, 0x3a, 0xff,
757  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
758  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
759  0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
760  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
761  0x01, 0x00, 0x7b, 0x85, 0x00, 0x00, 0x00, 0x00,
762  0x60, 0x4b, 0xe8, 0xbd, 0x00, 0x00, 0x3b, 0xff,
763  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
764  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
765  0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
766  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 };
767 
768  Packet *p = PacketGetFromAlloc();
769  FAIL_IF_NULL(p);
770  IPV6Hdr ip6h;
771  ThreadVars tv;
773  uint32_t *ipv6src;
774  uint32_t *ipv6dst;
775  ipv6src = (uint32_t*) &raw_ipv6[8];
776  ipv6dst = (uint32_t*) &raw_ipv6[24];
777 
778  memset(&tv, 0, sizeof(ThreadVars));
779  memset(&dtv, 0, sizeof(DecodeThreadVars));
780  memset(&ip6h, 0, sizeof(IPV6Hdr));
781 
783  DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6));
784  FAIL_IF(!PacketIsICMPv6(p));
785 
786  /* Note: it has an embedded ipv6 packet but no protocol after ipv6 (IPPROTO_NONE) */
787  FAIL_IF(ICMPV6_GET_TYPE(PacketGetICMPv6(p)) != 1);
788  FAIL_IF(ICMPV6_GET_CODE(PacketGetICMPv6(p)) != 0);
789  FAIL_IF_NULL(PacketGetICMPv6EmbIPv6(p));
790  FAIL_IF(ICMPV6_GET_EMB_PROTO(p) != IPPROTO_NONE);
791 
792  /* Let's check if we retrieved the embedded ipv6 addresses correctly */
793  for (int i = 0; i < 4; i++) {
794  FAIL_IF(PacketGetICMPv6EmbIPv6(p)->s_ip6_src[i] != ipv6src[i] ||
795  PacketGetICMPv6EmbIPv6(p)->s_ip6_dst[i] != ipv6dst[i]);
796  }
797 
798  PacketFree(p);
799  FlowShutdown();
800  PASS;
801 }
802 
803 /**\test icmpv6 message type: echo request, valid packet
804  * \retval retval 0 = Error ; 1 = ok
805  */
806 static int ICMPV6EchoReqTest01(void)
807 {
808  static uint8_t raw_ipv6[] = {
809  0x60, 0x00, 0x00, 0x00, 0x00, 0x08, 0x3a, 0xff,
810  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
811  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
812  0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
813  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
814  0x80, 0x00, 0xe5, 0xa5, 0x25, 0xf0, 0x75, 0x23 };
815 
816  Packet *p = PacketGetFromAlloc();
817  FAIL_IF_NULL(p);
818  IPV6Hdr ip6h;
819  ThreadVars tv;
821 
822  memset(&tv, 0, sizeof(ThreadVars));
823  memset(&dtv, 0, sizeof(DecodeThreadVars));
824  memset(&ip6h, 0, sizeof(IPV6Hdr));
825 
827  DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6));
828  FAIL_IF(!PacketIsICMPv6(p));
829 
830  SCLogDebug("ID: %u seq: %u", ICMPV6_GET_ID(p), ICMPV6_GET_SEQ(p));
831 
832  FAIL_IF(ICMPV6_GET_TYPE(PacketGetICMPv6(p)) != 128);
833  FAIL_IF(ICMPV6_GET_CODE(PacketGetICMPv6(p)) != 0);
834  FAIL_IF(SCNtohs(ICMPV6_GET_ID(p)) != 9712);
835  FAIL_IF(SCNtohs(ICMPV6_GET_SEQ(p)) != 29987);
836 
837  PacketFree(p);
838  FlowShutdown();
839  PASS;
840 }
841 
842 /**\test icmpv6 message type: echo reply, valid packet
843  * \retval retval 0 = Error ; 1 = ok
844  */
845 static int ICMPV6EchoRepTest01(void)
846 {
847  static uint8_t raw_ipv6[] = {
848  0x60, 0x00, 0x00, 0x00, 0x00, 0x08, 0x3a,
849  0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
850  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
851  0x00, 0x00, 0x00, 0xff, 0x02, 0x00, 0x00,
852  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
853  0x00, 0x00, 0x00, 0x00, 0x01, 0x81, 0x00,
854  0xe5, 0xa5, 0x25, 0xf0, 0x75, 0x23 };
855 
856  Packet *p = PacketGetFromAlloc();
857  FAIL_IF_NULL(p);
858  IPV6Hdr ip6h;
859  ThreadVars tv;
861 
862  memset(&tv, 0, sizeof(ThreadVars));
863  memset(&dtv, 0, sizeof(DecodeThreadVars));
864  memset(&ip6h, 0, sizeof(IPV6Hdr));
865 
867  DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6));
868  FAIL_IF(!PacketIsICMPv6(p));
869 
870  FAIL_IF(ICMPV6_GET_TYPE(PacketGetICMPv6(p)) != 129);
871  FAIL_IF(ICMPV6_GET_CODE(PacketGetICMPv6(p)) != 0);
872  FAIL_IF(SCNtohs(ICMPV6_GET_ID(p)) != 9712);
873  FAIL_IF(SCNtohs(ICMPV6_GET_SEQ(p)) != 29987);
874 
875  PacketFree(p);
876  FlowShutdown();
877  PASS;
878 }
879 
880 /** \test icmpv6 message type: parameter problem, invalid packet
881  * \brief set the event ICMPV6_IPV6_UNKNOWN_VER properly when the embedded packet has an unknown version
882  * \retval retval 0 = Error ; 1 = ok
883  */
884 static int ICMPV6ParamProbTest02(void)
885 {
886  static uint8_t raw_ipv6[] = {
887  0x60, 0x00, 0x00, 0x00, 0x00, 0x38, 0x3a, 0xff,
888  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
889  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
890  0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
891  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
892  0x04, 0x00, 0xcc, 0x2a, 0x6d, 0x93, 0x0b, 0xdf,
893  0x38, 0x70, 0x12, 0xb7, 0x00, 0x08, 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  0x80, 0x00, 0x08, 0xb5, 0x99, 0xc3, 0xde, 0x40 };
899 
900  Packet *p = PacketGetFromAlloc();
901  FAIL_IF_NULL(p);
902  IPV6Hdr ip6h;
903  ThreadVars tv;
905 
906  memset(&tv, 0, sizeof(ThreadVars));
907  memset(&dtv, 0, sizeof(DecodeThreadVars));
908  memset(&ip6h, 0, sizeof(IPV6Hdr));
909 
911  DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6));
912  FAIL_IF(!PacketIsICMPv6(p));
913  FAIL_IF(ICMPV6_GET_TYPE(PacketGetICMPv6(p)) != 4);
914  FAIL_IF(ICMPV6_GET_CODE(PacketGetICMPv6(p)) != 0);
916 
917  PacketFree(p);
918  FlowShutdown();
919  PASS;
920 }
921 
922 /** \test icmpv6 message type: packet too big, invalid packet
923  * \brief Set the event ICMPV6_UNKNOWN_CODE if code is invalid for this type
924  * \retval retval 0 = Error ; 1 = ok
925  */
926 static int ICMPV6PktTooBigTest02(void)
927 {
928  static uint8_t raw_ipv6[] = {
929  0x60, 0x00, 0x00, 0x00, 0x00, 0x30, 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  0x02, 0x10, 0x5c, 0x7a, 0x00, 0x00, 0x05, 0x00,
935  0x64, 0x14, 0xfd, 0xff, 0x00, 0x00, 0x3b, 0xff,
936  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
937  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
938  0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
939  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 };
940 
941  Packet *p = PacketGetFromAlloc();
942  FAIL_IF_NULL(p);
943  IPV6Hdr ip6h;
944  ThreadVars tv;
946 
947  memset(&tv, 0, sizeof(ThreadVars));
948  memset(&dtv, 0, sizeof(DecodeThreadVars));
949  memset(&ip6h, 0, sizeof(IPV6Hdr));
950 
952  DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6));
953  FAIL_IF(!PacketIsICMPv6(p));
955 
956  PacketFree(p);
957  FlowShutdown();
958  PASS;
959 }
960 
961 /** \test icmpv6 message type: time exceed, invalid packet
962  * \brief set the event ICMPV6_PKT_TOO_SMALL properly
963  * \retval retval 0 = Error ; 1 = ok
964  */
965 static int ICMPV6TimeExceedTest02(void)
966 {
967  static uint8_t raw_ipv6[] = {
968  0x60, 0x00, 0x00, 0x00, 0x00, 0x03, 0x3a, 0xff,
969  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
970  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
971  0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
972  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
973  0x02, 0x10, 0x5c };
974 
975  /* The icmpv6 header is broken in the checksum (so we dont have a complete header) */
976 
977  Packet *p = PacketGetFromAlloc();
978  FAIL_IF_NULL(p);
979  IPV6Hdr ip6h;
980  ThreadVars tv;
982 
983  memset(&tv, 0, sizeof(ThreadVars));
984  memset(&dtv, 0, sizeof(DecodeThreadVars));
985  memset(&ip6h, 0, sizeof(IPV6Hdr));
986 
988  DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6));
989 
991 
992  PacketFree(p);
993  FlowShutdown();
994  PASS;
995 }
996 
997 /**\test icmpv6 message type: destination unreach, invalid packet
998  * \brief The embedded packet header (ipv6) is truncated
999  * \retval retval 0 = Error ; 1 = ok
1000  */
1001 static int ICMPV6DestUnreachTest02(void)
1002 {
1003  static uint8_t raw_ipv6[] = {
1004  0x60, 0x00, 0x00, 0x00, 0x00, 0x2d, 0x3a, 0xff,
1005  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1006  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1007  0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1008  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
1009  0x01, 0x00, 0x7b, 0x85, 0x00, 0x00, 0x00, 0x00,
1010  0x60, 0x4b, 0xe8, 0xbd, 0x00, 0x00, 0x3b, 0xff,
1011  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1012  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1013  0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1014  0x00, 0x00, 0x00, 0x00, 0x00 };
1015 
1016  Packet *p = PacketGetFromAlloc();
1017  FAIL_IF_NULL(p);
1018  IPV6Hdr ip6h;
1019  ThreadVars tv;
1021 
1022  memset(&tv, 0, sizeof(ThreadVars));
1023  memset(&dtv, 0, sizeof(DecodeThreadVars));
1024  memset(&ip6h, 0, sizeof(IPV6Hdr));
1025 
1027  DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6));
1028 
1030 
1031  PacketFree(p);
1032  FlowShutdown();
1033  PASS;
1034 }
1035 
1036 /**\test icmpv6 message type: echo request, invalid packet
1037  * \brief unknown code
1038  * \retval retval 0 = Error ; 1 = ok
1039  */
1040 static int ICMPV6EchoReqTest02(void)
1041 {
1042  static uint8_t raw_ipv6[] = {
1043  0x60, 0x00, 0x00, 0x00, 0x00, 0x08, 0x3a,
1044  0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1045  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1046  0x00, 0x00, 0x00, 0xff, 0x02, 0x00, 0x00,
1047  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1048  0x00, 0x00, 0x00, 0x00, 0x01, 0x80, 0x01,
1049  0xe5, 0xa5, 0x25, 0xf0, 0x75, 0x23 };
1050 
1051  Packet *p = PacketGetFromAlloc();
1052  FAIL_IF_NULL(p);
1053  IPV6Hdr ip6h;
1054  ThreadVars tv;
1056 
1057  memset(&tv, 0, sizeof(ThreadVars));
1058  memset(&dtv, 0, sizeof(DecodeThreadVars));
1059  memset(&ip6h, 0, sizeof(IPV6Hdr));
1060 
1062  DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6));
1063 
1065 
1066  PacketFree(p);
1067  FlowShutdown();
1068  PASS;
1069 }
1070 
1071 /**\test icmpv6 message type: echo reply, invalid packet
1072  * \brief unknown code
1073  * \retval retval 0 = Error ; 1 = ok
1074  */
1075 static int ICMPV6EchoRepTest02(void)
1076 {
1077  static uint8_t raw_ipv6[] = {
1078  0x60, 0x00, 0x00, 0x00, 0x00, 0x08, 0x3a,
1079  0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1080  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1081  0x00, 0x00, 0x00, 0xff, 0x02, 0x00, 0x00,
1082  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1083  0x00, 0x00, 0x00, 0x00, 0x01, 0x81, 0x01,
1084  0xe5, 0xa5, 0x25, 0xf0, 0x75, 0x23 };
1085 
1086  Packet *p = PacketGetFromAlloc();
1087  FAIL_IF_NULL(p);
1088  IPV6Hdr ip6h;
1089  ThreadVars tv;
1091 
1092  memset(&tv, 0, sizeof(ThreadVars));
1093  memset(&dtv, 0, sizeof(DecodeThreadVars));
1094  memset(&ip6h, 0, sizeof(IPV6Hdr));
1095 
1097  DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6));
1098 
1100 
1101  PacketFree(p);
1102  FlowShutdown();
1103  PASS;
1104 }
1105 
1106 /**\test icmpv6 packet decoding and setting up of payload_len and payload buffer
1107  * \retval retval 0 = Error ; 1 = ok
1108  */
1109 static int ICMPV6PayloadTest01(void)
1110 {
1111  static uint8_t raw_ipv6[] = {
1112  0x60, 0x00, 0x00, 0x00, 0x00, 0x2d, 0x3a, 0xff,
1113  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1114  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1115  0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1116  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
1117  0x01, 0x00, 0x7b, 0x85, 0x00, 0x00, 0x00, 0x00,
1118  0x60, 0x4b, 0xe8, 0xbd, 0x00, 0x00, 0x3b, 0xff,
1119  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1120  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1121  0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1122  0x00, 0x00, 0x00, 0x00, 0x00 };
1123 
1124  Packet *p = PacketGetFromAlloc();
1125  FAIL_IF_NULL(p);
1126  IPV6Hdr ip6h;
1127  ThreadVars tv;
1129 
1130  memset(&tv, 0, sizeof(ThreadVars));
1131  memset(&dtv, 0, sizeof(DecodeThreadVars));
1132  memset(&ip6h, 0, sizeof(IPV6Hdr));
1133 
1135  DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6));
1136 
1137  FAIL_IF_NULL(p->payload);
1138  FAIL_IF(p->payload_len != 37);
1139 
1140  PacketFree(p);
1141  FlowShutdown();
1142  PASS;
1143 }
1144 
1145 static int ICMPV6RouterSolicitTestKnownCode(void)
1146 {
1147  static uint8_t raw_ipv6[] = {
1148  0x60, 0x00, 0x00, 0x00, 0x00, 0x08, 0x3a, 0xff,
1149  0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1150  0x02, 0x24, 0x8c, 0xff, 0xfe, 0x0e, 0x31, 0x54,
1151  0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1152  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
1153  0x85, 0x00, 0xbe, 0xb0, 0x00, 0x00, 0x00, 0x00
1154  };
1155 
1156  Packet *p = PacketGetFromAlloc();
1157  FAIL_IF_NULL(p);
1158  IPV6Hdr ip6h;
1159  ThreadVars tv;
1161 
1162  memset(&tv, 0, sizeof(ThreadVars));
1163  memset(&dtv, 0, sizeof(DecodeThreadVars));
1164  memset(&ip6h, 0, sizeof(IPV6Hdr));
1165 
1167  DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6));
1168 
1170 
1171  PacketFree(p);
1172  FlowShutdown();
1173  PASS;
1174 }
1175 
1176 static int ICMPV6RouterSolicitTestUnknownCode(void)
1177 {
1178  static uint8_t raw_ipv6[] = {
1179  0x60, 0x00, 0x00, 0x00, 0x00, 0x08, 0x3a, 0xff,
1180  0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1181  0x02, 0x24, 0x8c, 0xff, 0xfe, 0x0e, 0x31, 0x54,
1182  0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1183  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
1184  0x85, 0x01, 0xbe, 0xaf, 0x00, 0x00, 0x00, 0x00
1185  };
1186 
1187  Packet *p = PacketGetFromAlloc();
1188  FAIL_IF_NULL(p);
1189  IPV6Hdr ip6h;
1190  ThreadVars tv;
1192 
1193  memset(&tv, 0, sizeof(ThreadVars));
1194  memset(&dtv, 0, sizeof(DecodeThreadVars));
1195  memset(&ip6h, 0, sizeof(IPV6Hdr));
1196 
1198  DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6));
1199 
1201 
1202  PacketFree(p);
1203  FlowShutdown();
1204  PASS;
1205 }
1206 
1207 static int ICMPV6RouterAdvertTestKnownCode(void)
1208 {
1209  static uint8_t raw_ipv6[] = {
1210  0x60, 0x00, 0x00, 0x00, 0x00, 0x08, 0x3a, 0xff,
1211  0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1212  0x02, 0x24, 0x8c, 0xff, 0xfe, 0x0e, 0x31, 0x54,
1213  0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1214  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
1215  0x86, 0x00, 0xbd, 0xb0, 0x00, 0x00, 0x00, 0x00
1216  };
1217 
1218  Packet *p = PacketGetFromAlloc();
1219  FAIL_IF_NULL(p);
1220  IPV6Hdr ip6h;
1221  ThreadVars tv;
1223 
1224  memset(&tv, 0, sizeof(ThreadVars));
1225  memset(&dtv, 0, sizeof(DecodeThreadVars));
1226  memset(&ip6h, 0, sizeof(IPV6Hdr));
1227 
1229  DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6));
1230 
1232 
1233  PacketFree(p);
1234  FlowShutdown();
1235  PASS;
1236 }
1237 
1238 static int ICMPV6RouterAdvertTestUnknownCode(void)
1239 {
1240  static uint8_t raw_ipv6[] = {
1241  0x60, 0x00, 0x00, 0x00, 0x00, 0x08, 0x3a, 0xff,
1242  0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1243  0x02, 0x24, 0x8c, 0xff, 0xfe, 0x0e, 0x31, 0x54,
1244  0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1245  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
1246  0x86, 0x01, 0xbd, 0xaf, 0x00, 0x00, 0x00, 0x00
1247  };
1248 
1249  Packet *p = PacketGetFromAlloc();
1250  FAIL_IF_NULL(p);
1251  IPV6Hdr ip6h;
1252  ThreadVars tv;
1254 
1255  memset(&tv, 0, sizeof(ThreadVars));
1256  memset(&dtv, 0, sizeof(DecodeThreadVars));
1257  memset(&ip6h, 0, sizeof(IPV6Hdr));
1258 
1260  DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6));
1261 
1263 
1264  PacketFree(p);
1265  FlowShutdown();
1266  PASS;
1267 }
1268 
1269 static int ICMPV6NeighbourSolicitTestKnownCode(void)
1270 {
1271  static uint8_t raw_ipv6[] = {
1272  0x60, 0x00, 0x00, 0x00, 0x00, 0x08, 0x3a, 0xff,
1273  0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1274  0x02, 0x24, 0x8c, 0xff, 0xfe, 0x0e, 0x31, 0x54,
1275  0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1276  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
1277  0x87, 0x00, 0xbc, 0xb0, 0x00, 0x00, 0x00, 0x00
1278  };
1279 
1280  Packet *p = PacketGetFromAlloc();
1281  FAIL_IF_NULL(p);
1282  IPV6Hdr ip6h;
1283  ThreadVars tv;
1285 
1286  memset(&tv, 0, sizeof(ThreadVars));
1287  memset(&dtv, 0, sizeof(DecodeThreadVars));
1288  memset(&ip6h, 0, sizeof(IPV6Hdr));
1289 
1291  DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6));
1292 
1294 
1295  PacketFree(p);
1296  FlowShutdown();
1297  PASS;
1298 }
1299 
1300 static int ICMPV6NeighbourSolicitTestUnknownCode(void)
1301 {
1302  static uint8_t raw_ipv6[] = {
1303  0x60, 0x00, 0x00, 0x00, 0x00, 0x08, 0x3a, 0xff,
1304  0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1305  0x02, 0x24, 0x8c, 0xff, 0xfe, 0x0e, 0x31, 0x54,
1306  0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1307  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
1308  0x87, 0x01, 0xbc, 0xaf, 0x00, 0x00, 0x00, 0x00
1309  };
1310 
1311  Packet *p = PacketGetFromAlloc();
1312  FAIL_IF_NULL(p);
1313  IPV6Hdr ip6h;
1314  ThreadVars tv;
1316 
1317  memset(&tv, 0, sizeof(ThreadVars));
1318  memset(&dtv, 0, sizeof(DecodeThreadVars));
1319  memset(&ip6h, 0, sizeof(IPV6Hdr));
1320 
1322  DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6));
1323 
1325 
1326  PacketFree(p);
1327  FlowShutdown();
1328  PASS;
1329 }
1330 
1331 static int ICMPV6NeighbourAdvertTestKnownCode(void)
1332 {
1333  static uint8_t raw_ipv6[] = {
1334  0x60, 0x00, 0x00, 0x00, 0x00, 0x08, 0x3a, 0xff,
1335  0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1336  0x02, 0x24, 0x8c, 0xff, 0xfe, 0x0e, 0x31, 0x54,
1337  0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1338  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
1339  0x88, 0x00, 0xbb, 0xb0, 0x00, 0x00, 0x00, 0x00
1340  };
1341 
1342  Packet *p = PacketGetFromAlloc();
1343  FAIL_IF_NULL(p);
1344  IPV6Hdr ip6h;
1345  ThreadVars tv;
1347 
1348  memset(&tv, 0, sizeof(ThreadVars));
1349  memset(&dtv, 0, sizeof(DecodeThreadVars));
1350  memset(&ip6h, 0, sizeof(IPV6Hdr));
1351 
1353  DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6));
1354 
1356 
1357  PacketFree(p);
1358  FlowShutdown();
1359  PASS;
1360 }
1361 
1362 static int ICMPV6NeighbourAdvertTestUnknownCode(void)
1363 {
1364  static uint8_t raw_ipv6[] = {
1365  0x60, 0x00, 0x00, 0x00, 0x00, 0x08, 0x3a, 0xff,
1366  0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1367  0x02, 0x24, 0x8c, 0xff, 0xfe, 0x0e, 0x31, 0x54,
1368  0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1369  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
1370  0x88, 0x01, 0xbb, 0xaf, 0x00, 0x00, 0x00, 0x00
1371  };
1372 
1373  Packet *p = PacketGetFromAlloc();
1374  FAIL_IF_NULL(p);
1375  IPV6Hdr ip6h;
1376  ThreadVars tv;
1378 
1379  memset(&tv, 0, sizeof(ThreadVars));
1380  memset(&dtv, 0, sizeof(DecodeThreadVars));
1381  memset(&ip6h, 0, sizeof(IPV6Hdr));
1382 
1384  DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6));
1385 
1387 
1388  PacketFree(p);
1389  FlowShutdown();
1390  PASS;
1391 }
1392 
1393 static int ICMPV6RedirectTestKnownCode(void)
1394 {
1395  static uint8_t raw_ipv6[] = {
1396  0x60, 0x00, 0x00, 0x00, 0x00, 0x08, 0x3a, 0xff,
1397  0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1398  0x02, 0x24, 0x8c, 0xff, 0xfe, 0x0e, 0x31, 0x54,
1399  0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1400  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
1401  0x89, 0x00, 0xba, 0xb0, 0x00, 0x00, 0x00, 0x00
1402  };
1403 
1404  Packet *p = PacketGetFromAlloc();
1405  FAIL_IF_NULL(p);
1406  IPV6Hdr ip6h;
1407  ThreadVars tv;
1409 
1410  memset(&tv, 0, sizeof(ThreadVars));
1411  memset(&dtv, 0, sizeof(DecodeThreadVars));
1412  memset(&ip6h, 0, sizeof(IPV6Hdr));
1413 
1415  DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6));
1416 
1418 
1419  PacketFree(p);
1420  FlowShutdown();
1421  PASS;
1422 }
1423 
1424 static int ICMPV6RedirectTestUnknownCode(void)
1425 {
1426  static uint8_t raw_ipv6[] = {
1427  0x60, 0x00, 0x00, 0x00, 0x00, 0x08, 0x3a, 0xff,
1428  0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1429  0x02, 0x24, 0x8c, 0xff, 0xfe, 0x0e, 0x31, 0x54,
1430  0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1431  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
1432  0x89, 0x01, 0xba, 0xaf, 0x00, 0x00, 0x00, 0x00
1433  };
1434 
1435  Packet *p = PacketGetFromAlloc();
1436  FAIL_IF_NULL(p);
1437  IPV6Hdr ip6h;
1438  ThreadVars tv;
1440 
1441  memset(&tv, 0, sizeof(ThreadVars));
1442  memset(&dtv, 0, sizeof(DecodeThreadVars));
1443  memset(&ip6h, 0, sizeof(IPV6Hdr));
1444 
1446  DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6));
1447 
1449 
1450  PacketFree(p);
1451  FlowShutdown();
1452  PASS;
1453 }
1454 
1455 /**
1456  * \test Test for valid ICMPv6 checksum when the FCS is still attached.
1457  *
1458  * Tests that the packet is decoded with sufficient info to verify the
1459  * checksum even if the packet has some trailing data like an ethernet
1460  * FCS.
1461  */
1462 static int ICMPV6CalculateValidChecksumWithFCS(void)
1463 {
1464  /* IPV6/ICMPv6 packet with ethernet header.
1465  * - IPv6 payload length: 36
1466  */
1467  uint8_t raw_ipv6[] = {
1468  0x33, 0x33, 0x00, 0x00, 0x00, 0x16, 0x00, 0x50,
1469  0x56, 0xa6, 0x6a, 0x7d, 0x86, 0xdd, 0x60, 0x00,
1470  0x00, 0x00, 0x00, 0x24, 0x00, 0x01, 0xfe, 0x80,
1471  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf5, 0x09,
1472  0xad, 0x44, 0x49, 0x38, 0x5f, 0xa9, 0xff, 0x02,
1473  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1474  0x00, 0x00, 0x00, 0x00, 0x00, 0x16, 0x3a, 0x00,
1475  0x05, 0x02, 0x00, 0x00, 0x01, 0x00, 0x8f, 0x00,
1476  0x24, 0xe0, 0x00, 0x00, 0x00, 0x01, 0x03, 0x00, /* Checksum: 0x24e0. */
1477  0x00, 0x00, 0xff, 0x02, 0x00, 0x00, 0x00, 0x00,
1478  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1479  0x00, 0xfb, 0x1f, 0x34, 0xf6, 0xa4
1480  };
1481  uint16_t csum = *(((uint16_t *)(raw_ipv6 + 64)));
1482 
1483  Packet *p = PacketGetFromAlloc();
1484  FAIL_IF_NULL(p);
1485  ThreadVars tv;
1487  memset(&tv, 0, sizeof(ThreadVars));
1488  memset(&dtv, 0, sizeof(DecodeThreadVars));
1489 
1491  DecodeEthernet(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6));
1492  FAIL_IF(!PacketIsICMPv6(p));
1493 
1494  const ICMPV6Hdr *icmpv6h = PacketGetICMPv6(p);
1495  const IPV6Hdr *ip6h = PacketGetIPv6(p);
1496  uint16_t icmpv6_len = IPV6_GET_RAW_PLEN(ip6h) -
1497  ((const uint8_t *)icmpv6h - (const uint8_t *)ip6h - IPV6_HEADER_LEN);
1498  FAIL_IF(icmpv6_len != 28);
1499  FAIL_IF(ICMPV6CalculateChecksum(ip6h->s_ip6_addrs, (uint16_t *)icmpv6h, icmpv6_len) != csum);
1500 
1501  PacketFree(p);
1502  FlowShutdown();
1503  PASS;
1504 }
1505 
1506 #endif /* UNITTESTS */
1507 /**
1508  * \brief Registers ICMPV6 unit tests
1509  * \todo More ICMPv6 tests
1510  */
1512 {
1513 #ifdef UNITTESTS
1514  UtRegisterTest("ICMPV6CalculateValidChecksumtest01",
1515  ICMPV6CalculateValidChecksumtest01);
1516  UtRegisterTest("ICMPV6CalculateInvalidChecksumtest02", ICMPV6CalculateInvalidChecksumtest02);
1517 
1518  UtRegisterTest("ICMPV6ParamProbTest01 (Valid)", ICMPV6ParamProbTest01);
1519  UtRegisterTest("ICMPV6DestUnreachTest01 (Valid)", ICMPV6DestUnreachTest01);
1520  UtRegisterTest("ICMPV6PktTooBigTest01 (Valid)", ICMPV6PktTooBigTest01);
1521  UtRegisterTest("ICMPV6TimeExceedTest01 (Valid)", ICMPV6TimeExceedTest01);
1522  UtRegisterTest("ICMPV6EchoReqTest01 (Valid)", ICMPV6EchoReqTest01);
1523  UtRegisterTest("ICMPV6EchoRepTest01 (Valid)", ICMPV6EchoRepTest01);
1524 
1525  UtRegisterTest("ICMPV6ParamProbTest02 (Invalid)", ICMPV6ParamProbTest02);
1526  UtRegisterTest("ICMPV6DestUnreachTest02 (Invalid)",
1527  ICMPV6DestUnreachTest02);
1528  UtRegisterTest("ICMPV6PktTooBigTest02 (Invalid)", ICMPV6PktTooBigTest02);
1529  UtRegisterTest("ICMPV6TimeExceedTest02 (Invalid)", ICMPV6TimeExceedTest02);
1530  UtRegisterTest("ICMPV6EchoReqTest02 (Invalid)", ICMPV6EchoReqTest02);
1531  UtRegisterTest("ICMPV6EchoRepTest02 (Invalid)", ICMPV6EchoRepTest02);
1532 
1533  UtRegisterTest("ICMPV6PayloadTest01", ICMPV6PayloadTest01);
1534 
1535  UtRegisterTest("ICMPV6RouterSolicitTestKnownCode",
1536  ICMPV6RouterSolicitTestKnownCode);
1537  UtRegisterTest("ICMPV6RouterSolicitTestUnknownCode",
1538  ICMPV6RouterSolicitTestUnknownCode);
1539  UtRegisterTest("ICMPV6RouterAdvertTestKnownCode",
1540  ICMPV6RouterAdvertTestKnownCode);
1541  UtRegisterTest("ICMPV6RouterAdvertTestUnknownCode",
1542  ICMPV6RouterAdvertTestUnknownCode);
1543 
1544  UtRegisterTest("ICMPV6NeighbourSolicitTestKnownCode",
1545  ICMPV6NeighbourSolicitTestKnownCode);
1546  UtRegisterTest("ICMPV6NeighbourSolicitTestUnknownCode",
1547  ICMPV6NeighbourSolicitTestUnknownCode);
1548  UtRegisterTest("ICMPV6NeighbourAdvertTestKnownCode",
1549  ICMPV6NeighbourAdvertTestKnownCode);
1550  UtRegisterTest("ICMPV6NeighbourAdvertTestUnknownCode",
1551  ICMPV6NeighbourAdvertTestUnknownCode);
1552 
1553  UtRegisterTest("ICMPV6RedirectTestKnownCode", ICMPV6RedirectTestKnownCode);
1554  UtRegisterTest("ICMPV6RedirectTestUnknownCode",
1555  ICMPV6RedirectTestUnknownCode);
1556  UtRegisterTest("ICMPV6CalculateValidChecksumWithFCS",
1557  ICMPV6CalculateValidChecksumWithFCS);
1558 #endif /* UNITTESTS */
1559 }
1560 /**
1561  * @}
1562  */
ENGINE_SET_EVENT
#define ENGINE_SET_EVENT(p, e)
Definition: decode.h:1188
Packet_::proto
uint8_t proto
Definition: decode.h:523
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:1201
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:279
MC_ROUTER_ADVERT
#define MC_ROUTER_ADVERT
Definition: decode-icmpv6.h:68
MC_ROUTER_TERMINATE
#define MC_ROUTER_TERMINATE
Definition: decode-icmpv6.h:70
HOME_AGENT_AD_REPLY
#define HOME_AGENT_AD_REPLY
Definition: decode-icmpv6.h:62
TCP_HEADER_LEN
#define TCP_HEADER_LEN
Definition: decode-tcp.h:28
ICMPV6_UNKNOWN_CODE
@ ICMPV6_UNKNOWN_CODE
Definition: decode-events.h:59
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:605
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
MOBILE_PREFIX_ADVERT
#define MOBILE_PREFIX_ADVERT
Definition: decode-icmpv6.h:64
ICMP6_TIME_EXCEEDED
#define ICMP6_TIME_EXCEEDED
Definition: decode-icmpv6.h:38
ICMPV6_IPV6_UNKNOWN_VER
@ ICMPV6_IPV6_UNKNOWN_VER
Definition: decode-events.h:61
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_::@33::@40 icmp_s
ICMPV6_UNKNOWN_TYPE
@ ICMPV6_UNKNOWN_TYPE
Definition: decode-events.h:58
TM_ECODE_FAILED
@ TM_ECODE_FAILED
Definition: tm-threads-common.h:82
Packet_::payload_len
uint16_t payload_len
Definition: decode.h:606
ICMPV6Vars_::emb_sport
uint16_t emb_sport
Definition: decode-icmpv6.h:156
ICMP6_PARAM_PROB
#define ICMP6_PARAM_PROB
Definition: decode-icmpv6.h:39
util-unittest-helper.h
ICMP6_ECHO_REQUEST
#define ICMP6_ECHO_REQUEST
Definition: decode-icmpv6.h:42
TM_ECODE_OK
@ TM_ECODE_OK
Definition: tm-threads-common.h:81
CERT_PATH_ADVERT
#define CERT_PATH_ADVERT
Definition: decode-icmpv6.h:66
ND_NEIGHBOR_SOLICIT
#define ND_NEIGHBOR_SOLICIT
Definition: decode-icmpv6.h:51
FMIPV6_MSG
#define FMIPV6_MSG
Definition: decode-icmpv6.h:71
ICMPV6_UNASSIGNED_TYPE
@ ICMPV6_UNASSIGNED_TYPE
Definition: decode-events.h:64
ND_REDIRECT
#define ND_REDIRECT
Definition: decode-icmpv6.h:53
FlowInitConfig
void FlowInitConfig(bool quiet)
initialize the configuration
Definition: flow.c:547
TCPHdr_::th_sport
uint16_t th_sport
Definition: decode-tcp.h:150
ND_INVERSE_SOLICIT
#define ND_INVERSE_SOLICIT
Definition: decode-icmpv6.h:58
decode.h
PASS
#define PASS
Pass the test.
Definition: util-unittest.h:105
ICMP6_ECHO_REPLY
#define ICMP6_ECHO_REPLY
Definition: decode-icmpv6.h:43
ICMPV6Hdr_::icmpv6b
union ICMPV6Hdr_::@23 icmpv6b
MLD_LISTENER_REDUCTION
#define MLD_LISTENER_REDUCTION
Definition: decode-icmpv6.h:47
util-print.h
ThreadVars_
Per thread variable structure.
Definition: threadvars.h:58
PrintInet
const char * PrintInet(int af, const void *src, char *dst, socklen_t size)
Definition: util-print.c:231
PacketFree
void PacketFree(Packet *p)
Return a malloced packet.
Definition: decode.c:219
ICMPV6_IPV6_TRUNC_PKT
@ ICMPV6_IPV6_TRUNC_PKT
Definition: decode-events.h:62
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:317
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:501
type
uint16_t type
Definition: decode-vlan.c:106
DecodeIPV6
int DecodeIPV6(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, const uint8_t *pkt, uint16_t len)
Definition: decode-ipv6.c:549
ICMP6_RR
#define ICMP6_RR
Definition: decode-icmpv6.h:55
DecodeICMPV6RegisterTests
void DecodeICMPV6RegisterTests(void)
Registers ICMPV6 unit tests.
Definition: decode-icmpv6.c:1511
Packet_::l4
struct PacketL4 l4
Definition: decode.h:601
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
s_ip6_dst
#define s_ip6_dst
Definition: decode-ipv6.h:53
ICMPV6Hdr_
Definition: decode-icmpv6.h:129
ICMPV6_MLD_MESSAGE_WITH_INVALID_HL
@ ICMPV6_MLD_MESSAGE_WITH_INVALID_HL
Definition: decode-events.h:63
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:465
PacketL4::L4Hdrs::icmpv6h
ICMPV6Hdr * icmpv6h
Definition: decode.h:472
ICMPV6_EXPERIMENTATION_TYPE
@ ICMPV6_EXPERIMENTATION_TYPE
Definition: decode-events.h:65
SCNtohs
#define SCNtohs(x)
Definition: suricata-common.h:431
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:691
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
Packet_::icmp_d
struct Packet_::@35::@41 icmp_d
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
ICMPV6_PKT_TOO_SMALL
@ ICMPV6_PKT_TOO_SMALL
Definition: decode-events.h:60
tv
ThreadVars * tv
Definition: fuzz_decodepcapfile.c:32
PACKET_L4_ICMPV6
@ PACKET_L4_ICMPV6
Definition: decode.h:458
util-validate.h
PacketGetFromAlloc
Packet * PacketGetFromAlloc(void)
Get a malloced packet.
Definition: decode.c:258
ND_ROUTER_SOLICIT
#define ND_ROUTER_SOLICIT
Definition: decode-icmpv6.h:49
DecodeThreadVars_
Structure to hold thread specific data for all decode modules.
Definition: decode.h:963
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
DecodeThreadVars_::counter_icmpv6
uint16_t counter_icmpv6
Definition: decode.h:988
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:1196
FLOW_QUIET
#define FLOW_QUIET
Definition: flow.h:43
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
CASE_CODE
#define CASE_CODE(t, r)
flow.h
PacketL4::L4Vars::icmpv6
ICMPV6Vars icmpv6
Definition: decode.h:480
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:533
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