Victor Julien [Mon, 27 Jan 2014 13:36:15 +0000 (14:36 +0100)]
no-detect: handle protocols that have no logger
If a protocol parser is active without a logger when detection is
disabled, the transaction handling logic would fail. Now it will
return the proper tx id so we can clean up the complete transactions.
Victor Julien [Mon, 16 Dec 2013 16:25:11 +0000 (17:25 +0100)]
Introduce g_detect_disabled global
This global will be set to TRUE if detect is disabled. The reason for
adding a global is that there currently is no clean way to pass
configuration options to management threads.
Victor Julien [Fri, 24 Jan 2014 17:09:46 +0000 (18:09 +0100)]
flow-timeout: change error logic
If FlowForceReassemblyForFlowV2 can't get packets to inject into the
engine, until now it would bail and retry later. In case of resource
starvation issues, this would cause a lot of lock contention, as the
flow manager would try over and over again.
This patch limits FlowForceReassemblyForFlowV2 to one try per flow,
if it fails... bad luck. It will only fail in serious conditions,
which means we must prefer the health of the engine over the proper
inspection of the flow in question.
Victor Julien [Fri, 24 Jan 2014 10:40:06 +0000 (11:40 +0100)]
app-layer-proto: speed up
AppLayer Proto detection code uses a mix of pattern search and
"probing parsers". The pattern search validates potential matches
using a single pattern search algo. The code was using SpmSearch
for this, but this made it inefficient as it builds a BoyerMoore
context for each search. This lead to significant memory pressure,
especially on high speed/bandwidth boxes.
This patch switches the search calls to BoyerMoore and BoyerMoore-
Nocase directly. This can be done as the ctx' were available already.
Victor Julien [Thu, 23 Jan 2014 08:55:09 +0000 (09:55 +0100)]
app-layer-event: refactor
Move app layer event handling into app-layer-event.[ch].
Convert 'Set' macro's to functions.
Get rid of duplication in Set and SetRaw. Set now calls SetRaw.
Fix potentential int overflow condition in the event storage.
Update callers.
Victor Julien [Fri, 17 Jan 2014 12:49:10 +0000 (13:49 +0100)]
app-layer proto detect: optimization
Don't use FlowGetProtoMapping at runtime, use f->protomap instead.
Add safety check to make sure its value is within range, as it's
used to index an array.
Victor Julien [Fri, 17 Jan 2014 08:55:46 +0000 (09:55 +0100)]
App-layer proto detect cleanups
Remove unnecessay inlining.
Rename functions with wrong naming scheme. E.g. AllocAppLayer.. instead
of AppLayer..Alloc.
Use AppProto instead of uint16_t.
Convert u16 ipproto cases to u8.
Victor Julien [Tue, 21 Jan 2014 13:18:37 +0000 (14:18 +0100)]
dns: update counters
This patch updates the DNS counters from the main AppLayer entry
functions. Due to the limited scope of AppLayerThreadCtx some of
the logic had to be implemented in app-layer.c, where it doesn't
belong.
Eric Leblond [Mon, 20 Jan 2014 09:41:28 +0000 (10:41 +0100)]
util-device: use safe tailq foreach
The loop is freeing elements so we need to use the safe version
of TIALQ_FOREACH.
This fixes a valgrind error:
Thread 1 Suricata-Main:
Invalid read of size 8
at 0x8E129C: LiveDeviceListClean (util-device.c:167)
by 0x89B742: main (suricata.c:2284)
Address 0x8382988 is 24 bytes inside a block of size 40 free'd
at 0x4C2A70C: free (vg_replace_malloc.c:468)
by 0x8E1297: LiveDeviceListClean (util-device.c:179)
by 0x89B742: main (suricata.c:2284)
Victor Julien [Fri, 17 Jan 2014 17:58:21 +0000 (18:58 +0100)]
Bug 980: fix HTTP memory cleanup at shutdown
Buffers in per thread HTTP header, client body and server body storage
would be freed based on the usage indicator instead of the size
indicator.
As the usage indicator (e.g. hsbd_buffers_list_len) could be reset
while leaving the memory untouched for later reuse, the free function
would not iterate over all memory blocks.
Eric Leblond [Fri, 17 Jan 2014 16:43:50 +0000 (17:43 +0100)]
af-packet: fix problem introduced in recent commit
Logic of patch 98e4a14f6d59fe8928fd6e2af3d9c3e8b42d00bf was correct
but implementation is wrong because TP_STATUS_KERNEL is equal to
zero and thus can not be evaluated in a binary operation. This patch
updates the logic by doing two tests.
Ken Steele [Fri, 10 Jan 2014 17:36:02 +0000 (12:36 -0500)]
Remove GCC -no-strict-aliasing compiler flag.
GCC typically generates better code without the -no-strict-aliasing flag.
It is only required if code makes assumptiosn that break strict aliasing.
The unit tests pass on x86 and Tile without the flag.
Victor Julien [Mon, 9 Dec 2013 16:41:22 +0000 (17:41 +0100)]
app-layer: configurable GetActiveTxId function
In preparation of a patchset that will allow for disabling the detect
module, this patch introduces a way to register a function for getting
the lowest active tx id. This is used by the app layer for cleaning up
transactions that already fully inspected, and by the flow timeout code
to determine if a flow is fully inspected and logged at timeout.
The registration function RegisterAppLayerGetActiveTxIdFunc allows for
registration of a custom function of type:
uint64_t (*GetActiveTxIdFunc)(Flow *f, uint8_t flags);
If no function is called, AppLayerTransactionGetActiveDetectLog is used,
which implements the existing behaviour of considering both the
inspect_id's and the log_id.
Victor Julien [Mon, 9 Dec 2013 14:56:43 +0000 (15:56 +0100)]
Clean up TX clean up
In AppLayerTransactionsCleanup instead of figuring out 'done' tx id's
itself, now call AppLayerTransactionGetActive for both directions to
figure out the completed TX id's.
Victor Julien [Tue, 17 Dec 2013 15:57:48 +0000 (16:57 +0100)]
stream: remove per thread queue for stream msgs
StreamMsgs would be stored in a per thread queue before being
attached to the tcp ssn. This is unnecessary, so this patch
removes this queue and puts the smsgs into the ssn directly.
Victor Julien [Tue, 17 Dec 2013 15:33:26 +0000 (16:33 +0100)]
stream: remove flow reference from StreamMsg
StreamMsg' flow reference was used mostly to make sure a flow would
not get removed from the hash before inspection. For this it needed
to reference the flow use_cnt reference counter. Nowadays we have
more advanced flow timeout handling. This will make sure that if
there still are pending smsgs' in a flow, these will still be
processed.
Victor Julien [Tue, 17 Dec 2013 15:19:16 +0000 (16:19 +0100)]
stream: pass TcpSession to StreamTcpReassembleProcessAppLayer
Preparation for removing flow pointer from StreamMsg. Instead of
getting the ssn indirectly through StreamMsg->flow, we pass it
directly as all callers have it already.
Victor Julien [Tue, 17 Dec 2013 14:24:44 +0000 (15:24 +0100)]
stream: no longer process STREAM_GAP smsgs
StreamSmgs are used for raw stream reassembly only. They could also
be used to tell the rest of the engine about sequence gaps. This was
a left over from the older implementation, where the app layer used
the smsgs as well.
Eric Leblond [Mon, 16 Dec 2013 10:44:25 +0000 (11:44 +0100)]
doxygen: document all code
This patch update doxygen configuration to have all possible functions
documented (even the one without doxygen formated comments). It can be
really useful to have that in case we are trying to get some information
on call graph for example.
Eric Leblond [Wed, 18 Dec 2013 18:46:10 +0000 (19:46 +0100)]
af-packet: update packet reading loop logic
This patch updates the logic of the packet acquisition loop. When
the reader loop function is called and when the data to read
at offset is a without data (kernel) or still used by suricata. We
try to iter for a loop on the ring to try to find kernel put by
data.
As we are entering the function because the poll said there was some
data. This allow us to jump to the data added to the ring by the
kernel.
When using suricata in autofp mode, with multiple detect threads and
packet acquisition threads attached to a dedicated CPU, the reader
loop function was looping really fast because poll call was returning
immediatly because we did read the data available.
Eric Leblond [Mon, 30 Dec 2013 15:14:54 +0000 (16:14 +0100)]
htp layer: add memory usage counter
This patch adds a memory counter for HTP memory usage. As
there is no thread variables available in application layer
the counter has been added to the TCP reassembly thread.
Eric Leblond [Mon, 30 Dec 2013 10:06:22 +0000 (11:06 +0100)]
htp layer: use memcap for HTTP related allocations
This patch introduces wrapper functions around allocation functions
to be able to have a global HTP memcap. A simple subsitution of
function was not enough because allocated size needed to be known
during freeing and reallocation.
The value of the memcap can be set in the YAML and is left by default
to unlimited (0) to avoid any surprise to users.
Ken Steele [Wed, 18 Dec 2013 16:16:54 +0000 (11:16 -0500)]
Add 8-bit states to ac-tile
When running with sgh-mpm-context: full, many more MPMs are created
(16K) and many are small. If they have less than 128 states, they only
need 1 byte for the next state instead of 2 bytes, cutting the size of
the next-state table in half. This reduces total memory usage.
Since that makes 3 different state sizes (1, 2 and 4 bytes), rather
than going from 2 copies of the code to create the MPM to 3, I
factored out the code that fills the next-state table into three
functions so that all the other code could be the same.
The search function is now parameterize for 8-bit and 16-bit state
sizes and alphabet sizes 8, 16, 32, 64, 128 and 256.
Eric Leblond [Tue, 31 Dec 2013 15:09:43 +0000 (16:09 +0100)]
pfring: fix live device counter usage
Live device counter was in fact the number of packets seen by suricata
and not the total number of packet reported by pfring. This patch fixes
this by using counter provided by kernel instead.
Pfring kernel counter is per socket and is not cleared after read.
So to get the number of packet on the interface we can add the new
value for this thread and add it to the interface counter.
Eric Leblond [Tue, 31 Dec 2013 15:13:50 +0000 (16:13 +0100)]
af-packet: fix live device counter usage
Live device counter was in fact the number of packets seen by suricata
and not the total number of packet reported by kernel. This patch fixes
this by using counter provided by kernel instead.
The counter is Clear On Read, so by adding the value fetch at each call
and earch sockets we get the number of packets and drops for the
interface.