Commit Graph

217 Commits (c587e90ebccfe8883ea951e723be461dc58dcc06)

Author SHA1 Message Date
Philippe Antoine 31bed10ff6 runmode: fix coverity warning
CID 1619284:  Memory - illegal accesses  (OVERRUN)

In ParseAFXDPConfig, a pointer to bool is cast into a pointer
to int.

Also removing the cast pattern when useless
11 months ago
Victor Julien 96a0ffadde packetpool: allow larger max-pending-packets
Original limit was due to a specific data structure.
12 months ago
Victor Julien e5d3fad5f4 nfq: stricter thread sync
No longer update `Packet::flags` for tracking packet modifications,
as thread safety was not guaranteed.

Clearly separate between various kinds of `Packet::nfq_v` accesses for:
- mark
- mark_modified
- verdicted
These are either done under lock (Packet::persistent.tunnel_lock) or,
if the Packet is not part of a tunnel, not under lock.

This is safe as in all the related logic the Packet's tunnel state
is fixed and can no longer change.
1 year ago
Victor Julien 6066c4d6e7 decode/tunnel: improve tunnel handling
Give each packet explicit tunnel type `ttype`: none, root, child.

Assigning happens when a (tunnel) packet is set up and is thread
safe.
1 year ago
Victor Julien c31a6f5649 nfq: remove obsolete comment 1 year ago
Victor Julien 85ddeb6546 nfq: minor code cleanup 1 year ago
Victor Julien 792c87af25 nfq: use bool for verdicted packet var 1 year ago
Victor Julien d56f34370d stats: update ips capture counters centrally
This adds support to all capture methods for these counters.

The updates happen only on "real" packets, not on encapsulated
packets.

Ticket: #4756.
2 years ago
Victor Julien 6a1138e2b1 stats: register ips capture stats for each packet thread
ReleasePacket based verdicts can happen in several threads,
depending on the runmode details.

Only register and update if in IPS mode.
2 years ago
Victor Julien ece1cb3e94 stats: simplify ips capture stats logic
Since many implementations use the ReleasePacket callback to issue
their verdict, no thread ctx is available. To work around this
just register the stats in a `thread_local` variable instead.
2 years ago
Jason Ish b5fbdc3e5f capture: use uint16_t for max_pending_packets
Use a fixed type of max_pending_packets instead of intmax_t which can
differ based on the platform/standard library.

Should also prevent lints about possible arithmetic overflow.
2 years ago
Jeff Lucovsky 22485b368e source/nfq: Improve retry counter limit name
The NFQ verdict retry is based on attempts, not time; thus, we rename
the token controlling it to reflect that.
2 years ago
Jeff Lucovsky b470b55635 nfq: Ensure packet release function set
Issue: 5916

This commit ensures that the packet release function is set in
case the packet is released early.
2 years ago
Jeff Lucovsky 804c442568 general/typo: Correct typo
Issue: 5916
2 years ago
Victor Julien 0265c13550 src: fix extern max_pending_packets type 2 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
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
Victor Julien 7196257f68 nfq: minor error message improvement 3 years ago
Victor Julien b31ffde6f4 output: remove error codes from output 3 years ago
Victor Julien 39f5c7f56a error: use SC_EINVAL for invalid input 3 years ago
Victor Julien e042cd785e error: use SC_ENOMEM for alloc errors 3 years ago
Richard McConnell 13beba141c source: add THV_RUNNING flag to notify of running state
Each module (thread) updates its status to indicate running.
Main thread awaits for all threads to be in a running state
before continuing the initialisation process

