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