xen-netfront: use skb_partial_csum_set() to simplify the codes
use skb_partial_csum_set() to simplify the codes Cc: Jason Wang <jasowang@redhat.com> Signed-off-by: Li RongQing <roy.qing.li@gmail.com> Acked-by: Jason Wang <jasowang@redhat.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
2e42206948
commit
8249152c47
|
@ -858,7 +858,6 @@ static RING_IDX xennet_fill_frags(struct netfront_info *np,
|
||||||
static int checksum_setup(struct net_device *dev, struct sk_buff *skb)
|
static int checksum_setup(struct net_device *dev, struct sk_buff *skb)
|
||||||
{
|
{
|
||||||
struct iphdr *iph;
|
struct iphdr *iph;
|
||||||
unsigned char *th;
|
|
||||||
int err = -EPROTO;
|
int err = -EPROTO;
|
||||||
int recalculate_partial_csum = 0;
|
int recalculate_partial_csum = 0;
|
||||||
|
|
||||||
|
@ -883,27 +882,27 @@ static int checksum_setup(struct net_device *dev, struct sk_buff *skb)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
iph = (void *)skb->data;
|
iph = (void *)skb->data;
|
||||||
th = skb->data + 4 * iph->ihl;
|
|
||||||
if (th >= skb_tail_pointer(skb))
|
|
||||||
goto out;
|
|
||||||
|
|
||||||
skb->csum_start = th - skb->head;
|
|
||||||
switch (iph->protocol) {
|
switch (iph->protocol) {
|
||||||
case IPPROTO_TCP:
|
case IPPROTO_TCP:
|
||||||
skb->csum_offset = offsetof(struct tcphdr, check);
|
if (!skb_partial_csum_set(skb, 4 * iph->ihl,
|
||||||
|
offsetof(struct tcphdr, check)))
|
||||||
|
goto out;
|
||||||
|
|
||||||
if (recalculate_partial_csum) {
|
if (recalculate_partial_csum) {
|
||||||
struct tcphdr *tcph = (struct tcphdr *)th;
|
struct tcphdr *tcph = tcp_hdr(skb);
|
||||||
tcph->check = ~csum_tcpudp_magic(iph->saddr, iph->daddr,
|
tcph->check = ~csum_tcpudp_magic(iph->saddr, iph->daddr,
|
||||||
skb->len - iph->ihl*4,
|
skb->len - iph->ihl*4,
|
||||||
IPPROTO_TCP, 0);
|
IPPROTO_TCP, 0);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case IPPROTO_UDP:
|
case IPPROTO_UDP:
|
||||||
skb->csum_offset = offsetof(struct udphdr, check);
|
if (!skb_partial_csum_set(skb, 4 * iph->ihl,
|
||||||
|
offsetof(struct udphdr, check)))
|
||||||
|
goto out;
|
||||||
|
|
||||||
if (recalculate_partial_csum) {
|
if (recalculate_partial_csum) {
|
||||||
struct udphdr *udph = (struct udphdr *)th;
|
struct udphdr *udph = udp_hdr(skb);
|
||||||
udph->check = ~csum_tcpudp_magic(iph->saddr, iph->daddr,
|
udph->check = ~csum_tcpudp_magic(iph->saddr, iph->daddr,
|
||||||
skb->len - iph->ihl*4,
|
skb->len - iph->ihl*4,
|
||||||
IPPROTO_UDP, 0);
|
IPPROTO_UDP, 0);
|
||||||
|
@ -917,9 +916,6 @@ static int checksum_setup(struct net_device *dev, struct sk_buff *skb)
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((th + skb->csum_offset + 2) > skb_tail_pointer(skb))
|
|
||||||
goto out;
|
|
||||||
|
|
||||||
err = 0;
|
err = 0;
|
||||||
|
|
||||||
out:
|
out:
|
||||||
|
|
Loading…
Reference in New Issue