Commit Graph

149 Commits (695c9d8d20e533da2848ba46c5f48c50e670adbb)

Author SHA1 Message Date
Victor Julien 695c9d8d20 detect/alert: split append func per packet/tx 4 months ago
Victor Julien d4f005933a detect/proto: reduce size for common sigs
Make `Signature::proto` an optional member, meaning that if it is
NULL we can skip the check. This can be done for `alert ip`, as no check
is needed, and for `alert tcp` and `alert udp` as having a rule in a sgh
for those means that the protocol matches.

Some exceptions are rules that require:
- ipv4/ipv6 specific matching
- frames, due to sharing prefilter between tcp and udp
- ip-only rules, due to those not being per sgh
7 months ago
Victor Julien 103bad19bb detect/iponly: address format truncation warnings
This appears to be a FP. Work around it to allow for using this warning
as an error.

detect-engine-iponly.c: In function 'IPOnlyCIDRListParse2':
detect-engine-iponly.c:721:35: warning: 'snprintf' output may be truncated before the last format character [-Wformat-truncation=]
  721 |                              "[%s]", rule_var_address);
      |                                   ^
detect-engine-iponly.c:720:21: note: 'snprintf' output 3 or more bytes (assuming 4) into a destination of size 3
  720 |                     snprintf(temp_rule_var_address, strlen(rule_var_address) + 3,
      |                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  721 |                              "[%s]", rule_var_address);
      |                              ~~~~~~~~~~~~~~~~~~~~~~~~~
detect-engine-iponly.c:782:34: warning: 'snprintf' output may be truncated before the last format character [-Wformat-truncation=]
  782 |                             "[%s]", rule_var_address);
      |                                  ^
detect-engine-iponly.c:781:21: note: 'snprintf' output 3 or more bytes (assuming 4) into a destination of size 3
  781 |                     snprintf(temp_rule_var_address, strlen(rule_var_address) + 3,
      |                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  782 |                             "[%s]", rule_var_address);
      |                             ~~~~~~~~~~~~~~~~~~~~~~~~~

Ticket: #7905.
1 year ago
Jason Ish a1c5e93d45 util-byte: fix usage of util-byte integer parsers
Functions like ByteExtractStringUint8 return 0 or less on
failure. Many usages of this function treat 0 as successful as its our
common pattern.

Ticket: #7836
1 year ago
Shivani Bhardwaj 623229728d signature: rename num to iid
to signify that it refers to the internal ID of the signature and
distinguish it from the "id" param that signifies the "sid" specified in
a rule.
1 year ago
Victor Julien 3f3964555e detect/iponly: use flow first flags
Instead of ip-only specific flags, reuse the FLOW_PKT_TOSERVER_FIRST and
FLOW_PKT_TOCLIENT_FIRST flags.

Fixes false positives on one sided streams that trigger a opposing flow
timeout packet at the flow's end. That pseudo packet would trigger a
match even though it shouldn't.

Ticket: #7521.
2 years ago
Victor Julien 13f420c793 detect/ip-only: code cleanups
Move repeated pattern into helper function.
2 years ago
Victor Julien 4aeb606a97 detect/ip-only: remove dead code 2 years ago
Victor Julien 0ea6fe668e detect/iponly: reimplement with radix4 for ipv6
Use a more compact ipv6 specific structure.
2 years ago
Victor Julien 4b6296c848 detect/iponly: reimplement with radix4 for ipv4
Use a more compact ipv4 specific structure.
2 years ago
Nancy Enos a0fc2b8628 misc: Remove duplicate function declarations
Ticket: #7297
2 years ago
Philippe Antoine 20423fdd38 style: remove some useless return
and remove empty line before end of function
2 years ago
Victor Julien eb3ca643c1 decode: reduce PKT_IS_IPV4/PKT_IS_IPV6 use
Replace it with inline functions. Adds inline functions to
wrap PKT_IS_IPV4/PKT_IS_IPV6.

This is in preparation of removing the macro's, and cleaning up the
header pointers.

Ticket: #5517.
3 years ago
Victor Julien 813147755d decode: rename IP_GET_IPPROTO to PacketGetIPProto
To match function naming style.

Ticket: #5517.
3 years ago
Victor Julien 962b505aa6 detect/iponly: code cleanups
Constify and flatten branches.
3 years ago
Victor Julien 976d8e65ae detect/iponly: move parsing only fields to init_data
IP-only parse results were not used at runtime.
3 years ago
Simon Dugas 17f9d7aecc detect-engine-iponly: improve ip list performance
The runtime complexity of insertion sort is approx. O(h*n)^2 where
h is the size of the HOME_NET and n is the number of ip only rules
that use the HOME_NET.

Replacing this with qsort significantly improves rule load time when
a large HOME_NET is used in combination with a moderate amount of ip
only rules.
3 years ago
Jeff Lucovsky 193e0ea1a9 memory/alloc: Use SCCalloc instead of malloc/memset 3 years ago
Victor Julien a1401ab81b detect/iponly: fix minor warning with unittest but no debug 3 years ago
Victor Julien 2696fda041 detect: use explicit rule types
Instead of using flags to indicate a rule type, use an explicit `type`
field.

This will make it more clean in code paths what paths a rule is taking,
and will allow easier debugging as well as analyzer output.

Define the following fields:

