lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <160384964803.698509.11020605670605638967.stgit@localhost.localdomain>
Date:   Tue, 27 Oct 2020 18:47:28 -0700
From:   Alexander Duyck <alexander.duyck@...il.com>
To:     bpf@...r.kernel.org
Cc:     ast@...nel.org, daniel@...earbox.net, kafai@...com,
        john.fastabend@...il.com, kernel-team@...com,
        netdev@...r.kernel.org, edumazet@...gle.com, brakmo@...com,
        alexanderduyck@...com
Subject: [bpf-next PATCH 4/4] selftests/bpf: Migrate tcpbpf_user.c to use BPF
 skeleton

From: Alexander Duyck <alexanderduyck@...com>

Update tcpbpf_user.c to make use of the BPF skeleton. Doing this we can
simplify test_tcpbpf_user and reduce the overhead involved in setting up
the test.

Signed-off-by: Alexander Duyck <alexanderduyck@...com>
---
 .../testing/selftests/bpf/prog_tests/tcpbpf_user.c |   48 +++++++++-----------
 1 file changed, 21 insertions(+), 27 deletions(-)

diff --git a/tools/testing/selftests/bpf/prog_tests/tcpbpf_user.c b/tools/testing/selftests/bpf/prog_tests/tcpbpf_user.c
index 4e1190894e1e..7e92c37976ac 100644
--- a/tools/testing/selftests/bpf/prog_tests/tcpbpf_user.c
+++ b/tools/testing/selftests/bpf/prog_tests/tcpbpf_user.c
@@ -5,6 +5,7 @@
 
 #include "test_tcpbpf.h"
 #include "cgroup_helpers.h"
+#include "test_tcpbpf_kern.skel.h"
 
 #define LO_ADDR6 "::1"
 #define CG_NAME "/tcpbpf-user-test"
@@ -162,39 +163,32 @@ static void run_test(int map_fd, int sock_map_fd)
 
 void test_tcpbpf_user(void)
 {
-	const char *file = "test_tcpbpf_kern.o";
-	int prog_fd, map_fd, sock_map_fd;
-	struct bpf_object *obj;
+	struct test_tcpbpf_kern *skel;
+	int map_fd, sock_map_fd;
+	struct bpf_link *link;
 	int cg_fd = -1;
-	int rv;
-
-	cg_fd = cgroup_setup_and_join(CG_NAME);
-	if (CHECK_FAIL(cg_fd < 0))
-		goto err;
 
-	if (CHECK_FAIL(bpf_prog_load(file, BPF_PROG_TYPE_SOCK_OPS, &obj, &prog_fd))) {
-		fprintf(stderr, "FAILED: load_bpf_file failed for: %s\n", file);
-		goto err;
-	}
+	skel = test_tcpbpf_kern__open_and_load();
+	if (CHECK(!skel, "open and load skel", "failed"))
+		return;
 
-	rv = bpf_prog_attach(prog_fd, cg_fd, BPF_CGROUP_SOCK_OPS, 0);
-	if (CHECK_FAIL(rv)) {
-		fprintf(stderr, "FAILED: bpf_prog_attach: %d (%s)\n",
-		       errno, strerror(errno));
-		goto err;
-	}
+	cg_fd = test__join_cgroup(CG_NAME);
+	if (CHECK_FAIL(cg_fd < 0))
+		goto cleanup_skel;
 
-	map_fd = bpf_find_map(__func__, obj, "global_map");
-	if (CHECK_FAIL(map_fd < 0))
-		goto err;
+	map_fd = bpf_map__fd(skel->maps.global_map);
+	sock_map_fd = bpf_map__fd(skel->maps.sockopt_results);
 
-	sock_map_fd = bpf_find_map(__func__, obj, "sockopt_results");
-	if (CHECK_FAIL(sock_map_fd < 0))
-		goto err;
+	link = bpf_program__attach_cgroup(skel->progs.bpf_testcb, cg_fd);
+	if (CHECK(IS_ERR(link), "attach_cgroup(estab)", "err: %ld\n",
+		  PTR_ERR(link)))
+		goto cleanup_namespace;
 
 	run_test(map_fd, sock_map_fd);
-err:
-	bpf_prog_detach(cg_fd, BPF_CGROUP_SOCK_OPS);
+
+	bpf_link__destroy(link);
+cleanup_namespace:
 	close(cg_fd);
-	cleanup_cgroup_environment();
+cleanup_skel:
+	test_tcpbpf_kern__destroy(skel);
 }


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