- copy_bytes = min_t(size_t, skb->len, nbytes);
- iov.iov_base = buf;
- iov.iov_len = copy_bytes;
- retval = skb_copy_datagram_iovec(skb, 0, &iov, iov.iov_len);
+ copy_bytes = tot_copy_bytes = min_t(size_t, skb->len, nbytes);
+
+ retval = 0;
+ if (skb->ip_summed == CHECKSUM_PARTIAL) {
+ if (copy_bytes == skb->len) {
+ __wsum csum = 0;
+ int csum_start, csum_offset;
+
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
+ /* Until 2.6.22, the start of the transport header was
+ * also the start of data to be checksummed. Linux
+ * 2.6.22 introduced the csum_start field for this
+ * purpose, but we should point the transport header to
+ * it anyway for backward compatibility, as
+ * dev_queue_xmit() does even in 2.6.28. */
+ skb_set_transport_header(skb, skb->csum_start - skb_headroom(skb));
+ csum_offset = skb->csum_offset;
+#else
+ csum_offset = skb->csum;
+#endif
+ csum_start = skb_transport_header(skb) - skb->data;
+ retval = skb_copy_and_csum_datagram(skb, csum_start, buf + csum_start,
+ copy_bytes - csum_start, &csum);
+ if (!retval) {
+ __sum16 __user *csump;
+
+ copy_bytes = csum_start;
+ csump = (__sum16 __user *)(buf + csum_start + csum_offset);
+ put_user(csum_fold(csum), csump);
+ }
+ } else
+ retval = skb_checksum_help(skb);
+ }
+
+ if (!retval) {
+ struct iovec __user iov;
+
+ iov.iov_base = buf;
+ iov.iov_len = copy_bytes;
+ retval = skb_copy_datagram_iovec(skb, 0, &iov, iov.iov_len);
+ }
+