Commit Graph

183 Commits (74761b04fe8bf4da82bdacba64ff93009bc0a7e1)

Author SHA1 Message Date
Victor Julien b86e176262 af-packet: suppress noisy info message 7 years ago
Victor Julien efbb5ce0fe afpacket: fix formatting of errors 7 years ago
Eric Leblond fcd5e138b9 af-packet: close the socket in case of early fail 7 years ago
fooinha f67aa5deaa packet: gre over ip link type 7 years ago
Eric Leblond 6062c27eb7 af-packet: kill some white spaces 7 years ago
Eric Leblond f53e687bb8 af-packet: dump counters when timeout occurs
When traffic is becoming null (mainly seen in tests) we reach the
situation where there is timeouts in the poll on the socket and
only that. Existing code is then just looping on the poll and
the result is that the packet iface counters are not updated.

This patch calls the dump counter function to be sure to get
the counter right faster (and not only right at exit).
7 years ago
Eric Leblond 194751654f af-packet: count only CPUs once 8 years ago
Eric Leblond f04391031f af-packet: XDP bypass in IPS mode
Implement XDP bypass in IPS mode by using XDP redirect to send
packets from bypassed flow directly to the transmission interface.
8 years ago
Eric Leblond 94a622cb55 af-packet: add comments to eBPF/XDP code 8 years ago
Eric Leblond 3379311e66 af-packet: fix error handling in bypass case
If the key is already in the hash table then the bypass is
succesful.
8 years ago
Eric Leblond 2598078ee6 af-packet: code cleaning and comments 8 years ago
Eric Leblond cde438f670 af-packet: add missing copyright header
And also fixes the copyright date in some files.
8 years ago
Eric Leblond 1e729f059f af-packet: improve xdp error handling
Don't try to bypass the flow if the flow table is unknown.

Also continue after error message if ever XDP was not correctly
setup.
8 years ago
Eric Leblond 126488f74d af-packet: add support for multi iface bypass 8 years ago
Eric Leblond 9cb591aa6c af-packet: remove done fixme in XDP 8 years ago
Eric Leblond eff10fce10 af-packet: end of map factoring 8 years ago
Eric Leblond d65f45856c af-packet: cache map fd search 8 years ago
Eric Leblond 17a32bdaa0 af-packet: fix bypassing of IPv6
Also misc fixes.
8 years ago
Eric Leblond 8c88087948 af-packet: implementation of XDP bypass
This patch adds support for XDP bypass. It provides an XDP
filter that can be loaded to realize the bypass of flows.
8 years ago
Eric Leblond 06173267c6 af-packet: kernel bypass implementation
This patch implements bypass capability for af-packet.

The filter only bypass TCP and UDP in IPv4 and IPv6. It don't
don't bypass IPv6 with extended headers.

This patch also introduces a bypassed flow manager that takes
care of timeouting the bypassed flows. It uses a 60 sec
timeout on flow. As they are supposed to be active we can
try that. If they are not active then we don't care to get them
back in Suricata.
8 years ago
Eric Leblond 91e1256b01 af-packet: add support for eBPF cluster and filter
This patch introduces the ebpf cluster mode. This mode is using
an extended BPF function that is loaded into the kernel and
provide the load balancing.

An example of cluster function is provided in the ebpf
subdirectory and provide ippair load balancing function.
This is a function which uses the same method as
the one used in autofp ippair to provide a symetrical
load balancing based on IP addresses.

A simple filter example allowing to drop IPv6 is added to the
source.

This patch also prepares the infrastructure to be able to load
and use map inside eBPF files. This will be used later for flow
bypass.
8 years ago
Alexander Gozman cba41207b3 af_packet: bug #2422.
This commit fixes a leak of mmap'ed ring buffer that was not
unmaped when a socket was closed. In addition, the leak could
break an inline channel on certain configurations.

Also slightly changed AFPCreateSocket():
1. If an interface is not up, it does not try to apply any
   settings to a socket. This reduces a number of error messages
   while an interface is down.
