]> git.ipfire.org Git - thirdparty/suricata.git/log
thirdparty/suricata.git
11 years agodns: add event for when memcap is reached 789/head
Victor Julien [Tue, 21 Jan 2014 13:51:56 +0000 (14:51 +0100)] 
dns: add event for when memcap is reached

Raise event if state-memcap is reached for a flow.

11 years agodns: update counters 788/head
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.

11 years agodns: register counters
Victor Julien [Tue, 21 Jan 2014 12:22:48 +0000 (13:22 +0100)] 
dns: register counters

Register dns memory counters.
Keep track of memcap reached conditions, and increment counters for
those.

11 years agoapp-layer: update UDP entry function
Victor Julien [Tue, 21 Jan 2014 12:50:38 +0000 (13:50 +0100)] 
app-layer: update UDP entry function

Update AppLayerHandleUdp to take the ThreadVars pointer as an
argument in prepraration of handling counters in this function.

11 years agoPass ThreadVars ptr to various thread init funcs
Victor Julien [Tue, 21 Jan 2014 12:42:10 +0000 (13:42 +0100)] 
Pass ThreadVars ptr to various thread init funcs

To be able to register counters from AppLayerGetCtxThread, the
ThreadVars pointer needs to be available in it and thus in it's
callers:

- AppLayerGetCtxThread
- DecodeThreadVarsAlloc
- StreamTcpReassembleInitThreadCtx

11 years agodns: add memcap checking 787/head
Victor Julien [Tue, 21 Jan 2014 11:01:07 +0000 (12:01 +0100)] 
dns: add memcap checking

Add memuse tracking and memcap checking to the DNS parsers. Memuse
is tracked globally and per flow (state).

Memcaps are also checked per flow and globally before memory allocs
are done.

11 years agodns: make DNSTransactionAlloc static
Victor Julien [Tue, 21 Jan 2014 09:58:51 +0000 (10:58 +0100)] 
dns: make DNSTransactionAlloc static

11 years agodns: add memcap options
Victor Julien [Tue, 21 Jan 2014 09:39:50 +0000 (10:39 +0100)] 
dns: add memcap options

Add per state and global memcap option parsing.

11 years agodns: fix dns configure code
Victor Julien [Tue, 21 Jan 2014 09:27:28 +0000 (10:27 +0100)] 
dns: fix dns configure code

Yaml layout changed. DNS had to be updated to retrievel value
for dns flood from the correct location in the config tree.

11 years agoBug 1083 and 1084: add valgrind suppressions 786/head
Victor Julien [Mon, 20 Jan 2014 13:06:11 +0000 (14:06 +0100)] 
Bug 1083 and 1084: add valgrind suppressions

Add suppressions as these are minor issues and likely not bugs in
Suricata.

11 years agoapp-layer-ssl: fix unusual memory leak
Victor Julien [Mon, 20 Jan 2014 11:42:59 +0000 (12:42 +0100)] 
app-layer-ssl: fix unusual memory leak

In some cases the TLS state pointers to subject and issuerdn could
be overwritten by a new memory allocation, causing us to loose
track of the old.

This has been observed in the case of improper VLAN handling, where
it was suspected that multiple unrelated TLS streams were mangled
together.

11 years agoapp-layer-ssl: style fixes
Victor Julien [Mon, 20 Jan 2014 09:49:55 +0000 (10:49 +0100)] 
app-layer-ssl: style fixes

Coding style fixes for TLS handshake parser.

11 years agoapp-layer-ssl: code cleanup
Victor Julien [Mon, 20 Jan 2014 09:42:12 +0000 (10:42 +0100)] 
app-layer-ssl: code cleanup

Don't alloc a void ptr and then cast in every operation. Instead,
alloc a SSLState ptr and only case to void on returning the ptr.

11 years agoutil-device: use safe tailq foreach 784/head
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)

11 years agoBug 980: fix HTTP memory cleanup at shutdown
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.

Removed DrMemory suppressions as well.

Bug #980.

11 years agoaf-packet: fix problem introduced in recent commit 780/head
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.

Reported-by: Alessandro Guido
11 years agoRemove BUG_ON(1) in app layer event second stage preparation function.
Anoop Saldanha [Sat, 11 Jan 2014 15:08:40 +0000 (20:38 +0530)] 
Remove BUG_ON(1) in app layer event second stage preparation function.

This lets us single out and print rules that result in a failure, than
just post a core dump.

11 years agoFix make distcheck for Tile
Ken Steele [Tue, 14 Jan 2014 17:38:15 +0000 (12:38 -0500)] 
Fix make distcheck for Tile

src/Makefile.am was missing util-mpm-ac-tile-small.c which caused
release tarballs for fail to build on Tile-Gx.

11 years agoFix crash in AppLayer Proto Detect 778/head
Victor Julien [Fri, 17 Jan 2014 09:18:32 +0000 (10:18 +0100)] 
Fix crash in AppLayer Proto Detect

The App Proto Detect code would use the wrong pattern count to
index a results array, leading to SEGVs.

Bug #1080.

11 years agoCygwin: make configure pass with -Werror 773/head
Victor Julien [Mon, 16 Dec 2013 13:41:46 +0000 (14:41 +0100)] 
Cygwin: make configure pass with -Werror

11 years agoCygwin: fix compilation
Victor Julien [Mon, 16 Dec 2013 12:53:51 +0000 (13:53 +0100)] 
Cygwin: fix compilation

tm-threads.c:1190:5: error: unknown type name ‘DWORD’

11 years agoFix compiler warning:
Victor Julien [Mon, 16 Dec 2013 12:29:06 +0000 (13:29 +0100)] 
Fix compiler warning:

array subscript has type ‘char’ [-Werror=char-subscripts]

11 years agoFix coccinelle autotools check 771/head
Victor Julien [Tue, 14 Jan 2014 13:57:42 +0000 (14:57 +0100)] 
Fix coccinelle autotools check

11 years agococcinelle: add --disable-coccinelle to configure 770/head
Victor Julien [Tue, 14 Jan 2014 12:41:09 +0000 (13:41 +0100)] 
coccinelle: add --disable-coccinelle to configure

This allows disabling of the expensive cocci QA checks during
QA.

11 years agopool thread: undo CLS alignment
Victor Julien [Tue, 14 Jan 2014 12:03:43 +0000 (13:03 +0100)] 
pool thread: undo CLS alignment

This breaks clang on 32bit.

Test PoolThreadTestGrow01                                         : process killed by signal 11

11 years agoFix unittest size_t printing on 32bit
Victor Julien [Tue, 14 Jan 2014 10:48:25 +0000 (11:48 +0100)] 
Fix unittest size_t printing on 32bit

11 years agodns: tag each tx we get a reply for as replied 765/head
Victor Julien [Thu, 12 Dec 2013 12:12:13 +0000 (13:12 +0100)] 
dns: tag each tx we get a reply for as replied

Also, detect and print when server says recursion is desired.

11 years agoDNS: don't store duplicate queries
Victor Julien [Sat, 7 Dec 2013 10:41:45 +0000 (11:41 +0100)] 
DNS: don't store duplicate queries

When an exact duplicate DNS query is received, don't store it in the
tx.

11 years agomemcmp: convert all pointer arguments to be const pointers, like memcmp itself uses.
Victor Julien [Sat, 7 Dec 2013 10:29:22 +0000 (11:29 +0100)] 
memcmp: convert all pointer arguments to be const pointers, like memcmp itself uses.

11 years agodns log: cleanups
Victor Julien [Fri, 6 Dec 2013 13:43:15 +0000 (14:43 +0100)] 
dns log: cleanups

11 years agoapp-layer: API calls to check for TX aware proto
Victor Julien [Fri, 10 Jan 2014 12:02:19 +0000 (13:02 +0100)] 
app-layer: API calls to check for TX aware proto

Introduce AppLayerParserProtocolIsTxAware which returns 1 if protocol
is Tx aware, 0 if not.

