Victor Julien [Wed, 26 Jun 2019 10:22:33 +0000 (12:22 +0200)]
decoder/vxlan: improvements and cleanups
Implement port config handling. Also check both src port and dest
port for tunnels that only set the destination port to the VXLAN
port. At the point of the check we don't know the packet direction
yet.
Victor Julien [Fri, 21 Jun 2019 11:14:21 +0000 (13:14 +0200)]
mem: fix shadow declaration warning
Avoid clash by adding a leading underscore to the declaration in the
macro. These temporary vars should never clash with valid variables
from the code where they are called from.
Victor Julien [Wed, 19 Jun 2019 10:53:52 +0000 (12:53 +0200)]
detect: pkt inspect engines
Instead of hard coded calls to the inspection logic for
payload inspection and 'MATCH'-list inspection use a callback
approach. This will register a callback per 'sm_list' much like
how app-layer inspect engines are registered.
This will allow for adding more types later without adding
runtime overhead.
Implement the callback for the PMATCH and MATCH logic.
Jeff Lucovsky [Tue, 11 Jun 2019 22:53:35 +0000 (18:53 -0400)]
rust/parser: Extend Rust parser for event-by-id
Extend the Rust parsing infrastructure with the "get event info by id"
calls. This changeset extends the parser structure, the C-based
registration handlers and the template parser.
Jeff Lucovsky [Sat, 25 May 2019 20:38:45 +0000 (13:38 -0700)]
eve/logging: 2991 Optimize logging by TX
This changeset makes changes to the TX logging path. Since the txn
is passed to the TX logger, the TX can be used directly instead of
through the TX id.
Jeff Lucovsky [Tue, 21 May 2019 21:56:32 +0000 (14:56 -0700)]
logging/anomaly: Track event log progress
This changeset adds a mechanism to track when individual events
are logged. Transactions can be provided more than once; track
events to prevent event re-logging.
Victor Julien [Tue, 18 Jun 2019 13:58:36 +0000 (15:58 +0200)]
mingw: fix compile error
Declare _POSIX_C_SOURCE before sys/time.h to avoid:
util-time.c: In function 'SCUtcTime':
util-time.c:222:12: error: implicit declaration of function 'gmtime_r'; did you mean 'gmtime_s'? [-Werror=implicit-function-declaration]
222 | return gmtime_r(&timep, result);
| ^~~~~~~~
| gmtime_s
util-time.c:222:12: warning: returning 'int' from a function with return type 'struct tm *' makes pointer from integer without a cast [-Wint-conversion]
222 | return gmtime_r(&timep, result);
| ^~~~~~~~~~~~~~~~~~~~~~~~
util-time.c: In function 'SCLocalTime':
util-time.c:305:9: error: implicit declaration of function 'localtime_r'; did you mean 'localtime_s'? [-Werror=implicit-function-declaration]
305 | localtime_r(&timep, &cached_local_tm[lru]);
| ^~~~~~~~~~~
| localtime_s
util-time.c:321:56: warning: comparison between pointer and integer
321 | if (localtime_r(&timep, &cached_local_tm[lru]) == NULL)
| ^~
cc1.exe: some warnings being treated as errors
Eric Leblond [Tue, 11 Jun 2019 20:21:45 +0000 (22:21 +0200)]
bypass: add counter for local captured bypass
Packets from captured bypassed flows that are received by Suricata
before the capture method start to bypass them can represent an
important part due to various buffer and insertion delay.
This patch adds a two counters to know the number of packets and
bytes in this case.
Eric Leblond [Mon, 10 Jun 2019 14:40:47 +0000 (16:40 +0200)]
af-packet: better accounting and error handling
This patch improves the bypass error handling add adds more counters
to the interface so it is possible to get a view on success and
failure of insertion in the eBPF maps via the `iface-bypassed-stat`
command.
Eric Leblond [Sat, 8 Jun 2019 16:11:22 +0000 (18:11 +0200)]
bypass: new callback stragegy
This patch introduces and uses a new bypass strategy
based on a callback. EBPF bypass implementation is
updated to use this new strategy.
Once the flow manager detect that a flow should be timeouted,
it asks the capture method if it has seen packets in the interval.
If it is the case the lastts of the flow is updated and the timeout
is postponed.
Eric Leblond [Wed, 5 Jun 2019 13:12:13 +0000 (15:12 +0200)]
bypass: fix accounting
The flow bypass stats is computed at every pass so the accounting
needs to be done at each pass. This patch fixes the accounting
in the flow_bypassed counters.
Eric Leblond [Tue, 4 Jun 2019 11:49:32 +0000 (13:49 +0200)]
util-ebpf: more useful error message
At the time of the writing, libbpf output useful error message
on strdout only and errno is not really interesting. So let's
tell user to look at stdout.
Eric Leblond [Sat, 1 Jun 2019 15:04:40 +0000 (17:04 +0200)]
ebpf: don't use nexthdr to build hash
As pointed by Victor Julien, it is not a good idea to use the
nexthdr value, as init key for the hash as it could contain some
other headers and can be changed for a session.
Eric Leblond [Sat, 25 May 2019 14:04:03 +0000 (16:04 +0200)]
bypass: allow bypass for packet without flow
For capture method that have their own flow structure (not maintained
by Suricata), it can make sense to bypass a packet even if there is
no Flow in Suricata.
For AF_PACKET it does not make sense as the eBPF map entry will
be destroyed as soon as it will be checked by the flow bypass
manager. Thus we shortcut the bypass function if ever no Flow is
attached to the packet.
This path also removes reference to Flow in the bypass functions
for AF_PACKET. It was not necessary and we possibly could benefit
of it if ever we change the bypass algorithm.
Eric Leblond [Sun, 24 Mar 2019 18:47:02 +0000 (19:47 +0100)]
bypass: use flow storage for bypass counter
There is a synchronization issue occuring when a flow is
added to the eBPF bypass maps. The flow can have packets
in the ring buffer that have already passed the eBPF stage.
By consequences, they are not accounted in the eBPF counter
but are accounted by Suricata flow engine.
This was causing counters to be completely wrong. This code
fixes the issue by avoiding the counter change in invalid
case.
To avoid adding 4 64bits integers to the Flow structure for the
bypass accounting, we use instead a FlowStorage. This limits the
memory usage to the size of a pointer.
Eric Leblond [Sat, 11 May 2019 09:43:59 +0000 (11:43 +0200)]
ebpf: add vlan tracking option to xdp_filter
If vlan is not use for tracking in Suricata this result in vlan not
being used in the flow key in Suricata and we need to adjust that
in the XDP filter to avoid any problem.
Eric Leblond [Sat, 11 May 2019 09:14:23 +0000 (11:14 +0200)]
ebpf: tls encrypted bypass in xdp_filter
Tests have shown that when we bypass encrypted traffic a non
neglicteable amount of encrypted packets of the session are already in the
capture ring buffer. Result is that Suricata is doing unnecessary
work on these packets.
These packets can be identified via the first bytes of their payloads
so we can bypass them directly in the XDP code. This is done here
for application data packets on port 443 and for TLS 1.2.