Commit Graph

4090 Commits (5330b1cae1b1761e2911e9ddc0a9a94a2a55c034)

Author SHA1 Message Date
Victor Julien c1190545cf Revert change in queue handler wait logic. Bug #988. 13 years ago
Victor Julien 8d6bca72f7 Improve 'host-mode' info message 13 years ago
Victor Julien 57abba2e64 Coverity 1100842: add missing return statement 13 years ago
Victor Julien afaa10b37d Coverity 1100843: remove unnecessary check 13 years ago
Victor Julien cb15000387 http: add new events for invalid host header and host part of uri 13 years ago
Victor Julien 43b39d333f http: fix some decoder events
Some events we retrieved from error messages are flag now, so check
those. Not all can be converted though. These are no longer set:

HTTP_DECODER_EVENT_INVALID_TRANSFER_ENCODING_VALUE_IN_RESPONSE
HTTP_DECODER_EVENT_INVALID_AUTHORITY_PORT

Part of Bug #982.
13 years ago
Victor Julien 636791751e http: fix field too long events 13 years ago
Victor Julien 5d10bafdba http: don't call HTPHandleWarning before HTPHandleError as the latter handles warnings and errors. 13 years ago
Victor Julien 129b6a65ca http: add test for HTTP_DECODER_EVENT_UNKNOWN_ERROR event as a result of a too long request 13 years ago
Eric Leblond 2c50e41153 reject: try to fail more gracefully
In the case of reject both, a failure in sending one way do not lead to
abort the reset procedure.
13 years ago
Eric Leblond 10b05a6361 reject: clean respond-reject code. 13 years ago
Eric Leblond 6f1cf9728e reject: delete debug line 13 years ago
Eric Leblond f05efeb46f Add reject for IPv6
With this patch reject is now available in IPv6.
13 years ago
Eric Leblond 5f224f87d1 reject: update computation of seq and ack
We have follow TCP RFC (http://tools.ietf.org/html/rfc793#section-3.4).
There is two cases depending on wether the original packet contains a
ACK.
If packet has no ACK, the RST seq number is 0 and the ACK is built the
standard way.
If packet has a ACK, the seq of the RST packet is equal to the ACK of
incoming packet and the ACK is build using packet sequence number and
size of the data.

Regarding standard Ack number, it is computed using seq number of captured
packet added to packet length. Finally 1 is added so we respect the
RFC:
    If the ACK control bit is set this field contains the value of the
    next sequence number the sender of the segment is expecting to
    receive.  Once a connection is established this is always sent.

With this patch we have some correct results. With the following rule:
    reject ssh any any -> 192.168.56.3 any (msg:"no SSH  way"; sid:3; rev:1;)
ssh connection to 192.168.56.3 is correctly resetted on client side.

But this is not perfect. If we have the following rule:
    reject tcp any any -> 192.168.56.3 22 (msg:"no way"; sid:2; rev:1;)
then the connection is not resetted on a standard ethernet network. But
if we introduce 20ms delay on packets, then it is correctly resetted.
This is explained when looking at the network trace. The reset is sent
as answer to the SYN packet and it is emitted after the SYN ACK from
server because the exchange is really fast. So this is discarded by the
client OS which has already seen a ACK for the same sequence number.

This should fix #895.
13 years ago
Eric Leblond 4e15cf2245 reject: fix typo 13 years ago
Eric Leblond efc12b24ae reject: use host-mode to set interface
This patch update reject code to send the packet on the interface
it comes from when 'host-mode' is set to 'sniffer-only'. When
'host-mode' is set to 'router', the reject packet is sent via
the routing interface.

This should fix #957.
13 years ago
Eric Leblond 9bbd2a103d reject: reindent and code cleaning
Reindent file and use some switch instead of if else if.
13 years ago
Eric Leblond 6cf7da30e2 Introduce host-mode.
This variable can be used to indicate to suricata that the host
running is running as a router or is in sniffing only mode.
This will used at least to determine which interfaces are used to
send reject message.
13 years ago
Victor Julien d8cb821875 locks: clean up locks declarations
Split threads.h into several files, where each of these files defines
all lock types and macro's.

threads.h defines the normal case
threads-debug.h defines the debug variants
threads-profile.h defines the lock profiling variants

Finally, threads-arch-tile.h moves the Tilera specifics out
13 years ago
Anoop Saldanha c5cd3562d0 Stateful detection inspection continuation API call should update per
signature's Sigmatch entry as well.
13 years ago
Victor Julien 7f0cc97f5b Thresholding: move parsing code into separate func 13 years ago
Victor Julien 8ce38ac8fe Split Thresholds and Suppression
Thresholds and suppression can be handled independently. Suppression
only suppresses output, and is not related to Threshold state tracking.

This simplifies mixing suppression and thresholding rules.

Part of the Bug #425 effort.
13 years ago
Ken Steele 592d48aab7 Use Spin locks on Tile
On Tile, replace pthread_mutex_locks with queued spin locks (ticket
locks) for dataplane processing code. This is safe when running on
dataplane cores with one thread per core. The condition variables are
no-ops when the thread is spinning anyway.

For control plane threads, unix-manager, stats-logs, thread startup,
use pthread_mutex_locks. For these locks replaced SCMutex with SCCtrlMutex
and SCCond with SCCtrlCond.
13 years ago
Victor Julien 2f4e11b1ca Fix compiler warning
app-layer-parser.c: In function ‘AppLayerPPTestData’:
app-layer-parser.c:2525:9: error: variable ‘dir’ set but not used [-Werror=unused-but-set-variable]
     int dir = 0;
         ^
13 years ago
Ken Steele 85a51638c9 Improve Signature sorting speed
Changed the signature sorting code to use a a single merge sort instead
of the multiple pass sorting that was being used. This reduces startup
time on Tile by a factor of 3.

Also replace the user array of pointers to ints with a simpler array of
ints.
13 years ago
Victor Julien 5c08b2296f DNS: copy only the length of the hardcoded string, not the length of the destination buffer. 13 years ago
Anoop Saldanha 57ed5dfd32 Fix return value from DetectProtoParse() which is used by probing
parser.
13 years ago
Anoop Saldanha ac65784cbc Fix coverity scan defect #1099714.
Sending back uninitialized variable in DetectParseProto().
13 years ago
Anoop Saldanha e383cc27cd Fix a leak in probing parsers. We were freeing just the head of the list,
instead of all the members.
13 years ago
Anoop Saldanha 980934d670 Fix a leak in app layer parser proto code. Free the proto signatures
allocated internally for PM parser.
13 years ago
Anoop Saldanha fc82614025 Fix mem leak in b2g. 13 years ago
Anoop Saldanha 06db1e4cb8 Remove unused vars alp_content_module_handle and proto_map from
struct AlpProtoDetectCtx.
13 years ago
Anoop Saldanha 558f5705eb Remove the unused flow flags - FLOW_TS_PM_PP_ALPROTO_DETECT_DONE and
FLOW_TC_PM_PP_ALPROTO_DETECT_DONE.
13 years ago
Anoop Saldanha 36220b689b Reset some flow flags when port numbers are re-used and we re-use the
flow as a part of a new session.
13 years ago
Anoop Saldanha af1df7a89d Remove the smtp parser restriction that it accepts data only in to client
direction first.
13 years ago
Anoop Saldanha 3ec411486e Fix compilation failure when we don't enable unittests. Got to #ifdef
ALPROTO_TEST.
13 years ago
Anoop Saldanha d76a5bedbc Update stream inline to use the improved app proto detection. 13 years ago
Anoop Saldanha 96d1ba9106 Cosmetic changes to app parser struct.
Removed a flag parameter introuced earlier to indicate the data
that is first acceptable by the parser.  We now use a differently
named parameter to carry out the same activity.
13 years ago
Anoop Saldanha 2cb5bdd3fa Cosmetic changes to code. Introduce human readabel flag values for some constants. Here the parameter in question is "data_first_seen_dir" for session context. 13 years ago
Anoop Saldanha e42905f3b9 indentation fix. 13 years ago
Anoop Saldanha 6bef5fda06 If we have proto mismatch from 2 directions, use one of the protos, instead of erroring out and not sending the data further to the parser.
The logic we use currently is if we have already sent some data to
a parser before we figure out we have a proto mismatch, we use the
proto from the first direction from which we have already sent the
data to the parser, else we stick to the the to client direction.
13 years ago
Anoop Saldanha 976a86def4 Introduce convenience macro to set Stream app proto completion flag. 13 years ago
Anoop Saldanha 16144fe38a Rename function pointer var to use the FuncPtr typing convention. Resupply "dns" as the alproto name for ALPROTO_DNS. 13 years ago
Anoop Saldanha 8ae92c7a5e Add unittest to test for http ambiguous host header.
Previously we would not check the port part of the host from the uri
hostname, while we did use the port part from the host header, leading
to FPs.
13 years ago
Anoop Saldanha d0c5f51293 Update rule engine relationship with regard to setting ip protocol between specifying protocol after action, ip_proto and app-layer-protocol.
Now we can specify alproto, ip_proto combinations this way

alert dns (ip_proto:[tcp/udp];)
alert ip (app-layer-protocol:dns;)
alert ip (app-layer-protocol:dns; ip_proto:tcp;)
alert tcp (app-layer-protocol:dns:)

so on.  Neater than using dnstcp/dnsudp.

This is related to feature #424.
13 years ago
Anoop Saldanha 6eb8f66f0a alert ipv4 and alert ipv6 specified proto rules should be treated and PROTO_ANY just like how we treat alert ip rules. 13 years ago
Anoop Saldanha f592c481dc Introduce a separate inspection engine for app events. 13 years ago
Anoop Saldanha 9e4eec200f Update htp event handler to both warning and error events regardless of any conditions. 13 years ago
Anoop Saldanha b1dffdfbe0 Add app layer protocol packet event detection support. 13 years ago
Anoop Saldanha 5e2d9dbdc3 Add and use EventGetInfo for getting info on an event.
Also update existing parsers and app-layer-event Setup to use this.
13 years ago
Anoop Saldanha 60a2b157b2 Fix duplicate packet decoder events. Add event entries that were missing as well. 13 years ago
Anoop Saldanha 1077acecd7 validate dns sigs that are reported as plain dns and not dnsudp or dnstcp. 13 years ago
Anoop Saldanha 6cb0014287 Move app event module registration as a part of app layer proto table. 13 years ago
Anoop Saldanha 64b0939b4a code cleanup. 13 years ago
Anoop Saldanha 0d7159b525 App layer protocol detection updated and improved. We now use
confirmation from both directions and set events if there's a mismatch
between the 2 directions.

FPs from corrupt flows have disappeared with this.
13 years ago
Anoop Saldanha 22c05da3cd Replace ssn appproto_detection_completed flag with individual stream ones. 13 years ago
Anoop Saldanha c044541b1c Provide convenience macros for setting flow flags on protocol matching by
PM and PP phase.

Replace the areas of the code that would otherwise rely on setting/reading
these flags with these macros.

Other minor tweaks to some api calls.
13 years ago
Anoop Saldanha 00f546e739 update pmp to return whole set of matches, rather than a single match. 13 years ago
Anoop Saldanha 4f7339c423 code cleanup. 13 years ago
Anoop Saldanha 8e8bc49063 Introduce detection parser function pointer. 13 years ago
Anoop Saldanha 94e40907e2 feature #727 - Add support for app-layer-protocol:<protocol> keyword 13 years ago
Anoop Saldanha 6f8cfd999f Allow detection ports for alproto to be specified via the conf file.
To understand the option have a look at the option

app-layer.protocols.tls.detection-ports
13 years ago
Anoop Saldanha ddde572fba Introduce new options into the conf file to enable/disable -
1. Proto detection
2. Parsers

For app layer protocols.

libhtp has now been moved to the section under app-layer.protocols.http,
but we still provide backward compatibility with older conf files.
13 years ago
Anoop Saldanha d9686fae57 Now supports accepting port addresses as strings, like the ones accepted in our rules. As a consequence we now accept port range, and other such combination. Support PP for ports based on ipproto as well. 13 years ago
Victor Julien 48b5513ed9 Properly clean up decoder event rules
Addresses:
~~Dr.M~~ Error #3: LEAK 120 direct bytes 0x08a26ac8-0x08a26b40 + 1871 indirect bytes
~~Dr.M~~ # 0 replace_malloc                               [/work/drmemory_package/common/alloc_replace.c:2292]
~~Dr.M~~ # 1 SigGroupHeadAlloc                            [/home/victor/dev/oisf/src/detect-engine-siggroup.c:144]
~~Dr.M~~ # 2 SigGroupHeadAppendSig                        [/home/victor/dev/oisf/src/detect-engine-siggroup.c:1014]
~~Dr.M~~ # 3 DetectEngineAddDecoderEventSig               [/home/victor/dev/oisf/src/detect.c:3026]
~~Dr.M~~ # 4 SigAddressPrepareStage2                      [/home/victor/dev/oisf/src/detect.c:3075]
~~Dr.M~~ # 5 SigGroupBuild                                [/home/victor/dev/oisf/src/detect.c:4311]
~~Dr.M~~ # 6 SigLoadSignatures                            [/home/victor/dev/oisf/src/detect.c:464]
~~Dr.M~~ # 7 LoadSignatures                               [/home/victor/dev/oisf/src/suricata.c:1706]
~~Dr.M~~ # 8 main                                         [/home/victor/dev/oisf/src/suricata.c:1994]
13 years ago
Victor Julien c43e078db8 ipproto: improve cleanup
To address:
~~Dr.M~~ Error #2: LEAK 16 direct bytes 0x08399688-0x08399698 + 2 indirect bytes
~~Dr.M~~ # 0 replace_malloc                      [/work/drmemory_package/common/alloc_replace.c:2292]
~~Dr.M~~ # 1 SigMatchAlloc                       [/home/victor/dev/oisf/src/detect-parse.c:201]
~~Dr.M~~ # 2 DetectIPProtoSetup                  [/home/victor/dev/oisf/src/detect-ipproto.c:523]
~~Dr.M~~ # 3 SigParseOptions                     [/home/victor/dev/oisf/src/detect-parse.c:510]
~~Dr.M~~ # 4 SigParseOptions                     [/home/victor/dev/oisf/src/detect-parse.c:523]
~~Dr.M~~ # 5 SigParse                            [/home/victor/dev/oisf/src/detect-parse.c:881]
~~Dr.M~~ # 6 SigInitHelper                       [/home/victor/dev/oisf/src/detect-parse.c:1309]
~~Dr.M~~ # 7 SigInit                             [/home/victor/dev/oisf/src/detect-parse.c:1456]
~~Dr.M~~ # 8 DetectEngineAppendSig               [/home/victor/dev/oisf/src/detect-parse.c:1728]
~~Dr.M~~ # 9 DetectLoadSigFile                   [/home/victor/dev/oisf/src/detect.c:334]
~~Dr.M~~ #10 SigLoadSignatures                   [/home/victor/dev/oisf/src/detect.c:422]
~~Dr.M~~ #11 LoadSignatures                      [/home/victor/dev/oisf/src/suricata.c:1706]
13 years ago
Victor Julien 1006d905d0 Improve memory cleanup for decoder-events
To address:

~~Dr.M~~ Error #1: LEAK 1 direct bytes 0x0892c108-0x0892c109 + 0 indirect bytes
~~Dr.M~~ # 0 replace_malloc                        [/work/drmemory_package/common/alloc_replace.c:2292]
~~Dr.M~~ # 1 DetectEngineEventParse                [/home/victor/dev/oisf/src/detect-engine-event.c:173]
~~Dr.M~~ # 2 _DetectEngineEventSetup               [/home/victor/dev/oisf/src/detect-engine-event.c:204]
~~Dr.M~~ # 3 DetectDecodeEventSetup                [/home/victor/dev/oisf/src/detect-engine-event.c:248]
~~Dr.M~~ # 4 SigParseOptions                       [/home/victor/dev/oisf/src/detect-parse.c:510]
~~Dr.M~~ # 5 SigParseOptions                       [/home/victor/dev/oisf/src/detect-parse.c:523]
~~Dr.M~~ # 6 SigParse                              [/home/victor/dev/oisf/src/detect-parse.c:881]
~~Dr.M~~ # 7 SigInitHelper                         [/home/victor/dev/oisf/src/detect-parse.c:1309]
~~Dr.M~~ # 8 SigInit                               [/home/victor/dev/oisf/src/detect-parse.c:1456]
~~Dr.M~~ # 9 DetectEngineAppendSig                 [/home/victor/dev/oisf/src/detect-parse.c:1728]
~~Dr.M~~ #10 DetectLoadSigFile                     [/home/victor/dev/oisf/src/detect.c:334]
~~Dr.M~~ #11 SigLoadSignatures                     [/home/victor/dev/oisf/src/detect.c:422]
13 years ago
Victor Julien 1be6a8a48b Fix small leak in ports validation at startup 13 years ago
Victor Julien 3601091952 flowint: further setup fixes and cleanups 13 years ago
Victor Julien 8080494e9a counters: consolidate counters after all ThreadInit functions of a thread have run. This prevents duplicate and overwriting memory allocations. 13 years ago
Victor Julien 7f8d256e7c Fix tests that didn't expect radix to be freed 13 years ago
Victor Julien d2d784e31a radix: actually free a tree in SCRadixReleaseRadixTree 13 years ago
Victor Julien c94b920874 flowint: fix compile warning 13 years ago
Victor Julien a8c416fc8b flowint: fix setup memory leaks 13 years ago
Victor Julien 16130cc974 ssh: fix memleaks during ssh.softwareversion init and cleanup 13 years ago
Victor Julien ec724a1e56 urilen: fix memory leak when freeing the rule 13 years ago
Anoop Saldanha cfa2cda42b fix for bug #973.
An alternative solution for bug #970.

For chopped patterns, which in it's whole is a duplicate of another
pattern we assign an unique content id.
13 years ago
Anoop Saldanha 4da2f29054 Unittest for bug #973. 13 years ago
Victor Julien 0bfba8352d pcre: check for pcre_free_study, fall back to pcre_free if it unavailable 13 years ago
Victor Julien dd76e679fe mpm: clean up stream thread ctx 13 years ago
Victor Julien 6f450785fc profiling: properly clean up thread local memory. 13 years ago
Victor Julien eca1a8d73a profiling: don't alloc 0 bytes block if no rules are used 13 years ago
Victor Julien 468a8e1ca3 Properly cleanup NSS ctx 13 years ago
Victor Julien eedd4329da Change ParseSize api to not leak memory and only setup pcre once. 13 years ago
Victor Julien 3d78cc8ca6 DNS: free TX events using proper function 13 years ago
Victor Julien 6f2cb141cf Http: improve tx data cleanup 13 years ago
Victor Julien 239ab202c9 stream: clean up queue list in all cases 13 years ago
Victor Julien 67c12c61d3 Http: fix memory leaks when cleaning up our per-tx storage 13 years ago
Victor Julien 6aed56d093 Dns: fix memory leak when events are set 13 years ago
Anoop Saldanha cd80dcbfd4 bug #955 - Fix SSL parsing issue.
The parser wasn't carrying out a bounds check on record length while
in the middle of parsing a handshake.  As a result we would step onto the
next record header and consider it a part of the current handshake.

- Contains an unittest to test the issue.
- Disable the duplicate parser unittest registration.

The issue came to light through an irregular ssl record, which was
reported by Sebastian Roschke, via CVE-2013-5919.

Thanks to Sebastian Roschke for reporting this issue.
13 years ago
Anoop Saldanha 8c1e855632 fix for bug #970(ac-gfbs).
Content strings that are a duplicate of a pattern from another sig, but
have a fast_pattern chop being applied, would end up being assigned the
same pattern id as the duplicate string.  But the string supplied to the
mpm would be the chopped string, which might result in the state_table
output_state content entry being over-riden by the the fuller string at
the final state of the smaller content length, because of which during a
match we might end up inspecting the search buffer against the fuller
content pattern, instead of the chopped pattern, which would end up being
an inspection beyond the buffer bounds.
13 years ago
Anoop Saldanha 92a8b2b738 Unittest to display bug #970(ac-gfbs). 13 years ago
Anoop Saldanha 496f30a5e4 fix for bug #970(ac-bs).
Content strings that are a duplicate of a pattern from another sig, but
have a fast_pattern chop being applied, would end up being assigned the
same pattern id as the duplicate string.  But the string supplied to the
mpm would be the chopped string, which might result in the state_table
output_state content entry being over-riden by the the fuller string at
the final state of the smaller content length, because of which during a
match we might end up inspecting the search buffer against the fuller
content pattern, instead of the chopped pattern, which would end up being
an inspection beyond the buffer bounds.
13 years ago
Anoop Saldanha af95df67a5 Unittest to display bug #970(ac-bs). 13 years ago
Victor Julien 68ba9df8a0 Fix valgrind warning on memrchr unittest. 13 years ago
Anoop Saldanha d2ea799d38 fix for bug #970.
Content strings that are a duplicate of a pattern from another sig, but
have a fast_pattern chop being applied, would end up being assigned the
same pattern id as the duplicate string.  But the string supplied to the
mpm would be the chopped string, which might result in the state_table
output_state content entry being over-riden by the the fuller string at
the final state of the smaller content length, because of which during a
match we might end up inspecting the search buffer against the fuller
content pattern, instead of the chopped pattern, which would end up being
an inspection beyond the buffer bounds.
13 years ago
Anoop Saldanha da75db9330 Unittest to display bug #970. 13 years ago
Victor Julien 397a55457d Add sanity checks for command line argument handling
Coverity 1075221.

Normally getopt_long should cover this case, but can't hurt to
add in some extra checks.
13 years ago
Victor Julien c8b71938ff Add a fallback memrchr implementation for those platforms that dont support it. Bug #963. 13 years ago
Victor Julien e77b21a7f7 Suppress compiler warning about comparing signed and unsigned vars 13 years ago
Victor Julien bb8298ffa2 Move header thread_affinity declaration to extern to avoid duplicate declarations. 13 years ago
Victor Julien 3470b07ea5 Fix several compile and runtime warnings found by clang 3.2 with the -fsanitize=address option. 13 years ago
Victor Julien c82ecf553a Tag: document in the code that 'tag' is compatible with ip only 13 years ago
Victor Julien d12761233c Don't set tag on pseudo packets 13 years ago
Victor Julien 02cbbd0b89 unified2: fix tags not being logged. Bug #968 13 years ago
Anoop Saldanha 3749fc98fd Modify handling of negated content.
The old behaviour of returning a failure if we found a pattern while
matching on negated content is now changed to continuing searching
for other combinations where we don't find the pattern for the
negated content.

Thanks to Will Metcalf for reporting this.
13 years ago
Victor Julien 8539791c7e Coverity 1038102: remove dead code from host hash 13 years ago
Victor Julien 8237bbf18a Coverity 1038101: remove dead code from host hash timeout code 13 years ago
Victor Julien 440124a4b9 Coverity 1038100: remove dead code from flow hash timeout code(2) 13 years ago
Victor Julien 243060a6b7 Coverity 1038099: remove dead code from flow hash timeout code 13 years ago
Victor Julien 2e82772a0a Coverity 1038098: remove dead code from flow hash 13 years ago
Victor Julien aecefd00bd Coverity 1038095: remove dead code from defrag hash timeout code 13 years ago
Victor Julien 16056d51f2 Coverity 1038094: remove dead code from defrag hash 13 years ago
Victor Julien 32503bafaa Coverity 1038089: error check fseek call 13 years ago
Victor Julien 4827a4dcef Coverity 400477: pcre_get_substring retval
Add missing return code check to pcre_get_substring call.
13 years ago
Victor Julien 790866656b Coverity 1038129 fix
Don't leak memory on malloc error in b2gm mpm implementation.
13 years ago
Victor Julien 33919559d0 Fix memory leak on invalid luajit signature. Coverity 1038520. 13 years ago
Victor Julien 51c6a333d9 geoip: never try to store more locations than possible (Coverity 1038517) 13 years ago
Victor Julien 3cf3b485f2 Coverity 1038138 fix
Clean up parsing code to suppress Coverity:
Dereference before null check (REVERSE_INULL)

Proper checking was already done.
13 years ago
Victor Julien 27ea4232fe Coverity 1038134 fix
Cleaned up error check. "ipdup" can only be non-NULL there, so remove check
that confused coverity.
13 years ago
Victor Julien ecd5c7573b Coverity 1038135 fix
Small cleanup in the error handling. The extra null check confused
Coverity.
13 years ago
Victor Julien 38b6103ff5 Coverity 1038133 fix
Clean up parsing code to suppress Coverity:
Dereference before null check (REVERSE_INULL)

Proper checking was already done.
13 years ago
Ken Steele 50f859e9f2 Move SIMD implementations out of detect.c
Move SIMD the implementations of SigMatchSignaturesBuildMatchArray()
for SSE3 and Tile out of detect.c to reduce the size of the file.

Also moved SIMD unit tests to detect-simd.c
13 years ago
Victor Julien 7f140f6726 Coverity 1038111: fix local overrun of a string in app layer proto detect setup code. 13 years ago
Ken Steele eb4f0da97f Change one more atomic size in detect.h
Change uint16_t to int for better tile atomic performance. Checked with
pahole that it doesn't increase the size of the structure.
13 years ago
Ken Steele b08ddfa7f1 Support for Tile Gx atomic instructions
Tilera's GCC supports the GCC __sync_ intrinsics.

Increase the size of some atomic variables for better performance on
Tile.  The Tile-Gx architecture has native support for 32-bit and
64-bit atomic operations, but not 8-bit and 16-bit, which are emulated
using 32-bit atomics, so changing some 16-bit and 8-bit atomic into
ints improves performance.

Increasing the size of the atomic variables modified in this change
does not increase the total size of the structures in which they
reside because of existing padding requirements. The one case that
would increase the size of the structure (Flow_) was confitionalized
to only change the size on Tile.
13 years ago
Anoop Saldanha 54847e396f unittests for gzip, deflate http compression, multiple stacked
compressions, cunning compression that's not what it says it is, etc.

These unittests are tweaked to pass.  When libhtp fixes these issues
we will have to reenable them.
13 years ago
Anoop Saldanha 94e2527606 Introduce a saner way to validate the completion of request and
response bodies.

Also don't change app state for http from inside inspection.
13 years ago
Anoop Saldanha dcdcbd9721 Fix creating a backup of htp config. This is used by unittests that
changed htp config.
13 years ago
Ken Steele 62540eff3e Align some structures to cacheline
Align strucutres with pthread mutex locks to start on cachelines to keep
the lock within one cacheline.
13 years ago
Ken Steele d84079ba7d Move FlowIncrUsecnt to header file to allow for inlining.
Move FlowIncrUsecnt() and FlowDecrUsecnt() from flow.c to flow.h to
allow for inlining.
13 years ago
Ken Steele e05034f5dd New Multi-pattern matcher, ac-tile, optimized for Tile architecture.
Aho-Corasick mpm optimized for Tilera Tile-Gx architecture. Based on the
util-mpm-ac.c code base. The primary optimizations are:
1) Matching function used Tilera specific instructions.
2) Alphabet compression to reduce delta table size to increase cache
   utilization  and performance.

