ER_UINT ip6_lasthdr (T_NET_BUF *nbuf, uint_t off, uint_t proto, uint_t *nextp) { ER_UINT newoff; while (1) { newoff = ip6_nexthdr(nbuf, off, proto, nextp); if (newoff < 0) return (ER_UINT)off; off = newoff; proto = *nextp; } return (ER_UINT)0u; }
/* One level of recursion won't kill us */ static void dump_packet(const struct ip6t_log_info *info, struct ipv6hdr *ipv6h, int recurse) { u_int8_t currenthdr = ipv6h->nexthdr; u_int8_t *hdrptr; int fragment; /* Max length: 88 "SRC=0000.0000.0000.0000.0000.0000.0000.0000 DST=0000.0000.0000.0000.0000.0000.0000.0000" */ printk("SRC=%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x ", NIP6(ipv6h->saddr)); printk("DST=%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x ", NIP6(ipv6h->daddr)); /* Max length: 44 "LEN=65535 TC=255 HOPLIMIT=255 FLOWLBL=FFFFF " */ printk("LEN=%Zu TC=%u HOPLIMIT=%u FLOWLBL=%u ", ntohs(ipv6h->payload_len) + sizeof(struct ipv6hdr), (ntohl(*(u_int32_t *)ipv6h) & 0x0ff00000) >> 20, ipv6h->hop_limit, (ntohl(*(u_int32_t *)ipv6h) & 0x000fffff)); fragment = 0; hdrptr = (u_int8_t *)(ipv6h + 1); while (currenthdr != IPPROTO_NONE) { if ((currenthdr == IPPROTO_TCP) || (currenthdr == IPPROTO_UDP) || (currenthdr == IPPROTO_ICMPV6)) break; /* Max length: 48 "OPT (...) " */ printk("OPT ( "); switch (currenthdr) { case IPPROTO_FRAGMENT: { struct frag_hdr *fhdr = (struct frag_hdr *)hdrptr; /* Max length: 11 "FRAG:65535 " */ printk("FRAG:%u ", ntohs(fhdr->frag_off) & 0xFFF8); /* Max length: 11 "INCOMPLETE " */ if (fhdr->frag_off & htons(0x0001)) printk("INCOMPLETE "); printk("ID:%08x ", fhdr->identification); if (ntohs(fhdr->frag_off) & 0xFFF8) fragment = 1; break; } case IPPROTO_DSTOPTS: case IPPROTO_ROUTING: case IPPROTO_HOPOPTS: break; /* Max Length */ case IPPROTO_AH: case IPPROTO_ESP: if (info->logflags & IP6T_LOG_IPOPT) { struct esphdr *esph = (struct esphdr *)hdrptr; int esp = (currenthdr == IPPROTO_ESP); /* Max length: 4 "ESP " */ printk("%s ",esp ? "ESP" : "AH"); /* Length: 15 "SPI=0xF1234567 " */ printk("SPI=0x%x ", ntohl(esph->spi) ); break; } default: break; } printk(") "); currenthdr = ip6_nexthdr(currenthdr, &hdrptr); } switch (currenthdr) { case IPPROTO_TCP: { struct tcphdr *tcph = (struct tcphdr *)hdrptr; /* Max length: 10 "PROTO=TCP " */ printk("PROTO=TCP "); if (fragment) break; /* Max length: 20 "SPT=65535 DPT=65535 " */ printk("SPT=%u DPT=%u ", ntohs(tcph->source), ntohs(tcph->dest)); /* Max length: 30 "SEQ=4294967295 ACK=4294967295 " */ if (info->logflags & IP6T_LOG_TCPSEQ) printk("SEQ=%u ACK=%u ", ntohl(tcph->seq), ntohl(tcph->ack_seq)); /* Max length: 13 "WINDOW=65535 " */ printk("WINDOW=%u ", ntohs(tcph->window)); /* Max length: 9 "RES=0x3F " */ printk("RES=0x%02x ", (u_int8_t)(ntohl(tcp_flag_word(tcph) & TCP_RESERVED_BITS) >> 22)); /* Max length: 32 "CWR ECE URG ACK PSH RST SYN FIN " */ if (tcph->cwr) printk("CWR "); if (tcph->ece) printk("ECE "); if (tcph->urg) printk("URG "); if (tcph->ack) printk("ACK "); if (tcph->psh) printk("PSH "); if (tcph->rst) printk("RST "); if (tcph->syn) printk("SYN "); if (tcph->fin) printk("FIN "); /* Max length: 11 "URGP=65535 " */ printk("URGP=%u ", ntohs(tcph->urg_ptr)); if ((info->logflags & IP6T_LOG_TCPOPT) && tcph->doff * 4 != sizeof(struct tcphdr)) { unsigned int i; /* Max length: 127 "OPT (" 15*4*2chars ") " */ printk("OPT ("); for (i =sizeof(struct tcphdr); i < tcph->doff * 4; i++) printk("%02X", ((u_int8_t *)tcph)[i]); printk(") "); } break; } case IPPROTO_UDP: { struct udphdr *udph = (struct udphdr *)hdrptr; /* Max length: 10 "PROTO=UDP " */ printk("PROTO=UDP "); if (fragment) break; /* Max length: 20 "SPT=65535 DPT=65535 " */ printk("SPT=%u DPT=%u LEN=%u ", ntohs(udph->source), ntohs(udph->dest), ntohs(udph->len)); break; } case IPPROTO_ICMPV6: { struct icmp6hdr *icmp6h = (struct icmp6hdr *)hdrptr; /* Max length: 13 "PROTO=ICMPv6 " */ printk("PROTO=ICMPv6 "); if (fragment) break; /* Max length: 18 "TYPE=255 CODE=255 " */ printk("TYPE=%u CODE=%u ", icmp6h->icmp6_type, icmp6h->icmp6_code); switch (icmp6h->icmp6_type) { case ICMPV6_ECHO_REQUEST: case ICMPV6_ECHO_REPLY: /* Max length: 19 "ID=65535 SEQ=65535 " */ printk("ID=%u SEQ=%u ", ntohs(icmp6h->icmp6_identifier), ntohs(icmp6h->icmp6_sequence)); break; case ICMPV6_MGM_QUERY: case ICMPV6_MGM_REPORT: case ICMPV6_MGM_REDUCTION: break; case ICMPV6_PARAMPROB: /* Max length: 17 "POINTER=ffffffff " */ printk("POINTER=%08x ", ntohl(icmp6h->icmp6_pointer)); /* Fall through */ case ICMPV6_DEST_UNREACH: case ICMPV6_PKT_TOOBIG: case ICMPV6_TIME_EXCEED: /* Max length: 3+maxlen */ if (recurse) { printk("["); dump_packet(info, (struct ipv6hdr *)(icmp6h + 1), 0); printk("] "); } /* Max length: 10 "MTU=65535 " */ if (icmp6h->icmp6_type == ICMPV6_PKT_TOOBIG) printk("MTU=%u ", ntohl(icmp6h->icmp6_mtu)); } break; } /* Max length: 10 "PROTO=255 " */ default: printk("PROTO=%u ", currenthdr); } }
/* * Do a software calculation of the RSS for the given mbuf. * * This is typically used by the input path to recalculate the RSS after * some form of packet processing (eg de-capsulation, IP fragment reassembly.) * * dir is the packet direction - RSS_HASH_PKT_INGRESS for incoming and * RSS_HASH_PKT_EGRESS for outgoing. * * Returns 0 if a hash was done, -1 if no hash was done, +1 if * the mbuf already had a valid RSS flowid. * * This function doesn't modify the mbuf. It's up to the caller to * assign flowid/flowtype as appropriate. */ int rss_mbuf_software_hash_v6(const struct mbuf *m, int dir, uint32_t *hashval, uint32_t *hashtype) { const struct ip6_hdr *ip6; const struct tcphdr *th; const struct udphdr *uh; uint32_t flowtype; uint8_t proto; int off, newoff; int nxt; /* * XXX For now this only handles hashing on incoming mbufs. */ if (dir != RSS_HASH_PKT_INGRESS) { RSS_DEBUG("called on EGRESS packet!\n"); return (-1); } off = sizeof(struct ip6_hdr); /* * First, validate that the mbuf we have is long enough * to have an IPv6 header in it. */ if (m->m_pkthdr.len < off) { RSS_DEBUG("short mbuf pkthdr\n"); return (-1); } if (m->m_len < off) { RSS_DEBUG("short mbuf len\n"); return (-1); } /* Ok, let's dereference that */ ip6 = mtod(m, struct ip6_hdr *); proto = ip6->ip6_nxt; /* * Find the beginning of the TCP/UDP header. * * If this is a fragment then it shouldn't be four-tuple * hashed just yet. Once it's reassembled into a full * frame it should be re-hashed. */ while (proto != IPPROTO_FRAGMENT) { newoff = ip6_nexthdr(m, off, proto, &nxt); if (newoff < 0) break; off = newoff; proto = nxt; } /* * If the mbuf flowid/flowtype matches the packet type, * and we don't support the 4-tuple version of the given protocol, * then signal to the owner that it can trust the flowid/flowtype * details. * * This is a little picky - eg, if TCPv6 / UDPv6 hashing * is supported but we got a TCP/UDP frame only 2-tuple hashed, * then we shouldn't just "trust" the 2-tuple hash. We need * a 4-tuple hash. */ flowtype = M_HASHTYPE_GET(m); if (flowtype != M_HASHTYPE_NONE) { switch (proto) { case IPPROTO_UDP: if ((rss_gethashconfig() & RSS_HASHTYPE_RSS_UDP_IPV6) && (flowtype == M_HASHTYPE_RSS_UDP_IPV6)) { return (1); } /* * Only allow 2-tuple for UDP frames if we don't also * support 4-tuple for UDP. */ if ((rss_gethashconfig() & RSS_HASHTYPE_RSS_IPV6) && ((rss_gethashconfig() & RSS_HASHTYPE_RSS_UDP_IPV6) == 0) && flowtype == M_HASHTYPE_RSS_IPV6) { return (1); } break; case IPPROTO_TCP: if ((rss_gethashconfig() & RSS_HASHTYPE_RSS_TCP_IPV6) && (flowtype == M_HASHTYPE_RSS_TCP_IPV6)) { return (1); } /* * Only allow 2-tuple for TCP frames if we don't also * support 4-tuple for TCP. */ if ((rss_gethashconfig() & RSS_HASHTYPE_RSS_IPV6) && ((rss_gethashconfig() & RSS_HASHTYPE_RSS_TCP_IPV6) == 0) && flowtype == M_HASHTYPE_RSS_IPV6) { return (1); } break; default: if ((rss_gethashconfig() & RSS_HASHTYPE_RSS_IPV6) && flowtype == M_HASHTYPE_RSS_IPV6) { return (1); } break; } } /* * Decode enough information to make a hash decision. */ if ((rss_gethashconfig() & RSS_HASHTYPE_RSS_TCP_IPV6) && (proto == IPPROTO_TCP)) { if (m->m_len < off + sizeof(struct tcphdr)) { RSS_DEBUG("short TCP frame?\n"); return (-1); } th = (const struct tcphdr *)((c_caddr_t)ip6 + off); return rss_proto_software_hash_v6(&ip6->ip6_src, &ip6->ip6_dst, th->th_sport, th->th_dport, proto, hashval, hashtype); } else if ((rss_gethashconfig() & RSS_HASHTYPE_RSS_UDP_IPV6) && (proto == IPPROTO_UDP)) { if (m->m_len < off + sizeof(struct udphdr)) { RSS_DEBUG("short UDP frame?\n"); return (-1); } uh = (const struct udphdr *)((c_caddr_t)ip6 + off); return rss_proto_software_hash_v6(&ip6->ip6_src, &ip6->ip6_dst, uh->uh_sport, uh->uh_dport, proto, hashval, hashtype); } else if (rss_gethashconfig() & RSS_HASHTYPE_RSS_IPV6) { /* Default to 2-tuple hash */ return rss_proto_software_hash_v6(&ip6->ip6_src, &ip6->ip6_dst, 0, /* source port */ 0, /* destination port */ 0, /* IPPROTO_IP */ hashval, hashtype); } else { RSS_DEBUG("no available hashtypes!\n"); return (-1); } }