11 years agoRemove GCC -no-strict-aliasing compiler flag. 764/head
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.

11 years agoFix PmqSetup() argument removal in ac-tile MPM unit tests.
Ken Steele [Fri, 10 Jan 2014 15:40:52 +0000 (10:40 -0500)] 
Fix PmqSetup() argument removal in ac-tile MPM unit tests.

Needed to remove the second argument from all the calls, which was always 0
and was removed in other tests in a previous checkin.

11 years agocounters: fix 2 scan-build warnings
Victor Julien [Thu, 19 Dec 2013 20:14:06 +0000 (21:14 +0100)] 
counters: fix 2 scan-build warnings

counters.c:1069:13: warning: Potential leak of memory pointed to by 'temp'
            SCMutexUnlock(&sc_perf_op_ctx->pctmi_lock);
            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./threads.h:121:28: note: expanded from macro 'SCMutexUnlock'
                           ^~~~~~~~~~~~~~~~~~~~
counters.c:1156:16: warning: Potential leak of memory pointed to by 'pca'
        return NULL;
               ^~~~
/usr/include/clang/3.3/include/stddef.h:77:24: note: expanded from macro 'NULL'
                       ^
2 warnings generated.

11 years agoapp-layer: configurable GetActiveTxId function 762/head
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.

11 years agoClean up TX clean up
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.

11 years agostream: don't send empty streammsg at stream end 759/head
Victor Julien [Wed, 18 Dec 2013 08:14:20 +0000 (09:14 +0100)] 
stream: don't send empty streammsg at stream end

No longer send an empty StreamMsg through the engine on stream end,
the messages were ignored anyway.

11 years agostream: increase max StreamMsg data
Victor Julien [Tue, 17 Dec 2013 19:56:58 +0000 (20:56 +0100)] 
stream: increase max StreamMsg data

Increase from 4024 bytes to 4072 to make the whole structure
4096 again.

11 years agostream: remove flags from StreamMsg
Victor Julien [Tue, 17 Dec 2013 19:52:38 +0000 (20:52 +0100)] 
stream: remove flags from StreamMsg

11 years agostream: remove per thread queue for stream msgs
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.

Large patch as it affects a lot of tests.

11 years agostream: remove flow reference from StreamMsg
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.

11 years agostream: pass TcpSession to StreamTcpReassembleProcessAppLayer
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.

11 years agostream msg: remove structure
Victor Julien [Tue, 17 Dec 2013 14:54:09 +0000 (15:54 +0100)] 
stream msg: remove structure

11 years agostream: remove unused gap structure from StreamMsg.
Victor Julien [Tue, 17 Dec 2013 14:28:47 +0000 (15:28 +0100)] 
stream: remove unused gap structure from StreamMsg.

11 years agostream: no longer process STREAM_GAP smsgs
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.

11 years agoRemove the old include support.
Jason Ish [Fri, 6 Dec 2013 19:38:26 +0000 (13:38 -0600)] 
Remove the old include support.

11 years agoCorrect coding style in decode-ethernet.c 758/head
Ken Steele [Wed, 8 Jan 2014 17:16:00 +0000 (12:16 -0500)] 
Correct coding style in decode-ethernet.c

This file is given as the example of correct coding style, so make sure it
follows the coding standard.

11 years agodebug: default logging level is notice
Eric Leblond [Mon, 16 Dec 2013 12:41:39 +0000 (13:41 +0100)] 
debug: default logging level is notice

Update the string in message because default logging level is
now notice and not info.

11 years agodoxygen: document some functions
Eric Leblond [Mon, 16 Dec 2013 10:58:47 +0000 (11:58 +0100)] 
doxygen: document some functions

11 years agodoxygen: document all code
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.

11 years agodoxygen: add profiling to generated doc.
Eric Leblond [Mon, 16 Dec 2013 10:39:45 +0000 (11:39 +0100)] 
doxygen: add profiling to generated doc.

Profiling code needs the PROFILING define to be documented.

11 years agoAdd missing UNITTESTS
Eric Leblond [Mon, 16 Dec 2013 10:38:33 +0000 (11:38 +0100)] 
Add missing UNITTESTS

There is no need for test functions to be build in normal code.

11 years agoaf-packet: update packet reading loop logic
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.

11 years agoprscript: add --norebase option
Eric Leblond [Thu, 19 Dec 2013 14:18:46 +0000 (15:18 +0100)] 
prscript: add --norebase option

If --norebase option is provided, the prscript will start a build
that can be used to check if an out-of-sync branch pass the test.

11 years agohtp layer: add memory cap counter
Eric Leblond [Mon, 30 Dec 2013 16:29:46 +0000 (17:29 +0100)] 
htp layer: add memory cap counter

This patch adds a memcap counter for HTP memory usage. Counter
is increased each time an allocation is not done due to the memcap.

11 years agohtp layer: add memory usage counter
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.

11 years agohtp layer: use memcap for HTTP related allocations
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.

11 years agoPort unittest from bug #970 for util-mpm-ac.c to util-mpm-ac-tile.c
Ken Steele [Wed, 8 Jan 2014 15:46:04 +0000 (10:46 -0500)] 
Port unittest from bug #970 for util-mpm-ac.c to util-mpm-ac-tile.c

Passes on ac-tile too.

11 years agoAdd 8-bit states to ac-tile
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.

11 years agopfring: fix live device counter usage 757/head
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.

11 years agoaf-packet: fix live device counter usage
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.

11 years agocapture: display exit stats at default verbosity
Eric Leblond [Tue, 31 Dec 2013 14:09:10 +0000 (15:09 +0100)] 
capture: display exit stats at default verbosity

This patch updates capture modes not using LiveDecice counters
to display per-thread exit statistics with default verbosity.

11 years agodevice list: clean and display stat at exit
Eric Leblond [Tue, 31 Dec 2013 14:04:33 +0000 (15:04 +0100)] 
device list: clean and display stat at exit

This patch adds a cleaning function to device list. This also
permits to display per-interface statistics during the exit.

11 years agoFix the segmentation fault while logging the host on the custom HTTP logger.
Duarte Silva [Thu, 19 Dec 2013 14:07:30 +0000 (14:07 +0000)] 
Fix the segmentation fault while logging the host on the custom HTTP logger.
- Seems to be a regression introduced in the commit
  796bfab2317699779bb0d7dca257bb97083399d8 (fix was already done in commit
  ee0b21652b00f9398869b097c3ddceb9f86600a9)
- Doesn't happen with htplib v0.5.6, but it does in the latest, v0.5.9

11 years agococcinelle: protecting regexp operator is not needed
Eric Leblond [Fri, 20 Dec 2013 09:23:39 +0000 (10:23 +0100)] 
coccinelle: protecting regexp operator is not needed

It seems there was an evolution of coccinelle and the protection
of regexp is not necessary anymore. And doing it causing the
expression not to match.

11 years agofix size_t printing
Eric Leblond [Fri, 20 Dec 2013 09:22:25 +0000 (10:22 +0100)] 
fix size_t printing

This two problem were found by the new version of the size_t cocci
test.

11 years agoapp-layer: only typedef opaque pointers once 753/head
Victor Julien [Fri, 10 Jan 2014 09:15:48 +0000 (10:15 +0100)] 
app-layer: only typedef opaque pointers once

11 years agoapp layer: void -> AppLayerProtoDetectThreadCtx
Victor Julien [Thu, 9 Jan 2014 15:40:59 +0000 (16:40 +0100)] 
app layer: void -> AppLayerProtoDetectThreadCtx

User AppLayerProtoDetectThreadCtx ptr instead of void.

11 years agoUpdate tests to use AppLayerParserThreadCtx ptr instead of void. Fix a few bugs uncov...
Victor Julien [Thu, 9 Jan 2014 15:20:21 +0000 (16:20 +0100)] 
Update tests to use AppLayerParserThreadCtx ptr instead of void. Fix a few bugs uncovered by this.

