diff options
author | Angelos D. Keromytis <angelos@cvs.openbsd.org> | 2001-06-23 06:42:38 +0000 |
---|---|---|
committer | Angelos D. Keromytis <angelos@cvs.openbsd.org> | 2001-06-23 06:42:38 +0000 |
commit | 31f363c0f918ce123d97e42c13abddde85c569a8 (patch) | |
tree | f5aa53295c885f416056c6b35d4185a8f561ce21 /sys/netinet | |
parent | fb175880d9258c15b5ad6e47f07ab155216c393c (diff) |
Software-compute TCP/UDP checksum if we are going to do IPsec or if the
output interface does not support hardware checksumming.
Diffstat (limited to 'sys/netinet')
-rw-r--r-- | sys/netinet/ip_output.c | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/sys/netinet/ip_output.c b/sys/netinet/ip_output.c index 72497f6e5e3..2efb36c66b1 100644 --- a/sys/netinet/ip_output.c +++ b/sys/netinet/ip_output.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip_output.c,v 1.108 2001/06/23 06:13:42 angelos Exp $ */ +/* $OpenBSD: ip_output.c,v 1.109 2001/06/23 06:42:37 angelos Exp $ */ /* $NetBSD: ip_output.c,v 1.28 1996/02/13 23:43:07 christos Exp $ */ /* @@ -53,6 +53,8 @@ #include <netinet/in_pcb.h> #include <netinet/in_var.h> #include <netinet/ip_var.h> +#include <netinet/tcp.h> +#include <netinet/udp.h> #ifdef vax #include <machine/mtpr.h> @@ -105,6 +107,7 @@ ip_output(m0, va_alist) struct ip_moptions *imo; va_list ap; u_int8_t sproto = 0, donerouting = 0; + short csums; #ifdef IPSEC union sockaddr_union sdst; u_int32_t sspi; @@ -336,13 +339,17 @@ ip_output(m0, va_alist) */ if (m->m_pkthdr.csum & M_TCPV4_CSUM_OUT && !(ifp->if_capabilities & IFCAP_CSUM_TCPv4)) { - /* XXX Compute TCP checksum */ + csums = in4_cksum(m, IPPROTO_TCP, 0, m->m_pkthdr.len); + m_copydata(m, hlen + offsetof(struct tcphdr, th_sum), + sizeof(short), (caddr_t)&csums); m->m_pkthdr.csum &= ~M_TCPV4_CSUM_OUT; /* Clear */ } if (m->m_pkthdr.csum & M_UDPV4_CSUM_OUT && !(ifp->if_capabilities & IFCAP_CSUM_UDPv4)) { - /* XXX Compute UDP checksum */ + csums = in4_cksum(m, IPPROTO_UDP, 0, m->m_pkthdr.len); + m_copydata(m, hlen + offsetof(struct udphdr, uh_sum), + sizeof(short), (caddr_t)&csums); m->m_pkthdr.csum &= ~M_UDPV4_CSUM_OUT; /* Clear */ } @@ -605,13 +612,17 @@ sendit: /* Catch routing changes wrt. hardware checksumming for TCP or UDP. */ if (m->m_pkthdr.csum & M_TCPV4_CSUM_OUT && !(ifp->if_capabilities & IFCAP_CSUM_TCPv4)) { - /* XXX Compute TCP checksum */ + csums = in4_cksum(m, IPPROTO_TCP, 0, m->m_pkthdr.len); + m_copydata(m, hlen + offsetof(struct tcphdr, th_sum), + sizeof(short), (caddr_t)&csums); m->m_pkthdr.csum &= ~M_TCPV4_CSUM_OUT; /* Clear */ } if (m->m_pkthdr.csum & M_UDPV4_CSUM_OUT && !(ifp->if_capabilities & IFCAP_CSUM_UDPv4)) { - /* XXX Compute UDP checksum */ + csums = in4_cksum(m, IPPROTO_UDP, 0, m->m_pkthdr.len); + m_copydata(m, hlen + offsetof(struct udphdr, uh_sum), + sizeof(short), (caddr_t)&csums); m->m_pkthdr.csum &= ~M_UDPV4_CSUM_OUT; /* Clear */ } |