Commit Graph

192 Commits (d40dca5e55286c57e9a83018975022c4f08bf6d1)

Author SHA1 Message Date
Juliana Fajardini f511a4ae3f misc: fix typos, doc, update copyright years
Updated FlowGetNew documentation, where it said NULL was only returned
in case of error.
2 years ago
Victor Julien c90f67ac55 app-layer: improve/fix updates logic
In 23323a961f ("app-layer: reduce app cleanup and output-tx calls"), flag
was set per packet updating the app-layer state. However this was missing a
common pattern: in IDS mode most updates are done in the opposite direction
of the traffic due to updates getting triggered by ACK's. This meant that
file store processing might not happen for a long time, or at all. Also,
app layer cleanup might not be called, which includes file pruning.

This patch sets per flow set of flags to indicate app layer is (potentially)
updated. It sets this per direction, based on how the parsers were invoked.
If an ACK triggers an app update, the flow is tagged for the opposite
direction and the next packet in that direction triggers output and cleanup.

Fixes: 23323a961f ("app-layer: reduce app cleanup and output-tx calls")

Bug: #6120.
2 years ago
Victor Julien f28459ed78 app-layer: spelling 3 years ago
Victor Julien ebd8728219 src: fix strict-prototype warnings
Tested on Fedora 37 with clang 15.

app-layer.c:1055:27: error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes]
void AppLayerSetupCounters()
                          ^
                           void
app-layer.c:1176:29: error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes]
void AppLayerDeSetupCounters()
                            ^
                             void
2 errors generated.
3 years ago
Philippe Antoine 27d2bce1a1 flow: complete stats for app_layer protocol counters
In the case of a gap, or in the case of a flow where one side
is recognized, but the other is not before the end, we still
increase the counters to have consistency between

jq 'select(.event_type=="flow" and .app_proto=="ftp") | .app_proto'  log/eve.json | wc -l
jq 'select(.event_type=="stats") | .stats."app_layer".flow.ftp' log/eve.json

Ticket: #5769
3 years ago
Philippe Antoine ad713246a9 src: remove double includes
Keep the unconditional include to be sure it works

