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