tprintf: fix va_list arg exhaustion
[netsniff-ng-old.git] / src / proto_icmpv6.c
blobb26028609ccc635309b5ecd2b51cb15cdb2811b3
1 /*
2 * netsniff-ng - the packet sniffing beast
3 * Copyright 2012 Markus Amend <markus@netsniff-ng.org>
4 * Subject to the GPL, version 2.
6 * ICMPv6 described in RFC4443, RFC2710, RFC4861, RFC2894,
7 * RFC4620, RFC3122, RFC3810, RFC3775, RFC3971, RFC4065
8 * RFC4286
9 * Look also for an good overview:
10 * http://www.iana.org/assignments/icmpv6-parameters
13 #include <stdio.h>
14 #include <stdint.h>
15 #include <netinet/in.h>
16 #include <arpa/inet.h>
17 #include <asm/byteorder.h>
19 #include "proto.h"
20 #include "protos.h"
21 #include "dissector_eth.h"
22 #include "pkt_buff.h"
23 #include "built_in.h"
25 #define icmpv6_code_range_valid(code, sarr) ((code) < array_size((sarr)))
27 struct icmpv6_general_hdr {
28 uint8_t h_type;
29 uint8_t h_code;
30 uint16_t h_chksum;
31 } __packed;
33 /* for type 0x01 and 0x03 */
34 struct icmpv6_type_1_3 {
35 uint32_t unused;
36 uint8_t invoking_pkt[0];
37 } __packed;
39 struct icmpv6_type_2 {
40 uint32_t MTU;
41 uint8_t invoking_pkt[0];
42 } __packed;
44 struct icmpv6_type_4 {
45 uint32_t pointer;
46 uint8_t invoking_pkt[0];
47 } __packed;
49 struct icmpv6_type_128_129 {
50 uint16_t id;
51 uint16_t sn;
52 uint8_t data[0];
53 } __packed;
55 /* MLDv1 msg */
56 struct icmpv6_type_130_131_132 {
57 uint16_t maxrespdel;
58 uint16_t res;
59 struct in6_addr ipv6_addr;
60 } __packed;
61 /* end MLDv1 msg */
63 struct icmpv6_type_130_mldv2 {
64 uint8_t resv_S_QRV;
65 uint8_t QQIC;
66 uint16_t nr_src;
67 struct in6_addr ipv6_addr[0];
68 } __packed;
70 /* Neighbor Discovery msg */
71 struct icmpv6_type_133_141_142 {
72 uint32_t res;
73 uint8_t ops[0];
74 } __packed;
76 struct icmpv6_type_134 {
77 uint8_t cur_hop_limit;
78 uint8_t m_o_res;
79 uint16_t router_lifetime;
80 uint32_t reachable_time;
81 uint32_t retrans_timer;
82 uint8_t ops[0];
83 } __packed;
85 struct icmpv6_type_135 {
86 uint32_t res;
87 struct in6_addr ipv6_addr;
88 uint8_t ops[0];
89 } __packed;
91 struct icmpv6_type_136 {
92 uint32_t r_s_o_res;
93 struct in6_addr ipv6_addr;
94 uint8_t ops[0];
95 } __packed;
97 struct icmpv6_type_137 {
98 uint32_t res;
99 struct in6_addr ipv6_targ_addr;
100 struct in6_addr ipv6_dest_addr;
101 uint8_t ops[0];
102 } __packed;
104 struct icmpv6_neighb_disc_ops_general {
105 uint8_t type;
106 uint8_t len;
107 uint8_t ops[0];
108 } __packed;
110 struct icmpv6_neighb_disc_ops_type_1_2 {
111 uint8_t link_lay_addr[0];
112 } __packed;
114 struct icmpv6_neighb_disc_ops_type_3 {
115 uint8_t prefix_len;
116 uint8_t l_a_res1;
117 uint32_t valid_lifetime;
118 uint32_t preferred_lifetime;
119 uint32_t res2;
120 struct in6_addr prefix;
121 } __packed;
123 struct icmpv6_neighb_disc_ops_type_4 {
124 uint16_t res1;
125 uint32_t res2;
126 uint8_t ip_hdr_data[0];
127 } __packed;
129 struct icmpv6_neighb_disc_ops_type_5 {
130 uint16_t res1;
131 uint32_t MTU;
132 } __packed;
134 struct icmpv6_neighb_disc_ops_type_9_10 {
135 uint16_t res1;
136 uint32_t res2;
137 uint8_t ip_hdr_data[0];
138 } __packed;
140 struct icmpv6_neighb_disc_ops_type_15 {
141 uint8_t name_type;
142 size_t pad_len;
143 char name[0];
144 uint8_t pad[0];
145 } __packed;
147 struct icmpv6_neighb_disc_ops_type_16 {
148 uint8_t cert_type;
149 uint8_t res;
150 uint8_t cert[0];
151 uint8_t pad[0];
152 } __packed;
154 struct icmpv6_neighb_disc_ops_type_17 {
155 uint8_t opt_code;
156 uint8_t prefix_len;
157 uint8_t data[0];
158 } __packed;
160 struct icmpv6_neighb_disc_ops_type_17_1 {
161 uint32_t res;
162 struct in6_addr ipv6_addr;
163 } __packed;
165 struct icmpv6_neighb_disc_ops_type_17_2 {
166 struct in6_addr ipv6_addr;
167 } __packed;
169 struct icmpv6_neighb_disc_ops_type_19 {
170 uint8_t opt_code;
171 uint8_t lla[0];
172 } __packed;
173 /* end Neighbor Discovery msg */
175 struct icmpv6_type_138 {
176 uint32_t seq_nr;
177 uint8_t seg_nr;
178 uint8_t flags;
179 uint16_t maxdelay;
180 uint32_t res;
181 } __packed;
183 /* Node Information Queries */
184 struct icmpv6_type_139_140 {
185 uint16_t qtype;
186 uint16_t flags;
187 uint64_t nonce;
188 uint8_t data[0];
189 } __packed;
190 /* end Node Information Queries */
192 /* MLDv2 report */
193 struct icmpv6_type_143 {
194 uint16_t res;
195 uint16_t nr_rec;
196 uint8_t addr_rec[0];
197 } __packed;
199 struct icmpv6_mldv2_addr_rec {
200 uint8_t rec_type;
201 uint8_t aux_data_len;
202 uint16_t nr_src;
203 struct in6_addr multic_addr;
204 struct in6_addr src_addr[0];
205 } __packed;
206 /* end MLDv2 report */
208 /* ICMP Mobility Support */
209 struct icmpv6_type_144_146 {
210 uint16_t id;
211 uint16_t res;
212 } __packed;
214 struct icmpv6_type_145 {
215 uint16_t id;
216 uint16_t res;
217 struct in6_addr home_agent_addr[0];
218 } __packed;
220 struct icmpv6_type_147 {
221 uint16_t id;
222 uint16_t m_o_res;
223 uint8_t ops[0];
224 } __packed;
225 /* end ICMP Mobility Support */
227 /* SEcure Neighbor Discovery */
228 struct icmpv6_type_148 {
229 uint16_t id;
230 uint16_t comp;
231 uint8_t ops[0];
232 } __packed;
234 struct icmpv6_type_149 {
235 uint16_t id;
236 uint16_t all_comp;
237 uint16_t comp;
238 uint16_t res;
239 uint8_t ops[0];
240 } __packed;
241 /* end SEcure Neighbor Discovery */
243 struct icmpv6_type_150 {
244 union {
245 uint32_t subtype_res;
246 struct {
247 #if defined(__LITTLE_ENDIAN_BITFIELD)
248 uint32_t res :24,
249 subtype :8;
250 #elif defined(__BIG_ENDIAN_BITFIELD)
251 uint32_t subtype :8,
252 res :24;
253 #else
254 # error "Please fix <asm/byteorder.h>"
255 #endif
258 uint8_t ops[0];
259 } __packed;
261 /* Multicast Router Discovery */
262 struct icmpv6_type_151 {
263 uint16_t query_intv;
264 uint16_t rob_var;
265 } __packed;
267 struct icmpv6_type_152 {
268 uint8_t null[0];
269 } __packed;
271 struct icmpv6_type_153 {
272 uint8_t null[0];
273 } __packed;
274 /* end Multicast Router Discovery */
276 struct icmpv6_type_154 {
277 uint8_t subtype;
278 uint8_t res;
279 uint16_t id;
280 uint8_t ops[0];
281 } __packed;
283 static int8_t print_ipv6_addr_list(struct pkt_buff *pkt, uint8_t nr_addr)
285 char address[INET6_ADDRSTRLEN];
286 struct in6_addr *addr;
288 while (nr_addr--) {
289 addr = (struct in6_addr *) pkt_pull(pkt, sizeof(*addr));
290 if (addr == NULL)
291 return 0;
293 tprintf("\n\t Address: %s",
294 inet_ntop(AF_INET6, addr, address,
295 sizeof(address)));
298 return 1;
301 static char *icmpv6_mcast_rec_types[] = {
302 "MODE_IS_INCLUDE",
303 "MODE_IS_EXCLUDE",
304 "CHANGE_TO_INCLUDE_MODE",
305 "CHANGE_TO_EXCLUDE_MODE",
306 "ALLOW_NEW_SOURCES",
307 "BLOCK_OLD_SOURCES",
310 static int8_t dissect_icmpv6_mcast_rec(struct pkt_buff *pkt,
311 uint16_t nr_rec)
313 uint16_t nr_src, aux_data_len_bytes;
314 struct icmpv6_mldv2_addr_rec *addr_rec;
316 while (nr_rec--) {
317 addr_rec = (struct icmpv6_mldv2_addr_rec *)
318 pkt_pull(pkt,sizeof(*addr_rec));
319 if (addr_rec == NULL)
320 return 0;
321 aux_data_len_bytes = addr_rec->aux_data_len * 4;
322 nr_src = ntohs(addr_rec->nr_src);
324 tprintf(", Rec Type %s (%u)",
325 icmpv6_code_range_valid(addr_rec->rec_type - 1,
326 icmpv6_mcast_rec_types) ?
327 icmpv6_mcast_rec_types[addr_rec->rec_type - 1]
328 : "Unknown", addr_rec->rec_type);
329 if (aux_data_len_bytes > pkt_len(pkt)) {
330 tprintf(", Aux Data Len (%u, %u bytes) %s",
331 addr_rec->aux_data_len,
332 aux_data_len_bytes,
333 colorize_start_full(black, red) "invalid"
334 colorize_end());
335 return 0;
337 tprintf(", Aux Data Len (%u, %u bytes)",addr_rec->aux_data_len,
338 aux_data_len_bytes);
339 tprintf(", Nr. of Sources (%u)",nr_src);
341 if(!print_ipv6_addr_list(pkt, nr_src))
342 return 0;
344 tprintf(", Aux Data: ");
345 while (aux_data_len_bytes--) {
346 tprintf("%x", *pkt_pull(pkt,1));
350 return 1;
353 static int8_t dissect_neighb_disc_ops_1(struct pkt_buff *pkt,
354 ssize_t len)
356 struct icmpv6_neighb_disc_ops_type_1_2 *icmp_neighb_disc_1;
358 icmp_neighb_disc_1 = (struct icmpv6_neighb_disc_ops_type_1_2 *)
359 pkt_pull(pkt,sizeof(*icmp_neighb_disc_1));
360 if (icmp_neighb_disc_1 == NULL)
361 return 0;
362 len -= sizeof(*icmp_neighb_disc_1);
363 if (len < 0)
364 return 0;
366 tprintf("Address 0x");
368 while(len--){
369 tprintf("%x", *pkt_pull(pkt,1));
372 return 1;
375 static int8_t dissect_neighb_disc_ops_2(struct pkt_buff *pkt,
376 ssize_t len)
378 return dissect_neighb_disc_ops_1(pkt, len);
381 static int8_t dissect_neighb_disc_ops_3(struct pkt_buff *pkt,
382 ssize_t len)
384 char address[INET6_ADDRSTRLEN];
385 struct icmpv6_neighb_disc_ops_type_3 *icmp_neighb_disc_3;
387 icmp_neighb_disc_3 = (struct icmpv6_neighb_disc_ops_type_3 *)
388 pkt_pull(pkt,sizeof(*icmp_neighb_disc_3));
389 if (icmp_neighb_disc_3 == NULL)
390 return 0;
391 len -= sizeof(*icmp_neighb_disc_3);
392 if (len < 0)
393 return 0;
395 tprintf("Prefix Len (%u) ",icmp_neighb_disc_3->prefix_len);
396 tprintf("L (%u) A (%u) Res1 (0x%x) ",icmp_neighb_disc_3->l_a_res1 >> 7,
397 (icmp_neighb_disc_3->l_a_res1 >> 7) & 0x1,
398 icmp_neighb_disc_3->l_a_res1 & 0x3F);
399 tprintf("Valid Lifetime (%us) ",
400 ntohl(icmp_neighb_disc_3->valid_lifetime));
401 tprintf("Preferred Lifetime (%us) ",
402 ntohl(icmp_neighb_disc_3->preferred_lifetime));
403 tprintf("Reserved2 (0x%x) ",
404 ntohl(icmp_neighb_disc_3->res2));
405 tprintf("Prefix: %s ",
406 inet_ntop(AF_INET6,&icmp_neighb_disc_3->prefix,
407 address, sizeof(address)));
409 return 1;
412 static int8_t dissect_neighb_disc_ops_4(struct pkt_buff *pkt,
413 ssize_t len)
415 struct icmpv6_neighb_disc_ops_type_4 *icmp_neighb_disc_4;
417 icmp_neighb_disc_4 = (struct icmpv6_neighb_disc_ops_type_4 *)
418 pkt_pull(pkt,sizeof(*icmp_neighb_disc_4));
419 if (icmp_neighb_disc_4 == NULL)
420 return 0;
421 len -= sizeof(*icmp_neighb_disc_4);
422 if (len < 0)
423 return 0;
425 tprintf("Reserved 1 (0x%x) ", ntohs(icmp_neighb_disc_4->res1));
426 tprintf("Reserved 2 (0x%x) ", ntohl(icmp_neighb_disc_4->res2));
427 tprintf("IP header + data ");
429 while (len--) {
430 tprintf("%x", *pkt_pull(pkt,1));
433 return 1;
436 static int8_t dissect_neighb_disc_ops_5(struct pkt_buff *pkt,
437 ssize_t len)
439 struct icmpv6_neighb_disc_ops_type_5 *icmp_neighb_disc_5;
441 icmp_neighb_disc_5 = (struct icmpv6_neighb_disc_ops_type_5 *)
442 pkt_pull(pkt,sizeof(*icmp_neighb_disc_5));
443 if (icmp_neighb_disc_5 == NULL)
444 return 0;
445 len -= sizeof(*icmp_neighb_disc_5);
446 if (len < 0)
447 return 0;
449 tprintf("Reserved (0x%x) ", ntohs(icmp_neighb_disc_5->res1));
450 tprintf("MTU (%u)", ntohl(icmp_neighb_disc_5->MTU));
452 return 1;
455 static int8_t dissect_neighb_disc_ops_9(struct pkt_buff *pkt,
456 ssize_t len)
458 struct icmpv6_neighb_disc_ops_type_9_10 *icmp_neighb_disc_9;
460 icmp_neighb_disc_9 = (struct icmpv6_neighb_disc_ops_type_9_10 *)
461 pkt_pull(pkt,sizeof(*icmp_neighb_disc_9));
462 if (icmp_neighb_disc_9 == NULL)
463 return 0;
464 len -= sizeof(*icmp_neighb_disc_9);
465 if (len < 0)
466 return 0;
468 tprintf("Reserved 1 (0x%x) ", ntohs(icmp_neighb_disc_9->res1));
469 tprintf("Reserved 2 (0x%x) ", ntohl(icmp_neighb_disc_9->res2));
471 return print_ipv6_addr_list(pkt, len / sizeof(struct in6_addr));
474 static int8_t dissect_neighb_disc_ops_10(struct pkt_buff *pkt,
475 ssize_t len)
477 return dissect_neighb_disc_ops_9(pkt, len);
480 static char *icmpv6_neighb_disc_ops_15_name[] = {
481 "DER Encoded X.501 Name",
482 "FQDN",
485 static int8_t dissect_neighb_disc_ops_15(struct pkt_buff *pkt,
486 ssize_t len)
488 size_t pad_len;
489 ssize_t name_len;
490 struct icmpv6_neighb_disc_ops_type_15 *icmp_neighb_disc_15;
492 icmp_neighb_disc_15 = (struct icmpv6_neighb_disc_ops_type_15 *)
493 pkt_pull(pkt,sizeof(*icmp_neighb_disc_15));
494 if (icmp_neighb_disc_15 == NULL)
495 return 0;
496 len -= sizeof(*icmp_neighb_disc_15);
497 if (len < 0)
498 return 0;
499 pad_len = icmp_neighb_disc_15->pad_len;
501 tprintf("Name Type %s (%u) ",
502 icmpv6_code_range_valid(icmp_neighb_disc_15->name_type - 1,
503 icmpv6_neighb_disc_ops_15_name) ?
504 icmpv6_neighb_disc_ops_15_name[
505 icmp_neighb_disc_15->name_type - 1] : "Unknown",
506 icmp_neighb_disc_15->name_type);
507 if (pad_len > len) {
508 tprintf("Pad Len (%u, invalid)\n%s", pad_len,
509 colorize_start_full(black, red)
510 "Skip Option" colorize_end());
511 pkt_pull(pkt, len);
512 return 1;
514 else
515 tprintf("Pad Len (%u) ", pad_len);
517 name_len = len - pad_len;
519 tprintf("Name (");
520 while (name_len--) {
521 tprintf("%c", *pkt_pull(pkt,1));
523 tprintf(") ");
525 tprintf("Padding (");
527 while (pad_len--) {
528 tprintf("%x", *pkt_pull(pkt,1));
530 tprintf(")");
532 return 1;
535 static char *icmpv6_neighb_disc_ops_16_cert[] = {
536 "X.509v3 Certificate",
539 static int8_t dissect_neighb_disc_ops_16(struct pkt_buff *pkt,
540 ssize_t len)
542 struct icmpv6_neighb_disc_ops_type_16 *icmp_neighb_disc_16;
544 icmp_neighb_disc_16 = (struct icmpv6_neighb_disc_ops_type_16 *)
545 pkt_pull(pkt,sizeof(*icmp_neighb_disc_16));
546 if (icmp_neighb_disc_16 == NULL)
547 return 0;
548 len -= sizeof(*icmp_neighb_disc_16);
549 if (len < 0)
550 return 0;
552 tprintf("Cert Type %s (%u) ",
553 icmpv6_code_range_valid(icmp_neighb_disc_16->cert_type - 1,
554 icmpv6_neighb_disc_ops_16_cert) ?
555 icmpv6_neighb_disc_ops_16_cert[
556 icmp_neighb_disc_16->cert_type - 1] : "Unknown",
557 icmp_neighb_disc_16->cert_type);
558 tprintf("Res (0x%x) ", icmp_neighb_disc_16->res);
560 tprintf("Certificate + Padding (");
561 while (len--) {
562 tprintf("%x", *pkt_pull(pkt,1));
564 tprintf(") ");
566 return 1;
569 static char *icmpv6_neighb_disc_ops_17_codes[] = {
570 "Old Care-of Address",
571 "New Care-of Address",
572 "NAR's IP address",
573 "NAR's Prefix",
576 static int8_t dissect_neighb_disc_ops_17(struct pkt_buff *pkt,
577 ssize_t len)
579 char address[INET6_ADDRSTRLEN];
580 struct icmpv6_neighb_disc_ops_type_17 *icmp_neighb_disc_17;
582 icmp_neighb_disc_17 = (struct icmpv6_neighb_disc_ops_type_17 *)
583 pkt_pull(pkt,sizeof(*icmp_neighb_disc_17));
584 if (icmp_neighb_disc_17 == NULL)
585 return 0;
586 len -= sizeof(*icmp_neighb_disc_17);
587 if (len < 0)
588 return 0;
590 tprintf("Opt Code %s (%u) ",
591 icmpv6_code_range_valid(icmp_neighb_disc_17->opt_code - 1,
592 icmpv6_neighb_disc_ops_17_codes) ?
593 icmpv6_neighb_disc_ops_17_codes[
594 icmp_neighb_disc_17->opt_code - 1] : "Unknown",
595 icmp_neighb_disc_17->opt_code);
596 tprintf("Prefix Len (%u) ", icmp_neighb_disc_17->prefix_len);
598 if (len == sizeof(struct icmpv6_neighb_disc_ops_type_17_1)) {
599 struct icmpv6_neighb_disc_ops_type_17_1
600 *icmp_neighb_disc_17_1;
602 icmp_neighb_disc_17_1 =
603 (struct icmpv6_neighb_disc_ops_type_17_1 *)
604 pkt_pull(pkt,sizeof(*icmp_neighb_disc_17_1));
605 if (icmp_neighb_disc_17_1 == NULL)
606 return 0;
607 len -= sizeof(*icmp_neighb_disc_17_1);
608 if (len < 0)
609 return 0;
611 tprintf("Res (0x%x) ",icmp_neighb_disc_17_1->res);
612 tprintf("Addr: %s ",
613 inet_ntop(AF_INET6,&icmp_neighb_disc_17_1->ipv6_addr,
614 address, sizeof(address)));
616 else if (len == sizeof(struct icmpv6_neighb_disc_ops_type_17_2)) {
617 struct icmpv6_neighb_disc_ops_type_17_2
618 *icmp_neighb_disc_17_2;
620 icmp_neighb_disc_17_2 =
621 (struct icmpv6_neighb_disc_ops_type_17_2 *)
622 pkt_pull(pkt,sizeof(*icmp_neighb_disc_17_2));
623 if (icmp_neighb_disc_17_2 == NULL)
624 return 0;
625 len -= sizeof(*icmp_neighb_disc_17_2);
626 if (len < 0)
627 return 0;
629 tprintf("Addr: %s ",
630 inet_ntop(AF_INET6,&icmp_neighb_disc_17_2->ipv6_addr,
631 address, sizeof(address)));
633 else {
634 tprintf("%s (", colorize_start_full(black, red)
635 "Error Wrong Length. Skip Option" colorize_end());
636 while (len--) {
637 tprintf("%x", *pkt_pull(pkt,1));
639 tprintf(") ");
642 return 1;
645 static char *icmpv6_neighb_disc_ops_19_codes[] = {
646 "Wildcard requesting resolution for all nearby access points",
647 "Link-Layer Address of the New Access Point",
648 "Link-Layer Address of the MN",
649 "Link-Layer Address of the NAR",
650 "Link-Layer Address of the source of RtSolPr or PrRtAdv \
651 message",
652 "The access point identified by the LLA belongs to the \
653 current interface of the router",
654 "No prefix information available for the access point \
655 identified by the LLA",
656 "No fast handover support available for the access point \
657 identified by the LLA",
660 static int8_t dissect_neighb_disc_ops_19(struct pkt_buff *pkt,
661 ssize_t len)
663 struct icmpv6_neighb_disc_ops_type_19 *icmp_neighb_disc_19;
665 icmp_neighb_disc_19 = (struct icmpv6_neighb_disc_ops_type_19 *)
666 pkt_pull(pkt,sizeof(*icmp_neighb_disc_19));
667 if (icmp_neighb_disc_19 == NULL)
668 return 0;
669 len -= sizeof(*icmp_neighb_disc_19);
670 if (len < 0)
671 return 0;
673 tprintf("Opt Code %s (%u) ",
674 icmpv6_code_range_valid(icmp_neighb_disc_19->opt_code,
675 icmpv6_neighb_disc_ops_19_codes) ?
676 icmpv6_neighb_disc_ops_19_codes[
677 icmp_neighb_disc_19->opt_code] : "Unknown",
678 icmp_neighb_disc_19->opt_code);
680 tprintf("LLA (");
681 while(len--){
682 tprintf("%x", *pkt_pull(pkt,1));
684 tprintf(") ");
686 return 1;
689 static inline char *icmpv6_neighb_disc_ops(uint8_t code) {
690 switch (code) {
691 case 1:
692 return "Source Link-Layer Address";
693 case 2:
694 return "Target Link-Layer Address";
695 case 3:
696 return "Prefix Information";
697 case 4:
698 return "Redirected Header";
699 case 5:
700 return "MTU";
701 case 6:
702 return "NBMA Shortcut Limit Option";
703 case 7:
704 return "Advertisement Interval Option";
705 case 8:
706 return "Home Agent Information Option";
707 case 9:
708 return "Source Address List";
709 case 10:
710 return "Target Address List";
711 case 11:
712 return "CGA option";
713 case 12:
714 return "RSA Signature option";
715 case 13:
716 return "Timestamp option";
717 case 14:
718 return "Nonce option";
719 case 15:
720 return "Trust Anchor option";
721 case 16:
722 return "Certificate option";
723 case 17:
724 return "IP Address/Prefix Option";
725 case 18:
726 return "New Router Prefix Information Option";
727 case 19:
728 return "Link-layer Address Option";
729 case 20:
730 return "Neighbor Advertisement Acknowledgment Option";
732 case 23:
733 return "Prefix Information";
734 case 24:
735 return "Redirected Header";
736 case 25:
737 return "MTU";
738 case 26:
739 return "NBMA Shortcut Limit Option";
740 case 27:
741 return "Advertisement Interval Option";
742 case 28:
743 return "Home Agent Information Option";
744 case 29:
745 return "Source Address List";
746 case 30:
747 return "Target Address List";
748 case 31:
749 return "DNS Search List Option";
750 case 32:
751 return "Proxy Signature (PS)";
753 case 138:
754 return "CARD Request option";
755 case 139:
756 return "CARD Reply option";
758 case 253:
759 return "RFC3692-style Experiment 1";
760 case 254:
761 return "RFC3692-style Experiment 2";
764 return NULL;
767 static int8_t dissect_neighb_disc_ops(struct pkt_buff *pkt)
769 size_t pad_bytes;
770 uint16_t ops_total_len;
771 ssize_t ops_payl_len;
772 struct icmpv6_neighb_disc_ops_general *icmp_neighb_disc;
774 while(pkt_len(pkt)) {
775 icmp_neighb_disc = (struct icmpv6_neighb_disc_ops_general *)
776 pkt_pull(pkt,sizeof(*icmp_neighb_disc));
777 if (icmp_neighb_disc == NULL)
778 return 0;
780 ops_total_len = icmp_neighb_disc->len * 8;
781 pad_bytes = (size_t) (ops_total_len % 8);
782 ops_payl_len = ops_total_len - sizeof(*icmp_neighb_disc) -
783 pad_bytes;
785 tprintf("\n\tOption %s (%u) ",
786 icmpv6_neighb_disc_ops(icmp_neighb_disc->type) ?
787 icmpv6_neighb_disc_ops(icmp_neighb_disc->type)
788 : "Type Unknown", icmp_neighb_disc->type);
789 if (ops_payl_len > pkt_len(pkt) || ops_payl_len < 0) {
790 tprintf("Length (%u, %u bytes, %s%s%s) ",
791 icmp_neighb_disc->len,
792 ops_total_len,
793 colorize_start_full(black, red),
794 "invalid", colorize_end());
795 return 0;
798 tprintf("Length (%u, %u bytes) ",icmp_neighb_disc->len,
799 ops_total_len);
801 switch (icmp_neighb_disc->type) {
802 case 1:
803 if (!dissect_neighb_disc_ops_1(pkt, ops_payl_len))
804 return 0;
805 break;
806 case 2:
807 if (!dissect_neighb_disc_ops_2(pkt, ops_payl_len))
808 return 0;
809 break;
810 case 3:
811 if (!dissect_neighb_disc_ops_3(pkt, ops_payl_len))
812 return 0;
813 break;
814 case 4:
815 if (!dissect_neighb_disc_ops_4(pkt, ops_payl_len))
816 return 0;
817 break;
818 case 5:
819 if (!dissect_neighb_disc_ops_5(pkt, ops_payl_len))
820 return 0;
821 break;
822 /* Type 9 and 10 defined in
823 * http://tools.ietf.org/html/rfc3122#section-3.1
825 case 9:
826 if (!dissect_neighb_disc_ops_9(pkt, ops_payl_len))
827 return 0;
828 break;
829 case 10:
830 if (!dissect_neighb_disc_ops_10(pkt, ops_payl_len))
831 return 0;
832 break;
833 /* Type 15 and 16 defined in
834 * http://tools.ietf.org/html/rfc3971#section-6.4.3
835 * http://tools.ietf.org/html/rfc3971#section-6.4.4
837 case 15:
838 if (!dissect_neighb_disc_ops_15(pkt, ops_payl_len))
839 return 0;
840 break;
841 case 16:
842 if (!dissect_neighb_disc_ops_16(pkt, ops_payl_len))
843 return 0;
844 break;
845 /* Type 17 and 19 defined in
846 * http://tools.ietf.org/html/rfc5568#section-6.4
848 case 17:
849 if (!dissect_neighb_disc_ops_17(pkt, ops_payl_len))
850 return 0;
851 break;
852 case 19:
853 if (!dissect_neighb_disc_ops_19(pkt, ops_payl_len))
854 return 0;
855 break;
856 default:
857 pkt_pull(pkt, ops_payl_len);
860 /* Skip Padding Bytes */
861 if (pad_bytes > pkt_len(pkt)) {
862 tprintf(" %s",colorize_start_full(black, red)
863 "Invalid Padding" colorize_end());
864 return 0;
866 pkt_pull(pkt, pad_bytes);
869 return 1;
872 static char *icmpv6_type_1_codes[] = {
873 "No route to destination",
874 "Communication with destination administratively prohibited",
875 "Beyond scope of source address",
876 "Address unreachable",
877 "Port unreachable",
878 "Source address failed ingress/egress policy",
879 "Reject route to destination",
880 "Error in Source Routing Header",
883 static int8_t dissect_icmpv6_type1(struct pkt_buff *pkt)
885 struct icmpv6_type_1_3 *icmp_1;
887 icmp_1 = (struct icmpv6_type_1_3 *) pkt_pull(pkt,sizeof(*icmp_1));
888 if (icmp_1 == NULL)
889 return 0;
891 tprintf(", Unused (0x%x)",ntohl(icmp_1->unused));
892 tprintf(" Payload include as much of invoking packet");
894 return 1;
897 static int8_t dissect_icmpv6_type2(struct pkt_buff *pkt)
899 struct icmpv6_type_2 *icmp_2;
901 icmp_2 = (struct icmpv6_type_2 *) pkt_pull(pkt,sizeof(*icmp_2));
902 if (icmp_2 == NULL)
903 return 0;
905 tprintf(", MTU (0x%x)",ntohl(icmp_2->MTU));
906 tprintf(" Payload include as much of invoking packet");
908 return 1;
911 static char *icmpv6_type_3_codes[] = {
912 "Hop limit exceeded in transit",
913 "Fragment reassembly time exceeded",
916 static int8_t dissect_icmpv6_type3(struct pkt_buff *pkt)
918 struct icmpv6_type_1_3 *icmp_3;
920 icmp_3 = (struct icmpv6_type_1_3 *) pkt_pull(pkt,sizeof(*icmp_3));
921 if (icmp_3 == NULL)
922 return 0;
924 tprintf(", Unused (0x%x)",ntohl(icmp_3->unused));
925 tprintf(" Payload include as much of invoking packet");
927 return 1;
930 static char *icmpv6_type_4_codes[] = {
931 "Erroneous header field encountered",
932 "Unrecognized Next Header type encountered",
933 "Unrecognized IPv6 option encountered",
936 static int8_t dissect_icmpv6_type4(struct pkt_buff *pkt)
938 struct icmpv6_type_4 *icmp_4;
940 icmp_4 = (struct icmpv6_type_4 *) pkt_pull(pkt,sizeof(*icmp_4));
941 if (icmp_4 == NULL)
942 return 0;
944 tprintf(", Pointer (0x%x)",ntohl(icmp_4->pointer));
945 tprintf(" Payload include as much of invoking packet");
947 return 1;
950 static int8_t dissect_icmpv6_type128(struct pkt_buff *pkt)
952 struct icmpv6_type_128_129 *icmp_128;
954 icmp_128 = (struct icmpv6_type_128_129 *)
955 pkt_pull(pkt,sizeof(*icmp_128));
956 if (icmp_128 == NULL)
957 return 0;
959 tprintf(", ID (0x%x)",ntohs(icmp_128->id));
960 tprintf(", Seq. Nr. (%u)",ntohs(icmp_128->sn));
961 tprintf(" Payload include Data");
963 return 1;
966 static int8_t dissect_icmpv6_type129(struct pkt_buff *pkt)
968 struct icmpv6_type_128_129 *icmp_129;
970 icmp_129 = (struct icmpv6_type_128_129 *)
971 pkt_pull(pkt,sizeof(*icmp_129));
972 if (icmp_129 == NULL)
973 return 0;
975 tprintf(", ID (0x%x)",ntohs(icmp_129->id));
976 tprintf(", Seq. Nr. (%u)",ntohs(icmp_129->sn));
977 tprintf(" Payload include Data");
979 return 1;
982 static int8_t dissect_icmpv6_type130(struct pkt_buff *pkt)
984 char address[INET6_ADDRSTRLEN];
985 uint16_t nr_src, maxrespdel;
986 uint8_t switch_mldv2 = 0;
987 struct icmpv6_type_130_131_132 *icmp_130;
989 icmp_130 = (struct icmpv6_type_130_131_132 *)
990 pkt_pull(pkt,sizeof(*icmp_130));
991 if (icmp_130 == NULL)
992 return 0;
993 maxrespdel = ntohs(icmp_130->maxrespdel);
995 if(pkt_len(pkt) >= sizeof(struct icmpv6_type_130_mldv2))
996 switch_mldv2 = 1;
998 if(switch_mldv2)
999 tprintf(", MLDv2, Max Resp Delay (%ums)", maxrespdel >> 15 ?
1000 (((maxrespdel & 0xFFF) | 0x1000) <<
1001 (((maxrespdel >> 12) & 0x3) + 3)) : maxrespdel);
1002 else
1003 tprintf(", Max Resp Delay (%ums)",maxrespdel);
1004 tprintf(", Res (0x%x)",ntohs(icmp_130->res));
1005 tprintf(", Address: %s",
1006 inet_ntop(AF_INET6, &icmp_130->ipv6_addr,
1007 address, sizeof(address)));
1009 if(switch_mldv2) {
1010 struct icmpv6_type_130_mldv2 *icmp_130_mldv2;
1012 icmp_130_mldv2 = (struct icmpv6_type_130_mldv2 *)
1013 pkt_pull(pkt,sizeof(*icmp_130_mldv2));
1014 if (icmp_130_mldv2 == NULL)
1015 return 0;
1017 nr_src = ntohs(icmp_130_mldv2->nr_src);
1019 tprintf(", Resv (0x%x)",icmp_130_mldv2->resv_S_QRV >> 4);
1020 tprintf(", S (%u)",(icmp_130_mldv2->resv_S_QRV >> 3) & 0x1);
1021 tprintf(", QRV (0x%x)",icmp_130_mldv2->resv_S_QRV & 0x3);
1022 tprintf(", QQIC (%u)",icmp_130_mldv2->QQIC);
1023 tprintf(", Nr Src (0x%x)",nr_src);
1025 return print_ipv6_addr_list(pkt, nr_src);
1028 return 1;
1031 static int8_t dissect_icmpv6_type131(struct pkt_buff *pkt)
1033 char address[INET6_ADDRSTRLEN];
1034 struct icmpv6_type_130_131_132 *icmp_131;
1036 icmp_131 = (struct icmpv6_type_130_131_132 *)
1037 pkt_pull(pkt,sizeof(*icmp_131));
1038 if (icmp_131 == NULL)
1039 return 0;
1041 tprintf(", Max Resp Delay (%ums)",ntohs(icmp_131->maxrespdel));
1042 tprintf(", Res (0x%x)",ntohs(icmp_131->res));
1043 tprintf(", Address: %s",
1044 inet_ntop(AF_INET6, &icmp_131->ipv6_addr,
1045 address, sizeof(address)));
1047 return 1;
1050 static inline int8_t dissect_icmpv6_type132(struct pkt_buff *pkt)
1052 return dissect_icmpv6_type131(pkt);
1055 static int8_t dissect_icmpv6_type133(struct pkt_buff *pkt)
1057 struct icmpv6_type_133_141_142 *icmp_133;
1059 icmp_133 = (struct icmpv6_type_133_141_142 *)
1060 pkt_pull(pkt,sizeof(*icmp_133));
1061 if (icmp_133 == NULL)
1062 return 0;
1064 tprintf(", Reserved (0x%x)",ntohl(icmp_133->res));
1066 return dissect_neighb_disc_ops(pkt);
1069 static int8_t dissect_icmpv6_type134(struct pkt_buff *pkt)
1071 struct icmpv6_type_134 *icmp_134;
1073 icmp_134 = (struct icmpv6_type_134 *)
1074 pkt_pull(pkt,sizeof(*icmp_134));
1075 if (icmp_134 == NULL)
1076 return 0;
1078 tprintf(", Cur Hop Limit (%u)",icmp_134->cur_hop_limit);
1079 tprintf(", M (%u) O (%u)",icmp_134->m_o_res >> 7,
1080 (icmp_134->m_o_res >> 6) & 0x1);
1081 tprintf(", Router Lifetime (%us)",ntohs(icmp_134->router_lifetime));
1082 tprintf(", Reachable Time (%ums)",ntohl(icmp_134->reachable_time));
1083 tprintf(", Retrans Timer (%ums)",ntohl(icmp_134->retrans_timer));
1085 return dissect_neighb_disc_ops(pkt);
1088 static int8_t dissect_icmpv6_type135(struct pkt_buff *pkt)
1090 char address[INET6_ADDRSTRLEN];
1091 struct icmpv6_type_135 *icmp_135;
1093 icmp_135 = (struct icmpv6_type_135 *)
1094 pkt_pull(pkt,sizeof(*icmp_135));
1095 if (icmp_135 == NULL)
1096 return 0;
1098 tprintf(", Reserved (0x%x)",ntohl(icmp_135->res));
1099 tprintf(", Target Address: %s",
1100 inet_ntop(AF_INET6, &icmp_135->ipv6_addr,
1101 address, sizeof(address)));
1103 return dissect_neighb_disc_ops(pkt);
1106 static int8_t dissect_icmpv6_type136(struct pkt_buff *pkt)
1108 char address[INET6_ADDRSTRLEN];
1109 uint32_t r_s_o_res;
1110 struct icmpv6_type_136 *icmp_136;
1112 icmp_136 = (struct icmpv6_type_136 *)
1113 pkt_pull(pkt,sizeof(*icmp_136));
1114 if (icmp_136 == NULL)
1115 return 0;
1116 r_s_o_res = ntohl(icmp_136->r_s_o_res);
1118 tprintf(", R (%u) S (%u) O (%u) Reserved (0x%x)", r_s_o_res >> 31,
1119 (r_s_o_res >> 30) & 0x1, (r_s_o_res >> 29) & 0x1,
1120 r_s_o_res & 0x1FFFFFFF);
1121 tprintf(", Target Address: %s",
1122 inet_ntop(AF_INET6, &icmp_136->ipv6_addr,
1123 address, sizeof(address)));
1125 return dissect_neighb_disc_ops(pkt);
1128 static int8_t dissect_icmpv6_type137(struct pkt_buff *pkt)
1130 char address[INET6_ADDRSTRLEN];
1131 struct icmpv6_type_137 *icmp_137;
1133 icmp_137 = (struct icmpv6_type_137 *)
1134 pkt_pull(pkt,sizeof(*icmp_137));
1135 if (icmp_137 == NULL)
1136 return 0;
1138 tprintf(", Reserved (0x%x)",icmp_137->res);
1139 tprintf(", Target Address: %s",
1140 inet_ntop(AF_INET6, &icmp_137->ipv6_targ_addr,
1141 address, sizeof(address)));
1142 tprintf(", Dest Address: %s",
1143 inet_ntop(AF_INET6, &icmp_137->ipv6_dest_addr,
1144 address, sizeof(address)));
1146 return dissect_neighb_disc_ops(pkt);
1149 static void dissect_icmpv6_rr_body(struct pkt_buff *pkt)
1152 * Upgrade Dissector for Message Body
1153 * from http://tools.ietf.org/html/rfc2894#section-3.2
1155 if(pkt_len(pkt))
1156 tprintf(" Message Body recognized");
1159 static inline char *icmpv6_type_138_codes(uint8_t code) {
1160 switch (code) {
1161 case 1:
1162 return "Router Renumbering Command";
1163 case 2:
1164 return "Router Renumbering Result";
1165 case 255:
1166 return "Sequence Number Reset";
1169 return NULL;
1172 static int8_t dissect_icmpv6_type138(struct pkt_buff *pkt)
1174 struct icmpv6_type_138 *icmp_138;
1176 icmp_138 = (struct icmpv6_type_138 *)
1177 pkt_pull(pkt,sizeof(*icmp_138));
1178 if (icmp_138 == NULL)
1179 return 0;
1181 tprintf(", Sequence Nr. (%u)",ntohl(icmp_138->seq_nr));
1182 tprintf(", Segment Nr. (%u)",icmp_138->seg_nr);
1183 tprintf(", T (%u) R (%u) A (%u) S (%u) P (%u) Res \
1184 (0x%x) ",icmp_138->flags >> 7, (icmp_138->flags >> 6) & 1,
1185 (icmp_138->flags >> 5) & 1, (icmp_138->flags >> 4) & 1,
1186 (icmp_138->flags >> 3) & 1, icmp_138->flags & 7);
1187 tprintf(", Max Delay (%ums)", ntohs(icmp_138->maxdelay));
1188 tprintf(", Res (0x%x)", ntohl(icmp_138->res));
1190 dissect_icmpv6_rr_body(pkt);
1192 return 1;
1195 static void dissect_icmpv6_node_inf_data(struct pkt_buff *pkt)
1198 * Upgrade Dissector for Data field
1199 * http://tools.ietf.org/html/rfc4620#section-4
1201 if(pkt_len(pkt))
1202 tprintf(" Data recognized");
1205 static char *icmpv6_node_inf_qtypes[] = {
1206 "NOOP",
1207 "unused",
1208 "Node Name",
1209 "Node Addresses",
1210 "IPv4 Addresses ",
1213 static char *icmpv6_type_139_codes[] = {
1214 "Data contains IPv6 Address",
1215 "Data contains Name or nothing",
1216 "Data contains IPv4 Address",
1219 static int8_t dissect_icmpv6_type139(struct pkt_buff *pkt)
1221 char *qtype_name = "Unknown";
1222 uint16_t qtype_nr;
1223 struct icmpv6_type_139_140 *icmp_139;
1225 icmp_139 = (struct icmpv6_type_139_140 *)
1226 pkt_pull(pkt,sizeof(*icmp_139));
1227 if (icmp_139 == NULL)
1228 return 0;
1230 qtype_nr = ntohs(icmp_139->qtype);
1231 if (icmpv6_code_range_valid(qtype_nr, icmpv6_node_inf_qtypes))
1232 qtype_name = icmpv6_node_inf_qtypes[qtype_nr];
1234 tprintf(", Qtype %s (%u)",qtype_name, qtype_nr);
1235 tprintf(", Flags (0x%x)",ntohs(icmp_139->flags));
1236 tprintf(", Nonce (0x%x)",ntohll(icmp_139->nonce));
1238 dissect_icmpv6_node_inf_data(pkt);
1240 return 1;
1243 static char *icmpv6_type_140_codes[] = {
1244 "Successfull reply",
1245 "Responder refuses answer",
1246 "Qtype is unknown to the Responder",
1249 static inline int8_t dissect_icmpv6_type140(struct pkt_buff *pkt)
1251 return dissect_icmpv6_type139(pkt);
1254 static inline int8_t dissect_icmpv6_type141(struct pkt_buff *pkt)
1256 return dissect_icmpv6_type133(pkt);
1259 static inline int8_t dissect_icmpv6_type142(struct pkt_buff *pkt)
1261 return dissect_icmpv6_type133(pkt);
1264 static int8_t dissect_icmpv6_type143(struct pkt_buff *pkt)
1266 uint16_t nr_rec;
1267 struct icmpv6_type_143 *icmp_143;
1269 icmp_143 = (struct icmpv6_type_143 *)
1270 pkt_pull(pkt,sizeof(*icmp_143));
1271 if (icmp_143 == NULL)
1272 return 0;
1273 nr_rec = ntohs(icmp_143->nr_rec);
1275 tprintf(", Res (0x%x)",ntohs(icmp_143->res));
1276 tprintf(", Nr. Mcast Addr Records (%u)",nr_rec);
1278 return dissect_icmpv6_mcast_rec(pkt, nr_rec);
1281 static int8_t dissect_icmpv6_type144(struct pkt_buff *pkt)
1283 struct icmpv6_type_144_146 *icmp_144;
1285 icmp_144 = (struct icmpv6_type_144_146 *)
1286 pkt_pull(pkt,sizeof(*icmp_144));
1287 if (icmp_144 == NULL)
1288 return 0;
1290 tprintf(", ID (%u)",ntohs(icmp_144->id));
1291 tprintf(", Res (0x%x)",ntohs(icmp_144->res));
1293 return 1;
1296 static int8_t dissect_icmpv6_type145(struct pkt_buff *pkt)
1298 struct icmpv6_type_145 *icmp_145;
1300 icmp_145 = (struct icmpv6_type_145 *)
1301 pkt_pull(pkt,sizeof(*icmp_145));
1302 if (icmp_145 == NULL)
1303 return 0;
1305 tprintf(", ID (%u)",ntohs(icmp_145->id));
1306 tprintf(", Res (0x%x)",ntohs(icmp_145->res));
1308 return print_ipv6_addr_list(pkt, pkt_len(pkt) /
1309 sizeof(struct in6_addr));
1312 static inline int8_t dissect_icmpv6_type146(struct pkt_buff *pkt)
1314 return dissect_icmpv6_type144(pkt);
1317 static int8_t dissect_icmpv6_type147(struct pkt_buff *pkt)
1319 uint16_t m_o_res;
1320 struct icmpv6_type_147 *icmp_147;
1322 icmp_147 = (struct icmpv6_type_147 *)
1323 pkt_pull(pkt,sizeof(*icmp_147));
1324 if (icmp_147 == NULL)
1325 return 0;
1326 m_o_res = ntohs(icmp_147->m_o_res);
1328 tprintf(", ID (%u)",ntohs(icmp_147->id));
1329 tprintf(", M (%u) O (%u) Res (0x%x)",m_o_res >> 15,
1330 (m_o_res >> 14) & 1, m_o_res & 0x3FFF);
1332 return dissect_neighb_disc_ops(pkt);
1335 static int8_t dissect_icmpv6_type148(struct pkt_buff *pkt)
1337 struct icmpv6_type_148 *icmp_148;
1339 icmp_148 = (struct icmpv6_type_148 *)
1340 pkt_pull(pkt,sizeof(*icmp_148));
1341 if (icmp_148 == NULL)
1342 return 0;
1344 tprintf(", ID (%u)",ntohs(icmp_148->id));
1345 tprintf(", Component (%u)",ntohs(icmp_148->comp));
1347 return dissect_neighb_disc_ops(pkt);
1350 static int8_t dissect_icmpv6_type149(struct pkt_buff *pkt)
1352 struct icmpv6_type_149 *icmp_149;
1354 icmp_149 = (struct icmpv6_type_149 *)
1355 pkt_pull(pkt,sizeof(*icmp_149));
1356 if (icmp_149 == NULL)
1357 return 0;
1359 tprintf(", ID (%u)",ntohs(icmp_149->id));
1360 tprintf(", All Components (%u)",ntohs(icmp_149->all_comp));
1361 tprintf(", Component (%u)",ntohs(icmp_149->comp));
1362 tprintf(", Res (0x%x)",ntohs(icmp_149->res));
1364 return dissect_neighb_disc_ops(pkt);
1367 static int8_t dissect_icmpv6_type150(struct pkt_buff *pkt)
1369 struct icmpv6_type_150 *icmp_150;
1371 icmp_150 = (struct icmpv6_type_150 *)
1372 pkt_pull(pkt,sizeof(*icmp_150));
1373 if (icmp_150 == NULL)
1374 return 0;
1376 tprintf(", Subtype (%u)",icmp_150->subtype);
1377 tprintf(", Res (0x%x)",icmp_150->res);
1378 tprintf(", Options in Payload");
1380 return 1;
1383 static int8_t dissect_icmpv6_type151(struct pkt_buff *pkt)
1385 struct icmpv6_type_151 *icmp_151;
1387 icmp_151 = (struct icmpv6_type_151 *)
1388 pkt_pull(pkt,sizeof(*icmp_151));
1389 if (icmp_151 == NULL)
1390 return 0;
1392 tprintf(", Query Interval (%us)",ntohs(icmp_151->query_intv));
1393 tprintf(", Robustness Variable (%u)",ntohs(icmp_151->rob_var));
1395 return 1;
1398 static int8_t dissect_icmpv6_type152(struct pkt_buff *pkt)
1400 struct icmpv6_type_152 *icmp_152;
1402 icmp_152 = (struct icmpv6_type_152 *)
1403 pkt_pull(pkt,sizeof(*icmp_152));
1404 if (icmp_152 == NULL)
1405 return 0;
1407 return 1;
1410 static int8_t dissect_icmpv6_type153(struct pkt_buff *pkt)
1412 struct icmpv6_type_153 *icmp_153;
1414 icmp_153 = (struct icmpv6_type_153 *)
1415 pkt_pull(pkt,sizeof(*icmp_153));
1416 if (icmp_153 == NULL)
1417 return 0;
1419 return 1;
1422 static int8_t dissect_icmpv6_type154(struct pkt_buff *pkt)
1424 struct icmpv6_type_154 *icmp_154;
1426 icmp_154 = (struct icmpv6_type_154 *)
1427 pkt_pull(pkt,sizeof(*icmp_154));
1428 if (icmp_154 == NULL)
1429 return 0;
1431 tprintf(", Subtype (%u)",icmp_154->subtype);
1432 tprintf(", Res (0x%x)",icmp_154->res);
1433 tprintf(", ID (%u)",ntohs(icmp_154->id));
1435 return dissect_neighb_disc_ops(pkt);
1438 static inline char *icmpv6_type_155_codes(uint8_t code) {
1439 switch (code) {
1440 case 0x00:
1441 return "DODAG Information Solicitation";
1442 case 0x01:
1443 return "DODAG Information Object";
1444 case 0x02:
1445 return "Destination Advertisement Object";
1446 case 0x03:
1447 return "Destination Advertisement Object Acknowledgment";
1448 case 0x80:
1449 return "Secure DODAG Information Solicitation";
1450 case 0x81:
1451 return "Secure DODAG Information Object";
1452 case 0x82:
1453 return "Secure Destination Advertisement Object";
1454 case 0x83:
1455 return "Secure Destination Advertisement Object Acknowledgment";
1456 case 0x8A:
1457 return "Consistency Check";
1460 return NULL;
1463 static void icmpv6_process(struct icmpv6_general_hdr *icmp, char **type,
1464 char **code, int8_t (**optional)(struct pkt_buff *pkt))
1466 *type = "Unknown Type";
1467 *code = "Unknown Code";
1469 switch (icmp->h_type) {
1470 case 1:
1471 *type = "Destination Unreachable";
1472 if (icmpv6_code_range_valid(icmp->h_code, icmpv6_type_1_codes))
1473 *code = icmpv6_type_1_codes[icmp->h_code];
1474 *optional = dissect_icmpv6_type1;
1475 return;
1476 case 2:
1477 *type = "Packet Too Big";
1478 *optional = dissect_icmpv6_type2;
1479 return;
1480 case 3:
1481 *type = "Time Exceeded";
1482 if (icmpv6_code_range_valid(icmp->h_code, icmpv6_type_3_codes))
1483 *code = icmpv6_type_3_codes[icmp->h_code];
1484 *optional = dissect_icmpv6_type3;
1485 return;
1486 case 4:
1487 *type = "Parameter Problem";
1488 if (icmpv6_code_range_valid(icmp->h_code, icmpv6_type_4_codes))
1489 *code = icmpv6_type_4_codes[icmp->h_code];
1490 *optional = dissect_icmpv6_type4;
1491 return;
1492 case 100:
1493 *type = "Private experimation";
1494 return;
1495 case 101:
1496 *type = "Private experimation";
1497 return;
1498 case 127:
1499 *type = "Reserved for expansion of ICMPv6 error messages";
1500 return;
1501 case 128:
1502 *type = "Echo Request";
1503 *optional = dissect_icmpv6_type128;
1504 return;
1505 case 129:
1506 *type = "Echo Reply";
1507 *optional = dissect_icmpv6_type129;
1508 return;
1509 case 130:
1510 *type = "Multicast Listener Query";
1511 *optional = dissect_icmpv6_type130;
1512 return;
1513 case 131:
1514 *type = "Multicast Listener Report";
1515 *optional = dissect_icmpv6_type131;
1516 return;
1517 case 132:
1518 *type = "Multicast Listener Done";
1519 *optional = dissect_icmpv6_type132;
1520 return;
1521 case 133:
1522 *type = "Router Solicitation";
1523 *optional = dissect_icmpv6_type133;
1524 return;
1525 case 134:
1526 *type = "Router Advertisement";
1527 *optional = dissect_icmpv6_type134;
1528 return;
1529 case 135:
1530 *type = "Neighbor Solicitation";
1531 *optional = dissect_icmpv6_type135;
1532 return;
1533 case 136:
1534 *type = "Neighbor Advertisement";
1535 *optional = dissect_icmpv6_type136;
1536 return;
1537 case 137:
1538 *type = "Redirect Message";
1539 *optional = dissect_icmpv6_type137;
1540 return;
1541 case 138:
1542 *type = "Router Renumbering";
1543 if(icmpv6_type_138_codes(icmp->h_code))
1544 *code = icmpv6_type_138_codes(icmp->h_code);
1545 *optional = dissect_icmpv6_type138;
1546 return;
1547 case 139:
1548 *type = "ICMP Node Information Query";
1549 if (icmpv6_code_range_valid(icmp->h_code,
1550 icmpv6_type_139_codes))
1551 *code = icmpv6_type_139_codes[icmp->h_code];
1552 *optional = dissect_icmpv6_type139;
1553 return;
1554 case 140:
1555 *type = "ICMP Node Information Response";
1556 if (icmpv6_code_range_valid(icmp->h_code,
1557 icmpv6_type_140_codes))
1558 *code = icmpv6_type_140_codes[icmp->h_code];
1559 *optional = dissect_icmpv6_type140;
1560 return;
1561 case 141:
1562 *type = "Inverse Neighbor Discovery Solicitation Message";
1563 *optional = dissect_icmpv6_type141;
1564 return;
1565 case 142:
1566 *type = "Inverse Neighbor Discovery Advertisement Message";
1567 *optional = dissect_icmpv6_type142;
1568 return;
1569 case 143:
1570 *type = "Multicast Listener Report v2";
1571 *optional = dissect_icmpv6_type143;
1572 return;
1573 case 144:
1574 *type = "Home Agent Address Discovery Request Message";
1575 *optional = dissect_icmpv6_type144;
1576 return;
1577 case 145:
1578 *type = "Home Agent Address Discovery Reply Message";
1579 *optional = dissect_icmpv6_type145;
1580 return;
1581 case 146:
1582 *type = "Mobile Prefix Solicitation";
1583 *optional = dissect_icmpv6_type146;
1584 return;
1585 case 147:
1586 *type = "Mobile Prefix Advertisement";
1587 *optional = dissect_icmpv6_type147;
1588 return;
1589 case 148:
1590 *type = "Certification Path Solicitation";
1591 *optional = dissect_icmpv6_type148;
1592 return;
1593 case 149:
1594 *type = "Certification Path Advertisement";
1595 *optional = dissect_icmpv6_type149;
1596 return;
1597 case 150:
1598 *type = "ICMP messages utilized by experimental mobility "
1599 "protocols such as Seamoby";
1600 *optional = dissect_icmpv6_type150;
1601 return;
1602 case 151:
1603 *type = "Multicast Router Advertisement";
1604 *code = "Ad. Interval";
1605 *optional = dissect_icmpv6_type151;
1606 return;
1607 case 152:
1608 *type = "Multicast Router Solicitation";
1609 *code = "Reserved";
1610 *optional = dissect_icmpv6_type152;
1611 return;
1612 case 153:
1613 *type = "Multicast Router Termination";
1614 *code = "Reserved";
1615 *optional = dissect_icmpv6_type153;
1616 return;
1617 case 154:
1618 *type = "FMIPv6 Messages";
1619 *optional = dissect_icmpv6_type154;
1620 return;
1621 case 155:
1622 *type = "RPL Control Message";
1623 if(icmpv6_type_155_codes(icmp->h_code))
1624 *code = icmpv6_type_155_codes(icmp->h_code);
1625 return;
1626 case 200:
1627 *type = "Private experimation";
1628 return;
1629 case 201:
1630 *type = "Private experimation";
1631 return;
1632 case 255:
1633 *type = "Reserved for expansion of ICMPv6 error messages";
1634 return;
1638 static void icmpv6(struct pkt_buff *pkt)
1640 char *type = NULL, *code = NULL;
1641 int8_t (*optional)(struct pkt_buff *pkt) = NULL;
1642 struct icmpv6_general_hdr *icmp =
1643 (struct icmpv6_general_hdr *) pkt_pull(pkt, sizeof(*icmp));
1645 if (icmp == NULL)
1646 return;
1648 icmpv6_process(icmp, &type, &code, &optional);
1650 tprintf(" [ ICMPv6 ");
1651 tprintf("%s (%u), ", type, icmp->h_type);
1652 tprintf("%s (%u), ", code, icmp->h_code);
1653 tprintf("Chks (0x%x)", ntohs(icmp->h_chksum));
1654 if (optional)
1655 if (!((*optional) (pkt)))
1656 tprintf("\n%s%s%s", colorize_start_full(black, red),
1657 "Failed to dissect Message", colorize_end());
1658 tprintf(" ]\n");
1661 static void icmpv6_less(struct pkt_buff *pkt)
1663 struct icmpv6_general_hdr *icmp =
1664 (struct icmpv6_general_hdr *) pkt_pull(pkt, sizeof(*icmp));
1666 if (icmp == NULL)
1667 return;
1669 tprintf(" ICMPv6 Type (%u) Code (%u)", icmp->h_type, icmp->h_code);
1672 struct protocol icmpv6_ops = {
1673 .key = 0x3A,
1674 .print_full = icmpv6,
1675 .print_less = icmpv6_less,
1678 EXPORT_SYMBOL(icmpv6_ops);