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