Skip to content

Commit

Permalink
tcpstates: forget sockets when connection is closed
Browse files Browse the repository at this point in the history
The adress of struct sock, which are used as the map key, are often
reused. When it happens random duration appears in the MS field for
new connections (CLOSE->SYN_SENT and LISTEN->SYN_RECV
transitions). Let's forget about the socket when the connection is
closed.
  • Loading branch information
jeromemarchand authored and yonghong-song committed Mar 12, 2021
1 parent 0a04c41 commit 8bab454
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions tools/tcpstates.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,12 @@
ipv6_events.perf_submit(args, &data6, sizeof(data6));
}
u64 ts = bpf_ktime_get_ns();
last.update(&sk, &ts);
if (args->newstate == TCP_CLOSE) {
last.delete(&sk);
} else {
u64 ts = bpf_ktime_get_ns();
last.update(&sk, &ts);
}
return 0;
}
Expand Down Expand Up @@ -224,8 +228,12 @@
ipv6_events.perf_submit(ctx, &data6, sizeof(data6));
}
u64 ts = bpf_ktime_get_ns();
last.update(&sk, &ts);
if (state == TCP_CLOSE) {
last.delete(&sk);
} else {
u64 ts = bpf_ktime_get_ns();
last.update(&sk, &ts);
}
return 0;
Expand Down

0 comments on commit 8bab454

Please sign in to comment.