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