tools/testing/selftests/bpf/progs/bpf_smc.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/progs/bpf_smc.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/progs/bpf_smc.c- Extension
.c- Size
- 3268 bytes
- Lines
- 142
- 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
vmlinux.hbpf/bpf_helpers.hbpf/bpf_tracing.hbpf_tracing_net.h
Detected Declarations
struct smc_sock___localstruct smc_hs_ctrl___localstruct netns_smc___localstruct net___localstruct smc_policy_ip_keystruct smc_policy_ip_valuefunction BPF_PROGfunction BPF_PROGfunction smc_checkfunction BPF_PROGfunction BPF_PROGfunction BPF_PROG
Annotated Snippet
struct smc_sock___local {
struct sock sk;
struct smc_sock *listen_smc;
bool use_fallback;
} __attribute__((preserve_access_index));
struct smc_hs_ctrl___local {
char name[SMC_HS_CTRL_NAME_MAX];
int (*syn_option)(struct tcp_sock *);
int (*synack_option)(const struct tcp_sock *, struct inet_request_sock *);
} __attribute__((preserve_access_index));
struct netns_smc___local {
struct smc_hs_ctrl___local *hs_ctrl;
} __attribute__((preserve_access_index));
struct net___local {
struct netns_smc___local smc;
} __attribute__((preserve_access_index));
int smc_cnt = 0;
int fallback_cnt = 0;
SEC("fentry/smc_release")
int BPF_PROG(bpf_smc_release, struct socket *sock)
{
/* only count from one side (client) */
if (sock->sk->__sk_common.skc_state == BPF_SMC_LISTEN)
return 0;
smc_cnt++;
return 0;
}
SEC("fentry/smc_switch_to_fallback")
int BPF_PROG(bpf_smc_switch_to_fallback, struct smc_sock___local *smc)
{
/* only count from one side (client) */
if (smc && !smc->listen_smc)
fallback_cnt++;
return 0;
}
/* go with default value if no strat was found */
bool default_ip_strat_value = true;
struct smc_policy_ip_key {
__u32 sip;
__u32 dip;
};
struct smc_policy_ip_value {
__u8 mode;
};
struct {
__uint(type, BPF_MAP_TYPE_HASH);
__uint(key_size, sizeof(struct smc_policy_ip_key));
__uint(value_size, sizeof(struct smc_policy_ip_value));
__uint(max_entries, 128);
__uint(map_flags, BPF_F_NO_PREALLOC);
} smc_policy_ip SEC(".maps");
static bool smc_check(__u32 src, __u32 dst)
{
struct smc_policy_ip_value *value;
struct smc_policy_ip_key key = {
.sip = src,
.dip = dst,
};
value = bpf_map_lookup_elem(&smc_policy_ip, &key);
return value ? value->mode : default_ip_strat_value;
}
SEC("fmod_ret/update_socket_protocol")
int BPF_PROG(smc_run, int family, int type, int protocol)
{
struct task_struct *task;
if (family != AF_INET && family != AF_INET6)
return protocol;
if ((type & 0xf) != SOCK_STREAM)
return protocol;
if (protocol != 0 && protocol != IPPROTO_TCP)
return protocol;
task = bpf_get_current_task_btf();
/* Prevent from affecting other tests */
Annotation
- Immediate include surface: `vmlinux.h`, `bpf/bpf_helpers.h`, `bpf/bpf_tracing.h`, `bpf_tracing_net.h`.
- Detected declarations: `struct smc_sock___local`, `struct smc_hs_ctrl___local`, `struct netns_smc___local`, `struct net___local`, `struct smc_policy_ip_key`, `struct smc_policy_ip_value`, `function BPF_PROG`, `function BPF_PROG`, `function smc_check`, `function BPF_PROG`.
- 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.