Commit 749f7df1 authored by David S. Miller's avatar David S. Miller

Merge branch 'bpf-next'

Daniel Borkmann says:

====================
BPF update

Fixes a csum issue on ingress. As mentioned previously, net-next
seems just fine imho. Later on, will follow up with couple of
replacements like ovs_skb_postpush_rcsum() etc.

Thanks!

v1 -> v2:
  - Added patch 1 with helper
  - Implemented Hannes' idea to just use csum_partial, thanks!
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents 4156afaf f8ffad69
......@@ -2805,6 +2805,23 @@ static inline void skb_postpull_rcsum(struct sk_buff *skb,
unsigned char *skb_pull_rcsum(struct sk_buff *skb, unsigned int len);
static inline void skb_postpush_rcsum(struct sk_buff *skb,
const void *start, unsigned int len)
{
/* For performing the reverse operation to skb_postpull_rcsum(),
* we can instead of ...
*
* skb->csum = csum_add(skb->csum, csum_partial(start, len, 0));
*
* ... just use this equivalent version here to save a few
* instructions. Feeding csum of 0 in csum_partial() and later
* on adding skb->csum is equivalent to feed skb->csum in the
* first place.
*/
if (skb->ip_summed == CHECKSUM_COMPLETE)
skb->csum = csum_partial(start, len, skb->csum);
}
/**
* pskb_trim_rcsum - trim received skb and update checksum
* @skb: buffer to trim
......
......@@ -407,6 +407,15 @@ bool tcf_destroy(struct tcf_proto *tp, bool force);
void tcf_destroy_chain(struct tcf_proto __rcu **fl);
int skb_do_redirect(struct sk_buff *);
static inline bool skb_at_tc_ingress(const struct sk_buff *skb)
{
#ifdef CONFIG_NET_CLS_ACT
return G_TC_AT(skb->tc_verd) & AT_INGRESS;
#else
return false;
#endif
}
/* Reset all TX qdiscs greater then index of a device. */
static inline void qdisc_reset_all_tx_gt(struct net_device *dev, unsigned int i)
{
......
......@@ -1368,8 +1368,9 @@ static u64 bpf_skb_store_bytes(u64 r1, u64 r2, u64 r3, u64 r4, u64 flags)
/* skb_store_bits cannot return -EFAULT here */
skb_store_bits(skb, offset, ptr, len);
if (BPF_RECOMPUTE_CSUM(flags) && skb->ip_summed == CHECKSUM_COMPLETE)
skb->csum = csum_add(skb->csum, csum_partial(ptr, len, 0));
if (BPF_RECOMPUTE_CSUM(flags))
skb_postpush_rcsum(skb, ptr, len);
return 0;
}
......@@ -1525,8 +1526,12 @@ static u64 bpf_clone_redirect(u64 r1, u64 ifindex, u64 flags, u64 r4, u64 r5)
if (unlikely(!skb2))
return -ENOMEM;
if (BPF_IS_REDIRECT_INGRESS(flags))
if (BPF_IS_REDIRECT_INGRESS(flags)) {
if (skb_at_tc_ingress(skb2))
skb_postpush_rcsum(skb2, skb_mac_header(skb2),
skb2->mac_len);
return dev_forward_skb(dev, skb2);
}
skb2->dev = dev;
skb_sender_cpu_clear(skb2);
......@@ -1569,8 +1574,12 @@ int skb_do_redirect(struct sk_buff *skb)
return -EINVAL;
}
if (BPF_IS_REDIRECT_INGRESS(ri->flags))
if (BPF_IS_REDIRECT_INGRESS(ri->flags)) {
if (skb_at_tc_ingress(skb))
skb_postpush_rcsum(skb, skb_mac_header(skb),
skb->mac_len);
return dev_forward_skb(dev, skb);
}
skb->dev = dev;
skb_sender_cpu_clear(skb);
......
......@@ -79,12 +79,8 @@ static int cls_bpf_classify(struct sk_buff *skb, const struct tcf_proto *tp,
struct tcf_result *res)
{
struct cls_bpf_head *head = rcu_dereference_bh(tp->root);
bool at_ingress = skb_at_tc_ingress(skb);
struct cls_bpf_prog *prog;
#ifdef CONFIG_NET_CLS_ACT
bool at_ingress = G_TC_AT(skb->tc_verd) & AT_INGRESS;
#else
bool at_ingress = false;
#endif
int ret = -1;
if (unlikely(!skb_mac_header_was_set(skb)))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment