tools/testing/selftests/bpf/progs/cgrp_ls_attach_cgroup.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/progs/cgrp_ls_attach_cgroup.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/progs/cgrp_ls_attach_cgroup.c- Extension
.c- Size
- 2060 bytes
- Lines
- 101
- 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.hbpf_tracing_net.h
Detected Declarations
struct socket_cookiefunction set_cookiefunction update_cookie_sockopsfunction BPF_PROG
Annotated Snippet
struct socket_cookie {
__u64 cookie_key;
__u64 cookie_value;
};
struct {
__uint(type, BPF_MAP_TYPE_CGRP_STORAGE);
__uint(map_flags, BPF_F_NO_PREALLOC);
__type(key, int);
__type(value, struct socket_cookie);
} socket_cookies SEC(".maps");
SEC("cgroup/connect6")
int set_cookie(struct bpf_sock_addr *ctx)
{
struct socket_cookie *p;
struct tcp_sock *tcp_sk;
struct bpf_sock *sk;
if (ctx->family != AF_INET6 || ctx->user_family != AF_INET6)
return 1;
sk = ctx->sk;
if (!sk)
return 1;
tcp_sk = bpf_skc_to_tcp_sock(sk);
if (!tcp_sk)
return 1;
p = bpf_cgrp_storage_get(&socket_cookies,
tcp_sk->inet_conn.icsk_inet.sk.sk_cgrp_data.cgroup, 0,
BPF_LOCAL_STORAGE_GET_F_CREATE);
if (!p)
return 1;
p->cookie_value = 0xF;
p->cookie_key = bpf_get_socket_cookie(ctx);
return 1;
}
SEC("sockops")
int update_cookie_sockops(struct bpf_sock_ops *ctx)
{
struct socket_cookie *p;
struct tcp_sock *tcp_sk;
struct bpf_sock *sk;
if (ctx->family != AF_INET6 || ctx->op != BPF_SOCK_OPS_TCP_CONNECT_CB)
return 1;
sk = ctx->sk;
if (!sk)
return 1;
tcp_sk = bpf_skc_to_tcp_sock(sk);
if (!tcp_sk)
return 1;
p = bpf_cgrp_storage_get(&socket_cookies,
tcp_sk->inet_conn.icsk_inet.sk.sk_cgrp_data.cgroup, 0, 0);
if (!p)
return 1;
if (p->cookie_key != bpf_get_socket_cookie(ctx))
return 1;
p->cookie_value |= (ctx->local_port << 8);
return 1;
}
SEC("fexit/inet_stream_connect")
int BPF_PROG(update_cookie_tracing, struct socket *sock,
struct sockaddr *uaddr, int addr_len, int flags)
{
struct socket_cookie *p;
if (uaddr->sa_family != AF_INET6)
return 0;
p = bpf_cgrp_storage_get(&socket_cookies, sock->sk->sk_cgrp_data.cgroup, 0, 0);
if (!p)
return 0;
if (p->cookie_key != bpf_get_socket_cookie(sock->sk))
return 0;
p->cookie_value |= 0xF0;
return 0;
}
Annotation
- Immediate include surface: `vmlinux.h`, `bpf/bpf_helpers.h`, `bpf/bpf_tracing.h`, `bpf_tracing_net.h`.
- Detected declarations: `struct socket_cookie`, `function set_cookie`, `function update_cookie_sockops`, `function BPF_PROG`.
- 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.