Commit Graph

96 Commits (6c88cc1e0c7f8ef0c2518cb00e58b834b862f1e6)

Author SHA1 Message Date
Victor Julien 35e711d00a threads: clean up module flags
Remove unused TM_FLAG_STREAM_TM.

Rename TM_FLAG_DETECT_TM to TM_FLAG_FLOWWORKER_TM as it was mostly used
to check if a thread is a flow worker. TM_FLAG_DETECT_TM was always set
for a flow worker, even when there was no detection in use.
1 year ago
Philippe Antoine b29d46d81f rust: bindgen SCAppLayerParserStateIssetFlag
Ticket: 7667
1 year ago
Philippe Antoine 6d56beffef rust: bindgen AppLayerParserStateSetFlag
Ticket: 7667
1 year ago
Victor Julien df7fe5b0ce detect: add pre_flow hook
Allows dropping of packets before a flow is created/updated.
Directionless as direction is inferred from the flow.

Ticket: #7714.
1 year ago
Victor Julien 8f2b925e09 detect: add pre_stream hook
Meant to be used from the detection engine, to allow rules to drop
traffic before it modifies the stream state.

Ticket: #7712.
1 year ago
Victor Julien 0246668de7 flow-worker: use explicit type for DetectEngineThreadCtx 1 year ago
Jeff Lucovsky 49d4686144 main/flush: Support periodic flush logs
Issue: 3449
2 years ago
Jeff Lucovsky 7d5c170dd2 gen/bool: Clarify bool checks
Remove comparisons with true or false with C bools.
2 years ago
Victor Julien c587e90ebc 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.
2 years ago
Jason Ish fe69dd972a output: remove remaining ThreadExitPrintStats callbacks
Not used in output modules.

Ticket: #7227
2 years ago
Jason Ish afcf591719 output-flow: remove unused initdata argument
The initdata argument to OutputFlowThreadInit was always NULL, remove
it. Internally the ThreadInit functions still get initdata, but this
is the data provided when that logging instance was registered.

Ticket: #7227
2 years ago
Shivani Bhardwaj 903283d76e flow: declare and use constansts where possible 2 years ago
Shivani Bhardwaj eb95d2bf66 flow/timeout: cleanup fn names and comments 2 years ago
Shivani Bhardwaj 87fa7f10ef flow: use bool wherever possible 2 years ago
Victor Julien 2cebc8368c flow-worker: debug output about updates 2 years ago
Victor Julien a9dd1572d4 detect/frames: inspect frames only in correct direction
Inspect frames in the correct direction after they have been created.
2 years ago
Victor Julien 866c128c43 app-layer: flag flow for next packet in other dir
Add new flags to trigger FLOW_TS_APP_UPDATED/FLOW_TC_APP_UPDATED flags
to be set for the next packet in the relevant direction.

This allows for app relevant work to be done in the next packet in our
direction.
2 years ago
Victor Julien cca912e9b3 decode/tcp: add and use PacketIsTCP inline func
To prepare future changes to the Packet header pointers.

Ticket: #5517.
3 years ago
Philippe Antoine cc3b4b01ec detect: flush when setting no_inspection
Ticket: 6578

When a protocol such as SSH sets no_inspection, we still have to
flush the current streams and packets that contain clear-text
for detection.
3 years ago
Philippe Antoine 4c4f7ff1a2 detect: update packet action on protocol change
Ticket: #6305

When running FlowWorkerStreamTCPUpdate, one of the dequeued packet
may set the flow action to drop, without updating the not-pseudo
packet action, as is done usually with a previous call to
FlowHandlePacketUpdate
3 years ago
Philippe Antoine 497394eec6 detect: do not run tx detection on non established packets
Follows commit 2fb5059

Ticket: 6775
3 years ago
Victor Julien 13cc493885 flow/timeout: clean up flow finish code 3 years ago
Victor Julien ea4503c3e3 flow/timeout: use single packet for timeout handling
In the FlowFinish logic, one or two pseudo packets are used to finish flow
handling. In the case of 2 (one per direction), the logic first set up the
2 packets, then it would process them one by one. This lead to poor cache
locality.

This patch processes the first packet entirely first, followed by the second
packet.
3 years ago
Victor Julien 2a4fd85d1d flow/timeout: use const TcpSession; cleanup prototypes 3 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.
3 years ago
Victor Julien 6154bab49f flow/worker: minor refactor for app-layer callsite 3 years ago
Victor Julien 2a95154712 flow/timeout: no pseudo packets for dropped flows
When a flow is in the drop flow state, don't use pseudo packets
when it is timing out. There should be no work left to do at this
point.
3 years ago
Victor Julien 77f49661fd app-layer: don't update UDP applayer for dropped packets 3 years ago
Victor Julien afbd4162f2 flow/worker: don't double count flow.wrk.flows_evicted
Since the queue isn't fully processed every run, double counting
could happen.

