Commit Graph

371 Commits (d0f3f2d4628d6b5d42d5b9a6317d009e3e9d8127)

Author SHA1 Message Date
Philippe Antoine 20423fdd38 style: remove some useless return
and remove empty line before end of function
2 years ago
Philippe Antoine ce16a56a1f detect: unify functions for multi-buffer
Ticket: 6575

Multi buffers keywords now use a single registration function
DetectAppLayerMultiRegister with a GetBuffer argument.

This GetBuffer function pointer is similar to the ones used by
single-buffer keyword, except that it takes an additional
parameter which is the index of the buffer to get.
Under the hood, an anonymous union between these 2 functions
pointers types is used.

In the end, this deduplicates code, especially the calls to
DetectEngineContentInspection
2 years ago
Philippe Antoine b113bdd9e3 src: remove unused headers-exported functions
+ remove double definition of IPPairLock

Ticket: #4083
2 years ago
Victor Julien c312d670d4 mpm/ac: implement endswith
When a pattern is using endswith, only consider it a match when it
is the end of the data.

Ticket: #6852.
2 years ago
Victor Julien 124a8dea20 detect/mpm: don't test for impossible condition
Functions can't get called with NULL signature or NULL
Signature::init_data.
3 years ago
Victor Julien 11bf60aa3a detect/mpm: minor cleanup 3 years ago
Victor Julien bd66504a43 detect: implement --qa-skip-prefilter
Option meant for testing performance of rule engine w/o prefilter
optimizations.
3 years ago
Jason Ish 50be098839 detect: rename DetectAppLayerMpmRegister2 to DetectAppLayerMpmRegister
The old DetectAppLayerMpmRegister has not been around since 4.1.x.
Rename the v2 of this function to a versionless function as there is no
documentation referring to what the 2 means.
3 years ago
Victor Julien 0b21b543a2 mpm/ac-bs: add warning if still used
Fall back to default matcher.

Ticket #6586.
3 years ago
Victor Julien 68a2fcaad3 mpm: thread ctx cleanups
Remove unused thread ctx' from AC variants

Use single thread store in detection.

Minor cleanups.
3 years ago
Victor Julien 3fb92eec6f detect/mpm: remove useless checks
The pattern store has already done these checks before.
3 years ago
Jeff Lucovsky f1ddd310f7 mpm: Use typedef for mpm registration
Issue: 4145
3 years ago
Victor Julien da89164ba1 detect: spelling: DetectBufferMpmRegistry 3 years ago
Victor Julien ad88efc2d8 detect: support multi buffer matching
Multi buffer matching is implemented as a way for a rule to match
on multiple buffers within the same transaction.

Before this patch a rule like:

    dns.query; content:"example"; dns.query; content:".com";

would be equivalent to:

    dns.query; content:"example"; content:".com";

If a DNS query would request more than one name, e.g.:

    DNS: [example.net][something.com]

Eeach would be inspected to have both patterns present. Otherwise,
it would not be a match. So the rule above would not match, as neither
example.net and somthing.com satisfy both conditions at the same time.

This patch changes this behavior. Instead of the above, each time the
sticky buffer is specified, it creates a separate detection unit. Each
buffer is a "multi buffer" sticky buffer will now be evaluated against
each "instance" of the sticky buffer.

To continue with the above example:

    DNS: [example.net] <- matches 'dns.query; content:"example";'
    DNS: [something.com] <- matches 'dns.query; content:".com"'

So this would now be a match.

To make sure both patterns match in a single query string, the expression
'dns.query; content:"example"; content:".com";' still works for this.

This patch doesn't yet enable the behavior for the keywords. That is
done in a follow up patch.

To be able to implement this the internal storage of parsed rules
is changed. Until this patch and array of lists was used, where the
index was the buffer id (e.g. http_uri, dns_query). Therefore there
was only one list of matches per buffer id. As a side effect this
array was always very sparsely populated as many buffers could not
be mixed.

This patch changes the internal representation. The new array is densely
packed:

    dns.query; content:"1"; dns.query; bsize:1; content:"2";

    [type: dns_query][list: content:"1";]
    [type: dns_query][list: bsize:1; content:"2";]

The new scheme allows for multiple instances of the same buffer.
These lists are then translated into multiple inspection engines
during the final setup of the rule.

Ticket: #5784.
3 years ago
Victor Julien 9f0bea5410 detect: remove DetectEngineCtx members
Members were set but not checked.
3 years ago
Victor Julien 9b4fb63a7b detect/mpm: minor code cleanups 3 years ago
Victor Julien e624328deb detect: split mpm per alproto for file.data & others
Instead of a shared mpm context for just "file.data" or "file.magic"
use per alproto mpms. This way http file.data rules won't affect smb
file.data performance.