11 years agoapp-layer: Use opaque pointers instead of void
Victor Julien [Thu, 9 Jan 2014 14:10:37 +0000 (15:10 +0100)] 
app-layer: Use opaque pointers instead of void

For AppLayerThreadCtx, AppLayerParserState, AppLayerParserThreadCtx
and AppLayerProtoDetectThreadCtx, use opaque pointers instead of
void pointers.

AppLayerParserState is declared in flow.h as it's part of the Flow
structure.

AppLayerThreadCtx is declared in decode.h, as it's part of the
DecodeThreadVars structure.

11 years agoFix HTPBodyReassemblyTest01 Asan error
Victor Julien [Thu, 9 Jan 2014 11:40:08 +0000 (12:40 +0100)] 
Fix HTPBodyReassemblyTest01 Asan error

Fix improper pointer assignment in HTPBodyReassemblyTest01, causing
ASAN to error out.

11 years agoapp-layer: rename AppLayerThreadCtx funcs
Victor Julien [Thu, 9 Jan 2014 11:13:03 +0000 (12:13 +0100)] 
app-layer: rename AppLayerThreadCtx funcs

AppLayerParserGetCtxThread -> AppLayerParserThreadCtxAlloc
AppLayerParserDestroyCtxThread -> AppLayerParserThreadCtxFree

11 years agoapp layer: fix memory leak
Victor Julien [Thu, 9 Jan 2014 10:52:46 +0000 (11:52 +0100)] 
app layer: fix memory leak

Actually free the ctx in AppLayerParserDestroyCtxThread

11 years agoapp layer: uint16_t alproto -> AppProto alproto
Victor Julien [Thu, 9 Jan 2014 10:32:40 +0000 (11:32 +0100)] 
app layer: uint16_t alproto -> AppProto alproto

This conversion was missing in a couple of places.

11 years agoUse u8 for ipproto
Victor Julien [Thu, 9 Jan 2014 10:19:58 +0000 (11:19 +0100)] 
Use u8 for ipproto

In a few places in app layer and unittests u16 was used.

11 years agoApp Layer: cleanup state func naming
Victor Julien [Thu, 9 Jan 2014 10:06:59 +0000 (11:06 +0100)] 
App Layer: cleanup state func naming

Rename functions related to AppLayerState to be more consistent.

11 years agoRename AppLayerProtoDetectCtxThread -> AppLayerProtoDetectThreadCtx
Victor Julien [Thu, 9 Jan 2014 09:41:22 +0000 (10:41 +0100)] 
Rename AppLayerProtoDetectCtxThread -> AppLayerProtoDetectThreadCtx

11 years agoRename AppLayerParserParserState -> AppLayerParserState
Victor Julien [Thu, 9 Jan 2014 09:38:12 +0000 (10:38 +0100)] 
Rename AppLayerParserParserState -> AppLayerParserState

11 years agoRename AppLayerParserpCtx -> AppLayerParserProtoCtx
Victor Julien [Thu, 9 Jan 2014 09:33:54 +0000 (10:33 +0100)] 
Rename AppLayerParserpCtx -> AppLayerParserProtoCtx

11 years agoRename AppLayerParserCtxThread -> AppLayerParserThreadCtx
Victor Julien [Thu, 9 Jan 2014 09:28:34 +0000 (10:28 +0100)] 
Rename AppLayerParserCtxThread -> AppLayerParserThreadCtx

11 years agoRename AppLayerCtxThread -> AppLayerThreadCtx
Victor Julien [Thu, 9 Jan 2014 09:25:33 +0000 (10:25 +0100)] 
Rename AppLayerCtxThread -> AppLayerThreadCtx

11 years agodetect unittests: clang build fix and cleanups
Victor Julien [Thu, 9 Jan 2014 09:10:19 +0000 (10:10 +0100)] 
detect unittests: clang build fix and cleanups

A number of unittests would lead to clang build errors because
of unsafe det_ctx ptr usage. This patch fixes these and inits
det_ctx to NULL in the other detect tests.

