History

bpf: also call skb_postpush_rcsum on xmit occasions

Follow-up to commit f8ffad69c9f8 ("bpf: add skb_postpush_rcsum and fix dev_forward_skb occasions") to fix an issue for dev_queue_xmit() redirect locations which need CHECKSUM_COMPLETE fixups on ingress. For the same reasons as described in f8ffad69c9f8 already, we of course also need this here, since dev_queue_xmit() on a veth device will let us end up in the dev_forward_skb() helper again to cross namespaces. Latter then calls into skb_postpull_rcsum() to pull out L2 header, so that netif_rx_internal() sees CHECKSUM_COMPLETE as it is expected. That is, CHECKSUM_COMPLETE on ingress covering L2 _payload_, not L2 headers. Also here we have to address bpf_redirect() and bpf_clone_redirect().

Daniel Borkmann committed 10 years ago

Commit a2bfe6b1 parent 66cf3501 file · +10 −3Browse files

Unified · Split

net/core/filter.c+10−3
@@ -1365,6 +1365,12 @@ static inline int bpf_try_make_writable(struct sk_buff *skb, · 1364 unmodified lines
13651365 return err;
13661366 }
13671367
1368+static inline void bpf_push_mac_rcsum(struct sk_buff *skb)
1369+{
1370+ if (skb_at_tc_ingress(skb))
1371+ skb_postpush_rcsum(skb, skb_mac_header(skb), skb->mac_len);
1372+}
1373+
13681374 static u64 bpf_skb_store_bytes(u64 r1, u64 r2, u64 r3, u64 r4, u64 flags)
13691375 {
13701376 struct bpf_scratchpad *sp = this_cpu_ptr(&bpf_sp);
@@ -1607,9 +1613,6 @@ static const struct bpf_func_proto bpf_csum_diff_proto = { · 236 unmodified lines
16071613
16081614 static inline int __bpf_rx_skb(struct net_device *dev, struct sk_buff *skb)
16091615 {
1610− if (skb_at_tc_ingress(skb))
1611− skb_postpush_rcsum(skb, skb_mac_header(skb), skb->mac_len);
1612−
16131616 return dev_forward_skb(dev, skb);
16141617 }
16151618
@@ -1648,6 +1651,8 @@ static u64 bpf_clone_redirect(u64 r1, u64 ifindex, u64 flags, u64 r4, u64 r5) · 32 unmodified lines
16481651 if (unlikely(!skb))
16491652 return -ENOMEM;
16501653
1654+ bpf_push_mac_rcsum(skb);
1655+
16511656 return flags & BPF_F_INGRESS ?
16521657 __bpf_rx_skb(dev, skb) : __bpf_tx_skb(dev, skb);
16531658 }
@@ -1693,6 +1698,8 @@ int skb_do_redirect(struct sk_buff *skb) · 39 unmodified lines
16931698 return -EINVAL;
16941699 }
16951700
1701+ bpf_push_mac_rcsum(skb);
1702+
16961703 return ri->flags & BPF_F_INGRESS ?
16971704 __bpf_rx_skb(dev, skb) : __bpf_tx_skb(dev, skb);
16981705 }