tools/testing/selftests/bpf/progs/bpf_iter_bpf_sk_storage_helpers.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/progs/bpf_iter_bpf_sk_storage_helpers.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/progs/bpf_iter_bpf_sk_storage_helpers.c- Extension
.c- Size
- 1255 bytes
- Lines
- 66
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
vmlinux.hbpf/bpf_helpers.hbpf/bpf_tracing.h
Detected Declarations
function delete_bpf_sk_storage_mapfunction fill_socket_ownerfunction negate_socket_local_storage
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
/* Copyright (c) 2020 Google LLC. */
#include <vmlinux.h>
#include <bpf/bpf_helpers.h>
#include <bpf/bpf_tracing.h>
char _license[] SEC("license") = "GPL";
struct {
__uint(type, BPF_MAP_TYPE_SK_STORAGE);
__uint(map_flags, BPF_F_NO_PREALLOC);
__type(key, int);
__type(value, int);
} sk_stg_map SEC(".maps");
SEC("iter/bpf_sk_storage_map")
int delete_bpf_sk_storage_map(struct bpf_iter__bpf_sk_storage_map *ctx)
{
if (ctx->sk)
bpf_sk_storage_delete(&sk_stg_map, ctx->sk);
return 0;
}
SEC("iter/task_file")
int fill_socket_owner(struct bpf_iter__task_file *ctx)
{
struct task_struct *task = ctx->task;
struct file *file = ctx->file;
struct socket *sock;
int *sock_tgid;
if (!task || !file)
return 0;
sock = bpf_sock_from_file(file);
if (!sock)
return 0;
sock_tgid = bpf_sk_storage_get(&sk_stg_map, sock->sk, 0, 0);
if (!sock_tgid)
return 0;
*sock_tgid = task->tgid;
return 0;
}
SEC("iter/tcp")
int negate_socket_local_storage(struct bpf_iter__tcp *ctx)
{
struct sock_common *sk_common = ctx->sk_common;
int *sock_tgid;
if (!sk_common)
return 0;
sock_tgid = bpf_sk_storage_get(&sk_stg_map, sk_common, 0, 0);
if (!sock_tgid)
return 0;
*sock_tgid = -*sock_tgid;
return 0;
}
Annotation
- Immediate include surface: `vmlinux.h`, `bpf/bpf_helpers.h`, `bpf/bpf_tracing.h`.
- Detected declarations: `function delete_bpf_sk_storage_map`, `function fill_socket_owner`, `function negate_socket_local_storage`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
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.