]> git.ipfire.org Git - thirdparty/suricata.git/log
thirdparty/suricata.git
6 months agouserguide: explain rule types and categorization 12492/head
Juliana Fajardini [Wed, 6 Nov 2024 01:54:50 +0000 (22:54 -0300)] 
userguide: explain rule types and categorization

Add documentation about the rule types introduced by commit
2696fda04168cb82.

Add doc tags around code definitions that are referenced in the docs.

Task #https://redmine.openinfosecfoundation.org/issues/7031

6 months agohttp: htp_headers_t alias for htp_table_t
Philippe Antoine [Fri, 24 Jan 2025 16:46:33 +0000 (17:46 +0100)] 
http: htp_headers_t alias for htp_table_t

In preparation of libhtp rust

6 months agohttp: minor cleanups for detect
Philippe Antoine [Fri, 24 Jan 2025 16:42:39 +0000 (17:42 +0100)] 
http: minor cleanups for detect

In preparation of libhtp rust

Mainly adding some const

6 months agohttp: minor cleanups for output-json-http
Philippe Antoine [Fri, 24 Jan 2025 16:37:29 +0000 (17:37 +0100)] 
http: minor cleanups for output-json-http

In preparation of libhtp rust

Mainly using htp_header_value_ptr and htp_header_value_len
when possible

6 months agohttp: minor cleanups for htp-xff.c
Philippe Antoine [Fri, 24 Jan 2025 16:32:22 +0000 (17:32 +0100)] 
http: minor cleanups for htp-xff.c

In preparation of libhtp rust

6 months agohttp: minor cleanups for htp-file.c
Philippe Antoine [Fri, 24 Jan 2025 16:31:07 +0000 (17:31 +0100)] 
http: minor cleanups for htp-file.c

In preparation of libhtp rust

6 months agohttp: aliases for htp opaque htp_headers_t
Philippe Antoine [Fri, 24 Jan 2025 16:16:07 +0000 (17:16 +0100)] 
http: aliases for htp opaque htp_headers_t

In preparation of libhtp rust

6 months agohttp: use const http_header_t in stub
Philippe Antoine [Fri, 24 Jan 2025 16:07:33 +0000 (17:07 +0100)] 
http: use const http_header_t in stub

In preparation of libhtp rust

6 months agohttp: constify some function arguments
Philippe Antoine [Fri, 24 Jan 2025 16:04:06 +0000 (17:04 +0100)] 
http: constify some function arguments

In preparation of libhtp rust

6 months agoflow: optionally use pkt recursion for hash
Cole Dishington [Tue, 8 Aug 2023 19:47:12 +0000 (07:47 +1200)] 
flow: optionally use pkt recursion for hash

If a Suricata inline IPS device is routing traffic over a
non-encrypted tunnel, like IPv6 tunnels, packets in a flow
will be dropped and not be matched. e.g.

The following example is a Suricata inline IPS with an IPv6 tunnel:
request: IPv4]ICMP] -> |IPS| -> IPv6]IPv4]ICMP]
reply:              <- |IPS| <- IPv6]IPv4]ICMP]
Both the IPv4 request and IPv6 reply will be seen by Suricata on
ingress. The flows will not be matched due to flow recursion level.

Optionally use pkt recursion level in flow hash. Excluding recursion
level in flow hash allows matching of packet flows and defrag on an
inline IPS Suricata scenario where the IPS device is a tunnel
terminator.

Feature: 6260

6 months agodoc: Add ftp.command sticky buffer 12480/head
Jeff Lucovsky [Mon, 20 Jan 2025 15:37:08 +0000 (10:37 -0500)] 
doc: Add ftp.command sticky buffer

Issue: 7502

This commit documents the new FTP sticky buffer "ftp.command".

6 months agodetect/ftp.command: Add sticky buffer
Jeff Lucovsky [Sun, 19 Jan 2025 15:38:42 +0000 (10:38 -0500)] 
detect/ftp.command: Add sticky buffer

Issue: 7502

Add a sticky buffer for "ftp.command" for matching on FTP command names.

6 months agodetect/smtp: smtp.rcpt_to keyword
Philippe Antoine [Fri, 24 Jan 2025 12:54:39 +0000 (13:54 +0100)] 
detect/smtp: smtp.rcpt_to keyword

Ticket: 7516

