Skip to content

Commit

Permalink
selftests/bpf: Verify bpf_get_netns_cookie in BPF_PROG_TYPE_CGROUP_SO…
Browse files Browse the repository at this point in the history
…CKOPT

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
  • Loading branch information
Stanislav Fomichev authored and Andrii Nakryiko committed Aug 14, 2021
1 parent f1248de commit 6a3a3dc
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions tools/testing/selftests/bpf/progs/sockopt_sk.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 6a3a3dc

Please sign in to comment.