selftests/bpf: Verify bpf_get_netns_cookie in BPF_PROG_TYPE_CGROUP_SOCKOPT
authorStanislav Fomichev <sdf@google.com>
Fri, 13 Aug 2021 23:05:30 +0000 (16:05 -0700)
committerAndrii Nakryiko <andrii@kernel.org>
Sat, 14 Aug 2021 00:51:25 +0000 (17:51 -0700)
Add extra calls to sockopt_sk.c.

Signed-off-by: Stanislav Fomichev <sdf@google.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Acked-by: Martin KaFai Lau <kafai@fb.com>
Link: https://lore.kernel.org/bpf/20210813230530.333779-3-sdf@google.com
tools/testing/selftests/bpf/progs/sockopt_sk.c

index 8acdb99..79c8139 100644 (file)
@@ -33,6 +33,14 @@ int _getsockopt(struct bpf_sockopt *ctx)
        __u8 *optval = ctx->optval;
        struct sockopt_sk *storage;
 
+       /* Make sure bpf_get_netns_cookie is callable.
+        */
+       if (bpf_get_netns_cookie(NULL) == 0)
+               return 0;
+
+       if (bpf_get_netns_cookie(ctx) == 0)
+               return 0;
+
        if (ctx->level == SOL_IP && ctx->optname == IP_TOS) {
                /* Not interested in SOL_IP:IP_TOS;
                 * let next BPF program in the cgroup chain or kernel
@@ -123,6 +131,14 @@ int _setsockopt(struct bpf_sockopt *ctx)
        __u8 *optval = ctx->optval;
        struct sockopt_sk *storage;
 
+       /* Make sure bpf_get_netns_cookie is callable.
+        */
+       if (bpf_get_netns_cookie(NULL) == 0)
+               return 0;
+
+       if (bpf_get_netns_cookie(ctx) == 0)
+               return 0;
+
        if (ctx->level == SOL_IP && ctx->optname == IP_TOS) {
                /* Not interested in SOL_IP:IP_TOS;
                 * let next BPF program in the cgroup chain or kernel