History

bpf: fix bpf helpers to use skb->mac_header relative offsets

For the short-term solution, lets fix bpf helper functions to use skb->mac_header relative offsets instead of skb->data in order to get the same eBPF programs with cls_bpf and act_bpf work on ingress and egress qdisc path. We need to ensure that mac_header is set before calling into programs. This is effectively the first option from below referenced discussion. More long term solution for LD_ABS|LD_IND instructions will be more intrusive but also more beneficial than this, and implemented later as it's too risky at this point in time. I.e., we plan to look into the option of moving skb_pull() out of eth_type_trans() and into netif_receive_skb() as has been suggested as second option. Meanwhile, this solution ensures ingress can be used with eBPF, too, and that we won't run into ABI troubles later. For dealing with negative offsets inside eBPF helper functions, we've implemented bpf_skb_clone_unwritable() to test for unwriteable headers.

Alexei Starovoitov committed 11 years ago

Commit a1661511 parent 51b5df86 files · +50 −22Browse files

Showing the changes to include/uapi/linux (2 of 6 files). Show all

Unified · Split

2 files
  1. include/uapi/linux/bpf.h +1 −1
  2. include/uapi/linux/filter.h +5 −2
include/uapi/linux/bpf.h+1−1
@@ -177,7 +177,7 @@ enum bpf_func_id { · 176 unmodified lines
177177 /**
178178 * skb_store_bytes(skb, offset, from, len, flags) - store bytes into packet
179179 * @skb: pointer to skb
180− * @offset: offset within packet from skb->data
180+ * @offset: offset within packet from skb->mac_header
181181 * @from: pointer where to copy bytes from
182182 * @len: number of bytes to store into packet
183183 * @flags: bit 0 - if true, recompute skb->csum
include/uapi/linux/filter.h+5−2
@@ -79,8 +79,11 @@ struct sock_fprog { /* Required for SO_ATTACH_FILTER. */ · 78 unmodified lines
7979 #define SKF_AD_RANDOM 56
8080 #define SKF_AD_VLAN_TPID 60
8181 #define SKF_AD_MAX 64
82−#define SKF_NET_OFF (-0x100000)
83−#define SKF_LL_OFF (-0x200000)
8482
83+#define SKF_NET_OFF (-0x100000)
84+#define SKF_LL_OFF (-0x200000)
85+
86+#define BPF_NET_OFF SKF_NET_OFF
87+#define BPF_LL_OFF SKF_LL_OFF
8588
8689 #endif /* _UAPI__LINUX_FILTER_H__ */