Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
B
bcc
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
bcc
Commits
b06d97c1
Commit
b06d97c1
authored
Nov 28, 2016
by
4ast
Committed by
GitHub
Nov 28, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #820 from brendangregg/master
tcplife.py: Catch passive closed by server, #788
parents
70655ee8
4fd7d323
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
16 deletions
+16
-16
tools/tcplife.py
tools/tcplife.py
+16
-16
No files found.
tools/tcplife.py
View file @
b06d97c1
...
...
@@ -119,12 +119,16 @@ int kprobe__tcp_set_state(struct pt_regs *ctx, struct sock *sk, int state)
/*
* This tool includes PID and comm context. It's best effort, and may
* be wrong in some situations. It currently works like this:
* - active connections: cache PID & comm on TCP_SYN_SENT
* - passive connections: read PID & comm on TCP_LAST_ACK
*/
* - record timestamp on any state < TCP_FIN_WAIT1
* - cache task context on:
* TCP_SYN_SENT: tracing from client
* TCP_LAST_ACK: client-closed from server
* - do output on TCP_CLOSE:
* fetch task context if cached, or use current task
*/
// record PID & comm on SYN_SENT
if (state == TCP_SYN_SENT) {
if (state == TCP_SYN_SENT
|| state == TCP_LAST_ACK
) {
FILTER_PID
struct id_t me = {.pid = pid};
bpf_get_current_comm(&me.task, sizeof(me.task));
...
...
@@ -139,18 +143,18 @@ int kprobe__tcp_set_state(struct pt_regs *ctx, struct sock *sk, int state)
// timestamp is set.
u64 ts = bpf_ktime_get_ns();
birth.update(&sk, &ts);
return 0;
}
if (state != TCP_CLOSE)
return 0;
// fetch possible cached data
struct id_t *mep;
mep = whoami.lookup(&sk);
// passive connection closing; wait until TCP_LAST_ACK
if (mep == 0 && state != TCP_LAST_ACK)
return 0;
if (state == TCP_LAST_ACK) {
// fetch PID and filter
if (mep == 0) {
pid = mep->pid;
FILTER_PID
}
...
...
@@ -177,14 +181,11 @@ int kprobe__tcp_set_state(struct pt_regs *ctx, struct sock *sk, int state)
data4.saddr = sk->__sk_common.skc_rcv_saddr;
data4.daddr = sk->__sk_common.skc_daddr;
// a workaround until data4 compiles with separate lport/dport
data4.pid = pid;
data4.ports = ntohs(dport) + ((0ULL + lport) << 32);
if (mep == 0) {
data4.pid = pid;
bpf_get_current_comm(&data4.task, sizeof(data4.task));
bpf_trace_printk("state %d 0pid %d
\
\
n", state, pid);
} else {
data4.pid = mep->pid;
bpf_trace_printk("state %d mpid %d
\
\
n", state, mep->pid);
bpf_probe_read(&data4.task, sizeof(data4.task), (void *)mep->task);
}
ipv4_events.perf_submit(ctx, &data4, sizeof(data4));
...
...
@@ -199,11 +200,10 @@ int kprobe__tcp_set_state(struct pt_regs *ctx, struct sock *sk, int state)
sk->__sk_common.skc_v6_daddr.in6_u.u6_addr32);
// a workaround until data6 compiles with separate lport/dport
data6.ports = ntohs(dport) + ((0ULL + lport) << 32);
data6.pid = pid;
if (mep == 0) {
data6.pid = pid;
bpf_get_current_comm(&data6.task, sizeof(data6.task));
} else {
data6.pid = mep->pid;
bpf_probe_read(&data6.task, sizeof(data6.task), (void *)mep->task);
}
ipv6_events.perf_submit(ctx, &data6, sizeof(data6));
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment