mirror of
https://github.com/torvalds/linux.git
synced 2026-03-08 05:44:45 +01:00
bpf: Handle BPF_EXIST and BPF_NOEXIST for LPM trie
Add the currently missing handling for the BPF_EXIST and BPF_NOEXIST
flags. These flags can be specified by users and are relevant since LPM
trie supports exact matches during update.
Fixes: b95a5c4db0 ("bpf: add a longest prefix match trie map implementation")
Reviewed-by: Toke Høiland-Jørgensen <toke@redhat.com>
Acked-by: Daniel Borkmann <daniel@iogearbox.net>
Signed-off-by: Hou Tao <houtao1@huawei.com>
Link: https://lore.kernel.org/r/20241206110622.1161752-4-houtao@huaweicloud.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
This commit is contained in:
parent
3d5611b4d7
commit
eae6a075e9
1 changed files with 20 additions and 3 deletions
|
|
@ -375,6 +375,10 @@ static long trie_update_elem(struct bpf_map *map,
|
|||
* simply assign the @new_node to that slot and be done.
|
||||
*/
|
||||
if (!node) {
|
||||
if (flags == BPF_EXIST) {
|
||||
ret = -ENOENT;
|
||||
goto out;
|
||||
}
|
||||
rcu_assign_pointer(*slot, new_node);
|
||||
goto out;
|
||||
}
|
||||
|
|
@ -383,18 +387,31 @@ static long trie_update_elem(struct bpf_map *map,
|
|||
* which already has the correct data array set.
|
||||
*/
|
||||
if (node->prefixlen == matchlen) {
|
||||
if (!(node->flags & LPM_TREE_NODE_FLAG_IM)) {
|
||||
if (flags == BPF_NOEXIST) {
|
||||
ret = -EEXIST;
|
||||
goto out;
|
||||
}
|
||||
trie->n_entries--;
|
||||
} else if (flags == BPF_EXIST) {
|
||||
ret = -ENOENT;
|
||||
goto out;
|
||||
}
|
||||
|
||||
new_node->child[0] = node->child[0];
|
||||
new_node->child[1] = node->child[1];
|
||||
|
||||
if (!(node->flags & LPM_TREE_NODE_FLAG_IM))
|
||||
trie->n_entries--;
|
||||
|
||||
rcu_assign_pointer(*slot, new_node);
|
||||
free_node = node;
|
||||
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (flags == BPF_EXIST) {
|
||||
ret = -ENOENT;
|
||||
goto out;
|
||||
}
|
||||
|
||||
/* If the new node matches the prefix completely, it must be inserted
|
||||
* as an ancestor. Simply insert it between @node and *@slot.
|
||||
*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue