summaryrefslogtreecommitdiffstats
path: root/tools/testing/selftests/bpf/progs/connect_force_port6.c
diff options
context:
space:
mode:
authorStanislav Fomichev <sdf@google.com>2021-01-27 15:28:51 -0800
committerDaniel Borkmann <daniel@iogearbox.net>2021-01-29 02:09:05 +0100
commit073f4ec124bb2c431d9e4136e7f583abfea7f290 (patch)
tree5392d91fff59bfcd2375a442c3729ee6e0952956 /tools/testing/selftests/bpf/progs/connect_force_port6.c
parent62476cc1bf24b34d9442c7ba76e5eb6bf242f911 (diff)
downloadlinux-stable-073f4ec124bb2c431d9e4136e7f583abfea7f290.tar.gz
linux-stable-073f4ec124bb2c431d9e4136e7f583abfea7f290.tar.bz2
linux-stable-073f4ec124bb2c431d9e4136e7f583abfea7f290.zip
bpf: Enable bpf_{g,s}etsockopt in BPF_CGROUP_INET{4,6}_GET{PEER,SOCK}NAME
Those hooks run as BPF_CGROUP_RUN_SA_PROG_LOCK and operate on a locked socket. Signed-off-by: Stanislav Fomichev <sdf@google.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Link: https://lore.kernel.org/bpf/20210127232853.3753823-3-sdf@google.com
Diffstat (limited to 'tools/testing/selftests/bpf/progs/connect_force_port6.c')
-rw-r--r--tools/testing/selftests/bpf/progs/connect_force_port6.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/tools/testing/selftests/bpf/progs/connect_force_port6.c b/tools/testing/selftests/bpf/progs/connect_force_port6.c
index c1a2b555e9ad..afc8f1c5a9d6 100644
--- a/tools/testing/selftests/bpf/progs/connect_force_port6.c
+++ b/tools/testing/selftests/bpf/progs/connect_force_port6.c
@@ -9,6 +9,8 @@
#include <bpf/bpf_helpers.h>
#include <bpf/bpf_endian.h>
+#include <bpf_sockopt_helpers.h>
+
char _license[] SEC("license") = "GPL";
int _version SEC("version") = 1;
@@ -63,6 +65,9 @@ int connect6(struct bpf_sock_addr *ctx)
SEC("cgroup/getsockname6")
int getsockname6(struct bpf_sock_addr *ctx)
{
+ if (!get_set_sk_priority(ctx))
+ return 1;
+
/* Expose local server as [fc00::1]:60000 to client. */
if (ctx->user_port == bpf_htons(60124)) {
ctx->user_ip6[0] = bpf_htonl(0xfc000000);
@@ -79,6 +84,9 @@ int getpeername6(struct bpf_sock_addr *ctx)
{
struct svc_addr *orig;
+ if (!get_set_sk_priority(ctx))
+ return 1;
+
/* Expose service [fc00::1]:60000 as peer instead of backend. */
if (ctx->user_port == bpf_htons(60124)) {
orig = bpf_sk_storage_get(&service_mapping, ctx->sk, 0, 0);