It is a sticky buffer mapping to the smtp.rcpt_to[] log field
It is a multi-buffer

6 months agodetect/smtp: smtp.mail_from keyword
Philippe Antoine [Fri, 24 Jan 2025 12:30:47 +0000 (13:30 +0100)] 
detect/smtp: smtp.mail_from keyword

Ticket: 7517

It is a sticky buffer mapping to the smtp.mail_from log field

6 months agodetect/smtp: smtp.helo keyword
Philippe Antoine [Fri, 24 Jan 2025 12:17:38 +0000 (13:17 +0100)] 
detect/smtp: smtp.helo keyword

Ticket: 7515

It is a sticky buffer mapping to the smtp.helo log field

6 months agorust/logging: fix logging from plugins 12472/head
Jason Ish [Tue, 21 Jan 2025 15:40:34 +0000 (09:40 -0600)] 
rust/logging: fix logging from plugins

Commit 2bcc66da5826fa0e6e074a756754b295e5ac4da2 broke logging from
plugins:

- debug visibility was reduced making it unusable from an external crate
- the plugins view of the log level was broken

To fix:
- make debug pub
- minor change to initialization of the log LEVEL as seen by the plugin
  so its seen by the plugin. I'm not really sure why the previous
  version wasn't working though, but this one does

6 months agolua: add "builtins" file to consolidate registration 12462/head
Jason Ish [Wed, 22 Jan 2025 22:32:35 +0000 (16:32 -0600)] 
lua: add "builtins" file to consolidate registration

Use a single array of built-ins and provide 2 functions for
registering them:

- SCLuaLoadBuiltIn: for loading built-in modules in sandboxed
  environments.

- SCLuaRequirefBuiltIns: registers built-in modules with the standard
  package tool, allows built-ins to be loaded by output scripts that are
  not restricted

I hope to refactor the sandbox so they can use SCLuaRequirefBuiltIns
as well.

6 months agodoc/userguide: document lua hashlib
Jason Ish [Tue, 21 Jan 2025 22:57:31 +0000 (16:57 -0600)] 
doc/userguide: document lua hashlib

6 months agolua: expose hashing functions to lua scripts
Jason Ish [Tue, 21 Jan 2025 21:23:15 +0000 (15:23 -0600)] 
lua: expose hashing functions to lua scripts

Expose md5, sha1, and sha256 to Lua scripts with
`require("suricata.hashing")`.

Ticket: 7073

6 months agorust/hashing: add more hex variants
Jason Ish [Tue, 21 Jan 2025 21:21:46 +0000 (15:21 -0600)] 
rust/hashing: add more hex variants

Make all the hasher's have the same variants:
- add hex digest for sha256
- add finalize to hex for sha1
- add hex digest for sha1

6 months agosource/pcap-file: remove unused macro warning
Philippe Antoine [Thu, 23 Jan 2025 12:54:22 +0000 (13:54 +0100)] 
source/pcap-file: remove unused macro warning

6 months agodetect/base64: remove unused macro warning
Philippe Antoine [Thu, 23 Jan 2025 12:31:05 +0000 (13:31 +0100)] 
detect/base64: remove unused macro warning

when compiling without unit tests
detect-transform-base64.c:47:9: warning: macro is not used [-Wunused-macros]
   47 | #define DETECT_TRANSFORM_FROM_BASE64_MODE_DEFAULT (uint8_t) Base64ModeRFC4648

6 months agorust: AppLayerRegisterParser out of SuricataContext
Philippe Antoine [Thu, 23 Jan 2025 09:12:59 +0000 (10:12 +0100)] 
rust: AppLayerRegisterParser out of SuricataContext

Just use a regular compile time rust export, instead of having
a runtime definition through the SuricataContext structure

6 months agorust: generated bindings depend on cbindgen.toml
Philippe Antoine [Thu, 23 Jan 2025 09:12:05 +0000 (10:12 +0100)] 
rust: generated bindings depend on cbindgen.toml

make should rerun cbindgen if cbindgen.toml is modified

6 months agodetect: add ldap.responses.count
Alice Akaki [Mon, 20 Jan 2025 18:16:26 +0000 (14:16 -0400)] 
detect: add ldap.responses.count

ldap.responses.count matches on the number of LDAP responses
This keyword maps to the eve field len(ldap.responses[])
It is an unsigned 32-bit integer
Doesn't support prefiltering

