man: netsniff-ng: Fix a typo
[netsniff-ng.git] / proto_icmpv6.c
blob6b2d8267ff12bf78a33ea143943e5ec7de8b6b3e
1 /*
2 * netsniff-ng - the packet sniffing beast
3 * Copyright 2012 Markus Amend <markus@netsniff-ng.org>, Deutsche Flugsicherung GmbH
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 const 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 char address[INET6_ADDRSTRLEN];
315 struct icmpv6_mldv2_addr_rec *addr_rec;
317 while (nr_rec--) {
318 addr_rec = (struct icmpv6_mldv2_addr_rec *)
319 pkt_pull(pkt,sizeof(*addr_rec));
320 if (addr_rec == NULL)
321 return 0;
322 aux_data_len_bytes = addr_rec->aux_data_len * 4;
323 nr_src = ntohs(addr_rec->nr_src);
325 tprintf(", Rec Type %s (%u)",
326 icmpv6_code_range_valid(addr_rec->rec_type - 1,
327 icmpv6_mcast_rec_types) ?
328 icmpv6_mcast_rec_types[addr_rec->rec_type - 1]
329 : "Unknown", addr_rec->rec_type);
330 if (aux_data_len_bytes > pkt_len(pkt)) {
331 tprintf(", Aux Data Len (%u, %u bytes) %s",
332 addr_rec->aux_data_len,
333 aux_data_len_bytes,
334 colorize_start_full(black, red) "invalid"
335 colorize_end());
336 return 0;
338 tprintf(", Aux Data Len (%u, %u bytes)",addr_rec->aux_data_len,
339 aux_data_len_bytes);
340 tprintf(", Nr. of Sources (%u)",nr_src);
341 tprintf(", Address: %s",
342 inet_ntop(AF_INET6, &addr_rec->multic_addr,
343 address, sizeof(address)));
345 if(!print_ipv6_addr_list(pkt, nr_src))
346 return 0;
348 if (aux_data_len_bytes > pkt_len(pkt)) {
349 tprintf("\nAux Data Len %s",
350 colorize_start_full(black, red) "invalid"
351 colorize_end());
352 return 0;
355 tprintf(", Aux Data: ");
356 while (aux_data_len_bytes--) {
357 tprintf("%x", *pkt_pull(pkt,1));
361 return 1;
364 static int8_t dissect_neighb_disc_ops_1(struct pkt_buff *pkt,
365 ssize_t len)
367 struct icmpv6_neighb_disc_ops_type_1_2 *icmp_neighb_disc_1;
369 icmp_neighb_disc_1 = (struct icmpv6_neighb_disc_ops_type_1_2 *)
370 pkt_pull(pkt,sizeof(*icmp_neighb_disc_1));
371 if (icmp_neighb_disc_1 == NULL)
372 return 0;
373 len -= sizeof(*icmp_neighb_disc_1);
374 if (len < 0)
375 return 0;
377 tprintf("Address 0x");
379 while(len--){
380 tprintf("%x", *pkt_pull(pkt,1));
383 return 1;
386 static int8_t dissect_neighb_disc_ops_2(struct pkt_buff *pkt,
387 ssize_t len)
389 return dissect_neighb_disc_ops_1(pkt, len);
392 static int8_t dissect_neighb_disc_ops_3(struct pkt_buff *pkt,
393 ssize_t len)
395 char address[INET6_ADDRSTRLEN];
396 struct icmpv6_neighb_disc_ops_type_3 *icmp_neighb_disc_3;
398 icmp_neighb_disc_3 = (struct icmpv6_neighb_disc_ops_type_3 *)
399 pkt_pull(pkt,sizeof(*icmp_neighb_disc_3));
400 if (icmp_neighb_disc_3 == NULL)
401 return 0;
402 len -= sizeof(*icmp_neighb_disc_3);
403 if (len < 0)
404 return 0;
406 tprintf("Prefix Len (%u) ",icmp_neighb_disc_3->prefix_len);
407 tprintf("L (%u) A (%u) Res1 (0x%x) ",icmp_neighb_disc_3->l_a_res1 >> 7,
408 (icmp_neighb_disc_3->l_a_res1 >> 7) & 0x1,
409 icmp_neighb_disc_3->l_a_res1 & 0x3F);
410 tprintf("Valid Lifetime (%us) ",
411 ntohl(icmp_neighb_disc_3->valid_lifetime));
412 tprintf("Preferred Lifetime (%us) ",
413 ntohl(icmp_neighb_disc_3->preferred_lifetime));
414 tprintf("Reserved2 (0x%x) ",
415 ntohl(icmp_neighb_disc_3->res2));
416 tprintf("Prefix: %s ",
417 inet_ntop(AF_INET6,&icmp_neighb_disc_3->prefix,
418 address, sizeof(address)));
420 return 1;
423 static int8_t dissect_neighb_disc_ops_4(struct pkt_buff *pkt,
424 ssize_t len)
426 struct icmpv6_neighb_disc_ops_type_4 *icmp_neighb_disc_4;
428 icmp_neighb_disc_4 = (struct icmpv6_neighb_disc_ops_type_4 *)
429 pkt_pull(pkt,sizeof(*icmp_neighb_disc_4));
430 if (icmp_neighb_disc_4 == NULL)
431 return 0;
432 len -= sizeof(*icmp_neighb_disc_4);
433 if (len < 0)
434 return 0;
436 tprintf("Reserved 1 (0x%x) ", ntohs(icmp_neighb_disc_4->res1));
437 tprintf("Reserved 2 (0x%x) ", ntohl(icmp_neighb_disc_4->res2));
438 tprintf("IP header + data ");
440 while (len--) {
441 tprintf("%x", *pkt_pull(pkt,1));
444 return 1;
447 static int8_t dissect_neighb_disc_ops_5(struct pkt_buff *pkt,
448 ssize_t len)
450 struct icmpv6_neighb_disc_ops_type_5 *icmp_neighb_disc_5;
452 icmp_neighb_disc_5 = (struct icmpv6_neighb_disc_ops_type_5 *)
453 pkt_pull(pkt,sizeof(*icmp_neighb_disc_5));
454 if (icmp_neighb_disc_5 == NULL)
455 return 0;
456 len -= sizeof(*icmp_neighb_disc_5);
457 if (len < 0)
458 return 0;
460 tprintf("Reserved (0x%x) ", ntohs(icmp_neighb_disc_5->res1));
461 tprintf("MTU (%u)", ntohl(icmp_neighb_disc_5->MTU));
463 return 1;
466 static int8_t dissect_neighb_disc_ops_9(struct pkt_buff *pkt,
467 ssize_t len)
469 struct icmpv6_neighb_disc_ops_type_9_10 *icmp_neighb_disc_9;
471 icmp_neighb_disc_9 = (struct icmpv6_neighb_disc_ops_type_9_10 *)
472 pkt_pull(pkt,sizeof(*icmp_neighb_disc_9));
473 if (icmp_neighb_disc_9 == NULL)
474 return 0;
475 len -= sizeof(*icmp_neighb_disc_9);
476 if (len < 0)
477 return 0;
479 tprintf("Reserved 1 (0x%x) ", ntohs(icmp_neighb_disc_9->res1));
480 tprintf("Reserved 2 (0x%x) ", ntohl(icmp_neighb_disc_9->res2));
482 return print_ipv6_addr_list(pkt, len / sizeof(struct in6_addr));
485 static int8_t dissect_neighb_disc_ops_10(struct pkt_buff *pkt,
486 ssize_t len)
488 return dissect_neighb_disc_ops_9(pkt, len);
491 static const char *icmpv6_neighb_disc_ops_15_name[] = {
492 "DER Encoded X.501 Name",
493 "FQDN",
496 static int8_t dissect_neighb_disc_ops_15(struct pkt_buff *pkt,
497 ssize_t len)
499 size_t pad_len;
500 ssize_t name_len;
501 struct icmpv6_neighb_disc_ops_type_15 *icmp_neighb_disc_15;
503 icmp_neighb_disc_15 = (struct icmpv6_neighb_disc_ops_type_15 *)
504 pkt_pull(pkt,sizeof(*icmp_neighb_disc_15));
505 if (icmp_neighb_disc_15 == NULL)
506 return 0;
507 len -= sizeof(*icmp_neighb_disc_15);
508 if (len < 0)
509 return 0;
510 pad_len = icmp_neighb_disc_15->pad_len;
512 tprintf("Name Type %s (%u) ",
513 icmpv6_code_range_valid(icmp_neighb_disc_15->name_type - 1,
514 icmpv6_neighb_disc_ops_15_name) ?
515 icmpv6_neighb_disc_ops_15_name[
516 icmp_neighb_disc_15->name_type - 1] : "Unknown",
517 icmp_neighb_disc_15->name_type);
518 if (pad_len > len) {
519 tprintf("Pad Len (%zu, invalid)\n%s", pad_len,
520 colorize_start_full(black, red)
521 "Skip Option" colorize_end());
522 pkt_pull(pkt, len);
523 return 1;
525 else
526 tprintf("Pad Len (%zu) ", pad_len);
528 name_len = len - pad_len;
530 tprintf("Name (");
531 while (name_len--) {
532 tprintf("%c", *pkt_pull(pkt,1));
534 tprintf(") ");
536 tprintf("Padding (");
538 while (pad_len--) {
539 tprintf("%x", *pkt_pull(pkt,1));
541 tprintf(")");
543 return 1;
546 static const char *icmpv6_neighb_disc_ops_16_cert[] = {
547 "X.509v3 Certificate",
550 static int8_t dissect_neighb_disc_ops_16(struct pkt_buff *pkt,
551 ssize_t len)
553 struct icmpv6_neighb_disc_ops_type_16 *icmp_neighb_disc_16;
555 icmp_neighb_disc_16 = (struct icmpv6_neighb_disc_ops_type_16 *)
556 pkt_pull(pkt,sizeof(*icmp_neighb_disc_16));
557 if (icmp_neighb_disc_16 == NULL)
558 return 0;
559 len -= sizeof(*icmp_neighb_disc_16);
560 if (len < 0)
561 return 0;
563 tprintf("Cert Type %s (%u) ",
564 icmpv6_code_range_valid(icmp_neighb_disc_16->cert_type - 1,
565 icmpv6_neighb_disc_ops_16_cert) ?
566 icmpv6_neighb_disc_ops_16_cert[
567 icmp_neighb_disc_16->cert_type - 1] : "Unknown",
568 icmp_neighb_disc_16->cert_type);
569 tprintf("Res (0x%x) ", icmp_neighb_disc_16->res);
571 tprintf("Certificate + Padding (");
572 while (len--) {
573 tprintf("%x", *pkt_pull(pkt,1));
575 tprintf(") ");
577 return 1;
580 static const char *icmpv6_neighb_disc_ops_17_codes[] = {
581 "Old Care-of Address",
582 "New Care-of Address",
583 "NAR's IP address",
584 "NAR's Prefix",
587 static int8_t dissect_neighb_disc_ops_17(struct pkt_buff *pkt,
588 ssize_t len)
590 char address[INET6_ADDRSTRLEN];
591 struct icmpv6_neighb_disc_ops_type_17 *icmp_neighb_disc_17;
593 icmp_neighb_disc_17 = (struct icmpv6_neighb_disc_ops_type_17 *)
594 pkt_pull(pkt,sizeof(*icmp_neighb_disc_17));
595 if (icmp_neighb_disc_17 == NULL)
596 return 0;
597 len -= sizeof(*icmp_neighb_disc_17);
598 if (len < 0)
599 return 0;
601 tprintf("Opt Code %s (%u) ",
602 icmpv6_code_range_valid(icmp_neighb_disc_17->opt_code - 1,
603 icmpv6_neighb_disc_ops_17_codes) ?
604 icmpv6_neighb_disc_ops_17_codes[
605 icmp_neighb_disc_17->opt_code - 1] : "Unknown",
606 icmp_neighb_disc_17->opt_code);
607 tprintf("Prefix Len (%u) ", icmp_neighb_disc_17->prefix_len);
609 if (len == sizeof(struct icmpv6_neighb_disc_ops_type_17_1)) {
610 struct icmpv6_neighb_disc_ops_type_17_1
611 *icmp_neighb_disc_17_1;
613 icmp_neighb_disc_17_1 =
614 (struct icmpv6_neighb_disc_ops_type_17_1 *)
615 pkt_pull(pkt,sizeof(*icmp_neighb_disc_17_1));
616 if (icmp_neighb_disc_17_1 == NULL)
617 return 0;
618 len -= sizeof(*icmp_neighb_disc_17_1);
619 if (len < 0)
620 return 0;
622 tprintf("Res (0x%x) ",icmp_neighb_disc_17_1->res);
623 tprintf("Addr: %s ",
624 inet_ntop(AF_INET6,&icmp_neighb_disc_17_1->ipv6_addr,
625 address, sizeof(address)));
627 else if (len == sizeof(struct icmpv6_neighb_disc_ops_type_17_2)) {
628 struct icmpv6_neighb_disc_ops_type_17_2
629 *icmp_neighb_disc_17_2;
631 icmp_neighb_disc_17_2 =
632 (struct icmpv6_neighb_disc_ops_type_17_2 *)
633 pkt_pull(pkt,sizeof(*icmp_neighb_disc_17_2));
634 if (icmp_neighb_disc_17_2 == NULL)
635 return 0;
636 len -= sizeof(*icmp_neighb_disc_17_2);
637 if (len < 0)
638 return 0;
640 tprintf("Addr: %s ",
641 inet_ntop(AF_INET6,&icmp_neighb_disc_17_2->ipv6_addr,
642 address, sizeof(address)));
644 else {
645 tprintf("%s (", colorize_start_full(black, red)
646 "Error Wrong Length. Skip Option" colorize_end());
647 while (len--) {
648 tprintf("%x", *pkt_pull(pkt,1));
650 tprintf(") ");
653 return 1;
656 static const char *icmpv6_neighb_disc_ops_19_codes[] = {
657 "Wildcard requesting resolution for all nearby access points",
658 "Link-Layer Address of the New Access Point",
659 "Link-Layer Address of the MN",
660 "Link-Layer Address of the NAR",
661 "Link-Layer Address of the source of RtSolPr or PrRtAdv \
662 message",
663 "The access point identified by the LLA belongs to the \
664 current interface of the router",
665 "No prefix information available for the access point \
666 identified by the LLA",
667 "No fast handover support available for the access point \
668 identified by the LLA",
671 static int8_t dissect_neighb_disc_ops_19(struct pkt_buff *pkt,
672 ssize_t len)
674 struct icmpv6_neighb_disc_ops_type_19 *icmp_neighb_disc_19;
676 icmp_neighb_disc_19 = (struct icmpv6_neighb_disc_ops_type_19 *)
677 pkt_pull(pkt,sizeof(*icmp_neighb_disc_19));
678 if (icmp_neighb_disc_19 == NULL)
679 return 0;
680 len -= sizeof(*icmp_neighb_disc_19);
681 if (len < 0)
682 return 0;
684 tprintf("Opt Code %s (%u) ",
685 icmpv6_code_range_valid(icmp_neighb_disc_19->opt_code,
686 icmpv6_neighb_disc_ops_19_codes) ?
687 icmpv6_neighb_disc_ops_19_codes[
688 icmp_neighb_disc_19->opt_code] : "Unknown",
689 icmp_neighb_disc_19->opt_code);
691 tprintf("LLA (");
692 while(len--){
693 tprintf("%x", *pkt_pull(pkt,1));
695 tprintf(") ");
697 return 1;
700 static inline char *icmpv6_neighb_disc_ops(uint8_t code) {
701 switch (code) {
702 case 1: return "Source Link-Layer Address";
703 case 2: return "Target Link-Layer Address";
704 case 3: return "Prefix Information";
705 case 4: return "Redirected Header";
706 case 5: return "MTU";
707 case 6: return "NBMA Shortcut Limit Option";
708 case 7: return "Advertisement Interval Option";
709 case 8: return "Home Agent Information Option";
710 case 9: return "Source Address List";
711 case 10: return "Target Address List";
712 case 11: return "CGA option";
713 case 12: return "RSA Signature option";
714 case 13: return "Timestamp option";
715 case 14: return "Nonce option";
716 case 15: return "Trust Anchor option";
717 case 16: return "Certificate option";
718 case 17: return "IP Address/Prefix Option";
719 case 18: return "New Router Prefix Information Option";
720 case 19: return "Link-layer Address Option";
721 case 20: return "Neighbor Advertisement Acknowledgment Option";
723 case 23: return "Prefix Information";
724 case 24: return "Redirected Header";
725 case 25: return "MTU";
726 case 26: return "NBMA Shortcut Limit Option";
727 case 27: return "Advertisement Interval Option";
728 case 28: return "Home Agent Information Option";
729 case 29: return "Source Address List";
730 case 30: return "Target Address List";
731 case 31: return "DNS Search List Option";
732 case 32: return "Proxy Signature (PS)";
734 case 138: return "CARD Request option";
735 case 139: return "CARD Reply option";
737 case 253: return "RFC3692-style Experiment 1";
738 case 254: return "RFC3692-style Experiment 2";
741 return NULL;
744 static int8_t dissect_neighb_disc_ops(struct pkt_buff *pkt)
746 size_t pad_bytes;
747 uint16_t ops_total_len;
748 ssize_t ops_payl_len;
749 struct icmpv6_neighb_disc_ops_general *icmp_neighb_disc;
751 while(pkt_len(pkt)) {
752 icmp_neighb_disc = (struct icmpv6_neighb_disc_ops_general *)
753 pkt_pull(pkt,sizeof(*icmp_neighb_disc));
754 if (icmp_neighb_disc == NULL)
755 return 0;
757 ops_total_len = icmp_neighb_disc->len * 8;
758 pad_bytes = (size_t) (ops_total_len % 8);
759 ops_payl_len = ops_total_len - sizeof(*icmp_neighb_disc) -
760 pad_bytes;
762 tprintf("\n\tOption %s (%u) ",
763 icmpv6_neighb_disc_ops(icmp_neighb_disc->type) ?
764 icmpv6_neighb_disc_ops(icmp_neighb_disc->type)
765 : "Type Unknown", icmp_neighb_disc->type);
766 if (ops_payl_len > pkt_len(pkt) || ops_payl_len < 0) {
767 tprintf("Length (%u, %u bytes, %s%s%s) ",
768 icmp_neighb_disc->len,
769 ops_total_len,
770 colorize_start_full(black, red),
771 "invalid", colorize_end());
772 return 0;
775 tprintf("Length (%u, %u bytes) ",icmp_neighb_disc->len,
776 ops_total_len);
778 switch (icmp_neighb_disc->type) {
779 case 1:
780 if (!dissect_neighb_disc_ops_1(pkt, ops_payl_len))
781 return 0;
782 break;
783 case 2:
784 if (!dissect_neighb_disc_ops_2(pkt, ops_payl_len))
785 return 0;
786 break;
787 case 3:
788 if (!dissect_neighb_disc_ops_3(pkt, ops_payl_len))
789 return 0;
790 break;
791 case 4:
792 if (!dissect_neighb_disc_ops_4(pkt, ops_payl_len))
793 return 0;
794 break;
795 case 5:
796 if (!dissect_neighb_disc_ops_5(pkt, ops_payl_len))
797 return 0;
798 break;
799 /* Type 9 and 10 defined in
800 * http://tools.ietf.org/html/rfc3122#section-3.1
802 case 9:
803 if (!dissect_neighb_disc_ops_9(pkt, ops_payl_len))
804 return 0;
805 break;
806 case 10:
807 if (!dissect_neighb_disc_ops_10(pkt, ops_payl_len))
808 return 0;
809 break;
810 /* Type 15 and 16 defined in
811 * http://tools.ietf.org/html/rfc3971#section-6.4.3
812 * http://tools.ietf.org/html/rfc3971#section-6.4.4
814 case 15:
815 if (!dissect_neighb_disc_ops_15(pkt, ops_payl_len))
816 return 0;
817 break;
818 case 16:
819 if (!dissect_neighb_disc_ops_16(pkt, ops_payl_len))
820 return 0;
821 break;
822 /* Type 17 and 19 defined in
823 * http://tools.ietf.org/html/rfc5568#section-6.4
825 case 17:
826 if (!dissect_neighb_disc_ops_17(pkt, ops_payl_len))
827 return 0;
828 break;
829 case 19:
830 if (!dissect_neighb_disc_ops_19(pkt, ops_payl_len))
831 return 0;
832 break;
833 default:
834 pkt_pull(pkt, ops_payl_len);
837 /* Skip Padding Bytes */
838 if (pad_bytes > pkt_len(pkt)) {
839 tprintf(" %s",colorize_start_full(black, red)
840 "Invalid Padding" colorize_end());
841 return 0;
843 pkt_pull(pkt, pad_bytes);
846 return 1;
849 static const char *icmpv6_type_1_codes[] = {
850 "No route to destination",
851 "Communication with destination administratively prohibited",
852 "Beyond scope of source address",
853 "Address unreachable",
854 "Port unreachable",
855 "Source address failed ingress/egress policy",
856 "Reject route to destination",
857 "Error in Source Routing Header",
860 static int8_t dissect_icmpv6_type1(struct pkt_buff *pkt)
862 struct icmpv6_type_1_3 *icmp_1;
864 icmp_1 = (struct icmpv6_type_1_3 *) pkt_pull(pkt,sizeof(*icmp_1));
865 if (icmp_1 == NULL)
866 return 0;
868 tprintf(", Unused (0x%x)",ntohl(icmp_1->unused));
869 tprintf(" Payload include as much of invoking packet");
871 return 1;
874 static int8_t dissect_icmpv6_type2(struct pkt_buff *pkt)
876 struct icmpv6_type_2 *icmp_2;
878 icmp_2 = (struct icmpv6_type_2 *) pkt_pull(pkt,sizeof(*icmp_2));
879 if (icmp_2 == NULL)
880 return 0;
882 tprintf(", MTU (0x%x)",ntohl(icmp_2->MTU));
883 tprintf(" Payload include as much of invoking packet");
885 return 1;
888 static const char *icmpv6_type_3_codes[] = {
889 "Hop limit exceeded in transit",
890 "Fragment reassembly time exceeded",
893 static int8_t dissect_icmpv6_type3(struct pkt_buff *pkt)
895 struct icmpv6_type_1_3 *icmp_3;
897 icmp_3 = (struct icmpv6_type_1_3 *) pkt_pull(pkt,sizeof(*icmp_3));
898 if (icmp_3 == NULL)
899 return 0;
901 tprintf(", Unused (0x%x)",ntohl(icmp_3->unused));
902 tprintf(" Payload include as much of invoking packet");
904 return 1;
907 static const char *icmpv6_type_4_codes[] = {
908 "Erroneous header field encountered",
909 "Unrecognized Next Header type encountered",
910 "Unrecognized IPv6 option encountered",
913 static int8_t dissect_icmpv6_type4(struct pkt_buff *pkt)
915 struct icmpv6_type_4 *icmp_4;
917 icmp_4 = (struct icmpv6_type_4 *) pkt_pull(pkt,sizeof(*icmp_4));
918 if (icmp_4 == NULL)
919 return 0;
921 tprintf(", Pointer (0x%x)",ntohl(icmp_4->pointer));
922 tprintf(" Payload include as much of invoking packet");
924 return 1;
927 static int8_t dissect_icmpv6_type128(struct pkt_buff *pkt)
929 struct icmpv6_type_128_129 *icmp_128;
931 icmp_128 = (struct icmpv6_type_128_129 *)
932 pkt_pull(pkt,sizeof(*icmp_128));
933 if (icmp_128 == NULL)
934 return 0;
936 tprintf(", ID (0x%x)",ntohs(icmp_128->id));
937 tprintf(", Seq. Nr. (%u)",ntohs(icmp_128->sn));
938 tprintf(" Payload include Data");
940 return 1;
943 static int8_t dissect_icmpv6_type129(struct pkt_buff *pkt)
945 struct icmpv6_type_128_129 *icmp_129;
947 icmp_129 = (struct icmpv6_type_128_129 *)
948 pkt_pull(pkt,sizeof(*icmp_129));
949 if (icmp_129 == NULL)
950 return 0;
952 tprintf(", ID (0x%x)",ntohs(icmp_129->id));
953 tprintf(", Seq. Nr. (%u)",ntohs(icmp_129->sn));
954 tprintf(" Payload include Data");
956 return 1;
959 static int8_t dissect_icmpv6_type130(struct pkt_buff *pkt)
961 char address[INET6_ADDRSTRLEN];
962 uint16_t nr_src, maxrespdel;
963 uint8_t switch_mldv2 = 0;
964 struct icmpv6_type_130_131_132 *icmp_130;
966 icmp_130 = (struct icmpv6_type_130_131_132 *)
967 pkt_pull(pkt,sizeof(*icmp_130));
968 if (icmp_130 == NULL)
969 return 0;
970 maxrespdel = ntohs(icmp_130->maxrespdel);
972 if(pkt_len(pkt) >= sizeof(struct icmpv6_type_130_mldv2))
973 switch_mldv2 = 1;
975 if(switch_mldv2)
976 tprintf(", MLDv2, Max Resp Delay (%ums)", maxrespdel >> 15 ?
977 (((maxrespdel & 0xFFF) | 0x1000) <<
978 (((maxrespdel >> 12) & 0x3) + 3)) : maxrespdel);
979 else
980 tprintf(", Max Resp Delay (%ums)",maxrespdel);
981 tprintf(", Res (0x%x)",ntohs(icmp_130->res));
982 tprintf(", Address: %s",
983 inet_ntop(AF_INET6, &icmp_130->ipv6_addr,
984 address, sizeof(address)));
986 if(switch_mldv2) {
987 struct icmpv6_type_130_mldv2 *icmp_130_mldv2;
989 icmp_130_mldv2 = (struct icmpv6_type_130_mldv2 *)
990 pkt_pull(pkt,sizeof(*icmp_130_mldv2));
991 if (icmp_130_mldv2 == NULL)
992 return 0;
994 nr_src = ntohs(icmp_130_mldv2->nr_src);
996 tprintf(", Resv (0x%x)",icmp_130_mldv2->resv_S_QRV >> 4);
997 tprintf(", S (%u)",(icmp_130_mldv2->resv_S_QRV >> 3) & 0x1);
998 tprintf(", QRV (0x%x)",icmp_130_mldv2->resv_S_QRV & 0x3);
999 tprintf(", QQIC (%u)",icmp_130_mldv2->QQIC);
1000 tprintf(", Nr Src (%u)",nr_src);
1002 return print_ipv6_addr_list(pkt, nr_src);
1005 return 1;
1008 static int8_t dissect_icmpv6_type131(struct pkt_buff *pkt)
1010 char address[INET6_ADDRSTRLEN];
1011 struct icmpv6_type_130_131_132 *icmp_131;
1013 icmp_131 = (struct icmpv6_type_130_131_132 *)
1014 pkt_pull(pkt,sizeof(*icmp_131));
1015 if (icmp_131 == NULL)
1016 return 0;
1018 tprintf(", Max Resp Delay (%ums)",ntohs(icmp_131->maxrespdel));
1019 tprintf(", Res (0x%x)",ntohs(icmp_131->res));
1020 tprintf(", Address: %s",
1021 inet_ntop(AF_INET6, &icmp_131->ipv6_addr,
1022 address, sizeof(address)));
1024 return 1;
1027 static inline int8_t dissect_icmpv6_type132(struct pkt_buff *pkt)
1029 return dissect_icmpv6_type131(pkt);
1032 static int8_t dissect_icmpv6_type133(struct pkt_buff *pkt)
1034 struct icmpv6_type_133_141_142 *icmp_133;
1036 icmp_133 = (struct icmpv6_type_133_141_142 *)
1037 pkt_pull(pkt,sizeof(*icmp_133));
1038 if (icmp_133 == NULL)
1039 return 0;
1041 tprintf(", Reserved (0x%x)",ntohl(icmp_133->res));
1043 return dissect_neighb_disc_ops(pkt);
1046 static int8_t dissect_icmpv6_type134(struct pkt_buff *pkt)
1048 struct icmpv6_type_134 *icmp_134;
1050 icmp_134 = (struct icmpv6_type_134 *)
1051 pkt_pull(pkt,sizeof(*icmp_134));
1052 if (icmp_134 == NULL)
1053 return 0;
1055 tprintf(", Cur Hop Limit (%u)",icmp_134->cur_hop_limit);
1056 tprintf(", M (%u) O (%u)",icmp_134->m_o_res >> 7,
1057 (icmp_134->m_o_res >> 6) & 0x1);
1058 tprintf(", Router Lifetime (%us)",ntohs(icmp_134->router_lifetime));
1059 tprintf(", Reachable Time (%ums)",ntohl(icmp_134->reachable_time));
1060 tprintf(", Retrans Timer (%ums)",ntohl(icmp_134->retrans_timer));
1062 return dissect_neighb_disc_ops(pkt);
1065 static int8_t dissect_icmpv6_type135(struct pkt_buff *pkt)
1067 char address[INET6_ADDRSTRLEN];
1068 struct icmpv6_type_135 *icmp_135;
1070 icmp_135 = (struct icmpv6_type_135 *)
1071 pkt_pull(pkt,sizeof(*icmp_135));
1072 if (icmp_135 == NULL)
1073 return 0;
1075 tprintf(", Reserved (0x%x)",ntohl(icmp_135->res));
1076 tprintf(", Target Address: %s",
1077 inet_ntop(AF_INET6, &icmp_135->ipv6_addr,
1078 address, sizeof(address)));
1080 return dissect_neighb_disc_ops(pkt);
1083 static int8_t dissect_icmpv6_type136(struct pkt_buff *pkt)
1085 char address[INET6_ADDRSTRLEN];
1086 uint32_t r_s_o_res;
1087 struct icmpv6_type_136 *icmp_136;
1089 icmp_136 = (struct icmpv6_type_136 *)
1090 pkt_pull(pkt,sizeof(*icmp_136));
1091 if (icmp_136 == NULL)
1092 return 0;
1093 r_s_o_res = ntohl(icmp_136->r_s_o_res);
1095 tprintf(", R (%u) S (%u) O (%u) Reserved (0x%x)", r_s_o_res >> 31,
1096 (r_s_o_res >> 30) & 0x1, (r_s_o_res >> 29) & 0x1,
1097 r_s_o_res & 0x1FFFFFFF);
1098 tprintf(", Target Address: %s",
1099 inet_ntop(AF_INET6, &icmp_136->ipv6_addr,
1100 address, sizeof(address)));
1102 return dissect_neighb_disc_ops(pkt);
1105 static int8_t dissect_icmpv6_type137(struct pkt_buff *pkt)
1107 char address[INET6_ADDRSTRLEN];
1108 struct icmpv6_type_137 *icmp_137;
1110 icmp_137 = (struct icmpv6_type_137 *)
1111 pkt_pull(pkt,sizeof(*icmp_137));
1112 if (icmp_137 == NULL)
1113 return 0;
1115 tprintf(", Reserved (0x%x)",icmp_137->res);
1116 tprintf(", Target Address: %s",
1117 inet_ntop(AF_INET6, &icmp_137->ipv6_targ_addr,
1118 address, sizeof(address)));
1119 tprintf(", Dest Address: %s",
1120 inet_ntop(AF_INET6, &icmp_137->ipv6_dest_addr,
1121 address, sizeof(address)));
1123 return dissect_neighb_disc_ops(pkt);
1126 static void dissect_icmpv6_rr_body(struct pkt_buff *pkt)
1129 * Upgrade Dissector for Message Body
1130 * from http://tools.ietf.org/html/rfc2894#section-3.2
1132 if(pkt_len(pkt))
1133 tprintf(" Message Body recognized");
1136 static inline char *icmpv6_type_138_codes(uint8_t code) {
1137 switch (code) {
1138 case 1: return "Router Renumbering Command";
1139 case 2: return "Router Renumbering Result";
1140 case 255: return "Sequence Number Reset";
1143 return NULL;
1146 static int8_t dissect_icmpv6_type138(struct pkt_buff *pkt)
1148 struct icmpv6_type_138 *icmp_138;
1150 icmp_138 = (struct icmpv6_type_138 *)
1151 pkt_pull(pkt,sizeof(*icmp_138));
1152 if (icmp_138 == NULL)
1153 return 0;
1155 tprintf(", Sequence Nr. (%u)",ntohl(icmp_138->seq_nr));
1156 tprintf(", Segment Nr. (%u)",icmp_138->seg_nr);
1157 tprintf(", T (%u) R (%u) A (%u) S (%u) P (%u) Res \
1158 (0x%x) ",icmp_138->flags >> 7, (icmp_138->flags >> 6) & 1,
1159 (icmp_138->flags >> 5) & 1, (icmp_138->flags >> 4) & 1,
1160 (icmp_138->flags >> 3) & 1, icmp_138->flags & 7);
1161 tprintf(", Max Delay (%ums)", ntohs(icmp_138->maxdelay));
1162 tprintf(", Res (0x%x)", ntohl(icmp_138->res));
1164 dissect_icmpv6_rr_body(pkt);
1166 return 1;
1169 static void dissect_icmpv6_node_inf_data(struct pkt_buff *pkt)
1172 * Upgrade Dissector for Data field
1173 * http://tools.ietf.org/html/rfc4620#section-4
1175 if(pkt_len(pkt))
1176 tprintf(" Data recognized");
1179 static const char *icmpv6_node_inf_qtypes[] = {
1180 "NOOP",
1181 "unused",
1182 "Node Name",
1183 "Node Addresses",
1184 "IPv4 Addresses ",
1187 static const char *icmpv6_type_139_codes[] = {
1188 "Data contains IPv6 Address",
1189 "Data contains Name or nothing",
1190 "Data contains IPv4 Address",
1193 static int8_t dissect_icmpv6_type139(struct pkt_buff *pkt)
1195 const char *qtype_name = "Unknown";
1196 uint16_t qtype_nr;
1197 struct icmpv6_type_139_140 *icmp_139;
1199 icmp_139 = (struct icmpv6_type_139_140 *)
1200 pkt_pull(pkt,sizeof(*icmp_139));
1201 if (icmp_139 == NULL)
1202 return 0;
1204 qtype_nr = ntohs(icmp_139->qtype);
1205 if (icmpv6_code_range_valid(qtype_nr, icmpv6_node_inf_qtypes))
1206 qtype_name = icmpv6_node_inf_qtypes[qtype_nr];
1208 tprintf(", Qtype %s (%u)", qtype_name, qtype_nr);
1209 tprintf(", Flags (0x%x)", ntohs(icmp_139->flags));
1210 tprintf(", Nonce (0x%lx)", ntohll(icmp_139->nonce));
1212 dissect_icmpv6_node_inf_data(pkt);
1214 return 1;
1217 static char *icmpv6_type_140_codes[] = {
1218 "Successfull reply",
1219 "Responder refuses answer",
1220 "Qtype is unknown to the Responder",
1223 static inline int8_t dissect_icmpv6_type140(struct pkt_buff *pkt)
1225 return dissect_icmpv6_type139(pkt);
1228 static inline int8_t dissect_icmpv6_type141(struct pkt_buff *pkt)
1230 return dissect_icmpv6_type133(pkt);
1233 static inline int8_t dissect_icmpv6_type142(struct pkt_buff *pkt)
1235 return dissect_icmpv6_type133(pkt);
1238 static int8_t dissect_icmpv6_type143(struct pkt_buff *pkt)
1240 uint16_t nr_rec;
1241 struct icmpv6_type_143 *icmp_143;
1243 icmp_143 = (struct icmpv6_type_143 *)
1244 pkt_pull(pkt,sizeof(*icmp_143));
1245 if (icmp_143 == NULL)
1246 return 0;
1247 nr_rec = ntohs(icmp_143->nr_rec);
1249 tprintf(", Res (0x%x)",ntohs(icmp_143->res));
1250 tprintf(", Nr. Mcast Addr Records (%u)",nr_rec);
1252 return dissect_icmpv6_mcast_rec(pkt, nr_rec);
1255 static int8_t dissect_icmpv6_type144(struct pkt_buff *pkt)
1257 struct icmpv6_type_144_146 *icmp_144;
1259 icmp_144 = (struct icmpv6_type_144_146 *)
1260 pkt_pull(pkt,sizeof(*icmp_144));
1261 if (icmp_144 == NULL)
1262 return 0;
1264 tprintf(", ID (%u)",ntohs(icmp_144->id));
1265 tprintf(", Res (0x%x)",ntohs(icmp_144->res));
1267 return 1;
1270 static int8_t dissect_icmpv6_type145(struct pkt_buff *pkt)
1272 struct icmpv6_type_145 *icmp_145;
1274 icmp_145 = (struct icmpv6_type_145 *)
1275 pkt_pull(pkt,sizeof(*icmp_145));
1276 if (icmp_145 == NULL)
1277 return 0;
1279 tprintf(", ID (%u)",ntohs(icmp_145->id));
1280 tprintf(", Res (0x%x)",ntohs(icmp_145->res));
1282 return print_ipv6_addr_list(pkt, pkt_len(pkt) /
1283 sizeof(struct in6_addr));
1286 static inline int8_t dissect_icmpv6_type146(struct pkt_buff *pkt)
1288 return dissect_icmpv6_type144(pkt);
1291 static int8_t dissect_icmpv6_type147(struct pkt_buff *pkt)
1293 uint16_t m_o_res;
1294 struct icmpv6_type_147 *icmp_147;
1296 icmp_147 = (struct icmpv6_type_147 *)
1297 pkt_pull(pkt,sizeof(*icmp_147));
1298 if (icmp_147 == NULL)
1299 return 0;
1300 m_o_res = ntohs(icmp_147->m_o_res);
1302 tprintf(", ID (%u)",ntohs(icmp_147->id));
1303 tprintf(", M (%u) O (%u) Res (0x%x)",m_o_res >> 15,
1304 (m_o_res >> 14) & 1, m_o_res & 0x3FFF);
1306 return dissect_neighb_disc_ops(pkt);
1309 static int8_t dissect_icmpv6_type148(struct pkt_buff *pkt)
1311 struct icmpv6_type_148 *icmp_148;
1313 icmp_148 = (struct icmpv6_type_148 *)
1314 pkt_pull(pkt,sizeof(*icmp_148));
1315 if (icmp_148 == NULL)
1316 return 0;
1318 tprintf(", ID (%u)",ntohs(icmp_148->id));
1319 tprintf(", Component (%u)",ntohs(icmp_148->comp));
1321 return dissect_neighb_disc_ops(pkt);
1324 static int8_t dissect_icmpv6_type149(struct pkt_buff *pkt)
1326 struct icmpv6_type_149 *icmp_149;
1328 icmp_149 = (struct icmpv6_type_149 *)
1329 pkt_pull(pkt,sizeof(*icmp_149));
1330 if (icmp_149 == NULL)
1331 return 0;
1333 tprintf(", ID (%u)",ntohs(icmp_149->id));
1334 tprintf(", All Components (%u)",ntohs(icmp_149->all_comp));
1335 tprintf(", Component (%u)",ntohs(icmp_149->comp));
1336 tprintf(", Res (0x%x)",ntohs(icmp_149->res));
1338 return dissect_neighb_disc_ops(pkt);
1341 static int8_t dissect_icmpv6_type150(struct pkt_buff *pkt)
1343 struct icmpv6_type_150 *icmp_150;
1345 icmp_150 = (struct icmpv6_type_150 *)
1346 pkt_pull(pkt,sizeof(*icmp_150));
1347 if (icmp_150 == NULL)
1348 return 0;
1350 tprintf(", Subtype (%u)",icmp_150->subtype);
1351 tprintf(", Res (0x%x)",icmp_150->res);
1352 tprintf(", Options in Payload");
1354 return 1;
1357 static int8_t dissect_icmpv6_type151(struct pkt_buff *pkt)
1359 struct icmpv6_type_151 *icmp_151;
1361 icmp_151 = (struct icmpv6_type_151 *)
1362 pkt_pull(pkt,sizeof(*icmp_151));
1363 if (icmp_151 == NULL)
1364 return 0;
1366 tprintf(", Query Interval (%us)",ntohs(icmp_151->query_intv));
1367 tprintf(", Robustness Variable (%u)",ntohs(icmp_151->rob_var));
1369 return 1;
1372 static int8_t dissect_icmpv6_type152(struct pkt_buff *pkt)
1374 struct icmpv6_type_152 *icmp_152;
1376 icmp_152 = (struct icmpv6_type_152 *)
1377 pkt_pull(pkt,sizeof(*icmp_152));
1378 if (icmp_152 == NULL)
1379 return 0;
1381 return 1;
1384 static int8_t dissect_icmpv6_type153(struct pkt_buff *pkt)
1386 struct icmpv6_type_153 *icmp_153;
1388 icmp_153 = (struct icmpv6_type_153 *)
1389 pkt_pull(pkt,sizeof(*icmp_153));
1390 if (icmp_153 == NULL)
1391 return 0;
1393 return 1;
1396 static int8_t dissect_icmpv6_type154(struct pkt_buff *pkt)
1398 struct icmpv6_type_154 *icmp_154;
1400 icmp_154 = (struct icmpv6_type_154 *)
1401 pkt_pull(pkt,sizeof(*icmp_154));
1402 if (icmp_154 == NULL)
1403 return 0;
1405 tprintf(", Subtype (%u)",icmp_154->subtype);
1406 tprintf(", Res (0x%x)",icmp_154->res);
1407 tprintf(", ID (%u)",ntohs(icmp_154->id));
1409 return dissect_neighb_disc_ops(pkt);
1412 static inline char *icmpv6_type_155_codes(uint8_t code) {
1413 switch (code) {
1414 case 0x00: return "DODAG Information Solicitation";
1415 case 0x01: return "DODAG Information Object";
1416 case 0x02: return "Destination Advertisement Object";
1417 case 0x03: return "Destination Advertisement Object Acknowledgment";
1418 case 0x80: return "Secure DODAG Information Solicitation";
1419 case 0x81: return "Secure DODAG Information Object";
1420 case 0x82: return "Secure Destination Advertisement Object";
1421 case 0x83: return "Secure Destination Advertisement Object Acknowledgment";
1422 case 0x8A: return "Consistency Check";
1425 return NULL;
1428 static void icmpv6_process(struct icmpv6_general_hdr *icmp, const char **type,
1429 const char **code, int8_t (**optional)(struct pkt_buff *pkt))
1431 *type = "Unknown Type";
1432 *code = "Unknown Code";
1434 switch (icmp->h_type) {
1435 case 1:
1436 *type = "Destination Unreachable";
1437 if (icmpv6_code_range_valid(icmp->h_code, icmpv6_type_1_codes))
1438 *code = icmpv6_type_1_codes[icmp->h_code];
1439 *optional = dissect_icmpv6_type1;
1440 return;
1441 case 2:
1442 *type = "Packet Too Big";
1443 *optional = dissect_icmpv6_type2;
1444 return;
1445 case 3:
1446 *type = "Time Exceeded";
1447 if (icmpv6_code_range_valid(icmp->h_code, icmpv6_type_3_codes))
1448 *code = icmpv6_type_3_codes[icmp->h_code];
1449 *optional = dissect_icmpv6_type3;
1450 return;
1451 case 4:
1452 *type = "Parameter Problem";
1453 if (icmpv6_code_range_valid(icmp->h_code, icmpv6_type_4_codes))
1454 *code = icmpv6_type_4_codes[icmp->h_code];
1455 *optional = dissect_icmpv6_type4;
1456 return;
1457 case 100:
1458 *type = "Private experimation";
1459 return;
1460 case 101:
1461 *type = "Private experimation";
1462 return;
1463 case 127:
1464 *type = "Reserved for expansion of ICMPv6 error messages";
1465 return;
1466 case 128:
1467 *type = "Echo Request";
1468 *optional = dissect_icmpv6_type128;
1469 return;
1470 case 129:
1471 *type = "Echo Reply";
1472 *optional = dissect_icmpv6_type129;
1473 return;
1474 case 130:
1475 *type = "Multicast Listener Query";
1476 *optional = dissect_icmpv6_type130;
1477 return;
1478 case 131:
1479 *type = "Multicast Listener Report";
1480 *optional = dissect_icmpv6_type131;
1481 return;
1482 case 132:
1483 *type = "Multicast Listener Done";
1484 *optional = dissect_icmpv6_type132;
1485 return;
1486 case 133:
1487 *type = "Router Solicitation";
1488 *optional = dissect_icmpv6_type133;
1489 return;
1490 case 134:
1491 *type = "Router Advertisement";
1492 *optional = dissect_icmpv6_type134;
1493 return;
1494 case 135:
1495 *type = "Neighbor Solicitation";
1496 *optional = dissect_icmpv6_type135;
1497 return;
1498 case 136:
1499 *type = "Neighbor Advertisement";
1500 *optional = dissect_icmpv6_type136;
1501 return;
1502 case 137:
1503 *type = "Redirect Message";
1504 *optional = dissect_icmpv6_type137;
1505 return;
1506 case 138:
1507 *type = "Router Renumbering";
1508 if(icmpv6_type_138_codes(icmp->h_code))
1509 *code = icmpv6_type_138_codes(icmp->h_code);
1510 *optional = dissect_icmpv6_type138;
1511 return;
1512 case 139:
1513 *type = "ICMP Node Information Query";
1514 if (icmpv6_code_range_valid(icmp->h_code,
1515 icmpv6_type_139_codes))
1516 *code = icmpv6_type_139_codes[icmp->h_code];
1517 *optional = dissect_icmpv6_type139;
1518 return;
1519 case 140:
1520 *type = "ICMP Node Information Response";
1521 if (icmpv6_code_range_valid(icmp->h_code,
1522 icmpv6_type_140_codes))
1523 *code = icmpv6_type_140_codes[icmp->h_code];
1524 *optional = dissect_icmpv6_type140;
1525 return;
1526 case 141:
1527 *type = "Inverse Neighbor Discovery Solicitation Message";
1528 *optional = dissect_icmpv6_type141;
1529 return;
1530 case 142:
1531 *type = "Inverse Neighbor Discovery Advertisement Message";
1532 *optional = dissect_icmpv6_type142;
1533 return;
1534 case 143:
1535 *type = "Multicast Listener Report v2";
1536 *optional = dissect_icmpv6_type143;
1537 return;
1538 case 144:
1539 *type = "Home Agent Address Discovery Request Message";
1540 *optional = dissect_icmpv6_type144;
1541 return;
1542 case 145:
1543 *type = "Home Agent Address Discovery Reply Message";
1544 *optional = dissect_icmpv6_type145;
1545 return;
1546 case 146:
1547 *type = "Mobile Prefix Solicitation";
1548 *optional = dissect_icmpv6_type146;
1549 return;
1550 case 147:
1551 *type = "Mobile Prefix Advertisement";
1552 *optional = dissect_icmpv6_type147;
1553 return;
1554 case 148:
1555 *type = "Certification Path Solicitation";
1556 *optional = dissect_icmpv6_type148;
1557 return;
1558 case 149:
1559 *type = "Certification Path Advertisement";
1560 *optional = dissect_icmpv6_type149;
1561 return;
1562 case 150:
1563 *type = "ICMP messages utilized by experimental mobility "
1564 "protocols such as Seamoby";
1565 *optional = dissect_icmpv6_type150;
1566 return;
1567 case 151:
1568 *type = "Multicast Router Advertisement";
1569 *code = "Ad. Interval";
1570 *optional = dissect_icmpv6_type151;
1571 return;
1572 case 152:
1573 *type = "Multicast Router Solicitation";
1574 *code = "Reserved";
1575 *optional = dissect_icmpv6_type152;
1576 return;
1577 case 153:
1578 *type = "Multicast Router Termination";
1579 *code = "Reserved";
1580 *optional = dissect_icmpv6_type153;
1581 return;
1582 case 154:
1583 *type = "FMIPv6 Messages";
1584 *optional = dissect_icmpv6_type154;
1585 return;
1586 case 155:
1587 *type = "RPL Control Message";
1588 if(icmpv6_type_155_codes(icmp->h_code))
1589 *code = icmpv6_type_155_codes(icmp->h_code);
1590 return;
1591 case 200:
1592 *type = "Private experimation";
1593 return;
1594 case 201:
1595 *type = "Private experimation";
1596 return;
1597 case 255:
1598 *type = "Reserved for expansion of ICMPv6 error messages";
1599 return;
1603 static void icmpv6(struct pkt_buff *pkt)
1605 const char *type = NULL, *code = NULL;
1606 int8_t (*optional)(struct pkt_buff *pkt) = NULL;
1607 struct icmpv6_general_hdr *icmp =
1608 (struct icmpv6_general_hdr *) pkt_pull(pkt, sizeof(*icmp));
1610 if (icmp == NULL)
1611 return;
1613 icmpv6_process(icmp, &type, &code, &optional);
1615 tprintf(" [ ICMPv6 ");
1616 tprintf("%s (%u), ", type, icmp->h_type);
1617 tprintf("%s (%u), ", code, icmp->h_code);
1618 tprintf("Chks (0x%x)", ntohs(icmp->h_chksum));
1619 if (optional)
1620 if (!((*optional) (pkt)))
1621 tprintf("\n%s%s%s", colorize_start_full(black, red),
1622 "Failed to dissect Message", colorize_end());
1623 tprintf(" ]\n");
1626 static void icmpv6_less(struct pkt_buff *pkt)
1628 struct icmpv6_general_hdr *icmp =
1629 (struct icmpv6_general_hdr *) pkt_pull(pkt, sizeof(*icmp));
1631 if (icmp == NULL)
1632 return;
1634 tprintf(" ICMPv6 Type (%u) Code (%u)", icmp->h_type, icmp->h_code);
1637 struct protocol icmpv6_ops = {
1638 .key = 0x3A,
1639 .print_full = icmpv6,
1640 .print_less = icmpv6_less,