-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
selftests/bpf: Add a test for bpf sk_storage_map iterator
Added one test for bpf sk_storage_map_iterator. $ ./test_progs -n 4 ... #4/22 bpf_sk_storage_map:OK ... Signed-off-by: Yonghong Song <yhs@fb.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://lore.kernel.org/bpf/20200723184122.591591-1-yhs@fb.com
- Loading branch information
Yonghong Song
authored and
Alexei Starovoitov
committed
Jul 26, 2020
1 parent
60dd49e
commit 3b1c420
Showing
2 changed files
with
106 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
tools/testing/selftests/bpf/progs/bpf_iter_bpf_sk_storage_map.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// SPDX-License-Identifier: GPL-2.0 | ||
/* Copyright (c) 2020 Facebook */ | ||
#include "bpf_iter.h" | ||
#include "bpf_tracing_net.h" | ||
#include <bpf/bpf_helpers.h> | ||
#include <bpf/bpf_tracing.h> | ||
|
||
char _license[] SEC("license") = "GPL"; | ||
|
||
struct { | ||
__uint(type, BPF_MAP_TYPE_SK_STORAGE); | ||
__uint(map_flags, BPF_F_NO_PREALLOC); | ||
__type(key, int); | ||
__type(value, int); | ||
} sk_stg_map SEC(".maps"); | ||
|
||
__u32 val_sum = 0; | ||
__u32 ipv6_sk_count = 0; | ||
|
||
SEC("iter/bpf_sk_storage_map") | ||
int dump_bpf_sk_storage_map(struct bpf_iter__bpf_sk_storage_map *ctx) | ||
{ | ||
struct sock *sk = ctx->sk; | ||
__u32 *val = ctx->value; | ||
|
||
if (sk == (void *)0 || val == (void *)0) | ||
return 0; | ||
|
||
if (sk->sk_family == AF_INET6) | ||
ipv6_sk_count++; | ||
|
||
val_sum += *val; | ||
return 0; | ||
} |