suricata
app-layer-parser.c
Go to the documentation of this file.
1 /* Copyright (C) 2007-2020 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 "debug.h"
28 #include "util-unittest.h"
29 #include "decode.h"
30 #include "threads.h"
31 
32 #include "util-print.h"
33 #include "util-pool.h"
34 
35 #include "flow-util.h"
36 #include "flow-private.h"
37 
38 #include "detect-engine-state.h"
39 #include "detect-engine-port.h"
40 
41 #include "stream-tcp.h"
42 #include "stream-tcp-private.h"
43 #include "stream.h"
44 #include "stream-tcp-reassemble.h"
45 
46 #include "app-layer.h"
47 #include "app-layer-protos.h"
48 #include "app-layer-parser.h"
49 #include "app-layer-dcerpc.h"
50 #include "app-layer-dcerpc-udp.h"
51 #include "app-layer-smb.h"
52 #include "app-layer-htp.h"
53 #include "app-layer-ftp.h"
54 #include "app-layer-ssl.h"
55 #include "app-layer-ssh.h"
56 #include "app-layer-smtp.h"
57 #include "app-layer-modbus.h"
58 #include "app-layer-enip.h"
59 #include "app-layer-dnp3.h"
60 #include "app-layer-nfs-tcp.h"
61 #include "app-layer-nfs-udp.h"
62 #include "app-layer-ntp.h"
63 #include "app-layer-tftp.h"
64 #include "app-layer-ikev2.h"
65 #include "app-layer-krb5.h"
66 #include "app-layer-snmp.h"
67 #include "app-layer-sip.h"
68 #include "app-layer-rfb.h"
69 #include "app-layer-template.h"
71 #include "app-layer-rdp.h"
72 
73 #include "conf.h"
74 #include "util-spm.h"
75 
76 #include "util-debug.h"
77 #include "decode-events.h"
78 #include "util-unittest-helper.h"
79 #include "util-validate.h"
80 
81 #include "runmodes.h"
82 
83 #include "rust.h"
84 
87 };
88 
89 
90 /**
91  * \brief App layer protocol parser context.
92  */
94 {
95  /* 0 - to_server, 1 - to_client. */
97  bool logger;
98  uint32_t logger_bits; /**< registered loggers for this proto */
99 
100  void *(*StateAlloc)(void);
101  void (*StateFree)(void *);
102  void (*StateTransactionFree)(void *, uint64_t);
103  void *(*LocalStorageAlloc)(void);
104  void (*LocalStorageFree)(void *);
105 
106  void (*Truncate)(void *, uint8_t);
107  FileContainer *(*StateGetFiles)(void *, uint8_t);
108  AppLayerDecoderEvents *(*StateGetEvents)(void *);
109 
110  int (*StateGetProgress)(void *alstate, uint8_t direction);
111  uint64_t (*StateGetTxCnt)(void *alstate);
112  void *(*StateGetTx)(void *alstate, uint64_t tx_id);
114  int (*StateGetProgressCompletionStatus)(uint8_t direction);
115  int (*StateGetEventInfoById)(int event_id, const char **event_name,
116  AppLayerEventType *event_type);
117  int (*StateGetEventInfo)(const char *event_name,
118  int *event_id, AppLayerEventType *event_type);
119 
120  LoggerId (*StateGetTxLogged)(void *alstate, void *tx);
121  void (*StateSetTxLogged)(void *alstate, void *tx, LoggerId logger);
122 
123  DetectEngineState *(*GetTxDetectState)(void *tx);
124  int (*SetTxDetectState)(void *tx, DetectEngineState *);
125 
126  uint64_t (*GetTxDetectFlags)(void *tx, uint8_t dir);
127  void (*SetTxDetectFlags)(void *tx, uint8_t dir, uint64_t);
128 
129  void (*SetStreamDepthFlag)(void *tx, uint8_t flags);
130 
131  /* each app-layer has its own value */
132  uint32_t stream_depth;
133 
134  /* Indicates the direction the parser is ready to see the data
135  * the first time for a flow. Values accepted -
136  * STREAM_TOSERVER, STREAM_TOCLIENT */
137  uint8_t first_data_dir;
138 
139  /* Option flags such as supporting gaps or not. */
140  uint32_t option_flags;
141  /* coccinelle: AppLayerParserProtoCtx:option_flags:APP_LAYER_PARSER_OPT_ */
142 
143  uint32_t internal_flags;
144  /* coccinelle: AppLayerParserProtoCtx:internal_flags:APP_LAYER_PARSER_INT_ */
145 
146 #ifdef UNITTESTS
147  void (*RegisterUnittests)(void);
148 #endif
150 
151 typedef struct AppLayerParserCtx_ {
154 
156  /* coccinelle: AppLayerParserState:flags:APP_LAYER_PARSER_ */
157  uint8_t flags;
158 
159  /* Indicates the current transaction that is being inspected.
160  * We have a var per direction. */
161  uint64_t inspect_id[2];
162  /* Indicates the current transaction being logged. Unlike inspect_id,
163  * we don't need a var per direction since we don't log a transaction
164  * unless we have the entire transaction. */
165  uint64_t log_id;
166 
167  uint64_t min_id;
168 
169  /* Used to store decoder events. */
171 };
172 
173 #ifdef UNITTESTS
174 void UTHAppLayerParserStateGetIds(void *ptr, uint64_t *i1, uint64_t *i2, uint64_t *log, uint64_t *min)
175 {
176  struct AppLayerParserState_ *s = ptr;
177  *i1 = s->inspect_id[0];
178  *i2 = s->inspect_id[1];
179  *log = s->log_id;
180  *min = s->min_id;
181 }
182 #endif
183 
184 /* Static global version of the parser context.
185  * Post 2.0 let's look at changing this to move it out to app-layer.c. */
186 static AppLayerParserCtx alp_ctx;
187 
188 int AppLayerParserProtoIsRegistered(uint8_t ipproto, AppProto alproto)
189 {
190  uint8_t ipproto_map = FlowGetProtoMapping(ipproto);
191 
192  return (alp_ctx.ctxs[ipproto_map][alproto].StateAlloc != NULL) ? 1 : 0;
193 }
194 
196 {
197  SCEnter();
198 
199  AppLayerParserState *pstate = (AppLayerParserState *)SCMalloc(sizeof(*pstate));
200  if (pstate == NULL)
201  goto end;
202  memset(pstate, 0, sizeof(*pstate));
203 
204  end:
205  SCReturnPtr(pstate, "AppLayerParserState");
206 }
207 
209 {
210  SCEnter();
211 
212  if (pstate->decoder_events != NULL)
214  SCFree(pstate);
215 
216  SCReturn;
217 }
218 
220 {
221  SCEnter();
222  memset(&alp_ctx, 0, sizeof(alp_ctx));
223  SCReturnInt(0);
224 }
225 
227 {
228  AppProto alproto = 0;
229  int flow_proto = 0;
230 
231  /* lets set a default value for stream_depth */
232  for (flow_proto = 0; flow_proto < FLOW_PROTO_DEFAULT; flow_proto++) {
233  for (alproto = 0; alproto < ALPROTO_MAX; alproto++) {
234  if (!(alp_ctx.ctxs[flow_proto][alproto].internal_flags &
236  alp_ctx.ctxs[flow_proto][alproto].stream_depth =
238  }
239  }
240  }
241 }
242 
244 {
245  SCEnter();
246 
249 
250  SCReturnInt(0);
251 }
252 
254 {
255  SCEnter();
256 
257  AppProto alproto = 0;
258  int flow_proto = 0;
260 
261  tctx = SCMalloc(sizeof(*tctx));
262  if (tctx == NULL)
263  goto end;
264  memset(tctx, 0, sizeof(*tctx));
265 
266  for (flow_proto = 0; flow_proto < FLOW_PROTO_DEFAULT; flow_proto++) {
267  for (alproto = 0; alproto < ALPROTO_MAX; alproto++) {
268  uint8_t ipproto = FlowGetReverseProtoMapping(flow_proto);
269 
270  tctx->alproto_local_storage[flow_proto][alproto] =
272  }
273  }
274 
275  end:
276  SCReturnPtr(tctx, "void *");
277 }
278 
280 {
281  SCEnter();
282 
283  AppProto alproto = 0;
284  int flow_proto = 0;
285 
286  for (flow_proto = 0; flow_proto < FLOW_PROTO_DEFAULT; flow_proto++) {
287  for (alproto = 0; alproto < ALPROTO_MAX; alproto++) {
288  uint8_t ipproto = FlowGetReverseProtoMapping(flow_proto);
289 
291  tctx->alproto_local_storage[flow_proto][alproto]);
292  }
293  }
294 
295  SCFree(tctx);
296  SCReturn;
297 }
298 
299 /** \brief check if a parser is enabled in the config
300  * Returns enabled always if: were running unittests
301  */
302 int AppLayerParserConfParserEnabled(const char *ipproto,
303  const char *alproto_name)
304 {
305  SCEnter();
306 
307  int enabled = 1;
308  char param[100];
309  ConfNode *node;
310  int r;
311 
312  if (RunmodeIsUnittests())
313  goto enabled;
314 
315  r = snprintf(param, sizeof(param), "%s%s%s", "app-layer.protocols.",
316  alproto_name, ".enabled");
317  if (r < 0) {
318  SCLogError(SC_ERR_FATAL, "snprintf failure.");
319  exit(EXIT_FAILURE);
320  } else if (r > (int)sizeof(param)) {
321  SCLogError(SC_ERR_FATAL, "buffer not big enough to write param.");
322  exit(EXIT_FAILURE);
323  }
324 
325  node = ConfGetNode(param);
326  if (node == NULL) {
327  SCLogDebug("Entry for %s not found.", param);
328  r = snprintf(param, sizeof(param), "%s%s%s%s%s", "app-layer.protocols.",
329  alproto_name, ".", ipproto, ".enabled");
330  if (r < 0) {
331  SCLogError(SC_ERR_FATAL, "snprintf failure.");
332  exit(EXIT_FAILURE);
333  } else if (r > (int)sizeof(param)) {
334  SCLogError(SC_ERR_FATAL, "buffer not big enough to write param.");
335  exit(EXIT_FAILURE);
336  }
337 
338  node = ConfGetNode(param);
339  if (node == NULL) {
340  SCLogDebug("Entry for %s not found.", param);
341  goto enabled;
342  }
343  }
344 
345  if (ConfValIsTrue(node->val)) {
346  goto enabled;
347  } else if (ConfValIsFalse(node->val)) {
348  goto disabled;
349  } else if (strcasecmp(node->val, "detection-only") == 0) {
350  goto disabled;
351  } else {
352  SCLogError(SC_ERR_FATAL, "Invalid value found for %s.", param);
353  exit(EXIT_FAILURE);
354  }
355 
356  disabled:
357  enabled = 0;
358  enabled:
359  SCReturnInt(enabled);
360 }
361 
362 /***** Parser related registration *****/
363 
364 int AppLayerParserRegisterParser(uint8_t ipproto, AppProto alproto,
365  uint8_t direction,
366  AppLayerParserFPtr Parser)
367 {
368  SCEnter();
369 
370  alp_ctx.ctxs[FlowGetProtoMapping(ipproto)][alproto].
371  Parser[(direction & STREAM_TOSERVER) ? 0 : 1] = Parser;
372 
373  SCReturnInt(0);
374 }
375 
377  uint8_t direction)
378 {
379  SCEnter();
380 
381  alp_ctx.ctxs[FlowGetProtoMapping(ipproto)][alproto].first_data_dir |=
382  (direction & (STREAM_TOSERVER | STREAM_TOCLIENT));
383 
384  SCReturn;
385 }
386 
387 void AppLayerParserRegisterOptionFlags(uint8_t ipproto, AppProto alproto,
388  uint32_t flags)
389 {
390  SCEnter();
391 
392  alp_ctx.ctxs[FlowGetProtoMapping(ipproto)][alproto].option_flags |= flags;
393 
394  SCReturn;
395 }
396 
397 void AppLayerParserRegisterStateFuncs(uint8_t ipproto, AppProto alproto,
398  void *(*StateAlloc)(void),
399  void (*StateFree)(void *))
400 {
401  SCEnter();
402 
403  alp_ctx.ctxs[FlowGetProtoMapping(ipproto)][alproto].StateAlloc =
404  StateAlloc;
405  alp_ctx.ctxs[FlowGetProtoMapping(ipproto)][alproto].StateFree =
406  StateFree;
407 
408  SCReturn;
409 }
410 
411 void AppLayerParserRegisterLocalStorageFunc(uint8_t ipproto, AppProto alproto,
412  void *(*LocalStorageAlloc)(void),
413  void (*LocalStorageFree)(void *))
414 {
415  SCEnter();
416 
417  alp_ctx.ctxs[FlowGetProtoMapping(ipproto)][alproto].LocalStorageAlloc =
418  LocalStorageAlloc;
419  alp_ctx.ctxs[FlowGetProtoMapping(ipproto)][alproto].LocalStorageFree =
420  LocalStorageFree;
421 
422  SCReturn;
423 }
424 
425 void AppLayerParserRegisterGetFilesFunc(uint8_t ipproto, AppProto alproto,
426  FileContainer *(*StateGetFiles)(void *, uint8_t))
427 {
428  SCEnter();
429 
430  alp_ctx.ctxs[FlowGetProtoMapping(ipproto)][alproto].StateGetFiles =
431  StateGetFiles;
432 
433  SCReturn;
434 }
435 
436 void AppLayerParserRegisterGetEventsFunc(uint8_t ipproto, AppProto alproto,
437  AppLayerDecoderEvents *(*StateGetEvents)(void *))
438 {
439  SCEnter();
440 
441  alp_ctx.ctxs[FlowGetProtoMapping(ipproto)][alproto].StateGetEvents =
442  StateGetEvents;
443 
444  SCReturn;
445 }
446 
447 void AppLayerParserRegisterLoggerFuncs(uint8_t ipproto, AppProto alproto,
448  LoggerId (*StateGetTxLogged)(void *, void *),
449  void (*StateSetTxLogged)(void *, void *, LoggerId))
450 {
451  SCEnter();
452 
453  alp_ctx.ctxs[FlowGetProtoMapping(ipproto)][alproto].StateGetTxLogged =
454  StateGetTxLogged;
455 
456  alp_ctx.ctxs[FlowGetProtoMapping(ipproto)][alproto].StateSetTxLogged =
457  StateSetTxLogged;
458 
459  SCReturn;
460 }
461 
462 void AppLayerParserRegisterLoggerBits(uint8_t ipproto, AppProto alproto, LoggerId bits)
463 {
464  SCEnter();
465 
466  alp_ctx.ctxs[FlowGetProtoMapping(ipproto)][alproto].logger_bits = bits;
467 
468  SCReturn;
469 }
470 
471 void AppLayerParserRegisterLogger(uint8_t ipproto, AppProto alproto)
472 {
473  SCEnter();
474 
475  alp_ctx.ctxs[FlowGetProtoMapping(ipproto)][alproto].logger = true;
476 
477  SCReturn;
478 }
479 
480 void AppLayerParserRegisterTruncateFunc(uint8_t ipproto, AppProto alproto,
481  void (*Truncate)(void *, uint8_t))
482 {
483  SCEnter();
484 
485  alp_ctx.ctxs[FlowGetProtoMapping(ipproto)][alproto].Truncate = Truncate;
486 
487  SCReturn;
488 }
489 
491  int (*StateGetProgress)(void *alstate, uint8_t direction))
492 {
493  SCEnter();
494 
495  alp_ctx.ctxs[FlowGetProtoMapping(ipproto)][alproto].
496  StateGetProgress = StateGetProgress;
497 
498  SCReturn;
499 }
500 
501 void AppLayerParserRegisterTxFreeFunc(uint8_t ipproto, AppProto alproto,
502  void (*StateTransactionFree)(void *, uint64_t))
503 {
504  SCEnter();
505 
506  alp_ctx.ctxs[FlowGetProtoMapping(ipproto)][alproto].
507  StateTransactionFree = StateTransactionFree;
508 
509  SCReturn;
510 }
511 
512 void AppLayerParserRegisterGetTxCnt(uint8_t ipproto, AppProto alproto,
513  uint64_t (*StateGetTxCnt)(void *alstate))
514 {
515  SCEnter();
516 
517  alp_ctx.ctxs[FlowGetProtoMapping(ipproto)][alproto].
518  StateGetTxCnt = StateGetTxCnt;
519 
520  SCReturn;
521 }
522 
523 void AppLayerParserRegisterGetTx(uint8_t ipproto, AppProto alproto,
524  void *(StateGetTx)(void *alstate, uint64_t tx_id))
525 {
526  SCEnter();
527 
528  alp_ctx.ctxs[FlowGetProtoMapping(ipproto)][alproto].
529  StateGetTx = StateGetTx;
530 
531  SCReturn;
532 }
533 
534 void AppLayerParserRegisterGetTxIterator(uint8_t ipproto, AppProto alproto,
536 {
537  SCEnter();
538  alp_ctx.ctxs[FlowGetProtoMapping(ipproto)][alproto].StateGetTxIterator = Func;
539  SCReturn;
540 }
541 
543  int (*StateGetProgressCompletionStatus)(uint8_t direction))
544 {
545  SCEnter();
546 
547  alp_ctx.ctxs[FLOW_PROTO_DEFAULT][alproto].
548  StateGetProgressCompletionStatus = StateGetProgressCompletionStatus;
549 
550  SCReturn;
551 }
552 
553 void AppLayerParserRegisterGetEventInfoById(uint8_t ipproto, AppProto alproto,
554  int (*StateGetEventInfoById)(int event_id, const char **event_name,
555  AppLayerEventType *event_type))
556 {
557  SCEnter();
558 
559  alp_ctx.ctxs[FlowGetProtoMapping(ipproto)][alproto].
560  StateGetEventInfoById = StateGetEventInfoById;
561 
562  SCReturn;
563 }
564 
565 void AppLayerParserRegisterGetEventInfo(uint8_t ipproto, AppProto alproto,
566  int (*StateGetEventInfo)(const char *event_name, int *event_id,
567  AppLayerEventType *event_type))
568 {
569  SCEnter();
570 
571  alp_ctx.ctxs[FlowGetProtoMapping(ipproto)][alproto].
572  StateGetEventInfo = StateGetEventInfo;
573 
574  SCReturn;
575 }
576 
577 void AppLayerParserRegisterDetectStateFuncs(uint8_t ipproto, AppProto alproto,
578  DetectEngineState *(*GetTxDetectState)(void *tx),
579  int (*SetTxDetectState)(void *tx, DetectEngineState *))
580 {
581  SCEnter();
582 
583  alp_ctx.ctxs[FlowGetProtoMapping(ipproto)][alproto].GetTxDetectState = GetTxDetectState;
584  alp_ctx.ctxs[FlowGetProtoMapping(ipproto)][alproto].SetTxDetectState = SetTxDetectState;
585 
586  SCReturn;
587 }
588 
589 void AppLayerParserRegisterDetectFlagsFuncs(uint8_t ipproto, AppProto alproto,
590  uint64_t(*GetTxDetectFlags)(void *tx, uint8_t dir),
591  void (*SetTxDetectFlags)(void *tx, uint8_t dir, uint64_t))
592 {
593  SCEnter();
594 
595  alp_ctx.ctxs[FlowGetProtoMapping(ipproto)][alproto].GetTxDetectFlags = GetTxDetectFlags;
596  alp_ctx.ctxs[FlowGetProtoMapping(ipproto)][alproto].SetTxDetectFlags = SetTxDetectFlags;
597 
598  SCReturn;
599 }
600 
602  void (*SetStreamDepthFlag)(void *tx, uint8_t flags))
603 {
604  SCEnter();
605 
606  alp_ctx.ctxs[FlowGetProtoMapping(ipproto)][alproto].SetStreamDepthFlag = SetStreamDepthFlag;
607 
608  SCReturn;
609 }
610 
611 /***** Get and transaction functions *****/
612 
614 {
615  SCEnter();
616  void * r = NULL;
617 
618  if (alp_ctx.ctxs[FlowGetProtoMapping(ipproto)][alproto].
619  LocalStorageAlloc != NULL)
620  {
621  r = alp_ctx.ctxs[FlowGetProtoMapping(ipproto)][alproto].
622  LocalStorageAlloc();
623  }
624 
625  SCReturnPtr(r, "void *");
626 }
627 
629  void *local_data)
630 {
631  SCEnter();
632 
633  if (alp_ctx.ctxs[FlowGetProtoMapping(ipproto)][alproto].
634  LocalStorageFree != NULL)
635  {
636  alp_ctx.ctxs[FlowGetProtoMapping(ipproto)][alproto].
637  LocalStorageFree(local_data);
638  }
639 
640  SCReturn;
641 }
642 
643 /** \brief default tx iterator
644  *
645  * Used if the app layer parser doesn't register its own iterator.
646  * Simply walks the tx_id space until it finds a tx. Uses 'state' to
647  * keep track of where it left off.
648  *
649  * \retval txptr or NULL if no more txs in list
650  */
651 static AppLayerGetTxIterTuple AppLayerDefaultGetTxIterator(
652  const uint8_t ipproto, const AppProto alproto,
653  void *alstate, uint64_t min_tx_id, uint64_t max_tx_id,
654  AppLayerGetTxIterState *state)
655 {
656  uint64_t ustate = *(uint64_t *)state;
657  uint64_t tx_id = MAX(min_tx_id, ustate);
658  for ( ; tx_id < max_tx_id; tx_id++) {
659  void *tx_ptr = AppLayerParserGetTx(ipproto, alproto, alstate, tx_id);
660  if (tx_ptr != NULL) {
661  ustate = tx_id + 1;
662  *state = *(AppLayerGetTxIterState *)&ustate;
663  AppLayerGetTxIterTuple tuple = {
664  .tx_ptr = tx_ptr,
665  .tx_id = tx_id,
666  .has_next = (tx_id + 1 < max_tx_id),
667  };
668  SCLogDebug("tuple: %p/%"PRIu64"/%s", tuple.tx_ptr, tuple.tx_id,
669  tuple.has_next ? "true" : "false");
670  return tuple;
671  }
672  }
673 
674  AppLayerGetTxIterTuple no_tuple = { NULL, 0, false };
675  return no_tuple;
676 }
677 
679  const AppProto alproto)
680 {
682  alp_ctx.ctxs[FlowGetProtoMapping(ipproto)][alproto].StateGetTxIterator;
683  return Func ? Func : AppLayerDefaultGetTxIterator;
684 }
685 
686 void AppLayerParserSetTxLogged(uint8_t ipproto, AppProto alproto,
687  void *alstate, void *tx, LoggerId logger)
688 {
689  SCEnter();
690 
691  if (alp_ctx.ctxs[FlowGetProtoMapping(ipproto)][alproto].
692  StateSetTxLogged != NULL) {
693  alp_ctx.ctxs[FlowGetProtoMapping(ipproto)][alproto].
694  StateSetTxLogged(alstate, tx, logger);
695  }
696 
697  SCReturn;
698 }
699 
701  void *alstate, void *tx)
702 {
703  SCEnter();
704 
705  LoggerId r = 0;
706  if (alp_ctx.ctxs[f->protomap][f->alproto].StateGetTxLogged != NULL) {
707  r = alp_ctx.ctxs[f->protomap][f->alproto].
708  StateGetTxLogged(alstate, tx);
709  }
710 
711  SCReturnUInt(r);
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(0ULL, "uint64_t");
737 
738  SCReturnCT(pstate->inspect_id[direction & STREAM_TOSERVER ? 0 : 1], "uint64_t");
739 }
740 
742  void *alstate, const uint8_t flags,
743  bool tag_txs_as_inspected)
744 {
745  SCEnter();
746 
747  const int direction = (flags & STREAM_TOSERVER) ? 0 : 1;
748  const uint64_t total_txs = AppLayerParserGetTxCnt(f, alstate);
749  uint64_t idx = AppLayerParserGetTransactionInspectId(pstate, flags);
750  const int state_done_progress = AppLayerParserGetStateProgressCompletionStatus(f->alproto, flags);
751  const uint8_t ipproto = f->proto;
752  const AppProto alproto = f->alproto;
753 
754  AppLayerGetTxIteratorFunc IterFunc = AppLayerGetTxIterator(ipproto, alproto);
756  memset(&state, 0, sizeof(state));
757 
758  SCLogDebug("called: %s, tag_txs_as_inspected %s",direction==0?"toserver":"toclient",
759  tag_txs_as_inspected?"true":"false");
760 
761  /* mark all txs as inspected if the applayer progress is
762  * at the 'end state'. */
763  while (1) {
764  AppLayerGetTxIterTuple ires = IterFunc(ipproto, alproto, alstate, idx, total_txs, &state);
765  if (ires.tx_ptr == NULL)
766  break;
767 
768  void *tx = ires.tx_ptr;
769  idx = ires.tx_id;
770 
771  int state_progress = AppLayerParserGetStateProgress(ipproto, alproto, tx, flags);
772  if (state_progress < state_done_progress)
773  break;
774 
775  if (tag_txs_as_inspected) {
776  uint64_t detect_flags = AppLayerParserGetTxDetectFlags(ipproto, alproto, tx, flags);
777  if ((detect_flags & APP_LAYER_TX_INSPECTED_FLAG) == 0) {
778  detect_flags |= APP_LAYER_TX_INSPECTED_FLAG;
779  AppLayerParserSetTxDetectFlags(ipproto, alproto, tx, flags, detect_flags);
780  SCLogDebug("%p/%"PRIu64" in-order tx is done for direction %s. Flag %016"PRIx64,
781  tx, idx, flags & STREAM_TOSERVER ? "toserver" : "toclient", detect_flags);
782  }
783  }
784  idx++;
785  if (!ires.has_next)
786  break;
787  }
788  pstate->inspect_id[direction] = idx;
789  SCLogDebug("inspect_id now %"PRIu64, pstate->inspect_id[direction]);
790 
791  /* if necessary we flag all txs that are complete as 'inspected'
792  * also move inspect_id forward. */
793  if (tag_txs_as_inspected) {
794  /* continue at idx */
795  while (1) {
796  AppLayerGetTxIterTuple ires = IterFunc(ipproto, alproto, alstate, idx, total_txs, &state);
797  if (ires.tx_ptr == NULL)
798  break;
799 
800  void *tx = ires.tx_ptr;
801  /* if we got a higher id than the minimum we requested, we
802  * skipped a bunch of 'null-txs'. Lets see if we can up the
803  * inspect tracker */
804  if (ires.tx_id > idx && pstate->inspect_id[direction] == idx) {
805  pstate->inspect_id[direction] = ires.tx_id;
806  }
807  idx = ires.tx_id;
808 
809  const int state_progress = AppLayerParserGetStateProgress(ipproto, alproto, tx, flags);
810  if (state_progress < state_done_progress)
811  break;
812 
813  uint64_t detect_flags = AppLayerParserGetTxDetectFlags(ipproto, alproto, tx, flags);
814  if ((detect_flags & APP_LAYER_TX_INSPECTED_FLAG) == 0) {
815  detect_flags |= APP_LAYER_TX_INSPECTED_FLAG;
816  AppLayerParserSetTxDetectFlags(ipproto, alproto, tx, flags, detect_flags);
817  SCLogDebug("%p/%"PRIu64" out of order tx is done for direction %s. Flag %016"PRIx64,
818  tx, idx, flags & STREAM_TOSERVER ? "toserver" : "toclient", detect_flags);
819 
820  SCLogDebug("%p/%"PRIu64" out of order tx. Update inspect_id? %"PRIu64,
821  tx, idx, pstate->inspect_id[direction]);
822  if (pstate->inspect_id[direction]+1 == idx)
823  pstate->inspect_id[direction] = idx;
824  }
825  if (!ires.has_next)
826  break;
827  idx++;
828  }
829  }
830 
831  SCReturn;
832 }
833 
835 {
836  SCEnter();
837 
838  SCReturnPtr(pstate->decoder_events,
839  "AppLayerDecoderEvents *");
840 }
841 
843 {
844  pstate->decoder_events = devents;
845 }
846 
848  void *tx)
849 {
850  SCEnter();
851 
852  AppLayerDecoderEvents *ptr = NULL;
853 
854  if (alp_ctx.ctxs[FlowGetProtoMapping(ipproto)][alproto].
855  StateGetEvents != NULL)
856  {
857  ptr = alp_ctx.ctxs[FlowGetProtoMapping(ipproto)][alproto].
858  StateGetEvents(tx);
859  }
860 
861  SCReturnPtr(ptr, "AppLayerDecoderEvents *");
862 }
863 
864 FileContainer *AppLayerParserGetFiles(const Flow *f, const uint8_t direction)
865 {
866  SCEnter();
867 
868  FileContainer *ptr = NULL;
869 
870  if (alp_ctx.ctxs[f->protomap][f->alproto].StateGetFiles != NULL)
871  {
872  ptr = alp_ctx.ctxs[f->protomap][f->alproto].
873  StateGetFiles(f->alstate, direction);
874  }
875 
876  SCReturnPtr(ptr, "FileContainer *");
877 }
878 
879 /**
880  * \brief remove obsolete (inspected and logged) transactions
881  */
883 {
884  SCEnter();
886 
887  AppLayerParserProtoCtx *p = &alp_ctx.ctxs[f->protomap][f->alproto];
888  if (unlikely(p->StateTransactionFree == NULL))
889  SCReturn;
890 
891  const bool has_tx_detect_flags = (p->GetTxDetectFlags != NULL);
892  const uint8_t ipproto = f->proto;
893  const AppProto alproto = f->alproto;
894  void * const alstate = f->alstate;
895  AppLayerParserState * const alparser = f->alparser;
896 
897  if (alstate == NULL || alparser == NULL)
898  SCReturn;
899 
900  const uint64_t min = alparser->min_id;
901  const uint64_t total_txs = AppLayerParserGetTxCnt(f, alstate);
902  const LoggerId logger_expectation = AppLayerParserProtocolGetLoggerBits(ipproto, alproto);
903  const int tx_end_state_ts = AppLayerParserGetStateProgressCompletionStatus(alproto, STREAM_TOSERVER);
904  const int tx_end_state_tc = AppLayerParserGetStateProgressCompletionStatus(alproto, STREAM_TOCLIENT);
905 
906  AppLayerGetTxIteratorFunc IterFunc = AppLayerGetTxIterator(ipproto, alproto);
908  memset(&state, 0, sizeof(state));
909  uint64_t i = min;
910  uint64_t new_min = min;
911  SCLogDebug("start min %"PRIu64, min);
912  bool skipped = false;
913 
914  while (1) {
915  AppLayerGetTxIterTuple ires = IterFunc(ipproto, alproto, alstate, i, total_txs, &state);
916  if (ires.tx_ptr == NULL)
917  break;
918 
919  void *tx = ires.tx_ptr;
920  i = ires.tx_id; // actual tx id for the tx the IterFunc returned
921 
922  SCLogDebug("%p/%"PRIu64" checking", tx, i);
923 
924  const int tx_progress_tc = AppLayerParserGetStateProgress(ipproto, alproto, tx, STREAM_TOCLIENT);
925  if (tx_progress_tc < tx_end_state_tc) {
926  SCLogDebug("%p/%"PRIu64" skipping: tc parser not done", tx, i);
927  skipped = true;
928  goto next;
929  }
930  const int tx_progress_ts = AppLayerParserGetStateProgress(ipproto, alproto, tx, STREAM_TOSERVER);
931  if (tx_progress_ts < tx_end_state_ts) {
932  SCLogDebug("%p/%"PRIu64" skipping: ts parser not done", tx, i);
933  skipped = true;
934  goto next;
935  }
936  if (has_tx_detect_flags) {
937  if (f->sgh_toserver != NULL) {
938  uint64_t detect_flags_ts = AppLayerParserGetTxDetectFlags(ipproto, alproto, tx, STREAM_TOSERVER);
939  if (!(detect_flags_ts & APP_LAYER_TX_INSPECTED_FLAG)) {
940  SCLogDebug("%p/%"PRIu64" skipping: TS inspect not done: ts:%"PRIx64,
941  tx, i, detect_flags_ts);
942  skipped = true;
943  goto next;
944  }
945  }
946  if (f->sgh_toclient != NULL) {
947  uint64_t detect_flags_tc = AppLayerParserGetTxDetectFlags(ipproto, alproto, tx, STREAM_TOCLIENT);
948  if (!(detect_flags_tc & APP_LAYER_TX_INSPECTED_FLAG)) {
949  SCLogDebug("%p/%"PRIu64" skipping: TC inspect not done: tc:%"PRIx64,
950  tx, i, detect_flags_tc);
951  skipped = true;
952  goto next;
953  }
954  }
955  }
956  if (logger_expectation != 0) {
957  LoggerId tx_logged = AppLayerParserGetTxLogged(f, alstate, tx);
958  if (tx_logged != logger_expectation) {
959  SCLogDebug("%p/%"PRIu64" skipping: logging not done: want:%"PRIx32", have:%"PRIx32,
960  tx, i, logger_expectation, tx_logged);
961  skipped = true;
962  goto next;
963  }
964  }
965 
966  /* if we are here, the tx can be freed. */
967  p->StateTransactionFree(alstate, i);
968  SCLogDebug("%p/%"PRIu64" freed", tx, i);
969 
970  /* if we didn't skip any tx so far, up the minimum */
971  SCLogDebug("skipped? %s i %"PRIu64", new_min %"PRIu64, skipped ? "true" : "false", i, new_min);
972  if (!skipped)
973  new_min = i + 1;
974  SCLogDebug("final i %"PRIu64", new_min %"PRIu64, i, new_min);
975 
976 next:
977  if (!ires.has_next) {
978  /* this was the last tx. See if we skipped any. If not
979  * we removed all and can update the minimum to the max
980  * id. */
981  SCLogDebug("no next: cur tx i %"PRIu64", total %"PRIu64, i, total_txs);
982  if (!skipped) {
983  new_min = total_txs;
984  SCLogDebug("no next: cur tx i %"PRIu64", total %"PRIu64": "
985  "new_min updated to %"PRIu64, i, total_txs, new_min);
986  }
987  break;
988  }
989  i++;
990  }
991 
992  /* see if we need to bring all trackers up to date. */
993  SCLogDebug("update f->alparser->min_id? %"PRIu64" vs %"PRIu64, new_min, alparser->min_id);
994  if (new_min > alparser->min_id) {
995  const uint64_t next_id = new_min;
996  alparser->min_id = next_id;
997  alparser->inspect_id[0] = MAX(alparser->inspect_id[0], next_id);
998  alparser->inspect_id[1] = MAX(alparser->inspect_id[1], next_id);
999  alparser->log_id = MAX(alparser->log_id, next_id);
1000  SCLogDebug("updated f->alparser->min_id %"PRIu64, alparser->min_id);
1001  }
1002  SCReturn;
1003 }
1004 
1005 #define IS_DISRUPTED(flags) \
1006  ((flags) & (STREAM_DEPTH|STREAM_GAP))
1007 
1008 /**
1009  * \brief get the progress value for a tx/protocol
1010  *
1011  * If the stream is disrupted, we return the 'completion' value.
1012  */
1013 int AppLayerParserGetStateProgress(uint8_t ipproto, AppProto alproto,
1014  void *alstate, uint8_t flags)
1015 {
1016  SCEnter();
1017  int r = 0;
1018  if (unlikely(IS_DISRUPTED(flags))) {
1019  r = alp_ctx.ctxs[FLOW_PROTO_DEFAULT][alproto].
1020  StateGetProgressCompletionStatus(flags);
1021  } else {
1022  r = alp_ctx.ctxs[FlowGetProtoMapping(ipproto)][alproto].
1023  StateGetProgress(alstate, flags);
1024  }
1025  SCReturnInt(r);
1026 }
1027 
1028 uint64_t AppLayerParserGetTxCnt(const Flow *f, void *alstate)
1029 {
1030  SCEnter();
1031  uint64_t r = 0;
1032  r = alp_ctx.ctxs[f->protomap][f->alproto].
1033  StateGetTxCnt(alstate);
1034  SCReturnCT(r, "uint64_t");
1035 }
1036 
1037 void *AppLayerParserGetTx(uint8_t ipproto, AppProto alproto, void *alstate, uint64_t tx_id)
1038 {
1039  SCEnter();
1040  void * r = NULL;
1041  r = alp_ctx.ctxs[FlowGetProtoMapping(ipproto)][alproto].
1042  StateGetTx(alstate, tx_id);
1043  SCReturnPtr(r, "void *");
1044 }
1045 
1047  uint8_t direction)
1048 {
1049  SCEnter();
1050  int r = alp_ctx.ctxs[FLOW_PROTO_DEFAULT][alproto].
1051  StateGetProgressCompletionStatus(direction);
1052  SCReturnInt(r);
1053 }
1054 
1055 int AppLayerParserGetEventInfo(uint8_t ipproto, AppProto alproto, const char *event_name,
1056  int *event_id, AppLayerEventType *event_type)
1057 {
1058  SCEnter();
1059  int ipproto_map = FlowGetProtoMapping(ipproto);
1060  int r = (alp_ctx.ctxs[ipproto_map][alproto].StateGetEventInfo == NULL) ?
1061  -1 : alp_ctx.ctxs[ipproto_map][alproto].StateGetEventInfo(event_name, event_id, event_type);
1062  SCReturnInt(r);
1063 }
1064 
1065 int AppLayerParserGetEventInfoById(uint8_t ipproto, AppProto alproto, int event_id,
1066  const char **event_name, AppLayerEventType *event_type)
1067 {
1068  SCEnter();
1069  int ipproto_map = FlowGetProtoMapping(ipproto);
1070  *event_name = (const char *)NULL;
1071  int r = (alp_ctx.ctxs[ipproto_map][alproto].StateGetEventInfoById == NULL) ?
1072  -1 : alp_ctx.ctxs[ipproto_map][alproto].StateGetEventInfoById(event_id, event_name, event_type);
1073  SCReturnInt(r);
1074 }
1075 
1076 uint8_t AppLayerParserGetFirstDataDir(uint8_t ipproto, AppProto alproto)
1077 {
1078  SCEnter();
1079  uint8_t r = 0;
1080  r = alp_ctx.ctxs[FlowGetProtoMapping(ipproto)][alproto].
1081  first_data_dir;
1082  SCReturnCT(r, "uint8_t");
1083 }
1084 
1086  AppLayerParserState *pstate, uint8_t direction)
1087 {
1088  SCEnter();
1089 
1090  uint64_t active_id;
1091 
1092  uint64_t log_id = pstate->log_id;
1093  uint64_t inspect_id = pstate->inspect_id[direction & STREAM_TOSERVER ? 0 : 1];
1094  if (alp_ctx.ctxs[f->protomap][f->alproto].logger == true) {
1095  active_id = (log_id < inspect_id) ? log_id : inspect_id;
1096  } else {
1097  active_id = inspect_id;
1098  }
1099 
1100  SCReturnCT(active_id, "uint64_t");
1101 }
1102 
1103 int AppLayerParserSupportsFiles(uint8_t ipproto, AppProto alproto)
1104 {
1105  if (alp_ctx.ctxs[FlowGetProtoMapping(ipproto)][alproto].StateGetFiles != NULL)
1106  return TRUE;
1107  return FALSE;
1108 }
1109 
1110 int AppLayerParserSupportsTxDetectState(uint8_t ipproto, AppProto alproto)
1111 {
1112  if (alp_ctx.ctxs[FlowGetProtoMapping(ipproto)][alproto].GetTxDetectState != NULL)
1113  return TRUE;
1114  return FALSE;
1115 }
1116 
1117 DetectEngineState *AppLayerParserGetTxDetectState(uint8_t ipproto, AppProto alproto, void *tx)
1118 {
1119  SCEnter();
1120  DetectEngineState *s;
1121  s = alp_ctx.ctxs[FlowGetProtoMapping(ipproto)][alproto].GetTxDetectState(tx);
1122  SCReturnPtr(s, "DetectEngineState");
1123 }
1124 
1126  void *tx, DetectEngineState *s)
1127 {
1128  int r;
1129  SCEnter();
1130  if ((alp_ctx.ctxs[f->protomap][f->alproto].GetTxDetectState(tx) != NULL))
1131  SCReturnInt(-EBUSY);
1132  r = alp_ctx.ctxs[f->protomap][f->alproto].SetTxDetectState(tx, s);
1133  SCReturnInt(r);
1134 }
1135 
1137 {
1138  SCEnter();
1139  for (uint8_t p = 0; p < FLOW_PROTO_APPLAYER_MAX; p++) {
1140  if (alp_ctx.ctxs[p][alproto].GetTxDetectFlags != NULL) {
1141  SCReturnBool(true);
1142  }
1143  }
1144  SCReturnBool(false);
1145 }
1146 
1147 uint64_t AppLayerParserGetTxDetectFlags(uint8_t ipproto, AppProto alproto, void *tx, uint8_t dir)
1148 {
1149  SCEnter();
1150  uint64_t flags = 0;
1151  if (alp_ctx.ctxs[FlowGetProtoMapping(ipproto)][alproto].GetTxDetectFlags != NULL) {
1152  flags = alp_ctx.ctxs[FlowGetProtoMapping(ipproto)][alproto].GetTxDetectFlags(tx, dir);
1153  }
1155 }
1156 
1157 void AppLayerParserSetTxDetectFlags(uint8_t ipproto, AppProto alproto, void *tx, uint8_t dir, uint64_t flags)
1158 {
1159  SCEnter();
1160  if (alp_ctx.ctxs[FlowGetProtoMapping(ipproto)][alproto].SetTxDetectFlags != NULL) {
1161  alp_ctx.ctxs[FlowGetProtoMapping(ipproto)][alproto].SetTxDetectFlags(tx, dir, flags);
1162  }
1163  SCReturn;
1164 }
1165 
1166 /***** General *****/
1167 
1168 /** \retval int -1 in case of unrecoverable error. App-layer tracking stops for this flow.
1169  * \retval int 0 ok: we did not update app_progress
1170  * \retval int 1 ok: we updated app_progress */
1172  uint8_t flags, const uint8_t *input, uint32_t input_len)
1173 {
1174  SCEnter();
1175 #ifdef DEBUG_VALIDATION
1177 #endif
1178  AppLayerParserState *pstate = NULL;
1179  AppLayerParserProtoCtx *p = &alp_ctx.ctxs[f->protomap][alproto];
1180  void *alstate = NULL;
1181  uint64_t p_tx_cnt = 0;
1182  uint32_t consumed = input_len;
1183  const int direction = (flags & STREAM_TOSERVER) ? 0 : 1;
1184 
1185  /* we don't have the parser registered for this protocol */
1186  if (p->StateAlloc == NULL)
1187  goto end;
1188 
1189  if (flags & STREAM_GAP) {
1191  SCLogDebug("app-layer parser does not accept gaps");
1192  if (f->alstate != NULL) {
1194  flags);
1195  }
1196  goto error;
1197  }
1198  }
1199 
1200  /* Get the parser state (if any) */
1201  pstate = f->alparser;
1202  if (pstate == NULL) {
1203  f->alparser = pstate = AppLayerParserStateAlloc();
1204  if (pstate == NULL)
1205  goto error;
1206  }
1207 
1208  if (flags & STREAM_EOF)
1210 
1211  alstate = f->alstate;
1212  if (alstate == NULL) {
1213  f->alstate = alstate = p->StateAlloc();
1214  if (alstate == NULL)
1215  goto error;
1216  SCLogDebug("alloced new app layer state %p (name %s)",
1217  alstate, AppLayerGetProtoName(f->alproto));
1218  } else {
1219  SCLogDebug("using existing app layer state %p (name %s))",
1220  alstate, AppLayerGetProtoName(f->alproto));
1221  }
1222 
1223  p_tx_cnt = AppLayerParserGetTxCnt(f, f->alstate);
1224 
1225  /* invoke the recursive parser, but only on data. We may get empty msgs on EOF */
1226  if (input_len > 0 || (flags & STREAM_EOF)) {
1227  /* invoke the parser */
1228  AppLayerResult res = p->Parser[direction](f, alstate, pstate,
1229  input, input_len,
1230  alp_tctx->alproto_local_storage[f->protomap][alproto],
1231  flags);
1232  if (res.status < 0)
1233  {
1234  goto error;
1235  } else if (res.status > 0) {
1236  if (f->proto == IPPROTO_TCP && f->protoctx != NULL) {
1237  TcpSession *ssn = f->protoctx;
1238  SCLogDebug("direction %d/%s", direction,
1239  (flags & STREAM_TOSERVER) ? "toserver" : "toclient");
1240  BUG_ON(res.consumed > input_len);
1241  if (direction == 0) {
1242  /* parser told us how much data it needs on top of what it
1243  * consumed. So we need tell stream engine how much we need
1244  * before the next call */
1245  ssn->client.data_required = res.needed;
1246  SCLogDebug("setting data_required %u", ssn->client.data_required);
1247  } else {
1248  /* parser told us how much data it needs on top of what it
1249  * consumed. So we need tell stream engine how much we need
1250  * before the next call */
1251  ssn->server.data_required = res.needed;
1252  SCLogDebug("setting data_required %u", ssn->server.data_required);
1253  }
1254  } else {
1255  /* incomplete is only supported for TCP */
1256  BUG_ON(f->proto != IPPROTO_TCP);
1257  }
1258  BUG_ON(res.needed + res.consumed < input_len);
1259  BUG_ON(res.needed == 0);
1260  consumed = res.consumed;
1261  }
1262  }
1263 
1264  /* set the packets to no inspection and reassembly if required */
1265  if (pstate->flags & APP_LAYER_PARSER_NO_INSPECTION) {
1266  AppLayerParserSetEOF(pstate);
1267  FlowSetNoPayloadInspectionFlag(f);
1268 
1269  if (f->proto == IPPROTO_TCP) {
1271 
1272  /* Set the no reassembly flag for both the stream in this TcpSession */
1273  if (pstate->flags & APP_LAYER_PARSER_NO_REASSEMBLY) {
1274  /* Used only if it's TCP */
1275  TcpSession *ssn = f->protoctx;
1276  if (ssn != NULL) {
1279  }
1280  }
1281  /* Set the bypass flag for both the stream in this TcpSession */
1282  if (pstate->flags & APP_LAYER_PARSER_BYPASS_READY) {
1283  /* Used only if it's TCP */
1284  TcpSession *ssn = f->protoctx;
1285  if (ssn != NULL) {
1287  }
1288  }
1289  }
1290  }
1291 
1292  /* In cases like HeartBleed for TLS we need to inspect AppLayer but not Payload */
1294  FlowSetNoPayloadInspectionFlag(f);
1295  /* Set the no reassembly flag for both the stream in this TcpSession */
1296  if (f->proto == IPPROTO_TCP) {
1297  /* Used only if it's TCP */
1298  TcpSession *ssn = f->protoctx;
1299  if (ssn != NULL) {
1302  }
1303  }
1304  }
1305 
1306  /* get the diff in tx cnt for stats keeping */
1307  uint64_t cur_tx_cnt = AppLayerParserGetTxCnt(f, f->alstate);
1308  if (cur_tx_cnt > p_tx_cnt && tv) {
1309  AppLayerIncTxCounter(tv, f, cur_tx_cnt - p_tx_cnt);
1310  }
1311 
1312  /* stream truncated, inform app layer */
1313  if (flags & STREAM_DEPTH)
1314  AppLayerParserStreamTruncated(f->proto, alproto, alstate, flags);
1315 
1316  end:
1317  /* update app progress */
1318  if (consumed != input_len && f->proto == IPPROTO_TCP && f->protoctx != NULL) {
1319  TcpSession *ssn = f->protoctx;
1320  StreamTcpUpdateAppLayerProgress(ssn, direction, consumed);
1321  SCReturnInt(1);
1322  }
1323 
1324  SCReturnInt(0);
1325  error:
1326  /* Set the no app layer inspection flag for both
1327  * the stream in this Flow */
1328  if (f->proto == IPPROTO_TCP) {
1330  }
1331  AppLayerParserSetEOF(pstate);
1332  SCReturnInt(-1);
1333 }
1334 
1336 {
1337  SCEnter();
1338 
1339  if (pstate == NULL)
1340  goto end;
1341 
1343 
1344  end:
1345  SCReturn;
1346 }
1347 
1348 /* return true if there are app parser decoder events. These are
1349  * only the ones that are set during protocol detection. */
1351 {
1352  SCEnter();
1353 
1354  if (pstate == NULL)
1355  return false;
1356 
1359  return true;
1360 
1361  /* if we have reached here, we don't have events */
1362  return false;
1363 }
1364 
1365 /** \brief simple way to globally test if a alproto is registered
1366  * and fully enabled in the configuration.
1367  */
1369 {
1370  return (alp_ctx.ctxs[FLOW_PROTO_DEFAULT][alproto]
1372 }
1373 
1374 int AppLayerParserProtocolIsTxEventAware(uint8_t ipproto, AppProto alproto)
1375 {
1376  SCEnter();
1377  int ipproto_map = FlowGetProtoMapping(ipproto);
1378  int r = (alp_ctx.ctxs[ipproto_map][alproto].StateGetEvents == NULL) ? 0 : 1;
1379  SCReturnInt(r);
1380 }
1381 
1382 int AppLayerParserProtocolHasLogger(uint8_t ipproto, AppProto alproto)
1383 {
1384  SCEnter();
1385  int ipproto_map = FlowGetProtoMapping(ipproto);
1386  int r = (alp_ctx.ctxs[ipproto_map][alproto].logger == false) ? 0 : 1;
1387  SCReturnInt(r);
1388 }
1389 
1391 {
1392  SCEnter();
1393  const int ipproto_map = FlowGetProtoMapping(ipproto);
1394  LoggerId r = alp_ctx.ctxs[ipproto_map][alproto].logger_bits;
1395  SCReturnUInt(r);
1396 }
1397 
1399 {
1400  SCEnter();
1401 
1402  SCLogDebug("f %p tcp %p direction %d", f, f ? f->protoctx : NULL, direction);
1403  if (f != NULL && f->protoctx != NULL)
1405 
1406  SCReturn;
1407 }
1408 
1409 void AppLayerParserSetStreamDepth(uint8_t ipproto, AppProto alproto, uint32_t stream_depth)
1410 {
1411  SCEnter();
1412 
1413  alp_ctx.ctxs[FlowGetProtoMapping(ipproto)][alproto].stream_depth = stream_depth;
1414  alp_ctx.ctxs[FlowGetProtoMapping(ipproto)][alproto].internal_flags |=
1416 
1417  SCReturn;
1418 }
1419 
1421 {
1422  SCReturnInt(alp_ctx.ctxs[f->protomap][f->alproto].stream_depth);
1423 }
1424 
1425 void AppLayerParserSetStreamDepthFlag(uint8_t ipproto, AppProto alproto, void *state, uint64_t tx_id, uint8_t flags)
1426 {
1427  SCEnter();
1428  void *tx = NULL;
1429  if (state != NULL) {
1430  if ((tx = AppLayerParserGetTx(ipproto, alproto, state, tx_id)) != NULL) {
1431  if (alp_ctx.ctxs[FlowGetProtoMapping(ipproto)][alproto].SetStreamDepthFlag != NULL) {
1432  alp_ctx.ctxs[FlowGetProtoMapping(ipproto)][alproto].SetStreamDepthFlag(tx, flags);
1433  }
1434  }
1435  }
1436  SCReturn;
1437 }
1438 
1439 /***** Cleanup *****/
1440 
1441 void AppLayerParserStateCleanup(const Flow *f, void *alstate,
1442  AppLayerParserState *pstate)
1443 {
1444  SCEnter();
1445 
1446  AppLayerParserProtoCtx *ctx = &alp_ctx.ctxs[f->protomap][f->alproto];
1447 
1448  if (ctx->StateFree != NULL && alstate != NULL)
1449  ctx->StateFree(alstate);
1450 
1451  /* free the app layer parser api state */
1452  if (pstate != NULL)
1453  AppLayerParserStateFree(pstate);
1454 
1455  SCReturn;
1456 }
1457 
1458 static void ValidateParserProtoDump(AppProto alproto, uint8_t ipproto)
1459 {
1460  uint8_t map = FlowGetProtoMapping(ipproto);
1461  const AppLayerParserProtoCtx *ctx = &alp_ctx.ctxs[map][alproto];
1462  const AppLayerParserProtoCtx *ctx_def = &alp_ctx.ctxs[FLOW_PROTO_DEFAULT][alproto];
1463  printf("ERROR: incomplete app-layer registration\n");
1464  printf("AppLayer protocol %s ipproto %u\n", AppProtoToString(alproto), ipproto);
1465  printf("- option flags %"PRIx32"\n", ctx->option_flags);
1466  printf("- first_data_dir %"PRIx8"\n", ctx->first_data_dir);
1467  printf("Mandatory:\n");
1468  printf("- Parser[0] %p Parser[1] %p\n", ctx->Parser[0], ctx->Parser[1]);
1469  printf("- StateAlloc %p StateFree %p\n", ctx->StateAlloc, ctx->StateFree);
1470  printf("- StateGetTx %p StateGetTxCnt %p StateTransactionFree %p\n",
1471  ctx->StateGetTx, ctx->StateGetTxCnt, ctx->StateTransactionFree);
1472  printf("- StateGetProgress %p StateGetProgressCompletionStatus %p\n", ctx->StateGetProgress, ctx_def->StateGetProgressCompletionStatus);
1473  printf("- GetTxDetectState %p SetTxDetectState %p\n", ctx->GetTxDetectState, ctx->SetTxDetectState);
1474  printf("Optional:\n");
1475  printf("- LocalStorageAlloc %p LocalStorageFree %p\n", ctx->LocalStorageAlloc, ctx->LocalStorageFree);
1476  printf("- StateGetTxLogged %p StateSetTxLogged %p\n", ctx->StateGetTxLogged, ctx->StateSetTxLogged);
1477  printf("- StateGetEvents %p StateGetEventInfo %p StateGetEventInfoById %p\n", ctx->StateGetEvents, ctx->StateGetEventInfo,
1478  ctx->StateGetEventInfoById);
1479 }
1480 
1481 #define BOTH_SET(a, b) ((a) != NULL && (b) != NULL)
1482 #define BOTH_SET_OR_BOTH_UNSET(a, b) (((a) == NULL && (b) == NULL) || ((a) != NULL && (b) != NULL))
1483 #define THREE_SET_OR_THREE_UNSET(a, b, c) (((a) == NULL && (b) == NULL && (c) == NULL) || ((a) != NULL && (b) != NULL && (c) != NULL))
1484 #define THREE_SET(a, b, c) ((a) != NULL && (b) != NULL && (c) != NULL)
1486 static void ValidateParserProto(AppProto alproto, uint8_t ipproto)
1487 {
1488  uint8_t map = FlowGetProtoMapping(ipproto);
1489  const AppLayerParserProtoCtx *ctx = &alp_ctx.ctxs[map][alproto];
1490  const AppLayerParserProtoCtx *ctx_def = &alp_ctx.ctxs[FLOW_PROTO_DEFAULT][alproto];
1491 
1492  if (ctx->Parser[0] == NULL && ctx->Parser[1] == NULL)
1493  return;
1494 
1495  if (!(BOTH_SET(ctx->Parser[0], ctx->Parser[1]))) {
1496  goto bad;
1497  }
1498  if (!(BOTH_SET(ctx->StateFree, ctx->StateAlloc))) {
1499  goto bad;
1500  }
1501  if (!(THREE_SET(ctx->StateGetTx, ctx->StateGetTxCnt, ctx->StateTransactionFree))) {
1502  goto bad;
1503  }
1504  /* special case: StateGetProgressCompletionStatus is used from 'default'. */
1506  goto bad;
1507  }
1508  /* local storage is optional, but needs both set if used */
1510  goto bad;
1511  }
1513  goto bad;
1514  }
1515  if (!(BOTH_SET(ctx->GetTxDetectState, ctx->SetTxDetectState))) {
1516  goto bad;
1517  }
1519  goto bad;
1520  }
1522  goto bad;
1523  }
1524 
1525  return;
1526 bad:
1527  ValidateParserProtoDump(alproto, ipproto);
1528  exit(EXIT_FAILURE);
1529 }
1530 #undef BOTH_SET
1531 #undef BOTH_SET_OR_BOTH_UNSET
1532 #undef THREE_SET_OR_THREE_UNSET
1533 #undef THREE_SET
1534 
1535 static void ValidateParser(AppProto alproto)
1536 {
1537  ValidateParserProto(alproto, IPPROTO_TCP);
1538  ValidateParserProto(alproto, IPPROTO_UDP);
1539 }
1540 
1541 static void ValidateParsers(void)
1542 {
1543  AppProto p = 0;
1544  for ( ; p < ALPROTO_MAX; p++) {
1545  ValidateParser(p);
1546  }
1547 }
1548 
1550 {
1551  SCEnter();
1552 
1561  rs_dns_udp_register_parser();
1562  rs_dns_tcp_register_parser();
1573  rs_dhcp_register_parser();
1580 
1581  /** IMAP */
1583  if (AppLayerProtoDetectConfProtoDetectionEnabled("tcp", "imap")) {
1585  "1|20|capability", 12, 0, STREAM_TOSERVER) < 0)
1586  {
1587  SCLogInfo("imap proto registration failure");
1588  exit(EXIT_FAILURE);
1589  }
1590  } else {
1591  SCLogInfo("Protocol detection and parser disabled for %s protocol.",
1592  "imap");
1593  }
1594 
1595  ValidateParsers();
1596  return;
1597 }
1598 
1599 
1600 /* coccinelle: AppLayerParserStateSetFlag():2,2:APP_LAYER_PARSER_ */
1602 {
1603  SCEnter();
1604  pstate->flags |= flag;
1605  SCReturn;
1606 }
1607 
1608 /* coccinelle: AppLayerParserStateIssetFlag():2,2:APP_LAYER_PARSER_ */
1610 {
1611  SCEnter();
1612  SCReturnInt(pstate->flags & flag);
1613 }
1614 
1615 
1616 void AppLayerParserStreamTruncated(uint8_t ipproto, AppProto alproto, void *alstate,
1617  uint8_t direction)
1618 {
1619  SCEnter();
1620 
1621  if (alp_ctx.ctxs[FlowGetProtoMapping(ipproto)][alproto].Truncate != NULL)
1622  alp_ctx.ctxs[FlowGetProtoMapping(ipproto)][alproto].Truncate(alstate, direction);
1623 
1624  SCReturn;
1625 }
1626 
1627 #ifdef DEBUG
1628 void AppLayerParserStatePrintDetails(AppLayerParserState *pstate)
1629 {
1630  SCEnter();
1631 
1632  if (pstate == NULL)
1633  SCReturn;
1634 
1635  AppLayerParserState *p = pstate;
1636  SCLogDebug("AppLayerParser parser state information for parser state p(%p). "
1637  "p->inspect_id[0](%"PRIu64"), "
1638  "p->inspect_id[1](%"PRIu64"), "
1639  "p->log_id(%"PRIu64"), "
1640  "p->decoder_events(%p).",
1641  pstate, p->inspect_id[0], p->inspect_id[1], p->log_id,
1642  p->decoder_events);
1643 
1644  SCReturn;
1645 }
1646 #endif
1647 
1648 /***** Unittests *****/
1649 
1650 #ifdef UNITTESTS
1651 
1652 static AppLayerParserCtx alp_ctx_backup_unittest;
1653 
1654 typedef struct TestState_ {
1655  uint8_t test;
1657 
1658 /**
1659  * \brief Test parser function to test the memory deallocation of app layer
1660  * parser of occurence of an error.
1661  */
1662 static AppLayerResult TestProtocolParser(Flow *f, void *test_state, AppLayerParserState *pstate,
1663  const uint8_t *input, uint32_t input_len,
1664  void *local_data, const uint8_t flags)
1665 {
1666  SCEnter();
1668 }
1669 
1670 /** \brief Function to allocates the Test protocol state memory
1671  */
1672 static void *TestProtocolStateAlloc(void)
1673 {
1674  SCEnter();
1675  void *s = SCMalloc(sizeof(TestState));
1676  if (unlikely(s == NULL))
1677  goto end;
1678  memset(s, 0, sizeof(TestState));
1679  end:
1680  SCReturnPtr(s, "TestState");
1681 }
1682 
1683 /** \brief Function to free the Test Protocol state memory
1684  */
1685 static void TestProtocolStateFree(void *s)
1686 {
1687  SCFree(s);
1688 }
1689 
1690 static uint64_t TestGetTxCnt(void *state)
1691 {
1692  /* single tx */
1693  return 1;
1694 }
1695 
1696 static void TestStateTransactionFree(void *state, uint64_t tx_id)
1697 {
1698  /* do nothing */
1699 }
1700 
1701 static void *TestGetTx(void *state, uint64_t tx_id)
1702 {
1703  TestState *test_state = (TestState *)state;
1704  return test_state;
1705 }
1706 
1708  void (*RegisterUnittests)(void))
1709 {
1710  SCEnter();
1711  alp_ctx.ctxs[FlowGetProtoMapping(ipproto)][alproto].
1712  RegisterUnittests = RegisterUnittests;
1713  SCReturn;
1714 }
1715 
1717 {
1718  SCEnter();
1719  alp_ctx_backup_unittest = alp_ctx;
1720  memset(&alp_ctx, 0, sizeof(alp_ctx));
1721  SCReturn;
1722 }
1723 
1725 {
1726  SCEnter();
1727  alp_ctx = alp_ctx_backup_unittest;
1728  memset(&alp_ctx_backup_unittest, 0, sizeof(alp_ctx_backup_unittest));
1729  SCReturn;
1730 }
1731 
1732 /**
1733  * \test Test the deallocation of app layer parser memory on occurance of
1734  * error in the parsing process.
1735  */
1736 static int AppLayerParserTest01(void)
1737 {
1739 
1740  int result = 0;
1741  Flow *f = NULL;
1742  uint8_t testbuf[] = { 0x11 };
1743  uint32_t testlen = sizeof(testbuf);
1744  TcpSession ssn;
1746 
1747  memset(&ssn, 0, sizeof(ssn));
1748 
1749  /* Register the Test protocol state and parser functions */
1751  TestProtocolParser);
1753  TestProtocolStateAlloc, TestProtocolStateFree);
1754  AppLayerParserRegisterTxFreeFunc(IPPROTO_TCP, ALPROTO_TEST, TestStateTransactionFree);
1755  AppLayerParserRegisterGetTx(IPPROTO_TCP, ALPROTO_TEST, TestGetTx);
1756  AppLayerParserRegisterGetTxCnt(IPPROTO_TCP, ALPROTO_TEST, TestGetTxCnt);
1757 
1758  f = UTHBuildFlow(AF_INET, "1.2.3.4", "4.3.2.1", 20, 40);
1759  if (f == NULL)
1760  goto end;
1761  f->protoctx = &ssn;
1762  f->alproto = ALPROTO_TEST;
1763  f->proto = IPPROTO_TCP;
1764 
1766 
1767  FLOWLOCK_WRLOCK(f);
1768  int r = AppLayerParserParse(NULL, alp_tctx, f, ALPROTO_TEST,
1769  STREAM_TOSERVER | STREAM_EOF, testbuf,
1770  testlen);
1771  if (r != -1) {
1772  printf("returned %" PRId32 ", expected -1: ", r);
1773  FLOWLOCK_UNLOCK(f);
1774  goto end;
1775  }
1776  FLOWLOCK_UNLOCK(f);
1777 
1779  printf("flag should have been set, but is not: ");
1780  goto end;
1781  }
1782 
1783  result = 1;
1784  end:
1787 
1788  UTHFreeFlow(f);
1789  return result;
1790 }
1791 
1792 /**
1793  * \test Test the deallocation of app layer parser memory on occurance of
1794  * error in the parsing process for UDP.
1795  */
1796 static int AppLayerParserTest02(void)
1797 {
1799 
1800  int result = 1;
1801  Flow *f = NULL;
1802  uint8_t testbuf[] = { 0x11 };
1803  uint32_t testlen = sizeof(testbuf);
1805 
1806  /* Register the Test protocol state and parser functions */
1808  TestProtocolParser);
1810  TestProtocolStateAlloc, TestProtocolStateFree);
1811  AppLayerParserRegisterTxFreeFunc(IPPROTO_UDP, ALPROTO_TEST, TestStateTransactionFree);
1812  AppLayerParserRegisterGetTx(IPPROTO_UDP, ALPROTO_TEST, TestGetTx);
1813  AppLayerParserRegisterGetTxCnt(IPPROTO_UDP, ALPROTO_TEST, TestGetTxCnt);
1814 
1815  f = UTHBuildFlow(AF_INET, "1.2.3.4", "4.3.2.1", 20, 40);
1816  if (f == NULL)
1817  goto end;
1818  f->alproto = ALPROTO_TEST;
1819  f->proto = IPPROTO_UDP;
1821 
1823 
1824  FLOWLOCK_WRLOCK(f);
1825  int r = AppLayerParserParse(NULL, alp_tctx, f, ALPROTO_TEST,
1826  STREAM_TOSERVER | STREAM_EOF, testbuf,
1827  testlen);
1828  if (r != -1) {
1829  printf("returned %" PRId32 ", expected -1: \n", r);
1830  result = 0;
1831  FLOWLOCK_UNLOCK(f);
1832  goto end;
1833  }
1834  FLOWLOCK_UNLOCK(f);
1835 
1836  end:
1839  UTHFreeFlow(f);
1840  return result;
1841 }
1842 
1843 
1845 {
1846  SCEnter();
1847 
1848  int ip;
1849  AppProto alproto;
1851 
1852  for (ip = 0; ip < FLOW_PROTO_DEFAULT; ip++) {
1853  for (alproto = 0; alproto < ALPROTO_MAX; alproto++) {
1854  ctx = &alp_ctx.ctxs[ip][alproto];
1855  if (ctx->RegisterUnittests == NULL)
1856  continue;
1857  ctx->RegisterUnittests();
1858  }
1859  }
1860 
1861  UtRegisterTest("AppLayerParserTest01", AppLayerParserTest01);
1862  UtRegisterTest("AppLayerParserTest02", AppLayerParserTest02);
1863 
1864  SCReturn;
1865 }
1866 
1867 #endif
AppLayerParserProtoCtx_::Truncate
void(* Truncate)(void *, uint8_t)
Definition: app-layer-parser.c:106
AppLayerParserSetTxLogged
void AppLayerParserSetTxLogged(uint8_t ipproto, AppProto alproto, void *alstate, void *tx, LoggerId logger)
Definition: app-layer-parser.c:686
app-layer-nfs-udp.h
app-layer-dcerpc.h
ALPROTO_TEST
@ ALPROTO_TEST
Definition: app-layer-protos.h:63
AppLayerParserRegisterGetStateProgressFunc
void AppLayerParserRegisterGetStateProgressFunc(uint8_t ipproto, AppProto alproto, int(*StateGetProgress)(void *alstate, uint8_t direction))
Definition: app-layer-parser.c:490
AppLayerParserDeSetup
int AppLayerParserDeSetup(void)
Definition: app-layer-parser.c:243
FileContainer_
Definition: util-file.h:100
app-layer-dcerpc-udp.h
RegisterNTPParsers
void RegisterNTPParsers(void)
Definition: app-layer-ntp.c:38
AppLayerParserProtoCtx_::StateGetTxCnt
uint64_t(* StateGetTxCnt)(void *alstate)
Definition: app-layer-parser.c:111
AppLayerParserProtoCtx_::logger_bits
uint32_t logger_bits
Definition: app-layer-parser.c:98
RegisterTemplateRustParsers
void RegisterTemplateRustParsers(void)
Definition: app-layer-template-rust.c:48
app-layer-tftp.h
AppLayerParserCtx_::ctxs
AppLayerParserProtoCtx ctxs[FLOW_PROTO_MAX][ALPROTO_MAX]
Definition: app-layer-parser.c:152
AppLayerParserGetTxLogged
LoggerId AppLayerParserGetTxLogged(const Flow *f, void *alstate, void *tx)
Definition: app-layer-parser.c:700
AppLayerParserState_::log_id
uint64_t log_id
Definition: app-layer-parser.c:165
RegisterSMBParsers
void RegisterSMBParsers(void)
Definition: app-layer-smb.c:255
app-layer-ssh.h
FLOW_PROTO_DEFAULT
@ FLOW_PROTO_DEFAULT
Definition: flow-private.h:72
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:1368
AppLayerParserRegisterLocalStorageFunc
void AppLayerParserRegisterLocalStorageFunc(uint8_t ipproto, AppProto alproto, void *(*LocalStorageAlloc)(void), void(*LocalStorageFree)(void *))
Definition: app-layer-parser.c:411
BOTH_SET
#define BOTH_SET(a, b)
Definition: app-layer-parser.c:1481
AppLayerParserProtocolHasLogger
int AppLayerParserProtocolHasLogger(uint8_t ipproto, AppProto alproto)
Definition: app-layer-parser.c:1382
AppLayerParserRegisterOptionFlags
void AppLayerParserRegisterOptionFlags(uint8_t ipproto, AppProto alproto, uint32_t flags)
Definition: app-layer-parser.c:387
flow-util.h
AppLayerParserSetStreamDepthFlag
void AppLayerParserSetStreamDepthFlag(uint8_t ipproto, AppProto alproto, void *state, uint64_t tx_id, uint8_t flags)
Definition: app-layer-parser.c:1425
AppLayerParserSetTransactionLogId
void AppLayerParserSetTransactionLogId(AppLayerParserState *pstate, uint64_t tx_id)
Definition: app-layer-parser.c:721
AppLayerParserRegisterStateFuncs
void AppLayerParserRegisterStateFuncs(uint8_t ipproto, AppProto alproto, void *(*StateAlloc)(void), void(*StateFree)(void *))
Definition: app-layer-parser.c:397
AppLayerParserSetStreamDepth
void AppLayerParserSetStreamDepth(uint8_t ipproto, AppProto alproto, uint32_t stream_depth)
Definition: app-layer-parser.c:1409
DetectEngineState_
Definition: detect-engine-state.h:92
ConfNode_::val
char * val
Definition: conf.h:34
stream-tcp.h
unlikely
#define unlikely(expr)
Definition: util-optimize.h:35
AppLayerParserGetProtocolParserLocalStorage
void * AppLayerParserGetProtocolParserLocalStorage(uint8_t ipproto, AppProto alproto)
Definition: app-layer-parser.c:613
UtRegisterTest
void UtRegisterTest(const char *name, int(*TestFn)(void))
Register unit test.
Definition: util-unittest.c:103
AppLayerParserProtoCtx_::LocalStorageFree
void(* LocalStorageFree)(void *)
Definition: app-layer-parser.c:104
AppLayerParserSetTxDetectFlags
void AppLayerParserSetTxDetectFlags(uint8_t ipproto, AppProto alproto, void *tx, uint8_t dir, uint64_t flags)
Definition: app-layer-parser.c:1157
app-layer-ikev2.h
AppLayerParserProtoCtx_
App layer protocol parser context.
Definition: app-layer-parser.c:94
RegisterSSHParsers
void RegisterSSHParsers(void)
Function to register the SSH protocol parsers and other functions.
Definition: app-layer-ssh.c:74
AppLayerParserProtoCtx_::StateGetTx
void *(* StateGetTx)(void *alstate, uint64_t tx_id)
Definition: app-layer-parser.c:112
SCLogDebug
#define SCLogDebug(...)
Definition: util-debug.h:298
AppLayerParserSetTransactionInspectId
void AppLayerParserSetTransactionInspectId(const Flow *f, AppLayerParserState *pstate, void *alstate, const uint8_t flags, bool tag_txs_as_inspected)
Definition: app-layer-parser.c:741
APP_LAYER_PARSER_BYPASS_READY
#define APP_LAYER_PARSER_BYPASS_READY
Definition: app-layer-parser.h:39
AppLayerParserGetEventsByTx
AppLayerDecoderEvents * AppLayerParserGetEventsByTx(uint8_t ipproto, AppProto alproto, void *tx)
Definition: app-layer-parser.c:847
AppLayerGetTxIterator
AppLayerGetTxIteratorFunc AppLayerGetTxIterator(const uint8_t ipproto, const AppProto alproto)
Definition: app-layer-parser.c:678
next
struct HtpBodyChunk_ * next
Definition: app-layer-htp.h:0
AppLayerParserRegisterDetectFlagsFuncs
void AppLayerParserRegisterDetectFlagsFuncs(uint8_t ipproto, AppProto alproto, uint64_t(*GetTxDetectFlags)(void *tx, uint8_t dir), void(*SetTxDetectFlags)(void *tx, uint8_t dir, uint64_t))
Definition: app-layer-parser.c:589
RegisterModbusParsers
void RegisterModbusParsers(void)
Function to register the Modbus protocol parsers and other functions.
Definition: app-layer-modbus.c:1490
AppLayerParserRegisterLoggerFuncs
void AppLayerParserRegisterLoggerFuncs(uint8_t ipproto, AppProto alproto, LoggerId(*StateGetTxLogged)(void *, void *), void(*StateSetTxLogged)(void *, void *, LoggerId))
Definition: app-layer-parser.c:447
Flow_::proto
uint8_t proto
Definition: flow.h:361
AppProto
uint16_t AppProto
Definition: app-layer-protos.h:71
AppLayerParserFPtr
AppLayerResult(* AppLayerParserFPtr)(Flow *f, void *protocol_state, AppLayerParserState *pstate, const uint8_t *buf, uint32_t buf_len, void *local_storage, const uint8_t flags)
Prototype for parsing functions.
Definition: app-layer-parser.h:109
StreamTcpSetDisableRawReassemblyFlag
void StreamTcpSetDisableRawReassemblyFlag(TcpSession *, char)
Set the No reassembly flag for the given direction in given TCP session.
Definition: stream-tcp.c:5888
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:302
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:1013
AppLayerParserTriggerRawStreamReassembly
void AppLayerParserTriggerRawStreamReassembly(Flow *f, int direction)
Definition: app-layer-parser.c:1398
AppLayerParserProtoCtx_::SetTxDetectFlags
void(* SetTxDetectFlags)(void *tx, uint8_t dir, uint64_t)
Definition: app-layer-parser.c:127
ConfGetNode
ConfNode * ConfGetNode(const char *name)
Get a ConfNode by name.
Definition: conf.c:176
threads.h
TcpStreamCnf_::reassembly_depth
uint32_t reassembly_depth
Definition: stream-tcp.h:60
flow-private.h
Flow_
Flow data structure.
Definition: flow.h:343
APP_LAYER_PARSER_INT_STREAM_DEPTH_SET
#define APP_LAYER_PARSER_INT_STREAM_DEPTH_SET
Definition: app-layer-parser.h:44
AppLayerEventType
enum AppLayerEventType_ AppLayerEventType
AppLayerParserRegisterGetEventsFunc
void AppLayerParserRegisterGetEventsFunc(uint8_t ipproto, AppProto alproto, AppLayerDecoderEvents *(*StateGetEvents)(void *))
Definition: app-layer-parser.c:436
StreamTcpReassembleTriggerRawReassembly
void StreamTcpReassembleTriggerRawReassembly(TcpSession *ssn, int direction)
Trigger RAW stream reassembly.
Definition: stream-tcp-reassemble.c:1860
LoggerId
LoggerId
Definition: suricata-common.h:439
Flow_::protomap
uint8_t protomap
Definition: flow.h:420
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:30
AppLayerParserRegisterTruncateFunc
void AppLayerParserRegisterTruncateFunc(uint8_t ipproto, AppProto alproto, void(*Truncate)(void *, uint8_t))
Definition: app-layer-parser.c:480
AppLayerParserRegisterParserAcceptableDataDirection
void AppLayerParserRegisterParserAcceptableDataDirection(uint8_t ipproto, AppProto alproto, uint8_t direction)
Definition: app-layer-parser.c:376
AppLayerParserGetStateProgressCompletionStatus
int AppLayerParserGetStateProgressCompletionStatus(AppProto alproto, uint8_t direction)
Definition: app-layer-parser.c:1046
AppLayerParserGetFirstDataDir
uint8_t AppLayerParserGetFirstDataDir(uint8_t ipproto, AppProto alproto)
Definition: app-layer-parser.c:1076
AppLayerParserProtoIsRegistered
int AppLayerParserProtoIsRegistered(uint8_t ipproto, AppProto alproto)
Definition: app-layer-parser.c:188
AppLayerParserRegisterTxFreeFunc
void AppLayerParserRegisterTxFreeFunc(uint8_t ipproto, AppProto alproto, void(*StateTransactionFree)(void *, uint64_t))
Definition: app-layer-parser.c:501
FLOW_NOPAYLOAD_INSPECTION
#define FLOW_NOPAYLOAD_INSPECTION
Definition: flow.h:61
AppLayerParserSupportsFiles
int AppLayerParserSupportsFiles(uint8_t ipproto, AppProto alproto)
Definition: app-layer-parser.c:1103
AppLayerParserProtoCtx_::StateGetTxIterator
AppLayerGetTxIteratorFunc StateGetTxIterator
Definition: app-layer-parser.c:113
AppLayerParserThreadCtxFree
void AppLayerParserThreadCtxFree(AppLayerParserThreadCtx *tctx)
Destroys the app layer parser thread context obtained using AppLayerParserThreadCtxAlloc().
Definition: app-layer-parser.c:279
rust.h
AppLayerDecoderEventsFreeEvents
void AppLayerDecoderEventsFreeEvents(AppLayerDecoderEvents **events)
Definition: app-layer-events.c:148
StreamTcpUpdateAppLayerProgress
void StreamTcpUpdateAppLayerProgress(TcpSession *ssn, char direction, const uint32_t progress)
update reassembly progress
Definition: stream-tcp.c:5854
AppLayerParserGetFiles
FileContainer * AppLayerParserGetFiles(const Flow *f, const uint8_t direction)
Definition: app-layer-parser.c:864
APP_LAYER_TX_INSPECTED_FLAG
#define APP_LAYER_TX_INSPECTED_FLAG
Definition: app-layer-parser.h:49
stream-tcp-reassemble.h
AppLayerParserRegisterDetectStateFuncs
void AppLayerParserRegisterDetectStateFuncs(uint8_t ipproto, AppProto alproto, DetectEngineState *(*GetTxDetectState)(void *tx), int(*SetTxDetectState)(void *tx, DetectEngineState *))
Definition: app-layer-parser.c:577
TestState
struct TestState_ TestState
AppLayerParserProtoCtx_::StateAlloc
void *(* StateAlloc)(void)
Definition: app-layer-parser.c:100
RegisterSIPParsers
void RegisterSIPParsers(void)
Definition: app-layer-sip.c:38
app-layer-ftp.h
MAX
#define MAX(x, y)
Definition: suricata-common.h:381
ALPROTO_MAX
@ ALPROTO_MAX
Definition: app-layer-protos.h:66
Flow_::protoctx
void * protoctx
Definition: flow.h:416
TcpStream_::data_required
uint32_t data_required
Definition: stream-tcp-private.h:120
AppLayerParserRegisterUnittests
void AppLayerParserRegisterUnittests(void)
Definition: app-layer-parser.c:1844
AppLayerParserGetTransactionInspectId
uint64_t AppLayerParserGetTransactionInspectId(AppLayerParserState *pstate, uint8_t direction)
Definition: app-layer-parser.c:731
RegisterKRB5Parsers
void RegisterKRB5Parsers(void)
Definition: app-layer-krb5.c:38
AppLayerDecoderEvents_
Data structure to store app layer decoder events.
Definition: app-layer-events.h:34
util-unittest.h
FlowGetReverseProtoMapping
uint8_t FlowGetReverseProtoMapping(uint8_t rproto)
Definition: flow-util.c:111
AppLayerParserProtocolIsTxEventAware
int AppLayerParserProtocolIsTxEventAware(uint8_t ipproto, AppProto alproto)
Definition: app-layer-parser.c:1374
RegisterDNP3Parsers
void RegisterDNP3Parsers(void)
Register the DNP3 application protocol parser.
Definition: app-layer-dnp3.c:1599
ConfValIsTrue
int ConfValIsTrue(const char *val)
Check if a value is true.
Definition: conf.c:566
util-unittest-helper.h
FTPParserCleanup
void FTPParserCleanup(void)
Free memory allocated for global FTP parser state.
Definition: app-layer-ftp.c:1467
TcpSession_::flags
uint16_t flags
Definition: stream-tcp-private.h:269
FLOWLOCK_UNLOCK
#define FLOWLOCK_UNLOCK(fb)
Definition: flow.h:260
AppLayerParserGetEventInfoById
int AppLayerParserGetEventInfoById(uint8_t ipproto, AppProto alproto, int event_id, const char **event_name, AppLayerEventType *event_type)
Definition: app-layer-parser.c:1065
Flow_::sgh_toserver
const struct SigGroupHead_ * sgh_toserver
Definition: flow.h:461
SCReturnBool
#define SCReturnBool(x)
Definition: util-debug.h:318
AppLayerParserRestoreParserTable
void AppLayerParserRestoreParserTable(void)
Definition: app-layer-parser.c:1724
AppLayerParserState_::inspect_id
uint64_t inspect_id[2]
Definition: app-layer-parser.c:161
AppLayerParserCtx
struct AppLayerParserCtx_ AppLayerParserCtx
Flow_::alparser
AppLayerParserState * alparser
Definition: flow.h:453
AppLayerParserRegisterProtocolParsers
void AppLayerParserRegisterProtocolParsers(void)
Definition: app-layer-parser.c:1549
app-layer-krb5.h
RegisterRFBParsers
void RegisterRFBParsers(void)
Definition: app-layer-rfb.c:54
RegisterDCERPCParsers
void RegisterDCERPCParsers(void)
Definition: app-layer-dcerpc.c:155
UTHBuildFlow
Flow * UTHBuildFlow(int family, const char *src, const char *dst, Port sp, Port dp)
Definition: util-unittest-helper.c:520
app-layer-htp.h
AppLayerParserStateIssetFlag
int AppLayerParserStateIssetFlag(AppLayerParserState *pstate, uint8_t flag)
Definition: app-layer-parser.c:1609
FLOW_PROTO_MAX
@ FLOW_PROTO_MAX
Definition: flow-private.h:75
AppLayerParserProtoCtx_::stream_depth
uint32_t stream_depth
Definition: app-layer-parser.c:132
decode.h
util-debug.h
AppLayerParserState_
Definition: app-layer-parser.c:155
AppLayerParserGetTransactionActive
uint64_t AppLayerParserGetTransactionActive(const Flow *f, AppLayerParserState *pstate, uint8_t direction)
Definition: app-layer-parser.c:1085
AppLayerParserProtoCtx_::logger
bool logger
Definition: app-layer-parser.c:97
app-layer-dnp3.h
AppLayerParserStreamTruncated
void AppLayerParserStreamTruncated(uint8_t ipproto, AppProto alproto, void *alstate, uint8_t direction)
Definition: app-layer-parser.c:1616
STREAM_TOSERVER
#define STREAM_TOSERVER
Definition: stream.h:31
res
PoolThreadReserved res
Definition: stream-tcp-private.h:0
alp_tctx
AppLayerParserThreadCtx * alp_tctx
Definition: fuzz_applayerparserparse.c:19
AppLayerParserRegisterLogger
void AppLayerParserRegisterLogger(uint8_t ipproto, AppProto alproto)
Definition: app-layer-parser.c:471
FLOWLOCK_WRLOCK
#define FLOWLOCK_WRLOCK(fb)
Definition: flow.h:257
app-layer-rfb.h
AppLayerParserRegisterGetFilesFunc
void AppLayerParserRegisterGetFilesFunc(uint8_t ipproto, AppProto alproto, FileContainer *(*StateGetFiles)(void *, uint8_t))
Definition: app-layer-parser.c:425
util-print.h
SCEnter
#define SCEnter(...)
Definition: util-debug.h:300
AppLayerParserProtoCtx_::SetStreamDepthFlag
void(* SetStreamDepthFlag)(void *tx, uint8_t flags)
Definition: app-layer-parser.c:129
AppLayerParserState_::min_id
uint64_t min_id
Definition: app-layer-parser.c:167
RegisterENIPTCPParsers
void RegisterENIPTCPParsers(void)
Function to register the ENIP protocol parsers and other functions.
Definition: app-layer-enip.c:512
ThreadVars_
Per thread variable structure.
Definition: threadvars.h:58
AppLayerParserRegisterLoggerBits
void AppLayerParserRegisterLoggerBits(uint8_t ipproto, AppProto alproto, LoggerId bits)
Definition: app-layer-parser.c:462
AppLayerParserProtoCtx_::StateGetEventInfo
int(* StateGetEventInfo)(const char *event_name, int *event_id, AppLayerEventType *event_type)
Definition: app-layer-parser.c:117
AppLayerParserProtoCtx_::GetTxDetectState
DetectEngineState *(* GetTxDetectState)(void *tx)
Definition: app-layer-parser.c:123
detect-engine-port.h
AppLayerParserSupportsTxDetectState
int AppLayerParserSupportsTxDetectState(uint8_t ipproto, AppProto alproto)
Definition: app-layer-parser.c:1110
AppLayerParserProtoCtx_::SetTxDetectState
int(* SetTxDetectState)(void *tx, DetectEngineState *)
Definition: app-layer-parser.c:124
AppLayerParserSupportsTxDetectFlags
bool AppLayerParserSupportsTxDetectFlags(AppProto alproto)
Definition: app-layer-parser.c:1136
APP_LAYER_PARSER_NO_REASSEMBLY
#define APP_LAYER_PARSER_NO_REASSEMBLY
Definition: app-layer-parser.h:37
IS_DISRUPTED
#define IS_DISRUPTED(flags)
Definition: app-layer-parser.c:1005
AppLayerParserSetEOF
void AppLayerParserSetEOF(AppLayerParserState *pstate)
Definition: app-layer-parser.c:1335
AppLayerParserProtoCtx_::RegisterUnittests
void(* RegisterUnittests)(void)
Definition: app-layer-parser.c:147
AppLayerParserStateFree
void AppLayerParserStateFree(AppLayerParserState *pstate)
Definition: app-layer-parser.c:208
app-layer-parser.h
AppLayerParserStateCleanup
void AppLayerParserStateCleanup(const Flow *f, void *alstate, AppLayerParserState *pstate)
Definition: app-layer-parser.c:1441
TRUE
#define TRUE
Definition: suricata-common.h:33
AppLayerParserBackupParserTable
void AppLayerParserBackupParserTable(void)
Definition: app-layer-parser.c:1716
AppLayerParserProtoCtx_::StateGetEventInfoById
int(* StateGetEventInfoById)(int event_id, const char **event_name, AppLayerEventType *event_type)
Definition: app-layer-parser.c:115
stream_config
TcpStreamCnf stream_config
Definition: stream-tcp.c:119
BUG_ON
#define BUG_ON(x)
Definition: suricata-common.h:282
AppLayerDecoderEvents_::cnt
uint8_t cnt
Definition: app-layer-events.h:38
Flow_::sgh_toclient
const struct SigGroupHead_ * sgh_toclient
Definition: flow.h:458
RegisterNFSTCPParsers
void RegisterNFSTCPParsers(void)
Definition: app-layer-nfs-tcp.c:283
AppLayerParserProtoCtx
struct AppLayerParserProtoCtx_ AppLayerParserProtoCtx
App layer protocol parser context.
FALSE
#define FALSE
Definition: suricata-common.h:34
AppLayerParserSetup
int AppLayerParserSetup(void)
Definition: app-layer-parser.c:219
SCReturn
#define SCReturn
Definition: util-debug.h:302
RegisterFTPParsers
void RegisterFTPParsers(void)
Definition: app-layer-ftp.c:1317
stream.h
AppLayerParserRegisterProtocolUnittests
void AppLayerParserRegisterProtocolUnittests(uint8_t ipproto, AppProto alproto, void(*RegisterUnittests)(void))
Definition: app-layer-parser.c:1707
AppLayerGetTxIterState
Definition: app-layer-parser.h:114
FlowGetProtoMapping
uint8_t FlowGetProtoMapping(uint8_t proto)
Function to map the protocol to the defined FLOW_PROTO_* enumeration.
Definition: flow-util.c:95
STREAM_DEPTH
#define STREAM_DEPTH
Definition: stream.h:34
RegisterTFTPParsers
void RegisterTFTPParsers(void)
Definition: app-layer-tftp.c:192
StreamTcpFreeConfig
void StreamTcpFreeConfig(char quiet)
Definition: stream-tcp.c:669
ALPROTO_IMAP
@ ALPROTO_IMAP
Definition: app-layer-protos.h:35
stream-tcp-private.h
FLOW_PROTO_APPLAYER_MAX
#define FLOW_PROTO_APPLAYER_MAX
Definition: flow-private.h:78
SCReturnUInt
#define SCReturnUInt(x)
Definition: util-debug.h:306
conf.h
DEBUG_ASSERT_FLOW_LOCKED
#define DEBUG_ASSERT_FLOW_LOCKED(f)
Definition: util-validate.h:108
BOTH_SET_OR_BOTH_UNSET
#define BOTH_SET_OR_BOTH_UNSET(a, b)
Definition: app-layer-parser.c:1482
AppLayerParserThreadCtx_::alproto_local_storage
void * alproto_local_storage[FLOW_PROTO_MAX][ALPROTO_MAX]
Definition: app-layer-parser.c:86
AppLayerParserRegisterGetEventInfo
void AppLayerParserRegisterGetEventInfo(uint8_t ipproto, AppProto alproto, int(*StateGetEventInfo)(const char *event_name, int *event_id, AppLayerEventType *event_type))
Definition: app-layer-parser.c:565
AppLayerParserSetDecoderEvents
void AppLayerParserSetDecoderEvents(AppLayerParserState *pstate, AppLayerDecoderEvents *devents)
Definition: app-layer-parser.c:842
RegisterDCERPCUDPParsers
void RegisterDCERPCUDPParsers(void)
Definition: app-layer-dcerpc-udp.c:116
SCReturnPtr
#define SCReturnPtr(x, type)
Definition: util-debug.h:316
AppLayerParserProtoCtx_::StateFree
void(* StateFree)(void *)
Definition: app-layer-parser.c:101
detect-engine-state.h
Data structures and function prototypes for keeping state for the detection engine.
STREAM_GAP
#define STREAM_GAP
Definition: stream.h:33
AppLayerProtoDetectRegisterProtocol
void AppLayerProtoDetectRegisterProtocol(AppProto alproto, const char *alproto_name)
Registers a protocol for protocol detection phase.
Definition: app-layer-detect-proto.c:1826
AppLayerParserRegisterSetStreamDepthFlag
void AppLayerParserRegisterSetStreamDepthFlag(uint8_t ipproto, AppProto alproto, void(*SetStreamDepthFlag)(void *tx, uint8_t flags))
Definition: app-layer-parser.c:601
app-layer-sip.h
APP_LAYER_PARSER_EOF
#define APP_LAYER_PARSER_EOF
Definition: app-layer-parser.h:35
runmodes.h
RunmodeIsUnittests
int RunmodeIsUnittests(void)
Definition: suricata.c:264
SCLogInfo
#define SCLogInfo(...)
Macro used to log INFORMATIONAL messages.
Definition: util-debug.h:217
RegisterRdpParsers
void RegisterRdpParsers(void)
Definition: app-layer-rdp.c:35
APP_LAYER_PARSER_NO_INSPECTION
#define APP_LAYER_PARSER_NO_INSPECTION
Definition: app-layer-parser.h:36
AppLayerParserGetTx
void * AppLayerParserGetTx(uint8_t ipproto, AppProto alproto, void *alstate, uint64_t tx_id)
Definition: app-layer-parser.c:1037
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:364
RegisterIKEV2Parsers
void RegisterIKEV2Parsers(void)
Definition: app-layer-ikev2.c:38
decode-events.h
AppLayerParserRegisterGetStateProgressCompletionStatus
void AppLayerParserRegisterGetStateProgressCompletionStatus(AppProto alproto, int(*StateGetProgressCompletionStatus)(uint8_t direction))
Definition: app-layer-parser.c:542
UTHFreeFlow
void UTHFreeFlow(Flow *flow)
Definition: util-unittest-helper.c:525
AppLayerParserThreadCtxAlloc
AppLayerParserThreadCtx * AppLayerParserThreadCtxAlloc(void)
Gets a new app layer protocol's parser thread context.
Definition: app-layer-parser.c:253
AppLayerParserRegisterGetTx
void AppLayerParserRegisterGetTx(uint8_t ipproto, AppProto alproto, void *(StateGetTx)(void *alstate, uint64_t tx_id))
Definition: app-layer-parser.c:523
AppLayerParserProtoCtx_::Parser
AppLayerParserFPtr Parser[2]
Definition: app-layer-parser.c:96
app-layer-modbus.h
AppLayerParserProtoCtx_::StateTransactionFree
void(* StateTransactionFree)(void *, uint64_t)
Definition: app-layer-parser.c:102
app-layer-enip.h
SCReturnStruct
#define SCReturnStruct(x)
Definition: util-debug.h:320
app-layer-template-rust.h
RegisterSSLParsers
void RegisterSSLParsers(void)
Function to register the SSL protocol parser and other functions.
Definition: app-layer-ssl.c:2945
AppLayerParserProtoCtx_::option_flags
uint32_t option_flags
Definition: app-layer-parser.c:140
StreamTcpSetSessionNoReassemblyFlag
void StreamTcpSetSessionNoReassemblyFlag(TcpSession *, char)
disable reassembly
Definition: stream-tcp.c:5872
AppLayerParserTransactionsCleanup
void AppLayerParserTransactionsCleanup(Flow *f)
remove obsolete (inspected and logged) transactions
Definition: app-layer-parser.c:882
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:1171
StreamTcpDisableAppLayer
void StreamTcpDisableAppLayer(Flow *f)
Definition: stream-tcp-reassemble.c:336
suricata-common.h
AppLayerParserProtoCtx_::StateSetTxLogged
void(* StateSetTxLogged)(void *alstate, void *tx, LoggerId logger)
Definition: app-layer-parser.c:121
AppLayerParserProtoCtx_::internal_flags
uint32_t internal_flags
Definition: app-layer-parser.c:143
util-spm.h
STREAM_TOCLIENT
#define STREAM_TOCLIENT
Definition: stream.h:32
AppLayerParserProtoCtx_::StateGetFiles
FileContainer *(* StateGetFiles)(void *, uint8_t)
Definition: app-layer-parser.c:107
SCLogError
#define SCLogError(err_code,...)
Macro used to log ERROR messages.
Definition: util-debug.h:257
RegisterENIPUDPParsers
void RegisterENIPUDPParsers(void)
Function to register the ENIP protocol parsers and other functions.
Definition: app-layer-enip.c:422
TcpSession_::client
TcpStream client
Definition: stream-tcp-private.h:272
AppLayerParserGetStreamDepth
uint32_t AppLayerParserGetStreamDepth(const Flow *f)
Definition: app-layer-parser.c:1420
tv
ThreadVars * tv
Definition: fuzz_decodepcapfile.c:29
util-validate.h
SCMalloc
#define SCMalloc(sz)
Definition: util-mem.h:47
RegisterSNMPParsers
void RegisterSNMPParsers(void)
Definition: app-layer-snmp.c:39
APP_LAYER_PARSER_OPT_ACCEPT_GAPS
#define APP_LAYER_PARSER_OPT_ACCEPT_GAPS
Definition: app-layer-parser.h:42
TcpSession_::server
TcpStream server
Definition: stream-tcp-private.h:271
AppLayerParserRegisterGetTxIterator
void AppLayerParserRegisterGetTxIterator(uint8_t ipproto, AppProto alproto, AppLayerGetTxIteratorFunc Func)
Definition: app-layer-parser.c:534
SCFree
#define SCFree(p)
Definition: util-mem.h:61
ConfNode_
Definition: conf.h:32
Flow_::alstate
void * alstate
Definition: flow.h:454
SC_ERR_FATAL
@ SC_ERR_FATAL
Definition: util-error.h:203
AppLayerParserPostStreamSetup
void AppLayerParserPostStreamSetup(void)
Definition: app-layer-parser.c:226
app-layer-template.h
Flow_::flags
uint32_t flags
Definition: flow.h:396
AppLayerParserGetDecoderEvents
AppLayerDecoderEvents * AppLayerParserGetDecoderEvents(AppLayerParserState *pstate)
Definition: app-layer-parser.c:834
THREE_SET
#define THREE_SET(a, b, c)
Definition: app-layer-parser.c:1484
TestState_::test
uint8_t test
Definition: app-layer-parser.c:1655
AppLayerParserRegisterGetEventInfoById
void AppLayerParserRegisterGetEventInfoById(uint8_t ipproto, AppProto alproto, int(*StateGetEventInfoById)(int event_id, const char **event_name, AppLayerEventType *event_type))
Definition: app-layer-parser.c:553
AppLayerGetProtoName
const char * AppLayerGetProtoName(AppProto alproto)
Given the internal protocol id, returns a string representation of the protocol.
Definition: app-layer.c:776
UTHAppLayerParserStateGetIds
void UTHAppLayerParserStateGetIds(void *ptr, uint64_t *i1, uint64_t *i2, uint64_t *log, uint64_t *min)
Definition: app-layer-parser.c:174
ConfValIsFalse
int ConfValIsFalse(const char *val)
Check if a value is false.
Definition: conf.c:591
RegisterHTPParsers
void RegisterHTPParsers(void)
Register the HTTP protocol and state handling functions to APP layer of the engine.
Definition: app-layer-htp.c:3184
AppLayerIncTxCounter
void AppLayerIncTxCounter(ThreadVars *tv, Flow *f, uint64_t step)
Definition: app-layer.c:112
StreamTcpInitConfig
void StreamTcpInitConfig(char)
To initialize the stream global configuration data.
Definition: stream-tcp.c:365
AppLayerParserGetTxDetectState
DetectEngineState * AppLayerParserGetTxDetectState(uint8_t ipproto, AppProto alproto, void *tx)
Definition: app-layer-parser.c:1117
app-layer-snmp.h
STREAM_EOF
#define STREAM_EOF
Definition: stream.h:30
RegisterSMTPParsers
void RegisterSMTPParsers(void)
Register the SMTP Protocol parser.
Definition: app-layer-smtp.c:1806
AppLayerParserProtoCtx_::GetTxDetectFlags
uint64_t(* GetTxDetectFlags)(void *tx, uint8_t dir)
Definition: app-layer-parser.c:126
AppLayerParserSetTxDetectState
int AppLayerParserSetTxDetectState(const Flow *f, void *tx, DetectEngineState *s)
Definition: app-layer-parser.c:1125
AppLayerParserStateAlloc
AppLayerParserState * AppLayerParserStateAlloc(void)
Definition: app-layer-parser.c:195
SCReturnCT
#define SCReturnCT(x, type)
Definition: util-debug.h:314
app-layer-protos.h
RegisterTemplateParsers
void RegisterTemplateParsers(void)
Definition: app-layer-template.c:476
STREAMTCP_FLAG_APP_LAYER_DISABLED
#define STREAMTCP_FLAG_APP_LAYER_DISABLED
Definition: stream-tcp-private.h:187
AppLayerParserState_::decoder_events
AppLayerDecoderEvents * decoder_events
Definition: app-layer-parser.c:170
AppLayerParserRegisterGetTxCnt
void AppLayerParserRegisterGetTxCnt(uint8_t ipproto, AppProto alproto, uint64_t(*StateGetTxCnt)(void *alstate))
Definition: app-layer-parser.c:512
APP_LAYER_ERROR
#define APP_LAYER_ERROR
Definition: app-layer-parser.h:60
app-layer-smb.h
AppLayerParserProtoCtx_::StateGetProgress
int(* StateGetProgress)(void *alstate, uint8_t direction)
Definition: app-layer-parser.c:110
AppLayerParserProtocolGetLoggerBits
LoggerId AppLayerParserProtocolGetLoggerBits(uint8_t ipproto, AppProto alproto)
Definition: app-layer-parser.c:1390
AppLayerParserStateSetFlag
void AppLayerParserStateSetFlag(AppLayerParserState *pstate, uint8_t flag)
Definition: app-layer-parser.c:1601
AppLayerParserCtx_
Definition: app-layer-parser.c:151
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:123
AppLayerParserThreadCtx_
Definition: app-layer-parser.c:85
AppLayerProtoDetectPMRegisterPatternCS
int AppLayerProtoDetectPMRegisterPatternCS(uint8_t ipproto, AppProto alproto, const char *pattern, uint16_t depth, uint16_t offset, uint8_t direction)
Registers a case-sensitive pattern for protocol detection.
Definition: app-layer-detect-proto.c:1723
app-layer-smtp.h
AppLayerParserProtoCtx_::StateGetProgressCompletionStatus
int(* StateGetProgressCompletionStatus)(uint8_t direction)
Definition: app-layer-parser.c:114
APP_LAYER_PARSER_NO_INSPECTION_PAYLOAD
#define APP_LAYER_PARSER_NO_INSPECTION_PAYLOAD
Definition: app-layer-parser.h:38
TcpSession_
Definition: stream-tcp-private.h:260
AppLayerParserProtoCtx_::StateGetTxLogged
LoggerId(* StateGetTxLogged)(void *alstate, void *tx)
Definition: app-layer-parser.c:120
RegisterNFSUDPParsers
void RegisterNFSUDPParsers(void)
Definition: app-layer-nfs-udp.c:253
Flow_::alproto
AppProto alproto
application level protocol
Definition: flow.h:425
AppLayerParserDestroyProtocolParserLocalStorage
void AppLayerParserDestroyProtocolParserLocalStorage(uint8_t ipproto, AppProto alproto, void *local_data)
Definition: app-layer-parser.c:628
util-pool.h
SCReturnInt
#define SCReturnInt(x)
Definition: util-debug.h:304
AppLayerParserGetTxCnt
uint64_t AppLayerParserGetTxCnt(const Flow *f, void *alstate)
Definition: app-layer-parser.c:1028
AppLayerProtoDetectConfProtoDetectionEnabled
int AppLayerProtoDetectConfProtoDetectionEnabled(const char *ipproto, const char *alproto)
Given a protocol name, checks if proto detection is enabled in the conf file.
Definition: app-layer-detect-proto.c:1890
SMTPParserCleanup
void SMTPParserCleanup(void)
Free memory allocated for global SMTP parser state.
Definition: app-layer-smtp.c:1868
AppLayerParserHasDecoderEvents
bool AppLayerParserHasDecoderEvents(AppLayerParserState *pstate)
Definition: app-layer-parser.c:1350
StreamTcpSetSessionBypassFlag
void StreamTcpSetSessionBypassFlag(TcpSession *)
enable bypass
Definition: stream-tcp.c:5899
app-layer-ssl.h
AppLayerParserProtoCtx_::StateGetEvents
AppLayerDecoderEvents *(* StateGetEvents)(void *)
Definition: app-layer-parser.c:108
TestState_
Definition: app-layer-parser.c:1654
AppLayerParserGetTxDetectFlags
uint64_t AppLayerParserGetTxDetectFlags(uint8_t ipproto, AppProto alproto, void *tx, uint8_t dir)
Definition: app-layer-parser.c:1147
app-layer-ntp.h
debug.h
AppLayerParserState_::flags
uint8_t flags
Definition: app-layer-parser.c:157
AppLayerParserProtoCtx_::LocalStorageAlloc
void *(* LocalStorageAlloc)(void)
Definition: app-layer-parser.c:103
app-layer-nfs-tcp.h
app-layer-rdp.h
app-layer.h
AppLayerParserGetEventInfo
int AppLayerParserGetEventInfo(uint8_t ipproto, AppProto alproto, const char *event_name, int *event_id, AppLayerEventType *event_type)
Definition: app-layer-parser.c:1055
AppLayerParserProtoCtx_::first_data_dir
uint8_t first_data_dir
Definition: app-layer-parser.c:137