[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20200123014210.38412-3-dsahern@kernel.org>
Date: Wed, 22 Jan 2020 18:42:00 -0700
From: David Ahern <dsahern@...nel.org>
To: netdev@...r.kernel.org
Cc: prashantbhole.linux@...il.com, jasowang@...hat.com,
davem@...emloft.net, jakub.kicinski@...ronome.com,
jbrouer@...hat.com, toke@...hat.com, mst@...hat.com,
toshiaki.makita1@...il.com, daniel@...earbox.net,
john.fastabend@...il.com, ast@...nel.org, kafai@...com,
songliubraving@...com, yhs@...com, andriin@...com,
dsahern@...il.com, David Ahern <dahern@...italocean.com>
Subject: [PATCH bpf-next 02/12] net: Add BPF_XDP_EGRESS as a bpf_attach_type
From: Prashant Bhole <prashantbhole.linux@...il.com>
Add new bpf_attach_type, BPF_XDP_EGRESS, for BPF programs attached
at the XDP layer, but the egress path.
Since egress path does not have rx_queue_index and ingress_ifindex set,
update xdp_is_valid_access to block access to these entries in the xdp
context when a program is attached to egress path.
Signed-off-by: Prashant Bhole <prashantbhole.linux@...il.com>
Signed-off-by: David Ahern <dahern@...italocean.com>
---
include/uapi/linux/bpf.h | 1 +
net/core/filter.c | 8 ++++++++
tools/include/uapi/linux/bpf.h | 1 +
3 files changed, 10 insertions(+)
diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h
index 033d90a2282d..72f2a9a4621e 100644
--- a/include/uapi/linux/bpf.h
+++ b/include/uapi/linux/bpf.h
@@ -209,6 +209,7 @@ enum bpf_attach_type {
BPF_TRACE_RAW_TP,
BPF_TRACE_FENTRY,
BPF_TRACE_FEXIT,
+ BPF_XDP_EGRESS,
__MAX_BPF_ATTACH_TYPE
};
diff --git a/net/core/filter.c b/net/core/filter.c
index 17de6747d9e3..a903f3a15d74 100644
--- a/net/core/filter.c
+++ b/net/core/filter.c
@@ -6803,6 +6803,14 @@ static bool xdp_is_valid_access(int off, int size,
return false;
}
+ if (prog->expected_attach_type == BPF_XDP_EGRESS) {
+ switch (off) {
+ case offsetof(struct xdp_md, rx_queue_index):
+ case offsetof(struct xdp_md, ingress_ifindex):
+ return false;
+ }
+ }
+
switch (off) {
case offsetof(struct xdp_md, data):
info->reg_type = PTR_TO_PACKET;
diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h
index 033d90a2282d..72f2a9a4621e 100644
--- a/tools/include/uapi/linux/bpf.h
+++ b/tools/include/uapi/linux/bpf.h
@@ -209,6 +209,7 @@ enum bpf_attach_type {
BPF_TRACE_RAW_TP,
BPF_TRACE_FENTRY,
BPF_TRACE_FEXIT,
+ BPF_XDP_EGRESS,
__MAX_BPF_ATTACH_TYPE
};
--
2.21.1 (Apple Git-122.3)
Powered by blists - more mailing lists