11 years agoApp Layer: fix memory leaks
Victor Julien [Wed, 8 Jan 2014 17:43:48 +0000 (18:43 +0100)] 
App Layer: fix memory leaks

Call FlowCleanupAppLayer before setting f->proto to 0, as the former
bails out without doing anything if proto is 0.

11 years agoFix AppLayerProtoDetectPMFreeSignature related valgrind errors
Victor Julien [Wed, 8 Jan 2014 17:10:16 +0000 (18:10 +0100)] 
Fix AppLayerProtoDetectPMFreeSignature related valgrind errors

11 years agoapp proto detect: fix valgrind test warnings
Victor Julien [Wed, 8 Jan 2014 16:20:58 +0000 (17:20 +0100)] 
app proto detect: fix valgrind test warnings

Only in unittests when debug is enabled would valgrind warn about
a print statement.

11 years agoCleanup and fix scan-build warning
Victor Julien [Wed, 8 Jan 2014 16:05:04 +0000 (17:05 +0100)] 
Cleanup and fix scan-build warning

Add comments and slightly refactor to make function more understandable
and fix a scan-build warning too.

11 years agoscan-build fixes
Victor Julien [Wed, 8 Jan 2014 16:04:49 +0000 (17:04 +0100)] 
scan-build fixes

11 years agoprofiling: fix compilation
Victor Julien [Wed, 8 Jan 2014 15:11:43 +0000 (16:11 +0100)] 
profiling: fix compilation

Stream engine can't access app layer proto detection datatypes
anymore, so moved some of the logic into app-layer.c

11 years agocompile fixes
Victor Julien [Wed, 8 Jan 2014 15:11:21 +0000 (16:11 +0100)] 
compile fixes

11 years agoVarious style fixes
Victor Julien [Wed, 8 Jan 2014 15:10:26 +0000 (16:10 +0100)] 
Various style fixes

11 years agoApp layer API rewritten. The main files in question are: 745/head
Anoop Saldanha [Tue, 24 Dec 2013 10:00:57 +0000 (15:30 +0530)] 
App layer API rewritten.  The main files in question are:
app-layer.[ch], app-layer-detect-proto.[ch] and app-layer-parser.[ch].

Things addressed in this commit:
- Brings out a proper separation between protocol detection phase and the
  parser phase.
- The dns app layer now is registered such that we don't use "dnstcp" and
  "dnsudp" in the rules.  A user who previously wrote a rule like this -

  "alert dnstcp....." or
  "alert dnsudp....."

  would now have to use,

  alert dns (ipproto:tcp;) or
  alert udp (app-layer-protocol:dns;) or
  alert ip (ipproto:udp; app-layer-protocol:dns;)

  The same rules extend to other another such protocol, dcerpc.
- The app layer parser api now takes in the ipproto while registering
  callbacks.
- The app inspection/detection engine also takes an ipproto.
- All app layer parser functions now take direction as STREAM_TOSERVER or
  STREAM_TOCLIENT, as opposed to 0 or 1, which was taken by some of the
  functions.
- FlowInitialize() and FlowRecycle() now resets proto to 0.  This is
  needed by unittests, which would try to clean the flow, and that would
  call the api, AppLayerParserCleanupParserState(), which would try to
  clean the app state, but the app layer now needs an ipproto to figure
  out which api to internally call to clean the state, and if the ipproto
  is 0, it would return without trying to clean the state.
- A lot of unittests are now updated where if they are using a flow and
  they need to use the app layer, we would set a flow ipproto.
- The "app-layer" section in the yaml conf has also been updated as well.

11 years agoUse a typdef AppProto <-> uint16_t for representing app layer protocol.
Anoop Saldanha [Fri, 6 Dec 2013 11:51:57 +0000 (17:21 +0530)] 
Use a typdef AppProto <-> uint16_t for representing app layer protocol.

Some minor refactoring/cleanup, including renaming functions.

