Lines Matching +full:key +full:- +full:code

1 .. SPDX-License-Identifier: GPL-2.0-only
9 - ``BPF_MAP_TYPE_DEVMAP`` was introduced in kernel version 4.14
10 - ``BPF_MAP_TYPE_DEVMAP_HASH`` was introduced in kernel version 5.4
14 ``BPF_MAP_TYPE_DEVMAP`` is backed by an array that uses the key as
16 is backed by a hash table that uses a key to lookup a reference to a net device.
17 The user provides either <``key``/ ``ifindex``> or <``key``/ ``struct bpf_devmap_val``>
21 - The key to a hash map doesn't have to be an ``ifindex``.
22 - While ``BPF_MAP_TYPE_DEVMAP_HASH`` allows for densely packing the net devices
23 it comes at the cost of a hash of the key when performing a look up.
25 The setup and packet enqueue/send code is shared between the two types of
31 ----------
34 .. code-block:: c
36 long bpf_redirect_map(struct bpf_map *map, u32 key, u64 flags)
38 Redirect the packet to the endpoint referenced by ``map`` at index ``key``.
42 The lower two bits of *flags* are used as the return code if the map lookup
53 - The key is ignored if BPF_F_BROADCAST is set.
54 - The broadcast feature can also be used to implement multicast forwarding:
64 .. code-block:: c
66 void *bpf_map_lookup_elem(struct bpf_map *map, const void *key)
72 ----------
80 .. code-block:: c
82 int bpf_map_update_elem(int fd, const void *key, const void *value, __u64 flags);
89 .. code-block:: c
100 - ``BPF_ANY``: Create a new element or update an existing element.
101 - ``BPF_NOEXIST``: Create a new element only if it did not exist.
102 - ``BPF_EXIST``: Update an existing element.
109 ``XDP_REDIRECT`` and before the buffer is added to the per-cpu queue. Examples
112 - ``tools/testing/selftests/bpf/prog_tests/xdp_devmap_attach.c``
113 - ``tools/testing/selftests/bpf/progs/test_xdp_with_devmap_helpers.c``
117 .. code-block:: c
120 int bpf_map_lookup_elem(int fd, const void *key, void *value);
127 .. code-block:: c
130 int bpf_map_delete_elem(int fd, const void *key);
140 ----------
142 The following code snippet shows how to declare a ``BPF_MAP_TYPE_DEVMAP``
145 .. code-block:: c
149 __type(key, __u32);
154 The following code snippet shows how to declare a ``BPF_MAP_TYPE_DEVMAP_HASH``
157 .. code-block:: c
161 __type(key, __u32);
170 The following code snippet shows a simple xdp_redirect_map program. This program
173 ingress ``ifindex`` as the ``key``.
175 .. code-block:: c
180 int index = ctx->ingress_ifindex;
185 The following code snippet shows a BPF program that is broadcasting packets to
188 .. code-block:: c
197 ----------
199 The following code snippet shows how to update a devmap called ``tx_port``.
201 .. code-block:: c
216 The following code snippet shows how to update a hash_devmap called ``forward_map``.
218 .. code-block:: c
236 - https://lwn.net/Articles/728146/
237 - https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git/commit/?id=6f9d451ab1a33728adb72…
238 - https://elixir.bootlin.com/linux/latest/source/net/core/filter.c#L4106