proto_ip_authentication_hdr.h:Usable with pkt_buff
[netsniff-ng.git] / src / proto_icmpv6.h
blob634e0e715c3df7841b1fa63c5db5f2e9cd8d873b
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 */
11 #ifndef PROTO_ICMPV6_H
12 #define PROTO_ICMPV6_H
14 #include <stdio.h>
15 #include <stdint.h>
16 #include <netinet/in.h>
17 #include <arpa/inet.h>
19 #include "built_in.h"
20 #include "proto_struct.h"
21 #include "dissector_eth.h"
22 #include "pkt_buff.h"
23 #include "built_in.h"
25 struct icmpv6hdr {
26 uint8_t h_type;
27 uint8_t h_code;
28 uint16_t h_chksum;
29 } __packed;
31 static char *icmpv6_type_1_strings[] = {
32 "No route to destination",
33 "Communication with destination administratively prohibited",
34 "Beyond scope of source address",
35 "Address unreachable",
36 "Port unreachable",
37 "Source address failed ingress/egress policy",
38 "Reject route to destination",
39 "Error in Source Routing Header",
42 #define icmpv6_code_range_valid(code, sarr) ((code) < array_size((sarr)))
44 static inline void icmpv6_process(struct icmpv6hdr *icmp, char **type,
45 char **code, char **optional)
47 *type = "Unknown Type";
48 *code = "Unknown Code";
50 switch (icmp->h_type) {
51 case 1:
52 *type = "Destination Unreachable";
53 if (icmpv6_code_range_valid(icmp->h_code, icmpv6_type_1_strings))
54 *code = icmpv6_type_1_strings[icmp->h_code];
55 return;
56 case 2:
57 *type = "Packet Too Big";
58 return;
59 case 3:
60 *type = "Time Exceeded";
61 return;
62 case 4:
63 *type = "Parameter Problem";
64 return;
65 case 100:
66 *type = "Private experimation";
67 return;
68 case 101:
69 *type = "Private experimation";
70 return;
71 case 127:
72 *type = "Reserved for expansion of ICMPv6 error messages";
73 return;
74 case 128:
75 *type = "Echo Request";
76 return;
77 case 129:
78 *type = "Echo Reply";
79 return;
80 case 130:
81 *type = "Multicast Listener Query";
82 return;
83 case 131:
84 *type = "Multicast Listener Report";
85 return;
86 case 132:
87 *type = "Multicast Listener Done";
88 return;
89 case 133:
90 *type = "Router Solicitation";
91 return;
92 case 134:
93 *type = "Router Advertisement";
94 return;
95 case 135:
96 *type = "Neighbor Solicitation";
97 return;
98 case 136:
99 *type = "Neighbor Advertisement";
100 return;
101 case 137:
102 *type = "Redirect Message";
103 return;
104 case 138:
105 *type = "Router Renumbering";
106 return;
107 case 139:
108 *type = "ICMP Node Information Query";
109 return;
110 case 140:
111 *type = "ICMP Node Information Response";
112 return;
113 case 141:
114 *type = "Inverse Neighbor Discovery Solicitation Message";
115 return;
116 case 142:
117 *type = "Inverse Neighbor Discovery Advertisement Message";
118 return;
119 case 143:
120 *type = "Multicast Listener Report v2";
121 return;
122 case 144:
123 *type = "Home Agent Address Discovery Request Message";
124 return;
125 case 145:
126 *type = "Home Agent Address Discovery Reply Message";
127 return;
128 case 146:
129 *type = "Mobile Prefix Solicitation";
130 return;
131 case 147:
132 *type = "Mobile Prefix Advertisement";
133 return;
134 case 148:
135 *type = "Certification Path Solicitation";
136 return;
137 case 149:
138 *type = "Certification Path Advertisement";
139 return;
140 case 150:
141 *type = "ICMP messages utilized by experimental mobility "
142 "protocols such as Seamoby";
143 return;
144 case 151:
145 *type = "Multicast Router Advertisement";
146 return;
147 case 152:
148 *type = "Multicast Router Solicitation";
149 return;
150 case 153:
151 *type = "Multicast Router Termination";
152 return;
153 case 155:
154 *type = "RPL Control Message";
155 return;
156 case 200:
157 *type = "Private experimation";
158 return;
159 case 201:
160 *type = "Private experimation";
161 return;
162 case 255:
163 *type = "Reserved for expansion of ICMPv6 error messages";
164 return;
168 static inline void icmpv6(struct pkt_buff *pkt)
170 char *type = NULL, *code = NULL, *optional = NULL;
171 struct icmpv6hdr *icmp =
172 (struct icmpv6hdr *) pkt_pull(pkt, sizeof(*icmp));
174 if (icmp == NULL)
175 return;
177 icmpv6_process(icmp, &type, &code, &optional);
179 tprintf(" [ ICMPv6 ");
180 tprintf("%s (%u), ", type, icmp->h_type);
181 tprintf("%s (%u), ", code, icmp->h_code);
182 tprintf("Chks (0x%x)", ntohs(icmp->h_chksum));
183 if (optional)
184 tprintf(" %s", optional);
185 tprintf(" ]\n\n");
188 static inline void icmpv6_less(struct pkt_buff *pkt)
190 struct icmpv6hdr *icmp =
191 (struct icmpv6hdr *) pkt_pull(pkt, sizeof(*icmp));
193 if (icmp == NULL)
194 return;
196 tprintf(" ICMPv6 Type (%u) Code (%u)", icmp->h_type, icmp->h_code);
199 struct protocol icmpv6_ops = {
200 .key = 0x3A,
201 .print_full = icmpv6,
202 .print_less = icmpv6_less,
205 #endif /* PROTO_ICMPV6_H */