Commit Graph

162 Commits

Author SHA1 Message Date
Matthias Radestock
b52b2078ca refactor: remove unnecessary conditional
we always have a flowWalker when not using ebpf
2017-05-25 23:04:45 +01:00
Matthias Radestock
b80a51bc39 cosmetic: remove outdated comment
we now do correctly fall back to proc scanning when eBPF fails
2017-05-25 23:04:45 +01:00
Matthias Radestock
a6cc8ece4f simplify connection tracker initialization
- eliminate the code duplication when falling back to procfs scanning
- trim some superfluous comments

Also fix a bug in the procvess: when falling back to procfs scanning
in ReportConnections, the scanner was given a "--any-nat" param, which
is wrong.
2017-05-25 23:02:19 +01:00
Alban Crequy
d715ccc391 ebpf: handle fd_install events from tcptracer-bpf
Since https://github.com/weaveworks/tcptracer-bpf/pull/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).
2017-05-19 14:49:38 +02:00
Alfonso Acosta
dbdb648ada Merge pull request #2527 from weaveworks/2494-track-non-natted-shortlived-conns
Let conntrack track non-NATed short-lived connections
2017-05-19 01:42:02 +02:00
Alfonso Acosta
7497c7d432 Let conntrack track non-NATed short-lived connections 2017-05-16 23:15:16 +00:00
Alban Crequy
9079677873 ebpf tracker: add callback for lost events
Lost events were previously unnoticed. This patch adds an error in the
log and stops the ebpf tracker if an event is lost.
2017-05-10 18:37:32 +02:00
Michael Schubert
1d1f7347ce proc_linux: don't exec getNetNamespacePathSuffix() on every walk 2017-04-19 12:49:04 +02:00
Bryan Boreham
515f4b1a47 Make various anonymous fields named
Anonymous fields make any methods on the inner object visible on the
outer, so they should only be used when the outer is-a inner.
2017-04-01 11:35:10 +00:00
Michael Schubert
cd25b8b935 endpoint/ebpf: implement stop
Since d60874aca8 `connectionTracker` can
fallback when the `EbpfTracker` died. Hence we only have to stop the
`tracer` in `stop()`.

This commit is also a fixup for d60874aca8
where we do a gentle fallback but never actually stop the tracer to stop
polling.
2017-03-21 14:42:34 +01:00
Michael Schubert
5572895a2b ebpf_test: tracker set to dead after out of order events 2017-03-17 16:50:25 +01:00
Michael Schubert
5262e0765d reader_linux: only access latestBuf when set
.. and avoid nil pointer dereference. It can happen that
`getWalkedProcPid` is called before the first `performWalk` finished.
2017-03-17 14:43:31 +01:00
Michael Schubert
d60874aca8 Fallback to proc when ebpf timestamps are wrong 2017-03-17 14:43:31 +01:00
Michael Schubert
22ae6c45a0 Implement ebpf proc fallback 2017-03-14 13:59:09 +01:00
Michael Schubert
5f2ba891a4 endpoint/reporter: only stop scanner if not nil 2017-03-14 11:56:04 +01:00
Michael Schubert
ce904fc56c Remove redundant arg from newEbpfTracker 2017-03-14 11:56:04 +01:00
Iago López Galeiras
9920c4ea48 Add eBPF connection tracking without dependencies on kernel headers
Based on work from Lorenzo, updated by Iago, Alban, Alessandro and
Michael.

This PR adds connection tracking using eBPF. This feature is not enabled by default.
For now, you can enable it by launching scope with the following command:

```
sudo ./scope launch --probe.ebpf.connections=true
```

This patch allows scope to get notified of every connection event,
without relying on the parsing of /proc/$pid/net/tcp{,6} and
/proc/$pid/fd/*, and therefore improve performance.

We vendor https://github.com/iovisor/gobpf in Scope to load the
pre-compiled ebpf program and https://github.com/weaveworks/tcptracer-bpf
to guess the offsets of the structures we need in the kernel. In this
way we don't need a different pre-compiled ebpf object file per kernel.
The pre-compiled ebpf program is included in the vendoring of
tcptracer-bpf.

The ebpf program uses kprobes/kretprobes on the following kernel functions:
- tcp_v4_connect
- tcp_v6_connect
- tcp_set_state
- inet_csk_accept
- tcp_close

It generates "connect", "accept" and "close" events containing the
connection tuple but also pid and netns.
Note: the IPv6 events are not supported in Scope and thus not passed on.

probe/endpoint/ebpf.go maintains the list of connections. Similarly to
conntrack, it also keeps the dead connections for one iteration in order
to report short-lived connections.

The code for parsing /proc/$pid/net/tcp{,6} and /proc/$pid/fd/* is still
there and still used at start-up because eBPF only brings us the events
and not the initial state. However, the /proc parsing for the initial
state is now done in foreground instead of background, via
newForegroundReader().

NAT resolution on connections from eBPF works in the same way as it did
on connections from /proc: by using conntrack. One of the two conntrack
instances is only started to get the initial state and then it is
stopped since eBPF detects short-lived connections.

The Scope Docker image size comparison:
- weaveworks/scope in current master:  22 MB (compressed),  68 MB
  (uncompressed)
- weaveworks/scope with this patchset: 23 MB (compressed), 69 MB
  (uncompressed)

Fixes #1168 (walking /proc to obtain connections is very expensive)

Fixes #1260 (Short-lived connections not tracked for containers in
shared networking namespaces)

Fixes #1962 (Port ebpf tracker to Go)

Fixes #1961 (Remove runtime kernel header dependency from ebpf tracker)
2017-03-08 22:11:12 +01:00
Alfonso Acosta
6347238f10 Review feedback 2017-01-27 13:05:50 +00:00
Alfonso Acosta
7ae94a8c8a DNSSnooper: Support Dot1Q and limit decoding errors 2017-01-27 10:59:33 +00:00
Alban Crequy
f1e2b5d93a probe: conntrack: fix output parsing
With net.netfilter.nf_conntrack_acct = 1, conntrack adds the following
fields in the output: packets=3 bytes=164

And with SELinux (e.g. Fedora), conntrack adds: secctx=...

The parsing with fmt.Sscanf introduced in #2095 was unfortunately
rejecting lines with those fields. This patch fixes that by adding more
complicated parsing in decodeFlowKeyValues() with FieldsFunc and SplitN.

Fixes #2117
Regression from #2095
2017-01-17 19:30:56 +01:00
Alfonso Acosta
496e3f2072 Merge pull request #2114 from weaveworks/1972-non-established-proc-conns
Report persistent connections in states other than ESTABLISHED
2017-01-17 10:45:53 +01:00
Alfonso Acosta
2be26e2be4 Limit connections to established and half-closed 2017-01-10 15:35:32 +00:00
Alfonso Acosta
89a0ab6799 Fix test data and improve /proc/net/tcp header parsing
The header checking code was unsafe because:

1. It was accessing the byteslice at [2] without ensuring a length >= 3
2. It was assuming that the indentation of the 'sl' header is always 2 (which seems to be the case in recent kernels 8f18e4d03e/net/ipv4/tcp_ipv4.c (L2304) and 8f18e4d03e/net/ipv6/tcp_ipv6.c (L1831) ) but it's more robust to simply trim the byteslice.
2017-01-04 00:27:16 +00:00
Alfonso Acosta
99a7dc3b9a Fix tests 2017-01-03 23:34:32 +00:00
Alfonso Acosta
a8b4e65b5c Make linter happy 2017-01-03 22:55:28 +00:00
Alfonso Acosta
7716d96810 Report persistent connections in states other than ESTABLISHED
This aligns the `/proc` connection tracking (persistent connections) with
conntrack (short-lived connections).
2017-01-03 18:38:02 +00:00
Alfonso Acosta
b4e1fc7074 Merge pull request #2112 from weaveworks/2032-ensure-conntrack-events
Check that conntrack events are enabled in the kernel
2017-01-02 23:11:52 +01:00
Alfonso Acosta
5c3ea83846 Fix minor typo 2017-01-02 14:28:22 +00:00
Alfonso Acosta
dfb52f0d93 Clarify even further that proc/PID/net/tcp varies by namespace 2017-01-02 14:27:37 +00:00
Alfonso Acosta
64f1a5d0f5 Check that conntrack events are enabled in the kernel 2017-01-02 09:22:26 +00:00
Alfonso Acosta
9d352e96f5 Review feedback 2016-12-22 09:33:52 +00:00
Alfonso Acosta
d22d64c710 Cleanup
* Remove XML traces
* Improve performance
* Fix tests
2016-12-21 19:35:37 +00:00
Alfonso Acosta
f19889f63c Reduce garbage 2016-12-19 19:30:23 +00:00
Alfonso Acosta
5c02dfcbd2 Complete hacky manual parser 2016-12-19 11:30:00 +00:00
Alfonso Acosta
710c3bf82e [WIP] Diable XML in conntrack parsing
Not working yet
2016-12-19 11:30:00 +00:00
Alfonso Acosta
07aee0ed97 Merge pull request #2020 from kinvolk/alban/fix-getWalkedProcPid
procspy: use a Reader to copy the background reader buffer
2016-12-07 12:53:53 +01:00
Jonathan Lange
1020fc5f85 Use test.Diff from common 2016-12-07 11:22:40 +00:00
Jonathan Lange
b5c750ddea Move test & fs 2016-12-07 11:22:39 +00:00
Jonathan Lange
e8085b01b6 Use 'common' library 2016-12-07 11:22:38 +00:00
Alban Crequy
543f3d5bdc procspy: use a Reader to copy the background reader buffer
getWalkedProcPid() reads latestBuf every 3 seconds (for each report).
But performWalk() writes latestBuf every 10 seconds or so. So we need to
be able to read the same buffer several times.
2016-12-05 18:12:11 +01:00
Alfonso Acosta
6ed79a7427 Merge pull request #1897 from weaveworks/stricter-dns-over-tcp-snooping
Be more strict when snooping DNS over TCP traffic
2016-09-27 21:12:35 +02:00
Alfonso Acosta
45a9367d97 Be more strict when snooping DNS over TCP traffic 2016-09-27 12:48:25 +00:00
Tom Wilkie
b130f1ba13 Allow users to specify conntrack buffer size. (#1896)
* Allow users to specify conntrack buffer size.

* Fix tests.

* Use a config struct.
2016-09-26 12:08:38 -07:00
Alfonso Acosta
326208c395 Skip DNS length field (only included over TCP) 2016-09-23 13:57:39 +00:00
Alfonso Acosta
6f95d05c59 Add support for snooping DNS over TCP 2016-09-23 12:41:32 +00:00
Alfonso Acosta
c5ac315b38 Review feedback 2016-09-20 16:50:29 +00:00
Alfonso Acosta
f5ad6a8e97 Minor fixes/refinements 2016-09-19 14:38:59 +00:00
Alfonso Acosta
028ed32b6f Simplify service node matching 2016-09-19 14:38:59 +00:00
Alfonso Acosta
0223b0b385 Implement DNS snooper 2016-09-19 14:38:59 +00:00
Matthias Radestock
9d010fabc8 refactor: extract makeEndpointNode helper 2016-09-02 21:12:23 +01:00