2. Interface is considered active if both IFF_UP and IFF_RUNNING
   are present.
8 years ago
Eric Leblond 4bfa3aeaf9 af-packet: synchronize flags sizes
They are passed from config to threads so they need to be of the
same size.
8 years ago
Eric Leblond ce59ec5d13 af-packet: free ring buffer at exit 8 years ago
Victor Julien 746638b220 cuda: remove
Remove CUDA support as it has been broken for a long time.

Ticket #2382.
8 years ago
Eric Leblond 8fa6e065bc af-packet: free bpf program
This fixes a small memory leak when Suricata is running with a
BPF filter.
8 years ago
Eric Leblond 7127ae2b44 af-packet: call thread deinit function 8 years ago
Victor Julien f47df5a671 afpacket: free ring mem on error 8 years ago
Alexander Gozman 39807b47cb Bug #2201: af_packet - treat BPF filter error as fatal
There is no need to try to set erroneous BPF filter again and again. Such attempts
lead to constant mmap() calls without corresponding munmap() when 'use-mmap' is enabled.
8 years ago
Eric Leblond cc82ef065c af-packet: optimize BPF
This patch turn on code optimization on BPF filter building by
libpcap. This allow to reduce the size of the BPF bytecode and
thus increase the size of BPF filter supported by Suricata.

Reported-by: Martijn van Oosterhout
8 years ago
Victor Julien ab1200fbd7 compiler: more strict compiler warnings
Set flags by default:

    -Wmissing-prototypes
    -Wmissing-declarations
    -Wstrict-prototypes
    -Wwrite-strings
    -Wcast-align
    -Wbad-function-cast
    -Wformat-security
    -Wno-format-nonliteral
    -Wmissing-format-attribute
    -funsigned-char

Fix minor compiler warnings for these new flags on gcc and clang.
8 years ago
Victor Julien 6227d0955f af-packet: fix cppcheck false positive
[src/source-af-packet.c:1903]: (error) Resource leak: fd
8 years ago
Alexander Gozman 310b27a196 af-packet: fix parsing packet in TPACKET_V3 mode
AFPParsePacketV3() saved tpacket_block_desc structure
instead of tpacket3_hdr. As a result, reconstructed
packets were wrong.

Bug #2044.
8 years ago
Alexander Gozman e41a9d637b af-packet: get VLAN info for packets in TPACKET_V3 mode 8 years ago
Alexander Gozman ee7e689b54 af-packet: write VLAN info for both TPACKET_V2 and V3 8 years ago
Eric Leblond ecf59be413 af-packet: add VLAN header when needed in IPS mode
When packet is coming from a real ethernet card, the kernel is
stripping the vlan header and delivering a modified packet so
we need to insert the VLAN header back before sending the packet
on the wire.

To do so, we pass an option to the raw socket to add a reserve
before the packet data. It will get Suricata some head room to
to move the ethernet addresses before there actual place and
and insert the VLAN header in the correct place.

We get VLAN info from the ring buffer as the call of AFPWrite is
always done in the release function so we still have access to the
memory.
9 years ago
Victor Julien ab8faefd37 af-packet: fix fanout support on Debian Jessie
Debian Jessie with kernel 3.16 would not accept the 'id' of 99 used
in the test. Id 1 does work.
9 years ago
Victor Julien 85db260eed threads: remove EngineKill & SURICATA_KILL
EngineStop and EngineKill were effectively doing the same, so
removed the kill variant.
9 years ago
Victor Julien 4111331ab0 af-packet: minor cleanups 9 years ago
Victor Julien 402bdf9b2b af-packet: test if fanout is supported before use
Older system may pretend they can support FANOUT but then fail to
work at runtime. CentOS6 is an example of this. It would fail to
start up with the default configuration with errors like:

