tools/testing/selftests/bpf/prog_tests/test_bpf_smc.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/prog_tests/test_bpf_smc.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/prog_tests/test_bpf_smc.c- Extension
.c- Size
- 9313 bytes
- Lines
- 393
- 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.hlinux/genetlink.hnetwork_helpers.hbpf_smc.skel.h
Detected Declarations
struct smc_policy_ip_keystruct smc_policy_ip_valuestruct msgtemplatefunction setup_ueidfunction cleanup_ueidfunction send_cmdfunction get_smc_nl_family_idfunction smc_ueidfunction setup_ueidfunction cleanup_ueidfunction setup_netnsfunction cleanup_netnsfunction setup_smcfunction set_client_addr_cbfunction run_linkfunction block_linkfunction test_topofunction test_bpf_smc
Annotated Snippet
struct smc_policy_ip_key {
__u32 sip;
__u32 dip;
};
struct smc_policy_ip_value {
__u8 mode;
};
#if defined(__s390x__)
/* s390x has default seid */
static bool setup_ueid(void) { return true; }
static void cleanup_ueid(void) {}
#else
enum {
SMC_NETLINK_ADD_UEID = 10,
SMC_NETLINK_REMOVE_UEID
};
enum {
SMC_NLA_EID_TABLE_UNSPEC,
SMC_NLA_EID_TABLE_ENTRY, /* string */
};
struct msgtemplate {
struct nlmsghdr n;
struct genlmsghdr g;
char buf[1024];
};
#define GENLMSG_DATA(glh) ((void *)(NLMSG_DATA(glh) + GENL_HDRLEN))
#define GENLMSG_PAYLOAD(glh) (NLMSG_PAYLOAD(glh, 0) - GENL_HDRLEN)
#define NLA_DATA(na) ((void *)((char *)(na) + NLA_HDRLEN))
#define NLA_PAYLOAD(len) ((len) - NLA_HDRLEN)
#define SMC_GENL_FAMILY_NAME "SMC_GEN_NETLINK"
#define SMC_BPFTEST_UEID "SMC-BPFTEST-UEID"
static uint16_t smc_nl_family_id = -1;
static int send_cmd(int fd, __u16 nlmsg_type, __u32 nlmsg_pid,
__u16 nlmsg_flags, __u8 genl_cmd, __u16 nla_type,
void *nla_data, int nla_len)
{
struct nlattr *na;
struct sockaddr_nl nladdr;
int r, buflen;
char *buf;
struct msgtemplate msg = {0};
msg.n.nlmsg_len = NLMSG_LENGTH(GENL_HDRLEN);
msg.n.nlmsg_type = nlmsg_type;
msg.n.nlmsg_flags = nlmsg_flags;
msg.n.nlmsg_seq = 0;
msg.n.nlmsg_pid = nlmsg_pid;
msg.g.cmd = genl_cmd;
msg.g.version = 1;
na = (struct nlattr *)GENLMSG_DATA(&msg);
na->nla_type = nla_type;
na->nla_len = nla_len + 1 + NLA_HDRLEN;
memcpy(NLA_DATA(na), nla_data, nla_len);
msg.n.nlmsg_len += NLMSG_ALIGN(na->nla_len);
buf = (char *)&msg;
buflen = msg.n.nlmsg_len;
memset(&nladdr, 0, sizeof(nladdr));
nladdr.nl_family = AF_NETLINK;
while ((r = sendto(fd, buf, buflen, 0, (struct sockaddr *)&nladdr,
sizeof(nladdr))) < buflen) {
if (r > 0) {
buf += r;
buflen -= r;
} else if (errno != EAGAIN) {
return -1;
}
}
return 0;
}
static bool get_smc_nl_family_id(void)
{
struct sockaddr_nl nl_src;
struct msgtemplate msg;
struct nlattr *nl;
int fd, ret;
pid_t pid;
fd = socket(AF_NETLINK, SOCK_RAW, NETLINK_GENERIC);
Annotation
- Immediate include surface: `test_progs.h`, `linux/genetlink.h`, `network_helpers.h`, `bpf_smc.skel.h`.
- Detected declarations: `struct smc_policy_ip_key`, `struct smc_policy_ip_value`, `struct msgtemplate`, `function setup_ueid`, `function cleanup_ueid`, `function send_cmd`, `function get_smc_nl_family_id`, `function smc_ueid`, `function setup_ueid`, `function cleanup_ueid`.
- 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.