aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/xen-netfront.c
diff options
context:
space:
mode:
authorLi RongQing <roy.qing.li@gmail.com>2013-06-06 02:35:18 -0400
committerDavid S. Miller <davem@davemloft.net>2013-06-11 05:34:36 -0400
commit8249152c472e10c18936b774737fd58c60335154 (patch)
treeaa760c3d66169704edae39b35dc1749d02f676d1 /drivers/net/xen-netfront.c
parent2e42206948c98fdd32b64094264419a47ee2718c (diff)
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>
Diffstat (limited to 'drivers/net/xen-netfront.c')
-rw-r--r--drivers/net/xen-netfront.c20
1 files changed, 8 insertions, 12 deletions
diff --git a/drivers/net/xen-netfront.c b/drivers/net/xen-netfront.c
index 62238a08cb51..76a22365d4e9 100644
--- a/drivers/net/xen-netfront.c
+++ b/drivers/net/xen-netfront.c
@@ -858,7 +858,6 @@ static RING_IDX xennet_fill_frags(struct netfront_info *np,
858static int checksum_setup(struct net_device *dev, struct sk_buff *skb) 858static int checksum_setup(struct net_device *dev, struct sk_buff *skb)
859{ 859{
860 struct iphdr *iph; 860 struct iphdr *iph;
861 unsigned char *th;
862 int err = -EPROTO; 861 int err = -EPROTO;
863 int recalculate_partial_csum = 0; 862 int recalculate_partial_csum = 0;
864 863
@@ -883,27 +882,27 @@ static int checksum_setup(struct net_device *dev, struct sk_buff *skb)
883 goto out; 882 goto out;
884 883
885 iph = (void *)skb->data; 884 iph = (void *)skb->data;
886 th = skb->data + 4 * iph->ihl;
887 if (th >= skb_tail_pointer(skb))
888 goto out;
889 885
890 skb->csum_start = th - skb->head;
891 switch (iph->protocol) { 886 switch (iph->protocol) {
892 case IPPROTO_TCP: 887 case IPPROTO_TCP:
893 skb->csum_offset = offsetof(struct tcphdr, check); 888 if (!skb_partial_csum_set(skb, 4 * iph->ihl,
889 offsetof(struct tcphdr, check)))
890 goto out;
894 891
895 if (recalculate_partial_csum) { 892 if (recalculate_partial_csum) {
896 struct tcphdr *tcph = (struct tcphdr *)th; 893 struct tcphdr *tcph = tcp_hdr(skb);
897 tcph->check = ~csum_tcpudp_magic(iph->saddr, iph->daddr, 894 tcph->check = ~csum_tcpudp_magic(iph->saddr, iph->daddr,
898 skb->len - iph->ihl*4, 895 skb->len - iph->ihl*4,
899 IPPROTO_TCP, 0); 896 IPPROTO_TCP, 0);
900 } 897 }
901 break; 898 break;
902 case IPPROTO_UDP: 899 case IPPROTO_UDP:
903 skb->csum_offset = offsetof(struct udphdr, check); 900 if (!skb_partial_csum_set(skb, 4 * iph->ihl,
901 offsetof(struct udphdr, check)))
902 goto out;
904 903
905 if (recalculate_partial_csum) { 904 if (recalculate_partial_csum) {
906 struct udphdr *udph = (struct udphdr *)th; 905 struct udphdr *udph = udp_hdr(skb);
907 udph->check = ~csum_tcpudp_magic(iph->saddr, iph->daddr, 906 udph->check = ~csum_tcpudp_magic(iph->saddr, iph->daddr,
908 skb->len - iph->ihl*4, 907 skb->len - iph->ihl*4,
909 IPPROTO_UDP, 0); 908 IPPROTO_UDP, 0);
@@ -917,9 +916,6 @@ static int checksum_setup(struct net_device *dev, struct sk_buff *skb)
917 goto out; 916 goto out;
918 } 917 }
919 918
920 if ((th + skb->csum_offset + 2) > skb_tail_pointer(skb))
921 goto out;
922
923 err = 0; 919 err = 0;
924 920
925out: 921out: