From: John Fastabend <john.fastabend@gmail.com>
To: yhs@fb.com, andrii.nakryiko@gmail.com, ast@kernel.org,
daniel@iogearbox.net
Cc: netdev@vger.kernel.org, bpf@vger.kernel.org,
john.fastabend@gmail.com, jakub@cloudflare.com,
lmb@cloudflare.com
Subject: [bpf-next PATCH v4 5/5] bpf: selftests, test probe_* helpers from SCHED_CLS
Date: Thu, 21 May 2020 21:25:29 -0700 [thread overview]
Message-ID: <159012152966.14791.8918300114023263488.stgit@john-Precision-5820-Tower> (raw)
In-Reply-To: <159012108670.14791.18091717338621259928.stgit@john-Precision-5820-Tower>
Lets test using probe* in SCHED_CLS network programs as well just
to be sure these keep working. Its cheap to add the extra test
and provides a second context to test outside of sk_msg after
we generalized probe* helpers to all networking types.
Acked-by: Yonghong Song <yhs@fb.com>
Signed-off-by: John Fastabend <john.fastabend@gmail.com>
---
.../testing/selftests/bpf/prog_tests/skb_helpers.c | 30 ++++++++++++++++++
.../testing/selftests/bpf/progs/test_skb_helpers.c | 33 ++++++++++++++++++++
2 files changed, 63 insertions(+)
create mode 100644 tools/testing/selftests/bpf/prog_tests/skb_helpers.c
create mode 100644 tools/testing/selftests/bpf/progs/test_skb_helpers.c
diff --git a/tools/testing/selftests/bpf/prog_tests/skb_helpers.c b/tools/testing/selftests/bpf/prog_tests/skb_helpers.c
new file mode 100644
index 0000000..f302ad8
--- /dev/null
+++ b/tools/testing/selftests/bpf/prog_tests/skb_helpers.c
@@ -0,0 +1,30 @@
+// SPDX-License-Identifier: GPL-2.0
+#include <test_progs.h>
+#include <network_helpers.h>
+
+void test_skb_helpers(void)
+{
+ struct __sk_buff skb = {
+ .wire_len = 100,
+ .gso_segs = 8,
+ .gso_size = 10,
+ };
+ struct bpf_prog_test_run_attr tattr = {
+ .data_in = &pkt_v4,
+ .data_size_in = sizeof(pkt_v4),
+ .ctx_in = &skb,
+ .ctx_size_in = sizeof(skb),
+ .ctx_out = &skb,
+ .ctx_size_out = sizeof(skb),
+ };
+ struct bpf_object *obj;
+ int err;
+
+ err = bpf_prog_load("./test_skb_helpers.o", BPF_PROG_TYPE_SCHED_CLS, &obj,
+ &tattr.prog_fd);
+ if (CHECK_ATTR(err, "load", "err %d errno %d\n", err, errno))
+ return;
+ err = bpf_prog_test_run_xattr(&tattr);
+ CHECK_ATTR(err, "len", "err %d errno %d\n", err, errno);
+ bpf_object__close(obj);
+}
diff --git a/tools/testing/selftests/bpf/progs/test_skb_helpers.c b/tools/testing/selftests/bpf/progs/test_skb_helpers.c
new file mode 100644
index 0000000..54c0993
--- /dev/null
+++ b/tools/testing/selftests/bpf/progs/test_skb_helpers.c
@@ -0,0 +1,33 @@
+// SPDX-License-Identifier: GPL-2.0-only
+#include "vmlinux.h"
+#include <bpf/bpf_helpers.h>
+#include <bpf/bpf_endian.h>
+
+#define TEST_COMM_LEN 16
+
+struct {
+ __uint(type, BPF_MAP_TYPE_CGROUP_ARRAY);
+ __uint(max_entries, 1);
+ __type(key, u32);
+ __type(value, u32);
+} cgroup_map SEC(".maps");
+
+char _license[] SEC("license") = "GPL";
+
+SEC("classifier/test_skb_helpers")
+int test_skb_helpers(struct __sk_buff *skb)
+{
+ struct task_struct *task;
+ char comm[TEST_COMM_LEN];
+ int ctask, ret = 0;
+ __u32 tpid;
+
+ ctask = bpf_current_task_under_cgroup(&cgroup_map, 0);
+ if (ctask)
+ ret = 1;
+ task = (struct task_struct *)bpf_get_current_task();
+
+ bpf_probe_read_kernel(&tpid , sizeof(tpid), &task->tgid);
+ bpf_probe_read_kernel_str(&comm, sizeof(comm), &task->comm);
+ return ret;
+}
prev parent reply other threads:[~2020-05-22 4:25 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-22 4:23 [bpf-next PATCH v4 0/5] bpf: Add sk_msg and networking helpers John Fastabend
2020-05-22 4:24 ` [bpf-next PATCH v4 1/5] bpf: sk_msg add some generic helpers that may be useful from sk_msg John Fastabend
2020-05-22 4:24 ` [bpf-next PATCH v4 2/5] bpf: extend bpf_base_func_proto helpers with probe_* and *current_task* John Fastabend
2020-05-22 23:03 ` Daniel Borkmann
2020-05-23 16:29 ` John Fastabend
2020-05-22 4:24 ` [bpf-next PATCH v4 3/5] bpf: sk_msg add get socket storage helpers John Fastabend
2020-05-22 4:25 ` [bpf-next PATCH v4 4/5] bpf: selftests, add sk_msg helpers load and attach test John Fastabend
2020-05-22 9:20 ` Jakub Sitnicki
2020-05-22 4:25 ` John Fastabend [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=159012152966.14791.8918300114023263488.stgit@john-Precision-5820-Tower \
--to=john.fastabend@gmail.com \
--cc=andrii.nakryiko@gmail.com \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=jakub@cloudflare.com \
--cc=lmb@cloudflare.com \
--cc=netdev@vger.kernel.org \
--cc=yhs@fb.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).