Lines Matching +full:key +full:- +full:code
1 .. SPDX-License-Identifier: GPL-2.0-only
9 - ``BPF_MAP_TYPE_SK_STORAGE`` was introduced in kernel version 5.2
11 ``BPF_MAP_TYPE_SK_STORAGE`` is used to provide socket-local storage for BPF
13 to be provided and acts as the handle for accessing the socket-local
20 - The key type must be ``int`` and ``max_entries`` must be set to ``0``.
21 - The ``BPF_F_NO_PREALLOC`` flag must be used when creating a map for
22 socket-local storage.
28 ----------
33 .. code-block:: c
37 Socket-local storage for ``map`` can be retrieved from socket ``sk`` using the
46 - ``sk`` is a kernel ``struct sock`` pointer for LSM or tracing programs.
47 - ``sk`` is a ``struct bpf_sock`` pointer for other program types.
52 .. code-block:: c
56 Socket-local storage for ``map`` can be deleted from socket ``sk`` using the
61 ----------
66 .. code-block:: c
68 int bpf_map_update_elem(int map_fd, const void *key, const void *value, __u64 flags)
70 Socket-local storage for map ``map_fd`` can be added or updated locally to a
72 identified by a `socket` ``fd`` stored in the pointer ``key``. The pointer
79 - ``BPF_ANY`` will create storage for `socket` ``fd`` or update existing storage.
80 - ``BPF_NOEXIST`` will create storage for `socket` ``fd`` only if it did not
81 already exist, otherwise the call will fail with ``-EEXIST``.
82 - ``BPF_EXIST`` will update existing storage for `socket` ``fd`` if it already
83 exists, otherwise the call will fail with ``-ENOENT``.
90 .. code-block:: c
92 int bpf_map_lookup_elem(int map_fd, const void *key, void *value)
94 Socket-local storage for map ``map_fd`` can be retrieved from a socket using
97 ``key``. Returns ``0`` on success, or negative error in case of failure.
102 .. code-block:: c
104 int bpf_map_delete_elem(int map_fd, const void *key)
106 Socket-local storage for map ``map_fd`` can be deleted from a socket using the
108 socket identified by a `socket` ``fd`` stored in the pointer ``key``. Returns
115 ----------
117 This snippet shows how to declare socket-local storage in a BPF program:
119 .. code-block:: c
124 __type(key, int);
128 This snippet shows how to retrieve socket-local storage in a BPF program:
130 .. code-block:: c
138 sk = ctx->sk;
159 https://lwn.net/ml/netdev/20190426171103.61892-1-kafai@fb.com/