]> git.ipfire.org Git - people/ms/suricata.git/blob - src/decode-icmpv6.c
7972ea797c98af30636bb619cd2a0adf5bf0d743
[people/ms/suricata.git] / src / decode-icmpv6.c
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 "decode-tcp.h"
37 #include "decode-sctp.h"
38 #include "decode-udp.h"
39 #include "decode-events.h"
40 #include "util-unittest.h"
41 #include "flow.h"
42 #include "util-debug.h"
43 #include "util-print.h"
44
45 #include "pkt-var.h"
46 #include "util-profiling.h"
47 #include "host.h"
48
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 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");
64 ENGINE_SET_INVALID_EVENT(p, 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");
75 ENGINE_SET_INVALID_EVENT(p, ICMPV6_IPV6_UNKNOWN_VER);
76 return;
77 }
78
79 /** We need to fill icmpv6vars */
80 p->icmpv6vars.emb_ipv6h = icmp6_ip6h;
81
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];
87
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];
92
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;
95
96 switch (icmp6_ip6h->s_ip6_nxt) {
97 case IPPROTO_TCP:
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;
102
103 SCLogDebug("ICMPV6->IPV6->TCP header sport: "
104 "%"PRIu8" dport %"PRIu8"", p->icmpv6vars.emb_sport,
105 p->icmpv6vars.emb_dport);
106 } else {
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;
111 }
112
113 break;
114 case IPPROTO_UDP:
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;
119
120 SCLogDebug("ICMPV6->IPV6->UDP header sport: "
121 "%"PRIu8" dport %"PRIu8"", p->icmpv6vars.emb_sport,
122 p->icmpv6vars.emb_dport);
123 } else {
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;
128 }
129
130 break;
131 case IPPROTO_ICMPV6:
132 p->icmpv6vars.emb_icmpv6h = (ICMPV6Hdr*)(partial_packet + IPV6_HEADER_LEN);
133 p->icmpv6vars.emb_sport = 0;
134 p->icmpv6vars.emb_dport = 0;
135
136 SCLogDebug("ICMPV6->IPV6->ICMP header");
137
138 break;
139 }
140
141 /* debug print */
142 #ifdef DEBUG
143 char s[46], d[46];
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));
150 #endif
151
152 return;
153 }
154
155 /**
156 * \brief Decode ICMPV6 packets and fill the Packet with the decoded info
157 *
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
164 *
165 * \retval void No return value
166 */
167 int DecodeICMPV6(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p,
168 uint8_t *pkt, uint16_t len, PacketQueue *pq)
169 {
170 int full_hdr = 0;
171 StatsIncr(tv, dtv->counter_icmpv6);
172
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;
177 }
178
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;
185
186 SCLogDebug("ICMPV6 TYPE %" PRIu32 " CODE %" PRIu32 "", p->icmpv6h->type,
187 p->icmpv6h->code);
188
189 switch (ICMPV6_GET_TYPE(p)) {
190 case ICMP6_DST_UNREACH:
191 SCLogDebug("ICMP6_DST_UNREACH");
192
193 if (ICMPV6_GET_CODE(p) > ICMP6_DST_UNREACH_REJECTROUTE) {
194 ENGINE_SET_EVENT(p, ICMPV6_UNKNOWN_CODE);
195 } else {
196 DecodePartialIPV6(p, (uint8_t*) (pkt + ICMPV6_HEADER_LEN),
197 len - ICMPV6_HEADER_LEN );
198 full_hdr = 1;
199 }
200
201 break;
202 case ICMP6_PACKET_TOO_BIG:
203 SCLogDebug("ICMP6_PACKET_TOO_BIG");
204
205 if (ICMPV6_GET_CODE(p) != 0) {
206 ENGINE_SET_EVENT(p, ICMPV6_UNKNOWN_CODE);
207 } else {
208 p->icmpv6vars.mtu = ICMPV6_GET_MTU(p);
209 DecodePartialIPV6(p, (uint8_t*) (pkt + ICMPV6_HEADER_LEN),
210 len - ICMPV6_HEADER_LEN );
211 full_hdr = 1;
212 }
213
214 break;
215 case ICMP6_TIME_EXCEEDED:
216 SCLogDebug("ICMP6_TIME_EXCEEDED");
217
218 if (ICMPV6_GET_CODE(p) > ICMP6_TIME_EXCEED_REASSEMBLY) {
219 ENGINE_SET_EVENT(p, ICMPV6_UNKNOWN_CODE);
220 } else {
221 DecodePartialIPV6(p, (uint8_t*) (pkt + ICMPV6_HEADER_LEN),
222 len - ICMPV6_HEADER_LEN );
223 full_hdr = 1;
224 }
225
226 break;
227 case ICMP6_PARAM_PROB:
228 SCLogDebug("ICMP6_PARAM_PROB");
229
230 if (ICMPV6_GET_CODE(p) > ICMP6_PARAMPROB_OPTION) {
231 ENGINE_SET_EVENT(p, ICMPV6_UNKNOWN_CODE);
232 } else {
233 p->icmpv6vars.error_ptr= ICMPV6_GET_ERROR_PTR(p);
234 DecodePartialIPV6(p, (uint8_t*) (pkt + ICMPV6_HEADER_LEN),
235 len - ICMPV6_HEADER_LEN );
236 full_hdr = 1;
237 }
238
239 break;
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);
243
244 if (ICMPV6_GET_CODE(p) != 0) {
245 ENGINE_SET_EVENT(p, ICMPV6_UNKNOWN_CODE);
246 } else {
247 p->icmpv6vars.id = p->icmpv6h->icmpv6b.icmpv6i.id;
248 p->icmpv6vars.seq = p->icmpv6h->icmpv6b.icmpv6i.seq;
249 full_hdr = 1;
250 }
251
252 break;
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);
256
257 if (p->icmpv6h->code != 0) {
258 ENGINE_SET_EVENT(p, ICMPV6_UNKNOWN_CODE);
259 } else {
260 p->icmpv6vars.id = p->icmpv6h->icmpv6b.icmpv6i.id;
261 p->icmpv6vars.seq = p->icmpv6h->icmpv6b.icmpv6i.seq;
262 full_hdr = 1;
263 }
264
265 break;
266 case ND_ROUTER_SOLICIT:
267 SCLogDebug("ND_ROUTER_SOLICIT");
268 if (p->icmpv6h->code != 0) {
269 ENGINE_SET_EVENT(p, ICMPV6_UNKNOWN_CODE);
270 }
271 break;
272 case ND_ROUTER_ADVERT:
273 SCLogDebug("ND_ROUTER_ADVERT");
274 if (p->icmpv6h->code != 0) {
275 ENGINE_SET_EVENT(p, ICMPV6_UNKNOWN_CODE);
276 }
277 break;
278 case ND_NEIGHBOR_SOLICIT:
279 SCLogDebug("ND_NEIGHBOR_SOLICIT");
280 if (p->icmpv6h->code != 0) {
281 ENGINE_SET_EVENT(p, ICMPV6_UNKNOWN_CODE);
282 }
283 break;
284 case ND_NEIGHBOR_ADVERT:
285 SCLogDebug("ND_NEIGHBOR_ADVERT");
286 if (p->icmpv6h->code != 0) {
287 ENGINE_SET_EVENT(p, ICMPV6_UNKNOWN_CODE);
288 }
289 break;
290 case ND_REDIRECT:
291 SCLogDebug("ND_REDIRECT");
292 if (p->icmpv6h->code != 0) {
293 ENGINE_SET_EVENT(p, ICMPV6_UNKNOWN_CODE);
294 }
295 break;
296 case MLD_LISTENER_QUERY:
297 SCLogDebug("MLD_LISTENER_QUERY");
298 if (p->icmpv6h->code != 0) {
299 ENGINE_SET_EVENT(p, ICMPV6_UNKNOWN_CODE);
300 }
301 if (IPV6_GET_HLIM(p) != 1) {
302 ENGINE_SET_EVENT(p, ICMPV6_MLD_MESSAGE_WITH_INVALID_HL);
303 }
304 break;
305 case MLD_LISTENER_REPORT:
306 SCLogDebug("MLD_LISTENER_REPORT");
307 if (p->icmpv6h->code != 0) {
308 ENGINE_SET_EVENT(p, ICMPV6_UNKNOWN_CODE);
309 }
310 if (IPV6_GET_HLIM(p) != 1) {
311 ENGINE_SET_EVENT(p, ICMPV6_MLD_MESSAGE_WITH_INVALID_HL);
312 }
313 break;
314 case MLD_LISTENER_REDUCTION:
315 SCLogDebug("MLD_LISTENER_REDUCTION");
316 if (p->icmpv6h->code != 0) {
317 ENGINE_SET_EVENT(p, ICMPV6_UNKNOWN_CODE);
318 }
319 if (IPV6_GET_HLIM(p) != 1) {
320 ENGINE_SET_EVENT(p, ICMPV6_MLD_MESSAGE_WITH_INVALID_HL);
321 }
322 break;
323 default:
324 SCLogDebug("ICMPV6 Message type %" PRIu8 " not "
325 "implemented yet", ICMPV6_GET_TYPE(p));
326 ENGINE_SET_EVENT(p, ICMPV6_UNKNOWN_TYPE);
327 }
328
329 /* for a info message the header is just 4 bytes */
330 if (!full_hdr) {
331 if (p->payload_len >= 4) {
332 p->payload_len -= 4;
333 p->payload = pkt + 4;
334 } else {
335 p->payload_len = 0;
336 p->payload = NULL;
337 }
338 }
339
340 #ifdef DEBUG
341 if (ENGINE_ISSET_EVENT(p, ICMPV6_UNKNOWN_CODE))
342 SCLogDebug("Unknown Code, ICMPV6_UNKNOWN_CODE");
343
344 if (ENGINE_ISSET_EVENT(p, ICMPV6_UNKNOWN_TYPE))
345 SCLogDebug("Unknown Type, ICMPV6_UNKNOWN_TYPE");
346 #endif
347
348 /* Flow is an integral part of us */
349 FlowHandlePacket(tv, dtv, p);
350
351 return TM_ECODE_OK;
352 }
353
354 #ifdef UNITTESTS
355
356 static int ICMPV6CalculateValidChecksumtest01(void)
357 {
358 uint16_t csum = 0;
359
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,
376 0x08, 0x00};
377
378 csum = *( ((uint16_t *)(raw_ipv6 + 56)));
379
380 return (csum == ICMPV6CalculateChecksum((uint16_t *)(raw_ipv6 + 14 + 8),
381 (uint16_t *)(raw_ipv6 + 54), 68));
382 }
383
384 static int ICMPV6CalculateInvalidChecksumtest02(void)
385 {
386 uint16_t csum = 0;
387
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,
404 0x08, 0x01};
405
406 csum = *( ((uint16_t *)(raw_ipv6 + 56)));
407
408 return (csum == ICMPV6CalculateChecksum((uint16_t *)(raw_ipv6 + 14 + 8),
409 (uint16_t *)(raw_ipv6 + 54), 68));
410 }
411
412
413 /** \test icmpv6 message type: parameter problem, valid packet
414 *
415 * \retval retval 0 = Error ; 1 = ok
416 */
417 static int ICMPV6ParamProbTest01(void)
418 {
419 int retval = 0;
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 };
433
434 Packet *p = SCMalloc(SIZE_OF_PACKET);
435 if (unlikely(p == NULL))
436 return 0;
437 IPV6Hdr ip6h;
438 ThreadVars tv;
439 DecodeThreadVars dtv;
440 uint32_t *ipv6src;
441 uint32_t *ipv6dst;
442 ipv6src = (uint32_t*) &raw_ipv6[8];
443 ipv6dst = (uint32_t*) &raw_ipv6[24];
444
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));
449
450 FlowInitConfig(FLOW_QUIET);
451 DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6), NULL);
452
453 if (p->icmpv6h == NULL) {
454 SCLogDebug("ICMPv6 Unable to detect icmpv6 layer from ipv6");
455 retval = 0;
456 goto end;
457 }
458
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");
462 retval = 0;
463 goto end;
464 }
465
466 /* Let's check if we retrieved the embedded ipv6 addresses correctly */
467 uint32_t i=0;
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");
473 retval = 0;
474 goto end;
475 }
476 }
477
478 retval = 1;
479 end:
480 PACKET_RECYCLE(p);
481 FlowShutdown();
482 SCFree(p);
483 return retval;
484 }
485
486 /** \test icmpv6 message type: packet too big, valid packet
487 *
488 * \retval retval 0 = Error ; 1 = ok
489 */
490 static int ICMPV6PktTooBigTest01(void)
491 {
492 int retval = 0;
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 };
505
506 Packet *p = SCMalloc(SIZE_OF_PACKET);
507 if (unlikely(p == NULL))
508 return 0;
509 IPV6Hdr ip6h;
510 ThreadVars tv;
511 DecodeThreadVars dtv;
512 uint32_t *ipv6src;
513 uint32_t *ipv6dst;
514 ipv6src = (uint32_t*) &raw_ipv6[8];
515 ipv6dst = (uint32_t*) &raw_ipv6[24];
516
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));
521
522 FlowInitConfig(FLOW_QUIET);
523 DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6), NULL);
524
525 if (p->icmpv6h == NULL) {
526 SCLogDebug("ICMPv6 Unable to detect icmpv6 layer from ipv6");
527 retval = 0;
528 goto end;
529 }
530
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");
534 retval = 0;
535 goto end;
536 }
537
538 /* Let's check if we retrieved the embedded ipv6 addresses correctly */
539 uint32_t i=0;
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");
545 retval = 0;
546 goto end;
547 }
548 }
549
550 SCLogDebug("ICMPV6 IPV6 src and dst properly set");
551
552 retval = 1;
553 end:
554 PACKET_RECYCLE(p);
555 FlowShutdown();
556 SCFree(p);
557 return retval;
558 }
559
560 /** \test icmpv6 message type: time exceed, valid packet
561 *
562 * \retval retval 0 = Error ; 1 = ok
563 */
564 static int ICMPV6TimeExceedTest01(void)
565 {
566 int retval = 0;
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 };
579
580 Packet *p = SCMalloc(SIZE_OF_PACKET);
581 if (unlikely(p == NULL))
582 return 0;
583 IPV6Hdr ip6h;
584 ThreadVars tv;
585 DecodeThreadVars dtv;
586 uint32_t *ipv6src;
587 uint32_t *ipv6dst;
588 ipv6src = (uint32_t*) &raw_ipv6[8];
589 ipv6dst = (uint32_t*) &raw_ipv6[24];
590
591
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));
596
597 FlowInitConfig(FLOW_QUIET);
598 DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6), NULL);
599
600 if (p->icmpv6h == NULL) {
601 SCLogDebug("ICMPv6 Unable to detect icmpv6 layer from ipv6");
602 retval = 0;
603 goto end;
604 }
605
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");
610 retval = 0;
611 goto end;
612 }
613
614 /* Let's check if we retrieved the embedded ipv6 addresses correctly */
615 uint32_t i=0;
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");
621 retval = 0;
622 goto end;
623 }
624 }
625
626 SCLogDebug("ICMPV6 IPV6 src and dst properly set");
627
628 retval = 1;
629 end:
630 PACKET_RECYCLE(p);
631 FlowShutdown();
632 SCFree(p);
633 return retval;
634 }
635
636 /** \test icmpv6 message type: destination unreach, valid packet
637 *
638 * \retval retval 0 = Error ; 1 = ok
639 */
640 static int ICMPV6DestUnreachTest01(void)
641 {
642 int retval = 0;
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 };
655
656 Packet *p = SCMalloc(SIZE_OF_PACKET);
657 if (unlikely(p == NULL))
658 return 0;
659 IPV6Hdr ip6h;
660 ThreadVars tv;
661 DecodeThreadVars dtv;
662 uint32_t *ipv6src;
663 uint32_t *ipv6dst;
664 ipv6src = (uint32_t*) &raw_ipv6[8];
665 ipv6dst = (uint32_t*) &raw_ipv6[24];
666
667
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));
672
673 FlowInitConfig(FLOW_QUIET);
674 DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6), NULL);
675
676 if (p->icmpv6h == NULL) {
677 SCLogDebug("ICMPv6 Unable to detect icmpv6 layer from ipv6");
678 retval = 0;
679 goto end;
680 }
681
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");
686 retval = 0;
687 goto end;
688 }
689
690 /* Let's check if we retrieved the embedded ipv6 addresses correctly */
691 uint32_t i=0;
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");
697 retval = 0;
698 goto end;
699 }
700 }
701
702 retval = 1;
703 end:
704 PACKET_RECYCLE(p);
705 FlowShutdown();
706 SCFree(p);
707 return retval;
708 }
709
710 /**\test icmpv6 message type: echo request, valid packet
711 * \retval retval 0 = Error ; 1 = ok
712 */
713 static int ICMPV6EchoReqTest01(void)
714 {
715 int retval = 0;
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 };
723
724 Packet *p = SCMalloc(SIZE_OF_PACKET);
725 if (unlikely(p == NULL))
726 return 0;
727 IPV6Hdr ip6h;
728 ThreadVars tv;
729 DecodeThreadVars dtv;
730
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));
735
736 FlowInitConfig(FLOW_QUIET);
737 DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6), NULL);
738
739 if (p->icmpv6h == NULL) {
740 SCLogDebug("ICMPv6 Unable to detect icmpv6 layer from ipv6");
741 goto end;
742 }
743
744 SCLogDebug("ID: %u seq: %u", ICMPV6_GET_ID(p), ICMPV6_GET_SEQ(p));
745
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)));
751 goto end;
752 }
753
754 retval = 1;
755 end:
756 PACKET_RECYCLE(p);
757 FlowShutdown();
758 SCFree(p);
759 return retval;
760 }
761
762 /**\test icmpv6 message type: echo reply, valid packet
763 * \retval retval 0 = Error ; 1 = ok
764 */
765 static int ICMPV6EchoRepTest01(void)
766 {
767 int retval = 0;
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 };
776
777 Packet *p = SCMalloc(SIZE_OF_PACKET);
778 if (unlikely(p == NULL))
779 return 0;
780 IPV6Hdr ip6h;
781 ThreadVars tv;
782 DecodeThreadVars dtv;
783
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));
788
789 FlowInitConfig(FLOW_QUIET);
790 DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6), NULL);
791
792 if (p->icmpv6h == NULL) {
793 SCLogDebug("ICMPv6 Unable to detect icmpv6 layer from ipv6");
794 goto end;
795 }
796
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));
799
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)));
805 goto end;
806 }
807
808 retval = 1;
809 end:
810 PACKET_RECYCLE(p);
811 FlowShutdown();
812 SCFree(p);
813 return retval;
814 }
815
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
819 */
820 static int ICMPV6ParamProbTest02(void)
821 {
822 int retval = 0;
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 };
836
837 Packet *p = SCMalloc(SIZE_OF_PACKET);
838 if (unlikely(p == NULL))
839 return 0;
840 IPV6Hdr ip6h;
841 ThreadVars tv;
842 DecodeThreadVars dtv;
843
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));
848
849 FlowInitConfig(FLOW_QUIET);
850 DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6), NULL);
851
852 if (p->icmpv6h == NULL) {
853 SCLogDebug("ICMPv6 Unable to detect icmpv6 layer from ipv6");
854 retval = 0;
855 goto end;
856 }
857
858 if (ICMPV6_GET_TYPE(p) != 4 || ICMPV6_GET_CODE(p) != 0) {
859 SCLogDebug("ICMPv6 Not processed at all");
860 retval = 0;
861 goto end;
862 }
863
864 if (!ENGINE_ISSET_EVENT(p, ICMPV6_IPV6_UNKNOWN_VER)) {
865 SCLogDebug("ICMPv6 Error: Unknown embedded ipv6 version event not set");
866 retval = 0;
867 goto end;
868 }
869
870 retval = 1;
871 end:
872 PACKET_RECYCLE(p);
873 FlowShutdown();
874 SCFree(p);
875 return retval;
876 }
877
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
881 */
882 static int ICMPV6PktTooBigTest02(void)
883 {
884 int retval = 0;
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 };
897
898 Packet *p = SCMalloc(SIZE_OF_PACKET);
899 if (unlikely(p == NULL))
900 return 0;
901 IPV6Hdr ip6h;
902 ThreadVars tv;
903 DecodeThreadVars dtv;
904
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));
909
910 FlowInitConfig(FLOW_QUIET);
911 DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6), NULL);
912
913 if (p->icmpv6h == NULL) {
914 SCLogDebug("ICMPv6 Unable to detect icmpv6 layer from ipv6");
915 retval = 0;
916 goto end;
917 }
918
919 if (!ENGINE_ISSET_EVENT(p, ICMPV6_UNKNOWN_CODE)) {
920 SCLogDebug("ICMPv6 Error: Unknown code event not set");
921 retval = 0;
922 goto end;
923 }
924
925 retval = 1;
926 end:
927 PACKET_RECYCLE(p);
928 FlowShutdown();
929 SCFree(p);
930 return retval;
931 }
932
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
936 */
937 static int ICMPV6TimeExceedTest02(void)
938 {
939 int retval = 0;
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,
946 0x02, 0x10, 0x5c };
947
948 /* The icmpv6 header is broken in the checksum (so we dont have a complete header) */
949
950 Packet *p = SCMalloc(SIZE_OF_PACKET);
951 if (unlikely(p == NULL))
952 return 0;
953 IPV6Hdr ip6h;
954 ThreadVars tv;
955 DecodeThreadVars dtv;
956
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));
961
962 FlowInitConfig(FLOW_QUIET);
963 DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6), NULL);
964
965 if (!ENGINE_ISSET_EVENT(p, ICMPV6_PKT_TOO_SMALL)) {
966 SCLogDebug("ICMPv6 Error: event packet too small not set");
967 retval = 0;
968 goto end;
969 }
970
971 retval = 1;
972 end:
973 PACKET_RECYCLE(p);
974 FlowShutdown();
975 SCFree(p);
976 return retval;
977 }
978
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
982 */
983 static int ICMPV6DestUnreachTest02(void)
984 {
985 int retval = 0;
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 };
998
999 Packet *p = SCMalloc(SIZE_OF_PACKET);
1000 if (unlikely(p == NULL))
1001 return 0;
1002 IPV6Hdr ip6h;
1003 ThreadVars tv;
1004 DecodeThreadVars dtv;
1005
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));
1010
1011 FlowInitConfig(FLOW_QUIET);
1012 DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6), NULL);
1013
1014 if (!ENGINE_ISSET_EVENT(p, ICMPV6_IPV6_TRUNC_PKT)) {
1015 SCLogDebug("ICMPv6 Error: embedded ipv6 truncated packet event not set");
1016 retval = 0;
1017 goto end;
1018 }
1019
1020 retval = 1;
1021 end:
1022 PACKET_RECYCLE(p);
1023 FlowShutdown();
1024 SCFree(p);
1025 return retval;
1026 }
1027
1028 /**\test icmpv6 message type: echo request, invalid packet
1029 * \brief unknown code
1030 * \retval retval 0 = Error ; 1 = ok
1031 */
1032 static int ICMPV6EchoReqTest02(void)
1033 {
1034 int retval = 0;
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 };
1043
1044 Packet *p = SCMalloc(SIZE_OF_PACKET);
1045 if (unlikely(p == NULL))
1046 return 0;
1047 IPV6Hdr ip6h;
1048 ThreadVars tv;
1049 DecodeThreadVars dtv;
1050
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));
1055
1056 FlowInitConfig(FLOW_QUIET);
1057 DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6), NULL);
1058
1059 if (!ENGINE_ISSET_EVENT(p, ICMPV6_UNKNOWN_CODE)) {
1060 SCLogDebug("ICMPv6 Error: Unknown code event not set");
1061 retval = 0;
1062 goto end;
1063 }
1064
1065 retval = 1;
1066 end:
1067 PACKET_RECYCLE(p);
1068 FlowShutdown();
1069 SCFree(p);
1070 return retval;
1071 }
1072
1073 /**\test icmpv6 message type: echo reply, invalid packet
1074 * \brief unknown code
1075 * \retval retval 0 = Error ; 1 = ok
1076 */
1077 static int ICMPV6EchoRepTest02(void)
1078 {
1079 int retval = 0;
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 };
1088
1089 Packet *p = SCMalloc(SIZE_OF_PACKET);
1090 if (unlikely(p == NULL))
1091 return 0;
1092 IPV6Hdr ip6h;
1093 ThreadVars tv;
1094 DecodeThreadVars dtv;
1095
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));
1100
1101 FlowInitConfig(FLOW_QUIET);
1102 DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6), NULL);
1103
1104 if (!ENGINE_ISSET_EVENT(p, ICMPV6_UNKNOWN_CODE)) {
1105 SCLogDebug("ICMPv6 Error: Unknown code event not set");
1106 retval = 0;
1107 goto end;
1108 }
1109
1110 retval = 1;
1111 end:
1112 PACKET_RECYCLE(p);
1113 FlowShutdown();
1114 SCFree(p);
1115 return retval;
1116 }
1117
1118 /**\test icmpv6 packet decoding and setting up of payload_len and payload buufer
1119 * \retval retval 0 = Error ; 1 = ok
1120 */
1121 static int ICMPV6PayloadTest01(void)
1122 {
1123 int retval = 0;
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 };
1136
1137 Packet *p = SCMalloc(SIZE_OF_PACKET);
1138 if (unlikely(p == NULL))
1139 return 0;
1140 IPV6Hdr ip6h;
1141 ThreadVars tv;
1142 DecodeThreadVars dtv;
1143
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));
1148
1149 FlowInitConfig(FLOW_QUIET);
1150 DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6), NULL);
1151
1152 if (p->payload == NULL) {
1153 printf("payload == NULL, expected non-NULL: ");
1154 goto end;
1155 }
1156
1157 if (p->payload_len != 37) {
1158 printf("payload_len %"PRIu16", expected 37: ", p->payload_len);
1159 goto end;
1160 }
1161
1162 retval = 1;
1163 end:
1164 PACKET_RECYCLE(p);
1165 FlowShutdown();
1166 SCFree(p);
1167 return retval;
1168 }
1169
1170 static int ICMPV6RouterSolicitTestKnownCode(void)
1171 {
1172 int retval = 0;
1173
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
1181 };
1182
1183 Packet *p = SCMalloc(SIZE_OF_PACKET);
1184 if (unlikely(p == NULL))
1185 return 0;
1186 IPV6Hdr ip6h;
1187 ThreadVars tv;
1188 DecodeThreadVars dtv;
1189
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));
1194
1195 FlowInitConfig(FLOW_QUIET);
1196 DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6), NULL);
1197
1198 if (ENGINE_ISSET_EVENT(p, ICMPV6_UNKNOWN_CODE)) {
1199 SCLogDebug("ICMPv6 Error: Unknown code event is set");
1200 retval = 0;
1201 goto end;
1202 }
1203
1204 retval = 1;
1205 end:
1206 PACKET_RECYCLE(p);
1207 FlowShutdown();
1208 SCFree(p);
1209 return retval;
1210 }
1211
1212 static int ICMPV6RouterSolicitTestUnknownCode(void)
1213 {
1214 int retval = 0;
1215
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
1223 };
1224
1225 Packet *p = SCMalloc(SIZE_OF_PACKET);
1226 if (unlikely(p == NULL))
1227 return 0;
1228 IPV6Hdr ip6h;
1229 ThreadVars tv;
1230 DecodeThreadVars dtv;
1231
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));
1236
1237 FlowInitConfig(FLOW_QUIET);
1238 DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6), NULL);
1239
1240 if (!ENGINE_ISSET_EVENT(p, ICMPV6_UNKNOWN_CODE)) {
1241 SCLogDebug("ICMPv6 Error: Unknown code event is not set");
1242 retval = 0;
1243 goto end;
1244 }
1245
1246 retval = 1;
1247 end:
1248 PACKET_RECYCLE(p);
1249 FlowShutdown();
1250 SCFree(p);
1251 return retval;
1252 }
1253
1254 static int ICMPV6RouterAdvertTestKnownCode(void)
1255 {
1256 int retval = 0;
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, 0x00, 0xbd, 0xb0, 0x00, 0x00, 0x00, 0x00
1265 };
1266
1267 Packet *p = SCMalloc(SIZE_OF_PACKET);
1268 if (unlikely(p == NULL))
1269 return 0;
1270 IPV6Hdr ip6h;
1271 ThreadVars tv;
1272 DecodeThreadVars dtv;
1273
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));
1278
1279 FlowInitConfig(FLOW_QUIET);
1280 DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6), NULL);
1281
1282 if (ENGINE_ISSET_EVENT(p, ICMPV6_UNKNOWN_CODE)) {
1283 SCLogDebug("ICMPv6 Error: Unknown code event is set");
1284 retval = 0;
1285 goto end;
1286 }
1287
1288 retval = 1;
1289 end:
1290 PACKET_RECYCLE(p);
1291 FlowShutdown();
1292 SCFree(p);
1293 return retval;
1294 }
1295
1296 static int ICMPV6RouterAdvertTestUnknownCode(void)
1297 {
1298 int retval = 0;
1299
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
1307 };
1308
1309 Packet *p = SCMalloc(SIZE_OF_PACKET);
1310 if (unlikely(p == NULL))
1311 return 0;
1312 IPV6Hdr ip6h;
1313 ThreadVars tv;
1314 DecodeThreadVars dtv;
1315
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));
1320
1321 FlowInitConfig(FLOW_QUIET);
1322 DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6), NULL);
1323
1324 if (!ENGINE_ISSET_EVENT(p, ICMPV6_UNKNOWN_CODE)) {
1325 SCLogDebug("ICMPv6 Error: Unknown code event is not set");
1326 retval = 0;
1327 goto end;
1328 }
1329
1330 retval = 1;
1331 end:
1332 PACKET_RECYCLE(p);
1333 FlowShutdown();
1334 SCFree(p);
1335 return retval;
1336 }
1337
1338 static int ICMPV6NeighbourSolicitTestKnownCode(void)
1339 {
1340 int retval = 0;
1341
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
1349 };
1350
1351 Packet *p = SCMalloc(SIZE_OF_PACKET);
1352 if (unlikely(p == NULL))
1353 return 0;
1354 IPV6Hdr ip6h;
1355 ThreadVars tv;
1356 DecodeThreadVars dtv;
1357
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));
1362
1363 FlowInitConfig(FLOW_QUIET);
1364 DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6), NULL);
1365
1366 if (ENGINE_ISSET_EVENT(p, ICMPV6_UNKNOWN_CODE)) {
1367 SCLogDebug("ICMPv6 Error: Unknown code event is set");
1368 retval = 0;
1369 goto end;
1370 }
1371
1372 retval = 1;
1373 end:
1374 PACKET_RECYCLE(p);
1375 FlowShutdown();
1376 SCFree(p);
1377 return retval;
1378 }
1379
1380 static int ICMPV6NeighbourSolicitTestUnknownCode(void)
1381 {
1382 int retval = 0;
1383
1384 static uint8_t raw_ipv6[] = {
1385 0x60, 0x00, 0x00, 0x00, 0x00, 0x08, 0x3a, 0xff,
1386 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1387 0x02, 0x24, 0x8c, 0xff, 0xfe, 0x0e, 0x31, 0x54,
1388 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1389 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
1390 0x87, 0x01, 0xbc, 0xaf, 0x00, 0x00, 0x00, 0x00
1391 };
1392
1393 Packet *p = SCMalloc(SIZE_OF_PACKET);
1394 if (unlikely(p == NULL))
1395 return 0;
1396 IPV6Hdr ip6h;
1397 ThreadVars tv;
1398 DecodeThreadVars dtv;
1399
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));
1404
1405 FlowInitConfig(FLOW_QUIET);
1406 DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6), NULL);
1407
1408 if (!ENGINE_ISSET_EVENT(p, ICMPV6_UNKNOWN_CODE)) {
1409 SCLogDebug("ICMPv6 Error: Unknown code event is not set");
1410 retval = 0;
1411 goto end;
1412 }
1413
1414 retval = 1;
1415 end:
1416 PACKET_RECYCLE(p);
1417 FlowShutdown();
1418 SCFree(p);
1419 return retval;
1420 }
1421
1422 static int ICMPV6NeighbourAdvertTestKnownCode(void)
1423 {
1424 int retval = 0;
1425
1426 static uint8_t raw_ipv6[] = {
1427 0x60, 0x00, 0x00, 0x00, 0x00, 0x08, 0x3a, 0xff,
1428 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1429 0x02, 0x24, 0x8c, 0xff, 0xfe, 0x0e, 0x31, 0x54,
1430 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1431 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
1432 0x88, 0x00, 0xbb, 0xb0, 0x00, 0x00, 0x00, 0x00
1433 };
1434
1435 Packet *p = SCMalloc(SIZE_OF_PACKET);
1436 if (unlikely(p == NULL))
1437 return 0;
1438 IPV6Hdr ip6h;
1439 ThreadVars tv;
1440 DecodeThreadVars dtv;
1441
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));
1446
1447 FlowInitConfig(FLOW_QUIET);
1448 DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6), NULL);
1449
1450 if (ENGINE_ISSET_EVENT(p, ICMPV6_UNKNOWN_CODE)) {
1451 SCLogDebug("ICMPv6 Error: Unknown code event is set");
1452 retval = 0;
1453 goto end;
1454 }
1455
1456 retval = 1;
1457 end:
1458 PACKET_RECYCLE(p);
1459 FlowShutdown();
1460 SCFree(p);
1461 return retval;
1462 }
1463
1464 static int ICMPV6NeighbourAdvertTestUnknownCode(void)
1465 {
1466 int retval = 0;
1467
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
1475 };
1476
1477 Packet *p = SCMalloc(SIZE_OF_PACKET);
1478 if (unlikely(p == NULL))
1479 return 0;
1480 IPV6Hdr ip6h;
1481 ThreadVars tv;
1482 DecodeThreadVars dtv;
1483
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));
1488
1489 FlowInitConfig(FLOW_QUIET);
1490 DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6), NULL);
1491
1492 if (!ENGINE_ISSET_EVENT(p, ICMPV6_UNKNOWN_CODE)) {
1493 SCLogDebug("ICMPv6 Error: Unknown code event is not set");
1494 retval = 0;
1495 goto end;
1496 }
1497
1498 retval = 1;
1499 end:
1500 PACKET_RECYCLE(p);
1501 FlowShutdown();
1502 SCFree(p);
1503 return retval;
1504 }
1505
1506 static int ICMPV6RedirectTestKnownCode(void)
1507 {
1508 int retval = 0;
1509
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
1517 };
1518
1519 Packet *p = SCMalloc(SIZE_OF_PACKET);
1520 if (unlikely(p == NULL))
1521 return 0;
1522 IPV6Hdr ip6h;
1523 ThreadVars tv;
1524 DecodeThreadVars dtv;
1525
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));
1530
1531 FlowInitConfig(FLOW_QUIET);
1532 DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6), NULL);
1533
1534 if (ENGINE_ISSET_EVENT(p, ICMPV6_UNKNOWN_CODE)) {
1535 SCLogDebug("ICMPv6 Error: Unknown code event is set");
1536 retval = 0;
1537 goto end;
1538 }
1539
1540 retval = 1;
1541 end:
1542 PACKET_RECYCLE(p);
1543 FlowShutdown();
1544 SCFree(p);
1545 return retval;
1546 }
1547
1548 static int ICMPV6RedirectTestUnknownCode(void)
1549 {
1550 int retval = 0;
1551
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
1559 };
1560
1561 Packet *p = SCMalloc(SIZE_OF_PACKET);
1562 if (unlikely(p == NULL))
1563 return 0;
1564 IPV6Hdr ip6h;
1565 ThreadVars tv;
1566 DecodeThreadVars dtv;
1567
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));
1572
1573 FlowInitConfig(FLOW_QUIET);
1574 DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6), NULL);
1575
1576 if (!ENGINE_ISSET_EVENT(p, ICMPV6_UNKNOWN_CODE)) {
1577 SCLogDebug("ICMPv6 Error: Unknown code event is not set");
1578 retval = 0;
1579 goto end;
1580 }
1581
1582 retval = 1;
1583 end:
1584 PACKET_RECYCLE(p);
1585 FlowShutdown();
1586 SCFree(p);
1587 return retval;
1588 }
1589
1590 #endif /* UNITTESTS */
1591 /**
1592 * \brief Registers ICMPV6 unit tests
1593 * \todo More ICMPv6 tests
1594 */
1595 void DecodeICMPV6RegisterTests(void)
1596 {
1597 #ifdef UNITTESTS
1598 UtRegisterTest("ICMPV6CalculateValidChecksumtest01", ICMPV6CalculateValidChecksumtest01, 1);
1599 UtRegisterTest("ICMPV6CalculateInValidChecksumtest02", ICMPV6CalculateInvalidChecksumtest02, 0);
1600
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);
1607
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);
1614
1615 UtRegisterTest("ICMPV6PayloadTest01", ICMPV6PayloadTest01, 1);
1616
1617 UtRegisterTest("ICMPV6RouterSolicitTestKnownCode",
1618 ICMPV6RouterSolicitTestKnownCode, 1);
1619 UtRegisterTest("ICMPV6RouterSolicitTestUnknownCode",
1620 ICMPV6RouterSolicitTestUnknownCode, 1);
1621 UtRegisterTest("ICMPV6RouterAdvertTestKnownCode",
1622 ICMPV6RouterAdvertTestKnownCode, 1);
1623 UtRegisterTest("ICMPV6RouterAdvertTestUnknownCode",
1624 ICMPV6RouterAdvertTestUnknownCode, 1);
1625
1626 UtRegisterTest("ICMPV6NeighbourSolicitTestKnownCode",
1627 ICMPV6NeighbourSolicitTestKnownCode, 1);
1628 UtRegisterTest("ICMPV6NeighbourSolicitTestUnknownCode",
1629 ICMPV6NeighbourSolicitTestUnknownCode, 1);
1630 UtRegisterTest("ICMPV6NeighbourAdvertTestKnownCode",
1631 ICMPV6NeighbourAdvertTestKnownCode, 1);
1632 UtRegisterTest("ICMPV6NeighbourAdvertTestUnknownCode",
1633 ICMPV6NeighbourAdvertTestUnknownCode, 1);
1634
1635 UtRegisterTest("ICMPV6RedirectTestKnownCode", ICMPV6RedirectTestKnownCode, 1);
1636 UtRegisterTest("ICMPV6RedirectTestUnknownCode",
1637 ICMPV6RedirectTestUnknownCode, 1);
1638 #endif /* UNITTESTS */
1639 }
1640 /**
1641 * @}
1642 */