svn commit: r238235 - stable/9/sys/netinet6

Bjoern A. Zeeb bz at FreeBSD.org
Sun Jul 8 11:57:12 UTC 2012


Author: bz
Date: Sun Jul  8 11:57:11 2012
New Revision: 238235
URL: http://svn.freebsd.org/changeset/base/238235

Log:
  MFC r235959:
  
     Defer checksum calulations on UDP6 output and respect the mbuf
     flags set by NICs having done checksum validation for us already,
     thus saving the computing time in the input path as well.
  
  Approved by:	re

Modified:
  stable/9/sys/netinet6/udp6_usrreq.c
Directory Properties:
  stable/9/sys/   (props changed)

Modified: stable/9/sys/netinet6/udp6_usrreq.c
==============================================================================
--- stable/9/sys/netinet6/udp6_usrreq.c	Sun Jul  8 11:53:13 2012	(r238234)
+++ stable/9/sys/netinet6/udp6_usrreq.c	Sun Jul  8 11:57:11 2012	(r238235)
@@ -185,6 +185,7 @@ udp6_input(struct mbuf **mp, int *offp, 
 #ifdef IPFIREWALL_FORWARD
 	struct m_tag *fwd_tag;
 #endif
+	uint16_t uh_sum;
 
 	ifp = m->m_pkthdr.rcvif;
 	ip6 = mtod(m, struct ip6_hdr *);
@@ -228,7 +229,18 @@ udp6_input(struct mbuf **mp, int *offp, 
 		UDPSTAT_INC(udps_nosum);
 		goto badunlocked;
 	}
-	if (in6_cksum(m, IPPROTO_UDP, off, ulen) != 0) {
+
+	if (m->m_pkthdr.csum_flags & CSUM_DATA_VALID) {
+		if (m->m_pkthdr.csum_flags & CSUM_PSEUDO_HDR)
+			uh_sum = m->m_pkthdr.csum_data;
+		else
+			uh_sum = in6_cksum_pseudo(ip6, ulen,
+			    IPPROTO_UDP, m->m_pkthdr.csum_data);
+		uh_sum ^= 0xffff;
+	} else
+		uh_sum = in6_cksum(m, IPPROTO_UDP, off, ulen);
+
+	if (uh_sum != 0) {
 		UDPSTAT_INC(udps_badsum);
 		goto badunlocked;
 	}
@@ -771,10 +783,9 @@ udp6_output(struct inpcb *inp, struct mb
 		ip6->ip6_src	= *laddr;
 		ip6->ip6_dst	= *faddr;
 
-		if ((udp6->uh_sum = in6_cksum(m, IPPROTO_UDP,
-				sizeof(struct ip6_hdr), plen)) == 0) {
-			udp6->uh_sum = 0xffff;
-		}
+		udp6->uh_sum = in6_cksum_pseudo(ip6, plen, IPPROTO_UDP, 0);
+		m->m_pkthdr.csum_flags = CSUM_UDP;
+		m->m_pkthdr.csum_data = offsetof(struct udphdr, uh_sum);
 
 		flags = 0;
 


More information about the svn-src-stable-9 mailing list