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