The basic observation is that not all 256 ASCII characters are used by
the set of multiple patterns in a group for which a DFA is
created. The first reason is that Suricata's pattern matching is
case-insensitive, so all uppercase characters are converted to
lowercase, leaving a hole of 26 characters in the
alphabet. Previously, this hole was simply left in the middle of the
alphabet and thus in the generated Next State (delta) tables.

A new, smaller, alphabet is created using a translation table of 256
bytes per mpm group. Previously, there was one global translation
table for converting upper case to lowercase.

Additional, unused characters are found by creating a histogram of all
the characters in all the patterns. Then all the characters with zero
counts are mapped to one character (0) in the new alphabet. Since
These characters appear in no pattern, they can all be mapped to a
single character and still result in the same matches being
found. Zero was chosen for the value in the new alphabet since this
"character" is more likely to appear in the input. The unused
character always results in the next state being state zero, but that
fact is not currently used by the code, since special casing takes
additional instructions.

The characters that do appear in some pattern are mapped to
consecutive characters in the new alphabet, starting at 1. This
results in a dense packing of next state values in the delta tables
and additionally can allow for a smaller number of columns in that
table, thus using less memory and better packing into the cache. The
size of the new alphabet is the number of used characters plus 1 for
the unused catch-all character.

The alphabet size is rounded up to the next larger power-of-2 so that
multiplication by the alphabet size can be done with a shift.  It
might be possible to use a multiply instruction, so that the exact
alphabet size could be used, which would further reduce the size of
the delta tables, increase cache density and not require the
specialized search functions. The multiply would likely add 1 cycle to
the inner search loop.

