Commit fb286bb2 authored by Herbert Xu's avatar Herbert Xu Committed by David S. Miller

[NET]: Detect hardware rx checksum faults correctly

Here is the patch that introduces the generic skb_checksum_complete
which also checks for hardware RX checksum faults.  If that happens,
it'll call netdev_rx_csum_fault which currently prints out a stack
trace with the device name.  In future it can turn off RX checksum.

I've converted every spot under net/ that does RX checksum checks to
use skb_checksum_complete or __skb_checksum_complete with the
exceptions of:

* Those places where checksums are done bit by bit.  These will call
netdev_rx_csum_fault directly.

* The following have not been completely checked/converted:

ipmr
ip_vs
netfilter
dccp

This patch is based on patches and suggestions from Stephen Hemminger
and David S. Miller.
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 1064e944
...@@ -927,6 +927,13 @@ extern int netdev_max_backlog; ...@@ -927,6 +927,13 @@ extern int netdev_max_backlog;
extern int weight_p; extern int weight_p;
extern int netdev_set_master(struct net_device *dev, struct net_device *master); extern int netdev_set_master(struct net_device *dev, struct net_device *master);
extern int skb_checksum_help(struct sk_buff *skb, int inward); extern int skb_checksum_help(struct sk_buff *skb, int inward);
#ifdef CONFIG_BUG
extern void netdev_rx_csum_fault(struct net_device *dev);
#else
static inline void netdev_rx_csum_fault(struct net_device *dev)
{
}
#endif
/* rx skb timestamps */ /* rx skb timestamps */
extern void net_enable_timestamp(void); extern void net_enable_timestamp(void);
extern void net_disable_timestamp(void); extern void net_disable_timestamp(void);
......
...@@ -1236,8 +1236,7 @@ extern unsigned int datagram_poll(struct file *file, struct socket *sock, ...@@ -1236,8 +1236,7 @@ extern unsigned int datagram_poll(struct file *file, struct socket *sock,
extern int skb_copy_datagram_iovec(const struct sk_buff *from, extern int skb_copy_datagram_iovec(const struct sk_buff *from,
int offset, struct iovec *to, int offset, struct iovec *to,
int size); int size);
extern int skb_copy_and_csum_datagram_iovec(const extern int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb,
struct sk_buff *skb,
int hlen, int hlen,
struct iovec *iov); struct iovec *iov);
extern void skb_free_datagram(struct sock *sk, struct sk_buff *skb); extern void skb_free_datagram(struct sock *sk, struct sk_buff *skb);
...@@ -1305,6 +1304,30 @@ static inline void skb_set_timestamp(struct sk_buff *skb, const struct timeval * ...@@ -1305,6 +1304,30 @@ static inline void skb_set_timestamp(struct sk_buff *skb, const struct timeval *
extern void __net_timestamp(struct sk_buff *skb); extern void __net_timestamp(struct sk_buff *skb);
extern unsigned int __skb_checksum_complete(struct sk_buff *skb);
/**
* skb_checksum_complete - Calculate checksum of an entire packet
* @skb: packet to process
*
* This function calculates the checksum over the entire packet plus
* the value of skb->csum. The latter can be used to supply the
* checksum of a pseudo header as used by TCP/UDP. It returns the
* checksum.
*
* For protocols that contain complete checksums such as ICMP/TCP/UDP,
* this function can be used to verify that checksum on received
* packets. In that case the function should return zero if the
* checksum is correct. In particular, this function will return zero
* if skb->ip_summed is CHECKSUM_UNNECESSARY which indicates that the
* hardware has already verified the correctness of the checksum.
*/
static inline unsigned int skb_checksum_complete(struct sk_buff *skb)
{
return skb->ip_summed != CHECKSUM_UNNECESSARY &&
__skb_checksum_complete(skb);
}
#ifdef CONFIG_NETFILTER #ifdef CONFIG_NETFILTER
static inline void nf_conntrack_put(struct nf_conntrack *nfct) static inline void nf_conntrack_put(struct nf_conntrack *nfct)
{ {
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/cache.h> #include <linux/cache.h>
#include <linux/percpu.h> #include <linux/percpu.h>
#include <linux/skbuff.h>
#include <net/inet_connection_sock.h> #include <net/inet_connection_sock.h>
#include <net/inet_timewait_sock.h> #include <net/inet_timewait_sock.h>
...@@ -852,7 +853,7 @@ static __inline__ u16 tcp_v4_check(struct tcphdr *th, int len, ...@@ -852,7 +853,7 @@ static __inline__ u16 tcp_v4_check(struct tcphdr *th, int len,
static __inline__ int __tcp_checksum_complete(struct sk_buff *skb) static __inline__ int __tcp_checksum_complete(struct sk_buff *skb)
{ {
return (unsigned short)csum_fold(skb_checksum(skb, 0, skb->len, skb->csum)); return __skb_checksum_complete(skb);
} }
static __inline__ int tcp_checksum_complete(struct sk_buff *skb) static __inline__ int tcp_checksum_complete(struct sk_buff *skb)
......
...@@ -350,6 +350,20 @@ static int skb_copy_and_csum_datagram(const struct sk_buff *skb, int offset, ...@@ -350,6 +350,20 @@ static int skb_copy_and_csum_datagram(const struct sk_buff *skb, int offset,
return -EFAULT; return -EFAULT;
} }
unsigned int __skb_checksum_complete(struct sk_buff *skb)
{
unsigned int sum;
sum = (u16)csum_fold(skb_checksum(skb, 0, skb->len, skb->csum));
if (likely(!sum)) {
if (unlikely(skb->ip_summed == CHECKSUM_HW))
netdev_rx_csum_fault(skb->dev);
skb->ip_summed = CHECKSUM_UNNECESSARY;
}
return sum;
}
EXPORT_SYMBOL(__skb_checksum_complete);
/** /**
* skb_copy_and_csum_datagram_iovec - Copy and checkum skb to user iovec. * skb_copy_and_csum_datagram_iovec - Copy and checkum skb to user iovec.
* @skb: skbuff * @skb: skbuff
...@@ -363,7 +377,7 @@ static int skb_copy_and_csum_datagram(const struct sk_buff *skb, int offset, ...@@ -363,7 +377,7 @@ static int skb_copy_and_csum_datagram(const struct sk_buff *skb, int offset,
* -EFAULT - fault during copy. Beware, in this case iovec * -EFAULT - fault during copy. Beware, in this case iovec
* can be modified! * can be modified!
*/ */
int skb_copy_and_csum_datagram_iovec(const struct sk_buff *skb, int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb,
int hlen, struct iovec *iov) int hlen, struct iovec *iov)
{ {
unsigned int csum; unsigned int csum;
...@@ -376,8 +390,7 @@ int skb_copy_and_csum_datagram_iovec(const struct sk_buff *skb, ...@@ -376,8 +390,7 @@ int skb_copy_and_csum_datagram_iovec(const struct sk_buff *skb,
iov++; iov++;
if (iov->iov_len < chunk) { if (iov->iov_len < chunk) {
if ((unsigned short)csum_fold(skb_checksum(skb, 0, chunk + hlen, if (__skb_checksum_complete(skb))
skb->csum)))
goto csum_error; goto csum_error;
if (skb_copy_datagram_iovec(skb, hlen, iov, chunk)) if (skb_copy_datagram_iovec(skb, hlen, iov, chunk))
goto fault; goto fault;
...@@ -388,6 +401,8 @@ int skb_copy_and_csum_datagram_iovec(const struct sk_buff *skb, ...@@ -388,6 +401,8 @@ int skb_copy_and_csum_datagram_iovec(const struct sk_buff *skb,
goto fault; goto fault;
if ((unsigned short)csum_fold(csum)) if ((unsigned short)csum_fold(csum))
goto csum_error; goto csum_error;
if (unlikely(skb->ip_summed == CHECKSUM_HW))
netdev_rx_csum_fault(skb->dev);
iov->iov_len -= chunk; iov->iov_len -= chunk;
iov->iov_base += chunk; iov->iov_base += chunk;
} }
......
...@@ -1108,6 +1108,18 @@ int skb_checksum_help(struct sk_buff *skb, int inward) ...@@ -1108,6 +1108,18 @@ int skb_checksum_help(struct sk_buff *skb, int inward)
return ret; return ret;
} }
/* Take action when hardware reception checksum errors are detected. */
#ifdef CONFIG_BUG
void netdev_rx_csum_fault(struct net_device *dev)
{
if (net_ratelimit()) {
printk(KERN_ERR "%s: hw csum failure.\n", dev->name);
dump_stack();
}
}
EXPORT_SYMBOL(netdev_rx_csum_fault);
#endif
#ifdef CONFIG_HIGHMEM #ifdef CONFIG_HIGHMEM
/* Actually, we should eliminate this check as soon as we know, that: /* Actually, we should eliminate this check as soon as we know, that:
* 1. IOMMU is present and allows to map all the memory. * 1. IOMMU is present and allows to map all the memory.
......
...@@ -101,16 +101,20 @@ void netpoll_queue(struct sk_buff *skb) ...@@ -101,16 +101,20 @@ void netpoll_queue(struct sk_buff *skb)
static int checksum_udp(struct sk_buff *skb, struct udphdr *uh, static int checksum_udp(struct sk_buff *skb, struct udphdr *uh,
unsigned short ulen, u32 saddr, u32 daddr) unsigned short ulen, u32 saddr, u32 daddr)
{ {
if (uh->check == 0) unsigned int psum;
if (uh->check == 0 || skb->ip_summed == CHECKSUM_UNNECESSARY)
return 0; return 0;
if (skb->ip_summed == CHECKSUM_HW) psum = csum_tcpudp_nofold(saddr, daddr, ulen, IPPROTO_UDP, 0);
return csum_tcpudp_magic(
saddr, daddr, ulen, IPPROTO_UDP, skb->csum); if (skb->ip_summed == CHECKSUM_HW &&
!(u16)csum_fold(csum_add(psum, skb->csum)))
return 0;
skb->csum = csum_tcpudp_nofold(saddr, daddr, ulen, IPPROTO_UDP, 0); skb->csum = psum;
return csum_fold(skb_checksum(skb, 0, skb->len, skb->csum)); return __skb_checksum_complete(skb);
} }
/* /*
...@@ -489,7 +493,7 @@ int __netpoll_rx(struct sk_buff *skb) ...@@ -489,7 +493,7 @@ int __netpoll_rx(struct sk_buff *skb)
if (ulen != len) if (ulen != len)
goto out; goto out;
if (checksum_udp(skb, uh, ulen, iph->saddr, iph->daddr) < 0) if (checksum_udp(skb, uh, ulen, iph->saddr, iph->daddr))
goto out; goto out;
if (np->local_ip && np->local_ip != ntohl(iph->daddr)) if (np->local_ip && np->local_ip != ntohl(iph->daddr))
goto out; goto out;
......
...@@ -934,11 +934,11 @@ int icmp_rcv(struct sk_buff *skb) ...@@ -934,11 +934,11 @@ int icmp_rcv(struct sk_buff *skb)
case CHECKSUM_HW: case CHECKSUM_HW:
if (!(u16)csum_fold(skb->csum)) if (!(u16)csum_fold(skb->csum))
break; break;
LIMIT_NETDEBUG(KERN_DEBUG "icmp v4 hw csum failure\n"); /* fall through */
case CHECKSUM_NONE: case CHECKSUM_NONE:
if ((u16)csum_fold(skb_checksum(skb, 0, skb->len, 0))) skb->csum = 0;
if (__skb_checksum_complete(skb))
goto error; goto error;
default:;
} }
if (!pskb_pull(skb, sizeof(struct icmphdr))) if (!pskb_pull(skb, sizeof(struct icmphdr)))
......
...@@ -872,11 +872,18 @@ int igmp_rcv(struct sk_buff *skb) ...@@ -872,11 +872,18 @@ int igmp_rcv(struct sk_buff *skb)
return 0; return 0;
} }
if (!pskb_may_pull(skb, sizeof(struct igmphdr)) || if (!pskb_may_pull(skb, sizeof(struct igmphdr)))
(u16)csum_fold(skb_checksum(skb, 0, len, 0))) { goto drop;
in_dev_put(in_dev);
kfree_skb(skb); switch (skb->ip_summed) {
return 0; case CHECKSUM_HW:
if (!(u16)csum_fold(skb->csum))
break;
/* fall through */
case CHECKSUM_NONE:
skb->csum = 0;
if (__skb_checksum_complete(skb))
goto drop;
} }
ih = skb->h.igmph; ih = skb->h.igmph;
...@@ -906,6 +913,8 @@ int igmp_rcv(struct sk_buff *skb) ...@@ -906,6 +913,8 @@ int igmp_rcv(struct sk_buff *skb)
default: default:
NETDEBUG(KERN_DEBUG "New IGMP type=%d, why we do not know about it?\n", ih->type); NETDEBUG(KERN_DEBUG "New IGMP type=%d, why we do not know about it?\n", ih->type);
} }
drop:
in_dev_put(in_dev); in_dev_put(in_dev);
kfree_skb(skb); kfree_skb(skb);
return 0; return 0;
......
...@@ -577,15 +577,16 @@ static int ipgre_rcv(struct sk_buff *skb) ...@@ -577,15 +577,16 @@ static int ipgre_rcv(struct sk_buff *skb)
goto drop_nolock; goto drop_nolock;
if (flags&GRE_CSUM) { if (flags&GRE_CSUM) {
if (skb->ip_summed == CHECKSUM_HW) { switch (skb->ip_summed) {
case CHECKSUM_HW:
csum = (u16)csum_fold(skb->csum); csum = (u16)csum_fold(skb->csum);
if (csum) if (!csum)
skb->ip_summed = CHECKSUM_NONE; break;
} /* fall through */
if (skb->ip_summed == CHECKSUM_NONE) { case CHECKSUM_NONE:
skb->csum = skb_checksum(skb, 0, skb->len, 0); skb->csum = 0;
csum = __skb_checksum_complete(skb);
skb->ip_summed = CHECKSUM_HW; skb->ip_summed = CHECKSUM_HW;
csum = (u16)csum_fold(skb->csum);
} }
offset += 4; offset += 4;
} }
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include <linux/in.h> #include <linux/in.h>
#include <linux/icmp.h> #include <linux/icmp.h>
#include <linux/seq_file.h> #include <linux/seq_file.h>
#include <linux/skbuff.h>
#include <net/ip.h> #include <net/ip.h>
#include <net/checksum.h> #include <net/checksum.h>
#include <linux/netfilter.h> #include <linux/netfilter.h>
...@@ -230,19 +231,15 @@ icmp_error(struct sk_buff *skb, enum ip_conntrack_info *ctinfo, ...@@ -230,19 +231,15 @@ icmp_error(struct sk_buff *skb, enum ip_conntrack_info *ctinfo,
case CHECKSUM_HW: case CHECKSUM_HW:
if (!(u16)csum_fold(skb->csum)) if (!(u16)csum_fold(skb->csum))
break; break;
if (LOG_INVALID(IPPROTO_ICMP)) /* fall through */
nf_log_packet(PF_INET, 0, skb, NULL, NULL, NULL,
"ip_ct_icmp: bad HW ICMP checksum ");
return -NF_ACCEPT;
case CHECKSUM_NONE: case CHECKSUM_NONE:
if ((u16)csum_fold(skb_checksum(skb, 0, skb->len, 0))) { skb->csum = 0;
if (__skb_checksum_complete(skb)) {
if (LOG_INVALID(IPPROTO_ICMP)) if (LOG_INVALID(IPPROTO_ICMP))
nf_log_packet(PF_INET, 0, skb, NULL, NULL, NULL, nf_log_packet(PF_INET, 0, skb, NULL, NULL, NULL,
"ip_ct_icmp: bad ICMP checksum "); "ip_ct_icmp: bad ICMP checksum ");
return -NF_ACCEPT; return -NF_ACCEPT;
} }
default:
break;
} }
checksum_skipped: checksum_skipped:
......
...@@ -1110,24 +1110,18 @@ static struct sock *tcp_v4_hnd_req(struct sock *sk, struct sk_buff *skb) ...@@ -1110,24 +1110,18 @@ static struct sock *tcp_v4_hnd_req(struct sock *sk, struct sk_buff *skb)
static int tcp_v4_checksum_init(struct sk_buff *skb) static int tcp_v4_checksum_init(struct sk_buff *skb)
{ {
if (skb->ip_summed == CHECKSUM_HW) { if (skb->ip_summed == CHECKSUM_HW) {
skb->ip_summed = CHECKSUM_UNNECESSARY;
if (!tcp_v4_check(skb->h.th, skb->len, skb->nh.iph->saddr, if (!tcp_v4_check(skb->h.th, skb->len, skb->nh.iph->saddr,
skb->nh.iph->daddr, skb->csum)) skb->nh.iph->daddr, skb->csum)) {
skb->ip_summed = CHECKSUM_UNNECESSARY;
return 0; return 0;
}
LIMIT_NETDEBUG(KERN_DEBUG "hw tcp v4 csum failed\n");
skb->ip_summed = CHECKSUM_NONE;
} }
skb->csum = csum_tcpudp_nofold(skb->nh.iph->saddr, skb->nh.iph->daddr,
skb->len, IPPROTO_TCP, 0);
if (skb->len <= 76) { if (skb->len <= 76) {
if (tcp_v4_check(skb->h.th, skb->len, skb->nh.iph->saddr, return __skb_checksum_complete(skb);
skb->nh.iph->daddr,
skb_checksum(skb, 0, skb->len, 0)))
return -1;
skb->ip_summed = CHECKSUM_UNNECESSARY;
} else {
skb->csum = ~tcp_v4_check(skb->h.th, skb->len,
skb->nh.iph->saddr,
skb->nh.iph->daddr, 0);
} }
return 0; return 0;
} }
...@@ -1219,7 +1213,7 @@ int tcp_v4_rcv(struct sk_buff *skb) ...@@ -1219,7 +1213,7 @@ int tcp_v4_rcv(struct sk_buff *skb)
* provided case of th->doff==0 is elimineted. * provided case of th->doff==0 is elimineted.
* So, we defer the checks. */ * So, we defer the checks. */
if ((skb->ip_summed != CHECKSUM_UNNECESSARY && if ((skb->ip_summed != CHECKSUM_UNNECESSARY &&
tcp_v4_checksum_init(skb) < 0)) tcp_v4_checksum_init(skb)))
goto bad_packet; goto bad_packet;
th = skb->h.th; th = skb->h.th;
......
...@@ -761,7 +761,7 @@ int udp_ioctl(struct sock *sk, int cmd, unsigned long arg) ...@@ -761,7 +761,7 @@ int udp_ioctl(struct sock *sk, int cmd, unsigned long arg)
static __inline__ int __udp_checksum_complete(struct sk_buff *skb) static __inline__ int __udp_checksum_complete(struct sk_buff *skb)
{ {
return (unsigned short)csum_fold(skb_checksum(skb, 0, skb->len, skb->csum)); return __skb_checksum_complete(skb);
} }
static __inline__ int udp_checksum_complete(struct sk_buff *skb) static __inline__ int udp_checksum_complete(struct sk_buff *skb)
...@@ -1100,11 +1100,8 @@ static int udp_checksum_init(struct sk_buff *skb, struct udphdr *uh, ...@@ -1100,11 +1100,8 @@ static int udp_checksum_init(struct sk_buff *skb, struct udphdr *uh,
if (uh->check == 0) { if (uh->check == 0) {
skb->ip_summed = CHECKSUM_UNNECESSARY; skb->ip_summed = CHECKSUM_UNNECESSARY;
} else if (skb->ip_summed == CHECKSUM_HW) { } else if (skb->ip_summed == CHECKSUM_HW) {
skb->ip_summed = CHECKSUM_UNNECESSARY;
if (!udp_check(uh, ulen, saddr, daddr, skb->csum)) if (!udp_check(uh, ulen, saddr, daddr, skb->csum))
return 0; skb->ip_summed = CHECKSUM_UNNECESSARY;
LIMIT_NETDEBUG(KERN_DEBUG "udp v4 hw csum failure.\n");
skb->ip_summed = CHECKSUM_NONE;
} }
if (skb->ip_summed != CHECKSUM_UNNECESSARY) if (skb->ip_summed != CHECKSUM_UNNECESSARY)
skb->csum = csum_tcpudp_nofold(saddr, daddr, ulen, IPPROTO_UDP, 0); skb->csum = csum_tcpudp_nofold(saddr, daddr, ulen, IPPROTO_UDP, 0);
......
...@@ -585,17 +585,16 @@ static int icmpv6_rcv(struct sk_buff **pskb, unsigned int *nhoffp) ...@@ -585,17 +585,16 @@ static int icmpv6_rcv(struct sk_buff **pskb, unsigned int *nhoffp)
daddr = &skb->nh.ipv6h->daddr; daddr = &skb->nh.ipv6h->daddr;
/* Perform checksum. */ /* Perform checksum. */
if (skb->ip_summed == CHECKSUM_HW) { switch (skb->ip_summed) {
skb->ip_summed = CHECKSUM_UNNECESSARY; case CHECKSUM_HW:
if (csum_ipv6_magic(saddr, daddr, skb->len, IPPROTO_ICMPV6, if (!csum_ipv6_magic(saddr, daddr, skb->len, IPPROTO_ICMPV6,
skb->csum)) { skb->csum))
LIMIT_NETDEBUG(KERN_DEBUG "ICMPv6 hw checksum failed\n"); break;
skb->ip_summed = CHECKSUM_NONE; /* fall through */
} case CHECKSUM_NONE:
} skb->csum = ~csum_ipv6_magic(saddr, daddr, skb->len,
if (skb->ip_summed == CHECKSUM_NONE) { IPPROTO_ICMPV6, 0);
if (csum_ipv6_magic(saddr, daddr, skb->len, IPPROTO_ICMPV6, if (__skb_checksum_complete(skb)) {
skb_checksum(skb, 0, skb->len, 0))) {
LIMIT_NETDEBUG(KERN_DEBUG "ICMPv6 checksum failed [%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x > %04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x]\n", LIMIT_NETDEBUG(KERN_DEBUG "ICMPv6 checksum failed [%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x > %04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x]\n",
NIP6(*saddr), NIP6(*daddr)); NIP6(*saddr), NIP6(*daddr));
goto discard_it; goto discard_it;
......
...@@ -298,13 +298,10 @@ void rawv6_err(struct sock *sk, struct sk_buff *skb, ...@@ -298,13 +298,10 @@ void rawv6_err(struct sock *sk, struct sk_buff *skb,
static inline int rawv6_rcv_skb(struct sock * sk, struct sk_buff * skb) static inline int rawv6_rcv_skb(struct sock * sk, struct sk_buff * skb)
{ {
if ((raw6_sk(sk)->checksum || sk->sk_filter) && if ((raw6_sk(sk)->checksum || sk->sk_filter) &&
skb->ip_summed != CHECKSUM_UNNECESSARY) { skb_checksum_complete(skb)) {
if ((unsigned short)csum_fold(skb_checksum(skb, 0, skb->len, skb->csum))) { /* FIXME: increment a raw6 drops counter here */
/* FIXME: increment a raw6 drops counter here */ kfree_skb(skb);
kfree_skb(skb); return 0;
return 0;
}
skb->ip_summed = CHECKSUM_UNNECESSARY;
} }
/* Charge it to the socket. */ /* Charge it to the socket. */
...@@ -337,32 +334,25 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb) ...@@ -337,32 +334,25 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
if (!rp->checksum) if (!rp->checksum)
skb->ip_summed = CHECKSUM_UNNECESSARY; skb->ip_summed = CHECKSUM_UNNECESSARY;
if (skb->ip_summed != CHECKSUM_UNNECESSARY) { if (skb->ip_summed == CHECKSUM_HW) {
if (skb->ip_summed == CHECKSUM_HW) { skb_postpull_rcsum(skb, skb->nh.raw,
skb_postpull_rcsum(skb, skb->nh.raw, skb->h.raw - skb->nh.raw);
skb->h.raw - skb->nh.raw); if (!csum_ipv6_magic(&skb->nh.ipv6h->saddr,
&skb->nh.ipv6h->daddr,
skb->len, inet->num, skb->csum))
skb->ip_summed = CHECKSUM_UNNECESSARY; skb->ip_summed = CHECKSUM_UNNECESSARY;
if (csum_ipv6_magic(&skb->nh.ipv6h->saddr,
&skb->nh.ipv6h->daddr,
skb->len, inet->num, skb->csum)) {
LIMIT_NETDEBUG(KERN_DEBUG "raw v6 hw csum failure.\n");
skb->ip_summed = CHECKSUM_NONE;
}
}
if (skb->ip_summed == CHECKSUM_NONE)
skb->csum = ~csum_ipv6_magic(&skb->nh.ipv6h->saddr,
&skb->nh.ipv6h->daddr,
skb->len, inet->num, 0);
} }
if (skb->ip_summed != CHECKSUM_UNNECESSARY)
skb->csum = ~csum_ipv6_magic(&skb->nh.ipv6h->saddr,
&skb->nh.ipv6h->daddr,
skb->len, inet->num, 0);
if (inet->hdrincl) { if (inet->hdrincl) {
if (skb->ip_summed != CHECKSUM_UNNECESSARY && if (skb_checksum_complete(skb)) {
(unsigned short)csum_fold(skb_checksum(skb, 0, skb->len, skb->csum))) {
/* FIXME: increment a raw6 drops counter here */ /* FIXME: increment a raw6 drops counter here */
kfree_skb(skb); kfree_skb(skb);
return 0; return 0;
} }
skb->ip_summed = CHECKSUM_UNNECESSARY;
} }
rawv6_rcv_skb(sk, skb); rawv6_rcv_skb(sk, skb);
...@@ -407,7 +397,7 @@ static int rawv6_recvmsg(struct kiocb *iocb, struct sock *sk, ...@@ -407,7 +397,7 @@ static int rawv6_recvmsg(struct kiocb *iocb, struct sock *sk,
if (skb->ip_summed==CHECKSUM_UNNECESSARY) { if (skb->ip_summed==CHECKSUM_UNNECESSARY) {
err = skb_copy_datagram_iovec(skb, 0, msg->msg_iov, copied); err = skb_copy_datagram_iovec(skb, 0, msg->msg_iov, copied);
} else if (msg->msg_flags&MSG_TRUNC) { } else if (msg->msg_flags&MSG_TRUNC) {
if ((unsigned short)csum_fold(skb_checksum(skb, 0, skb->len, skb->csum))) if (__skb_checksum_complete(skb))
goto csum_copy_err; goto csum_copy_err;
err = skb_copy_datagram_iovec(skb, 0, msg->msg_iov, copied); err = skb_copy_datagram_iovec(skb, 0, msg->msg_iov, copied);
} else { } else {
......
...@@ -1401,20 +1401,18 @@ static struct sock * tcp_v6_syn_recv_sock(struct sock *sk, struct sk_buff *skb, ...@@ -1401,20 +1401,18 @@ static struct sock * tcp_v6_syn_recv_sock(struct sock *sk, struct sk_buff *skb,
static int tcp_v6_checksum_init(struct sk_buff *skb) static int tcp_v6_checksum_init(struct sk_buff *skb)
{ {
if (skb->ip_summed == CHECKSUM_HW) { if (skb->ip_summed == CHECKSUM_HW) {
skb->ip_summed = CHECKSUM_UNNECESSARY;
if (!tcp_v6_check(skb->h.th,skb->len,&skb->nh.ipv6h->saddr, if (!tcp_v6_check(skb->h.th,skb->len,&skb->nh.ipv6h->saddr,
&skb->nh.ipv6h->daddr,skb->csum)) &skb->nh.ipv6h->daddr,skb->csum)) {
skb->ip_summed = CHECKSUM_UNNECESSARY;
return 0; return 0;
LIMIT_NETDEBUG(KERN_DEBUG "hw tcp v6 csum failed\n"); }
} }
skb->csum = ~tcp_v6_check(skb->h.th,skb->len,&skb->nh.ipv6h->saddr,
&skb->nh.ipv6h->daddr, 0);
if (skb->len <= 76) { if (skb->len <= 76) {
if (tcp_v6_check(skb->h.th,skb->len,&skb->nh.ipv6h->saddr, return __skb_checksum_complete(skb);
&skb->nh.ipv6h->daddr,skb_checksum(skb, 0, skb->len, 0)))
return -1;
skb->ip_summed = CHECKSUM_UNNECESSARY;
} else {
skb->csum = ~tcp_v6_check(skb->h.th,skb->len,&skb->nh.ipv6h->saddr,
&skb->nh.ipv6h->daddr,0);
} }
return 0; return 0;
} }
...@@ -1575,7 +1573,7 @@ static int tcp_v6_rcv(struct sk_buff **pskb, unsigned int *nhoffp) ...@@ -1575,7 +1573,7 @@ static int tcp_v6_rcv(struct sk_buff **pskb, unsigned int *nhoffp)
goto discard_it; goto discard_it;
if ((skb->ip_summed != CHECKSUM_UNNECESSARY && if ((skb->ip_summed != CHECKSUM_UNNECESSARY &&
tcp_v6_checksum_init(skb) < 0)) tcp_v6_checksum_init(skb)))
goto bad_packet; goto bad_packet;
th = skb->h.th; th = skb->h.th;
......
...@@ -248,7 +248,7 @@ static int udpv6_recvmsg(struct kiocb *iocb, struct sock *sk, ...@@ -248,7 +248,7 @@ static int udpv6_recvmsg(struct kiocb *iocb, struct sock *sk,
err = skb_copy_datagram_iovec(skb, sizeof(struct udphdr), msg->msg_iov, err = skb_copy_datagram_iovec(skb, sizeof(struct udphdr), msg->msg_iov,
copied); copied);
} else if (msg->msg_flags&MSG_TRUNC) { } else if (msg->msg_flags&MSG_TRUNC) {
if ((unsigned short)csum_fold(skb_checksum(skb, 0, skb->len, skb->csum))) if (__skb_checksum_complete(skb))
goto csum_copy_err; goto csum_copy_err;
err = skb_copy_datagram_iovec(skb, sizeof(struct udphdr), msg->msg_iov, err = skb_copy_datagram_iovec(skb, sizeof(struct udphdr), msg->msg_iov,
copied); copied);
...@@ -363,13 +363,10 @@ static inline int udpv6_queue_rcv_skb(struct sock * sk, struct sk_buff *skb) ...@@ -363,13 +363,10 @@ static inline int udpv6_queue_rcv_skb(struct sock * sk, struct sk_buff *skb)
return -1; return -1;
} }
if (skb->ip_summed != CHECKSUM_UNNECESSARY) { if (skb_checksum_complete(skb)) {
if ((unsigned short)csum_fold(skb_checksum(skb, 0, skb->len, skb->csum))) { UDP6_INC_STATS_BH(UDP_MIB_INERRORS);
UDP6_INC_STATS_BH(UDP_MIB_INERRORS); kfree_skb(skb);
kfree_skb(skb); return 0;
return 0;
}
skb->ip_summed = CHECKSUM_UNNECESSARY;
} }
if (sock_queue_rcv_skb(sk,skb)<0) { if (sock_queue_rcv_skb(sk,skb)<0) {
...@@ -491,13 +488,10 @@ static int udpv6_rcv(struct sk_buff **pskb, unsigned int *nhoffp) ...@@ -491,13 +488,10 @@ static int udpv6_rcv(struct sk_buff **pskb, unsigned int *nhoffp)
uh = skb->h.uh; uh = skb->h.uh;
} }
if (skb->ip_summed==CHECKSUM_HW) { if (skb->ip_summed == CHECKSUM_HW &&
!csum_ipv6_magic(saddr, daddr, ulen, IPPROTO_UDP, skb->csum))
skb->ip_summed = CHECKSUM_UNNECESSARY; skb->ip_summed = CHECKSUM_UNNECESSARY;
if (csum_ipv6_magic(saddr, daddr, ulen, IPPROTO_UDP, skb->csum)) {
LIMIT_NETDEBUG(KERN_DEBUG "udp v6 hw csum failure.\n");
skb->ip_summed = CHECKSUM_NONE;
}
}
if (skb->ip_summed != CHECKSUM_UNNECESSARY) if (skb->ip_summed != CHECKSUM_UNNECESSARY)
skb->csum = ~csum_ipv6_magic(saddr, daddr, ulen, IPPROTO_UDP, 0); skb->csum = ~csum_ipv6_magic(saddr, daddr, ulen, IPPROTO_UDP, 0);
...@@ -521,8 +515,7 @@ static int udpv6_rcv(struct sk_buff **pskb, unsigned int *nhoffp) ...@@ -521,8 +515,7 @@ static int udpv6_rcv(struct sk_buff **pskb, unsigned int *nhoffp)
if (!xfrm6_policy_check(NULL, XFRM_POLICY_IN, skb)) if (!xfrm6_policy_check(NULL, XFRM_POLICY_IN, skb))
goto discard; goto discard;
if (skb->ip_summed != CHECKSUM_UNNECESSARY && if (skb_checksum_complete(skb))
(unsigned short)csum_fold(skb_checksum(skb, 0, skb->len, skb->csum)))
goto discard; goto discard;
UDP6_INC_STATS_BH(UDP_MIB_NOPORTS); UDP6_INC_STATS_BH(UDP_MIB_NOPORTS);
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include <linux/in.h> #include <linux/in.h>
#include <linux/in6.h> #include <linux/in6.h>
#include <linux/icmp.h> #include <linux/icmp.h>
#include <linux/skbuff.h>
#include <net/sock.h> #include <net/sock.h>
#include <net/ip.h> #include <net/ip.h>
#if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE) #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
...@@ -475,15 +476,11 @@ void rxrpc_trans_receive_packet(struct rxrpc_transport *trans) ...@@ -475,15 +476,11 @@ void rxrpc_trans_receive_packet(struct rxrpc_transport *trans)
/* we'll probably need to checksum it (didn't call /* we'll probably need to checksum it (didn't call
* sock_recvmsg) */ * sock_recvmsg) */
if (pkt->ip_summed != CHECKSUM_UNNECESSARY) { if (skb_checksum_complete(pkt)) {
if ((unsigned short) kfree_skb(pkt);
csum_fold(skb_checksum(pkt, 0, pkt->len, rxrpc_krxiod_queue_transport(trans);
pkt->csum))) { _leave(" CSUM failed");
kfree_skb(pkt); return;
rxrpc_krxiod_queue_transport(trans);
_leave(" CSUM failed");
return;
}
} }
addr = pkt->nh.iph->saddr; addr = pkt->nh.iph->saddr;
......
...@@ -6,6 +6,9 @@ ...@@ -6,6 +6,9 @@
* Copyright (C) 1995, 1996 Olaf Kirch <okir@monad.swb.de> * Copyright (C) 1995, 1996 Olaf Kirch <okir@monad.swb.de>
*/ */
#include <linux/compiler.h>
#include <linux/netdevice.h>
#include <linux/skbuff.h>
#include <linux/types.h> #include <linux/types.h>
#include <linux/pagemap.h> #include <linux/pagemap.h>
#include <linux/udp.h> #include <linux/udp.h>
...@@ -165,6 +168,8 @@ int csum_partial_copy_to_xdr(struct xdr_buf *xdr, struct sk_buff *skb) ...@@ -165,6 +168,8 @@ int csum_partial_copy_to_xdr(struct xdr_buf *xdr, struct sk_buff *skb)
return -1; return -1;
if ((unsigned short)csum_fold(desc.csum)) if ((unsigned short)csum_fold(desc.csum))
return -1; return -1;
if (unlikely(skb->ip_summed == CHECKSUM_HW))
netdev_rx_csum_fault(skb->dev);
return 0; return 0;
no_checksum: no_checksum:
if (xdr_partial_copy_from_skb(xdr, 0, &desc, skb_read_bits) < 0) if (xdr_partial_copy_from_skb(xdr, 0, &desc, skb_read_bits) < 0)
......
...@@ -623,12 +623,9 @@ svc_udp_recvfrom(struct svc_rqst *rqstp) ...@@ -623,12 +623,9 @@ svc_udp_recvfrom(struct svc_rqst *rqstp)
/* we can use it in-place */ /* we can use it in-place */
rqstp->rq_arg.head[0].iov_base = skb->data + sizeof(struct udphdr); rqstp->rq_arg.head[0].iov_base = skb->data + sizeof(struct udphdr);
rqstp->rq_arg.head[0].iov_len = len; rqstp->rq_arg.head[0].iov_len = len;
if (skb->ip_summed != CHECKSUM_UNNECESSARY) { if (skb_checksum_complete(skb)) {
if ((unsigned short)csum_fold(skb_checksum(skb, 0, skb->len, skb->csum))) { skb_free_datagram(svsk->sk_sk, skb);
skb_free_datagram(svsk->sk_sk, skb); return 0;
return 0;
}
skb->ip_summed = CHECKSUM_UNNECESSARY;
} }
rqstp->rq_skbuff = skb; rqstp->rq_skbuff = skb;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment