net/core/bpf_sk_storage.c
Source file repositories/reference/linux-study-clean/net/core/bpf_sk_storage.c
File Facts
- System
- Linux kernel
- Corpus path
net/core/bpf_sk_storage.c- Extension
.c- Size
- 23061 bytes
- Lines
- 923
- Domain
- Networking Core
- Bucket
- Sockets, Protocols, Packet Path, And Network Policy
- Inferred role
- Networking Core: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Networking stack implementation surface: socket APIs, protocol dispatch, packet flow, routing, filtering, and network namespaces.
- Networking stack implementation surface: socket APIs, protocol dispatch, packet flow, routing, filtering, and network namespaces.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/rculist.hlinux/list.hlinux/hash.hlinux/types.hlinux/spinlock.hlinux/bpf.hlinux/btf.hlinux/btf_ids.hlinux/bpf_local_storage.hnet/bpf_sk_storage.hnet/sock.huapi/linux/sock_diag.huapi/linux/btf.hlinux/rcupdate_trace.h
Detected Declarations
struct bpf_sk_storage_diagstruct bpf_iter_seq_sk_storage_map_infostruct bpf_iter__bpf_sk_storage_mapfunction bpf_sk_storage_lookupfunction bpf_sk_storage_delfunction bpf_sk_storage_freefunction bpf_sk_storage_map_freefunction notsupp_get_next_keyfunction bpf_fd_sk_storage_update_elemfunction bpf_fd_sk_storage_delete_elemfunction bpf_sk_storage_clone_elemfunction bpf_sk_storage_clonefunction hlist_for_each_entry_rcufunction bpf_sk_storage_chargefunction atomic_readfunction bpf_sk_storage_unchargefunction bpf_sk_storage_ptrfunction bpf_sk_storage_tracing_allowedfunction bpf_sk_storage_function INET_DIAG_BPF_SK_STORAGESfunction bpf_sk_storage_diag_freefunction diag_check_dupfunction bpf_sk_storage_diag_allocfunction nla_for_each_nested_typefunction nla_for_each_nested_typefunction diag_getfunction bpf_sk_storage_diag_put_allfunction bpf_sk_storage_diag_putfunction bpf_sk_storage_map_seq_find_nextfunction hlist_for_each_entry_rcufunction __bpf_sk_storage_map_seq_showfunction bpf_sk_storage_map_seq_showfunction bpf_sk_storage_map_seq_stopfunction bpf_iter_init_sk_storage_mapfunction bpf_iter_fini_sk_storage_mapfunction bpf_iter_attach_mapfunction bpf_iter_detach_mapfunction bpf_sk_storage_map_iter_initexport bpf_sk_storage_diag_freeexport bpf_sk_storage_diag_allocexport bpf_sk_storage_diag_put
Annotated Snippet
struct bpf_sk_storage_diag {
u32 nr_maps;
struct bpf_map *maps[];
};
/* The reply will be like:
* INET_DIAG_BPF_SK_STORAGES (nla_nest)
* SK_DIAG_BPF_STORAGE (nla_nest)
* SK_DIAG_BPF_STORAGE_MAP_ID (nla_put_u32)
* SK_DIAG_BPF_STORAGE_MAP_VALUE (nla_reserve_64bit)
* SK_DIAG_BPF_STORAGE (nla_nest)
* SK_DIAG_BPF_STORAGE_MAP_ID (nla_put_u32)
* SK_DIAG_BPF_STORAGE_MAP_VALUE (nla_reserve_64bit)
* ....
*/
static int nla_value_size(u32 value_size)
{
/* SK_DIAG_BPF_STORAGE (nla_nest)
* SK_DIAG_BPF_STORAGE_MAP_ID (nla_put_u32)
* SK_DIAG_BPF_STORAGE_MAP_VALUE (nla_reserve_64bit)
*/
return nla_total_size(0) + nla_total_size(sizeof(u32)) +
nla_total_size_64bit(value_size);
}
void bpf_sk_storage_diag_free(struct bpf_sk_storage_diag *diag)
{
u32 i;
if (!diag)
return;
for (i = 0; i < diag->nr_maps; i++)
bpf_map_put(diag->maps[i]);
kfree(diag);
}
EXPORT_SYMBOL_GPL(bpf_sk_storage_diag_free);
static bool diag_check_dup(const struct bpf_sk_storage_diag *diag,
const struct bpf_map *map)
{
u32 i;
for (i = 0; i < diag->nr_maps; i++) {
if (diag->maps[i] == map)
return true;
}
return false;
}
struct bpf_sk_storage_diag *
bpf_sk_storage_diag_alloc(const struct nlattr *nla_stgs)
{
struct bpf_sk_storage_diag *diag;
struct nlattr *nla;
u32 nr_maps = 0;
int rem, err;
/* bpf_local_storage_map is currently limited to CAP_SYS_ADMIN as
* the map_alloc_check() side also does.
*/
if (!bpf_capable())
return ERR_PTR(-EPERM);
nla_for_each_nested_type(nla, SK_DIAG_BPF_STORAGE_REQ_MAP_FD,
nla_stgs, rem) {
if (nla_len(nla) != sizeof(u32))
return ERR_PTR(-EINVAL);
nr_maps++;
}
diag = kzalloc_flex(*diag, maps, nr_maps);
if (!diag)
return ERR_PTR(-ENOMEM);
nla_for_each_nested_type(nla, SK_DIAG_BPF_STORAGE_REQ_MAP_FD,
nla_stgs, rem) {
int map_fd = nla_get_u32(nla);
struct bpf_map *map = bpf_map_get(map_fd);
if (IS_ERR(map)) {
err = PTR_ERR(map);
goto err_free;
}
if (map->map_type != BPF_MAP_TYPE_SK_STORAGE) {
bpf_map_put(map);
err = -EINVAL;
goto err_free;
Annotation
- Immediate include surface: `linux/rculist.h`, `linux/list.h`, `linux/hash.h`, `linux/types.h`, `linux/spinlock.h`, `linux/bpf.h`, `linux/btf.h`, `linux/btf_ids.h`.
- Detected declarations: `struct bpf_sk_storage_diag`, `struct bpf_iter_seq_sk_storage_map_info`, `struct bpf_iter__bpf_sk_storage_map`, `function bpf_sk_storage_lookup`, `function bpf_sk_storage_del`, `function bpf_sk_storage_free`, `function bpf_sk_storage_map_free`, `function notsupp_get_next_key`, `function bpf_fd_sk_storage_update_elem`, `function bpf_fd_sk_storage_delete_elem`.
- Atlas domain: Networking Core / Sockets, Protocols, Packet Path, And Network Policy.
- Implementation status: integration implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.