Coverage Report

Created: 2026-08-14 07:34

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/suricata/src/stream-tcp-reassemble.h
Line
Count
Source
1
/* Copyright (C) 2007-2024 Open Information Security Foundation
2
 *
3
 * You can copy, redistribute or modify this Program under the terms of
4
 * the GNU General Public License version 2 as published by the Free
5
 * Software Foundation.
6
 *
7
 * This program is distributed in the hope that it will be useful,
8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 * GNU General Public License for more details.
11
 *
12
 * You should have received a copy of the GNU General Public License
13
 * version 2 along with this program; if not, write to the Free Software
14
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
15
 * 02110-1301, USA.
16
 */
17
18
/**
19
 * \file
20
 *
21
 * \author Victor Julien <victor@inliniac.net>
22
 * \author Gurvinder Singh <gurvindersinghdahiya@gmail.com>
23
 */
24
25
#ifndef SURICATA_STREAM_TCP_REASSEMBLE_H
26
#define SURICATA_STREAM_TCP_REASSEMBLE_H
27
28
#include "suricata.h"
29
#include "flow.h"
30
#include "stream-tcp-private.h"
31
#include "util-exception-policy.h"
32
33
/** Supported OS list and default OS policy is BSD */
34
enum
35
{
36
    OS_POLICY_NONE = 1,
37
    OS_POLICY_BSD,
38
    OS_POLICY_BSD_RIGHT,
39
    OS_POLICY_OLD_LINUX,
40
    OS_POLICY_LINUX,
41
    OS_POLICY_OLD_SOLARIS,
42
    OS_POLICY_SOLARIS,
43
    OS_POLICY_HPUX10,
44
    OS_POLICY_HPUX11,
45
    OS_POLICY_IRIX,
46
    OS_POLICY_MACOS,
47
    OS_POLICY_WINDOWS,
48
    OS_POLICY_VISTA,
49
    OS_POLICY_WINDOWS2K3,
50
    OS_POLICY_FIRST,
51
    OS_POLICY_LAST
52
};
53
54
enum StreamUpdateDir {
55
    UPDATE_DIR_NONE = 0,
56
    UPDATE_DIR_PACKET,
57
    UPDATE_DIR_OPPOSING,
58
    UPDATE_DIR_BOTH,
59
};
60
61
typedef struct TcpReassemblyThreadCtx_ {
62
    void *app_tctx;
63
64
    int segment_thread_pool_id;
65
66
    /** TCP segments which are not being reassembled due to memcap was reached */
67
    StatsCounterId counter_tcp_segment_memcap;
68
    /** times exception policy for stream reassembly memcap was applied **/
69
    ExceptionPolicyCounters counter_tcp_reas_eps;
70
71
    StatsCounterId counter_tcp_segment_from_cache;
72
    StatsCounterId counter_tcp_segment_from_pool;
73
74
    /** number of streams that stop reassembly because their depth is reached */
75
    StatsCounterId counter_tcp_stream_depth;
76
    /** count number of streams with a unrecoverable stream gap (missing pkts) */
77
    StatsCounterId counter_tcp_reass_gap;
78
79
    /** count packet data overlaps */
80
    StatsCounterId counter_tcp_reass_overlap;
81
    /** count overlaps with different data */
82
    StatsCounterId counter_tcp_reass_overlap_diff_data;
83
84
    StatsCounterId counter_tcp_reass_data_normal_fail;
85
    StatsCounterId counter_tcp_reass_data_overlap_fail;
86
87
    /** count OOB bytes */
88
    StatsCounterId counter_tcp_urgent_oob;
89
} TcpReassemblyThreadCtx;
90
91
305k
#define OS_POLICY_DEFAULT   OS_POLICY_BSD
92
93
void StreamTcpReassembleInitMemuse(void);
94
int StreamTcpReassembleHandleSegment(
95
        ThreadVars *, TcpReassemblyThreadCtx *, TcpSession *, TcpStream *, Packet *);