Ticket: #7453

6 months agodetect: add ldap.responses.operation
Alice Akaki [Mon, 20 Jan 2025 18:12:02 +0000 (14:12 -0400)] 
detect: add ldap.responses.operation

ldap.responses.operation matches on Lightweight Directory Access Protocol response operations
This keyword maps to the eve field ldap.responses[].operation
It is an unsigned 8-bit integer
Doesn't support prefiltering

Ticket: #7453

6 months agodetect: add ldap.request.operation
Alice Akaki [Mon, 20 Jan 2025 18:06:03 +0000 (14:06 -0400)] 
detect: add ldap.request.operation

ldap.request.operation matches on Lightweight Directory Access Protocol request operations
This keyword maps to the eve field ldap.request.operation
It is an unsigned 8-bit integer
Doesn't support prefiltering

Ticket: #7453

6 months agorustfmt: rust/src/ldap/types.rs
Alice Akaki [Mon, 20 Jan 2025 18:18:22 +0000 (14:18 -0400)] 
rustfmt: rust/src/ldap/types.rs

6 months agohttp: aliases for htp opaque htp_header_t
Philippe Antoine [Sun, 19 Jan 2025 20:45:54 +0000 (21:45 +0100)] 
http: aliases for htp opaque htp_header_t

In preparation of libhtp rust

6 months agohttp: use even more aliases for htp opaque htp_tx_t
Philippe Antoine [Sun, 19 Jan 2025 20:32:01 +0000 (21:32 +0100)] 
http: use even more aliases for htp opaque htp_tx_t

For request and response headers

In preparation of libhtp rust

6 months agohttp: use alias for htp opaque htp_tx_t
Philippe Antoine [Sun, 19 Jan 2025 20:23:36 +0000 (21:23 +0100)] 
http: use alias for htp opaque htp_tx_t

In preparation of libhtp rust

This occurence was missed in 23050d70ede31e842b316908c3428fabeb1de8f9

6 months agohttp: include htp-libhtp.h from header
Philippe Antoine [Sun, 19 Jan 2025 20:20:45 +0000 (21:20 +0100)] 
http: include htp-libhtp.h from header

Instead of C files requiring it.
In preparation of libhtp rust, to minimize the final commit.

6 months agodetect: set mpm/prefilter during signature parsing
Victor Julien [Wed, 5 Oct 2022 06:40:15 +0000 (08:40 +0200)] 
detect: set mpm/prefilter during signature parsing

In preparation of flowbit prefilter work that needs this info
earlier.

Track potential prefilter sm's to avoid unnecessary looping during
setup.

6 months agorust/ssh: rustfmt 12445/head
Jason Ish [Mon, 20 Jan 2025 18:08:41 +0000 (12:08 -0600)] 
rust/ssh: rustfmt

6 months agossh: cleanup rust visibility and naming
Jason Ish [Mon, 20 Jan 2025 18:06:20 +0000 (12:06 -0600)] 
ssh: cleanup rust visibility and naming

Remove pub and no_mangle from non-exported functions and rename to
Rust as-needed.

Ticket: 7498

6 months agorust/ntp: rustfmt
Jason Ish [Mon, 20 Jan 2025 17:34:49 +0000 (11:34 -0600)] 
rust/ntp: rustfmt

6 months agontp: cleanup visibility and naming
Jason Ish [Mon, 20 Jan 2025 17:34:00 +0000 (11:34 -0600)] 
ntp: cleanup visibility and naming

Remove pub and no_mangle from non-exported functions and rename to
Rust as-needed.

Ticket: 7498

6 months agopgsql: cleanup visibility and naming
Jason Ish [Mon, 20 Jan 2025 17:29:42 +0000 (11:29 -0600)] 
pgsql: cleanup visibility and naming

Remove pub and no_mangle from non-exported functions and rename to
Rust style as needed.

Ticket: 7498

6 months agorust/dhcp: rustfmt
Jason Ish [Mon, 20 Jan 2025 16:02:17 +0000 (10:02 -0600)] 
rust/dhcp: rustfmt

6 months agodhcp: cleanup visibility and naming
Jason Ish [Mon, 20 Jan 2025 16:00:19 +0000 (10:00 -0600)] 
dhcp: cleanup visibility and naming

