Commit Graph

191 Commits (c17df004ed609cd19e12c87b48cfce60bb016951)

Author SHA1 Message Date
Victor Julien 1190e426f9 defrag: remove trackers on lookup
When looking up a tracker, remove any timed out / completed trackers.
1 year ago
Victor Julien 83dc703d1f defrag: add various counters 1 year ago
Philippe Antoine 20423fdd38 style: remove some useless return
and remove empty line before end of function
1 year ago
Philippe Antoine a262e203f9 src: remove some unused parameters 1 year ago
Giuseppe Longo b728916ca6 decode/gre: decode arp packets 1 year ago
Victor Julien 49c67b2bb1 defrag: fix wrong datalink being logged
Eve's packet_info.linktype should correctly indicated what the `packet`
field contains. Until now it was using DLT_RAW even if Ethernet or other
L2+ headers were present.

This commit records the datalink of the packet creating the first
fragment, which can include the L2+ header data.

Bug: #6887.
1 year ago
Juliana Fajardini 485c0e1d9a defrag: add exception policy memcap stats counters
Add defrag memcap stats counter.

Task #5816
1 year ago
Juliana Fajardini 657419b53e decode/flow: add exception policy stats counters
We will register stats counters for all policies, even though for now
Suri only uses one possible configuration policy at a time. The idea is
that this could change in the near future, so we want to have this
ready.

Task #5816
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
Jeff Lucovsky 193e0ea1a9 memory/alloc: Use SCCalloc instead of malloc/memset 2 years ago
Jeff Lucovsky 904f0ddeee stats: Track stream reassembly drops
Issue: 6235
2 years ago
Victor Julien 1f9767a9cb stats: add drop reason counters
{
  "accepted": 296185,
  "blocked": 162,
  "rejected": 0,
  "replaced": 0,
  "drop_reason": {
    "decode_error": 0,
    "defrag_error": 0,
    "defrag_memcap": 0,
    "flow_memcap": 0,
    "flow_drop": 94,
    "applayer_error": 0,
    "applayer_memcap": 0,
    "rules": 3,
    "threshold_detection_filter": 0,
    "stream_error": 63,
    "stream_memcap": 0,
    "stream_midstream": 2,
    "nfq_error": 0,
    "tunnel_packet_drop": 0
  }
}

Ticket: #6230.
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
Juliana Fajardini d9c430d73d misc: fix typos & update copyright years 2 years ago
Juliana Fajardini a37a88dcd5 defrag: clean up existing stats counters
7a044a99ee removed the lines that incremented these defrag
counters, but kept the entities themselves. This commit removes counters
that we judge too complex to maintain, given the current state of the
code, and re-adds incrementing max_hit (memcap related).

Related to
Task #5816
2 years ago
Jeff Lucovsky 0d2268ddfc decode/vlan: Decode upto 3 layers of VLAN
Issue: 2816

This commit increase the number of VLAN layers supported by Suricata
from 2 to 3. 3-layers are dubbed "Q-in-Q-in-Q".

Note that 3 layers are not compliant with any existing standard but are
often seen in larger deployments.
2 years ago
Victor Julien 36f6e05155 counters: make tcp stats independent of flow, ssn
Counters depended on availability of flow and tcp session, meaning
that 2 memcaps could affect the counters.

Bug: #5017.
2 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.
2 years ago
Victor Julien 59ca5cc655 decode: suppress scan-build warning 2 years ago
Jeff Lucovsky c1c67536b6 decode/stat: Add decode counters for unknown/arp
Issue: 5761

This commit adds statistics for ARP and unknown ethertype packets for
diagnostic purposes.
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
2 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 03d049dadc decode: enforce layer limit through tunnel layers
Bug: #5686.
3 years ago
Philippe Antoine 62352ad030 src: fix remaining cppclean warnings 3 years ago
Victor Julien 0e7adc21a6 decode: alloc packets using calloc 3 years ago
Victor Julien 68a9da52ad packetpool: remove PKT_ALLOC flag
Use Packet::pool instead. If Packet::pool is non-NULL the packet is
owned by a pool. Otherwise it is allocated and should be freed after
use.
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 fe5a8beb50 decode: minor code cleanup 3 years ago
Victor Julien ba3e0b3155 nfq: set drop reason on verdict error 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
Juliana Fajardini aa5bb2c329 stream: add exception policy for midstream flows
This allows to set a midstream-policy that can:
- fail closed (stream.midstream-policy=drop-flow)
- fail open (stream.midstream-policy=pass-flow)
- bypass stream (stream.midstream-policy=bypass)
- do nothing (default behavior)