git grep '#include "' src/*.c | sort | uniq -c | awk '$1 > 1'
3 years ago
Victor Julien 0f7fe2a4c3 app-layer/tests: don't memset new packet 3 years ago
Victor Julien 23323a961f app-layer: reduce app cleanup and output-tx calls
Track packets that updated the app-layer, and for those run
the transaction housekeeping and output-tx logging loops.

Do the same of end of flow packets.

This skips needless iterations over the transaction stores.
3 years ago
Victor Julien 39cf5b151a src: includes cleanup
Work towards making `suricata-common.h` only introduce system headers
and other things that are independent of complex internal Suricata
data structures.

Update files to compile after this.

Remove special DPDK handling for strlcpy and strlcat, as this caused
many compilation failures w/o including DPDK headers for all files.

Remove packet macros from decode.h and move them into their own file,
turn them into functions and rename them to match our function naming
policy.
3 years ago
Philippe Antoine e692530021 event: only sets APPLAYER_UNEXPECTED_PROTOCOL once
If f->alproto == ALPROTO_UNKNOWN, we do not know the new protocol
yet, so we do not set the event yet.
3 years ago
Victor Julien fea374626a stream/midstream: fix double flow reverse case
In the case of midstream SYN/ACK pickup, we reverse the flow based on
the SYN/ACK. If we then later get traffic that appears to be in the
reverse direction based on the app-layer, we would reverse it again.
This isn't correct. When we have the SYN/ACK we know the flow's real
direction.
3 years ago
Victor Julien 8580499ded exceptions: initial exception-policy implementation
Adds a framework for setting exception policies. These would be called
when the engine reaches some kind of exception condition, like hitting
a memcap or some traffic processing error.

The policy gives control over what should happen next: drop the packet,
drop the packet and flow, bypass, etc.

Implements the policy for:

    stream: If stream session or reassembly memcaps are hit call the
    memcap policy on the packet and flow.

    flow: Apply policy when memcap is reached and no flow could be
    freed up.

    defrag: Apply policy when no tracker could be picked up.

    app-layer: Apply ppolicy if a parser reaches an error state.

All options default to 'ignore', which means the default behavior
is unchanged.

Adds commandline options: add simulation options for exceptions. These
are only exposed if compiled with `--enable-debug`.

Ticket: #5214.
Ticket: #5215.
Ticket: #5216.
Ticket: #5218.
Ticket: #5194.
3 years ago
Philippe Antoine 3051f7f23f protodetect: use both directions over UDP
As is already done for TCP

Ticket: #2757
4 years ago
Victor Julien a5df176956 app-layer: minor code cleanups suggested by cppcheck 4 years ago
Victor Julien 905050a053 app-layer/profiling: hide profiling code behind guards 4 years ago
Philippe Antoine f30975fb16 app-layer: fix integer warnings
Ticket: 4516
4 years ago
Victor Julien 86e8611f5e app-layer: don't switch dir if proto already known 4 years ago
Victor Julien 0437ca61ff unittests: clean up packet clear logic 4 years ago
Victor Julien 84d91e2e0d app-layer: fix counter setup logic
Completes 0ccf5b9147
4 years ago
Victor Julien 0ccf5b9147 app-layer: fix error counter logic 4 years ago
Victor Julien 609a7eaab2 app-layer: error counters
Per app-layer error counters for:
gap, parser, internal (AppLayerResult issues), alloc
4 years ago
Victor Julien ca29d33c69 proto-detect: set flags in packet direction for UDP 4 years ago
Victor Julien 449cc82943 proto-detect: fix UDP not setting alproto_ts/tc
This would lead to the `app-layer-protocol` keyword not matching correctly.
4 years ago
Victor Julien a27ee49c73 app-layer: move app_progress forward on errors as well
In case of APP_LAYER_ERROR still move the app_progress forward.
This helps validation of frame offsets and should be harmless
otherwise.
4 years ago
Victor Julien 1556e86c7d app/frames: initial support
The idea of stream frames is that the applayer parsers can tag PDUs and
other arbitrary frames in the stream while parsing. These frames can then
be inspected from the rule language. This will allow rules that are more
precise and less costly.

The frames are stored per direction in the `AppLayerParserState` and will only
be initialized when actual frames are in use. The per direction storage has a
fixed size static portion and dynamic support for a larger number. This is done
for effeciency.

When the Stream Buffer slides, frames are updated as they use offsets relative
to the stream. A negative offset is used for frames that started before the
current window.

Frames have events to inspect/log parser errors that don't fit the TX model.

Frame id starts at 1. So implementations can keep track of frame ids where 0
is not set.

Frames affect TCP window sliding. The frames keep a "left edge" which
signifies how much data to keep for frames that are still in progress.
4 years ago
Philippe Antoine be617a3c1b protodetect: opposing side cannot change protocol
Ticket: #4562

As the data which triggered the opposing side
was the same protocol and not another one,
that means the protocol change failed.

Prevents a memory leak in later call of AppLayerParserParse
which would allocate a new state and leak the old one
4 years ago
Philippe Antoine 527415dba0 protodetect: handle all gaps, even when depth is reached 4 years ago
Philippe Antoine f77b027ada app-layer/pd: review bailout conditions
To take TCP window into account
And to actually bail out if we received too much data
where the limit is configured by stream.reassembly.depth
4 years ago
Victor Julien 7a114e506a app-layer/pd: only consider actual available data
For size limit checks consider only available data at the stream start
and before any GAPS.

The old check would consider too much data if there were temporary gaps,
like when a data packet was in-window but (far) ahead of the expected
segment.
4 years ago
Jeff Lucovsky 1eeb96696b general: Cleanup bool usage 5 years ago
Shivani Bhardwaj 089972fd31 applayer: fix test data for a valid DCERPC pkt 5 years ago
Philippe Antoine 707f027231 protos: renaming ALPROTO_HTTP* constants
Having now ALPROTO_HTTP1, ALPROTO_HTTP2 and ALPROTO_HTTP

Run with 3 sed commands
git grep ALPROTO_HTTP | cut -d: -f1 | uniq |
 xargs sed -i -e 's/ALPROTO_HTTP/ALPROTO_HTTP1/g'
git grep ALPROTO_HTTP12 | cut -d: -f1 | uniq |
 xargs sed -i -e 's/ALPROTO_HTTP12/ALPROTO_HTTP2/g'
git grep ALPROTO_HTTP1_ANY | cut -d: -f1 | uniq |
 xargs sed -i -e 's/ALPROTO_HTTP1_ANY/ALPROTO_HTTP/g'

and then running clang-format
5 years ago
Philippe Antoine 65711f6bc2 app-layer: do not try to parse gaps during protocol change
As this will leak the flow alstate because AppLayerParserParse
relies on FlowChangeProto to know if it should allocate a new
alstate
5 years ago
Philippe Antoine 6b50a71d1a app-layer: lower limit for protocol detection on protocol change
So that protocol detection does not run for too long because
TCPProtoDetectCheckBailConditions somehow relies on its TCP stream
to start from zero, which is not the case on protocol change

Adds also debug validation checks, such as
both sides are known on protocol change

And only sets once alproto_orig
5 years ago
Philippe Antoine 518e0e66cb applayer: fix a leak in protocol change
TCPProtoDetect can either set f->alproto, change f->alstate
and return error.

When the original alstate gets freed, we shall set the pointer
to NULL, as it can get reused.
5 years ago
Victor Julien 34e83b8acf stream: remove GAP flag from stream
This flag was checked in many places, but never set expect in 2 unittests.
5 years ago
Philippe Antoine 82f1758573 applayer: keep running detection on protocol change
ie do not stop on first try if we do not have enough data
5 years ago
Philippe Antoine 21e741795d applayer: on protocol change, use previous state 5 years ago
Victor Julien 5fd9386665 app-layer/pd: improve size check in bail conditions 5 years ago
Victor Julien 7ca94ba0a2 app-layer: fix protocol detection bail conditions for TCP fastopen 6 years ago
Victor Julien 960045323d app-layer: minor code cleanup 6 years ago
Victor Julien 9b1f0656d0 app-layer: fix progress tracking
Esp in combination with GAPs and proto detection.
6 years ago
Victor Julien 674b8dc0fb app-layer: add 'incomplete' return logic
Allow app-layer parsers to indicate how much data they need
before being called again.
6 years ago
Jason Ish a0e3e2d7b4 dns: register parsers from Rust
And port the C DNS tests to Rust.
6 years ago
Victor Julien e3fbdf1948 flowworker/stream: use no-lock packet queue
Use smaller structure for temporary packet queues.
6 years ago
Victor Julien 0f41cf3d74 debug/validation: check tcp/app-layer data lengths 6 years ago
Victor Julien a272e433a8 pd: don't reverse flow if TCP session not midstream 6 years ago
Victor Julien 5ddfc42b87 stream: fix midstream reverse flow handling
When a TCP session is picked up from the response the flow is
reversed by the protocol detection code.

This would lead to duplicate logging of the response. The reason this
happened was that the per stream app progress tracker was not handled
correctly by the direction reversing code. While the streams were
swapped the stream engine would continue to use a now outdated pointer
to what had become the wrong direction.

This patches fixes this by making the stream a ptr to ptr that can be
updated by the protocol detection as well.

In addition, the progress tracking was cleaned up and the GAP error
handling in this case was improved as well.
6 years ago
Victor Julien 952cbb563c app-layer: mandatory tx registration checks
All protocols now implement the TX API, so the runtime checks for
whether or not a protocol supports the TX API can be removed.
7 years ago
Jason Ish 67b2692d34 dns: remove as much C DNS code as possible
As some of the C code is still used it can't all be removed.

Redmine issue:
https://redmine.openinfosecfoundation.org/issues/2850
7 years ago