diff options
author | Angelos D. Keromytis <angelos@cvs.openbsd.org> | 2001-06-23 05:36:09 +0000 |
---|---|---|
committer | Angelos D. Keromytis <angelos@cvs.openbsd.org> | 2001-06-23 05:36:09 +0000 |
commit | 6272e736471bec5a541944eb9a5658a0f86df5dd (patch) | |
tree | 7d7d0b33211a8ebe0fd137166c9c8b29640fcf2a /sys/netinet | |
parent | 6ef71fcb530fc9a775f3285bf915f49ee2794d45 (diff) |
TCP/UDP hardware checksumming. Untested, since txp dies when it tries
to compute the checksums. Still, it shouldn't affect anything.
Diffstat (limited to 'sys/netinet')
-rw-r--r-- | sys/netinet/tcp_output.c | 19 | ||||
-rw-r--r-- | sys/netinet/udp_usrreq.c | 15 |
2 files changed, 32 insertions, 2 deletions
diff --git a/sys/netinet/tcp_output.c b/sys/netinet/tcp_output.c index 37c2419b1ca..10ca016a510 100644 --- a/sys/netinet/tcp_output.c +++ b/sys/netinet/tcp_output.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tcp_output.c,v 1.38 2001/06/23 03:10:21 provos Exp $ */ +/* $OpenBSD: tcp_output.c,v 1.39 2001/06/23 05:36:08 angelos Exp $ */ /* $NetBSD: tcp_output.c,v 1.16 1997/06/03 16:17:09 kml Exp $ */ /* @@ -80,6 +80,7 @@ #include <sys/socketvar.h> #include <net/route.h> +#include <net/if.h> #include <netinet/in.h> #include <netinet/in_systm.h> @@ -225,6 +226,8 @@ tcp_output(tp) u_char opt[MAX_TCPOPTLEN]; unsigned int optlen, hdrlen; int idle, sendalot = 0; + struct route *ro; + struct ifnet *ifp; #ifdef TCP_SACK int i, sack_rxmit = 0; struct sackhole *p; @@ -948,6 +951,20 @@ send: case 0: /*default to PF_INET*/ #ifdef INET case AF_INET: + /* + * If we know our route, and the interface supports TCPv4 + * checksumming, only compute the pseudoheader. + */ + ro = &tp->t_inpcb->inp_route; + if (ro->ro_rt && (ro->ro_rt->rt_flags & RTF_UP)) { + ifp = ro->ro_rt->rt_ifp; + if (ifp->if_capabilities & IFCAP_CSUM_TCPv4) { + m->m_pkthdr.csum |= M_TCPV4_CSUM_OUT; + th->th_sum = in_cksum(m, (int)hdrlen); + break; + } + } + th->th_sum = in_cksum(m, (int)(hdrlen + len)); break; #endif /* INET */ diff --git a/sys/netinet/udp_usrreq.c b/sys/netinet/udp_usrreq.c index 83e18106505..55ade377152 100644 --- a/sys/netinet/udp_usrreq.c +++ b/sys/netinet/udp_usrreq.c @@ -1,4 +1,4 @@ -/* $OpenBSD: udp_usrreq.c,v 1.65 2001/06/23 03:42:10 angelos Exp $ */ +/* $OpenBSD: udp_usrreq.c,v 1.66 2001/06/23 05:36:08 angelos Exp $ */ /* $NetBSD: udp_usrreq.c,v 1.28 1996/03/16 23:54:03 christos Exp $ */ /* @@ -856,6 +856,8 @@ udp_output(m, va_alist) register int len = m->m_pkthdr.len; struct in_addr laddr; int s = 0, error = 0; + struct route *ro; + struct ifnet *ifp; va_list ap; int pcbflags = 0; @@ -936,9 +938,20 @@ udp_output(m, va_alist) ui->ui_sum = 0; if (udpcksum) { + ro = &inp->inp_route; + if (ro->ro_rt && (ro->ro_rt->rt_flags & RTF_UP)) { + ifp = ro->ro_rt->rt_ifp; + if (ifp->if_capabilities & IFCAP_CSUM_UDPv4) { + m->m_pkthdr.csum |= M_UDPV4_CSUM_OUT; + ui->ui_sum = in_cksum(m, + sizeof(struct udpiphdr)); + goto skipudpcsum; + } + } if ((ui->ui_sum = in_cksum(m, sizeof (struct udpiphdr) + len)) == 0) ui->ui_sum = 0xffff; + skipudpcsum: } ((struct ip *)ui)->ip_len = sizeof (struct udpiphdr) + len; ((struct ip *)ui)->ip_ttl = inp->inp_ip.ip_ttl; |