- memset(&tha, 0, sizeof(tha));
- rev = 0;
- if (ip6) {
- src = &ip6->ip6_src;
- dst = &ip6->ip6_dst;
- if (sport > dport)
- rev = 1;
- else if (sport == dport) {
- if (memcmp(src, dst, sizeof ip6->ip6_dst) > 0)
- rev = 1;
- }
- if (rev) {
- memcpy(&tha.src, dst, sizeof ip6->ip6_dst);
- memcpy(&tha.dst, src, sizeof ip6->ip6_src);
- tha.port = dport << 16 | sport;
- } else {
- memcpy(&tha.dst, dst, sizeof ip6->ip6_dst);
- memcpy(&tha.src, src, sizeof ip6->ip6_src);
- tha.port = sport << 16 | dport;
- }
- } else {
- src = &ip->ip_src;
- dst = &ip->ip_dst;
- if (sport > dport)
- rev = 1;
- else if (sport == dport) {
- if (memcmp(src, dst, sizeof ip->ip_dst) > 0)
- rev = 1;
- }
- if (rev) {
- memcpy(&tha.src, dst, sizeof ip->ip_dst);
- memcpy(&tha.dst, src, sizeof ip->ip_src);
- tha.port = dport << 16 | sport;
- } else {
- memcpy(&tha.dst, dst, sizeof ip->ip_dst);
- memcpy(&tha.src, src, sizeof ip->ip_src);
- tha.port = sport << 16 | dport;
- }
- }
+ rev = 0;
+ if (ip6) {
+ src = &ip6->ip6_src;
+ dst = &ip6->ip6_dst;
+ if (sport > dport)
+ rev = 1;
+ else if (sport == dport) {
+ if (memcmp(src, dst, sizeof ip6->ip6_dst) > 0)
+ rev = 1;
+ }
+ if (rev) {
+ memcpy(&tha.src, dst, sizeof ip6->ip6_dst);
+ memcpy(&tha.dst, src, sizeof ip6->ip6_src);
+ tha.port = dport << 16 | sport;
+ } else {
+ memcpy(&tha.dst, dst, sizeof ip6->ip6_dst);
+ memcpy(&tha.src, src, sizeof ip6->ip6_src);
+ tha.port = sport << 16 | dport;
+ }
+ } else {
+ /*
+ * Zero out the tha structure; the src and dst
+ * fields are big enough to hold an IPv6
+ * address, but we only have IPv4 addresses
+ * and thus must clear out the remaining 124
+ * bits.
+ *
+ * XXX - should we just clear those bytes after
+ * copying the IPv4 addresses, rather than
+ * zeroing out the entire structure and then
+ * overwriting some of the zeroes?
+ *
+ * XXX - this could fail if we see TCP packets
+ * with an IPv6 address with the lower 124 bits
+ * all zero and also see TCP packes with an
+ * IPv4 address with the same 32 bits as the
+ * upper 32 bits of the IPv6 address in question.
+ * Can that happen? Is it likely enough to be
+ * an issue?
+ */
+ memset(&tha, 0, sizeof(tha));
+ src = &ip->ip_src;
+ dst = &ip->ip_dst;
+ if (sport > dport)
+ rev = 1;
+ else if (sport == dport) {
+ if (memcmp(src, dst, sizeof ip->ip_dst) > 0)
+ rev = 1;
+ }
+ if (rev) {
+ memcpy(&tha.src, dst, sizeof ip->ip_dst);
+ memcpy(&tha.dst, src, sizeof ip->ip_src);
+ tha.port = dport << 16 | sport;
+ } else {
+ memcpy(&tha.dst, dst, sizeof ip->ip_dst);
+ memcpy(&tha.src, src, sizeof ip->ip_src);
+ tha.port = sport << 16 | dport;
+ }
+ }