lsphinx.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]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}(hhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhubh% 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](h)}(h``BPF_MAP_TYPE_SK_STORAGE``h]hBPF_MAP_TYPE_SK_STORAGE}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubhI is used to provide socket-local storage for BPF programs. A map of type }(hjhhhNhNubh)}(h``BPF_MAP_TYPE_SK_STORAGE``h]hBPF_MAP_TYPE_SK_STORAGE}(hj1hhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh 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 }(hjhhhNhNubh)}(h``BPF_MAP_TYPE_SK_STORAGE``h]hBPF_MAP_TYPE_SK_STORAGE}(hjChhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh 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.}(hjhhhNhNubeh}(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)}(hjdh](hThe key type must be }(hjfhhhNhNubh)}(h``int``h]hint}(hjmhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjfubh and }(hjfhhhNhNubh)}(h``max_entries``h]h max_entries}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjfubh must be set to }(hjfhhhNhNubh)}(h``0``h]h0}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjfubh.}(hjfhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjbubah}(h]h ]h"]h$]h&]uh1hhj_ubh)}(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 }(hjhhhNhNubh)}(h``BPF_F_NO_PREALLOC``h]hBPF_F_NO_PREALLOC}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh@ flag must be used when creating a map for socket-local storage.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1hhj_ubeh}(h]h ]h"]h$]h&]jjuh1hhhhKhj[ubah}(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}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhKubh)}(hhh](h)}(hbpf_sk_storage_get()h]hbpf_sk_storage_get()}(hj hhhNhNubah}(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)}hjsbah}(h]h ]h"]h$]h&]hhforcelanguagechighlight_args}uh1jhhhK!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 }(hj-hhhNhNubh)}(h``map``h]hmap}(hj5hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj-ubh can be retrieved from socket }(hj-hhhNhNubh)}(h``sk``h]hsk}(hjGhhhNhNubah}(h]h ]h"]h$]h&]uh1hhj-ubh using the }(hj-hhhNhNubh)}(h``bpf_sk_storage_get()``h]hbpf_sk_storage_get()}(hjYhhhNhNubah}(h]h ]h"]h$]h&]uh1hhj-ubh helper. If the }(hj-hhhNhNubh)}(h"``BPF_LOCAL_STORAGE_GET_F_CREATE``h]hBPF_LOCAL_STORAGE_GET_F_CREATE}(hjkhhhNhNubah}(h]h ]h"]h$]h&]uh1hhj-ubh flag is used then }(hj-hhhNhNubh)}(h``bpf_sk_storage_get()``h]hbpf_sk_storage_get()}(hj}hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj-ubh will create the storage for }(hj-hhhNhNubh)}(h``sk``h]hsk}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhj-ubh if it does not already exist. }(hj-hhhNhNubh)}(h ``value``h]hvalue}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhj-ubh can be used together with }(hj-hhhNhNubh)}(h"``BPF_LOCAL_STORAGE_GET_F_CREATE``h]hBPF_LOCAL_STORAGE_GET_F_CREATE}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhj-ubhy to initialize the storage value, otherwise it will be zero initialized. Returns a pointer to the storage on success, or }(hj-hhhNhNubh)}(h``NULL``h]hNULL}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhj-ubh in case of failure.}(hj-hhhNhNubeh}(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](h)}(h``sk``h]hsk}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh is a kernel }(hjhhhNhNubh)}(h``struct sock``h]h struct sock}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh% 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)}(hjh](h)}(h``sk``h]hsk}(hj"hhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh is a }(hjhhhNhNubh)}(h``struct bpf_sock``h]hstruct bpf_sock}(hj4hhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh! pointer for other program types.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhK/hjubah}(h]h ]h"]h$]h&]uh1hhjubeh}(h]h ]h"]h$]h&]jjuh1hhhhK.hjubah}(h]h ]h"]h$]h&]uh1hhjhhhNhNubeh}(h]bpf-sk-storage-getah ]h"]bpf_sk_storage_get()ah$]h&]uh1hhjhhhhhKubh)}(hhh](h)}(hbpf_sk_storage_delete()h]hbpf_sk_storage_delete()}(hjihhhNhNubah}(h]h ]h"]h$]h&]uh1hhjfhhhhhK2ubj)}(h9long bpf_sk_storage_delete(struct bpf_map *map, void *sk)h]h9long bpf_sk_storage_delete(struct bpf_map *map, void *sk)}hjwsbah}(h]h ]h"]h$]h&]hhj(j)j*j+}uh1jhhhK4hjfhhubh)}(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 }(hjhhhNhNubh)}(h``map``h]hmap}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh can be deleted from socket }(hjhhhNhNubh)}(h``sk``h]hsk}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh using the }(hjhhhNhNubh)}(h``bpf_sk_storage_delete()``h]hbpf_sk_storage_delete()}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh helper. Returns }(hjhhhNhNubh)}(h``0``h]h0}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh2 on success, or negative error in case of failure.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhK8hjfhhubeh}(h]bpf-sk-storage-deleteah ]h"]bpf_sk_storage_delete()ah$]h&]uh1hhjhhhhhK2ubeh}(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)}hjsbah}(h]h ]h"]h$]h&]hhj(j)j*j+}uh1jhhhKBhjhhubh)}(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 }(hjhhhNhNubh)}(h ``map_fd``h]hmap_fd}(hj&hhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh7 can be added or updated locally to a socket using the }(hjhhhNhNubh)}(h``bpf_map_update_elem()``h]hbpf_map_update_elem()}(hj8hhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh0 libbpf function. The socket is identified by a }(hjhhhNhNubhtitle_reference)}(h`socket`h]hsocket}(hjLhhhNhNubah}(h]h ]h"]h$]h&]uh1jJhjubh }(hjhhhNhNubh)}(h``fd``h]hfd}(hj^hhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh stored in the pointer }(hjhhhNhNubh)}(h``key``h]hkey}(hjphhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh. The pointer }(hjhhhNhNubh)}(h ``value``h]hvalue}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh3 has the data to be added or updated to the socket }(hjhhhNhNubh)}(h``fd``h]hfd}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh. The type and size of }(hjhhhNhNubh)}(h ``value``h]hvalue}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh< should be the same as the value type of the map definition.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKFhjhhubh)}(hDThe ``flags`` parameter can be used to control the update behaviour:h](hThe }(hjhhhNhNubh)}(h ``flags``h]hflags}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh7 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](h)}(h ``BPF_ANY``h]hBPF_ANY}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh will create storage for }(hjhhhNhNubjK)}(h`socket`h]hsocket}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jJhjubh }(hjhhhNhNubh)}(h``fd``h]hfd}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh 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](h)}(h``BPF_NOEXIST``h]h BPF_NOEXIST}(hj2hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj.ubh will create storage for }(hj.hhhNhNubjK)}(h`socket`h]hsocket}(hjDhhhNhNubah}(h]h ]h"]h$]h&]uh1jJhj.ubh }(hj.hhhNhNubh)}(h``fd``h]hfd}(hjVhhhNhNubah}(h]h ]h"]h$]h&]uh1hhj.ubhE only if it did not already exist, otherwise the call will fail with }(hj.hhhNhNubh)}(h ``-EEXIST``h]h-EEXIST}(hjhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhj.ubh.}(hj.hhhNhNubeh}(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](h)}(h ``BPF_EXIST``h]h BPF_EXIST}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh" will update existing storage for }(hjhhhNhNubjK)}(h`socket`h]hsocket}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jJhjubh }(hjhhhNhNubh)}(h``fd``h]hfd}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh9 if it already exists, otherwise the call will fail with }(hjhhhNhNubh)}(h ``-ENOENT``h]h-ENOENT}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKRhjubah}(h]h ]h"]h$]h&]uh1hhjhhhhhNubeh}(h]h ]h"]h$]h&]jjuh1hhhhKOhjhhubh)}(h?Returns ``0`` on success, or negative error in case of failure.h](hReturns }(hjhhhNhNubh)}(h``0``h]h0}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh2 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()}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhKXubj)}(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)}hj!sbah}(h]h ]h"]h$]h&]hhj(j)j*j+}uh1jhhhKZhjhhubh)}(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 }(hj0hhhNhNubh)}(h ``map_fd``h]hmap_fd}(hj8hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj0ubh* can be retrieved from a socket using the }(hj0hhhNhNubh)}(h``bpf_map_lookup_elem()``h]hbpf_map_lookup_elem()}(hjJhhhNhNubah}(h]h ]h"]h$]h&]uh1hhj0ubhK libbpf function. The storage is retrieved from the socket identified by a }(hj0hhhNhNubjK)}(h`socket`h]hsocket}(hj\hhhNhNubah}(h]h ]h"]h$]h&]uh1jJhj0ubh }(hj0hhhNhNubh)}(h``fd``h]hfd}(hjnhhhNhNubah}(h]h ]h"]h$]h&]uh1hhj0ubh stored in the pointer }(hj0hhhNhNubh)}(h``key``h]hkey}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhj0ubh . Returns }(hj0hhhNhNubh)}(h``0``h]h0}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhj0ubh2 on success, or negative error in case of failure.}(hj0hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhK^hjhhubeh}(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+}uh1jhhhKfhjhhubh)}(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 }(hjhhhNhNubh)}(h ``map_fd``h]hmap_fd}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh( can be deleted from a socket using the }(hjhhhNhNubh)}(h``bpf_map_delete_elem()``h]hbpf_map_delete_elem()}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubhI libbpf function. The storage is deleted from the socket identified by a }(hjhhhNhNubjK)}(h`socket`h]hsocket}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jJhjubh }(hjhhhNhNubh)}(h``fd``h]hfd}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh stored in the pointer }(hjhhhNhNubh)}(h``key``h]hkey}(hj"hhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh . Returns }(hjhhhNhNubh)}(h``0``h]h0}(hj4hhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh2 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}(hjghhhNhNubah}(h]h ]h"]h$]h&]uh1hhjdhhhhhKpubh)}(hhh](h)}(h Kernel BPFh]h Kernel BPF}(hjxhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjuhhhhhKsubh)}(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&]uh1hhhhKuhjuhhubj)}(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+}uh1jhhhKwhjuhhubh)}(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&]uh1hhhhKhjuhhubj)}(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+}uh1jhhhKhjuhhubh)}(hQPlease see the ``tools/testing/selftests/bpf`` directory for functional examples.h](hPlease see the }(hjhhhNhNubh)}(h``tools/testing/selftests/bpf``h]htools/testing/selftests/bpf}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh# directory for functional examples.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjuhhubeh}(h]id1ah ]h"]h$]jah&]uh1hhjdhhhhhKsjKubeh}(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_handlerjMerror_encodingutf-8error_encoding_error_handlerbackslashreplace language_codeenrecord_dependenciesNconfigN id_prefixhauto_id_prefixid dump_settingsNdump_internalsNdump_transformsNdump_pseudo_xmlNexpose_internalsNstrict_visitorN_disable_configN_sourceh _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'j$jaj^ kernel bpfNjcj`jjjYjVj j jjjQjNjjjju nametypes}(j'jajjcjjYj jjQjjuh}(j$hj^jjjj`jjjfjVjj jjjjNjjjdjjujju footnote_refs} citation_refs} autofootnotes]autofootnote_refs]symbol_footnotes]symbol_footnote_refs] footnotes] citations]autofootnote_startKsymbol_footnote_startK id_counter collectionsCounter}j[KsRparse_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&]jalevelKtypeINFOsourcehlineKsuh1jhjuhhhhhKsubatransform_messages] transformerN include_log] decorationNhhub.