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