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  return;
144 }
145 
146 /** \retval type counterpart type or -1 */
148 {
149 #define CASE_CODE(t,r) case (t): return r; case (r): return t;
150  switch (type) {
157 
162  default:
163  return -1;
164  }
165 #undef CASE_CODE
166 }
167 
168 /**
169  * \brief Decode ICMPV6 packets and fill the Packet with the decoded info
170  *
171  * \param tv Pointer to the thread variables
172  * \param dtv Pointer to the decode thread variables
173  * \param p Pointer to the packet we are filling
174  * \param pkt Pointer to the raw packet buffer
175  * \param len the len of the rest of the packet not processed yet
176  *
177  * \retval void No return value
178  */
180  const uint8_t *pkt, uint32_t len)
181 {
182  const IPV6Hdr *ip6h = PacketGetIPv6(p);
183  int full_hdr = 0;
185 
186  if (len < ICMPV6_HEADER_LEN) {
187  SCLogDebug("ICMPV6_PKT_TOO_SMALL");
189  return TM_ECODE_FAILED;
190  }
191 
192  ICMPV6Hdr *icmpv6h = PacketSetICMPv6(p, pkt);
193  p->proto = IPPROTO_ICMPV6;
194  const uint8_t type = p->icmp_s.type = icmpv6h->type;
195  const uint8_t code = p->icmp_s.code = icmpv6h->code;
197  p->payload_len = (uint16_t)(len - ICMPV6_HEADER_LEN);
198  p->payload = (uint8_t *)pkt + ICMPV6_HEADER_LEN;
199 
200  int ctype = ICMPv6GetCounterpart(p->icmp_s.type);
201  if (ctype != -1) {
202  p->icmp_d.type = (uint8_t)ctype;
203  }
204 
205  SCLogDebug("ICMPV6 TYPE %u CODE %u", type, code);
206 
207  switch (type) {
208  case ICMP6_DST_UNREACH:
209  SCLogDebug("ICMP6_DST_UNREACH");
210 
211  if (code > ICMP6_DST_UNREACH_REJECTROUTE) {
213  } else {
214  if (unlikely(len > ICMPV6_HEADER_LEN + USHRT_MAX)) {
215  return TM_ECODE_FAILED;
216  }
217  DecodePartialIPV6(p, (uint8_t *)(pkt + ICMPV6_HEADER_LEN),
218  (uint16_t)(len - ICMPV6_HEADER_LEN));
219  full_hdr = 1;
220  }
221 
222  break;
224  SCLogDebug("ICMP6_PACKET_TOO_BIG");
225 
226  if (code != 0) {
228  } else {
229  if (unlikely(len > ICMPV6_HEADER_LEN + USHRT_MAX)) {
230  return TM_ECODE_FAILED;
231  }
232  p->l4.vars.icmpv6.mtu = ICMPV6_GET_MTU(icmpv6h);
233  DecodePartialIPV6(p, (uint8_t *)(pkt + ICMPV6_HEADER_LEN),
234  (uint16_t)(len - ICMPV6_HEADER_LEN));
235  full_hdr = 1;
236  }
237 
238  break;
239  case ICMP6_TIME_EXCEEDED:
240  SCLogDebug("ICMP6_TIME_EXCEEDED");
241 
242  if (code > ICMP6_TIME_EXCEED_REASSEMBLY) {
244  } else {
245  if (unlikely(len > ICMPV6_HEADER_LEN + USHRT_MAX)) {
246  return TM_ECODE_FAILED;
247  }
248  DecodePartialIPV6(p, (uint8_t *)(pkt + ICMPV6_HEADER_LEN),
249  (uint16_t)(len - ICMPV6_HEADER_LEN));
250  full_hdr = 1;
251  }
252 
253  break;
254  case ICMP6_PARAM_PROB:
255  SCLogDebug("ICMP6_PARAM_PROB");
256 
257  if (code > ICMP6_PARAMPROB_OPTION) {
259  } else {
260  if (unlikely(len > ICMPV6_HEADER_LEN + USHRT_MAX)) {
261  return TM_ECODE_FAILED;
262  }
263  DecodePartialIPV6(p, (uint8_t *)(pkt + ICMPV6_HEADER_LEN),
264  (uint16_t)(len - ICMPV6_HEADER_LEN));
265  full_hdr = 1;
266  }
267 
268  break;
269  case ICMP6_ECHO_REQUEST:
270  SCLogDebug("ICMP6_ECHO_REQUEST id: %u seq: %u", icmpv6h->icmpv6b.icmpv6i.id,
271  icmpv6h->icmpv6b.icmpv6i.seq);
272 
273  if (code != 0) {
275  } else {
276  p->l4.vars.icmpv6.id = icmpv6h->icmpv6b.icmpv6i.id;
277  p->l4.vars.icmpv6.seq = icmpv6h->icmpv6b.icmpv6i.seq;
278  full_hdr = 1;
279  }
280 
281  break;
282  case ICMP6_ECHO_REPLY:
283  SCLogDebug("ICMP6_ECHO_REPLY id: %u seq: %u", icmpv6h->icmpv6b.icmpv6i.id,
284  icmpv6h->icmpv6b.icmpv6i.seq);
285 
286  if (code != 0) {
288  } else {
289  p->l4.vars.icmpv6.id = icmpv6h->icmpv6b.icmpv6i.id;
290  p->l4.vars.icmpv6.seq = icmpv6h->icmpv6b.icmpv6i.seq;
291  full_hdr = 1;
292  }
293 
294  break;
295  case ND_ROUTER_SOLICIT:
296  SCLogDebug("ND_ROUTER_SOLICIT");
297  if (code != 0) {
299  }
300  break;
301  case ND_ROUTER_ADVERT:
302  SCLogDebug("ND_ROUTER_ADVERT");
303  if (code != 0) {
305  }
306  break;
307  case ND_NEIGHBOR_SOLICIT:
308  SCLogDebug("ND_NEIGHBOR_SOLICIT");
309  if (code != 0) {
311  }
312  break;
313  case ND_NEIGHBOR_ADVERT:
314  SCLogDebug("ND_NEIGHBOR_ADVERT");
315  if (code != 0) {
317  }
318  break;
319  case ND_REDIRECT:
320  SCLogDebug("ND_REDIRECT");
321  if (code != 0) {
323  }
324  break;
325  case MLD_LISTENER_QUERY:
326  SCLogDebug("MLD_LISTENER_QUERY");
327  if (code != 0) {
329  }
330  if (IPV6_GET_RAW_HLIM(ip6h) != 1) {
332  }
333  break;
334  case MLD_LISTENER_REPORT:
335  SCLogDebug("MLD_LISTENER_REPORT");
336  if (code != 0) {
338  }
339  if (IPV6_GET_RAW_HLIM(ip6h) != 1) {
341  }
342  break;
344  SCLogDebug("MLD_LISTENER_REDUCTION");
345  if (code != 0) {
347  }
348  if (IPV6_GET_RAW_HLIM(ip6h) != 1) {
350  }
351  break;
352  case ICMP6_RR:
353  SCLogDebug("ICMP6_RR");
354  if (code > 2 && code != 255) {
356  }
357  break;
358  case ICMP6_NI_QUERY:
359  SCLogDebug("ICMP6_NI_QUERY");
360  if (code > 2) {
362  }
363  break;
364  case ICMP6_NI_REPLY:
365  SCLogDebug("ICMP6_NI_REPLY");
366  if (code > 2) {
368  }
369  break;
370  case ND_INVERSE_SOLICIT:
371  SCLogDebug("ND_INVERSE_SOLICIT");
372  if (code != 0) {
374  }
375  break;
376  case ND_INVERSE_ADVERT:
377  SCLogDebug("ND_INVERSE_ADVERT");
378  if (code != 0) {
380  }
381  break;
382  case MLD_V2_LIST_REPORT:
383  SCLogDebug("MLD_V2_LIST_REPORT");
384  if (code != 0) {
386  }
387  break;
389  SCLogDebug("HOME_AGENT_AD_REQUEST");
390  if (code != 0) {
392  }
393  break;
394  case HOME_AGENT_AD_REPLY:
395  SCLogDebug("HOME_AGENT_AD_REPLY");
396  if (code != 0) {
398  }
399  break;
401  SCLogDebug("MOBILE_PREFIX_SOLICIT");
402  if (code != 0) {
404  }
405  break;
407  SCLogDebug("MOBILE_PREFIX_ADVERT");
408  if (code != 0) {
410  }
411  break;
412  case CERT_PATH_SOLICIT:
413  SCLogDebug("CERT_PATH_SOLICIT");
414  if (code != 0) {
416  }
417  break;
418  case CERT_PATH_ADVERT:
419  SCLogDebug("CERT_PATH_ADVERT");
420  if (code != 0) {
422  }
423  break;
425  SCLogDebug("ICMP6_MOBILE_EXPERIMENTAL");
426  break;
427  case MC_ROUTER_ADVERT:
428  SCLogDebug("MC_ROUTER_ADVERT");
429  break;
430  case MC_ROUTER_SOLICIT:
431  SCLogDebug("MC_ROUTER_SOLICIT");
432  break;
433  case MC_ROUTER_TERMINATE:
434  SCLogDebug("MC_ROUTER_TERMINATE");
435  break;
436  case FMIPV6_MSG:
437  SCLogDebug("FMIPV6_MSG");
438  if (code != 0) {
440  }
441  break;
442  case RPL_CONTROL_MSG:
443  SCLogDebug("RPL_CONTROL_MSG");
444  if (code > 3 && code < 128) {
446  }
447  if (code > 132) {
449  }
450  break;
451  case LOCATOR_UDATE_MSG:
452  SCLogDebug("LOCATOR_UDATE_MSG");
453  if (code != 0) {
455  }
456  break;
457  case DUPL_ADDR_REQUEST:
458  SCLogDebug("DUPL_ADDR_REQUEST");
459  if (code != 0) {
461  }
462  break;
463  case DUPL_ADDR_CONFIRM:
464  SCLogDebug("DUPL_ADDR_CONFIRM");
465  if (code != 0) {
467  }
468  break;
469  case MPL_CONTROL_MSG:
470  SCLogDebug("MPL_CONTROL_MSG");
471  if (code != 0) {
473  }
474  break;
475  default:
476  /* Various range taken from:
477  * http://www.iana.org/assignments/icmpv6-parameters/icmpv6-parameters.xhtml#icmpv6-parameters-2
478  */
479  if (type > 4 && type < 100) {
481  } else if (type >= 100 && type < 102) {
483  } else if (type >= 102 && type < 127) {
485  } else if (type >= 160 && type < 200) {
487  } else if (type >= 200 && type < 202) {
489  } else if (type >= 202) {
491  } else {
492  SCLogDebug("ICMPV6 Message type %u not "
493  "implemented yet",
494  type);
496  }
497  }
498 
499  /* for a info message the header is just 4 bytes */
500  if (!full_hdr) {
501  if (p->payload_len >= 4) {
502  p->payload_len -= 4;
503  p->payload = (uint8_t *)pkt + 4;
504  } else {
505  p->payload_len = 0;
506  p->payload = NULL;
507  }
508  }
509 
510 #ifdef DEBUG
512  SCLogDebug("Unknown Code, ICMPV6_UNKNOWN_CODE");
513 
515  SCLogDebug("Unknown Type, ICMPV6_UNKNOWN_TYPE");
516 #endif
517 
518  FlowSetupPacket(p);
519 
520  return TM_ECODE_OK;
521 }
522 
523 #ifdef UNITTESTS
524 #include "packet.h"
525 #include "util-unittest-helper.h"
526 
527 static int ICMPV6CalculateValidChecksumtest01(void)
528 {
529  uint16_t csum = 0;
530 
531  uint8_t raw_ipv6[] = {
532  0x00, 0x00, 0x86, 0x05, 0x80, 0xda, 0x00, 0x60,
533  0x97, 0x07, 0x69, 0xea, 0x86, 0xdd, 0x60, 0x00,
534  0x00, 0x00, 0x00, 0x44, 0x3a, 0x40, 0x3f, 0xfe,
535  0x05, 0x07, 0x00, 0x00, 0x00, 0x01, 0x02, 0x60,
536  0x97, 0xff, 0xfe, 0x07, 0x69, 0xea, 0x3f, 0xfe,
537  0x05, 0x07, 0x00, 0x00, 0x00, 0x01, 0x02, 0x00,
538  0x86, 0xff, 0xfe, 0x05, 0x80, 0xda, 0x03, 0x00,
539  0xf7, 0x52, 0x00, 0x00, 0x00, 0x00, 0x60, 0x00,
540  0x00, 0x00, 0x00, 0x14, 0x11, 0x01, 0x3f, 0xfe,
541  0x05, 0x07, 0x00, 0x00, 0x00, 0x01, 0x02, 0x00,
542  0x86, 0xff, 0xfe, 0x05, 0x80, 0xda, 0x3f, 0xfe,
543  0x05, 0x01, 0x04, 0x10, 0x00, 0x00, 0x02, 0xc0,
544  0xdf, 0xff, 0xfe, 0x47, 0x03, 0x3e, 0xa0, 0x75,
545  0x82, 0x9b, 0x00, 0x14, 0x82, 0x8b, 0x01, 0x01,
546  0x00, 0x00, 0xf9, 0xc8, 0xe7, 0x36, 0xf5, 0xed,
547  0x08, 0x00};
548 
549  csum = *( ((uint16_t *)(raw_ipv6 + 56)));
550 
551  FAIL_IF(csum != ICMPV6CalculateChecksum((uint16_t *)(raw_ipv6 + 14 + 8),
552  (uint16_t *)(raw_ipv6 + 54), 68));
553  PASS;
554 }
555 
556 static int ICMPV6CalculateInvalidChecksumtest02(void)
557 {
558  uint16_t csum = 0;
559 
560  uint8_t raw_ipv6[] = {
561  0x00, 0x00, 0x86, 0x05, 0x80, 0xda, 0x00, 0x60,
562  0x97, 0x07, 0x69, 0xea, 0x86, 0xdd, 0x60, 0x00,
563  0x00, 0x00, 0x00, 0x44, 0x3a, 0x40, 0x3f, 0xfe,
564  0x05, 0x07, 0x00, 0x00, 0x00, 0x01, 0x02, 0x60,
565  0x97, 0xff, 0xfe, 0x07, 0x69, 0xea, 0x3f, 0xfe,
566  0x05, 0x07, 0x00, 0x00, 0x00, 0x01, 0x02, 0x00,
567  0x86, 0xff, 0xfe, 0x05, 0x80, 0xda, 0x03, 0x00,
568  0xf7, 0x52, 0x00, 0x00, 0x00, 0x00, 0x60, 0x00,
569  0x00, 0x00, 0x00, 0x14, 0x11, 0x01, 0x3f, 0xfe,
570  0x05, 0x07, 0x00, 0x00, 0x00, 0x01, 0x02, 0x00,
571  0x86, 0xff, 0xfe, 0x05, 0x80, 0xda, 0x3f, 0xfe,
572  0x05, 0x01, 0x04, 0x10, 0x00, 0x00, 0x02, 0xc0,
573  0xdf, 0xff, 0xfe, 0x47, 0x03, 0x3e, 0xa0, 0x75,
574  0x82, 0x9b, 0x00, 0x14, 0x82, 0x8b, 0x01, 0x01,
575  0x00, 0x00, 0xf9, 0xc8, 0xe7, 0x36, 0xf5, 0xed,
576  0x08, 0x01};
577 
578  csum = *( ((uint16_t *)(raw_ipv6 + 56)));
579 
580  FAIL_IF(csum == ICMPV6CalculateChecksum((uint16_t *)(raw_ipv6 + 14 + 8),
581  (uint16_t *)(raw_ipv6 + 54), 68));
582  PASS;
583 }
584 
585 /** \test icmpv6 message type: parameter problem, valid packet
586  *
587  * \retval retval 0 = Error ; 1 = ok
588  */
589 static int ICMPV6ParamProbTest01(void)
590 {
591  static uint8_t raw_ipv6[] = {
592  0x60, 0x00, 0x00, 0x00, 0x00, 0x38, 0x3a, 0xff,
593  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
594  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
595  0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
596  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
597  0x04, 0x00, 0xcc, 0x2a, 0x6d, 0x93, 0x0b, 0xdf,
598  0x69, 0x70, 0x12, 0xb7, 0x00, 0x08, 0x3a, 0xff,
599  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
600  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
601  0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
602  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
603  0x80, 0x00, 0x08, 0xb5, 0x99, 0xc3, 0xde, 0x40 };
604 
605  Packet *p = PacketGetFromAlloc();
606  FAIL_IF_NULL(p);
607  IPV6Hdr ip6h;
608  ThreadVars tv;
610  uint32_t *ipv6src;
611  uint32_t *ipv6dst;
612  ipv6src = (uint32_t*) &raw_ipv6[8];
613  ipv6dst = (uint32_t*) &raw_ipv6[24];
614 
615  memset(&tv, 0, sizeof(ThreadVars));
616  memset(&dtv, 0, sizeof(DecodeThreadVars));
617  memset(&ip6h, 0, sizeof(IPV6Hdr));
618 
620  DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6));
621  FAIL_IF(!PacketIsICMPv6(p));
622 
623  /* ICMPv6 not processed at all? */
624  FAIL_IF(ICMPV6_GET_TYPE(PacketGetICMPv6(p)) != 4);
625  FAIL_IF(ICMPV6_GET_CODE(PacketGetICMPv6(p)) != 0);
626  FAIL_IF(ICMPV6_GET_EMB_PROTO(p) != IPPROTO_ICMPV6);
627 
628  /* Let's check if we retrieved the embedded ipv6 addresses correctly */
629  for (int i = 0; i < 4; i++) {
630  FAIL_IF(PacketGetICMPv6EmbIPv6(p)->s_ip6_src[i] != ipv6src[i] ||
631  PacketGetICMPv6EmbIPv6(p)->s_ip6_dst[i] != ipv6dst[i]);
632  }
633 
634  PacketRecycle(p);
635  FlowShutdown();
636  SCFree(p);
637  PASS;
638 }
639 
640 /** \test icmpv6 message type: packet too big, valid packet
641  *
642  * \retval retval 0 = Error ; 1 = ok
643  */
644 static int ICMPV6PktTooBigTest01(void)
645 {
646  static uint8_t raw_ipv6[] = {
647  0x60, 0x00, 0x00, 0x00, 0x00, 0x30, 0x3a, 0xff,
648  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
649  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
650  0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
651  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
652  0x02, 0x00, 0x5c, 0x7a, 0x00, 0x00, 0x05, 0x00,
653  0x64, 0x14, 0xfd, 0xff, 0x00, 0x00, 0x3b, 0xff,
654  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
655  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
656  0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
657  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 };
658 
659  Packet *p = PacketGetFromAlloc();
660  FAIL_IF_NULL(p);
661  IPV6Hdr ip6h;
662  ThreadVars tv;
664  uint32_t *ipv6src;
665  uint32_t *ipv6dst;
666  ipv6src = (uint32_t*) &raw_ipv6[8];
667  ipv6dst = (uint32_t*) &raw_ipv6[24];
668 
669  memset(&tv, 0, sizeof(ThreadVars));
670  memset(&dtv, 0, sizeof(DecodeThreadVars));
671  memset(&ip6h, 0, sizeof(IPV6Hdr));
672 
674  DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6));
675  FAIL_IF(!PacketIsICMPv6(p));
676 
677  /* Note: it has an embedded ipv6 packet but no protocol after ipv6
678  * (IPPROTO_NONE) */
679  /* Check if ICMPv6 header was processed at all. */
680  FAIL_IF(ICMPV6_GET_TYPE(PacketGetICMPv6(p)) != 2);
681  FAIL_IF(ICMPV6_GET_CODE(PacketGetICMPv6(p)) != 0);
682 
683  /* Let's check if we retrieved the embedded ipv6 addresses correctly */
684  for (int i = 0; i < 4; i++) {
685  FAIL_IF(PacketGetICMPv6EmbIPv6(p)->s_ip6_src[i] != ipv6src[i] ||
686  PacketGetICMPv6EmbIPv6(p)->s_ip6_dst[i] != ipv6dst[i]);
687  }
688 
689  SCLogDebug("ICMPV6 IPV6 src and dst properly set");
690 
691  PacketRecycle(p);
692  FlowShutdown();
693  SCFree(p);
694  PASS;
695 }
696 
697 /** \test icmpv6 message type: time exceed, valid packet
698  *
699  * \retval retval 0 = Error ; 1 = ok
700  */
701 static int ICMPV6TimeExceedTest01(void)
702 {
703  static uint8_t raw_ipv6[] = {
704  0x60, 0x00, 0x00, 0x00, 0x00, 0x30, 0x3a, 0xff,
705  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
706  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
707  0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
708  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
709  0x03, 0x00, 0x56, 0x2d, 0x00, 0x00, 0x00, 0x00,
710  0x6d, 0x23, 0xff, 0x3d, 0x00, 0x00, 0x3b, 0xff,
711  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
712  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
713  0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
714  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 };
715 
716  Packet *p = PacketGetFromAlloc();
717  FAIL_IF_NULL(p);
718  IPV6Hdr ip6h;
719  ThreadVars tv;
721  uint32_t *ipv6src;
722  uint32_t *ipv6dst;
723  ipv6src = (uint32_t*) &raw_ipv6[8];
724  ipv6dst = (uint32_t*) &raw_ipv6[24];
725 
726  memset(&tv, 0, sizeof(ThreadVars));
727  memset(&dtv, 0, sizeof(DecodeThreadVars));
728  memset(&ip6h, 0, sizeof(IPV6Hdr));
729 
731  DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6));
732  FAIL_IF(!PacketIsICMPv6(p));
733 
734  /* Note: it has an embedded ipv6 packet but no protocol after ipv6 (IPPROTO_NONE) */
735  FAIL_IF(ICMPV6_GET_TYPE(PacketGetICMPv6(p)) != 3);
736  FAIL_IF(ICMPV6_GET_CODE(PacketGetICMPv6(p)) != 0);
737  FAIL_IF_NULL(PacketGetICMPv6EmbIPv6(p));
738  FAIL_IF(ICMPV6_GET_EMB_PROTO(p) != IPPROTO_NONE);
739 
740  /* Let's check if we retrieved the embedded ipv6 addresses correctly */
741  for (int i = 0; i < 4; i++) {
742  FAIL_IF(PacketGetICMPv6EmbIPv6(p)->s_ip6_src[i] != ipv6src[i] ||
743  PacketGetICMPv6EmbIPv6(p)->s_ip6_dst[i] != ipv6dst[i]);
744  }
745 
746  SCLogDebug("ICMPV6 IPV6 src and dst properly set");
747 
748  PacketRecycle(p);
749  FlowShutdown();
750  SCFree(p);
751  PASS;
752 }
753 
754 /** \test icmpv6 message type: destination unreach, valid packet
755  *
756  * \retval retval 0 = Error ; 1 = ok
757  */
758 static int ICMPV6DestUnreachTest01(void)
759 {
760  static uint8_t raw_ipv6[] = {
761  0x60, 0x00, 0x00, 0x00, 0x00, 0x30, 0x3a, 0xff,
762  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
763  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
764  0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
765  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
766  0x01, 0x00, 0x7b, 0x85, 0x00, 0x00, 0x00, 0x00,
767  0x60, 0x4b, 0xe8, 0xbd, 0x00, 0x00, 0x3b, 0xff,
768  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
769  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
770  0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
771  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 };
772 
773  Packet *p = PacketGetFromAlloc();
774  FAIL_IF_NULL(p);
775  IPV6Hdr ip6h;
776  ThreadVars tv;
778  uint32_t *ipv6src;
779  uint32_t *ipv6dst;
780  ipv6src = (uint32_t*) &raw_ipv6[8];
781  ipv6dst = (uint32_t*) &raw_ipv6[24];
782 
783  memset(&tv, 0, sizeof(ThreadVars));
784  memset(&dtv, 0, sizeof(DecodeThreadVars));
785  memset(&ip6h, 0, sizeof(IPV6Hdr));
786 
788  DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6));
789  FAIL_IF(!PacketIsICMPv6(p));
790 
791  /* Note: it has an embedded ipv6 packet but no protocol after ipv6 (IPPROTO_NONE) */
792  FAIL_IF(ICMPV6_GET_TYPE(PacketGetICMPv6(p)) != 1);
793  FAIL_IF(ICMPV6_GET_CODE(PacketGetICMPv6(p)) != 0);
794  FAIL_IF_NULL(PacketGetICMPv6EmbIPv6(p));
795  FAIL_IF(ICMPV6_GET_EMB_PROTO(p) != IPPROTO_NONE);
796 
797  /* Let's check if we retrieved the embedded ipv6 addresses correctly */
798  for (int i = 0; i < 4; i++) {
799  FAIL_IF(PacketGetICMPv6EmbIPv6(p)->s_ip6_src[i] != ipv6src[i] ||
800  PacketGetICMPv6EmbIPv6(p)->s_ip6_dst[i] != ipv6dst[i]);
801  }
802 
803  PacketRecycle(p);
804  FlowShutdown();
805  SCFree(p);
806  PASS;
807 }
808 
809 /**\test icmpv6 message type: echo request, valid packet
810  * \retval retval 0 = Error ; 1 = ok
811  */
812 static int ICMPV6EchoReqTest01(void)
813 {
814  static uint8_t raw_ipv6[] = {
815  0x60, 0x00, 0x00, 0x00, 0x00, 0x08, 0x3a, 0xff,
816  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
817  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
818  0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
819  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
820  0x80, 0x00, 0xe5, 0xa5, 0x25, 0xf0, 0x75, 0x23 };
821 
822  Packet *p = PacketGetFromAlloc();
823  FAIL_IF_NULL(p);
824  IPV6Hdr ip6h;
825  ThreadVars tv;
827 
828  memset(&tv, 0, sizeof(ThreadVars));
829  memset(&dtv, 0, sizeof(DecodeThreadVars));
830  memset(&ip6h, 0, sizeof(IPV6Hdr));
831 
833  DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6));
834  FAIL_IF(!PacketIsICMPv6(p));
835 
836  SCLogDebug("ID: %u seq: %u", ICMPV6_GET_ID(p), ICMPV6_GET_SEQ(p));
837 
838  FAIL_IF(ICMPV6_GET_TYPE(PacketGetICMPv6(p)) != 128);
839  FAIL_IF(ICMPV6_GET_CODE(PacketGetICMPv6(p)) != 0);
840  FAIL_IF(SCNtohs(ICMPV6_GET_ID(p)) != 9712);
841  FAIL_IF(SCNtohs(ICMPV6_GET_SEQ(p)) != 29987);
842 
843  PacketRecycle(p);
844  FlowShutdown();
845  SCFree(p);
846  PASS;
847 }
848 
849 /**\test icmpv6 message type: echo reply, valid packet
850  * \retval retval 0 = Error ; 1 = ok
851  */
852 static int ICMPV6EchoRepTest01(void)
853 {
854  static uint8_t raw_ipv6[] = {
855  0x60, 0x00, 0x00, 0x00, 0x00, 0x08, 0x3a,
856  0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
857  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
858  0x00, 0x00, 0x00, 0xff, 0x02, 0x00, 0x00,
859  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
860  0x00, 0x00, 0x00, 0x00, 0x01, 0x81, 0x00,
861  0xe5, 0xa5, 0x25, 0xf0, 0x75, 0x23 };
862 
863  Packet *p = PacketGetFromAlloc();
864  FAIL_IF_NULL(p);
865  IPV6Hdr ip6h;
866  ThreadVars tv;
868 
869  memset(&tv, 0, sizeof(ThreadVars));
870  memset(&dtv, 0, sizeof(DecodeThreadVars));
871  memset(&ip6h, 0, sizeof(IPV6Hdr));
872 
874  DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6));
875  FAIL_IF(!PacketIsICMPv6(p));
876 
877  FAIL_IF(ICMPV6_GET_TYPE(PacketGetICMPv6(p)) != 129);
878  FAIL_IF(ICMPV6_GET_CODE(PacketGetICMPv6(p)) != 0);
879  FAIL_IF(SCNtohs(ICMPV6_GET_ID(p)) != 9712);
880  FAIL_IF(SCNtohs(ICMPV6_GET_SEQ(p)) != 29987);
881 
882  PacketRecycle(p);
883  FlowShutdown();
884  SCFree(p);
885  PASS;
886 }
887 
888 /** \test icmpv6 message type: parameter problem, invalid packet
889  * \brief set the event ICMPV6_IPV6_UNKNOWN_VER properly when the embedded packet has an unknown version
890  * \retval retval 0 = Error ; 1 = ok
891  */
892 static int ICMPV6ParamProbTest02(void)
893 {
894  static uint8_t raw_ipv6[] = {
895  0x60, 0x00, 0x00, 0x00, 0x00, 0x38, 0x3a, 0xff,
896  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
897  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
898  0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
899  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
900  0x04, 0x00, 0xcc, 0x2a, 0x6d, 0x93, 0x0b, 0xdf,
901  0x38, 0x70, 0x12, 0xb7, 0x00, 0x08, 0x3a, 0xff,
902  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
903  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
904  0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
905  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
906  0x80, 0x00, 0x08, 0xb5, 0x99, 0xc3, 0xde, 0x40 };
907 
908  Packet *p = PacketGetFromAlloc();
909  FAIL_IF_NULL(p);
910  IPV6Hdr ip6h;
911  ThreadVars tv;
913 
914  memset(&tv, 0, sizeof(ThreadVars));
915  memset(&dtv, 0, sizeof(DecodeThreadVars));
916  memset(&ip6h, 0, sizeof(IPV6Hdr));
917 
919  DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6));
920  FAIL_IF(!PacketIsICMPv6(p));
921  FAIL_IF(ICMPV6_GET_TYPE(PacketGetICMPv6(p)) != 4);
922  FAIL_IF(ICMPV6_GET_CODE(PacketGetICMPv6(p)) != 0);
924 
925  PacketRecycle(p);
926  FlowShutdown();
927  SCFree(p);
928  PASS;
929 }
930 
931 /** \test icmpv6 message type: packet too big, invalid packet
932  * \brief Set the event ICMPV6_UNKNOWN_CODE if code is invalid for this type
933  * \retval retval 0 = Error ; 1 = ok
934  */
935 static int ICMPV6PktTooBigTest02(void)
936 {
937  static uint8_t raw_ipv6[] = {
938  0x60, 0x00, 0x00, 0x00, 0x00, 0x30, 0x3a, 0xff,
939  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
940  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
941  0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
942  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
943  0x02, 0x10, 0x5c, 0x7a, 0x00, 0x00, 0x05, 0x00,
944  0x64, 0x14, 0xfd, 0xff, 0x00, 0x00, 0x3b, 0xff,
945  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
946  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
947  0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
948  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 };
949 
950  Packet *p = PacketGetFromAlloc();
951  FAIL_IF_NULL(p);
952  IPV6Hdr ip6h;
953  ThreadVars tv;
955 
956  memset(&tv, 0, sizeof(ThreadVars));
957  memset(&dtv, 0, sizeof(DecodeThreadVars));
958  memset(&ip6h, 0, sizeof(IPV6Hdr));
959 
961  DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6));
962  FAIL_IF(!PacketIsICMPv6(p));
964 
965  PacketRecycle(p);
966  FlowShutdown();
967  SCFree(p);
968  PASS;
969 }
970 
971 /** \test icmpv6 message type: time exceed, invalid packet
972  * \brief set the event ICMPV6_PKT_TOO_SMALL properly
973  * \retval retval 0 = Error ; 1 = ok
974  */
975 static int ICMPV6TimeExceedTest02(void)
976 {
977  static uint8_t raw_ipv6[] = {
978  0x60, 0x00, 0x00, 0x00, 0x00, 0x03, 0x3a, 0xff,
979  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
980  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
981  0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
982  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
983  0x02, 0x10, 0x5c };
984 
985  /* The icmpv6 header is broken in the checksum (so we dont have a complete header) */
986 
987  Packet *p = PacketGetFromAlloc();
988  FAIL_IF_NULL(p);
989  IPV6Hdr ip6h;
990  ThreadVars tv;
992 
993  memset(&tv, 0, sizeof(ThreadVars));
994  memset(&dtv, 0, sizeof(DecodeThreadVars));
995  memset(&ip6h, 0, sizeof(IPV6Hdr));
996 
998  DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6));
999 
1001 
1002  PacketRecycle(p);
1003  FlowShutdown();
1004  SCFree(p);
1005  PASS;
1006 }
1007 
1008 /**\test icmpv6 message type: destination unreach, invalid packet
1009  * \brief The embedded packet header (ipv6) is truncated
1010  * \retval retval 0 = Error ; 1 = ok
1011  */
1012 static int ICMPV6DestUnreachTest02(void)
1013 {
1014  static uint8_t raw_ipv6[] = {
1015  0x60, 0x00, 0x00, 0x00, 0x00, 0x2d, 0x3a, 0xff,
1016  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1017  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1018  0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1019  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
1020  0x01, 0x00, 0x7b, 0x85, 0x00, 0x00, 0x00, 0x00,
1021  0x60, 0x4b, 0xe8, 0xbd, 0x00, 0x00, 0x3b, 0xff,
1022  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1023  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1024  0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1025  0x00, 0x00, 0x00, 0x00, 0x00 };
1026 
1027  Packet *p = PacketGetFromAlloc();
1028  FAIL_IF_NULL(p);
1029  IPV6Hdr ip6h;
1030  ThreadVars tv;
1032 
1033  memset(&tv, 0, sizeof(ThreadVars));
1034  memset(&dtv, 0, sizeof(DecodeThreadVars));
1035  memset(&ip6h, 0, sizeof(IPV6Hdr));
1036 
1038  DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6));
1039 
1041 
1042  PacketRecycle(p);
1043  FlowShutdown();
1044  SCFree(p);
1045  PASS;
1046 }
1047 
1048 /**\test icmpv6 message type: echo request, invalid packet
1049  * \brief unknown code
1050  * \retval retval 0 = Error ; 1 = ok
1051  */
1052 static int ICMPV6EchoReqTest02(void)
1053 {
1054  static uint8_t raw_ipv6[] = {
1055  0x60, 0x00, 0x00, 0x00, 0x00, 0x08, 0x3a,
1056  0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1057  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1058  0x00, 0x00, 0x00, 0xff, 0x02, 0x00, 0x00,
1059  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1060  0x00, 0x00, 0x00, 0x00, 0x01, 0x80, 0x01,
1061  0xe5, 0xa5, 0x25, 0xf0, 0x75, 0x23 };
1062 
1063  Packet *p = PacketGetFromAlloc();
1064  FAIL_IF_NULL(p);
1065  IPV6Hdr ip6h;
1066  ThreadVars tv;
1068 
1069  memset(&tv, 0, sizeof(ThreadVars));
1070  memset(&dtv, 0, sizeof(DecodeThreadVars));
1071  memset(&ip6h, 0, sizeof(IPV6Hdr));
1072 
1074  DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6));
1075 
1077 
1078  PacketRecycle(p);
1079  FlowShutdown();
1080  SCFree(p);
1081  PASS;
1082 }
1083 
1084 /**\test icmpv6 message type: echo reply, invalid packet
1085  * \brief unknown code
1086  * \retval retval 0 = Error ; 1 = ok
1087  */
1088 static int ICMPV6EchoRepTest02(void)
1089 {
1090  static uint8_t raw_ipv6[] = {
1091  0x60, 0x00, 0x00, 0x00, 0x00, 0x08, 0x3a,
1092  0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1093  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1094  0x00, 0x00, 0x00, 0xff, 0x02, 0x00, 0x00,
1095  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1096  0x00, 0x00, 0x00, 0x00, 0x01, 0x81, 0x01,
1097  0xe5, 0xa5, 0x25, 0xf0, 0x75, 0x23 };
1098 
1099  Packet *p = PacketGetFromAlloc();
1100  FAIL_IF_NULL(p);
1101  IPV6Hdr ip6h;
1102  ThreadVars tv;
1104 
1105  memset(&tv, 0, sizeof(ThreadVars));
1106  memset(&dtv, 0, sizeof(DecodeThreadVars));
1107  memset(&ip6h, 0, sizeof(IPV6Hdr));
1108 
1110  DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6));
1111 
1113 
1114  PacketRecycle(p);
1115  FlowShutdown();
1116  SCFree(p);
1117  PASS;
1118 }
1119 
1120 /**\test icmpv6 packet decoding and setting up of payload_len and payload buffer
1121  * \retval retval 0 = Error ; 1 = ok
1122  */
1123 static int ICMPV6PayloadTest01(void)
1124 {
1125  static uint8_t raw_ipv6[] = {
1126  0x60, 0x00, 0x00, 0x00, 0x00, 0x2d, 0x3a, 0xff,
1127  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1128  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1129  0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1130  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
1131  0x01, 0x00, 0x7b, 0x85, 0x00, 0x00, 0x00, 0x00,
1132  0x60, 0x4b, 0xe8, 0xbd, 0x00, 0x00, 0x3b, 0xff,
1133  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1134  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1135  0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1136  0x00, 0x00, 0x00, 0x00, 0x00 };
1137 
1138  Packet *p = PacketGetFromAlloc();
1139  FAIL_IF_NULL(p);
1140  IPV6Hdr ip6h;
1141  ThreadVars tv;
1143 
1144  memset(&tv, 0, sizeof(ThreadVars));
1145  memset(&dtv, 0, sizeof(DecodeThreadVars));
1146  memset(&ip6h, 0, sizeof(IPV6Hdr));
1147 
1149  DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6));
1150 
1151  FAIL_IF_NULL(p->payload);
1152  FAIL_IF(p->payload_len != 37);
1153 
1154  PacketRecycle(p);
1155  FlowShutdown();
1156  SCFree(p);
1157  PASS;
1158 }
1159 
1160 static int ICMPV6RouterSolicitTestKnownCode(void)
1161 {
1162  static uint8_t raw_ipv6[] = {
1163  0x60, 0x00, 0x00, 0x00, 0x00, 0x08, 0x3a, 0xff,
1164  0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1165  0x02, 0x24, 0x8c, 0xff, 0xfe, 0x0e, 0x31, 0x54,
1166  0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1167  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
1168  0x85, 0x00, 0xbe, 0xb0, 0x00, 0x00, 0x00, 0x00
1169  };
1170 
1171  Packet *p = PacketGetFromAlloc();
1172  FAIL_IF_NULL(p);
1173  IPV6Hdr ip6h;
1174  ThreadVars tv;
1176 
1177  memset(&tv, 0, sizeof(ThreadVars));
1178  memset(&dtv, 0, sizeof(DecodeThreadVars));
1179  memset(&ip6h, 0, sizeof(IPV6Hdr));
1180 
1182  DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6));
1183 
1185 
1186  PacketRecycle(p);
1187  FlowShutdown();
1188  SCFree(p);
1189  PASS;
1190 }
1191 
1192 static int ICMPV6RouterSolicitTestUnknownCode(void)
1193 {
1194  static uint8_t raw_ipv6[] = {
1195  0x60, 0x00, 0x00, 0x00, 0x00, 0x08, 0x3a, 0xff,
1196  0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1197  0x02, 0x24, 0x8c, 0xff, 0xfe, 0x0e, 0x31, 0x54,
1198  0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1199  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
1200  0x85, 0x01, 0xbe, 0xaf, 0x00, 0x00, 0x00, 0x00
1201  };
1202 
1203  Packet *p = PacketGetFromAlloc();
1204  FAIL_IF_NULL(p);
1205  IPV6Hdr ip6h;
1206  ThreadVars tv;
1208 
1209  memset(&tv, 0, sizeof(ThreadVars));
1210  memset(&dtv, 0, sizeof(DecodeThreadVars));
1211  memset(&ip6h, 0, sizeof(IPV6Hdr));
1212 
1214  DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6));
1215 
1217 
1218  PacketRecycle(p);
1219  FlowShutdown();
1220  SCFree(p);
1221  PASS;
1222 }
1223 
1224 static int ICMPV6RouterAdvertTestKnownCode(void)
1225 {
1226  static uint8_t raw_ipv6[] = {
1227  0x60, 0x00, 0x00, 0x00, 0x00, 0x08, 0x3a, 0xff,
1228  0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1229  0x02, 0x24, 0x8c, 0xff, 0xfe, 0x0e, 0x31, 0x54,
1230  0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1231  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
1232  0x86, 0x00, 0xbd, 0xb0, 0x00, 0x00, 0x00, 0x00
1233  };
1234 
1235  Packet *p = PacketGetFromAlloc();
1236  FAIL_IF_NULL(p);
1237  IPV6Hdr ip6h;
1238  ThreadVars tv;
1240 
1241  memset(&tv, 0, sizeof(ThreadVars));
1242  memset(&dtv, 0, sizeof(DecodeThreadVars));
1243  memset(&ip6h, 0, sizeof(IPV6Hdr));
1244 
1246  DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6));
1247 
1249 
1250  PacketRecycle(p);
1251  FlowShutdown();
1252  SCFree(p);
1253  PASS;
1254 }
1255 
1256 static int ICMPV6RouterAdvertTestUnknownCode(void)
1257 {
1258  static uint8_t raw_ipv6[] = {
1259  0x60, 0x00, 0x00, 0x00, 0x00, 0x08, 0x3a, 0xff,
1260  0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1261  0x02, 0x24, 0x8c, 0xff, 0xfe, 0x0e, 0x31, 0x54,
1262  0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1263  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
1264  0x86, 0x01, 0xbd, 0xaf, 0x00, 0x00, 0x00, 0x00
1265  };
1266 
1267  Packet *p = PacketGetFromAlloc();
1268  FAIL_IF_NULL(p);
1269  IPV6Hdr ip6h;
1270  ThreadVars tv;
1272 
1273  memset(&tv, 0, sizeof(ThreadVars));
1274  memset(&dtv, 0, sizeof(DecodeThreadVars));
1275  memset(&ip6h, 0, sizeof(IPV6Hdr));
1276 
1278  DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6));
1279 
1281 
1282  PacketRecycle(p);
1283  FlowShutdown();
1284  SCFree(p);
1285  PASS;
1286 }
1287 
1288 static int ICMPV6NeighbourSolicitTestKnownCode(void)
1289 {
1290  static uint8_t raw_ipv6[] = {
1291  0x60, 0x00, 0x00, 0x00, 0x00, 0x08, 0x3a, 0xff,
1292  0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1293  0x02, 0x24, 0x8c, 0xff, 0xfe, 0x0e, 0x31, 0x54,
1294  0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1295  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
1296  0x87, 0x00, 0xbc, 0xb0, 0x00, 0x00, 0x00, 0x00
1297  };
1298 
1299  Packet *p = PacketGetFromAlloc();
1300  FAIL_IF_NULL(p);
1301  IPV6Hdr ip6h;
1302  ThreadVars tv;
1304 
1305  memset(&tv, 0, sizeof(ThreadVars));
1306  memset(&dtv, 0, sizeof(DecodeThreadVars));
1307  memset(&ip6h, 0, sizeof(IPV6Hdr));
1308 
1310  DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6));
1311 
1313 
1314  PacketRecycle(p);
1315  FlowShutdown();
1316  SCFree(p);
1317  PASS;
1318 }
1319 
1320 static int ICMPV6NeighbourSolicitTestUnknownCode(void)
1321 {
1322  static uint8_t raw_ipv6[] = {
1323  0x60, 0x00, 0x00, 0x00, 0x00, 0x08, 0x3a, 0xff,
1324  0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1325  0x02, 0x24, 0x8c, 0xff, 0xfe, 0x0e, 0x31, 0x54,
1326  0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1327  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
1328  0x87, 0x01, 0xbc, 0xaf, 0x00, 0x00, 0x00, 0x00
1329  };
1330 
1331  Packet *p = PacketGetFromAlloc();
1332  FAIL_IF_NULL(p);
1333  IPV6Hdr ip6h;
1334  ThreadVars tv;
1336 
1337  memset(&tv, 0, sizeof(ThreadVars));
1338  memset(&dtv, 0, sizeof(DecodeThreadVars));
1339  memset(&ip6h, 0, sizeof(IPV6Hdr));
1340 
1342  DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6));
1343 
1345 
1346  PacketRecycle(p);
1347  FlowShutdown();
1348  SCFree(p);
1349  PASS;
1350 }
1351 
1352 static int ICMPV6NeighbourAdvertTestKnownCode(void)
1353 {
1354  static uint8_t raw_ipv6[] = {
1355  0x60, 0x00, 0x00, 0x00, 0x00, 0x08, 0x3a, 0xff,
1356  0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1357  0x02, 0x24, 0x8c, 0xff, 0xfe, 0x0e, 0x31, 0x54,
1358  0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1359  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
1360  0x88, 0x00, 0xbb, 0xb0, 0x00, 0x00, 0x00, 0x00
1361  };
1362 
1363  Packet *p = PacketGetFromAlloc();
1364  FAIL_IF_NULL(p);
1365  IPV6Hdr ip6h;
1366  ThreadVars tv;
1368 
1369  memset(&tv, 0, sizeof(ThreadVars));
1370  memset(&dtv, 0, sizeof(DecodeThreadVars));
1371  memset(&ip6h, 0, sizeof(IPV6Hdr));
1372 
1374  DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6));
1375 
1377 
1378  PacketRecycle(p);
1379  FlowShutdown();
1380  SCFree(p);
1381  PASS;
1382 }
1383 
1384 static int ICMPV6NeighbourAdvertTestUnknownCode(void)
1385 {
1386  static uint8_t raw_ipv6[] = {
1387  0x60, 0x00, 0x00, 0x00, 0x00, 0x08, 0x3a, 0xff,
1388  0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1389  0x02, 0x24, 0x8c, 0xff, 0xfe, 0x0e, 0x31, 0x54,
1390  0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1391  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
1392  0x88, 0x01, 0xbb, 0xaf, 0x00, 0x00, 0x00, 0x00
1393  };
1394 
1395  Packet *p = PacketGetFromAlloc();
1396  FAIL_IF_NULL(p);
1397  IPV6Hdr ip6h;
1398  ThreadVars tv;
1400 
1401  memset(&tv, 0, sizeof(ThreadVars));
1402  memset(&dtv, 0, sizeof(DecodeThreadVars));
1403  memset(&ip6h, 0, sizeof(IPV6Hdr));
1404 
1406  DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6));
1407 
1409 
1410  PacketRecycle(p);
1411  FlowShutdown();
1412  SCFree(p);
1413  PASS;
1414 }
1415 
1416 static int ICMPV6RedirectTestKnownCode(void)
1417 {
1418  static uint8_t raw_ipv6[] = {
1419  0x60, 0x00, 0x00, 0x00, 0x00, 0x08, 0x3a, 0xff,
1420  0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1421  0x02, 0x24, 0x8c, 0xff, 0xfe, 0x0e, 0x31, 0x54,
1422  0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1423  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
1424  0x89, 0x00, 0xba, 0xb0, 0x00, 0x00, 0x00, 0x00
1425  };
1426 
1427  Packet *p = PacketGetFromAlloc();
1428  FAIL_IF_NULL(p);
1429  IPV6Hdr ip6h;
1430  ThreadVars tv;
1432 
1433  memset(&tv, 0, sizeof(ThreadVars));
1434  memset(&dtv, 0, sizeof(DecodeThreadVars));
1435  memset(&ip6h, 0, sizeof(IPV6Hdr));
1436 
1438  DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6));
1439 
1441 
1442  PacketRecycle(p);
1443  FlowShutdown();
1444  SCFree(p);
1445  PASS;
1446 }
1447 
1448 static int ICMPV6RedirectTestUnknownCode(void)
1449 {
1450  static uint8_t raw_ipv6[] = {
1451  0x60, 0x00, 0x00, 0x00, 0x00, 0x08, 0x3a, 0xff,
1452  0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1453  0x02, 0x24, 0x8c, 0xff, 0xfe, 0x0e, 0x31, 0x54,
1454  0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1455  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
1456  0x89, 0x01, 0xba, 0xaf, 0x00, 0x00, 0x00, 0x00
1457  };
1458 
1459  Packet *p = PacketGetFromAlloc();
1460  FAIL_IF_NULL(p);
1461  IPV6Hdr ip6h;
1462  ThreadVars tv;
1464 
1465  memset(&tv, 0, sizeof(ThreadVars));
1466  memset(&dtv, 0, sizeof(DecodeThreadVars));
1467  memset(&ip6h, 0, sizeof(IPV6Hdr));
1468 
1470  DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6));
1471 
1473 
1474  PacketRecycle(p);
1475  FlowShutdown();
1476  SCFree(p);
1477  PASS;
1478 }
1479 
1480 /**
1481  * \test Test for valid ICMPv6 checksum when the FCS is still attached.
1482  *
1483  * Tests that the packet is decoded with sufficient info to verify the
1484  * checksum even if the packet has some trailing data like an ethernet
1485  * FCS.
1486  */
1487 static int ICMPV6CalculateValidChecksumWithFCS(void)
1488 {
1489  /* IPV6/ICMPv6 packet with ethernet header.
1490  * - IPv6 payload length: 36
1491  */
1492  uint8_t raw_ipv6[] = {
1493  0x33, 0x33, 0x00, 0x00, 0x00, 0x16, 0x00, 0x50,
1494  0x56, 0xa6, 0x6a, 0x7d, 0x86, 0xdd, 0x60, 0x00,
1495  0x00, 0x00, 0x00, 0x24, 0x00, 0x01, 0xfe, 0x80,
1496  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf5, 0x09,
1497  0xad, 0x44, 0x49, 0x38, 0x5f, 0xa9, 0xff, 0x02,
1498  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1499  0x00, 0x00, 0x00, 0x00, 0x00, 0x16, 0x3a, 0x00,
1500  0x05, 0x02, 0x00, 0x00, 0x01, 0x00, 0x8f, 0x00,
1501  0x24, 0xe0, 0x00, 0x00, 0x00, 0x01, 0x03, 0x00, /* Checksum: 0x24e0. */
1502  0x00, 0x00, 0xff, 0x02, 0x00, 0x00, 0x00, 0x00,
1503  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1504  0x00, 0xfb, 0x1f, 0x34, 0xf6, 0xa4
1505  };
1506  uint16_t csum = *(((uint16_t *)(raw_ipv6 + 64)));
1507 
1508  Packet *p = PacketGetFromAlloc();
1509  FAIL_IF_NULL(p);
1510  ThreadVars tv;
1512  memset(&tv, 0, sizeof(ThreadVars));
1513  memset(&dtv, 0, sizeof(DecodeThreadVars));
1514 
1516  DecodeEthernet(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6));
1517  FAIL_IF(!PacketIsICMPv6(p));
1518 
1519  const ICMPV6Hdr *icmpv6h = PacketGetICMPv6(p);
1520  const IPV6Hdr *ip6h = PacketGetIPv6(p);
1521  uint16_t icmpv6_len = IPV6_GET_RAW_PLEN(ip6h) -
1522  ((const uint8_t *)icmpv6h - (const uint8_t *)ip6h - IPV6_HEADER_LEN);
1523  FAIL_IF(icmpv6_len != 28);
1524  FAIL_IF(ICMPV6CalculateChecksum(ip6h->s_ip6_addrs, (uint16_t *)icmpv6h, icmpv6_len) != csum);
1525 
1526  PacketRecycle(p);
1527  FlowShutdown();
1528  SCFree(p);
1529  PASS;
1530 }
1531 
1532 #endif /* UNITTESTS */
1533 /**
1534  * \brief Registers ICMPV6 unit tests
1535  * \todo More ICMPv6 tests
1536  */
1538 {
1539 #ifdef UNITTESTS
1540  UtRegisterTest("ICMPV6CalculateValidChecksumtest01",
1541  ICMPV6CalculateValidChecksumtest01);
1542  UtRegisterTest("ICMPV6CalculateInvalidChecksumtest02", ICMPV6CalculateInvalidChecksumtest02);
1543 
1544  UtRegisterTest("ICMPV6ParamProbTest01 (Valid)", ICMPV6ParamProbTest01);
1545  UtRegisterTest("ICMPV6DestUnreachTest01 (Valid)", ICMPV6DestUnreachTest01);
1546  UtRegisterTest("ICMPV6PktTooBigTest01 (Valid)", ICMPV6PktTooBigTest01);
1547  UtRegisterTest("ICMPV6TimeExceedTest01 (Valid)", ICMPV6TimeExceedTest01);
1548  UtRegisterTest("ICMPV6EchoReqTest01 (Valid)", ICMPV6EchoReqTest01);
1549  UtRegisterTest("ICMPV6EchoRepTest01 (Valid)", ICMPV6EchoRepTest01);
1550 
1551  UtRegisterTest("ICMPV6ParamProbTest02 (Invalid)", ICMPV6ParamProbTest02);
1552  UtRegisterTest("ICMPV6DestUnreachTest02 (Invalid)",
1553  ICMPV6DestUnreachTest02);
1554  UtRegisterTest("ICMPV6PktTooBigTest02 (Invalid)", ICMPV6PktTooBigTest02);
1555  UtRegisterTest("ICMPV6TimeExceedTest02 (Invalid)", ICMPV6TimeExceedTest02);
1556  UtRegisterTest("ICMPV6EchoReqTest02 (Invalid)", ICMPV6EchoReqTest02);
1557  UtRegisterTest("ICMPV6EchoRepTest02 (Invalid)", ICMPV6EchoRepTest02);
1558 
1559  UtRegisterTest("ICMPV6PayloadTest01", ICMPV6PayloadTest01);
1560 
1561  UtRegisterTest("ICMPV6RouterSolicitTestKnownCode",
1562  ICMPV6RouterSolicitTestKnownCode);
1563  UtRegisterTest("ICMPV6RouterSolicitTestUnknownCode",
1564  ICMPV6RouterSolicitTestUnknownCode);
1565  UtRegisterTest("ICMPV6RouterAdvertTestKnownCode",
1566  ICMPV6RouterAdvertTestKnownCode);
1567  UtRegisterTest("ICMPV6RouterAdvertTestUnknownCode",
1568  ICMPV6RouterAdvertTestUnknownCode);
1569 
1570  UtRegisterTest("ICMPV6NeighbourSolicitTestKnownCode",
1571  ICMPV6NeighbourSolicitTestKnownCode);
1572  UtRegisterTest("ICMPV6NeighbourSolicitTestUnknownCode",
1573  ICMPV6NeighbourSolicitTestUnknownCode);
1574  UtRegisterTest("ICMPV6NeighbourAdvertTestKnownCode",
1575  ICMPV6NeighbourAdvertTestKnownCode);
1576  UtRegisterTest("ICMPV6NeighbourAdvertTestUnknownCode",
1577  ICMPV6NeighbourAdvertTestUnknownCode);
1578 
1579  UtRegisterTest("ICMPV6RedirectTestKnownCode", ICMPV6RedirectTestKnownCode);
1580  UtRegisterTest("ICMPV6RedirectTestUnknownCode",
1581  ICMPV6RedirectTestUnknownCode);
1582  UtRegisterTest("ICMPV6CalculateValidChecksumWithFCS",
1583  ICMPV6CalculateValidChecksumWithFCS);
1584 #endif /* UNITTESTS */
1585 }
1586 /**
1587  * @}
1588  */
ENGINE_SET_EVENT
#define ENGINE_SET_EVENT(p, e)
Definition: decode.h:1168
Packet_::proto
uint8_t proto
Definition: decode.h:513
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:167
IPV6_GET_RAW_HLIM
#define IPV6_GET_RAW_HLIM(ip6h)
Definition: decode-ipv6.h:67
CERT_PATH_SOLICIT
#define CERT_PATH_SOLICIT
Definition: decode-icmpv6.h:65
IPV6_GET_RAW_NH
#define IPV6_GET_RAW_NH(ip6h)
Definition: decode-ipv6.h:65
ICMP6_PACKET_TOO_BIG
#define ICMP6_PACKET_TOO_BIG
Definition: decode-icmpv6.h:37
unlikely
#define unlikely(expr)
Definition: util-optimize.h:35
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:1183
MLD_LISTENER_REPORT
#define MLD_LISTENER_REPORT
Definition: decode-icmpv6.h:46
ICMPv6GetCounterpart
int ICMPv6GetCounterpart(uint8_t type)
Definition: decode-icmpv6.c:147
SCLogDebug
#define SCLogDebug(...)
Definition: util-debug.h:269
MC_ROUTER_ADVERT
#define MC_ROUTER_ADVERT
Definition: decode-icmpv6.h:68
MC_ROUTER_TERMINATE
#define MC_ROUTER_TERMINATE
Definition: decode-icmpv6.h:70
HOME_AGENT_AD_REPLY
#define HOME_AGENT_AD_REPLY
Definition: decode-icmpv6.h:62
TCP_HEADER_LEN
#define TCP_HEADER_LEN
Definition: decode-tcp.h:28
ICMPV6_UNKNOWN_CODE
@ ICMPV6_UNKNOWN_CODE
Definition: decode-events.h:56
ICMP6_MOBILE_EXPERIMENTAL
#define ICMP6_MOBILE_EXPERIMENTAL
Definition: decode-icmpv6.h:67
DUPL_ADDR_REQUEST
#define DUPL_ADDR_REQUEST
Definition: decode-icmpv6.h:74
Packet_::payload
uint8_t * payload
Definition: decode.h:597
PacketRecycle
void PacketRecycle(Packet *p)
Definition: packet.c:142
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:58
ICMP6_TIME_EXCEED_REASSEMBLY
#define ICMP6_TIME_EXCEED_REASSEMBLY
Definition: decode-icmpv6.h:92
ICMP6_DST_UNREACH_REJECTROUTE
#define ICMP6_DST_UNREACH_REJECTROUTE
Definition: decode-icmpv6.h:87
ICMPV6_GET_ID
#define ICMPV6_GET_ID(p)
Definition: decode-icmpv6.h: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:55
TM_ECODE_FAILED
@ TM_ECODE_FAILED
Definition: tm-threads-common.h:85
Packet_::payload_len
uint16_t payload_len
Definition: decode.h:598
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:84
CERT_PATH_ADVERT
#define CERT_PATH_ADVERT
Definition: decode-icmpv6.h:66
ND_NEIGHBOR_SOLICIT
#define ND_NEIGHBOR_SOLICIT
Definition: decode-icmpv6.h:51
FMIPV6_MSG
#define FMIPV6_MSG
Definition: decode-icmpv6.h:71
ICMPV6_UNASSIGNED_TYPE
@ ICMPV6_UNASSIGNED_TYPE
Definition: decode-events.h:61
ND_REDIRECT
#define ND_REDIRECT
Definition: decode-icmpv6.h:53
FlowInitConfig
void FlowInitConfig(bool quiet)
initialize the configuration
Definition: flow.c:527
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:57
PrintInet
const char * PrintInet(int af, const void *src, char *dst, socklen_t size)
Definition: util-print.c:241
ICMPV6_IPV6_TRUNC_PKT
@ ICMPV6_IPV6_TRUNC_PKT
Definition: decode-events.h:59
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:491
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:561
ICMP6_RR
#define ICMP6_RR
Definition: decode-icmpv6.h:55
DecodeICMPV6RegisterTests
void DecodeICMPV6RegisterTests(void)
Registers ICMPV6 unit tests.
Definition: decode-icmpv6.c:1537
Packet_::l4
struct PacketL4 l4
Definition: decode.h:593
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:60
ND_INVERSE_ADVERT
#define ND_INVERSE_ADVERT
Definition: decode-icmpv6.h:59
FAIL_IF
#define FAIL_IF(expr)
Fail a test if expression evaluates to true.
Definition: util-unittest.h:71
PacketL4::type
enum PacketL4Types type
Definition: decode.h:455
PacketL4::L4Hdrs::icmpv6h
ICMPV6Hdr * icmpv6h
Definition: decode.h:462
ICMPV6_EXPERIMENTATION_TYPE
@ ICMPV6_EXPERIMENTATION_TYPE
Definition: decode-events.h:62
SCNtohs
#define SCNtohs(x)
Definition: suricata-common.h:414
DecodeICMPV6
int DecodeICMPV6(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, const uint8_t *pkt, uint32_t len)
Decode ICMPV6 packets and fill the Packet with the decoded info.
Definition: decode-icmpv6.c:179
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:675
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:57
tv
ThreadVars * tv
Definition: fuzz_decodepcapfile.c:32
PACKET_L4_ICMPV6
@ PACKET_L4_ICMPV6
Definition: decode.h:448
util-validate.h
PacketGetFromAlloc
Packet * PacketGetFromAlloc(void)
Get a malloced packet.
Definition: decode.c:232
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:955
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:979
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:1176
FLOW_QUIET
#define FLOW_QUIET
Definition: flow.h:42
IPV6_HEADER_LEN
#define IPV6_HEADER_LEN
Definition: decode-ipv6.h:27
ICMPV6Vars_::mtu
uint32_t mtu
Definition: decode-icmpv6.h: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:470
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:521
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