tools/testing/selftests/bpf/prog_tests/lwt_reroute.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/prog_tests/lwt_reroute.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/prog_tests/lwt_reroute.c- Extension
.c- Size
- 7171 bytes
- Lines
- 265
- 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
netinet/in.hlwt_helpers.hnetwork_helpers.hlinux/net_tstamp.h
Detected Declarations
function ping_oncefunction overflow_fqfunction setupfunction test_lwt_reroute_normal_xmitfunction test_lwt_reroute_qdisc_droppedfunction test_lwt_reroute
Annotated Snippet
if (!ASSERT_OK(err, "clock_gettime(CLOCK_MONOTONIC)")) {
err = -1;
goto out;
}
*(uint64_t *)CMSG_DATA(cmsg) = (now.tv_nsec + 1) * NSEC_PER_SEC +
now.tv_nsec;
/* we will intentionally send more than fq limit, so ignore
* the error here.
*/
sendmsg(s, &msg, MSG_NOSIGNAL);
snd_target--;
}
/* no kernel crash so far is considered success */
err = 0;
out:
if (s >= 0)
close(s);
return err;
}
static int setup(const char *tun_dev)
{
int target_index = -1;
int tap_fd = -1;
tap_fd = open_tuntap(tun_dev, false);
if (!ASSERT_GE(tap_fd, 0, "open_tun"))
return -1;
target_index = if_nametoindex(tun_dev);
if (!ASSERT_GE(target_index, 0, "if_nametoindex"))
return -1;
SYS(fail, "ip link add link_err type dummy");
SYS(fail, "ip link set lo up");
SYS(fail, "ip addr add dev lo " LOCAL_SRC "/32");
SYS(fail, "ip link set link_err up");
SYS(fail, "ip link set %s up", tun_dev);
SYS(fail, "ip route add %s dev link_err encap bpf xmit obj %s sec lwt_xmit",
TEST_CIDR, BPF_OBJECT);
SYS(fail, "ip rule add pref 100 from all fwmark %d lookup 100",
target_index);
SYS(fail, "ip route add t 100 default dev %s", tun_dev);
return tap_fd;
fail:
if (tap_fd >= 0)
close(tap_fd);
return -1;
}
static void test_lwt_reroute_normal_xmit(void)
{
const char *tun_dev = "tun0";
int tun_fd = -1;
int ifindex = -1;
char ip[256];
struct timeval timeo = {
.tv_sec = 0,
.tv_usec = 250000,
};
tun_fd = setup(tun_dev);
if (!ASSERT_GE(tun_fd, 0, "setup_reroute"))
return;
ifindex = if_nametoindex(tun_dev);
if (!ASSERT_GE(ifindex, 0, "if_nametoindex"))
return;
snprintf(ip, 256, "10.0.0.%d", ifindex);
/* ping packets should be received by the tun device */
ping_once(ip);
if (!ASSERT_EQ(wait_for_packet(tun_fd, __expect_icmp_ipv4, &timeo), 1,
"wait_for_packet"))
log_err("%s xmit", __func__);
}
/*
* Test the failure case when the skb is dropped at the qdisc. This is a
Annotation
- Immediate include surface: `netinet/in.h`, `lwt_helpers.h`, `network_helpers.h`, `linux/net_tstamp.h`.
- Detected declarations: `function ping_once`, `function overflow_fq`, `function setup`, `function test_lwt_reroute_normal_xmit`, `function test_lwt_reroute_qdisc_dropped`, `function test_lwt_reroute`.
- 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.