tools/testing/selftests/bpf/prog_tests/xdp_flowtable.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/prog_tests/xdp_flowtable.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/prog_tests/xdp_flowtable.c- Extension
.c- Size
- 4289 bytes
- Lines
- 170
- 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
test_progs.hnetwork_helpers.hbpf/btf.hlinux/if_link.hnetinet/udp.hnet/if.hunistd.hxdp_flowtable.skel.h
Detected Declarations
function send_udp_trafficfunction test_xdp_flowtable
Annotated Snippet
if (n != sizeof(buf)) {
close(sock);
return -EINVAL;
}
usleep(50000); /* 50ms */
}
close(sock);
return 0;
}
void test_xdp_flowtable(void)
{
struct xdp_flowtable *skel = NULL;
struct nstoken *tok = NULL;
int iifindex, stats_fd;
__u32 value, key = 0;
struct bpf_link *link = NULL;
if (SYS_NOFAIL("nft -v")) {
fprintf(stdout, "Missing required nft tool\n");
test__skip();
return;
}
SYS(out, "ip netns add " TX_NETNS_NAME);
SYS(out, "ip netns add " RX_NETNS_NAME);
tok = open_netns(RX_NETNS_NAME);
if (!ASSERT_OK_PTR(tok, "setns"))
goto out;
SYS(out, "sysctl -qw net.ipv4.conf.all.forwarding=1");
SYS(out, "ip link add " TX_NAME " type veth peer " FORWARD_NAME);
SYS(out, "ip link set " TX_NAME " netns " TX_NETNS_NAME);
SYS(out, "ip link set dev " FORWARD_NAME " address " FORWARD_MAC);
SYS(out,
"ip addr add " FORWARD_ADDR "/" PREFIX_LEN " dev " FORWARD_NAME);
SYS(out, "ip link set dev " FORWARD_NAME " up");
SYS(out, "ip link add " RX_NAME " type dummy");
SYS(out, "ip link set dev " RX_NAME " address " RX_MAC);
SYS(out, "ip addr add " RX_ADDR "/" PREFIX_LEN " dev " RX_NAME);
SYS(out, "ip link set dev " RX_NAME " up");
/* configure the flowtable */
SYS(out, "nft add table ip filter");
SYS(out,
"nft add flowtable ip filter f { hook ingress priority 0\\; "
"devices = { " FORWARD_NAME ", " RX_NAME " }\\; }");
SYS(out,
"nft add chain ip filter forward "
"{ type filter hook forward priority 0\\; }");
SYS(out,
"nft add rule ip filter forward ip protocol udp th dport "
UDP_PORT_STR " flow add @f");
/* Avoid ARP calls */
SYS(out,
"ip -4 neigh add " DST_ADDR " lladdr " DST_MAC " dev " RX_NAME);
close_netns(tok);
tok = open_netns(TX_NETNS_NAME);
if (!ASSERT_OK_PTR(tok, "setns"))
goto out;
SYS(out, "ip addr add " TX_ADDR "/" PREFIX_LEN " dev " TX_NAME);
SYS(out, "ip link set dev " TX_NAME " address " TX_MAC);
SYS(out, "ip link set dev " TX_NAME " up");
SYS(out, "ip route add default via " FORWARD_ADDR);
close_netns(tok);
tok = open_netns(RX_NETNS_NAME);
if (!ASSERT_OK_PTR(tok, "setns"))
goto out;
iifindex = if_nametoindex(FORWARD_NAME);
if (!ASSERT_NEQ(iifindex, 0, "iifindex"))
goto out;
skel = xdp_flowtable__open_and_load();
if (!ASSERT_OK_PTR(skel, "skel"))
goto out;
link = bpf_program__attach_xdp(skel->progs.xdp_flowtable_do_lookup,
iifindex);
if (!ASSERT_OK_PTR(link, "prog_attach"))
goto out;
Annotation
- Immediate include surface: `test_progs.h`, `network_helpers.h`, `bpf/btf.h`, `linux/if_link.h`, `netinet/udp.h`, `net/if.h`, `unistd.h`, `xdp_flowtable.skel.h`.
- Detected declarations: `function send_udp_traffic`, `function test_xdp_flowtable`.
- 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.