tools/testing/selftests/bpf/prog_tests/tc_netkit.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/prog_tests/tc_netkit.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/prog_tests/tc_netkit.c- Extension
.c- Size
- 25670 bytes
- Lines
- 871
- 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
uapi/linux/if_link.hnet/if.htest_progs.htest_tc_link.skel.hnetlink_helpers.htc_helpers.h
Detected Declarations
struct icmphdrstruct iplink_reqfunction create_netkitfunction move_netkitfunction destroy_netkitfunction __send_icmpfunction send_icmpfunction serial_test_tc_netkit_basicfunction serial_test_tc_netkit_multi_links_targetfunction serial_test_tc_netkit_multi_linksfunction serial_test_tc_netkit_multi_opts_targetfunction serial_test_tc_netkit_multi_optsfunction serial_test_tc_netkit_devicefunction serial_test_tc_netkit_neigh_links_targetfunction serial_test_tc_netkit_neigh_linksfunction serial_test_tc_netkit_pkt_type_modefunction serial_test_tc_netkit_pkt_typefunction serial_test_tc_netkit_scrub_typefunction serial_test_tc_netkit_scrub
Annotated Snippet
struct icmphdr {
__u8 type;
__u8 code;
__sum16 checksum;
struct {
__be16 id;
__be16 sequence;
} echo;
};
struct iplink_req {
struct nlmsghdr n;
struct ifinfomsg i;
char buf[1024];
};
static int create_netkit(int mode, int policy, int peer_policy, int *ifindex,
int scrub, int peer_scrub, __u32 flags)
{
struct rtnl_handle rth = { .fd = -1 };
struct iplink_req req = {};
struct rtattr *linkinfo, *data;
const char *type = "netkit";
int err;
err = rtnl_open(&rth, 0);
if (!ASSERT_OK(err, "open_rtnetlink"))
return err;
memset(&req, 0, sizeof(req));
req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg));
req.n.nlmsg_flags = NLM_F_REQUEST | NLM_F_CREATE | NLM_F_EXCL;
req.n.nlmsg_type = RTM_NEWLINK;
req.i.ifi_family = AF_UNSPEC;
addattr_l(&req.n, sizeof(req), IFLA_IFNAME, netkit_name,
strlen(netkit_name));
linkinfo = addattr_nest(&req.n, sizeof(req), IFLA_LINKINFO);
addattr_l(&req.n, sizeof(req), IFLA_INFO_KIND, type, strlen(type));
data = addattr_nest(&req.n, sizeof(req), IFLA_INFO_DATA);
addattr32(&req.n, sizeof(req), IFLA_NETKIT_POLICY, policy);
addattr32(&req.n, sizeof(req), IFLA_NETKIT_PEER_POLICY, peer_policy);
addattr32(&req.n, sizeof(req), IFLA_NETKIT_SCRUB, scrub);
addattr32(&req.n, sizeof(req), IFLA_NETKIT_PEER_SCRUB, peer_scrub);
addattr32(&req.n, sizeof(req), IFLA_NETKIT_MODE, mode);
if (flags & FLAG_ADJUST_ROOM) {
addattr16(&req.n, sizeof(req), IFLA_NETKIT_HEADROOM, NETKIT_HEADROOM);
addattr16(&req.n, sizeof(req), IFLA_NETKIT_TAILROOM, NETKIT_TAILROOM);
}
addattr_nest_end(&req.n, data);
addattr_nest_end(&req.n, linkinfo);
err = rtnl_talk(&rth, &req.n, NULL);
ASSERT_OK(err, "talk_rtnetlink");
rtnl_close(&rth);
*ifindex = if_nametoindex(netkit_name);
ASSERT_GT(*ifindex, 0, "retrieve_ifindex");
ASSERT_OK(system("ip netns add foo"), "create netns");
ASSERT_OK(system("ip link set dev " netkit_name " up"),
"up primary");
ASSERT_OK(system("ip addr add dev " netkit_name " 10.0.0.1/24"),
"addr primary");
if (mode == NETKIT_L3) {
ASSERT_EQ(system("ip link set dev " netkit_name
" addr ee:ff:bb:cc:aa:dd 2> /dev/null"), 512,
"set hwaddress");
} else {
ASSERT_OK(system("ip link set dev " netkit_name
" addr ee:ff:bb:cc:aa:dd"),
"set hwaddress");
}
if (flags & FLAG_SAME_NETNS) {
ASSERT_OK(system("ip link set dev " netkit_peer " up"),
"up peer");
ASSERT_OK(system("ip addr add dev " netkit_peer " 10.0.0.2/24"),
"addr peer");
} else {
ASSERT_OK(system("ip link set " netkit_peer " netns foo"),
"move peer");
ASSERT_OK(system("ip netns exec foo ip link set dev "
netkit_peer " up"), "up peer");
ASSERT_OK(system("ip netns exec foo ip addr add dev "
netkit_peer " 10.0.0.2/24"), "addr peer");
}
return err;
}
static void move_netkit(void)
Annotation
- Immediate include surface: `uapi/linux/if_link.h`, `net/if.h`, `test_progs.h`, `test_tc_link.skel.h`, `netlink_helpers.h`, `tc_helpers.h`.
- Detected declarations: `struct icmphdr`, `struct iplink_req`, `function create_netkit`, `function move_netkit`, `function destroy_netkit`, `function __send_icmp`, `function send_icmp`, `function serial_test_tc_netkit_basic`, `function serial_test_tc_netkit_multi_links_target`, `function serial_test_tc_netkit_multi_links`.
- 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.