]> The Tcpdump Group git mirrors - tcpdump/blob - print-icmp6.c
Remove #if 0 sections
[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.55 2001-06-15 22:17:32 fenner 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
41 #include <netinet/in.h>
42
43 #include <arpa/inet.h>
44
45 #include <stdio.h>
46 #include <netdb.h>
47
48 #include "ip6.h"
49 #include "icmp6.h"
50
51 #include "interface.h"
52 #include "addrtoname.h"
53
54 #include "udp.h"
55 #include "ah.h"
56
57 static const char *get_rtpref(u_int);
58 static const char *get_lifetime(u_int32_t);
59 static void print_lladdr(const u_char *, size_t);
60 void icmp6_opt_print(const u_char *, int);
61 void mld6_print(const u_char *);
62 static struct udphdr *get_upperlayer(u_char *, int *);
63 static void dnsname_print(const u_char *, const u_char *);
64 void icmp6_nodeinfo_print(int, const u_char *, const u_char *);
65 void icmp6_rrenum_print(int, const u_char *, const u_char *);
66
67 #ifndef abs
68 #define abs(a) ((0 < (a)) ? (a) : -(a))
69 #endif
70
71 static const char *
72 get_rtpref(u_int v)
73 {
74 static const char *rtpref_str[] = {
75 "medium", /* 00 */
76 "high", /* 01 */
77 "rsv", /* 10 */
78 "low" /* 11 */
79 };
80
81 return rtpref_str[((v & ND_RA_FLAG_RTPREF_MASK) >> 3) & 0xff];
82 }
83
84 static const char *
85 get_lifetime(u_int32_t v)
86 {
87 static char buf[20];
88
89 if (v == (u_int32_t)~0UL)
90 return "infinity";
91 else {
92 snprintf(buf, sizeof(buf), "%u", v);
93 return buf;
94 }
95 }
96
97 static void
98 print_lladdr(const u_int8_t *p, size_t l)
99 {
100 const u_int8_t *ep, *q;
101
102 q = p;
103 ep = p + l;
104 while (l > 0 && q < ep) {
105 if (q > p)
106 printf(":");
107 printf("%02x", *q++);
108 l--;
109 }
110 }
111
112 void
113 icmp6_print(const u_char *bp, const u_char *bp2)
114 {
115 const struct icmp6_hdr *dp;
116 const struct ip6_hdr *ip;
117 const char *str;
118 const struct ip6_hdr *oip;
119 const struct udphdr *ouh;
120 int dport;
121 const u_char *ep;
122 char buf[256];
123 int icmp6len, prot;
124
125 dp = (struct icmp6_hdr *)bp;
126 ip = (struct ip6_hdr *)bp2;
127 oip = (struct ip6_hdr *)(dp + 1);
128 str = buf;
129 /* 'ep' points to the end of available data. */
130 ep = snapend;
131 if (ip->ip6_plen)
132 icmp6len = (ntohs(ip->ip6_plen) + sizeof(struct ip6_hdr) -
133 (bp - bp2));
134 else /* XXX: jumbo payload case... */
135 icmp6len = snapend - bp;
136
137 TCHECK(dp->icmp6_code);
138 switch (dp->icmp6_type) {
139 case ICMP6_DST_UNREACH:
140 TCHECK(oip->ip6_dst);
141 switch (dp->icmp6_code) {
142 case ICMP6_DST_UNREACH_NOROUTE:
143 printf("icmp6: %s unreachable route",
144 ip6addr_string(&oip->ip6_dst));
145 break;
146 case ICMP6_DST_UNREACH_ADMIN:
147 printf("icmp6: %s unreachable prohibited",
148 ip6addr_string(&oip->ip6_dst));
149 break;
150 case ICMP6_DST_UNREACH_BEYONDSCOPE:
151 printf("icmp6: %s beyond scope of source address %s",
152 ip6addr_string(&oip->ip6_dst),
153 ip6addr_string(&oip->ip6_src));
154 break;
155 case ICMP6_DST_UNREACH_ADDR:
156 printf("icmp6: %s unreachable address",
157 ip6addr_string(&oip->ip6_dst));
158 break;
159 case ICMP6_DST_UNREACH_NOPORT:
160 if ((ouh = get_upperlayer((u_char *)oip, &prot))
161 == NULL)
162 goto trunc;
163
164 dport = ntohs(ouh->uh_dport);
165 switch (prot) {
166 case IPPROTO_TCP:
167 printf("icmp6: %s tcp port %s unreachable",
168 ip6addr_string(&oip->ip6_dst),
169 tcpport_string(dport));
170 break;
171 case IPPROTO_UDP:
172 printf("icmp6: %s udp port %s unreachable",
173 ip6addr_string(&oip->ip6_dst),
174 udpport_string(dport));
175 break;
176 default:
177 printf("icmp6: %s protocol %d port %d unreachable",
178 ip6addr_string(&oip->ip6_dst),
179 oip->ip6_nxt, dport);
180 break;
181 }
182 break;
183 default:
184 printf("icmp6: %s unreachable code-#%d",
185 ip6addr_string(&oip->ip6_dst),
186 dp->icmp6_code);
187 break;
188 }
189 break;
190 case ICMP6_PACKET_TOO_BIG:
191 TCHECK(dp->icmp6_mtu);
192 printf("icmp6: too big %u", (u_int32_t)ntohl(dp->icmp6_mtu));
193 break;
194 case ICMP6_TIME_EXCEEDED:
195 TCHECK(oip->ip6_dst);
196 switch (dp->icmp6_code) {
197 case ICMP6_TIME_EXCEED_TRANSIT:
198 printf("icmp6: time exceeded in-transit for %s",
199 ip6addr_string(&oip->ip6_dst));
200 break;
201 case ICMP6_TIME_EXCEED_REASSEMBLY:
202 printf("icmp6: ip6 reassembly time exceeded");
203 break;
204 default:
205 printf("icmp6: time exceeded code-#%d",
206 dp->icmp6_code);
207 break;
208 }
209 break;
210 case ICMP6_PARAM_PROB:
211 TCHECK(oip->ip6_dst);
212 switch (dp->icmp6_code) {
213 case ICMP6_PARAMPROB_HEADER:
214 printf("icmp6: parameter problem errorneous - octet %u",
215 (u_int32_t)ntohl(dp->icmp6_pptr));
216 break;
217 case ICMP6_PARAMPROB_NEXTHEADER:
218 printf("icmp6: parameter problem next header - octet %u",
219 (u_int32_t)ntohl(dp->icmp6_pptr));
220 break;
221 case ICMP6_PARAMPROB_OPTION:
222 printf("icmp6: parameter problem option - octet %u",
223 (u_int32_t)ntohl(dp->icmp6_pptr));
224 break;
225 default:
226 printf("icmp6: parameter problem code-#%d",
227 dp->icmp6_code);
228 break;
229 }
230 break;
231 case ICMP6_ECHO_REQUEST:
232 printf("icmp6: echo request");
233 break;
234 case ICMP6_ECHO_REPLY:
235 printf("icmp6: echo reply");
236 break;
237 case ICMP6_MEMBERSHIP_QUERY:
238 printf("icmp6: multicast listener query ");
239 mld6_print((const u_char *)dp);
240 break;
241 case ICMP6_MEMBERSHIP_REPORT:
242 printf("icmp6: multicast listener report ");
243 mld6_print((const u_char *)dp);
244 break;
245 case ICMP6_MEMBERSHIP_REDUCTION:
246 printf("icmp6: multicast listener done ");
247 mld6_print((const u_char *)dp);
248 break;
249 case ND_ROUTER_SOLICIT:
250 printf("icmp6: router solicitation ");
251 if (vflag) {
252 #define RTSOLLEN 8
253 icmp6_opt_print((const u_char *)dp + RTSOLLEN,
254 icmp6len - RTSOLLEN);
255 }
256 break;
257 case ND_ROUTER_ADVERT:
258 printf("icmp6: router advertisement");
259 if (vflag) {
260 struct nd_router_advert *p;
261
262 p = (struct nd_router_advert *)dp;
263 TCHECK(p->nd_ra_retransmit);
264 printf("(chlim=%d, ", (int)p->nd_ra_curhoplimit);
265 if (p->nd_ra_flags_reserved & ND_RA_FLAG_MANAGED)
266 printf("M");
267 if (p->nd_ra_flags_reserved & ND_RA_FLAG_OTHER)
268 printf("O");
269 if (p->nd_ra_flags_reserved & ND_RA_FLAG_HOME_AGENT)
270 printf("H");
271
272 if ((p->nd_ra_flags_reserved & ~ND_RA_FLAG_RTPREF_MASK)
273 != 0)
274 printf(" ");
275
276 printf("pref=%s, ",
277 get_rtpref(p->nd_ra_flags_reserved));
278
279 printf("router_ltime=%d, ", ntohs(p->nd_ra_router_lifetime));
280 printf("reachable_time=%u, ",
281 (u_int32_t)ntohl(p->nd_ra_reachable));
282 printf("retrans_time=%u)",
283 (u_int32_t)ntohl(p->nd_ra_retransmit));
284 #define RTADVLEN 16
285 icmp6_opt_print((const u_char *)dp + RTADVLEN,
286 icmp6len - RTADVLEN);
287 }
288 break;
289 case ND_NEIGHBOR_SOLICIT:
290 {
291 struct nd_neighbor_solicit *p;
292 p = (struct nd_neighbor_solicit *)dp;
293 TCHECK(p->nd_ns_target);
294 printf("icmp6: neighbor sol: who has %s",
295 ip6addr_string(&p->nd_ns_target));
296 if (vflag) {
297 #define NDSOLLEN 24
298 icmp6_opt_print((const u_char *)dp + NDSOLLEN,
299 icmp6len - NDSOLLEN);
300 }
301 }
302 break;
303 case ND_NEIGHBOR_ADVERT:
304 {
305 struct nd_neighbor_advert *p;
306
307 p = (struct nd_neighbor_advert *)dp;
308 TCHECK(p->nd_na_target);
309 printf("icmp6: neighbor adv: tgt is %s",
310 ip6addr_string(&p->nd_na_target));
311 if (vflag) {
312 #define ND_NA_FLAG_ALL \
313 (ND_NA_FLAG_ROUTER|ND_NA_FLAG_SOLICITED|ND_NA_FLAG_OVERRIDE)
314 /* we don't need ntohl() here. see advanced-api-04. */
315 if (p->nd_na_flags_reserved & ND_NA_FLAG_ALL) {
316 #undef ND_NA_FLAG_ALL
317 u_int32_t flags;
318
319 flags = p->nd_na_flags_reserved;
320 printf("(");
321 if (flags & ND_NA_FLAG_ROUTER)
322 printf("R");
323 if (flags & ND_NA_FLAG_SOLICITED)
324 printf("S");
325 if (flags & ND_NA_FLAG_OVERRIDE)
326 printf("O");
327 printf(")");
328 }
329 #define NDADVLEN 24
330 icmp6_opt_print((const u_char *)dp + NDADVLEN,
331 icmp6len - NDADVLEN);
332 #undef NDADVLEN
333 }
334 }
335 break;
336 case ND_REDIRECT:
337 #define RDR(i) ((struct nd_redirect *)(i))
338 TCHECK(RDR(dp)->nd_rd_dst);
339 printf("icmp6: redirect %s",
340 getname6((const u_char *)&RDR(dp)->nd_rd_dst));
341 printf(" to %s",
342 getname6((const u_char*)&RDR(dp)->nd_rd_target));
343 #define REDIRECTLEN 40
344 if (vflag) {
345 icmp6_opt_print((const u_char *)dp + REDIRECTLEN,
346 icmp6len - REDIRECTLEN);
347 }
348 break;
349 #undef REDIRECTLEN
350 #undef RDR
351 case ICMP6_ROUTER_RENUMBERING:
352 icmp6_rrenum_print(icmp6len, bp, ep);
353 break;
354 case ICMP6_NI_QUERY:
355 case ICMP6_NI_REPLY:
356 icmp6_nodeinfo_print(icmp6len, bp, ep);
357 break;
358 default:
359 printf("icmp6: type-#%d", dp->icmp6_type);
360 break;
361 }
362 return;
363 trunc:
364 fputs("[|icmp6]", stdout);
365 }
366
367 static struct udphdr *
368 get_upperlayer(u_char *bp, int *prot)
369 {
370 const u_char *ep;
371 struct ip6_hdr *ip6 = (struct ip6_hdr *)bp;
372 struct udphdr *uh;
373 struct ip6_hbh *hbh;
374 struct ip6_frag *fragh;
375 struct ah *ah;
376 int nh, hlen;
377
378 /* 'ep' points to the end of available data. */
379 ep = snapend;
380
381 if (TTEST(ip6->ip6_nxt) == 0)
382 return NULL;
383
384 nh = ip6->ip6_nxt;
385 hlen = sizeof(struct ip6_hdr);
386
387 while (bp < snapend) {
388 bp += hlen;
389
390 switch(nh) {
391 case IPPROTO_UDP:
392 case IPPROTO_TCP:
393 uh = (struct udphdr *)bp;
394 if (TTEST(uh->uh_dport)) {
395 *prot = nh;
396 return(uh);
397 }
398 else
399 return(NULL);
400 /* NOTREACHED */
401
402 case IPPROTO_HOPOPTS:
403 case IPPROTO_DSTOPTS:
404 case IPPROTO_ROUTING:
405 hbh = (struct ip6_hbh *)bp;
406 if (TTEST(hbh->ip6h_len) == 0)
407 return(NULL);
408 nh = hbh->ip6h_nxt;
409 hlen = (hbh->ip6h_len + 1) << 3;
410 break;
411
412 case IPPROTO_FRAGMENT: /* this should be odd, but try anyway */
413 fragh = (struct ip6_frag *)bp;
414 if (TTEST(fragh->ip6f_offlg) == 0)
415 return(NULL);
416 /* fragments with non-zero offset are meaningless */
417 if ((fragh->ip6f_offlg & IP6F_OFF_MASK) != 0)
418 return(NULL);
419 nh = fragh->ip6f_nxt;
420 hlen = sizeof(struct ip6_frag);
421 break;
422
423 case IPPROTO_AH:
424 ah = (struct ah *)bp;
425 if (TTEST(ah->ah_len) == 0)
426 return(NULL);
427 nh = ah->ah_nxt;
428 hlen = (ah->ah_len + 2) << 2;
429 break;
430
431 default: /* unknown or undecodable header */
432 *prot = nh; /* meaningless, but set here anyway */
433 return(NULL);
434 }
435 }
436
437 return(NULL); /* should be notreached, though */
438 }
439
440 void
441 icmp6_opt_print(const u_char *bp, int resid)
442 {
443 const struct nd_opt_hdr *op;
444 const struct nd_opt_hdr *opl; /* why there's no struct? */
445 const struct nd_opt_prefix_info *opp;
446 const struct icmp6_opts_redirect *opr;
447 const struct nd_opt_mtu *opm;
448 const struct nd_opt_advinterval *opa;
449 const struct nd_opt_route_info *opri;
450 const u_char *cp, *ep;
451 struct in6_addr in6, *in6p;
452 size_t l;
453
454 #define ECHECK(var) if ((u_char *)&(var) > ep - sizeof(var)) return
455
456 cp = bp;
457 /* 'ep' points to the end of available data. */
458 ep = snapend;
459
460 while (cp < ep) {
461 op = (struct nd_opt_hdr *)cp;
462
463 ECHECK(op->nd_opt_len);
464 if (resid <= 0)
465 return;
466 if (op->nd_opt_len == 0)
467 goto trunc;
468 if (cp + (op->nd_opt_len << 3) > ep)
469 goto trunc;
470
471 switch (op->nd_opt_type) {
472 case ND_OPT_SOURCE_LINKADDR:
473 opl = (struct nd_opt_hdr *)op;
474 printf("(src lladdr: ");
475 l = (op->nd_opt_len << 3) - 2;
476 print_lladdr(cp + 2, l);
477 /*(*/
478 printf(")");
479 break;
480 case ND_OPT_TARGET_LINKADDR:
481 opl = (struct nd_opt_hdr *)op;
482 printf("(tgt lladdr: ");
483 l = (op->nd_opt_len << 3) - 2;
484 print_lladdr(cp + 2, l);
485 /*(*/
486 printf(")");
487 break;
488 case ND_OPT_PREFIX_INFORMATION:
489 opp = (struct nd_opt_prefix_info *)op;
490 TCHECK(opp->nd_opt_pi_prefix);
491 printf("(prefix info: "); /*)*/
492 if (op->nd_opt_len != 4) {
493 printf("badlen");
494 /*(*/
495 printf(")");
496 break;
497 }
498 if (opp->nd_opt_pi_flags_reserved & ND_OPT_PI_FLAG_ONLINK)
499 printf("L");
500 if (opp->nd_opt_pi_flags_reserved & ND_OPT_PI_FLAG_AUTO)
501 printf("A");
502 if (opp->nd_opt_pi_flags_reserved & ND_OPT_PI_FLAG_ROUTER)
503 printf("R");
504 if (opp->nd_opt_pi_flags_reserved)
505 printf(" ");
506 printf("valid_ltime=%s,",
507 get_lifetime((u_int32_t)ntohl(opp->nd_opt_pi_valid_time)));
508 printf("preferred_ltime=%s,",
509 get_lifetime((u_int32_t)ntohl(opp->nd_opt_pi_preferred_time)));
510 printf("prefix=%s/%d",
511 ip6addr_string(&opp->nd_opt_pi_prefix),
512 opp->nd_opt_pi_prefix_len);
513 if (opp->nd_opt_pi_len != 4)
514 printf("!");
515 /*(*/
516 printf(")");
517 break;
518 case ND_OPT_REDIRECTED_HEADER:
519 opr = (struct icmp6_opts_redirect *)op;
520 printf("(redirect)");
521 /* xxx */
522 break;
523 case ND_OPT_MTU:
524 opm = (struct nd_opt_mtu *)op;
525 TCHECK(opm->nd_opt_mtu_mtu);
526 printf("(mtu:"); /*)*/
527 if (op->nd_opt_len != 1) {
528 printf("badlen");
529 /*(*/
530 printf(")");
531 break;
532 }
533 printf(" mtu=%u", (u_int32_t)ntohl(opm->nd_opt_mtu_mtu));
534 if (opm->nd_opt_mtu_len != 1)
535 printf("!");
536 printf(")");
537 break;
538 case ND_OPT_ADVINTERVAL:
539 opa = (struct nd_opt_advinterval *)op;
540 TCHECK(opa->nd_opt_adv_interval);
541 printf("(advint:"); /*)*/
542 printf(" advint=%u",
543 (u_int32_t)ntohl(opa->nd_opt_adv_interval));
544 /*(*/
545 printf(")");
546 break;
547 case ND_OPT_ROUTE_INFO:
548 opri = (struct nd_opt_route_info *)op;
549 TCHECK(opri->nd_opt_rti_lifetime);
550 memset(&in6, 0, sizeof(in6));
551 in6p = (struct in6_addr *)(opri + 1);
552 switch (op->nd_opt_len) {
553 case 1:
554 break;
555 case 2:
556 TCHECK2(*in6p, 8);
557 memcpy(&in6, opri + 1, 8);
558 break;
559 case 3:
560 TCHECK(*in6p);
561 memcpy(&in6, opri + 1, sizeof(in6));
562 break;
563 default:
564 goto trunc;
565 }
566 printf("(rtinfo:"); /*)*/
567 printf(" %s/%u", ip6addr_string(&in6),
568 opri->nd_opt_rti_prefixlen);
569 printf(", pref=%s", get_rtpref(opri->nd_opt_rti_flags));
570 printf(", lifetime=%s",
571 get_lifetime((u_int32_t)ntohl(opri->nd_opt_rti_lifetime)));
572 /*(*/
573 printf(")");
574 break;
575 default:
576 printf("(unknwon opt_type=%d, opt_len=%d)",
577 op->nd_opt_type, op->nd_opt_len);
578 break;
579 }
580
581 cp += op->nd_opt_len << 3;
582 resid -= op->nd_opt_len << 3;
583 }
584 return;
585
586 trunc:
587 fputs("[ndp opt]", stdout);
588 return;
589 #undef ECHECK
590 }
591
592 void
593 mld6_print(const u_char *bp)
594 {
595 struct mld6_hdr *mp = (struct mld6_hdr *)bp;
596 const u_char *ep;
597
598 /* 'ep' points to the end of available data. */
599 ep = snapend;
600
601 if ((u_char *)mp + sizeof(*mp) > ep)
602 return;
603
604 printf("max resp delay: %d ", ntohs(mp->mld6_maxdelay));
605 printf("addr: %s", ip6addr_string(&mp->mld6_addr));
606 }
607
608 static void
609 dnsname_print(const u_char *cp, const u_char *ep)
610 {
611 int i;
612
613 /* DNS name decoding - no decompression */
614 printf(", \"");
615 while (cp < ep) {
616 i = *cp++;
617 if (i) {
618 if (i > ep - cp) {
619 printf("???");
620 break;
621 }
622 while (i-- && cp < ep) {
623 safeputchar(*cp);
624 cp++;
625 }
626 if (cp + 1 < ep && *cp)
627 printf(".");
628 } else {
629 if (cp == ep) {
630 /* FQDN */
631 printf(".");
632 } else if (cp + 1 == ep && *cp == '\0') {
633 /* truncated */
634 } else {
635 /* invalid */
636 printf("???");
637 }
638 break;
639 }
640 }
641 printf("\"");
642 }
643
644 void
645 icmp6_nodeinfo_print(int icmp6len, const u_char *bp, const u_char *ep)
646 {
647 struct icmp6_nodeinfo *ni6;
648 struct icmp6_hdr *dp;
649 const u_char *cp;
650 int siz, i;
651 int needcomma;
652
653 dp = (struct icmp6_hdr *)bp;
654 ni6 = (struct icmp6_nodeinfo *)bp;
655 siz = ep - bp;
656
657 switch (ni6->ni_type) {
658 case ICMP6_NI_QUERY:
659 if (siz == sizeof(*dp) + 4) {
660 /* KAME who-are-you */
661 printf("icmp6: who-are-you request");
662 break;
663 }
664 printf("icmp6: node information query");
665
666 TCHECK2(*dp, sizeof(*ni6));
667 ni6 = (struct icmp6_nodeinfo *)dp;
668 printf(" ("); /*)*/
669 switch (ntohs(ni6->ni_qtype)) {
670 case NI_QTYPE_NOOP:
671 printf("noop");
672 break;
673 case NI_QTYPE_SUPTYPES:
674 printf("supported qtypes");
675 i = ntohs(ni6->ni_flags);
676 if (i)
677 printf(" [%s]", (i & 0x01) ? "C" : "");
678 break;
679 break;
680 case NI_QTYPE_FQDN:
681 printf("DNS name");
682 break;
683 case NI_QTYPE_NODEADDR:
684 printf("node addresses");
685 i = ni6->ni_flags;
686 if (!i)
687 break;
688 /* NI_NODEADDR_FLAG_TRUNCATE undefined for query */
689 printf(" [%s%s%s%s%s%s]",
690 (i & NI_NODEADDR_FLAG_ANYCAST) ? "a" : "",
691 (i & NI_NODEADDR_FLAG_GLOBAL) ? "G" : "",
692 (i & NI_NODEADDR_FLAG_SITELOCAL) ? "S" : "",
693 (i & NI_NODEADDR_FLAG_LINKLOCAL) ? "L" : "",
694 (i & NI_NODEADDR_FLAG_COMPAT) ? "C" : "",
695 (i & NI_NODEADDR_FLAG_ALL) ? "A" : "");
696 break;
697 default:
698 printf("unknown");
699 break;
700 }
701
702 if (ni6->ni_qtype == NI_QTYPE_NOOP ||
703 ni6->ni_qtype == NI_QTYPE_SUPTYPES) {
704 if (siz != sizeof(*ni6))
705 if (vflag)
706 printf(", invalid len");
707 /*(*/
708 printf(")");
709 break;
710 }
711
712
713 /* XXX backward compat, icmp-name-lookup-03 */
714 if (siz == sizeof(*ni6)) {
715 printf(", 03 draft");
716 /*(*/
717 printf(")");
718 break;
719 }
720
721 switch (ni6->ni_code) {
722 case ICMP6_NI_SUBJ_IPV6:
723 if (!TTEST2(*dp,
724 sizeof(*ni6) + sizeof(struct in6_addr)))
725 break;
726 if (siz != sizeof(*ni6) + sizeof(struct in6_addr)) {
727 if (vflag)
728 printf(", invalid subject len");
729 break;
730 }
731 printf(", subject=%s",
732 getname6((const u_char *)(ni6 + 1)));
733 break;
734 case ICMP6_NI_SUBJ_FQDN:
735 printf(", subject=DNS name");
736 cp = (const u_char *)(ni6 + 1);
737 if (cp[0] == ep - cp - 1) {
738 /* icmp-name-lookup-03, pascal string */
739 if (vflag)
740 printf(", 03 draft");
741 cp++;
742 printf(", \"");
743 while (cp < ep) {
744 safeputchar(*cp);
745 cp++;
746 }
747 printf("\"");
748 } else
749 dnsname_print(cp, ep);
750 break;
751 case ICMP6_NI_SUBJ_IPV4:
752 if (!TTEST2(*dp, sizeof(*ni6) + sizeof(struct in_addr)))
753 break;
754 if (siz != sizeof(*ni6) + sizeof(struct in_addr)) {
755 if (vflag)
756 printf(", invalid subject len");
757 break;
758 }
759 printf(", subject=%s",
760 getname((const u_char *)(ni6 + 1)));
761 break;
762 default:
763 printf(", unknown subject");
764 break;
765 }
766
767 /*(*/
768 printf(")");
769 break;
770
771 case ICMP6_NI_REPLY:
772 if (icmp6len > siz) {
773 printf("[|icmp6: node information reply]");
774 break;
775 }
776
777 needcomma = 0;
778
779 ni6 = (struct icmp6_nodeinfo *)dp;
780 printf("icmp6: node information reply");
781 printf(" ("); /*)*/
782 switch (ni6->ni_code) {
783 case ICMP6_NI_SUCCESS:
784 if (vflag) {
785 printf("success");
786 needcomma++;
787 }
788 break;
789 case ICMP6_NI_REFUSED:
790 printf("refused");
791 needcomma++;
792 if (siz != sizeof(*ni6))
793 if (vflag)
794 printf(", invalid length");
795 break;
796 case ICMP6_NI_UNKNOWN:
797 printf("unknown");
798 needcomma++;
799 if (siz != sizeof(*ni6))
800 if (vflag)
801 printf(", invalid length");
802 break;
803 }
804
805 if (ni6->ni_code != ICMP6_NI_SUCCESS) {
806 /*(*/
807 printf(")");
808 break;
809 }
810
811 switch (ntohs(ni6->ni_qtype)) {
812 case NI_QTYPE_NOOP:
813 if (needcomma)
814 printf(", ");
815 printf("noop");
816 if (siz != sizeof(*ni6))
817 if (vflag)
818 printf(", invalid length");
819 break;
820 case NI_QTYPE_SUPTYPES:
821 if (needcomma)
822 printf(", ");
823 printf("supported qtypes");
824 i = ntohs(ni6->ni_flags);
825 if (i)
826 printf(" [%s]", (i & 0x01) ? "C" : "");
827 break;
828 case NI_QTYPE_FQDN:
829 if (needcomma)
830 printf(", ");
831 printf("DNS name");
832 cp = (const u_char *)(ni6 + 1) + 4;
833 if (cp[0] == ep - cp - 1) {
834 /* icmp-name-lookup-03, pascal string */
835 if (vflag)
836 printf(", 03 draft");
837 cp++;
838 printf(", \"");
839 while (cp < ep) {
840 safeputchar(*cp);
841 cp++;
842 }
843 printf("\"");
844 } else
845 dnsname_print(cp, ep);
846 if ((ntohs(ni6->ni_flags) & 0x01) != 0)
847 printf(" [TTL=%u]", *(u_int32_t *)(ni6 + 1));
848 break;
849 case NI_QTYPE_NODEADDR:
850 if (needcomma)
851 printf(", ");
852 printf("node addresses");
853 i = sizeof(*ni6);
854 while (i < siz) {
855 if (i + sizeof(struct in6_addr) + sizeof(int32_t) > siz)
856 break;
857 printf(" %s", getname6(bp + i));
858 i += sizeof(struct in6_addr);
859 printf("(%d)", (int32_t)ntohl(*(int32_t *)(bp + i)));
860 i += sizeof(int32_t);
861 }
862 i = ni6->ni_flags;
863 if (!i)
864 break;
865 printf(" [%s%s%s%s%s%s%s]",
866 (i & NI_NODEADDR_FLAG_ANYCAST) ? "a" : "",
867 (i & NI_NODEADDR_FLAG_GLOBAL) ? "G" : "",
868 (i & NI_NODEADDR_FLAG_SITELOCAL) ? "S" : "",
869 (i & NI_NODEADDR_FLAG_LINKLOCAL) ? "L" : "",
870 (i & NI_NODEADDR_FLAG_COMPAT) ? "C" : "",
871 (i & NI_NODEADDR_FLAG_ALL) ? "A" : "",
872 (i & NI_NODEADDR_FLAG_TRUNCATE) ? "T" : "");
873 break;
874 default:
875 if (needcomma)
876 printf(", ");
877 printf("unknown");
878 break;
879 }
880
881 /*(*/
882 printf(")");
883 break;
884 }
885 return;
886
887 trunc:
888 fputs("[|icmp6]", stdout);
889 }
890
891 void
892 icmp6_rrenum_print(int icmp6len, const u_char *bp, const u_char *ep)
893 {
894 struct icmp6_router_renum *rr6;
895 struct icmp6_hdr *dp;
896 size_t siz;
897 const char *cp;
898 struct rr_pco_match *match;
899 struct rr_pco_use *use;
900 char hbuf[NI_MAXHOST];
901 int n;
902
903 dp = (struct icmp6_hdr *)bp;
904 rr6 = (struct icmp6_router_renum *)bp;
905 siz = ep - bp;
906 cp = (const char *)(rr6 + 1);
907
908 TCHECK(rr6->rr_reserved);
909 switch (rr6->rr_code) {
910 case ICMP6_ROUTER_RENUMBERING_COMMAND:
911 printf("router renum: command");
912 break;
913 case ICMP6_ROUTER_RENUMBERING_RESULT:
914 printf("router renum: result");
915 break;
916 case ICMP6_ROUTER_RENUMBERING_SEQNUM_RESET:
917 printf("router renum: sequence number reset");
918 break;
919 default:
920 printf("router renum: code-#%d", rr6->rr_code);
921 break;
922 }
923
924 printf(", seq=%u", (u_int32_t)ntohl(rr6->rr_seqnum));
925
926 if (vflag) {
927 #define F(x, y) ((rr6->rr_flags) & (x) ? (y) : "")
928 printf("["); /*]*/
929 if (rr6->rr_flags) {
930 printf("%s%s%s%s%s,", F(ICMP6_RR_FLAGS_TEST, "T"),
931 F(ICMP6_RR_FLAGS_REQRESULT, "R"),
932 F(ICMP6_RR_FLAGS_FORCEAPPLY, "A"),
933 F(ICMP6_RR_FLAGS_SPECSITE, "S"),
934 F(ICMP6_RR_FLAGS_PREVDONE, "P"));
935 }
936 printf("seg=%u,", rr6->rr_segnum);
937 printf("maxdelay=%u", rr6->rr_maxdelay);
938 if (rr6->rr_reserved)
939 printf("rsvd=0x%x", (u_int16_t)ntohs(rr6->rr_reserved));
940 /*[*/
941 printf("]");
942 #undef F
943 }
944
945 if (rr6->rr_code == ICMP6_ROUTER_RENUMBERING_COMMAND) {
946 match = (struct rr_pco_match *)cp;
947 cp = (const char *)(match + 1);
948
949 TCHECK(match->rpm_prefix);
950
951 if (vflag > 1)
952 printf("\n\t");
953 else
954 printf(" ");
955 printf("match("); /*)*/
956 switch (match->rpm_code) {
957 case RPM_PCO_ADD: printf("add"); break;
958 case RPM_PCO_CHANGE: printf("change"); break;
959 case RPM_PCO_SETGLOBAL: printf("setglobal"); break;
960 default: printf("#%u", match->rpm_code); break;
961 }
962
963 if (vflag) {
964 printf(",ord=%u", match->rpm_ordinal);
965 printf(",min=%u", match->rpm_minlen);
966 printf(",max=%u", match->rpm_maxlen);
967 }
968 if (inet_ntop(AF_INET6, &match->rpm_prefix, hbuf, sizeof(hbuf)))
969 printf(",%s/%u", hbuf, match->rpm_matchlen);
970 else
971 printf(",?/%u", match->rpm_matchlen);
972 /*(*/
973 printf(")");
974
975 n = match->rpm_len - 3;
976 if (n % 4)
977 goto trunc;
978 n /= 4;
979 while (n-- > 0) {
980 use = (struct rr_pco_use *)cp;
981 cp = (const char *)(use + 1);
982
983 TCHECK(use->rpu_prefix);
984
985 if (vflag > 1)
986 printf("\n\t");
987 else
988 printf(" ");
989 printf("use("); /*)*/
990 if (use->rpu_flags) {
991 #define F(x, y) ((use->rpu_flags) & (x) ? (y) : "")
992 printf("%s%s,",
993 F(ICMP6_RR_PCOUSE_FLAGS_DECRVLTIME, "V"),
994 F(ICMP6_RR_PCOUSE_FLAGS_DECRPLTIME, "P"));
995 #undef F
996 }
997 if (vflag) {
998 printf("mask=0x%x,", use->rpu_ramask);
999 printf("raflags=0x%x,", use->rpu_raflags);
1000 if (~use->rpu_vltime == 0)
1001 printf("vltime=infty,");
1002 else
1003 printf("vltime=%u,",
1004 (u_int32_t)ntohl(use->rpu_vltime));
1005 if (~use->rpu_pltime == 0)
1006 printf("pltime=infty,");
1007 else
1008 printf("pltime=%u,",
1009 (u_int32_t)ntohl(use->rpu_pltime));
1010 }
1011 if (inet_ntop(AF_INET6, &use->rpu_prefix, hbuf,
1012 sizeof(hbuf)))
1013 printf("%s/%u/%u", hbuf, use->rpu_uselen,
1014 use->rpu_keeplen);
1015 else
1016 printf("?/%u/%u", use->rpu_uselen,
1017 use->rpu_keeplen);
1018 /*(*/
1019 printf(")");
1020 }
1021 }
1022
1023 return;
1024
1025 trunc:
1026 fputs("[|icmp6]", stdout);
1027 }
1028
1029 #endif /* INET6 */