-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a test that exercises a basic sockmap / sockhash iteration. For
now we simply count the number of elements seen. Once sockmap update from iterators works we can extend this to perform a full copy. Signed-off-by: Lorenz Bauer <lmb@cloudflare.com> --- .../selftests/bpf/prog_tests/sockmap_basic.c | 89 +++++++++++++++++++ tools/testing/selftests/bpf/progs/bpf_iter.h | 9 ++ .../selftests/bpf/progs/bpf_iter_sockmap.c | 43 +++++++++ .../selftests/bpf/progs/bpf_iter_sockmap.h | 3 + 4 files changed, 144 insertions(+) create mode 100644 tools/testing/selftests/bpf/progs/bpf_iter_sockmap.c create mode 100644 tools/testing/selftests/bpf/progs/bpf_iter_sockmap.h
- Loading branch information
1 parent
f7bac72
commit 74636e2
Showing
4 changed files
with
144 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
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
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,43 @@ | ||
// SPDX-License-Identifier: GPL-2.0 | ||
/* Copyright (c) 2020 Cloudflare */ | ||
#include "bpf_iter.h" | ||
#include "bpf_tracing_net.h" | ||
#include "bpf_iter_sockmap.h" | ||
#include <bpf/bpf_helpers.h> | ||
#include <bpf/bpf_tracing.h> | ||
#include <errno.h> | ||
|
||
char _license[] SEC("license") = "GPL"; | ||
|
||
struct { | ||
__uint(type, BPF_MAP_TYPE_SOCKMAP); | ||
__uint(max_entries, SOCKMAP_MAX_ENTRIES); | ||
__type(key, __u32); | ||
__type(value, __u64); | ||
} sockmap SEC(".maps"); | ||
|
||
struct { | ||
__uint(type, BPF_MAP_TYPE_SOCKHASH); | ||
__uint(max_entries, SOCKMAP_MAX_ENTRIES); | ||
__type(key, __u32); | ||
__type(value, __u64); | ||
} sockhash SEC(".maps"); | ||
|
||
__u32 elems = 0; | ||
__u32 socks = 0; | ||
|
||
SEC("iter/sockmap") | ||
int count_elems(struct bpf_iter__sockmap *ctx) | ||
{ | ||
struct sock *sk = ctx->sk; | ||
__u32 tmp, *key = ctx->key; | ||
int ret; | ||
|
||
if (key) | ||
elems++; | ||
|
||
if (sk) | ||
socks++; | ||
|
||
return 0; | ||
} |
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,3 @@ | ||
/* SPDX-License-Identifier: GPL-2.0 */ | ||
|
||
#define SOCKMAP_MAX_ENTRIES (64) |