- remove "rs_" prefix from functions that are not exported
- prefix exported functions with "SC"
- don't export functions that are only used by pointer

Ticket: 7498

6 months agorust/applayer: clean visibility of export macros
Jason Ish [Mon, 20 Jan 2025 15:46:09 +0000 (09:46 -0600)] 
rust/applayer: clean visibility of export macros

Both the macros export_tx_data_get and export_state_data_get can
generate non-pub functions as the function they generate is only used
as a pointer during registration.

Remove "pub" and "no_mangle" from the generated functions and update
the names of the generated functions to follow Rust rules as they are
no longer exported into the global C namespace.

Ticket: 7498

6 months agorust/transforms: remove no_mangle from non-pub functions
Jason Ish [Mon, 20 Jan 2025 15:11:48 +0000 (09:11 -0600)] 
rust/transforms: remove no_mangle from non-pub functions

Ticket: 7498

6 months agorust/ldap: cleanup no_mangle and extern C pub functions
Jason Ish [Mon, 20 Jan 2025 15:02:59 +0000 (09:02 -0600)] 
rust/ldap: cleanup no_mangle and extern C pub functions

If a function is extern "C" and not pub, remove no_mangle so its not
exposed as-is into the global name space.

Ticket: 7498

6 months agodecode/tcp: fix some macros
Eric Leblond [Sun, 19 Jan 2025 21:27:52 +0000 (22:27 +0100)] 
decode/tcp: fix some macros

Ticket: #7509

6 months agosmtp: recognize if client initiated TLS
Philippe Antoine [Thu, 19 Dec 2024 10:19:56 +0000 (11:19 +0100)] 
smtp: recognize if client initiated TLS

Ticket: 7469

6 months agoprotodetect: finish probing parser sooner
Philippe Antoine [Thu, 16 Jan 2025 08:26:30 +0000 (09:26 +0100)] 
protodetect: finish probing parser sooner

Ticket: 7495

We want to finish also if we tested all the expected protocols
in mask, or if we tested even more.

There can be one more protocol coming from pe0, which can be
the protocol already found in the other direction.

6 months agogen: Remove _AL_ usage in detect keywords 12433/head 12436/head
Jeff Lucovsky [Mon, 20 Jan 2025 14:35:01 +0000 (09:35 -0500)] 
gen: Remove _AL_ usage in detect keywords

This commit removes the `_AL_` usage in detect keywords for improved
readability.

Some of the HTTP rule keywords already had counterparts without using
"_AL_". These rule keywords are the legacy content modifier keywords
that now have sticky buffer equivalents.

For these, "_AL_" was removed and a suffix was added to the #define:
src/detect-engine-register.h:151:    DETECT_HTTP_COOKIE_CM
src/detect-engine-register.h:153:    DETECT_HTTP_METHOD_CM
src/detect-engine-register.h:161:    DETECT_HTTP_HEADER_CM
src/detect-engine-register.h:173:    DETECT_HTTP_RAW_HEADER_CM
src/detect-engine-register.h:175:    DETECT_HTTP_URI_CM
src/detect-engine-register.h:179:    DETECT_HTTP_STAT_MSG_CM
src/detect-engine-register.h:181:    DETECT_HTTP_STAT_CODE_CM
src/detect-engine-register.h:185:    DETECT_HTTP_HOST_CM

6 months agorust/detect: remove nested unsafe around keyword registration 12424/head
Jason Ish [Fri, 17 Jan 2025 18:17:27 +0000 (12:17 -0600)] 
rust/detect: remove nested unsafe around keyword registration

Just a cleanup, I'm not sure why Rust wasn't warning on these
nested/unneeded unsafe's.

6 months agorust/log: move rust log and debug utils to debug module
Jason Ish [Fri, 17 Jan 2025 18:06:53 +0000 (12:06 -0600)] 
rust/log: move rust log and debug utils to debug module

Move Rust logging, and debug_validation to a debug module to mirrow
the C side.

6 months agorust/direction: move direction to own file (cleanup)
Jason Ish [Fri, 17 Jan 2025 17:29:06 +0000 (11:29 -0600)] 
rust/direction: move direction to own file (cleanup)

Move the implementation of Direction to its own file, direction.rs.