11 years agoDisabling the ssh parser temporarily, since we are moving away from some
Anoop Saldanha [Wed, 23 Oct 2013 05:55:46 +0000 (11:25 +0530)] 
Disabling the ssh parser temporarily, since we are moving away from some
of the archaic features we use in the app layer. We will reintroduce this
parser shortly. Also do note that keywords that rely on the ssh parser
would now be disabled.

11 years agoUpdate Changelog for 2.0beta2 suricata-2.0beta2
Victor Julien [Wed, 18 Dec 2013 13:01:28 +0000 (14:01 +0100)] 
Update Changelog for 2.0beta2

11 years agoconf: fix potential use-after-free on error 730/head
Victor Julien [Wed, 18 Dec 2013 11:23:50 +0000 (12:23 +0100)] 
conf: fix potential use-after-free on error

Coverity 1139544

If strdup would fail, 'node' was freed but it wasn't set to NULL. The
code then returned node. The caller would not detect there was an error
and use the freed pointer.

11 years agostream: fix potential memory loss on error
Victor Julien [Wed, 18 Dec 2013 11:17:56 +0000 (12:17 +0100)] 
stream: fix potential memory loss on error

Coverity 1139543.

If StreamTcpPseudoPacket would be called with len == 0, the packet
it acquired before checking the len value would be lost.

11 years agoRevert TmqhFlowMode alignment as it breaks on CLANG
Victor Julien [Fri, 13 Dec 2013 11:50:43 +0000 (12:50 +0100)] 
Revert TmqhFlowMode alignment as it breaks on CLANG

11 years agorealloc error handling: remove unnecessary else branch
Victor Julien [Fri, 13 Dec 2013 11:20:00 +0000 (12:20 +0100)] 
realloc error handling: remove unnecessary else branch

11 years agococcinelle: add test on realloc
Eric Leblond [Thu, 12 Dec 2013 12:34:54 +0000 (13:34 +0100)] 
coccinelle: add test on realloc

If we use SCRealloc like:
 x = SCRealloc(x, ...)
then in case of failure we are loosing the original pointer value
and the memory is lost and can not be free.

This test just check for this construction and output an error if
it finds it.

11 years agoFix realloc error handling
Eric Leblond [Thu, 12 Dec 2013 12:10:01 +0000 (13:10 +0100)] 
Fix realloc error handling

This patch is fixing realloc error handling. In case of a realloc
failure, it free the initial memory and continue existing error
handling.

The patch has been obtained via the following semantic patch and
a bit oh hand editing:

@@
expression x, E;
identifier f;
@@

f(...)
{
+ void *ptmp;
<+...
- x = SCRealloc(x, E);
+ ptmp = SCRealloc(x, E);
... when != x
- if (x == NULL)
+ if (ptmp == NULL)
{
+ SCFree(x);
+ x = NULL;
...
- }
+ } else {
+     x = ptmp;
+ }
...+>
}

@@
expression x, E;
identifier f;
statement ES;
@@

f(...) {
+ void *ptmp;

<+...
- x = SCRealloc(x, E);
+ ptmp = SCRealloc(x, E);
... when != x
- if (x == NULL) ES
+ if (ptmp == NULL) {
+ SCFree(x);
+ x = NULL;
+ ES
+ } else {
+     x = ptmp;
+ }
...+>

}

@@
expression x, E;
identifier f;
@@

f(...)
{
+ void *ptmp;
<+...
- x = SCRealloc(x, E);
+ ptmp = SCRealloc(x, E);
... when != x
- if (unlikely(x == NULL))
+ if (unlikely(ptmp == NULL))
{
+ SCFree(x);
+ x = NULL;
...
- }
+ } else {
+     x = ptmp;
+ }
...+>
}

@@
expression x, E;
identifier f;
statement ES;
@@

f(...) {
+ void *ptmp;

<+...
- x = SCRealloc(x, E);
+ ptmp = SCRealloc(x, E);
... when != x
- if (unlikely(x == NULL)) ES
+ if (unlikely(ptmp == NULL)) {
+ SCFree(x);
+ x = NULL;
+ ES
+ } else {
+     x = ptmp;
+ }
...+>

}