• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

OISF / suricata / 22550902417

01 Mar 2026 07:32PM UTC coverage: 68.401% (-5.3%) from 73.687%
22550902417

Pull #14922

github

web-flow
github-actions: bump actions/upload-artifact from 6.0.0 to 7.0.0

Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from 6.0.0 to 7.0.0.
- [Release notes](https://github.com/actions/upload-artifact/releases)
- [Commits](https://github.com/actions/upload-artifact/compare/v6...v7)

---
updated-dependencies:
- dependency-name: actions/upload-artifact
  dependency-version: 7.0.0
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Pull Request #14922: github-actions: bump actions/upload-artifact from 6.0.0 to 7.0.0

218243 of 319063 relevant lines covered (68.4%)

3284926.58 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

82.0
/src/app-layer-parser.c
1
/* Copyright (C) 2007-2026 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
 *
23
 * Generic App-layer parsing functions.
24
 */
25

26
#include "suricata-common.h"
27
#include "app-layer-parser.h"
28

29
#include "flow.h"
30
#include "flow-private.h"
31
#include "flow-util.h"
32

33
#include "app-layer-frames.h"
34
#include "app-layer-events.h"
35

36
#include "stream-tcp.h"
37

38
#include "util-validate.h"
39
#include "util-config.h"
40

41
#include "app-layer.h"
42
#include "app-layer-detect-proto.h"
43

44
#include "app-layer-ftp.h"
45
#include "app-layer-smtp.h"
46

47
#include "app-layer-smb.h"
48
#include "app-layer-htp.h"
49
#include "app-layer-ssl.h"
50
#include "app-layer-ssh.h"
51
#include "app-layer-modbus.h"
52
#include "app-layer-dnp3.h"
53
#include "app-layer-nfs-tcp.h"
54
#include "app-layer-nfs-udp.h"
55
#include "app-layer-tftp.h"
56
#include "app-layer-ike.h"
57
#include "app-layer-http2.h"
58
#include "app-layer-imap.h"
59

60
struct AppLayerParserThreadCtx_ {
61
    void *(*alproto_local_storage)[FLOW_PROTO_MAX];
62
};
63

64

65
/**
66
 * \brief App layer protocol parser context.
67
 */
68
typedef struct AppLayerParserProtoCtx_
69
{
70
    /* 0 - to_server, 1 - to_client. */
71
    AppLayerParserFPtr Parser[2];
72

73
    bool logger;
74

75
    /* Indicates the direction the parser is ready to see the data
76
     * the first time for a flow.  Values accepted -
77
     * STREAM_TOSERVER, STREAM_TOCLIENT */
78
    uint8_t first_data_dir;
79

80
    uint32_t logger_bits;   /**< registered loggers for this proto */
81

82
    void *(*StateAlloc)(void *, AppProto);
83
    void (*StateFree)(void *);
84
    void (*StateTransactionFree)(void *, uint64_t);
85
    void *(*LocalStorageAlloc)(void);
86
    void (*LocalStorageFree)(void *);
87

88
    /** get FileContainer reference from the TX. MUST return a non-NULL reference if the TX
89
     *  has or may have files in the requested direction at some point. */
90
    AppLayerGetFileState (*GetTxFiles)(void *, uint8_t);
91

92
    int (*StateGetProgress)(void *alstate, uint8_t direction);
93
    uint64_t (*StateGetTxCnt)(void *alstate);
94
    void *(*StateGetTx)(void *alstate, uint64_t tx_id);
95
    AppLayerGetTxIteratorFunc StateGetTxIterator;
96
    int complete_ts;
97
    int complete_tc;
98
    int (*StateGetEventInfoById)(
99
            uint8_t event_id, const char **event_name, AppLayerEventType *event_type);
100
    int (*StateGetEventInfo)(
101
            const char *event_name, uint8_t *event_id, AppLayerEventType *event_type);
102

103
    AppLayerStateData *(*GetStateData)(void *state);
104
    AppLayerTxData *(*GetTxData)(void *tx);
105
    void (*ApplyTxConfig)(void *state, void *tx, int mode, AppLayerTxConfig);
106

107
    void (*SetStreamDepthFlag)(void *tx, uint8_t flags);
108

109
    AppLayerParserGetFrameIdByNameFn GetFrameIdByName;
110
    AppLayerParserGetFrameNameByIdFn GetFrameNameById;
111

112
    AppLayerParserGetStateIdByNameFn GetStateIdByName;
113
    AppLayerParserGetStateNameByIdFn GetStateNameById;
114

115
    /* each app-layer has its own value */
116
    uint32_t stream_depth;
117

118
    /* Option flags such as supporting gaps or not. */
119
    uint32_t option_flags;
120
    /* coccinelle: AppLayerParserProtoCtx:option_flags:APP_LAYER_PARSER_OPT_ */
121

122
    uint32_t internal_flags;
123
    /* coccinelle: AppLayerParserProtoCtx:internal_flags:APP_LAYER_PARSER_INT_ */
124

125
#ifdef UNITTESTS
126
    void (*RegisterUnittests)(void);
127
#endif
128
} AppLayerParserProtoCtx;
129

130
typedef struct AppLayerParserCtx_ {
131
    AppLayerParserProtoCtx (*ctxs)[FLOW_PROTO_MAX];
132
    size_t ctxs_len;
133
} AppLayerParserCtx;
134

135
struct AppLayerParserState_ {
136
    /* coccinelle: AppLayerParserState:flags:APP_LAYER_PARSER_ */
137
    uint16_t flags;
138

139
    /* Indicates the current transaction that is being inspected.
140
     * We have a var per direction. */
141
    uint64_t inspect_id[2];
142
    /* Indicates the current transaction being logged.  Unlike inspect_id,
143
     * we don't need a var per direction since we don't log a transaction
144
     * unless we have the entire transaction. */
145
    uint64_t log_id;
146

147
    uint64_t min_id;
148

149
    /* Used to store decoder events. */
150
    AppLayerDecoderEvents *decoder_events;
151

152
    FramesContainer *frames;
153
};
154

155
enum ExceptionPolicy g_applayerparser_error_policy = EXCEPTION_POLICY_NOT_SET;
156

157
static void AppLayerConfig(void)
158
{
40✔
159
    g_applayerparser_error_policy = ExceptionPolicyParse("app-layer.error-policy", true);
40✔
160
}
40✔
161

162
enum ExceptionPolicy AppLayerErrorGetExceptionPolicy(void)
163
{
102✔
164
    return g_applayerparser_error_policy;
102✔
165
}
102✔
166

167
static void AppLayerParserFramesFreeContainer(FramesContainer *frames)
168
{
3,541✔
169
    if (frames != NULL) {
3,541✔
170
        FramesFree(&frames->toserver);
×
171
        FramesFree(&frames->toclient);
×
172
        SCFree(frames);
×
173
    }
×
174
}
3,541✔
175

176
void AppLayerFramesFreeContainer(Flow *f)
177
{
×
178
    if (f == NULL || f->alparser == NULL || f->alparser->frames == NULL)
×
179
        return;
×
180
    AppLayerParserFramesFreeContainer(f->alparser->frames);
×
181
    f->alparser->frames = NULL;
×
182
}
×
183

184
FramesContainer *AppLayerFramesGetContainer(const Flow *f)
185
{
820,023✔
186
    if (f == NULL || f->alparser == NULL)
820,111✔
187
        return NULL;
11,378✔
188
    return f->alparser->frames;
808,645✔
189
}
820,023✔
190

191
FramesContainer *AppLayerFramesSetupContainer(Flow *f)
192
{
×
193
#ifdef UNITTESTS
194
    if (f == NULL || f->alparser == NULL || (f->proto == IPPROTO_TCP && f->protoctx == NULL))
195
        return NULL;
196
#endif
197
    DEBUG_VALIDATE_BUG_ON(f == NULL || f->alparser == NULL);
×
198
    if (f->alparser->frames == NULL) {
×
199
        f->alparser->frames = SCCalloc(1, sizeof(FramesContainer));
×
200
        if (f->alparser->frames == NULL) {
×
201
            return NULL;
×
202
        }
×
203
#ifdef DEBUG
204
        f->alparser->frames->toserver.ipproto = f->proto;
205
        f->alparser->frames->toserver.alproto = f->alproto;
206
        f->alparser->frames->toclient.ipproto = f->proto;
207
        f->alparser->frames->toclient.alproto = f->alproto;
208
#endif
209
    }
×
210
    return f->alparser->frames;
×
211
}
×
212

213
#ifdef UNITTESTS
214
void UTHAppLayerParserStateGetIds(void *ptr, uint64_t *i1, uint64_t *i2, uint64_t *log, uint64_t *min)
215
{
9✔
216
    struct AppLayerParserState_ *s = ptr;
9✔
217
    *i1 = s->inspect_id[0];
9✔
218
    *i2 = s->inspect_id[1];
9✔
219
    *log = s->log_id;
9✔
220
    *min = s->min_id;
9✔
221
}
9✔
222
#endif
223

224
/* Static global version of the parser context.
225
 * Post 2.0 let's look at changing this to move it out to app-layer.c. */
226
static AppLayerParserCtx alp_ctx;
227

228
int AppLayerParserProtoIsRegistered(uint8_t ipproto, AppProto alproto)
229
{
338,252✔
230
    uint8_t ipproto_map = FlowGetProtoMapping(ipproto);
338,252✔
231

232
    return (alp_ctx.ctxs[alproto][ipproto_map].StateAlloc != NULL) ? 1 : 0;
338,252✔
233
}
338,252✔
234

235
AppLayerParserState *AppLayerParserStateAlloc(void)
236
{
3,536✔
237
    SCEnter();
3,536✔
238

239
    AppLayerParserState *pstate = (AppLayerParserState *)SCCalloc(1, sizeof(*pstate));
3,536✔
240
    if (pstate == NULL)
3,536✔
241
        goto end;
×
242

243
 end:
3,536✔
244
    SCReturnPtr(pstate, "AppLayerParserState");
3,533✔
245
}
3,536✔
246

247
void AppLayerParserStateFree(AppLayerParserState *pstate)
248
{
3,541✔
249
    SCEnter();
3,541✔
250

251
    if (pstate->decoder_events != NULL)
3,541✔
252
        SCAppLayerDecoderEventsFreeEvents(&pstate->decoder_events);
×
253
    AppLayerParserFramesFreeContainer(pstate->frames);
3,541✔
254
    SCFree(pstate);
3,541✔
255

256
    SCReturn;
3,541✔
257
}
3,541✔
258

259
int AppLayerParserSetup(void)
260
{
40✔
261
    SCEnter();
40✔
262
    // initial allocation that will later be grown using realloc,
263
    // when new protocols register themselves and make g_alproto_max grow
264
    alp_ctx.ctxs = SCCalloc(g_alproto_max, sizeof(AppLayerParserProtoCtx[FLOW_PROTO_MAX]));
40✔
265
    if (unlikely(alp_ctx.ctxs == NULL)) {
40✔
266
        FatalError("Unable to alloc alp_ctx.ctxs.");
×
267
    }
×
268
    alp_ctx.ctxs_len = g_alproto_max;
40✔
269
    SCReturnInt(0);
40✔
270
}
40✔
271

272
void AppLayerParserPostStreamSetup(void)
273
{
1,423✔
274
    /* lets set a default value for stream_depth */
275
    for (int flow_proto = 0; flow_proto < FLOW_PROTO_DEFAULT; flow_proto++) {
5,692✔
276
        for (AppProto alproto = 0; alproto < g_alproto_max; alproto++) {
175,029✔
277
            if (!(alp_ctx.ctxs[alproto][flow_proto].internal_flags &
170,760✔
278
                        APP_LAYER_PARSER_INT_STREAM_DEPTH_SET)) {
170,760✔
279
                alp_ctx.ctxs[alproto][flow_proto].stream_depth = stream_config.reassembly_depth;
167,940✔
280
            }
167,940✔
281
        }
170,760✔
282
    }
4,269✔
283
}
1,423✔
284

285
int AppLayerParserDeSetup(void)
286
{
30✔
287
    SCEnter();
30✔
288

289
    SCFree(alp_ctx.ctxs);
30✔
290

291
    FTPParserCleanup();
30✔
292
    SMTPParserCleanup();
30✔
293

294
    SCReturnInt(0);
30✔
295
}
30✔
296

297
AppLayerParserThreadCtx *AppLayerParserThreadCtxAlloc(void)
298
{
13,480✔
299
    SCEnter();
13,480✔
300

301
    AppLayerParserThreadCtx *tctx = SCCalloc(1, sizeof(*tctx));
13,480✔
302
    if (tctx == NULL)
13,480✔
303
        goto end;
×
304

305
    tctx->alproto_local_storage = SCCalloc(g_alproto_max, sizeof(void *[FLOW_PROTO_MAX]));
13,480✔
306
    if (unlikely(tctx->alproto_local_storage == NULL)) {
13,480✔
307
        SCFree(tctx);
×
308
        tctx = NULL;
×
309
        goto end;
×
310
    }
×
311
    for (uint8_t flow_proto = 0; flow_proto < FLOW_PROTO_DEFAULT; flow_proto++) {
53,920✔
312
        for (AppProto alproto = 0; alproto < g_alproto_max; alproto++) {
1,658,040✔
313
            uint8_t ipproto = FlowGetReverseProtoMapping(flow_proto);
1,617,600✔
314

315
            tctx->alproto_local_storage[alproto][flow_proto] =
1,617,600✔
316
                    AppLayerParserGetProtocolParserLocalStorage(ipproto, alproto);
1,617,600✔
317
        }
1,617,600✔
318
    }
40,440✔
319

320
 end:
13,480✔
321
    SCReturnPtr(tctx, "void *");
13,480✔
322
}
13,480✔
323

324
void AppLayerParserThreadCtxFree(AppLayerParserThreadCtx *tctx)
325
{
13,480✔
326
    SCEnter();
13,480✔
327

328
    for (uint8_t flow_proto = 0; flow_proto < FLOW_PROTO_DEFAULT; flow_proto++) {
53,920✔
329
        for (AppProto alproto = 0; alproto < g_alproto_max; alproto++) {
1,658,040✔
330
            uint8_t ipproto = FlowGetReverseProtoMapping(flow_proto);
1,617,600✔
331

332
            AppLayerParserDestroyProtocolParserLocalStorage(
1,617,600✔
333
                    ipproto, alproto, tctx->alproto_local_storage[alproto][flow_proto]);
1,617,600✔
334
        }
1,617,600✔
335
    }
40,440✔
336

337
    SCFree(tctx->alproto_local_storage);
13,480✔
338
    SCFree(tctx);
13,480✔
339
    SCReturn;
13,480✔
340
}
13,480✔
341

342
/** \brief check if a parser is enabled in the config
343
 *  Returns enabled always if: were running unittests
344
 */
345
int SCAppLayerParserConfParserEnabled(const char *ipproto, const char *alproto_name)
346
{
1,574✔
347
    SCEnter();
1,574✔
348

349
    int enabled = 1;
1,574✔
350
    char param[100];
1,574✔
351
    SCConfNode *node;
1,574✔
352
    int r;
1,574✔
353

354
    if (RunmodeIsUnittests())
1,574✔
355
        goto enabled;
89✔
356

357
    r = snprintf(param, sizeof(param), "%s%s%s", "app-layer.protocols.",
1,485✔
358
                 alproto_name, ".enabled");
1,485✔
359
    if (r < 0) {
1,485✔
360
        FatalError("snprintf failure.");
×
361
    } else if (r > (int)sizeof(param)) {
1,485✔
362
        FatalError("buffer not big enough to write param.");
×
363
    }
×
364

365
    node = SCConfGetNode(param);
1,485✔
366
    if (node == NULL) {
1,485✔
367
        SCLogDebug("Entry for %s not found.", param);
1,233✔
368
        r = snprintf(param, sizeof(param), "%s%s%s%s%s", "app-layer.protocols.",
1,233✔
369
                     alproto_name, ".", ipproto, ".enabled");
1,233✔
370
        if (r < 0) {
1,233✔
371
            FatalError("snprintf failure.");
×
372
        } else if (r > (int)sizeof(param)) {
1,233✔
373
            FatalError("buffer not big enough to write param.");
×
374
        }
×
375

376
        node = SCConfGetNode(param);
1,233✔
377
        if (node == NULL) {
1,233✔
378
            SCLogDebug("Entry for %s not found.", param);
1,197✔
379
            goto enabled;
1,197✔
380
        }
1,197✔
381
    }
1,233✔
382

383
    if (SCConfValIsTrue(node->val)) {
288✔
384
        goto enabled;
288✔
385
    } else if (SCConfValIsFalse(node->val)) {
288✔
386
        goto disabled;
×
387
    } else if (strcasecmp(node->val, "detection-only") == 0) {
×
388
        goto disabled;
×
389
    } else {
×
390
        SCLogError("Invalid value found for %s.", param);
×
391
        exit(EXIT_FAILURE);
×
392
    }
×
393

394
 disabled:
×
395
    enabled = 0;
×
396
 enabled:
1,574✔
397
    SCReturnInt(enabled);
1,574✔
398
}
×
399

400
/***** Parser related registration *****/
401

402
int AppLayerParserRegisterParser(uint8_t ipproto, AppProto alproto,
403
                      uint8_t direction,
404
                      AppLayerParserFPtr Parser)
405
{
3,070✔
406
    SCEnter();
3,070✔
407

408
    alp_ctx.ctxs[alproto][FlowGetProtoMapping(ipproto)]
3,070✔
409
            .Parser[(direction & STREAM_TOSERVER) ? 0 : 1] = Parser;
3,070✔
410

411
    SCReturnInt(0);
3,070✔
412
}
3,070✔
413

414
void SCAppLayerParserRegisterParserAcceptableDataDirection(
415
        uint8_t ipproto, AppProto alproto, uint8_t direction)
416
{
222✔
417
    SCEnter();
222✔
418

419
    alp_ctx.ctxs[alproto][FlowGetProtoMapping(ipproto)].first_data_dir |=
222✔
420
            (direction & (STREAM_TOSERVER | STREAM_TOCLIENT));
222✔
421

422
    SCReturn;
222✔
423
}
222✔
424

425
void AppLayerParserRegisterOptionFlags(uint8_t ipproto, AppProto alproto,
426
        uint32_t flags)
427
{
382✔
428
    SCEnter();
382✔
429

430
    alp_ctx.ctxs[alproto][FlowGetProtoMapping(ipproto)].option_flags |= flags;
382✔
431

432
    SCReturn;
382✔
433
}
382✔
434

435
void AppLayerParserRegisterStateFuncs(uint8_t ipproto, AppProto alproto,
436
        void *(*StateAlloc)(void *, AppProto), void (*StateFree)(void *))
437
{
1,535✔
438
    SCEnter();
1,535✔
439

440
    alp_ctx.ctxs[alproto][FlowGetProtoMapping(ipproto)].StateAlloc = StateAlloc;
1,535✔
441
    alp_ctx.ctxs[alproto][FlowGetProtoMapping(ipproto)].StateFree = StateFree;
1,535✔
442

443
    SCReturn;
1,535✔
444
}
1,535✔
445

446
void AppLayerParserRegisterLocalStorageFunc(uint8_t ipproto, AppProto alproto,
447
                                 void *(*LocalStorageAlloc)(void),
448
                                 void (*LocalStorageFree)(void *))
449
{
80✔
450
    SCEnter();
80✔
451

452
    alp_ctx.ctxs[alproto][FlowGetProtoMapping(ipproto)].LocalStorageAlloc = LocalStorageAlloc;
80✔
453
    alp_ctx.ctxs[alproto][FlowGetProtoMapping(ipproto)].LocalStorageFree = LocalStorageFree;
80✔
454

455
    SCReturn;
80✔
456
}
80✔
457

458
void AppLayerParserRegisterGetTxFilesFunc(
459
        uint8_t ipproto, AppProto alproto, AppLayerGetFileState (*GetTxFiles)(void *, uint8_t))
460
{
320✔
461
    SCEnter();
320✔
462

463
    alp_ctx.ctxs[alproto][FlowGetProtoMapping(ipproto)].GetTxFiles = GetTxFiles;
320✔
464

465
    SCReturn;
320✔
466
}
320✔
467

468
void AppLayerParserRegisterLoggerBits(uint8_t ipproto, AppProto alproto, LoggerId bits)
469
{
78,352✔
470
    SCEnter();
78,352✔
471

472
    alp_ctx.ctxs[alproto][FlowGetProtoMapping(ipproto)].logger_bits = bits;
78,352✔
473

474
    SCReturn;
78,352✔
475
}
78,352✔
476

477
void SCAppLayerParserRegisterLogger(uint8_t ipproto, AppProto alproto)
478
{
24,596✔
479
    SCEnter();
24,596✔
480

481
    alp_ctx.ctxs[alproto][FlowGetProtoMapping(ipproto)].logger = true;
24,596✔
482

483
    SCReturn;
24,596✔
484
}
24,596✔
485

486
void AppLayerParserRegisterGetStateProgressFunc(uint8_t ipproto, AppProto alproto,
487
    int (*StateGetProgress)(void *alstate, uint8_t direction))
488
{
1,535✔
489
    SCEnter();
1,535✔
490

491
    alp_ctx.ctxs[alproto][FlowGetProtoMapping(ipproto)].StateGetProgress = StateGetProgress;
1,535✔
492

493
    SCReturn;
1,535✔
494
}
1,535✔
495

496
void AppLayerParserRegisterTxFreeFunc(uint8_t ipproto, AppProto alproto,
497
                           void (*StateTransactionFree)(void *, uint64_t))
498
{
1,535✔
499
    SCEnter();
1,535✔
500

501
    alp_ctx.ctxs[alproto][FlowGetProtoMapping(ipproto)].StateTransactionFree = StateTransactionFree;
1,535✔
502

503
    SCReturn;
1,535✔
504
}
1,535✔
505

506
void AppLayerParserRegisterGetTxCnt(uint8_t ipproto, AppProto alproto,
507
                         uint64_t (*StateGetTxCnt)(void *alstate))
508
{
1,535✔
509
    SCEnter();
1,535✔
510

511
    alp_ctx.ctxs[alproto][FlowGetProtoMapping(ipproto)].StateGetTxCnt = StateGetTxCnt;
1,535✔
512

513
    SCReturn;
1,535✔
514
}
1,535✔
515

516
void AppLayerParserRegisterGetTx(uint8_t ipproto, AppProto alproto,
517
                      void *(StateGetTx)(void *alstate, uint64_t tx_id))
518
{
1,535✔
519
    SCEnter();
1,535✔
520

521
    alp_ctx.ctxs[alproto][FlowGetProtoMapping(ipproto)].StateGetTx = StateGetTx;
1,535✔
522

523
    SCReturn;
1,535✔
524
}
1,535✔
525

526
void AppLayerParserRegisterGetTxIterator(uint8_t ipproto, AppProto alproto,
527
                      AppLayerGetTxIteratorFunc Func)
528
{
1,375✔
529
    SCEnter();
1,375✔
530
    alp_ctx.ctxs[alproto][FlowGetProtoMapping(ipproto)].StateGetTxIterator = Func;
1,375✔
531
    SCReturn;
1,375✔
532
}
1,375✔
533

534
void AppLayerParserRegisterStateProgressCompletionStatus(
535
        AppProto alproto, const int ts, const int tc)
536
{
1,535✔
537
    BUG_ON(ts == 0);
1,535✔
538
    BUG_ON(tc == 0);
1,535✔
539
    BUG_ON(!AppProtoIsValid(alproto));
1,535✔
540
    BUG_ON(alp_ctx.ctxs[alproto][FLOW_PROTO_DEFAULT].complete_ts != 0 &&
1,535✔
541
            alp_ctx.ctxs[alproto][FLOW_PROTO_DEFAULT].complete_ts != ts);
1,535✔
542
    BUG_ON(alp_ctx.ctxs[alproto][FLOW_PROTO_DEFAULT].complete_tc != 0 &&
1,535✔
543
            alp_ctx.ctxs[alproto][FLOW_PROTO_DEFAULT].complete_tc != tc);
1,535✔
544

545
    alp_ctx.ctxs[alproto][FLOW_PROTO_DEFAULT].complete_ts = ts;
1,535✔
546
    alp_ctx.ctxs[alproto][FLOW_PROTO_DEFAULT].complete_tc = tc;
1,535✔
547
}
1,535✔
548

549
void AppLayerParserRegisterGetEventInfoById(uint8_t ipproto, AppProto alproto,
550
        int (*StateGetEventInfoById)(
551
                uint8_t event_id, const char **event_name, AppLayerEventType *event_type))
552
{
1,335✔
553
    SCEnter();
1,335✔
554

555
    alp_ctx.ctxs[alproto][FlowGetProtoMapping(ipproto)].StateGetEventInfoById =
1,335✔
556
            StateGetEventInfoById;
1,335✔
557

558
    SCReturn;
1,335✔
559
}
1,335✔
560

561
void AppLayerParserRegisterGetStateFuncs(uint8_t ipproto, AppProto alproto,
562
        AppLayerParserGetStateIdByNameFn GetIdByNameFunc,
563
        AppLayerParserGetStateNameByIdFn GetNameByIdFunc)
564
{
120✔
565
    SCEnter();
120✔
566
    alp_ctx.ctxs[alproto][FlowGetProtoMapping(ipproto)].GetStateIdByName = GetIdByNameFunc;
120✔
567
    alp_ctx.ctxs[alproto][FlowGetProtoMapping(ipproto)].GetStateNameById = GetNameByIdFunc;
120✔
568
    SCReturn;
120✔
569
}
120✔
570

571
void AppLayerParserRegisterGetFrameFuncs(uint8_t ipproto, AppProto alproto,
572
        AppLayerParserGetFrameIdByNameFn GetIdByNameFunc,
573
        AppLayerParserGetFrameNameByIdFn GetNameByIdFunc)
574
{
902✔
575
    SCEnter();
902✔
576
    alp_ctx.ctxs[alproto][FlowGetProtoMapping(ipproto)].GetFrameIdByName = GetIdByNameFunc;
902✔
577
    alp_ctx.ctxs[alproto][FlowGetProtoMapping(ipproto)].GetFrameNameById = GetNameByIdFunc;
902✔
578
    SCReturn;
902✔
579
}
902✔
580

581
void AppLayerParserRegisterGetEventInfo(uint8_t ipproto, AppProto alproto,
582
        int (*StateGetEventInfo)(
583
                const char *event_name, uint8_t *event_id, AppLayerEventType *event_type))
584
{
1,375✔
585
    SCEnter();
1,375✔
586

587
    alp_ctx.ctxs[alproto][FlowGetProtoMapping(ipproto)].StateGetEventInfo = StateGetEventInfo;
1,375✔
588

589
    SCReturn;
1,375✔
590
}
1,375✔
591

592
void AppLayerParserRegisterTxDataFunc(uint8_t ipproto, AppProto alproto,
593
        AppLayerTxData *(*GetTxData)(void *tx))
594
{
1,535✔
595
    SCEnter();
1,535✔
596

597
    alp_ctx.ctxs[alproto][FlowGetProtoMapping(ipproto)].GetTxData = GetTxData;
1,535✔
598

599
    SCReturn;
1,535✔
600
}
1,535✔
601

602
void AppLayerParserRegisterStateDataFunc(
603
        uint8_t ipproto, AppProto alproto, AppLayerStateData *(*GetStateData)(void *state))
604
{
1,535✔
605
    SCEnter();
1,535✔
606

607
    alp_ctx.ctxs[alproto][FlowGetProtoMapping(ipproto)].GetStateData = GetStateData;
1,535✔
608

609
    SCReturn;
1,535✔
610
}
1,535✔
611

612
void AppLayerParserRegisterApplyTxConfigFunc(uint8_t ipproto, AppProto alproto,
613
        void (*ApplyTxConfig)(void *state, void *tx, int mode, AppLayerTxConfig))
614
{
80✔
615
    SCEnter();
80✔
616

617
    alp_ctx.ctxs[alproto][FlowGetProtoMapping(ipproto)].ApplyTxConfig = ApplyTxConfig;
80✔
618

619
    SCReturn;
80✔
620
}
80✔
621

622
void AppLayerParserRegisterSetStreamDepthFlag(uint8_t ipproto, AppProto alproto,
623
        void (*SetStreamDepthFlag)(void *tx, uint8_t flags))
624
{
40✔
625
    SCEnter();
40✔
626

627
    alp_ctx.ctxs[alproto][FlowGetProtoMapping(ipproto)].SetStreamDepthFlag = SetStreamDepthFlag;
40✔
628

629
    SCReturn;
40✔
630
}
40✔
631

632
/***** Get and transaction functions *****/
633

634
void *AppLayerParserGetProtocolParserLocalStorage(uint8_t ipproto, AppProto alproto)
635
{
1,617,600✔
636
    SCEnter();
1,617,600✔
637
    void * r = NULL;
1,617,600✔
638

639
    if (alp_ctx.ctxs[alproto][FlowGetProtoMapping(ipproto)].LocalStorageAlloc != NULL) {
1,617,600✔
640
        r = alp_ctx.ctxs[alproto][FlowGetProtoMapping(ipproto)].LocalStorageAlloc();
26,960✔
641
    }
26,960✔
642

643
    SCReturnPtr(r, "void *");
1,617,600✔
644
}
1,617,600✔
645

646
void AppLayerParserDestroyProtocolParserLocalStorage(uint8_t ipproto, AppProto alproto,
647
                                          void *local_data)
648
{
1,617,600✔
649
    SCEnter();
1,617,600✔
650

651
    if (alp_ctx.ctxs[alproto][FlowGetProtoMapping(ipproto)].LocalStorageFree != NULL) {
1,617,600✔
652
        alp_ctx.ctxs[alproto][FlowGetProtoMapping(ipproto)].LocalStorageFree(local_data);
26,960✔
653
    }
26,960✔
654

655
    SCReturn;
1,617,600✔
656
}
1,617,600✔
657

658
/** \brief default tx iterator
659
 *
660
 *  Used if the app layer parser doesn't register its own iterator.
661
 *  Simply walks the tx_id space until it finds a tx. Uses 'state' to
662
 *  keep track of where it left off.
663
 *
664
 *  \retval txptr or NULL if no more txs in list
665
 */
666
static AppLayerGetTxIterTuple AppLayerDefaultGetTxIterator(
667
        const uint8_t ipproto, const AppProto alproto,
668
        void *alstate, uint64_t min_tx_id, uint64_t max_tx_id,
669
        AppLayerGetTxIterState *state)
670
{
73,665✔
671
    uint64_t ustate = *(uint64_t *)state;
73,665✔
672
    uint64_t tx_id = MAX(min_tx_id, ustate);
73,665✔
673
    for ( ; tx_id < max_tx_id; tx_id++) {
73,688✔
674
        void *tx_ptr = AppLayerParserGetTx(ipproto, alproto, alstate, tx_id);
57,662✔
675
        if (tx_ptr != NULL) {
57,662✔
676
            ustate = tx_id + 1;
57,639✔
677
            *state = *(AppLayerGetTxIterState *)&ustate;
57,639✔
678
            AppLayerGetTxIterTuple tuple = {
57,639✔
679
                .tx_ptr = tx_ptr,
57,639✔
680
                .tx_id = tx_id,
57,639✔
681
                .has_next = (tx_id + 1 < max_tx_id),
57,639✔
682
            };
57,639✔
683
            SCLogDebug("tuple: %p/%"PRIu64"/%s", tuple.tx_ptr, tuple.tx_id,
57,639✔
684
                    tuple.has_next ? "true" : "false");
57,639✔
685
            return tuple;
57,639✔
686
        }
57,639✔
687
    }
57,662✔
688

689
    AppLayerGetTxIterTuple no_tuple = { NULL, 0, false };
16,026✔
690
    return no_tuple;
16,026✔
691
}
73,665✔
692

693
AppLayerGetTxIteratorFunc AppLayerGetTxIterator(const uint8_t ipproto,
694
        const AppProto alproto)
695
{
340,993✔
696
    AppLayerGetTxIteratorFunc Func =
340,993✔
697
            alp_ctx.ctxs[alproto][FlowGetProtoMapping(ipproto)].StateGetTxIterator;
340,993✔
698
    return Func ? Func : AppLayerDefaultGetTxIterator;
340,993✔
699
}
340,993✔
700

701
uint64_t AppLayerParserGetTransactionLogId(AppLayerParserState *pstate)
702
{
85,887✔
703
    SCEnter();
85,887✔
704

705
    SCReturnCT((pstate == NULL) ? 0 : pstate->log_id, "uint64_t");
85,887✔
706
}
85,887✔
707

708
uint64_t AppLayerParserGetMinId(AppLayerParserState *pstate)
709
{
×
710
    SCEnter();
×
711

712
    SCReturnCT((pstate == NULL) ? 0 : pstate->min_id, "uint64_t");
×
713
}
×
714

715
void AppLayerParserSetTransactionLogId(AppLayerParserState *pstate, uint64_t tx_id)
716
{
17,964✔
717
    SCEnter();
17,964✔
718

719
    if (pstate != NULL)
17,964✔
720
        pstate->log_id = tx_id;
17,964✔
721

722
    SCReturn;
17,964✔
723
}
17,964✔
724

725
uint64_t AppLayerParserGetTransactionInspectId(AppLayerParserState *pstate, uint8_t direction)
726
{
173,988✔
727
    SCEnter();
173,988✔
728

729
    if (pstate != NULL)
173,988✔
730
        SCReturnCT(pstate->inspect_id[(direction & STREAM_TOSERVER) ? 0 : 1], "uint64_t");
174,005✔
731

732
    DEBUG_VALIDATE_BUG_ON(1);
2,147,483,647✔
733
    SCReturnCT(0ULL, "uint64_t");
2,147,483,647✔
734
}
173,988✔
735

736
inline uint8_t AppLayerParserGetTxDetectProgress(AppLayerTxData *txd, const uint8_t dir)
737
{
×
738
    uint8_t p = (dir & STREAM_TOSERVER) ? txd->detect_progress_ts : txd->detect_progress_tc;
×
739
    return p;
×
740
}
×
741

742
static inline uint32_t GetTxLogged(AppLayerTxData *txd)
743
{
13,858✔
744
    return txd->logged;
13,858✔
745
}
13,858✔
746

747
void SCAppLayerTxDataCleanup(AppLayerTxData *txd)
748
{
31,811✔
749
    if (txd->de_state) {
31,811✔
750
        SCDetectEngineStateFree(txd->de_state);
109✔
751
    }
109✔
752
    if (txd->events) {
31,811✔
753
        SCAppLayerDecoderEventsFreeEvents(&txd->events);
669✔
754
    }
669✔
755
    if (txd->txbits) {
31,811✔
756
        SCGenericVarFree(txd->txbits);
×
757
    }
×
758
}
31,811✔
759

760
void AppLayerParserSetTransactionInspectId(const Flow *f, AppLayerParserState *pstate,
761
                                           void *alstate, const uint8_t flags,
762
                                           bool tag_txs_as_inspected)
763
{
86,426✔
764
    SCEnter();
86,426✔
765

766
    const int direction = (flags & STREAM_TOSERVER) ? 0 : 1;
86,426✔
767
    const uint64_t total_txs = AppLayerParserGetTxCnt(f, alstate);
86,426✔
768
    uint64_t idx = AppLayerParserGetTransactionInspectId(pstate, flags);
86,426✔
769
    const int state_done_progress = AppLayerParserGetStateProgressCompletionStatus(f->alproto, flags);
86,426✔
770
    const uint8_t ipproto = f->proto;
86,426✔
771
    const AppProto alproto = f->alproto;
86,426✔
772

773
    AppLayerGetTxIteratorFunc IterFunc = AppLayerGetTxIterator(ipproto, alproto);
86,426✔
774
    AppLayerGetTxIterState state = { 0 };
86,426✔
775

776
    SCLogDebug("called: %s, tag_txs_as_inspected %s",direction==0?"toserver":"toclient",
86,426✔
777
            tag_txs_as_inspected?"true":"false");
86,426✔
778

779
    /* mark all txs as inspected if the applayer progress is
780
     * at the 'end state'. */
781
    while (1) {
95,645✔
782
        AppLayerGetTxIterTuple ires = IterFunc(ipproto, alproto, alstate, idx, total_txs, &state);
95,645✔
783
        if (ires.tx_ptr == NULL)
95,645✔
784
            break;
20,332✔
785

786
        void *tx = ires.tx_ptr;
75,313✔
787
        idx = ires.tx_id;
75,313✔
788

789
        int state_progress = AppLayerParserGetStateProgress(ipproto, alproto, tx, flags);
75,313✔
790
        if (state_progress < state_done_progress)
75,313✔
791
            break;
46,693✔
792

793
        AppLayerTxData *txd = AppLayerParserGetTxData(ipproto, alproto, tx);
28,620✔
794
        if (tag_txs_as_inspected) {
28,620✔
795
            const uint8_t inspected_flag = (flags & STREAM_TOSERVER) ? APP_LAYER_TX_INSPECTED_TS
×
796
                                                                     : APP_LAYER_TX_INSPECTED_TC;
×
797
            if (txd->flags & inspected_flag) {
×
798
                txd->flags |= inspected_flag;
×
799
                SCLogDebug("%p/%" PRIu64 " in-order tx is done for direction %s. Flags %02x", tx,
×
800
                        idx, flags & STREAM_TOSERVER ? "toserver" : "toclient", txd->flags);
×
801
            }
×
802
        }
×
803
        idx++;
28,620✔
804
        if (!ires.has_next)
28,620✔
805
            break;
19,557✔
806
    }
28,620✔
807
    pstate->inspect_id[direction] = idx;
86,426✔
808
    SCLogDebug("inspect_id now %"PRIu64, pstate->inspect_id[direction]);
86,426✔
809

810
    /* if necessary we flag all txs that are complete as 'inspected'
811
     * also move inspect_id forward. */
812
    if (tag_txs_as_inspected) {
86,426✔
813
        /* continue at idx */
814
        while (1) {
×
815
            AppLayerGetTxIterTuple ires = IterFunc(ipproto, alproto, alstate, idx, total_txs, &state);
×
816
            if (ires.tx_ptr == NULL)
×
817
                break;
×
818

819
            void *tx = ires.tx_ptr;
×
820
            /* if we got a higher id than the minimum we requested, we
821
             * skipped a bunch of 'null-txs'. Lets see if we can up the
822
             * inspect tracker */
823
            if (ires.tx_id > idx && pstate->inspect_id[direction] == idx) {
×
824
                pstate->inspect_id[direction] = ires.tx_id;
×
825
            }
×
826
            idx = ires.tx_id;
×
827

828
            const int state_progress = AppLayerParserGetStateProgress(ipproto, alproto, tx, flags);
×
829
            if (state_progress < state_done_progress)
×
830
                break;
×
831

832
            /* txd can be NULL for HTTP sessions where the user data alloc failed */
833
            AppLayerTxData *txd = AppLayerParserGetTxData(ipproto, alproto, tx);
×
834
            const uint8_t inspected_flag = (flags & STREAM_TOSERVER) ? APP_LAYER_TX_INSPECTED_TS
×
835
                                                                     : APP_LAYER_TX_INSPECTED_TC;
×
836
            if (txd->flags & inspected_flag) {
×
837
                txd->flags |= inspected_flag;
×
838
                SCLogDebug("%p/%" PRIu64 " out of order tx is done for direction %s. Flag %02x", tx,
×
839
                        idx, flags & STREAM_TOSERVER ? "toserver" : "toclient", txd->flags);
×
840

841
                SCLogDebug("%p/%" PRIu64 " out of order tx. Update inspect_id? %" PRIu64, tx, idx,
×
842
                        pstate->inspect_id[direction]);
×
843
                if (pstate->inspect_id[direction] + 1 == idx)
×
844
                    pstate->inspect_id[direction] = idx;
×
845
            }
×
846
            if (!ires.has_next)
×
847
                break;
×
848
            idx++;
×
849
        }
×
850
    }
×
851

852
    SCReturn;
86,426✔
853
}
86,426✔
854

855
AppLayerDecoderEvents *AppLayerParserGetDecoderEvents(AppLayerParserState *pstate)
856
{
1,294,878✔
857
    SCEnter();
1,294,878✔
858

859
    SCReturnPtr(pstate->decoder_events,
1,294,878✔
860
                "AppLayerDecoderEvents *");
1,294,878✔
861
}
1,294,878✔
862

863
AppLayerDecoderEvents *AppLayerParserGetEventsByTx(uint8_t ipproto, AppProto alproto,
864
                                        void *tx)
865
{
132,212✔
866
    SCEnter();
132,212✔
867

868
    AppLayerDecoderEvents *ptr = NULL;
132,212✔
869

870
    /* Access events via the tx_data. */
871
    AppLayerTxData *txd = AppLayerParserGetTxData(ipproto, alproto, tx);
132,212✔
872
    if (txd->events != NULL) {
132,212✔
873
        ptr = txd->events;
25,012✔
874
    }
25,012✔
875

876
    SCReturnPtr(ptr, "AppLayerDecoderEvents *");
132,212✔
877
}
132,212✔
878

879
AppLayerGetFileState AppLayerParserGetTxFiles(const Flow *f, void *tx, const uint8_t direction)
880
{
80,700✔
881
    SCEnter();
80,700✔
882

883
    if (alp_ctx.ctxs[f->alproto][f->protomap].GetTxFiles != NULL) {
80,700✔
884
        return alp_ctx.ctxs[f->alproto][f->protomap].GetTxFiles(tx, direction);
80,677✔
885
    }
80,677✔
886

887
    AppLayerGetFileState files = { .fc = NULL, .cfg = NULL };
23✔
888
    return files;
23✔
889
}
80,700✔
890

891
static void AppLayerParserFileTxHousekeeping(
892
        const Flow *f, void *tx, const uint8_t pkt_dir, const bool trunc)
893
{
18,573✔
894
    AppLayerGetFileState files = AppLayerParserGetTxFiles(f, tx, pkt_dir);
18,573✔
895
    if (files.fc) {
18,573✔
896
        FilesPrune(files.fc, files.cfg, trunc);
18,573✔
897
    }
18,573✔
898
}
18,573✔
899

900
#define IS_DISRUPTED(flags) ((flags) & (STREAM_DEPTH | STREAM_GAP))
200,147,725✔
901

902
extern int g_detect_disabled;
903
extern bool g_file_logger_enabled;
904
extern bool g_filedata_logger_enabled;
905

906
/**
907
 * \brief remove obsolete (inspected and logged) transactions
908
 */
909
void AppLayerParserTransactionsCleanup(Flow *f, const uint8_t pkt_dir)
910
{
83,667✔
911
    SCEnter();
83,667✔
912
    DEBUG_ASSERT_FLOW_LOCKED(f);
83,667✔
913

914
    AppLayerParserProtoCtx *p = &alp_ctx.ctxs[f->alproto][f->protomap];
83,667✔
915
    if (unlikely(p->StateTransactionFree == NULL))
83,667✔
916
        SCReturn;
1,421✔
917

918
    const bool has_tx_detect_flags = !g_detect_disabled;
82,246✔
919
    const uint8_t ipproto = f->proto;
82,246✔
920
    const AppProto alproto = f->alproto;
82,246✔
921
    void * const alstate = f->alstate;
82,246✔
922
    AppLayerParserState * const alparser = f->alparser;
82,246✔
923

924
    if (alstate == NULL || alparser == NULL)
82,259✔
925
        SCReturn;
×
926

927
    const uint64_t min = alparser->min_id;
82,246✔
928
    const uint64_t total_txs = AppLayerParserGetTxCnt(f, alstate);
82,246✔
929
    const LoggerId logger_expectation = AppLayerParserProtocolGetLoggerBits(ipproto, alproto);
82,246✔
930
    const int tx_end_state_ts = AppLayerParserGetStateProgressCompletionStatus(alproto, STREAM_TOSERVER);
82,246✔
931
    const int tx_end_state_tc = AppLayerParserGetStateProgressCompletionStatus(alproto, STREAM_TOCLIENT);
82,246✔
932
    const uint8_t ts_disrupt_flags = FlowGetDisruptionFlags(f, STREAM_TOSERVER);
82,246✔
933
    const uint8_t tc_disrupt_flags = FlowGetDisruptionFlags(f, STREAM_TOCLIENT);
82,246✔
934

935
    int pkt_dir_trunc = -1;
82,246✔
936

937
    AppLayerGetTxIteratorFunc IterFunc = AppLayerGetTxIterator(ipproto, alproto);
82,246✔
938
    AppLayerGetTxIterState state;
82,246✔
939
    memset(&state, 0, sizeof(state));
82,246✔
940
    uint64_t i = min;
82,246✔
941
    uint64_t new_min = min;
82,246✔
942
    SCLogDebug("start min %"PRIu64, min);
82,246✔
943
    bool skipped = false;
82,246✔
944
    // const bool support_files = AppLayerParserSupportsFiles(f->proto, f->alproto);
945

946
    while (1) {
50,172,252✔
947
        AppLayerGetTxIterTuple ires = IterFunc(ipproto, alproto, alstate, i, total_txs, &state);
50,172,252✔
948
        if (ires.tx_ptr == NULL)
50,172,252✔
949
            break;
24,261✔
950

951
        bool tx_skipped = false;
50,172,252✔
952
        void *tx = ires.tx_ptr;
50,147,991✔
953
        i = ires.tx_id; // actual tx id for the tx the IterFunc returned
50,147,991✔
954

955
        SCLogDebug("%p/%"PRIu64" checking", tx, i);
50,147,991✔
956
        AppLayerTxData *txd = AppLayerParserGetTxData(ipproto, alproto, tx);
50,147,991✔
957
        if (AppLayerParserHasFilesInDir(txd, pkt_dir)) {
50,147,991✔
958
            if (pkt_dir_trunc == -1)
18,571✔
959
                pkt_dir_trunc = IS_DISRUPTED(
18,225✔
960
                        (pkt_dir == STREAM_TOSERVER) ? ts_disrupt_flags : tc_disrupt_flags);
18,571✔
961
            AppLayerParserFileTxHousekeeping(f, tx, pkt_dir, (bool)pkt_dir_trunc);
18,571✔
962
        }
18,571✔
963
        // should be reset by parser next time it updates the tx
964
        if (pkt_dir & STREAM_TOSERVER) {
50,147,991✔
965
            txd->updated_ts = false;
50,074,682✔
966
        } else {
50,074,698✔
967
            txd->updated_tc = false;
73,309✔
968
        }
73,309✔
969
        const int tx_progress_tc =
50,147,991✔
970
                AppLayerParserGetStateProgress(ipproto, alproto, tx, tc_disrupt_flags);
50,147,991✔
971
        if (tx_progress_tc < tx_end_state_tc) {
50,147,991✔
972
            SCLogDebug("%p/%"PRIu64" skipping: tc parser not done", tx, i);
99,105✔
973
            skipped = true;
99,105✔
974
            goto next;
99,105✔
975
        }
99,105✔
976
        const int tx_progress_ts =
50,048,886✔
977
                AppLayerParserGetStateProgress(ipproto, alproto, tx, ts_disrupt_flags);
50,048,886✔
978
        if (tx_progress_ts < tx_end_state_ts) {
50,048,886✔
979
            SCLogDebug("%p/%"PRIu64" skipping: ts parser not done", tx, i);
16,541✔
980
            skipped = true;
16,541✔
981
            goto next;
16,541✔
982
        }
16,541✔
983

984
        if (has_tx_detect_flags) {
50,032,375✔
985
            if (!IS_DISRUPTED(ts_disrupt_flags) &&
50,032,375✔
986
                    (f->sgh_toserver != NULL || (f->flags & FLOW_SGH_TOSERVER) == 0)) {
50,032,375✔
987
                if ((txd->flags & (APP_LAYER_TX_INSPECTED_TS | APP_LAYER_TX_SKIP_INSPECT_TS)) ==
50,032,339✔
988
                        0) {
50,032,339✔
989
                    SCLogDebug("%p/%" PRIu64 " skipping: TS inspect not done: ts:%02x", tx, i,
646✔
990
                            txd->flags);
646✔
991
                    tx_skipped = true;
646✔
992
                }
646✔
993
            }
50,032,339✔
994
            if (!IS_DISRUPTED(tc_disrupt_flags) &&
50,032,375✔
995
                    (f->sgh_toclient != NULL || (f->flags & FLOW_SGH_TOCLIENT) == 0)) {
50,032,375✔
996
                if ((txd->flags & (APP_LAYER_TX_INSPECTED_TC | APP_LAYER_TX_SKIP_INSPECT_TC)) ==
50,032,327✔
997
                        0) {
50,032,327✔
998
                    SCLogDebug("%p/%" PRIu64 " skipping: TC inspect not done: ts:%02x", tx, i,
50,017,844✔
999
                            txd->flags);
50,017,844✔
1000
                    tx_skipped = true;
50,017,844✔
1001
                }
50,017,844✔
1002
            }
50,032,327✔
1003
        }
50,032,375✔
1004

1005
        if (tx_skipped) {
50,032,345✔
1006
            SCLogDebug("%p/%" PRIu64 " tx_skipped", tx, i);
50,018,490✔
1007
            skipped = true;
50,018,490✔
1008
            goto next;
50,018,490✔
1009
        }
50,018,490✔
1010

1011
        if (logger_expectation != 0) {
13,881✔
1012
            LoggerId tx_logged = GetTxLogged(txd);
13,858✔
1013
            if (tx_logged != logger_expectation) {
13,858✔
1014
                SCLogDebug("%p/%"PRIu64" skipping: logging not done: want:%"PRIx32", have:%"PRIx32,
×
1015
                        tx, i, logger_expectation, tx_logged);
×
1016
                skipped = true;
×
1017
                goto next;
×
1018
            }
×
1019
        }
13,858✔
1020

1021
        /* if file logging is enabled, we keep a tx active while some of the files aren't
1022
         * logged yet. */
1023
        SCLogDebug("files_opened %u files_logged %u files_stored %u", txd->files_opened,
13,855✔
1024
                txd->files_logged, txd->files_stored);
13,855✔
1025

1026
        if (txd->files_opened) {
13,855✔
1027
            if (g_file_logger_enabled && txd->files_opened != txd->files_logged) {
2,251✔
1028
                skipped = true;
11✔
1029
                goto next;
11✔
1030
            }
11✔
1031
            if (g_filedata_logger_enabled && txd->files_opened != txd->files_stored) {
2,240✔
1032
                skipped = true;
×
1033
                goto next;
×
1034
            }
×
1035
        }
2,240✔
1036

1037
        /* if we are here, the tx can be freed. */
1038
        p->StateTransactionFree(alstate, i);
13,844✔
1039
        SCLogDebug("%p/%"PRIu64" freed", tx, i);
13,844✔
1040

1041
        /* if we didn't skip any tx so far, up the minimum */
1042
        SCLogDebug("skipped? %s i %"PRIu64", new_min %"PRIu64, skipped ? "true" : "false", i, new_min);
13,844✔
1043
        if (!skipped)
13,844✔
1044
            new_min = i + 1;
9,466✔
1045
        SCLogDebug("final i %"PRIu64", new_min %"PRIu64, i, new_min);
13,844✔
1046

1047
next:
50,147,993✔
1048
        if (!ires.has_next) {
50,147,993✔
1049
            /* this was the last tx. See if we skipped any. If not
1050
             * we removed all and can update the minimum to the max
1051
             * id. */
1052
            SCLogDebug("no next: cur tx i %"PRIu64", total %"PRIu64, i, total_txs);
58,017✔
1053
            if (!skipped) {
58,017✔
1054
                new_min = total_txs;
4,416✔
1055
                SCLogDebug("no next: cur tx i %"PRIu64", total %"PRIu64": "
4,416✔
1056
                        "new_min updated to %"PRIu64, i, total_txs, new_min);
4,416✔
1057
            }
4,416✔
1058
            break;
58,017✔
1059
        }
58,017✔
1060
        i++;
50,089,976✔
1061
    }
50,089,976✔
1062

1063
    /* see if we need to bring all trackers up to date. */
1064
    SCLogDebug("update f->alparser->min_id? %"PRIu64" vs %"PRIu64, new_min, alparser->min_id);
82,248✔
1065
    if (new_min > alparser->min_id) {
82,248✔
1066
        const uint64_t next_id = new_min;
9,257✔
1067
        alparser->min_id = next_id;
9,257✔
1068
        alparser->inspect_id[0] = MAX(alparser->inspect_id[0], next_id);
9,257✔
1069
        alparser->inspect_id[1] = MAX(alparser->inspect_id[1], next_id);
9,257✔
1070
        alparser->log_id = MAX(alparser->log_id, next_id);
9,257✔
1071
        SCLogDebug("updated f->alparser->min_id %"PRIu64, alparser->min_id);
9,257✔
1072
    }
9,257✔
1073
    SCReturn;
82,248✔
1074
}
82,246✔
1075

1076
static inline int StateGetProgressCompletionStatus(const AppProto alproto, const uint8_t flags)
1077
{
581,893✔
1078
    if (flags & STREAM_TOSERVER) {
581,893✔
1079
        return alp_ctx.ctxs[alproto][FLOW_PROTO_DEFAULT].complete_ts;
304,679✔
1080
    } else if (flags & STREAM_TOCLIENT) {
304,679✔
1081
        return alp_ctx.ctxs[alproto][FLOW_PROTO_DEFAULT].complete_tc;
277,657✔
1082
    } else {
2,147,485,970✔
1083
        DEBUG_VALIDATE_BUG_ON(1);
2,147,483,647✔
1084
        return 0;
2,147,483,647✔
1085
    }
2,147,483,647✔
1086
}
581,893✔
1087

1088
/**
1089
 *  \brief get the progress value for a tx/protocol
1090
 *
1091
 *  If the stream is disrupted, we return the 'completion' value.
1092
 */
1093
int AppLayerParserGetStateProgress(uint8_t ipproto, AppProto alproto,
1094
                        void *alstate, uint8_t flags)
1095
{
104,428,499✔
1096
    SCEnter();
104,428,499✔
1097
    int r;
104,428,499✔
1098
    if (unlikely(IS_DISRUPTED(flags))) {
104,428,499✔
1099
        r = StateGetProgressCompletionStatus(alproto, flags);
312✔
1100
    } else {
104,428,187✔
1101
        uint8_t direction = flags & (STREAM_TOCLIENT | STREAM_TOSERVER);
104,428,187✔
1102
        r = alp_ctx.ctxs[alproto][FlowGetProtoMapping(ipproto)].StateGetProgress(
104,428,187✔
1103
                alstate, direction);
104,428,187✔
1104
    }
104,428,187✔
1105
    SCReturnInt(r);
104,428,499✔
1106
}
104,428,499✔
1107

1108
uint64_t AppLayerParserGetTxCnt(const Flow *f, void *alstate)
1109
{
549,359✔
1110
    SCEnter();
549,359✔
1111
    uint64_t r = alp_ctx.ctxs[f->alproto][f->protomap].StateGetTxCnt(alstate);
549,359✔
1112
    SCReturnCT(r, "uint64_t");
549,359✔
1113
}
549,359✔
1114

1115
void *AppLayerParserGetTx(uint8_t ipproto, AppProto alproto, void *alstate, uint64_t tx_id)
1116
{
60,576✔
1117
    SCEnter();
60,576✔
1118
    void *r = alp_ctx.ctxs[alproto][FlowGetProtoMapping(ipproto)].StateGetTx(alstate, tx_id);
60,576✔
1119
    SCReturnPtr(r, "void *");
60,576✔
1120
}
60,576✔
1121

1122
int AppLayerParserGetStateProgressCompletionStatus(AppProto alproto,
1123
                                                   uint8_t direction)
1124
{
581,683✔
1125
    SCEnter();
581,683✔
1126
    int r = StateGetProgressCompletionStatus(alproto, direction);
581,683✔
1127
    SCReturnInt(r);
581,683✔
1128
}
581,683✔
1129

1130
int AppLayerParserGetEventInfo(uint8_t ipproto, AppProto alproto, const char *event_name,
1131
        uint8_t *event_id, AppLayerEventType *event_type)
1132
{
19✔
1133
    SCEnter();
19✔
1134
    const int ipproto_map = FlowGetProtoMapping(ipproto);
19✔
1135
    int r = (alp_ctx.ctxs[alproto][ipproto_map].StateGetEventInfo == NULL)
19✔
1136
                    ? -1
19✔
1137
                    : alp_ctx.ctxs[alproto][ipproto_map].StateGetEventInfo(
19✔
1138
                              event_name, event_id, event_type);
19✔
1139
    SCReturnInt(r);
19✔
1140
}
19✔
1141

1142
int AppLayerParserGetEventInfoById(uint8_t ipproto, AppProto alproto, uint8_t event_id,
1143
        const char **event_name, AppLayerEventType *event_type)
1144
{
831✔
1145
    SCEnter();
831✔
1146
    const int ipproto_map = FlowGetProtoMapping(ipproto);
831✔
1147
    *event_name = (const char *)NULL;
831✔
1148
    int r = (alp_ctx.ctxs[alproto][ipproto_map].StateGetEventInfoById == NULL)
831✔
1149
                    ? -1
831✔
1150
                    : alp_ctx.ctxs[alproto][ipproto_map].StateGetEventInfoById(
831✔
1151
                              event_id, event_name, event_type);
831✔
1152
    SCReturnInt(r);
831✔
1153
}
831✔
1154

1155
uint8_t AppLayerParserGetFirstDataDir(uint8_t ipproto, AppProto alproto)
1156
{
2,543✔
1157
    SCEnter();
2,543✔
1158
    uint8_t r = alp_ctx.ctxs[alproto][FlowGetProtoMapping(ipproto)].first_data_dir;
2,543✔
1159
    SCReturnCT(r, "uint8_t");
2,543✔
1160
}
2,543✔
1161

1162
uint64_t AppLayerParserGetTransactionActive(const Flow *f,
1163
        AppLayerParserState *pstate, uint8_t direction)
1164
{
6,464✔
1165
    SCEnter();
6,464✔
1166

1167
    uint64_t active_id;
6,464✔
1168
    uint64_t log_id = pstate->log_id;
6,464✔
1169
    uint64_t inspect_id = pstate->inspect_id[(direction & STREAM_TOSERVER) ? 0 : 1];
6,464✔
1170
    if (alp_ctx.ctxs[f->alproto][f->protomap].logger) {
6,464✔
1171
        active_id = MIN(log_id, inspect_id);
6,460✔
1172
    } else {
6,460✔
1173
        active_id = inspect_id;
4✔
1174
    }
4✔
1175

1176
    SCReturnCT(active_id, "uint64_t");
6,464✔
1177
}
6,464✔
1178

1179
bool AppLayerParserSupportsFiles(uint8_t ipproto, AppProto alproto)
1180
{
214,030✔
1181
    // Custom case for only signature-only protocol so far
1182
    if (alproto == ALPROTO_HTTP) {
214,030✔
1183
        return AppLayerParserSupportsFiles(ipproto, ALPROTO_HTTP1) ||
7,842✔
1184
               AppLayerParserSupportsFiles(ipproto, ALPROTO_HTTP2);
7,842✔
1185
    }
7,842✔
1186
    return alp_ctx.ctxs[alproto][FlowGetProtoMapping(ipproto)].GetTxFiles != NULL;
206,188✔
1187
}
214,030✔
1188

1189
AppLayerTxData *AppLayerParserGetTxData(uint8_t ipproto, AppProto alproto, void *tx)
1190
{
54,285,653✔
1191
    SCEnter();
54,285,653✔
1192
    AppLayerTxData *d = alp_ctx.ctxs[alproto][FlowGetProtoMapping(ipproto)].GetTxData(tx);
54,285,653✔
1193
    SCReturnPtr(d, "AppLayerTxData");
54,285,653✔
1194
}
54,285,653✔
1195

1196
AppLayerStateData *AppLayerParserGetStateData(uint8_t ipproto, AppProto alproto, void *state)
1197
{
3,855✔
1198
    SCEnter();
3,855✔
1199
    if (alp_ctx.ctxs[alproto][FlowGetProtoMapping(ipproto)].GetStateData) {
3,856✔
1200
        AppLayerStateData *d =
3,856✔
1201
                alp_ctx.ctxs[alproto][FlowGetProtoMapping(ipproto)].GetStateData(state);
3,856✔
1202
        SCReturnPtr(d, "AppLayerStateData");
3,856✔
1203
    }
3,856✔
1204
    SCReturnPtr(NULL, "AppLayerStateData");
2,147,484,213✔
1205
}
3,855✔
1206

1207
void AppLayerParserApplyTxConfig(uint8_t ipproto, AppProto alproto,
1208
        void *state, void *tx, enum ConfigAction mode, AppLayerTxConfig config)
1209
{
×
1210
    SCEnter();
×
1211
    const int ipproto_map = FlowGetProtoMapping(ipproto);
×
1212
    if (alp_ctx.ctxs[alproto][ipproto_map].ApplyTxConfig) {
×
1213
        alp_ctx.ctxs[alproto][ipproto_map].ApplyTxConfig(state, tx, mode, config);
×
1214
    }
×
1215
    SCReturn;
×
1216
}
×
1217

1218
/***** General *****/
1219

1220
static inline void SetEOFFlags(AppLayerParserState *pstate, const uint8_t flags)
1221
{
101,557✔
1222
    if ((flags & (STREAM_EOF|STREAM_TOSERVER)) == (STREAM_EOF|STREAM_TOSERVER)) {
101,557✔
1223
        SCLogDebug("setting APP_LAYER_PARSER_EOF_TS");
2,383✔
1224
        SCAppLayerParserStateSetFlag(pstate, APP_LAYER_PARSER_EOF_TS);
2,383✔
1225
    } else if ((flags & (STREAM_EOF|STREAM_TOCLIENT)) == (STREAM_EOF|STREAM_TOCLIENT)) {
99,174✔
1226
        SCLogDebug("setting APP_LAYER_PARSER_EOF_TC");
2,271✔
1227
        SCAppLayerParserStateSetFlag(pstate, APP_LAYER_PARSER_EOF_TC);
2,271✔
1228
    }
2,271✔
1229
}
101,557✔
1230

1231
/** \internal
1232
 *  \brief create/close stream frames
1233
 *  On first invocation of TCP parser in a direction, create a <alproto>.stream frame.
1234
 *  On STREAM_EOF, set the final length. */
1235
static void HandleStreamFrames(Flow *f, StreamSlice stream_slice, const uint8_t *input,
1236
        const uint32_t input_len, const uint8_t flags)
1237
{
101,537✔
1238
    const uint8_t direction = (flags & STREAM_TOSERVER) ? 0 : 1;
101,537✔
1239
    AppLayerParserState *pstate = f->alparser;
101,537✔
1240

1241
    /* setup the generic stream frame */
1242
    if (((direction == 0 && (pstate->flags & APP_LAYER_PARSER_SFRAME_TS) == 0) ||
101,537✔
1243
                (direction == 1 && (pstate->flags & APP_LAYER_PARSER_SFRAME_TC) == 0)) &&
101,537✔
1244
            input != NULL && f->proto == IPPROTO_TCP) {
101,537✔
1245
        Frame *frame = AppLayerFrameGetLastOpenByType(f, direction, FRAME_STREAM_TYPE);
5,410✔
1246
        if (frame == NULL) {
5,410✔
1247
            int64_t frame_len = -1;
5,406✔
1248
            if (flags & STREAM_EOF)
5,406✔
1249
                frame_len = input_len;
127✔
1250

1251
            frame = AppLayerFrameNewByAbsoluteOffset(
5,406✔
1252
                    f, &stream_slice, stream_slice.offset, frame_len, direction, FRAME_STREAM_TYPE);
5,406✔
1253
            if (frame) {
5,406✔
1254
                SCLogDebug("opened: frame %p id %" PRIi64, frame, frame->id);
×
1255
                frame->flags = FRAME_FLAG_ENDS_AT_EOF; // TODO logic is not yet implemented
×
1256
                DEBUG_VALIDATE_BUG_ON(
×
1257
                        frame->id != 1); // should always be the first frame that is created
×
1258
            }
×
1259
            if (direction == 0) {
5,406✔
1260
                pstate->flags |= APP_LAYER_PARSER_SFRAME_TS;
2,952✔
1261
            } else {
2,952✔
1262
                pstate->flags |= APP_LAYER_PARSER_SFRAME_TC;
2,454✔
1263
            }
2,454✔
1264
        }
5,406✔
1265
    } else if (flags & STREAM_EOF) {
96,127✔
1266
        Frame *frame = AppLayerFrameGetLastOpenByType(f, direction, FRAME_STREAM_TYPE);
4,526✔
1267
        SCLogDebug("EOF closing: frame %p", frame);
4,526✔
1268
        if (frame) {
4,526✔
1269
            /* calculate final frame length */
1270
            int64_t slice_o = (int64_t)stream_slice.offset - (int64_t)frame->offset;
×
1271
            int64_t frame_len = slice_o + (int64_t)input_len;
×
1272
            SCLogDebug("%s: EOF frame->offset %" PRIu64 " -> %" PRIi64 ": o %" PRIi64,
×
1273
                    AppProtoToString(f->alproto), frame->offset, frame_len, slice_o);
×
1274
            frame->len = frame_len;
×
1275
        }
×
1276
    }
4,526✔
1277
}
101,537✔
1278

1279
static void Setup(Flow *f, const uint8_t direction, const uint8_t *input, uint32_t input_len,
1280
        const uint8_t flags, StreamSlice *as)
1281
{
101,512✔
1282
    memset(as, 0, sizeof(*as));
101,512✔
1283
    as->input = input;
101,512✔
1284
    as->input_len = input_len;
101,512✔
1285
    as->flags = flags;
101,512✔
1286

1287
    if (f->proto == IPPROTO_TCP && f->protoctx != NULL) {
101,512✔
1288
        TcpSession *ssn = f->protoctx;
87,297✔
1289
        TcpStream *stream = (direction & STREAM_TOSERVER) ? &ssn->client : &ssn->server;
87,297✔
1290
        as->offset = STREAM_APP_PROGRESS(stream);
87,297✔
1291
    }
87,297✔
1292
}
101,512✔
1293

1294
/** \retval int -1 in case of unrecoverable error. App-layer tracking stops for this flow.
1295
 *  \retval int 0 ok: we did not update app_progress
1296
 *  \retval int 1 ok: we updated app_progress */
1297
int AppLayerParserParse(ThreadVars *tv, AppLayerParserThreadCtx *alp_tctx, Flow *f, AppProto alproto,
1298
                        uint8_t flags, const uint8_t *input, uint32_t input_len)
1299
{
102,430✔
1300
    SCEnter();
102,430✔
1301
#ifdef DEBUG_VALIDATION
1302
    BUG_ON(f->protomap != FlowGetProtoMapping(f->proto));
1303
#endif
1304
    AppLayerParserState *pstate = f->alparser;
102,430✔
1305
    AppLayerParserProtoCtx *p = &alp_ctx.ctxs[alproto][f->protomap];
102,430✔
1306
    StreamSlice stream_slice;
102,430✔
1307
    void *alstate = NULL;
102,430✔
1308
    uint64_t p_tx_cnt = 0;
102,430✔
1309
    uint32_t consumed = input_len;
102,430✔
1310
    const uint8_t direction = (flags & STREAM_TOSERVER) ? 0 : 1;
102,430✔
1311

1312
    /* we don't have the parser registered for this protocol */
1313
    if (p->StateAlloc == NULL) {
102,430✔
1314
        if (f->proto == IPPROTO_TCP) {
873✔
1315
            StreamTcpDisableAppLayer(f);
1✔
1316
        }
1✔
1317
        goto end;
873✔
1318
    }
873✔
1319

1320
    if (flags & STREAM_GAP) {
101,557✔
1321
        if (!(p->option_flags & APP_LAYER_PARSER_OPT_ACCEPT_GAPS)) {
105✔
1322
            SCLogDebug("app-layer parser does not accept gaps");
6✔
1323
            if (f->alstate != NULL && !FlowChangeProto(f)) {
6✔
1324
                SCAppLayerParserTriggerRawStreamInspection(f, direction);
6✔
1325
            }
6✔
1326
            AppLayerIncGapErrorCounter(tv, f);
6✔
1327
            goto error;
6✔
1328
        }
6✔
1329
    }
105✔
1330

1331
    /* Get the parser state (if any) */
1332
    if (pstate == NULL) {
101,551✔
1333
        f->alparser = pstate = AppLayerParserStateAlloc();
3,538✔
1334
        if (pstate == NULL) {
3,538✔
1335
            AppLayerIncAllocErrorCounter(tv, f);
×
1336
            goto error;
×
1337
        }
×
1338
    }
3,538✔
1339

1340
    SetEOFFlags(pstate, flags);
101,551✔
1341

1342
    alstate = f->alstate;
101,551✔
1343
    if (alstate == NULL || FlowChangeProto(f)) {
101,551✔
1344
        f->alstate = alstate = p->StateAlloc(alstate, f->alproto_orig);
3,525✔
1345
        if (alstate == NULL) {
3,525✔
1346
            AppLayerIncAllocErrorCounter(tv, f);
×
1347
            goto error;
×
1348
        }
×
1349
        SCLogDebug("alloced new app layer state %p (name %s)",
3,525✔
1350
                   alstate, AppLayerGetProtoName(f->alproto));
3,525✔
1351

1352
        /* set flow flags to state */
1353
        if (f->file_flags != 0) {
3,525✔
1354
            AppLayerStateData *sd = AppLayerParserGetStateData(f->proto, f->alproto, f->alstate);
2,446✔
1355
            if (sd != NULL) {
2,446✔
1356
                if ((sd->file_flags & f->file_flags) != f->file_flags) {
2,444✔
1357
                    SCLogDebug("state data: updating file_flags %04x with flow file_flags %04x",
2,444✔
1358
                            sd->file_flags, f->file_flags);
2,444✔
1359
                    sd->file_flags |= f->file_flags;
2,444✔
1360
                }
2,444✔
1361
            }
2,444✔
1362
        }
2,446✔
1363
    } else {
98,026✔
1364
        SCLogDebug("using existing app layer state %p (name %s))",
98,026✔
1365
                   alstate, AppLayerGetProtoName(f->alproto));
98,026✔
1366
    }
98,026✔
1367

1368
    p_tx_cnt = AppLayerParserGetTxCnt(f, f->alstate);
101,551✔
1369

1370
    /* invoke the recursive parser, but only on data. We may get empty msgs on EOF */
1371
    if (input_len > 0 || (flags & STREAM_EOF)) {
101,551✔
1372
        Setup(f, flags & (STREAM_TOSERVER | STREAM_TOCLIENT), input, input_len, flags,
101,518✔
1373
                &stream_slice);
101,518✔
1374
        HandleStreamFrames(f, stream_slice, input, input_len, flags);
101,518✔
1375

1376
#ifdef QA_SIMULATION
1377
        if (((stream_slice.flags & STREAM_TOSERVER) &&
1378
                    stream_slice.offset >= g_eps_applayer_error_offset_ts)) {
1379
            SCLogNotice("putting parser %s into an error state from toserver offset %" PRIu64,
1380
                    AppProtoToString(alproto), g_eps_applayer_error_offset_ts);
1381
            AppLayerIncParserErrorCounter(tv, f);
1382
            goto error;
1383
        }
1384
        if (((stream_slice.flags & STREAM_TOCLIENT) &&
1385
                    stream_slice.offset >= g_eps_applayer_error_offset_tc)) {
1386
            SCLogNotice("putting parser %s into an error state from toclient offset %" PRIu64,
1387
                    AppProtoToString(alproto), g_eps_applayer_error_offset_tc);
1388
            AppLayerIncParserErrorCounter(tv, f);
1389
            goto error;
1390
        }
1391
#endif
1392
        /* invoke the parser */
1393
        AppLayerResult res = p->Parser[direction](f, alstate, pstate, stream_slice,
101,518✔
1394
                alp_tctx->alproto_local_storage[alproto][f->protomap]);
101,518✔
1395
        if (res.status < 0) {
101,518✔
1396
            AppLayerIncParserErrorCounter(tv, f);
772✔
1397
            goto error;
772✔
1398
        } else if (res.status > 0) {
100,746✔
1399
            DEBUG_VALIDATE_BUG_ON(res.consumed > input_len);
967✔
1400
            DEBUG_VALIDATE_BUG_ON(res.needed + res.consumed < input_len);
967✔
1401
            DEBUG_VALIDATE_BUG_ON(res.needed == 0);
967✔
1402
            /* incomplete is only supported for TCP */
1403
            DEBUG_VALIDATE_BUG_ON(f->proto != IPPROTO_TCP);
967✔
1404

1405
            /* put protocol in error state on improper use of the
1406
             * return codes. */
1407
            if (res.consumed > input_len || res.needed + res.consumed < input_len) {
967✔
1408
                AppLayerIncInternalErrorCounter(tv, f);
×
1409
                goto error;
×
1410
            }
×
1411

1412
            if (f->proto == IPPROTO_TCP && f->protoctx != NULL) {
967✔
1413
                TcpSession *ssn = f->protoctx;
967✔
1414
                SCLogDebug("direction %d/%s", direction,
967✔
1415
                        (flags & STREAM_TOSERVER) ? "toserver" : "toclient");
967✔
1416
                if (direction == 0) {
967✔
1417
                    /* parser told us how much data it needs on top of what it
1418
                     * consumed. So we need tell stream engine how much we need
1419
                     * before the next call */
1420
                    ssn->client.data_required = res.needed;
207✔
1421
                    SCLogDebug("setting data_required %u", ssn->client.data_required);
207✔
1422
                } else {
760✔
1423
                    /* parser told us how much data it needs on top of what it
1424
                     * consumed. So we need tell stream engine how much we need
1425
                     * before the next call */
1426
                    ssn->server.data_required = res.needed;
760✔
1427
                    SCLogDebug("setting data_required %u", ssn->server.data_required);
760✔
1428
                }
760✔
1429
            }
967✔
1430
            consumed = res.consumed;
967✔
1431
        }
967✔
1432
    }
101,518✔
1433

1434
    /* set the packets to no inspection and reassembly if required */
1435
    if (pstate->flags & APP_LAYER_PARSER_NO_INSPECTION) {
100,779✔
1436
        AppLayerParserSetEOF(pstate);
441✔
1437

1438
        if (f->proto == IPPROTO_TCP) {
441✔
1439
            StreamTcpDisableAppLayer(f);
12✔
1440

1441
            /* Set the no reassembly flag for both the stream in this TcpSession */
1442
            if (pstate->flags & APP_LAYER_PARSER_NO_REASSEMBLY) {
12✔
1443
                /* Used only if it's TCP */
1444
                TcpSession *ssn = f->protoctx;
×
1445
                if (ssn != NULL) {
×
1446
                    StreamTcpSetSessionNoReassemblyFlag(ssn, 0);
×
1447
                    StreamTcpSetSessionNoReassemblyFlag(ssn, 1);
×
1448
                }
×
1449
            }
×
1450
            /* Set the bypass flag for both the stream in this TcpSession */
1451
            if (pstate->flags & APP_LAYER_PARSER_BYPASS_READY) {
12✔
1452
                /* Used only if it's TCP */
1453
                TcpSession *ssn = f->protoctx;
×
1454
                if (ssn != NULL) {
×
1455
                    StreamTcpSetSessionBypassFlag(ssn);
×
1456
                }
×
1457
            }
×
1458
        } else {
430✔
1459
            // for TCP, this is set after flushing
1460
            FlowSetNoPayloadInspectionFlag(f);
429✔
1461
        }
429✔
1462
    }
441✔
1463

1464
    /* In cases like HeartBleed for TLS we need to inspect AppLayer but not Payload */
1465
    if (!(f->flags & FLOW_NOPAYLOAD_INSPECTION) && pstate->flags & APP_LAYER_PARSER_NO_INSPECTION_PAYLOAD) {
100,779✔
1466
        FlowSetNoPayloadInspectionFlag(f);
361✔
1467
        /* Set the no reassembly flag for both the stream in this TcpSession */
1468
        if (f->proto == IPPROTO_TCP) {
362✔
1469
            /* Used only if it's TCP */
1470
            TcpSession *ssn = f->protoctx;
362✔
1471
            if (ssn != NULL) {
362✔
1472
                StreamTcpSetDisableRawReassemblyFlag(ssn, 0);
362✔
1473
                StreamTcpSetDisableRawReassemblyFlag(ssn, 1);
362✔
1474
            }
362✔
1475
        }
362✔
1476
    }
361✔
1477

1478
    /* get the diff in tx cnt for stats keeping */
1479
    uint64_t cur_tx_cnt = AppLayerParserGetTxCnt(f, f->alstate);
100,779✔
1480
    if (cur_tx_cnt > p_tx_cnt && tv) {
100,779✔
1481
        AppLayerIncTxCounter(tv, f, cur_tx_cnt - p_tx_cnt);
22,755✔
1482
    }
22,755✔
1483

1484
 end:
101,671✔
1485
    /* update app progress */
1486
    if (consumed != input_len && f->proto == IPPROTO_TCP && f->protoctx != NULL) {
101,671✔
1487
        TcpSession *ssn = f->protoctx;
957✔
1488
        StreamTcpUpdateAppLayerProgress(ssn, direction, consumed);
957✔
1489
        SCReturnInt(1);
957✔
1490
    }
957✔
1491

1492
    SCReturnInt(0);
101,671✔
1493
 error:
778✔
1494
    /* Set the no app layer inspection flag for both
1495
     * the stream in this Flow */
1496
    if (f->proto == IPPROTO_TCP) {
778✔
1497
        StreamTcpDisableAppLayer(f);
729✔
1498
    }
729✔
1499
    AppLayerParserSetEOF(pstate);
778✔
1500
    SCReturnInt(-1);
778✔
1501
}
101,671✔
1502

1503
void AppLayerParserSetEOF(AppLayerParserState *pstate)
1504
{
1,219✔
1505
    SCEnter();
1,219✔
1506

1507
    if (pstate == NULL)
1,219✔
1508
        goto end;
×
1509

1510
    SCLogDebug("setting APP_LAYER_PARSER_EOF_TC and APP_LAYER_PARSER_EOF_TS");
1,219✔
1511
    SCAppLayerParserStateSetFlag(pstate, (APP_LAYER_PARSER_EOF_TS | APP_LAYER_PARSER_EOF_TC));
1,219✔
1512

1513
 end:
1,219✔
1514
    SCReturn;
1,219✔
1515
}
1,219✔
1516

1517
/* return true if there are app parser decoder events. These are
1518
 * only the ones that are set during protocol detection. */
1519
bool AppLayerParserHasDecoderEvents(AppLayerParserState *pstate)
1520
{
1,750,863✔
1521
    SCEnter();
1,750,863✔
1522

1523
    if (pstate == NULL)
1,750,863✔
1524
        return false;
455,987✔
1525

1526
    const AppLayerDecoderEvents *decoder_events = AppLayerParserGetDecoderEvents(pstate);
1,294,876✔
1527
    if (decoder_events && decoder_events->cnt)
1,294,876✔
1528
        return true;
×
1529

1530
    /* if we have reached here, we don't have events */
1531
    return false;
1,294,876✔
1532
}
1,294,876✔
1533

1534
/** \brief simple way to globally test if a alproto is registered
1535
 *         and fully enabled in the configuration.
1536
 */
1537
int AppLayerParserIsEnabled(AppProto alproto)
1538
{
37,737✔
1539
    for (int i = 0; i < FLOW_PROTO_APPLAYER_MAX; i++) {
47,516✔
1540
        if (alp_ctx.ctxs[alproto][i].StateGetProgress != NULL) {
47,516✔
1541
            return 1;
37,737✔
1542
        }
37,737✔
1543
    }
47,516✔
1544
    return 0;
×
1545
}
37,737✔
1546

1547
int AppLayerParserProtocolHasLogger(uint8_t ipproto, AppProto alproto)
1548
{
78,352✔
1549
    SCEnter();
78,352✔
1550
    int ipproto_map = FlowGetProtoMapping(ipproto);
78,352✔
1551
    int r = (!alp_ctx.ctxs[alproto][ipproto_map].logger) ? 0 : 1;
78,352✔
1552
    SCReturnInt(r);
78,352✔
1553
}
78,352✔
1554

1555
LoggerId AppLayerParserProtocolGetLoggerBits(uint8_t ipproto, AppProto alproto)
1556
{
168,188✔
1557
    SCEnter();
168,188✔
1558
    const int ipproto_map = FlowGetProtoMapping(ipproto);
168,188✔
1559
    LoggerId r = alp_ctx.ctxs[alproto][ipproto_map].logger_bits;
168,188✔
1560
    SCReturnUInt(r);
168,188✔
1561
}
168,188✔
1562

1563
void SCAppLayerParserTriggerRawStreamInspection(Flow *f, int direction)
1564
{
26,006✔
1565
    SCEnter();
26,006✔
1566

1567
    SCLogDebug("f %p tcp %p direction %d", f, f ? f->protoctx : NULL, direction);
26,006✔
1568
    if (f != NULL && f->protoctx != NULL)
26,006✔
1569
        StreamTcpReassembleTriggerRawInspection(f->protoctx, direction);
25,726✔
1570

1571
    SCReturn;
26,006✔
1572
}
26,006✔
1573

1574
void SCAppLayerParserSetStreamDepth(uint8_t ipproto, AppProto alproto, uint32_t stream_depth)
1575
{
49✔
1576
    SCEnter();
49✔
1577

1578
    alp_ctx.ctxs[alproto][FlowGetProtoMapping(ipproto)].stream_depth = stream_depth;
49✔
1579
    alp_ctx.ctxs[alproto][FlowGetProtoMapping(ipproto)].internal_flags |=
49✔
1580
            APP_LAYER_PARSER_INT_STREAM_DEPTH_SET;
49✔
1581

1582
    SCReturn;
49✔
1583
}
49✔
1584

1585
uint32_t AppLayerParserGetStreamDepth(const Flow *f)
1586
{
4,714✔
1587
    SCReturnInt(alp_ctx.ctxs[f->alproto][f->protomap].stream_depth);
4,714✔
1588
}
4,714✔
1589

1590
void AppLayerParserSetStreamDepthFlag(uint8_t ipproto, AppProto alproto, void *state, uint64_t tx_id, uint8_t flags)
1591
{
10✔
1592
    SCEnter();
10✔
1593
    void *tx = NULL;
10✔
1594
    if (state != NULL) {
10✔
1595
        if ((tx = AppLayerParserGetTx(ipproto, alproto, state, tx_id)) != NULL) {
10✔
1596
            if (alp_ctx.ctxs[alproto][FlowGetProtoMapping(ipproto)].SetStreamDepthFlag != NULL) {
10✔
1597
                alp_ctx.ctxs[alproto][FlowGetProtoMapping(ipproto)].SetStreamDepthFlag(tx, flags);
10✔
1598
            }
10✔
1599
        }
10✔
1600
    }
10✔
1601
    SCReturn;
10✔
1602
}
10✔
1603

1604
/**
1605
 *  \param id progress value id to get the name for
1606
 *  \param direction STREAM_TOSERVER/STREAM_TOCLIENT
1607
 */
1608
int AppLayerParserGetStateIdByName(
1609
        uint8_t ipproto, AppProto alproto, const char *name, const uint8_t direction)
1610
{
×
1611
    if (alp_ctx.ctxs[alproto][FlowGetProtoMapping(ipproto)].GetStateIdByName != NULL) {
×
1612
        return alp_ctx.ctxs[alproto][FlowGetProtoMapping(ipproto)].GetStateIdByName(
×
1613
                name, direction);
×
1614
    } else {
×
1615
        return -1;
×
1616
    }
×
1617
}
×
1618

1619
/**
1620
 *  \param id progress value id to get the name for
1621
 *  \param direction STREAM_TOSERVER/STREAM_TOCLIENT
1622
 */
1623
const char *AppLayerParserGetStateNameById(
1624
        uint8_t ipproto, AppProto alproto, const int id, const uint8_t direction)
1625
{
7,238✔
1626
    if (alp_ctx.ctxs[alproto][FlowGetProtoMapping(ipproto)].GetStateNameById != NULL) {
7,238✔
1627
        return alp_ctx.ctxs[alproto][FlowGetProtoMapping(ipproto)].GetStateNameById(id, direction);
1,496✔
1628
    } else {
5,917✔
1629
        return NULL;
5,742✔
1630
    }
5,742✔
1631
}
7,238✔
1632

1633
int AppLayerParserGetFrameIdByName(uint8_t ipproto, AppProto alproto, const char *name)
1634
{
6✔
1635
    if (alp_ctx.ctxs[alproto][FlowGetProtoMapping(ipproto)].GetFrameIdByName != NULL) {
6✔
1636
        return alp_ctx.ctxs[alproto][FlowGetProtoMapping(ipproto)].GetFrameIdByName(name);
5✔
1637
    } else {
5✔
1638
        return -1;
1✔
1639
    }
1✔
1640
}
6✔
1641

1642
const char *AppLayerParserGetFrameNameById(uint8_t ipproto, AppProto alproto, const uint8_t id)
1643
{
×
1644
    if (alp_ctx.ctxs[alproto][FlowGetProtoMapping(ipproto)].GetFrameNameById != NULL) {
×
1645
        return alp_ctx.ctxs[alproto][FlowGetProtoMapping(ipproto)].GetFrameNameById(id);
×
1646
    } else {
×
1647
        return NULL;
×
1648
    }
×
1649
}
×
1650

1651
/***** Cleanup *****/
1652

1653
void AppLayerParserStateProtoCleanup(
1654
        uint8_t protomap, AppProto alproto, void *alstate, AppLayerParserState *pstate)
1655
{
35,451✔
1656
    SCEnter();
35,451✔
1657

1658
    AppLayerParserProtoCtx *ctx = &alp_ctx.ctxs[alproto][protomap];
35,451✔
1659

1660
    if (ctx->StateFree != NULL && alstate != NULL)
35,451✔
1661
        ctx->StateFree(alstate);
3,540✔
1662

1663
    /* free the app layer parser api state */
1664
    if (pstate != NULL)
35,451✔
1665
        AppLayerParserStateFree(pstate);
3,540✔
1666

1667
    SCReturn;
35,451✔
1668
}
35,451✔
1669

1670
void AppLayerParserStateCleanup(const Flow *f, void *alstate, AppLayerParserState *pstate)
1671
{
35,310✔
1672
    AppLayerParserStateProtoCleanup(f->protomap, f->alproto, alstate, pstate);
35,310✔
1673
}
35,310✔
1674

1675
static void ValidateParserProtoDump(AppProto alproto, uint8_t ipproto)
1676
{
×
1677
    uint8_t map = FlowGetProtoMapping(ipproto);
×
1678
    const AppLayerParserProtoCtx *ctx = &alp_ctx.ctxs[alproto][map];
×
1679
    printf("ERROR: incomplete app-layer registration\n");
×
1680
    printf("AppLayer protocol %s ipproto %u\n", AppProtoToString(alproto), ipproto);
×
1681
    printf("- option flags %"PRIx32"\n", ctx->option_flags);
×
1682
    printf("- first_data_dir %"PRIx8"\n", ctx->first_data_dir);
×
1683
    printf("Mandatory:\n");
×
1684
    printf("- Parser[0] %p Parser[1] %p\n", ctx->Parser[0], ctx->Parser[1]);
×
1685
    printf("- StateAlloc %p StateFree %p\n", ctx->StateAlloc, ctx->StateFree);
×
1686
    printf("- StateGetTx %p StateGetTxCnt %p StateTransactionFree %p\n",
×
1687
            ctx->StateGetTx, ctx->StateGetTxCnt, ctx->StateTransactionFree);
×
1688
    printf("- GetTxData %p\n", ctx->GetTxData);
×
1689
    printf("- GetStateData %p\n", ctx->GetStateData);
×
1690
    printf("- StateGetProgress %p\n", ctx->StateGetProgress);
×
1691
    printf("Optional:\n");
×
1692
    printf("- LocalStorageAlloc %p LocalStorageFree %p\n", ctx->LocalStorageAlloc, ctx->LocalStorageFree);
×
1693
    printf("- StateGetEventInfo %p StateGetEventInfoById %p\n", ctx->StateGetEventInfo,
×
1694
            ctx->StateGetEventInfoById);
×
1695
}
×
1696

1697
#define BOTH_SET(a, b) ((a) != NULL && (b) != NULL)
2,990✔
1698
#define BOTH_SET_OR_BOTH_UNSET(a, b) (((a) == NULL && (b) == NULL) || ((a) != NULL && (b) != NULL))
1,495✔
1699
#define THREE_SET(a, b, c) ((a) != NULL && (b) != NULL && (c) != NULL)
1,495✔
1700

1701
static void ValidateParserProto(AppProto alproto, uint8_t ipproto)
1702
{
3,200✔
1703
    uint8_t map = FlowGetProtoMapping(ipproto);
3,200✔
1704
    const AppLayerParserProtoCtx *ctx = &alp_ctx.ctxs[alproto][map];
3,200✔
1705

1706
    if (ctx->Parser[0] == NULL && ctx->Parser[1] == NULL)
3,200✔
1707
        return;
1,705✔
1708

1709
    if (!(BOTH_SET(ctx->Parser[0], ctx->Parser[1]))) {
1,495✔
1710
        goto bad;
×
1711
    }
×
1712
    if (!(BOTH_SET(ctx->StateFree, ctx->StateAlloc))) {
1,495✔
1713
        goto bad;
×
1714
    }
×
1715
    if (!(THREE_SET(ctx->StateGetTx, ctx->StateGetTxCnt, ctx->StateTransactionFree))) {
1,495✔
1716
        goto bad;
×
1717
    }
×
1718
    if (ctx->StateGetProgress == NULL) {
1,495✔
1719
        goto bad;
×
1720
    }
×
1721
    /* local storage is optional, but needs both set if used */
1722
    if (!(BOTH_SET_OR_BOTH_UNSET(ctx->LocalStorageAlloc, ctx->LocalStorageFree))) {
1,495✔
1723
        goto bad;
×
1724
    }
×
1725
    if (ctx->GetTxData == NULL) {
1,495✔
1726
        goto bad;
×
1727
    }
×
1728
    if (ctx->GetStateData == NULL) {
1,495✔
1729
        goto bad;
×
1730
    }
×
1731
    return;
1,495✔
1732
bad:
1,495✔
1733
    ValidateParserProtoDump(alproto, ipproto);
×
1734
    exit(EXIT_FAILURE);
×
1735
}
1,495✔
1736
#undef BOTH_SET
1737
#undef BOTH_SET_OR_BOTH_UNSET
1738
#undef THREE_SET
1739

1740
static void ValidateParser(AppProto alproto)
1741
{
1,600✔
1742
    ValidateParserProto(alproto, IPPROTO_TCP);
1,600✔
1743
    ValidateParserProto(alproto, IPPROTO_UDP);
1,600✔
1744
}
1,600✔
1745

1746
static void ValidateParsers(void)
1747
{
40✔
1748
    AppProto p = 0;
40✔
1749
    for (; p < g_alproto_max; p++) {
1,640✔
1750
        ValidateParser(p);
1,600✔
1751
    }
1,600✔
1752
}
40✔
1753

1754
#define ARRAY_CAP_STEP 16
80✔
1755
static void (**PreRegisteredCallbacks)(void) = NULL;
1756
static size_t preregistered_callbacks_nb = 0;
1757
static size_t preregistered_callbacks_cap = 0;
1758

1759
int SCAppLayerParserReallocCtx(AppProto alproto)
1760
{
40✔
1761
    if (alp_ctx.ctxs_len <= alproto && alproto < g_alproto_max) {
40✔
1762
        /* Realloc alp_ctx.ctxs, so that dynamic alproto can be treated as real/normal ones.
1763
         * In case we need to turn off dynamic alproto. */
1764
        void *tmp = SCRealloc(alp_ctx.ctxs, sizeof(AppLayerParserProtoCtx[FLOW_PROTO_MAX]) *
40✔
1765
                                                    (alp_ctx.ctxs_len + ARRAY_CAP_STEP));
40✔
1766
        if (unlikely(tmp == NULL)) {
40✔
1767
            FatalError("Unable to realloc alp_ctx.ctxs.");
×
1768
        }
×
1769
        alp_ctx.ctxs = tmp;
40✔
1770
        memset(&alp_ctx.ctxs[alp_ctx.ctxs_len], 0,
40✔
1771
                sizeof(AppLayerParserProtoCtx[FLOW_PROTO_MAX]) * ARRAY_CAP_STEP);
40✔
1772
        alp_ctx.ctxs_len += ARRAY_CAP_STEP;
40✔
1773
    }
40✔
1774
    return 0;
40✔
1775
}
40✔
1776

1777
int AppLayerParserPreRegister(void (*Register)(void))
1778
{
×
1779
    if (preregistered_callbacks_nb == preregistered_callbacks_cap) {
×
1780
        void *tmp = SCRealloc(PreRegisteredCallbacks,
×
1781
                sizeof(void *) * (preregistered_callbacks_cap + ARRAY_CAP_STEP));
×
1782
        if (tmp == NULL) {
×
1783
            return 1;
×
1784
        }
×
1785
        preregistered_callbacks_cap += ARRAY_CAP_STEP;
×
1786
        PreRegisteredCallbacks = tmp;
×
1787
    }
×
1788
    PreRegisteredCallbacks[preregistered_callbacks_nb] = Register;
×
1789
    preregistered_callbacks_nb++;
×
1790
    return 0;
×
1791
}
×
1792

1793
void AppLayerParserRegisterProtocolParsers(void)
1794
{
40✔
1795
    SCEnter();
40✔
1796

1797
    AppLayerConfig();
40✔
1798

1799
    RegisterHTPParsers();
40✔
1800
    RegisterSSLParsers();
40✔
1801
    SCRegisterDcerpcParser();
40✔
1802
    SCRegisterDcerpcUdpParser();
40✔
1803
    RegisterSMBParsers();
40✔
1804
    RegisterFTPParsers();
40✔
1805
    RegisterSSHParsers();
40✔
1806
    RegisterSMTPParsers();
40✔
1807
    SCRegisterDnsUdpParser();
40✔
1808
    SCRegisterDnsTcpParser();
40✔
1809
    SCRegisterBittorrentDhtUdpParser();
40✔
1810
    RegisterModbusParsers();
40✔
1811
    SCEnipRegisterParsers();
40✔
1812
    RegisterDNP3Parsers();
40✔
1813
    RegisterNFSTCPParsers();
40✔
1814
    RegisterNFSUDPParsers();
40✔
1815
    SCRegisterNtpParser();
40✔
1816
    RegisterTFTPParsers();
40✔
1817
    RegisterIKEParsers();
40✔
1818
    SCRegisterKrb5Parser();
40✔
1819
    SCRegisterDhcpParser();
40✔
1820
    SCRegisterSnmpParser();
40✔
1821
    SCRegisterSipParser();
40✔
1822
    SCRegisterQuicParser();
40✔
1823
    SCRegisterWebSocketParser();
40✔
1824
    SCRegisterLdapTcpParser();
40✔
1825
    SCRegisterLdapUdpParser();
40✔
1826
    SCRegisterMdnsParser();
40✔
1827
    SCRegisterTemplateParser();
40✔
1828
    SCRfbRegisterParser();
40✔
1829
    SCMqttRegisterParser();
40✔
1830
    SCRegisterPgsqlParser();
40✔
1831
    SCRegisterPop3Parser();
40✔
1832
    SCRegisterRdpParser();
40✔
1833
    RegisterHTTP2Parsers();
40✔
1834
    SCRegisterTelnetParser();
40✔
1835
    RegisterIMAPParsers();
40✔
1836

1837
    for (size_t i = 0; i < preregistered_callbacks_nb; i++) {
40✔
1838
        PreRegisteredCallbacks[i]();
×
1839
    }
×
1840

1841
    ValidateParsers();
40✔
1842
}
40✔
1843

1844
/* coccinelle: SCAppLayerParserStateSetFlag():2,2:APP_LAYER_PARSER_ */
1845
void SCAppLayerParserStateSetFlag(AppLayerParserState *pstate, uint16_t flag)
1846
{
19,859✔
1847
    SCEnter();
19,859✔
1848
    pstate->flags |= flag;
19,859✔
1849
    SCReturn;
19,859✔
1850
}
19,859✔
1851

1852
/* coccinelle: SCAppLayerParserStateIssetFlag():2,2:APP_LAYER_PARSER_ */
1853
uint16_t SCAppLayerParserStateIssetFlag(AppLayerParserState *pstate, uint16_t flag)
1854
{
1,501,696✔
1855
    SCEnter();
1,501,696✔
1856
    SCReturnUInt(pstate->flags & flag);
1,501,696✔
1857
}
1,501,696✔
1858

1859
/***** Unittests *****/
1860

1861
#ifdef UNITTESTS
1862
#include "util-unittest-helper.h"
1863

1864
void AppLayerParserRegisterProtocolUnittests(uint8_t ipproto, AppProto alproto,
1865
                                  void (*RegisterUnittests)(void))
1866
{
49✔
1867
    SCEnter();
49✔
1868
    alp_ctx.ctxs[alproto][FlowGetProtoMapping(ipproto)].RegisterUnittests = RegisterUnittests;
49✔
1869
    SCReturn;
49✔
1870
}
49✔
1871

1872
void AppLayerParserRegisterUnittests(void)
1873
{
1✔
1874
    SCEnter();
1✔
1875

1876
    int ip;
1✔
1877
    AppProto alproto;
1✔
1878
    AppLayerParserProtoCtx *ctx;
1✔
1879

1880
    for (ip = 0; ip < FLOW_PROTO_DEFAULT; ip++) {
4✔
1881
        for (alproto = 0; alproto < g_alproto_max; alproto++) {
123✔
1882
            ctx = &alp_ctx.ctxs[alproto][ip];
120✔
1883
            if (ctx->RegisterUnittests == NULL)
120✔
1884
                continue;
111✔
1885
            ctx->RegisterUnittests();
9✔
1886
        }
9✔
1887
    }
3✔
1888

1889
    SCReturn;
1✔
1890
}
1✔
1891

1892
#endif
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc