diff options
| author | Martin KaFai Lau <[email protected]> | 2017-03-22 17:00:35 +0000 |
|---|---|---|
| committer | David S. Miller <[email protected]> | 2017-03-22 22:45:45 +0000 |
| commit | fb30d4b71214aa1811e997f8f753b14b46d5b912 (patch) | |
| tree | a546eefbd355792aa544c0f220b38bab4493b1aa /samples/bpf/bpf_load.c | |
| parent | bpf: Add hash of maps support (diff) | |
| download | kernel-fb30d4b71214aa1811e997f8f753b14b46d5b912.tar.gz kernel-fb30d4b71214aa1811e997f8f753b14b46d5b912.zip | |
bpf: Add tests for map-in-map
Test cases for array of maps and hash of maps.
Signed-off-by: Martin KaFai Lau <[email protected]>
Acked-by: Alexei Starovoitov <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
Diffstat (limited to 'samples/bpf/bpf_load.c')
| -rw-r--r-- | samples/bpf/bpf_load.c | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/samples/bpf/bpf_load.c b/samples/bpf/bpf_load.c index b86ee54da2d1..dcdce1270d38 100644 --- a/samples/bpf/bpf_load.c +++ b/samples/bpf/bpf_load.c @@ -43,6 +43,7 @@ struct bpf_map_def { unsigned int value_size; unsigned int max_entries; unsigned int map_flags; + unsigned int inner_map_idx; }; static int populate_prog_array(const char *event, int prog_fd) @@ -198,11 +199,22 @@ static int load_maps(struct bpf_map_def *maps, int len) for (i = 0; i < len / sizeof(struct bpf_map_def); i++) { - map_fd[i] = bpf_create_map(maps[i].type, - maps[i].key_size, - maps[i].value_size, - maps[i].max_entries, - maps[i].map_flags); + if (maps[i].type == BPF_MAP_TYPE_ARRAY_OF_MAPS || + maps[i].type == BPF_MAP_TYPE_HASH_OF_MAPS) { + int inner_map_fd = map_fd[maps[i].inner_map_idx]; + + map_fd[i] = bpf_create_map_in_map(maps[i].type, + maps[i].key_size, + inner_map_fd, + maps[i].max_entries, + maps[i].map_flags); + } else { + map_fd[i] = bpf_create_map(maps[i].type, + maps[i].key_size, + maps[i].value_size, + maps[i].max_entries, + maps[i].map_flags); + } if (map_fd[i] < 0) { printf("failed to create a map: %d %s\n", errno, strerror(errno)); |
