-
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.
Nikita V. Shirokov says: ==================== In this patch series I'm adding a helper for libbpf which would allow it to load map-in-map(BPF_MAP_TYPE_ARRAY_OF_MAPS and BPF_MAP_TYPE_HASH_OF_MAPS). First patch contains new helper + explains proposed workflow second patch contains tests which also could be used as example usage. v4->v5: - naming: renamed everything to map_in_map instead of mapinmap - start to return nonzero val if set_inner_map_fd failed v3->v4: - renamed helper to set_inner_map_fd - now we set this value only if it haven't been set before and only for (array|hash) of maps v2->v3: - fixing typo in patch description - initializing inner_map_fd to -1 by default v1->v2: - addressing nits - removing const identifier from fd in new helper - starting to check return val for bpf_map_update_elem ==================== Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
- Loading branch information
Showing
5 changed files
with
177 additions
and
7 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
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,49 @@ | ||
// SPDX-License-Identifier: GPL-2.0 | ||
/* Copyright (c) 2018 Facebook */ | ||
#include <stddef.h> | ||
#include <linux/bpf.h> | ||
#include <linux/types.h> | ||
#include "bpf_helpers.h" | ||
|
||
struct bpf_map_def SEC("maps") mim_array = { | ||
.type = BPF_MAP_TYPE_ARRAY_OF_MAPS, | ||
.key_size = sizeof(int), | ||
/* must be sizeof(__u32) for map in map */ | ||
.value_size = sizeof(__u32), | ||
.max_entries = 1, | ||
.map_flags = 0, | ||
}; | ||
|
||
struct bpf_map_def SEC("maps") mim_hash = { | ||
.type = BPF_MAP_TYPE_HASH_OF_MAPS, | ||
.key_size = sizeof(int), | ||
/* must be sizeof(__u32) for map in map */ | ||
.value_size = sizeof(__u32), | ||
.max_entries = 1, | ||
.map_flags = 0, | ||
}; | ||
|
||
SEC("xdp_mimtest") | ||
int xdp_mimtest0(struct xdp_md *ctx) | ||
{ | ||
int value = 123; | ||
int key = 0; | ||
void *map; | ||
|
||
map = bpf_map_lookup_elem(&mim_array, &key); | ||
if (!map) | ||
return XDP_DROP; | ||
|
||
bpf_map_update_elem(map, &key, &value, 0); | ||
|
||
map = bpf_map_lookup_elem(&mim_hash, &key); | ||
if (!map) | ||
return XDP_DROP; | ||
|
||
bpf_map_update_elem(map, &key, &value, 0); | ||
|
||
return XDP_PASS; | ||
} | ||
|
||
int _version SEC("version") = 1; | ||
char _license[] SEC("license") = "GPL"; |
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