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
9 * Look also for an good overview:
10 * http://www.iana.org/assignments/icmpv6-parameters
13 #ifndef PROTO_ICMPV6_H
14 #define PROTO_ICMPV6_H
18 #include <netinet/in.h>
19 #include <arpa/inet.h>
20 #include <asm/byteorder.h>
23 #include "proto_struct.h"
24 #include "dissector_eth.h"
28 #define icmpv6_code_range_valid(code, sarr) ((code) < array_size((sarr)))
30 struct icmpv6_general_hdr
{
36 /* for type 0x01 and 0x03 */
37 struct icmpv6_type_1_3
{
39 uint8_t invoking_pkt
[0];
42 struct icmpv6_type_2
{
44 uint8_t invoking_pkt
[0];
47 struct icmpv6_type_4
{
49 uint8_t invoking_pkt
[0];
52 struct icmpv6_type_128_129
{
59 struct icmpv6_type_130_131_132
{
62 struct in6_addr ipv6_addr
;
66 struct icmpv6_type_130_mldv2
{
70 struct in6_addr ipv6_addr
[0];
73 /* Neighbor Discovery msg */
74 struct icmpv6_type_133_141_142
{
79 struct icmpv6_type_134
{
80 uint8_t cur_hop_limit
;
82 uint16_t router_lifetime
;
83 uint32_t reachable_time
;
84 uint32_t retrans_timer
;
88 struct icmpv6_type_135
{
90 struct in6_addr ipv6_addr
;
94 struct icmpv6_type_136
{
96 struct in6_addr ipv6_addr
;
100 struct icmpv6_type_137
{
102 struct in6_addr ipv6_targ_addr
;
103 struct in6_addr ipv6_dest_addr
;
107 struct icmpv6_neighb_disc_ops_general
{
113 struct icmpv6_neighb_disc_ops_type_1_2
{
114 uint8_t link_lay_addr
[0];
117 struct icmpv6_neighb_disc_ops_type_3
{
120 uint32_t valid_lifetime
;
121 uint32_t preferred_lifetime
;
123 struct in6_addr prefix
;
126 struct icmpv6_neighb_disc_ops_type_4
{
129 uint8_t ip_hdr_data
[0];
132 struct icmpv6_neighb_disc_ops_type_5
{
137 struct icmpv6_neighb_disc_ops_type_9_10
{
140 uint8_t ip_hdr_data
[0];
143 struct icmpv6_neighb_disc_ops_type_15
{
150 struct icmpv6_neighb_disc_ops_type_16
{
157 struct icmpv6_neighb_disc_ops_type_17
{
163 struct icmpv6_neighb_disc_ops_type_17_1
{
165 struct in6_addr ipv6_addr
;
168 struct icmpv6_neighb_disc_ops_type_17_2
{
169 struct in6_addr ipv6_addr
;
172 struct icmpv6_neighb_disc_ops_type_19
{
176 /* end Neighbor Discovery msg */
178 struct icmpv6_type_138
{
186 /* Node Information Queries */
187 struct icmpv6_type_139_140
{
193 /* end Node Information Queries */
196 struct icmpv6_type_143
{
202 struct icmpv6_mldv2_addr_rec
{
204 uint8_t aux_data_len
;
206 struct in6_addr multic_addr
;
207 struct in6_addr src_addr
[0];
209 /* end MLDv2 report */
211 /* ICMP Mobility Support */
212 struct icmpv6_type_144_146
{
217 struct icmpv6_type_145
{
220 struct in6_addr home_agent_addr
[0];
223 struct icmpv6_type_147
{
228 /* end ICMP Mobility Support */
230 /* SEcure Neighbor Discovery */
231 struct icmpv6_type_148
{
237 struct icmpv6_type_149
{
244 /* end SEcure Neighbor Discovery */
246 struct icmpv6_type_150
{
248 uint32_t subtype_res
;
250 #if defined(__LITTLE_ENDIAN_BITFIELD)
253 #elif defined(__BIG_ENDIAN_BITFIELD)
257 # error "Please fix <asm/byteorder.h>"
264 /* Multicast Router Discovery */
265 struct icmpv6_type_151
{
270 struct icmpv6_type_152
{
274 struct icmpv6_type_153
{
277 /* end Multicast Router Discovery */
279 struct icmpv6_type_154
{
286 static inline void print_ipv6_addr_list(struct pkt_buff
*pkt
, uint8_t nr_addr
)
288 char address
[INET6_ADDRSTRLEN
];
289 struct in6_addr
*addr
;
292 addr
= (struct in6_addr
*) pkt_pull(pkt
, sizeof(*addr
));
296 tprintf("\n\t Address: %s",
297 inet_ntop(AF_INET6
, addr
, address
,
302 static char *icmpv6_mcast_rec_types
[] = {
305 "CHANGE_TO_INCLUDE_MODE",
306 "CHANGE_TO_EXCLUDE_MODE",
311 static inline void dissect_icmpv6_mcast_rec(struct pkt_buff
*pkt
,
314 size_t aux_data_len_bytes
;
316 struct icmpv6_mldv2_addr_rec
*addr_rec
;
319 addr_rec
= (struct icmpv6_mldv2_addr_rec
*)
320 pkt_pull(pkt
,sizeof(*addr_rec
));
321 if (addr_rec
== NULL
)
323 aux_data_len_bytes
= addr_rec
->aux_data_len
* 4;
324 nr_src
= ntohs(addr_rec
->nr_src
);
326 tprintf(", Rec Type %s (%u)",
327 icmpv6_code_range_valid(addr_rec
->rec_type
- 1,
328 icmpv6_mcast_rec_types
) ?
329 icmpv6_mcast_rec_types
[addr_rec
->rec_type
- 1]
330 : "Unknown", addr_rec
->rec_type
);
331 tprintf(", Aux Data Len (%u, %u bytes)",addr_rec
->aux_data_len
,
333 tprintf(", Nr. of Sources (%u)",nr_src
);
335 print_ipv6_addr_list(pkt
, nr_src
);
337 tprintf(", Aux Data: ");
338 while (aux_data_len_bytes
--) {
339 tprintf("%x", *pkt_pull(pkt
,1));
344 static inline void dissect_neighb_disc_ops_1(struct pkt_buff
*pkt
, size_t len
)
346 struct icmpv6_neighb_disc_ops_type_1_2
*icmp_neighb_disc_1
;
348 icmp_neighb_disc_1
= (struct icmpv6_neighb_disc_ops_type_1_2
*)
349 pkt_pull(pkt
,sizeof(*icmp_neighb_disc_1
));
350 if (icmp_neighb_disc_1
== NULL
)
352 len
-= sizeof(*icmp_neighb_disc_1
);
354 tprintf("Address 0x");
357 tprintf("%x", *pkt_pull(pkt
,1));
361 static inline void dissect_neighb_disc_ops_2(struct pkt_buff
*pkt
, size_t len
)
363 dissect_neighb_disc_ops_1(pkt
, len
);
366 static inline void dissect_neighb_disc_ops_3(struct pkt_buff
*pkt
, size_t len
)
368 char address
[INET6_ADDRSTRLEN
];
369 struct icmpv6_neighb_disc_ops_type_3
*icmp_neighb_disc_3
;
371 icmp_neighb_disc_3
= (struct icmpv6_neighb_disc_ops_type_3
*)
372 pkt_pull(pkt
,sizeof(*icmp_neighb_disc_3
));
373 if (icmp_neighb_disc_3
== NULL
)
375 len
-= sizeof(*icmp_neighb_disc_3
);
377 tprintf("Prefix Len (%u) ",icmp_neighb_disc_3
->prefix_len
);
378 tprintf("L (%u) A (%u) Res1 (0x%x) ",icmp_neighb_disc_3
->l_a_res1
>> 7,
379 (icmp_neighb_disc_3
->l_a_res1
>> 7) & 0x1,
380 icmp_neighb_disc_3
->l_a_res1
& 0x3F);
381 tprintf("Valid Lifetime (%us) ",
382 ntohl(icmp_neighb_disc_3
->valid_lifetime
));
383 tprintf("Preferred Lifetime (%us) ",
384 ntohl(icmp_neighb_disc_3
->preferred_lifetime
));
385 tprintf("Reserved2 (0x%x) ",
386 ntohl(icmp_neighb_disc_3
->res2
));
387 tprintf("Prefix: %s ",
388 inet_ntop(AF_INET6
,&icmp_neighb_disc_3
->prefix
,
389 address
, sizeof(address
)));
392 static inline void dissect_neighb_disc_ops_4(struct pkt_buff
*pkt
, size_t len
)
394 struct icmpv6_neighb_disc_ops_type_4
*icmp_neighb_disc_4
;
396 icmp_neighb_disc_4
= (struct icmpv6_neighb_disc_ops_type_4
*)
397 pkt_pull(pkt
,sizeof(*icmp_neighb_disc_4
));
398 if (icmp_neighb_disc_4
== NULL
)
400 len
-= sizeof(*icmp_neighb_disc_4
);
402 tprintf("Reserved 1 (0x%x) ", ntohs(icmp_neighb_disc_4
->res1
));
403 tprintf("Reserved 2 (0x%x) ", ntohl(icmp_neighb_disc_4
->res2
));
404 tprintf("IP header + data ");
407 tprintf("%x", *pkt_pull(pkt
,1));
411 static inline void dissect_neighb_disc_ops_5(struct pkt_buff
*pkt
, size_t len
)
413 struct icmpv6_neighb_disc_ops_type_5
*icmp_neighb_disc_5
;
415 icmp_neighb_disc_5
= (struct icmpv6_neighb_disc_ops_type_5
*)
416 pkt_pull(pkt
,sizeof(*icmp_neighb_disc_5
));
417 if (icmp_neighb_disc_5
== NULL
)
419 len
-= sizeof(*icmp_neighb_disc_5
);
421 tprintf("Reserved (0x%x) ", ntohs(icmp_neighb_disc_5
->res1
));
422 tprintf("MTU (%u)", ntohl(icmp_neighb_disc_5
->MTU
));
425 static inline void dissect_neighb_disc_ops_9(struct pkt_buff
*pkt
, size_t len
)
427 struct icmpv6_neighb_disc_ops_type_9_10
*icmp_neighb_disc_9
;
429 icmp_neighb_disc_9
= (struct icmpv6_neighb_disc_ops_type_9_10
*)
430 pkt_pull(pkt
,sizeof(*icmp_neighb_disc_9
));
431 if (icmp_neighb_disc_9
== NULL
)
433 len
-= sizeof(*icmp_neighb_disc_9
);
435 tprintf("Reserved 1 (0x%x) ", ntohs(icmp_neighb_disc_9
->res1
));
436 tprintf("Reserved 2 (0x%x) ", ntohl(icmp_neighb_disc_9
->res2
));
438 print_ipv6_addr_list(pkt
, len
/ sizeof(struct in6_addr
));
441 static inline void dissect_neighb_disc_ops_10(struct pkt_buff
*pkt
, size_t len
)
443 dissect_neighb_disc_ops_9(pkt
, len
);
446 static char *icmpv6_neighb_disc_ops_15_name
[] = {
447 "DER Encoded X.501 Name",
451 static inline void dissect_neighb_disc_ops_15(struct pkt_buff
*pkt
, size_t len
)
453 uint8_t name_len
, pad_len
;
454 struct icmpv6_neighb_disc_ops_type_15
*icmp_neighb_disc_15
;
456 icmp_neighb_disc_15
= (struct icmpv6_neighb_disc_ops_type_15
*)
457 pkt_pull(pkt
,sizeof(*icmp_neighb_disc_15
));
458 if (icmp_neighb_disc_15
== NULL
)
460 len
-= sizeof(*icmp_neighb_disc_15
);
461 pad_len
= icmp_neighb_disc_15
->pad_len
;
462 name_len
= len
- pad_len
;
464 tprintf("Name Type %s (%u) ",
465 icmpv6_code_range_valid(icmp_neighb_disc_15
->name_type
- 1,
466 icmpv6_neighb_disc_ops_15_name
) ?
467 icmpv6_neighb_disc_ops_15_name
[
468 icmp_neighb_disc_15
->name_type
- 1] : "Unknown",
469 icmp_neighb_disc_15
->name_type
);
470 tprintf("Pad Len (0x%x) ", icmp_neighb_disc_15
->pad_len
);
474 tprintf("%c", *pkt_pull(pkt
,1));
478 tprintf("Padding (");
481 tprintf("%x", *pkt_pull(pkt
,1));
486 static char *icmpv6_neighb_disc_ops_16_cert
[] = {
487 "X.509v3 Certificate",
490 static inline void dissect_neighb_disc_ops_16(struct pkt_buff
*pkt
, size_t len
)
492 struct icmpv6_neighb_disc_ops_type_16
*icmp_neighb_disc_16
;
494 icmp_neighb_disc_16
= (struct icmpv6_neighb_disc_ops_type_16
*)
495 pkt_pull(pkt
,sizeof(*icmp_neighb_disc_16
));
496 if (icmp_neighb_disc_16
== NULL
)
498 len
-= sizeof(*icmp_neighb_disc_16
);
500 tprintf("Cert Type %s (%u) ",
501 icmpv6_code_range_valid(icmp_neighb_disc_16
->cert_type
- 1,
502 icmpv6_neighb_disc_ops_16_cert
) ?
503 icmpv6_neighb_disc_ops_16_cert
[
504 icmp_neighb_disc_16
->cert_type
- 1] : "Unknown",
505 icmp_neighb_disc_16
->cert_type
);
506 tprintf("Res (0x%x) ", icmp_neighb_disc_16
->res
);
508 tprintf("Certificate + Padding (");
510 tprintf("%x", *pkt_pull(pkt
,1));
515 static char *icmpv6_neighb_disc_ops_17_codes
[] = {
516 "Old Care-of Address",
517 "New Care-of Address",
522 static inline void dissect_neighb_disc_ops_17(struct pkt_buff
*pkt
, size_t len
)
524 char address
[INET6_ADDRSTRLEN
];
525 struct icmpv6_neighb_disc_ops_type_17
*icmp_neighb_disc_17
;
527 icmp_neighb_disc_17
= (struct icmpv6_neighb_disc_ops_type_17
*)
528 pkt_pull(pkt
,sizeof(*icmp_neighb_disc_17
));
529 if (icmp_neighb_disc_17
== NULL
)
531 len
-= sizeof(*icmp_neighb_disc_17
);
533 tprintf("Opt Code %s (%u) ",
534 icmpv6_code_range_valid(icmp_neighb_disc_17
->opt_code
- 1,
535 icmpv6_neighb_disc_ops_17_codes
) ?
536 icmpv6_neighb_disc_ops_17_codes
[
537 icmp_neighb_disc_17
->opt_code
- 1] : "Unknown",
538 icmp_neighb_disc_17
->opt_code
);
539 tprintf("Prefix Len (%u) ", icmp_neighb_disc_17
->prefix_len
);
541 if (len
== sizeof(struct icmpv6_neighb_disc_ops_type_17_1
)) {
542 struct icmpv6_neighb_disc_ops_type_17_1
543 *icmp_neighb_disc_17_1
;
545 icmp_neighb_disc_17_1
=
546 (struct icmpv6_neighb_disc_ops_type_17_1
*)
547 pkt_pull(pkt
,sizeof(*icmp_neighb_disc_17_1
));
548 if (icmp_neighb_disc_17_1
== NULL
)
550 len
-= sizeof(*icmp_neighb_disc_17_1
);
552 tprintf("Res (0x%x) ",icmp_neighb_disc_17_1
->res
);
554 inet_ntop(AF_INET6
,&icmp_neighb_disc_17_1
->ipv6_addr
,
555 address
, sizeof(address
)));
557 else if (len
== sizeof(struct icmpv6_neighb_disc_ops_type_17_1
)) {
558 struct icmpv6_neighb_disc_ops_type_17_2
559 *icmp_neighb_disc_17_2
;
561 icmp_neighb_disc_17_2
=
562 (struct icmpv6_neighb_disc_ops_type_17_2
*)
563 pkt_pull(pkt
,sizeof(*icmp_neighb_disc_17_2
));
564 if (icmp_neighb_disc_17_2
== NULL
)
566 len
-= sizeof(*icmp_neighb_disc_17_2
);
569 inet_ntop(AF_INET6
,&icmp_neighb_disc_17_2
->ipv6_addr
,
570 address
, sizeof(address
)));
573 tprintf("Error Wrong Params (");
575 tprintf("%x", *pkt_pull(pkt
,1));
580 static char *icmpv6_neighb_disc_ops_19_codes
[] = {
581 "Wildcard requesting resolution for all nearby access points",
582 "Link-Layer Address of the New Access Point",
583 "Link-Layer Address of the MN",
584 "Link-Layer Address of the NAR",
585 "Link-Layer Address of the source of RtSolPr or PrRtAdv \
587 "The access point identified by the LLA belongs to the \
588 current interface of the router",
589 "No prefix information available for the access point \
590 identified by the LLA",
591 "No fast handover support available for the access point \
592 identified by the LLA",
595 static inline void dissect_neighb_disc_ops_19(struct pkt_buff
*pkt
, size_t len
)
597 struct icmpv6_neighb_disc_ops_type_19
*icmp_neighb_disc_19
;
599 icmp_neighb_disc_19
= (struct icmpv6_neighb_disc_ops_type_19
*)
600 pkt_pull(pkt
,sizeof(*icmp_neighb_disc_19
));
601 if (icmp_neighb_disc_19
== NULL
)
603 len
-= sizeof(*icmp_neighb_disc_19
);
605 tprintf("Opt Code %s (%u) ",
606 icmpv6_code_range_valid(icmp_neighb_disc_19
->opt_code
,
607 icmpv6_neighb_disc_ops_19_codes
) ?
608 icmpv6_neighb_disc_ops_19_codes
[
609 icmp_neighb_disc_19
->opt_code
] : "Unknown",
610 icmp_neighb_disc_19
->opt_code
);
614 tprintf("%x", *pkt_pull(pkt
,1));
619 static inline char *icmpv6_neighb_disc_ops(uint8_t code
) {
622 return "Source Link-Layer Address";
624 return "Target Link-Layer Address";
626 return "Prefix Information";
628 return "Redirected Header";
632 return "NBMA Shortcut Limit Option";
634 return "Advertisement Interval Option";
636 return "Home Agent Information Option";
638 return "Source Address List";
640 return "Target Address List";
644 return "RSA Signature option";
646 return "Timestamp option";
648 return "Nonce option";
650 return "Trust Anchor option";
652 return "Certificate option";
654 return "IP Address/Prefix Option";
656 return "New Router Prefix Information Option";
658 return "Link-layer Address Option";
660 return "Neighbor Advertisement Acknowledgment Option";
663 return "Prefix Information";
665 return "Redirected Header";
669 return "NBMA Shortcut Limit Option";
671 return "Advertisement Interval Option";
673 return "Home Agent Information Option";
675 return "Source Address List";
677 return "Target Address List";
679 return "DNS Search List Option";
681 return "Proxy Signature (PS)";
684 return "CARD Request option";
686 return "CARD Reply option";
689 return "RFC3692-style Experiment 1";
691 return "RFC3692-style Experiment 2";
697 static inline void dissect_neighb_disc_ops(struct pkt_buff
*pkt
)
699 size_t ops_total_len
, ops_payl_len
, pad_bytes
;
700 struct icmpv6_neighb_disc_ops_general
*icmp_neighb_disc
;
702 while(pkt_len(pkt
)) {
703 icmp_neighb_disc
= (struct icmpv6_neighb_disc_ops_general
*)
704 pkt_pull(pkt
,sizeof(*icmp_neighb_disc
));
705 if (icmp_neighb_disc
== NULL
)
708 ops_total_len
= icmp_neighb_disc
->len
* 8;
709 pad_bytes
= ops_total_len
% 8;
710 ops_payl_len
= ops_total_len
- sizeof(*icmp_neighb_disc
) -
713 tprintf("\n\tOption %s (%u) ",
714 icmpv6_neighb_disc_ops(icmp_neighb_disc
->type
) ?
715 icmpv6_neighb_disc_ops(icmp_neighb_disc
->type
)
716 : "Type Unknown", icmp_neighb_disc
->type
);
717 tprintf("Length (%u, %u bytes) ", icmp_neighb_disc
->len
,
720 switch (icmp_neighb_disc
->type
) {
722 dissect_neighb_disc_ops_1(pkt
, ops_payl_len
);
725 dissect_neighb_disc_ops_2(pkt
, ops_payl_len
);
728 dissect_neighb_disc_ops_3(pkt
, ops_payl_len
);
731 dissect_neighb_disc_ops_4(pkt
, ops_payl_len
);
734 dissect_neighb_disc_ops_5(pkt
, ops_payl_len
);
736 /* Type 9 and 10 defined in
737 * http://tools.ietf.org/html/rfc3122#section-3.1
740 dissect_neighb_disc_ops_9(pkt
, ops_payl_len
);
743 dissect_neighb_disc_ops_10(pkt
, ops_payl_len
);
745 /* Type 15 and 16 defined in
746 * http://tools.ietf.org/html/rfc3971#section-6.4.3
747 * http://tools.ietf.org/html/rfc3971#section-6.4.4
750 dissect_neighb_disc_ops_15(pkt
, ops_payl_len
);
753 dissect_neighb_disc_ops_16(pkt
, ops_payl_len
);
755 /* Type 17 and 19 defined in
756 * http://tools.ietf.org/html/rfc5568#section-6.4
759 dissect_neighb_disc_ops_17(pkt
, ops_payl_len
);
762 dissect_neighb_disc_ops_19(pkt
, ops_payl_len
);
765 pkt_pull(pkt
, ops_payl_len
);
768 /* Skip Padding Bytes */
769 pkt_pull(pkt
, pad_bytes
);
773 static char *icmpv6_type_1_codes
[] = {
774 "No route to destination",
775 "Communication with destination administratively prohibited",
776 "Beyond scope of source address",
777 "Address unreachable",
779 "Source address failed ingress/egress policy",
780 "Reject route to destination",
781 "Error in Source Routing Header",
784 static inline void dissect_icmpv6_type1(struct pkt_buff
*pkt
)
786 struct icmpv6_type_1_3
*icmp_1
;
788 icmp_1
= (struct icmpv6_type_1_3
*) pkt_pull(pkt
,sizeof(*icmp_1
));
792 tprintf(", Unused (0x%x)",ntohl(icmp_1
->unused
));
793 tprintf(" Payload include as much of invoking packet");
796 static inline void dissect_icmpv6_type2(struct pkt_buff
*pkt
)
798 struct icmpv6_type_2
*icmp_2
;
800 icmp_2
= (struct icmpv6_type_2
*) pkt_pull(pkt
,sizeof(*icmp_2
));
804 tprintf(", MTU (0x%x)",ntohl(icmp_2
->MTU
));
805 tprintf(" Payload include as much of invoking packet");
808 static char *icmpv6_type_3_codes
[] = {
809 "Hop limit exceeded in transit",
810 "Fragment reassembly time exceeded",
813 static inline void dissect_icmpv6_type3(struct pkt_buff
*pkt
)
815 struct icmpv6_type_1_3
*icmp_3
;
817 icmp_3
= (struct icmpv6_type_1_3
*) pkt_pull(pkt
,sizeof(*icmp_3
));
821 tprintf(", Unused (0x%x)",ntohl(icmp_3
->unused
));
822 tprintf(" Payload include as much of invoking packet");
825 static char *icmpv6_type_4_codes
[] = {
826 "Erroneous header field encountered",
827 "Unrecognized Next Header type encountered",
828 "Unrecognized IPv6 option encountered",
831 static inline void dissect_icmpv6_type4(struct pkt_buff
*pkt
)
833 struct icmpv6_type_4
*icmp_4
;
835 icmp_4
= (struct icmpv6_type_4
*) pkt_pull(pkt
,sizeof(*icmp_4
));
839 tprintf(", Pointer (0x%x)",ntohl(icmp_4
->pointer
));
840 tprintf(" Payload include as much of invoking packet");
843 static inline void dissect_icmpv6_type128(struct pkt_buff
*pkt
)
845 struct icmpv6_type_128_129
*icmp_128
;
847 icmp_128
= (struct icmpv6_type_128_129
*)
848 pkt_pull(pkt
,sizeof(*icmp_128
));
849 if (icmp_128
== NULL
)
852 tprintf(", ID (0x%x)",ntohs(icmp_128
->id
));
853 tprintf(", Seq. Nr. (%u)",ntohs(icmp_128
->sn
));
854 tprintf(" Payload include Data");
857 static inline void dissect_icmpv6_type129(struct pkt_buff
*pkt
)
859 struct icmpv6_type_128_129
*icmp_129
;
861 icmp_129
= (struct icmpv6_type_128_129
*)
862 pkt_pull(pkt
,sizeof(*icmp_129
));
863 if (icmp_129
== NULL
)
866 tprintf(", ID (0x%x)",ntohs(icmp_129
->id
));
867 tprintf(", Seq. Nr. (%u)",ntohs(icmp_129
->sn
));
868 tprintf(" Payload include Data");
871 static inline void dissect_icmpv6_type130(struct pkt_buff
*pkt
)
873 char address
[INET6_ADDRSTRLEN
];
874 uint16_t nr_src
, maxrespdel
;
875 uint8_t switch_mldv2
= 0;
876 struct icmpv6_type_130_131_132
*icmp_130
;
878 icmp_130
= (struct icmpv6_type_130_131_132
*)
879 pkt_pull(pkt
,sizeof(*icmp_130
));
880 if (icmp_130
== NULL
)
882 maxrespdel
= ntohs(icmp_130
->maxrespdel
);
884 if(pkt_len(pkt
) >= sizeof(struct icmpv6_type_130_mldv2
))
888 tprintf(", MLDv2, Max Resp Delay (%ums)", maxrespdel
>> 15 ?
889 (((maxrespdel
& 0xFFF) | 0x1000) <<
890 (((maxrespdel
>> 12) & 0x3) + 3)) : maxrespdel
);
892 tprintf(", Max Resp Delay (%ums)",maxrespdel
);
893 tprintf(", Res (0x%x)",ntohs(icmp_130
->res
));
894 tprintf(", Address: %s",
895 inet_ntop(AF_INET6
, &icmp_130
->ipv6_addr
,
896 address
, sizeof(address
)));
899 struct icmpv6_type_130_mldv2
*icmp_130_mldv2
;
901 icmp_130_mldv2
= (struct icmpv6_type_130_mldv2
*)
902 pkt_pull(pkt
,sizeof(*icmp_130_mldv2
));
903 if (icmp_130_mldv2
== NULL
)
906 nr_src
= ntohs(icmp_130_mldv2
->nr_src
);
908 tprintf(", Resv (0x%x)",icmp_130_mldv2
->resv_S_QRV
>> 4);
909 tprintf(", S (%u)",(icmp_130_mldv2
->resv_S_QRV
>> 3) & 0x1);
910 tprintf(", QRV (0x%x)",icmp_130_mldv2
->resv_S_QRV
& 0x3);
911 tprintf(", QQIC (%u)",icmp_130_mldv2
->QQIC
);
912 tprintf(", Nr Src (0x%x)",nr_src
);
914 print_ipv6_addr_list(pkt
, nr_src
);
918 static inline void dissect_icmpv6_type131(struct pkt_buff
*pkt
)
920 char address
[INET6_ADDRSTRLEN
];
921 struct icmpv6_type_130_131_132
*icmp_131
;
923 icmp_131
= (struct icmpv6_type_130_131_132
*)
924 pkt_pull(pkt
,sizeof(*icmp_131
));
925 if (icmp_131
== NULL
)
928 tprintf(", Max Resp Delay (%ums)",ntohs(icmp_131
->maxrespdel
));
929 tprintf(", Res (0x%x)",ntohs(icmp_131
->res
));
930 tprintf(", Address: %s",
931 inet_ntop(AF_INET6
, &icmp_131
->ipv6_addr
,
932 address
, sizeof(address
)));
935 static inline void dissect_icmpv6_type132(struct pkt_buff
*pkt
)
937 dissect_icmpv6_type131(pkt
);
940 static inline void dissect_icmpv6_type133(struct pkt_buff
*pkt
)
942 struct icmpv6_type_133_141_142
*icmp_133
;
944 icmp_133
= (struct icmpv6_type_133_141_142
*)
945 pkt_pull(pkt
,sizeof(*icmp_133
));
946 if (icmp_133
== NULL
)
949 tprintf(", Reserved (0x%x)",ntohl(icmp_133
->res
));
951 dissect_neighb_disc_ops(pkt
);
954 static inline void dissect_icmpv6_type134(struct pkt_buff
*pkt
)
956 struct icmpv6_type_134
*icmp_134
;
958 icmp_134
= (struct icmpv6_type_134
*)
959 pkt_pull(pkt
,sizeof(*icmp_134
));
960 if (icmp_134
== NULL
)
963 tprintf(", Cur Hop Limit (%u)",icmp_134
->cur_hop_limit
);
964 tprintf(", M (%u) O (%u)",icmp_134
->m_o_res
>> 7,
965 (icmp_134
->m_o_res
>> 6) & 0x1);
966 tprintf(", Router Lifetime (%us)",ntohs(icmp_134
->router_lifetime
));
967 tprintf(", Reachable Time (%ums)",ntohl(icmp_134
->reachable_time
));
968 tprintf(", Retrans Timer (%ums)",ntohl(icmp_134
->retrans_timer
));
970 dissect_neighb_disc_ops(pkt
);
973 static inline void dissect_icmpv6_type135(struct pkt_buff
*pkt
)
975 char address
[INET6_ADDRSTRLEN
];
976 struct icmpv6_type_135
*icmp_135
;
978 icmp_135
= (struct icmpv6_type_135
*)
979 pkt_pull(pkt
,sizeof(*icmp_135
));
980 if (icmp_135
== NULL
)
983 tprintf(", Reserved (0x%x)",ntohl(icmp_135
->res
));
984 tprintf(", Target Address: %s",
985 inet_ntop(AF_INET6
, &icmp_135
->ipv6_addr
,
986 address
, sizeof(address
)));
988 dissect_neighb_disc_ops(pkt
);
991 static inline void dissect_icmpv6_type136(struct pkt_buff
*pkt
)
993 char address
[INET6_ADDRSTRLEN
];
995 struct icmpv6_type_136
*icmp_136
;
997 icmp_136
= (struct icmpv6_type_136
*)
998 pkt_pull(pkt
,sizeof(*icmp_136
));
999 if (icmp_136
== NULL
)
1001 r_s_o_res
= ntohl(icmp_136
->r_s_o_res
);
1003 tprintf(", R (%u) S (%u) O (%u) Reserved (0x%x)", r_s_o_res
>> 31,
1004 (r_s_o_res
>> 30) & 0x1, (r_s_o_res
>> 29) & 0x1,
1005 r_s_o_res
& 0x1FFFFFFF);
1006 tprintf(", Target Address: %s",
1007 inet_ntop(AF_INET6
, &icmp_136
->ipv6_addr
,
1008 address
, sizeof(address
)));
1010 dissect_neighb_disc_ops(pkt
);
1013 static inline void dissect_icmpv6_type137(struct pkt_buff
*pkt
)
1015 char address
[INET6_ADDRSTRLEN
];
1016 struct icmpv6_type_137
*icmp_137
;
1018 icmp_137
= (struct icmpv6_type_137
*)
1019 pkt_pull(pkt
,sizeof(*icmp_137
));
1020 if (icmp_137
== NULL
)
1023 tprintf(", Reserved (0x%x)",icmp_137
->res
);
1024 tprintf(", Target Address: %s",
1025 inet_ntop(AF_INET6
, &icmp_137
->ipv6_targ_addr
,
1026 address
, sizeof(address
)));
1027 tprintf(", Dest Address: %s",
1028 inet_ntop(AF_INET6
, &icmp_137
->ipv6_dest_addr
,
1029 address
, sizeof(address
)));
1031 dissect_neighb_disc_ops(pkt
);
1034 static inline void dissect_icmpv6_rr_body(struct pkt_buff
*pkt
)
1037 * Upgrade Dissector for Message Body
1038 * from http://tools.ietf.org/html/rfc2894#section-3.2
1041 tprintf(" Message Body recognized");
1044 static inline char *icmpv6_type_138_codes(uint8_t code
) {
1047 return "Router Renumbering Command";
1049 return "Router Renumbering Result";
1051 return "Sequence Number Reset";
1057 static inline void dissect_icmpv6_type138(struct pkt_buff
*pkt
)
1059 struct icmpv6_type_138
*icmp_138
;
1061 icmp_138
= (struct icmpv6_type_138
*)
1062 pkt_pull(pkt
,sizeof(*icmp_138
));
1063 if (icmp_138
== NULL
)
1066 tprintf(", Sequence Nr. (%u)",ntohl(icmp_138
->seq_nr
));
1067 tprintf(", Segment Nr. (%u)",icmp_138
->seg_nr
);
1068 tprintf(", T (%u) R (%u) A (%u) S (%u) P (%u) Res \
1069 (0x%x) ",icmp_138
->flags
>> 7, (icmp_138
->flags
>> 6) & 1,
1070 (icmp_138
->flags
>> 5) & 1, (icmp_138
->flags
>> 4) & 1,
1071 (icmp_138
->flags
>> 3) & 1, icmp_138
->flags
& 7);
1072 tprintf(", Max Delay (%ums)", ntohs(icmp_138
->maxdelay
));
1073 tprintf(", Res (0x%x)", ntohl(icmp_138
->res
));
1075 dissect_icmpv6_rr_body(pkt
);
1078 static inline void dissect_icmpv6_node_inf_data(struct pkt_buff
*pkt
)
1081 * Upgrade Dissector for Data field
1082 * http://tools.ietf.org/html/rfc4620#section-4
1085 tprintf(" Data recognized");
1088 static char *icmpv6_node_inf_qtypes
[] = {
1096 static char *icmpv6_type_139_codes
[] = {
1097 "Data contains IPv6 Address",
1098 "Data contains Name or nothing",
1099 "Data contains IPv4 Address",
1102 static inline void dissect_icmpv6_type139(struct pkt_buff
*pkt
)
1104 char *qtype_name
= "Unknown";
1106 struct icmpv6_type_139_140
*icmp_139
;
1108 icmp_139
= (struct icmpv6_type_139_140
*)
1109 pkt_pull(pkt
,sizeof(*icmp_139
));
1110 if (icmp_139
== NULL
)
1113 qtype_nr
= ntohs(icmp_139
->qtype
);
1114 if (icmpv6_code_range_valid(qtype_nr
, icmpv6_node_inf_qtypes
))
1115 qtype_name
= icmpv6_node_inf_qtypes
[qtype_nr
];
1117 tprintf(", Qtype %s (%u)",qtype_name
, qtype_nr
);
1118 tprintf(", Flags (0x%x)",ntohs(icmp_139
->flags
));
1119 tprintf(", Nonce (0x%x)",ntohll(icmp_139
->nonce
));
1121 dissect_icmpv6_node_inf_data(pkt
);
1124 static char *icmpv6_type_140_codes
[] = {
1125 "Successfull reply",
1126 "Responder refuses answer",
1127 "Qtype is unknown to the Responder",
1130 static inline void dissect_icmpv6_type140(struct pkt_buff
*pkt
)
1132 dissect_icmpv6_type139(pkt
);
1135 static inline void dissect_icmpv6_type141(struct pkt_buff
*pkt
)
1137 dissect_icmpv6_type133(pkt
);
1140 static inline void dissect_icmpv6_type142(struct pkt_buff
*pkt
)
1142 dissect_icmpv6_type133(pkt
);
1145 static inline void dissect_icmpv6_type143(struct pkt_buff
*pkt
)
1148 struct icmpv6_type_143
*icmp_143
;
1150 icmp_143
= (struct icmpv6_type_143
*)
1151 pkt_pull(pkt
,sizeof(*icmp_143
));
1152 if (icmp_143
== NULL
)
1154 nr_rec
= ntohs(icmp_143
->nr_rec
);
1156 tprintf(", Res (0x%x)",ntohs(icmp_143
->res
));
1157 tprintf(", Nr. Mcast Addr Records (%u)",nr_rec
);
1159 dissect_icmpv6_mcast_rec(pkt
, nr_rec
);
1162 static inline void dissect_icmpv6_type144(struct pkt_buff
*pkt
)
1164 struct icmpv6_type_144_146
*icmp_144
;
1166 icmp_144
= (struct icmpv6_type_144_146
*)
1167 pkt_pull(pkt
,sizeof(*icmp_144
));
1168 if (icmp_144
== NULL
)
1171 tprintf(", ID (%u)",ntohs(icmp_144
->id
));
1172 tprintf(", Res (0x%x)",ntohs(icmp_144
->res
));
1175 static inline void dissect_icmpv6_type145(struct pkt_buff
*pkt
)
1177 struct icmpv6_type_145
*icmp_145
;
1179 icmp_145
= (struct icmpv6_type_145
*)
1180 pkt_pull(pkt
,sizeof(*icmp_145
));
1181 if (icmp_145
== NULL
)
1184 tprintf(", ID (%u)",ntohs(icmp_145
->id
));
1185 tprintf(", Res (0x%x)",ntohs(icmp_145
->res
));
1187 print_ipv6_addr_list(pkt
, pkt_len(pkt
) / sizeof(struct in6_addr
));
1190 static inline void dissect_icmpv6_type146(struct pkt_buff
*pkt
)
1192 dissect_icmpv6_type144(pkt
);
1195 static inline void dissect_icmpv6_type147(struct pkt_buff
*pkt
)
1198 struct icmpv6_type_147
*icmp_147
;
1200 icmp_147
= (struct icmpv6_type_147
*)
1201 pkt_pull(pkt
,sizeof(*icmp_147
));
1202 if (icmp_147
== NULL
)
1204 m_o_res
= ntohs(icmp_147
->m_o_res
);
1206 tprintf(", ID (%u)",ntohs(icmp_147
->id
));
1207 tprintf(", M (%u) O (%u) Res (0x%x)",m_o_res
>> 15,
1208 (m_o_res
>> 14) & 1, m_o_res
& 0x3FFF);
1210 dissect_neighb_disc_ops(pkt
);
1213 static inline void dissect_icmpv6_type148(struct pkt_buff
*pkt
)
1215 struct icmpv6_type_148
*icmp_148
;
1217 icmp_148
= (struct icmpv6_type_148
*)
1218 pkt_pull(pkt
,sizeof(*icmp_148
));
1219 if (icmp_148
== NULL
)
1222 tprintf(", ID (%u)",ntohs(icmp_148
->id
));
1223 tprintf(", Component (%u)",ntohs(icmp_148
->comp
));
1225 dissect_neighb_disc_ops(pkt
);
1228 static inline void dissect_icmpv6_type149(struct pkt_buff
*pkt
)
1230 struct icmpv6_type_149
*icmp_149
;
1232 icmp_149
= (struct icmpv6_type_149
*)
1233 pkt_pull(pkt
,sizeof(*icmp_149
));
1234 if (icmp_149
== NULL
)
1237 tprintf(", ID (%u)",ntohs(icmp_149
->id
));
1238 tprintf(", All Components (%u)",ntohs(icmp_149
->all_comp
));
1239 tprintf(", Component (%u)",ntohs(icmp_149
->comp
));
1240 tprintf(", Res (0x%x)",ntohs(icmp_149
->res
));
1242 dissect_neighb_disc_ops(pkt
);
1245 static inline void dissect_icmpv6_type150(struct pkt_buff
*pkt
)
1247 struct icmpv6_type_150
*icmp_150
;
1249 icmp_150
= (struct icmpv6_type_150
*)
1250 pkt_pull(pkt
,sizeof(*icmp_150
));
1251 if (icmp_150
== NULL
)
1254 tprintf(", Subtype (%u)",icmp_150
->subtype
);
1255 tprintf(", Res (0x%x)",icmp_150
->res
);
1256 tprintf(", Options in Payload");
1259 static inline void dissect_icmpv6_type151(struct pkt_buff
*pkt
)
1261 struct icmpv6_type_151
*icmp_151
;
1263 icmp_151
= (struct icmpv6_type_151
*)
1264 pkt_pull(pkt
,sizeof(*icmp_151
));
1265 if (icmp_151
== NULL
)
1268 tprintf(", Query Interval (%us)",ntohs(icmp_151
->query_intv
));
1269 tprintf(", Robustness Variable (%u)",ntohs(icmp_151
->rob_var
));
1272 static inline void dissect_icmpv6_type152(struct pkt_buff
*pkt
)
1274 struct icmpv6_type_152
*icmp_152
;
1276 icmp_152
= (struct icmpv6_type_152
*)
1277 pkt_pull(pkt
,sizeof(*icmp_152
));
1278 if (icmp_152
== NULL
)
1282 static inline void dissect_icmpv6_type153(struct pkt_buff
*pkt
)
1284 struct icmpv6_type_153
*icmp_153
;
1286 icmp_153
= (struct icmpv6_type_153
*)
1287 pkt_pull(pkt
,sizeof(*icmp_153
));
1288 if (icmp_153
== NULL
)
1292 static inline void dissect_icmpv6_type154(struct pkt_buff
*pkt
)
1294 struct icmpv6_type_154
*icmp_154
;
1296 icmp_154
= (struct icmpv6_type_154
*)
1297 pkt_pull(pkt
,sizeof(*icmp_154
));
1298 if (icmp_154
== NULL
)
1301 tprintf(", Subtype (%u)",icmp_154
->subtype
);
1302 tprintf(", Res (0x%x)",icmp_154
->res
);
1303 tprintf(", ID (%u)",ntohs(icmp_154
->id
));
1305 dissect_neighb_disc_ops(pkt
);
1308 static inline char *icmpv6_type_155_codes(uint8_t code
) {
1311 return "DODAG Information Solicitation";
1313 return "DODAG Information Object";
1315 return "Destination Advertisement Object";
1317 return "Destination Advertisement Object Acknowledgment";
1319 return "Secure DODAG Information Solicitation";
1321 return "Secure DODAG Information Object";
1323 return "Secure Destination Advertisement Object";
1325 return "Secure Destination Advertisement Object Acknowledgment";
1327 return "Consistency Check";
1333 static inline void icmpv6_process(struct icmpv6_general_hdr
*icmp
, char **type
,
1335 void (**optional
)(struct pkt_buff
*pkt
))
1337 *type
= "Unknown Type";
1338 *code
= "Unknown Code";
1340 switch (icmp
->h_type
) {
1342 *type
= "Destination Unreachable";
1343 if (icmpv6_code_range_valid(icmp
->h_code
, icmpv6_type_1_codes
))
1344 *code
= icmpv6_type_1_codes
[icmp
->h_code
];
1345 *optional
= dissect_icmpv6_type1
;
1348 *type
= "Packet Too Big";
1349 *optional
= dissect_icmpv6_type2
;
1352 *type
= "Time Exceeded";
1353 if (icmpv6_code_range_valid(icmp
->h_code
, icmpv6_type_3_codes
))
1354 *code
= icmpv6_type_3_codes
[icmp
->h_code
];
1355 *optional
= dissect_icmpv6_type3
;
1358 *type
= "Parameter Problem";
1359 if (icmpv6_code_range_valid(icmp
->h_code
, icmpv6_type_4_codes
))
1360 *code
= icmpv6_type_4_codes
[icmp
->h_code
];
1361 *optional
= dissect_icmpv6_type4
;
1364 *type
= "Private experimation";
1367 *type
= "Private experimation";
1370 *type
= "Reserved for expansion of ICMPv6 error messages";
1373 *type
= "Echo Request";
1374 *optional
= dissect_icmpv6_type128
;
1377 *type
= "Echo Reply";
1378 *optional
= dissect_icmpv6_type129
;
1381 *type
= "Multicast Listener Query";
1382 *optional
= dissect_icmpv6_type130
;
1385 *type
= "Multicast Listener Report";
1386 *optional
= dissect_icmpv6_type131
;
1389 *type
= "Multicast Listener Done";
1390 *optional
= dissect_icmpv6_type132
;
1393 *type
= "Router Solicitation";
1394 *optional
= dissect_icmpv6_type133
;
1397 *type
= "Router Advertisement";
1398 *optional
= dissect_icmpv6_type134
;
1401 *type
= "Neighbor Solicitation";
1402 *optional
= dissect_icmpv6_type135
;
1405 *type
= "Neighbor Advertisement";
1406 *optional
= dissect_icmpv6_type136
;
1409 *type
= "Redirect Message";
1410 *optional
= dissect_icmpv6_type137
;
1413 *type
= "Router Renumbering";
1414 if(icmpv6_type_138_codes(icmp
->h_code
))
1415 *code
= icmpv6_type_138_codes(icmp
->h_code
);
1416 *optional
= dissect_icmpv6_type138
;
1419 *type
= "ICMP Node Information Query";
1420 if (icmpv6_code_range_valid(icmp
->h_code
,
1421 icmpv6_type_139_codes
))
1422 *code
= icmpv6_type_139_codes
[icmp
->h_code
];
1423 *optional
= dissect_icmpv6_type139
;
1426 *type
= "ICMP Node Information Response";
1427 if (icmpv6_code_range_valid(icmp
->h_code
,
1428 icmpv6_type_140_codes
))
1429 *code
= icmpv6_type_140_codes
[icmp
->h_code
];
1430 *optional
= dissect_icmpv6_type140
;
1433 *type
= "Inverse Neighbor Discovery Solicitation Message";
1434 *optional
= dissect_icmpv6_type141
;
1437 *type
= "Inverse Neighbor Discovery Advertisement Message";
1438 *optional
= dissect_icmpv6_type142
;
1441 *type
= "Multicast Listener Report v2";
1442 *optional
= dissect_icmpv6_type143
;
1445 *type
= "Home Agent Address Discovery Request Message";
1446 *optional
= dissect_icmpv6_type144
;
1449 *type
= "Home Agent Address Discovery Reply Message";
1450 *optional
= dissect_icmpv6_type145
;
1453 *type
= "Mobile Prefix Solicitation";
1454 *optional
= dissect_icmpv6_type146
;
1457 *type
= "Mobile Prefix Advertisement";
1458 *optional
= dissect_icmpv6_type147
;
1461 *type
= "Certification Path Solicitation";
1462 *optional
= dissect_icmpv6_type148
;
1465 *type
= "Certification Path Advertisement";
1466 *optional
= dissect_icmpv6_type149
;
1469 *type
= "ICMP messages utilized by experimental mobility "
1470 "protocols such as Seamoby";
1471 *optional
= dissect_icmpv6_type150
;
1474 *type
= "Multicast Router Advertisement";
1475 *code
= "Ad. Interval";
1476 *optional
= dissect_icmpv6_type151
;
1479 *type
= "Multicast Router Solicitation";
1481 *optional
= dissect_icmpv6_type152
;
1484 *type
= "Multicast Router Termination";
1486 *optional
= dissect_icmpv6_type153
;
1489 *type
= "FMIPv6 Messages";
1490 *optional
= dissect_icmpv6_type154
;
1493 *type
= "RPL Control Message";
1494 if(icmpv6_type_155_codes(icmp
->h_code
))
1495 *code
= icmpv6_type_155_codes(icmp
->h_code
);
1498 *type
= "Private experimation";
1501 *type
= "Private experimation";
1504 *type
= "Reserved for expansion of ICMPv6 error messages";
1509 static inline void icmpv6(struct pkt_buff
*pkt
)
1511 char *type
= NULL
, *code
= NULL
;
1512 void (*optional
)(struct pkt_buff
*pkt
) = NULL
;
1513 struct icmpv6_general_hdr
*icmp
=
1514 (struct icmpv6_general_hdr
*) pkt_pull(pkt
, sizeof(*icmp
));
1519 icmpv6_process(icmp
, &type
, &code
, &optional
);
1521 tprintf(" [ ICMPv6 ");
1522 tprintf("%s (%u), ", type
, icmp
->h_type
);
1523 tprintf("%s (%u), ", code
, icmp
->h_code
);
1524 tprintf("Chks (0x%x)", ntohs(icmp
->h_chksum
));
1530 static inline void icmpv6_less(struct pkt_buff
*pkt
)
1532 struct icmpv6_general_hdr
*icmp
=
1533 (struct icmpv6_general_hdr
*) pkt_pull(pkt
, sizeof(*icmp
));
1538 tprintf(" ICMPv6 Type (%u) Code (%u)", icmp
->h_type
, icmp
->h_code
);
1541 struct protocol icmpv6_ops
= {
1543 .print_full
= icmpv6
,
1544 .print_less
= icmpv6_less
,
1547 #endif /* PROTO_ICMPV6_H */