Fix by only counting actually processed flows from the queue.
3 years ago
Victor Julien 73e665f42a flow/worker: batch return flows to spare pool 3 years ago
Victor Julien 3247e39f0c flowworker: simplify pseudo packet use
Pseudo packets originating in the flow worker do not need to leave the
flow worker. Putting those in the ThreadVars::decode_pq will make them
be evaluated by the next steps in the pipeline, but those will all
ignore pseudo packets.

Instead, this patch returns them to the packet pool, while still honoring
the IPS verdict logic.
4 years ago
Victor Julien b591813b86 profiling/rules: reduce sync logic scope
Use a simple once a second scheme.
4 years ago
Eric Leblond 75b46edd79 profiling: add 'ruleset-profile' unix command
This patch adds a new unix command that allows the user to trigger
a dump of the ruleset profile to the file without having to stop
Suricata.

This will be really useful to debug performance issue related to
signatures in production environment.
4 years ago
Victor Julien fa3f16ec75 threading: wait for flow housekeeping at shutdown
Flow house keeping can accumulate work that wasn't taken into account
during shutdown. This could lead to flows still in the flowworker
thread context when being it was freed, leading to missed work and
memory leaks.

This patch adds a new way of checking if a thread module is still
busy.

Bug: #6062.
4 years ago
Victor Julien d333dffdcb flowworker: flush local work queue on capture timeout
Capture timeout means no packets have been received for some
time, so this is a good time to flush out all work.
4 years ago
Victor Julien 55e32b2544 flowworker: rate limit flow queue processing
Until this patch the logic the flow worker flow house keeping used was:
- at most 2 flows are handled per packet
- pseudo packets could flush the entire queue

This patch changes that. Pseudo packets are fairly common, and can lead
to packet stalls / latency spikes if the number of flows in the queue
is large.

It does that by adding a new packet type only used at shutdown, which
flushes out the queues completely. All other packets will now stick
to the 2 flow rate limit.
4 years ago
Victor Julien 5e4cf182ab flow/worker: refresh detect thread during housekeeping
During housekeeping multiple flows are processed. If a rule reload happens
at that time, we need to use the new detect thread as soon as possible.

Bug: #5969.
4 years ago
Victor Julien 4176c7df6a flow/worker: remove unused detect thread arg 4 years ago
Victor Julien 7951d8a14f flow: remove use_cnt
Packets only ever reference the flow while holding its lock. This
means than any code possibly evicting the flow will have to wait
for the existing users to complete their work. Therefore the use_cnt
serves no function anymore and can be removed.
4 years ago
Victor Julien a2dc9a40e7 flowworker: don't keep unnecessary flow reference
Flow stream/detect/log flush packets, don't hold on to the flow
beyond the flow worker module.
4 years ago
Jeff Lucovsky 31793aface time: Replace struct timeval with scalar value
Issue: 5718

This commit switches the majority of time handling to a new type --
SCTime_t -- which is a 64 bit container for time:
- 44 bits -- seconds
- 20 bits -- useconds
4 years ago
Victor Julien b79c14f710 flow-worker: prune frames and stream for pseudo packets as well 4 years ago
Victor Julien b31ffde6f4 output: remove error codes from output 4 years ago
Victor Julien b07c7ad14c threading: improve/add thread queues explanations 4 years ago
Victor Julien f837146321 flow/worker: process injected flows more gradually
Worker threads are responsible for final processing of timed out flows.
These are selected by the Flow Manager and inserted into a per thread
queue. The Flow Worker then checks this queue after each packet. Due to
the burstiness of this process, the packet threads would sometimes process
a lot of these flows in the context of a single packet, leading to spike
in latency which might cause packet loss.

This patch changes the behavior to only process at max 2 flows per packet.
This way added processing cost is amortized over many packets.
4 years ago
Victor Julien ce1bdcb474 flow: count max number of injected flows in workers 4 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.
4 years ago
Victor Julien 79499e4769 app-layer: move files into transactions
Update APIs to store files in transactions instead of the per flow state.

Goal is to avoid the overhead of matching up files and transactions in
cases where there are many of both.

Update all protocol implementations to support this.

Update file logging logic to account for having files in transactions. Instead
of it acting separately on file containers, it is now tied into the
transaction logging.

Update the filestore keyword to consider a match if filestore output not
enabled.
4 years ago
Victor Julien a1d728bb65 app-layer: specify direction in tx cleanup
In preparation of per tx files storage.
4 years ago
Philippe Antoine 02f2602dde src: rework includes as per cppclean 4 years ago