Since the multiply by alphabet-size is cleverly merged with a mask
instruction (in the SINDEX macro), specialized versions of the
SCACSearch function are generated for alphabet sizes 256, 128, 64, 32
and 16.  This is done by including the file util-mpm-ac-small.c
multiple times with a redefined SINDEX macro. A function pointer is
then stored in the mpm context for the search function. For alpha bit
sizes of 8 or smaller, the number of states usually small, so the DFA
is already very small, so there is little difference using the 16
state search function.

The SCACSearch function is also specialized by the size of the value
stored in the next state (delta) tables, either 16-bits or 32-bits.
This removes a conditional inside the Search function. That
conditional is only called once, but doesn't hurt to remove
it. 16-bits are used for up to 32K states, with the sign bit set for
states with matches.

Future optimization:

The state-has-match values is only needed per state, not per next
state, so checking the next-state sign bit could be replaced with
reading a different value, at the cost of an additional load, but
increasing the 16-bit next state span to 64K.

Since the order of the characters in the new alphabet doesn't matter,
the new alphabet could be sorted by the frequency of the characters in
the expected input stream for that multi-pattern matcher. This would
group more frequent characters into the same cache lines, thus
increasing the probability of reusing a cache-line.

All the next state values for each state live in their own set of
cache-lines. With power-of-two sizes alphabets, these don't overlap.
So either 32 or 16 character's next states are loaded in each cache
line load. If the alphabet size is not an exact power-of-2, then the
last cache-line is not completely full and up to 31*2 bytes of that
line could be wasted per state.

