summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorAlexander Bluhm <bluhm@cvs.openbsd.org>2013-06-03 13:19:09 +0000
committerAlexander Bluhm <bluhm@cvs.openbsd.org>2013-06-03 13:19:09 +0000
commit986d735127559ffcbd38a2c7d971cd1a53a6d831 (patch)
tree907b9263ff87582cd8825a600ecd8bc49392fbd4 /sys
parentf73d3b0503e3387e53f6454456fa3743286d7131 (diff)
Merge the duplicate IPv4 and IPv6 checksum checking code in tcp_input()
into one block. OK mpi@
Diffstat (limited to 'sys')
-rw-r--r--sys/netinet/tcp_input.c65
1 files changed, 30 insertions, 35 deletions
diff --git a/sys/netinet/tcp_input.c b/sys/netinet/tcp_input.c
index f2b74f845dd..67d980bf29d 100644
--- a/sys/netinet/tcp_input.c
+++ b/sys/netinet/tcp_input.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tcp_input.c,v 1.260 2013/04/10 08:50:59 mpi Exp $ */
+/* $OpenBSD: tcp_input.c,v 1.261 2013/06/03 13:19:08 bluhm Exp $ */
/* $NetBSD: tcp_input.c,v 1.23 1996/02/13 23:43:44 christos Exp $ */
/*
@@ -468,23 +468,6 @@ tcp_input(struct mbuf *m, ...)
/* save ip_tos before clearing it for checksum */
iptos = ip->ip_tos;
#endif
- /*
- * Checksum extended TCP header and data.
- */
- if ((m->m_pkthdr.csum_flags & M_TCP_CSUM_IN_OK) == 0) {
- if (m->m_pkthdr.csum_flags & M_TCP_CSUM_IN_BAD) {
- tcpstat.tcps_inhwcsum++;
- tcpstat.tcps_rcvbadsum++;
- goto drop;
- }
- if (in4_cksum(m, IPPROTO_TCP, iphlen, tlen) != 0) {
- tcpstat.tcps_rcvbadsum++;
- goto drop;
- }
- } else {
- m->m_pkthdr.csum_flags &= ~M_TCP_CSUM_IN_OK;
- tcpstat.tcps_inhwcsum++;
- }
break;
#ifdef INET6
case AF_INET6:
@@ -518,27 +501,39 @@ tcp_input(struct mbuf *m, ...)
/* XXX stat */
goto drop;
}
+ break;
+#endif
+ }
- /*
- * Checksum extended TCP header and data.
- */
- if ((m->m_pkthdr.csum_flags & M_TCP_CSUM_IN_OK) == 0) {
- if (m->m_pkthdr.csum_flags & M_TCP_CSUM_IN_BAD) {
- tcpstat.tcps_inhwcsum++;
- tcpstat.tcps_rcvbadsum++;
- goto drop;
- }
- if (in6_cksum(m, IPPROTO_TCP, sizeof(struct ip6_hdr),
- tlen)) {
- tcpstat.tcps_rcvbadsum++;
- goto drop;
- }
- } else {
- m->m_pkthdr.csum_flags &= ~M_TCP_CSUM_IN_OK;
+ /*
+ * Checksum extended TCP header and data.
+ */
+ if ((m->m_pkthdr.csum_flags & M_TCP_CSUM_IN_OK) == 0) {
+ int sum;
+
+ if (m->m_pkthdr.csum_flags & M_TCP_CSUM_IN_BAD) {
tcpstat.tcps_inhwcsum++;
+ tcpstat.tcps_rcvbadsum++;
+ goto drop;
}
- break;
+ switch (af) {
+ case AF_INET:
+ sum = in4_cksum(m, IPPROTO_TCP, iphlen, tlen);
+ break;
+#ifdef INET6
+ case AF_INET6:
+ sum = in6_cksum(m, IPPROTO_TCP, sizeof(struct ip6_hdr),
+ tlen);
+ break;
#endif
+ }
+ if (sum != 0) {
+ tcpstat.tcps_rcvbadsum++;
+ goto drop;
+ }
+ } else {
+ m->m_pkthdr.csum_flags &= ~M_TCP_CSUM_IN_OK;
+ tcpstat.tcps_inhwcsum++;
}
/*