aboutsummaryrefslogtreecommitdiffstats
path: root/tools/testing/selftests/bpf/progs/getpeername4_prog.c
diff options
context:
space:
mode:
authorJordan Rife <[email protected]>2024-05-10 19:02:33 +0000
committerAlexei Starovoitov <[email protected]>2024-05-13 00:10:42 +0000
commitbc467e953e4fbafd94d04c355f875bf1adf438e2 (patch)
tree1c303bfb6d17fe713f8c0d371084c2e2fcf574b6 /tools/testing/selftests/bpf/progs/getpeername4_prog.c
parentsefltests/bpf: Expand sockaddr hook deny tests (diff)
downloadkernel-bc467e953e4fbafd94d04c355f875bf1adf438e2.tar.gz
kernel-bc467e953e4fbafd94d04c355f875bf1adf438e2.zip
selftests/bpf: Expand getsockname and getpeername tests
This expands coverage for getsockname and getpeername hooks to include getsockname4, getsockname6, getpeername4, and getpeername6. Signed-off-by: Jordan Rife <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]>
Diffstat (limited to 'tools/testing/selftests/bpf/progs/getpeername4_prog.c')
-rw-r--r--tools/testing/selftests/bpf/progs/getpeername4_prog.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/tools/testing/selftests/bpf/progs/getpeername4_prog.c b/tools/testing/selftests/bpf/progs/getpeername4_prog.c
new file mode 100644
index 000000000000..4c97208cd25d
--- /dev/null
+++ b/tools/testing/selftests/bpf/progs/getpeername4_prog.c
@@ -0,0 +1,24 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright (c) 2024 Google LLC */
+
+#include "vmlinux.h"
+
+#include <string.h>
+#include <bpf/bpf_helpers.h>
+#include <bpf/bpf_endian.h>
+#include <bpf/bpf_core_read.h>
+#include "bpf_kfuncs.h"
+
+#define REWRITE_ADDRESS_IP4 0xc0a801fe // 192.168.1.254
+#define REWRITE_ADDRESS_PORT4 4040
+
+SEC("cgroup/getpeername4")
+int getpeername_v4_prog(struct bpf_sock_addr *ctx)
+{
+ ctx->user_ip4 = bpf_htonl(REWRITE_ADDRESS_IP4);
+ ctx->user_port = bpf_htons(REWRITE_ADDRESS_PORT4);
+
+ return 1;
+}
+
+char _license[] SEC("license") = "GPL";