The next state table could be transposed, so that all the next states
for a specific character are stored sequentially, this could be better
if some characters, for example the unused character, are much more
frequent.
13 years ago
Victor Julien 77b429c402 xff: fix unittest crashes 13 years ago
Victor Julien 05d68ce394 xff: don't do xff check if there are no alerts anyway. 13 years ago
Duarte Silva 7dbb305255 Adds X-Forwarded-For support to the Unified2 output format
- Added the Unified2 file format related constants
 - Added IPv6 support
 - Two modes of operation with a fall-back to "extra-data" mode if
   "overwrite" mode is not applicable
 - Changed the configuration loading code to handle the new
   configuration structure
 - When creating the packet that fakes the one that generated the alert
   the flow direction wasn't taken into account in overwrite mode
 - Fixed BUG_ON condition
13 years ago
Victor Julien 900918a5d1 Bug #948: detect thread local storage support 13 years ago
Ken Steele 0861d3a2a3 Minor optimization in time caching code.
Reduced the size of the cached string buffer from 128 to 32, which is
still larger than the largest possible time string, which is 26
characters.

Added a check for the user passing in an output buffer that is smaller
than the cached string. Previously, the code would have copied past
the end of the users buffer.
13 years ago
Anoop Saldanha 49dcb0ca84 fix for #925.
Log sensible error message when the user doesn't supply a value for
stream.prealloc-sessions or when the values supplied in invalid and
the engine resorts to using a default.
13 years ago
Anoop Saldanha db6ef81fb0 fix for #926.
Supply meaningful error message when user supplies invalid value for
host.prealloc.
13 years ago
Anoop Saldanha b90a56b626 fix for #927.
Print an error message when the user supplies an invalid value for
detect-thread-ratio in the conf file.
13 years ago
Anoop Saldanha bed3f605fa Fix for #922.
Add more relevant error message when we supply invalid value for
defrag.trackers and defrag.hash-size
13 years ago
Anoop Saldanha 6608e7f523 Introduce generic utility API to log message on invalid config entry. 13 years ago
Victor Julien 6d34834623 Runmode fixes and cleanups
Bug #939: thread name buffers are sized inconsistently
These buffers are now all fixed at 16 bytes.