Ticket: #4378.
3 years ago
Victor Julien a806445abf mpm factory: include alproto
In preparation of spliting out mpm's for keywords shared by
multiple protocols, like file.data.
3 years ago
Victor Julien b31ffde6f4 output: remove error codes from output 4 years ago
Victor Julien 39f5c7f56a error: use SC_EINVAL for invalid input 4 years ago
Victor Julien cdd52dc8cd detect/mpm: output cleanups 4 years ago
Juliana Fajardini 5f4bcfe313 detect/engine: fix typos in assorted files 4 years ago
Philippe Antoine c5cf2967b3 detect: fix integer warnings
Ticket: #4516
4 years ago
Philippe Antoine 45d1a9ae77 detect: faster linked list copy
In DetectAppLayerInspectEngineCopyListToDetectCtx
Avoid quadratic complexity by remembering last element
of the linked list we are inserting into
4 years ago
Philippe Antoine f30975fb16 app-layer: fix integer warnings
Ticket: 4516
4 years ago
Victor Julien 087151ddc3 detect/mpm: initialization micro optimization 4 years ago
Victor Julien 54a6dd09dd detect: pattern id assignment through hash table
Only consider active part of the pattern for mpm (so consider chop).

Move data structure to hash list table over the custom array logic.
4 years ago
Victor Julien 9e6370ae2e detect: optimize mpm-engine setup
Instead of a loop over the rules in a group *per engine* do a single
loop in which all the engines are prepared in parallel.
4 years ago
Victor Julien 3352c0bee4 detect: initialization optimization
A lot of time was spent in `SigMatchListSMBelongsTo` for the `mpm_sm`.

Optimize this by keeping the value at hand during Signature parsing and
detection engine setup.
4 years ago
Philippe Antoine 529678d501 dns: wrap with HAVE_LUA
This is just code style, to minimize the compiled code.
5 years ago
Victor Julien f6f124f283 detect/engine: support frames
Implement the low level detect engine support for inspecting frames,
including MPM, transforms and inspect API's.
5 years ago
Victor Julien ecce116117 detect/fast_pattern: allow for rule time registration
In preparation of more dynamic logic in rule loading also doing
some registration, allow for buffers to be registered as fast_patterns
during rule parsing.

Leaves the register time registrations mostly as-is, but copies the
resulting list into the DetectEngineCtx and works with that onwards.
This list can then be extended.
5 years ago
Victor Julien 5bcaae0a01 detect: use hashes for all buffer to id
Instead of a map that is constantly realloc'd, use 2 hash tables for
DetectBufferType entries: one by name (+transforms), the other by
id. Use these everywhere.
5 years ago
Victor Julien ed87784907 detect: enforce max app-layer progress
Allow progress values in the range 0-47 so we have 48 bits to track
prefilter engines.

Mark bits 48-62 as reserved explicitly.

Add debug validation checks to make sure the reserved space isn't used.
5 years ago
Victor Julien ce18f4b8e2 detect/mpm: micro optimization for initialization
Do less expensive check first.
5 years ago
Philippe Antoine bbbb816ed6 detect: debug validation for list ids overflows 5 years ago
Victor Julien 86681c9d7c detect: move init only array to init data 5 years ago
Victor Julien 975062cf40 detect: track base id for xform buffers
Buffers with transforms are based on the non-transformed "base"
buffer, with a new ID assigned and the transform callbacks added.

This patch stores the id of the original buffer in the new buffer
inspect and prefilter structures. This way the buffers with and
without transforms can share some of the logic are progression
of file and body inspection trackers.

Related tickets: #4361 #4199 #3616
6 years ago
Victor Julien e7b5201016 detect/mpm: remove usused cleanup function 6 years ago
Victor Julien 82d7f64630 detect/mpm: improve transforms handling
Make sure keywords with transforms get their own mpm ctx, instead of
sharing it with the 'pure' version of the keyword.
6 years ago
Victor Julien ee15bd8076 detect/mpm: rename variable to ease code review 6 years ago
Victor Julien 9831839388 detect/mpm: fix hs check 6 years ago
Victor Julien 4726d7027c detect/mpm: 'mpm-algo' parsing cleanups 6 years ago
Shivani Bhardwaj 6f7d8e50c8 src: use FatalError whenever possible
Replaces all patterns of SCLogError() followed by exit() with
FatalError(). Cocci script to do this:

@@
constant C;
constant char[] msg;
@@

- SCLogError(C,
+ FatalError(SC_ERR_FATAL,
  msg);
- exit(EXIT_FAILURE);

Closes redmine ticket 3188.
6 years ago
Jeff Lucovsky fb409664d2 detect: byte_math support 6 years ago
Shivani Bhardwaj 537fb7a1c6 hyperscan: better error message if not compiled 6 years ago
Jeff Lucovsky 5d10db88bc detect/transform: Support transform options
This commit adds support for transform-specific options. During Setup,
transforms have the signature string available for options detection.
When a transform detects an option, it should convert the option into an
internal format and supply a pointer to this format as the last argument
to DetectSignatureAddTransform.

Transforms that support options must provide a function in their
Sigmatch table entry. When the transform is freed, a pointer to the
internal format of the option is passed to this function.
6 years ago
Victor Julien f903766849 detect/mpm: don't process empty store 6 years ago
Jeff Lucovsky 218a5c4345 mpm: Fix typos and spelling errors 7 years ago
Jeff Lucovsky db8527e7b3 detect/mpm: Improved handling of variable values
This commit removes the offset and depth if either of these values are
dependent upon a byte-extract operation.
7 years ago