1 /* Copyright (C) 2007-2010 Open Information Security Foundation
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
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.
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
28 * \author Victor Julien <victor@inliniac.net>
33 #include "suricata-common.h"
34 #include "decode-icmpv6.h"
36 #include "decode-tcp.h"
37 #include "decode-sctp.h"
38 #include "decode-udp.h"
39 #include "decode-events.h"
40 #include "util-unittest.h"
42 #include "util-debug.h"
43 #include "util-print.h"
46 #include "util-profiling.h"
51 * \brief Get variables and do some checks of the embedded IPV6 packet
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
57 * \retval void No return value
59 void DecodePartialIPV6(Packet
*p
, uint8_t *partial_packet
, uint16_t len
)
61 /** Check the sizes, the header must fit at least */
62 if (len
< IPV6_HEADER_LEN
) {
63 SCLogDebug("ICMPV6_IPV6_TRUNC_PKT");
64 ENGINE_SET_INVALID_EVENT(p
, ICMPV6_IPV6_TRUNC_PKT
);
68 IPV6Hdr
*icmp6_ip6h
= (IPV6Hdr
*)partial_packet
;
70 /** Check the embedded version */
71 if(((icmp6_ip6h
->s_ip6_vfc
& 0xf0) >> 4) != 6)
73 SCLogDebug("ICMPv6 contains Unknown IPV6 version "
74 "ICMPV6_IPV6_UNKNOWN_VER");
75 ENGINE_SET_INVALID_EVENT(p
, ICMPV6_IPV6_UNKNOWN_VER
);
79 /** We need to fill icmpv6vars */
80 p
->icmpv6vars
.emb_ipv6h
= icmp6_ip6h
;
82 /** Get the IP6 address */
83 p
->icmpv6vars
.emb_ip6_src
[0] = icmp6_ip6h
->s_ip6_src
[0];
84 p
->icmpv6vars
.emb_ip6_src
[1] = icmp6_ip6h
->s_ip6_src
[1];
85 p
->icmpv6vars
.emb_ip6_src
[2] = icmp6_ip6h
->s_ip6_src
[2];
86 p
->icmpv6vars
.emb_ip6_src
[3] = icmp6_ip6h
->s_ip6_src
[3];
88 p
->icmpv6vars
.emb_ip6_dst
[0] = icmp6_ip6h
->s_ip6_dst
[0];
89 p
->icmpv6vars
.emb_ip6_dst
[1] = icmp6_ip6h
->s_ip6_dst
[1];
90 p
->icmpv6vars
.emb_ip6_dst
[2] = icmp6_ip6h
->s_ip6_dst
[2];
91 p
->icmpv6vars
.emb_ip6_dst
[3] = icmp6_ip6h
->s_ip6_dst
[3];
93 /** Get protocol and ports inside the embedded ipv6 packet and set the pointers */
94 p
->icmpv6vars
.emb_ip6_proto_next
= icmp6_ip6h
->s_ip6_nxt
;
96 switch (icmp6_ip6h
->s_ip6_nxt
) {
98 if (len
>= IPV6_HEADER_LEN
+ TCP_HEADER_LEN
) {
99 p
->icmpv6vars
.emb_tcph
= (TCPHdr
*)(partial_packet
+ IPV6_HEADER_LEN
);
100 p
->icmpv6vars
.emb_sport
= p
->icmpv6vars
.emb_tcph
->th_sport
;
101 p
->icmpv6vars
.emb_dport
= p
->icmpv6vars
.emb_tcph
->th_dport
;
103 SCLogDebug("ICMPV6->IPV6->TCP header sport: "
104 "%"PRIu8
" dport %"PRIu8
"", p
->icmpv6vars
.emb_sport
,
105 p
->icmpv6vars
.emb_dport
);
107 SCLogDebug("Warning, ICMPV6->IPV6->TCP "
108 "header Didn't fit in the packet!");
109 p
->icmpv6vars
.emb_sport
= 0;
110 p
->icmpv6vars
.emb_dport
= 0;
115 if (len
>= IPV6_HEADER_LEN
+ UDP_HEADER_LEN
) {
116 p
->icmpv6vars
.emb_udph
= (UDPHdr
*)(partial_packet
+ IPV6_HEADER_LEN
);
117 p
->icmpv6vars
.emb_sport
= p
->icmpv6vars
.emb_udph
->uh_sport
;
118 p
->icmpv6vars
.emb_dport
= p
->icmpv6vars
.emb_udph
->uh_dport
;
120 SCLogDebug("ICMPV6->IPV6->UDP header sport: "
121 "%"PRIu8
" dport %"PRIu8
"", p
->icmpv6vars
.emb_sport
,
122 p
->icmpv6vars
.emb_dport
);
124 SCLogDebug("Warning, ICMPV6->IPV6->UDP "
125 "header Didn't fit in the packet!");
126 p
->icmpv6vars
.emb_sport
= 0;
127 p
->icmpv6vars
.emb_dport
= 0;
132 p
->icmpv6vars
.emb_icmpv6h
= (ICMPV6Hdr
*)(partial_packet
+ IPV6_HEADER_LEN
);
133 p
->icmpv6vars
.emb_sport
= 0;
134 p
->icmpv6vars
.emb_dport
= 0;
136 SCLogDebug("ICMPV6->IPV6->ICMP header");
144 PrintInet(AF_INET6
, (const void *)p
->icmpv6vars
.emb_ip6_src
, s
, sizeof(s
));
145 PrintInet(AF_INET6
, (const void *)p
->icmpv6vars
.emb_ip6_dst
, d
, sizeof(d
));
146 SCLogDebug("ICMPv6 embedding IPV6 %s->%s - CLASS: %" PRIu32
" FLOW: "
147 "%" PRIu32
" NH: %" PRIu32
" PLEN: %" PRIu32
" HLIM: %" PRIu32
,
148 s
, d
, IPV6_GET_RAW_CLASS(icmp6_ip6h
), IPV6_GET_RAW_FLOW(icmp6_ip6h
),
149 IPV6_GET_RAW_NH(icmp6_ip6h
), IPV6_GET_RAW_PLEN(icmp6_ip6h
), IPV6_GET_RAW_HLIM(icmp6_ip6h
));
156 * \brief Decode ICMPV6 packets and fill the Packet with the decoded info
158 * \param tv Pointer to the thread variables
159 * \param dtv Pointer to the decode thread variables
160 * \param p Pointer to the packet we are filling
161 * \param pkt Pointer to the raw packet buffer
162 * \param len the len of the rest of the packet not processed yet
163 * \param pq the packet queue were this packet go
165 * \retval void No return value
167 int DecodeICMPV6(ThreadVars
*tv
, DecodeThreadVars
*dtv
, Packet
*p
,
168 uint8_t *pkt
, uint16_t len
, PacketQueue
*pq
)
171 StatsIncr(tv
, dtv
->counter_icmpv6
);
173 if (len
< ICMPV6_HEADER_LEN
) {
174 SCLogDebug("ICMPV6_PKT_TOO_SMALL");
175 ENGINE_SET_INVALID_EVENT(p
, ICMPV6_PKT_TOO_SMALL
);
176 return TM_ECODE_FAILED
;
179 p
->icmpv6h
= (ICMPV6Hdr
*)pkt
;
180 p
->proto
= IPPROTO_ICMPV6
;
181 p
->type
= p
->icmpv6h
->type
;
182 p
->code
= p
->icmpv6h
->code
;
183 p
->payload_len
= len
- ICMPV6_HEADER_LEN
;
184 p
->payload
= pkt
+ ICMPV6_HEADER_LEN
;
186 SCLogDebug("ICMPV6 TYPE %" PRIu32
" CODE %" PRIu32
"", p
->icmpv6h
->type
,
189 switch (ICMPV6_GET_TYPE(p
)) {
190 case ICMP6_DST_UNREACH
:
191 SCLogDebug("ICMP6_DST_UNREACH");
193 if (ICMPV6_GET_CODE(p
) > ICMP6_DST_UNREACH_REJECTROUTE
) {
194 ENGINE_SET_EVENT(p
, ICMPV6_UNKNOWN_CODE
);
196 DecodePartialIPV6(p
, (uint8_t*) (pkt
+ ICMPV6_HEADER_LEN
),
197 len
- ICMPV6_HEADER_LEN
);
202 case ICMP6_PACKET_TOO_BIG
:
203 SCLogDebug("ICMP6_PACKET_TOO_BIG");
205 if (ICMPV6_GET_CODE(p
) != 0) {
206 ENGINE_SET_EVENT(p
, ICMPV6_UNKNOWN_CODE
);
208 p
->icmpv6vars
.mtu
= ICMPV6_GET_MTU(p
);
209 DecodePartialIPV6(p
, (uint8_t*) (pkt
+ ICMPV6_HEADER_LEN
),
210 len
- ICMPV6_HEADER_LEN
);
215 case ICMP6_TIME_EXCEEDED
:
216 SCLogDebug("ICMP6_TIME_EXCEEDED");
218 if (ICMPV6_GET_CODE(p
) > ICMP6_TIME_EXCEED_REASSEMBLY
) {
219 ENGINE_SET_EVENT(p
, ICMPV6_UNKNOWN_CODE
);
221 DecodePartialIPV6(p
, (uint8_t*) (pkt
+ ICMPV6_HEADER_LEN
),
222 len
- ICMPV6_HEADER_LEN
);
227 case ICMP6_PARAM_PROB
:
228 SCLogDebug("ICMP6_PARAM_PROB");
230 if (ICMPV6_GET_CODE(p
) > ICMP6_PARAMPROB_OPTION
) {
231 ENGINE_SET_EVENT(p
, ICMPV6_UNKNOWN_CODE
);
233 p
->icmpv6vars
.error_ptr
= ICMPV6_GET_ERROR_PTR(p
);
234 DecodePartialIPV6(p
, (uint8_t*) (pkt
+ ICMPV6_HEADER_LEN
),
235 len
- ICMPV6_HEADER_LEN
);
240 case ICMP6_ECHO_REQUEST
:
241 SCLogDebug("ICMP6_ECHO_REQUEST id: %u seq: %u",
242 p
->icmpv6h
->icmpv6b
.icmpv6i
.id
, p
->icmpv6h
->icmpv6b
.icmpv6i
.seq
);
244 if (ICMPV6_GET_CODE(p
) != 0) {
245 ENGINE_SET_EVENT(p
, ICMPV6_UNKNOWN_CODE
);
247 p
->icmpv6vars
.id
= p
->icmpv6h
->icmpv6b
.icmpv6i
.id
;
248 p
->icmpv6vars
.seq
= p
->icmpv6h
->icmpv6b
.icmpv6i
.seq
;
253 case ICMP6_ECHO_REPLY
:
254 SCLogDebug("ICMP6_ECHO_REPLY id: %u seq: %u",
255 p
->icmpv6h
->icmpv6b
.icmpv6i
.id
, p
->icmpv6h
->icmpv6b
.icmpv6i
.seq
);
257 if (p
->icmpv6h
->code
!= 0) {
258 ENGINE_SET_EVENT(p
, ICMPV6_UNKNOWN_CODE
);
260 p
->icmpv6vars
.id
= p
->icmpv6h
->icmpv6b
.icmpv6i
.id
;
261 p
->icmpv6vars
.seq
= p
->icmpv6h
->icmpv6b
.icmpv6i
.seq
;
266 case ND_ROUTER_SOLICIT
:
267 SCLogDebug("ND_ROUTER_SOLICIT");
268 if (p
->icmpv6h
->code
!= 0) {
269 ENGINE_SET_EVENT(p
, ICMPV6_UNKNOWN_CODE
);
272 case ND_ROUTER_ADVERT
:
273 SCLogDebug("ND_ROUTER_ADVERT");
274 if (p
->icmpv6h
->code
!= 0) {
275 ENGINE_SET_EVENT(p
, ICMPV6_UNKNOWN_CODE
);
278 case ND_NEIGHBOR_SOLICIT
:
279 SCLogDebug("ND_NEIGHBOR_SOLICIT");
280 if (p
->icmpv6h
->code
!= 0) {
281 ENGINE_SET_EVENT(p
, ICMPV6_UNKNOWN_CODE
);
284 case ND_NEIGHBOR_ADVERT
:
285 SCLogDebug("ND_NEIGHBOR_ADVERT");
286 if (p
->icmpv6h
->code
!= 0) {
287 ENGINE_SET_EVENT(p
, ICMPV6_UNKNOWN_CODE
);
291 SCLogDebug("ND_REDIRECT");
292 if (p
->icmpv6h
->code
!= 0) {
293 ENGINE_SET_EVENT(p
, ICMPV6_UNKNOWN_CODE
);
296 case MLD_LISTENER_QUERY
:
297 SCLogDebug("MLD_LISTENER_QUERY");
298 if (p
->icmpv6h
->code
!= 0) {
299 ENGINE_SET_EVENT(p
, ICMPV6_UNKNOWN_CODE
);
301 if (IPV6_GET_HLIM(p
) != 1) {
302 ENGINE_SET_EVENT(p
, ICMPV6_MLD_MESSAGE_WITH_INVALID_HL
);
305 case MLD_LISTENER_REPORT
:
306 SCLogDebug("MLD_LISTENER_REPORT");
307 if (p
->icmpv6h
->code
!= 0) {
308 ENGINE_SET_EVENT(p
, ICMPV6_UNKNOWN_CODE
);
310 if (IPV6_GET_HLIM(p
) != 1) {
311 ENGINE_SET_EVENT(p
, ICMPV6_MLD_MESSAGE_WITH_INVALID_HL
);
314 case MLD_LISTENER_REDUCTION
:
315 SCLogDebug("MLD_LISTENER_REDUCTION");
316 if (p
->icmpv6h
->code
!= 0) {
317 ENGINE_SET_EVENT(p
, ICMPV6_UNKNOWN_CODE
);
319 if (IPV6_GET_HLIM(p
) != 1) {
320 ENGINE_SET_EVENT(p
, ICMPV6_MLD_MESSAGE_WITH_INVALID_HL
);
324 /* Various range taken from:
325 * http://www.iana.org/assignments/icmpv6-parameters/icmpv6-parameters.xhtml#icmpv6-parameters-2
327 if ((ICMPV6_GET_TYPE(p
) > 4) && (ICMPV6_GET_TYPE(p
) < 100)) {
328 ENGINE_SET_EVENT(p
, ICMPV6_UNASSIGNED_TYPE
);
329 } else if ((ICMPV6_GET_TYPE(p
) >= 100) && (ICMPV6_GET_TYPE(p
) < 102)) {
330 ENGINE_SET_EVENT(p
, ICMPV6_EXPERIMENTATION_TYPE
);
331 } else if ((ICMPV6_GET_TYPE(p
) >= 102) && (ICMPV6_GET_TYPE(p
) < 127)) {
332 ENGINE_SET_EVENT(p
, ICMPV6_UNASSIGNED_TYPE
);
333 } else if ((ICMPV6_GET_TYPE(p
) >= 160) && (ICMPV6_GET_TYPE(p
) < 200)) {
334 ENGINE_SET_EVENT(p
, ICMPV6_UNASSIGNED_TYPE
);
335 } else if ((ICMPV6_GET_TYPE(p
) >= 200) && (ICMPV6_GET_TYPE(p
) < 202)) {
336 ENGINE_SET_EVENT(p
, ICMPV6_EXPERIMENTATION_TYPE
);
337 } else if (ICMPV6_GET_TYPE(p
) >= 202) {
338 ENGINE_SET_EVENT(p
, ICMPV6_UNASSIGNED_TYPE
);
340 SCLogDebug("ICMPV6 Message type %" PRIu8
" not "
341 "implemented yet", ICMPV6_GET_TYPE(p
));
342 ENGINE_SET_EVENT(p
, ICMPV6_UNKNOWN_TYPE
);
346 /* for a info message the header is just 4 bytes */
348 if (p
->payload_len
>= 4) {
350 p
->payload
= pkt
+ 4;
358 if (ENGINE_ISSET_EVENT(p
, ICMPV6_UNKNOWN_CODE
))
359 SCLogDebug("Unknown Code, ICMPV6_UNKNOWN_CODE");
361 if (ENGINE_ISSET_EVENT(p
, ICMPV6_UNKNOWN_TYPE
))
362 SCLogDebug("Unknown Type, ICMPV6_UNKNOWN_TYPE");
365 /* Flow is an integral part of us */
366 FlowHandlePacket(tv
, dtv
, p
);
373 static int ICMPV6CalculateValidChecksumtest01(void)
377 uint8_t raw_ipv6
[] = {
378 0x00, 0x00, 0x86, 0x05, 0x80, 0xda, 0x00, 0x60,
379 0x97, 0x07, 0x69, 0xea, 0x86, 0xdd, 0x60, 0x00,
380 0x00, 0x00, 0x00, 0x44, 0x3a, 0x40, 0x3f, 0xfe,
381 0x05, 0x07, 0x00, 0x00, 0x00, 0x01, 0x02, 0x60,
382 0x97, 0xff, 0xfe, 0x07, 0x69, 0xea, 0x3f, 0xfe,
383 0x05, 0x07, 0x00, 0x00, 0x00, 0x01, 0x02, 0x00,
384 0x86, 0xff, 0xfe, 0x05, 0x80, 0xda, 0x03, 0x00,
385 0xf7, 0x52, 0x00, 0x00, 0x00, 0x00, 0x60, 0x00,
386 0x00, 0x00, 0x00, 0x14, 0x11, 0x01, 0x3f, 0xfe,
387 0x05, 0x07, 0x00, 0x00, 0x00, 0x01, 0x02, 0x00,
388 0x86, 0xff, 0xfe, 0x05, 0x80, 0xda, 0x3f, 0xfe,
389 0x05, 0x01, 0x04, 0x10, 0x00, 0x00, 0x02, 0xc0,
390 0xdf, 0xff, 0xfe, 0x47, 0x03, 0x3e, 0xa0, 0x75,
391 0x82, 0x9b, 0x00, 0x14, 0x82, 0x8b, 0x01, 0x01,
392 0x00, 0x00, 0xf9, 0xc8, 0xe7, 0x36, 0xf5, 0xed,
395 csum
= *( ((uint16_t *)(raw_ipv6
+ 56)));
397 return (csum
== ICMPV6CalculateChecksum((uint16_t *)(raw_ipv6
+ 14 + 8),
398 (uint16_t *)(raw_ipv6
+ 54), 68));
401 static int ICMPV6CalculateInvalidChecksumtest02(void)
405 uint8_t raw_ipv6
[] = {
406 0x00, 0x00, 0x86, 0x05, 0x80, 0xda, 0x00, 0x60,
407 0x97, 0x07, 0x69, 0xea, 0x86, 0xdd, 0x60, 0x00,
408 0x00, 0x00, 0x00, 0x44, 0x3a, 0x40, 0x3f, 0xfe,
409 0x05, 0x07, 0x00, 0x00, 0x00, 0x01, 0x02, 0x60,
410 0x97, 0xff, 0xfe, 0x07, 0x69, 0xea, 0x3f, 0xfe,
411 0x05, 0x07, 0x00, 0x00, 0x00, 0x01, 0x02, 0x00,
412 0x86, 0xff, 0xfe, 0x05, 0x80, 0xda, 0x03, 0x00,
413 0xf7, 0x52, 0x00, 0x00, 0x00, 0x00, 0x60, 0x00,
414 0x00, 0x00, 0x00, 0x14, 0x11, 0x01, 0x3f, 0xfe,
415 0x05, 0x07, 0x00, 0x00, 0x00, 0x01, 0x02, 0x00,
416 0x86, 0xff, 0xfe, 0x05, 0x80, 0xda, 0x3f, 0xfe,
417 0x05, 0x01, 0x04, 0x10, 0x00, 0x00, 0x02, 0xc0,
418 0xdf, 0xff, 0xfe, 0x47, 0x03, 0x3e, 0xa0, 0x75,
419 0x82, 0x9b, 0x00, 0x14, 0x82, 0x8b, 0x01, 0x01,
420 0x00, 0x00, 0xf9, 0xc8, 0xe7, 0x36, 0xf5, 0xed,
423 csum
= *( ((uint16_t *)(raw_ipv6
+ 56)));
425 return (csum
== ICMPV6CalculateChecksum((uint16_t *)(raw_ipv6
+ 14 + 8),
426 (uint16_t *)(raw_ipv6
+ 54), 68));
430 /** \test icmpv6 message type: parameter problem, valid packet
432 * \retval retval 0 = Error ; 1 = ok
434 static int ICMPV6ParamProbTest01(void)
437 static uint8_t raw_ipv6
[] = {
438 0x60, 0x00, 0x00, 0x00, 0x00, 0x38, 0x3a, 0xff,
439 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
440 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
441 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
442 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
443 0x04, 0x00, 0xcc, 0x2a, 0x6d, 0x93, 0x0b, 0xdf,
444 0x69, 0x70, 0x12, 0xb7, 0x00, 0x08, 0x3a, 0xff,
445 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
446 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
447 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
448 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
449 0x80, 0x00, 0x08, 0xb5, 0x99, 0xc3, 0xde, 0x40 };
451 Packet
*p
= SCMalloc(SIZE_OF_PACKET
);
452 if (unlikely(p
== NULL
))
456 DecodeThreadVars dtv
;
459 ipv6src
= (uint32_t*) &raw_ipv6
[8];
460 ipv6dst
= (uint32_t*) &raw_ipv6
[24];
462 memset(&tv
, 0, sizeof(ThreadVars
));
463 memset(p
, 0, SIZE_OF_PACKET
);
464 memset(&dtv
, 0, sizeof(DecodeThreadVars
));
465 memset(&ip6h
, 0, sizeof(IPV6Hdr
));
467 FlowInitConfig(FLOW_QUIET
);
468 DecodeIPV6(&tv
, &dtv
, p
, raw_ipv6
, sizeof(raw_ipv6
), NULL
);
470 if (p
->icmpv6h
== NULL
) {
471 SCLogDebug("ICMPv6 Unable to detect icmpv6 layer from ipv6");
476 if (ICMPV6_GET_TYPE(p
) != 4 || ICMPV6_GET_CODE(p
) != 0 ||
477 ICMPV6_GET_EMB_PROTO(p
) != IPPROTO_ICMPV6
) {
478 SCLogDebug("ICMPv6 not processed at all");
483 /* Let's check if we retrieved the embedded ipv6 addresses correctly */
485 for (i
= 0; i
< 4; i
++) {
486 if (p
->icmpv6vars
.emb_ip6_src
[i
] != ipv6src
[i
] ||
487 p
->icmpv6vars
.emb_ip6_dst
[i
] != ipv6dst
[i
]) {
488 SCLogDebug("ICMPv6 DecodePartialICMPV6 (Embedded ip6h) didn't set "
489 "the src and dest ip addresses correctly");
503 /** \test icmpv6 message type: packet too big, valid packet
505 * \retval retval 0 = Error ; 1 = ok
507 static int ICMPV6PktTooBigTest01(void)
510 static uint8_t raw_ipv6
[] = {
511 0x60, 0x00, 0x00, 0x00, 0x00, 0x30, 0x3a, 0xff,
512 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
513 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
514 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
515 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
516 0x02, 0x00, 0x5c, 0x7a, 0x00, 0x00, 0x05, 0x00,
517 0x64, 0x14, 0xfd, 0xff, 0x00, 0x00, 0x3b, 0xff,
518 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
519 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
520 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
521 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 };
523 Packet
*p
= SCMalloc(SIZE_OF_PACKET
);
524 if (unlikely(p
== NULL
))
528 DecodeThreadVars dtv
;
531 ipv6src
= (uint32_t*) &raw_ipv6
[8];
532 ipv6dst
= (uint32_t*) &raw_ipv6
[24];
534 memset(&tv
, 0, sizeof(ThreadVars
));
535 memset(p
, 0, SIZE_OF_PACKET
);
536 memset(&dtv
, 0, sizeof(DecodeThreadVars
));
537 memset(&ip6h
, 0, sizeof(IPV6Hdr
));
539 FlowInitConfig(FLOW_QUIET
);
540 DecodeIPV6(&tv
, &dtv
, p
, raw_ipv6
, sizeof(raw_ipv6
), NULL
);
542 if (p
->icmpv6h
== NULL
) {
543 SCLogDebug("ICMPv6 Unable to detect icmpv6 layer from ipv6");
548 /* Note: it has an embedded ipv6 packet but no protocol after ipv6 (IPPROTO_NONE) */
549 if (ICMPV6_GET_TYPE(p
) != 2 || ICMPV6_GET_CODE(p
) != 0 ) {
550 SCLogDebug("ICMPv6 Not processed at all");
555 /* Let's check if we retrieved the embedded ipv6 addresses correctly */
557 for (i
= 0; i
< 4; i
++) {
558 if (p
->icmpv6vars
.emb_ip6_src
[i
] != ipv6src
[i
] ||
559 p
->icmpv6vars
.emb_ip6_dst
[i
] != ipv6dst
[i
]) {
560 SCLogDebug("ICMPv6 DecodePartialICMPV6 (Embedded ip6h) didn't set "
561 "the src and dest ip addresses correctly");
567 SCLogDebug("ICMPV6 IPV6 src and dst properly set");
577 /** \test icmpv6 message type: time exceed, valid packet
579 * \retval retval 0 = Error ; 1 = ok
581 static int ICMPV6TimeExceedTest01(void)
584 static uint8_t raw_ipv6
[] = {
585 0x60, 0x00, 0x00, 0x00, 0x00, 0x30, 0x3a, 0xff,
586 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
587 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
588 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
589 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
590 0x03, 0x00, 0x56, 0x2d, 0x00, 0x00, 0x00, 0x00,
591 0x6d, 0x23, 0xff, 0x3d, 0x00, 0x00, 0x3b, 0xff,
592 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
593 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
594 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
595 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 };
597 Packet
*p
= SCMalloc(SIZE_OF_PACKET
);
598 if (unlikely(p
== NULL
))
602 DecodeThreadVars dtv
;
605 ipv6src
= (uint32_t*) &raw_ipv6
[8];
606 ipv6dst
= (uint32_t*) &raw_ipv6
[24];
609 memset(&tv
, 0, sizeof(ThreadVars
));
610 memset(p
, 0, SIZE_OF_PACKET
);
611 memset(&dtv
, 0, sizeof(DecodeThreadVars
));
612 memset(&ip6h
, 0, sizeof(IPV6Hdr
));
614 FlowInitConfig(FLOW_QUIET
);
615 DecodeIPV6(&tv
, &dtv
, p
, raw_ipv6
, sizeof(raw_ipv6
), NULL
);
617 if (p
->icmpv6h
== NULL
) {
618 SCLogDebug("ICMPv6 Unable to detect icmpv6 layer from ipv6");
623 /* Note: it has an embedded ipv6 packet but no protocol after ipv6 (IPPROTO_NONE) */
624 if (ICMPV6_GET_TYPE(p
) != 3 || ICMPV6_GET_CODE(p
) != 0 ||
625 ICMPV6_GET_EMB_IPV6(p
)==NULL
|| ICMPV6_GET_EMB_PROTO(p
) != IPPROTO_NONE
) {
626 SCLogDebug("ICMPv6 Not processed at all");
631 /* Let's check if we retrieved the embedded ipv6 addresses correctly */
633 for (i
= 0; i
< 4; i
++) {
634 if (p
->icmpv6vars
.emb_ip6_src
[i
] != ipv6src
[i
] ||
635 p
->icmpv6vars
.emb_ip6_dst
[i
] != ipv6dst
[i
]) {
636 SCLogDebug("ICMPv6 DecodePartialICMPV6 (Embedded ip6h) didn't set "
637 "the src and dest ip addresses correctly");
643 SCLogDebug("ICMPV6 IPV6 src and dst properly set");
653 /** \test icmpv6 message type: destination unreach, valid packet
655 * \retval retval 0 = Error ; 1 = ok
657 static int ICMPV6DestUnreachTest01(void)
660 static uint8_t raw_ipv6
[] = {
661 0x60, 0x00, 0x00, 0x00, 0x00, 0x30, 0x3a, 0xff,
662 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
663 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
664 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
665 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
666 0x01, 0x00, 0x7b, 0x85, 0x00, 0x00, 0x00, 0x00,
667 0x60, 0x4b, 0xe8, 0xbd, 0x00, 0x00, 0x3b, 0xff,
668 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
669 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
670 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
671 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 };
673 Packet
*p
= SCMalloc(SIZE_OF_PACKET
);
674 if (unlikely(p
== NULL
))
678 DecodeThreadVars dtv
;
681 ipv6src
= (uint32_t*) &raw_ipv6
[8];
682 ipv6dst
= (uint32_t*) &raw_ipv6
[24];
685 memset(&tv
, 0, sizeof(ThreadVars
));
686 memset(p
, 0, SIZE_OF_PACKET
);
687 memset(&dtv
, 0, sizeof(DecodeThreadVars
));
688 memset(&ip6h
, 0, sizeof(IPV6Hdr
));
690 FlowInitConfig(FLOW_QUIET
);
691 DecodeIPV6(&tv
, &dtv
, p
, raw_ipv6
, sizeof(raw_ipv6
), NULL
);
693 if (p
->icmpv6h
== NULL
) {
694 SCLogDebug("ICMPv6 Unable to detect icmpv6 layer from ipv6");
699 /* Note: it has an embedded ipv6 packet but no protocol after ipv6 (IPPROTO_NONE) */
700 if (ICMPV6_GET_TYPE(p
) != 1 || ICMPV6_GET_CODE(p
) != 0 ||
701 ICMPV6_GET_EMB_IPV6(p
) == NULL
|| ICMPV6_GET_EMB_PROTO(p
) != IPPROTO_NONE
) {
702 SCLogDebug("ICMPv6 Not processed at all");
707 /* Let's check if we retrieved the embedded ipv6 addresses correctly */
709 for (i
= 0; i
< 4; i
++) {
710 if (p
->icmpv6vars
.emb_ip6_src
[i
] != ipv6src
[i
] ||
711 p
->icmpv6vars
.emb_ip6_dst
[i
] != ipv6dst
[i
]) {
712 SCLogDebug("ICMPv6 DecodePartialICMPV6 (Embedded ip6h) didn't set "
713 "the src and dest ip addresses correctly");
727 /**\test icmpv6 message type: echo request, valid packet
728 * \retval retval 0 = Error ; 1 = ok
730 static int ICMPV6EchoReqTest01(void)
733 static uint8_t raw_ipv6
[] = {
734 0x60, 0x00, 0x00, 0x00, 0x00, 0x08, 0x3a, 0xff,
735 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
736 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
737 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
738 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
739 0x80, 0x00, 0xe5, 0xa5, 0x25, 0xf0, 0x75, 0x23 };
741 Packet
*p
= SCMalloc(SIZE_OF_PACKET
);
742 if (unlikely(p
== NULL
))
746 DecodeThreadVars dtv
;
748 memset(&tv
, 0, sizeof(ThreadVars
));
749 memset(p
, 0, SIZE_OF_PACKET
);
750 memset(&dtv
, 0, sizeof(DecodeThreadVars
));
751 memset(&ip6h
, 0, sizeof(IPV6Hdr
));
753 FlowInitConfig(FLOW_QUIET
);
754 DecodeIPV6(&tv
, &dtv
, p
, raw_ipv6
, sizeof(raw_ipv6
), NULL
);
756 if (p
->icmpv6h
== NULL
) {
757 SCLogDebug("ICMPv6 Unable to detect icmpv6 layer from ipv6");
761 SCLogDebug("ID: %u seq: %u", ICMPV6_GET_ID(p
), ICMPV6_GET_SEQ(p
));
763 if (ICMPV6_GET_TYPE(p
) != 128 || ICMPV6_GET_CODE(p
) != 0 ||
764 ntohs(ICMPV6_GET_ID(p
)) != 9712 || ntohs(ICMPV6_GET_SEQ(p
)) != 29987) {
765 printf("ICMPv6 Echo reply decode failed TYPE %u CODE %u ID %04x(%u) SEQ %04x(%u): ",
766 ICMPV6_GET_TYPE(p
), ICMPV6_GET_CODE(p
), ICMPV6_GET_ID(p
), ntohs(ICMPV6_GET_ID(p
)),
767 ICMPV6_GET_SEQ(p
), ntohs(ICMPV6_GET_SEQ(p
)));
779 /**\test icmpv6 message type: echo reply, valid packet
780 * \retval retval 0 = Error ; 1 = ok
782 static int ICMPV6EchoRepTest01(void)
785 static uint8_t raw_ipv6
[] = {
786 0x60, 0x00, 0x00, 0x00, 0x00, 0x08, 0x3a,
787 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
788 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
789 0x00, 0x00, 0x00, 0xff, 0x02, 0x00, 0x00,
790 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
791 0x00, 0x00, 0x00, 0x00, 0x01, 0x81, 0x00,
792 0xe5, 0xa5, 0x25, 0xf0, 0x75, 0x23 };
794 Packet
*p
= SCMalloc(SIZE_OF_PACKET
);
795 if (unlikely(p
== NULL
))
799 DecodeThreadVars dtv
;
801 memset(&tv
, 0, sizeof(ThreadVars
));
802 memset(p
, 0, SIZE_OF_PACKET
);
803 memset(&dtv
, 0, sizeof(DecodeThreadVars
));
804 memset(&ip6h
, 0, sizeof(IPV6Hdr
));
806 FlowInitConfig(FLOW_QUIET
);
807 DecodeIPV6(&tv
, &dtv
, p
, raw_ipv6
, sizeof(raw_ipv6
), NULL
);
809 if (p
->icmpv6h
== NULL
) {
810 SCLogDebug("ICMPv6 Unable to detect icmpv6 layer from ipv6");
814 SCLogDebug("type: %u code %u ID: %u seq: %u", ICMPV6_GET_TYPE(p
),
815 ICMPV6_GET_CODE(p
),ICMPV6_GET_ID(p
), ICMPV6_GET_SEQ(p
));
817 if (ICMPV6_GET_TYPE(p
) != 129 || ICMPV6_GET_CODE(p
) != 0 ||
818 ntohs(ICMPV6_GET_ID(p
)) != 9712 || ntohs(ICMPV6_GET_SEQ(p
)) != 29987) {
819 printf("ICMPv6 Echo reply decode failed TYPE %u CODE %u ID %04x(%u) SEQ %04x(%u): ",
820 ICMPV6_GET_TYPE(p
), ICMPV6_GET_CODE(p
), ICMPV6_GET_ID(p
), ntohs(ICMPV6_GET_ID(p
)),
821 ICMPV6_GET_SEQ(p
), ntohs(ICMPV6_GET_SEQ(p
)));
833 /** \test icmpv6 message type: parameter problem, invalid packet
834 * \brief set the event ICMPV6_IPV6_UNKNOWN_VER properly when the embedded packet has an unknown version
835 * \retval retval 0 = Error ; 1 = ok
837 static int ICMPV6ParamProbTest02(void)
840 static uint8_t raw_ipv6
[] = {
841 0x60, 0x00, 0x00, 0x00, 0x00, 0x38, 0x3a, 0xff,
842 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
843 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
844 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
845 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
846 0x04, 0x00, 0xcc, 0x2a, 0x6d, 0x93, 0x0b, 0xdf,
847 0x38, 0x70, 0x12, 0xb7, 0x00, 0x08, 0x3a, 0xff,
848 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
849 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
850 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
851 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
852 0x80, 0x00, 0x08, 0xb5, 0x99, 0xc3, 0xde, 0x40 };
854 Packet
*p
= SCMalloc(SIZE_OF_PACKET
);
855 if (unlikely(p
== NULL
))
859 DecodeThreadVars dtv
;
861 memset(&tv
, 0, sizeof(ThreadVars
));
862 memset(p
, 0, SIZE_OF_PACKET
);
863 memset(&dtv
, 0, sizeof(DecodeThreadVars
));
864 memset(&ip6h
, 0, sizeof(IPV6Hdr
));
866 FlowInitConfig(FLOW_QUIET
);
867 DecodeIPV6(&tv
, &dtv
, p
, raw_ipv6
, sizeof(raw_ipv6
), NULL
);
869 if (p
->icmpv6h
== NULL
) {
870 SCLogDebug("ICMPv6 Unable to detect icmpv6 layer from ipv6");
875 if (ICMPV6_GET_TYPE(p
) != 4 || ICMPV6_GET_CODE(p
) != 0) {
876 SCLogDebug("ICMPv6 Not processed at all");
881 if (!ENGINE_ISSET_EVENT(p
, ICMPV6_IPV6_UNKNOWN_VER
)) {
882 SCLogDebug("ICMPv6 Error: Unknown embedded ipv6 version event not set");
895 /** \test icmpv6 message type: packet too big, invalid packet
896 * \brief Set the event ICMPV6_UNKNOWN_CODE if code is invalid for this type
897 * \retval retval 0 = Error ; 1 = ok
899 static int ICMPV6PktTooBigTest02(void)
902 static uint8_t raw_ipv6
[] = {
903 0x60, 0x00, 0x00, 0x00, 0x00, 0x30, 0x3a, 0xff,
904 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
905 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
906 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
907 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
908 0x02, 0x10, 0x5c, 0x7a, 0x00, 0x00, 0x05, 0x00,
909 0x64, 0x14, 0xfd, 0xff, 0x00, 0x00, 0x3b, 0xff,
910 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
911 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
912 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
913 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 };
915 Packet
*p
= SCMalloc(SIZE_OF_PACKET
);
916 if (unlikely(p
== NULL
))
920 DecodeThreadVars dtv
;
922 memset(&tv
, 0, sizeof(ThreadVars
));
923 memset(p
, 0, SIZE_OF_PACKET
);
924 memset(&dtv
, 0, sizeof(DecodeThreadVars
));
925 memset(&ip6h
, 0, sizeof(IPV6Hdr
));
927 FlowInitConfig(FLOW_QUIET
);
928 DecodeIPV6(&tv
, &dtv
, p
, raw_ipv6
, sizeof(raw_ipv6
), NULL
);
930 if (p
->icmpv6h
== NULL
) {
931 SCLogDebug("ICMPv6 Unable to detect icmpv6 layer from ipv6");
936 if (!ENGINE_ISSET_EVENT(p
, ICMPV6_UNKNOWN_CODE
)) {
937 SCLogDebug("ICMPv6 Error: Unknown code event not set");
950 /** \test icmpv6 message type: time exceed, invalid packet
951 * \brief set the event ICMPV6_PKT_TOO_SMALL properly
952 * \retval retval 0 = Error ; 1 = ok
954 static int ICMPV6TimeExceedTest02(void)
957 static uint8_t raw_ipv6
[] = {
958 0x60, 0x00, 0x00, 0x00, 0x00, 0x03, 0x3a, 0xff,
959 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
960 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
961 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
962 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
965 /* The icmpv6 header is broken in the checksum (so we dont have a complete header) */
967 Packet
*p
= SCMalloc(SIZE_OF_PACKET
);
968 if (unlikely(p
== NULL
))
972 DecodeThreadVars dtv
;
974 memset(&tv
, 0, sizeof(ThreadVars
));
975 memset(p
, 0, SIZE_OF_PACKET
);
976 memset(&dtv
, 0, sizeof(DecodeThreadVars
));
977 memset(&ip6h
, 0, sizeof(IPV6Hdr
));
979 FlowInitConfig(FLOW_QUIET
);
980 DecodeIPV6(&tv
, &dtv
, p
, raw_ipv6
, sizeof(raw_ipv6
), NULL
);
982 if (!ENGINE_ISSET_EVENT(p
, ICMPV6_PKT_TOO_SMALL
)) {
983 SCLogDebug("ICMPv6 Error: event packet too small not set");
996 /**\test icmpv6 message type: destination unreach, invalid packet
997 * \brief The embedded packet header (ipv6) is truncated
998 * \retval retval 0 = Error ; 1 = ok
1000 static int ICMPV6DestUnreachTest02(void)
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 };
1016 Packet
*p
= SCMalloc(SIZE_OF_PACKET
);
1017 if (unlikely(p
== NULL
))
1021 DecodeThreadVars dtv
;
1023 memset(&tv
, 0, sizeof(ThreadVars
));
1024 memset(p
, 0, SIZE_OF_PACKET
);
1025 memset(&dtv
, 0, sizeof(DecodeThreadVars
));
1026 memset(&ip6h
, 0, sizeof(IPV6Hdr
));
1028 FlowInitConfig(FLOW_QUIET
);
1029 DecodeIPV6(&tv
, &dtv
, p
, raw_ipv6
, sizeof(raw_ipv6
), NULL
);
1031 if (!ENGINE_ISSET_EVENT(p
, ICMPV6_IPV6_TRUNC_PKT
)) {
1032 SCLogDebug("ICMPv6 Error: embedded ipv6 truncated packet event not set");
1045 /**\test icmpv6 message type: echo request, invalid packet
1046 * \brief unknown code
1047 * \retval retval 0 = Error ; 1 = ok
1049 static int ICMPV6EchoReqTest02(void)
1052 static uint8_t raw_ipv6
[] = {
1053 0x60, 0x00, 0x00, 0x00, 0x00, 0x08, 0x3a,
1054 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1055 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1056 0x00, 0x00, 0x00, 0xff, 0x02, 0x00, 0x00,
1057 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1058 0x00, 0x00, 0x00, 0x00, 0x01, 0x80, 0x01,
1059 0xe5, 0xa5, 0x25, 0xf0, 0x75, 0x23 };
1061 Packet
*p
= SCMalloc(SIZE_OF_PACKET
);
1062 if (unlikely(p
== NULL
))
1066 DecodeThreadVars dtv
;
1068 memset(&tv
, 0, sizeof(ThreadVars
));
1069 memset(p
, 0, SIZE_OF_PACKET
);
1070 memset(&dtv
, 0, sizeof(DecodeThreadVars
));
1071 memset(&ip6h
, 0, sizeof(IPV6Hdr
));
1073 FlowInitConfig(FLOW_QUIET
);
1074 DecodeIPV6(&tv
, &dtv
, p
, raw_ipv6
, sizeof(raw_ipv6
), NULL
);
1076 if (!ENGINE_ISSET_EVENT(p
, ICMPV6_UNKNOWN_CODE
)) {
1077 SCLogDebug("ICMPv6 Error: Unknown code event not set");
1090 /**\test icmpv6 message type: echo reply, invalid packet
1091 * \brief unknown code
1092 * \retval retval 0 = Error ; 1 = ok
1094 static int ICMPV6EchoRepTest02(void)
1097 static uint8_t raw_ipv6
[] = {
1098 0x60, 0x00, 0x00, 0x00, 0x00, 0x08, 0x3a,
1099 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1100 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1101 0x00, 0x00, 0x00, 0xff, 0x02, 0x00, 0x00,
1102 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1103 0x00, 0x00, 0x00, 0x00, 0x01, 0x81, 0x01,
1104 0xe5, 0xa5, 0x25, 0xf0, 0x75, 0x23 };
1106 Packet
*p
= SCMalloc(SIZE_OF_PACKET
);
1107 if (unlikely(p
== NULL
))
1111 DecodeThreadVars dtv
;
1113 memset(&tv
, 0, sizeof(ThreadVars
));
1114 memset(p
, 0, SIZE_OF_PACKET
);
1115 memset(&dtv
, 0, sizeof(DecodeThreadVars
));
1116 memset(&ip6h
, 0, sizeof(IPV6Hdr
));
1118 FlowInitConfig(FLOW_QUIET
);
1119 DecodeIPV6(&tv
, &dtv
, p
, raw_ipv6
, sizeof(raw_ipv6
), NULL
);
1121 if (!ENGINE_ISSET_EVENT(p
, ICMPV6_UNKNOWN_CODE
)) {
1122 SCLogDebug("ICMPv6 Error: Unknown code event not set");
1135 /**\test icmpv6 packet decoding and setting up of payload_len and payload buufer
1136 * \retval retval 0 = Error ; 1 = ok
1138 static int ICMPV6PayloadTest01(void)
1141 static uint8_t raw_ipv6
[] = {
1142 0x60, 0x00, 0x00, 0x00, 0x00, 0x2d, 0x3a, 0xff,
1143 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1144 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1145 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1146 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
1147 0x01, 0x00, 0x7b, 0x85, 0x00, 0x00, 0x00, 0x00,
1148 0x60, 0x4b, 0xe8, 0xbd, 0x00, 0x00, 0x3b, 0xff,
1149 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1150 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1151 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1152 0x00, 0x00, 0x00, 0x00, 0x00 };
1154 Packet
*p
= SCMalloc(SIZE_OF_PACKET
);
1155 if (unlikely(p
== NULL
))
1159 DecodeThreadVars dtv
;
1161 memset(&tv
, 0, sizeof(ThreadVars
));
1162 memset(p
, 0, SIZE_OF_PACKET
);
1163 memset(&dtv
, 0, sizeof(DecodeThreadVars
));
1164 memset(&ip6h
, 0, sizeof(IPV6Hdr
));
1166 FlowInitConfig(FLOW_QUIET
);
1167 DecodeIPV6(&tv
, &dtv
, p
, raw_ipv6
, sizeof(raw_ipv6
), NULL
);
1169 if (p
->payload
== NULL
) {
1170 printf("payload == NULL, expected non-NULL: ");
1174 if (p
->payload_len
!= 37) {
1175 printf("payload_len %"PRIu16
", expected 37: ", p
->payload_len
);
1187 static int ICMPV6RouterSolicitTestKnownCode(void)
1191 static uint8_t raw_ipv6
[] = {
1192 0x60, 0x00, 0x00, 0x00, 0x00, 0x08, 0x3a, 0xff,
1193 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1194 0x02, 0x24, 0x8c, 0xff, 0xfe, 0x0e, 0x31, 0x54,
1195 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1196 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
1197 0x85, 0x00, 0xbe, 0xb0, 0x00, 0x00, 0x00, 0x00
1200 Packet
*p
= SCMalloc(SIZE_OF_PACKET
);
1201 if (unlikely(p
== NULL
))
1205 DecodeThreadVars dtv
;
1207 memset(&tv
, 0, sizeof(ThreadVars
));
1208 memset(p
, 0, SIZE_OF_PACKET
);
1209 memset(&dtv
, 0, sizeof(DecodeThreadVars
));
1210 memset(&ip6h
, 0, sizeof(IPV6Hdr
));
1212 FlowInitConfig(FLOW_QUIET
);
1213 DecodeIPV6(&tv
, &dtv
, p
, raw_ipv6
, sizeof(raw_ipv6
), NULL
);
1215 if (ENGINE_ISSET_EVENT(p
, ICMPV6_UNKNOWN_CODE
)) {
1216 SCLogDebug("ICMPv6 Error: Unknown code event is set");
1229 static int ICMPV6RouterSolicitTestUnknownCode(void)
1233 static uint8_t raw_ipv6
[] = {
1234 0x60, 0x00, 0x00, 0x00, 0x00, 0x08, 0x3a, 0xff,
1235 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1236 0x02, 0x24, 0x8c, 0xff, 0xfe, 0x0e, 0x31, 0x54,
1237 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1238 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
1239 0x85, 0x01, 0xbe, 0xaf, 0x00, 0x00, 0x00, 0x00
1242 Packet
*p
= SCMalloc(SIZE_OF_PACKET
);
1243 if (unlikely(p
== NULL
))
1247 DecodeThreadVars dtv
;
1249 memset(&tv
, 0, sizeof(ThreadVars
));
1250 memset(p
, 0, SIZE_OF_PACKET
);
1251 memset(&dtv
, 0, sizeof(DecodeThreadVars
));
1252 memset(&ip6h
, 0, sizeof(IPV6Hdr
));
1254 FlowInitConfig(FLOW_QUIET
);
1255 DecodeIPV6(&tv
, &dtv
, p
, raw_ipv6
, sizeof(raw_ipv6
), NULL
);
1257 if (!ENGINE_ISSET_EVENT(p
, ICMPV6_UNKNOWN_CODE
)) {
1258 SCLogDebug("ICMPv6 Error: Unknown code event is not set");
1271 static int ICMPV6RouterAdvertTestKnownCode(void)
1275 static uint8_t raw_ipv6
[] = {
1276 0x60, 0x00, 0x00, 0x00, 0x00, 0x08, 0x3a, 0xff,
1277 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1278 0x02, 0x24, 0x8c, 0xff, 0xfe, 0x0e, 0x31, 0x54,
1279 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1280 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
1281 0x86, 0x00, 0xbd, 0xb0, 0x00, 0x00, 0x00, 0x00
1284 Packet
*p
= SCMalloc(SIZE_OF_PACKET
);
1285 if (unlikely(p
== NULL
))
1289 DecodeThreadVars dtv
;
1291 memset(&tv
, 0, sizeof(ThreadVars
));
1292 memset(p
, 0, SIZE_OF_PACKET
);
1293 memset(&dtv
, 0, sizeof(DecodeThreadVars
));
1294 memset(&ip6h
, 0, sizeof(IPV6Hdr
));
1296 FlowInitConfig(FLOW_QUIET
);
1297 DecodeIPV6(&tv
, &dtv
, p
, raw_ipv6
, sizeof(raw_ipv6
), NULL
);
1299 if (ENGINE_ISSET_EVENT(p
, ICMPV6_UNKNOWN_CODE
)) {
1300 SCLogDebug("ICMPv6 Error: Unknown code event is set");
1313 static int ICMPV6RouterAdvertTestUnknownCode(void)
1317 static uint8_t raw_ipv6
[] = {
1318 0x60, 0x00, 0x00, 0x00, 0x00, 0x08, 0x3a, 0xff,
1319 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1320 0x02, 0x24, 0x8c, 0xff, 0xfe, 0x0e, 0x31, 0x54,
1321 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1322 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
1323 0x86, 0x01, 0xbd, 0xaf, 0x00, 0x00, 0x00, 0x00
1326 Packet
*p
= SCMalloc(SIZE_OF_PACKET
);
1327 if (unlikely(p
== NULL
))
1331 DecodeThreadVars dtv
;
1333 memset(&tv
, 0, sizeof(ThreadVars
));
1334 memset(p
, 0, SIZE_OF_PACKET
);
1335 memset(&dtv
, 0, sizeof(DecodeThreadVars
));
1336 memset(&ip6h
, 0, sizeof(IPV6Hdr
));
1338 FlowInitConfig(FLOW_QUIET
);
1339 DecodeIPV6(&tv
, &dtv
, p
, raw_ipv6
, sizeof(raw_ipv6
), NULL
);
1341 if (!ENGINE_ISSET_EVENT(p
, ICMPV6_UNKNOWN_CODE
)) {
1342 SCLogDebug("ICMPv6 Error: Unknown code event is not set");
1355 static int ICMPV6NeighbourSolicitTestKnownCode(void)
1359 static uint8_t raw_ipv6
[] = {
1360 0x60, 0x00, 0x00, 0x00, 0x00, 0x08, 0x3a, 0xff,
1361 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1362 0x02, 0x24, 0x8c, 0xff, 0xfe, 0x0e, 0x31, 0x54,
1363 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1364 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
1365 0x87, 0x00, 0xbc, 0xb0, 0x00, 0x00, 0x00, 0x00
1368 Packet
*p
= SCMalloc(SIZE_OF_PACKET
);
1369 if (unlikely(p
== NULL
))
1373 DecodeThreadVars dtv
;
1375 memset(&tv
, 0, sizeof(ThreadVars
));
1376 memset(p
, 0, SIZE_OF_PACKET
);
1377 memset(&dtv
, 0, sizeof(DecodeThreadVars
));
1378 memset(&ip6h
, 0, sizeof(IPV6Hdr
));
1380 FlowInitConfig(FLOW_QUIET
);
1381 DecodeIPV6(&tv
, &dtv
, p
, raw_ipv6
, sizeof(raw_ipv6
), NULL
);
1383 if (ENGINE_ISSET_EVENT(p
, ICMPV6_UNKNOWN_CODE
)) {
1384 SCLogDebug("ICMPv6 Error: Unknown code event is set");
1397 static int ICMPV6NeighbourSolicitTestUnknownCode(void)
1401 static uint8_t raw_ipv6
[] = {
1402 0x60, 0x00, 0x00, 0x00, 0x00, 0x08, 0x3a, 0xff,
1403 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1404 0x02, 0x24, 0x8c, 0xff, 0xfe, 0x0e, 0x31, 0x54,
1405 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1406 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
1407 0x87, 0x01, 0xbc, 0xaf, 0x00, 0x00, 0x00, 0x00
1410 Packet
*p
= SCMalloc(SIZE_OF_PACKET
);
1411 if (unlikely(p
== NULL
))
1415 DecodeThreadVars dtv
;
1417 memset(&tv
, 0, sizeof(ThreadVars
));
1418 memset(p
, 0, SIZE_OF_PACKET
);
1419 memset(&dtv
, 0, sizeof(DecodeThreadVars
));
1420 memset(&ip6h
, 0, sizeof(IPV6Hdr
));
1422 FlowInitConfig(FLOW_QUIET
);
1423 DecodeIPV6(&tv
, &dtv
, p
, raw_ipv6
, sizeof(raw_ipv6
), NULL
);
1425 if (!ENGINE_ISSET_EVENT(p
, ICMPV6_UNKNOWN_CODE
)) {
1426 SCLogDebug("ICMPv6 Error: Unknown code event is not set");
1439 static int ICMPV6NeighbourAdvertTestKnownCode(void)
1443 static uint8_t raw_ipv6
[] = {
1444 0x60, 0x00, 0x00, 0x00, 0x00, 0x08, 0x3a, 0xff,
1445 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1446 0x02, 0x24, 0x8c, 0xff, 0xfe, 0x0e, 0x31, 0x54,
1447 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1448 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
1449 0x88, 0x00, 0xbb, 0xb0, 0x00, 0x00, 0x00, 0x00
1452 Packet
*p
= SCMalloc(SIZE_OF_PACKET
);
1453 if (unlikely(p
== NULL
))
1457 DecodeThreadVars dtv
;
1459 memset(&tv
, 0, sizeof(ThreadVars
));
1460 memset(p
, 0, SIZE_OF_PACKET
);
1461 memset(&dtv
, 0, sizeof(DecodeThreadVars
));
1462 memset(&ip6h
, 0, sizeof(IPV6Hdr
));
1464 FlowInitConfig(FLOW_QUIET
);
1465 DecodeIPV6(&tv
, &dtv
, p
, raw_ipv6
, sizeof(raw_ipv6
), NULL
);
1467 if (ENGINE_ISSET_EVENT(p
, ICMPV6_UNKNOWN_CODE
)) {
1468 SCLogDebug("ICMPv6 Error: Unknown code event is set");
1481 static int ICMPV6NeighbourAdvertTestUnknownCode(void)
1485 static uint8_t raw_ipv6
[] = {
1486 0x60, 0x00, 0x00, 0x00, 0x00, 0x08, 0x3a, 0xff,
1487 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1488 0x02, 0x24, 0x8c, 0xff, 0xfe, 0x0e, 0x31, 0x54,
1489 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1490 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
1491 0x88, 0x01, 0xbb, 0xaf, 0x00, 0x00, 0x00, 0x00
1494 Packet
*p
= SCMalloc(SIZE_OF_PACKET
);
1495 if (unlikely(p
== NULL
))
1499 DecodeThreadVars dtv
;
1501 memset(&tv
, 0, sizeof(ThreadVars
));
1502 memset(p
, 0, SIZE_OF_PACKET
);
1503 memset(&dtv
, 0, sizeof(DecodeThreadVars
));
1504 memset(&ip6h
, 0, sizeof(IPV6Hdr
));
1506 FlowInitConfig(FLOW_QUIET
);
1507 DecodeIPV6(&tv
, &dtv
, p
, raw_ipv6
, sizeof(raw_ipv6
), NULL
);
1509 if (!ENGINE_ISSET_EVENT(p
, ICMPV6_UNKNOWN_CODE
)) {
1510 SCLogDebug("ICMPv6 Error: Unknown code event is not set");
1523 static int ICMPV6RedirectTestKnownCode(void)
1527 static uint8_t raw_ipv6
[] = {
1528 0x60, 0x00, 0x00, 0x00, 0x00, 0x08, 0x3a, 0xff,
1529 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1530 0x02, 0x24, 0x8c, 0xff, 0xfe, 0x0e, 0x31, 0x54,
1531 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1532 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
1533 0x89, 0x00, 0xba, 0xb0, 0x00, 0x00, 0x00, 0x00
1536 Packet
*p
= SCMalloc(SIZE_OF_PACKET
);
1537 if (unlikely(p
== NULL
))
1541 DecodeThreadVars dtv
;
1543 memset(&tv
, 0, sizeof(ThreadVars
));
1544 memset(p
, 0, SIZE_OF_PACKET
);
1545 memset(&dtv
, 0, sizeof(DecodeThreadVars
));
1546 memset(&ip6h
, 0, sizeof(IPV6Hdr
));
1548 FlowInitConfig(FLOW_QUIET
);
1549 DecodeIPV6(&tv
, &dtv
, p
, raw_ipv6
, sizeof(raw_ipv6
), NULL
);
1551 if (ENGINE_ISSET_EVENT(p
, ICMPV6_UNKNOWN_CODE
)) {
1552 SCLogDebug("ICMPv6 Error: Unknown code event is set");
1565 static int ICMPV6RedirectTestUnknownCode(void)
1569 static uint8_t raw_ipv6
[] = {
1570 0x60, 0x00, 0x00, 0x00, 0x00, 0x08, 0x3a, 0xff,
1571 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1572 0x02, 0x24, 0x8c, 0xff, 0xfe, 0x0e, 0x31, 0x54,
1573 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1574 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
1575 0x89, 0x01, 0xba, 0xaf, 0x00, 0x00, 0x00, 0x00
1578 Packet
*p
= SCMalloc(SIZE_OF_PACKET
);
1579 if (unlikely(p
== NULL
))
1583 DecodeThreadVars dtv
;
1585 memset(&tv
, 0, sizeof(ThreadVars
));
1586 memset(p
, 0, SIZE_OF_PACKET
);
1587 memset(&dtv
, 0, sizeof(DecodeThreadVars
));
1588 memset(&ip6h
, 0, sizeof(IPV6Hdr
));
1590 FlowInitConfig(FLOW_QUIET
);
1591 DecodeIPV6(&tv
, &dtv
, p
, raw_ipv6
, sizeof(raw_ipv6
), NULL
);
1593 if (!ENGINE_ISSET_EVENT(p
, ICMPV6_UNKNOWN_CODE
)) {
1594 SCLogDebug("ICMPv6 Error: Unknown code event is not set");
1607 #endif /* UNITTESTS */
1609 * \brief Registers ICMPV6 unit tests
1610 * \todo More ICMPv6 tests
1612 void DecodeICMPV6RegisterTests(void)
1615 UtRegisterTest("ICMPV6CalculateValidChecksumtest01", ICMPV6CalculateValidChecksumtest01
, 1);
1616 UtRegisterTest("ICMPV6CalculateInValidChecksumtest02", ICMPV6CalculateInvalidChecksumtest02
, 0);
1618 UtRegisterTest("ICMPV6ParamProbTest01 (Valid)", ICMPV6ParamProbTest01
, 1);
1619 UtRegisterTest("ICMPV6DestUnreachTest01 (Valid)", ICMPV6DestUnreachTest01
, 1);
1620 UtRegisterTest("ICMPV6PktTooBigTest01 (Valid)", ICMPV6PktTooBigTest01
, 1);
1621 UtRegisterTest("ICMPV6TimeExceedTest01 (Valid)", ICMPV6TimeExceedTest01
, 1);
1622 UtRegisterTest("ICMPV6EchoReqTest01 (Valid)", ICMPV6EchoReqTest01
, 1);
1623 UtRegisterTest("ICMPV6EchoRepTest01 (Valid)", ICMPV6EchoRepTest01
, 1);
1625 UtRegisterTest("ICMPV6ParamProbTest02 (Invalid)", ICMPV6ParamProbTest02
, 1);
1626 UtRegisterTest("ICMPV6DestUnreachTest02 (Invalid)", ICMPV6DestUnreachTest02
, 1);
1627 UtRegisterTest("ICMPV6PktTooBigTest02 (Invalid)", ICMPV6PktTooBigTest02
, 1);
1628 UtRegisterTest("ICMPV6TimeExceedTest02 (Invalid)", ICMPV6TimeExceedTest02
, 1);
1629 UtRegisterTest("ICMPV6EchoReqTest02 (Invalid)", ICMPV6EchoReqTest02
, 1);
1630 UtRegisterTest("ICMPV6EchoRepTest02 (Invalid)", ICMPV6EchoRepTest02
, 1);
1632 UtRegisterTest("ICMPV6PayloadTest01", ICMPV6PayloadTest01
, 1);
1634 UtRegisterTest("ICMPV6RouterSolicitTestKnownCode",
1635 ICMPV6RouterSolicitTestKnownCode
, 1);
1636 UtRegisterTest("ICMPV6RouterSolicitTestUnknownCode",
1637 ICMPV6RouterSolicitTestUnknownCode
, 1);
1638 UtRegisterTest("ICMPV6RouterAdvertTestKnownCode",
1639 ICMPV6RouterAdvertTestKnownCode
, 1);
1640 UtRegisterTest("ICMPV6RouterAdvertTestUnknownCode",
1641 ICMPV6RouterAdvertTestUnknownCode
, 1);
1643 UtRegisterTest("ICMPV6NeighbourSolicitTestKnownCode",
1644 ICMPV6NeighbourSolicitTestKnownCode
, 1);
1645 UtRegisterTest("ICMPV6NeighbourSolicitTestUnknownCode",
1646 ICMPV6NeighbourSolicitTestUnknownCode
, 1);
1647 UtRegisterTest("ICMPV6NeighbourAdvertTestKnownCode",
1648 ICMPV6NeighbourAdvertTestKnownCode
, 1);
1649 UtRegisterTest("ICMPV6NeighbourAdvertTestUnknownCode",
1650 ICMPV6NeighbourAdvertTestUnknownCode
, 1);
1652 UtRegisterTest("ICMPV6RedirectTestKnownCode", ICMPV6RedirectTestKnownCode
, 1);
1653 UtRegisterTest("ICMPV6RedirectTestUnknownCode",
1654 ICMPV6RedirectTestUnknownCode
, 1);
1655 #endif /* UNITTESTS */