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

1 .. SPDX-License-Identifier: GPL-2.0-only
9 - ``BPF_MAP_TYPE_SOCKMAP`` was introduced in kernel version 4.14
10 - ``BPF_MAP_TYPE_SOCKHASH`` was introduced in kernel version 4.18
18 ``BPF_MAP_TYPE_SOCKMAP`` is backed by an array that uses an integer key as the
26 the map holds to user-space is neither safe nor useful.
44 .. code-block:: c
59 - ``msg_parser`` program - ``BPF_SK_MSG_VERDICT``.
60 - ``stream_parser`` program - ``BPF_SK_SKB_STREAM_PARSER``.
61 - ``stream_verdict`` program - ``BPF_SK_SKB_STREAM_VERDICT``.
62 - ``skb_verdict`` program - ``BPF_SK_SKB_VERDICT``.
82 ----------
85 .. code-block:: c
87 long bpf_msg_redirect_map(struct sk_msg_buff *msg, struct bpf_map *map, u32 key, u64 flags)
92 ``BPF_MAP_TYPE_SOCKMAP``) at index ``key``. Both ingress and egress interfaces
101 .. code-block:: c
103 long bpf_sk_redirect_map(struct sk_buff *skb, struct bpf_map *map, u32 key u64 flags)
106 ``BPF_MAP_TYPE_SOCKMAP``) at index ``key``. Both ingress and egress interfaces
115 .. code-block:: c
117 void *bpf_map_lookup_elem(struct bpf_map *map, const void *key)
124 .. code-block:: c
126 long bpf_sock_map_update(struct bpf_sock_ops *skops, struct bpf_map *map, void *key, u64 flags)
129 as a new value for the entry associated to ``key``. The ``flags`` argument can
132 - ``BPF_ANY``: Create a new element or update an existing element.
133 - ``BPF_NOEXIST``: Create a new element only if it did not exist.
134 - ``BPF_EXIST``: Update an existing element.
144 .. code-block:: c
146 long bpf_sock_hash_update(struct bpf_sock_ops *skops, struct bpf_map *map, void *key, u64 flags)
149 is used as a new value for the entry associated to ``key``.
153 - ``BPF_ANY``: Create a new element or update an existing element.
154 - ``BPF_NOEXIST``: Create a new element only if it did not exist.
155 - ``BPF_EXIST``: Update an existing element.
165 .. code-block:: c
167 long bpf_msg_redirect_hash(struct sk_msg_buff *msg, struct bpf_map *map, void *key, u64 flags)
172 ``BPF_MAP_TYPE_SOCKHASH``) using hash ``key``. Both ingress and egress
181 .. code-block:: c
183 long bpf_sk_redirect_hash(struct sk_buff *skb, struct bpf_map *map, void *key, u64 flags)
188 ``BPF_MAP_TYPE_SOCKHASH``) using hash ``key``. Both ingress and egress
197 .. code-block:: c
205 - A single ``sendmsg()`` or ``sendfile()`` system call contains multiple
208 - A BPF program only cares to read the first ``bytes`` of a ``msg``. If the
217 .. code-block:: c
232 .. code-block:: c
236 For socket policies, pull in non-linear data from user space for ``msg`` and set
237 pointers ``msg->data`` and ``msg->data_end`` to ``start`` and ``end`` bytes
264 .. code-block:: c
266 void *bpf_map_lookup_elem(struct bpf_map *map, const void *key)
270 Returns the socket entry associated to ``key``, or NULL if no entry was found.
274 .. code-block:: c
276 long bpf_map_update_elem(struct bpf_map *map, const void *key, const void *value, u64 flags)
282 - BPF_ANY: Create a new element or update an existing element.
283 - BPF_NOEXIST: Create a new element only if it did not exist.
284 - BPF_EXIST: Update an existing element.
290 .. code-block:: c
292 long bpf_map_delete_elem(struct bpf_map *map, const void *key)
299 ----------
302 .. code-block:: c
304 int bpf_map_update_elem(int fd, const void *key, const void *value, __u64 flags)
307 function. The ``key`` parameter is the index value of the sockmap array. And the
315 - BPF_ANY: Create a new element or update an existing element.
316 - BPF_NOEXIST: Create a new element only if it did not exist.
317 - BPF_EXIST: Update an existing element.
321 .. code-block:: c
323 int bpf_map_lookup_elem(int fd, const void *key, void *value)
332 .. code-block:: c
334 int bpf_map_delete_elem(int fd, const void *key)
345 ----------
348 - `tools/testing/selftests/bpf/progs/test_sockmap_kern.h`_
349 - `tools/testing/selftests/bpf/progs/sockmap_parse_prog.c`_
350 - `tools/testing/selftests/bpf/progs/sockmap_verdict_prog.c`_
351 - `tools/testing/selftests/bpf/progs/test_sockmap_listen.c`_
352 - `tools/testing/selftests/bpf/progs/test_sockmap_update.c`_
354 The following code snippet shows how to declare a sockmap.
356 .. code-block:: c
361 __type(key, __u32);
365 The following code snippet shows a sample parser program.
367 .. code-block:: c
372 return skb->len;
375 The following code snippet shows a simple verdict program that interacts with a
378 .. code-block:: c
383 __u32 lport = skb->local_port;
392 The following code snippet shows how to declare a sockhash map.
394 .. code-block:: c
406 __type(key, struct socket_key);
410 The following code snippet shows a simple verdict program that interacts with a
414 .. code-block:: c
417 void extract_socket_key(struct __sk_buff *skb, struct socket_key *key)
419 key->src_ip = skb->remote_ip4;
420 key->dst_ip = skb->local_ip4;
421 key->src_port = skb->remote_port >> 16;
422 key->dst_port = (bpf_htonl(skb->local_port)) >> 16;
428 struct socket_key key;
430 extract_socket_key(skb, &key);
432 return bpf_sk_redirect_hash(skb, &sock_hash_rx, &key, 0);
436 ----------
439 - `tools/testing/selftests/bpf/prog_tests/sockmap_basic.c`_
440 - `tools/testing/selftests/bpf/test_sockmap.c`_
441 - `tools/testing/selftests/bpf/test_maps.c`_
443 The following code sample shows how to create a sockmap, attach a parser and
446 .. code-block:: c
456 return -1;
485 - https://github.com/jrfastab/linux-kernel-xdp/commit/c89fd73cb9d2d7f3c716c3e00836f07b1aeb261f
486 - https://lwn.net/Articles/731133/
487 - http://vger.kernel.org/lpc_net2018_talks/ktls_bpf_paper.pdf
488 - https://lwn.net/Articles/748628/
489 - https://lore.kernel.org/bpf/20200218171023.844439-7-jakub@cloudflare.com/