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