summaryrefslogtreecommitdiff
path: root/net
diff options
context:
space:
mode:
authorDavid S. Miller <davem@davemloft.net>2016-12-08 14:25:14 -0500
committerDavid S. Miller <davem@davemloft.net>2016-12-08 14:25:14 -0500
commit293bfa9b48614137c1514bd091dff8e2a894dad7 (patch)
treee772f55d041956a3e07a487b48b42df8a0b830bf /net
parent8a03cf2cb7efe269913db079afb8c31f20bf0bef (diff)
parent12d8bb64e3f65f5287ff17c084d076a28daa8096 (diff)
downloadlwn-293bfa9b48614137c1514bd091dff8e2a894dad7.tar.gz
lwn-293bfa9b48614137c1514bd091dff8e2a894dad7.zip
Merge branch 'xdp-head-adjustment'
Martin KaFai Lau says: ==================== Allow head adjustment in XDP prog This series adds a helper to allow head adjusting in XDP prog. mlx4 driver has been modified to support this feature. An example is written to encapsulate a packet with an IPv4/v6 header and then XDP_TX it out. v4: 1. Remove XDP_QUERY_FEATURES command. Instead, check the prog->xdp_adjust_head bit inside the driver itself during XDP_SETUP_PROG in patch 1of4. Thanks for everybody's ideas. 2. Nit changes on sample code per Jesper v3: 1. Check if the driver supports head adjustment before setting the xdp_prog fd to the device in patch 1of4. 2. Remove the page alignment assumption on the data_hard_start. Instead, add data_hard_start to the struct xdp_buff and the driver has to fill it if it supports head adjustment. 3. Keep the wire MTU as before in mlx4 4. Set map0_byte_count to PAGE_SIZE in patch 3of4 v2: 1. Make a variable name change in bpf_xdp_adjust_head() in patch 1 2. Ensure no less than ETH_HLEN data in bpf_xdp_adjust_head() in patch 1 3. Some clarifications in commit log messages of patch 2 and 3 ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net')
-rw-r--r--net/core/filter.c28
1 files changed, 26 insertions, 2 deletions
diff --git a/net/core/filter.c b/net/core/filter.c
index b751202e12f8..b1461708a977 100644
--- a/net/core/filter.c
+++ b/net/core/filter.c
@@ -2234,7 +2234,28 @@ static const struct bpf_func_proto bpf_skb_change_head_proto = {
.arg3_type = ARG_ANYTHING,
};
-bool bpf_helper_changes_skb_data(void *func)
+BPF_CALL_2(bpf_xdp_adjust_head, struct xdp_buff *, xdp, int, offset)
+{
+ void *data = xdp->data + offset;
+
+ if (unlikely(data < xdp->data_hard_start ||
+ data > xdp->data_end - ETH_HLEN))
+ return -EINVAL;
+
+ xdp->data = data;
+
+ return 0;
+}
+
+static const struct bpf_func_proto bpf_xdp_adjust_head_proto = {
+ .func = bpf_xdp_adjust_head,
+ .gpl_only = false,
+ .ret_type = RET_INTEGER,
+ .arg1_type = ARG_PTR_TO_CTX,
+ .arg2_type = ARG_ANYTHING,
+};
+
+bool bpf_helper_changes_pkt_data(void *func)
{
if (func == bpf_skb_vlan_push ||
func == bpf_skb_vlan_pop ||
@@ -2244,7 +2265,8 @@ bool bpf_helper_changes_skb_data(void *func)
func == bpf_skb_change_tail ||
func == bpf_skb_pull_data ||
func == bpf_l3_csum_replace ||
- func == bpf_l4_csum_replace)
+ func == bpf_l4_csum_replace ||
+ func == bpf_xdp_adjust_head)
return true;
return false;
@@ -2670,6 +2692,8 @@ xdp_func_proto(enum bpf_func_id func_id)
return &bpf_xdp_event_output_proto;
case BPF_FUNC_get_smp_processor_id:
return &bpf_get_smp_processor_id_proto;
+ case BPF_FUNC_xdp_adjust_head:
+ return &bpf_xdp_adjust_head_proto;
default:
return sk_filter_func_proto(func_id);
}