96
int StreamTcpReassembleInit(bool);
97
void StreamTcpReassembleFree(bool);
98
void *StreamTcpReassembleRealloc(void *optr, size_t orig_size, size_t size);
99
void StreamTcpReassembleRegisterTests(void);
100
TcpReassemblyThreadCtx *StreamTcpReassembleInitThreadCtx(ThreadVars *tv);
101
void StreamTcpReassembleFreeThreadCtx(TcpReassemblyThreadCtx *);
102
int StreamTcpReassembleAppLayer (ThreadVars *tv, TcpReassemblyThreadCtx *ra_ctx,
103
                                 TcpSession *ssn, TcpStream *stream,
104
                                 Packet *p, enum StreamUpdateDir dir);
105
106
void StreamTcpCreateTestPacket(uint8_t *, uint8_t, uint8_t, uint8_t);
107
108
void StreamTcpSetSessionNoReassemblyFlag(TcpSession *, char);
109
void StreamTcpSetSessionBypassFlag(TcpSession *);
110
void StreamTcpSetDisableRawReassemblyFlag(TcpSession *, char);
111
112
void StreamTcpSetOSPolicy(TcpStream *, Packet *);
113
114
int StreamTcpReassembleHandleSegmentHandleData(ThreadVars *tv, TcpReassemblyThreadCtx *ra_ctx,
115
        TcpSession *ssn, TcpStream *stream, Packet *p);
116
int StreamTcpReassembleInsertSegment(ThreadVars *, TcpReassemblyThreadCtx *, TcpStream *,
117
        TcpSegment *, Packet *, uint8_t *pkt_data, uint16_t pkt_datalen);
