]> The Tcpdump Group git mirrors - tcpdump/blob - print-icmp6.c
typo. query/reply mixup. from [email protected]
[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 #ifndef lint
23 static const char rcsid[] =
24 "@(#) $Header: /tcpdump/master/tcpdump/print-icmp6.c,v 1.21 2000-08-30 14:28:44 itojun Exp $";
25 #endif
26
27 #ifdef HAVE_CONFIG_H
28 #include "config.h"
29 #endif
30
31 #ifdef INET6
32
33 #include <ctype.h>
34
35 #include <sys/param.h>
36 #include <sys/time.h>
37 #include <sys/types.h>
38 #include <sys/socket.h>
39
40 #include <net/if.h>
41
42 #include <netinet/in.h>
43 #include <netinet/if_ether.h>
44 #include <netinet/in_systm.h>
45 #include <netinet/ip.h>
46 #include <netinet/ip_icmp.h>
47 #include <netinet/ip_var.h>
48 #include <netinet/udp.h>
49 #include <netinet/udp_var.h>
50 #include <netinet/tcp.h>
51
52 #include <arpa/inet.h>
53
54 #include <stdio.h>
55
56 #include <netinet/ip6.h>
57 #include <netinet/icmp6.h>
58
59 #include "interface.h"
60 #include "addrtoname.h"
61
62 void icmp6_opt_print(const u_char *, int);
63 void mld6_print(const u_char *);
64 #ifdef HAVE_STRUCT_ICMP6_NODEINFO
65 static void dnsname_print(const u_char *, const u_char *);
66 void icmp6_nodeinfo_print(int, const u_char *, const u_char *);
67 #endif
68
69 #ifndef abs
70 #define abs(a) ((0 < (a)) ? (a) : -(a))
71 #endif
72
73 #ifndef HAVE_STRUCT_ICMP6_NODEINFO
74 struct icmp6_nodeinfo {
75 struct icmp6_hdr icmp6_ni_hdr;
76 u_int8_t icmp6_ni_nonce[8];
77 /* could be followed by reply data */
78 };
79
80 #define ni_type icmp6_ni_hdr.icmp6_type
81 #define ni_code icmp6_ni_hdr.icmp6_code
82 #define ni_cksum icmp6_ni_hdr.icmp6_cksum
83 #define ni_qtype icmp6_ni_hdr.icmp6_data16[0]
84 #define ni_flags icmp6_ni_hdr.icmp6_data16[1]
85 #endif
86
87 /* cope with past KAME typo - shipped with freebsd4[01] and openbsd27 */
88 #if defined(ICMP6_NI_SUCESS) && !defined(ICMP6_NI_SUCCESS)
89 #define ICMP6_NI_SUCCESS ICMP6_NI_SUCESS
90 #endif
91 #ifndef ICMP6_NI_SUCCESS
92 #define ICMP6_NI_SUCCESS 0 /* node information successful reply */
93 #define ICMP6_NI_REFUSED 1 /* node information request is refused */
94 #define ICMP6_NI_UNKNOWN 2 /* unknown Qtype */
95 #endif
96
97 #ifdef NI_QTYPE_NOOP
98 #define NI_QTYPE_NOOP 0 /* NOOP */
99 #define NI_QTYPE_SUPTYPES 1 /* Supported Qtypes */
100 #define NI_QTYPE_FQDN 2 /* FQDN */
101 #define NI_QTYPE_NODEADDR 3 /* Node Addresses. XXX: spec says 2, but it may be a typo... */
102 #endif
103
104 #ifndef ICMP6_NI_SUBJ_IPV6
105 #define ICMP6_NI_SUBJ_IPV6 0 /* Query Subject is an IPv6 address */
106 #define ICMP6_NI_SUBJ_FQDN 1 /* Query Subject is a Domain name */
107 #define ICMP6_NI_SUBJ_IPV4 2 /* Query Subject is an IPv4 address */
108 #endif
109
110 void
111 icmp6_print(register const u_char *bp, register const u_char *bp2)
112 {
113 const struct icmp6_hdr *dp;
114 register const struct ip6_hdr *ip;
115 register const char *str;
116 register const struct ip6_hdr *oip;
117 register const struct udphdr *ouh;
118 register int hlen, dport;
119 register const u_char *ep;
120 char buf[256];
121 int icmp6len;
122
123 #if 0
124 #define TCHECK(var) if ((u_char *)&(var) > ep - sizeof(var)) goto trunc
125 #endif
126
127 dp = (struct icmp6_hdr *)bp;
128 ip = (struct ip6_hdr *)bp2;
129 oip = (struct ip6_hdr *)(dp + 1);
130 str = buf;
131 /* 'ep' points to the end of avaible data. */
132 ep = snapend;
133 if (ip->ip6_plen)
134 icmp6len = (ntohs(ip->ip6_plen) + sizeof(struct ip6_hdr) -
135 (bp - bp2));
136 else /* XXX: jumbo payload case... */
137 icmp6len = snapend - bp;
138
139 #if 0
140 (void)printf("%s > %s: ",
141 ip6addr_string(&ip->ip6_src),
142 ip6addr_string(&ip->ip6_dst));
143 #endif
144
145 TCHECK(dp->icmp6_code);
146 switch (dp->icmp6_type) {
147 case ICMP6_DST_UNREACH:
148 TCHECK(oip->ip6_dst);
149 switch (dp->icmp6_code) {
150 case ICMP6_DST_UNREACH_NOROUTE:
151 printf("icmp6: %s unreachable route",
152 ip6addr_string(&oip->ip6_dst));
153 break;
154 case ICMP6_DST_UNREACH_ADMIN:
155 printf("icmp6: %s unreachable prohibited",
156 ip6addr_string(&oip->ip6_dst));
157 break;
158 #ifdef ICMP6_DST_UNREACH_BEYONDSCOPE
159 case ICMP6_DST_UNREACH_BEYONDSCOPE:
160 #else
161 case ICMP6_DST_UNREACH_NOTNEIGHBOR:
162 #endif
163 printf("icmp6: %s beyond scope of source address %s",
164 ip6addr_string(&oip->ip6_dst),
165 ip6addr_string(&oip->ip6_src));
166 break;
167 case ICMP6_DST_UNREACH_ADDR:
168 printf("icmp6: %s unreachable address",
169 ip6addr_string(&oip->ip6_dst));
170 break;
171 case ICMP6_DST_UNREACH_NOPORT:
172 TCHECK(oip->ip6_nxt);
173 hlen = sizeof(struct ip6_hdr);
174 ouh = (struct udphdr *)(((u_char *)oip) + hlen);
175 dport = ntohs(ouh->uh_dport);
176 switch (oip->ip6_nxt) {
177 case IPPROTO_TCP:
178 printf("icmp6: %s tcp port %s unreachable",
179 ip6addr_string(&oip->ip6_dst),
180 tcpport_string(dport));
181 break;
182 case IPPROTO_UDP:
183 printf("icmp6: %s udp port %s unreachable",
184 ip6addr_string(&oip->ip6_dst),
185 udpport_string(dport));
186 break;
187 default:
188 printf("icmp6: %s protocol %d port %d unreachable",
189 ip6addr_string(&oip->ip6_dst),
190 oip->ip6_nxt, dport);
191 break;
192 }
193 break;
194 default:
195 printf("icmp6: %s unreachable code-#%d",
196 ip6addr_string(&oip->ip6_dst),
197 dp->icmp6_code);
198 break;
199 }
200 break;
201 case ICMP6_PACKET_TOO_BIG:
202 TCHECK(dp->icmp6_mtu);
203 printf("icmp6: too big %u\n", (u_int32_t)ntohl(dp->icmp6_mtu));
204 break;
205 case ICMP6_TIME_EXCEEDED:
206 TCHECK(oip->ip6_dst);
207 switch (dp->icmp6_code) {
208 case ICMP6_TIME_EXCEED_TRANSIT:
209 printf("icmp6: time exceeded in-transit for %s",
210 ip6addr_string(&oip->ip6_dst));
211 break;
212 case ICMP6_TIME_EXCEED_REASSEMBLY:
213 printf("icmp6: ip6 reassembly time exceeded");
214 break;
215 default:
216 printf("icmp6: time exceeded code-#%d",
217 dp->icmp6_code);
218 break;
219 }
220 break;
221 case ICMP6_PARAM_PROB:
222 TCHECK(oip->ip6_dst);
223 switch (dp->icmp6_code) {
224 case ICMP6_PARAMPROB_HEADER:
225 printf("icmp6: parameter problem errorneous - octet %u\n",
226 (u_int32_t)ntohl(dp->icmp6_pptr));
227 break;
228 case ICMP6_PARAMPROB_NEXTHEADER:
229 printf("icmp6: parameter problem next header - octet %u\n",
230 (u_int32_t)ntohl(dp->icmp6_pptr));
231 break;
232 case ICMP6_PARAMPROB_OPTION:
233 printf("icmp6: parameter problem option - octet %u\n",
234 (u_int32_t)ntohl(dp->icmp6_pptr));
235 break;
236 default:
237 printf("icmp6: parameter problem code-#%d",
238 dp->icmp6_code);
239 break;
240 }
241 break;
242 case ICMP6_ECHO_REQUEST:
243 printf("icmp6: echo request");
244 break;
245 case ICMP6_ECHO_REPLY:
246 printf("icmp6: echo reply");
247 break;
248 #if defined(HAVE_STRUCT_MLD6_HDR) || defined(HAVE_STRUCT_ICMP6_MLD)
249 case ICMP6_MEMBERSHIP_QUERY:
250 printf("icmp6: multicast listener query ");
251 mld6_print((const u_char *)dp);
252 break;
253 case ICMP6_MEMBERSHIP_REPORT:
254 printf("icmp6: multicast listener report ");
255 mld6_print((const u_char *)dp);
256 break;
257 case ICMP6_MEMBERSHIP_REDUCTION:
258 printf("icmp6: multicast listener done ");
259 mld6_print((const u_char *)dp);
260 break;
261 #endif
262 case ND_ROUTER_SOLICIT:
263 printf("icmp6: router solicitation ");
264 if (vflag) {
265 #define RTSOLLEN 8
266 icmp6_opt_print((const u_char *)dp + RTSOLLEN,
267 icmp6len - RTSOLLEN);
268 }
269 break;
270 case ND_ROUTER_ADVERT:
271 printf("icmp6: router advertisement");
272 if (vflag) {
273 struct nd_router_advert *p;
274
275 p = (struct nd_router_advert *)dp;
276 TCHECK(p->nd_ra_retransmit);
277 printf("(chlim=%d, ", (int)p->nd_ra_curhoplimit);
278 if (p->nd_ra_flags_reserved & ND_RA_FLAG_MANAGED)
279 printf("M");
280 if (p->nd_ra_flags_reserved & ND_RA_FLAG_OTHER)
281 printf("O");
282 #ifndef ND_RA_FLAG_HA
283 #define ND_RA_FLAG_HA 0x20
284 #endif
285 if (p->nd_ra_flags_reserved & ND_RA_FLAG_HA)
286 printf("H");
287 if (p->nd_ra_flags_reserved != 0)
288 printf(" ");
289 printf("router_ltime=%d, ", ntohs(p->nd_ra_router_lifetime));
290 printf("reachable_time=%u, ",
291 (u_int32_t)ntohl(p->nd_ra_reachable));
292 printf("retrans_time=%u)",
293 (u_int32_t)ntohl(p->nd_ra_retransmit));
294 #define RTADVLEN 16
295 icmp6_opt_print((const u_char *)dp + RTADVLEN,
296 icmp6len - RTADVLEN);
297 }
298 break;
299 case ND_NEIGHBOR_SOLICIT:
300 {
301 struct nd_neighbor_solicit *p;
302 p = (struct nd_neighbor_solicit *)dp;
303 TCHECK(p->nd_ns_target);
304 printf("icmp6: neighbor sol: who has %s",
305 ip6addr_string(&p->nd_ns_target));
306 if (vflag) {
307 #define NDSOLLEN 24
308 icmp6_opt_print((const u_char *)dp + NDSOLLEN,
309 icmp6len - NDSOLLEN);
310 }
311 }
312 break;
313 case ND_NEIGHBOR_ADVERT:
314 {
315 struct nd_neighbor_advert *p;
316
317 p = (struct nd_neighbor_advert *)dp;
318 TCHECK(p->nd_na_target);
319 printf("icmp6: neighbor adv: tgt is %s",
320 ip6addr_string(&p->nd_na_target));
321 if (vflag) {
322 #define ND_NA_FLAG_ALL \
323 (ND_NA_FLAG_ROUTER|ND_NA_FLAG_SOLICITED|ND_NA_FLAG_OVERRIDE)
324 /* we don't need ntohl() here. see advanced-api-04. */
325 if (p->nd_na_flags_reserved & ND_NA_FLAG_ALL) {
326 #undef ND_NA_FLAG_ALL
327 u_int32_t flags;
328
329 flags = p->nd_na_flags_reserved;
330 printf("(");
331 if (flags & ND_NA_FLAG_ROUTER)
332 printf("R");
333 if (flags & ND_NA_FLAG_SOLICITED)
334 printf("S");
335 if (flags & ND_NA_FLAG_OVERRIDE)
336 printf("O");
337 printf(")");
338 }
339 #define NDADVLEN 24
340 icmp6_opt_print((const u_char *)dp + NDADVLEN,
341 icmp6len - NDADVLEN);
342 #undef NDADVLEN
343 }
344 }
345 break;
346 case ND_REDIRECT:
347 #define RDR(i) ((struct nd_redirect *)(i))
348 TCHECK(RDR(dp)->nd_rd_dst);
349 printf("icmp6: redirect %s",
350 getname6((const u_char *)&RDR(dp)->nd_rd_dst));
351 printf(" to %s",
352 getname6((const u_char*)&RDR(dp)->nd_rd_target));
353 #define REDIRECTLEN 40
354 if (vflag) {
355 icmp6_opt_print((const u_char *)dp + REDIRECTLEN,
356 icmp6len - REDIRECTLEN);
357 }
358 break;
359 #undef REDIRECTLEN
360 #undef RDR
361 #ifndef ICMP6_ROUTER_RENUMBERING
362 #define ICMP6_ROUTER_RENUMBERING 138 /* router renumbering */
363 #endif
364 case ICMP6_ROUTER_RENUMBERING:
365 switch (dp->icmp6_code) {
366 #ifndef ICMP6_ROUTER_RENUMBERING_COMMAND
367 #define ICMP6_ROUTER_RENUMBERING_COMMAND 0 /* rr command */
368 #endif
369 case ICMP6_ROUTER_RENUMBERING_COMMAND:
370 printf("icmp6: router renum command");
371 break;
372 #ifndef ICMP6_ROUTER_RENUMBERING_RESULT
373 #define ICMP6_ROUTER_RENUMBERING_RESULT 1 /* rr result */
374 #endif
375 case ICMP6_ROUTER_RENUMBERING_RESULT:
376 printf("icmp6: router renum result");
377 break;
378 default:
379 printf("icmp6: router renum code-#%d", dp->icmp6_code);
380 break;
381 }
382 break;
383 #ifdef HAVE_STRUCT_ICMP6_NODEINFO
384 #ifndef ICMP6_NI_QUERY
385 #define ICMP6_NI_QUERY 139
386 #endif
387 case ICMP6_NI_QUERY:
388 icmp6_nodeinfo_print(icmp6len, bp, ep);
389 break;
390 #ifndef ICMP6_NI_REPLY
391 #define ICMP6_NI_REPLY 140
392 #endif
393 case ICMP6_NI_REPLY:
394 icmp6_nodeinfo_print(icmp6len, bp, ep);
395 break;
396 #endif
397 default:
398 printf("icmp6: type-#%d", dp->icmp6_type);
399 break;
400 }
401 return;
402 trunc:
403 fputs("[|icmp6]", stdout);
404 #if 0
405 #undef TCHECK
406 #endif
407 }
408
409 void
410 icmp6_opt_print(register const u_char *bp, int resid)
411 {
412 register const struct nd_opt_hdr *op;
413 register const struct nd_opt_hdr *opl; /* why there's no struct? */
414 register const struct nd_opt_prefix_info *opp;
415 register const struct icmp6_opts_redirect *opr;
416 register const struct nd_opt_mtu *opm;
417 register const u_char *ep;
418 int opts_len;
419 #if 0
420 register const struct ip6_hdr *ip;
421 register const char *str;
422 register const struct ip6_hdr *oip;
423 register const struct udphdr *ouh;
424 register int hlen, dport;
425 char buf[256];
426 #endif
427
428 #define ECHECK(var) if ((u_char *)&(var) > ep - sizeof(var)) return
429
430 op = (struct nd_opt_hdr *)bp;
431 #if 0
432 ip = (struct ip6_hdr *)bp2;
433 oip = &dp->icmp6_ip6;
434 str = buf;
435 #endif
436 /* 'ep' points to the end of avaible data. */
437 ep = snapend;
438
439 ECHECK(op->nd_opt_len);
440 if (resid <= 0)
441 return;
442 switch (op->nd_opt_type) {
443 case ND_OPT_SOURCE_LINKADDR:
444 opl = (struct nd_opt_hdr *)op;
445 #if 1
446 if ((u_char *)opl + (opl->nd_opt_len << 3) > ep)
447 goto trunc;
448 #else
449 TCHECK((u_char *)opl + (opl->nd_opt_len << 3) - 1);
450 #endif
451 printf("(src lladdr: %s", /*)*/
452 etheraddr_string((u_char *)(opl + 1)));
453 if (opl->nd_opt_len != 1)
454 printf("!");
455 /*(*/
456 printf(")");
457 icmp6_opt_print((const u_char *)op + (op->nd_opt_len << 3),
458 resid - (op->nd_opt_len << 3));
459 break;
460 case ND_OPT_TARGET_LINKADDR:
461 opl = (struct nd_opt_hdr *)op;
462 #if 1
463 if ((u_char *)opl + (opl->nd_opt_len << 3) > ep)
464 goto trunc;
465 #else
466 TCHECK((u_char *)opl + (opl->nd_opt_len << 3) - 1);
467 #endif
468 printf("(tgt lladdr: %s", /*)*/
469 etheraddr_string((u_char *)(opl + 1)));
470 if (opl->nd_opt_len != 1)
471 printf("!");
472 /*(*/
473 printf(")");
474 icmp6_opt_print((const u_char *)op + (op->nd_opt_len << 3),
475 resid - (op->nd_opt_len << 3));
476 break;
477 case ND_OPT_PREFIX_INFORMATION:
478 opp = (struct nd_opt_prefix_info *)op;
479 TCHECK(opp->nd_opt_pi_prefix);
480 printf("(prefix info: "); /*)*/
481 if (opp->nd_opt_pi_flags_reserved & ND_OPT_PI_FLAG_ONLINK)
482 printf("L");
483 if (opp->nd_opt_pi_flags_reserved & ND_OPT_PI_FLAG_AUTO)
484 printf("A");
485 if (opp->nd_opt_pi_flags_reserved)
486 printf(" ");
487 printf("valid_ltime=");
488 if ((u_int32_t)ntohl(opp->nd_opt_pi_valid_time) == ~0U)
489 printf("infinity");
490 else {
491 printf("%u", (u_int32_t)ntohl(opp->nd_opt_pi_valid_time));
492 }
493 printf(", ");
494 printf("preffered_ltime=");
495 if ((u_int32_t)ntohl(opp->nd_opt_pi_preferred_time) == ~0U)
496 printf("infinity");
497 else {
498 printf("%u", (u_int32_t)ntohl(opp->nd_opt_pi_preferred_time));
499 }
500 printf(", ");
501 printf("prefix=%s/%d", ip6addr_string(&opp->nd_opt_pi_prefix),
502 opp->nd_opt_pi_prefix_len);
503 if (opp->nd_opt_pi_len != 4)
504 printf("!");
505 /*(*/
506 printf(")");
507 icmp6_opt_print((const u_char *)op + (op->nd_opt_len << 3),
508 resid - (op->nd_opt_len << 3));
509 break;
510 case ND_OPT_REDIRECTED_HEADER:
511 opr = (struct icmp6_opts_redirect *)op;
512 printf("(redirect)");
513 /* xxx */
514 icmp6_opt_print((const u_char *)op + (op->nd_opt_len << 3),
515 resid - (op->nd_opt_len << 3));
516 break;
517 case ND_OPT_MTU:
518 opm = (struct nd_opt_mtu *)op;
519 TCHECK(opm->nd_opt_mtu_mtu);
520 printf("(mtu: "); /*)*/
521 printf("mtu=%u", (u_int32_t)ntohl(opm->nd_opt_mtu_mtu));
522 if (opm->nd_opt_mtu_len != 1)
523 printf("!");
524 printf(")");
525 icmp6_opt_print((const u_char *)op + (op->nd_opt_len << 3),
526 resid - (op->nd_opt_len << 3));
527 break;
528 default:
529 opts_len = op->nd_opt_len;
530 printf("(unknwon opt_type=%d, opt_len=%d)",
531 op->nd_opt_type, opts_len);
532 if (opts_len == 0)
533 opts_len = 1; /* XXX */
534 icmp6_opt_print((const u_char *)op + (opts_len << 3),
535 resid - (opts_len << 3));
536 break;
537 }
538 return;
539 trunc:
540 fputs("[ndp opt]", stdout);
541 return;
542 #undef ECHECK
543 }
544
545 #if defined(HAVE_STRUCT_MLD6_HDR)
546 void
547 mld6_print(register const u_char *bp)
548 {
549 register struct mld6_hdr *mp = (struct mld6_hdr *)bp;
550 register const u_char *ep;
551
552 /* 'ep' points to the end of avaible data. */
553 ep = snapend;
554
555 if ((u_char *)mp + sizeof(*mp) > ep)
556 return;
557
558 printf("max resp delay: %d ", ntohs(mp->mld6_maxdelay));
559 printf("addr: %s", ip6addr_string(&mp->mld6_addr));
560 }
561
562 #elif defined(HAVE_STRUCT_ICMP6_MLD)
563
564 void
565 mld6_print(register const u_char *bp)
566 {
567 register struct icmp6_mld *mp = (struct icmp6_mld *)bp;
568 register const u_char *ep;
569
570 /* 'ep' points to the end of avaible data. */
571 ep = snapend;
572
573 if ((u_char *)mp + sizeof(*mp) > ep)
574 return;
575
576 printf("max resp delay: %d ", ntohs(mp->icmp6m_hdr.icmp6_maxdelay));
577 printf("addr: %s", ip6addr_string(&mp->icmp6m_group));
578 }
579
580 #endif
581
582 #ifdef HAVE_STRUCT_ICMP6_NODEINFO
583 static void
584 dnsname_print(const u_char *cp, const u_char *ep)
585 {
586 int i;
587
588 /* DNS name decoding - no decompression */
589 printf(", \"");
590 while (cp < ep) {
591 i = *cp++;
592 if (i) {
593 if (i > ep - cp) {
594 printf("???");
595 break;
596 }
597 while (i-- && cp < ep) {
598 safeputchar(*cp);
599 cp++;
600 }
601 if (cp + 1 < ep && *cp)
602 printf(".");
603 } else {
604 if (cp == ep) {
605 /* FQDN */
606 printf(".");
607 } else if (cp + 1 == ep && *cp == '\0') {
608 /* truncated */
609 } else {
610 /* invalid */
611 printf("???");
612 }
613 break;
614 }
615 }
616 printf("\"");
617 }
618
619 void
620 icmp6_nodeinfo_print(int icmp6len, const u_char *bp, const u_char *ep)
621 {
622 struct icmp6_nodeinfo *ni6;
623 struct icmp6_hdr *dp;
624 const u_char *cp;
625 int siz, i;
626 int needcomma;
627
628 dp = (struct icmp6_hdr *)bp;
629 ni6 = (struct icmp6_nodeinfo *)bp;
630 siz = ep - bp;
631
632 switch (ni6->ni_type) {
633 case ICMP6_NI_QUERY:
634 if (siz == sizeof(*dp) + 4) {
635 /* KAME who-are-you */
636 printf("icmp6: who-are-you request");
637 break;
638 }
639 printf("icmp6: node information query");
640
641 TCHECK2(*dp, sizeof(*ni6));
642 ni6 = (struct icmp6_nodeinfo *)dp;
643 printf(" ("); /*)*/
644 switch (ntohs(ni6->ni_qtype)) {
645 case NI_QTYPE_NOOP:
646 printf("noop");
647 break;
648 case NI_QTYPE_SUPTYPES:
649 printf("supported qtypes");
650 i = ntohs(ni6->ni_flags);
651 if (i)
652 printf(" [%s]", (i & 0x01) ? "C" : "");
653 break;
654 break;
655 case NI_QTYPE_FQDN:
656 printf("DNS name");
657 break;
658 case NI_QTYPE_NODEADDR:
659 printf("node addresses");
660 i = ni6->ni_flags;
661 if (!i)
662 break;
663 /* NI_NODEADDR_FLAG_TRUNCATE undefined for query */
664 printf(" [%s%s%s%s%s%s]",
665 (i & NI_NODEADDR_FLAG_ANYCAST) ? "a" : "",
666 (i & NI_NODEADDR_FLAG_GLOBAL) ? "G" : "",
667 (i & NI_NODEADDR_FLAG_SITELOCAL) ? "S" : "",
668 (i & NI_NODEADDR_FLAG_LINKLOCAL) ? "L" : "",
669 (i & NI_NODEADDR_FLAG_COMPAT) ? "C" : "",
670 (i & NI_NODEADDR_FLAG_ALL) ? "A" : "");
671 break;
672 default:
673 printf("unknown");
674 break;
675 }
676
677 if (ni6->ni_qtype == NI_QTYPE_NOOP ||
678 ni6->ni_qtype == NI_QTYPE_SUPTYPES) {
679 if (siz != sizeof(*ni6))
680 if (vflag)
681 printf(", invalid len");
682 /*(*/
683 printf(")");
684 break;
685 }
686
687
688 /* XXX backward compat, icmp-name-lookup-03 */
689 if (siz == sizeof(*ni6)) {
690 printf(", 03 draft");
691 /*(*/
692 printf(")");
693 break;
694 }
695
696 switch (ni6->ni_code) {
697 case ICMP6_NI_SUBJ_IPV6:
698 if (!TTEST2(*dp,
699 sizeof(*ni6) + sizeof(struct in6_addr)))
700 break;
701 if (siz != sizeof(*ni6) + sizeof(struct in6_addr)) {
702 if (vflag)
703 printf(", invalid subject len");
704 break;
705 }
706 printf(", subject=%s",
707 getname6((const u_char *)(ni6 + 1)));
708 break;
709 case ICMP6_NI_SUBJ_FQDN:
710 printf(", subject=DNS name");
711 cp = (const u_char *)(ni6 + 1);
712 if (cp[0] == ep - cp - 1) {
713 /* icmp-name-lookup-03, pascal string */
714 if (vflag)
715 printf(", 03 draft");
716 cp++;
717 printf(", \"");
718 while (cp < ep) {
719 safeputchar(*cp);
720 cp++;
721 }
722 printf("\"");
723 } else
724 dnsname_print(cp, ep);
725 break;
726 case ICMP6_NI_SUBJ_IPV4:
727 if (!TTEST2(*dp, sizeof(*ni6) + sizeof(struct in_addr)))
728 break;
729 if (siz != sizeof(*ni6) + sizeof(struct in_addr)) {
730 if (vflag)
731 printf(", invalid subject len");
732 break;
733 }
734 printf(", subject=%s",
735 getname((const u_char *)(ni6 + 1)));
736 break;
737 default:
738 printf(", unknown subject");
739 break;
740 }
741
742 /*(*/
743 printf(")");
744 break;
745
746 case ICMP6_NI_REPLY:
747 if (icmp6len > siz) {
748 printf("[|icmp6: node information reply]");
749 break;
750 }
751
752 needcomma = 0;
753
754 ni6 = (struct icmp6_nodeinfo *)dp;
755 printf("icmp6: node information reply");
756 printf(" ("); /*)*/
757 switch (ni6->ni_code) {
758 case ICMP6_NI_SUCCESS:
759 if (vflag) {
760 printf("success");
761 needcomma++;
762 }
763 break;
764 case ICMP6_NI_REFUSED:
765 printf("refused");
766 needcomma++;
767 if (siz != sizeof(*ni6))
768 if (vflag)
769 printf(", invalid length");
770 break;
771 case ICMP6_NI_UNKNOWN:
772 printf("unknown");
773 needcomma++;
774 if (siz != sizeof(*ni6))
775 if (vflag)
776 printf(", invalid length");
777 break;
778 }
779
780 if (ni6->ni_code != ICMP6_NI_SUCCESS) {
781 /*(*/
782 printf(")");
783 break;
784 }
785
786 switch (ntohs(ni6->ni_qtype)) {
787 case NI_QTYPE_NOOP:
788 if (needcomma)
789 printf(", ");
790 printf("noop");
791 if (siz != sizeof(*ni6))
792 if (vflag)
793 printf(", invalid length");
794 break;
795 case NI_QTYPE_SUPTYPES:
796 if (needcomma)
797 printf(", ");
798 printf("supported qtypes");
799 i = ntohs(ni6->ni_flags);
800 if (i)
801 printf(" [%s]", (i & 0x01) ? "C" : "");
802 break;
803 case NI_QTYPE_FQDN:
804 if (needcomma)
805 printf(", ");
806 printf("DNS name");
807 cp = (const u_char *)(ni6 + 1) + 4;
808 if (cp[0] == ep - cp - 1) {
809 /* icmp-name-lookup-03, pascal string */
810 if (vflag)
811 printf(", 03 draft");
812 cp++;
813 printf(", \"");
814 while (cp < ep) {
815 safeputchar(*cp);
816 cp++;
817 }
818 printf("\"");
819 } else
820 dnsname_print(cp, ep);
821 if ((ntohs(ni6->ni_flags) & 0x01) != 0)
822 printf(" [TTL=%u]", *(u_int32_t *)(ni6 + 1));
823 break;
824 case NI_QTYPE_NODEADDR:
825 if (needcomma)
826 printf(", ");
827 printf("node addresses");
828 i = sizeof(*ni6);
829 while (i < siz) {
830 if (i + sizeof(struct in6_addr) + sizeof(int32_t) > siz)
831 break;
832 printf(" %s", getname6(bp + i));
833 i += sizeof(struct in6_addr);
834 printf("(%d)", ntohl(*(int32_t *)(bp + i)));
835 i += sizeof(int32_t);
836 }
837 i = ni6->ni_flags;
838 if (!i)
839 break;
840 printf(" [%s%s%s%s%s%s%s]",
841 (i & NI_NODEADDR_FLAG_ANYCAST) ? "a" : "",
842 (i & NI_NODEADDR_FLAG_GLOBAL) ? "G" : "",
843 (i & NI_NODEADDR_FLAG_SITELOCAL) ? "S" : "",
844 (i & NI_NODEADDR_FLAG_LINKLOCAL) ? "L" : "",
845 (i & NI_NODEADDR_FLAG_COMPAT) ? "C" : "",
846 (i & NI_NODEADDR_FLAG_ALL) ? "A" : "",
847 (i & NI_NODEADDR_FLAG_TRUNCATE) ? "T" : "");
848 break;
849 default:
850 if (needcomma)
851 printf(", ");
852 printf("unknown");
853 break;
854 }
855
856 /*(*/
857 printf(")");
858 break;
859 }
860 return;
861
862 trunc:
863 fputs("[|icmp6]", stdout);
864 }
865 #endif
866
867 #endif /* INET6 */