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.
Showing the changes to include/uapi/linux (2 of 6 files). Show all
Unified · Split
| @@ -177,7 +177,7 @@ enum bpf_func_id { · 176 unmodified lines | |||
| 177 | /** | 177 | /** |
| 178 | * skb_store_bytes(skb, offset, from, len, flags) - store bytes into packet | 178 | * skb_store_bytes(skb, offset, from, len, flags) - store bytes into packet |
| 179 | * @skb: pointer to skb | 179 | * @skb: pointer to skb |
| 180 | * @offset: offset within packet from skb->data | 180 | * @offset: offset within packet from skb->mac_header |
| 181 | * @from: pointer where to copy bytes from | 181 | * @from: pointer where to copy bytes from |
| 182 | * @len: number of bytes to store into packet | 182 | * @len: number of bytes to store into packet |
| 183 | * @flags: bit 0 - if true, recompute skb->csum | 183 | * @flags: bit 0 - if true, recompute skb->csum |
| @@ -79,8 +79,11 @@ struct sock_fprog { /* Required for SO_ATTACH_FILTER. */ · 78 unmodified lines | |||
| 79 | #define SKF_AD_RANDOM 56 | 79 | #define SKF_AD_RANDOM 56 |
| 80 | #define SKF_AD_VLAN_TPID 60 | 80 | #define SKF_AD_VLAN_TPID 60 |
| 81 | #define SKF_AD_MAX 64 | 81 | #define SKF_AD_MAX 64 |
| 82 | #define SKF_NET_OFF (-0x100000) | ||
| 83 | #define SKF_LL_OFF (-0x200000) | ||
| 84 | 82 | ||
| 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 | ||
| 85 | 88 | ||
| 86 | #endif /* _UAPI__LINUX_FILTER_H__ */ | 89 | #endif /* _UAPI__LINUX_FILTER_H__ */ |