Skip to content

Commit

Permalink
tcpaccept/tcpconnect: use PID not TID
Browse files Browse the repository at this point in the history
  • Loading branch information
brendangregg committed Apr 7, 2019
1 parent 1b9ae96 commit 8cd3efd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
4 changes: 2 additions & 2 deletions tools/tcpaccept.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
int kretprobe__inet_csk_accept(struct pt_regs *ctx)
{
struct sock *newsk = (struct sock *)PT_REGS_RC(ctx);
u32 pid = bpf_get_current_pid_tgid();
u32 pid = bpf_get_current_pid_tgid() >> 32;
##FILTER_PID##
Expand Down Expand Up @@ -177,7 +177,7 @@
return 0;
if (args->oldstate != TCP_SYN_RECV || args->newstate != TCP_ESTABLISHED)
return 0;
u32 pid = bpf_get_current_pid_tgid();
u32 pid = bpf_get_current_pid_tgid() >> 32;
##FILTER_PID##
Expand Down
16 changes: 10 additions & 6 deletions tools/tcpconnect.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,33 +89,37 @@
int trace_connect_entry(struct pt_regs *ctx, struct sock *sk)
{
u32 pid = bpf_get_current_pid_tgid();
u64 pid_tgid = bpf_get_current_pid_tgid();
u32 pid = pid_tgid >> 32;
u32 tid = pid_tgid;
FILTER_PID
u32 uid = bpf_get_current_uid_gid();
FILTER_UID
// stash the sock ptr for lookup on return
currsock.update(&pid, &sk);
currsock.update(&tid, &sk);
return 0;
};
static int trace_connect_return(struct pt_regs *ctx, short ipver)
{
int ret = PT_REGS_RC(ctx);
u32 pid = bpf_get_current_pid_tgid();
u64 pid_tgid = bpf_get_current_pid_tgid();
u32 pid = pid_tgid >> 32;
u32 tid = pid_tgid;
struct sock **skpp;
skpp = currsock.lookup(&pid);
skpp = currsock.lookup(&tid);
if (skpp == 0) {
return 0; // missed entry
}
if (ret != 0) {
// failed to send SYNC packet, may not have populated
// socket __sk_common.{skc_rcv_saddr, ...}
currsock.delete(&pid);
currsock.delete(&tid);
return 0;
}
Expand Down Expand Up @@ -148,7 +152,7 @@
ipv6_events.perf_submit(ctx, &data6, sizeof(data6));
}
currsock.delete(&pid);
currsock.delete(&tid);
return 0;
}
Expand Down

0 comments on commit 8cd3efd

Please sign in to comment.