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

OISF / suricata / 22550237931

01 Mar 2026 06:56PM UTC coverage: 64.812% (-8.9%) from 73.687%
22550237931

Pull #14920

github

web-flow
Merge e05854a6d into 90823fa90
Pull Request #14920: draft: rust based configuration file parser and loader - v4

561 of 789 new or added lines in 4 files covered. (71.1%)

23225 existing lines in 498 files now uncovered.

131605 of 203055 relevant lines covered (64.81%)

2328818.84 hits per line

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

88.44
/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
{
31✔
159
    g_applayerparser_error_policy = ExceptionPolicyParse("app-layer.error-policy", true);
31✔
160
}
31✔
161

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

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

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

184
FramesContainer *AppLayerFramesGetContainer(const Flow *f)
185
{
2,714,663✔
186
    if (f == NULL || f->alparser == NULL)
2,714,663✔
187
        return NULL;
155,035✔
188
    return f->alparser->frames;
2,559,628✔
189
}
2,714,663✔
190

191
FramesContainer *AppLayerFramesSetupContainer(Flow *f)
192
{
1,245,129✔
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);
1,245,129✔
198
    if (f->alparser->frames == NULL) {
1,245,129✔
199
        f->alparser->frames = SCCalloc(1, sizeof(FramesContainer));
27,699✔
200
        if (f->alparser->frames == NULL) {
27,699✔
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
    }
27,699✔
210
    return f->alparser->frames;
1,245,129✔
211
}
1,245,129✔
212

213
#ifdef UNITTESTS
214
void UTHAppLayerParserStateGetIds(void *ptr, uint64_t *i1, uint64_t *i2, uint64_t *log, uint64_t *min)
215
{
216
    struct AppLayerParserState_ *s = ptr;
217
    *i1 = s->inspect_id[0];
218
    *i2 = s->inspect_id[1];
219
    *log = s->log_id;
220
    *min = s->min_id;
221
}
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
{
3,106✔
230
    uint8_t ipproto_map = FlowGetProtoMapping(ipproto);
3,106✔
231

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

235
AppLayerParserState *AppLayerParserStateAlloc(void)
236
{
34,040✔
237
    SCEnter();
34,040✔
238

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

243
 end:
34,040✔
244
    SCReturnPtr(pstate, "AppLayerParserState");
34,040✔
245
}
34,040✔
246

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

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

256
    SCReturn;
34,040✔
257
}
34,040✔
258

259
int AppLayerParserSetup(void)
260
{
31✔
261
    SCEnter();
31✔
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]));
31✔
265
    if (unlikely(alp_ctx.ctxs == NULL)) {
31✔
266
        FatalError("Unable to alloc alp_ctx.ctxs.");
×
267
    }
×
268
    alp_ctx.ctxs_len = g_alproto_max;
31✔
269
    SCReturnInt(0);
31✔
270
}
31✔
271

272
void AppLayerParserPostStreamSetup(void)
273
{
29✔
274
    /* lets set a default value for stream_depth */
275
    for (int flow_proto = 0; flow_proto < FLOW_PROTO_DEFAULT; flow_proto++) {
116✔
276
        for (AppProto alproto = 0; alproto < g_alproto_max; alproto++) {
3,567✔
277
            if (!(alp_ctx.ctxs[alproto][flow_proto].internal_flags &
3,480✔
278
                        APP_LAYER_PARSER_INT_STREAM_DEPTH_SET)) {
3,480✔
279
                alp_ctx.ctxs[alproto][flow_proto].stream_depth = stream_config.reassembly_depth;
3,444✔
280
            }
3,444✔
281
        }
3,480✔
282
    }
87✔
283
}
29✔
284

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

289
    SCFree(alp_ctx.ctxs);
22✔
290

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

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

297
AppLayerParserThreadCtx *AppLayerParserThreadCtxAlloc(void)
298
{
145✔
299
    SCEnter();
145✔
300

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

305
    tctx->alproto_local_storage = SCCalloc(g_alproto_max, sizeof(void *[FLOW_PROTO_MAX]));
145✔
306
    if (unlikely(tctx->alproto_local_storage == NULL)) {
145✔
307
        SCFree(tctx);
×
308
        tctx = NULL;
×
309
        goto end;
×
310
    }
×
311
    for (uint8_t flow_proto = 0; flow_proto < FLOW_PROTO_DEFAULT; flow_proto++) {
580✔
312
        for (AppProto alproto = 0; alproto < g_alproto_max; alproto++) {
17,835✔
313
            uint8_t ipproto = FlowGetReverseProtoMapping(flow_proto);
17,400✔
314

315
            tctx->alproto_local_storage[alproto][flow_proto] =
17,400✔
316
                    AppLayerParserGetProtocolParserLocalStorage(ipproto, alproto);
17,400✔
317
        }
17,400✔
318
    }
435✔
319

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

324
void AppLayerParserThreadCtxFree(AppLayerParserThreadCtx *tctx)
325
{
141✔
326
    SCEnter();
141✔
327

328
    for (uint8_t flow_proto = 0; flow_proto < FLOW_PROTO_DEFAULT; flow_proto++) {
564✔
329
        for (AppProto alproto = 0; alproto < g_alproto_max; alproto++) {
17,343✔
330
            uint8_t ipproto = FlowGetReverseProtoMapping(flow_proto);
16,920✔
331

332
            AppLayerParserDestroyProtocolParserLocalStorage(
16,920✔
333
                    ipproto, alproto, tctx->alproto_local_storage[alproto][flow_proto]);
16,920✔
334
        }
16,920✔
335
    }
423✔
336

337
    SCFree(tctx->alproto_local_storage);
141✔
338
    SCFree(tctx);
141✔
339
    SCReturn;
141✔
340
}
141✔
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,187✔
347
    SCEnter();
1,187✔
348

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

354
    if (RunmodeIsUnittests())
1,187✔
UNCOV
355
        goto enabled;
×
356

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

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

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

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

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

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

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

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

411
    SCReturnInt(0);
2,392✔
412
}
2,392✔
413

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

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

