tools/testing/selftests/bpf/progs/connect4_prog.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/progs/connect4_prog.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/progs/connect4_prog.c- Extension
.c- Size
- 4577 bytes
- Lines
- 204
- 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.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
string.hlinux/stddef.hlinux/bpf.hlinux/in.hlinux/in6.hlinux/tcp.hlinux/if.herrno.hbpf/bpf_helpers.hbpf/bpf_endian.h
Detected Declarations
function do_bindfunction verify_ccfunction set_ccfunction bind_to_devicefunction set_keepalivefunction set_notsent_lowatfunction connect_v4_progfunction connect_v4_deny_prog
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
// Copyright (c) 2018 Facebook
#include <string.h>
#include <linux/stddef.h>
#include <linux/bpf.h>
#include <linux/in.h>
#include <linux/in6.h>
#include <linux/tcp.h>
#include <linux/if.h>
#include <errno.h>
#include <bpf/bpf_helpers.h>
#include <bpf/bpf_endian.h>
#define SRC_REWRITE_IP4 0x7f000004U
#define DST_REWRITE_IP4 0x7f000001U
#define DST_REWRITE_PORT4 4444
#ifndef TCP_CA_NAME_MAX
#define TCP_CA_NAME_MAX 16
#endif
#ifndef TCP_NOTSENT_LOWAT
#define TCP_NOTSENT_LOWAT 25
#endif
#ifndef IFNAMSIZ
#define IFNAMSIZ 16
#endif
#ifndef SOL_TCP
#define SOL_TCP 6
#endif
const char reno[] = "reno";
const char cubic[] = "cubic";
__attribute__ ((noinline)) __weak
int do_bind(struct bpf_sock_addr *ctx)
{
struct sockaddr_in sa = {};
sa.sin_family = AF_INET;
sa.sin_port = bpf_htons(0);
sa.sin_addr.s_addr = bpf_htonl(SRC_REWRITE_IP4);
if (bpf_bind(ctx, (struct sockaddr *)&sa, sizeof(sa)) != 0)
return 0;
return 1;
}
static __inline int verify_cc(struct bpf_sock_addr *ctx,
const char expected[])
{
char buf[TCP_CA_NAME_MAX];
if (bpf_getsockopt(ctx, SOL_TCP, TCP_CONGESTION, &buf, sizeof(buf)))
return 1;
if (bpf_strncmp(buf, TCP_CA_NAME_MAX, expected))
return 1;
return 0;
}
static __inline int set_cc(struct bpf_sock_addr *ctx)
{
if (bpf_setsockopt(ctx, SOL_TCP, TCP_CONGESTION, (void *)reno, sizeof(reno)))
return 1;
if (verify_cc(ctx, reno))
return 1;
if (bpf_setsockopt(ctx, SOL_TCP, TCP_CONGESTION, (void *)cubic, sizeof(cubic)))
return 1;
if (verify_cc(ctx, cubic))
return 1;
return 0;
}
static __inline int bind_to_device(struct bpf_sock_addr *ctx)
{
char veth1[IFNAMSIZ] = "test_sock_addr1";
char veth2[IFNAMSIZ] = "test_sock_addr2";
char missing[IFNAMSIZ] = "nonexistent_dev";
char del_bind[IFNAMSIZ] = "";
Annotation
- Immediate include surface: `string.h`, `linux/stddef.h`, `linux/bpf.h`, `linux/in.h`, `linux/in6.h`, `linux/tcp.h`, `linux/if.h`, `errno.h`.
- Detected declarations: `function do_bind`, `function verify_cc`, `function set_cc`, `function bind_to_device`, `function set_keepalive`, `function set_notsent_lowat`, `function connect_v4_prog`, `function connect_v4_deny_prog`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
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.