47 Commits
Author SHA1 Message Date
Philippe Antoine 8461e3f3e7 src: do not include "util-unittest.h" directly
It is included in suricata-common.h

Ticket: 945
2026-10-08 13:08:16 +00:00
Jason Ish a01636c84b defrag/ipv6: support maximum payload length
The maximum IPv6 payload of 65535 bytes results in a packet of 65575
bytes when the fixed header is included. This was truncated to a u16
before decoding a reassembled packet, causing it to bypass further
inspection.

Use a u32 for the IPv6 decoder length so maximum sized reassembled
packets are fully inspected.

Ticket: #8818
2026-09-08 20:24:50 +02:00
Victor Julien 78da4cfcae counters: regular counter Incr API update 2025-12-02 06:21:54 +00:00
Victor Julien fda72e6f83 unittests: clean up memory for ppp tests 2025-10-14 19:40:56 +02:00
Thomas Winter 804ce2ed3c decode/pppoe: CDPCP as a known protocol
Cisco Discovery Protocol Control Protocol may be sent over pppoe.
We should allow it to help network functions.
2025-09-08 18:47:11 +02:00
Thomas Winter 1f5fc68dc4 decode/pppoe: Don't mark expected PPP protos as unsupported
After upgrading from 7.0.6 to 7.0.8, regular ppp packets are getting
dropped when ppp rules in decoder-events.rules were set as drop.
This was caused by commit a8f35806 ("detect: fix decoder only events").
Previously these rules would not be alerted or dropped.

It turns out several PPP protocols in a switch statement were falling
into the PPP_UNSUP_PROTO case. This has always been the case, I assume
the intention was that they don't get further inspected for size and
other decode errors hence unsupported.
But really some of the protocols are fundamentally required for a PPP
connection to take place.

Change some types that we know should be allowed to pass this.

Ticket: 7651
2025-09-08 18:47:11 +02:00
Thomas Winter 498ae6d1fa decode/pppoe: Run clang-format
These files have existing problems which prevent patches from
passing the format check on them.
2025-09-08 18:47:11 +02:00
Victor Julien dc5b78ec71 decode/ppp: fix iplen check int handling
** CID 1596376:    (CONSTANT_EXPRESSION_RESULT)
/src/decode-ppp.c: 64 in DecodePPPCompressedProto()
/src/decode-ppp.c: 55 in DecodePPPCompressedProto()

