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 SCLogDebug("ICMPV6 Message type %" PRIu8
" not "
325 "implemented yet", ICMPV6_GET_TYPE(p
));
326 ENGINE_SET_EVENT(p
, ICMPV6_UNKNOWN_TYPE
);
329 /* for a info message the header is just 4 bytes */
331 if (p
->payload_len
>= 4) {
333 p
->payload
= pkt
+ 4;
341 if (ENGINE_ISSET_EVENT(p
, ICMPV6_UNKNOWN_CODE
))
342 SCLogDebug("Unknown Code, ICMPV6_UNKNOWN_CODE");
344 if (ENGINE_ISSET_EVENT(p
, ICMPV6_UNKNOWN_TYPE
))
345 SCLogDebug("Unknown Type, ICMPV6_UNKNOWN_TYPE");
348 /* Flow is an integral part of us */
349 FlowHandlePacket(tv
, dtv
, p
);
356 static int ICMPV6CalculateValidChecksumtest01(void)
360 uint8_t raw_ipv6
[] = {
361 0x00, 0x00, 0x86, 0x05, 0x80, 0xda, 0x00, 0x60,
362 0x97, 0x07, 0x69, 0xea, 0x86, 0xdd, 0x60, 0x00,
363 0x00, 0x00, 0x00, 0x44, 0x3a, 0x40, 0x3f, 0xfe,
364 0x05, 0x07, 0x00, 0x00, 0x00, 0x01, 0x02, 0x60,
365 0x97, 0xff, 0xfe, 0x07, 0x69, 0xea, 0x3f, 0xfe,
366 0x05, 0x07, 0x00, 0x00, 0x00, 0x01, 0x02, 0x00,
367 0x86, 0xff, 0xfe, 0x05, 0x80, 0xda, 0x03, 0x00,
368 0xf7, 0x52, 0x00, 0x00, 0x00, 0x00, 0x60, 0x00,
369 0x00, 0x00, 0x00, 0x14, 0x11, 0x01, 0x3f, 0xfe,
370 0x05, 0x07, 0x00, 0x00, 0x00, 0x01, 0x02, 0x00,
371 0x86, 0xff, 0xfe, 0x05, 0x80, 0xda, 0x3f, 0xfe,
372 0x05, 0x01, 0x04, 0x10, 0x00, 0x00, 0x02, 0xc0,
373 0xdf, 0xff, 0xfe, 0x47, 0x03, 0x3e, 0xa0, 0x75,
374 0x82, 0x9b, 0x00, 0x14, 0x82, 0x8b, 0x01, 0x01,
375 0x00, 0x00, 0xf9, 0xc8, 0xe7, 0x36, 0xf5, 0xed,
378 csum
= *( ((uint16_t *)(raw_ipv6
+ 56)));
380 return (csum
== ICMPV6CalculateChecksum((uint16_t *)(raw_ipv6
+ 14 + 8),
381 (uint16_t *)(raw_ipv6
+ 54), 68));
384 static int ICMPV6CalculateInvalidChecksumtest02(void)
388 uint8_t raw_ipv6
[] = {
389 0x00, 0x00, 0x86, 0x05, 0x80, 0xda, 0x00, 0x60,
390 0x97, 0x07, 0x69, 0xea, 0x86, 0xdd, 0x60, 0x00,
391 0x00, 0x00, 0x00, 0x44, 0x3a, 0x40, 0x3f, 0xfe,
392 0x05, 0x07, 0x00, 0x00, 0x00, 0x01, 0x02, 0x60,
393 0x97, 0xff, 0xfe, 0x07, 0x69, 0xea, 0x3f, 0xfe,
394 0x05, 0x07, 0x00, 0x00, 0x00, 0x01, 0x02, 0x00,
395 0x86, 0xff, 0xfe, 0x05, 0x80, 0xda, 0x03, 0x00,
396 0xf7, 0x52, 0x00, 0x00, 0x00, 0x00, 0x60, 0x00,
397 0x00, 0x00, 0x00, 0x14, 0x11, 0x01, 0x3f, 0xfe,
398 0x05, 0x07, 0x00, 0x00, 0x00, 0x01, 0x02, 0x00,
399 0x86, 0xff, 0xfe, 0x05, 0x80, 0xda, 0x3f, 0xfe,
400 0x05, 0x01, 0x04, 0x10, 0x00, 0x00, 0x02, 0xc0,
401 0xdf, 0xff, 0xfe, 0x47, 0x03, 0x3e, 0xa0, 0x75,
402 0x82, 0x9b, 0x00, 0x14, 0x82, 0x8b, 0x01, 0x01,
403 0x00, 0x00, 0xf9, 0xc8, 0xe7, 0x36, 0xf5, 0xed,
406 csum
= *( ((uint16_t *)(raw_ipv6
+ 56)));
408 return (csum
== ICMPV6CalculateChecksum((uint16_t *)(raw_ipv6
+ 14 + 8),
409 (uint16_t *)(raw_ipv6
+ 54), 68));
413 /** \test icmpv6 message type: parameter problem, valid packet
415 * \retval retval 0 = Error ; 1 = ok
417 static int ICMPV6ParamProbTest01(void)
420 static uint8_t raw_ipv6
[] = {
421 0x60, 0x00, 0x00, 0x00, 0x00, 0x38, 0x3a, 0xff,
422 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
423 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
424 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
425 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
426 0x04, 0x00, 0xcc, 0x2a, 0x6d, 0x93, 0x0b, 0xdf,
427 0x69, 0x70, 0x12, 0xb7, 0x00, 0x08, 0x3a, 0xff,
428 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
429 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
430 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
431 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
432 0x80, 0x00, 0x08, 0xb5, 0x99, 0xc3, 0xde, 0x40 };
434 Packet
*p
= SCMalloc(SIZE_OF_PACKET
);
435 if (unlikely(p
== NULL
))
439 DecodeThreadVars dtv
;
442 ipv6src
= (uint32_t*) &raw_ipv6
[8];
443 ipv6dst
= (uint32_t*) &raw_ipv6
[24];
445 memset(&tv
, 0, sizeof(ThreadVars
));
446 memset(p
, 0, SIZE_OF_PACKET
);
447 memset(&dtv
, 0, sizeof(DecodeThreadVars
));
448 memset(&ip6h
, 0, sizeof(IPV6Hdr
));
450 FlowInitConfig(FLOW_QUIET
);
451 DecodeIPV6(&tv
, &dtv
, p
, raw_ipv6
, sizeof(raw_ipv6
), NULL
);
453 if (p
->icmpv6h
== NULL
) {
454 SCLogDebug("ICMPv6 Unable to detect icmpv6 layer from ipv6");
459 if (ICMPV6_GET_TYPE(p
) != 4 || ICMPV6_GET_CODE(p
) != 0 ||
460 ICMPV6_GET_EMB_PROTO(p
) != IPPROTO_ICMPV6
) {
461 SCLogDebug("ICMPv6 not processed at all");
466 /* Let's check if we retrieved the embedded ipv6 addresses correctly */
468 for (i
= 0; i
< 4; i
++) {
469 if (p
->icmpv6vars
.emb_ip6_src
[i
] != ipv6src
[i
] ||
470 p
->icmpv6vars
.emb_ip6_dst
[i
] != ipv6dst
[i
]) {
471 SCLogDebug("ICMPv6 DecodePartialICMPV6 (Embedded ip6h) didn't set "
472 "the src and dest ip addresses correctly");
486 /** \test icmpv6 message type: packet too big, valid packet
488 * \retval retval 0 = Error ; 1 = ok
490 static int ICMPV6PktTooBigTest01(void)
493 static uint8_t raw_ipv6
[] = {
494 0x60, 0x00, 0x00, 0x00, 0x00, 0x30, 0x3a, 0xff,
495 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
496 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
497 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
498 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
499 0x02, 0x00, 0x5c, 0x7a, 0x00, 0x00, 0x05, 0x00,
500 0x64, 0x14, 0xfd, 0xff, 0x00, 0x00, 0x3b, 0xff,
501 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
502 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
503 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
504 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 };
506 Packet
*p
= SCMalloc(SIZE_OF_PACKET
);
507 if (unlikely(p
== NULL
))
511 DecodeThreadVars dtv
;
514 ipv6src
= (uint32_t*) &raw_ipv6
[8];
515 ipv6dst
= (uint32_t*) &raw_ipv6
[24];
517 memset(&tv
, 0, sizeof(ThreadVars
));
518 memset(p
, 0, SIZE_OF_PACKET
);
519 memset(&dtv
, 0, sizeof(DecodeThreadVars
));
520 memset(&ip6h
, 0, sizeof(IPV6Hdr
));
522 FlowInitConfig(FLOW_QUIET
);
523 DecodeIPV6(&tv
, &dtv
, p
, raw_ipv6
, sizeof(raw_ipv6
), NULL
);
525 if (p
->icmpv6h
== NULL
) {
526 SCLogDebug("ICMPv6 Unable to detect icmpv6 layer from ipv6");
531 /* Note: it has an embedded ipv6 packet but no protocol after ipv6 (IPPROTO_NONE) */
532 if (ICMPV6_GET_TYPE(p
) != 2 || ICMPV6_GET_CODE(p
) != 0 ) {
533 SCLogDebug("ICMPv6 Not processed at all");
538 /* Let's check if we retrieved the embedded ipv6 addresses correctly */
540 for (i
= 0; i
< 4; i
++) {
541 if (p
->icmpv6vars
.emb_ip6_src
[i
] != ipv6src
[i
] ||
542 p
->icmpv6vars
.emb_ip6_dst
[i
] != ipv6dst
[i
]) {
543 SCLogDebug("ICMPv6 DecodePartialICMPV6 (Embedded ip6h) didn't set "
544 "the src and dest ip addresses correctly");
550 SCLogDebug("ICMPV6 IPV6 src and dst properly set");
560 /** \test icmpv6 message type: time exceed, valid packet
562 * \retval retval 0 = Error ; 1 = ok
564 static int ICMPV6TimeExceedTest01(void)
567 static uint8_t raw_ipv6
[] = {
568 0x60, 0x00, 0x00, 0x00, 0x00, 0x30, 0x3a, 0xff,
569 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
570 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
571 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
572 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
573 0x03, 0x00, 0x56, 0x2d, 0x00, 0x00, 0x00, 0x00,
574 0x6d, 0x23, 0xff, 0x3d, 0x00, 0x00, 0x3b, 0xff,
575 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
576 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
577 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
578 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 };
580 Packet
*p
= SCMalloc(SIZE_OF_PACKET
);
581 if (unlikely(p
== NULL
))
585 DecodeThreadVars dtv
;
588 ipv6src
= (uint32_t*) &raw_ipv6
[8];
589 ipv6dst
= (uint32_t*) &raw_ipv6
[24];
592 memset(&tv
, 0, sizeof(ThreadVars
));
593 memset(p
, 0, SIZE_OF_PACKET
);
594 memset(&dtv
, 0, sizeof(DecodeThreadVars
));
595 memset(&ip6h
, 0, sizeof(IPV6Hdr
));
597 FlowInitConfig(FLOW_QUIET
);
598 DecodeIPV6(&tv
, &dtv
, p
, raw_ipv6
, sizeof(raw_ipv6
), NULL
);
600 if (p
->icmpv6h
== NULL
) {
601 SCLogDebug("ICMPv6 Unable to detect icmpv6 layer from ipv6");
606 /* Note: it has an embedded ipv6 packet but no protocol after ipv6 (IPPROTO_NONE) */
607 if (ICMPV6_GET_TYPE(p
) != 3 || ICMPV6_GET_CODE(p
) != 0 ||
608 ICMPV6_GET_EMB_IPV6(p
)==NULL
|| ICMPV6_GET_EMB_PROTO(p
) != IPPROTO_NONE
) {
609 SCLogDebug("ICMPv6 Not processed at all");
614 /* Let's check if we retrieved the embedded ipv6 addresses correctly */
616 for (i
= 0; i
< 4; i
++) {
617 if (p
->icmpv6vars
.emb_ip6_src
[i
] != ipv6src
[i
] ||
618 p
->icmpv6vars
.emb_ip6_dst
[i
] != ipv6dst
[i
]) {
619 SCLogDebug("ICMPv6 DecodePartialICMPV6 (Embedded ip6h) didn't set "
620 "the src and dest ip addresses correctly");
626 SCLogDebug("ICMPV6 IPV6 src and dst properly set");
636 /** \test icmpv6 message type: destination unreach, valid packet
638 * \retval retval 0 = Error ; 1 = ok
640 static int ICMPV6DestUnreachTest01(void)
643 static uint8_t raw_ipv6
[] = {
644 0x60, 0x00, 0x00, 0x00, 0x00, 0x30, 0x3a, 0xff,
645 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
646 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
647 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
648 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
649 0x01, 0x00, 0x7b, 0x85, 0x00, 0x00, 0x00, 0x00,
650 0x60, 0x4b, 0xe8, 0xbd, 0x00, 0x00, 0x3b, 0xff,
651 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
652 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
653 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
654 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 };
656 Packet
*p
= SCMalloc(SIZE_OF_PACKET
);
657 if (unlikely(p
== NULL
))
661 DecodeThreadVars dtv
;
664 ipv6src
= (uint32_t*) &raw_ipv6
[8];
665 ipv6dst
= (uint32_t*) &raw_ipv6
[24];
668 memset(&tv
, 0, sizeof(ThreadVars
));
669 memset(p
, 0, SIZE_OF_PACKET
);
670 memset(&dtv
, 0, sizeof(DecodeThreadVars
));
671 memset(&ip6h
, 0, sizeof(IPV6Hdr
));
673 FlowInitConfig(FLOW_QUIET
);
674 DecodeIPV6(&tv
, &dtv
, p
, raw_ipv6
, sizeof(raw_ipv6
), NULL
);
676 if (p
->icmpv6h
== NULL
) {
677 SCLogDebug("ICMPv6 Unable to detect icmpv6 layer from ipv6");
682 /* Note: it has an embedded ipv6 packet but no protocol after ipv6 (IPPROTO_NONE) */
683 if (ICMPV6_GET_TYPE(p
) != 1 || ICMPV6_GET_CODE(p
) != 0 ||
684 ICMPV6_GET_EMB_IPV6(p
) == NULL
|| ICMPV6_GET_EMB_PROTO(p
) != IPPROTO_NONE
) {
685 SCLogDebug("ICMPv6 Not processed at all");
690 /* Let's check if we retrieved the embedded ipv6 addresses correctly */
692 for (i
= 0; i
< 4; i
++) {
693 if (p
->icmpv6vars
.emb_ip6_src
[i
] != ipv6src
[i
] ||
694 p
->icmpv6vars
.emb_ip6_dst
[i
] != ipv6dst
[i
]) {
695 SCLogDebug("ICMPv6 DecodePartialICMPV6 (Embedded ip6h) didn't set "
696 "the src and dest ip addresses correctly");
710 /**\test icmpv6 message type: echo request, valid packet
711 * \retval retval 0 = Error ; 1 = ok
713 static int ICMPV6EchoReqTest01(void)
716 static uint8_t raw_ipv6
[] = {
717 0x60, 0x00, 0x00, 0x00, 0x00, 0x08, 0x3a, 0xff,
718 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
719 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
720 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
721 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
722 0x80, 0x00, 0xe5, 0xa5, 0x25, 0xf0, 0x75, 0x23 };
724 Packet
*p
= SCMalloc(SIZE_OF_PACKET
);
725 if (unlikely(p
== NULL
))
729 DecodeThreadVars dtv
;
731 memset(&tv
, 0, sizeof(ThreadVars
));
732 memset(p
, 0, SIZE_OF_PACKET
);
733 memset(&dtv
, 0, sizeof(DecodeThreadVars
));
734 memset(&ip6h
, 0, sizeof(IPV6Hdr
));
736 FlowInitConfig(FLOW_QUIET
);
737 DecodeIPV6(&tv
, &dtv
, p
, raw_ipv6
, sizeof(raw_ipv6
), NULL
);
739 if (p
->icmpv6h
== NULL
) {
740 SCLogDebug("ICMPv6 Unable to detect icmpv6 layer from ipv6");
744 SCLogDebug("ID: %u seq: %u", ICMPV6_GET_ID(p
), ICMPV6_GET_SEQ(p
));
746 if (ICMPV6_GET_TYPE(p
) != 128 || ICMPV6_GET_CODE(p
) != 0 ||
747 ntohs(ICMPV6_GET_ID(p
)) != 9712 || ntohs(ICMPV6_GET_SEQ(p
)) != 29987) {
748 printf("ICMPv6 Echo reply decode failed TYPE %u CODE %u ID %04x(%u) SEQ %04x(%u): ",
749 ICMPV6_GET_TYPE(p
), ICMPV6_GET_CODE(p
), ICMPV6_GET_ID(p
), ntohs(ICMPV6_GET_ID(p
)),
750 ICMPV6_GET_SEQ(p
), ntohs(ICMPV6_GET_SEQ(p
)));
762 /**\test icmpv6 message type: echo reply, valid packet
763 * \retval retval 0 = Error ; 1 = ok
765 static int ICMPV6EchoRepTest01(void)
768 static uint8_t raw_ipv6
[] = {
769 0x60, 0x00, 0x00, 0x00, 0x00, 0x08, 0x3a,
770 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
771 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
772 0x00, 0x00, 0x00, 0xff, 0x02, 0x00, 0x00,
773 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
774 0x00, 0x00, 0x00, 0x00, 0x01, 0x81, 0x00,
775 0xe5, 0xa5, 0x25, 0xf0, 0x75, 0x23 };
777 Packet
*p
= SCMalloc(SIZE_OF_PACKET
);
778 if (unlikely(p
== NULL
))
782 DecodeThreadVars dtv
;
784 memset(&tv
, 0, sizeof(ThreadVars
));
785 memset(p
, 0, SIZE_OF_PACKET
);
786 memset(&dtv
, 0, sizeof(DecodeThreadVars
));
787 memset(&ip6h
, 0, sizeof(IPV6Hdr
));
789 FlowInitConfig(FLOW_QUIET
);
790 DecodeIPV6(&tv
, &dtv
, p
, raw_ipv6
, sizeof(raw_ipv6
), NULL
);
792 if (p
->icmpv6h
== NULL
) {
793 SCLogDebug("ICMPv6 Unable to detect icmpv6 layer from ipv6");
797 SCLogDebug("type: %u code %u ID: %u seq: %u", ICMPV6_GET_TYPE(p
),
798 ICMPV6_GET_CODE(p
),ICMPV6_GET_ID(p
), ICMPV6_GET_SEQ(p
));
800 if (ICMPV6_GET_TYPE(p
) != 129 || ICMPV6_GET_CODE(p
) != 0 ||
801 ntohs(ICMPV6_GET_ID(p
)) != 9712 || ntohs(ICMPV6_GET_SEQ(p
)) != 29987) {
802 printf("ICMPv6 Echo reply decode failed TYPE %u CODE %u ID %04x(%u) SEQ %04x(%u): ",
803 ICMPV6_GET_TYPE(p
), ICMPV6_GET_CODE(p
), ICMPV6_GET_ID(p
), ntohs(ICMPV6_GET_ID(p
)),
804 ICMPV6_GET_SEQ(p
), ntohs(ICMPV6_GET_SEQ(p
)));
816 /** \test icmpv6 message type: parameter problem, invalid packet
817 * \brief set the event ICMPV6_IPV6_UNKNOWN_VER properly when the embedded packet has an unknown version
818 * \retval retval 0 = Error ; 1 = ok
820 static int ICMPV6ParamProbTest02(void)
823 static uint8_t raw_ipv6
[] = {
824 0x60, 0x00, 0x00, 0x00, 0x00, 0x38, 0x3a, 0xff,
825 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
826 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
827 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
828 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
829 0x04, 0x00, 0xcc, 0x2a, 0x6d, 0x93, 0x0b, 0xdf,
830 0x38, 0x70, 0x12, 0xb7, 0x00, 0x08, 0x3a, 0xff,
831 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
832 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
833 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
834 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
835 0x80, 0x00, 0x08, 0xb5, 0x99, 0xc3, 0xde, 0x40 };
837 Packet
*p
= SCMalloc(SIZE_OF_PACKET
);
838 if (unlikely(p
== NULL
))
842 DecodeThreadVars dtv
;
844 memset(&tv
, 0, sizeof(ThreadVars
));
845 memset(p
, 0, SIZE_OF_PACKET
);
846 memset(&dtv
, 0, sizeof(DecodeThreadVars
));
847 memset(&ip6h
, 0, sizeof(IPV6Hdr
));
849 FlowInitConfig(FLOW_QUIET
);
850 DecodeIPV6(&tv
, &dtv
, p
, raw_ipv6
, sizeof(raw_ipv6
), NULL
);
852 if (p
->icmpv6h
== NULL
) {
853 SCLogDebug("ICMPv6 Unable to detect icmpv6 layer from ipv6");
858 if (ICMPV6_GET_TYPE(p
) != 4 || ICMPV6_GET_CODE(p
) != 0) {
859 SCLogDebug("ICMPv6 Not processed at all");
864 if (!ENGINE_ISSET_EVENT(p
, ICMPV6_IPV6_UNKNOWN_VER
)) {
865 SCLogDebug("ICMPv6 Error: Unknown embedded ipv6 version event not set");
878 /** \test icmpv6 message type: packet too big, invalid packet
879 * \brief Set the event ICMPV6_UNKNOWN_CODE if code is invalid for this type
880 * \retval retval 0 = Error ; 1 = ok
882 static int ICMPV6PktTooBigTest02(void)
885 static uint8_t raw_ipv6
[] = {
886 0x60, 0x00, 0x00, 0x00, 0x00, 0x30, 0x3a, 0xff,
887 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
888 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
889 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
890 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
891 0x02, 0x10, 0x5c, 0x7a, 0x00, 0x00, 0x05, 0x00,
892 0x64, 0x14, 0xfd, 0xff, 0x00, 0x00, 0x3b, 0xff,
893 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
894 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
895 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
896 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 };
898 Packet
*p
= SCMalloc(SIZE_OF_PACKET
);
899 if (unlikely(p
== NULL
))
903 DecodeThreadVars dtv
;
905 memset(&tv
, 0, sizeof(ThreadVars
));
906 memset(p
, 0, SIZE_OF_PACKET
);
907 memset(&dtv
, 0, sizeof(DecodeThreadVars
));
908 memset(&ip6h
, 0, sizeof(IPV6Hdr
));
910 FlowInitConfig(FLOW_QUIET
);
911 DecodeIPV6(&tv
, &dtv
, p
, raw_ipv6
, sizeof(raw_ipv6
), NULL
);
913 if (p
->icmpv6h
== NULL
) {
914 SCLogDebug("ICMPv6 Unable to detect icmpv6 layer from ipv6");
919 if (!ENGINE_ISSET_EVENT(p
, ICMPV6_UNKNOWN_CODE
)) {
920 SCLogDebug("ICMPv6 Error: Unknown code event not set");
933 /** \test icmpv6 message type: time exceed, invalid packet
934 * \brief set the event ICMPV6_PKT_TOO_SMALL properly
935 * \retval retval 0 = Error ; 1 = ok
937 static int ICMPV6TimeExceedTest02(void)
940 static uint8_t raw_ipv6
[] = {
941 0x60, 0x00, 0x00, 0x00, 0x00, 0x03, 0x3a, 0xff,
942 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
943 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
944 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
945 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
948 /* The icmpv6 header is broken in the checksum (so we dont have a complete header) */
950 Packet
*p
= SCMalloc(SIZE_OF_PACKET
);
951 if (unlikely(p
== NULL
))
955 DecodeThreadVars dtv
;
957 memset(&tv
, 0, sizeof(ThreadVars
));
958 memset(p
, 0, SIZE_OF_PACKET
);
959 memset(&dtv
, 0, sizeof(DecodeThreadVars
));
960 memset(&ip6h
, 0, sizeof(IPV6Hdr
));
962 FlowInitConfig(FLOW_QUIET
);
963 DecodeIPV6(&tv
, &dtv
, p
, raw_ipv6
, sizeof(raw_ipv6
), NULL
);
965 if (!ENGINE_ISSET_EVENT(p
, ICMPV6_PKT_TOO_SMALL
)) {
966 SCLogDebug("ICMPv6 Error: event packet too small not set");
979 /**\test icmpv6 message type: destination unreach, invalid packet
980 * \brief The embedded packet header (ipv6) is truncated
981 * \retval retval 0 = Error ; 1 = ok
983 static int ICMPV6DestUnreachTest02(void)
986 static uint8_t raw_ipv6
[] = {
987 0x60, 0x00, 0x00, 0x00, 0x00, 0x2d, 0x3a, 0xff,
988 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
989 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
990 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
991 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
992 0x01, 0x00, 0x7b, 0x85, 0x00, 0x00, 0x00, 0x00,
993 0x60, 0x4b, 0xe8, 0xbd, 0x00, 0x00, 0x3b, 0xff,
994 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
995 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
996 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
997 0x00, 0x00, 0x00, 0x00, 0x00 };
999 Packet
*p
= SCMalloc(SIZE_OF_PACKET
);
1000 if (unlikely(p
== NULL
))
1004 DecodeThreadVars dtv
;
1006 memset(&tv
, 0, sizeof(ThreadVars
));
1007 memset(p
, 0, SIZE_OF_PACKET
);
1008 memset(&dtv
, 0, sizeof(DecodeThreadVars
));
1009 memset(&ip6h
, 0, sizeof(IPV6Hdr
));
1011 FlowInitConfig(FLOW_QUIET
);
1012 DecodeIPV6(&tv
, &dtv
, p
, raw_ipv6
, sizeof(raw_ipv6
), NULL
);
1014 if (!ENGINE_ISSET_EVENT(p
, ICMPV6_IPV6_TRUNC_PKT
)) {
1015 SCLogDebug("ICMPv6 Error: embedded ipv6 truncated packet event not set");
1028 /**\test icmpv6 message type: echo request, invalid packet
1029 * \brief unknown code
1030 * \retval retval 0 = Error ; 1 = ok
1032 static int ICMPV6EchoReqTest02(void)
1035 static uint8_t raw_ipv6
[] = {
1036 0x60, 0x00, 0x00, 0x00, 0x00, 0x08, 0x3a,
1037 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1038 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1039 0x00, 0x00, 0x00, 0xff, 0x02, 0x00, 0x00,
1040 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1041 0x00, 0x00, 0x00, 0x00, 0x01, 0x80, 0x01,
1042 0xe5, 0xa5, 0x25, 0xf0, 0x75, 0x23 };
1044 Packet
*p
= SCMalloc(SIZE_OF_PACKET
);
1045 if (unlikely(p
== NULL
))
1049 DecodeThreadVars dtv
;
1051 memset(&tv
, 0, sizeof(ThreadVars
));
1052 memset(p
, 0, SIZE_OF_PACKET
);
1053 memset(&dtv
, 0, sizeof(DecodeThreadVars
));
1054 memset(&ip6h
, 0, sizeof(IPV6Hdr
));
1056 FlowInitConfig(FLOW_QUIET
);
1057 DecodeIPV6(&tv
, &dtv
, p
, raw_ipv6
, sizeof(raw_ipv6
), NULL
);
1059 if (!ENGINE_ISSET_EVENT(p
, ICMPV6_UNKNOWN_CODE
)) {
1060 SCLogDebug("ICMPv6 Error: Unknown code event not set");
1073 /**\test icmpv6 message type: echo reply, invalid packet
1074 * \brief unknown code
1075 * \retval retval 0 = Error ; 1 = ok
1077 static int ICMPV6EchoRepTest02(void)
1080 static uint8_t raw_ipv6
[] = {
1081 0x60, 0x00, 0x00, 0x00, 0x00, 0x08, 0x3a,
1082 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1083 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1084 0x00, 0x00, 0x00, 0xff, 0x02, 0x00, 0x00,
1085 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1086 0x00, 0x00, 0x00, 0x00, 0x01, 0x81, 0x01,
1087 0xe5, 0xa5, 0x25, 0xf0, 0x75, 0x23 };
1089 Packet
*p
= SCMalloc(SIZE_OF_PACKET
);
1090 if (unlikely(p
== NULL
))
1094 DecodeThreadVars dtv
;
1096 memset(&tv
, 0, sizeof(ThreadVars
));
1097 memset(p
, 0, SIZE_OF_PACKET
);
1098 memset(&dtv
, 0, sizeof(DecodeThreadVars
));
1099 memset(&ip6h
, 0, sizeof(IPV6Hdr
));
1101 FlowInitConfig(FLOW_QUIET
);
1102 DecodeIPV6(&tv
, &dtv
, p
, raw_ipv6
, sizeof(raw_ipv6
), NULL
);
1104 if (!ENGINE_ISSET_EVENT(p
, ICMPV6_UNKNOWN_CODE
)) {
1105 SCLogDebug("ICMPv6 Error: Unknown code event not set");
1118 /**\test icmpv6 packet decoding and setting up of payload_len and payload buufer
1119 * \retval retval 0 = Error ; 1 = ok
1121 static int ICMPV6PayloadTest01(void)
1124 static uint8_t raw_ipv6
[] = {
1125 0x60, 0x00, 0x00, 0x00, 0x00, 0x2d, 0x3a, 0xff,
1126 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1127 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1128 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1129 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
1130 0x01, 0x00, 0x7b, 0x85, 0x00, 0x00, 0x00, 0x00,
1131 0x60, 0x4b, 0xe8, 0xbd, 0x00, 0x00, 0x3b, 0xff,
1132 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1133 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1134 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1135 0x00, 0x00, 0x00, 0x00, 0x00 };
1137 Packet
*p
= SCMalloc(SIZE_OF_PACKET
);
1138 if (unlikely(p
== NULL
))
1142 DecodeThreadVars dtv
;
1144 memset(&tv
, 0, sizeof(ThreadVars
));
1145 memset(p
, 0, SIZE_OF_PACKET
);
1146 memset(&dtv
, 0, sizeof(DecodeThreadVars
));
1147 memset(&ip6h
, 0, sizeof(IPV6Hdr
));
1149 FlowInitConfig(FLOW_QUIET
);
1150 DecodeIPV6(&tv
, &dtv
, p
, raw_ipv6
, sizeof(raw_ipv6
), NULL
);
1152 if (p
->payload
== NULL
) {
1153 printf("payload == NULL, expected non-NULL: ");
1157 if (p
->payload_len
!= 37) {
1158 printf("payload_len %"PRIu16
", expected 37: ", p
->payload_len
);
1170 static int ICMPV6RouterSolicitTestKnownCode(void)
1174 static uint8_t raw_ipv6
[] = {
1175 0x60, 0x00, 0x00, 0x00, 0x00, 0x08, 0x3a, 0xff,
1176 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1177 0x02, 0x24, 0x8c, 0xff, 0xfe, 0x0e, 0x31, 0x54,
1178 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1179 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
1180 0x85, 0x00, 0xbe, 0xb0, 0x00, 0x00, 0x00, 0x00
1183 Packet
*p
= SCMalloc(SIZE_OF_PACKET
);
1184 if (unlikely(p
== NULL
))
1188 DecodeThreadVars dtv
;
1190 memset(&tv
, 0, sizeof(ThreadVars
));
1191 memset(p
, 0, SIZE_OF_PACKET
);
1192 memset(&dtv
, 0, sizeof(DecodeThreadVars
));
1193 memset(&ip6h
, 0, sizeof(IPV6Hdr
));
1195 FlowInitConfig(FLOW_QUIET
);
1196 DecodeIPV6(&tv
, &dtv
, p
, raw_ipv6
, sizeof(raw_ipv6
), NULL
);
1198 if (ENGINE_ISSET_EVENT(p
, ICMPV6_UNKNOWN_CODE
)) {
1199 SCLogDebug("ICMPv6 Error: Unknown code event is set");
1212 static int ICMPV6RouterSolicitTestUnknownCode(void)
1216 static uint8_t raw_ipv6
[] = {
1217 0x60, 0x00, 0x00, 0x00, 0x00, 0x08, 0x3a, 0xff,
1218 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1219 0x02, 0x24, 0x8c, 0xff, 0xfe, 0x0e, 0x31, 0x54,
1220 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1221 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
1222 0x85, 0x01, 0xbe, 0xaf, 0x00, 0x00, 0x00, 0x00
1225 Packet
*p
= SCMalloc(SIZE_OF_PACKET
);
1226 if (unlikely(p
== NULL
))
1230 DecodeThreadVars dtv
;
1232 memset(&tv
, 0, sizeof(ThreadVars
));
1233 memset(p
, 0, SIZE_OF_PACKET
);
1234 memset(&dtv
, 0, sizeof(DecodeThreadVars
));
1235 memset(&ip6h
, 0, sizeof(IPV6Hdr
));
1237 FlowInitConfig(FLOW_QUIET
);
1238 DecodeIPV6(&tv
, &dtv
, p
, raw_ipv6
, sizeof(raw_ipv6
), NULL
);
1240 if (!ENGINE_ISSET_EVENT(p
, ICMPV6_UNKNOWN_CODE
)) {
1241 SCLogDebug("ICMPv6 Error: Unknown code event is not set");
1254 static int ICMPV6RouterAdvertTestKnownCode(void)
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, 0x00, 0xbd, 0xb0, 0x00, 0x00, 0x00, 0x00
1267 Packet
*p
= SCMalloc(SIZE_OF_PACKET
);
1268 if (unlikely(p
== NULL
))
1272 DecodeThreadVars dtv
;
1274 memset(&tv
, 0, sizeof(ThreadVars
));
1275 memset(p
, 0, SIZE_OF_PACKET
);
1276 memset(&dtv
, 0, sizeof(DecodeThreadVars
));
1277 memset(&ip6h
, 0, sizeof(IPV6Hdr
));
1279 FlowInitConfig(FLOW_QUIET
);
1280 DecodeIPV6(&tv
, &dtv
, p
, raw_ipv6
, sizeof(raw_ipv6
), NULL
);
1282 if (ENGINE_ISSET_EVENT(p
, ICMPV6_UNKNOWN_CODE
)) {
1283 SCLogDebug("ICMPv6 Error: Unknown code event is set");
1296 static int ICMPV6RouterAdvertTestUnknownCode(void)
1300 static uint8_t raw_ipv6
[] = {
1301 0x60, 0x00, 0x00, 0x00, 0x00, 0x08, 0x3a, 0xff,
1302 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1303 0x02, 0x24, 0x8c, 0xff, 0xfe, 0x0e, 0x31, 0x54,
1304 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1305 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
1306 0x86, 0x01, 0xbd, 0xaf, 0x00, 0x00, 0x00, 0x00
1309 Packet
*p
= SCMalloc(SIZE_OF_PACKET
);
1310 if (unlikely(p
== NULL
))
1314 DecodeThreadVars dtv
;
1316 memset(&tv
, 0, sizeof(ThreadVars
));
1317 memset(p
, 0, SIZE_OF_PACKET
);
1318 memset(&dtv
, 0, sizeof(DecodeThreadVars
));
1319 memset(&ip6h
, 0, sizeof(IPV6Hdr
));
1321 FlowInitConfig(FLOW_QUIET
);
1322 DecodeIPV6(&tv
, &dtv
, p
, raw_ipv6
, sizeof(raw_ipv6
), NULL
);
1324 if (!ENGINE_ISSET_EVENT(p
, ICMPV6_UNKNOWN_CODE
)) {
1325 SCLogDebug("ICMPv6 Error: Unknown code event is not set");
1338 static int ICMPV6NeighbourSolicitTestKnownCode(void)
1342 static uint8_t raw_ipv6
[] = {
1343 0x60, 0x00, 0x00, 0x00, 0x00, 0x08, 0x3a, 0xff,
1344 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1345 0x02, 0x24, 0x8c, 0xff, 0xfe, 0x0e, 0x31, 0x54,
1346 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1347 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
1348 0x87, 0x00, 0xbc, 0xb0, 0x00, 0x00, 0x00, 0x00
1351 Packet
*p
= SCMalloc(SIZE_OF_PACKET
);
1352 if (unlikely(p
== NULL
))
1356 DecodeThreadVars dtv
;
1358 memset(&tv
, 0, sizeof(ThreadVars
));
1359 memset(p
, 0, SIZE_OF_PACKET
);
1360 memset(&dtv
, 0, sizeof(DecodeThreadVars
));
1361 memset(&ip6h
, 0, sizeof(IPV6Hdr
));
1363 FlowInitConfig(FLOW_QUIET
);
1364 DecodeIPV6(&tv
, &dtv
, p
, raw_ipv6
, sizeof(raw_ipv6
), NULL
);
1366 if (ENGINE_ISSET_EVENT(p
, ICMPV6_UNKNOWN_CODE
)) {
1367 SCLogDebug("ICMPv6 Error: Unknown code event is set");
1380 static int ICMPV6NeighbourSolicitTestUnknownCode(void)
1384 static uint8_t raw_ipv6
[] = {
1385 0x60, 0x00, 0x00, 0x00, 0x00, 0x08, 0x3a, 0xff,
1386 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1387 0x02, 0x24, 0x8c, 0xff, 0xfe, 0x0e, 0x31, 0x54,
1388 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1389 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
1390 0x87, 0x01, 0xbc, 0xaf, 0x00, 0x00, 0x00, 0x00
1393 Packet
*p
= SCMalloc(SIZE_OF_PACKET
);
1394 if (unlikely(p
== NULL
))
1398 DecodeThreadVars dtv
;
1400 memset(&tv
, 0, sizeof(ThreadVars
));
1401 memset(p
, 0, SIZE_OF_PACKET
);
1402 memset(&dtv
, 0, sizeof(DecodeThreadVars
));
1403 memset(&ip6h
, 0, sizeof(IPV6Hdr
));
1405 FlowInitConfig(FLOW_QUIET
);
1406 DecodeIPV6(&tv
, &dtv
, p
, raw_ipv6
, sizeof(raw_ipv6
), NULL
);
1408 if (!ENGINE_ISSET_EVENT(p
, ICMPV6_UNKNOWN_CODE
)) {
1409 SCLogDebug("ICMPv6 Error: Unknown code event is not set");
1422 static int ICMPV6NeighbourAdvertTestKnownCode(void)
1426 static uint8_t raw_ipv6
[] = {
1427 0x60, 0x00, 0x00, 0x00, 0x00, 0x08, 0x3a, 0xff,
1428 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1429 0x02, 0x24, 0x8c, 0xff, 0xfe, 0x0e, 0x31, 0x54,
1430 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1431 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
1432 0x88, 0x00, 0xbb, 0xb0, 0x00, 0x00, 0x00, 0x00
1435 Packet
*p
= SCMalloc(SIZE_OF_PACKET
);
1436 if (unlikely(p
== NULL
))
1440 DecodeThreadVars dtv
;
1442 memset(&tv
, 0, sizeof(ThreadVars
));
1443 memset(p
, 0, SIZE_OF_PACKET
);
1444 memset(&dtv
, 0, sizeof(DecodeThreadVars
));
1445 memset(&ip6h
, 0, sizeof(IPV6Hdr
));
1447 FlowInitConfig(FLOW_QUIET
);
1448 DecodeIPV6(&tv
, &dtv
, p
, raw_ipv6
, sizeof(raw_ipv6
), NULL
);
1450 if (ENGINE_ISSET_EVENT(p
, ICMPV6_UNKNOWN_CODE
)) {
1451 SCLogDebug("ICMPv6 Error: Unknown code event is set");
1464 static int ICMPV6NeighbourAdvertTestUnknownCode(void)
1468 static uint8_t raw_ipv6
[] = {
1469 0x60, 0x00, 0x00, 0x00, 0x00, 0x08, 0x3a, 0xff,
1470 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1471 0x02, 0x24, 0x8c, 0xff, 0xfe, 0x0e, 0x31, 0x54,
1472 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1473 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
1474 0x88, 0x01, 0xbb, 0xaf, 0x00, 0x00, 0x00, 0x00
1477 Packet
*p
= SCMalloc(SIZE_OF_PACKET
);
1478 if (unlikely(p
== NULL
))
1482 DecodeThreadVars dtv
;
1484 memset(&tv
, 0, sizeof(ThreadVars
));
1485 memset(p
, 0, SIZE_OF_PACKET
);
1486 memset(&dtv
, 0, sizeof(DecodeThreadVars
));
1487 memset(&ip6h
, 0, sizeof(IPV6Hdr
));
1489 FlowInitConfig(FLOW_QUIET
);
1490 DecodeIPV6(&tv
, &dtv
, p
, raw_ipv6
, sizeof(raw_ipv6
), NULL
);
1492 if (!ENGINE_ISSET_EVENT(p
, ICMPV6_UNKNOWN_CODE
)) {
1493 SCLogDebug("ICMPv6 Error: Unknown code event is not set");
1506 static int ICMPV6RedirectTestKnownCode(void)
1510 static uint8_t raw_ipv6
[] = {
1511 0x60, 0x00, 0x00, 0x00, 0x00, 0x08, 0x3a, 0xff,
1512 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1513 0x02, 0x24, 0x8c, 0xff, 0xfe, 0x0e, 0x31, 0x54,
1514 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1515 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
1516 0x89, 0x00, 0xba, 0xb0, 0x00, 0x00, 0x00, 0x00
1519 Packet
*p
= SCMalloc(SIZE_OF_PACKET
);
1520 if (unlikely(p
== NULL
))
1524 DecodeThreadVars dtv
;
1526 memset(&tv
, 0, sizeof(ThreadVars
));
1527 memset(p
, 0, SIZE_OF_PACKET
);
1528 memset(&dtv
, 0, sizeof(DecodeThreadVars
));
1529 memset(&ip6h
, 0, sizeof(IPV6Hdr
));
1531 FlowInitConfig(FLOW_QUIET
);
1532 DecodeIPV6(&tv
, &dtv
, p
, raw_ipv6
, sizeof(raw_ipv6
), NULL
);
1534 if (ENGINE_ISSET_EVENT(p
, ICMPV6_UNKNOWN_CODE
)) {
1535 SCLogDebug("ICMPv6 Error: Unknown code event is set");
1548 static int ICMPV6RedirectTestUnknownCode(void)
1552 static uint8_t raw_ipv6
[] = {
1553 0x60, 0x00, 0x00, 0x00, 0x00, 0x08, 0x3a, 0xff,
1554 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1555 0x02, 0x24, 0x8c, 0xff, 0xfe, 0x0e, 0x31, 0x54,
1556 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1557 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
1558 0x89, 0x01, 0xba, 0xaf, 0x00, 0x00, 0x00, 0x00
1561 Packet
*p
= SCMalloc(SIZE_OF_PACKET
);
1562 if (unlikely(p
== NULL
))
1566 DecodeThreadVars dtv
;
1568 memset(&tv
, 0, sizeof(ThreadVars
));
1569 memset(p
, 0, SIZE_OF_PACKET
);
1570 memset(&dtv
, 0, sizeof(DecodeThreadVars
));
1571 memset(&ip6h
, 0, sizeof(IPV6Hdr
));
1573 FlowInitConfig(FLOW_QUIET
);
1574 DecodeIPV6(&tv
, &dtv
, p
, raw_ipv6
, sizeof(raw_ipv6
), NULL
);
1576 if (!ENGINE_ISSET_EVENT(p
, ICMPV6_UNKNOWN_CODE
)) {
1577 SCLogDebug("ICMPv6 Error: Unknown code event is not set");
1590 #endif /* UNITTESTS */
1592 * \brief Registers ICMPV6 unit tests
1593 * \todo More ICMPv6 tests
1595 void DecodeICMPV6RegisterTests(void)
1598 UtRegisterTest("ICMPV6CalculateValidChecksumtest01", ICMPV6CalculateValidChecksumtest01
, 1);
1599 UtRegisterTest("ICMPV6CalculateInValidChecksumtest02", ICMPV6CalculateInvalidChecksumtest02
, 0);
1601 UtRegisterTest("ICMPV6ParamProbTest01 (Valid)", ICMPV6ParamProbTest01
, 1);
1602 UtRegisterTest("ICMPV6DestUnreachTest01 (Valid)", ICMPV6DestUnreachTest01
, 1);
1603 UtRegisterTest("ICMPV6PktTooBigTest01 (Valid)", ICMPV6PktTooBigTest01
, 1);
1604 UtRegisterTest("ICMPV6TimeExceedTest01 (Valid)", ICMPV6TimeExceedTest01
, 1);
1605 UtRegisterTest("ICMPV6EchoReqTest01 (Valid)", ICMPV6EchoReqTest01
, 1);
1606 UtRegisterTest("ICMPV6EchoRepTest01 (Valid)", ICMPV6EchoRepTest01
, 1);
1608 UtRegisterTest("ICMPV6ParamProbTest02 (Invalid)", ICMPV6ParamProbTest02
, 1);
1609 UtRegisterTest("ICMPV6DestUnreachTest02 (Invalid)", ICMPV6DestUnreachTest02
, 1);
1610 UtRegisterTest("ICMPV6PktTooBigTest02 (Invalid)", ICMPV6PktTooBigTest02
, 1);
1611 UtRegisterTest("ICMPV6TimeExceedTest02 (Invalid)", ICMPV6TimeExceedTest02
, 1);
1612 UtRegisterTest("ICMPV6EchoReqTest02 (Invalid)", ICMPV6EchoReqTest02
, 1);
1613 UtRegisterTest("ICMPV6EchoRepTest02 (Invalid)", ICMPV6EchoRepTest02
, 1);
1615 UtRegisterTest("ICMPV6PayloadTest01", ICMPV6PayloadTest01
, 1);
1617 UtRegisterTest("ICMPV6RouterSolicitTestKnownCode",
1618 ICMPV6RouterSolicitTestKnownCode
, 1);
1619 UtRegisterTest("ICMPV6RouterSolicitTestUnknownCode",
1620 ICMPV6RouterSolicitTestUnknownCode
, 1);
1621 UtRegisterTest("ICMPV6RouterAdvertTestKnownCode",
1622 ICMPV6RouterAdvertTestKnownCode
, 1);
1623 UtRegisterTest("ICMPV6RouterAdvertTestUnknownCode",
1624 ICMPV6RouterAdvertTestUnknownCode
, 1);
1626 UtRegisterTest("ICMPV6NeighbourSolicitTestKnownCode",
1627 ICMPV6NeighbourSolicitTestKnownCode
, 1);
1628 UtRegisterTest("ICMPV6NeighbourSolicitTestUnknownCode",
1629 ICMPV6NeighbourSolicitTestUnknownCode
, 1);
1630 UtRegisterTest("ICMPV6NeighbourAdvertTestKnownCode",
1631 ICMPV6NeighbourAdvertTestKnownCode
, 1);
1632 UtRegisterTest("ICMPV6NeighbourAdvertTestUnknownCode",
1633 ICMPV6NeighbourAdvertTestUnknownCode
, 1);
1635 UtRegisterTest("ICMPV6RedirectTestKnownCode", ICMPV6RedirectTestKnownCode
, 1);
1636 UtRegisterTest("ICMPV6RedirectTestUnknownCode",
1637 ICMPV6RedirectTestUnknownCode
, 1);
1638 #endif /* UNITTESTS */