Skip to content

Commit

Permalink
[Fix] fix 3.10 bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
hengyoush committed Sep 10, 2024
1 parent 01f3ebf commit c501670
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 20 deletions.
6 changes: 3 additions & 3 deletions bpf/agent_x86_bpfel.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 3 additions & 6 deletions bpf/agentold_x86_bpfel.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 23 additions & 10 deletions bpf/pktlatency.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -1059,10 +1059,9 @@ static __always_inline void process_syscall_connect(void* ctx, int ret_val, str
// bpf_printk("process_syscall_connect, tgid:%lu, fd: %d", tgid, args->fd);
submit_new_conn(ctx, tgid, args->fd, args->addr, NULL, kRoleClient , args->start_ts);
}
static __always_inline void process_syscall_accept(struct pt_regs* ctx, struct accept_args *args, uint64_t id) {
static __always_inline void process_syscall_accept(void* ctx, long int ret, struct accept_args *args, uint64_t id) {
uint32_t tgid = id >> 32;
int ret_fd = _PT_REGS_RC(ctx);
if (ret_fd < 0) {
if (ret < 0) {
// bpf_printk("process_syscall_accept, ret_fd: %d, socket:%d", -ret_fd,args->sock_alloc_socket);
return;
}
Expand All @@ -1071,7 +1070,7 @@ static __always_inline void process_syscall_accept(struct pt_regs* ctx, struct a
return;
}
// bpf_printk("process_syscall_accept, tgid:%lu, ret_fd: %d, socket:%d", tgid,ret_fd,args->sock_alloc_socket);
submit_new_conn(ctx, tgid, ret_fd, args->addr, args->sock_alloc_socket, kRoleServer , 0);
submit_new_conn(ctx, tgid, ret, args->addr, args->sock_alloc_socket, kRoleServer , 0);
}

static __always_inline void process_syscall_data_vecs(void* ctx, struct data_args *args, uint64_t id, enum traffic_direction_t direct,
Expand Down Expand Up @@ -1581,14 +1580,28 @@ int BPF_KRETPROBE(sock_alloc_ret)
return 0;
}

SEC("kretprobe/__sys_accept4")
int BPF_KRETPROBE(sys_accept4_ret)
{
// SEC("kretprobe/__sys_accept4")
// int BPF_KRETPROBE(sys_accept4_ret)
// {
// uint64_t id = bpf_get_current_pid_tgid();
// struct accept_args *args = bpf_map_lookup_elem(&accept_args_map, &id);
// if (args != NULL) {
// process_syscall_accept(ctx, args, id);
// }
// bpf_map_delete_elem(&accept_args_map, &id);
// return 0;
// }

SEC("tracepoint/syscalls/sys_exit_accept4")
int tracepoint__syscalls__sys_exit_accept4(struct trace_event_raw_sys_exit *ctx) {
uint64_t id = bpf_get_current_pid_tgid();
struct accept_args *args = bpf_map_lookup_elem(&accept_args_map, &id);

if (args != NULL) {
process_syscall_accept(ctx, args, id);
}
long int ret;
TP_RET(&ret, ctx);
process_syscall_accept(ctx, ret, args, id);
}
bpf_map_delete_elem(&accept_args_map, &id);
return 0;
}
}
2 changes: 1 addition & 1 deletion bpf/prog.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func AttachSyscallAcceptEntry(programs interface{}) link.Link {
}

func AttachSyscallAcceptExit(programs interface{}) link.Link {
return kretprobe("__sys_accept4", GetProgram(programs, "SysAccept4Ret"))
return tracepoint("syscalls", "sys_exit_accept4", GetProgram(programs, "TracepointSyscallsSysExitAccept4"))
}

/* sock_alloc */
Expand Down

0 comments on commit c501670

Please sign in to comment.