[net-next] xen-netback: switch to use skb_partial_csum_set()
diff mbox series

Message ID 1365662129-38031-1-git-send-email-jasowang@redhat.com
State New, archived
Headers show
Series
  • [net-next] xen-netback: switch to use skb_partial_csum_set()
Related show

Commit Message

Jason Wang April 11, 2013, 6:35 a.m. UTC
Switch to use skb_partial_csum_set() to simplify the codes.

Cc: Ian Campbell <ian.campbell@citrix.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>
---
Note:
- Compile test only.
---
 drivers/net/xen-netback/netback.c |   22 ++++++++--------------
 1 files changed, 8 insertions(+), 14 deletions(-)

Comments

Ian Campbell April 11, 2013, 7:46 a.m. UTC | #1
On Thu, 2013-04-11 at 07:35 +0100, Jason Wang wrote:
> Switch to use skb_partial_csum_set() to simplify the codes.

This is incremental on top of your previous patch, right?

> 
> Cc: Ian Campbell <ian.campbell@citrix.com>
> Signed-off-by: Jason Wang <jasowang@redhat.com>
> ---
> Note:
> - Compile test only.
> ---
>  drivers/net/xen-netback/netback.c |   22 ++++++++--------------
>  1 files changed, 8 insertions(+), 14 deletions(-)
> 
> diff --git a/drivers/net/xen-netback/netback.c b/drivers/net/xen-netback/netback.c
> index 83905a9..70631f0 100644
> --- a/drivers/net/xen-netback/netback.c
> +++ b/drivers/net/xen-netback/netback.c
> @@ -1156,7 +1156,6 @@ static int netbk_set_skb_gso(struct xenvif *vif,
>  static int checksum_setup(struct xenvif *vif, struct sk_buff *skb)
>  {
>  	struct iphdr *iph;
> -	unsigned char *th;
>  	int err = -EPROTO;
>  	int recalculate_partial_csum = 0;
>  
> @@ -1180,28 +1179,26 @@ static int checksum_setup(struct xenvif *vif, 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_set_transport_header(skb, 4 * iph->ihl);

Is removing this line really correct?

> -	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);
> @@ -1215,9 +1212,6 @@ static int checksum_setup(struct xenvif *vif, struct sk_buff *skb)
>  		goto out;
>  	}
>  
> -	if ((th + skb->csum_offset + 2) > skb_tail_pointer(skb))
> -		goto out;
> -
>  	err = 0;
>  
>  out:


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/
Jason Wang April 11, 2013, 7:58 a.m. UTC | #2
On 04/11/2013 03:46 PM, Ian Campbell wrote:
> On Thu, 2013-04-11 at 07:35 +0100, Jason Wang wrote:
>> Switch to use skb_partial_csum_set() to simplify the codes.
> This is incremental on top of your previous patch, right?

It's an independent patch, since the previous patch has been applied.
>> Cc: Ian Campbell <ian.campbell@citrix.com>
>> Signed-off-by: Jason Wang <jasowang@redhat.com>
>> ---
>> Note:
>> - Compile test only.
>> ---
>>  drivers/net/xen-netback/netback.c |   22 ++++++++--------------
>>  1 files changed, 8 insertions(+), 14 deletions(-)
>>
>> diff --git a/drivers/net/xen-netback/netback.c b/drivers/net/xen-netback/netback.c
>> index 83905a9..70631f0 100644
>> --- a/drivers/net/xen-netback/netback.c
>> +++ b/drivers/net/xen-netback/netback.c
>> @@ -1156,7 +1156,6 @@ static int netbk_set_skb_gso(struct xenvif *vif,
>>  static int checksum_setup(struct xenvif *vif, struct sk_buff *skb)
>>  {
>>  	struct iphdr *iph;
>> -	unsigned char *th;
>>  	int err = -EPROTO;
>>  	int recalculate_partial_csum = 0;
>>  
>> @@ -1180,28 +1179,26 @@ static int checksum_setup(struct xenvif *vif, 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_set_transport_header(skb, 4 * iph->ihl);
> Is removing this line really correct?

After commit e5d5deca (net: core: let skb_partial_csum_set() set
transport header), this work was done by skb_partial_csum_set().
>
>> -	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);
>> @@ -1215,9 +1212,6 @@ static int checksum_setup(struct xenvif *vif, struct sk_buff *skb)
>>  		goto out;
>>  	}
>>  
>> -	if ((th + skb->csum_offset + 2) > skb_tail_pointer(skb))
>> -		goto out;
>> -
>>  	err = 0;
>>  
>>  out:
>

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/
Ian Campbell April 11, 2013, 8:03 a.m. UTC | #3
On Thu, 2013-04-11 at 08:58 +0100, Jason Wang wrote:
> On 04/11/2013 03:46 PM, Ian Campbell wrote:
> > On Thu, 2013-04-11 at 07:35 +0100, Jason Wang wrote:
> >> Switch to use skb_partial_csum_set() to simplify the codes.
> > This is incremental on top of your previous patch, right?
> 
> It's an independent patch, since the previous patch has been applied.
> >> Cc: Ian Campbell <ian.campbell@citrix.com>
> >> Signed-off-by: Jason Wang <jasowang@redhat.com>
> >> ---
> >> Note:
> >> - Compile test only.
> >> ---
> >>  drivers/net/xen-netback/netback.c |   22 ++++++++--------------
> >>  1 files changed, 8 insertions(+), 14 deletions(-)
> >>
> >> diff --git a/drivers/net/xen-netback/netback.c b/drivers/net/xen-netback/netback.c
> >> index 83905a9..70631f0 100644
> >> --- a/drivers/net/xen-netback/netback.c
> >> +++ b/drivers/net/xen-netback/netback.c
> >> @@ -1156,7 +1156,6 @@ static int netbk_set_skb_gso(struct xenvif *vif,
> >>  static int checksum_setup(struct xenvif *vif, struct sk_buff *skb)
> >>  {
> >>  	struct iphdr *iph;
> >> -	unsigned char *th;
> >>  	int err = -EPROTO;
> >>  	int recalculate_partial_csum = 0;
> >>  
> >> @@ -1180,28 +1179,26 @@ static int checksum_setup(struct xenvif *vif, 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_set_transport_header(skb, 4 * iph->ihl);
> > Is removing this line really correct?
> 
> After commit e5d5deca (net: core: let skb_partial_csum_set() set
> transport header), this work was done by skb_partial_csum_set().

Ah, my working tree must be out of date, thanks.

> >
> >> -	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);
> >> @@ -1215,9 +1212,6 @@ static int checksum_setup(struct xenvif *vif, struct sk_buff *skb)
> >>  		goto out;
> >>  	}
> >>  
> >> -	if ((th + skb->csum_offset + 2) > skb_tail_pointer(skb))
> >> -		goto out;
> >> -
> >>  	err = 0;
> >>  
> >>  out:
> >
> 


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/
David Miller April 12, 2013, 6:59 p.m. UTC | #4
From: Jason Wang <jasowang@redhat.com>
Date: Thu, 11 Apr 2013 14:35:29 +0800

> Switch to use skb_partial_csum_set() to simplify the codes.
> 
> Cc: Ian Campbell <ian.campbell@citrix.com>
> Signed-off-by: Jason Wang <jasowang@redhat.com>

Applied, thanks Jason.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Patch
diff mbox series

diff --git a/drivers/net/xen-netback/netback.c b/drivers/net/xen-netback/netback.c
index 83905a9..70631f0 100644
--- a/drivers/net/xen-netback/netback.c
+++ b/drivers/net/xen-netback/netback.c
@@ -1156,7 +1156,6 @@  static int netbk_set_skb_gso(struct xenvif *vif,
 static int checksum_setup(struct xenvif *vif, struct sk_buff *skb)
 {
 	struct iphdr *iph;
-	unsigned char *th;
 	int err = -EPROTO;
 	int recalculate_partial_csum = 0;
 
@@ -1180,28 +1179,26 @@  static int checksum_setup(struct xenvif *vif, 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_set_transport_header(skb, 4 * iph->ihl);
-	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);
@@ -1215,9 +1212,6 @@  static int checksum_setup(struct xenvif *vif, struct sk_buff *skb)
 		goto out;
 	}
 
-	if ((th + skb->csum_offset + 2) > skb_tail_pointer(skb))
-		goto out;
-
 	err = 0;
 
 out: