]> git.ipfire.org Git - thirdparty/suricata.git/log
thirdparty/suricata.git
10 years agoBug 1401: on midstream pickup, fix packet direction 1383/head
Victor Julien [Tue, 17 Mar 2015 10:48:17 +0000 (11:48 +0100)] 
Bug 1401: on midstream pickup, fix packet direction

On midstream SYN/ACK pickups, we would flip the direction of packets
after the first. This meant the first (pickup) packet's direction
was wrong.

This patch fixes that.

10 years agoBug 1417 - Record sequence nodes as sequences. 1380/head
Jason Ish [Tue, 17 Mar 2015 04:29:22 +0000 (22:29 -0600)] 
Bug 1417 - Record sequence nodes as sequences.

Nodes that are sequences weren't being recorded as such, causing
rules to fail to load.

Change sequence test name to reflect better what it tests, and
test that the sequence node is detected as a sequence.

10 years agodetect-state: implement tx state reset for reload 1375/head
Victor Julien [Tue, 10 Mar 2015 16:41:03 +0000 (17:41 +0100)] 
detect-state: implement tx state reset for reload

In case of Detect Reload, we need to reset active tx' state.

10 years agodetect-state: split flow and tx state
Victor Julien [Fri, 27 Feb 2015 14:21:17 +0000 (15:21 +0100)] 
detect-state: split flow and tx state

Use separate data structures for storing TX and FLOW (AMATCH) detect
state.

- move state storing into util funcs
- remove de_state_m
- simplify reset state logic on reload

10 years agomodbus: tx de_state
Victor Julien [Mon, 9 Mar 2015 14:58:07 +0000 (15:58 +0100)] 
modbus: tx de_state

10 years agosmtp: tx de_state
Victor Julien [Mon, 9 Mar 2015 14:45:39 +0000 (15:45 +0100)] 
smtp: tx de_state

10 years agodns: implement tx de_state
Victor Julien [Mon, 9 Mar 2015 14:32:40 +0000 (15:32 +0100)] 
dns: implement tx de_state

10 years agohttp: clean up tx destate at tx destroy
Victor Julien [Mon, 9 Mar 2015 10:08:47 +0000 (11:08 +0100)] 
http: clean up tx destate at tx destroy

10 years agohttp: support per TX destate storage
Victor Julien [Fri, 6 Mar 2015 18:37:55 +0000 (19:37 +0100)] 
http: support per TX destate storage

10 years agoapp-layer: per tx destate
Victor Julien [Fri, 6 Mar 2015 18:11:10 +0000 (19:11 +0100)] 
app-layer: per tx destate

Add API calls for storing detection state in the TX.

10 years agodetect-state: fix profiling
Victor Julien [Thu, 26 Feb 2015 17:40:31 +0000 (18:40 +0100)] 
detect-state: fix profiling

10 years agodetect-state: various cleanups
Victor Julien [Thu, 26 Feb 2015 17:38:04 +0000 (18:38 +0100)] 
detect-state: various cleanups

10 years agodetect-state: rip per sig detect out of ContinueDetect
Victor Julien [Thu, 26 Feb 2015 16:23:49 +0000 (17:23 +0100)] 
detect-state: rip per sig detect out of ContinueDetect

10 years agodetect-state: remove DeStateResetFileInspection
Victor Julien [Thu, 26 Feb 2015 16:32:36 +0000 (17:32 +0100)] 
detect-state: remove DeStateResetFileInspection

It was effectively unused.

10 years agodetect-state: remove redundant code
Victor Julien [Thu, 26 Feb 2015 16:49:30 +0000 (17:49 +0100)] 
detect-state: remove redundant code

10 years agodetect-state: add helper to test state
Victor Julien [Thu, 26 Feb 2015 15:11:31 +0000 (16:11 +0100)] 
detect-state: add helper to test state

Add little helper function StateIsValid() to test if the state
can be inspected safely.

Cleans up stateful detection loops.

10 years agodetect-state: add helper to indicate last tx
Victor Julien [Thu, 26 Feb 2015 14:58:43 +0000 (15:58 +0100)] 
detect-state: add helper to indicate last tx

Add little helper to indicate current tx is that last we have.

10 years agodetect-state: cleanup ContinueDetection
Victor Julien [Thu, 26 Feb 2015 14:23:41 +0000 (15:23 +0100)] 
detect-state: cleanup ContinueDetection

Only lock f->de_state->m when we start to access it. So after
declaration and initialization of local vars.

10 years agodetect-state: cleanup retvals
Victor Julien [Thu, 26 Feb 2015 14:02:21 +0000 (15:02 +0100)] 
detect-state: cleanup retvals

Use DETECT_ENGINE_INSPECT_SIG_* instead of 0, 1, 2 and 3.

10 years agomodbus: shrink data structure
Victor Julien [Mon, 9 Mar 2015 14:49:28 +0000 (15:49 +0100)] 
modbus: shrink data structure

10 years agofile: don't 'close' file if we need to track it
Victor Julien [Fri, 27 Feb 2015 16:10:09 +0000 (17:10 +0100)] 
file: don't 'close' file if we need to track it

10 years agohttp: add inspection engine for http request line
Victor Julien [Mon, 9 Mar 2015 13:56:24 +0000 (14:56 +0100)] 
http: add inspection engine for http request line

No MPM though.

10 years agohttp: fix stat_msg and stat_code state tracking
Victor Julien [Thu, 26 Feb 2015 23:04:11 +0000 (00:04 +0100)] 
http: fix stat_msg and stat_code state tracking

10 years agoRemove spinning PacketPoolWait 1374/head
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.

10 years agodrop json log: log out 'drop' signature 1365/head
Victor Julien [Tue, 21 Oct 2014 17:27:34 +0000 (19:27 +0200)] 
drop json log: log out 'drop' signature

If no normal sig was logged as the 'drop' reason, try the stored
drop signature instead, this will also log out 'noalert' sigs.

10 years agodrop json: make alerts logging optional
Victor Julien [Mon, 20 Oct 2014 13:43:42 +0000 (15:43 +0200)] 
drop json: make alerts logging optional

Make logging out alerts that caused the drop optional.

10 years agodrop json: add sids (if applicable)
Victor Julien [Mon, 20 Oct 2014 12:02:20 +0000 (14:02 +0200)] 
drop json: add sids (if applicable)

If a drop is caused by a SID match, add it to the drop record.

10 years agoalert json: move alert info into function
Victor Julien [Mon, 20 Oct 2014 11:59:28 +0000 (13:59 +0200)] 
alert json: move alert info into function

Move adding the alert info (sid,rev,gid,etc) into it's own function,
so it can be called from other outputs as well.

10 years agodetect: set action from utility function
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.

10 years agodetect: cleanup, remove unused order_id
Victor Julien [Tue, 21 Oct 2014 08:43:56 +0000 (10:43 +0200)] 
detect: cleanup, remove unused order_id

No longer used, so remove.

10 years agoflow-timeout: fix init of pseudo packet
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.

10 years agodecode: introduce PacketCallocExtPkt function
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.

10 years agoWhen re-opening a log file on HUP, always append.
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.

Thanks to iro on IRC.

10 years agoDon't attempt to load the rule files if the rule-files configuration
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.

10 years agoNew function to test if a configuration node is a sequence or not.
Jason Ish [Thu, 15 Jan 2015 20:43:22 +0000 (14:43 -0600)] 
New function to test if a configuration node is a sequence or not.

10 years agoaf-packet: don't unlock twice the bpf mutex
Eric Leblond [Tue, 24 Feb 2015 16:46:06 +0000 (17:46 +0100)] 
af-packet: don't unlock twice the bpf mutex

10 years agojson-alert: use getter for appstate 1356/head
Eric Leblond [Fri, 6 Mar 2015 21:21:12 +0000 (22:21 +0100)] 
json-alert: use getter for appstate

10 years agoflow: constify getters param
Eric Leblond [Fri, 6 Mar 2015 21:17:30 +0000 (22:17 +0100)] 
flow: constify getters param

Some potential callers are already using constified values so it
is good to do it.

10 years agojson-alert: add SSH fields in alert logging
Eric Leblond [Fri, 6 Mar 2015 20:16:52 +0000 (21:16 +0100)] 
json-alert: add SSH fields in alert logging

10 years agojson-ssh: export logging function
Eric Leblond [Fri, 6 Mar 2015 20:05:51 +0000 (21:05 +0100)] 
json-ssh: export logging function

It will be use in alert logging to display SSH information.

10 years agojson-alert: log tls info in alert
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.

10 years agojson-tls: refactor to export logging function
Eric Leblond [Fri, 6 Mar 2015 18:55:28 +0000 (19:55 +0100)] 
json-tls: refactor to export logging function

To be able to add TLS data in alert we need to do the same as what
is done with HTTP ie export the logging functions.

10 years agoInject pseudo packet periodically when there is not traffic in mPIPE. 1351/head
Ken Steele [Fri, 27 Feb 2015 04:22:35 +0000 (23:22 -0500)] 
Inject pseudo packet periodically when there is not traffic in mPIPE.

To prevent pseudo packets from not being processed when there is no traffic,
inject a pseudo packet if no traffic is seen by a thread for ~100ms.

10 years agoDefine _DEFAULT_SOURCE. Its the replacement for _BSD_SOURCE which
Jason Ish [Thu, 15 Jan 2015 15:44:45 +0000 (09:44 -0600)] 
Define _DEFAULT_SOURCE.  Its the replacement for _BSD_SOURCE which
which has been deprecated as of glibc 2.20.

10 years agobuild: don't link with libnfnetlink
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.

10 years agoutil-magic: make unittests less specific
Victor Julien [Wed, 25 Feb 2015 06:37:54 +0000 (07:37 +0100)] 
util-magic: make unittests less specific

So they pass on CentOS 5.11 as well.

10 years agoapp-layer: init flow in tests
Victor Julien [Wed, 4 Mar 2015 16:06:59 +0000 (17:06 +0100)] 
app-layer: init flow in tests

10 years agopcap-file: add missing atomic init
Eric Leblond [Thu, 12 Feb 2015 21:27:07 +0000 (22:27 +0100)] 
pcap-file: add missing atomic init

It is mandatory to init all atomic to avoid problem on system
without atomic support.

10 years agorunmode-pcap-file: suppress useless include
Eric Leblond [Thu, 12 Feb 2015 21:18:23 +0000 (22:18 +0100)] 
runmode-pcap-file: suppress useless include

10 years agoflow-manager: init global atomics
Victor Julien [Wed, 4 Mar 2015 15:47:28 +0000 (16:47 +0100)] 
flow-manager: init global atomics

10 years agostream: fix unittests wrt flow
Victor Julien [Thu, 19 Feb 2015 19:58:36 +0000 (20:58 +0100)] 
stream: fix unittests wrt flow

10 years agoFix make distcheck on CentOS 5.11
Victor Julien [Thu, 19 Feb 2015 10:45:09 +0000 (11:45 +0100)] 
Fix make distcheck on CentOS 5.11

datarootdir was undefined. Define it.

10 years agoFix compiler warning on CentOS 5.11
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

10 years agoCentOS 5.11 pkg-config fix
Victor Julien [Thu, 19 Feb 2015 09:29:14 +0000 (10:29 +0100)] 
CentOS 5.11 pkg-config fix

Check for the minimal pkg-config 0.21 version. Without it, CentOS'
pkg-config will fail with the warning:

configure: error: The pkg-config script could not be found or is too old.

10 years agoutil-ioctl: don't build code RX ring on old system
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.

10 years agohttp: add event for suspicious method delimeter 1346/head
Victor Julien [Wed, 18 Feb 2015 22:46:19 +0000 (23:46 +0100)] 
http: add event for suspicious method delimeter

Add event and rule for suspicious delim(s) between method and uri.

Add unittests as well.

10 years agohttp: add libhtp uri warning event
Victor Julien [Wed, 18 Feb 2015 15:45:20 +0000 (16:45 +0100)] 
http: add libhtp uri warning event

Add event for libhtp warning added 0.5.17 for URI's with suspicious
delimeters.

10 years agostream: init global config after flow engine
Victor Julien [Wed, 25 Feb 2015 10:06:41 +0000 (11:06 +0100)] 
stream: init global config after flow engine

Stream depends on flow engine.

10 years agohttp: remove unused and broken 'content-len' logic
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.

This patch simply removes the offending code.

Reported-by: The Yahoo pentest team
10 years agodcerpc: don't exit() on malloc failure
Victor Julien [Fri, 23 Jan 2015 11:12:53 +0000 (12:12 +0100)] 
dcerpc: don't exit() on malloc failure

In 2 places we would exit() if malloc failed. We should never exit in
such cases. This patch silently handles it.

10 years agodcerpc: fix error handling for alloc errors
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.

Reported-By: The Yahoo pentest team
10 years agoflow: make TCP reuse handling in flow engine optional 1342/head
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.

10 years agotcp reuse: don't double 'reuse'
Victor Julien [Tue, 17 Feb 2015 12:01:52 +0000 (13:01 +0100)] 
tcp reuse: don't double 'reuse'

If the flow engine already reused a flow then the stream engine
won't have to do the same.

10 years agoflow: tag first packet in each direction
Victor Julien [Tue, 17 Feb 2015 11:47:01 +0000 (12:47 +0100)] 
flow: tag first packet in each direction

Set a flowflag for the first packet in each direction:

FLOW_PKT_TOSERVER_FIRST and FLOW_PKT_TOCLIENT_FIRST

10 years agotcp reuse: enable stream handling based on runmode
Victor Julien [Tue, 17 Feb 2015 09:34:53 +0000 (10:34 +0100)] 
tcp reuse: enable stream handling based on runmode

Add a way for runmodes to state that flow and stream run asynchorously.

In the stream engine, enable the TCP reuse handling only if that flag
is set.

10 years agotcp reuse: support reuse on syn/ack
Victor Julien [Mon, 9 Feb 2015 15:44:11 +0000 (16:44 +0100)] 
tcp reuse: support reuse on syn/ack

Support TCP reuse on SYN/ACK. Only effective if midstream and/or
async-oneside options are enabled.

10 years agotcp reuse: unify autofp and single/workers check
Victor Julien [Tue, 3 Feb 2015 11:06:49 +0000 (12:06 +0100)] 
tcp reuse: unify autofp and single/workers check

10 years agotcp reuse: handle reuse in stream engine
Victor Julien [Thu, 22 Jan 2015 16:30:10 +0000 (17:30 +0100)] 
tcp reuse: handle reuse in stream engine

For the autofp case, handling TCP reuse in the flow engine didn't work.

The problem is the mismatch between the moment the flow engine looks at
packets and the stream, and the moment the stream engine runs. Flow engine
is invoked in the packet capture thread(s), while the stream engine runs
as part of the stream/detect thread(s). Because of the queues between
those threads the flow manager may already inspect a new SYN while the
stream engine still has to process the previous session.

Moving the flow engine to the stream/detect thread(s) wasn't an option
as the 'autofp' load balancing depends on the flow already being
available in the packet.

The solution here is to add a check for this condition to the stream
engine. At this point the TCP state is up to date. If a TCP reuse case
is encountered, this is the global logic:

- detach packet for old flow
- get a new flow and attach it to the packet
- flag the old flow that it is now obsolete

Additional logic makes sure that the packets already in the queue
between the flow thread(s) and the stream thread are reassigned the
new flow.

Some special handling:

Apply previous 'reuse' before checking for a new reuse. Otherwise we're
tagging the wrong flow in some cases (multiple reuses in the same tuple).

When in a flow/ssn reuse condition, properly remove the packet from
the flow.

Don't 'reuse' if packet is a SYN retransmission.

The old flow is timed out normally by the flow manager.

10 years agoflow: add util func to remove packet from flow
Victor Julien [Mon, 2 Feb 2015 16:14:49 +0000 (17:14 +0100)] 
flow: add util func to remove packet from flow

Unsets the p::flowflags that were previously set.

10 years agoflow: overwrite p::flowflags on first set
Victor Julien [Mon, 2 Feb 2015 14:46:24 +0000 (15:46 +0100)] 
flow: overwrite p::flowflags on first set

10 years agoflow: move flow/packet updates into util func
Victor Julien [Mon, 2 Feb 2015 13:40:21 +0000 (14:40 +0100)] 
flow: move flow/packet updates into util func

Move the code responsible for updating the flow and packet after
a new packet has come in to a util func "FlowHandlePacketUpdate"

10 years agoflow: add flow.tcp_reuse counter
Victor Julien [Mon, 15 Dec 2014 16:42:56 +0000 (17:42 +0100)] 
flow: add flow.tcp_reuse counter

This replaces the tcp.reused_ssn counter. The flow engine now
enforces the TCP flow reuse logic.

The counter is incremented only when the flow is timed out, so
after the "tcp closed" timeout expired for a flow.

10 years agotcp reuse: remove old code
Victor Julien [Mon, 15 Dec 2014 15:01:28 +0000 (16:01 +0100)] 
tcp reuse: remove old code

10 years agoflow: handle TCP session reuse in flow engine
Victor Julien [Mon, 15 Dec 2014 14:06:53 +0000 (15:06 +0100)] 
flow: handle TCP session reuse in flow engine

Until now, TCP session reuse was handled in the TCP stream engine.
If the state was TCP_CLOSED, a new SYN packet was received and a few
other conditions were met, the flow was 'reset' and reused for the
'new' TCP session.

There are a number of problems with this approach:
- it breaks the normal flow lifecycle wrt timeout, detection, logging
- new TCP sessions could come in on different threads due to mismatches
  in timeouts between suricata and flow balancing hw/nic/drivers
- cleanup code was often causing problems
- it complicated locking because of the possible thread mismatch

This patch implements a different solution, where a new TCP session also
gets a new flow. To do this 2 main things needed to be done:

1. the flow engine needed to be aware of when the TCP reuse case was
   happening
2. the flow engine needs to be able to 'skip' the old flow once it was
   replaced by a new one

To handle (1), a new function TcpSessionPacketSsnReuse() is introduced
to check for the TCP reuse conditions. It's called from 'FlowCompare()'
for TCP packets / TCP flows that are candidates for reuse. FlowCompare
returns FALSE for the 'old' flow in the case of TCP reuse.

This in turn will lead to the flow engine not finding a flow for the TCP
SYN packet, resulting in the creation of a new flow.

To handle (2), FlowCompare flags the 'old' flow. This flag causes future
FlowCompare calls to always return FALSE on it. In other words, the flow
can't be found anymore. It can only be accessed by:

1. existing packets with a reference to it
2. flow timeout handling as this logic gets the flows from walking the
   hash directly
3. flow timeout pseudo packets, as they are set up by (2)

The old flow will time out normally, as governed by the "tcp closed"
flow timeout setting. At timeout, the normal detection, logging and
cleanup code will process it.

The flagging of a flow making it 'unfindable' in the flow hash is a bit
of a hack. The reason for this approach over for example putting the
old flow into a forced timeout queue where it could be timed out, is
that such a queue could easily become a contention point. The TCP
session reuse case can easily be created by an attacker. In case of
multiple packet handlers, this could lead to contention on such a flow
timeout queue.

10 years agotcp midstream: fix window scaling
Victor Julien [Tue, 10 Feb 2015 11:03:42 +0000 (12:03 +0100)] 
tcp midstream: fix window scaling

If stream is picked by ACK, we can't know the wscale, so we assume it's
set to max. Howver, we didn't apply this to the initial window size we
set.

10 years agodetect-flow: use dedicated flags
Victor Julien [Tue, 17 Feb 2015 11:08:20 +0000 (12:08 +0100)] 
detect-flow: use dedicated flags

The flow keyword used flag names that were shared with the
Packet::flowflags field. Some of the flags were'nt used by the packet
though. This lead to waste of some 'flag space'.

This patch defines dedicated flags for the flow keyword and removes
the otherwise unused flags from the FLOW_PKT_* space.

10 years agostats api: call thread deinit API functions 1329/head
Victor Julien [Thu, 5 Feb 2015 08:36:34 +0000 (09:36 +0100)] 
stats api: call thread deinit API functions

Thread deinit funcs weren't called. This meant the lua scripts 'deinit'
functions weren't called either.

10 years agonetmap support 1318/head
gureedo [Sat, 13 Dec 2014 11:12:40 +0000 (16:12 +0500)] 
netmap support

10 years agofile: register filedata log before file log 1315/head
Victor Julien [Fri, 23 Jan 2015 09:22:55 +0000 (10:22 +0100)] 
file: register filedata log before file log

This way the file log can log the 'stored' info that the filedata
log sets.

10 years agofile: improve file pruning
Victor Julien [Fri, 23 Jan 2015 09:22:01 +0000 (10:22 +0100)] 
file: improve file pruning

Check if file has been logged/stored before considering it 'done'.

10 years agorunmodes: add funcs to check if file loggers enabled
Victor Julien [Fri, 23 Jan 2015 09:20:37 +0000 (10:20 +0100)] 
runmodes: add funcs to check if file loggers enabled

Add functions to check if file/filedata loggers are enabled.

10 years agofile: optimize file pruning
Victor Julien [Thu, 22 Jan 2015 18:24:35 +0000 (19:24 +0100)] 
file: optimize file pruning

FilePrune would clear the files, but not free them and remove them
from the list. This lead to ever growing lists in some cases.
Especially in HTTP sessions with many transactions, this could slow
us down.

10 years agoflow: lockless flow manager checks
Victor Julien [Sat, 24 Jan 2015 13:10:11 +0000 (14:10 +0100)] 
flow: lockless flow manager checks

Until this point, the flow manager would check for timed out flows
by walking the flow hash, locking first the hash row and then each
individual flow to get it's state and timestamp. To not be too
intrusive trylocks were used so that a busy flow wouldn't cause the
flow manager to wait for a long time while holding the hash row lock.

Building on the changes in handling of the flow state and lastts
fields, this patch changes the flow managers behavior.

It can now get a flows state atomically and the lastts can be safely
read while holding just the flow hash row lock. This allows the flow
manager to do the basic time out check much more cheaply:

1. it doesn't have to wait for getting a lock
2. it doesn't interupt the packet path

As a consequence the trylock is now also gone. A flow that returns
'true' on timeout is pretty much certainly not going to be busy so
we can safely lock it unconditionally. This also means the flow
manager now walks the entire row unconditionally and is guaranteed
to inspect each flow in the row.

To make sure the functions called before the flow lock don't
accidentally change the flow (which would require a lock) the args
to these flows are changed to const pointers.

10 years agoflow: modify lastts update logic
Victor Julien [Sat, 24 Jan 2015 12:46:25 +0000 (13:46 +0100)] 
flow: modify lastts update logic

In the lastts timeval struct field in the flow the timestamp of the
last packet to update is recorded. This allows for tracking the timeout
of the flow. So far, this value was updated under the flow lock and also
read under the flow lock.

This patch moves the updating of this field to the FlowGetFlowFromHash
function, where it updated at the point where both the Flow and the
Flow Hash Row lock are held. This guarantees that the field is only
updated when both locks are held.

This makes reading the field safe when either lock is held, which is the
purpose of this patch.

The flow manager, while holding the flow hash row lock, can now safely
read the lastts value. This allows it to do the flow timeout check
without actually locking the flow.

10 years agoflow: change flow state logic
Victor Julien [Sat, 24 Jan 2015 12:18:51 +0000 (13:18 +0100)] 
flow: change flow state logic

A flow has 3 states: NEW, ESTABLISHED and CLOSED.

For all protocols except TCP, a flow is in state NEW as long as just one
side of the conversation has been seen. When both sides have been
observed the state is moved to ESTABLISHED.

TCP has a different logic, controlled by the stream engine. Here the TCP
state is leading.

Until now, when parts of the engine needed to know the flow state, it
would invoke a per protocol callback 'GetProtoState'. For TCP this would
return the state based on the TcpSession.

This patch changes this logic. It introduces an atomic variable in the
flow 'flow_state'. It defaults to NEW and is set to ESTABLISHED for non-
TCP protocols when we've seen both sides of the conversation.

For TCP, the state is updated from the TCP engine directly.

The goal is to allow for access to the state without holding the Flow's
main mutex lock. This will later allow the Flow Manager(s) to evaluate
the Flow w/o interupting it.

10 years agotcp: add stream.reassembly.zero-copy-size option
Victor Julien [Thu, 22 Jan 2015 12:43:31 +0000 (13:43 +0100)] 
tcp: add stream.reassembly.zero-copy-size option

The option sets in bytes the value at which segment data is passed to
the app layer API directly. Data sizes equal to and higher than the
value set are passed on directly.

Default is 128.

10 years agotcp: add debug stats about reassembly fast paths
Victor Julien [Fri, 16 Jan 2015 11:12:38 +0000 (12:12 +0100)] 
tcp: add debug stats about reassembly fast paths

Only shown if --enable-debug is passed to configure.

10 years agotcp: zero copy fast path in app-layer reassembly
Victor Julien [Fri, 16 Jan 2015 10:53:29 +0000 (11:53 +0100)] 
tcp: zero copy fast path in app-layer reassembly

Create 2 'fast paths' for app layer reassembly. Both are about reducing
copying. In the cases described below, we pass the segment's data
directly to the app layer API, instead of first copying it into a buffer
than we then pass. This safes a copy.

The first is for the case when we have just one single segment that was
just ack'd. As we know that we won't use any other segment this round,
we can just use the segment data.

The second case is more aggressive. When the segment meets a certain
size limit (currently hardcoded at 128 bytes), we pass it to the
app-layer API directly. Thus invoking the app-layer somewhat more often
to safe some copies.

10 years agostream: move raw stream gap handling into util func
Victor Julien [Tue, 9 Dec 2014 18:08:14 +0000 (19:08 +0100)] 
stream: move raw stream gap handling into util func

10 years agostream: move raw reassembly into util func
Victor Julien [Tue, 9 Dec 2014 18:01:03 +0000 (19:01 +0100)] 
stream: move raw reassembly into util func

10 years agostream: remove StreamTcpReassembleInlineAppLayer
Victor Julien [Tue, 9 Dec 2014 14:39:49 +0000 (15:39 +0100)] 
stream: remove StreamTcpReassembleInlineAppLayer

Function is now unused.

10 years agostream: unify inline and non-inline applayer assembly
Victor Julien [Tue, 9 Dec 2014 14:27:58 +0000 (15:27 +0100)] 
stream: unify inline and non-inline applayer assembly

Unifiy inline and non-inline app layer stream reassembly to aid
maintainability of the code.

10 years agostream: remove STREAM_SET_FLAGS
Victor Julien [Tue, 9 Dec 2014 13:36:05 +0000 (14:36 +0100)] 
stream: remove STREAM_SET_FLAGS

Use the unified StreamGetAppLayerFlags instead.

10 years agostream: update inline tests
Victor Julien [Tue, 9 Dec 2014 13:26:35 +0000 (14:26 +0100)] 
stream: update inline tests

Make sure inline tests set the stream_inline flag.

10 years agostream: replace STREAM_SET_INLINE_FLAGS macro
Victor Julien [Tue, 9 Dec 2014 13:25:34 +0000 (14:25 +0100)] 
stream: replace STREAM_SET_INLINE_FLAGS macro

Replace it by a generic function StreamGetAppLayerFlags, that can
be used both by inline and non-inline.

10 years agostream: track data sent to app-layer
Victor Julien [Tue, 9 Dec 2014 12:48:00 +0000 (13:48 +0100)] 
stream: track data sent to app-layer

10 years agostream: move reassembly loop into util funcs
Victor Julien [Tue, 9 Dec 2014 11:56:55 +0000 (12:56 +0100)] 
stream: move reassembly loop into util funcs

Move IDS per segment reassembly and gap handling into utility functions.

10 years agoUpdate changelog for 2.1beta3 suricata-2.1beta3
Victor Julien [Thu, 29 Jan 2015 15:51:54 +0000 (16:51 +0100)] 
Update changelog for 2.1beta3

10 years agodetect: fix small memory leaks 1305/head
Victor Julien [Wed, 21 Jan 2015 10:43:58 +0000 (11:43 +0100)] 
detect: fix small memory leaks

Fix small memory leaks in option parsing. Move away from
pcre_get_substring in favor of pcre_copy_substring.

Related to #1046.

10 years agoClean up Conf API memory on shutdown.
Victor Julien [Wed, 21 Jan 2015 10:31:15 +0000 (11:31 +0100)] 
Clean up Conf API memory on shutdown.