tools/testing/selftests/bpf/prog_tests/test_xdp_veth.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/prog_tests/test_xdp_veth.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/prog_tests/test_xdp_veth.c- Extension
.c- Size
- 23376 bytes
- Lines
- 760
- 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
net/if.htest_progs.hnetwork_helpers.hxdp_dummy.skel.hxdp_redirect_map.skel.hxdp_redirect_multi_kern.skel.hxdp_tx.skel.huapi/linux/if_link.h
Detected Declarations
struct veth_configurationstruct net_configurationstruct prog_configurationfunction attach_programs_to_veth_pairfunction create_networkfunction cleanup_networkfunction xdp_veth_redirectfunction xdp_veth_broadcast_redirectfunction xdp_veth_egressfunction xdp_veth_egress_last_dstfunction test_xdp_veth_redirectfunction test_xdp_veth_broadcast_redirectfunction test_xdp_veth_egress
Annotated Snippet
struct veth_configuration {
char local_veth[VETH_NAME_MAX_LEN]; /* Interface in main namespace */
char remote_veth[VETH_NAME_MAX_LEN]; /* Peer interface in dedicated namespace*/
char namespace[NS_NAME_MAX_LEN]; /* Namespace for the remote veth */
int next_veth; /* Local interface to redirect traffic to */
char remote_addr[IP_MAX_LEN]; /* IP address of the remote veth */
};
struct net_configuration {
char ns0_name[NS_NAME_MAX_LEN];
struct veth_configuration veth_cfg[VETH_PAIRS_COUNT];
};
static const struct net_configuration default_config = {
.ns0_name = "ns0-",
{
{
.local_veth = "veth1-",
.remote_veth = "veth11",
.next_veth = 1,
.remote_addr = IP_SRC,
.namespace = "ns-veth11-"
},
{
.local_veth = "veth2-",
.remote_veth = "veth22",
.next_veth = 2,
.remote_addr = "",
.namespace = "ns-veth22-"
},
{
.local_veth = "veth3-",
.remote_veth = "veth33",
.next_veth = 0,
.remote_addr = IP_DST,
.namespace = "ns-veth33-"
}
}
};
struct prog_configuration {
char local_name[PROG_NAME_MAX_LEN]; /* BPF prog to attach to local_veth */
char remote_name[PROG_NAME_MAX_LEN]; /* BPF prog to attach to remote_veth */
u32 local_flags; /* XDP flags to use on local_veth */
u32 remote_flags; /* XDP flags to use on remote_veth */
};
static int attach_programs_to_veth_pair(struct bpf_object **objs, size_t nb_obj,
struct net_configuration *net_config,
struct prog_configuration *prog, int index)
{
struct bpf_program *local_prog, *remote_prog;
struct nstoken *nstoken;
int interface, ret, i;
for (i = 0; i < nb_obj; i++) {
local_prog = bpf_object__find_program_by_name(objs[i], prog[index].local_name);
if (local_prog)
break;
}
if (!ASSERT_OK_PTR(local_prog, "find local program"))
return -1;
for (i = 0; i < nb_obj; i++) {
remote_prog = bpf_object__find_program_by_name(objs[i], prog[index].remote_name);
if (remote_prog)
break;
}
if (!ASSERT_OK_PTR(remote_prog, "find remote program"))
return -1;
interface = if_nametoindex(net_config->veth_cfg[index].local_veth);
if (!ASSERT_NEQ(interface, 0, "non zero interface index"))
return -1;
ret = bpf_xdp_attach(interface, bpf_program__fd(local_prog),
prog[index].local_flags, NULL);
if (!ASSERT_OK(ret, "attach xdp program to local veth"))
return -1;
nstoken = open_netns(net_config->veth_cfg[index].namespace);
if (!ASSERT_OK_PTR(nstoken, "switch to remote veth namespace"))
return -1;
interface = if_nametoindex(net_config->veth_cfg[index].remote_veth);
if (!ASSERT_NEQ(interface, 0, "non zero interface index")) {
close_netns(nstoken);
return -1;
}
Annotation
- Immediate include surface: `net/if.h`, `test_progs.h`, `network_helpers.h`, `xdp_dummy.skel.h`, `xdp_redirect_map.skel.h`, `xdp_redirect_multi_kern.skel.h`, `xdp_tx.skel.h`, `uapi/linux/if_link.h`.
- Detected declarations: `struct veth_configuration`, `struct net_configuration`, `struct prog_configuration`, `function attach_programs_to_veth_pair`, `function create_network`, `function cleanup_network`, `function xdp_veth_redirect`, `function xdp_veth_broadcast_redirect`, `function xdp_veth_egress`, `function xdp_veth_egress_last_dst`.
- 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.