6 months agorust/flow: move flow support to its own file (cleanup)
Jason Ish [Fri, 17 Jan 2025 17:03:48 +0000 (11:03 -0600)] 
rust/flow: move flow support to its own file (cleanup)

Move the Rust Flow support from core.rs to flow.rs.

6 months agohttp: aliases for htp opaque htp_tx_t 12419/head
Philippe Antoine [Fri, 17 Jan 2025 13:42:41 +0000 (14:42 +0100)] 
http: aliases for htp opaque htp_tx_t

In preparation of libhtp rust

6 months agorust: remove unneeded mut for tx in detect 12413/head
Philippe Antoine [Thu, 16 Jan 2025 12:36:03 +0000 (13:36 +0100)] 
rust: remove unneeded mut for tx in detect

Detection does not change transactions, it reads only.

6 months agorust: remove unneeded mut for tx in loggers
Philippe Antoine [Thu, 16 Jan 2025 08:03:56 +0000 (09:03 +0100)] 
rust: remove unneeded mut for tx in loggers

Loggers do not change transactions, they read only.

6 months agohttp: aliases for htp progresses
Philippe Antoine [Thu, 16 Jan 2025 09:58:35 +0000 (10:58 +0100)] 
http: aliases for htp progresses

In preparation of libhtp rust

6 months agohttp: aliases for htp protocol versions
Philippe Antoine [Thu, 16 Jan 2025 09:50:07 +0000 (10:50 +0100)] 
http: aliases for htp protocol versions

In preparation of libhtp rust

6 months agohttp: aliases for htp stream states
Philippe Antoine [Thu, 16 Jan 2025 09:47:50 +0000 (10:47 +0100)] 
http: aliases for htp stream states

In preparation of libhtp rust

6 months agohttp: aliases for htp methods
Philippe Antoine [Thu, 16 Jan 2025 09:45:29 +0000 (10:45 +0100)] 
http: aliases for htp methods

In preparation of libhtp rust

6 months agohttp: aliases for htp auths
Philippe Antoine [Thu, 16 Jan 2025 09:43:12 +0000 (10:43 +0100)] 
http: aliases for htp auths

In preparation of libhtp rust

6 months agohttp: aliases for htp flags
Philippe Antoine [Thu, 16 Jan 2025 09:38:19 +0000 (10:38 +0100)] 
http: aliases for htp flags

In preparation of libhtp rust

6 months agohttp: aliases for htp server personalities
Philippe Antoine [Thu, 16 Jan 2025 09:36:39 +0000 (10:36 +0100)] 
http: aliases for htp server personalities

In preparation of libhtp rust

6 months agohttp: aliases for htp statuses
Philippe Antoine [Thu, 16 Jan 2025 09:32:08 +0000 (10:32 +0100)] 
http: aliases for htp statuses

In preparation of libhtp rust

6 months agoldap: implement abandon request 12390/head 12396/head
Philippe Antoine [Thu, 9 Jan 2025 14:21:20 +0000 (15:21 +0100)] 
ldap: implement abandon request

Ticket: #7477

6 months agoldap: update ldap-parser crate
Philippe Antoine [Thu, 9 Jan 2025 14:07:19 +0000 (15:07 +0100)] 
ldap: update ldap-parser crate

so that we can implement abandon request support

Ticket: #7477

6 months agodetect: add vlan.layers keyword 12393/head
Alice Akaki [Wed, 8 Jan 2025 21:03:24 +0000 (17:03 -0400)] 
detect: add vlan.layers keyword

vlan.layers matches on the number of VLAN layers per packet
It is an unsigned 8-bit integer
Valid range = [0-3]
Supports prefiltering

Ticket: #1065

6 months agodetect: add vlan.id keyword
Alice Akaki [Thu, 7 Nov 2024 20:46:33 +0000 (16:46 -0400)] 
detect: add vlan.id keyword

vlan.id matches on Virtual Local Area Network IDs
It is an unsigned 16-bit integer
Valid range = [0-4095]
Supports prefiltering

Ticket: #1065

6 months agofuzz: remove unused macro 12383/head 12389/head
Philippe Antoine [Mon, 13 Jan 2025 12:39:21 +0000 (13:39 +0100)] 
fuzz: remove unused macro

6 months agofuzz: better init for signature parsing harness
Philippe Antoine [Fri, 10 Jan 2025 16:27:55 +0000 (17:27 +0100)] 
fuzz: better init for signature parsing harness