118
TcpSegment *StreamTcpGetSegment(ThreadVars *, TcpReassemblyThreadCtx *);
119
120
void StreamTcpReturnStreamSegments(TcpStream *);
121
void StreamTcpSegmentReturntoPool(TcpSegment *);
122
123
void StreamTcpReassembleTriggerRawInspection(TcpSession *, int direction);
124
125
void StreamTcpPruneSession(Flow *, uint8_t);
126
bool StreamTcpReassembleDepthReached(Packet *p);
127
128
int StreamTcpReassembleSetMemcap(uint64_t size);
129
uint64_t StreamTcpReassembleGetMemcap(void);
130
int StreamTcpReassembleCheckMemcap(uint64_t size);
131
uint64_t StreamTcpReassembleMemuseGlobalCounter(void);
132
133
void StreamTcpDisableAppLayer(Flow *f);
134
int StreamTcpAppLayerIsDisabled(Flow *f);
135
136
bool StreamReassembleRawHasDataReady(TcpSession *ssn, Packet *p);
137
void StreamTcpReassemblySetMinInspectDepth(TcpSession *ssn, int direction, uint32_t depth);
138
139
bool IsTcpSessionDumpingEnabled(void);
140
void EnableTcpSessionDumping(void);
141
142
static inline bool STREAM_LASTACK_GT_BASESEQ(const TcpStream *stream)
143
14.1M
{
144
    /* last ack not yet initialized */
145
14.1M
    if (STREAM_BASE_OFFSET(stream) == 0 && (stream->tcp_flags & TH_ACK) == 0) {
146
#ifdef UNITTESTS
147
        if (RunmodeIsUnittests() && stream->last_ack == 0)
148
            return false;
149
#else
150
69.1k
        return false;
151
69.1k
#endif
152
69.1k
    }
153
14.0M
    return SEQ_GT(stream->last_ack, stream->base_seq);
154
14.1M
}
Unexecuted instantiation: app-layer-parser.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: app-layer-smtp.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: app-layer-ssh.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: app-layer-ssl.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: app-layer-tftp.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: app-layer.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: decode.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: defrag.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: detect-engine-state.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: flow-util.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: output.c:STREAM_LASTACK_GT_BASESEQ
stream-tcp-reassemble.c:STREAM_LASTACK_GT_BASESEQ
Line
Count
Source
143
8.25M
{
144
    /* last ack not yet initialized */
145
8.25M
    if (STREAM_BASE_OFFSET(stream) == 0 && (stream->tcp_flags & TH_ACK) == 0) {
146
#ifdef UNITTESTS
147
        if (RunmodeIsUnittests() && stream->last_ack == 0)
148
            return false;
149
#else
150
21.0k
        return false;
151
21.0k
#endif
152
21.0k
    }
153
8.22M
    return SEQ_GT(stream->last_ack, stream->base_seq);
154
8.25M
}
Unexecuted instantiation: stream-tcp.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: suricata.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: util-exception-policy.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: util-file.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: util-host-os-info.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: util-running-modes.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: alert-debuglog.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: app-layer-detect-proto.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: app-layer-dnp3.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: app-layer-frames.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: app-layer-ftp.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: app-layer-htp.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: app-layer-imap.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: decode-udp.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: detect-content.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: detect-engine-payload.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: detect-engine-register.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: detect-file-data.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: detect-filemagic.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: detect-filename.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: detect-filesize.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: detect-filestore.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: detect-fragbits.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: detect-ftp-command-data.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: detect-ftp-command.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: detect-ftp-dynamic-port.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: detect-ftp-completion-code.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: detect-ftp-reply.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: detect-ftpbounce.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: detect-ftp-mode.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: detect-http-client-body.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: detect-http-cookie.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: detect-http-header-names.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: detect-http-header.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: detect-http-host.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: detect-http-method.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: detect-http-protocol.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: detect-http-raw-header.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: detect-http-request-line.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: detect-http-response-line.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: detect-http-server-body.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: detect-http-start.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: detect-http-stat-code.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: detect-http-stat-msg.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: detect-http-ua.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: detect-http-uri.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: detect-isdataat.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: detect-lua.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: detect-parse.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: detect-pcre.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: detect-reference.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: detect-replace.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: detect-sip-method.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: detect-sip-uri.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: detect-ssl-state.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: detect-ssl-version.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: detect-stream_size.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: detect-threshold.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: detect-tls-alpn.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: detect-tls-cert-fingerprint.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: detect-tls-cert-issuer.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: detect-tls-cert-serial.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: detect-tls-cert-subject.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: detect-tls-cert-validity.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: detect-tls-certs.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: detect-tls-ja3-hash.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: detect-tls-ja3-string.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: detect-tls-ja3s-hash.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: detect-tls-ja3s-string.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: detect-tls-random.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: detect-tls-sni.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: detect-tls-subjectaltname.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: detect-tls-version.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: detect-tls.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: detect-ttl.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: detect-uricontent.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: detect-urilen.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: detect-within.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: detect.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: flow-hash.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: flow-manager.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: flow-timeout.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: flow-worker.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: log-pcap.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: output-eve-stream.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: output-filestore.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: output-json-alert.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: output-json-anomaly.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: output-json-dhcp.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: output-json-dnp3.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: output-json-email-common.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: output-json-file.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: output-json-flow.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: output-json-frame.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: output-json-ftp.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: output-json-http.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: output-json-ike.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: output-json-mqtt.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: output-json-nfs.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: output-json-pgsql.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: output-json-smtp.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: output-json-tls.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: output-streaming.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: output-tx.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: runmode-unix-socket.c:STREAM_LASTACK_GT_BASESEQ
stream-tcp-list.c:STREAM_LASTACK_GT_BASESEQ
Line
Count
Source
143
5.87M
{
144
    /* last ack not yet initialized */
145
5.87M
    if (STREAM_BASE_OFFSET(stream) == 0 && (stream->tcp_flags & TH_ACK) == 0) {
146
#ifdef UNITTESTS
147
        if (RunmodeIsUnittests() && stream->last_ack == 0)
148
            return false;
149
#else
150
48.0k
        return false;
151
48.0k
#endif
152
48.0k
    }
153
5.82M
    return SEQ_GT(stream->last_ack, stream->base_seq);
154
5.87M
}
Unexecuted instantiation: stream-tcp-sack.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: stream.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: util-lua-rule.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: util-lua-tls.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: util-lua.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: detect-app-layer-event.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: detect-app-layer-protocol.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: detect-app-layer-state.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: detect-bypass.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: detect-bytejump.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: detect-bytetest.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: detect-config.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: detect-depth.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: detect-distance.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: detect-engine-event.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: detect-engine-file.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: detect-engine-frame.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: detect-http-header-common.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: fuzz_predefpcap_aware.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: fuzz_sigpcap.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: util-unittest-helper.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: fuzz_sigpcap_aware.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: fuzz_applayerprotodetectgetproto.c:STREAM_LASTACK_GT_BASESEQ
Unexecuted instantiation: fuzz_siginit.c:STREAM_LASTACK_GT_BASESEQ
155
156
uint32_t StreamDataAvailableForProtoDetect(TcpStream *stream);
157
158
#endif /* SURICATA_STREAM_TCP_REASSEMBLE_H */