要在BPF中追踪TCP套接字的状态,你可以使用bpf_sock_ops结构体来获取套接字的相关信息。以下是一个简单的BPF程序示例,它将输出新建连接的五元组信息: #include <linux/bpf.h> #include <bpf/bpf_helpers.h> #include <bpf/bpf_tracing.h> char LICENSE[] SEC("license") = "Dual BSD/GPL"; SEC("sock...
struct bpf_struct_ops_tcp_congestion_ops { refcount_t refcnt; enum bpf_struct_ops_state state; struct tcp_congestion_ops data; /* <-- kernel subsystem struct here */ } The map value is "struct bpf_struct_ops_tcp_congestion_ops". The "bpftool map dump" will then be able to show th...
3.BPF_MAP_TYPE_STRUCT_OPS映射表:eBPF通过创建一种新的映射表类型BPF_MAP_TYPE_STRUCT_OPS,将eBPF程序中的结构体与内核中的原生结构体进行关联。在这个过程中,eBPF可以通过BPF_MAP_UPDATE的方式替换原有的内核结构体中的函数指针,指向eBPF程序中的实现。 4.内核的BTF解析:内核通过BTF(BPF Type Format)信息识别...