It needs app-layer registration for the names

6 months agoplugins: app-layer plugins
Philippe Antoine [Fri, 10 Jan 2025 15:57:51 +0000 (16:57 +0100)] 
plugins: app-layer plugins

Ticket: 5053

6 months agoapp-layer: make number of alprotos dynamic
Philippe Antoine [Mon, 11 Nov 2024 06:26:11 +0000 (07:26 +0100)] 
app-layer: make number of alprotos dynamic

Ticket: 5053

The names are now dynamically registered at runtime.
The AppProto alproto enum identifiers are still static for now.

This is the final step before app-layer plugins.

6 months agoapp-layer: move ALPROTO_FAILED definition
Philippe Antoine [Mon, 11 Nov 2024 06:21:03 +0000 (07:21 +0100)] 
app-layer: move ALPROTO_FAILED definition

Because some alprotos will remain static and defined as a constant,
such as ALPROTO_UNKNOWN=0, or ALPROTO_FAILED.

The regular already used protocols keep for now their static
identifier such as ALPROTO_SNMP, but this could be made more
dynamic in a later commit.

ALPROTO_FAILED was used in comparison and these needed to change to use
either ALPROTO_MAX or use standard function AppProtoIsValid

6 months agolua/datasets: factor out into its own file 12379/head
Jason Ish [Fri, 10 Jan 2025 23:23:35 +0000 (17:23 -0600)] 
lua/datasets: factor out into its own file

This is mainly for header sanitization to avoid pulling in detect
modules into the Lua sandbox definition.

Plus if we namespace modules with names like "suricata.dataset", it
probably makes sense to keep those modules in their own files.

6 months agolua/datasets: rework to be a "required" module
Jason Ish [Fri, 10 Jan 2025 21:40:26 +0000 (15:40 -0600)] 
lua/datasets: rework to be a "required" module

Re-work the Lua dataset lib to be required into a user script like:

    local dataset = require("suricata.data")

The main difference from loading it into global space is providing a
custom require function (as we removed it in the sandbox) and load it on
demand, returning a table to the module.

6 months agodetect/lua: add support for datasets
Victor Julien [Thu, 11 Apr 2024 14:10:34 +0000 (16:10 +0200)] 
detect/lua: add support for datasets

dataset.new
  create a dataset object in lua

<dataset>:get
  gets a reference to an existing dataset

<dataset>:add
  returns 1 if a new entry was added
  returns 0 if entry was already in the set

Example:
```
function init (args)
    local needs = {}
    needs["packet"] = tostring(true)
    return needs
end

function thread_init (args)
    conn_new, dataset.new()
    ret, err conn_new:get("conn-seen")
    if err ~= nil then
        SCLogWarning("dataset warning: " .. err)
        return 0
    end
end

function match (args)
    ipver, srcip, dstip, proto, sp, dp = SCFlowTuple()
    str = ipver .. ":<" .. srcip .. ">:<" .. dstip .. ">:" .. dp

    ret, err = conn_new:add(str, #str);
    if ret == 1 then
        SCLogInfo(str .. " => " .. ret)
    end
    return ret
end
```

Ticket: #7243.

6 months agodetect/lua: add thread_init
Victor Julien [Mon, 10 Jun 2024 18:34:40 +0000 (20:34 +0200)] 
detect/lua: add thread_init

Add optional `thread_init` function support. This function is called per
script, per thread to allow a user to initialize the lua state.

6 months agodetect/lua: improve stack dumping
Victor Julien [Wed, 6 Nov 2024 08:13:10 +0000 (09:13 +0100)] 
detect/lua: improve stack dumping

Only useful when debugging. Add a prefix and a stack size indication.

6 months agolog/file: Ensure file ctx pointer is returned . 12375/head
Jeff Lucovsky [Sat, 11 Jan 2025 14:23:50 +0000 (09:23 -0500)] 
log/file: Ensure file ctx pointer is returned .

The fix for issue 7447 introduced an error with threaded eve output.

The changes that were committed for that issue mishandled the return
value when a file is being opened for the 2nd or higher time.

Instead of returning the existing file context, null was returned.

6 months agoflow/pkts: allow matching on either direction 12373/head
Shivani Bhardwaj [Fri, 23 Aug 2024 06:57:35 +0000 (12:27 +0530)] 
flow/pkts: allow matching on either direction

