Victor Julien [Fri, 20 Mar 2015 14:47:39 +0000 (15:47 +0100)]
detect-state: handle 'post match' locking
The post match list was called with an unlocked flow until now.
However, recent de_state handling updates changed this. The stateful
detection code can now call the post match functions while keeping
the flow locked. The normal detection code still calls it with an
unlocked flow.
This patch adds a hint to the DetectEngineThreadCtx called
'flow_locked' that is set to true if the caller has already locked
the flow.
Victor Julien [Tue, 17 Mar 2015 22:05:07 +0000 (23:05 +0100)]
dns: optimize tx list walks
The detection engine and log engines can walk the tx list indirectly,
by looping AppLayerParserGetTx. This would lead to new list walks in
the DNS tx list though. Leading to bad performance.
This patch stores the last returned tx and uses that to determine if
the next tx is what we need next. If so, we can return that w/o list
walk.
Victor Julien [Thu, 5 Mar 2015 12:04:33 +0000 (13:04 +0100)]
detect reload: load config
Load the YAML into a prefix "detect-engine-reloads.N" where N is the
reload counter. This way we can load the updated config w/o overwriting
the current one.
Victor Julien [Tue, 27 Jan 2015 11:33:21 +0000 (12:33 +0100)]
detect: reload thread init cleanup
Rename the thread init function DetectEngineThreadCtxInitForLiveRuleSwap
to DetectEngineThreadCtxInitForReload and change it's logic to take the
new detection engine as argument and let it return the
DetectEngineThreadCtx or NULL on error.
The old approach used the thread init API format, but it wasn't used in
that way.
Victor Julien [Tue, 27 Jan 2015 10:30:08 +0000 (11:30 +0100)]
detect reload: allow master update during reload
Add DetectEngineReference, which takes a reference to a detect engine,
and make DetectEngineThreadCtxInitForLiveRuleSwap use it. This way
reload will not depend on master staying the same. This allows master
to be updated in between w/o affecting the reload that is in progress.
Victor Julien [Mon, 19 Jan 2015 21:09:59 +0000 (22:09 +0100)]
detect: move reload into main loop
Use new DetectEngineReload() function. It's called from the main loop
instead of it being spawned into it's own temporary thread. This greatly
simplifies the signal handling.
An added advantage is that this seems to improve the memory usage.
Victor Julien [Mon, 19 Jan 2015 13:54:11 +0000 (14:54 +0100)]
detect: introduce 'minimal' detect engine
The minimal detect engine has only the minimal memory use and setup
time. It's to be used for 'delayed' detect where the first detection
engine is essentially empty.
Victor Julien [Sat, 17 Jan 2015 17:44:23 +0000 (18:44 +0100)]
detect: update detect engine management
Update detect engine management to make it easier to reload the detect
engine.
Core of the new approach is a 'master' ctx, that keeps a list of one or
more detect engines. The detect engines will not be passed to any thread
directly, but instead will only be accessed through the detect engine
thread contexts. As we can replace those atomically, replacing a detect
engine becomes easier.
Each thread keeps a reference to its detect context. When a detect engine
is replaced or removed, it's added to a free list. Once its reference
count reaches 0, it is freed.
Victor Julien [Sat, 21 Feb 2015 13:19:48 +0000 (14:19 +0100)]
Remove spinning PacketPoolWait
PacketPoolWait in autofp can wait for considerable time. Until now
it was essentially spinning, keeping the CPU 100% busy.
This patch introduces a condition to wait in such cases.
Atomically flag pool that consumer is waiting, so that we can sync
the pending pool right away instead of waiting for the
MAX_PENDING_RETURN_PACKETS limit.
Victor Julien [Tue, 21 Oct 2014 08:04:57 +0000 (10:04 +0200)]
detect: set action from utility function
Set actions that are set directly from Signatures using the new
utility function DetectSignatureApplyActions. This will apply
the actions and also store info about the 'drop' that first made
the rule drop.
Eric Leblond [Mon, 19 Jan 2015 18:16:49 +0000 (19:16 +0100)]
flow-timeout: fix init of pseudo packet
The code was not checking if we had enough room in the direct
data. In case default_packet_size was set really small, this was
resulting in data being written over the data and causing a crash.
The patch fixes the issue by forcing an allocation if the direct
data size in the Packet is to small.
Eric Leblond [Thu, 12 Feb 2015 20:15:27 +0000 (21:15 +0100)]
decode: introduce PacketCallocExtPkt function
In flow timeout handling we need a function that allocate and blank
a place that will be used to put constructed packet data. This new
function has no other goal.
Jason Ish [Fri, 27 Feb 2015 17:30:47 +0000 (11:30 -0600)]
When re-opening a log file on HUP, always append.
This will prevent log files that have not been rotated by some
external tool from being deleted, but log files that were
rotated (moved out of the way) will be re-opened.
This is a better default behaviour, especially when not all
log files are rotated at the same time.
Jason Ish [Thu, 15 Jan 2015 20:43:45 +0000 (14:43 -0600)]
Don't attempt to load the rule files if the rule-files configuration
node is not a sequence. Instead log a warning as this is usually
a configuration error.
Eric Leblond [Fri, 6 Mar 2015 19:03:13 +0000 (20:03 +0100)]
json-alert: log tls info in alert
This patch adds the capabilities to log the TLS information the
same way it is currently possible to do with HTTP. As it is
quite hard to read ASN.1 directly in the stream, this will help
people to understand why suricata is firing on alert relative
to TLS.
Eric Leblond [Wed, 18 Feb 2015 10:45:12 +0000 (11:45 +0100)]
build: don't link with libnfnetlink
Don't link suricata with libnfnetlink when we don't have support
for NFQUEUE or NFLOG. Previously, suricata was linked with this
library without reason.
Victor Julien [Thu, 19 Feb 2015 09:39:50 +0000 (10:39 +0100)]
Fix compiler warning on CentOS 5.11
cc1: warnings being treated as errors
app-layer-smtp.c: In function ‘SMTPParseCommandBDAT’:
app-layer-smtp.c:908: warning: dereferencing type-punned pointer will break strict-aliasing rules
Eric Leblond [Thu, 19 Feb 2015 08:37:23 +0000 (09:37 +0100)]
util-ioctl: don't build code RX ring on old system
If ETHTOOL_GRXRINGS is undefined we will not be able to build the
RX rings code. So we can make the build conditional to the
definition of ETHTOOL_GRXRINGS.
Victor Julien [Fri, 23 Jan 2015 12:06:44 +0000 (13:06 +0100)]
http: remove unused and broken 'content-len' logic
The HTTP tracking code would parse the content lenght and store it
in the TX user data. It didn't take the possibility or errors into
account though, leading to a possible negative int being cases to
unsigned int. Luckily, the result was unused.
Victor Julien [Fri, 23 Jan 2015 11:09:29 +0000 (12:09 +0100)]
dcerpc: fix error handling for alloc errors
Fix error handling of stub parsers. In case of SCRealloc error the
function would return a non-error code. This could possibly lead to
memory corruption.
Victor Julien [Wed, 18 Feb 2015 07:50:01 +0000 (08:50 +0100)]
flow: make TCP reuse handling in flow engine optional
In case of autofp (or more general, when flow and stream engine
run in different threads) the flow engine should not trigger a flow
reuse as this can lead to race conditions between the flow and the
stream engine.
In such cases, the flow engine can be far ahead of the stream engine
as packets are in a queue between the threads.
Observed:
Flow engine tags packet 10 as start of new flow. Flow is tagged as
'reused'.
Stream engine evaluates packet 5 which belongs to the old flow. It
rejects the flow as it's tagged 'reused'. Attaches packet 5 to the
new flow which is wrong.
Solution:
This patch connects the flow engines handling of reuse cases to
the runmode. It hooks into the RunmodeSetFlowStreamAsync() call to
notify the flow engine that it shouldn't handle the reuse.