tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c- Extension
.c- Size
- 15674 bytes
- Lines
- 645
- 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
linux/err.hnetinet/tcp.htest_progs.hnetwork_helpers.hbpf_dctcp.skel.hbpf_cubic.skel.hbpf_tcp_nogpl.skel.htcp_ca_update.skel.hbpf_dctcp_release.skel.htcp_ca_write_sk_pacing.skel.htcp_ca_incompl_cong_ops.skel.htcp_ca_unsupp_cong_op.skel.htcp_ca_kfunc.skel.hbpf_cc_cubic.skel.h
Detected Declarations
struct cb_optsfunction settcpcafunction start_testfunction do_testfunction cc_cbfunction test_cubicfunction stg_post_socket_cbfunction test_dctcpfunction test_dctcp_autoattach_mapfunction libbpf_debug_printfunction test_invalid_licensefunction test_dctcp_fallbackfunction test_rel_setsockoptfunction test_write_sk_pacingfunction test_incompl_cong_opsfunction test_unsupp_cong_opfunction test_update_cafunction test_update_wrongfunction test_mixed_linksfunction test_multi_linksfunction test_link_replacefunction test_tcp_ca_kfuncfunction test_cc_cubicfunction test_bpf_tcp_ca
Annotated Snippet
struct cb_opts {
const char *cc;
int map_fd;
};
static int settcpca(int fd, const char *tcp_ca)
{
int err;
err = setsockopt(fd, IPPROTO_TCP, TCP_CONGESTION, tcp_ca, strlen(tcp_ca));
if (!ASSERT_NEQ(err, -1, "setsockopt"))
return -1;
return 0;
}
static bool start_test(char *addr_str,
const struct network_helper_opts *srv_opts,
const struct network_helper_opts *cli_opts,
int *srv_fd, int *cli_fd)
{
*srv_fd = start_server_str(AF_INET6, SOCK_STREAM, addr_str, 0, srv_opts);
if (!ASSERT_NEQ(*srv_fd, -1, "start_server_str"))
goto err;
/* connect to server */
*cli_fd = connect_to_fd_opts(*srv_fd, cli_opts);
if (!ASSERT_NEQ(*cli_fd, -1, "connect_to_fd_opts"))
goto err;
return true;
err:
if (*srv_fd != -1) {
close(*srv_fd);
*srv_fd = -1;
}
if (*cli_fd != -1) {
close(*cli_fd);
*cli_fd = -1;
}
return false;
}
static void do_test(const struct network_helper_opts *opts)
{
int lfd = -1, fd = -1;
if (!start_test(NULL, opts, opts, &lfd, &fd))
goto done;
ASSERT_OK(send_recv_data(lfd, fd, total_bytes), "send_recv_data");
done:
if (lfd != -1)
close(lfd);
if (fd != -1)
close(fd);
}
static int cc_cb(int fd, void *opts)
{
struct cb_opts *cb_opts = (struct cb_opts *)opts;
return settcpca(fd, cb_opts->cc);
}
static void test_cubic(void)
{
struct cb_opts cb_opts = {
.cc = "bpf_cubic",
};
struct network_helper_opts opts = {
.post_socket_cb = cc_cb,
.cb_opts = &cb_opts,
};
struct bpf_cubic *cubic_skel;
struct bpf_link *link;
cubic_skel = bpf_cubic__open_and_load();
if (!ASSERT_OK_PTR(cubic_skel, "bpf_cubic__open_and_load"))
return;
link = bpf_map__attach_struct_ops(cubic_skel->maps.cubic);
if (!ASSERT_OK_PTR(link, "bpf_map__attach_struct_ops")) {
bpf_cubic__destroy(cubic_skel);
return;
}
do_test(&opts);
Annotation
- Immediate include surface: `linux/err.h`, `netinet/tcp.h`, `test_progs.h`, `network_helpers.h`, `bpf_dctcp.skel.h`, `bpf_cubic.skel.h`, `bpf_tcp_nogpl.skel.h`, `tcp_ca_update.skel.h`.
- Detected declarations: `struct cb_opts`, `function settcpca`, `function start_test`, `function do_test`, `function cc_cb`, `function test_cubic`, `function stg_post_socket_cb`, `function test_dctcp`, `function test_dctcp_autoattach_map`, `function libbpf_debug_print`.
- 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.