422
    SCReturn;
172✔
423
}
172✔
424

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

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

432
    SCReturn;
298✔
433
}
298✔
434

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

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

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

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

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

455
    SCReturn;
62✔
456
}
62✔
457

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

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

465
    SCReturn;
248✔
466
}
248✔
467

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

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

474
    SCReturn;
436✔
475
}
436✔
476

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

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

483
    SCReturn;
777✔
484
}
777✔
485

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

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

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

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

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

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

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

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

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

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

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

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

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

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

545
    alp_ctx.ctxs[alproto][FLOW_PROTO_DEFAULT].complete_ts = ts;
1,196✔
546
    alp_ctx.ctxs[alproto][FLOW_PROTO_DEFAULT].complete_tc = tc;
1,196✔
547
}
1,196✔
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,041✔
553
    SCEnter();
1,041✔
554

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

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

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

571
void AppLayerParserRegisterGetFrameFuncs(uint8_t ipproto, AppProto alproto,
572
        AppLayerParserGetFrameIdByNameFn GetIdByNameFunc,
573
        AppLayerParserGetFrameNameByIdFn GetNameByIdFunc)
574
{
699✔
575
    SCEnter();
699✔
576
    alp_ctx.ctxs[alproto][FlowGetProtoMapping(ipproto)].GetFrameIdByName = GetIdByNameFunc;
699✔
577
    alp_ctx.ctxs[alproto][FlowGetProtoMapping(ipproto)].GetFrameNameById = GetNameByIdFunc;
699✔
578
    SCReturn;
699✔
579
}
699✔
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,072✔
585
    SCEnter();
1,072✔
586

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

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

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

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

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

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

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

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

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

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

619
    SCReturn;
62✔
620
}
62✔
621

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

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

629
    SCReturn;
31✔
630
}
31✔
631

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

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

639
    if (alp_ctx.ctxs[alproto][FlowGetProtoMapping(ipproto)].LocalStorageAlloc != NULL) {
17,400✔
640
        r = alp_ctx.ctxs[alproto][FlowGetProtoMapping(ipproto)].LocalStorageAlloc();
290✔
641
    }
290✔
642

643
    SCReturnPtr(r, "void *");
17,400✔
644
}
17,400✔
645

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

651
    if (alp_ctx.ctxs[alproto][FlowGetProtoMapping(ipproto)].LocalStorageFree != NULL) {
16,920✔
652
        alp_ctx.ctxs[alproto][FlowGetProtoMapping(ipproto)].LocalStorageFree(local_data);
282✔
653
    }
282✔
654

655
    SCReturn;
16,920✔
656
}
16,920✔
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
{
132,463✔
671
    uint64_t ustate = *(uint64_t *)state;
132,463✔
672
    uint64_t tx_id = MAX(min_tx_id, ustate);
132,463✔
673
    for ( ; tx_id < max_tx_id; tx_id++) {
132,463✔
674
        void *tx_ptr = AppLayerParserGetTx(ipproto, alproto, alstate, tx_id);
123,856✔
675
        if (tx_ptr != NULL) {
123,856✔
676
            ustate = tx_id + 1;
123,856✔
677
            *state = *(AppLayerGetTxIterState *)&ustate;
123,856✔
678
            AppLayerGetTxIterTuple tuple = {
123,856✔
679
                .tx_ptr = tx_ptr,
123,856✔
680
                .tx_id = tx_id,
123,856✔
681
                .has_next = (tx_id + 1 < max_tx_id),
123,856✔
682
            };
123,856✔
683
            SCLogDebug("tuple: %p/%"PRIu64"/%s", tuple.tx_ptr, tuple.tx_id,
123,856✔
684
                    tuple.has_next ? "true" : "false");
123,856✔
685
            return tuple;
123,856✔
686
        }
123,856✔
687
    }
123,856✔
688

689
    AppLayerGetTxIterTuple no_tuple = { NULL, 0, false };
8,607✔
690
    return no_tuple;
8,607✔
691
}
132,463✔
692

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

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

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

708
uint64_t AppLayerParserGetMinId(AppLayerParserState *pstate)
709
{
8,943✔
710
    SCEnter();
8,943✔
711

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

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

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

722
    SCReturn;
76,154✔
723
}
76,154✔
724

725
uint64_t AppLayerParserGetTransactionInspectId(AppLayerParserState *pstate, uint8_t direction)
726
{
1,020,562✔
727
    SCEnter();
1,020,562✔
728

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

UNCOV
732
    DEBUG_VALIDATE_BUG_ON(1);
×
UNCOV
733
    SCReturnCT(0ULL, "uint64_t");
×
734
}
1,020,562✔
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
{
173,686✔
744
    return txd->logged;
173,686✔
745
}
173,686✔
746

747
void SCAppLayerTxDataCleanup(AppLayerTxData *txd)
748
{
279,196✔
749
    if (txd->de_state) {
279,196✔
750
        SCDetectEngineStateFree(txd->de_state);
16,927✔
751
    }
16,927✔
752
    if (txd->events) {
279,196✔
753
        SCAppLayerDecoderEventsFreeEvents(&txd->events);
15,505✔
754
    }
15,505✔
755
    if (txd->txbits) {
279,196✔
UNCOV
756
        SCGenericVarFree(txd->txbits);
×
UNCOV
757
    }
×
758
}
279,196✔
759

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

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

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

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

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

786
        void *tx = ires.tx_ptr;
457,541✔
787
        idx = ires.tx_id;
457,541✔
788

789
        int state_progress = AppLayerParserGetStateProgress(ipproto, alproto, tx, flags);
457,541✔
790
        if (state_progress < state_done_progress)
457,541✔
791
            break;
343,257✔
792

793
        AppLayerTxData *txd = AppLayerParserGetTxData(ipproto, alproto, tx);
114,284✔
794
        if (tag_txs_as_inspected) {
114,284✔
795
            const uint8_t inspected_flag = (flags & STREAM_TOSERVER) ? APP_LAYER_TX_INSPECTED_TS
2,423✔
796
                                                                     : APP_LAYER_TX_INSPECTED_TC;
2,423✔
797
            if (txd->flags & inspected_flag) {
2,423✔
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
        }
2,423✔
803
        idx++;
114,284✔
804
        if (!ires.has_next)
114,284✔
805
            break;
69,586✔
806
    }
114,284✔
807
    pstate->inspect_id[direction] = idx;
493,531✔
808
    SCLogDebug("inspect_id now %"PRIu64, pstate->inspect_id[direction]);
493,531✔
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) {
493,531✔
813
        /* continue at idx */
814
        while (1) {
8,971✔
815
            AppLayerGetTxIterTuple ires = IterFunc(ipproto, alproto, alstate, idx, total_txs, &state);
8,971✔
816
            if (ires.tx_ptr == NULL)
8,971✔
817
                break;
6,117✔
818

819
            void *tx = ires.tx_ptr;
2,854✔
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) {
2,854✔
824
                pstate->inspect_id[direction] = ires.tx_id;
3✔
825
            }
3✔
826
            idx = ires.tx_id;
2,854✔
827

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

832
            /* txd can be NULL for HTTP sessions where the user data alloc failed */
833
            AppLayerTxData *txd = AppLayerParserGetTxData(ipproto, alproto, tx);
4✔
834
            const uint8_t inspected_flag = (flags & STREAM_TOSERVER) ? APP_LAYER_TX_INSPECTED_TS
4✔
835
                                                                     : APP_LAYER_TX_INSPECTED_TC;
4✔
836
            if (txd->flags & inspected_flag) {
4✔
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)
4✔
847
                break;
2✔
848
            idx++;
2✔
849
        }
2✔
850
    }
8,969✔
851

852
    SCReturn;
493,531✔
853
}
493,531✔
854

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

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

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

868
    AppLayerDecoderEvents *ptr = NULL;
2,090,357✔
869

870
    /* Access events via the tx_data. */
871
    AppLayerTxData *txd = AppLayerParserGetTxData(ipproto, alproto, tx);
2,090,357✔
872
    if (txd->events != NULL) {
2,090,357✔
873
        ptr = txd->events;
99,355✔
874
    }
99,355✔
875

876
    SCReturnPtr(ptr, "AppLayerDecoderEvents *");
2,090,357✔
877
}
2,090,357✔
878

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

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

887
    AppLayerGetFileState files = { .fc = NULL, .cfg = NULL };
16,624✔
888
    return files;
16,624✔
889
}
910,154✔
890

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

