tools/testing/selftests/bpf/prog_tests/xdp_bonding.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/prog_tests/xdp_bonding.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/prog_tests/xdp_bonding.c- Extension
.c- Size
- 24437 bytes
- Lines
- 842
- 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
sched.hnet/if.hlinux/if_link.htest_progs.hnetwork_helpers.hlinux/if_bonding.hlinux/limits.hnetinet/udp.huapi/linux/netdev.hxdp_dummy.skel.hxdp_redirect_multi_kern.skel.hxdp_tx.skel.h
Detected Declarations
struct skeletonsstruct bond_test_casefunction restore_root_netnsfunction setns_by_namefunction get_rx_packetsfunction xdp_attachfunction bonding_setupfunction link_cleanupfunction bonding_cleanupfunction send_udp_packetsfunction test_xdp_bonding_with_modefunction devicefunction test_xdp_bonding_attachfunction test_xdp_bonding_nestedfunction xdp_master_redirectfunction test_xdp_bonding_featuresfunction dev_xdp_uninstallfunction libbpf_debug_printfunction serial_test_xdp_bonding
Annotated Snippet
struct skeletons {
struct xdp_dummy *xdp_dummy;
struct xdp_tx *xdp_tx;
struct xdp_redirect_multi_kern *xdp_redirect_multi_kern;
int nlinks;
struct bpf_link *links[MAX_BPF_LINKS];
};
static int xdp_attach(struct skeletons *skeletons, struct bpf_program *prog, char *iface)
{
struct bpf_link *link;
int ifindex;
ifindex = if_nametoindex(iface);
if (!ASSERT_GT(ifindex, 0, "get ifindex"))
return -1;
if (!ASSERT_LE(skeletons->nlinks+1, MAX_BPF_LINKS, "too many XDP programs attached"))
return -1;
link = bpf_program__attach_xdp(prog, ifindex);
if (!ASSERT_OK_PTR(link, "attach xdp program"))
return -1;
skeletons->links[skeletons->nlinks++] = link;
return 0;
}
enum {
BOND_ONE_NO_ATTACH = 0,
BOND_BOTH_AND_ATTACH,
};
static const char * const mode_names[] = {
[BOND_MODE_ROUNDROBIN] = "balance-rr",
[BOND_MODE_ACTIVEBACKUP] = "active-backup",
[BOND_MODE_XOR] = "balance-xor",
[BOND_MODE_BROADCAST] = "broadcast",
[BOND_MODE_8023AD] = "802.3ad",
[BOND_MODE_TLB] = "balance-tlb",
[BOND_MODE_ALB] = "balance-alb",
};
static const char * const xmit_policy_names[] = {
[BOND_XMIT_POLICY_LAYER2] = "layer2",
[BOND_XMIT_POLICY_LAYER34] = "layer3+4",
[BOND_XMIT_POLICY_LAYER23] = "layer2+3",
[BOND_XMIT_POLICY_ENCAP23] = "encap2+3",
[BOND_XMIT_POLICY_ENCAP34] = "encap3+4",
};
static int bonding_setup(struct skeletons *skeletons, int mode, int xmit_policy,
int bond_both_attach)
{
SYS(fail, "ip netns add ns_dst");
SYS(fail, "ip link add veth1_1 type veth peer name veth2_1 netns ns_dst");
SYS(fail, "ip link add veth1_2 type veth peer name veth2_2 netns ns_dst");
SYS(fail, "ip link add bond1 type bond mode %s xmit_hash_policy %s",
mode_names[mode], xmit_policy_names[xmit_policy]);
SYS(fail, "ip link set bond1 up address " BOND1_MAC_STR " addrgenmode none");
SYS(fail, "ip -netns ns_dst link add bond2 type bond mode %s xmit_hash_policy %s",
mode_names[mode], xmit_policy_names[xmit_policy]);
SYS(fail, "ip -netns ns_dst link set bond2 up address " BOND2_MAC_STR " addrgenmode none");
SYS(fail, "ip link set veth1_1 master bond1");
if (bond_both_attach == BOND_BOTH_AND_ATTACH) {
SYS(fail, "ip link set veth1_2 master bond1");
} else {
SYS(fail, "ip link set veth1_2 up addrgenmode none");
if (xdp_attach(skeletons, skeletons->xdp_dummy->progs.xdp_dummy_prog, "veth1_2"))
return -1;
}
SYS(fail, "ip -netns ns_dst link set veth2_1 master bond2");
if (bond_both_attach == BOND_BOTH_AND_ATTACH)
SYS(fail, "ip -netns ns_dst link set veth2_2 master bond2");
else
SYS(fail, "ip -netns ns_dst link set veth2_2 up addrgenmode none");
/* Load a dummy program on sending side as with veth peer needs to have a
* XDP program loaded as well.
*/
if (xdp_attach(skeletons, skeletons->xdp_dummy->progs.xdp_dummy_prog, "bond1"))
return -1;
if (bond_both_attach == BOND_BOTH_AND_ATTACH) {
Annotation
- Immediate include surface: `sched.h`, `net/if.h`, `linux/if_link.h`, `test_progs.h`, `network_helpers.h`, `linux/if_bonding.h`, `linux/limits.h`, `netinet/udp.h`.
- Detected declarations: `struct skeletons`, `struct bond_test_case`, `function restore_root_netns`, `function setns_by_name`, `function get_rx_packets`, `function xdp_attach`, `function bonding_setup`, `function link_cleanup`, `function bonding_cleanup`, `function send_udp_packets`.
- 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.