tools/testing/selftests/bpf/prog_tests/cgroup_tcp_skb.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/prog_tests/cgroup_tcp_skb.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/prog_tests/cgroup_tcp_skb.c- Extension
.c- Size
- 9522 bytes
- Lines
- 345
- 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
test_progs.hlinux/in6.hsys/socket.hsched.hunistd.hcgroup_helpers.htesting_helpers.hcgroup_tcp_skb.skel.hcgroup_tcp_skb.hnetwork_helpers.h
Detected Declarations
function install_filtersfunction uninstall_filtersfunction create_client_sock_v6function talk_to_cgroupfunction talk_to_outsidefunction close_connectionfunction test_cgroup_tcp_skb
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
/* Copyright (c) 2023 Facebook */
#include <test_progs.h>
#include <linux/in6.h>
#include <sys/socket.h>
#include <sched.h>
#include <unistd.h>
#include "cgroup_helpers.h"
#include "testing_helpers.h"
#include "cgroup_tcp_skb.skel.h"
#include "cgroup_tcp_skb.h"
#include "network_helpers.h"
#define CGROUP_TCP_SKB_PATH "/test_cgroup_tcp_skb"
static int install_filters(int cgroup_fd,
struct bpf_link **egress_link,
struct bpf_link **ingress_link,
struct bpf_program *egress_prog,
struct bpf_program *ingress_prog,
struct cgroup_tcp_skb *skel)
{
/* Prepare filters */
skel->bss->g_sock_state = 0;
skel->bss->g_unexpected = 0;
*egress_link =
bpf_program__attach_cgroup(egress_prog,
cgroup_fd);
if (!ASSERT_OK_PTR(egress_link, "egress_link"))
return -1;
*ingress_link =
bpf_program__attach_cgroup(ingress_prog,
cgroup_fd);
if (!ASSERT_OK_PTR(ingress_link, "ingress_link"))
return -1;
return 0;
}
static void uninstall_filters(struct bpf_link **egress_link,
struct bpf_link **ingress_link)
{
bpf_link__destroy(*egress_link);
*egress_link = NULL;
bpf_link__destroy(*ingress_link);
*ingress_link = NULL;
}
static int create_client_sock_v6(void)
{
int fd;
fd = socket(AF_INET6, SOCK_STREAM, 0);
if (fd < 0) {
perror("socket");
return -1;
}
return fd;
}
/* Connect to the server in a cgroup from the outside of the cgroup. */
static int talk_to_cgroup(int *client_fd, int *listen_fd, int *service_fd,
struct cgroup_tcp_skb *skel)
{
int err, cp;
char buf[5];
int port;
/* Create client & server socket */
err = join_root_cgroup();
if (!ASSERT_OK(err, "join_root_cgroup"))
return -1;
*client_fd = create_client_sock_v6();
if (!ASSERT_GE(*client_fd, 0, "client_fd"))
return -1;
err = join_cgroup(CGROUP_TCP_SKB_PATH);
if (!ASSERT_OK(err, "join_cgroup"))
return -1;
*listen_fd = start_server(AF_INET6, SOCK_STREAM, NULL, 0, 0);
if (!ASSERT_GE(*listen_fd, 0, "listen_fd"))
return -1;
port = get_socket_local_port(*listen_fd);
if (!ASSERT_GE(port, 0, "get_socket_local_port"))
return -1;
skel->bss->g_sock_port = ntohs(port);
/* Connect client to server */
err = connect_fd_to_fd(*client_fd, *listen_fd, 0);
if (!ASSERT_OK(err, "connect_fd_to_fd"))
Annotation
- Immediate include surface: `test_progs.h`, `linux/in6.h`, `sys/socket.h`, `sched.h`, `unistd.h`, `cgroup_helpers.h`, `testing_helpers.h`, `cgroup_tcp_skb.skel.h`.
- Detected declarations: `function install_filters`, `function uninstall_filters`, `function create_client_sock_v6`, `function talk_to_cgroup`, `function talk_to_outside`, `function close_connection`, `function test_cgroup_tcp_skb`.
- 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.