]> The Tcpdump Group git mirrors - tcpdump/blob - print-icmp6.c
df8935675d6bb7d9206d371150b7bf3a3460c3f9
[tcpdump] / print-icmp6.c
1 /*
2 * Copyright (c) 1988, 1989, 1990, 1991, 1993, 1994
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that: (1) source code distributions
7 * retain the above copyright notice and this paragraph in its entirety, (2)
8 * distributions including binary code include the above copyright notice and
9 * this paragraph in its entirety in the documentation or other materials
10 * provided with the distribution, and (3) all advertising materials mentioning
11 * features or use of this software display the following acknowledgement:
12 * ``This product includes software developed by the University of California,
13 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
14 * the University nor the names of its contributors may be used to endorse
15 * or promote products derived from this software without specific prior
16 * written permission.
17 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20 */
21
22 /* \summary: IPv6 Internet Control Message Protocol (ICMPv6) printer */
23
24 #ifdef HAVE_CONFIG_H
25 #include "config.h"
26 #endif
27
28 #include <netdissect-stdinc.h>
29
30 #include <stdio.h>
31 #include <string.h>
32
33 #include "netdissect.h"
34 #include "addrtoname.h"
35 #include "addrtostr.h"
36 #include "extract.h"
37
38 #include "ip6.h"
39 #include "ipproto.h"
40
41 #include "udp.h"
42 #include "ah.h"
43
44 /* NetBSD: icmp6.h,v 1.13 2000/08/03 16:30:37 itojun Exp */
45 /* $KAME: icmp6.h,v 1.22 2000/08/03 15:25:16 jinmei Exp $ */
46
47 /*
48 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
49 * All rights reserved.
50 *
51 * Redistribution and use in source and binary forms, with or without
52 * modification, are permitted provided that the following conditions
53 * are met:
54 * 1. Redistributions of source code must retain the above copyright
55 * notice, this list of conditions and the following disclaimer.
56 * 2. Redistributions in binary form must reproduce the above copyright
57 * notice, this list of conditions and the following disclaimer in the
58 * documentation and/or other materials provided with the distribution.
59 * 3. Neither the name of the project nor the names of its contributors
60 * may be used to endorse or promote products derived from this software
61 * without specific prior written permission.
62 *
63 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
64 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
65 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
66 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
67 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
68 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
69 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
70 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
71 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
72 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
73 * SUCH DAMAGE.
74 */
75
76 struct icmp6_hdr {
77 uint8_t icmp6_type; /* type field */
78 uint8_t icmp6_code; /* code field */
79 uint16_t icmp6_cksum; /* checksum field */
80 union {
81 uint32_t icmp6_un_data32[1]; /* type-specific field */
82 uint16_t icmp6_un_data16[2]; /* type-specific field */
83 uint8_t icmp6_un_data8[4]; /* type-specific field */
84 } icmp6_dataun;
85 };
86
87 #define icmp6_data32 icmp6_dataun.icmp6_un_data32
88 #define icmp6_data16 icmp6_dataun.icmp6_un_data16
89 #define icmp6_data8 icmp6_dataun.icmp6_un_data8
90 #define icmp6_pptr icmp6_data32[0] /* parameter prob */
91 #define icmp6_mtu icmp6_data32[0] /* packet too big */
92 #define icmp6_id icmp6_data16[0] /* echo request/reply */
93 #define icmp6_seq icmp6_data16[1] /* echo request/reply */
94 #define icmp6_maxdelay icmp6_data16[0] /* mcast group membership */
95
96 #define ICMP6_DST_UNREACH 1 /* dest unreachable, codes: */
97 #define ICMP6_PACKET_TOO_BIG 2 /* packet too big */
98 #define ICMP6_TIME_EXCEEDED 3 /* time exceeded, code: */
99 #define ICMP6_PARAM_PROB 4 /* ip6 header bad */
100
101 #define ICMP6_ECHO_REQUEST 128 /* echo service */
102 #define ICMP6_ECHO_REPLY 129 /* echo reply */
103 #define ICMP6_MEMBERSHIP_QUERY 130 /* group membership query */
104 #define MLD6_LISTENER_QUERY 130 /* multicast listener query */
105 #define ICMP6_MEMBERSHIP_REPORT 131 /* group membership report */
106 #define MLD6_LISTENER_REPORT 131 /* multicast listener report */
107 #define ICMP6_MEMBERSHIP_REDUCTION 132 /* group membership termination */
108 #define MLD6_LISTENER_DONE 132 /* multicast listener done */
109
110 #define ND_ROUTER_SOLICIT 133 /* router solicitation */
111 #define ND_ROUTER_ADVERT 134 /* router advertisement */
112 #define ND_NEIGHBOR_SOLICIT 135 /* neighbor solicitation */
113 #define ND_NEIGHBOR_ADVERT 136 /* neighbor advertisement */
114 #define ND_REDIRECT 137 /* redirect */
115
116 #define ICMP6_ROUTER_RENUMBERING 138 /* router renumbering */
117
118 #define ICMP6_WRUREQUEST 139 /* who are you request */
119 #define ICMP6_WRUREPLY 140 /* who are you reply */
120 #define ICMP6_FQDN_QUERY 139 /* FQDN query */
121 #define ICMP6_FQDN_REPLY 140 /* FQDN reply */
122 #define ICMP6_NI_QUERY 139 /* node information request */
123 #define ICMP6_NI_REPLY 140 /* node information reply */
124 #define IND_SOLICIT 141 /* inverse neighbor solicitation */
125 #define IND_ADVERT 142 /* inverse neighbor advertisement */
126
127 #define ICMP6_V2_MEMBERSHIP_REPORT 143 /* v2 membership report */
128 #define MLDV2_LISTENER_REPORT 143 /* v2 multicast listener report */
129 #define ICMP6_HADISCOV_REQUEST 144
130 #define ICMP6_HADISCOV_REPLY 145
131 #define ICMP6_MOBILEPREFIX_SOLICIT 146
132 #define ICMP6_MOBILEPREFIX_ADVERT 147
133
134 #define MLD6_MTRACE_RESP 200 /* mtrace response(to sender) */
135 #define MLD6_MTRACE 201 /* mtrace messages */
136
137 #define ICMP6_MAXTYPE 201
138
139 #define ICMP6_DST_UNREACH_NOROUTE 0 /* no route to destination */
140 #define ICMP6_DST_UNREACH_ADMIN 1 /* administratively prohibited */
141 #define ICMP6_DST_UNREACH_NOTNEIGHBOR 2 /* not a neighbor(obsolete) */
142 #define ICMP6_DST_UNREACH_BEYONDSCOPE 2 /* beyond scope of source address */
143 #define ICMP6_DST_UNREACH_ADDR 3 /* address unreachable */
144 #define ICMP6_DST_UNREACH_NOPORT 4 /* port unreachable */
145
146 #define ICMP6_TIME_EXCEED_TRANSIT 0 /* ttl==0 in transit */
147 #define ICMP6_TIME_EXCEED_REASSEMBLY 1 /* ttl==0 in reass */
148
149 #define ICMP6_PARAMPROB_HEADER 0 /* erroneous header field */
150 #define ICMP6_PARAMPROB_NEXTHEADER 1 /* unrecognized next header */
151 #define ICMP6_PARAMPROB_OPTION 2 /* unrecognized option */
152
153 #define ICMP6_INFOMSG_MASK 0x80 /* all informational messages */
154
155 #define ICMP6_NI_SUBJ_IPV6 0 /* Query Subject is an IPv6 address */
156 #define ICMP6_NI_SUBJ_FQDN 1 /* Query Subject is a Domain name */
157 #define ICMP6_NI_SUBJ_IPV4 2 /* Query Subject is an IPv4 address */
158
159 #define ICMP6_NI_SUCCESS 0 /* node information successful reply */
160 #define ICMP6_NI_REFUSED 1 /* node information request is refused */
161 #define ICMP6_NI_UNKNOWN 2 /* unknown Qtype */
162
163 #define ICMP6_ROUTER_RENUMBERING_COMMAND 0 /* rr command */
164 #define ICMP6_ROUTER_RENUMBERING_RESULT 1 /* rr result */
165 #define ICMP6_ROUTER_RENUMBERING_SEQNUM_RESET 255 /* rr seq num reset */
166
167 /* Used in kernel only */
168 #define ND_REDIRECT_ONLINK 0 /* redirect to an on-link node */
169 #define ND_REDIRECT_ROUTER 1 /* redirect to a better router */
170
171 /*
172 * Multicast Listener Discovery
173 */
174 struct mld6_hdr {
175 struct icmp6_hdr mld6_hdr;
176 struct in6_addr mld6_addr; /* multicast address */
177 };
178
179 #define mld6_type mld6_hdr.icmp6_type
180 #define mld6_code mld6_hdr.icmp6_code
181 #define mld6_cksum mld6_hdr.icmp6_cksum
182 #define mld6_maxdelay mld6_hdr.icmp6_data16[0]
183 #define mld6_reserved mld6_hdr.icmp6_data16[1]
184
185 #define MLD_MINLEN 24
186 #define MLDV2_MINLEN 28
187
188 /*
189 * Neighbor Discovery
190 */
191
192 struct nd_router_solicit { /* router solicitation */
193 struct icmp6_hdr nd_rs_hdr;
194 /* could be followed by options */
195 };
196
197 #define nd_rs_type nd_rs_hdr.icmp6_type
198 #define nd_rs_code nd_rs_hdr.icmp6_code
199 #define nd_rs_cksum nd_rs_hdr.icmp6_cksum
200 #define nd_rs_reserved nd_rs_hdr.icmp6_data32[0]
201
202 struct nd_router_advert { /* router advertisement */
203 struct icmp6_hdr nd_ra_hdr;
204 uint32_t nd_ra_reachable; /* reachable time */
205 uint32_t nd_ra_retransmit; /* retransmit timer */
206 /* could be followed by options */
207 };
208
209 #define nd_ra_type nd_ra_hdr.icmp6_type
210 #define nd_ra_code nd_ra_hdr.icmp6_code
211 #define nd_ra_cksum nd_ra_hdr.icmp6_cksum
212 #define nd_ra_curhoplimit nd_ra_hdr.icmp6_data8[0]
213 #define nd_ra_flags_reserved nd_ra_hdr.icmp6_data8[1]
214 #define ND_RA_FLAG_MANAGED 0x80
215 #define ND_RA_FLAG_OTHER 0x40
216 #define ND_RA_FLAG_HOME_AGENT 0x20
217
218 /*
219 * Router preference values based on draft-draves-ipngwg-router-selection-01.
220 * These are non-standard definitions.
221 */
222 #define ND_RA_FLAG_RTPREF_MASK 0x18 /* 00011000 */
223
224 #define ND_RA_FLAG_RTPREF_HIGH 0x08 /* 00001000 */
225 #define ND_RA_FLAG_RTPREF_MEDIUM 0x00 /* 00000000 */
226 #define ND_RA_FLAG_RTPREF_LOW 0x18 /* 00011000 */
227 #define ND_RA_FLAG_RTPREF_RSV 0x10 /* 00010000 */
228
229 #define nd_ra_router_lifetime nd_ra_hdr.icmp6_data16[1]
230
231 struct nd_neighbor_solicit { /* neighbor solicitation */
232 struct icmp6_hdr nd_ns_hdr;
233 struct in6_addr nd_ns_target; /*target address */
234 /* could be followed by options */
235 };
236
237 #define nd_ns_type nd_ns_hdr.icmp6_type
238 #define nd_ns_code nd_ns_hdr.icmp6_code
239 #define nd_ns_cksum nd_ns_hdr.icmp6_cksum
240 #define nd_ns_reserved nd_ns_hdr.icmp6_data32[0]
241
242 struct nd_neighbor_advert { /* neighbor advertisement */
243 struct icmp6_hdr nd_na_hdr;
244 struct in6_addr nd_na_target; /* target address */
245 /* could be followed by options */
246 };
247
248 #define nd_na_type nd_na_hdr.icmp6_type
249 #define nd_na_code nd_na_hdr.icmp6_code
250 #define nd_na_cksum nd_na_hdr.icmp6_cksum
251 #define nd_na_flags_reserved nd_na_hdr.icmp6_data32[0]
252
253 #define ND_NA_FLAG_ROUTER 0x80000000
254 #define ND_NA_FLAG_SOLICITED 0x40000000
255 #define ND_NA_FLAG_OVERRIDE 0x20000000
256
257 struct nd_redirect { /* redirect */
258 struct icmp6_hdr nd_rd_hdr;
259 struct in6_addr nd_rd_target; /* target address */
260 struct in6_addr nd_rd_dst; /* destination address */
261 /* could be followed by options */
262 };
263
264 #define nd_rd_type nd_rd_hdr.icmp6_type
265 #define nd_rd_code nd_rd_hdr.icmp6_code
266 #define nd_rd_cksum nd_rd_hdr.icmp6_cksum
267 #define nd_rd_reserved nd_rd_hdr.icmp6_data32[0]
268
269 struct nd_opt_hdr { /* Neighbor discovery option header */
270 uint8_t nd_opt_type;
271 uint8_t nd_opt_len;
272 /* followed by option specific data*/
273 };
274
275 #define ND_OPT_SOURCE_LINKADDR 1
276 #define ND_OPT_TARGET_LINKADDR 2
277 #define ND_OPT_PREFIX_INFORMATION 3
278 #define ND_OPT_REDIRECTED_HEADER 4
279 #define ND_OPT_MTU 5
280 #define ND_OPT_ADVINTERVAL 7
281 #define ND_OPT_HOMEAGENT_INFO 8
282 #define ND_OPT_ROUTE_INFO 24 /* RFC4191 */
283 #define ND_OPT_RDNSS 25
284 #define ND_OPT_DNSSL 31
285
286 struct nd_opt_prefix_info { /* prefix information */
287 nd_uint8_t nd_opt_pi_type;
288 nd_uint8_t nd_opt_pi_len;
289 nd_uint8_t nd_opt_pi_prefix_len;
290 nd_uint8_t nd_opt_pi_flags_reserved;
291 nd_uint32_t nd_opt_pi_valid_time;
292 nd_uint32_t nd_opt_pi_preferred_time;
293 nd_uint32_t nd_opt_pi_reserved2;
294 struct in6_addr nd_opt_pi_prefix;
295 };
296
297 #define ND_OPT_PI_FLAG_ONLINK 0x80
298 #define ND_OPT_PI_FLAG_AUTO 0x40
299 #define ND_OPT_PI_FLAG_ROUTER 0x20 /*2292bis*/
300
301 struct nd_opt_rd_hdr { /* redirected header */
302 uint8_t nd_opt_rh_type;
303 uint8_t nd_opt_rh_len;
304 uint16_t nd_opt_rh_reserved1;
305 uint32_t nd_opt_rh_reserved2;
306 /* followed by IP header and data */
307 };
308
309 struct nd_opt_mtu { /* MTU option */
310 uint8_t nd_opt_mtu_type;
311 uint8_t nd_opt_mtu_len;
312 uint16_t nd_opt_mtu_reserved;
313 uint32_t nd_opt_mtu_mtu;
314 };
315
316 struct nd_opt_rdnss { /* RDNSS RFC 6106 5.1 */
317 uint8_t nd_opt_rdnss_type;
318 uint8_t nd_opt_rdnss_len;
319 uint16_t nd_opt_rdnss_reserved;
320 uint32_t nd_opt_rdnss_lifetime;
321 struct in6_addr nd_opt_rdnss_addr[1]; /* variable-length */
322 };
323
324 struct nd_opt_dnssl { /* DNSSL RFC 6106 5.2 */
325 uint8_t nd_opt_dnssl_type;
326 uint8_t nd_opt_dnssl_len;
327 uint16_t nd_opt_dnssl_reserved;
328 uint32_t nd_opt_dnssl_lifetime;
329 /* followed by list of DNS search domains, variable-length */
330 };
331
332 struct nd_opt_advinterval { /* Advertisement interval option */
333 uint8_t nd_opt_adv_type;
334 uint8_t nd_opt_adv_len;
335 uint16_t nd_opt_adv_reserved;
336 uint32_t nd_opt_adv_interval;
337 };
338
339 struct nd_opt_homeagent_info { /* Home Agent info */
340 uint8_t nd_opt_hai_type;
341 uint8_t nd_opt_hai_len;
342 uint16_t nd_opt_hai_reserved;
343 int16_t nd_opt_hai_preference;
344 uint16_t nd_opt_hai_lifetime;
345 };
346
347 struct nd_opt_route_info { /* route info */
348 uint8_t nd_opt_rti_type;
349 uint8_t nd_opt_rti_len;
350 uint8_t nd_opt_rti_prefixlen;
351 uint8_t nd_opt_rti_flags;
352 uint32_t nd_opt_rti_lifetime;
353 /* prefix follows */
354 };
355
356 /*
357 * icmp6 namelookup
358 */
359
360 struct icmp6_namelookup {
361 struct icmp6_hdr icmp6_nl_hdr;
362 uint8_t icmp6_nl_nonce[8];
363 int32_t icmp6_nl_ttl;
364 #if 0
365 uint8_t icmp6_nl_len;
366 uint8_t icmp6_nl_name[3];
367 #endif
368 /* could be followed by options */
369 };
370
371 /*
372 * icmp6 node information
373 */
374 struct icmp6_nodeinfo {
375 struct icmp6_hdr icmp6_ni_hdr;
376 uint8_t icmp6_ni_nonce[8];
377 /* could be followed by reply data */
378 };
379
380 #define ni_type icmp6_ni_hdr.icmp6_type
381 #define ni_code icmp6_ni_hdr.icmp6_code
382 #define ni_cksum icmp6_ni_hdr.icmp6_cksum
383 #define ni_qtype icmp6_ni_hdr.icmp6_data16[0]
384 #define ni_flags icmp6_ni_hdr.icmp6_data16[1]
385
386 #define NI_QTYPE_NOOP 0 /* NOOP */
387 #define NI_QTYPE_SUPTYPES 1 /* Supported Qtypes */
388 #define NI_QTYPE_FQDN 2 /* FQDN (draft 04) */
389 #define NI_QTYPE_DNSNAME 2 /* DNS Name */
390 #define NI_QTYPE_NODEADDR 3 /* Node Addresses */
391 #define NI_QTYPE_IPV4ADDR 4 /* IPv4 Addresses */
392
393 /* network endian */
394 #define NI_SUPTYPE_FLAG_COMPRESS ((uint16_t)htons(0x1))
395 #define NI_FQDN_FLAG_VALIDTTL ((uint16_t)htons(0x1))
396
397 /* network endian */
398 #define NI_NODEADDR_FLAG_TRUNCATE ((uint16_t)htons(0x1))
399 #define NI_NODEADDR_FLAG_ALL ((uint16_t)htons(0x2))
400 #define NI_NODEADDR_FLAG_COMPAT ((uint16_t)htons(0x4))
401 #define NI_NODEADDR_FLAG_LINKLOCAL ((uint16_t)htons(0x8))
402 #define NI_NODEADDR_FLAG_SITELOCAL ((uint16_t)htons(0x10))
403 #define NI_NODEADDR_FLAG_GLOBAL ((uint16_t)htons(0x20))
404 #define NI_NODEADDR_FLAG_ANYCAST ((uint16_t)htons(0x40)) /* just experimental. not in spec */
405
406 struct ni_reply_fqdn {
407 uint32_t ni_fqdn_ttl; /* TTL */
408 uint8_t ni_fqdn_namelen; /* length in octets of the FQDN */
409 uint8_t ni_fqdn_name[3]; /* XXX: alignment */
410 };
411
412 /*
413 * Router Renumbering. as router-renum-08.txt
414 */
415 struct icmp6_router_renum { /* router renumbering header */
416 struct icmp6_hdr rr_hdr;
417 uint8_t rr_segnum;
418 uint8_t rr_flags;
419 uint16_t rr_maxdelay;
420 uint32_t rr_reserved;
421 };
422 #define ICMP6_RR_FLAGS_TEST 0x80
423 #define ICMP6_RR_FLAGS_REQRESULT 0x40
424 #define ICMP6_RR_FLAGS_FORCEAPPLY 0x20
425 #define ICMP6_RR_FLAGS_SPECSITE 0x10
426 #define ICMP6_RR_FLAGS_PREVDONE 0x08
427
428 #define rr_type rr_hdr.icmp6_type
429 #define rr_code rr_hdr.icmp6_code
430 #define rr_cksum rr_hdr.icmp6_cksum
431 #define rr_seqnum rr_hdr.icmp6_data32[0]
432
433 struct rr_pco_match { /* match prefix part */
434 uint8_t rpm_code;
435 uint8_t rpm_len;
436 uint8_t rpm_ordinal;
437 uint8_t rpm_matchlen;
438 uint8_t rpm_minlen;
439 uint8_t rpm_maxlen;
440 uint16_t rpm_reserved;
441 struct in6_addr rpm_prefix;
442 };
443
444 #define RPM_PCO_ADD 1
445 #define RPM_PCO_CHANGE 2
446 #define RPM_PCO_SETGLOBAL 3
447 #define RPM_PCO_MAX 4
448
449 struct rr_pco_use { /* use prefix part */
450 uint8_t rpu_uselen;
451 uint8_t rpu_keeplen;
452 uint8_t rpu_ramask;
453 uint8_t rpu_raflags;
454 uint32_t rpu_vltime;
455 uint32_t rpu_pltime;
456 uint32_t rpu_flags;
457 struct in6_addr rpu_prefix;
458 };
459 #define ICMP6_RR_PCOUSE_RAFLAGS_ONLINK 0x80
460 #define ICMP6_RR_PCOUSE_RAFLAGS_AUTO 0x40
461
462 /* network endian */
463 #define ICMP6_RR_PCOUSE_FLAGS_DECRVLTIME ((uint32_t)htonl(0x80000000))
464 #define ICMP6_RR_PCOUSE_FLAGS_DECRPLTIME ((uint32_t)htonl(0x40000000))
465
466 struct rr_result { /* router renumbering result message */
467 uint16_t rrr_flags;
468 uint8_t rrr_ordinal;
469 uint8_t rrr_matchedlen;
470 uint32_t rrr_ifid;
471 struct in6_addr rrr_prefix;
472 };
473 /* network endian */
474 #define ICMP6_RR_RESULT_FLAGS_OOB ((uint16_t)htons(0x0002))
475 #define ICMP6_RR_RESULT_FLAGS_FORBIDDEN ((uint16_t)htons(0x0001))
476
477 static const char *get_rtpref(u_int);
478 static const char *get_lifetime(uint32_t);
479 static void print_lladdr(netdissect_options *ndo, const u_char *, size_t);
480 static void icmp6_opt_print(netdissect_options *ndo, const u_char *, int);
481 static void mld6_print(netdissect_options *ndo, const u_char *);
482 static void mldv2_report_print(netdissect_options *ndo, const u_char *, u_int);
483 static void mldv2_query_print(netdissect_options *ndo, const u_char *, u_int);
484 static const struct udphdr *get_upperlayer(netdissect_options *ndo, const u_char *, u_int *);
485 static void dnsname_print(netdissect_options *ndo, const u_char *, const u_char *);
486 static void icmp6_nodeinfo_print(netdissect_options *ndo, u_int, const u_char *, const u_char *);
487 static void icmp6_rrenum_print(netdissect_options *ndo, const u_char *, const u_char *);
488
489 #ifndef abs
490 #define abs(a) ((0 < (a)) ? (a) : -(a))
491 #endif
492
493 #include "rpl.h"
494
495 static const struct tok icmp6_type_values[] = {
496 { ICMP6_DST_UNREACH, "destination unreachable"},
497 { ICMP6_PACKET_TOO_BIG, "packet too big"},
498 { ICMP6_TIME_EXCEEDED, "time exceeded in-transit"},
499 { ICMP6_PARAM_PROB, "parameter problem"},
500 { ICMP6_ECHO_REQUEST, "echo request"},
501 { ICMP6_ECHO_REPLY, "echo reply"},
502 { MLD6_LISTENER_QUERY, "multicast listener query"},
503 { MLD6_LISTENER_REPORT, "multicast listener report"},
504 { MLD6_LISTENER_DONE, "multicast listener done"},
505 { ND_ROUTER_SOLICIT, "router solicitation"},
506 { ND_ROUTER_ADVERT, "router advertisement"},
507 { ND_NEIGHBOR_SOLICIT, "neighbor solicitation"},
508 { ND_NEIGHBOR_ADVERT, "neighbor advertisement"},
509 { ND_REDIRECT, "redirect"},
510 { ICMP6_ROUTER_RENUMBERING, "router renumbering"},
511 { IND_SOLICIT, "inverse neighbor solicitation"},
512 { IND_ADVERT, "inverse neighbor advertisement"},
513 { MLDV2_LISTENER_REPORT, "multicast listener report v2"},
514 { ICMP6_HADISCOV_REQUEST, "ha discovery request"},
515 { ICMP6_HADISCOV_REPLY, "ha discovery reply"},
516 { ICMP6_MOBILEPREFIX_SOLICIT, "mobile router solicitation"},
517 { ICMP6_MOBILEPREFIX_ADVERT, "mobile router advertisement"},
518 { ICMP6_WRUREQUEST, "who-are-you request"},
519 { ICMP6_WRUREPLY, "who-are-you reply"},
520 { ICMP6_NI_QUERY, "node information query"},
521 { ICMP6_NI_REPLY, "node information reply"},
522 { MLD6_MTRACE, "mtrace message"},
523 { MLD6_MTRACE_RESP, "mtrace response"},
524 { ND_RPL_MESSAGE, "RPL"},
525 { 0, NULL }
526 };
527
528 static const struct tok icmp6_dst_unreach_code_values[] = {
529 { ICMP6_DST_UNREACH_NOROUTE, "unreachable route" },
530 { ICMP6_DST_UNREACH_ADMIN, " unreachable prohibited"},
531 { ICMP6_DST_UNREACH_BEYONDSCOPE, "beyond scope"},
532 { ICMP6_DST_UNREACH_ADDR, "unreachable address"},
533 { ICMP6_DST_UNREACH_NOPORT, "unreachable port"},
534 { 0, NULL }
535 };
536
537 static const struct tok icmp6_opt_pi_flag_values[] = {
538 { ND_OPT_PI_FLAG_ONLINK, "onlink" },
539 { ND_OPT_PI_FLAG_AUTO, "auto" },
540 { ND_OPT_PI_FLAG_ROUTER, "router" },
541 { 0, NULL }
542 };
543
544 static const struct tok icmp6_opt_ra_flag_values[] = {
545 { ND_RA_FLAG_MANAGED, "managed" },
546 { ND_RA_FLAG_OTHER, "other stateful"},
547 { ND_RA_FLAG_HOME_AGENT, "home agent"},
548 { 0, NULL }
549 };
550
551 static const struct tok icmp6_nd_na_flag_values[] = {
552 { ND_NA_FLAG_ROUTER, "router" },
553 { ND_NA_FLAG_SOLICITED, "solicited" },
554 { ND_NA_FLAG_OVERRIDE, "override" },
555 { 0, NULL }
556 };
557
558
559 static const struct tok icmp6_opt_values[] = {
560 { ND_OPT_SOURCE_LINKADDR, "source link-address"},
561 { ND_OPT_TARGET_LINKADDR, "destination link-address"},
562 { ND_OPT_PREFIX_INFORMATION, "prefix info"},
563 { ND_OPT_REDIRECTED_HEADER, "redirected header"},
564 { ND_OPT_MTU, "mtu"},
565 { ND_OPT_RDNSS, "rdnss"},
566 { ND_OPT_DNSSL, "dnssl"},
567 { ND_OPT_ADVINTERVAL, "advertisement interval"},
568 { ND_OPT_HOMEAGENT_INFO, "homeagent information"},
569 { ND_OPT_ROUTE_INFO, "route info"},
570 { 0, NULL }
571 };
572
573 /* mldv2 report types */
574 static const struct tok mldv2report2str[] = {
575 { 1, "is_in" },
576 { 2, "is_ex" },
577 { 3, "to_in" },
578 { 4, "to_ex" },
579 { 5, "allow" },
580 { 6, "block" },
581 { 0, NULL }
582 };
583
584 static const char *
585 get_rtpref(u_int v)
586 {
587 static const char *rtpref_str[] = {
588 "medium", /* 00 */
589 "high", /* 01 */
590 "rsv", /* 10 */
591 "low" /* 11 */
592 };
593
594 return rtpref_str[((v & ND_RA_FLAG_RTPREF_MASK) >> 3) & 0xff];
595 }
596
597 static const char *
598 get_lifetime(uint32_t v)
599 {
600 static char buf[20];
601
602 if (v == (uint32_t)~0UL)
603 return "infinity";
604 else {
605 snprintf(buf, sizeof(buf), "%us", v);
606 return buf;
607 }
608 }
609
610 static void
611 print_lladdr(netdissect_options *ndo, const uint8_t *p, size_t l)
612 {
613 const uint8_t *ep, *q;
614
615 q = p;
616 ep = p + l;
617 while (l > 0 && q < ep) {
618 if (q > p)
619 ND_PRINT((ndo,":"));
620 ND_PRINT((ndo,"%02x", EXTRACT_U_1(q)));
621 q++;
622 l--;
623 }
624 }
625
626 static int icmp6_cksum(netdissect_options *ndo, const struct ip6_hdr *ip6,
627 const struct icmp6_hdr *icp, u_int len)
628 {
629 return nextproto6_cksum(ndo, ip6, (const uint8_t *)(const void *)icp, len, len,
630 IPPROTO_ICMPV6);
631 }
632
633 static const struct tok rpl_mop_values[] = {
634 { RPL_DIO_NONSTORING, "nonstoring"},
635 { RPL_DIO_STORING, "storing"},
636 { RPL_DIO_NONSTORING_MULTICAST, "nonstoring-multicast"},
637 { RPL_DIO_STORING_MULTICAST, "storing-multicast"},
638 { 0, NULL},
639 };
640
641 static const struct tok rpl_subopt_values[] = {
642 { RPL_OPT_PAD0, "pad0"},
643 { RPL_OPT_PADN, "padN"},
644 { RPL_DIO_METRICS, "metrics"},
645 { RPL_DIO_ROUTINGINFO, "routinginfo"},
646 { RPL_DIO_CONFIG, "config"},
647 { RPL_DAO_RPLTARGET, "rpltarget"},
648 { RPL_DAO_TRANSITINFO, "transitinfo"},
649 { RPL_DIO_DESTPREFIX, "destprefix"},
650 { RPL_DAO_RPLTARGET_DESC, "rpltargetdesc"},
651 { 0, NULL},
652 };
653
654 static void
655 rpl_dio_printopt(netdissect_options *ndo,
656 const struct rpl_dio_genoption *opt,
657 u_int length)
658 {
659 if(length < RPL_DIO_GENOPTION_LEN) return;
660 length -= RPL_DIO_GENOPTION_LEN;
661
662 ND_TCHECK(opt->rpl_dio_len);
663
664 while((opt->rpl_dio_type == RPL_OPT_PAD0 &&
665 (const u_char *)opt < ndo->ndo_snapend) ||
666 ND_TTEST2(*opt,(opt->rpl_dio_len+2))) {
667
668 unsigned int optlen = opt->rpl_dio_len+2;
669 if(opt->rpl_dio_type == RPL_OPT_PAD0) {
670 optlen = 1;
671 ND_PRINT((ndo, " opt:pad0"));
672 } else {
673 ND_PRINT((ndo, " opt:%s len:%u ",
674 tok2str(rpl_subopt_values, "subopt:%u", opt->rpl_dio_type),
675 optlen));
676 if(ndo->ndo_vflag > 2) {
677 unsigned int paylen = opt->rpl_dio_len;
678 if(paylen > length) paylen = length;
679 hex_print(ndo,
680 " ",
681 ((const uint8_t *)opt) + RPL_DIO_GENOPTION_LEN, /* content of DIO option */
682 paylen);
683 }
684 }
685 opt = (const struct rpl_dio_genoption *)(((const char *)opt) + optlen);
686 length -= optlen;
687 }
688 return;
689 trunc:
690 ND_PRINT((ndo," [|truncated]"));
691 return;
692 }
693
694 static void
695 rpl_dio_print(netdissect_options *ndo,
696 const u_char *bp, u_int length)
697 {
698 const struct nd_rpl_dio *dio = (const struct nd_rpl_dio *)bp;
699 const char *dagid_str;
700
701 ND_TCHECK(*dio);
702 dagid_str = ip6addr_string (ndo, dio->rpl_dagid);
703
704 ND_PRINT((ndo, " [dagid:%s,seq:%u,instance:%u,rank:%u,%smop:%s,prf:%u]",
705 dagid_str,
706 dio->rpl_dtsn,
707 dio->rpl_instanceid,
708 EXTRACT_BE_U_2(&dio->rpl_dagrank),
709 RPL_DIO_GROUNDED(dio->rpl_mopprf) ? "grounded,":"",
710 tok2str(rpl_mop_values, "mop%u", RPL_DIO_MOP(dio->rpl_mopprf)),
711 RPL_DIO_PRF(dio->rpl_mopprf)));
712
713 if(ndo->ndo_vflag > 1) {
714 const struct rpl_dio_genoption *opt = (const struct rpl_dio_genoption *)&dio[1];
715 rpl_dio_printopt(ndo, opt, length);
716 }
717 return;
718 trunc:
719 ND_PRINT((ndo," [|truncated]"));
720 return;
721 }
722
723 static void
724 rpl_dao_print(netdissect_options *ndo,
725 const u_char *bp, u_int length)
726 {
727 const struct nd_rpl_dao *dao = (const struct nd_rpl_dao *)bp;
728 const char *dagid_str = "<elided>";
729
730 ND_TCHECK(*dao);
731 if (length < ND_RPL_DAO_MIN_LEN)
732 goto tooshort;
733
734 bp += ND_RPL_DAO_MIN_LEN;
735 length -= ND_RPL_DAO_MIN_LEN;
736 if(RPL_DAO_D(dao->rpl_flags)) {
737 ND_TCHECK2(dao->rpl_dagid, DAGID_LEN);
738 if (length < DAGID_LEN)
739 goto tooshort;
740 dagid_str = ip6addr_string (ndo, dao->rpl_dagid);
741 bp += DAGID_LEN;
742 length -= DAGID_LEN;
743 }
744
745 ND_PRINT((ndo, " [dagid:%s,seq:%u,instance:%u%s%s,%02x]",
746 dagid_str,
747 dao->rpl_daoseq,
748 dao->rpl_instanceid,
749 RPL_DAO_K(dao->rpl_flags) ? ",acK":"",
750 RPL_DAO_D(dao->rpl_flags) ? ",Dagid":"",
751 dao->rpl_flags));
752
753 if(ndo->ndo_vflag > 1) {
754 const struct rpl_dio_genoption *opt = (const struct rpl_dio_genoption *)bp;
755 rpl_dio_printopt(ndo, opt, length);
756 }
757 return;
758
759 trunc:
760 ND_PRINT((ndo," [|truncated]"));
761 return;
762
763 tooshort:
764 ND_PRINT((ndo," [|length too short]"));
765 return;
766 }
767
768 static void
769 rpl_daoack_print(netdissect_options *ndo,
770 const u_char *bp, u_int length)
771 {
772 const struct nd_rpl_daoack *daoack = (const struct nd_rpl_daoack *)bp;
773 const char *dagid_str = "<elided>";
774
775 ND_TCHECK2(*daoack, ND_RPL_DAOACK_MIN_LEN);
776 if (length < ND_RPL_DAOACK_MIN_LEN)
777 goto tooshort;
778
779 bp += ND_RPL_DAOACK_MIN_LEN;
780 length -= ND_RPL_DAOACK_MIN_LEN;
781 if(RPL_DAOACK_D(daoack->rpl_flags)) {
782 ND_TCHECK2(daoack->rpl_dagid, DAGID_LEN);
783 if (length < DAGID_LEN)
784 goto tooshort;
785 dagid_str = ip6addr_string (ndo, daoack->rpl_dagid);
786 bp += DAGID_LEN;
787 length -= DAGID_LEN;
788 }
789
790 ND_PRINT((ndo, " [dagid:%s,seq:%u,instance:%u,status:%u]",
791 dagid_str,
792 daoack->rpl_daoseq,
793 daoack->rpl_instanceid,
794 daoack->rpl_status));
795
796 /* no officially defined options for DAOACK, but print any we find */
797 if(ndo->ndo_vflag > 1) {
798 const struct rpl_dio_genoption *opt = (const struct rpl_dio_genoption *)bp;
799 rpl_dio_printopt(ndo, opt, length);
800 }
801 return;
802
803 trunc:
804 ND_PRINT((ndo," [|dao-truncated]"));
805 return;
806
807 tooshort:
808 ND_PRINT((ndo," [|dao-length too short]"));
809 return;
810 }
811
812 static void
813 rpl_print(netdissect_options *ndo,
814 const struct icmp6_hdr *hdr,
815 const u_char *bp, u_int length)
816 {
817 int secured = hdr->icmp6_code & 0x80;
818 int basecode= hdr->icmp6_code & 0x7f;
819
820 if(secured) {
821 ND_PRINT((ndo, ", (SEC) [worktodo]"));
822 /* XXX
823 * the next header pointer needs to move forward to
824 * skip the secure part.
825 */
826 return;
827 } else {
828 ND_PRINT((ndo, ", (CLR)"));
829 }
830
831 switch(basecode) {
832 case ND_RPL_DAG_IS:
833 ND_PRINT((ndo, "DODAG Information Solicitation"));
834 if(ndo->ndo_vflag) {
835 }
836 break;
837 case ND_RPL_DAG_IO:
838 ND_PRINT((ndo, "DODAG Information Object"));
839 if(ndo->ndo_vflag) {
840 rpl_dio_print(ndo, bp, length);
841 }
842 break;
843 case ND_RPL_DAO:
844 ND_PRINT((ndo, "Destination Advertisement Object"));
845 if(ndo->ndo_vflag) {
846 rpl_dao_print(ndo, bp, length);
847 }
848 break;
849 case ND_RPL_DAO_ACK:
850 ND_PRINT((ndo, "Destination Advertisement Object Ack"));
851 if(ndo->ndo_vflag) {
852 rpl_daoack_print(ndo, bp, length);
853 }
854 break;
855 default:
856 ND_PRINT((ndo, "RPL message, unknown code %u",hdr->icmp6_code));
857 break;
858 }
859 return;
860
861 #if 0
862 trunc:
863 ND_PRINT((ndo," [|truncated]"));
864 return;
865 #endif
866
867 }
868
869
870 void
871 icmp6_print(netdissect_options *ndo,
872 const u_char *bp, u_int length, const u_char *bp2, int fragmented)
873 {
874 const struct icmp6_hdr *dp;
875 const struct ip6_hdr *ip;
876 const struct ip6_hdr *oip;
877 const struct udphdr *ouh;
878 int dport;
879 const u_char *ep;
880 u_int prot;
881
882 dp = (const struct icmp6_hdr *)bp;
883 ip = (const struct ip6_hdr *)bp2;
884 oip = (const struct ip6_hdr *)(dp + 1);
885 /* 'ep' points to the end of available data. */
886 ep = ndo->ndo_snapend;
887
888 ND_TCHECK(dp->icmp6_cksum);
889
890 if (ndo->ndo_vflag && !fragmented) {
891 uint16_t sum, udp_sum;
892
893 if (ND_TTEST2(bp[0], length)) {
894 udp_sum = EXTRACT_BE_U_2(&dp->icmp6_cksum);
895 sum = icmp6_cksum(ndo, ip, dp, length);
896 if (sum != 0)
897 ND_PRINT((ndo,"[bad icmp6 cksum 0x%04x -> 0x%04x!] ",
898 udp_sum,
899 in_cksum_shouldbe(udp_sum, sum)));
900 else
901 ND_PRINT((ndo,"[icmp6 sum ok] "));
902 }
903 }
904
905 ND_PRINT((ndo,"ICMP6, %s", tok2str(icmp6_type_values,"unknown icmp6 type (%u)",dp->icmp6_type)));
906
907 /* display cosmetics: print the packet length for printer that use the vflag now */
908 if (ndo->ndo_vflag && (dp->icmp6_type == ND_ROUTER_SOLICIT ||
909 dp->icmp6_type == ND_ROUTER_ADVERT ||
910 dp->icmp6_type == ND_NEIGHBOR_ADVERT ||
911 dp->icmp6_type == ND_NEIGHBOR_SOLICIT ||
912 dp->icmp6_type == ND_REDIRECT ||
913 dp->icmp6_type == ICMP6_HADISCOV_REPLY ||
914 dp->icmp6_type == ICMP6_MOBILEPREFIX_ADVERT ))
915 ND_PRINT((ndo,", length %u", length));
916
917 switch (dp->icmp6_type) {
918 case ICMP6_DST_UNREACH:
919 ND_TCHECK(oip->ip6_dst);
920 ND_PRINT((ndo,", %s", tok2str(icmp6_dst_unreach_code_values,"unknown unreach code (%u)",dp->icmp6_code)));
921 switch (dp->icmp6_code) {
922
923 case ICMP6_DST_UNREACH_NOROUTE: /* fall through */
924 case ICMP6_DST_UNREACH_ADMIN:
925 case ICMP6_DST_UNREACH_ADDR:
926 ND_PRINT((ndo," %s",ip6addr_string(ndo, &oip->ip6_dst)));
927 break;
928 case ICMP6_DST_UNREACH_BEYONDSCOPE:
929 ND_PRINT((ndo," %s, source address %s",
930 ip6addr_string(ndo, &oip->ip6_dst),
931 ip6addr_string(ndo, &oip->ip6_src)));
932 break;
933 case ICMP6_DST_UNREACH_NOPORT:
934 if ((ouh = get_upperlayer(ndo, (const u_char *)oip, &prot))
935 == NULL)
936 goto trunc;
937
938 dport = EXTRACT_BE_U_2(&ouh->uh_dport);
939 switch (prot) {
940 case IPPROTO_TCP:
941 ND_PRINT((ndo,", %s tcp port %s",
942 ip6addr_string(ndo, &oip->ip6_dst),
943 tcpport_string(ndo, dport)));
944 break;
945 case IPPROTO_UDP:
946 ND_PRINT((ndo,", %s udp port %s",
947 ip6addr_string(ndo, &oip->ip6_dst),
948 udpport_string(ndo, dport)));
949 break;
950 default:
951 ND_PRINT((ndo,", %s protocol %d port %d unreachable",
952 ip6addr_string(ndo, &oip->ip6_dst),
953 oip->ip6_nxt, dport));
954 break;
955 }
956 break;
957 default:
958 if (ndo->ndo_vflag <= 1) {
959 print_unknown_data(ndo, bp,"\n\t",length);
960 return;
961 }
962 break;
963 }
964 break;
965 case ICMP6_PACKET_TOO_BIG:
966 ND_TCHECK(dp->icmp6_mtu);
967 ND_PRINT((ndo,", mtu %u", EXTRACT_BE_U_4(&dp->icmp6_mtu)));
968 break;
969 case ICMP6_TIME_EXCEEDED:
970 ND_TCHECK(oip->ip6_dst);
971 switch (dp->icmp6_code) {
972 case ICMP6_TIME_EXCEED_TRANSIT:
973 ND_PRINT((ndo," for %s",
974 ip6addr_string(ndo, &oip->ip6_dst)));
975 break;
976 case ICMP6_TIME_EXCEED_REASSEMBLY:
977 ND_PRINT((ndo," (reassembly)"));
978 break;
979 default:
980 ND_PRINT((ndo,", unknown code (%u)", dp->icmp6_code));
981 break;
982 }
983 break;
984 case ICMP6_PARAM_PROB:
985 ND_TCHECK(oip->ip6_dst);
986 switch (dp->icmp6_code) {
987 case ICMP6_PARAMPROB_HEADER:
988 ND_PRINT((ndo,", erroneous - octet %u", EXTRACT_BE_U_4(&dp->icmp6_pptr)));
989 break;
990 case ICMP6_PARAMPROB_NEXTHEADER:
991 ND_PRINT((ndo,", next header - octet %u", EXTRACT_BE_U_4(&dp->icmp6_pptr)));
992 break;
993 case ICMP6_PARAMPROB_OPTION:
994 ND_PRINT((ndo,", option - octet %u", EXTRACT_BE_U_4(&dp->icmp6_pptr)));
995 break;
996 default:
997 ND_PRINT((ndo,", code-#%d",
998 dp->icmp6_code));
999 break;
1000 }
1001 break;
1002 case ICMP6_ECHO_REQUEST:
1003 case ICMP6_ECHO_REPLY:
1004 ND_TCHECK(dp->icmp6_seq);
1005 ND_PRINT((ndo,", seq %u", EXTRACT_BE_U_2(&dp->icmp6_seq)));
1006 break;
1007 case ICMP6_MEMBERSHIP_QUERY:
1008 if (length == MLD_MINLEN) {
1009 mld6_print(ndo, (const u_char *)dp);
1010 } else if (length >= MLDV2_MINLEN) {
1011 ND_PRINT((ndo," v2"));
1012 mldv2_query_print(ndo, (const u_char *)dp, length);
1013 } else {
1014 ND_PRINT((ndo," unknown-version (len %u) ", length));
1015 }
1016 break;
1017 case ICMP6_MEMBERSHIP_REPORT:
1018 mld6_print(ndo, (const u_char *)dp);
1019 break;
1020 case ICMP6_MEMBERSHIP_REDUCTION:
1021 mld6_print(ndo, (const u_char *)dp);
1022 break;
1023 case ND_ROUTER_SOLICIT:
1024 #define RTSOLLEN 8
1025 if (ndo->ndo_vflag) {
1026 icmp6_opt_print(ndo, (const u_char *)dp + RTSOLLEN,
1027 length - RTSOLLEN);
1028 }
1029 break;
1030 case ND_ROUTER_ADVERT:
1031 #define RTADVLEN 16
1032 if (ndo->ndo_vflag) {
1033 const struct nd_router_advert *p;
1034
1035 p = (const struct nd_router_advert *)dp;
1036 ND_TCHECK(p->nd_ra_retransmit);
1037 ND_PRINT((ndo,"\n\thop limit %u, Flags [%s]" \
1038 ", pref %s, router lifetime %us, reachable time %us, retrans time %us",
1039 (u_int)p->nd_ra_curhoplimit,
1040 bittok2str(icmp6_opt_ra_flag_values,"none",(p->nd_ra_flags_reserved)),
1041 get_rtpref(p->nd_ra_flags_reserved),
1042 EXTRACT_BE_U_2(&p->nd_ra_router_lifetime),
1043 EXTRACT_BE_U_4(&p->nd_ra_reachable),
1044 EXTRACT_BE_U_4(&p->nd_ra_retransmit)));
1045
1046 icmp6_opt_print(ndo, (const u_char *)dp + RTADVLEN,
1047 length - RTADVLEN);
1048 }
1049 break;
1050 case ND_NEIGHBOR_SOLICIT:
1051 {
1052 const struct nd_neighbor_solicit *p;
1053 p = (const struct nd_neighbor_solicit *)dp;
1054 ND_TCHECK(p->nd_ns_target);
1055 ND_PRINT((ndo,", who has %s", ip6addr_string(ndo, &p->nd_ns_target)));
1056 if (ndo->ndo_vflag) {
1057 #define NDSOLLEN 24
1058 icmp6_opt_print(ndo, (const u_char *)dp + NDSOLLEN,
1059 length - NDSOLLEN);
1060 }
1061 }
1062 break;
1063 case ND_NEIGHBOR_ADVERT:
1064 {
1065 const struct nd_neighbor_advert *p;
1066
1067 p = (const struct nd_neighbor_advert *)dp;
1068 ND_TCHECK(p->nd_na_target);
1069 ND_PRINT((ndo,", tgt is %s",
1070 ip6addr_string(ndo, &p->nd_na_target)));
1071 if (ndo->ndo_vflag) {
1072 ND_PRINT((ndo,", Flags [%s]",
1073 bittok2str(icmp6_nd_na_flag_values,
1074 "none",
1075 EXTRACT_BE_U_4(&p->nd_na_flags_reserved))));
1076 #define NDADVLEN 24
1077 icmp6_opt_print(ndo, (const u_char *)dp + NDADVLEN,
1078 length - NDADVLEN);
1079 #undef NDADVLEN
1080 }
1081 }
1082 break;
1083 case ND_REDIRECT:
1084 #define RDR(i) ((const struct nd_redirect *)(i))
1085 ND_TCHECK(RDR(dp)->nd_rd_dst);
1086 ND_PRINT((ndo,", %s", ip6addr_string(ndo, &RDR(dp)->nd_rd_dst)));
1087 ND_TCHECK(RDR(dp)->nd_rd_target);
1088 ND_PRINT((ndo," to %s",
1089 ip6addr_string(ndo, &RDR(dp)->nd_rd_target)));
1090 #define REDIRECTLEN 40
1091 if (ndo->ndo_vflag) {
1092 icmp6_opt_print(ndo, (const u_char *)dp + REDIRECTLEN,
1093 length - REDIRECTLEN);
1094 }
1095 break;
1096 #undef REDIRECTLEN
1097 #undef RDR
1098 case ICMP6_ROUTER_RENUMBERING:
1099 icmp6_rrenum_print(ndo, bp, ep);
1100 break;
1101 case ICMP6_NI_QUERY:
1102 case ICMP6_NI_REPLY:
1103 icmp6_nodeinfo_print(ndo, length, bp, ep);
1104 break;
1105 case IND_SOLICIT:
1106 case IND_ADVERT:
1107 break;
1108 case ICMP6_V2_MEMBERSHIP_REPORT:
1109 mldv2_report_print(ndo, (const u_char *) dp, length);
1110 break;
1111 case ICMP6_MOBILEPREFIX_SOLICIT: /* fall through */
1112 case ICMP6_HADISCOV_REQUEST:
1113 ND_TCHECK(dp->icmp6_data16[0]);
1114 ND_PRINT((ndo,", id 0x%04x", EXTRACT_BE_U_2(&dp->icmp6_data16[0])));
1115 break;
1116 case ICMP6_HADISCOV_REPLY:
1117 if (ndo->ndo_vflag) {
1118 const struct in6_addr *in6;
1119 const u_char *cp;
1120
1121 ND_TCHECK(dp->icmp6_data16[0]);
1122 ND_PRINT((ndo,", id 0x%04x", EXTRACT_BE_U_2(&dp->icmp6_data16[0])));
1123 cp = (const u_char *)dp + length;
1124 in6 = (const struct in6_addr *)(dp + 1);
1125 for (; (const u_char *)in6 < cp; in6++) {
1126 ND_TCHECK(*in6);
1127 ND_PRINT((ndo,", %s", ip6addr_string(ndo, in6)));
1128 }
1129 }
1130 break;
1131 case ICMP6_MOBILEPREFIX_ADVERT:
1132 if (ndo->ndo_vflag) {
1133 ND_TCHECK(dp->icmp6_data16[0]);
1134 ND_PRINT((ndo,", id 0x%04x", EXTRACT_BE_U_2(&dp->icmp6_data16[0])));
1135 ND_TCHECK(dp->icmp6_data16[1]);
1136 if (dp->icmp6_data16[1] & 0xc0)
1137 ND_PRINT((ndo," "));
1138 if (dp->icmp6_data16[1] & 0x80)
1139 ND_PRINT((ndo,"M"));
1140 if (dp->icmp6_data16[1] & 0x40)
1141 ND_PRINT((ndo,"O"));
1142 #define MPADVLEN 8
1143 icmp6_opt_print(ndo, (const u_char *)dp + MPADVLEN,
1144 length - MPADVLEN);
1145 }
1146 break;
1147 case ND_RPL_MESSAGE:
1148 /* plus 4, because struct icmp6_hdr contains 4 bytes of icmp payload */
1149 rpl_print(ndo, dp, &dp->icmp6_data8[0], length-sizeof(struct icmp6_hdr)+4);
1150 break;
1151 default:
1152 ND_PRINT((ndo,", length %u", length));
1153 if (ndo->ndo_vflag <= 1)
1154 print_unknown_data(ndo, bp,"\n\t", length);
1155 return;
1156 }
1157 if (!ndo->ndo_vflag)
1158 ND_PRINT((ndo,", length %u", length));
1159 return;
1160 trunc:
1161 ND_PRINT((ndo, "[|icmp6]"));
1162 }
1163
1164 static const struct udphdr *
1165 get_upperlayer(netdissect_options *ndo, const u_char *bp, u_int *prot)
1166 {
1167 const u_char *ep;
1168 const struct ip6_hdr *ip6 = (const struct ip6_hdr *)bp;
1169 const struct udphdr *uh;
1170 const struct ip6_hbh *hbh;
1171 const struct ip6_frag *fragh;
1172 const struct ah *ah;
1173 u_int nh;
1174 int hlen;
1175
1176 /* 'ep' points to the end of available data. */
1177 ep = ndo->ndo_snapend;
1178
1179 if (!ND_TTEST(ip6->ip6_nxt))
1180 return NULL;
1181
1182 nh = ip6->ip6_nxt;
1183 hlen = sizeof(struct ip6_hdr);
1184
1185 while (bp < ep) {
1186 bp += hlen;
1187
1188 switch(nh) {
1189 case IPPROTO_UDP:
1190 case IPPROTO_TCP:
1191 uh = (const struct udphdr *)bp;
1192 if (ND_TTEST(uh->uh_dport)) {
1193 *prot = nh;
1194 return(uh);
1195 }
1196 else
1197 return(NULL);
1198 /* NOTREACHED */
1199
1200 case IPPROTO_HOPOPTS:
1201 case IPPROTO_DSTOPTS:
1202 case IPPROTO_ROUTING:
1203 hbh = (const struct ip6_hbh *)bp;
1204 if (!ND_TTEST(hbh->ip6h_len))
1205 return(NULL);
1206 nh = hbh->ip6h_nxt;
1207 hlen = (hbh->ip6h_len + 1) << 3;
1208 break;
1209
1210 case IPPROTO_FRAGMENT: /* this should be odd, but try anyway */
1211 fragh = (const struct ip6_frag *)bp;
1212 if (!ND_TTEST(fragh->ip6f_offlg))
1213 return(NULL);
1214 /* fragments with non-zero offset are meaningless */
1215 if ((EXTRACT_BE_U_2(&fragh->ip6f_offlg) & IP6F_OFF_MASK) != 0)
1216 return(NULL);
1217 nh = fragh->ip6f_nxt;
1218 hlen = sizeof(struct ip6_frag);
1219 break;
1220
1221 case IPPROTO_AH:
1222 ah = (const struct ah *)bp;
1223 if (!ND_TTEST(ah->ah_len))
1224 return(NULL);
1225 nh = ah->ah_nxt;
1226 hlen = (ah->ah_len + 2) << 2;
1227 break;
1228
1229 default: /* unknown or undecodable header */
1230 *prot = nh; /* meaningless, but set here anyway */
1231 return(NULL);
1232 }
1233 }
1234
1235 return(NULL); /* should be notreached, though */
1236 }
1237
1238 static void
1239 icmp6_opt_print(netdissect_options *ndo, const u_char *bp, int resid)
1240 {
1241 const struct nd_opt_hdr *op;
1242 const struct nd_opt_prefix_info *opp;
1243 const struct nd_opt_mtu *opm;
1244 const struct nd_opt_rdnss *oprd;
1245 const struct nd_opt_dnssl *opds;
1246 const struct nd_opt_advinterval *opa;
1247 const struct nd_opt_homeagent_info *oph;
1248 const struct nd_opt_route_info *opri;
1249 const u_char *cp, *ep, *domp;
1250 struct in6_addr in6;
1251 const struct in6_addr *in6p;
1252 size_t l;
1253 u_int i;
1254
1255 #define ECHECK(var) if ((const u_char *)&(var) > ep - sizeof(var)) return
1256
1257 cp = bp;
1258 /* 'ep' points to the end of available data. */
1259 ep = ndo->ndo_snapend;
1260
1261 while (cp < ep) {
1262 op = (const struct nd_opt_hdr *)cp;
1263
1264 ECHECK(op->nd_opt_len);
1265 if (resid <= 0)
1266 return;
1267 if (op->nd_opt_len == 0)
1268 goto trunc;
1269 if (cp + (op->nd_opt_len << 3) > ep)
1270 goto trunc;
1271
1272 ND_PRINT((ndo,"\n\t %s option (%u), length %u (%u): ",
1273 tok2str(icmp6_opt_values, "unknown", op->nd_opt_type),
1274 op->nd_opt_type,
1275 op->nd_opt_len << 3,
1276 op->nd_opt_len));
1277
1278 switch (op->nd_opt_type) {
1279 case ND_OPT_SOURCE_LINKADDR:
1280 l = (op->nd_opt_len << 3) - 2;
1281 print_lladdr(ndo, cp + 2, l);
1282 break;
1283 case ND_OPT_TARGET_LINKADDR:
1284 l = (op->nd_opt_len << 3) - 2;
1285 print_lladdr(ndo, cp + 2, l);
1286 break;
1287 case ND_OPT_PREFIX_INFORMATION:
1288 opp = (const struct nd_opt_prefix_info *)op;
1289 ND_TCHECK(opp->nd_opt_pi_prefix);
1290 ND_PRINT((ndo,"%s/%u%s, Flags [%s], valid time %s",
1291 ip6addr_string(ndo, &opp->nd_opt_pi_prefix),
1292 opp->nd_opt_pi_prefix_len,
1293 (op->nd_opt_len != 4) ? "badlen" : "",
1294 bittok2str(icmp6_opt_pi_flag_values, "none", opp->nd_opt_pi_flags_reserved),
1295 get_lifetime(EXTRACT_BE_U_4(&opp->nd_opt_pi_valid_time))));
1296 ND_PRINT((ndo,", pref. time %s", get_lifetime(EXTRACT_BE_U_4(&opp->nd_opt_pi_preferred_time))));
1297 break;
1298 case ND_OPT_REDIRECTED_HEADER:
1299 print_unknown_data(ndo, bp,"\n\t ",op->nd_opt_len<<3);
1300 /* xxx */
1301 break;
1302 case ND_OPT_MTU:
1303 opm = (const struct nd_opt_mtu *)op;
1304 ND_TCHECK(opm->nd_opt_mtu_mtu);
1305 ND_PRINT((ndo," %u%s",
1306 EXTRACT_BE_U_4(&opm->nd_opt_mtu_mtu),
1307 (op->nd_opt_len != 1) ? "bad option length" : "" ));
1308 break;
1309 case ND_OPT_RDNSS:
1310 oprd = (const struct nd_opt_rdnss *)op;
1311 l = (op->nd_opt_len - 1) / 2;
1312 ND_PRINT((ndo," lifetime %us,",
1313 EXTRACT_BE_U_4(&oprd->nd_opt_rdnss_lifetime)));
1314 for (i = 0; i < l; i++) {
1315 ND_TCHECK(oprd->nd_opt_rdnss_addr[i]);
1316 ND_PRINT((ndo," addr: %s",
1317 ip6addr_string(ndo, &oprd->nd_opt_rdnss_addr[i])));
1318 }
1319 break;
1320 case ND_OPT_DNSSL:
1321 opds = (const struct nd_opt_dnssl *)op;
1322 ND_PRINT((ndo," lifetime %us, domain(s):",
1323 EXTRACT_BE_U_4(&opds->nd_opt_dnssl_lifetime)));
1324 domp = cp + 8; /* domain names, variable-sized, RFC1035-encoded */
1325 while (domp < cp + (op->nd_opt_len << 3) && EXTRACT_U_1(domp) != '\0')
1326 {
1327 ND_PRINT((ndo, " "));
1328 if ((domp = ns_nprint (ndo, domp, bp)) == NULL)
1329 goto trunc;
1330 }
1331 break;
1332 case ND_OPT_ADVINTERVAL:
1333 opa = (const struct nd_opt_advinterval *)op;
1334 ND_TCHECK(opa->nd_opt_adv_interval);
1335 ND_PRINT((ndo," %ums", EXTRACT_BE_U_4(&opa->nd_opt_adv_interval)));
1336 break;
1337 case ND_OPT_HOMEAGENT_INFO:
1338 oph = (const struct nd_opt_homeagent_info *)op;
1339 ND_TCHECK(oph->nd_opt_hai_lifetime);
1340 ND_PRINT((ndo," preference %u, lifetime %u",
1341 EXTRACT_BE_U_2(&oph->nd_opt_hai_preference),
1342 EXTRACT_BE_U_2(&oph->nd_opt_hai_lifetime)));
1343 break;
1344 case ND_OPT_ROUTE_INFO:
1345 opri = (const struct nd_opt_route_info *)op;
1346 ND_TCHECK(opri->nd_opt_rti_lifetime);
1347 memset(&in6, 0, sizeof(in6));
1348 in6p = (const struct in6_addr *)(opri + 1);
1349 switch (op->nd_opt_len) {
1350 case 1:
1351 break;
1352 case 2:
1353 ND_TCHECK_8(in6p);
1354 memcpy(&in6, opri + 1, 8);
1355 break;
1356 case 3:
1357 ND_TCHECK(*in6p);
1358 memcpy(&in6, opri + 1, sizeof(in6));
1359 break;
1360 default:
1361 goto trunc;
1362 }
1363 ND_PRINT((ndo," %s/%u", ip6addr_string(ndo, &in6),
1364 opri->nd_opt_rti_prefixlen));
1365 ND_PRINT((ndo,", pref=%s", get_rtpref(opri->nd_opt_rti_flags)));
1366 ND_PRINT((ndo,", lifetime=%s",
1367 get_lifetime(EXTRACT_BE_U_4(&opri->nd_opt_rti_lifetime))));
1368 break;
1369 default:
1370 if (ndo->ndo_vflag <= 1) {
1371 print_unknown_data(ndo,cp+2,"\n\t ", (op->nd_opt_len << 3) - 2); /* skip option header */
1372 return;
1373 }
1374 break;
1375 }
1376 /* do we want to see an additional hexdump ? */
1377 if (ndo->ndo_vflag> 1)
1378 print_unknown_data(ndo, cp+2,"\n\t ", (op->nd_opt_len << 3) - 2); /* skip option header */
1379
1380 cp += op->nd_opt_len << 3;
1381 resid -= op->nd_opt_len << 3;
1382 }
1383 return;
1384
1385 trunc:
1386 ND_PRINT((ndo, "[ndp opt]"));
1387 return;
1388 #undef ECHECK
1389 }
1390
1391 static void
1392 mld6_print(netdissect_options *ndo, const u_char *bp)
1393 {
1394 const struct mld6_hdr *mp = (const struct mld6_hdr *)bp;
1395 const u_char *ep;
1396
1397 /* 'ep' points to the end of available data. */
1398 ep = ndo->ndo_snapend;
1399
1400 if ((const u_char *)mp + sizeof(*mp) > ep)
1401 return;
1402
1403 ND_PRINT((ndo,"max resp delay: %d ", EXTRACT_BE_U_2(&mp->mld6_maxdelay)));
1404 ND_PRINT((ndo,"addr: %s", ip6addr_string(ndo, &mp->mld6_addr)));
1405 }
1406
1407 static void
1408 mldv2_report_print(netdissect_options *ndo, const u_char *bp, u_int len)
1409 {
1410 const struct icmp6_hdr *icp = (const struct icmp6_hdr *) bp;
1411 u_int group, nsrcs, ngroups;
1412 u_int i, j;
1413
1414 /* Minimum len is 8 */
1415 if (len < 8) {
1416 ND_PRINT((ndo," [invalid len %d]", len));
1417 return;
1418 }
1419
1420 ND_TCHECK(icp->icmp6_data16[1]);
1421 ngroups = EXTRACT_BE_U_2(&icp->icmp6_data16[1]);
1422 ND_PRINT((ndo,", %d group record(s)", ngroups));
1423 if (ndo->ndo_vflag > 0) {
1424 /* Print the group records */
1425 group = 8;
1426 for (i = 0; i < ngroups; i++) {
1427 /* type(1) + auxlen(1) + numsrc(2) + grp(16) */
1428 if (len < group + 20) {
1429 ND_PRINT((ndo," [invalid number of groups]"));
1430 return;
1431 }
1432 ND_TCHECK2(bp[group + 4], sizeof(struct in6_addr));
1433 ND_PRINT((ndo," [gaddr %s", ip6addr_string(ndo, bp + group + 4)));
1434 ND_PRINT((ndo," %s", tok2str(mldv2report2str, " [v2-report-#%d]",
1435 EXTRACT_U_1(bp + group))));
1436 nsrcs = (bp[group + 2] << 8) + bp[group + 3];
1437 /* Check the number of sources and print them */
1438 if (len < group + 20 + (nsrcs * sizeof(struct in6_addr))) {
1439 ND_PRINT((ndo," [invalid number of sources %d]", nsrcs));
1440 return;
1441 }
1442 if (ndo->ndo_vflag == 1)
1443 ND_PRINT((ndo,", %d source(s)", nsrcs));
1444 else {
1445 /* Print the sources */
1446 ND_PRINT((ndo," {"));
1447 for (j = 0; j < nsrcs; j++) {
1448 ND_TCHECK2(bp[group + 20 + j * sizeof(struct in6_addr)],
1449 sizeof(struct in6_addr));
1450 ND_PRINT((ndo," %s", ip6addr_string(ndo, bp + group + 20 + (j * sizeof(struct in6_addr)))));
1451 }
1452 ND_PRINT((ndo," }"));
1453 }
1454 /* Next group record */
1455 group += 20 + nsrcs * sizeof(struct in6_addr);
1456 ND_PRINT((ndo,"]"));
1457 }
1458 }
1459 return;
1460 trunc:
1461 ND_PRINT((ndo,"[|icmp6]"));
1462 return;
1463 }
1464
1465 static void
1466 mldv2_query_print(netdissect_options *ndo, const u_char *bp, u_int len)
1467 {
1468 const struct icmp6_hdr *icp = (const struct icmp6_hdr *) bp;
1469 u_int mrc;
1470 int mrt, qqi;
1471 u_int nsrcs;
1472 register u_int i;
1473
1474 /* Minimum len is 28 */
1475 if (len < 28) {
1476 ND_PRINT((ndo," [invalid len %d]", len));
1477 return;
1478 }
1479 ND_TCHECK(icp->icmp6_data16[0]);
1480 mrc = EXTRACT_BE_U_2(&icp->icmp6_data16[0]);
1481 if (mrc < 32768) {
1482 mrt = mrc;
1483 } else {
1484 mrt = ((mrc & 0x0fff) | 0x1000) << (((mrc & 0x7000) >> 12) + 3);
1485 }
1486 if (ndo->ndo_vflag) {
1487 ND_PRINT((ndo," [max resp delay=%d]", mrt));
1488 }
1489 ND_TCHECK2(bp[8], sizeof(struct in6_addr));
1490 ND_PRINT((ndo," [gaddr %s", ip6addr_string(ndo, bp + 8)));
1491
1492 if (ndo->ndo_vflag) {
1493 ND_TCHECK(bp[25]);
1494 if (EXTRACT_U_1(bp + 24) & 0x08) {
1495 ND_PRINT((ndo," sflag"));
1496 }
1497 if (EXTRACT_U_1(bp + 24) & 0x07) {
1498 ND_PRINT((ndo," robustness=%d", EXTRACT_U_1(bp + 24) & 0x07));
1499 }
1500 if (EXTRACT_U_1(bp + 25) < 128) {
1501 qqi = bp[25];
1502 } else {
1503 qqi = ((bp[25] & 0x0f) | 0x10) << (((bp[25] & 0x70) >> 4) + 3);
1504 }
1505 ND_PRINT((ndo," qqi=%d", qqi));
1506 }
1507
1508 ND_TCHECK_2(bp + 26);
1509 nsrcs = EXTRACT_BE_U_2(bp + 26);
1510 if (nsrcs > 0) {
1511 if (len < 28 + nsrcs * sizeof(struct in6_addr))
1512 ND_PRINT((ndo," [invalid number of sources]"));
1513 else if (ndo->ndo_vflag > 1) {
1514 ND_PRINT((ndo," {"));
1515 for (i = 0; i < nsrcs; i++) {
1516 ND_TCHECK2(bp[28 + i * sizeof(struct in6_addr)],
1517 sizeof(struct in6_addr));
1518 ND_PRINT((ndo," %s", ip6addr_string(ndo, bp + 28 + (i * sizeof(struct in6_addr)))));
1519 }
1520 ND_PRINT((ndo," }"));
1521 } else
1522 ND_PRINT((ndo,", %d source(s)", nsrcs));
1523 }
1524 ND_PRINT((ndo,"]"));
1525 return;
1526 trunc:
1527 ND_PRINT((ndo,"[|icmp6]"));
1528 return;
1529 }
1530
1531 static void
1532 dnsname_print(netdissect_options *ndo, const u_char *cp, const u_char *ep)
1533 {
1534 int i;
1535
1536 /* DNS name decoding - no decompression */
1537 ND_PRINT((ndo,", \""));
1538 while (cp < ep) {
1539 i = EXTRACT_U_1(cp);
1540 cp++;
1541 if (i) {
1542 if (i > ep - cp) {
1543 ND_PRINT((ndo,"???"));
1544 break;
1545 }
1546 while (i-- && cp < ep) {
1547 safeputchar(ndo, EXTRACT_U_1(cp));
1548 cp++;
1549 }
1550 if (cp + 1 < ep && EXTRACT_U_1(cp))
1551 ND_PRINT((ndo,"."));
1552 } else {
1553 if (cp == ep) {
1554 /* FQDN */
1555 ND_PRINT((ndo,"."));
1556 } else if (cp + 1 == ep && *cp == '\0') {
1557 /* truncated */
1558 } else {
1559 /* invalid */
1560 ND_PRINT((ndo,"???"));
1561 }
1562 break;
1563 }
1564 }
1565 ND_PRINT((ndo,"\""));
1566 }
1567
1568 static void
1569 icmp6_nodeinfo_print(netdissect_options *ndo, u_int icmp6len, const u_char *bp, const u_char *ep)
1570 {
1571 const struct icmp6_nodeinfo *ni6;
1572 const struct icmp6_hdr *dp;
1573 const u_char *cp;
1574 size_t siz, i;
1575 int needcomma;
1576
1577 if (ep < bp)
1578 return;
1579 dp = (const struct icmp6_hdr *)bp;
1580 ni6 = (const struct icmp6_nodeinfo *)bp;
1581 siz = ep - bp;
1582
1583 switch (ni6->ni_type) {
1584 case ICMP6_NI_QUERY:
1585 if (siz == sizeof(*dp) + 4) {
1586 /* KAME who-are-you */
1587 ND_PRINT((ndo," who-are-you request"));
1588 break;
1589 }
1590 ND_PRINT((ndo," node information query"));
1591
1592 ND_TCHECK2(*dp, sizeof(*ni6));
1593 ni6 = (const struct icmp6_nodeinfo *)dp;
1594 ND_PRINT((ndo," (")); /*)*/
1595 switch (EXTRACT_BE_U_2(&ni6->ni_qtype)) {
1596 case NI_QTYPE_NOOP:
1597 ND_PRINT((ndo,"noop"));
1598 break;
1599 case NI_QTYPE_SUPTYPES:
1600 ND_PRINT((ndo,"supported qtypes"));
1601 i = EXTRACT_BE_U_2(&ni6->ni_flags);
1602 if (i)
1603 ND_PRINT((ndo," [%s]", (i & 0x01) ? "C" : ""));
1604 break;
1605 case NI_QTYPE_FQDN:
1606 ND_PRINT((ndo,"DNS name"));
1607 break;
1608 case NI_QTYPE_NODEADDR:
1609 ND_PRINT((ndo,"node addresses"));
1610 i = ni6->ni_flags;
1611 if (!i)
1612 break;
1613 /* NI_NODEADDR_FLAG_TRUNCATE undefined for query */
1614 ND_PRINT((ndo," [%s%s%s%s%s%s]",
1615 (i & NI_NODEADDR_FLAG_ANYCAST) ? "a" : "",
1616 (i & NI_NODEADDR_FLAG_GLOBAL) ? "G" : "",
1617 (i & NI_NODEADDR_FLAG_SITELOCAL) ? "S" : "",
1618 (i & NI_NODEADDR_FLAG_LINKLOCAL) ? "L" : "",
1619 (i & NI_NODEADDR_FLAG_COMPAT) ? "C" : "",
1620 (i & NI_NODEADDR_FLAG_ALL) ? "A" : ""));
1621 break;
1622 default:
1623 ND_PRINT((ndo,"unknown"));
1624 break;
1625 }
1626
1627 if (ni6->ni_qtype == NI_QTYPE_NOOP ||
1628 ni6->ni_qtype == NI_QTYPE_SUPTYPES) {
1629 if (siz != sizeof(*ni6))
1630 if (ndo->ndo_vflag)
1631 ND_PRINT((ndo,", invalid len"));
1632 /*(*/
1633 ND_PRINT((ndo,")"));
1634 break;
1635 }
1636
1637
1638 /* XXX backward compat, icmp-name-lookup-03 */
1639 if (siz == sizeof(*ni6)) {
1640 ND_PRINT((ndo,", 03 draft"));
1641 /*(*/
1642 ND_PRINT((ndo,")"));
1643 break;
1644 }
1645
1646 switch (ni6->ni_code) {
1647 case ICMP6_NI_SUBJ_IPV6:
1648 if (!ND_TTEST2(*dp,
1649 sizeof(*ni6) + sizeof(struct in6_addr)))
1650 break;
1651 if (siz != sizeof(*ni6) + sizeof(struct in6_addr)) {
1652 if (ndo->ndo_vflag)
1653 ND_PRINT((ndo,", invalid subject len"));
1654 break;
1655 }
1656 ND_PRINT((ndo,", subject=%s",
1657 ip6addr_string(ndo, ni6 + 1)));
1658 break;
1659 case ICMP6_NI_SUBJ_FQDN:
1660 ND_PRINT((ndo,", subject=DNS name"));
1661 cp = (const u_char *)(ni6 + 1);
1662 if (EXTRACT_U_1(cp) == ep - cp - 1) {
1663 /* icmp-name-lookup-03, pascal string */
1664 if (ndo->ndo_vflag)
1665 ND_PRINT((ndo,", 03 draft"));
1666 cp++;
1667 ND_PRINT((ndo,", \""));
1668 while (cp < ep) {
1669 safeputchar(ndo, EXTRACT_U_1(cp));
1670 cp++;
1671 }
1672 ND_PRINT((ndo,"\""));
1673 } else
1674 dnsname_print(ndo, cp, ep);
1675 break;
1676 case ICMP6_NI_SUBJ_IPV4:
1677 if (!ND_TTEST2(*dp, sizeof(*ni6) + sizeof(struct in_addr)))
1678 break;
1679 if (siz != sizeof(*ni6) + sizeof(struct in_addr)) {
1680 if (ndo->ndo_vflag)
1681 ND_PRINT((ndo,", invalid subject len"));
1682 break;
1683 }
1684 ND_PRINT((ndo,", subject=%s",
1685 ipaddr_string(ndo, ni6 + 1)));
1686 break;
1687 default:
1688 ND_PRINT((ndo,", unknown subject"));
1689 break;
1690 }
1691
1692 /*(*/
1693 ND_PRINT((ndo,")"));
1694 break;
1695
1696 case ICMP6_NI_REPLY:
1697 if (icmp6len > siz) {
1698 ND_PRINT((ndo,"[|icmp6: node information reply]"));
1699 break;
1700 }
1701
1702 needcomma = 0;
1703
1704 ND_TCHECK2(*dp, sizeof(*ni6));
1705 ni6 = (const struct icmp6_nodeinfo *)dp;
1706 ND_PRINT((ndo," node information reply"));
1707 ND_PRINT((ndo," (")); /*)*/
1708 switch (ni6->ni_code) {
1709 case ICMP6_NI_SUCCESS:
1710 if (ndo->ndo_vflag) {
1711 ND_PRINT((ndo,"success"));
1712 needcomma++;
1713 }
1714 break;
1715 case ICMP6_NI_REFUSED:
1716 ND_PRINT((ndo,"refused"));
1717 needcomma++;
1718 if (siz != sizeof(*ni6))
1719 if (ndo->ndo_vflag)
1720 ND_PRINT((ndo,", invalid length"));
1721 break;
1722 case ICMP6_NI_UNKNOWN:
1723 ND_PRINT((ndo,"unknown"));
1724 needcomma++;
1725 if (siz != sizeof(*ni6))
1726 if (ndo->ndo_vflag)
1727 ND_PRINT((ndo,", invalid length"));
1728 break;
1729 }
1730
1731 if (ni6->ni_code != ICMP6_NI_SUCCESS) {
1732 /*(*/
1733 ND_PRINT((ndo,")"));
1734 break;
1735 }
1736
1737 switch (EXTRACT_BE_U_2(&ni6->ni_qtype)) {
1738 case NI_QTYPE_NOOP:
1739 if (needcomma)
1740 ND_PRINT((ndo,", "));
1741 ND_PRINT((ndo,"noop"));
1742 if (siz != sizeof(*ni6))
1743 if (ndo->ndo_vflag)
1744 ND_PRINT((ndo,", invalid length"));
1745 break;
1746 case NI_QTYPE_SUPTYPES:
1747 if (needcomma)
1748 ND_PRINT((ndo,", "));
1749 ND_PRINT((ndo,"supported qtypes"));
1750 i = EXTRACT_BE_U_2(&ni6->ni_flags);
1751 if (i)
1752 ND_PRINT((ndo," [%s]", (i & 0x01) ? "C" : ""));
1753 break;
1754 case NI_QTYPE_FQDN:
1755 if (needcomma)
1756 ND_PRINT((ndo,", "));
1757 ND_PRINT((ndo,"DNS name"));
1758 cp = (const u_char *)(ni6 + 1) + 4;
1759 ND_TCHECK(cp[0]);
1760 if (EXTRACT_U_1(cp) == ep - cp - 1) {
1761 /* icmp-name-lookup-03, pascal string */
1762 if (ndo->ndo_vflag)
1763 ND_PRINT((ndo,", 03 draft"));
1764 cp++;
1765 ND_PRINT((ndo,", \""));
1766 while (cp < ep) {
1767 safeputchar(ndo, EXTRACT_U_1(cp));
1768 cp++;
1769 }
1770 ND_PRINT((ndo,"\""));
1771 } else
1772 dnsname_print(ndo, cp, ep);
1773 if ((EXTRACT_BE_U_2(&ni6->ni_flags) & 0x01) != 0)
1774 ND_PRINT((ndo," [TTL=%u]", EXTRACT_BE_U_4(ni6 + 1)));
1775 break;
1776 case NI_QTYPE_NODEADDR:
1777 if (needcomma)
1778 ND_PRINT((ndo,", "));
1779 ND_PRINT((ndo,"node addresses"));
1780 i = sizeof(*ni6);
1781 while (i < siz) {
1782 if (i + sizeof(struct in6_addr) + sizeof(int32_t) > siz)
1783 break;
1784 ND_PRINT((ndo," %s", ip6addr_string(ndo, bp + i)));
1785 i += sizeof(struct in6_addr);
1786 ND_PRINT((ndo,"(%d)", (int32_t) EXTRACT_BE_U_4(bp + i)));
1787 i += sizeof(int32_t);
1788 }
1789 i = ni6->ni_flags;
1790 if (!i)
1791 break;
1792 ND_PRINT((ndo," [%s%s%s%s%s%s%s]",
1793 (i & NI_NODEADDR_FLAG_ANYCAST) ? "a" : "",
1794 (i & NI_NODEADDR_FLAG_GLOBAL) ? "G" : "",
1795 (i & NI_NODEADDR_FLAG_SITELOCAL) ? "S" : "",
1796 (i & NI_NODEADDR_FLAG_LINKLOCAL) ? "L" : "",
1797 (i & NI_NODEADDR_FLAG_COMPAT) ? "C" : "",
1798 (i & NI_NODEADDR_FLAG_ALL) ? "A" : "",
1799 (i & NI_NODEADDR_FLAG_TRUNCATE) ? "T" : ""));
1800 break;
1801 default:
1802 if (needcomma)
1803 ND_PRINT((ndo,", "));
1804 ND_PRINT((ndo,"unknown"));
1805 break;
1806 }
1807
1808 /*(*/
1809 ND_PRINT((ndo,")"));
1810 break;
1811 }
1812 return;
1813
1814 trunc:
1815 ND_PRINT((ndo, "[|icmp6]"));
1816 }
1817
1818 static void
1819 icmp6_rrenum_print(netdissect_options *ndo, const u_char *bp, const u_char *ep)
1820 {
1821 const struct icmp6_router_renum *rr6;
1822 const char *cp;
1823 const struct rr_pco_match *match;
1824 const struct rr_pco_use *use;
1825 char hbuf[NI_MAXHOST];
1826 int n;
1827
1828 if (ep < bp)
1829 return;
1830 rr6 = (const struct icmp6_router_renum *)bp;
1831 cp = (const char *)(rr6 + 1);
1832
1833 ND_TCHECK(rr6->rr_reserved);
1834 switch (rr6->rr_code) {
1835 case ICMP6_ROUTER_RENUMBERING_COMMAND:
1836 ND_PRINT((ndo,"router renum: command"));
1837 break;
1838 case ICMP6_ROUTER_RENUMBERING_RESULT:
1839 ND_PRINT((ndo,"router renum: result"));
1840 break;
1841 case ICMP6_ROUTER_RENUMBERING_SEQNUM_RESET:
1842 ND_PRINT((ndo,"router renum: sequence number reset"));
1843 break;
1844 default:
1845 ND_PRINT((ndo,"router renum: code-#%d", rr6->rr_code));
1846 break;
1847 }
1848
1849 ND_PRINT((ndo,", seq=%u", EXTRACT_BE_U_4(&rr6->rr_seqnum)));
1850
1851 if (ndo->ndo_vflag) {
1852 #define F(x, y) ((rr6->rr_flags) & (x) ? (y) : "")
1853 ND_PRINT((ndo,"[")); /*]*/
1854 if (rr6->rr_flags) {
1855 ND_PRINT((ndo,"%s%s%s%s%s,", F(ICMP6_RR_FLAGS_TEST, "T"),
1856 F(ICMP6_RR_FLAGS_REQRESULT, "R"),
1857 F(ICMP6_RR_FLAGS_FORCEAPPLY, "A"),
1858 F(ICMP6_RR_FLAGS_SPECSITE, "S"),
1859 F(ICMP6_RR_FLAGS_PREVDONE, "P")));
1860 }
1861 ND_PRINT((ndo,"seg=%u,", rr6->rr_segnum));
1862 ND_PRINT((ndo,"maxdelay=%u", EXTRACT_BE_U_2(&rr6->rr_maxdelay)));
1863 if (rr6->rr_reserved)
1864 ND_PRINT((ndo,"rsvd=0x%x", EXTRACT_BE_U_4(&rr6->rr_reserved)));
1865 /*[*/
1866 ND_PRINT((ndo,"]"));
1867 #undef F
1868 }
1869
1870 if (rr6->rr_code == ICMP6_ROUTER_RENUMBERING_COMMAND) {
1871 match = (const struct rr_pco_match *)cp;
1872 cp = (const char *)(match + 1);
1873
1874 ND_TCHECK(match->rpm_prefix);
1875
1876 if (ndo->ndo_vflag > 1)
1877 ND_PRINT((ndo,"\n\t"));
1878 else
1879 ND_PRINT((ndo," "));
1880 ND_PRINT((ndo,"match(")); /*)*/
1881 switch (match->rpm_code) {
1882 case RPM_PCO_ADD: ND_PRINT((ndo,"add")); break;
1883 case RPM_PCO_CHANGE: ND_PRINT((ndo,"change")); break;
1884 case RPM_PCO_SETGLOBAL: ND_PRINT((ndo,"setglobal")); break;
1885 default: ND_PRINT((ndo,"#%u", match->rpm_code)); break;
1886 }
1887
1888 if (ndo->ndo_vflag) {
1889 ND_PRINT((ndo,",ord=%u", match->rpm_ordinal));
1890 ND_PRINT((ndo,",min=%u", match->rpm_minlen));
1891 ND_PRINT((ndo,",max=%u", match->rpm_maxlen));
1892 }
1893 if (addrtostr6(&match->rpm_prefix, hbuf, sizeof(hbuf)))
1894 ND_PRINT((ndo,",%s/%u", hbuf, match->rpm_matchlen));
1895 else
1896 ND_PRINT((ndo,",?/%u", match->rpm_matchlen));
1897 /*(*/
1898 ND_PRINT((ndo,")"));
1899
1900 n = match->rpm_len - 3;
1901 if (n % 4)
1902 goto trunc;
1903 n /= 4;
1904 while (n-- > 0) {
1905 use = (const struct rr_pco_use *)cp;
1906 cp = (const char *)(use + 1);
1907
1908 ND_TCHECK(use->rpu_prefix);
1909
1910 if (ndo->ndo_vflag > 1)
1911 ND_PRINT((ndo,"\n\t"));
1912 else
1913 ND_PRINT((ndo," "));
1914 ND_PRINT((ndo,"use(")); /*)*/
1915 if (use->rpu_flags) {
1916 #define F(x, y) ((use->rpu_flags) & (x) ? (y) : "")
1917 ND_PRINT((ndo,"%s%s,",
1918 F(ICMP6_RR_PCOUSE_FLAGS_DECRVLTIME, "V"),
1919 F(ICMP6_RR_PCOUSE_FLAGS_DECRPLTIME, "P")));
1920 #undef F
1921 }
1922 if (ndo->ndo_vflag) {
1923 ND_PRINT((ndo,"mask=0x%x,", use->rpu_ramask));
1924 ND_PRINT((ndo,"raflags=0x%x,", use->rpu_raflags));
1925 if (~use->rpu_vltime == 0)
1926 ND_PRINT((ndo,"vltime=infty,"));
1927 else
1928 ND_PRINT((ndo,"vltime=%u,",
1929 EXTRACT_BE_U_4(&use->rpu_vltime)));
1930 if (~use->rpu_pltime == 0)
1931 ND_PRINT((ndo,"pltime=infty,"));
1932 else
1933 ND_PRINT((ndo,"pltime=%u,",
1934 EXTRACT_BE_U_4(&use->rpu_pltime)));
1935 }
1936 if (addrtostr6(&use->rpu_prefix, hbuf, sizeof(hbuf)))
1937 ND_PRINT((ndo,"%s/%u/%u", hbuf, use->rpu_uselen,
1938 use->rpu_keeplen));
1939 else
1940 ND_PRINT((ndo,"?/%u/%u", use->rpu_uselen,
1941 use->rpu_keeplen));
1942 /*(*/
1943 ND_PRINT((ndo,")"));
1944 }
1945 }
1946
1947 return;
1948
1949 trunc:
1950 ND_PRINT((ndo,"[|icmp6]"));
1951 }
1952
1953 /*
1954 * Local Variables:
1955 * c-style: whitesmith
1956 * c-basic-offset: 8
1957 * End:
1958 */