osphinx.addnodesdocument)}( rawsourcechildren]( translations LanguagesNode)}(hhh](h pending_xref)}(hhh]docutils.nodesTextChinese (Simplified)}parenthsba attributes}(ids]classes]names]dupnames]backrefs] refdomainstdreftypedoc reftarget&/translations/zh_CN/bpf/map_sk_storagemodnameN classnameN refexplicitutagnamehhh ubh)}(hhh]hChinese (Traditional)}hh2sbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget&/translations/zh_TW/bpf/map_sk_storagemodnameN classnameN refexplicituh1hhh ubh)}(hhh]hItalian}hhFsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget&/translations/it_IT/bpf/map_sk_storagemodnameN classnameN refexplicituh1hhh ubh)}(hhh]hJapanese}hhZsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget&/translations/ja_JP/bpf/map_sk_storagemodnameN classnameN refexplicituh1hhh ubh)}(hhh]hKorean}hhnsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget&/translations/ko_KR/bpf/map_sk_storagemodnameN classnameN refexplicituh1hhh ubh)}(hhh]hPortuguese (Brazilian)}hhsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget&/translations/pt_BR/bpf/map_sk_storagemodnameN classnameN refexplicituh1hhh ubh)}(hhh]hSpanish}hhsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget&/translations/sp_SP/bpf/map_sk_storagemodnameN classnameN refexplicituh1hhh ubeh}(h]h ]h"]h$]h&]current_languageEnglishuh1h hh _documenthsourceNlineNubhcomment)}(h%SPDX-License-Identifier: GPL-2.0-onlyh]h%SPDX-License-Identifier: GPL-2.0-only}hhsbah}(h]h ]h"]h$]h&] xml:spacepreserveuh1hhhhhh@/var/lib/git/docbuild/linux/Documentation/bpf/map_sk_storage.rsthKubh)}(h Copyright (C) 2022 Red Hat, Inc.h]h Copyright (C) 2022 Red Hat, Inc.}hhsbah}(h]h ]h"]h$]h&]hhuh1hhhhhhhhKubhsection)}(hhh](htitle)}(hBPF_MAP_TYPE_SK_STORAGEh]hBPF_MAP_TYPE_SK_STORAGE}(hhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhhhhhKubhnote)}(hB- ``BPF_MAP_TYPE_SK_STORAGE`` was introduced in kernel version 5.2h]h bullet_list)}(hhh]h list_item)}(h@``BPF_MAP_TYPE_SK_STORAGE`` was introduced in kernel version 5.2h]h paragraph)}(hhh](hliteral)}(h``BPF_MAP_TYPE_SK_STORAGE``h]hBPF_MAP_TYPE_SK_STORAGE}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhhubh% was introduced in kernel version 5.2}(hhhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhK hhubah}(h]h ]h"]h$]h&]uh1hhhubah}(h]h ]h"]h$]h&]bullet-uh1hhhhK hhubah}(h]h ]h"]h$]h&]uh1hhhhhhNhNubh)}(hX``BPF_MAP_TYPE_SK_STORAGE`` is used to provide socket-local storage for BPF programs. A map of type ``BPF_MAP_TYPE_SK_STORAGE`` declares the type of storage to be provided and acts as the handle for accessing the socket-local storage. The values for maps of type ``BPF_MAP_TYPE_SK_STORAGE`` are stored locally with each socket instead of with the map. The kernel is responsible for allocating storage for a socket when requested and for freeing the storage when either the map or the socket is deleted.h](j)}(h``BPF_MAP_TYPE_SK_STORAGE``h]hBPF_MAP_TYPE_SK_STORAGE}(hj3hhhNhNubah}(h]h ]h"]h$]h&]uh1jhj/ubhI is used to provide socket-local storage for BPF programs. A map of type }(hj/hhhNhNubj)}(h``BPF_MAP_TYPE_SK_STORAGE``h]hBPF_MAP_TYPE_SK_STORAGE}(hjEhhhNhNubah}(h]h ]h"]h$]h&]uh1jhj/ubh declares the type of storage to be provided and acts as the handle for accessing the socket-local storage. The values for maps of type }(hj/hhhNhNubj)}(h``BPF_MAP_TYPE_SK_STORAGE``h]hBPF_MAP_TYPE_SK_STORAGE}(hjWhhhNhNubah}(h]h ]h"]h$]h&]uh1jhj/ubh are stored locally with each socket instead of with the map. The kernel is responsible for allocating storage for a socket when requested and for freeing the storage when either the map or the socket is deleted.}(hj/hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhK hhhhubh)}(h- The key type must be ``int`` and ``max_entries`` must be set to ``0``. - The ``BPF_F_NO_PREALLOC`` flag must be used when creating a map for socket-local storage.h]h)}(hhh](h)}(hFThe key type must be ``int`` and ``max_entries`` must be set to ``0``.h]h)}(hjxh](hThe key type must be }(hjzhhhNhNubj)}(h``int``h]hint}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjzubh and }(hjzhhhNhNubj)}(h``max_entries``h]h max_entries}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjzubh must be set to }(hjzhhhNhNubj)}(h``0``h]h0}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjzubh.}(hjzhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjvubah}(h]h ]h"]h$]h&]uh1hhjsubh)}(hYThe ``BPF_F_NO_PREALLOC`` flag must be used when creating a map for socket-local storage.h]h)}(hYThe ``BPF_F_NO_PREALLOC`` flag must be used when creating a map for socket-local storage.h](hThe }(hjhhhNhNubj)}(h``BPF_F_NO_PREALLOC``h]hBPF_F_NO_PREALLOC}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh@ flag must be used when creating a map for socket-local storage.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1hhjsubeh}(h]h ]h"]h$]h&]j'j(uh1hhhhKhjoubah}(h]h ]h"]h$]h&]uh1hhhhhhNhNubh)}(hhh](h)}(hUsageh]hUsage}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhKubh)}(hhh](h)}(h Kernel BPFh]h Kernel BPF}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj hhhhhKubh)}(hhh](h)}(hbpf_sk_storage_get()h]hbpf_sk_storage_get()}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhKubh literal_block)}(hOvoid *bpf_sk_storage_get(struct bpf_map *map, void *sk, void *value, u64 flags)h]hOvoid *bpf_sk_storage_get(struct bpf_map *map, void *sk, void *value, u64 flags)}hj.sbah}(h]h ]h"]h$]h&]hhƌforcelanguagechighlight_args}uh1j,hhhK!hjhhubh)}(hXSocket-local storage for ``map`` can be retrieved from socket ``sk`` using the ``bpf_sk_storage_get()`` helper. If the ``BPF_LOCAL_STORAGE_GET_F_CREATE`` flag is used then ``bpf_sk_storage_get()`` will create the storage for ``sk`` if it does not already exist. ``value`` can be used together with ``BPF_LOCAL_STORAGE_GET_F_CREATE`` to initialize the storage value, otherwise it will be zero initialized. Returns a pointer to the storage on success, or ``NULL`` in case of failure.h](hSocket-local storage for }(hjAhhhNhNubj)}(h``map``h]hmap}(hjIhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjAubh can be retrieved from socket }(hjAhhhNhNubj)}(h``sk``h]hsk}(hj[hhhNhNubah}(h]h ]h"]h$]h&]uh1jhjAubh using the }(hjAhhhNhNubj)}(h``bpf_sk_storage_get()``h]hbpf_sk_storage_get()}(hjmhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjAubh helper. If the }(hjAhhhNhNubj)}(h"``BPF_LOCAL_STORAGE_GET_F_CREATE``h]hBPF_LOCAL_STORAGE_GET_F_CREATE}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjAubh flag is used then }(hjAhhhNhNubj)}(h``bpf_sk_storage_get()``h]hbpf_sk_storage_get()}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjAubh will create the storage for }(hjAhhhNhNubj)}(h``sk``h]hsk}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjAubh if it does not already exist. }(hjAhhhNhNubj)}(h ``value``h]hvalue}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjAubh can be used together with }(hjAhhhNhNubj)}(h"``BPF_LOCAL_STORAGE_GET_F_CREATE``h]hBPF_LOCAL_STORAGE_GET_F_CREATE}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjAubhy to initialize the storage value, otherwise it will be zero initialized. Returns a pointer to the storage on success, or }(hjAhhhNhNubj)}(h``NULL``h]hNULL}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjAubh in case of failure.}(hjAhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhK%hjhhubh)}(h- ``sk`` is a kernel ``struct sock`` pointer for LSM or tracing programs. - ``sk`` is a ``struct bpf_sock`` pointer for other program types.h]h)}(hhh](h)}(hG``sk`` is a kernel ``struct sock`` pointer for LSM or tracing programs.h]h)}(hjh](j)}(h``sk``h]hsk}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh is a kernel }(hjhhhNhNubj)}(h``struct sock``h]h struct sock}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh% pointer for LSM or tracing programs.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhK.hjubah}(h]h ]h"]h$]h&]uh1hhjubh)}(h@``sk`` is a ``struct bpf_sock`` pointer for other program types.h]h)}(hj1h](j)}(h``sk``h]hsk}(hj6hhhNhNubah}(h]h ]h"]h$]h&]uh1jhj3ubh is a }(hj3hhhNhNubj)}(h``struct bpf_sock``h]hstruct bpf_sock}(hjHhhhNhNubah}(h]h ]h"]h$]h&]uh1jhj3ubh! pointer for other program types.}(hj3hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhK/hj/ubah}(h]h ]h"]h$]h&]uh1hhjubeh}(h]h ]h"]h$]h&]j'j(uh1hhhhK.hjubah}(h]h ]h"]h$]h&]uh1hhjhhhNhNubeh}(h]bpf-sk-storage-getah ]h"]bpf_sk_storage_get()ah$]h&]uh1hhj hhhhhKubh)}(hhh](h)}(hbpf_sk_storage_delete()h]hbpf_sk_storage_delete()}(hj}hhhNhNubah}(h]h ]h"]h$]h&]uh1hhjzhhhhhK2ubj-)}(h9long bpf_sk_storage_delete(struct bpf_map *map, void *sk)h]h9long bpf_sk_storage_delete(struct bpf_map *map, void *sk)}hjsbah}(h]h ]h"]h$]h&]hhj<j=j>j?}uh1j,hhhK4hjzhhubh)}(hSocket-local storage for ``map`` can be deleted from socket ``sk`` using the ``bpf_sk_storage_delete()`` helper. Returns ``0`` on success, or negative error in case of failure.h](hSocket-local storage for }(hjhhhNhNubj)}(h``map``h]hmap}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh can be deleted from socket }(hjhhhNhNubj)}(h``sk``h]hsk}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh using the }(hjhhhNhNubj)}(h``bpf_sk_storage_delete()``h]hbpf_sk_storage_delete()}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh helper. Returns }(hjhhhNhNubj)}(h``0``h]h0}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh2 on success, or negative error in case of failure.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhK8hjzhhubeh}(h]bpf-sk-storage-deleteah ]h"]bpf_sk_storage_delete()ah$]h&]uh1hhj hhhhhK2ubeh}(h] kernel-bpfah ]h"]h$] kernel bpfah&]uh1hhjhhhhhK referencedKubh)}(hhh](h)}(h User spaceh]h User space}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhK=ubh)}(hhh](h)}(hbpf_map_update_elem()h]hbpf_map_update_elem()}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhK@ubj-)}(hTint bpf_map_update_elem(int map_fd, const void *key, const void *value, __u64 flags)h]hTint bpf_map_update_elem(int map_fd, const void *key, const void *value, __u64 flags)}hj#sbah}(h]h ]h"]h$]h&]hhj<j=j>j?}uh1j,hhhKBhjhhubh)}(hXSocket-local storage for map ``map_fd`` can be added or updated locally to a socket using the ``bpf_map_update_elem()`` libbpf function. The socket is identified by a `socket` ``fd`` stored in the pointer ``key``. The pointer ``value`` has the data to be added or updated to the socket ``fd``. The type and size of ``value`` should be the same as the value type of the map definition.h](hSocket-local storage for map }(hj2hhhNhNubj)}(h ``map_fd``h]hmap_fd}(hj:hhhNhNubah}(h]h ]h"]h$]h&]uh1jhj2ubh7 can be added or updated locally to a socket using the }(hj2hhhNhNubj)}(h``bpf_map_update_elem()``h]hbpf_map_update_elem()}(hjLhhhNhNubah}(h]h ]h"]h$]h&]uh1jhj2ubh0 libbpf function. The socket is identified by a }(hj2hhhNhNubhtitle_reference)}(h`socket`h]hsocket}(hj`hhhNhNubah}(h]h ]h"]h$]h&]uh1j^hj2ubh }(hj2hhhNhNubj)}(h``fd``h]hfd}(hjrhhhNhNubah}(h]h ]h"]h$]h&]uh1jhj2ubh stored in the pointer }(hj2hhhNhNubj)}(h``key``h]hkey}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhj2ubh. The pointer }(hj2hhhNhNubj)}(h ``value``h]hvalue}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhj2ubh3 has the data to be added or updated to the socket }(hj2hhhNhNubj)}(h``fd``h]hfd}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhj2ubh. The type and size of }(hj2hhhNhNubj)}(h ``value``h]hvalue}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhj2ubh< should be the same as the value type of the map definition.}(hj2hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKFhjhhubh)}(hDThe ``flags`` parameter can be used to control the update behaviour:h](hThe }(hjhhhNhNubj)}(h ``flags``h]hflags}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh7 parameter can be used to control the update behaviour:}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKMhjhhubh)}(hhh](h)}(hO``BPF_ANY`` will create storage for `socket` ``fd`` or update existing storage.h]h)}(hjh](j)}(h ``BPF_ANY``h]hBPF_ANY}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh will create storage for }(hjhhhNhNubj_)}(h`socket`h]hsocket}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j^hjubh }(hjhhhNhNubj)}(h``fd``h]hfd}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh or update existing storage.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKOhjubah}(h]h ]h"]h$]h&]uh1hhjhhhhhNubh)}(h``BPF_NOEXIST`` will create storage for `socket` ``fd`` only if it did not already exist, otherwise the call will fail with ``-EEXIST``.h]h)}(h``BPF_NOEXIST`` will create storage for `socket` ``fd`` only if it did not already exist, otherwise the call will fail with ``-EEXIST``.h](j)}(h``BPF_NOEXIST``h]h BPF_NOEXIST}(hjFhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjBubh will create storage for }(hjBhhhNhNubj_)}(h`socket`h]hsocket}(hjXhhhNhNubah}(h]h ]h"]h$]h&]uh1j^hjBubh }(hjBhhhNhNubj)}(h``fd``h]hfd}(hjjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjBubhE only if it did not already exist, otherwise the call will fail with }(hjBhhhNhNubj)}(h ``-EEXIST``h]h-EEXIST}(hj|hhhNhNubah}(h]h ]h"]h$]h&]uh1jhjBubh.}(hjBhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKPhj>ubah}(h]h ]h"]h$]h&]uh1hhjhhhhhNubh)}(h``BPF_EXIST`` will update existing storage for `socket` ``fd`` if it already exists, otherwise the call will fail with ``-ENOENT``. h]h)}(h``BPF_EXIST`` will update existing storage for `socket` ``fd`` if it already exists, otherwise the call will fail with ``-ENOENT``.h](j)}(h ``BPF_EXIST``h]h BPF_EXIST}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh" will update existing storage for }(hjhhhNhNubj_)}(h`socket`h]hsocket}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j^hjubh }(hjhhhNhNubj)}(h``fd``h]hfd}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh9 if it already exists, otherwise the call will fail with }(hjhhhNhNubj)}(h ``-ENOENT``h]h-ENOENT}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKRhjubah}(h]h ]h"]h$]h&]uh1hhjhhhhhNubeh}(h]h ]h"]h$]h&]j'j(uh1hhhhKOhjhhubh)}(h?Returns ``0`` on success, or negative error in case of failure.h](hReturns }(hjhhhNhNubj)}(h``0``h]h0}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh2 on success, or negative error in case of failure.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKUhjhhubeh}(h]bpf-map-update-elemah ]h"]bpf_map_update_elem()ah$]h&]uh1hhjhhhhhK@ubh)}(hhh](h)}(hbpf_map_lookup_elem()h]hbpf_map_lookup_elem()}(hj'hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj$hhhhhKXubj-)}(hAint bpf_map_lookup_elem(int map_fd, const void *key, void *value)h]hAint bpf_map_lookup_elem(int map_fd, const void *key, void *value)}hj5sbah}(h]h ]h"]h$]h&]hhj<j=j>j?}uh1j,hhhKZhj$hhubh)}(hX#Socket-local storage for map ``map_fd`` can be retrieved from a socket using the ``bpf_map_lookup_elem()`` libbpf function. The storage is retrieved from the socket identified by a `socket` ``fd`` stored in the pointer ``key``. Returns ``0`` on success, or negative error in case of failure.h](hSocket-local storage for map }(hjDhhhNhNubj)}(h ``map_fd``h]hmap_fd}(hjLhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjDubh* can be retrieved from a socket using the }(hjDhhhNhNubj)}(h``bpf_map_lookup_elem()``h]hbpf_map_lookup_elem()}(hj^hhhNhNubah}(h]h ]h"]h$]h&]uh1jhjDubhK libbpf function. The storage is retrieved from the socket identified by a }(hjDhhhNhNubj_)}(h`socket`h]hsocket}(hjphhhNhNubah}(h]h ]h"]h$]h&]uh1j^hjDubh }(hjDhhhNhNubj)}(h``fd``h]hfd}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjDubh stored in the pointer }(hjDhhhNhNubj)}(h``key``h]hkey}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjDubh . Returns }(hjDhhhNhNubj)}(h``0``h]h0}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjDubh2 on success, or negative error in case of failure.}(hjDhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhK^hj$hhubeh}(h]bpf-map-lookup-elemah ]h"]bpf_map_lookup_elem()ah$]h&]uh1hhjhhhhhKXubh)}(hhh](h)}(hbpf_map_delete_elem()h]hbpf_map_delete_elem()}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhKdubj-)}(h4int bpf_map_delete_elem(int map_fd, const void *key)h]h4int bpf_map_delete_elem(int map_fd, const void *key)}hjsbah}(h]h ]h"]h$]h&]hhj<j=j>j?}uh1j,hhhKfhjhhubh)}(hXSocket-local storage for map ``map_fd`` can be deleted from a socket using the ``bpf_map_delete_elem()`` libbpf function. The storage is deleted from the socket identified by a `socket` ``fd`` stored in the pointer ``key``. Returns ``0`` on success, or negative error in case of failure.h](hSocket-local storage for map }(hjhhhNhNubj)}(h ``map_fd``h]hmap_fd}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh( can be deleted from a socket using the }(hjhhhNhNubj)}(h``bpf_map_delete_elem()``h]hbpf_map_delete_elem()}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubhI libbpf function. The storage is deleted from the socket identified by a }(hjhhhNhNubj_)}(h`socket`h]hsocket}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j^hjubh }(hjhhhNhNubj)}(h``fd``h]hfd}(hj$hhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh stored in the pointer }(hjhhhNhNubj)}(h``key``h]hkey}(hj6hhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh . Returns }(hjhhhNhNubj)}(h``0``h]h0}(hjHhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh2 on success, or negative error in case of failure.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKjhjhhubeh}(h]bpf-map-delete-elemah ]h"]bpf_map_delete_elem()ah$]h&]uh1hhjhhhhhKdubeh}(h] user-spaceah ]h"] user spaceah$]h&]uh1hhjhhhhhK=ubeh}(h]usageah ]h"]usageah$]h&]uh1hhhhhhhhKubh)}(hhh](h)}(hExamplesh]hExamples}(hj{hhhNhNubah}(h]h ]h"]h$]h&]uh1hhjxhhhhhKpubh)}(hhh](h)}(h Kernel BPFh]h Kernel BPF}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhKsubh)}(hHThis snippet shows how to declare socket-local storage in a BPF program:h]hHThis snippet shows how to declare socket-local storage in a BPF program:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKuhjhhubj-)}(hstruct { __uint(type, BPF_MAP_TYPE_SK_STORAGE); __uint(map_flags, BPF_F_NO_PREALLOC); __type(key, int); __type(value, struct my_storage); } socket_storage SEC(".maps");h]hstruct { __uint(type, BPF_MAP_TYPE_SK_STORAGE); __uint(map_flags, BPF_F_NO_PREALLOC); __type(key, int); __type(value, struct my_storage); } socket_storage SEC(".maps");}hjsbah}(h]h ]h"]h$]h&]hhj<j=j>j?}uh1j,hhhKwhjhhubh)}(hIThis snippet shows how to retrieve socket-local storage in a BPF program:h]hIThis snippet shows how to retrieve socket-local storage in a BPF program:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubj-)}(hXSEC("sockops") int _sockops(struct bpf_sock_ops *ctx) { struct my_storage *storage; struct bpf_sock *sk; sk = ctx->sk; if (!sk) return 1; storage = bpf_sk_storage_get(&socket_storage, sk, 0, BPF_LOCAL_STORAGE_GET_F_CREATE); if (!storage) return 1; /* Use 'storage' here */ return 1; }h]hXSEC("sockops") int _sockops(struct bpf_sock_ops *ctx) { struct my_storage *storage; struct bpf_sock *sk; sk = ctx->sk; if (!sk) return 1; storage = bpf_sk_storage_get(&socket_storage, sk, 0, BPF_LOCAL_STORAGE_GET_F_CREATE); if (!storage) return 1; /* Use 'storage' here */ return 1; }}hjsbah}(h]h ]h"]h$]h&]hhj<j=j>j?}uh1j,hhhKhjhhubh)}(hQPlease see the ``tools/testing/selftests/bpf`` directory for functional examples.h](hPlease see the }(hjhhhNhNubj)}(h``tools/testing/selftests/bpf``h]htools/testing/selftests/bpf}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh# directory for functional examples.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjhhubeh}(h]id1ah ]h"]h$]jah&]uh1hhjxhhhhhKsjKubeh}(h]examplesah ]h"]examplesah$]h&]uh1hhhhhhhhKpubh)}(hhh](h)}(h Referencesh]h References}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhKubh)}(h>https://lwn.net/ml/netdev/20190426171103.61892-1-kafai@fb.com/h]h reference)}(hjh]h>https://lwn.net/ml/netdev/20190426171103.61892-1-kafai@fb.com/}(hjhhhNhNubah}(h]h ]h"]h$]h&]refurijuh1jhjubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubeh}(h] referencesah ]h"] referencesah$]h&]uh1hhhhhhhhKubeh}(h]bpf-map-type-sk-storageah ]h"]bpf_map_type_sk_storageah$]h&]uh1hhhhhhhhKubeh}(h]h ]h"]h$]h&]sourcehuh1hcurrent_sourceN current_lineNsettingsdocutils.frontendValues)}(hN generatorN datestampN source_linkN source_urlN toc_backlinksentryfootnote_backlinksK sectnum_xformKstrip_commentsNstrip_elements_with_classesN strip_classesN report_levelK halt_levelKexit_status_levelKdebugNwarning_streamN tracebackinput_encoding utf-8-siginput_encoding_error_handlerstrictoutput_encodingutf-8output_encoding_error_handlerjaerror_encodingutf-8error_encoding_error_handlerbackslashreplace language_codeenrecord_dependenciesNconfigN id_prefixhauto_id_prefixid dump_settingsNdump_internalsNdump_transformsNdump_pseudo_xmlNexpose_internalsNstrict_visitorN_disable_configN_sourcehnj _destinationN _config_files]7/var/lib/git/docbuild/linux/Documentation/docutils.confafile_insertion_enabled raw_enabledKline_length_limitM'pep_referencesN pep_base_urlhttps://peps.python.org/pep_file_url_templatepep-%04drfc_referencesN rfc_base_url&https://datatracker.ietf.org/doc/html/ tab_widthKtrim_footnote_reference_spacesyntax_highlightlong smart_quotessmartquotes_locales]character_level_inline_markupdoctitle_xform docinfo_xformKsectsubtitle_xform image_loadinglinkembed_stylesheetcloak_email_addressessection_self_linkenvNubreporterNindirect_targets]substitution_defs}substitution_names}refnames}refids}nameids}(j;j8jujr kernel bpfNjwjtjjjmjjj!jjjjejbjjj3j0u nametypes}(j;jujjwjjmj!jjejj3uh}(j8hjrjjj jtjjjzjjjjjjj$jbjjjxjjj0ju footnote_refs} citation_refs} autofootnotes]autofootnote_refs]symbol_footnotes]symbol_footnote_refs] footnotes] citations]autofootnote_startKsymbol_footnote_startK id_counter collectionsCounter}joKsRparse_messages]hsystem_message)}(hhh]h)}(h-Duplicate implicit target name: "kernel bpf".h]h1Duplicate implicit target name: “kernel bpf”.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubah}(h]h ]h"]h$]h&]jalevelKtypeINFOsourcehnjlineKsuh1jhjhhhhhKsubatransform_messages] transformerN include_log] decorationNhhub.