-
Notifications
You must be signed in to change notification settings - Fork 61
add probes on fd_install to catch accept events before kretprobe was installed #39
Conversation
Could we avoid this by making the probe on |
Not sure how to do that, but this would involve more complicated offset guessing to inspect the |
ee23432
to
58f9bf1
Compare
I rebased this on top of #37 because I needed to revendor gobpf for iovisor/gobpf#45 but this also brings other gobpf API changes that cause tcptracer-bpf changes that were already done in #37. |
tests/tracer.go
Outdated
if len(os.Args) != 1 { | ||
fmt.Fprintf(os.Stderr, "Usage: %s\n", os.Args[0]) | ||
if len(os.Args) > 2 { | ||
fmt.Fprintf(os.Stderr, "Usage: %s pid\n", os.Args[0]) |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
dac0b87
to
3b09ef1
Compare
I added a test and it passes in Semaphore with Linux 4.4.45 and 4.9.6. It works as well on my laptop with Linux 4.10.10. |
62db57c
to
ac7da48
Compare
I updated this PR:
|
960d222 Merge pull request #97 from kinvolk/alban/update-shfmt-3 1d535c7 shellcheck: fix escaping issue git-subtree-dir: tools git-subtree-split: 960d2228b3c967d28b7cb329d020f44b55429d94
Since weaveworks/build-tools#97 is merged, I rebased & updated the "git subtree". But this time, there are new errors (see weaveworks/build-tools#99) |
Symptoms: ``` Step 4 : RUN go get -u gopkg.in/mvdan/sh.v1/cmd/shfmt ---> Running in 0438ed51be8b go/src/gopkg.in/mvdan/sh.v1/cmd/shfmt/main.go:26: undefined: "github.com/mvdan/sh/syntax".ParseMode go/src/gopkg.in/mvdan/sh.v1/cmd/shfmt/main.go:27: undefined: "github.com/mvdan/sh/syntax".PrintConfig go/src/gopkg.in/mvdan/sh.v1/cmd/shfmt/main.go:46: undefined: "github.com/mvdan/sh/syntax".ParseComments go/src/gopkg.in/mvdan/sh.v1/cmd/shfmt/main.go:48: undefined: "github.com/mvdan/sh/syntax".PosixConformant go/src/gopkg.in/mvdan/sh.v1/cmd/shfmt/main.go:73: undefined: "github.com/mvdan/sh/syntax".Parse go/src/gopkg.in/mvdan/sh.v1/cmd/shfmt/main.go:139: undefined: "github.com/mvdan/sh/syntax".Parse The command '/bin/sh -c go get -u gopkg.in/mvdan/sh.v1/cmd/shfmt' returned a non-zero code: 2 make: *** [build-docker-image] Error 2 ```
I added a commit that fixes the error. The Dockerfile now uses shfmt with another importpath. Thanks @tomwilkie for the hint in weaveworks/build-tools#99 (comment) @2opremio PTAL |
EventConnect EventType = 1 | ||
EventAccept = 2 | ||
EventClose = 3 | ||
EventConnect EventType = 1 |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
{ | ||
u64 pid = bpf_get_current_pid_tgid(); | ||
u32 tgid = pid >> 32; | ||
unsigned long fd = (unsigned long) PT_REGS_PARM1(ctx); |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
Minor comment, otherwise LGTM |
@2opremio I think I replied to the comment. Someone with merge-powers could merge this :) |
Merging, but let's continue the comment thread on LLVM please. |
This includes weaveworks/tcptracer-bpf#39
Since weaveworks/tcptracer-bpf#39, tcptracer-bpf can generate "fd_install" events when a process installs a new file descriptor in its fd table. Those events must be requested explicitely on a per-pid basis with tracer.AddFdInstallWatcher(pid). This is useful to know about "accept" events that would otherwise be missed because kretprobes are not triggered for functions that were called before the installation of the kretprobe. This patch find all the processes that are currently blocked on an accept() syscall during the EbpfTracker initialization. feedInitialConnections() will use tracer.AddFdInstallWatcher() to subscribe to fd_install events. When a fd_install event is received, synthesise an accept event with the connection tuple and the network namespace (from /proc).
Since weaveworks/tcptracer-bpf#39, tcptracer-bpf can generate "fd_install" events when a process installs a new file descriptor in its fd table. Those events must be requested explicitely on a per-pid basis with tracer.AddFdInstallWatcher(pid). This is useful to know about "accept" events that would otherwise be missed because kretprobes are not triggered for functions that were called before the installation of the kretprobe. This patch find all the processes that are currently blocked on an accept() syscall during the EbpfTracker initialization. feedInitialConnections() will use tracer.AddFdInstallWatcher() to subscribe to fd_install events. When a fd_install event is received, synthesise an accept event with the connection tuple and the network namespace (from /proc).
First start a process that will block in the
accept()
syscall:Once the
accept()
syscall has started, start the tcptracer-bpf tool:Makes the
accept()
syscall return:Notice that we get the "connect" event as normal. The "accept" event is missing because of #10 but we get the new event "fdinstall" that says that the process 16389 received the new file descriptor 4:
Weave Scope would need to iterate over
/proc
to find all the processes blocked on theaccept
syscall (/proc/$pid/wchan
will showinet_csk_accept
) and then request the tracker to monitor fd_install on them:We don't notify fd_install events for all processes because that would be too much. Instead, Scope would only request the notification for specific pids. Internally, this uses a hash map to keep track of the pids to monitor or not.
We don't need any new offset guessing for this because we don't dereference any kernel structures in the fd_install kprobes.
This is for #10
Depends on:
TODO
fd
in the event struct/cc @iaguis @2opremio