netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next] xen-netfront: use skb_partial_csum_set() to simplify the codes
@ 2013-06-06  6:35 roy.qing.li
  2013-06-07  3:05 ` Jason Wang
  0 siblings, 1 reply; 3+ messages in thread
From: roy.qing.li @ 2013-06-06  6:35 UTC (permalink / raw)
  To: netdev; +Cc: jasowang

From: Li RongQing <roy.qing.li@gmail.com>

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>
---
 drivers/net/xen-netfront.c |   20 ++++++++------------
 1 file changed, 8 insertions(+), 12 deletions(-)

diff --git a/drivers/net/xen-netfront.c b/drivers/net/xen-netfront.c
index 62238a0..76a2236 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,
 static int checksum_setup(struct net_device *dev, struct sk_buff *skb)
 {
 	struct iphdr *iph;
-	unsigned char *th;
 	int err = -EPROTO;
 	int recalculate_partial_csum = 0;
 
@@ -883,27 +882,27 @@ static int checksum_setup(struct net_device *dev, struct sk_buff *skb)
 		goto out;
 
 	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) {
 	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) {
-			struct tcphdr *tcph = (struct tcphdr *)th;
+			struct tcphdr *tcph = tcp_hdr(skb);
 			tcph->check = ~csum_tcpudp_magic(iph->saddr, iph->daddr,
 							 skb->len - iph->ihl*4,
 							 IPPROTO_TCP, 0);
 		}
 		break;
 	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) {
-			struct udphdr *udph = (struct udphdr *)th;
+			struct udphdr *udph = udp_hdr(skb);
 			udph->check = ~csum_tcpudp_magic(iph->saddr, iph->daddr,
 							 skb->len - iph->ihl*4,
 							 IPPROTO_UDP, 0);
@@ -917,9 +916,6 @@ static int checksum_setup(struct net_device *dev, struct sk_buff *skb)
 		goto out;
 	}
 
-	if ((th + skb->csum_offset + 2) > skb_tail_pointer(skb))
-		goto out;
-
 	err = 0;
 
 out:
-- 
1.7.10.4

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH net-next] xen-netfront: use skb_partial_csum_set() to simplify the codes
  2013-06-06  6:35 [PATCH net-next] xen-netfront: use skb_partial_csum_set() to simplify the codes roy.qing.li
@ 2013-06-07  3:05 ` Jason Wang
  2013-06-11  9:35   ` David Miller
  0 siblings, 1 reply; 3+ messages in thread
From: Jason Wang @ 2013-06-07  3:05 UTC (permalink / raw)
  To: roy.qing.li; +Cc: netdev

On 06/06/2013 02:35 PM, roy.qing.li@gmail.com wrote:
> From: Li RongQing <roy.qing.li@gmail.com>
>
> 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>
> ---
>  drivers/net/xen-netfront.c |   20 ++++++++------------
>  1 file changed, 8 insertions(+), 12 deletions(-)
>
> diff --git a/drivers/net/xen-netfront.c b/drivers/net/xen-netfront.c
> index 62238a0..76a2236 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,
>  static int checksum_setup(struct net_device *dev, struct sk_buff *skb)
>  {
>  	struct iphdr *iph;
> -	unsigned char *th;
>  	int err = -EPROTO;
>  	int recalculate_partial_csum = 0;
>  
> @@ -883,27 +882,27 @@ static int checksum_setup(struct net_device *dev, struct sk_buff *skb)
>  		goto out;
>  
>  	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) {
>  	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) {
> -			struct tcphdr *tcph = (struct tcphdr *)th;
> +			struct tcphdr *tcph = tcp_hdr(skb);
>  			tcph->check = ~csum_tcpudp_magic(iph->saddr, iph->daddr,
>  							 skb->len - iph->ihl*4,
>  							 IPPROTO_TCP, 0);
>  		}
>  		break;
>  	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) {
> -			struct udphdr *udph = (struct udphdr *)th;
> +			struct udphdr *udph = udp_hdr(skb);
>  			udph->check = ~csum_tcpudp_magic(iph->saddr, iph->daddr,
>  							 skb->len - iph->ihl*4,
>  							 IPPROTO_UDP, 0);
> @@ -917,9 +916,6 @@ static int checksum_setup(struct net_device *dev, struct sk_buff *skb)
>  		goto out;
>  	}
>  
> -	if ((th + skb->csum_offset + 2) > skb_tail_pointer(skb))
> -		goto out;
> -
>  	err = 0;
>  
>  out:

Acked-by: Jason Wang <jasowang@redhat.com>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH net-next] xen-netfront: use skb_partial_csum_set() to simplify the codes
  2013-06-07  3:05 ` Jason Wang
@ 2013-06-11  9:35   ` David Miller
  0 siblings, 0 replies; 3+ messages in thread
From: David Miller @ 2013-06-11  9:35 UTC (permalink / raw)
  To: jasowang; +Cc: roy.qing.li, netdev

From: Jason Wang <jasowang@redhat.com>
Date: Fri, 07 Jun 2013 11:05:29 +0800

> On 06/06/2013 02:35 PM, roy.qing.li@gmail.com wrote:
>> From: Li RongQing <roy.qing.li@gmail.com>
>>
>> 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>

Applied, thanks.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2013-06-11  9:35 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-06-06  6:35 [PATCH net-next] xen-netfront: use skb_partial_csum_set() to simplify the codes roy.qing.li
2013-06-07  3:05 ` Jason Wang
2013-06-11  9:35   ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).