suricata
app-layer-parser.c
Go to the documentation of this file.
1 /* Copyright (C) 2007-2025 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 
61  void *(*alproto_local_storage)[FLOW_PROTO_MAX];
62 };
63 
64 
65 /**
66  * \brief App layer protocol parser context.
67  */
69 {
70  /* 0 - to_server, 1 - to_client. */
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);
99  uint8_t event_id, const char **event_name, AppLayerEventType *event_type);
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 
111 
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
129 
130 typedef struct AppLayerParserCtx_ {
132  size_t ctxs_len;
134 
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. */
151 
153 };
154 
156 
157 static void AppLayerConfig(void)
158 {
159  g_applayerparser_error_policy = ExceptionPolicyParse("app-layer.error-policy", true);
160 }
161 
163 {
165 }
166 
167 static void AppLayerParserFramesFreeContainer(FramesContainer *frames)
168 {
169  if (frames != NULL) {
170  FramesFree(&frames->toserver);
171  FramesFree(&frames->toclient);
172  SCFree(frames);
173  }
174 }
175 
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 
185 {
186  if (f == NULL || f->alparser == NULL)
187  return NULL;
188  return f->alparser->frames;
189 }
190 
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 {
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 {
230  uint8_t ipproto_map = FlowGetProtoMapping(ipproto);
231 
232  return (alp_ctx.ctxs[alproto][ipproto_map].StateAlloc != NULL) ? 1 : 0;
233 }
234 
236 {
237  SCEnter();
238 
239  AppLayerParserState *pstate = (AppLayerParserState *)SCCalloc(1, sizeof(*pstate));
240  if (pstate == NULL)
241  goto end;
242 
243  end:
244  SCReturnPtr(pstate, "AppLayerParserState");
245 }
246 
248 {
249  SCEnter();
250 
251  if (pstate->decoder_events != NULL)
253  AppLayerParserFramesFreeContainer(pstate->frames);
254  SCFree(pstate);
255 
256  SCReturn;
257 }
258 
260 {
261  SCEnter();
262  // initial allocation that will later be grown using realloc,
263  // when new protocols register themselves and make g_alproto_max grow
265  if (unlikely(alp_ctx.ctxs == NULL)) {
266  FatalError("Unable to alloc alp_ctx.ctxs.");
267  }
268  alp_ctx.ctxs_len = g_alproto_max;
269  SCReturnInt(0);
270 }
271 
273 {
274  /* lets set a default value for stream_depth */
275  for (int flow_proto = 0; flow_proto < FLOW_PROTO_DEFAULT; flow_proto++) {
276  for (AppProto alproto = 0; alproto < g_alproto_max; alproto++) {
277  if (!(alp_ctx.ctxs[alproto][flow_proto].internal_flags &
279  alp_ctx.ctxs[alproto][flow_proto].stream_depth = stream_config.reassembly_depth;
280  }
281  }
282  }
283 }
284 
286 {
287  SCEnter();
288 
289  SCFree(alp_ctx.ctxs);
290 
293 
294  SCReturnInt(0);
295 }
296 
298 {
299  SCEnter();
300 
301  AppLayerParserThreadCtx *tctx = SCCalloc(1, sizeof(*tctx));
302  if (tctx == NULL)
303  goto end;
304 
306  if (unlikely(tctx->alproto_local_storage == NULL)) {
307  SCFree(tctx);
308  tctx = NULL;
309  goto end;
310  }
311  for (uint8_t flow_proto = 0; flow_proto < FLOW_PROTO_DEFAULT; flow_proto++) {
312  for (AppProto alproto = 0; alproto < g_alproto_max; alproto++) {
313  uint8_t ipproto = FlowGetReverseProtoMapping(flow_proto);
314 
315  tctx->alproto_local_storage[alproto][flow_proto] =
317  }
318  }
319 
320  end:
321  SCReturnPtr(tctx, "void *");
322 }
323 
325 {
326  SCEnter();
327 
328  for (uint8_t flow_proto = 0; flow_proto < FLOW_PROTO_DEFAULT; flow_proto++) {
329  for (AppProto alproto = 0; alproto < g_alproto_max; alproto++) {
330  uint8_t ipproto = FlowGetReverseProtoMapping(flow_proto);
331 
333  ipproto, alproto, tctx->alproto_local_storage[alproto][flow_proto]);
334  }
335  }
336 
338  SCFree(tctx);
339  SCReturn;
340 }
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 {
347  SCEnter();
348 
349  int enabled = 1;
350  char param[100];
351  SCConfNode *node;
352  int r;
353 
354  if (RunmodeIsUnittests())
355  goto enabled;
356 
357  r = snprintf(param, sizeof(param), "%s%s%s", "app-layer.protocols.",
358  alproto_name, ".enabled");
359  if (r < 0) {
360  FatalError("snprintf failure.");
361  } else if (r > (int)sizeof(param)) {
362  FatalError("buffer not big enough to write param.");
363  }
364 
365  node = SCConfGetNode(param);
366  if (node == NULL) {
367  SCLogDebug("Entry for %s not found.", param);
368  r = snprintf(param, sizeof(param), "%s%s%s%s%s", "app-layer.protocols.",
369  alproto_name, ".", ipproto, ".enabled");
370  if (r < 0) {
371  FatalError("snprintf failure.");
372  } else if (r > (int)sizeof(param)) {
373  FatalError("buffer not big enough to write param.");
374  }
375 
376  node = SCConfGetNode(param);
377  if (node == NULL) {
378  SCLogDebug("Entry for %s not found.", param);
379  goto enabled;
380  }
381  }
382 
383  if (SCConfValIsTrue(node->val)) {
384  goto enabled;
385  } else if (SCConfValIsFalse(node->val)) {
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:
397  SCReturnInt(enabled);
398 }
399 
400 /***** Parser related registration *****/
401 
402 int AppLayerParserRegisterParser(uint8_t ipproto, AppProto alproto,
403  uint8_t direction,
404  AppLayerParserFPtr Parser)
405 {
406  SCEnter();
407 
408  alp_ctx.ctxs[alproto][FlowGetProtoMapping(ipproto)]
409  .Parser[(direction & STREAM_TOSERVER) ? 0 : 1] = Parser;
410 
411  SCReturnInt(0);
412 }
413 
415  uint8_t ipproto, AppProto alproto, uint8_t direction)
416 {
417  SCEnter();
418 
419  alp_ctx.ctxs[alproto][FlowGetProtoMapping(ipproto)].first_data_dir |=
420  (direction & (STREAM_TOSERVER | STREAM_TOCLIENT));
421 
422  SCReturn;
423 }
424 
425 void AppLayerParserRegisterOptionFlags(uint8_t ipproto, AppProto alproto,
426  uint32_t flags)
427 {
428  SCEnter();
429 
430  alp_ctx.ctxs[alproto][FlowGetProtoMapping(ipproto)].option_flags |= flags;
431 
432  SCReturn;
433 }
434 
435 void AppLayerParserRegisterStateFuncs(uint8_t ipproto, AppProto alproto,
436  void *(*StateAlloc)(void *, AppProto), void (*StateFree)(void *))
437 {
438  SCEnter();
439 
440  alp_ctx.ctxs[alproto][FlowGetProtoMapping(ipproto)].StateAlloc = StateAlloc;
441  alp_ctx.ctxs[alproto][FlowGetProtoMapping(ipproto)].StateFree = StateFree;
442 
443  SCReturn;
444 }
445 
446 void AppLayerParserRegisterLocalStorageFunc(uint8_t ipproto, AppProto alproto,
447  void *(*LocalStorageAlloc)(void),
448  void (*LocalStorageFree)(void *))
449 {
450  SCEnter();
451 
452  alp_ctx.ctxs[alproto][FlowGetProtoMapping(ipproto)].LocalStorageAlloc = LocalStorageAlloc;
453  alp_ctx.ctxs[alproto][FlowGetProtoMapping(ipproto)].LocalStorageFree = LocalStorageFree;
454 
455  SCReturn;
456 }
457 
459  uint8_t ipproto, AppProto alproto, AppLayerGetFileState (*GetTxFiles)(void *, uint8_t))
460 {
461  SCEnter();
462 
463  alp_ctx.ctxs[alproto][FlowGetProtoMapping(ipproto)].GetTxFiles = GetTxFiles;
464 
465  SCReturn;
466 }
467 
468 void AppLayerParserRegisterLoggerBits(uint8_t ipproto, AppProto alproto, LoggerId bits)
469 {
470  SCEnter();
471 
472  alp_ctx.ctxs[alproto][FlowGetProtoMapping(ipproto)].logger_bits = bits;
473 
474  SCReturn;
475 }
476 
477 void SCAppLayerParserRegisterLogger(uint8_t ipproto, AppProto alproto)
478 {
479  SCEnter();
480 
481  alp_ctx.ctxs[alproto][FlowGetProtoMapping(ipproto)].logger = true;
482 
483  SCReturn;
484 }
485 
487  int (*StateGetProgress)(void *alstate, uint8_t direction))
488 {
489  SCEnter();
490 
491  alp_ctx.ctxs[alproto][FlowGetProtoMapping(ipproto)].StateGetProgress = StateGetProgress;
492 
493  SCReturn;
494 }
495 
496 void AppLayerParserRegisterTxFreeFunc(uint8_t ipproto, AppProto alproto,
497  void (*StateTransactionFree)(void *, uint64_t))
498 {
499  SCEnter();
500 
501  alp_ctx.ctxs[alproto][FlowGetProtoMapping(ipproto)].StateTransactionFree = StateTransactionFree;
502 
503  SCReturn;
504 }
505 
506 void AppLayerParserRegisterGetTxCnt(uint8_t ipproto, AppProto alproto,
507  uint64_t (*StateGetTxCnt)(void *alstate))
508 {
509  SCEnter();
510 
511  alp_ctx.ctxs[alproto][FlowGetProtoMapping(ipproto)].StateGetTxCnt = StateGetTxCnt;
512 
513  SCReturn;
514 }
515 
516 void AppLayerParserRegisterGetTx(uint8_t ipproto, AppProto alproto,
517  void *(StateGetTx)(void *alstate, uint64_t tx_id))
518 {
519  SCEnter();
520 
521  alp_ctx.ctxs[alproto][FlowGetProtoMapping(ipproto)].StateGetTx = StateGetTx;
522 
523  SCReturn;
524 }
525 
526 void AppLayerParserRegisterGetTxIterator(uint8_t ipproto, AppProto alproto,
528 {
529  SCEnter();
530  alp_ctx.ctxs[alproto][FlowGetProtoMapping(ipproto)].StateGetTxIterator = Func;
531  SCReturn;
532 }
533 
535  AppProto alproto, const int ts, const int tc)
536 {
537  BUG_ON(ts == 0);
538  BUG_ON(tc == 0);
539  BUG_ON(!AppProtoIsValid(alproto));
540  BUG_ON(alp_ctx.ctxs[alproto][FLOW_PROTO_DEFAULT].complete_ts != 0 &&
541  alp_ctx.ctxs[alproto][FLOW_PROTO_DEFAULT].complete_ts != ts);
542  BUG_ON(alp_ctx.ctxs[alproto][FLOW_PROTO_DEFAULT].complete_tc != 0 &&
543  alp_ctx.ctxs[alproto][FLOW_PROTO_DEFAULT].complete_tc != tc);
544 
545  alp_ctx.ctxs[alproto][FLOW_PROTO_DEFAULT].complete_ts = ts;
546  alp_ctx.ctxs[alproto][FLOW_PROTO_DEFAULT].complete_tc = tc;
547 }
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 {
553  SCEnter();
554 
555  alp_ctx.ctxs[alproto][FlowGetProtoMapping(ipproto)].StateGetEventInfoById =
556  StateGetEventInfoById;
557 
558  SCReturn;
559 }
560 
561 void AppLayerParserRegisterGetStateFuncs(uint8_t ipproto, AppProto alproto,
562  AppLayerParserGetStateIdByNameFn GetIdByNameFunc,
563  AppLayerParserGetStateNameByIdFn GetNameByIdFunc)
564 {
565  SCEnter();
566  alp_ctx.ctxs[alproto][FlowGetProtoMapping(ipproto)].GetStateIdByName = GetIdByNameFunc;
567  alp_ctx.ctxs[alproto][FlowGetProtoMapping(ipproto)].GetStateNameById = GetNameByIdFunc;
568  SCReturn;
569 }
570 
571 void AppLayerParserRegisterGetFrameFuncs(uint8_t ipproto, AppProto alproto,
572  AppLayerParserGetFrameIdByNameFn GetIdByNameFunc,
573  AppLayerParserGetFrameNameByIdFn GetNameByIdFunc)
574 {
575  SCEnter();
576  alp_ctx.ctxs[alproto][FlowGetProtoMapping(ipproto)].GetFrameIdByName = GetIdByNameFunc;
577  alp_ctx.ctxs[alproto][FlowGetProtoMapping(ipproto)].GetFrameNameById = GetNameByIdFunc;
578  SCReturn;
579 }
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 {
585  SCEnter();
586 
587  alp_ctx.ctxs[alproto][FlowGetProtoMapping(ipproto)].StateGetEventInfo = StateGetEventInfo;
588 
589  SCReturn;
590 }
591 
592 void AppLayerParserRegisterTxDataFunc(uint8_t ipproto, AppProto alproto,
593  AppLayerTxData *(*GetTxData)(void *tx))
594 {
595  SCEnter();
596 
597  alp_ctx.ctxs[alproto][FlowGetProtoMapping(ipproto)].GetTxData = GetTxData;
598 
599  SCReturn;
600 }
601 
603  uint8_t ipproto, AppProto alproto, AppLayerStateData *(*GetStateData)(void *state))
604 {
605  SCEnter();
606 
607  alp_ctx.ctxs[alproto][FlowGetProtoMapping(ipproto)].GetStateData = GetStateData;
608 
609  SCReturn;
610 }
611 
612 void AppLayerParserRegisterApplyTxConfigFunc(uint8_t ipproto, AppProto alproto,
613  void (*ApplyTxConfig)(void *state, void *tx, int mode, AppLayerTxConfig))
614 {
615  SCEnter();
616 
617  alp_ctx.ctxs[alproto][FlowGetProtoMapping(ipproto)].ApplyTxConfig = ApplyTxConfig;
618 
619  SCReturn;
620 }
621 
623  void (*SetStreamDepthFlag)(void *tx, uint8_t flags))
624 {
625  SCEnter();
626 
627  alp_ctx.ctxs[alproto][FlowGetProtoMapping(ipproto)].SetStreamDepthFlag = SetStreamDepthFlag;
628 
629  SCReturn;
630 }
631 
632 /***** Get and transaction functions *****/
633 
635 {
636  SCEnter();
637  void * r = NULL;
638 
639  if (alp_ctx.ctxs[alproto][FlowGetProtoMapping(ipproto)].LocalStorageAlloc != NULL) {
640  r = alp_ctx.ctxs[alproto][FlowGetProtoMapping(ipproto)].LocalStorageAlloc();
641  }
642 
643  SCReturnPtr(r, "void *");
644 }
645 
647  void *local_data)
648 {
649  SCEnter();
650 
651  if (alp_ctx.ctxs[alproto][FlowGetProtoMapping(ipproto)].LocalStorageFree != NULL) {
652  alp_ctx.ctxs[alproto][FlowGetProtoMapping(ipproto)].LocalStorageFree(local_data);
653  }
654 
655  SCReturn;
656 }
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 {
671  uint64_t ustate = *(uint64_t *)state;
672  uint64_t tx_id = MAX(min_tx_id, ustate);
673  for ( ; tx_id < max_tx_id; tx_id++) {
674  void *tx_ptr = AppLayerParserGetTx(ipproto, alproto, alstate, tx_id);
675  if (tx_ptr != NULL) {
676  ustate = tx_id + 1;
677  *state = *(AppLayerGetTxIterState *)&ustate;
678  AppLayerGetTxIterTuple tuple = {
679  .tx_ptr = tx_ptr,
680  .tx_id = tx_id,
681  .has_next = (tx_id + 1 < max_tx_id),
682  };
683  SCLogDebug("tuple: %p/%"PRIu64"/%s", tuple.tx_ptr, tuple.tx_id,
684  tuple.has_next ? "true" : "false");
685  return tuple;
686  }
687  }
688 
689  AppLayerGetTxIterTuple no_tuple = { NULL, 0, false };
690  return no_tuple;
691 }
692 
694  const AppProto alproto)
695 {
697  alp_ctx.ctxs[alproto][FlowGetProtoMapping(ipproto)].StateGetTxIterator;
698  return Func ? Func : AppLayerDefaultGetTxIterator;
699 }
700 
702 {
703  SCEnter();
704 
705  SCReturnCT((pstate == NULL) ? 0 : pstate->log_id, "uint64_t");
706 }
707 
709 {
710  SCEnter();
711 
712  SCReturnCT((pstate == NULL) ? 0 : pstate->min_id, "uint64_t");
713 }
714 
716 {
717  SCEnter();
718 
719  if (pstate != NULL)
720  pstate->log_id = tx_id;
721 
722  SCReturn;
723 }
724 
725 uint64_t AppLayerParserGetTransactionInspectId(AppLayerParserState *pstate, uint8_t direction)
726 {
727  SCEnter();
728 
729  if (pstate != NULL)
730  SCReturnCT(pstate->inspect_id[(direction & STREAM_TOSERVER) ? 0 : 1], "uint64_t");
731 
733  SCReturnCT(0ULL, "uint64_t");
734 }
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 {
744  return txd->logged;
745 }
746 
748  void *alstate, const uint8_t flags,
749  bool tag_txs_as_inspected)
750 {
751  SCEnter();
752 
753  const int direction = (flags & STREAM_TOSERVER) ? 0 : 1;
754  const uint64_t total_txs = AppLayerParserGetTxCnt(f, alstate);
755  uint64_t idx = AppLayerParserGetTransactionInspectId(pstate, flags);
756  const int state_done_progress = AppLayerParserGetStateProgressCompletionStatus(f->alproto, flags);
757  const uint8_t ipproto = f->proto;
758  const AppProto alproto = f->alproto;
759 
760  AppLayerGetTxIteratorFunc IterFunc = AppLayerGetTxIterator(ipproto, alproto);
761  AppLayerGetTxIterState state = { 0 };
762 
763  SCLogDebug("called: %s, tag_txs_as_inspected %s",direction==0?"toserver":"toclient",
764  tag_txs_as_inspected?"true":"false");
765 
766  /* mark all txs as inspected if the applayer progress is
767  * at the 'end state'. */
768  while (1) {
769  AppLayerGetTxIterTuple ires = IterFunc(ipproto, alproto, alstate, idx, total_txs, &state);
770  if (ires.tx_ptr == NULL)
771  break;
772 
773  void *tx = ires.tx_ptr;
774  idx = ires.tx_id;
775 
776  int state_progress = AppLayerParserGetStateProgress(ipproto, alproto, tx, flags);
777  if (state_progress < state_done_progress)
778  break;
779 
780  AppLayerTxData *txd = AppLayerParserGetTxData(ipproto, alproto, tx);
781  if (tag_txs_as_inspected) {
782  const uint8_t inspected_flag = (flags & STREAM_TOSERVER) ? APP_LAYER_TX_INSPECTED_TS
784  if (txd->flags & inspected_flag) {
785  txd->flags |= inspected_flag;
786  SCLogDebug("%p/%" PRIu64 " in-order tx is done for direction %s. Flags %02x", tx,
787  idx, flags & STREAM_TOSERVER ? "toserver" : "toclient", txd->flags);
788  }
789  }
790  idx++;
791  if (!ires.has_next)
792  break;
793  }
794  pstate->inspect_id[direction] = idx;
795  SCLogDebug("inspect_id now %"PRIu64, pstate->inspect_id[direction]);
796 
797  /* if necessary we flag all txs that are complete as 'inspected'
798  * also move inspect_id forward. */
799  if (tag_txs_as_inspected) {
800  /* continue at idx */
801  while (1) {
802  AppLayerGetTxIterTuple ires = IterFunc(ipproto, alproto, alstate, idx, total_txs, &state);
803  if (ires.tx_ptr == NULL)
804  break;
805 
806  void *tx = ires.tx_ptr;
807  /* if we got a higher id than the minimum we requested, we
808  * skipped a bunch of 'null-txs'. Lets see if we can up the
809  * inspect tracker */
810  if (ires.tx_id > idx && pstate->inspect_id[direction] == idx) {
811  pstate->inspect_id[direction] = ires.tx_id;
812  }
813  idx = ires.tx_id;
814 
815  const int state_progress = AppLayerParserGetStateProgress(ipproto, alproto, tx, flags);
816  if (state_progress < state_done_progress)
817  break;
818 
819  /* txd can be NULL for HTTP sessions where the user data alloc failed */
820  AppLayerTxData *txd = AppLayerParserGetTxData(ipproto, alproto, tx);
821  const uint8_t inspected_flag = (flags & STREAM_TOSERVER) ? APP_LAYER_TX_INSPECTED_TS
823  if (txd->flags & inspected_flag) {
824  txd->flags |= inspected_flag;
825  SCLogDebug("%p/%" PRIu64 " out of order tx is done for direction %s. Flag %02x", tx,
826  idx, flags & STREAM_TOSERVER ? "toserver" : "toclient", txd->flags);
827 
828  SCLogDebug("%p/%" PRIu64 " out of order tx. Update inspect_id? %" PRIu64, tx, idx,
829  pstate->inspect_id[direction]);
830  if (pstate->inspect_id[direction] + 1 == idx)
831  pstate->inspect_id[direction] = idx;
832  }
833  if (!ires.has_next)
834  break;
835  idx++;
836  }
837  }
838 
839  SCReturn;
840 }
841 
843 {
844  SCEnter();
845 
846  SCReturnPtr(pstate->decoder_events,
847  "AppLayerDecoderEvents *");
848 }
849 
851  void *tx)
852 {
853  SCEnter();
854 
855  AppLayerDecoderEvents *ptr = NULL;
856 
857  /* Access events via the tx_data. */
858  AppLayerTxData *txd = AppLayerParserGetTxData(ipproto, alproto, tx);
859  if (txd->events != NULL) {
860  ptr = txd->events;
861  }
862 
863  SCReturnPtr(ptr, "AppLayerDecoderEvents *");
864 }
865 
866 AppLayerGetFileState AppLayerParserGetTxFiles(const Flow *f, void *tx, const uint8_t direction)
867 {
868  SCEnter();
869 
870  if (alp_ctx.ctxs[f->alproto][f->protomap].GetTxFiles != NULL) {
871  return alp_ctx.ctxs[f->alproto][f->protomap].GetTxFiles(tx, direction);
872  }
873 
874  AppLayerGetFileState files = { .fc = NULL, .cfg = NULL };
875  return files;
876 }
877 
878 static void AppLayerParserFileTxHousekeeping(
879  const Flow *f, void *tx, const uint8_t pkt_dir, const bool trunc)
880 {
881  AppLayerGetFileState files = AppLayerParserGetTxFiles(f, tx, pkt_dir);
882  if (files.fc) {
883  FilesPrune(files.fc, files.cfg, trunc);
884  }
885 }
886 
887 #define IS_DISRUPTED(flags) ((flags) & (STREAM_DEPTH | STREAM_GAP))
888 
889 extern int g_detect_disabled;
890 extern bool g_file_logger_enabled;
891 extern bool g_filedata_logger_enabled;
892 
893 /**
894  * \brief remove obsolete (inspected and logged) transactions
895  */
896 void AppLayerParserTransactionsCleanup(Flow *f, const uint8_t pkt_dir)
897 {
898  SCEnter();
900 
901  AppLayerParserProtoCtx *p = &alp_ctx.ctxs[f->alproto][f->protomap];
902  if (unlikely(p->StateTransactionFree == NULL))
903  SCReturn;
904 
905  const bool has_tx_detect_flags = !g_detect_disabled;
906  const uint8_t ipproto = f->proto;
907  const AppProto alproto = f->alproto;
908  void * const alstate = f->alstate;
909  AppLayerParserState * const alparser = f->alparser;
910 
911  if (alstate == NULL || alparser == NULL)
912  SCReturn;
913 
914  const uint64_t min = alparser->min_id;
915  const uint64_t total_txs = AppLayerParserGetTxCnt(f, alstate);
916  const LoggerId logger_expectation = AppLayerParserProtocolGetLoggerBits(ipproto, alproto);
917  const int tx_end_state_ts = AppLayerParserGetStateProgressCompletionStatus(alproto, STREAM_TOSERVER);
918  const int tx_end_state_tc = AppLayerParserGetStateProgressCompletionStatus(alproto, STREAM_TOCLIENT);
919  const uint8_t ts_disrupt_flags = FlowGetDisruptionFlags(f, STREAM_TOSERVER);
920  const uint8_t tc_disrupt_flags = FlowGetDisruptionFlags(f, STREAM_TOCLIENT);
921 
922  int pkt_dir_trunc = -1;
923 
924  AppLayerGetTxIteratorFunc IterFunc = AppLayerGetTxIterator(ipproto, alproto);
926  memset(&state, 0, sizeof(state));
927  uint64_t i = min;
928  uint64_t new_min = min;
929  SCLogDebug("start min %"PRIu64, min);
930  bool skipped = false;
931  // const bool support_files = AppLayerParserSupportsFiles(f->proto, f->alproto);
932 
933  while (1) {
934  AppLayerGetTxIterTuple ires = IterFunc(ipproto, alproto, alstate, i, total_txs, &state);
935  if (ires.tx_ptr == NULL)
936  break;
937 
938  bool tx_skipped = false;
939  void *tx = ires.tx_ptr;
940  i = ires.tx_id; // actual tx id for the tx the IterFunc returned
941 
942  SCLogDebug("%p/%"PRIu64" checking", tx, i);
943  AppLayerTxData *txd = AppLayerParserGetTxData(ipproto, alproto, tx);
944  if (AppLayerParserHasFilesInDir(txd, pkt_dir)) {
945  if (pkt_dir_trunc == -1)
946  pkt_dir_trunc = IS_DISRUPTED(
947  (pkt_dir == STREAM_TOSERVER) ? ts_disrupt_flags : tc_disrupt_flags);
948  AppLayerParserFileTxHousekeeping(f, tx, pkt_dir, (bool)pkt_dir_trunc);
949  }
950  // should be reset by parser next time it updates the tx
951  if (pkt_dir & STREAM_TOSERVER) {
952  txd->updated_ts = false;
953  } else {
954  txd->updated_tc = false;
955  }
956  const int tx_progress_tc =
957  AppLayerParserGetStateProgress(ipproto, alproto, tx, tc_disrupt_flags);
958  if (tx_progress_tc < tx_end_state_tc) {
959  SCLogDebug("%p/%"PRIu64" skipping: tc parser not done", tx, i);
960  skipped = true;
961  goto next;
962  }
963  const int tx_progress_ts =
964  AppLayerParserGetStateProgress(ipproto, alproto, tx, ts_disrupt_flags);
965  if (tx_progress_ts < tx_end_state_ts) {
966  SCLogDebug("%p/%"PRIu64" skipping: ts parser not done", tx, i);
967  skipped = true;
968  goto next;
969  }
970 
971  if (has_tx_detect_flags) {
972  if (!IS_DISRUPTED(ts_disrupt_flags) &&
973  (f->sgh_toserver != NULL || (f->flags & FLOW_SGH_TOSERVER) == 0)) {
975  0) {
976  SCLogDebug("%p/%" PRIu64 " skipping: TS inspect not done: ts:%02x", tx, i,
977  txd->flags);
978  tx_skipped = true;
979  }
980  }
981  if (!IS_DISRUPTED(tc_disrupt_flags) &&
982  (f->sgh_toclient != NULL || (f->flags & FLOW_SGH_TOCLIENT) == 0)) {
984  0) {
985  SCLogDebug("%p/%" PRIu64 " skipping: TC inspect not done: ts:%02x", tx, i,
986  txd->flags);
987  tx_skipped = true;
988  }
989  }
990  }
991 
992  if (tx_skipped) {
993  SCLogDebug("%p/%" PRIu64 " tx_skipped", tx, i);
994  skipped = true;
995  goto next;
996  }
997 
998  if (logger_expectation != 0) {
999  LoggerId tx_logged = GetTxLogged(txd);
1000  if (tx_logged != logger_expectation) {
1001  SCLogDebug("%p/%"PRIu64" skipping: logging not done: want:%"PRIx32", have:%"PRIx32,
1002  tx, i, logger_expectation, tx_logged);
1003  skipped = true;
1004  goto next;
1005  }
1006  }
1007 
1008  /* if file logging is enabled, we keep a tx active while some of the files aren't
1009  * logged yet. */
1010  SCLogDebug("files_opened %u files_logged %u files_stored %u", txd->files_opened,
1011  txd->files_logged, txd->files_stored);
1012 
1013  if (txd->files_opened) {
1014  if (g_file_logger_enabled && txd->files_opened != txd->files_logged) {
1015  skipped = true;
1016  goto next;
1017  }
1018  if (g_filedata_logger_enabled && txd->files_opened != txd->files_stored) {
1019  skipped = true;
1020  goto next;
1021  }
1022  }
1023 
1024  /* if we are here, the tx can be freed. */
1025  p->StateTransactionFree(alstate, i);
1026  SCLogDebug("%p/%"PRIu64" freed", tx, i);
1027 
1028  /* if we didn't skip any tx so far, up the minimum */
1029  SCLogDebug("skipped? %s i %"PRIu64", new_min %"PRIu64, skipped ? "true" : "false", i, new_min);
1030  if (!skipped)
1031  new_min = i + 1;
1032  SCLogDebug("final i %"PRIu64", new_min %"PRIu64, i, new_min);
1033 
1034 next:
1035  if (!ires.has_next) {
1036  /* this was the last tx. See if we skipped any. If not
1037  * we removed all and can update the minimum to the max
1038  * id. */
1039  SCLogDebug("no next: cur tx i %"PRIu64", total %"PRIu64, i, total_txs);
1040  if (!skipped) {
1041  new_min = total_txs;
1042  SCLogDebug("no next: cur tx i %"PRIu64", total %"PRIu64": "
1043  "new_min updated to %"PRIu64, i, total_txs, new_min);
1044  }
1045  break;
1046  }
1047  i++;
1048  }
1049 
1050  /* see if we need to bring all trackers up to date. */
1051  SCLogDebug("update f->alparser->min_id? %"PRIu64" vs %"PRIu64, new_min, alparser->min_id);
1052  if (new_min > alparser->min_id) {
1053  const uint64_t next_id = new_min;
1054  alparser->min_id = next_id;
1055  alparser->inspect_id[0] = MAX(alparser->inspect_id[0], next_id);
1056  alparser->inspect_id[1] = MAX(alparser->inspect_id[1], next_id);
1057  alparser->log_id = MAX(alparser->log_id, next_id);
1058  SCLogDebug("updated f->alparser->min_id %"PRIu64, alparser->min_id);
1059  }
1060  SCReturn;
1061 }
1062 
1063 static inline int StateGetProgressCompletionStatus(const AppProto alproto, const uint8_t flags)
1064 {
1065  if (flags & STREAM_TOSERVER) {
1066  return alp_ctx.ctxs[alproto][FLOW_PROTO_DEFAULT].complete_ts;
1067  } else if (flags & STREAM_TOCLIENT) {
1068  return alp_ctx.ctxs[alproto][FLOW_PROTO_DEFAULT].complete_tc;
1069  } else {
1071  return 0;
1072  }
1073 }
1074 
1075 /**
1076  * \brief get the progress value for a tx/protocol
1077  *
1078  * If the stream is disrupted, we return the 'completion' value.
1079  */
1080 int AppLayerParserGetStateProgress(uint8_t ipproto, AppProto alproto,
1081  void *alstate, uint8_t flags)
1082 {
1083  SCEnter();
1084  int r;
1085  if (unlikely(IS_DISRUPTED(flags))) {
1086  r = StateGetProgressCompletionStatus(alproto, flags);
1087  } else {
1088  uint8_t direction = flags & (STREAM_TOCLIENT | STREAM_TOSERVER);
1089  r = alp_ctx.ctxs[alproto][FlowGetProtoMapping(ipproto)].StateGetProgress(
1090  alstate, direction);
1091  }
1092  SCReturnInt(r);
1093 }
1094 
1095 uint64_t AppLayerParserGetTxCnt(const Flow *f, void *alstate)
1096 {
1097  SCEnter();
1098  uint64_t r = alp_ctx.ctxs[f->alproto][f->protomap].StateGetTxCnt(alstate);
1099  SCReturnCT(r, "uint64_t");
1100 }
1101 
1102 void *AppLayerParserGetTx(uint8_t ipproto, AppProto alproto, void *alstate, uint64_t tx_id)
1103 {
1104  SCEnter();
1105  void *r = alp_ctx.ctxs[alproto][FlowGetProtoMapping(ipproto)].StateGetTx(alstate, tx_id);
1106  SCReturnPtr(r, "void *");
1107 }
1108 
1110  uint8_t direction)
1111 {
1112  SCEnter();
1113  int r = StateGetProgressCompletionStatus(alproto, direction);
1114  SCReturnInt(r);
1115 }
1116 
1117 int AppLayerParserGetEventInfo(uint8_t ipproto, AppProto alproto, const char *event_name,
1118  uint8_t *event_id, AppLayerEventType *event_type)
1119 {
1120  SCEnter();
1121  const int ipproto_map = FlowGetProtoMapping(ipproto);
1122  int r = (alp_ctx.ctxs[alproto][ipproto_map].StateGetEventInfo == NULL)
1123  ? -1
1124  : alp_ctx.ctxs[alproto][ipproto_map].StateGetEventInfo(
1125  event_name, event_id, event_type);
1126  SCReturnInt(r);
1127 }
1128 
1129 int AppLayerParserGetEventInfoById(uint8_t ipproto, AppProto alproto, uint8_t event_id,
1130  const char **event_name, AppLayerEventType *event_type)
1131 {
1132  SCEnter();
1133  const int ipproto_map = FlowGetProtoMapping(ipproto);
1134  *event_name = (const char *)NULL;
1135  int r = (alp_ctx.ctxs[alproto][ipproto_map].StateGetEventInfoById == NULL)
1136  ? -1
1137  : alp_ctx.ctxs[alproto][ipproto_map].StateGetEventInfoById(
1138  event_id, event_name, event_type);
1139  SCReturnInt(r);
1140 }
1141 
1142 uint8_t AppLayerParserGetFirstDataDir(uint8_t ipproto, AppProto alproto)
1143 {
1144  SCEnter();
1145  uint8_t r = alp_ctx.ctxs[alproto][FlowGetProtoMapping(ipproto)].first_data_dir;
1146  SCReturnCT(r, "uint8_t");
1147 }
1148 
1150  AppLayerParserState *pstate, uint8_t direction)
1151 {
1152  SCEnter();
1153 
1154  uint64_t active_id;
1155  uint64_t log_id = pstate->log_id;
1156  uint64_t inspect_id = pstate->inspect_id[(direction & STREAM_TOSERVER) ? 0 : 1];
1157  if (alp_ctx.ctxs[f->alproto][f->protomap].logger) {
1158  active_id = MIN(log_id, inspect_id);
1159  } else {
1160  active_id = inspect_id;
1161  }
1162 
1163  SCReturnCT(active_id, "uint64_t");
1164 }
1165 
1166 bool AppLayerParserSupportsFiles(uint8_t ipproto, AppProto alproto)
1167 {
1168  // Custom case for only signature-only protocol so far
1169  if (alproto == ALPROTO_HTTP) {
1170  return AppLayerParserSupportsFiles(ipproto, ALPROTO_HTTP1) ||
1172  }
1173  return alp_ctx.ctxs[alproto][FlowGetProtoMapping(ipproto)].GetTxFiles != NULL;
1174 }
1175 
1176 AppLayerTxData *AppLayerParserGetTxData(uint8_t ipproto, AppProto alproto, void *tx)
1177 {
1178  SCEnter();
1179  AppLayerTxData *d = alp_ctx.ctxs[alproto][FlowGetProtoMapping(ipproto)].GetTxData(tx);
1180  SCReturnPtr(d, "AppLayerTxData");
1181 }
1182 
1183 AppLayerStateData *AppLayerParserGetStateData(uint8_t ipproto, AppProto alproto, void *state)
1184 {
1185  SCEnter();
1186  if (alp_ctx.ctxs[alproto][FlowGetProtoMapping(ipproto)].GetStateData) {
1187  AppLayerStateData *d =
1188  alp_ctx.ctxs[alproto][FlowGetProtoMapping(ipproto)].GetStateData(state);
1189  SCReturnPtr(d, "AppLayerStateData");
1190  }
1191  SCReturnPtr(NULL, "AppLayerStateData");
1192 }
1193 
1194 void AppLayerParserApplyTxConfig(uint8_t ipproto, AppProto alproto,
1195  void *state, void *tx, enum ConfigAction mode, AppLayerTxConfig config)
1196 {
1197  SCEnter();
1198  const int ipproto_map = FlowGetProtoMapping(ipproto);
1199  if (alp_ctx.ctxs[alproto][ipproto_map].ApplyTxConfig) {
1200  alp_ctx.ctxs[alproto][ipproto_map].ApplyTxConfig(state, tx, mode, config);
1201  }
1202  SCReturn;
1203 }
1204 
1205 /***** General *****/
1206 
1207 static inline void SetEOFFlags(AppLayerParserState *pstate, const uint8_t flags)
1208 {
1209  if ((flags & (STREAM_EOF|STREAM_TOSERVER)) == (STREAM_EOF|STREAM_TOSERVER)) {
1210  SCLogDebug("setting APP_LAYER_PARSER_EOF_TS");
1212  } else if ((flags & (STREAM_EOF|STREAM_TOCLIENT)) == (STREAM_EOF|STREAM_TOCLIENT)) {
1213  SCLogDebug("setting APP_LAYER_PARSER_EOF_TC");
1215  }
1216 }
1217 
1218 /** \internal
1219  * \brief create/close stream frames
1220  * On first invocation of TCP parser in a direction, create a <alproto>.stream frame.
1221  * On STREAM_EOF, set the final length. */
1222 static void HandleStreamFrames(Flow *f, StreamSlice stream_slice, const uint8_t *input,
1223  const uint32_t input_len, const uint8_t flags)
1224 {
1225  const uint8_t direction = (flags & STREAM_TOSERVER) ? 0 : 1;
1226  AppLayerParserState *pstate = f->alparser;
1227 
1228  /* setup the generic stream frame */
1229  if (((direction == 0 && (pstate->flags & APP_LAYER_PARSER_SFRAME_TS) == 0) ||
1230  (direction == 1 && (pstate->flags & APP_LAYER_PARSER_SFRAME_TC) == 0)) &&
1231  input != NULL && f->proto == IPPROTO_TCP) {
1232  Frame *frame = AppLayerFrameGetLastOpenByType(f, direction, FRAME_STREAM_TYPE);
1233  if (frame == NULL) {
1234  int64_t frame_len = -1;
1235  if (flags & STREAM_EOF)
1236  frame_len = input_len;
1237 
1239  f, &stream_slice, stream_slice.offset, frame_len, direction, FRAME_STREAM_TYPE);
1240  if (frame) {
1241  SCLogDebug("opened: frame %p id %" PRIi64, frame, frame->id);
1242  frame->flags = FRAME_FLAG_ENDS_AT_EOF; // TODO logic is not yet implemented
1244  frame->id != 1); // should always be the first frame that is created
1245  }
1246  if (direction == 0) {
1247  pstate->flags |= APP_LAYER_PARSER_SFRAME_TS;
1248  } else {
1249  pstate->flags |= APP_LAYER_PARSER_SFRAME_TC;
1250  }
1251  }
1252  } else if (flags & STREAM_EOF) {
1253  Frame *frame = AppLayerFrameGetLastOpenByType(f, direction, FRAME_STREAM_TYPE);
1254  SCLogDebug("EOF closing: frame %p", frame);
1255  if (frame) {
1256  /* calculate final frame length */
1257  int64_t slice_o = (int64_t)stream_slice.offset - (int64_t)frame->offset;
1258  int64_t frame_len = slice_o + (int64_t)input_len;
1259  SCLogDebug("%s: EOF frame->offset %" PRIu64 " -> %" PRIi64 ": o %" PRIi64,
1260  AppProtoToString(f->alproto), frame->offset, frame_len, slice_o);
1261  frame->len = frame_len;
1262  }
1263  }
1264 }
1265 
1266 static void Setup(Flow *f, const uint8_t direction, const uint8_t *input, uint32_t input_len,
1267  const uint8_t flags, StreamSlice *as)
1268 {
1269  memset(as, 0, sizeof(*as));
1270  as->input = input;
1271  as->input_len = input_len;
1272  as->flags = flags;
1273 
1274  if (f->proto == IPPROTO_TCP && f->protoctx != NULL) {
1275  TcpSession *ssn = f->protoctx;
1276  TcpStream *stream = (direction & STREAM_TOSERVER) ? &ssn->client : &ssn->server;
1277  as->offset = STREAM_APP_PROGRESS(stream);
1278  }
1279 }
1280 
1281 /** \retval int -1 in case of unrecoverable error. App-layer tracking stops for this flow.
1282  * \retval int 0 ok: we did not update app_progress
1283  * \retval int 1 ok: we updated app_progress */
1285  uint8_t flags, const uint8_t *input, uint32_t input_len)
1286 {
1287  SCEnter();
1288 #ifdef DEBUG_VALIDATION
1290 #endif
1291  AppLayerParserState *pstate = f->alparser;
1292  AppLayerParserProtoCtx *p = &alp_ctx.ctxs[alproto][f->protomap];
1293  StreamSlice stream_slice;
1294  void *alstate = NULL;
1295  uint64_t p_tx_cnt = 0;
1296  uint32_t consumed = input_len;
1297  const uint8_t direction = (flags & STREAM_TOSERVER) ? 0 : 1;
1298 
1299  /* we don't have the parser registered for this protocol */
1300  if (p->StateAlloc == NULL) {
1301  if (f->proto == IPPROTO_TCP) {
1303  }
1304  goto end;
1305  }
1306 
1307  if (flags & STREAM_GAP) {
1309  SCLogDebug("app-layer parser does not accept gaps");
1310  if (f->alstate != NULL && !FlowChangeProto(f)) {
1312  }
1314  goto error;
1315  }
1316  }
1317 
1318  /* Get the parser state (if any) */
1319  if (pstate == NULL) {
1320  f->alparser = pstate = AppLayerParserStateAlloc();
1321  if (pstate == NULL) {
1323  goto error;
1324  }
1325  }
1326 
1327  SetEOFFlags(pstate, flags);
1328 
1329  alstate = f->alstate;
1330  if (alstate == NULL || FlowChangeProto(f)) {
1331  f->alstate = alstate = p->StateAlloc(alstate, f->alproto_orig);
1332  if (alstate == NULL) {
1334  goto error;
1335  }
1336  SCLogDebug("alloced new app layer state %p (name %s)",
1337  alstate, AppLayerGetProtoName(f->alproto));
1338 
1339  /* set flow flags to state */
1340  if (f->file_flags != 0) {
1342  if (sd != NULL) {
1343  if ((sd->file_flags & f->file_flags) != f->file_flags) {
1344  SCLogDebug("state data: updating file_flags %04x with flow file_flags %04x",
1345  sd->file_flags, f->file_flags);
1346  sd->file_flags |= f->file_flags;
1347  }
1348  }
1349  }
1350  } else {
1351  SCLogDebug("using existing app layer state %p (name %s))",
1352  alstate, AppLayerGetProtoName(f->alproto));
1353  }
1354 
1355  p_tx_cnt = AppLayerParserGetTxCnt(f, f->alstate);
1356 
1357  /* invoke the recursive parser, but only on data. We may get empty msgs on EOF */
1358  if (input_len > 0 || (flags & STREAM_EOF)) {
1359  Setup(f, flags & (STREAM_TOSERVER | STREAM_TOCLIENT), input, input_len, flags,
1360  &stream_slice);
1361  HandleStreamFrames(f, stream_slice, input, input_len, flags);
1362 
1363 #ifdef DEBUG
1364  if (((stream_slice.flags & STREAM_TOSERVER) &&
1365  stream_slice.offset >= g_eps_applayer_error_offset_ts)) {
1366  SCLogNotice("putting parser %s into an error state from toserver offset %" PRIu64,
1367  AppProtoToString(alproto), g_eps_applayer_error_offset_ts);
1369  goto error;
1370  }
1371  if (((stream_slice.flags & STREAM_TOCLIENT) &&
1372  stream_slice.offset >= g_eps_applayer_error_offset_tc)) {
1373  SCLogNotice("putting parser %s into an error state from toclient offset %" PRIu64,
1374  AppProtoToString(alproto), g_eps_applayer_error_offset_tc);
1376  goto error;
1377  }
1378 #endif
1379  /* invoke the parser */
1380  AppLayerResult res = p->Parser[direction](f, alstate, pstate, stream_slice,
1381  alp_tctx->alproto_local_storage[alproto][f->protomap]);
1382  if (res.status < 0) {
1384  goto error;
1385  } else if (res.status > 0) {
1386  DEBUG_VALIDATE_BUG_ON(res.consumed > input_len);
1387  DEBUG_VALIDATE_BUG_ON(res.needed + res.consumed < input_len);
1388  DEBUG_VALIDATE_BUG_ON(res.needed == 0);
1389  /* incomplete is only supported for TCP */
1390  DEBUG_VALIDATE_BUG_ON(f->proto != IPPROTO_TCP);
1391 
1392  /* put protocol in error state on improper use of the
1393  * return codes. */
1394  if (res.consumed > input_len || res.needed + res.consumed < input_len) {
1396  goto error;
1397  }
1398 
1399  if (f->proto == IPPROTO_TCP && f->protoctx != NULL) {
1400  TcpSession *ssn = f->protoctx;
1401  SCLogDebug("direction %d/%s", direction,
1402  (flags & STREAM_TOSERVER) ? "toserver" : "toclient");
1403  if (direction == 0) {
1404  /* parser told us how much data it needs on top of what it
1405  * consumed. So we need tell stream engine how much we need
1406  * before the next call */
1407  ssn->client.data_required = res.needed;
1408  SCLogDebug("setting data_required %u", ssn->client.data_required);
1409  } else {
1410  /* parser told us how much data it needs on top of what it
1411  * consumed. So we need tell stream engine how much we need
1412  * before the next call */
1413  ssn->server.data_required = res.needed;
1414  SCLogDebug("setting data_required %u", ssn->server.data_required);
1415  }
1416  }
1417  consumed = res.consumed;
1418  }
1419  }
1420 
1421  /* set the packets to no inspection and reassembly if required */
1422  if (pstate->flags & APP_LAYER_PARSER_NO_INSPECTION) {
1423  AppLayerParserSetEOF(pstate);
1424 
1425  if (f->proto == IPPROTO_TCP) {
1427 
1428  /* Set the no reassembly flag for both the stream in this TcpSession */
1429  if (pstate->flags & APP_LAYER_PARSER_NO_REASSEMBLY) {
1430  /* Used only if it's TCP */
1431  TcpSession *ssn = f->protoctx;
1432  if (ssn != NULL) {
1435  }
1436  }
1437  /* Set the bypass flag for both the stream in this TcpSession */
1438  if (pstate->flags & APP_LAYER_PARSER_BYPASS_READY) {
1439  /* Used only if it's TCP */
1440  TcpSession *ssn = f->protoctx;
1441  if (ssn != NULL) {
1443  }
1444  }
1445  } else {
1446  // for TCP, this is set after flushing
1447  FlowSetNoPayloadInspectionFlag(f);
1448  }
1449  }
1450 
1451  /* In cases like HeartBleed for TLS we need to inspect AppLayer but not Payload */
1453  FlowSetNoPayloadInspectionFlag(f);
1454  /* Set the no reassembly flag for both the stream in this TcpSession */
1455  if (f->proto == IPPROTO_TCP) {
1456  /* Used only if it's TCP */
1457  TcpSession *ssn = f->protoctx;
1458  if (ssn != NULL) {
1461  }
1462  }
1463  }
1464 
1465  /* get the diff in tx cnt for stats keeping */
1466  uint64_t cur_tx_cnt = AppLayerParserGetTxCnt(f, f->alstate);
1467  if (cur_tx_cnt > p_tx_cnt && tv) {
1468  AppLayerIncTxCounter(tv, f, cur_tx_cnt - p_tx_cnt);
1469  }
1470 
1471  end:
1472  /* update app progress */
1473  if (consumed != input_len && f->proto == IPPROTO_TCP && f->protoctx != NULL) {
1474  TcpSession *ssn = f->protoctx;
1475  StreamTcpUpdateAppLayerProgress(ssn, direction, consumed);
1476  SCReturnInt(1);
1477  }
1478 
1479  SCReturnInt(0);
1480  error:
1481  /* Set the no app layer inspection flag for both
1482  * the stream in this Flow */
1483  if (f->proto == IPPROTO_TCP) {
1485  }
1486  AppLayerParserSetEOF(pstate);
1487  SCReturnInt(-1);
1488 }
1489 
1491 {
1492  SCEnter();
1493 
1494  if (pstate == NULL)
1495  goto end;
1496 
1497  SCLogDebug("setting APP_LAYER_PARSER_EOF_TC and APP_LAYER_PARSER_EOF_TS");
1499 
1500  end:
1501  SCReturn;
1502 }
1503 
1504 /* return true if there are app parser decoder events. These are
1505  * only the ones that are set during protocol detection. */
1507 {
1508  SCEnter();
1509 
1510  if (pstate == NULL)
1511  return false;
1512 
1515  return true;
1516 
1517  /* if we have reached here, we don't have events */
1518  return false;
1519 }
1520 
1521 /** \brief simple way to globally test if a alproto is registered
1522  * and fully enabled in the configuration.
1523  */
1525 {
1526  for (int i = 0; i < FLOW_PROTO_APPLAYER_MAX; i++) {
1527  if (alp_ctx.ctxs[alproto][i].StateGetProgress != NULL) {
1528  return 1;
1529  }
1530  }
1531  return 0;
1532 }
1533 
1534 int AppLayerParserProtocolHasLogger(uint8_t ipproto, AppProto alproto)
1535 {
1536  SCEnter();
1537  int ipproto_map = FlowGetProtoMapping(ipproto);
1538  int r = (!alp_ctx.ctxs[alproto][ipproto_map].logger) ? 0 : 1;
1539  SCReturnInt(r);
1540 }
1541 
1543 {
1544  SCEnter();
1545  const int ipproto_map = FlowGetProtoMapping(ipproto);
1546  LoggerId r = alp_ctx.ctxs[alproto][ipproto_map].logger_bits;
1547  SCReturnUInt(r);
1548 }
1549 
1551 {
1552  SCEnter();
1553 
1554  SCLogDebug("f %p tcp %p direction %d", f, f ? f->protoctx : NULL, direction);
1555  if (f != NULL && f->protoctx != NULL)
1557 
1558  SCReturn;
1559 }
1560 
1561 void SCAppLayerParserSetStreamDepth(uint8_t ipproto, AppProto alproto, uint32_t stream_depth)
1562 {
1563  SCEnter();
1564 
1565  alp_ctx.ctxs[alproto][FlowGetProtoMapping(ipproto)].stream_depth = stream_depth;
1566  alp_ctx.ctxs[alproto][FlowGetProtoMapping(ipproto)].internal_flags |=
1568 
1569  SCReturn;
1570 }
1571 
1573 {
1574  SCReturnInt(alp_ctx.ctxs[f->alproto][f->protomap].stream_depth);
1575 }
1576 
1577 void AppLayerParserSetStreamDepthFlag(uint8_t ipproto, AppProto alproto, void *state, uint64_t tx_id, uint8_t flags)
1578 {
1579  SCEnter();
1580  void *tx = NULL;
1581  if (state != NULL) {
1582  if ((tx = AppLayerParserGetTx(ipproto, alproto, state, tx_id)) != NULL) {
1583  if (alp_ctx.ctxs[alproto][FlowGetProtoMapping(ipproto)].SetStreamDepthFlag != NULL) {
1584  alp_ctx.ctxs[alproto][FlowGetProtoMapping(ipproto)].SetStreamDepthFlag(tx, flags);
1585  }
1586  }
1587  }
1588  SCReturn;
1589 }
1590 
1591 /**
1592  * \param id progress value id to get the name for
1593  * \param direction STREAM_TOSERVER/STREAM_TOCLIENT
1594  */
1596  uint8_t ipproto, AppProto alproto, const char *name, const uint8_t direction)
1597 {
1598  if (alp_ctx.ctxs[alproto][FlowGetProtoMapping(ipproto)].GetStateIdByName != NULL) {
1599  return alp_ctx.ctxs[alproto][FlowGetProtoMapping(ipproto)].GetStateIdByName(
1600  name, direction);
1601  } else {
1602  return -1;
1603  }
1604 }
1605 
1606 /**
1607  * \param id progress value id to get the name for
1608  * \param direction STREAM_TOSERVER/STREAM_TOCLIENT
1609  */
1611  uint8_t ipproto, AppProto alproto, const int id, const uint8_t direction)
1612 {
1613  if (alp_ctx.ctxs[alproto][FlowGetProtoMapping(ipproto)].GetStateNameById != NULL) {
1614  return alp_ctx.ctxs[alproto][FlowGetProtoMapping(ipproto)].GetStateNameById(id, direction);
1615  } else {
1616  return NULL;
1617  }
1618 }
1619 
1620 int AppLayerParserGetFrameIdByName(uint8_t ipproto, AppProto alproto, const char *name)
1621 {
1622  if (alp_ctx.ctxs[alproto][FlowGetProtoMapping(ipproto)].GetFrameIdByName != NULL) {
1623  return alp_ctx.ctxs[alproto][FlowGetProtoMapping(ipproto)].GetFrameIdByName(name);
1624  } else {
1625  return -1;
1626  }
1627 }
1628 
1629 const char *AppLayerParserGetFrameNameById(uint8_t ipproto, AppProto alproto, const uint8_t id)
1630 {
1631  if (alp_ctx.ctxs[alproto][FlowGetProtoMapping(ipproto)].GetFrameNameById != NULL) {
1632  return alp_ctx.ctxs[alproto][FlowGetProtoMapping(ipproto)].GetFrameNameById(id);
1633  } else {
1634  return NULL;
1635  }
1636 }
1637 
1638 /***** Cleanup *****/
1639 
1641  uint8_t protomap, AppProto alproto, void *alstate, AppLayerParserState *pstate)
1642 {
1643  SCEnter();
1644 
1645  AppLayerParserProtoCtx *ctx = &alp_ctx.ctxs[alproto][protomap];
1646 
1647  if (ctx->StateFree != NULL && alstate != NULL)
1648  ctx->StateFree(alstate);
1649 
1650  /* free the app layer parser api state */
1651  if (pstate != NULL)
1652  AppLayerParserStateFree(pstate);
1653 
1654  SCReturn;
1655 }
1656 
1657 void AppLayerParserStateCleanup(const Flow *f, void *alstate, AppLayerParserState *pstate)
1658 {
1659  AppLayerParserStateProtoCleanup(f->protomap, f->alproto, alstate, pstate);
1660 }
1661 
1662 static void ValidateParserProtoDump(AppProto alproto, uint8_t ipproto)
1663 {
1664  uint8_t map = FlowGetProtoMapping(ipproto);
1665  const AppLayerParserProtoCtx *ctx = &alp_ctx.ctxs[alproto][map];
1666  printf("ERROR: incomplete app-layer registration\n");
1667  printf("AppLayer protocol %s ipproto %u\n", AppProtoToString(alproto), ipproto);
1668  printf("- option flags %"PRIx32"\n", ctx->option_flags);
1669  printf("- first_data_dir %"PRIx8"\n", ctx->first_data_dir);
1670  printf("Mandatory:\n");
1671  printf("- Parser[0] %p Parser[1] %p\n", ctx->Parser[0], ctx->Parser[1]);
1672  printf("- StateAlloc %p StateFree %p\n", ctx->StateAlloc, ctx->StateFree);
1673  printf("- StateGetTx %p StateGetTxCnt %p StateTransactionFree %p\n",
1674  ctx->StateGetTx, ctx->StateGetTxCnt, ctx->StateTransactionFree);
1675  printf("- GetTxData %p\n", ctx->GetTxData);
1676  printf("- GetStateData %p\n", ctx->GetStateData);
1677  printf("- StateGetProgress %p\n", ctx->StateGetProgress);
1678  printf("Optional:\n");
1679  printf("- LocalStorageAlloc %p LocalStorageFree %p\n", ctx->LocalStorageAlloc, ctx->LocalStorageFree);
1680  printf("- StateGetEventInfo %p StateGetEventInfoById %p\n", ctx->StateGetEventInfo,
1681  ctx->StateGetEventInfoById);
1682 }
1683 
1684 #define BOTH_SET(a, b) ((a) != NULL && (b) != NULL)
1685 #define BOTH_SET_OR_BOTH_UNSET(a, b) (((a) == NULL && (b) == NULL) || ((a) != NULL && (b) != NULL))
1686 #define THREE_SET(a, b, c) ((a) != NULL && (b) != NULL && (c) != NULL)
1688 static void ValidateParserProto(AppProto alproto, uint8_t ipproto)
1689 {
1690  uint8_t map = FlowGetProtoMapping(ipproto);
1691  const AppLayerParserProtoCtx *ctx = &alp_ctx.ctxs[alproto][map];
1692 
1693  if (ctx->Parser[0] == NULL && ctx->Parser[1] == NULL)
1694  return;
1695 
1696  if (!(BOTH_SET(ctx->Parser[0], ctx->Parser[1]))) {
1697  goto bad;
1698  }
1699  if (!(BOTH_SET(ctx->StateFree, ctx->StateAlloc))) {
1700  goto bad;
1701  }
1702  if (!(THREE_SET(ctx->StateGetTx, ctx->StateGetTxCnt, ctx->StateTransactionFree))) {
1703  goto bad;
1704  }
1705  if (ctx->StateGetProgress == NULL) {
1706  goto bad;
1707  }
1708  /* local storage is optional, but needs both set if used */
1709  if (!(BOTH_SET_OR_BOTH_UNSET(ctx->LocalStorageAlloc, ctx->LocalStorageFree))) {
1710  goto bad;
1711  }
1712  if (ctx->GetTxData == NULL) {
1713  goto bad;
1714  }
1715  if (ctx->GetStateData == NULL) {
1716  goto bad;
1717  }
1718  return;
1719 bad:
1720  ValidateParserProtoDump(alproto, ipproto);
1721  exit(EXIT_FAILURE);
1722 }
1723 #undef BOTH_SET
1724 #undef BOTH_SET_OR_BOTH_UNSET
1725 #undef THREE_SET
1726 
1727 static void ValidateParser(AppProto alproto)
1728 {
1729  ValidateParserProto(alproto, IPPROTO_TCP);
1730  ValidateParserProto(alproto, IPPROTO_UDP);
1731 }
1732 
1733 static void ValidateParsers(void)
1734 {
1735  AppProto p = 0;
1736  for (; p < g_alproto_max; p++) {
1737  ValidateParser(p);
1738  }
1739 }
1740 
1741 #define ARRAY_CAP_STEP 16
1742 static void (**PreRegisteredCallbacks)(void) = NULL;
1743 static size_t preregistered_callbacks_nb = 0;
1744 static size_t preregistered_callbacks_cap = 0;
1745 
1747 {
1748  if (alp_ctx.ctxs_len <= alproto && alproto < g_alproto_max) {
1749  /* Realloc alp_ctx.ctxs, so that dynamic alproto can be treated as real/normal ones.
1750  * In case we need to turn off dynamic alproto. */
1751  void *tmp = SCRealloc(alp_ctx.ctxs, sizeof(AppLayerParserProtoCtx[FLOW_PROTO_MAX]) *
1752  (alp_ctx.ctxs_len + ARRAY_CAP_STEP));
1753  if (unlikely(tmp == NULL)) {
1754  FatalError("Unable to realloc alp_ctx.ctxs.");
1755  }
1756  alp_ctx.ctxs = tmp;
1757  memset(&alp_ctx.ctxs[alp_ctx.ctxs_len], 0,
1759  alp_ctx.ctxs_len += ARRAY_CAP_STEP;
1760  }
1761  return 0;
1762 }
1763 
1764 int AppLayerParserPreRegister(void (*Register)(void))
1765 {
1766  if (preregistered_callbacks_nb == preregistered_callbacks_cap) {
1767  void *tmp = SCRealloc(PreRegisteredCallbacks,
1768  sizeof(void *) * (preregistered_callbacks_cap + ARRAY_CAP_STEP));
1769  if (tmp == NULL) {
1770  return 1;
1771  }
1772  preregistered_callbacks_cap += ARRAY_CAP_STEP;
1773  PreRegisteredCallbacks = tmp;
1774  }
1775  PreRegisteredCallbacks[preregistered_callbacks_nb] = Register;
1776  preregistered_callbacks_nb++;
1777  return 0;
1778 }
1779 
1781 {
1782  SCEnter();
1783 
1784  AppLayerConfig();
1785 
1788  SCRegisterDcerpcParser();
1789  SCRegisterDcerpcUdpParser();
1794  SCRegisterDnsUdpParser();
1795  SCRegisterDnsTcpParser();
1796  SCRegisterBittorrentDhtUdpParser();
1798  SCEnipRegisterParsers();
1802  SCRegisterNtpParser();
1805  SCRegisterKrb5Parser();
1806  SCRegisterDhcpParser();
1807  SCRegisterSnmpParser();
1808  SCRegisterSipParser();
1809  SCRegisterQuicParser();
1810  SCRegisterWebSocketParser();
1811  SCRegisterLdapTcpParser();
1812  SCRegisterLdapUdpParser();
1813  SCRegisterMdnsParser();
1814  SCRegisterTemplateParser();
1815  SCRfbRegisterParser();
1816  SCMqttRegisterParser();
1817  SCRegisterPgsqlParser();
1818  SCRegisterPop3Parser();
1819  SCRegisterRdpParser();
1821  SCRegisterTelnetParser();
1823 
1824  for (size_t i = 0; i < preregistered_callbacks_nb; i++) {
1825  PreRegisteredCallbacks[i]();
1826  }
1827 
1828  ValidateParsers();
1829 }
1830 
1831 /* coccinelle: SCAppLayerParserStateSetFlag():2,2:APP_LAYER_PARSER_ */
1833 {
1834  SCEnter();
1835  pstate->flags |= flag;
1836  SCReturn;
1837 }
1838 
1839 /* coccinelle: SCAppLayerParserStateIssetFlag():2,2:APP_LAYER_PARSER_ */
1840 uint16_t SCAppLayerParserStateIssetFlag(AppLayerParserState *pstate, uint16_t flag)
1841 {
1842  SCEnter();
1843  SCReturnUInt(pstate->flags & flag);
1844 }
1845 
1846 /***** Unittests *****/
1847 
1848 #ifdef UNITTESTS
1849 #include "util-unittest-helper.h"
1850 
1852  void (*RegisterUnittests)(void))
1853 {
1854  SCEnter();
1855  alp_ctx.ctxs[alproto][FlowGetProtoMapping(ipproto)].RegisterUnittests = RegisterUnittests;
1856  SCReturn;
1857 }
1858 
1860 {
1861  SCEnter();
1862 
1863  int ip;
1864  AppProto alproto;
1866 
1867  for (ip = 0; ip < FLOW_PROTO_DEFAULT; ip++) {
1868  for (alproto = 0; alproto < g_alproto_max; alproto++) {
1869  ctx = &alp_ctx.ctxs[alproto][ip];
1870  if (ctx->RegisterUnittests == NULL)
1871  continue;
1872  ctx->RegisterUnittests();
1873  }
1874  }
1875 
1876  SCReturn;
1877 }
1878 
1879 #endif
AppLayerParserHasFilesInDir
#define AppLayerParserHasFilesInDir(txd, direction)
check if tx (possibly) has files in this tx for the direction
Definition: app-layer-parser.h:266
app-layer-nfs-udp.h
AppLayerParserRegisterGetStateProgressFunc
void AppLayerParserRegisterGetStateProgressFunc(uint8_t ipproto, AppProto alproto, int(*StateGetProgress)(void *alstate, uint8_t direction))
Definition: app-layer-parser.c:486
AppLayerParserDeSetup
int AppLayerParserDeSetup(void)
Definition: app-layer-parser.c:285
TcpStream_
Definition: stream-tcp-private.h:106
AppLayerParserProtoCtx_::GetStateData
AppLayerStateData *(* GetStateData)(void *state)
Definition: app-layer-parser.c:103
ts
uint64_t ts
Definition: source-erf-file.c:55
AppLayerParserProtoCtx_::StateGetTxCnt
uint64_t(* StateGetTxCnt)(void *alstate)
Definition: app-layer-parser.c:93
g_applayerparser_error_policy
enum ExceptionPolicy g_applayerparser_error_policy
Definition: app-layer-parser.c:155
SCAppLayerParserStateIssetFlag
uint16_t SCAppLayerParserStateIssetFlag(AppLayerParserState *pstate, uint16_t flag)
Definition: app-layer-parser.c:1840
SCConfValIsTrue
int SCConfValIsTrue(const char *val)
Check if a value is true.
Definition: conf.c:552
AppLayerParserProtoCtx_::logger_bits
uint32_t logger_bits
Definition: app-layer-parser.c:80
AppLayerParserProtoCtx_::complete_tc
int complete_tc
Definition: app-layer-parser.c:97
AppLayerParserProtoCtx_::GetTxData
AppLayerTxData *(* GetTxData)(void *tx)
Definition: app-layer-parser.c:104
app-layer-tftp.h
AppLayerParserState_::log_id
uint64_t log_id
Definition: app-layer-parser.c:145
RegisterSMBParsers
void RegisterSMBParsers(void)
Definition: app-layer-smb.c:45
app-layer-ssh.h
RegisterIKEParsers
void RegisterIKEParsers(void)
Definition: app-layer-ike.c:40
AppLayerParserIsEnabled
int AppLayerParserIsEnabled(AppProto alproto)
simple way to globally test if a alproto is registered and fully enabled in the configuration.
Definition: app-layer-parser.c:1524
AppLayerParserRegisterLocalStorageFunc
void AppLayerParserRegisterLocalStorageFunc(uint8_t ipproto, AppProto alproto, void *(*LocalStorageAlloc)(void), void(*LocalStorageFree)(void *))
Definition: app-layer-parser.c:446
BOTH_SET
#define BOTH_SET(a, b)
Definition: app-layer-parser.c:1684
AppLayerParserProtocolHasLogger
int AppLayerParserProtocolHasLogger(uint8_t ipproto, AppProto alproto)
Definition: app-layer-parser.c:1534
AppLayerParserRegisterOptionFlags
void AppLayerParserRegisterOptionFlags(uint8_t ipproto, AppProto alproto, uint32_t flags)
Definition: app-layer-parser.c:425
AppLayerParserGetStateNameById
const char * AppLayerParserGetStateNameById(uint8_t ipproto, AppProto alproto, const int id, const uint8_t direction)
Definition: app-layer-parser.c:1610
flow-util.h
FramesFree
void FramesFree(Frames *frames)
Definition: app-layer-frames.c:454
AppLayerParserSetStreamDepthFlag
void AppLayerParserSetStreamDepthFlag(uint8_t ipproto, AppProto alproto, void *state, uint64_t tx_id, uint8_t flags)
Definition: app-layer-parser.c:1577
APP_LAYER_TX_SKIP_INSPECT_TC
#define APP_LAYER_TX_SKIP_INSPECT_TC
Definition: app-layer-parser.h:68
AppLayerParserSetTransactionLogId
void AppLayerParserSetTransactionLogId(AppLayerParserState *pstate, uint64_t tx_id)
Definition: app-layer-parser.c:715
g_filedata_logger_enabled
bool g_filedata_logger_enabled
Definition: output-filedata.c:37
stream-tcp.h
AppLayerParserCtx_::ctxs_len
size_t ctxs_len
Definition: app-layer-parser.c:132
StreamSlice
struct StreamSlice StreamSlice
Definition: app-layer-parser.h:39
AppLayerParserApplyTxConfig
void AppLayerParserApplyTxConfig(uint8_t ipproto, AppProto alproto, void *state, void *tx, enum ConfigAction mode, AppLayerTxConfig config)
Definition: app-layer-parser.c:1194
unlikely
#define unlikely(expr)
Definition: util-optimize.h:35
AppLayerParserTransactionsCleanup
void AppLayerParserTransactionsCleanup(Flow *f, const uint8_t pkt_dir)
remove obsolete (inspected and logged) transactions
Definition: app-layer-parser.c:896
AppLayerParserGetProtocolParserLocalStorage
void * AppLayerParserGetProtocolParserLocalStorage(uint8_t ipproto, AppProto alproto)
Definition: app-layer-parser.c:634
AppLayerParserProtoCtx_::LocalStorageFree
void(* LocalStorageFree)(void *)
Definition: app-layer-parser.c:86
AppLayerParserProtoCtx_
App layer protocol parser context.
Definition: app-layer-parser.c:69
RegisterSSHParsers
void RegisterSSHParsers(void)
Function to register the SSH protocol parsers and other functions.
Definition: app-layer-ssh.c:81
AppLayerParserProtoCtx_::StateGetTx
void *(* StateGetTx)(void *alstate, uint64_t tx_id)
Definition: app-layer-parser.c:94
SCLogDebug
#define SCLogDebug(...)
Definition: util-debug.h:282
FLOW_SGH_TOCLIENT
#define FLOW_SGH_TOCLIENT
Definition: flow.h:74
AppLayerParserSetTransactionInspectId
void AppLayerParserSetTransactionInspectId(const Flow *f, AppLayerParserState *pstate, void *alstate, const uint8_t flags, bool tag_txs_as_inspected)
Definition: app-layer-parser.c:747
APP_LAYER_PARSER_BYPASS_READY
#define APP_LAYER_PARSER_BYPASS_READY
Definition: app-layer-parser.h:52
AppLayerParserProtoCtx_::ApplyTxConfig
void(* ApplyTxConfig)(void *state, void *tx, int mode, AppLayerTxConfig)
Definition: app-layer-parser.c:105
AppLayerParserGetEventsByTx
AppLayerDecoderEvents * AppLayerParserGetEventsByTx(uint8_t ipproto, AppProto alproto, void *tx)
Definition: app-layer-parser.c:850
AppLayerGetTxIterator
AppLayerGetTxIteratorFunc AppLayerGetTxIterator(const uint8_t ipproto, const AppProto alproto)
Definition: app-layer-parser.c:693
next
struct HtpBodyChunk_ * next
Definition: app-layer-htp.h:0
RegisterModbusParsers
void RegisterModbusParsers(void)
Function to register the Modbus protocol parser.
Definition: app-layer-modbus.c:50
name
const char * name
Definition: detect-engine-proto.c:48
AppLayerParserGetTxDetectProgress
uint8_t AppLayerParserGetTxDetectProgress(AppLayerTxData *txd, const uint8_t dir)
Definition: app-layer-parser.c:736
Flow_::proto
uint8_t proto
Definition: flow.h:369
AppProto
uint16_t AppProto
Definition: app-layer-protos.h:86
StreamTcpSetDisableRawReassemblyFlag
void StreamTcpSetDisableRawReassemblyFlag(TcpSession *, char)
Set the No reassembly flag for the given direction in given TCP session.
Definition: stream-tcp.c:6878
AppLayerFramesSetupContainer
FramesContainer * AppLayerFramesSetupContainer(Flow *f)
Definition: app-layer-parser.c:191
AppLayerParserGetStateProgress
int AppLayerParserGetStateProgress(uint8_t ipproto, AppProto alproto, void *alstate, uint8_t flags)
get the progress value for a tx/protocol
Definition: app-layer-parser.c:1080
FramesContainer::toserver
Frames toserver
Definition: app-layer-frames.h:72
SCAppLayerParserStateSetFlag
void SCAppLayerParserStateSetFlag(AppLayerParserState *pstate, uint16_t flag)
Definition: app-layer-parser.c:1832
Frame::offset
uint64_t offset
Definition: app-layer-frames.h:49
TcpStreamCnf_::reassembly_depth
uint32_t reassembly_depth
Definition: stream-tcp.h:75
Frame
Definition: app-layer-frames.h:43
flow-private.h
Flow_
Flow data structure.
Definition: flow.h:347
AppLayerParserProtoCtx_::GetStateNameById
AppLayerParserGetStateNameByIdFn GetStateNameById
Definition: app-layer-parser.c:113
AppLayerIncGapErrorCounter
void AppLayerIncGapErrorCounter(ThreadVars *tv, Flow *f)
Definition: app-layer.c:165
APP_LAYER_PARSER_INT_STREAM_DEPTH_SET
#define APP_LAYER_PARSER_INT_STREAM_DEPTH_SET
Definition: app-layer-parser.h:62
SCAppLayerParserSetStreamDepth
void SCAppLayerParserSetStreamDepth(uint8_t ipproto, AppProto alproto, uint32_t stream_depth)
Definition: app-layer-parser.c:1561
LoggerId
LoggerId
Definition: suricata-common.h:477
Flow_::protomap
uint8_t protomap
Definition: flow.h:436
AppLayerParserGetTransactionLogId
uint64_t AppLayerParserGetTransactionLogId(AppLayerParserState *pstate)
Definition: app-layer-parser.c:701
AppProtoToString
const char * AppProtoToString(AppProto alproto)
Maps the ALPROTO_*, to its string equivalent.
Definition: app-layer-protos.c:41
ctx
struct Thresholds ctx
AppLayerParserSupportsFiles
bool AppLayerParserSupportsFiles(uint8_t ipproto, AppProto alproto)
Definition: app-layer-parser.c:1166
AppLayerParserRegisterStateProgressCompletionStatus
void AppLayerParserRegisterStateProgressCompletionStatus(AppProto alproto, const int ts, const int tc)
Definition: app-layer-parser.c:534
AppLayerParserGetStateProgressCompletionStatus
int AppLayerParserGetStateProgressCompletionStatus(AppProto alproto, uint8_t direction)
Definition: app-layer-parser.c:1109
AppLayerParserGetFirstDataDir
uint8_t AppLayerParserGetFirstDataDir(uint8_t ipproto, AppProto alproto)
Definition: app-layer-parser.c:1142
AppLayerParserProtoIsRegistered
int AppLayerParserProtoIsRegistered(uint8_t ipproto, AppProto alproto)
Definition: app-layer-parser.c:228
AppLayerParserRegisterTxFreeFunc
void AppLayerParserRegisterTxFreeFunc(uint8_t ipproto, AppProto alproto, void(*StateTransactionFree)(void *, uint64_t))
Definition: app-layer-parser.c:496
FLOW_NOPAYLOAD_INSPECTION
#define FLOW_NOPAYLOAD_INSPECTION
Definition: flow.h:66
Frame::id
int64_t id
Definition: app-layer-frames.h:51
AppLayerParserGetStateIdByName
int AppLayerParserGetStateIdByName(uint8_t ipproto, AppProto alproto, const char *name, const uint8_t direction)
Definition: app-layer-parser.c:1595
Flow_::alproto_orig
AppProto alproto_orig
Definition: flow.h:447
AppLayerParserStateProtoCleanup
void AppLayerParserStateProtoCleanup(uint8_t protomap, AppProto alproto, void *alstate, AppLayerParserState *pstate)
Definition: app-layer-parser.c:1640
AppLayerParserProtoCtx_::StateGetTxIterator
AppLayerGetTxIteratorFunc StateGetTxIterator
Definition: app-layer-parser.c:95
AppLayerParserThreadCtxFree
void AppLayerParserThreadCtxFree(AppLayerParserThreadCtx *tctx)
Destroys the app layer parser thread context obtained using AppLayerParserThreadCtxAlloc().
Definition: app-layer-parser.c:324
MIN
#define MIN(x, y)
Definition: suricata-common.h:408
StreamTcpUpdateAppLayerProgress
void StreamTcpUpdateAppLayerProgress(TcpSession *ssn, char direction, const uint32_t progress)
update reassembly progress
Definition: stream-tcp.c:6846
AppLayerParserRegisterGetStateFuncs
void AppLayerParserRegisterGetStateFuncs(uint8_t ipproto, AppProto alproto, AppLayerParserGetStateIdByNameFn GetIdByNameFunc, AppLayerParserGetStateNameByIdFn GetNameByIdFunc)
Definition: app-layer-parser.c:561
FramesContainer
Definition: app-layer-frames.h:71
SCConfValIsFalse
int SCConfValIsFalse(const char *val)
Check if a value is false.
Definition: conf.c:577
AppLayerTxData
struct AppLayerTxData AppLayerTxData
Definition: app-layer-parser.h:43
AppLayerParserGetStateData
AppLayerStateData * AppLayerParserGetStateData(uint8_t ipproto, AppProto alproto, void *state)
Definition: app-layer-parser.c:1183
app-layer-http2.h
app-layer-ftp.h
AppLayerFrameNewByAbsoluteOffset
Frame * AppLayerFrameNewByAbsoluteOffset(Flow *f, const StreamSlice *stream_slice, const uint64_t frame_start, const int64_t len, int dir, uint8_t frame_type)
create new frame using the absolute offset from the start of the stream
Definition: app-layer-frames.c:609
AppLayerFrameGetLastOpenByType
Frame * AppLayerFrameGetLastOpenByType(Flow *f, const int dir, const uint8_t frame_type)
Definition: app-layer-frames.c:714
stream_config
TcpStreamCnf stream_config
Definition: stream-tcp.c:227
MAX
#define MAX(x, y)
Definition: suricata-common.h:412
APP_LAYER_PARSER_EOF_TS
#define APP_LAYER_PARSER_EOF_TS
Definition: app-layer-parser.h:53
Flow_::protoctx
void * protoctx
Definition: flow.h:432
TcpStream_::data_required
uint32_t data_required
Definition: stream-tcp-private.h:133
AppLayerIncAllocErrorCounter
void AppLayerIncAllocErrorCounter(ThreadVars *tv, Flow *f)
Definition: app-layer.c:173
EXCEPTION_POLICY_NOT_SET
@ EXCEPTION_POLICY_NOT_SET
Definition: util-exception-policy-types.h:27
ExceptionPolicyParse
enum ExceptionPolicy ExceptionPolicyParse(const char *option, bool support_flow)
Definition: util-exception-policy.c:311
AppLayerParserRegisterUnittests
void AppLayerParserRegisterUnittests(void)
Definition: app-layer-parser.c:1859
AppLayerParserGetTransactionInspectId
uint64_t AppLayerParserGetTransactionInspectId(AppLayerParserState *pstate, uint8_t direction)
Definition: app-layer-parser.c:725
AppLayerParserRegisterApplyTxConfigFunc
void AppLayerParserRegisterApplyTxConfigFunc(uint8_t ipproto, AppProto alproto, void(*ApplyTxConfig)(void *state, void *tx, int mode, AppLayerTxConfig))
Definition: app-layer-parser.c:612
AppLayerDecoderEvents_
Data structure to store app layer decoder events.
Definition: app-layer-events.h:33
AppLayerTxConfig
struct AppLayerTxConfig AppLayerTxConfig
Definition: app-layer-parser.h:45
FlowGetReverseProtoMapping
uint8_t FlowGetReverseProtoMapping(uint8_t rproto)
Definition: flow-util.c:113
RegisterDNP3Parsers
void RegisterDNP3Parsers(void)
Register the DNP3 application protocol parser.
Definition: app-layer-dnp3.c:1562
util-unittest-helper.h
AppLayerParserProtoCtx_::StateGetEventInfoById
int(* StateGetEventInfoById)(uint8_t event_id, const char **event_name, AppLayerEventType *event_type)
Definition: app-layer-parser.c:98
FTPParserCleanup
void FTPParserCleanup(void)
Free memory allocated for global FTP parser state.
Definition: app-layer-ftp.c:1408
AppLayerParserGetTxFiles
AppLayerGetFileState AppLayerParserGetTxFiles(const Flow *f, void *tx, const uint8_t direction)
Definition: app-layer-parser.c:866
AppLayerParserState_::flags
uint16_t flags
Definition: app-layer-parser.c:137
Flow_::sgh_toserver
const struct SigGroupHead_ * sgh_toserver
Definition: flow.h:477
StreamTcpReassembleTriggerRawInspection
void StreamTcpReassembleTriggerRawInspection(TcpSession *ssn, int direction)
Trigger RAW stream inspection.
Definition: stream-tcp-reassemble.c:2156
AppLayerParserState_::inspect_id
uint64_t inspect_id[2]
Definition: app-layer-parser.c:141
AppLayerParserFPtr
AppLayerResult(* AppLayerParserFPtr)(Flow *f, void *protocol_state, AppLayerParserState *pstate, StreamSlice stream_slice, void *local_storage)
Prototype for parsing functions.
Definition: app-layer-parser.h:131
AppLayerParserCtx
struct AppLayerParserCtx_ AppLayerParserCtx
Flow_::alparser
AppLayerParserState * alparser
Definition: flow.h:469
AppLayerParserRegisterProtocolParsers
void AppLayerParserRegisterProtocolParsers(void)
Definition: app-layer-parser.c:1780
SCAppLayerParserTriggerRawStreamInspection
void SCAppLayerParserTriggerRawStreamInspection(Flow *f, int direction)
Definition: app-layer-parser.c:1550
app-layer-detect-proto.h
APP_LAYER_PARSER_SFRAME_TS
#define APP_LAYER_PARSER_SFRAME_TS
Definition: app-layer-parser.h:56
app-layer-htp.h
FramesContainer::toclient
Frames toclient
Definition: app-layer-frames.h:73
AppLayerResult
struct AppLayerResult AppLayerResult
Definition: app-layer-parser.h:40
AppLayerParserProtoCtx_::stream_depth
uint32_t stream_depth
Definition: app-layer-parser.c:116
AppLayerParserState_
Definition: app-layer-parser.c:135
AppLayerParserGetEventInfoById
int AppLayerParserGetEventInfoById(uint8_t ipproto, AppProto alproto, uint8_t event_id, const char **event_name, AppLayerEventType *event_type)
Definition: app-layer-parser.c:1129
AppLayerParserProtoCtx_::GetFrameIdByName
AppLayerParserGetFrameIdByNameFn GetFrameIdByName
Definition: app-layer-parser.c:109
AppLayerParserGetFrameNameById
const char * AppLayerParserGetFrameNameById(uint8_t ipproto, AppProto alproto, const uint8_t id)
Definition: app-layer-parser.c:1629
g_alproto_max
AppProto g_alproto_max
Definition: app-layer-protos.c:30
AppLayerParserGetTransactionActive
uint64_t AppLayerParserGetTransactionActive(const Flow *f, AppLayerParserState *pstate, uint8_t direction)
Definition: app-layer-parser.c:1149
SCAppLayerParserConfParserEnabled
int SCAppLayerParserConfParserEnabled(const char *ipproto, const char *alproto_name)
check if a parser is enabled in the config Returns enabled always if: were running unittests
Definition: app-layer-parser.c:345
AppLayerParserProtoCtx_::logger
bool logger
Definition: app-layer-parser.c:73
app-layer-ike.h
AppLayerFramesFreeContainer
void AppLayerFramesFreeContainer(Flow *f)
Definition: app-layer-parser.c:176
SCAppLayerParserRegisterLogger
void SCAppLayerParserRegisterLogger(uint8_t ipproto, AppProto alproto)
Definition: app-layer-parser.c:477
app-layer-dnp3.h
AppLayerGetTxIterTuple
struct AppLayerGetTxIterTuple AppLayerGetTxIterTuple
Definition: app-layer-parser.h:41
AppLayerEventType
AppLayerEventType
Definition: app-layer-events.h:54
AppLayerIncTxCounter
void AppLayerIncTxCounter(ThreadVars *tv, Flow *f, int64_t step)
Definition: app-layer.c:157
AppLayerParserThreadCtx_::alproto_local_storage
void *(* alproto_local_storage)[FLOW_PROTO_MAX]
Definition: app-layer-parser.c:61
AppLayerGetFileState
struct AppLayerGetFileState AppLayerGetFileState
Definition: app-layer-parser.h:42
AppLayerParserProtoCtx_::StateGetEventInfo
int(* StateGetEventInfo)(const char *event_name, uint8_t *event_id, AppLayerEventType *event_type)
Definition: app-layer-parser.c:100
alp_tctx
AppLayerParserThreadCtx * alp_tctx
Definition: fuzz_applayerparserparse.c:24
AppLayerParserRegisterGetFrameFuncs
void AppLayerParserRegisterGetFrameFuncs(uint8_t ipproto, AppProto alproto, AppLayerParserGetFrameIdByNameFn GetIdByNameFunc, AppLayerParserGetFrameNameByIdFn GetNameByIdFunc)
Definition: app-layer-parser.c:571
SCEnter
#define SCEnter(...)
Definition: util-debug.h:284
AppLayerParserProtoCtx_::SetStreamDepthFlag
void(* SetStreamDepthFlag)(void *tx, uint8_t flags)
Definition: app-layer-parser.c:107
AppLayerFramesGetContainer
FramesContainer * AppLayerFramesGetContainer(const Flow *f)
Definition: app-layer-parser.c:184
AppLayerParserState_::min_id
uint64_t min_id
Definition: app-layer-parser.c:147
ThreadVars_
Per thread variable structure.
Definition: threadvars.h:58
AppLayerParserRegisterLoggerBits
void AppLayerParserRegisterLoggerBits(uint8_t ipproto, AppProto alproto, LoggerId bits)
Definition: app-layer-parser.c:468
AppLayerParserRegisterStateFuncs
void AppLayerParserRegisterStateFuncs(uint8_t ipproto, AppProto alproto, void *(*StateAlloc)(void *, AppProto), void(*StateFree)(void *))
Definition: app-layer-parser.c:435
APP_LAYER_PARSER_NO_REASSEMBLY
#define APP_LAYER_PARSER_NO_REASSEMBLY
Definition: app-layer-parser.h:50
IS_DISRUPTED
#define IS_DISRUPTED(flags)
Definition: app-layer-parser.c:887
FLOW_PROTO_DEFAULT
@ FLOW_PROTO_DEFAULT
Definition: flow-private.h:69
AppLayerParserSetEOF
void AppLayerParserSetEOF(AppLayerParserState *pstate)
Definition: app-layer-parser.c:1490
AppLayerParserProtoCtx_::RegisterUnittests
void(* RegisterUnittests)(void)
Definition: app-layer-parser.c:126
AppLayerParserStateFree
void AppLayerParserStateFree(AppLayerParserState *pstate)
Definition: app-layer-parser.c:247
app-layer-parser.h
AppLayerParserStateCleanup
void AppLayerParserStateCleanup(const Flow *f, void *alstate, AppLayerParserState *pstate)
Definition: app-layer-parser.c:1657
BUG_ON
#define BUG_ON(x)
Definition: suricata-common.h:317
AppLayerDecoderEvents_::cnt
uint8_t cnt
Definition: app-layer-events.h:37
Flow_::sgh_toclient
const struct SigGroupHead_ * sgh_toclient
Definition: flow.h:474
RegisterNFSTCPParsers
void RegisterNFSTCPParsers(void)
Definition: app-layer-nfs-tcp.c:46
AppLayerParserRegisterGetEventInfo
void AppLayerParserRegisterGetEventInfo(uint8_t ipproto, AppProto alproto, int(*StateGetEventInfo)(const char *event_name, uint8_t *event_id, AppLayerEventType *event_type))
Definition: app-layer-parser.c:581
AppLayerParserProtoCtx_::GetFrameNameById
AppLayerParserGetFrameNameByIdFn GetFrameNameById
Definition: app-layer-parser.c:110
AppLayerParserProtoCtx
struct AppLayerParserProtoCtx_ AppLayerParserProtoCtx
App layer protocol parser context.
AppLayerParserSetup
int AppLayerParserSetup(void)
Definition: app-layer-parser.c:259
SCReturn
#define SCReturn
Definition: util-debug.h:286
RegisterFTPParsers
void RegisterFTPParsers(void)
Definition: app-layer-ftp.c:1272
AppLayerParserRegisterProtocolUnittests
void AppLayerParserRegisterProtocolUnittests(uint8_t ipproto, AppProto alproto, void(*RegisterUnittests)(void))
Definition: app-layer-parser.c:1851
AppLayerGetTxIterState
Definition: app-layer-parser.h:134
AppLayerParserProtoCtx_::StateAlloc
void *(* StateAlloc)(void *, AppProto)
Definition: app-layer-parser.c:82
FlowGetProtoMapping
uint8_t FlowGetProtoMapping(uint8_t proto)
Function to map the protocol to the defined FLOW_PROTO_* enumeration.
Definition: flow-util.c:99
RegisterTFTPParsers
void RegisterTFTPParsers(void)
Definition: app-layer-tftp.c:155
FLOW_PROTO_APPLAYER_MAX
#define FLOW_PROTO_APPLAYER_MAX
Definition: flow-private.h:75
APP_LAYER_PARSER_EOF_TC
#define APP_LAYER_PARSER_EOF_TC
Definition: app-layer-parser.h:54
SCReturnUInt
#define SCReturnUInt(x)
Definition: util-debug.h:290
DEBUG_ASSERT_FLOW_LOCKED
#define DEBUG_ASSERT_FLOW_LOCKED(f)
Definition: util-validate.h:99
BOTH_SET_OR_BOTH_UNSET
#define BOTH_SET_OR_BOTH_UNSET(a, b)
Definition: app-layer-parser.c:1685
Frame::len
int64_t len
Definition: app-layer-frames.h:50
SCReturnPtr
#define SCReturnPtr(x, type)
Definition: util-debug.h:300
AppLayerParserProtoCtx_::StateFree
void(* StateFree)(void *)
Definition: app-layer-parser.c:83
AppLayerParserRegisterGetTxFilesFunc
void AppLayerParserRegisterGetTxFilesFunc(uint8_t ipproto, AppProto alproto, AppLayerGetFileState(*GetTxFiles)(void *, uint8_t))
Definition: app-layer-parser.c:458
AppLayerParserRegisterSetStreamDepthFlag
void AppLayerParserRegisterSetStreamDepthFlag(uint8_t ipproto, AppProto alproto, void(*SetStreamDepthFlag)(void *tx, uint8_t flags))
Definition: app-layer-parser.c:622
APP_LAYER_PARSER_SFRAME_TC
#define APP_LAYER_PARSER_SFRAME_TC
Definition: app-layer-parser.h:57
AppLayerIncParserErrorCounter
void AppLayerIncParserErrorCounter(ThreadVars *tv, Flow *f)
Definition: app-layer.c:181
ALPROTO_HTTP2
@ ALPROTO_HTTP2
Definition: app-layer-protos.h:69
RunmodeIsUnittests
int RunmodeIsUnittests(void)
Definition: suricata.c:274
APP_LAYER_PARSER_NO_INSPECTION
#define APP_LAYER_PARSER_NO_INSPECTION
Definition: app-layer-parser.h:49
AppLayerParserGetTx
void * AppLayerParserGetTx(uint8_t ipproto, AppProto alproto, void *alstate, uint64_t tx_id)
Definition: app-layer-parser.c:1102
g_detect_disabled
int g_detect_disabled
Definition: suricata.c:190
AppLayerParserRegisterParser
int AppLayerParserRegisterParser(uint8_t ipproto, AppProto alproto, uint8_t direction, AppLayerParserFPtr Parser)
Register app layer parser for the protocol.
Definition: app-layer-parser.c:402
app-layer-imap.h
Frame::flags
uint8_t flags
Definition: app-layer-frames.h:45
SCRealloc
#define SCRealloc(ptr, sz)
Definition: util-mem.h:50
AppLayerParserThreadCtxAlloc
AppLayerParserThreadCtx * AppLayerParserThreadCtxAlloc(void)
Gets a new app layer protocol's parser thread context.
Definition: app-layer-parser.c:297
AppLayerParserRegisterGetTx
void AppLayerParserRegisterGetTx(uint8_t ipproto, AppProto alproto, void *(StateGetTx)(void *alstate, uint64_t tx_id))
Definition: app-layer-parser.c:516
ConfigAction
ConfigAction
Definition: util-config.h:27
AppLayerErrorGetExceptionPolicy
enum ExceptionPolicy AppLayerErrorGetExceptionPolicy(void)
Definition: app-layer-parser.c:162
AppLayerParserProtoCtx_::Parser
AppLayerParserFPtr Parser[2]
Definition: app-layer-parser.c:71
app-layer-modbus.h
AppLayerParserProtoCtx_::StateTransactionFree
void(* StateTransactionFree)(void *, uint64_t)
Definition: app-layer-parser.c:84
app-layer-frames.h
AppLayerParserPreRegister
int AppLayerParserPreRegister(void(*Register)(void))
Definition: app-layer-parser.c:1764
RegisterSSLParsers
void RegisterSSLParsers(void)
Function to register the SSL protocol parser and other functions.
Definition: app-layer-ssl.c:3187
AppLayerParserProtoCtx_::option_flags
uint32_t option_flags
Definition: app-layer-parser.c:119
StreamTcpSetSessionNoReassemblyFlag
void StreamTcpSetSessionNoReassemblyFlag(TcpSession *, char)
disable reassembly
Definition: stream-tcp.c:6866
flags
uint8_t flags
Definition: decode-gre.h:0
AppLayerParserParse
int AppLayerParserParse(ThreadVars *tv, AppLayerParserThreadCtx *alp_tctx, Flow *f, AppProto alproto, uint8_t flags, const uint8_t *input, uint32_t input_len)
Definition: app-layer-parser.c:1284
AppLayerParserGetFrameNameByIdFn
const char *(* AppLayerParserGetFrameNameByIdFn)(const uint8_t id)
Definition: app-layer-parser.h:161
StreamTcpDisableAppLayer
void StreamTcpDisableAppLayer(Flow *f)
Definition: stream-tcp-reassemble.c:446
suricata-common.h
AppLayerParserCtx_::ctxs
AppLayerParserProtoCtx(* ctxs)[FLOW_PROTO_MAX]
Definition: app-layer-parser.c:131
AppLayerParserGetFrameIdByName
int AppLayerParserGetFrameIdByName(uint8_t ipproto, AppProto alproto, const char *name)
Definition: app-layer-parser.c:1620
ALPROTO_HTTP1
@ ALPROTO_HTTP1
Definition: app-layer-protos.h:36
SCAppLayerParserRegisterParserAcceptableDataDirection
void SCAppLayerParserRegisterParserAcceptableDataDirection(uint8_t ipproto, AppProto alproto, uint8_t direction)
Definition: app-layer-parser.c:414
AppLayerParserProtoCtx_::internal_flags
uint32_t internal_flags
Definition: app-layer-parser.c:122
AppLayerParserRegisterStateDataFunc
void AppLayerParserRegisterStateDataFunc(uint8_t ipproto, AppProto alproto, AppLayerStateData *(*GetStateData)(void *state))
Definition: app-layer-parser.c:602
FilesPrune
void FilesPrune(FileContainer *fc, const StreamingBufferConfig *sbcfg, const bool trunc)
Definition: util-file.c:1175
AppLayerIncInternalErrorCounter
void AppLayerIncInternalErrorCounter(ThreadVars *tv, Flow *f)
Definition: app-layer.c:189
AppLayerParserGetStateNameByIdFn
const char *(* AppLayerParserGetStateNameByIdFn)(const int id, const uint8_t direction)
Definition: app-layer-parser.h:158
AppLayerParserGetTxData
AppLayerTxData * AppLayerParserGetTxData(uint8_t ipproto, AppProto alproto, void *tx)
Definition: app-layer-parser.c:1176
FatalError
#define FatalError(...)
Definition: util-debug.h:517
AppLayerParserRegisterTxDataFunc
void AppLayerParserRegisterTxDataFunc(uint8_t ipproto, AppProto alproto, AppLayerTxData *(*GetTxData)(void *tx))
Definition: app-layer-parser.c:592
SCAppLayerDecoderEventsFreeEvents
void SCAppLayerDecoderEventsFreeEvents(AppLayerDecoderEvents **events)
Definition: app-layer-events.c:137
TcpSession_::client
TcpStream client
Definition: stream-tcp-private.h:297
AppLayerParserGetStreamDepth
uint32_t AppLayerParserGetStreamDepth(const Flow *f)
Definition: app-layer-parser.c:1572
RegisterIMAPParsers
void RegisterIMAPParsers(void)
Definition: app-layer-imap.c:84
tv
ThreadVars * tv
Definition: fuzz_decodepcapfile.c:33
AppLayerParserProtoCtx_::GetTxFiles
AppLayerGetFileState(* GetTxFiles)(void *, uint8_t)
Definition: app-layer-parser.c:90
AppLayerParserProtoCtx_::GetStateIdByName
AppLayerParserGetStateIdByNameFn GetStateIdByName
Definition: app-layer-parser.c:112
AppLayerStateData
struct AppLayerStateData AppLayerStateData
Definition: app-layer-parser.h:44
app-layer-events.h
util-validate.h
FRAME_STREAM_TYPE
#define FRAME_STREAM_TYPE
Definition: app-layer-frames.h:30
APP_LAYER_PARSER_OPT_ACCEPT_GAPS
#define APP_LAYER_PARSER_OPT_ACCEPT_GAPS
Definition: app-layer-parser.h:60
APP_LAYER_TX_INSPECTED_TS
#define APP_LAYER_TX_INSPECTED_TS
Definition: app-layer-parser.h:70
TcpSession_::server
TcpStream server
Definition: stream-tcp-private.h:296
AppLayerParserRegisterGetTxIterator
void AppLayerParserRegisterGetTxIterator(uint8_t ipproto, AppProto alproto, AppLayerGetTxIteratorFunc Func)
Definition: app-layer-parser.c:526
SCConfGetNode
SCConfNode * SCConfGetNode(const char *name)
Get a SCConfNode by name.
Definition: conf.c:182
SCLogError
#define SCLogError(...)
Macro used to log ERROR messages.
Definition: util-debug.h:274
AppLayerParserProtoCtx_::complete_ts
int complete_ts
Definition: app-layer-parser.c:96
FLOW_SGH_TOSERVER
#define FLOW_SGH_TOSERVER
Definition: flow.h:72
SCFree
#define SCFree(p)
Definition: util-mem.h:61
Flow_::alstate
void * alstate
Definition: flow.h:470
AppLayerParserPostStreamSetup
void AppLayerParserPostStreamSetup(void)
Definition: app-layer-parser.c:272
util-config.h
Flow_::flags
uint32_t flags
Definition: flow.h:412
AppLayerParserGetDecoderEvents
AppLayerDecoderEvents * AppLayerParserGetDecoderEvents(AppLayerParserState *pstate)
Definition: app-layer-parser.c:842
THREE_SET
#define THREE_SET(a, b, c)
Definition: app-layer-parser.c:1686
AppLayerGetProtoName
const char * AppLayerGetProtoName(AppProto alproto)
Given the internal protocol id, returns a string representation of the protocol.
Definition: app-layer.c:1014
UTHAppLayerParserStateGetIds
void UTHAppLayerParserStateGetIds(void *ptr, uint64_t *i1, uint64_t *i2, uint64_t *log, uint64_t *min)
Definition: app-layer-parser.c:214
RegisterHTPParsers
void RegisterHTPParsers(void)
Register the HTTP protocol and state handling functions to APP layer of the engine.
Definition: app-layer-htp.c:2620
AppLayerParserGetStateIdByNameFn
int(* AppLayerParserGetStateIdByNameFn)(const char *name, const uint8_t direction)
Definition: app-layer-parser.h:153
ALPROTO_HTTP
@ ALPROTO_HTTP
Definition: app-layer-protos.h:76
FRAME_FLAG_ENDS_AT_EOF
#define FRAME_FLAG_ENDS_AT_EOF
Definition: app-layer-frames.h:38
RegisterSMTPParsers
void RegisterSMTPParsers(void)
Register the SMTP Protocol parser.
Definition: app-layer-smtp.c:1867
AppLayerParserStateAlloc
AppLayerParserState * AppLayerParserStateAlloc(void)
Definition: app-layer-parser.c:235
SCReturnCT
#define SCReturnCT(x, type)
Definition: util-debug.h:298
AppLayerParserState_::decoder_events
AppLayerDecoderEvents * decoder_events
Definition: app-layer-parser.c:150
AppLayerParserRegisterGetTxCnt
void AppLayerParserRegisterGetTxCnt(uint8_t ipproto, AppProto alproto, uint64_t(*StateGetTxCnt)(void *alstate))
Definition: app-layer-parser.c:506
app-layer-smb.h
AppLayerParserProtoCtx_::StateGetProgress
int(* StateGetProgress)(void *alstate, uint8_t direction)
Definition: app-layer-parser.c:92
AppLayerParserProtocolGetLoggerBits
LoggerId AppLayerParserProtocolGetLoggerBits(uint8_t ipproto, AppProto alproto)
Definition: app-layer-parser.c:1542
AppLayerParserCtx_
Definition: app-layer-parser.c:130
AppLayerParserRegisterGetEventInfoById
void AppLayerParserRegisterGetEventInfoById(uint8_t ipproto, AppProto alproto, int(*StateGetEventInfoById)(uint8_t event_id, const char **event_name, AppLayerEventType *event_type))
Definition: app-layer-parser.c:549
AppLayerGetTxIteratorFunc
AppLayerGetTxIterTuple(* AppLayerGetTxIteratorFunc)(const uint8_t ipproto, const AppProto alproto, void *alstate, uint64_t min_tx_id, uint64_t max_tx_id, AppLayerGetTxIterState *state)
tx iterator prototype
Definition: app-layer-parser.h:143
g_file_logger_enabled
bool g_file_logger_enabled
Definition: output-file.c:39
RegisterHTTP2Parsers
void RegisterHTTP2Parsers(void)
Definition: app-layer-http2.c:54
STREAM_APP_PROGRESS
#define STREAM_APP_PROGRESS(stream)
Definition: stream-tcp-private.h:145
AppLayerParserThreadCtx_
Definition: app-layer-parser.c:60
app-layer-smtp.h
APP_LAYER_PARSER_NO_INSPECTION_PAYLOAD
#define APP_LAYER_PARSER_NO_INSPECTION_PAYLOAD
Definition: app-layer-parser.h:51
FlowChangeProto
int FlowChangeProto(Flow *f)
Check if change proto flag is set for flow.
Definition: flow.c:197
FlowGetDisruptionFlags
uint8_t FlowGetDisruptionFlags(const Flow *f, uint8_t flags)
get 'disruption' flags: GAP/DEPTH/PASS
Definition: flow.c:1165
TcpSession_
Definition: stream-tcp-private.h:283
flow.h
SCAppLayerParserReallocCtx
int SCAppLayerParserReallocCtx(AppProto alproto)
Definition: app-layer-parser.c:1746
SCLogNotice
#define SCLogNotice(...)
Macro used to log NOTICE messages.
Definition: util-debug.h:250
RegisterNFSUDPParsers
void RegisterNFSUDPParsers(void)
Definition: app-layer-nfs-udp.c:63
AppLayerParserGetMinId
uint64_t AppLayerParserGetMinId(AppLayerParserState *pstate)
Definition: app-layer-parser.c:708
Flow_::file_flags
uint16_t file_flags
Definition: flow.h:414
Flow_::alproto
AppProto alproto
application level protocol
Definition: flow.h:441
ExceptionPolicy
ExceptionPolicy
Definition: util-exception-policy-types.h:26
SCCalloc
#define SCCalloc(nm, sz)
Definition: util-mem.h:53
AppLayerParserDestroyProtocolParserLocalStorage
void AppLayerParserDestroyProtocolParserLocalStorage(uint8_t ipproto, AppProto alproto, void *local_data)
Definition: app-layer-parser.c:646
SCReturnInt
#define SCReturnInt(x)
Definition: util-debug.h:288
SCConfNode_
Definition: conf.h:37
SCConfNode_::val
char * val
Definition: conf.h:39
AppLayerParserGetTxCnt
uint64_t AppLayerParserGetTxCnt(const Flow *f, void *alstate)
Definition: app-layer-parser.c:1095
SMTPParserCleanup
void SMTPParserCleanup(void)
Free memory allocated for global SMTP parser state.
Definition: app-layer-smtp.c:1922
AppLayerParserHasDecoderEvents
bool AppLayerParserHasDecoderEvents(AppLayerParserState *pstate)
Definition: app-layer-parser.c:1506
AppLayerParserGetFrameIdByNameFn
int(* AppLayerParserGetFrameIdByNameFn)(const char *frame_name)
Definition: app-layer-parser.h:160
AppLayerDecoderEvents_::events
uint8_t * events
Definition: app-layer-events.h:35
AppLayerParserState_::frames
FramesContainer * frames
Definition: app-layer-parser.c:152
StreamTcpSetSessionBypassFlag
void StreamTcpSetSessionBypassFlag(TcpSession *)
enable bypass
Definition: stream-tcp.c:6889
DEBUG_VALIDATE_BUG_ON
#define DEBUG_VALIDATE_BUG_ON(exp)
Definition: util-validate.h:102
app-layer-ssl.h
ARRAY_CAP_STEP
#define ARRAY_CAP_STEP
Definition: app-layer-parser.c:1741
FLOW_PROTO_MAX
@ FLOW_PROTO_MAX
Definition: flow-private.h:72
APP_LAYER_TX_INSPECTED_TC
#define APP_LAYER_TX_INSPECTED_TC
Definition: app-layer-parser.h:71
AppLayerParserProtoCtx_::LocalStorageAlloc
void *(* LocalStorageAlloc)(void)
Definition: app-layer-parser.c:85
AppLayerParserGetEventInfo
int AppLayerParserGetEventInfo(uint8_t ipproto, AppProto alproto, const char *event_name, uint8_t *event_id, AppLayerEventType *event_type)
Definition: app-layer-parser.c:1117
app-layer-nfs-tcp.h
APP_LAYER_TX_SKIP_INSPECT_TS
#define APP_LAYER_TX_SKIP_INSPECT_TS
Definition: app-layer-parser.h:67
app-layer.h
AppLayerParserProtoCtx_::first_data_dir
uint8_t first_data_dir
Definition: app-layer-parser.c:78