________________________________________________________________________________________________________
*** CID 1596376:    (CONSTANT_EXPRESSION_RESULT)
/src/decode-ppp.c: 64 in DecodePPPCompressedProto()
58             case 0x57: { /* PPP_IPV6 */
59                 if (unlikely(len < (data_offset + IPV6_HEADER_LEN))) {
60                     ENGINE_SET_INVALID_EVENT(p, PPPIPV6_PKT_TOO_SMALL);
61                     return TM_ECODE_FAILED;
62                 }
63                 DEBUG_VALIDATE_BUG_ON(len < data_offset);
>>>     CID 1596376:    (CONSTANT_EXPRESSION_RESULT)
>>>     "65535 /* 32767 * 2 + 1 */ < (uint16_t)(len - data_offset)" is always false regardless of the values of its operands. This occurs as the logical first operand of "?:".
64                 uint16_t iplen = MIN(USHRT_MAX, (uint16_t)(len - data_offset));
65                 return DecodeIPV6(tv, dtv, p, pkt + data_offset, iplen);
66             }
67             case 0x2f: /* PPP_VJ_UCOMP */
68                 if (unlikely(len < (data_offset + IPV4_HEADER_LEN))) {
69                     ENGINE_SET_INVALID_EVENT(p, PPPVJU_PKT_TOO_SMALL);
/src/decode-ppp.c: 55 in DecodePPPCompressedProto()
49             case 0x21: { /* PPP_IP */
50                 if (unlikely(len < (data_offset + IPV4_HEADER_LEN))) {
51                     ENGINE_SET_INVALID_EVENT(p, PPPVJU_PKT_TOO_SMALL);
52                     return TM_ECODE_FAILED;
53                 }
54                 DEBUG_VALIDATE_BUG_ON(len < data_offset);
>>>     CID 1596376:    (CONSTANT_EXPRESSION_RESULT)
>>>     "65535 /* 32767 * 2 + 1 */ < (uint16_t)(len - data_offset)" is always false regardless of the values of its operands. This occurs as the logical first operand of "?:".
55                 uint16_t iplen = MIN(USHRT_MAX, (uint16_t)(len - data_offset));
56                 return DecodeIPV4(tv, dtv, p, pkt + data_offset, iplen);
57             }
58             case 0x57: { /* PPP_IPV6 */
59                 if (unlikely(len < (data_offset + IPV6_HEADER_LEN))) {
60                     ENGINE_SET_INVALID_EVENT(p, PPPIPV6_PKT_TOO_SMALL);
2024-04-16 19:42:14 +02:00
Victor Julien 516441b600 decode/ppp: add missing types definitions
Recognize PPP_CCP, PPP_CBCP and PPP_COMP_DGRAM.

Does not implement decoders for these record types, so these
are logged as unsupported types. Was "wrong_type" before.
2024-04-15 20:34:38 +02:00
Victor Julien 7e3f071e49 decode/ppp: clean up ppph pointer use
No users of the pointer anymore, so remove it.
2024-04-15 20:34:38 +02:00
Victor Julien 6067955afd decode/ppp: remove ppph check in favor of flag
As we now support variable size headers, we can't use the old pointer.

Replace with a flag.
2024-04-15 20:34:38 +02:00
Victor Julien 68092ff33c decode/ppp: support different header formats
Support compressed proto and optional HDLC header.

Bug: #6942.
2024-04-15 20:34:38 +02:00
Philippe Antoine 73ed780095 decode: fix integer warnings
Ticket: 4516
2022-04-30 08:11:29 +02:00
Jeff Lucovsky 83067e5a55 decode: Eliminate NULL pkt checks
This commit removes the NULL pkt check that each decoder performs as
this is a "can't happen" case.
2021-06-04 12:02:58 +02:00
Philippe Antoine 7500c29300 decode: limits the number of decoded layers
so as to avoid overrecursion leading to stack exhaustion
2021-02-26 11:32:15 +01:00
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.
2020-02-07 15:43:10 +01:00
Victor Julien 579cc9f02b const: constify decoder, app-layer, detect funcs 2019-09-02 15:29:32 +02:00
Maurizio Abba 55b14f3721 decode: set pktlen of decode handler to uint32
Change the decode handler signature to increase the size of its decode
handler, from uint16 to uint32. This is necessary to let suricata use
interfaces with mtu > 65535 (ex: lo interface has default size 65536).

It's necessary to change several primitive for Packet manipulation, to
unify the parameter "packet length" whenever we are before IP decoding.

Add tests before calling DecodeIPVX function to avoid a possible
integer overflow over the len parameter.
2018-08-06 11:35:35 +02:00
Victor Julien 11be9bd971 mingw: add SCNtohl and SCNtohs macro's
On MinGW the result of ntohl needs to be casted to uint32_t and
the result of ntohs to uint16_t. To avoid doing this everywhere
add SCNtohl and SCNtohs macros.
2017-12-20 16:23:31 +01:00
Jason Ish 796dd5223b tests: no longer necessary to provide successful return code
1 pass, 0 is fail.
2016-04-08 12:28:09 +02:00
Victor Julien 1c0b4ee0ae counters: s/SCPerfCounterIncr/StatsIncr/g 2015-05-27 14:14:46 +02:00
Victor Julien e9b067c1eb counters: make increment call take threadvars
This hides the implementation from the caller.
2015-05-26 17:52:57 +02:00
Victor Julien 9a8bff7d96 counters: threadvars s/sc_perf_pca/perf_private_ctx/g 2015-05-26 17:49:36 +02:00
Ken Steele 8f1d75039a Enforce function coding standard
Functions should be defined as:

int foo(void)
{
}

Rather than:
int food(void) {
}

All functions where changed by a script to match this standard.
2014-07-30 14:19:35 -04:00
Eric Leblond b2c58b8d14 Set packet invalid flag during decoding.
This patch set a new value in pkt->flag to signal that a packet is
invalid during decoding. The patch has been obtained via a coccinelle
transformation.
2013-12-02 11:05:45 +01:00
Eric Leblond d4b7ecfbe3 decode: update API to return error
In some cases, the decoding is not possible and some really invalid
packet can be created. This is in particular the case of tunnel. In
that case, it is more interesting to forget about the tunneled
packet and only consider the original packet.

DecodeTunnel function is maked as warn_unused_result because it is
meaningful for the decoder to know if the underlying data were not
correct. And in this case, only focus detection on the content.
2013-11-28 17:38:11 +01:00
Victor Julien 49087f21e4 Optimizations to reduce branch misses 2013-10-30 15:35:01 +01:00
Ken Steele 9c7b411a5d More PacketGetFromMalloc() to allocate packets. 2013-05-21 18:30:13 +02:00
Eric Leblond e176be6fcc Use unlikely for error treatment.
When handling error case on SCMallog, SCCalloc or SCStrdup
we are in an unlikely case. This patch adds the unlikely()
expression to indicate this to gcc.

This patch has been obtained via coccinelle. The transformation
is the following:

@istested@
identifier x;
statement S1;
identifier func =~ "(SCMalloc|SCStrdup|SCCalloc)";
@@

x = func(...)
... when != x
- if (x == NULL) S1
+ if (unlikely(x == NULL)) S1
2012-09-25 16:24:39 +02:00
Eric Leblond acf10525f6 doc: add decode group and related documentation. 2011-10-30 13:03:05 +01:00
Eric Leblond 7425bf5ca6 Rename some decode event structure and macro.
This patch renames DECODER_SET_EVENT, DECODER_ISSET_EVENT and some
other structures to ENGINE equivalent to take into account the fact
the event list is now related to all engines and not only to decoder.
2011-09-08 17:09:44 +02:00
Eric Leblond 1db4aadd16 Supress usage of Packet declaration in tests.
For convenience, a massive usage of 'Packet p;' declaration has
been done in the tests function. Although this was completely
legal, this is not possible anymore because of the new Packet
allocation structure. This massive patch modifies all suricata
files to use a SCMalloc allocated pointer to Packet instead.

This patch has been done using coccinelle (http://coccinelle.lip6.fr)
which is a semantic patching tool. This ensures that things like call
to SCFree() should have not been forget because the semantic patch
explicitly forces the call to SCFree(p) before each return. With this
patch all unittests are running fine with a small and a big default
packet size.
2010-12-31 16:25:23 +01:00
Eric Leblond dd038c1906 Modify files to avoid direct pckt payload access
This patch implements the needed modification of payload access
in a Packet structure to support the abstraction introduced by
the extended data system.
2010-12-31 16:25:23 +01:00
William Metcalf ce01927515 Import of GPLv2 Header 050410 2010-05-05 16:28:56 +02:00
Victor Julien ecf86f9c23 Rename to Suricata. 2009-12-21 13:25:58 +01:00
Anoop Saldanha ceb7e495ae refactoring perf stats code 2009-11-10 16:23:21 +01:00
Breno Silva c43319c337 Regular expression for UnitTests
Signed-off-by: Brian Rectanus <[email protected]>
2009-09-30 07:58:15 +02:00
Victor Julien 968d8df12b More logging API usage. Changed logging macro's slightly so the vars inside them won't conflict with vars used by the calling function. 2009-09-28 13:15:45 +02:00
Victor Julien 0d0ffb9963 Reorganize header inclusions. 2009-09-17 10:43:45 +02:00
Victor Julien 57f71f7e4b Pass the DecodeThreadVars to all Decoder functions properly. Improve the error handling. 2009-08-20 15:25:12 +02:00
Anoop Saldanha 244f5d547a new registration functions for the stats api, with local thread storage for counter ids 2009-08-20 12:45:48 +02:00
Victor Julien 4ec31e0445 Fix short IPv4 packets not getting detected in the decoder. Set decode event on short ipv6 packets. 2009-08-16 23:31:32 +02:00
Brian Rectanus fa5939ca91 64 bit cleanup part2 2009-08-16 10:32:11 +02:00
Anoop Saldanha d0e70309c0 Implements counters for the decode module 2009-08-11 14:01:12 +02:00
Victor Julien 9854c19a88 Adapt Flow subsys init function to be able to initialize quietly for us in unit tests. Add flow to PPP unit tests. Fixes a floating point exception error. 2009-07-31 11:39:08 +02:00
Victor Julien 76581ef967 Small layout fixes to the ppp code. 2009-07-28 23:25:22 +02:00
Breno Silva dec11038c6 PPP Support 2009-07-28 23:25:22 +02:00