- SIG_TYPE_IPONLY: sig meets IP-only criteria and is handled by the IP-only
  engine.
- SIG_TYPE_PDONLY: sig inspects protocol detection results only.
- SIG_TYPE_DEONLY: sig inspects decoder events only.
- SIG_TYPE_PKT:    sig is inspected per packet.
- SIG_TYPE_PKT_STREAM: sig is inspected against either packet payload or
  stream payload.
- SIG_TYPE_STREAM: sig is inspected against the reassembled stream
- SIG_TYPE_APPLAYER: sig is inspected against an app-layer property, but not
  against a tx engine.
- SIG_TYPE_APP_TX: sig is inspected the tx aware inspection engine(s).

Ticket: #6085.
3 years ago
Justin Azoff aacb7dc291 detect/iponly: remove DetectEngineIPOnlyThreadCtx
This is unused.

Issue: 4578
4 years ago
Justin Azoff dfbc3da0eb detect/iponly: Reduce the size of the SigNumArray bitsets
Instead of tracking ip only rules by the internal signum, track them by
a separate counter that starts at zero.  This results in dense
SigNumArrays instead of sparse ones and a much smaller max_idx.

Issue: 4578
4 years ago
Victor Julien 1bc6976a06 src: fix unused-but-set-variable compile warnings
Tested on Fedora 37 with clang 15.

datasets.c:852:9: error: variable 'n' set but not used [-Werror,-Wunused-but-set-variable]
    int n = 0;
        ^
1 error generated.
4 years ago
Victor Julien b31ffde6f4 output: remove error codes from output 4 years ago
Victor Julien e250ef6402 debug: remove empty header 4 years ago
Philippe Antoine 02f2602dde src: rework includes as per cppclean 4 years ago
Philippe Antoine c5cf2967b3 detect: fix integer warnings
Ticket: #4516
4 years ago
Victor Julien 4b097460c2 detect/iponly: simplify handling of 'any' parsing 4 years ago
Victor Julien ffef10c5d7 detect: address parsing variable rename to match code style 4 years ago
Victor Julien 51ef6f4e3a detect/iponly: remove unused code 4 years ago
Victor Julien 9bdf18a3b0 detect/iponly: fix debug compiler warning 5 years ago
Juliana Fajardini 29b5f68bf0 assorted: fix low hanging typos 5 years ago
Juliana Fajardini aa547a8de3 detect/engine: use alert queue from det_ctx
Task #4943
5 years ago
Victor Julien 935ea745f5 detect/iponly: add tests for 5168 5 years ago
Victor Julien 79b7b7a0dd detect/iponly: validate netmask
Only accept netmask in dotted quad notation if they can be turned
into a CIDR.

According to rfc 4632, CIDR (compat) netmasks are all that should be
used.

Bug: #5168.
5 years ago
Victor Julien 4020e2faa7 detect/iponly: break out range insert code
So we can reuse it.
5 years ago
Victor Julien 51d4e0dced detect/iponly: fix netmask handling
If the ipaddress was not the address range start, it was not masked to turn
it into that. So 1.2.3.4/24 was not stored as address 1.2.3.0 with netmask 24,
but as 1.2.3.4 with netmask 24. This was then propagated into the radix tree,
where it was used as an exact key in exact lookups, giving unexpected results.

This patch implements the netmask handling for IPv4 and IPv6, and adds a set
of tests for it.

Bug: #5081.
Bug: #5066.
5 years ago
Victor Julien 860daceb04 detect/iponly: update SigNumArray comment 5 years ago
Victor Julien 6381b1a643 detect/iponly: cleanups 5 years ago
Victor Julien de4354abcb detect/iponly: minor debug 'Print' improvements 5 years ago
Victor Julien aa93984b7e detect: unify alert handling; fix bugs
Unify handling of signature matches between various rule types and
between noalert and regular rules.

"noalert" sigs are added to the alert queue initially, but removed
from it after handling their actions. This way all actions are applied
from a single place.

Make sure flow drop and pass are mutually exclusive.

The above addresses issue with pass and drops not getting applied
correctly in various cases.

Bug: #4663
Bug: #4670
5 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
Philippe Antoine ae102ca096 detect: refactoring parsing of ip range
To optimize first netmask
7 years ago
Philippe Antoine 8ca9c0e8f0 signature: minimizes ip CIDR for ip range
Example leading to over allocation is 41.232.107.2-43.252.37.6
7 years ago
Shivani Bhardwaj e7c0f0ad91 src: remove multiple uses of atoi
atoi() and related functions lack a mechanism for reporting errors for
invalid values. Replace them with calls to the appropriate
ByteExtractString* functions.

Partially closes redmine ticket #3053.
7 years ago
Jeff Lucovsky d3a65fe156 detect: Provide `de_ctx` to free functions
This commit makes sure that the `DetectEngineCtx *` is available
to each detector's "free" function.
7 years ago
Victor Julien 4d50eb1647 detect/iponly: fix parsing of '0' valued netmask 7 years ago
Victor Julien 34b7035a0d detect/iponly: debug output improvements 7 years ago
Jeff Lucovsky be22b23d2e cleanup: eliminate warnings/errors with debug build on macos 7 years ago
Victor Julien 14896365ef detect: remove Threadvars argument from API calls
Remove it as it's (almost) never used. If it is really needed it can
be accessed through DetectEngineThreadCtx::tv as well.
7 years ago