]> The Tcpdump Group git mirrors - tcpdump/blob - print-icmp6.c
remove tcpdump's own CVS keywords
[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 struct nd_rpl_dio {
655 u_int8_t rpl_flags;
656 u_int8_t rpl_seq;
657 u_int8_t rpl_instanceid;
658 u_int8_t rpl_dagrank;
659 u_int8_t rpl_dagid[16];
660 };
661
662 static void
663 rpl_print(netdissect_options *ndo,
664 const struct icmp6_hdr *hdr,
665 const u_char *bp, u_int length _U_)
666 {
667 struct nd_rpl_dio *dio = (struct nd_rpl_dio *)bp;
668 int secured = hdr->icmp6_code & 0x80;
669 int basecode= hdr->icmp6_code & 0x7f;
670
671 ND_TCHECK(dio->rpl_dagid);
672
673 if(secured) {
674 ND_PRINT((ndo, ", (SEC)"));
675 } else {
676 ND_PRINT((ndo, ", (CLR)"));
677 }
678
679 switch(basecode) {
680 case ND_RPL_DIS:
681 ND_PRINT((ndo, "DODAG Information Solicitation"));
682 if(ndo->ndo_vflag) {
683 }
684 break;
685 case ND_RPL_DIO:
686 ND_PRINT((ndo, "DODAG Information Object"));
687 if(ndo->ndo_vflag) {
688 char dagid[65];
689 char *d = dagid;
690 int i;
691 for(i=0;i<16;i++) {
692 if(isprint(dio->rpl_dagid[i])) {
693 *d++ = dio->rpl_dagid[i];
694 } else {
695 int cnt=snprintf(d,4,"0x%02x",
696 dio->rpl_dagid[i]);
697 d += cnt;
698 }
699 }
700 *d++ = '\0';
701 ND_PRINT((ndo, " [seq:%u,instance:%u,rank:%u,dagid:%s]",
702 dio->rpl_seq,
703 dio->rpl_instanceid,
704 dio->rpl_dagrank,
705 dagid));
706 }
707 break;
708 case ND_RPL_DAO:
709 ND_PRINT((ndo, "Destination Advertisement Object"));
710 if(ndo->ndo_vflag) {
711 }
712 break;
713 case ND_RPL_DAO_ACK:
714 ND_PRINT((ndo, "Destination Advertisement Object Ack"));
715 if(ndo->ndo_vflag) {
716 }
717 break;
718 default:
719 ND_PRINT((ndo, "RPL message, unknown code %u",hdr->icmp6_code));
720 break;
721 }
722 return;
723 trunc:
724 ND_PRINT((ndo," [|truncated]"));
725 return;
726
727 }
728
729
730 void
731 icmp6_print(netdissect_options *ndo,
732 const u_char *bp, u_int length, const u_char *bp2, int fragmented)
733 {
734 const struct icmp6_hdr *dp;
735 const struct ip6_hdr *ip;
736 const struct ip6_hdr *oip;
737 const struct udphdr *ouh;
738 int dport;
739 const u_char *ep;
740 u_int prot;
741
742 dp = (struct icmp6_hdr *)bp;
743 ip = (struct ip6_hdr *)bp2;
744 oip = (struct ip6_hdr *)(dp + 1);
745 /* 'ep' points to the end of available data. */
746 ep = ndo->ndo_snapend;
747
748 ND_TCHECK(dp->icmp6_cksum);
749
750 if (ndo->ndo_vflag && !fragmented) {
751 u_int16_t sum, udp_sum;
752
753 if (ND_TTEST2(bp[0], length)) {
754 udp_sum = EXTRACT_16BITS(&dp->icmp6_cksum);
755 sum = icmp6_cksum(ip, dp, length);
756 if (sum != 0)
757 (void)ND_PRINT((ndo,"[bad icmp6 cksum 0x%04x -> 0x%04x!] ",
758 udp_sum,
759 in_cksum_shouldbe(udp_sum, sum)));
760 else
761 (void)ND_PRINT((ndo,"[icmp6 sum ok] "));
762 }
763 }
764
765 ND_PRINT((ndo,"ICMP6, %s", tok2str(icmp6_type_values,"unknown icmp6 type (%u)",dp->icmp6_type)));
766
767 /* display cosmetics: print the packet length for printer that use the vflag now */
768 if (ndo->ndo_vflag && (dp->icmp6_type == ND_ROUTER_SOLICIT ||
769 dp->icmp6_type == ND_ROUTER_ADVERT ||
770 dp->icmp6_type == ND_NEIGHBOR_ADVERT ||
771 dp->icmp6_type == ND_NEIGHBOR_SOLICIT ||
772 dp->icmp6_type == ND_REDIRECT ||
773 dp->icmp6_type == ICMP6_HADISCOV_REPLY ||
774 dp->icmp6_type == ICMP6_MOBILEPREFIX_ADVERT ))
775 ND_PRINT((ndo,", length %u", length));
776
777 switch (dp->icmp6_type) {
778 case ICMP6_DST_UNREACH:
779 ND_TCHECK(oip->ip6_dst);
780 ND_PRINT((ndo,", %s", tok2str(icmp6_dst_unreach_code_values,"unknown unreach code (%u)",dp->icmp6_code)));
781 switch (dp->icmp6_code) {
782
783 case ICMP6_DST_UNREACH_NOROUTE: /* fall through */
784 case ICMP6_DST_UNREACH_ADMIN:
785 case ICMP6_DST_UNREACH_ADDR:
786 ND_PRINT((ndo," %s",ip6addr_string(&oip->ip6_dst)));
787 break;
788 case ICMP6_DST_UNREACH_BEYONDSCOPE:
789 ND_PRINT((ndo," %s, source address %s",
790 ip6addr_string(&oip->ip6_dst),
791 ip6addr_string(&oip->ip6_src)));
792 break;
793 case ICMP6_DST_UNREACH_NOPORT:
794 if ((ouh = get_upperlayer(ndo, (u_char *)oip, &prot))
795 == NULL)
796 goto trunc;
797
798 dport = EXTRACT_16BITS(&ouh->uh_dport);
799 switch (prot) {
800 case IPPROTO_TCP:
801 ND_PRINT((ndo,", %s tcp port %s",
802 ip6addr_string(&oip->ip6_dst),
803 tcpport_string(dport)));
804 break;
805 case IPPROTO_UDP:
806 ND_PRINT((ndo,", %s udp port %s",
807 ip6addr_string(&oip->ip6_dst),
808 udpport_string(dport)));
809 break;
810 default:
811 ND_PRINT((ndo,", %s protocol %d port %d unreachable",
812 ip6addr_string(&oip->ip6_dst),
813 oip->ip6_nxt, dport));
814 break;
815 }
816 break;
817 default:
818 if (ndo->ndo_vflag <= 1) {
819 print_unknown_data(ndo, bp,"\n\t",length);
820 return;
821 }
822 break;
823 }
824 break;
825 case ICMP6_PACKET_TOO_BIG:
826 ND_TCHECK(dp->icmp6_mtu);
827 ND_PRINT((ndo,", mtu %u", EXTRACT_32BITS(&dp->icmp6_mtu)));
828 break;
829 case ICMP6_TIME_EXCEEDED:
830 ND_TCHECK(oip->ip6_dst);
831 switch (dp->icmp6_code) {
832 case ICMP6_TIME_EXCEED_TRANSIT:
833 ND_PRINT((ndo," for %s",
834 ip6addr_string(&oip->ip6_dst)));
835 break;
836 case ICMP6_TIME_EXCEED_REASSEMBLY:
837 ND_PRINT((ndo," (reassembly)"));
838 break;
839 default:
840 ND_PRINT((ndo,", unknown code (%u)", dp->icmp6_code));
841 break;
842 }
843 break;
844 case ICMP6_PARAM_PROB:
845 ND_TCHECK(oip->ip6_dst);
846 switch (dp->icmp6_code) {
847 case ICMP6_PARAMPROB_HEADER:
848 ND_PRINT((ndo,", erroneous - octet %u", EXTRACT_32BITS(&dp->icmp6_pptr)));
849 break;
850 case ICMP6_PARAMPROB_NEXTHEADER:
851 ND_PRINT((ndo,", next header - octet %u", EXTRACT_32BITS(&dp->icmp6_pptr)));
852 break;
853 case ICMP6_PARAMPROB_OPTION:
854 ND_PRINT((ndo,", option - octet %u", EXTRACT_32BITS(&dp->icmp6_pptr)));
855 break;
856 default:
857 ND_PRINT((ndo,", code-#%d",
858 dp->icmp6_code));
859 break;
860 }
861 break;
862 case ICMP6_ECHO_REQUEST:
863 case ICMP6_ECHO_REPLY:
864 ND_TCHECK(dp->icmp6_seq);
865 ND_PRINT((ndo,", seq %u", EXTRACT_16BITS(&dp->icmp6_seq)));
866 break;
867 case ICMP6_MEMBERSHIP_QUERY:
868 if (length == MLD_MINLEN) {
869 mld6_print(ndo, (const u_char *)dp);
870 } else if (length >= MLDV2_MINLEN) {
871 ND_PRINT((ndo," v2"));
872 mldv2_query_print(ndo, (const u_char *)dp, length);
873 } else {
874 ND_PRINT((ndo," unknown-version (len %u) ", length));
875 }
876 break;
877 case ICMP6_MEMBERSHIP_REPORT:
878 mld6_print(ndo, (const u_char *)dp);
879 break;
880 case ICMP6_MEMBERSHIP_REDUCTION:
881 mld6_print(ndo, (const u_char *)dp);
882 break;
883 case ND_ROUTER_SOLICIT:
884 #define RTSOLLEN 8
885 if (ndo->ndo_vflag) {
886 icmp6_opt_print(ndo, (const u_char *)dp + RTSOLLEN,
887 length - RTSOLLEN);
888 }
889 break;
890 case ND_ROUTER_ADVERT:
891 #define RTADVLEN 16
892 if (ndo->ndo_vflag) {
893 struct nd_router_advert *p;
894
895 p = (struct nd_router_advert *)dp;
896 ND_TCHECK(p->nd_ra_retransmit);
897 ND_PRINT((ndo,"\n\thop limit %u, Flags [%s]" \
898 ", pref %s, router lifetime %us, reachable time %us, retrans time %us",
899 (u_int)p->nd_ra_curhoplimit,
900 bittok2str(icmp6_opt_ra_flag_values,"none",(p->nd_ra_flags_reserved)),
901 get_rtpref(p->nd_ra_flags_reserved),
902 EXTRACT_16BITS(&p->nd_ra_router_lifetime),
903 EXTRACT_32BITS(&p->nd_ra_reachable),
904 EXTRACT_32BITS(&p->nd_ra_retransmit)));
905
906 icmp6_opt_print(ndo, (const u_char *)dp + RTADVLEN,
907 length - RTADVLEN);
908 }
909 break;
910 case ND_NEIGHBOR_SOLICIT:
911 {
912 struct nd_neighbor_solicit *p;
913 p = (struct nd_neighbor_solicit *)dp;
914 ND_TCHECK(p->nd_ns_target);
915 ND_PRINT((ndo,", who has %s", ip6addr_string(&p->nd_ns_target)));
916 if (ndo->ndo_vflag) {
917 #define NDSOLLEN 24
918 icmp6_opt_print(ndo, (const u_char *)dp + NDSOLLEN,
919 length - NDSOLLEN);
920 }
921 }
922 break;
923 case ND_NEIGHBOR_ADVERT:
924 {
925 struct nd_neighbor_advert *p;
926
927 p = (struct nd_neighbor_advert *)dp;
928 ND_TCHECK(p->nd_na_target);
929 ND_PRINT((ndo,", tgt is %s",
930 ip6addr_string(&p->nd_na_target)));
931 if (ndo->ndo_vflag) {
932 ND_PRINT((ndo,", Flags [%s]",
933 bittok2str(icmp6_nd_na_flag_values,
934 "none",
935 EXTRACT_32BITS(&p->nd_na_flags_reserved))));
936 #define NDADVLEN 24
937 icmp6_opt_print(ndo, (const u_char *)dp + NDADVLEN,
938 length - NDADVLEN);
939 #undef NDADVLEN
940 }
941 }
942 break;
943 case ND_REDIRECT:
944 #define RDR(i) ((struct nd_redirect *)(i))
945 ND_TCHECK(RDR(dp)->nd_rd_dst);
946 ND_PRINT((ndo,", %s", getname6((const u_char *)&RDR(dp)->nd_rd_dst)));
947 ND_TCHECK(RDR(dp)->nd_rd_target);
948 ND_PRINT((ndo," to %s",
949 getname6((const u_char*)&RDR(dp)->nd_rd_target)));
950 #define REDIRECTLEN 40
951 if (ndo->ndo_vflag) {
952 icmp6_opt_print(ndo, (const u_char *)dp + REDIRECTLEN,
953 length - REDIRECTLEN);
954 }
955 break;
956 #undef REDIRECTLEN
957 #undef RDR
958 case ICMP6_ROUTER_RENUMBERING:
959 icmp6_rrenum_print(ndo, bp, ep);
960 break;
961 case ICMP6_NI_QUERY:
962 case ICMP6_NI_REPLY:
963 icmp6_nodeinfo_print(ndo, length, bp, ep);
964 break;
965 case IND_SOLICIT:
966 case IND_ADVERT:
967 break;
968 case ICMP6_V2_MEMBERSHIP_REPORT:
969 mldv2_report_print(ndo, (const u_char *) dp, length);
970 break;
971 case ICMP6_MOBILEPREFIX_SOLICIT: /* fall through */
972 case ICMP6_HADISCOV_REQUEST:
973 ND_TCHECK(dp->icmp6_data16[0]);
974 ND_PRINT((ndo,", id 0x%04x", EXTRACT_16BITS(&dp->icmp6_data16[0])));
975 break;
976 case ICMP6_HADISCOV_REPLY:
977 if (ndo->ndo_vflag) {
978 struct in6_addr *in6;
979 u_char *cp;
980
981 ND_TCHECK(dp->icmp6_data16[0]);
982 ND_PRINT((ndo,", id 0x%04x", EXTRACT_16BITS(&dp->icmp6_data16[0])));
983 cp = (u_char *)dp + length;
984 in6 = (struct in6_addr *)(dp + 1);
985 for (; (u_char *)in6 < cp; in6++) {
986 ND_TCHECK(*in6);
987 ND_PRINT((ndo,", %s", ip6addr_string(in6)));
988 }
989 }
990 break;
991 case ICMP6_MOBILEPREFIX_ADVERT:
992 if (ndo->ndo_vflag) {
993 ND_TCHECK(dp->icmp6_data16[0]);
994 ND_PRINT((ndo,", id 0x%04x", EXTRACT_16BITS(&dp->icmp6_data16[0])));
995 if (dp->icmp6_data16[1] & 0xc0)
996 ND_PRINT((ndo," "));
997 if (dp->icmp6_data16[1] & 0x80)
998 ND_PRINT((ndo,"M"));
999 if (dp->icmp6_data16[1] & 0x40)
1000 ND_PRINT((ndo,"O"));
1001 #define MPADVLEN 8
1002 icmp6_opt_print(ndo, (const u_char *)dp + MPADVLEN,
1003 length - MPADVLEN);
1004 }
1005 break;
1006 case ND_RPL_MESSAGE:
1007 rpl_print(ndo, dp, &dp->icmp6_data8[0], length);
1008 break;
1009 default:
1010 ND_PRINT((ndo,", length %u", length));
1011 if (ndo->ndo_vflag <= 1)
1012 print_unknown_data(ndo, bp,"\n\t", length);
1013 return;
1014 }
1015 if (!ndo->ndo_vflag)
1016 ND_PRINT((ndo,", length %u", length));
1017 return;
1018 trunc:
1019 ND_PRINT((ndo, "[|icmp6]"));
1020 }
1021
1022 static struct udphdr *
1023 get_upperlayer(netdissect_options *ndo, u_char *bp, u_int *prot)
1024 {
1025 const u_char *ep;
1026 struct ip6_hdr *ip6 = (struct ip6_hdr *)bp;
1027 struct udphdr *uh;
1028 struct ip6_hbh *hbh;
1029 struct ip6_frag *fragh;
1030 struct ah *ah;
1031 u_int nh;
1032 int hlen;
1033
1034 /* 'ep' points to the end of available data. */
1035 ep = ndo->ndo_snapend;
1036
1037 if (!ND_TTEST(ip6->ip6_nxt))
1038 return NULL;
1039
1040 nh = ip6->ip6_nxt;
1041 hlen = sizeof(struct ip6_hdr);
1042
1043 while (bp < ep) {
1044 bp += hlen;
1045
1046 switch(nh) {
1047 case IPPROTO_UDP:
1048 case IPPROTO_TCP:
1049 uh = (struct udphdr *)bp;
1050 if (ND_TTEST(uh->uh_dport)) {
1051 *prot = nh;
1052 return(uh);
1053 }
1054 else
1055 return(NULL);
1056 /* NOTREACHED */
1057
1058 case IPPROTO_HOPOPTS:
1059 case IPPROTO_DSTOPTS:
1060 case IPPROTO_ROUTING:
1061 hbh = (struct ip6_hbh *)bp;
1062 if (!ND_TTEST(hbh->ip6h_len))
1063 return(NULL);
1064 nh = hbh->ip6h_nxt;
1065 hlen = (hbh->ip6h_len + 1) << 3;
1066 break;
1067
1068 case IPPROTO_FRAGMENT: /* this should be odd, but try anyway */
1069 fragh = (struct ip6_frag *)bp;
1070 if (!ND_TTEST(fragh->ip6f_offlg))
1071 return(NULL);
1072 /* fragments with non-zero offset are meaningless */
1073 if ((EXTRACT_16BITS(&fragh->ip6f_offlg) & IP6F_OFF_MASK) != 0)
1074 return(NULL);
1075 nh = fragh->ip6f_nxt;
1076 hlen = sizeof(struct ip6_frag);
1077 break;
1078
1079 case IPPROTO_AH:
1080 ah = (struct ah *)bp;
1081 if (!ND_TTEST(ah->ah_len))
1082 return(NULL);
1083 nh = ah->ah_nxt;
1084 hlen = (ah->ah_len + 2) << 2;
1085 break;
1086
1087 default: /* unknown or undecodable header */
1088 *prot = nh; /* meaningless, but set here anyway */
1089 return(NULL);
1090 }
1091 }
1092
1093 return(NULL); /* should be notreached, though */
1094 }
1095
1096 static void
1097 icmp6_opt_print(netdissect_options *ndo, const u_char *bp, int resid)
1098 {
1099 const struct nd_opt_hdr *op;
1100 const struct nd_opt_prefix_info *opp;
1101 const struct nd_opt_mtu *opm;
1102 const struct nd_opt_rdnss *oprd;
1103 const struct nd_opt_dnssl *opds;
1104 const struct nd_opt_advinterval *opa;
1105 const struct nd_opt_homeagent_info *oph;
1106 const struct nd_opt_route_info *opri;
1107 const u_char *cp, *ep, *domp;
1108 struct in6_addr in6, *in6p;
1109 size_t l;
1110 u_int i;
1111
1112 #define ECHECK(var) if ((u_char *)&(var) > ep - sizeof(var)) return
1113
1114 cp = bp;
1115 /* 'ep' points to the end of available data. */
1116 ep = ndo->ndo_snapend;
1117
1118 while (cp < ep) {
1119 op = (struct nd_opt_hdr *)cp;
1120
1121 ECHECK(op->nd_opt_len);
1122 if (resid <= 0)
1123 return;
1124 if (op->nd_opt_len == 0)
1125 goto trunc;
1126 if (cp + (op->nd_opt_len << 3) > ep)
1127 goto trunc;
1128
1129 ND_PRINT((ndo,"\n\t %s option (%u), length %u (%u): ",
1130 tok2str(icmp6_opt_values, "unknown", op->nd_opt_type),
1131 op->nd_opt_type,
1132 op->nd_opt_len << 3,
1133 op->nd_opt_len));
1134
1135 switch (op->nd_opt_type) {
1136 case ND_OPT_SOURCE_LINKADDR:
1137 l = (op->nd_opt_len << 3) - 2;
1138 print_lladdr(ndo, cp + 2, l);
1139 break;
1140 case ND_OPT_TARGET_LINKADDR:
1141 l = (op->nd_opt_len << 3) - 2;
1142 print_lladdr(ndo, cp + 2, l);
1143 break;
1144 case ND_OPT_PREFIX_INFORMATION:
1145 opp = (struct nd_opt_prefix_info *)op;
1146 ND_TCHECK(opp->nd_opt_pi_prefix);
1147 ND_PRINT((ndo,"%s/%u%s, Flags [%s], valid time %s",
1148 ip6addr_string(&opp->nd_opt_pi_prefix),
1149 opp->nd_opt_pi_prefix_len,
1150 (op->nd_opt_len != 4) ? "badlen" : "",
1151 bittok2str(icmp6_opt_pi_flag_values, "none", opp->nd_opt_pi_flags_reserved),
1152 get_lifetime(EXTRACT_32BITS(&opp->nd_opt_pi_valid_time))));
1153 ND_PRINT((ndo,", pref. time %s", get_lifetime(EXTRACT_32BITS(&opp->nd_opt_pi_preferred_time))));
1154 break;
1155 case ND_OPT_REDIRECTED_HEADER:
1156 print_unknown_data(ndo, bp,"\n\t ",op->nd_opt_len<<3);
1157 /* xxx */
1158 break;
1159 case ND_OPT_MTU:
1160 opm = (struct nd_opt_mtu *)op;
1161 ND_TCHECK(opm->nd_opt_mtu_mtu);
1162 ND_PRINT((ndo," %u%s",
1163 EXTRACT_32BITS(&opm->nd_opt_mtu_mtu),
1164 (op->nd_opt_len != 1) ? "bad option length" : "" ));
1165 break;
1166 case ND_OPT_RDNSS:
1167 oprd = (struct nd_opt_rdnss *)op;
1168 l = (op->nd_opt_len - 1) / 2;
1169 ND_PRINT((ndo," lifetime %us,",
1170 EXTRACT_32BITS(&oprd->nd_opt_rdnss_lifetime)));
1171 for (i = 0; i < l; i++) {
1172 ND_TCHECK(oprd->nd_opt_rdnss_addr[i]);
1173 ND_PRINT((ndo," addr: %s",
1174 ip6addr_string(&oprd->nd_opt_rdnss_addr[i])));
1175 }
1176 break;
1177 case ND_OPT_DNSSL:
1178 opds = (struct nd_opt_dnssl *)op;
1179 ND_PRINT((ndo," lifetime %us, domain(s):",
1180 EXTRACT_32BITS(&opds->nd_opt_dnssl_lifetime)));
1181 domp = cp + 8; /* domain names, variable-sized, RFC1035-encoded */
1182 while (domp < cp + (op->nd_opt_len << 3) && *domp != '\0')
1183 {
1184 printf (" ");
1185 if ((domp = ns_nprint (domp, bp)) == NULL)
1186 goto trunc;
1187 }
1188 break;
1189 case ND_OPT_ADVINTERVAL:
1190 opa = (struct nd_opt_advinterval *)op;
1191 ND_TCHECK(opa->nd_opt_adv_interval);
1192 ND_PRINT((ndo," %ums", EXTRACT_32BITS(&opa->nd_opt_adv_interval)));
1193 break;
1194 case ND_OPT_HOMEAGENT_INFO:
1195 oph = (struct nd_opt_homeagent_info *)op;
1196 ND_TCHECK(oph->nd_opt_hai_lifetime);
1197 ND_PRINT((ndo," preference %u, lifetime %u",
1198 EXTRACT_16BITS(&oph->nd_opt_hai_preference),
1199 EXTRACT_16BITS(&oph->nd_opt_hai_lifetime)));
1200 break;
1201 case ND_OPT_ROUTE_INFO:
1202 opri = (struct nd_opt_route_info *)op;
1203 ND_TCHECK(opri->nd_opt_rti_lifetime);
1204 memset(&in6, 0, sizeof(in6));
1205 in6p = (struct in6_addr *)(opri + 1);
1206 switch (op->nd_opt_len) {
1207 case 1:
1208 break;
1209 case 2:
1210 ND_TCHECK2(*in6p, 8);
1211 memcpy(&in6, opri + 1, 8);
1212 break;
1213 case 3:
1214 ND_TCHECK(*in6p);
1215 memcpy(&in6, opri + 1, sizeof(in6));
1216 break;
1217 default:
1218 goto trunc;
1219 }
1220 ND_PRINT((ndo," %s/%u", ip6addr_string(&in6),
1221 opri->nd_opt_rti_prefixlen));
1222 ND_PRINT((ndo,", pref=%s", get_rtpref(opri->nd_opt_rti_flags)));
1223 ND_PRINT((ndo,", lifetime=%s",
1224 get_lifetime(EXTRACT_32BITS(&opri->nd_opt_rti_lifetime))));
1225 break;
1226 default:
1227 if (ndo->ndo_vflag <= 1) {
1228 print_unknown_data(ndo,cp+2,"\n\t ", (op->nd_opt_len << 3) - 2); /* skip option header */
1229 return;
1230 }
1231 break;
1232 }
1233 /* do we want to see an additional hexdump ? */
1234 if (ndo->ndo_vflag> 1)
1235 print_unknown_data(ndo, cp+2,"\n\t ", (op->nd_opt_len << 3) - 2); /* skip option header */
1236
1237 cp += op->nd_opt_len << 3;
1238 resid -= op->nd_opt_len << 3;
1239 }
1240 return;
1241
1242 trunc:
1243 ND_PRINT((ndo, "[ndp opt]"));
1244 return;
1245 #undef ECHECK
1246 }
1247
1248 static void
1249 mld6_print(netdissect_options *ndo, const u_char *bp)
1250 {
1251 struct mld6_hdr *mp = (struct mld6_hdr *)bp;
1252 const u_char *ep;
1253
1254 /* 'ep' points to the end of available data. */
1255 ep = ndo->ndo_snapend;
1256
1257 if ((u_char *)mp + sizeof(*mp) > ep)
1258 return;
1259
1260 ND_PRINT((ndo,"max resp delay: %d ", EXTRACT_16BITS(&mp->mld6_maxdelay)));
1261 ND_PRINT((ndo,"addr: %s", ip6addr_string(&mp->mld6_addr)));
1262 }
1263
1264 static void
1265 mldv2_report_print(netdissect_options *ndo, const u_char *bp, u_int len)
1266 {
1267 struct icmp6_hdr *icp = (struct icmp6_hdr *) bp;
1268 u_int group, nsrcs, ngroups;
1269 u_int i, j;
1270
1271 /* Minimum len is 8 */
1272 if (len < 8) {
1273 ND_PRINT((ndo," [invalid len %d]", len));
1274 return;
1275 }
1276
1277 ND_TCHECK(icp->icmp6_data16[1]);
1278 ngroups = EXTRACT_16BITS(&icp->icmp6_data16[1]);
1279 ND_PRINT((ndo,", %d group record(s)", ngroups));
1280 if (ndo->ndo_vflag > 0) {
1281 /* Print the group records */
1282 group = 8;
1283 for (i = 0; i < ngroups; i++) {
1284 /* type(1) + auxlen(1) + numsrc(2) + grp(16) */
1285 if (len < group + 20) {
1286 ND_PRINT((ndo," [invalid number of groups]"));
1287 return;
1288 }
1289 ND_TCHECK2(bp[group + 4], sizeof(struct in6_addr));
1290 ND_PRINT((ndo," [gaddr %s", ip6addr_string(&bp[group + 4])));
1291 ND_PRINT((ndo," %s", tok2str(mldv2report2str, " [v2-report-#%d]",
1292 bp[group])));
1293 nsrcs = (bp[group + 2] << 8) + bp[group + 3];
1294 /* Check the number of sources and print them */
1295 if (len < group + 20 + (nsrcs * sizeof(struct in6_addr))) {
1296 ND_PRINT((ndo," [invalid number of sources %d]", nsrcs));
1297 return;
1298 }
1299 if (ndo->ndo_vflag == 1)
1300 ND_PRINT((ndo,", %d source(s)", nsrcs));
1301 else {
1302 /* Print the sources */
1303 (void)ND_PRINT((ndo," {"));
1304 for (j = 0; j < nsrcs; j++) {
1305 ND_TCHECK2(bp[group + 20 + j * sizeof(struct in6_addr)],
1306 sizeof(struct in6_addr));
1307 ND_PRINT((ndo," %s", ip6addr_string(&bp[group + 20 + j * sizeof(struct in6_addr)])));
1308 }
1309 (void)ND_PRINT((ndo," }"));
1310 }
1311 /* Next group record */
1312 group += 20 + nsrcs * sizeof(struct in6_addr);
1313 ND_PRINT((ndo,"]"));
1314 }
1315 }
1316 return;
1317 trunc:
1318 (void)ND_PRINT((ndo,"[|icmp6]"));
1319 return;
1320 }
1321
1322 static void
1323 mldv2_query_print(netdissect_options *ndo, const u_char *bp, u_int len)
1324 {
1325 struct icmp6_hdr *icp = (struct icmp6_hdr *) bp;
1326 u_int mrc;
1327 int mrt, qqi;
1328 u_int nsrcs;
1329 register u_int i;
1330
1331 /* Minimum len is 28 */
1332 if (len < 28) {
1333 ND_PRINT((ndo," [invalid len %d]", len));
1334 return;
1335 }
1336 ND_TCHECK(icp->icmp6_data16[0]);
1337 mrc = EXTRACT_16BITS(&icp->icmp6_data16[0]);
1338 if (mrc < 32768) {
1339 mrt = mrc;
1340 } else {
1341 mrt = ((mrc & 0x0fff) | 0x1000) << (((mrc & 0x7000) >> 12) + 3);
1342 }
1343 if (ndo->ndo_vflag) {
1344 (void)ND_PRINT((ndo," [max resp delay=%d]", mrt));
1345 }
1346 ND_TCHECK2(bp[8], sizeof(struct in6_addr));
1347 ND_PRINT((ndo," [gaddr %s", ip6addr_string(&bp[8])));
1348
1349 if (ndo->ndo_vflag) {
1350 ND_TCHECK(bp[25]);
1351 if (bp[24] & 0x08) {
1352 ND_PRINT((ndo," sflag"));
1353 }
1354 if (bp[24] & 0x07) {
1355 ND_PRINT((ndo," robustness=%d", bp[24] & 0x07));
1356 }
1357 if (bp[25] < 128) {
1358 qqi = bp[25];
1359 } else {
1360 qqi = ((bp[25] & 0x0f) | 0x10) << (((bp[25] & 0x70) >> 4) + 3);
1361 }
1362 ND_PRINT((ndo," qqi=%d", qqi));
1363 }
1364
1365 ND_TCHECK2(bp[26], 2);
1366 nsrcs = EXTRACT_16BITS(&bp[26]);
1367 if (nsrcs > 0) {
1368 if (len < 28 + nsrcs * sizeof(struct in6_addr))
1369 ND_PRINT((ndo," [invalid number of sources]"));
1370 else if (ndo->ndo_vflag > 1) {
1371 ND_PRINT((ndo," {"));
1372 for (i = 0; i < nsrcs; i++) {
1373 ND_TCHECK2(bp[28 + i * sizeof(struct in6_addr)],
1374 sizeof(struct in6_addr));
1375 ND_PRINT((ndo," %s", ip6addr_string(&bp[28 + i * sizeof(struct in6_addr)])));
1376 }
1377 ND_PRINT((ndo," }"));
1378 } else
1379 ND_PRINT((ndo,", %d source(s)", nsrcs));
1380 }
1381 ND_PRINT((ndo,"]"));
1382 return;
1383 trunc:
1384 (void)ND_PRINT((ndo,"[|icmp6]"));
1385 return;
1386 }
1387
1388 static void
1389 dnsname_print(netdissect_options *ndo, const u_char *cp, const u_char *ep)
1390 {
1391 int i;
1392
1393 /* DNS name decoding - no decompression */
1394 ND_PRINT((ndo,", \""));
1395 while (cp < ep) {
1396 i = *cp++;
1397 if (i) {
1398 if (i > ep - cp) {
1399 ND_PRINT((ndo,"???"));
1400 break;
1401 }
1402 while (i-- && cp < ep) {
1403 safeputchar(*cp);
1404 cp++;
1405 }
1406 if (cp + 1 < ep && *cp)
1407 ND_PRINT((ndo,"."));
1408 } else {
1409 if (cp == ep) {
1410 /* FQDN */
1411 ND_PRINT((ndo,"."));
1412 } else if (cp + 1 == ep && *cp == '\0') {
1413 /* truncated */
1414 } else {
1415 /* invalid */
1416 ND_PRINT((ndo,"???"));
1417 }
1418 break;
1419 }
1420 }
1421 ND_PRINT((ndo,"\""));
1422 }
1423
1424 static void
1425 icmp6_nodeinfo_print(netdissect_options *ndo, u_int icmp6len, const u_char *bp, const u_char *ep)
1426 {
1427 struct icmp6_nodeinfo *ni6;
1428 struct icmp6_hdr *dp;
1429 const u_char *cp;
1430 size_t siz, i;
1431 int needcomma;
1432
1433 if (ep < bp)
1434 return;
1435 dp = (struct icmp6_hdr *)bp;
1436 ni6 = (struct icmp6_nodeinfo *)bp;
1437 siz = ep - bp;
1438
1439 switch (ni6->ni_type) {
1440 case ICMP6_NI_QUERY:
1441 if (siz == sizeof(*dp) + 4) {
1442 /* KAME who-are-you */
1443 ND_PRINT((ndo," who-are-you request"));
1444 break;
1445 }
1446 ND_PRINT((ndo," node information query"));
1447
1448 ND_TCHECK2(*dp, sizeof(*ni6));
1449 ni6 = (struct icmp6_nodeinfo *)dp;
1450 ND_PRINT((ndo," (")); /*)*/
1451 switch (EXTRACT_16BITS(&ni6->ni_qtype)) {
1452 case NI_QTYPE_NOOP:
1453 ND_PRINT((ndo,"noop"));
1454 break;
1455 case NI_QTYPE_SUPTYPES:
1456 ND_PRINT((ndo,"supported qtypes"));
1457 i = EXTRACT_16BITS(&ni6->ni_flags);
1458 if (i)
1459 ND_PRINT((ndo," [%s]", (i & 0x01) ? "C" : ""));
1460 break;
1461 break;
1462 case NI_QTYPE_FQDN:
1463 ND_PRINT((ndo,"DNS name"));
1464 break;
1465 case NI_QTYPE_NODEADDR:
1466 ND_PRINT((ndo,"node addresses"));
1467 i = ni6->ni_flags;
1468 if (!i)
1469 break;
1470 /* NI_NODEADDR_FLAG_TRUNCATE undefined for query */
1471 ND_PRINT((ndo," [%s%s%s%s%s%s]",
1472 (i & NI_NODEADDR_FLAG_ANYCAST) ? "a" : "",
1473 (i & NI_NODEADDR_FLAG_GLOBAL) ? "G" : "",
1474 (i & NI_NODEADDR_FLAG_SITELOCAL) ? "S" : "",
1475 (i & NI_NODEADDR_FLAG_LINKLOCAL) ? "L" : "",
1476 (i & NI_NODEADDR_FLAG_COMPAT) ? "C" : "",
1477 (i & NI_NODEADDR_FLAG_ALL) ? "A" : ""));
1478 break;
1479 default:
1480 ND_PRINT((ndo,"unknown"));
1481 break;
1482 }
1483
1484 if (ni6->ni_qtype == NI_QTYPE_NOOP ||
1485 ni6->ni_qtype == NI_QTYPE_SUPTYPES) {
1486 if (siz != sizeof(*ni6))
1487 if (ndo->ndo_vflag)
1488 ND_PRINT((ndo,", invalid len"));
1489 /*(*/
1490 ND_PRINT((ndo,")"));
1491 break;
1492 }
1493
1494
1495 /* XXX backward compat, icmp-name-lookup-03 */
1496 if (siz == sizeof(*ni6)) {
1497 ND_PRINT((ndo,", 03 draft"));
1498 /*(*/
1499 ND_PRINT((ndo,")"));
1500 break;
1501 }
1502
1503 switch (ni6->ni_code) {
1504 case ICMP6_NI_SUBJ_IPV6:
1505 if (!ND_TTEST2(*dp,
1506 sizeof(*ni6) + sizeof(struct in6_addr)))
1507 break;
1508 if (siz != sizeof(*ni6) + sizeof(struct in6_addr)) {
1509 if (ndo->ndo_vflag)
1510 ND_PRINT((ndo,", invalid subject len"));
1511 break;
1512 }
1513 ND_PRINT((ndo,", subject=%s",
1514 getname6((const u_char *)(ni6 + 1))));
1515 break;
1516 case ICMP6_NI_SUBJ_FQDN:
1517 ND_PRINT((ndo,", subject=DNS name"));
1518 cp = (const u_char *)(ni6 + 1);
1519 if (cp[0] == ep - cp - 1) {
1520 /* icmp-name-lookup-03, pascal string */
1521 if (ndo->ndo_vflag)
1522 ND_PRINT((ndo,", 03 draft"));
1523 cp++;
1524 ND_PRINT((ndo,", \""));
1525 while (cp < ep) {
1526 safeputchar(*cp);
1527 cp++;
1528 }
1529 ND_PRINT((ndo,"\""));
1530 } else
1531 dnsname_print(ndo, cp, ep);
1532 break;
1533 case ICMP6_NI_SUBJ_IPV4:
1534 if (!ND_TTEST2(*dp, sizeof(*ni6) + sizeof(struct in_addr)))
1535 break;
1536 if (siz != sizeof(*ni6) + sizeof(struct in_addr)) {
1537 if (ndo->ndo_vflag)
1538 ND_PRINT((ndo,", invalid subject len"));
1539 break;
1540 }
1541 ND_PRINT((ndo,", subject=%s",
1542 getname((const u_char *)(ni6 + 1))));
1543 break;
1544 default:
1545 ND_PRINT((ndo,", unknown subject"));
1546 break;
1547 }
1548
1549 /*(*/
1550 ND_PRINT((ndo,")"));
1551 break;
1552
1553 case ICMP6_NI_REPLY:
1554 if (icmp6len > siz) {
1555 ND_PRINT((ndo,"[|icmp6: node information reply]"));
1556 break;
1557 }
1558
1559 needcomma = 0;
1560
1561 ni6 = (struct icmp6_nodeinfo *)dp;
1562 ND_PRINT((ndo," node information reply"));
1563 ND_PRINT((ndo," (")); /*)*/
1564 switch (ni6->ni_code) {
1565 case ICMP6_NI_SUCCESS:
1566 if (ndo->ndo_vflag) {
1567 ND_PRINT((ndo,"success"));
1568 needcomma++;
1569 }
1570 break;
1571 case ICMP6_NI_REFUSED:
1572 ND_PRINT((ndo,"refused"));
1573 needcomma++;
1574 if (siz != sizeof(*ni6))
1575 if (ndo->ndo_vflag)
1576 ND_PRINT((ndo,", invalid length"));
1577 break;
1578 case ICMP6_NI_UNKNOWN:
1579 ND_PRINT((ndo,"unknown"));
1580 needcomma++;
1581 if (siz != sizeof(*ni6))
1582 if (ndo->ndo_vflag)
1583 ND_PRINT((ndo,", invalid length"));
1584 break;
1585 }
1586
1587 if (ni6->ni_code != ICMP6_NI_SUCCESS) {
1588 /*(*/
1589 ND_PRINT((ndo,")"));
1590 break;
1591 }
1592
1593 switch (EXTRACT_16BITS(&ni6->ni_qtype)) {
1594 case NI_QTYPE_NOOP:
1595 if (needcomma)
1596 ND_PRINT((ndo,", "));
1597 ND_PRINT((ndo,"noop"));
1598 if (siz != sizeof(*ni6))
1599 if (ndo->ndo_vflag)
1600 ND_PRINT((ndo,", invalid length"));
1601 break;
1602 case NI_QTYPE_SUPTYPES:
1603 if (needcomma)
1604 ND_PRINT((ndo,", "));
1605 ND_PRINT((ndo,"supported qtypes"));
1606 i = EXTRACT_16BITS(&ni6->ni_flags);
1607 if (i)
1608 ND_PRINT((ndo," [%s]", (i & 0x01) ? "C" : ""));
1609 break;
1610 case NI_QTYPE_FQDN:
1611 if (needcomma)
1612 ND_PRINT((ndo,", "));
1613 ND_PRINT((ndo,"DNS name"));
1614 cp = (const u_char *)(ni6 + 1) + 4;
1615 if (cp[0] == ep - cp - 1) {
1616 /* icmp-name-lookup-03, pascal string */
1617 if (ndo->ndo_vflag)
1618 ND_PRINT((ndo,", 03 draft"));
1619 cp++;
1620 ND_PRINT((ndo,", \""));
1621 while (cp < ep) {
1622 safeputchar(*cp);
1623 cp++;
1624 }
1625 ND_PRINT((ndo,"\""));
1626 } else
1627 dnsname_print(ndo, cp, ep);
1628 if ((EXTRACT_16BITS(&ni6->ni_flags) & 0x01) != 0)
1629 ND_PRINT((ndo," [TTL=%u]", *(u_int32_t *)(ni6 + 1)));
1630 break;
1631 case NI_QTYPE_NODEADDR:
1632 if (needcomma)
1633 ND_PRINT((ndo,", "));
1634 ND_PRINT((ndo,"node addresses"));
1635 i = sizeof(*ni6);
1636 while (i < siz) {
1637 if (i + sizeof(struct in6_addr) + sizeof(int32_t) > siz)
1638 break;
1639 ND_PRINT((ndo," %s", getname6(bp + i)));
1640 i += sizeof(struct in6_addr);
1641 ND_PRINT((ndo,"(%d)", (int32_t)EXTRACT_32BITS(bp + i)));
1642 i += sizeof(int32_t);
1643 }
1644 i = ni6->ni_flags;
1645 if (!i)
1646 break;
1647 ND_PRINT((ndo," [%s%s%s%s%s%s%s]",
1648 (i & NI_NODEADDR_FLAG_ANYCAST) ? "a" : "",
1649 (i & NI_NODEADDR_FLAG_GLOBAL) ? "G" : "",
1650 (i & NI_NODEADDR_FLAG_SITELOCAL) ? "S" : "",
1651 (i & NI_NODEADDR_FLAG_LINKLOCAL) ? "L" : "",
1652 (i & NI_NODEADDR_FLAG_COMPAT) ? "C" : "",
1653 (i & NI_NODEADDR_FLAG_ALL) ? "A" : "",
1654 (i & NI_NODEADDR_FLAG_TRUNCATE) ? "T" : ""));
1655 break;
1656 default:
1657 if (needcomma)
1658 ND_PRINT((ndo,", "));
1659 ND_PRINT((ndo,"unknown"));
1660 break;
1661 }
1662
1663 /*(*/
1664 ND_PRINT((ndo,")"));
1665 break;
1666 }
1667 return;
1668
1669 trunc:
1670 ND_PRINT((ndo, "[|icmp6]"));
1671 }
1672
1673 static void
1674 icmp6_rrenum_print(netdissect_options *ndo, const u_char *bp, const u_char *ep)
1675 {
1676 struct icmp6_router_renum *rr6;
1677 const char *cp;
1678 struct rr_pco_match *match;
1679 struct rr_pco_use *use;
1680 char hbuf[NI_MAXHOST];
1681 int n;
1682
1683 if (ep < bp)
1684 return;
1685 rr6 = (struct icmp6_router_renum *)bp;
1686 cp = (const char *)(rr6 + 1);
1687
1688 ND_TCHECK(rr6->rr_reserved);
1689 switch (rr6->rr_code) {
1690 case ICMP6_ROUTER_RENUMBERING_COMMAND:
1691 ND_PRINT((ndo,"router renum: command"));
1692 break;
1693 case ICMP6_ROUTER_RENUMBERING_RESULT:
1694 ND_PRINT((ndo,"router renum: result"));
1695 break;
1696 case ICMP6_ROUTER_RENUMBERING_SEQNUM_RESET:
1697 ND_PRINT((ndo,"router renum: sequence number reset"));
1698 break;
1699 default:
1700 ND_PRINT((ndo,"router renum: code-#%d", rr6->rr_code));
1701 break;
1702 }
1703
1704 ND_PRINT((ndo,", seq=%u", EXTRACT_32BITS(&rr6->rr_seqnum)));
1705
1706 if (ndo->ndo_vflag) {
1707 #define F(x, y) ((rr6->rr_flags) & (x) ? (y) : "")
1708 ND_PRINT((ndo,"[")); /*]*/
1709 if (rr6->rr_flags) {
1710 ND_PRINT((ndo,"%s%s%s%s%s,", F(ICMP6_RR_FLAGS_TEST, "T"),
1711 F(ICMP6_RR_FLAGS_REQRESULT, "R"),
1712 F(ICMP6_RR_FLAGS_FORCEAPPLY, "A"),
1713 F(ICMP6_RR_FLAGS_SPECSITE, "S"),
1714 F(ICMP6_RR_FLAGS_PREVDONE, "P")));
1715 }
1716 ND_PRINT((ndo,"seg=%u,", rr6->rr_segnum));
1717 ND_PRINT((ndo,"maxdelay=%u", EXTRACT_16BITS(&rr6->rr_maxdelay)));
1718 if (rr6->rr_reserved)
1719 ND_PRINT((ndo,"rsvd=0x%x", EXTRACT_32BITS(&rr6->rr_reserved)));
1720 /*[*/
1721 ND_PRINT((ndo,"]"));
1722 #undef F
1723 }
1724
1725 if (rr6->rr_code == ICMP6_ROUTER_RENUMBERING_COMMAND) {
1726 match = (struct rr_pco_match *)cp;
1727 cp = (const char *)(match + 1);
1728
1729 ND_TCHECK(match->rpm_prefix);
1730
1731 if (ndo->ndo_vflag > 1)
1732 ND_PRINT((ndo,"\n\t"));
1733 else
1734 ND_PRINT((ndo," "));
1735 ND_PRINT((ndo,"match(")); /*)*/
1736 switch (match->rpm_code) {
1737 case RPM_PCO_ADD: ND_PRINT((ndo,"add")); break;
1738 case RPM_PCO_CHANGE: ND_PRINT((ndo,"change")); break;
1739 case RPM_PCO_SETGLOBAL: ND_PRINT((ndo,"setglobal")); break;
1740 default: ND_PRINT((ndo,"#%u", match->rpm_code)); break;
1741 }
1742
1743 if (ndo->ndo_vflag) {
1744 ND_PRINT((ndo,",ord=%u", match->rpm_ordinal));
1745 ND_PRINT((ndo,",min=%u", match->rpm_minlen));
1746 ND_PRINT((ndo,",max=%u", match->rpm_maxlen));
1747 }
1748 if (inet_ntop(AF_INET6, &match->rpm_prefix, hbuf, sizeof(hbuf)))
1749 ND_PRINT((ndo,",%s/%u", hbuf, match->rpm_matchlen));
1750 else
1751 ND_PRINT((ndo,",?/%u", match->rpm_matchlen));
1752 /*(*/
1753 ND_PRINT((ndo,")"));
1754
1755 n = match->rpm_len - 3;
1756 if (n % 4)
1757 goto trunc;
1758 n /= 4;
1759 while (n-- > 0) {
1760 use = (struct rr_pco_use *)cp;
1761 cp = (const char *)(use + 1);
1762
1763 ND_TCHECK(use->rpu_prefix);
1764
1765 if (ndo->ndo_vflag > 1)
1766 ND_PRINT((ndo,"\n\t"));
1767 else
1768 ND_PRINT((ndo," "));
1769 ND_PRINT((ndo,"use(")); /*)*/
1770 if (use->rpu_flags) {
1771 #define F(x, y) ((use->rpu_flags) & (x) ? (y) : "")
1772 ND_PRINT((ndo,"%s%s,",
1773 F(ICMP6_RR_PCOUSE_FLAGS_DECRVLTIME, "V"),
1774 F(ICMP6_RR_PCOUSE_FLAGS_DECRPLTIME, "P")));
1775 #undef F
1776 }
1777 if (ndo->ndo_vflag) {
1778 ND_PRINT((ndo,"mask=0x%x,", use->rpu_ramask));
1779 ND_PRINT((ndo,"raflags=0x%x,", use->rpu_raflags));
1780 if (~use->rpu_vltime == 0)
1781 ND_PRINT((ndo,"vltime=infty,"));
1782 else
1783 ND_PRINT((ndo,"vltime=%u,",
1784 EXTRACT_32BITS(&use->rpu_vltime)));
1785 if (~use->rpu_pltime == 0)
1786 ND_PRINT((ndo,"pltime=infty,"));
1787 else
1788 ND_PRINT((ndo,"pltime=%u,",
1789 EXTRACT_32BITS(&use->rpu_pltime)));
1790 }
1791 if (inet_ntop(AF_INET6, &use->rpu_prefix, hbuf,
1792 sizeof(hbuf)))
1793 ND_PRINT((ndo,"%s/%u/%u", hbuf, use->rpu_uselen,
1794 use->rpu_keeplen));
1795 else
1796 ND_PRINT((ndo,"?/%u/%u", use->rpu_uselen,
1797 use->rpu_keeplen));
1798 /*(*/
1799 ND_PRINT((ndo,")"));
1800 }
1801 }
1802
1803 return;
1804
1805 trunc:
1806 ND_PRINT((ndo,"[|icmp6]"));
1807 }
1808
1809 #endif /* INET6 */
1810
1811 /*
1812 * Local Variables:
1813 * c-style: whitesmith
1814 * c-basic-offset: 8
1815 * End:
1816 */