Implements feature 5384
(https://redmine.openinfosecfoundation.org/issues/5384)
3 years ago
Victor Julien 1fafb83fed packet: turn tunnel lock into spinlock
Lock is only held to update/check ints, so spin lock will be more
efficient.

Place the member of Packet in a new "persistent" area to make it
clear this is not touched by the PacketReinit logic.

Ticket: #5592.
3 years ago
Victor Julien cd2a5ec84f packet: move action functions to packet files 3 years ago
Victor Julien 6c200c7793 detect: issue drop to root packet in all cases
Update DROP action handling in tunnel packets. DROP/REJECT action is set
to outer (root) and inner packet.

Check action flags both against outer (root) and inner packet.

Remove PACKET_SET_ACTION macro. Replace with RESET for the one reset usecase.
The reason to remove is to make the logic easier to understand.

Reduce scope of RESET macros.

Rename PacketTestAction to PacketCheckAction except in unittests. Keep
PacketTestAction as a wrapper around PacketCheckAction. This makes it
easier to trace the action handling in the real code.

Fix rate_filter setting actions directly.

General code cleanups.

Bug: #5571.
3 years ago
Victor Julien ba3e0b3155 nfq: set drop reason on verdict error 3 years ago
Eric Leblond 1c2fba57f8 suricata: introduce global linktype
As Suricata is not supporting pcap-ng we have to stick with one single
datalink type for the capture if ever we want to do pcap logging.
Assuming this, this patch introduces a function to set the link
type globally. This will be used with pcap conditional logging
to get the logging of TCP segments with the correct link type.
3 years ago
Victor Julien 4c7eb64411 decode: convert 'action' macros to inline funcs
Make sure most common branch is handled first to assist branch
prediction.

Macros still play a small role to please our 'action' cocci check.
4 years ago
Jeff Lucovsky 1eeb96696b general: Cleanup bool usage 4 years ago
Victor Julien c39101bbec nfq: suppress debug message using info level 5 years ago
Jason Ish 900f1522b4 plugins: config.h: move into src and rename to autoconf.h
While fixing files that include config.h, just remove the
include if possible.
5 years ago
Victor Julien 0025467f90 sources: hide RegisterTests behind ifdef UNITTESTS
Update callers.
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.
5 years ago
Victor Julien 7810f22413 decode: remove pseudo packet checks
Bug 1107 checks/hacks should not longer be needed, so remove them.
6 years ago
Victor Julien f8aed4ce2d threading: change local packet queue logic
Previously each 'TmSlot' had it's own packet queue that was passed
to the registered SlotFunc as an argument. This was used mostly for
tunnel packets by the decoders and by defrag.

This patch removes that in favor of a single queue in the ThreadVars:
decode_pq. This is the non-locked version of the queue as this is
only a temporary store for handling packets within a thread.

This patch removes the PacketQueue pointer argument from the API.
The new queue can be accessed directly through the ThreadVars
pointer.
6 years ago
Victor Julien 3a703c84ad threading/modules: declare prototypes static
Declare registered threading API funcs static where appropriate.
6 years ago
Victor Julien 7c83cb585e sources: fix pipeline failure handling
When TmThreadsSlotProcessPkt fails it will return the packet that was
passed to it to the packetpool.

Some of the packet sources were doing this manually as well. This patch
fixes those sources.
6 years ago
Victor Julien 49599dfe89 threading: use tm_flowworker for pseudo packets
Pseudo packets don't need to be processed by the decoding layer.
6 years ago
Victor Julien 44d7f636f2 threading: remove post_pq argument from 'SlotFunc'
This was not in use anywhere.
6 years ago
Victor Julien 64a789bbf6 nfq: clear memory of queue before using it
Avoids using uninitialized memory. Show showed itself
in nonsense values in counters, and in nfq_handle_packet
errors that were likely the result of passing uninitialized
memory to the nfq API.

Bug 3263.
Bug 3120.

Fixes: b2a6c60dee ("source-nfq: increase maximum queues number to 65535")
6 years ago
Victor Julien 2fd1174a56 nfq: micro optimization 6 years ago
Victor Julien 9d6087f7d6 nfq: don't warn on 'handle_packet' error
NFQ can generate warnings/errors with a delay. After Suricata has
succesfully passed a verdict to the kernel, there are still things
that can go wrong for that verdict. This is then passed to the
queue through a netlink error message, which leads to nfq_handle_packet
returning an error code.

Suppress the warning. Also remove the errno/strerror use as
nfq_handle_packet does not set the errno.

Thanks to Florian Westphal.

Bug 3120.
6 years ago
Victor Julien f8acad7fca nfq: code cleanups 6 years ago
Alexander Gozman f280e66f84 nfq: check for EAGAIN after recv() call in NFQRecvPkt() 6 years ago
Victor Julien 4cc90e9a4c nfq: minor code cleanups 6 years ago
Victor Julien ce71bf1fff capture: check for flow packets on capture timeout
The capture threads can receive packets from the flow manager in their
Threadvars::stream_pq packet queue. This mechanism makes sure the packets
the flow manager injects into the engine are processed by the correct
worker thread.

If the capture thread(s) would not receive packets for a long time, the
Threadvars::stream_pq would not be checked and processed. This could
lead to packet pool depletion in the flow manager. It would also lead
to flows not being timed out/logged until either packets started flowing
again or until the engine was shut down.

The scenario is more likely to happen in a test (e.g. replay) but could
also delay logging on low traffic sensors.
6 years ago
Alexander Gozman 3a16009966 Bug #2965: fix NFQ arguments parsing 6 years ago
Alexander Gozman 928fe1b859 Bug 2857: NFQ ASAN 'heap-use-after-free' error.
Global NFQ contexts were not freed properly causing
'use-after-free' error. Moving contexts cleanup to a
separate NFQContextsCleanup() and calling it from
GlobalsDestroy(), like it's done for AFPacket, solves
the problem.
6 years ago
Alexander Gozman 2869f8a746 nfqueue: more descriptive queue names (e.g. 'NFQ#1' instead of '1')
This will also make 'iface-list' output more informative.
7 years ago
Alexander Gozman 86d7dddfab nfqueue: added received packets counter for 'iface-stat' command
Previously nfqueue did not update received packets counter in a
livedev so 'iface-stat' UNIX-socket command always showed zeros.
7 years ago