Usage and behavior:

If stream.midstream-policy is set then if Suricata identifies a midstream flow
it will apply the corresponding action associated with the policy.

No setting means Suricata will not apply such policies, either inspecting the
flow (if stream.midstream=true) or ignoring it stream.midstream=false.

Task #5468
3 years ago
Philippe Antoine 02f2602dde src: rework includes as per cppclean 3 years ago
Victor Julien b0993d6fd8 flow: add various flow counters
Add flow.end state counters

Add active TCP sessions counter

Add flow.active counter

Add flow.total counter

Ticket: #1478.
3 years ago
Lukas Sismis 05797c45bb bypass: fix memory leak - reassign of FlowBypassInfo
In some situations bypass callback is called on already bypassed
flow. This allocates FlowBypassInfo structure for the flow but
does not check if the flow already has one.

Issue: #5368
3 years ago
Victor Julien 0035673208 eve/drop: log drop reason
Ticket: #5202.
3 years ago
Philippe Antoine d5abaf0b38 decode: fix integer warning
Newly introduced warning.
Regular cast as value is checked just before.

Ticket: #4516
3 years ago
Philippe Antoine 73ed780095 decode: fix integer warnings
Ticket: 4516
3 years ago
Juliana Fajardini 3ace577d54 decode: make packet_alert_max configurable
The maximum of possible alerts triggered by a unique packet was
hardcoded to 15. With usage of 'noalert' rules, that limit could be
reached somewhat easily. Make that configurable via suricata.yaml.

Conf Bug#4941

Task #4207
3 years ago
Philippe Antoine e1c0725e05 doc: fix typo lenght/length 4 years ago
Victor Julien 373278438d packetpool: ReleasePacket callback check on getter
Any packet coming from the pool should have `PacketPoolReturnPacket`
as its callback. Check that this is the case.
4 years ago
Victor Julien 07ce871da4 packetpool: reset PacketRelease on return to pool
Reset PacketRelease callback to make sure its not set to a capture
specific callback.

As an example:

  0x000055e00af09d35 in AFPReleaseDataFromRing (p=0x7f1d884cb830) at source-af-packet.c:653
  0x000055e00af09dd0 in AFPReleasePacket (p=0x7f1d884cb830) at source-af-packet.c:678
  0x000055e00ab53d7e in TmqhOutputPacketpool (t=0x55e00fb79250, p=0x7f1d884cb830) at tmqh-packetpool.c:465
  0x000055e00af08dec in TmThreadsSlotProcessPkt (tv=0x55e00fb79250, s=0x55e012134790, p=0x7f1d884cb830) at tm-threads.h:201
  0x000055e00af08e70 in TmThreadsCaptureInjectPacket (tv=0x55e00fb79250, p=0x7f1d884cb830) at tm-threads.h:221
  0x000055e00af08f2e in TmThreadsCaptureHandleTimeout (tv=0x55e00fb79250, p=0x0) at tm-threads.h:245
  0x000055e00af0ba76 in ReceiveAFPLoop (tv=0x55e00fb79250, data=0x7f1d884ccb60, slot=0x55e01198e4b0) at source-af-packet.c:1321
  0x000055e00ab55257 in TmThreadsSlotPktAcqLoop (td=0x55e00fb79250) at tm-threads.c:312
  0x00007f1dca9d5609 in start_thread (arg=<optimized out>) at pthread_create.c:477
  0x00007f1dca7c6293 in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95

Here the packet was a pseudo packet to handle a timeout condition. But
the ReleasePacket callback was still set to AFPReleasePacket from a
previous use of the Packet.

Bug: #4807.
4 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 b944e636a8 decode/stats: VNTAG stats 4 years ago
Philippe Antoine 7500c29300 decode: limits the number of decoded layers
so as to avoid overrecursion leading to stack exhaustion
4 years ago
Emmanuel Thompson f12daa710f decode/flow/esp: Add ESP decoder & flow
- Adds an ESP (Encapsulating Security Payload) header decoder
- Tracks ESP flows via the SPI field
5 years ago
Carl Smith 660b68a083 nsh: Parsing of Network Services Header and payload
Support for EtherType 0x894F and basic header
5 years ago
Philippe Antoine d5ac77ee8b packet: set length of 0 for too big copy 5 years ago
Victor Julien 8cd82486e2 flow/bypass: don't bypass on flow timeout pseudo packets 5 years ago