For flow.bytes and flow.pkts keywords, allow matching in either
direction.

Feature 5646

6 months agodoc: update syntax for flow.pkts & flow.bytes
Shivani Bhardwaj [Tue, 8 Oct 2024 07:13:27 +0000 (12:43 +0530)] 
doc: update syntax for flow.pkts & flow.bytes

6 months ago flow/pkts: make syntax cleaner and compact
Shivani Bhardwaj [Fri, 29 Nov 2024 08:31:12 +0000 (14:01 +0530)] 
 flow/pkts: make syntax cleaner and compact

Currently, the syntax includes direction as a part of the keyword which
is against how usually keywords are done. By making direction as a
mandatory argument, it is possible to make the syntax cleaner and the
implementation more compact and easily extendable.
Pros:
- Registration table sees lesser entries if newer options are added
- If the options have to be extended, it can be done trivially
- In accordance w existing keyword implementations

Note that this commit also retains the existing direction specific
keywords.

6 months agostream: RST no longer acks all data 12371/head
Victor Julien [Fri, 29 Nov 2024 13:37:08 +0000 (14:37 +0100)] 
stream: RST no longer acks all data

Since forever (1578ef1e3e8a24d0cc615430c4e6bec1fefdad28) a valid RST
would update the internal `last_ack` representation to include all
unack'd data. This was originally done to make sure the unACK'd data was
inspected/processed at flow timeout.

It was observed however, that if GAPs existed in this unACK'd data, a
GAP could be reported in the stats and a GAP event would be raised. This
doesn't make sense, as missing segments in the unACK'd part of the
stream are completely normal. Segments simply do not all arrive in
order.

It turns out that the original behavior of updating `last_ack` to
include all unACK'd data is no longer needed.

For raw stream inspection, the detection engine will already include the
unACK'd data on flow end.

For app-layer updates the unACK'd data is often harmful, as the data
often has GAPs. Parser like the http parser would report these GAPs and
could also get confused about the post-GAP data being a new transaction
including a file. This lead to many reported errors and fantom txs and
files.

Since the GAP detection uses `last_ack` to determine GAPs, not moving
`last_ack` addresses the GAP false positives.

Ticket: #7422.

6 months agoflow/manager: improve doc; minor cleanup
Victor Julien [Fri, 20 Dec 2024 07:53:23 +0000 (08:53 +0100)] 
flow/manager: improve doc; minor cleanup

Explain meaning of `ts` in flow managers main loop.

6 months agoflow: skip lock for skippable flows
Victor Julien [Wed, 18 Sep 2024 20:19:17 +0000 (22:19 +0200)] 
flow: skip lock for skippable flows

Some checks can be done w/o holding a lock:
- seeing if the flow matches the packet
- if the hash row needs a timeout check

This patch skips taking a lock in these conditions.

6 months agothreads: align struct to CLS to avoid false sharing
Victor Julien [Wed, 18 Sep 2024 09:50:59 +0000 (11:50 +0200)] 
threads: align struct to CLS to avoid false sharing

Since `Thread` objects are part of a big allocation, more than one
Thread could be on a single cache line, leading to false sharing. Atomic
updates to one `Thread` could then lead to poor performance accessing
another `Thread`. Align to CLS (cache line size) to avoid this.

6 months agothreads: seal after setup; unseal at shutdown
Victor Julien [Wed, 18 Sep 2024 08:48:29 +0000 (10:48 +0200)] 
threads: seal after setup; unseal at shutdown

The idea of sealing the thread store is that its members can be accessed
w/o holding a lock to the whole store at runtime.

6 months agothreads: fine grained locking for Thread
Victor Julien [Tue, 17 Sep 2024 09:02:00 +0000 (11:02 +0200)] 
threads: fine grained locking for Thread

Until now many accesses to the Thread structure required taking a global
lock, leading to performance issues. In practice this only happened in
offline mode.

This patch adds a finer grained locking scheme. It assumes that the
Thread object itself cannot disappear, and adds a spinlock to protect
updates to the structure.

Additionally, the `pktts` field is made an atomic, so that it can be
read w/o taking the spinlock. Updates to it are still done under lock.

