Skip to content

Commit

Permalink
net: add skb functions to process remote checksum offload
Browse files Browse the repository at this point in the history
This patch adds skb_remcsum_process and skb_gro_remcsum_process to
perform the appropriate adjustments to the skb when receiving
remote checksum offload.

Updated vxlan and gue to use these functions.

Tested: Ran TCP_RR and TCP_STREAM netperf for VXLAN and GUE, did
not see any change in performance.

Signed-off-by: Tom Herbert <therbert@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Tom Herbert authored and David S. Miller committed Feb 4, 2015
1 parent 9a05dde commit dcdc899
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 32 deletions.
18 changes: 2 additions & 16 deletions drivers/net/vxlan.c
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,6 @@ static struct vxlanhdr *vxlan_gro_remcsum(struct sk_buff *skb,
u32 data)
{
size_t start, offset, plen;
__wsum delta;

if (skb->remcsum_offload)
return vh;
Expand All @@ -580,12 +579,7 @@ static struct vxlanhdr *vxlan_gro_remcsum(struct sk_buff *skb,
return NULL;
}

delta = remcsum_adjust((void *)vh + hdrlen,
NAPI_GRO_CB(skb)->csum, start, offset);

/* Adjust skb->csum since we changed the packet */
skb->csum = csum_add(skb->csum, delta);
NAPI_GRO_CB(skb)->csum = csum_add(NAPI_GRO_CB(skb)->csum, delta);
skb_gro_remcsum_process(skb, (void *)vh + hdrlen, start, offset);

skb->remcsum_offload = 1;

Expand Down Expand Up @@ -1159,7 +1153,6 @@ static struct vxlanhdr *vxlan_remcsum(struct sk_buff *skb, struct vxlanhdr *vh,
size_t hdrlen, u32 data)
{
size_t start, offset, plen;
__wsum delta;

if (skb->remcsum_offload) {
/* Already processed in GRO path */
Expand All @@ -1179,14 +1172,7 @@ static struct vxlanhdr *vxlan_remcsum(struct sk_buff *skb, struct vxlanhdr *vh,

vh = (struct vxlanhdr *)(udp_hdr(skb) + 1);

if (unlikely(skb->ip_summed != CHECKSUM_COMPLETE))
__skb_checksum_complete(skb);

delta = remcsum_adjust((void *)vh + hdrlen,
skb->csum, start, offset);

/* Adjust skb->csum since we changed the packet */
skb->csum = csum_add(skb->csum, delta);
skb_remcsum_process(skb, (void *)vh + hdrlen, start, offset);

return vh;
}
Expand Down
15 changes: 15 additions & 0 deletions include/linux/netdevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -2318,6 +2318,21 @@ do { \
compute_pseudo(skb, proto)); \
} while (0)

static inline void skb_gro_remcsum_process(struct sk_buff *skb, void *ptr,
int start, int offset)
{
__wsum delta;

BUG_ON(!NAPI_GRO_CB(skb)->csum_valid);

delta = remcsum_adjust(ptr, NAPI_GRO_CB(skb)->csum, start, offset);

/* Adjust skb->csum since we changed the packet */
skb->csum = csum_add(skb->csum, delta);
NAPI_GRO_CB(skb)->csum = csum_add(NAPI_GRO_CB(skb)->csum, delta);
}


static inline int dev_hard_header(struct sk_buff *skb, struct net_device *dev,
unsigned short type,
const void *daddr, const void *saddr,
Expand Down
21 changes: 21 additions & 0 deletions include/linux/skbuff.h
Original file line number Diff line number Diff line change
Expand Up @@ -3099,6 +3099,27 @@ do { \
compute_pseudo(skb, proto)); \
} while (0)

/* Update skbuf and packet to reflect the remote checksum offload operation.
* When called, ptr indicates the starting point for skb->csum when
* ip_summed is CHECKSUM_COMPLETE. If we need create checksum complete
* here, skb_postpull_rcsum is done so skb->csum start is ptr.
*/
static inline void skb_remcsum_process(struct sk_buff *skb, void *ptr,
int start, int offset)
{
__wsum delta;

if (unlikely(skb->ip_summed != CHECKSUM_COMPLETE)) {
__skb_checksum_complete(skb);
skb_postpull_rcsum(skb, skb->data, ptr - (void *)skb->data);
}

delta = remcsum_adjust(ptr, skb->csum, start, offset);

/* Adjust skb->csum since we changed the packet */
skb->csum = csum_add(skb->csum, delta);
}

#if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE)
void nf_conntrack_destroy(struct nf_conntrack *nfct);
static inline void nf_conntrack_put(struct nf_conntrack *nfct)
Expand Down
18 changes: 2 additions & 16 deletions net/ipv4/fou.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ static struct guehdr *gue_remcsum(struct sk_buff *skb, struct guehdr *guehdr,
size_t start = ntohs(pd[0]);
size_t offset = ntohs(pd[1]);
size_t plen = hdrlen + max_t(size_t, offset + sizeof(u16), start);
__wsum delta;

if (skb->remcsum_offload) {
/* Already processed in GRO path */
Expand All @@ -82,14 +81,7 @@ static struct guehdr *gue_remcsum(struct sk_buff *skb, struct guehdr *guehdr,
return NULL;
guehdr = (struct guehdr *)&udp_hdr(skb)[1];

if (unlikely(skb->ip_summed != CHECKSUM_COMPLETE))
__skb_checksum_complete(skb);

delta = remcsum_adjust((void *)guehdr + hdrlen,
skb->csum, start, offset);

/* Adjust skb->csum since we changed the packet */
skb->csum = csum_add(skb->csum, delta);
skb_remcsum_process(skb, (void *)guehdr + hdrlen, start, offset);

return guehdr;
}
Expand Down Expand Up @@ -228,7 +220,6 @@ static struct guehdr *gue_gro_remcsum(struct sk_buff *skb, unsigned int off,
size_t start = ntohs(pd[0]);
size_t offset = ntohs(pd[1]);
size_t plen = hdrlen + max_t(size_t, offset + sizeof(u16), start);
__wsum delta;

if (skb->remcsum_offload)
return guehdr;
Expand All @@ -243,12 +234,7 @@ static struct guehdr *gue_gro_remcsum(struct sk_buff *skb, unsigned int off,
return NULL;
}

delta = remcsum_adjust((void *)guehdr + hdrlen,
NAPI_GRO_CB(skb)->csum, start, offset);

/* Adjust skb->csum since we changed the packet */
skb->csum = csum_add(skb->csum, delta);
NAPI_GRO_CB(skb)->csum = csum_add(NAPI_GRO_CB(skb)->csum, delta);
skb_gro_remcsum_process(skb, (void *)guehdr + hdrlen, start, offset);

skb->remcsum_offload = 1;

Expand Down

0 comments on commit dcdc899

Please sign in to comment.