[15770] 21/6/2016 -- 16:00:13 - (tm-threads.c:2168) <Notice> (TmThreadWaitOnThreadInit) -- all 4 packet processing threads, 4 management threads initialized, engine started.
[15785] 21/6/2016 -- 16:00:13 - (source-af-packet.c:1907) <Error> (AFPCreateSocket) -- [ERRCODE: SC_ERR_AFP_CREATE(190)] - Coudn't set fanout mode, error Protocol not available
[15785] 21/6/2016 -- 16:00:13 - (source-af-packet.c:1337) <Error> (ReceiveAFPLoop) -- [ERRCODE: SC_ERR_AFP_CREATE(190)] - Couldn't init AF_PACKET socket, fatal error
[15770] 21/6/2016 -- 16:00:13 - (suricata.c:2664) <Notice> (main) -- Signal Received.  Stopping engine.
[15787] 21/6/2016 -- 16:00:13 - (source-af-packet.c:1907) <Error> (AFPCreateSocket) -- [ERRCODE: SC_ERR_AFP_CREATE(190)] - Coudn't set fanout mode, error Protocol not available
[15788] 21/6/2016 -- 16:00:13 - (source-af-packet.c:1907) <Error> (AFPCreateSocket) -- [ERRCODE: SC_ERR_AFP_CREATE(190)] - Coudn't set fanout mode, error Protocol not available
[15786] 21/6/2016 -- 16:00:13 - (source-af-packet.c:1907) <Error> (AFPCreateSocket) -- [ERRCODE: SC_ERR_AFP_CREATE(190)] - Coudn't set fanout mode, error Protocol not available
[15789] 21/6/2016 -- 16:00:13 - (flow-manager.c:693) <Perf> (FlowManager) -- 0 new flows, 0 established flows were timed out, 0 flows in closed state
[15787] 21/6/2016 -- 16:00:13 - (source-af-packet.c:1337) <Error> (ReceiveAFPLoop) -- [ERRCODE: SC_ERR_AFP_CREATE(190)] - Couldn't init AF_PACKET socket, fatal error
[15788] 21/6/2016 -- 16:00:13 - (source-af-packet.c:1337) <Error> (ReceiveAFPLoop) -- [ERRCODE: SC_ERR_AFP_CREATE(190)] - Couldn't init AF_PACKET socket, fatal error
[15786] 21/6/2016 -- 16:00:13 - (source-af-packet.c:1337) <Error> (ReceiveAFPLoop) -- [ERRCODE: SC_ERR_AFP_CREATE(190)] - Couldn't init AF_PACKET socket, fatal error

This patch adds a test that if run before the number of threads
is determined. If the test fails, only 1 thread is created.
9 years ago
Victor Julien b3bf7a5729 output: introduce config and perf output levels
Goal is to reduce info output
9 years ago
Eric Leblond 291af719c6 coverity: fix CID 1362014
Error handling was not correct regarding ring buffer memory
handling.
9 years ago
Victor Julien 9f7ba07153 af-packet: use better defaults if config is missing 9 years ago
Victor Julien f947539d79 af-packet: CentOS6 build fixes 9 years ago
Eric Leblond 49612128f3 af-packet: use time() instead of GetTime()
As we only use the second we don't need GetTime() which is slower
and get us milliseconds.
9 years ago
Eric Leblond 88f5d7d166 af-packet: print errno on mmap error 9 years ago
Eric Leblond a40f08a213 af-packet: ask for hardware timestamp 9 years ago
Eric Leblond 7fea0ec6f9 af-packet: reset stats at start of capture
We can loose packets during setup because we are reading nothing.
So it is logical to discard the counter at start of capture to
start from a clean state. This means we don't need to account the
drop at start. But the stats call that will reset the drop counts
will also return and reset the packets count. So we need to know
how many packets we really have. This is in fact the number of
packets coming from the stats call minus the number of discarded
packets and the drop count. All the other packets will have to be
read.
9 years ago
Eric Leblond c2d0d93806 af-packet: detect availability of tpacket_v3
If TPACKET_V3 is not defined then it is not available and we should
not build anything related to tpacket_v3. This will allow us to
activate it dy default and fallback to v2 if not available.
9 years ago
Eric Leblond f5c2019167 af-packet: add option to use memory locked mmap 9 years ago