tools/testing/selftests/bpf/prog_tests/test_tc_tunnel.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/prog_tests/test_tc_tunnel.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/prog_tests/test_tc_tunnel.c- Extension
.c- Size
- 17943 bytes
- Lines
- 713
- 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
stdio.hunistd.hfcntl.hsys/socket.hbpf/libbpf.htest_progs.hnetwork_helpers.htest_tc_tunnel.skel.h
Detected Declarations
struct subtest_cfgstruct connectionfunction build_subtest_namefunction set_subtest_progsfunction set_subtest_addressesfunction run_serverfunction check_server_rx_datafunction disconnect_client_from_serverfunction send_and_test_datafunction vxlan_decap_mod_args_cbfunction udp_decap_mod_args_cbfunction configure_fou_rx_portfunction add_fou_rx_portfunction del_fou_rx_portfunction update_tunnel_intf_addrfunction configure_kernel_for_mplsfunction configure_encapsulationfunction configure_kernel_decapsulationfunction remove_kernel_decapsulationfunction configure_ebpf_decapsulationfunction run_testfunction setupfunction subtest_setupfunction subtest_cleanupfunction cleanupfunction test_tc_tunnel
Annotated Snippet
struct subtest_cfg {
char *ebpf_tun_type;
char *iproute_tun_type;
char *mac_tun_type;
int ipproto;
void (*extra_decap_mod_args_cb)(struct subtest_cfg *cfg, char *dst);
bool tunnel_need_veth_mac;
bool configure_fou_rx_port;
char *tmode;
bool expect_kern_decap_failure;
bool configure_mpls;
bool test_gso;
char *tunnel_client_addr;
char *tunnel_server_addr;
char name[TEST_NAME_MAX_LEN];
char *server_addr;
int client_egress_prog_fd;
int server_ingress_prog_fd;
char extra_decap_mod_args[TUNNEL_ARGS_MAX_LEN];
int server_fd;
};
struct connection {
int client_fd;
int server_fd;
};
static int build_subtest_name(struct subtest_cfg *cfg, char *dst, size_t size)
{
int ret;
ret = snprintf(dst, size, "%s_%s", cfg->ebpf_tun_type,
cfg->mac_tun_type);
return ret < 0 ? ret : 0;
}
static int set_subtest_progs(struct subtest_cfg *cfg, struct test_tc_tunnel *skel)
{
char prog_name[PROG_NAME_MAX_LEN];
struct bpf_program *prog;
int ret;
ret = snprintf(prog_name, PROG_NAME_MAX_LEN, "__encap_");
if (ret < 0)
return ret;
ret = build_subtest_name(cfg, prog_name + ret, PROG_NAME_MAX_LEN - ret);
if (ret < 0)
return ret;
prog = bpf_object__find_program_by_name(skel->obj, prog_name);
if (!prog)
return -1;
cfg->client_egress_prog_fd = bpf_program__fd(prog);
cfg->server_ingress_prog_fd = bpf_program__fd(skel->progs.decap_f);
return 0;
}
static void set_subtest_addresses(struct subtest_cfg *cfg)
{
if (cfg->ipproto == 6)
cfg->server_addr = IP6_ADDR_VETH2;
else
cfg->server_addr = IP4_ADDR_VETH2;
/* Some specific tunnel types need specific addressing, it then
* has been already set in the configuration table. Otherwise,
* deduce the relevant addressing from the ipproto
*/
if (cfg->tunnel_client_addr && cfg->tunnel_server_addr)
return;
if (cfg->ipproto == 6) {
cfg->tunnel_client_addr = IP6_ADDR_VETH1;
cfg->tunnel_server_addr = IP6_ADDR_VETH2;
} else {
cfg->tunnel_client_addr = IP4_ADDR_VETH1;
cfg->tunnel_server_addr = IP4_ADDR_VETH2;
}
}
static int run_server(struct subtest_cfg *cfg)
{
int family = cfg->ipproto == 6 ? AF_INET6 : AF_INET;
struct nstoken *nstoken;
struct network_helper_opts opts = {
.timeout_ms = TIMEOUT_MS
};
nstoken = open_netns(SERVER_NS);
Annotation
- Immediate include surface: `stdio.h`, `unistd.h`, `fcntl.h`, `sys/socket.h`, `bpf/libbpf.h`, `test_progs.h`, `network_helpers.h`, `test_tc_tunnel.skel.h`.
- Detected declarations: `struct subtest_cfg`, `struct connection`, `function build_subtest_name`, `function set_subtest_progs`, `function set_subtest_addresses`, `function run_server`, `function check_server_rx_data`, `function disconnect_client_from_server`, `function send_and_test_data`, `function vxlan_decap_mod_args_cb`.
- 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.