900
#define IS_DISRUPTED(flags) ((flags) & (STREAM_DEPTH | STREAM_GAP))
6,741,014✔
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
{
750,202✔
911
    SCEnter();
750,202✔
912
    DEBUG_ASSERT_FLOW_LOCKED(f);
750,202✔
913

914
    AppLayerParserProtoCtx *p = &alp_ctx.ctxs[f->alproto][f->protomap];
750,202✔
915
    if (unlikely(p->StateTransactionFree == NULL))
750,202✔
916
        SCReturn;
14,931✔
917

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

924
    if (alstate == NULL || alparser == NULL)
735,271✔
925
        SCReturn;
4✔
926

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

935
    int pkt_dir_trunc = -1;
735,267✔
936

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

946
    while (1) {
4,626,588✔
947
        AppLayerGetTxIterTuple ires = IterFunc(ipproto, alproto, alstate, i, total_txs, &state);
4,626,588✔
948
        if (ires.tx_ptr == NULL)
4,626,588✔
949
            break;
236,688✔
950

951
        bool tx_skipped = false;
4,626,588✔
952
        void *tx = ires.tx_ptr;
4,389,900✔
953
        i = ires.tx_id; // actual tx id for the tx the IterFunc returned
4,389,900✔
954

955
        SCLogDebug("%p/%"PRIu64" checking", tx, i);
4,389,900✔
956
        AppLayerTxData *txd = AppLayerParserGetTxData(ipproto, alproto, tx);
4,389,900✔
957
        if (AppLayerParserHasFilesInDir(txd, pkt_dir)) {
4,389,900✔
958
            if (pkt_dir_trunc == -1)
135,188✔
959
                pkt_dir_trunc = IS_DISRUPTED(
114,694✔
960
                        (pkt_dir == STREAM_TOSERVER) ? ts_disrupt_flags : tc_disrupt_flags);
135,188✔
961
            AppLayerParserFileTxHousekeeping(f, tx, pkt_dir, (bool)pkt_dir_trunc);
135,188✔
962
        }
135,188✔
963
        // should be reset by parser next time it updates the tx
964
        if (pkt_dir & STREAM_TOSERVER) {
4,389,900✔
965
            txd->updated_ts = false;
2,799,936✔
966
        } else {
2,799,936✔
967
            txd->updated_tc = false;
1,589,964✔
968
        }
1,589,964✔
969
        const int tx_progress_tc =
4,389,900✔
970
                AppLayerParserGetStateProgress(ipproto, alproto, tx, tc_disrupt_flags);
4,389,900✔
971
        if (tx_progress_tc < tx_end_state_tc) {
4,389,900✔
972
            SCLogDebug("%p/%"PRIu64" skipping: tc parser not done", tx, i);
2,190,725✔
973
            skipped = true;
2,190,725✔
974
            goto next;
2,190,725✔
975
        }
2,190,725✔
976
        const int tx_progress_ts =
2,199,175✔
977
                AppLayerParserGetStateProgress(ipproto, alproto, tx, ts_disrupt_flags);
2,199,175✔
978
        if (tx_progress_ts < tx_end_state_ts) {
2,199,175✔
979
            SCLogDebug("%p/%"PRIu64" skipping: ts parser not done", tx, i);
542,595✔
980
            skipped = true;
542,595✔
981
            goto next;
542,595✔
982
        }
542,595✔
983

984
        if (has_tx_detect_flags) {
1,656,580✔
985
            if (!IS_DISRUPTED(ts_disrupt_flags) &&
1,656,580✔
986
                    (f->sgh_toserver != NULL || (f->flags & FLOW_SGH_TOSERVER) == 0)) {
1,656,580✔
987
                if ((txd->flags & (APP_LAYER_TX_INSPECTED_TS | APP_LAYER_TX_SKIP_INSPECT_TS)) ==
1,562,167✔
988
                        0) {
1,562,167✔
989
                    SCLogDebug("%p/%" PRIu64 " skipping: TS inspect not done: ts:%02x", tx, i,
80,453✔
990
                            txd->flags);
80,453✔
991
                    tx_skipped = true;
80,453✔
992
                }
80,453✔
993
            }
1,562,167✔
994
            if (!IS_DISRUPTED(tc_disrupt_flags) &&
1,656,580✔
995
                    (f->sgh_toclient != NULL || (f->flags & FLOW_SGH_TOCLIENT) == 0)) {
1,656,580✔
996
                if ((txd->flags & (APP_LAYER_TX_INSPECTED_TC | APP_LAYER_TX_SKIP_INSPECT_TC)) ==
1,573,803✔
997
                        0) {
1,573,803✔
998
                    SCLogDebug("%p/%" PRIu64 " skipping: TC inspect not done: ts:%02x", tx, i,
1,454,082✔
999
                            txd->flags);
1,454,082✔
1000
                    tx_skipped = true;
1,454,082✔
1001
                }
1,454,082✔
1002
            }
1,573,803✔
1003
        }
1,656,580✔
1004

1005
        if (tx_skipped) {
1,656,580✔
1006
            SCLogDebug("%p/%" PRIu64 " tx_skipped", tx, i);
1,465,379✔
1007
            skipped = true;
1,465,379✔
1008
            goto next;
1,465,379✔
1009
        }
1,465,379✔
1010

1011
        if (logger_expectation != 0) {
191,201✔
1012
            LoggerId tx_logged = GetTxLogged(txd);
173,686✔
1013
            if (tx_logged != logger_expectation) {
173,686✔
1014
                SCLogDebug("%p/%"PRIu64" skipping: logging not done: want:%"PRIx32", have:%"PRIx32,
4,203✔
1015
                        tx, i, logger_expectation, tx_logged);
4,203✔
1016
                skipped = true;
4,203✔
1017
                goto next;
4,203✔
1018
            }
4,203✔
1019
        }
173,686✔
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,
186,998✔
1024
                txd->files_logged, txd->files_stored);
186,998✔
1025

1026
        if (txd->files_opened) {
186,998✔
1027
            if (g_file_logger_enabled && txd->files_opened != txd->files_logged) {
11,502✔
1028
                skipped = true;
142✔
1029
                goto next;
142✔
1030
            }
142✔
1031
            if (g_filedata_logger_enabled && txd->files_opened != txd->files_stored) {
11,360✔
UNCOV
1032
                skipped = true;
×
UNCOV
1033
                goto next;
×
UNCOV
1034
            }
×
1035
        }
11,360✔
1036

1037
        /* if we are here, the tx can be freed. */
1038
        p->StateTransactionFree(alstate, i);
186,856✔
1039
        SCLogDebug("%p/%"PRIu64" freed", tx, i);
186,856✔
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);
186,856✔
1043
        if (!skipped)
186,856✔
1044
            new_min = i + 1;
89,063✔
1045
        SCLogDebug("final i %"PRIu64", new_min %"PRIu64, i, new_min);
186,856✔
1046

1047
next:
4,389,900✔
1048
        if (!ires.has_next) {
4,389,900✔
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);
498,579✔
1053
            if (!skipped) {
498,579✔
1054
                new_min = total_txs;
55,767✔
1055
                SCLogDebug("no next: cur tx i %"PRIu64", total %"PRIu64": "
55,767✔
1056
                        "new_min updated to %"PRIu64, i, total_txs, new_min);
55,767✔
1057
            }
55,767✔
1058
            break;
498,579✔
1059
        }
498,579✔
1060
        i++;
3,891,321✔
1061
    }
3,891,321✔
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);
735,267✔
1065
    if (new_min > alparser->min_id) {
735,267✔
1066
        const uint64_t next_id = new_min;
81,754✔
1067
        alparser->min_id = next_id;
81,754✔
1068
        alparser->inspect_id[0] = MAX(alparser->inspect_id[0], next_id);
81,754✔
1069
        alparser->inspect_id[1] = MAX(alparser->inspect_id[1], next_id);
81,754✔
1070
        alparser->log_id = MAX(alparser->log_id, next_id);
81,754✔
1071
        SCLogDebug("updated f->alparser->min_id %"PRIu64, alparser->min_id);
81,754✔
1072
    }
81,754✔
1073
    SCReturn;
735,267✔
1074
}
735,267✔
1075

1076
static inline int StateGetProgressCompletionStatus(const AppProto alproto, const uint8_t flags)
1077
{
3,927,939✔
1078
    if (flags & STREAM_TOSERVER) {
3,927,939✔
1079
        return alp_ctx.ctxs[alproto][FLOW_PROTO_DEFAULT].complete_ts;
1,984,029✔
1080
    } else if (flags & STREAM_TOCLIENT) {
1,984,029✔
1081
        return alp_ctx.ctxs[alproto][FLOW_PROTO_DEFAULT].complete_tc;
1,943,910✔
1082
    } else {
1,943,910✔
UNCOV
1083
        DEBUG_VALIDATE_BUG_ON(1);
×
UNCOV
1084
        return 0;
×
UNCOV
1085
    }
×
1086
}
3,927,939✔
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
{
20,606,782✔
1096
    SCEnter();
20,606,782✔
1097
    int r;
20,606,782✔
1098
    if (unlikely(IS_DISRUPTED(flags))) {
20,606,782✔
1099
        r = StateGetProgressCompletionStatus(alproto, flags);
389✔
1100
    } else {
20,606,393✔
1101
        uint8_t direction = flags & (STREAM_TOCLIENT | STREAM_TOSERVER);
20,606,393✔
1102
        r = alp_ctx.ctxs[alproto][FlowGetProtoMapping(ipproto)].StateGetProgress(
20,606,393✔
1103
                alstate, direction);
20,606,393✔
1104
    }
20,606,393✔
1105
    SCReturnInt(r);
20,606,782✔
1106
}
20,606,782✔
1107

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

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

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

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

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

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

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

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

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

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

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

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

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

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

1220
static inline void SetEOFFlags(AppLayerParserState *pstate, const uint8_t flags)
1221
{
539,504✔
1222
    if ((flags & (STREAM_EOF|STREAM_TOSERVER)) == (STREAM_EOF|STREAM_TOSERVER)) {
539,504✔
1223
        SCLogDebug("setting APP_LAYER_PARSER_EOF_TS");
7,468✔
1224
        SCAppLayerParserStateSetFlag(pstate, APP_LAYER_PARSER_EOF_TS);
7,468✔
1225
    } else if ((flags & (STREAM_EOF|STREAM_TOCLIENT)) == (STREAM_EOF|STREAM_TOCLIENT)) {
532,036✔
1226
        SCLogDebug("setting APP_LAYER_PARSER_EOF_TC");
7,221✔
1227
        SCAppLayerParserStateSetFlag(pstate, APP_LAYER_PARSER_EOF_TC);
7,221✔
1228
    }
7,221✔
1229
}
539,504✔
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
{
539,493✔
1238
    const uint8_t direction = (flags & STREAM_TOSERVER) ? 0 : 1;
539,493✔
1239
    AppLayerParserState *pstate = f->alparser;
539,493✔
1240

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

1251
            frame = AppLayerFrameNewByAbsoluteOffset(
42,803✔
1252
                    f, &stream_slice, stream_slice.offset, frame_len, direction, FRAME_STREAM_TYPE);
42,803✔
1253
            if (frame) {
42,803✔
1254
                SCLogDebug("opened: frame %p id %" PRIi64, frame, frame->id);
20,152✔
1255
                frame->flags = FRAME_FLAG_ENDS_AT_EOF; // TODO logic is not yet implemented
20,152✔
1256
                DEBUG_VALIDATE_BUG_ON(
20,152✔
1257
                        frame->id != 1); // should always be the first frame that is created
20,152✔
1258
            }
20,152✔
1259
            if (direction == 0) {
42,803✔
1260
                pstate->flags |= APP_LAYER_PARSER_SFRAME_TS;
22,734✔
1261
            } else {
22,734✔
1262
                pstate->flags |= APP_LAYER_PARSER_SFRAME_TC;
20,069✔
1263
            }
20,069✔
1264
        }
42,803✔
1265
    } else if (flags & STREAM_EOF) {
496,690✔
1266
        Frame *frame = AppLayerFrameGetLastOpenByType(f, direction, FRAME_STREAM_TYPE);
13,361✔
1267
        SCLogDebug("EOF closing: frame %p", frame);
13,361✔
1268
        if (frame) {
13,361✔
1269
            /* calculate final frame length */
1270
            int64_t slice_o = (int64_t)stream_slice.offset - (int64_t)frame->offset;
7,401✔
1271
            int64_t frame_len = slice_o + (int64_t)input_len;
7,401✔
1272
            SCLogDebug("%s: EOF frame->offset %" PRIu64 " -> %" PRIi64 ": o %" PRIi64,
7,401✔
1273
                    AppProtoToString(f->alproto), frame->offset, frame_len, slice_o);
7,401✔
1274
            frame->len = frame_len;
7,401✔
1275
        }
7,401✔
1276
    }
13,361✔
1277
}
539,493✔
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
{
539,493✔
1282
    memset(as, 0, sizeof(*as));
539,493✔
1283
    as->input = input;
539,493✔
1284
    as->input_len = input_len;
539,493✔
1285
    as->flags = flags;
539,493✔
1286

1287
    if (f->proto == IPPROTO_TCP && f->protoctx != NULL) {
539,493✔
1288
        TcpSession *ssn = f->protoctx;
493,011✔
1289
        TcpStream *stream = (direction & STREAM_TOSERVER) ? &ssn->client : &ssn->server;
493,011✔
1290
        as->offset = STREAM_APP_PROGRESS(stream);
493,011✔
1291
    }
493,011✔
1292
}
539,493✔
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
{
551,828✔
1300
    SCEnter();
551,828✔
1301
#ifdef DEBUG_VALIDATION
1302
    BUG_ON(f->protomap != FlowGetProtoMapping(f->proto));
1303
#endif
1304
    AppLayerParserState *pstate = f->alparser;
551,828✔
1305
    AppLayerParserProtoCtx *p = &alp_ctx.ctxs[alproto][f->protomap];
551,828✔
1306
    StreamSlice stream_slice;
551,828✔
1307
    void *alstate = NULL;
551,828✔
1308
    uint64_t p_tx_cnt = 0;
551,828✔
1309
    uint32_t consumed = input_len;
551,828✔
1310
    const uint8_t direction = (flags & STREAM_TOSERVER) ? 0 : 1;
551,828✔
1311

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

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

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

1340
    SetEOFFlags(pstate, flags);
539,504✔
1341

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

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

1368
    p_tx_cnt = AppLayerParserGetTxCnt(f, f->alstate);
539,504✔
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)) {
539,504✔
1372
        Setup(f, flags & (STREAM_TOSERVER | STREAM_TOCLIENT), input, input_len, flags,
539,493✔
1373
                &stream_slice);
539,493✔
1374
        HandleStreamFrames(f, stream_slice, input, input_len, flags);
539,493✔
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,
539,493✔
1394
                alp_tctx->alproto_local_storage[alproto][f->protomap]);
539,493✔
1395
        if (res.status < 0) {
539,493✔
1396
            AppLayerIncParserErrorCounter(tv, f);
4,260✔
1397
            goto error;
4,260✔
1398
        } else if (res.status > 0) {
535,233✔
1399
            DEBUG_VALIDATE_BUG_ON(res.consumed > input_len);
9,043✔
1400
            DEBUG_VALIDATE_BUG_ON(res.needed + res.consumed < input_len);
9,043✔
1401
            DEBUG_VALIDATE_BUG_ON(res.needed == 0);
9,043✔
1402
            /* incomplete is only supported for TCP */
1403
            DEBUG_VALIDATE_BUG_ON(f->proto != IPPROTO_TCP);
9,043✔
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) {
9,043✔
1408
                AppLayerIncInternalErrorCounter(tv, f);
×
1409
                goto error;
×
1410
            }
×
1411

1412
            if (f->proto == IPPROTO_TCP && f->protoctx != NULL) {
9,043✔
1413
                TcpSession *ssn = f->protoctx;
9,043✔
1414
                SCLogDebug("direction %d/%s", direction,
9,043✔
1415
                        (flags & STREAM_TOSERVER) ? "toserver" : "toclient");
9,043✔
1416
                if (direction == 0) {
9,043✔
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;
3,772✔
1421
                    SCLogDebug("setting data_required %u", ssn->client.data_required);
3,772✔
1422
                } else {
5,271✔
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;
5,271✔
1427
                    SCLogDebug("setting data_required %u", ssn->server.data_required);
5,271✔
1428
                }
5,271✔
1429
            }
9,043✔
1430
            consumed = res.consumed;
9,043✔
1431
        }
9,043✔
1432
    }
539,493✔
1433

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

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

1441
            /* Set the no reassembly flag for both the stream in this TcpSession */
1442
            if (pstate->flags & APP_LAYER_PARSER_NO_REASSEMBLY) {
34✔
1443
                /* Used only if it's TCP */
UNCOV
1444
                TcpSession *ssn = f->protoctx;
×
UNCOV
1445
                if (ssn != NULL) {
×
UNCOV
1446
                    StreamTcpSetSessionNoReassemblyFlag(ssn, 0);
×
UNCOV
1447
                    StreamTcpSetSessionNoReassemblyFlag(ssn, 1);
×
UNCOV
1448
                }
×
UNCOV
1449
            }
×
1450
            /* Set the bypass flag for both the stream in this TcpSession */
1451
            if (pstate->flags & APP_LAYER_PARSER_BYPASS_READY) {
34✔
1452
                /* Used only if it's TCP */
UNCOV
1453
                TcpSession *ssn = f->protoctx;
×
UNCOV
1454
                if (ssn != NULL) {
×
UNCOV
1455
                    StreamTcpSetSessionBypassFlag(ssn);
×
UNCOV
1456
                }
×
UNCOV
1457
            }
×
1458
        } else {
661✔
1459
            // for TCP, this is set after flushing
1460
            FlowSetNoPayloadInspectionFlag(f);
661✔
1461
        }
661✔
1462
    }
695✔
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) {
535,244✔
1466
        FlowSetNoPayloadInspectionFlag(f);
1,478✔
1467
        /* Set the no reassembly flag for both the stream in this TcpSession */
1468
        if (f->proto == IPPROTO_TCP) {
1,478✔
1469
            /* Used only if it's TCP */
1470
            TcpSession *ssn = f->protoctx;
1,478✔
1471
            if (ssn != NULL) {
1,478✔
1472
                StreamTcpSetDisableRawReassemblyFlag(ssn, 0);
1,478✔
1473
                StreamTcpSetDisableRawReassemblyFlag(ssn, 1);
1,478✔
1474
            }
1,478✔
1475
        }
1,478✔
1476
    }
1,478✔
1477

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

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

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

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

1507
    if (pstate == NULL)
5,751✔
1508
        goto end;
7✔
1509

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

1513
 end:
5,751✔
1514
    SCReturn;
5,751✔
1515
}
5,744✔
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
{
2,257,252✔
1521
    SCEnter();
2,257,252✔
1522

1523
    if (pstate == NULL)
2,257,252✔
1524
        return false;
289,789✔
1525

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

1530
    /* if we have reached here, we don't have events */
1531
    return false;
1,967,463✔
1532
}
1,967,463✔
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
{
210✔
1539
    for (int i = 0; i < FLOW_PROTO_APPLAYER_MAX; i++) {
263✔
1540
        if (alp_ctx.ctxs[alproto][i].StateGetProgress != NULL) {
263✔
1541
            return 1;
210✔
1542
        }
210✔
1543
    }
263✔
UNCOV
1544
    return 0;
×
1545
}
210✔
1546

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

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

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

1567
    SCLogDebug("f %p tcp %p direction %d", f, f ? f->protoctx : NULL, direction);
156,637✔
1568
    if (f != NULL && f->protoctx != NULL)
156,637✔
1569
        StreamTcpReassembleTriggerRawInspection(f->protoctx, direction);
152,862✔
1570

1571
    SCReturn;
156,637✔
1572
}
156,637✔
1573

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

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

1582
    SCReturn;
38✔
1583
}
38✔
1584

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

1590
void AppLayerParserSetStreamDepthFlag(uint8_t ipproto, AppProto alproto, void *state, uint64_t tx_id, uint8_t flags)
1591
{
708✔
1592
    SCEnter();
708✔
1593
    void *tx = NULL;
708✔
1594
    if (state != NULL) {
708✔
1595
        if ((tx = AppLayerParserGetTx(ipproto, alproto, state, tx_id)) != NULL) {
708✔
1596
            if (alp_ctx.ctxs[alproto][FlowGetProtoMapping(ipproto)].SetStreamDepthFlag != NULL) {
708✔
1597
                alp_ctx.ctxs[alproto][FlowGetProtoMapping(ipproto)].SetStreamDepthFlag(tx, flags);
152✔
1598
            }
152✔
1599
        }
708✔
1600
    }
708✔
1601
    SCReturn;
708✔
1602
}
708✔
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
{
475✔
1611
    if (alp_ctx.ctxs[alproto][FlowGetProtoMapping(ipproto)].GetStateIdByName != NULL) {
475✔
1612
        return alp_ctx.ctxs[alproto][FlowGetProtoMapping(ipproto)].GetStateIdByName(
373✔
1613
                name, direction);
373✔
1614
    } else {
373✔
1615
        return -1;
102✔
1616
    }
102✔
1617
}
475✔
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
{
67,879✔
1626
    if (alp_ctx.ctxs[alproto][FlowGetProtoMapping(ipproto)].GetStateNameById != NULL) {
67,879✔
1627
        return alp_ctx.ctxs[alproto][FlowGetProtoMapping(ipproto)].GetStateNameById(id, direction);
6,407✔
1628
    } else {
61,472✔
1629
        return NULL;
61,472✔
1630
    }
61,472✔
1631
}
67,879✔
1632

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

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

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

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

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

1660
    if (ctx->StateFree != NULL && alstate != NULL)
77,069✔
1661
        ctx->StateFree(alstate);
34,040✔
1662

1663
    /* free the app layer parser api state */
1664
    if (pstate != NULL)
77,069✔
1665
        AppLayerParserStateFree(pstate);
34,040✔
1666

1667
    SCReturn;
77,069✔
1668
}
77,069✔
1669

1670
void AppLayerParserStateCleanup(const Flow *f, void *alstate, AppLayerParserState *pstate)
1671
{
76,041✔
1672
    AppLayerParserStateProtoCleanup(f->protomap, f->alproto, alstate, pstate);
76,041✔
1673
}
76,041✔
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,330✔
1698
#define BOTH_SET_OR_BOTH_UNSET(a, b) (((a) == NULL && (b) == NULL) || ((a) != NULL && (b) != NULL))
1,165✔
1699
#define THREE_SET(a, b, c) ((a) != NULL && (b) != NULL && (c) != NULL)
1,165✔
1700

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

1706
    if (ctx->Parser[0] == NULL && ctx->Parser[1] == NULL)
2,480✔
1707
        return;
1,315✔
1708

1709
    if (!(BOTH_SET(ctx->Parser[0], ctx->Parser[1]))) {
1,165✔
1710
        goto bad;
×
1711
    }
×
1712
    if (!(BOTH_SET(ctx->StateFree, ctx->StateAlloc))) {
1,165✔
1713
        goto bad;
×
1714
    }
×
1715
    if (!(THREE_SET(ctx->StateGetTx, ctx->StateGetTxCnt, ctx->StateTransactionFree))) {
1,165✔
1716
        goto bad;
×
1717
    }
×
1718
    if (ctx->StateGetProgress == NULL) {
1,165✔
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,165✔
1723
        goto bad;
×
1724
    }
×
1725
    if (ctx->GetTxData == NULL) {
1,165✔
1726
        goto bad;
×
1727
    }
×
1728
    if (ctx->GetStateData == NULL) {
1,165✔
1729
        goto bad;
×
1730
    }
×
1731
    return;
1,165✔
1732
bad:
1,165✔
1733
    ValidateParserProtoDump(alproto, ipproto);
×
1734
    exit(EXIT_FAILURE);
×
1735
}
1,165✔
1736
#undef BOTH_SET
1737
#undef BOTH_SET_OR_BOTH_UNSET
1738
#undef THREE_SET
1739

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

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

1754
#define ARRAY_CAP_STEP 16
62✔
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
{
31✔
1761
    if (alp_ctx.ctxs_len <= alproto && alproto < g_alproto_max) {
31✔
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]) *
31✔
1765
                                                    (alp_ctx.ctxs_len + ARRAY_CAP_STEP));
31✔
1766
        if (unlikely(tmp == NULL)) {
31✔
1767
            FatalError("Unable to realloc alp_ctx.ctxs.");
×
1768
        }
×
1769
        alp_ctx.ctxs = tmp;
31✔
1770
        memset(&alp_ctx.ctxs[alp_ctx.ctxs_len], 0,
31✔
1771
                sizeof(AppLayerParserProtoCtx[FLOW_PROTO_MAX]) * ARRAY_CAP_STEP);
31✔
1772
        alp_ctx.ctxs_len += ARRAY_CAP_STEP;
31✔
1773
    }
31✔
1774
    return 0;
31✔
1775
}
31✔
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
{
31✔
1795
    SCEnter();
31✔
1796

1797
    AppLayerConfig();
31✔
1798

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

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

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

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

1852
/* coccinelle: SCAppLayerParserStateIssetFlag():2,2:APP_LAYER_PARSER_ */
1853
uint16_t SCAppLayerParserStateIssetFlag(AppLayerParserState *pstate, uint16_t flag)
1854
{
3,135,976✔
1855
    SCEnter();
3,135,976✔
1856
    SCReturnUInt(pstate->flags & flag);
3,135,976✔
1857
}
3,135,976✔
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
{
1867
    SCEnter();
1868
    alp_ctx.ctxs[alproto][FlowGetProtoMapping(ipproto)].RegisterUnittests = RegisterUnittests;
1869
    SCReturn;
1870
}
1871

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

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

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

1889
    SCReturn;
1890
}
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