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