tools/testing/selftests/bpf/progs/net_timestamping.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/progs/net_timestamping.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/progs/net_timestamping.c- Extension
.c- Size
- 5631 bytes
- Lines
- 249
- 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_tracing_net.hbpf/bpf_helpers.hbpf/bpf_tracing.hbpf_misc.hbpf_kfuncs.herrno.h
Detected Declarations
struct sk_stgstruct sk_tskeystruct delay_infofunction bpf_test_sockoptfunction bpf_test_access_sockoptfunction bpf_test_access_load_hdr_optfunction bpf_test_access_cb_flags_setfunction bpf_test_access_bpf_callsfunction bpf_test_delayfunction BPF_PROGfunction skops_sockopt
Annotated Snippet
struct sk_stg {
__u64 sendmsg_ns; /* record ts when sendmsg is called */
};
struct sk_tskey {
u64 cookie;
u32 tskey;
};
struct delay_info {
u64 sendmsg_ns; /* record ts when sendmsg is called */
u32 sched_delay; /* SCHED_CB - sendmsg_ns */
u32 snd_sw_delay; /* SND_SW_CB - SCHED_CB */
u32 ack_delay; /* ACK_CB - SND_SW_CB */
};
struct {
__uint(type, BPF_MAP_TYPE_SK_STORAGE);
__uint(map_flags, BPF_F_NO_PREALLOC);
__type(key, int);
__type(value, struct sk_stg);
} sk_stg_map SEC(".maps");
struct {
__uint(type, BPF_MAP_TYPE_HASH);
__type(key, struct sk_tskey);
__type(value, struct delay_info);
__uint(max_entries, 1024);
} time_map SEC(".maps");
static u64 delay_tolerance_nsec = 10000000000; /* 10 second as an example */
extern int bpf_sock_ops_enable_tx_tstamp(struct bpf_sock_ops_kern *skops, u64 flags) __ksym;
static int bpf_test_sockopt(void *ctx, const struct sock *sk, int expected)
{
int tmp, new = SK_BPF_CB_TX_TIMESTAMPING;
int opt = SK_BPF_CB_FLAGS;
int level = SOL_SOCKET;
if (bpf_setsockopt(ctx, level, opt, &new, sizeof(new)) != expected)
return 1;
if (bpf_getsockopt(ctx, level, opt, &tmp, sizeof(tmp)) != expected ||
(!expected && tmp != new))
return 1;
return 0;
}
static bool bpf_test_access_sockopt(void *ctx, const struct sock *sk)
{
if (bpf_test_sockopt(ctx, sk, -EOPNOTSUPP))
return true;
return false;
}
static bool bpf_test_access_load_hdr_opt(struct bpf_sock_ops *skops)
{
u8 opt[3] = {0};
int load_flags = 0;
int ret;
ret = bpf_load_hdr_opt(skops, opt, sizeof(opt), load_flags);
if (ret != -EOPNOTSUPP)
return true;
return false;
}
static bool bpf_test_access_cb_flags_set(struct bpf_sock_ops *skops)
{
int ret;
ret = bpf_sock_ops_cb_flags_set(skops, 0);
if (ret != -EOPNOTSUPP)
return true;
return false;
}
/* In the timestamping callbacks, we're not allowed to call the following
* BPF CALLs for the safety concern. Return false if expected.
*/
static bool bpf_test_access_bpf_calls(struct bpf_sock_ops *skops,
const struct sock *sk)
{
if (bpf_test_access_sockopt(skops, sk))
return true;
Annotation
- Immediate include surface: `vmlinux.h`, `bpf_tracing_net.h`, `bpf/bpf_helpers.h`, `bpf/bpf_tracing.h`, `bpf_misc.h`, `bpf_kfuncs.h`, `errno.h`.
- Detected declarations: `struct sk_stg`, `struct sk_tskey`, `struct delay_info`, `function bpf_test_sockopt`, `function bpf_test_access_sockopt`, `function bpf_test_access_load_hdr_opt`, `function bpf_test_access_cb_flags_set`, `function bpf_test_access_bpf_calls`, `function bpf_test_delay`, `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.