+ icmp6_rrenum_print(icmp6len, bp, ep);
+ break;
+ case ICMP6_NI_QUERY:
+ case ICMP6_NI_REPLY:
+ icmp6_nodeinfo_print(icmp6len, bp, ep);
+ break;
+ case ICMP6_HADISCOV_REQUEST:
+ case ICMP6_HADISCOV_REPLY:
+ {
+ struct in6_addr *in6;
+ u_int32_t *res;
+ u_char *cp;
+ printf("icmp6: ha discovery %s: ",
+ dp->icmp6_type == ICMP6_HADISCOV_REQUEST ?
+ "request" : "reply");
+ TCHECK(dp->icmp6_data16[0]);
+ printf("id=%d", ntohs(dp->icmp6_data16[0]));
+ cp = (u_char *)dp + icmp6len;
+ res = (u_int32_t *)(dp + 1);
+ in6 = (struct in6_addr *)(res + 2);
+ for (; (u_char *)in6 < cp; in6++) {
+ TCHECK(*in6);
+ printf(", %s", ip6addr_string(in6));
+ }
+ break;
+ }
+ case ICMP6_MOBILEPREFIX_SOLICIT:
+ case ICMP6_MOBILEPREFIX_ADVERT:
+ default:
+ printf("icmp6: type-#%d", dp->icmp6_type);
+ break;
+ }
+ return;
+trunc:
+ fputs("[|icmp6]", stdout);
+}
+
+static struct udphdr *
+get_upperlayer(u_char *bp, int *prot)
+{
+ const u_char *ep;
+ struct ip6_hdr *ip6 = (struct ip6_hdr *)bp;
+ struct udphdr *uh;
+ struct ip6_hbh *hbh;
+ struct ip6_frag *fragh;
+ struct ah *ah;
+ int nh, hlen;
+
+ /* 'ep' points to the end of available data. */
+ ep = snapend;
+
+ if (TTEST(ip6->ip6_nxt) == 0)
+ return NULL;
+
+ nh = ip6->ip6_nxt;
+ hlen = sizeof(struct ip6_hdr);
+
+ while (bp < snapend) {
+ bp += hlen;
+
+ switch(nh) {
+ case IPPROTO_UDP:
+ case IPPROTO_TCP:
+ uh = (struct udphdr *)bp;
+ if (TTEST(uh->uh_dport)) {
+ *prot = nh;
+ return(uh);
+ }
+ else
+ return(NULL);
+ /* NOTREACHED */
+
+ case IPPROTO_HOPOPTS:
+ case IPPROTO_DSTOPTS:
+ case IPPROTO_ROUTING:
+ hbh = (struct ip6_hbh *)bp;
+ if (TTEST(hbh->ip6h_len) == 0)
+ return(NULL);
+ nh = hbh->ip6h_nxt;
+ hlen = (hbh->ip6h_len + 1) << 3;
+ break;
+
+ case IPPROTO_FRAGMENT: /* this should be odd, but try anyway */
+ fragh = (struct ip6_frag *)bp;
+ if (TTEST(fragh->ip6f_offlg) == 0)
+ return(NULL);
+ /* fragments with non-zero offset are meaningless */
+ if ((fragh->ip6f_offlg & IP6F_OFF_MASK) != 0)
+ return(NULL);
+ nh = fragh->ip6f_nxt;
+ hlen = sizeof(struct ip6_frag);
+ break;
+
+ case IPPROTO_AH:
+ ah = (struct ah *)bp;
+ if (TTEST(ah->ah_len) == 0)
+ return(NULL);
+ nh = ah->ah_nxt;
+ hlen = (ah->ah_len + 2) << 2;
+ break;
+
+ default: /* unknown or undecodable header */
+ *prot = nh; /* meaningless, but set here anyway */
+ return(NULL);
+ }
+ }
+
+ return(NULL); /* should be notreached, though */
+}
+
+void
+icmp6_opt_print(const u_char *bp, int resid)
+{
+ const struct nd_opt_hdr *op;
+ const struct nd_opt_hdr *opl; /* why there's no struct? */
+ const struct nd_opt_prefix_info *opp;
+ const struct icmp6_opts_redirect *opr;
+ const struct nd_opt_mtu *opm;
+ const struct nd_opt_advinterval *opa;
+ const struct nd_opt_homeagent_info *oph;
+ const struct nd_opt_route_info *opri;
+ const u_char *cp, *ep;
+ struct in6_addr in6, *in6p;
+ size_t l;
+
+#define ECHECK(var) if ((u_char *)&(var) > ep - sizeof(var)) return
+
+ cp = bp;
+ /* 'ep' points to the end of available data. */
+ ep = snapend;
+
+ while (cp < ep) {
+ op = (struct nd_opt_hdr *)cp;
+
+ ECHECK(op->nd_opt_len);
+ if (resid <= 0)
+ return;
+ if (op->nd_opt_len == 0)
+ goto trunc;
+ if (cp + (op->nd_opt_len << 3) > ep)
+ goto trunc;
+
+ switch (op->nd_opt_type) {
+ case ND_OPT_SOURCE_LINKADDR:
+ opl = (struct nd_opt_hdr *)op;
+ printf("(src lladdr: ");
+ l = (op->nd_opt_len << 3) - 2;
+ print_lladdr(cp + 2, l);
+ /*(*/
+ printf(")");
+ break;
+ case ND_OPT_TARGET_LINKADDR:
+ opl = (struct nd_opt_hdr *)op;
+ printf("(tgt lladdr: ");
+ l = (op->nd_opt_len << 3) - 2;
+ print_lladdr(cp + 2, l);
+ /*(*/
+ printf(")");
+ break;
+ case ND_OPT_PREFIX_INFORMATION:
+ opp = (struct nd_opt_prefix_info *)op;
+ TCHECK(opp->nd_opt_pi_prefix);
+ printf("(prefix info: "); /*)*/
+ if (op->nd_opt_len != 4) {
+ printf("badlen");
+ /*(*/
+ printf(")");
+ break;
+ }
+ if (opp->nd_opt_pi_flags_reserved & ND_OPT_PI_FLAG_ONLINK)
+ printf("L");
+ if (opp->nd_opt_pi_flags_reserved & ND_OPT_PI_FLAG_AUTO)
+ printf("A");
+ if (opp->nd_opt_pi_flags_reserved & ND_OPT_PI_FLAG_ROUTER)
+ printf("R");
+ if (opp->nd_opt_pi_flags_reserved)
+ printf(" ");
+ printf("valid_ltime=%s,",
+ get_lifetime((u_int32_t)ntohl(opp->nd_opt_pi_valid_time)));
+ printf("preferred_ltime=%s,",
+ get_lifetime((u_int32_t)ntohl(opp->nd_opt_pi_preferred_time)));
+ printf("prefix=%s/%d",
+ ip6addr_string(&opp->nd_opt_pi_prefix),
+ opp->nd_opt_pi_prefix_len);
+ if (opp->nd_opt_pi_len != 4)
+ printf("!");
+ /*(*/
+ printf(")");
+ break;
+ case ND_OPT_REDIRECTED_HEADER:
+ opr = (struct icmp6_opts_redirect *)op;
+ printf("(redirect)");
+ /* xxx */