6 months agoflow/manager: in offline mode, use owning threads time
Victor Julien [Tue, 17 Sep 2024 18:52:14 +0000 (20:52 +0200)] 
flow/manager: in offline mode, use owning threads time

As this may mean that a threads ts is a bit ahead of the minimum time
the flow manager normally uses, it can evict flows a bit faster.

Ticket: #7455.

6 months agoflow/worker: improve flow timeout time accuracy
Victor Julien [Wed, 18 Sep 2024 10:03:46 +0000 (12:03 +0200)] 
flow/worker: improve flow timeout time accuracy

When timing out flows, use the timestamp from the "owning" thread. This
avoids problems with threads being out of sync with each other.

Ticket: #7455.

6 months agoflow: fix flow bucket timestamp optimization
Victor Julien [Mon, 16 Sep 2024 06:54:43 +0000 (08:54 +0200)] 
flow: fix flow bucket timestamp optimization

Flow Manager skips rows based on a minimized tracker that tracks the
next second at which the first flow may time out.

If seconds match a flow can still be timing out.

6 months agothreads: use sleeping threads for minimum time a bit longer
Victor Julien [Wed, 18 Sep 2024 10:21:42 +0000 (12:21 +0200)] 
threads: use sleeping threads for minimum time a bit longer

If a thread doesn't receive packets for a while the packet timestamp
will no longer be used to determine a reasonable minimum timestamp for
flow timeout handling.

To avoid issues with the minimum timestamp to be set a bit too
aggressively, increase the time a thread can be inactive.

6 months agotime: thread time update after flow update
Victor Julien [Sun, 15 Sep 2024 17:15:56 +0000 (19:15 +0200)] 
time: thread time update after flow update

The flow worker needs to get the opportunity to run the flow update
before globally making it's current timestamp available. This is to
avoid another thread using the time to evict the flow that is about to
get a legitimate update.

Ticket: #7455.

6 months agoflow: exact flow timeout
Victor Julien [Sun, 15 Sep 2024 10:20:21 +0000 (12:20 +0200)] 
flow: exact flow timeout

Use a more precise calculation for timing out flows, using both the
seconds and the micro seconds.

Ticket: #7455.

6 months agotime: getter for SCTime_t timestamp of a thread
Victor Julien [Wed, 18 Sep 2024 09:15:00 +0000 (11:15 +0200)] 
time: getter for SCTime_t timestamp of a thread

6 months agostream: rename tcp reuse flag
Victor Julien [Fri, 13 Dec 2024 09:35:13 +0000 (10:35 +0100)] 
stream: rename tcp reuse flag

Rename to be consistent with other naming:

STREAM_PKT_FLAG_TCP_PORT_REUSE -> STREAM_PKT_FLAG_TCP_SESSION_REUSE

6 months agoeve/stream: add tcp-session-reuse trigger
Victor Julien [Wed, 11 Sep 2024 19:11:09 +0000 (21:11 +0200)] 
eve/stream: add tcp-session-reuse trigger

Can be used to log when the tcp session reuse logic triggers.

6 months agoflow: improve thread safety during timeout checks
Victor Julien [Sat, 14 Sep 2024 19:26:45 +0000 (21:26 +0200)] 
flow: improve thread safety during timeout checks

Timeout checks would access certain fields w/o locking, which could lead
to thread safety issues.

6 months agoeve/flow: log tcp reuse as 'reason'
Victor Julien [Fri, 13 Sep 2024 18:26:53 +0000 (20:26 +0200)] 
eve/flow: log tcp reuse as 'reason'

Ticket: #7482.

6 months agounix/socket: cleanup start up logic
Victor Julien [Thu, 31 Oct 2024 16:41:26 +0000 (17:41 +0100)] 
unix/socket: cleanup start up logic

No longer init then deinit part of the engine at startup of the unix
socket mode.

6 months agothreads: include name in error message
Victor Julien [Thu, 31 Oct 2024 19:26:08 +0000 (20:26 +0100)] 
threads: include name in error message

When a thread fails to spawn, include the thread name in the error
message.

6 months agodns: improved handling of corrupt additionals
Philippe Antoine [Tue, 10 Sep 2024 13:31:00 +0000 (15:31 +0200)] 
dns: improved handling of corrupt additionals

Ticket: 7228

That means log the rest of queries and answers, even if the
final field additionals is corrupt.
Set an event in this case.