Skip to content

Commit ea3acd7

Browse files
committed
datapath: Use skb_postpush_rcsum()
Use kernel function to update checksum. Signed-off-by: Pravin B Shelar <pshelar@ovn.org> Acked-by: Jesse Gross <jesse@kernel.org>
1 parent a5d59bf commit ea3acd7

5 files changed

Lines changed: 25 additions & 13 deletions

File tree

acinclude.m4

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,7 @@ AC_DEFUN([OVS_CHECK_LINUX_COMPAT], [
556556
OVS_GREP_IFELSE([$KSRC/include/linux/skbuff.h], [skb_vlan_pop])
557557
OVS_GREP_IFELSE([$KSRC/include/linux/skbuff.h], [skb_vlan_push])
558558
OVS_GREP_IFELSE([$KSRC/include/linux/skbuff.h], [skb_clear_hash_if_not_l4])
559+
OVS_GREP_IFELSE([$KSRC/include/linux/skbuff.h], [skb_postpush_rcsum])
559560
560561
OVS_GREP_IFELSE([$KSRC/include/linux/types.h], [bool],
561562
[OVS_DEFINE([HAVE_BOOL_TYPE])])

datapath/actions.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,7 @@ static int push_mpls(struct sk_buff *skb, struct sw_flow_key *key,
160160
new_mpls_lse = (__be32 *)skb_mpls_header(skb);
161161
*new_mpls_lse = mpls->mpls_lse;
162162

163-
if (skb->ip_summed == CHECKSUM_COMPLETE)
164-
skb->csum = csum_add(skb->csum, csum_partial(new_mpls_lse,
165-
MPLS_HLEN, 0));
163+
skb_postpush_rcsum(skb, new_mpls_lse, MPLS_HLEN);
166164

167165
hdr = eth_hdr(skb);
168166
hdr->h_proto = mpls->mpls_ethertype;
@@ -281,7 +279,7 @@ static int set_eth_addr(struct sk_buff *skb, struct sw_flow_key *flow_key,
281279
ether_addr_copy_masked(eth_hdr(skb)->h_dest, key->eth_dst,
282280
mask->eth_dst);
283281

284-
ovs_skb_postpush_rcsum(skb, eth_hdr(skb), ETH_ALEN * 2);
282+
skb_postpush_rcsum(skb, eth_hdr(skb), ETH_ALEN * 2);
285283

286284
ether_addr_copy(flow_key->eth.src, eth_hdr(skb)->h_source);
287285
ether_addr_copy(flow_key->eth.dst, eth_hdr(skb)->h_dest);
@@ -641,7 +639,7 @@ static int ovs_vport_output(OVS_VPORT_OUTPUT_PARAMS)
641639
/* Reconstruct the MAC header. */
642640
skb_push(skb, data->l2_len);
643641
memcpy(skb->data, &data->l2_data, data->l2_len);
644-
ovs_skb_postpush_rcsum(skb, skb->data, data->l2_len);
642+
skb_postpush_rcsum(skb, skb->data, data->l2_len);
645643
skb_reset_mac_header(skb);
646644

647645
ovs_vport_send(vport, skb);

datapath/linux/compat/include/linux/skbuff.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,4 +348,24 @@ static inline void skb_clear_hash_if_not_l4(struct sk_buff *skb)
348348
skb_clear_hash(skb);
349349
}
350350
#endif
351+
352+
#ifndef HAVE_SKB_POSTPUSH_RCSUM
353+
static inline void skb_postpush_rcsum(struct sk_buff *skb,
354+
const void *start, unsigned int len)
355+
{
356+
/* For performing the reverse operation to skb_postpull_rcsum(),
357+
* we can instead of ...
358+
*
359+
* skb->csum = csum_add(skb->csum, csum_partial(start, len, 0));
360+
*
361+
* ... just use this equivalent version here to save a few
362+
* instructions. Feeding csum of 0 in csum_partial() and later
363+
* on adding skb->csum is equivalent to feed skb->csum in the
364+
* first place.
365+
*/
366+
if (skb->ip_summed == CHECKSUM_COMPLETE)
367+
skb->csum = csum_partial(start, len, skb->csum);
368+
}
369+
#endif
370+
351371
#endif

datapath/vport-netdev.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ void netdev_port_receive(struct sk_buff *skb, struct ip_tunnel_info *tun_info)
5959
return;
6060

6161
skb_push(skb, ETH_HLEN);
62-
ovs_skb_postpush_rcsum(skb, skb->data, ETH_HLEN);
62+
skb_postpush_rcsum(skb, skb->data, ETH_HLEN);
6363
ovs_vport_receive(vport, skb, tun_info);
6464
return;
6565
error:

datapath/vport.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -187,13 +187,6 @@ static inline struct vport *vport_from_priv(void *priv)
187187
int ovs_vport_receive(struct vport *, struct sk_buff *,
188188
const struct ip_tunnel_info *);
189189

190-
static inline void ovs_skb_postpush_rcsum(struct sk_buff *skb,
191-
const void *start, unsigned int len)
192-
{
193-
if (skb->ip_summed == CHECKSUM_COMPLETE)
194-
skb->csum = csum_add(skb->csum, csum_partial(start, len, 0));
195-
}
196-
197190
static inline const char *ovs_vport_name(struct vport *vport)
198191
{
199192
return vport->dev->name;

0 commit comments

Comments
 (0)