linux/tools/testing/selftests/bpf/progs/bpf_iter_test_kern4.c
Yonghong Song 84544f5637 selftests/bpf: Move newer bpf_iter_* type redefining to a new header file
Commit b9f4c01f3e0b ("selftest/bpf: Make bpf_iter selftest
compilable against old vmlinux.h") and Commit dda18a5c0b75
("selftests/bpf: Convert bpf_iter_test_kern{3, 4}.c to define
own bpf_iter_meta") redefined newly introduced types
in bpf programs so the bpf program can still compile
properly with old kernels although loading may fail.

Since this patch set introduced new types and the same
workaround is needed, so let us move the workaround
to a separate header file so they do not clutter
bpf programs.

Signed-off-by: Yonghong Song <yhs@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Andrii Nakryiko <andriin@fb.com>
Acked-by: Martin KaFai Lau <kafai@fb.com>
Link: https://lore.kernel.org/bpf/20200623230816.3988656-1-yhs@fb.com
2020-06-24 18:37:59 -07:00

53 lines
1.1 KiB
C

// SPDX-License-Identifier: GPL-2.0
/* Copyright (c) 2020 Facebook */
#include "bpf_iter.h"
#include <bpf/bpf_helpers.h>
char _license[] SEC("license") = "GPL";
__u32 map1_id = 0, map2_id = 0;
__u32 map1_accessed = 0, map2_accessed = 0;
__u64 map1_seqnum = 0, map2_seqnum1 = 0, map2_seqnum2 = 0;
static volatile const __u32 print_len;
static volatile const __u32 ret1;
SEC("iter/bpf_map")
int dump_bpf_map(struct bpf_iter__bpf_map *ctx)
{
struct seq_file *seq = ctx->meta->seq;
struct bpf_map *map = ctx->map;
__u64 seq_num;
int i, ret = 0;
if (map == (void *)0)
return 0;
/* only dump map1_id and map2_id */
if (map->id != map1_id && map->id != map2_id)
return 0;
seq_num = ctx->meta->seq_num;
if (map->id == map1_id) {
map1_seqnum = seq_num;
map1_accessed++;
}
if (map->id == map2_id) {
if (map2_accessed == 0) {
map2_seqnum1 = seq_num;
if (ret1)
ret = 1;
} else {
map2_seqnum2 = seq_num;
}
map2_accessed++;
}
/* fill seq_file buffer */
for (i = 0; i < print_len; i++)
bpf_seq_write(seq, &seq_num, sizeof(seq_num));
return ret;
}