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