Bug #914: Having a high number of pickup queues (216+) makes suricata crash
Fixed so that we can now have 256 pickup queues, which is the current built-in
maximum. Improved the error reporting.

Bug #928: Max number of threads
Error reporting improved. Issue was the same as #914.
13 years ago
Anoop Saldanha 56143131da Fix unittests that use chunked encoding. 13 years ago
Nelson Escobar ef4d11aeb5 Use the Async versions of SCCudaMemcpy* to improve gpu performance. 13 years ago
Eric Leblond 77f2b9968e autotools: use builddir instead of srcdir
srcdir is supposed to be read-only when running distcheck so it is better to
create the log directory in builddir.
13 years ago
Ignacio Sanchez 1b2f251866 Various custom http logging improvements
Cookie is parsed now using uint8_t pointers (inliniac PR comments)
Changed buffer size to a power of 2 (8192) and cookie value extraction function to static (inliniac PR comments)
Added %b for request size (vinfang patch)
Writing "-" if an unknown % directive is used (vinfang patch)
Fixed bug in cookie parser
Fixed format string issue logging literal values
Improve error handling (Victor Julien comments)

(patchset rebased and reworded by Victor Julien)
13 years ago
Ignacio Sanchez 8051dc8a6a Added modifications suggested by Charles Smutz (https://redmine.openinfosecfoundation.org/issues/602) 13 years ago
Ignacio Sanchez 796bfab231 Added support for %{cookiename}C
Added support for the definition of maximun length. ie: %[50]{user-agent}i
Some small bugfixes
13 years ago
Eric Leblond 3dbf6c6fee solaris: fix compilation failure
This patch fixes a compilation failure on Solaris. Compiler does
not support when a function returning void is used in return of
an other function returning void.
13 years ago