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