Go to the documentation of this file.
91 void *(*LocalStorageAlloc)(void);
98 AppLayerGetFileState (*
GetTxFiles)(
void *,
void *, uint8_t);
102 void *(*StateGetTx)(
void *alstate, uint64_t tx_id);
111 AppLayerStateData *(*GetStateData)(
void *state);
161 static void AppLayerConfg(
void)
168 if (frames != NULL) {
185 if (f == NULL || f->
alparser == NULL)
212 static inline void AppLayerParserStreamTruncated(
AppLayerParserState *pstate,
const uint8_t ipproto,
213 const AppProto alproto,
void *alstate,
const uint8_t direction);
234 return (alp_ctx.
ctxs[ipproto_map][alproto].
StateAlloc != NULL) ? 1 : 0;
244 memset(pstate, 0,
sizeof(*pstate));
256 AppLayerParserFramesFreeContainer(pstate->
frames);
265 memset(&alp_ctx, 0,
sizeof(alp_ctx));
335 const char *alproto_name)
347 r = snprintf(param,
sizeof(param),
"%s%s%s",
"app-layer.protocols.",
348 alproto_name,
".enabled");
351 }
else if (r > (
int)
sizeof(param)) {
352 FatalError(
"buffer not big enough to write param.");
358 r = snprintf(param,
sizeof(param),
"%s%s%s%s%s",
"app-layer.protocols.",
359 alproto_name,
".", ipproto,
".enabled");
362 }
else if (r > (
int)
sizeof(param)) {
363 FatalError(
"buffer not big enough to write param.");
377 }
else if (strcasecmp(node->
val,
"detection-only") == 0) {
380 SCLogError(
"Invalid value found for %s.", param);
399 Parser[(direction & STREAM_TOSERVER) ? 0 : 1] = Parser;
410 (direction & (STREAM_TOSERVER | STREAM_TOCLIENT));
432 void *(*StateAlloc)(
void *,
AppProto),
void (*StateFree)(
void *))
445 void *(*LocalStorageAlloc)(
void),
446 void (*LocalStorageFree)(
void *))
459 AppLayerGetFileState (*GetTxFiles)(
void *,
void *, uint8_t))
487 void (*Truncate)(
void *, uint8_t))
497 int (*StateGetProgress)(
void *alstate, uint8_t direction))
502 StateGetProgress = StateGetProgress;
508 void (*StateTransactionFree)(
void *, uint64_t))
513 StateTransactionFree = StateTransactionFree;
519 uint64_t (*StateGetTxCnt)(
void *alstate))
524 StateGetTxCnt = StateGetTxCnt;
530 void *(StateGetTx)(
void *alstate, uint64_t tx_id))
535 StateGetTx = StateGetTx;
553 BUG_ON(!AppProtoIsValid(alproto));
564 int (*StateGetEventInfoById)(
int event_id,
const char **event_name,
570 StateGetEventInfoById = StateGetEventInfoById;
586 int (*StateGetEventInfo)(
const char *event_name,
int *event_id,
592 StateGetEventInfo = StateGetEventInfo;
608 uint8_t ipproto,
AppProto alproto, AppLayerStateData *(*GetStateData)(
void *state))
618 bool (*ApplyTxConfig)(
void *state,
void *tx,
int mode, AppLayerTxConfig))
628 void (*SetStreamDepthFlag)(
void *tx, uint8_t
flags))
645 LocalStorageAlloc != NULL)
660 LocalStorageFree != NULL)
663 LocalStorageFree(local_data);
677 static AppLayerGetTxIterTuple AppLayerDefaultGetTxIterator(
678 const uint8_t ipproto,
const AppProto alproto,
679 void *alstate, uint64_t min_tx_id, uint64_t max_tx_id,
682 uint64_t ustate = *(uint64_t *)state;
683 uint64_t tx_id =
MAX(min_tx_id, ustate);
684 for ( ; tx_id < max_tx_id; tx_id++) {
686 if (tx_ptr != NULL) {
689 AppLayerGetTxIterTuple tuple = {
692 .has_next = (tx_id + 1 < max_tx_id),
694 SCLogDebug(
"tuple: %p/%"PRIu64
"/%s", tuple.tx_ptr, tuple.tx_id,
695 tuple.has_next ?
"true" :
"false");
700 AppLayerGetTxIterTuple no_tuple = { NULL, 0,
false };
709 return Func ? Func : AppLayerDefaultGetTxIterator;
739 static inline uint64_t GetTxDetectFlags(
AppLayerTxData *txd,
const uint8_t dir)
741 uint64_t detect_flags =
742 (dir & STREAM_TOSERVER) ? txd->detect_flags_ts : txd->detect_flags_tc;
746 static inline void SetTxDetectFlags(
AppLayerTxData *txd,
const uint8_t dir,
const uint64_t detect_flags)
748 if (dir & STREAM_TOSERVER) {
749 txd->detect_flags_ts = detect_flags;
751 txd->detect_flags_tc = detect_flags;
757 return txd->logged.flags;
761 void *alstate,
const uint8_t
flags,
762 bool tag_txs_as_inspected)
766 const int direction = (
flags & STREAM_TOSERVER) ? 0 : 1;
770 const uint8_t ipproto = f->
proto;
775 memset(&state, 0,
sizeof(state));
777 SCLogDebug(
"called: %s, tag_txs_as_inspected %s",direction==0?
"toserver":
"toclient",
778 tag_txs_as_inspected?
"true":
"false");
783 AppLayerGetTxIterTuple ires = IterFunc(ipproto, alproto, alstate, idx, total_txs, &state);
784 if (ires.tx_ptr == NULL)
787 void *tx = ires.tx_ptr;
791 if (state_progress < state_done_progress)
795 if (txd && tag_txs_as_inspected) {
796 uint64_t detect_flags = GetTxDetectFlags(txd,
flags);
799 SetTxDetectFlags(txd,
flags, detect_flags);
800 SCLogDebug(
"%p/%"PRIu64
" in-order tx is done for direction %s. Flag %016"PRIx64,
801 tx, idx,
flags & STREAM_TOSERVER ?
"toserver" :
"toclient", detect_flags);
813 if (tag_txs_as_inspected) {
816 AppLayerGetTxIterTuple ires = IterFunc(ipproto, alproto, alstate, idx, total_txs, &state);
817 if (ires.tx_ptr == NULL)
820 void *tx = ires.tx_ptr;
824 if (ires.tx_id > idx && pstate->
inspect_id[direction] == idx) {
830 if (state_progress < state_done_progress)
836 uint64_t detect_flags = GetTxDetectFlags(txd,
flags);
839 SetTxDetectFlags(txd,
flags, detect_flags);
840 SCLogDebug(
"%p/%"PRIu64
" out of order tx is done for direction %s. Flag %016"PRIx64,
841 tx, idx,
flags & STREAM_TOSERVER ?
"toserver" :
"toclient", detect_flags);
843 SCLogDebug(
"%p/%"PRIu64
" out of order tx. Update inspect_id? %"PRIu64,
866 "AppLayerDecoderEvents *");
883 if (txd != NULL && txd->events != NULL) {
891 const Flow *f,
void *state,
void *tx,
const uint8_t direction)
899 AppLayerGetFileState files = { .fc = NULL, .cfg = NULL };
903 static void AppLayerParserFileTxHousekeeping(
904 const Flow *f,
void *tx,
const uint8_t pkt_dir,
const bool trunc)
912 #define IS_DISRUPTED(flags) ((flags) & (STREAM_DEPTH | STREAM_GAP))
931 const uint8_t ipproto = f->
proto;
933 void *
const alstate = f->
alstate;
936 if (alstate == NULL || alparser == NULL)
939 const uint64_t min = alparser->
min_id;
947 int pkt_dir_trunc = -1;
951 memset(&state, 0,
sizeof(state));
953 uint64_t new_min = min;
955 bool skipped =
false;
956 const bool is_unidir =
961 AppLayerGetTxIterTuple ires = IterFunc(ipproto, alproto, alstate, i, total_txs, &state);
962 if (ires.tx_ptr == NULL)
965 bool tx_skipped =
false;
966 void *tx = ires.tx_ptr;
971 if (txd != NULL && AppLayerParserHasFilesInDir(txd, pkt_dir)) {
972 if (pkt_dir_trunc == -1)
978 AppLayerParserFileTxHousekeeping(f, tx, pkt_dir, (
bool)pkt_dir_trunc);
981 const int tx_progress_tc =
983 if (tx_progress_tc < tx_end_state_tc) {
984 SCLogDebug(
"%p/%"PRIu64
" skipping: tc parser not done", tx, i);
988 const int tx_progress_ts =
990 if (tx_progress_ts < tx_end_state_ts) {
991 SCLogDebug(
"%p/%"PRIu64
" skipping: ts parser not done", tx, i);
996 bool inspected =
false;
997 if (txd && has_tx_detect_flags) {
999 uint64_t detect_flags_ts = GetTxDetectFlags(txd, STREAM_TOSERVER);
1001 SCLogDebug(
"%p/%"PRIu64
" skipping: TS inspect not done: ts:%"PRIx64,
1002 tx, i, detect_flags_ts);
1009 uint64_t detect_flags_tc = GetTxDetectFlags(txd, STREAM_TOCLIENT);
1011 SCLogDebug(
"%p/%"PRIu64
" skipping: TC inspect not done: tc:%"PRIx64,
1012 tx, i, detect_flags_tc);
1022 if (!is_unidir && tx_skipped) {
1023 SCLogDebug(
"%p/%" PRIu64
" !is_unidir && tx_skipped", tx, i);
1032 if (is_unidir && tx_skipped && !inspected) {
1033 SCLogDebug(
"%p/%" PRIu64
" is_unidir && tx_skipped && !inspected", tx, i);
1038 if (txd && logger_expectation != 0) {
1039 LoggerId tx_logged = GetTxLogged(txd);
1040 if (tx_logged != logger_expectation) {
1041 SCLogDebug(
"%p/%"PRIu64
" skipping: logging not done: want:%"PRIx32
", have:%"PRIx32,
1042 tx, i, logger_expectation, tx_logged);
1051 SCLogDebug(
"files_opened %u files_logged %u files_stored %u", txd->files_opened,
1052 txd->files_logged, txd->files_stored);
1054 if (txd->files_opened) {
1071 SCLogDebug(
"skipped? %s i %"PRIu64
", new_min %"PRIu64, skipped ?
"true" :
"false", i, new_min);
1074 SCLogDebug(
"final i %"PRIu64
", new_min %"PRIu64, i, new_min);
1077 if (!ires.has_next) {
1081 SCLogDebug(
"no next: cur tx i %"PRIu64
", total %"PRIu64, i, total_txs);
1083 new_min = total_txs;
1084 SCLogDebug(
"no next: cur tx i %"PRIu64
", total %"PRIu64
": "
1085 "new_min updated to %"PRIu64, i, total_txs, new_min);
1093 SCLogDebug(
"update f->alparser->min_id? %"PRIu64
" vs %"PRIu64, new_min, alparser->
min_id);
1094 if (new_min > alparser->
min_id) {
1095 const uint64_t next_id = new_min;
1096 alparser->
min_id = next_id;
1105 static inline int StateGetProgressCompletionStatus(
const AppProto alproto,
const uint8_t
flags)
1107 if (
flags & STREAM_TOSERVER) {
1109 }
else if (
flags & STREAM_TOCLIENT) {
1123 void *alstate, uint8_t
flags)
1128 r = StateGetProgressCompletionStatus(alproto,
flags);
1131 StateGetProgress(alstate,
flags);
1154 int r = StateGetProgressCompletionStatus(alproto, direction);
1173 *event_name = (
const char *)NULL;
1226 AppLayerStateData *d =
1234 void *state,
void *tx,
enum ConfigAction mode, AppLayerTxConfig config)
1248 if ((
flags & (STREAM_EOF|STREAM_TOSERVER)) == (STREAM_EOF|STREAM_TOSERVER)) {
1249 SCLogDebug(
"setting APP_LAYER_PARSER_EOF_TS");
1251 }
else if ((
flags & (STREAM_EOF|STREAM_TOCLIENT)) == (STREAM_EOF|STREAM_TOCLIENT)) {
1252 SCLogDebug(
"setting APP_LAYER_PARSER_EOF_TC");
1261 static void HandleStreamFrames(
Flow *f, StreamSlice stream_slice,
const uint8_t *input,
1262 const uint32_t input_len,
const uint8_t
flags)
1264 const uint8_t direction = (
flags & STREAM_TOSERVER) ? 0 : 1;
1270 input != NULL && f->
proto == IPPROTO_TCP) {
1272 if (frame == NULL) {
1273 int64_t frame_len = -1;
1274 if (
flags & STREAM_EOF)
1275 frame_len = input_len;
1278 f, &stream_slice, stream_slice.offset, frame_len, direction,
FRAME_STREAM_TYPE);
1280 SCLogDebug(
"opened: frame %p id %" PRIi64, frame, frame->
id);
1285 if (direction == 0) {
1291 }
else if (
flags & STREAM_EOF) {
1296 int64_t slice_o = (int64_t)stream_slice.offset - (int64_t)frame->
offset;
1297 int64_t frame_len = slice_o + (int64_t)input_len;
1298 SCLogDebug(
"%s: EOF frame->offset %" PRIu64
" -> %" PRIi64
": o %" PRIi64,
1300 frame->
len = frame_len;
1305 static void Setup(
Flow *f,
const uint8_t direction,
const uint8_t *input, uint32_t input_len,
1306 const uint8_t
flags, StreamSlice *as)
1308 memset(as, 0,
sizeof(*as));
1310 as->input_len = input_len;
1324 uint8_t
flags,
const uint8_t *input, uint32_t input_len)
1327 #ifdef DEBUG_VALIDATION
1332 StreamSlice stream_slice;
1333 void *alstate = NULL;
1334 uint64_t p_tx_cnt = 0;
1335 uint32_t consumed = input_len;
1336 const uint8_t direction = (
flags & STREAM_TOSERVER) ? 0 : 1;
1340 if (f->
proto == IPPROTO_TCP) {
1346 if (
flags & STREAM_GAP) {
1348 SCLogDebug(
"app-layer parser does not accept gaps");
1358 if (pstate == NULL) {
1360 if (pstate == NULL) {
1366 SetEOFFlags(pstate,
flags);
1371 if (alstate == NULL) {
1375 SCLogDebug(
"alloced new app layer state %p (name %s)",
1383 SCLogDebug(
"state data: updating file_flags %04x with flow file_flags %04x",
1390 SCLogDebug(
"using existing app layer state %p (name %s))",
1397 if (input_len > 0 || (
flags & STREAM_EOF)) {
1398 Setup(f,
flags & (STREAM_TOSERVER | STREAM_TOCLIENT), input, input_len,
flags,
1400 HandleStreamFrames(f, stream_slice, input, input_len,
flags);
1403 if (((stream_slice.flags & STREAM_TOSERVER) &&
1404 stream_slice.offset >= g_eps_applayer_error_offset_ts)) {
1405 SCLogNotice(
"putting parser %s into an error state from toserver offset %" PRIu64,
1410 if (((stream_slice.flags & STREAM_TOCLIENT) &&
1411 stream_slice.offset >= g_eps_applayer_error_offset_tc)) {
1412 SCLogNotice(
"putting parser %s into an error state from toclient offset %" PRIu64,
1419 AppLayerResult res = p->
Parser[direction](f, alstate, pstate, stream_slice,
1421 if (res.status < 0) {
1424 }
else if (res.status > 0) {
1433 if (res.consumed > input_len || res.needed + res.consumed < input_len) {
1441 (
flags & STREAM_TOSERVER) ?
"toserver" :
"toclient");
1442 if (direction == 0) {
1456 consumed = res.consumed;
1463 FlowSetNoPayloadInspectionFlag(f);
1465 if (f->
proto == IPPROTO_TCP) {
1490 FlowSetNoPayloadInspectionFlag(f);
1492 if (f->
proto == IPPROTO_TCP) {
1504 if (cur_tx_cnt > p_tx_cnt &&
tv) {
1509 if (
flags & STREAM_DEPTH)
1514 if (consumed != input_len && f->
proto == IPPROTO_TCP && f->
protoctx != NULL) {
1524 if (f->
proto == IPPROTO_TCP) {
1538 SCLogDebug(
"setting APP_LAYER_PARSER_EOF_TC and APP_LAYER_PARSER_EOF_TS");
1579 int r = (alp_ctx.
ctxs[ipproto_map][alproto].
logger ==
false) ? 0 : 1;
1596 if (f != NULL && f->
protoctx != NULL)
1622 if (state != NULL) {
1659 if (ctx->
StateFree != NULL && alstate != NULL)
1674 static void ValidateParserProtoDump(
AppProto alproto, uint8_t ipproto)
1678 printf(
"ERROR: incomplete app-layer registration\n");
1679 printf(
"AppLayer protocol %s ipproto %u\n",
AppProtoToString(alproto), ipproto);
1680 printf(
"- option flags %"PRIx32
"\n", ctx->
option_flags);
1682 printf(
"Mandatory:\n");
1683 printf(
"- Parser[0] %p Parser[1] %p\n", ctx->
Parser[0], ctx->
Parser[1]);
1685 printf(
"- StateGetTx %p StateGetTxCnt %p StateTransactionFree %p\n",
1687 printf(
"- GetTxData %p\n", ctx->
GetTxData);
1690 printf(
"Optional:\n");
1692 printf(
"- StateGetEventInfo %p StateGetEventInfoById %p\n", ctx->
StateGetEventInfo,
1696 #define BOTH_SET(a, b) ((a) != NULL && (b) != NULL)
1697 #define BOTH_SET_OR_BOTH_UNSET(a, b) (((a) == NULL && (b) == NULL) || ((a) != NULL && (b) != NULL))
1698 #define THREE_SET_OR_THREE_UNSET(a, b, c) (((a) == NULL && (b) == NULL && (c) == NULL) || ((a) != NULL && (b) != NULL && (c) != NULL))
1699 #define THREE_SET(a, b, c) ((a) != NULL && (b) != NULL && (c) != NULL)
1701 static void ValidateParserProto(
AppProto alproto, uint8_t ipproto)
1733 ValidateParserProtoDump(alproto, ipproto);
1737 #undef BOTH_SET_OR_BOTH_UNSET
1738 #undef THREE_SET_OR_THREE_UNSET
1741 static void ValidateParser(
AppProto alproto)
1743 ValidateParserProto(alproto, IPPROTO_TCP);
1744 ValidateParserProto(alproto, IPPROTO_UDP);
1747 static void ValidateParsers(
void)
1763 rs_dcerpc_register_parser();
1764 rs_dcerpc_udp_register_parser();
1769 rs_dns_udp_register_parser();
1770 rs_dns_tcp_register_parser();
1771 rs_bittorrent_dht_udp_register_parser();
1782 rs_dhcp_register_parser();
1786 rs_template_register_parser();
1789 rs_pgsql_register_parser();
1792 rs_telnet_register_parser();
1798 "1|20|capability", 12, 0, STREAM_TOSERVER) < 0)
1800 SCLogInfo(
"imap proto registration failure");
1804 SCLogInfo(
"Protocol detection and parser disabled for %s protocol.",
1817 pstate->
flags |= flag;
1828 static inline void AppLayerParserStreamTruncated(
AppLayerParserState *pstate,
const uint8_t ipproto,
1829 const AppProto alproto,
void *alstate,
const uint8_t direction)
1833 if (direction & STREAM_TOSERVER) {
1855 SCLogDebug(
"AppLayerParser parser state information for parser state p(%p). "
1856 "p->inspect_id[0](%"PRIu64
"), "
1857 "p->inspect_id[1](%"PRIu64
"), "
1858 "p->log_id(%"PRIu64
"), "
1859 "p->decoder_events(%p).",
1883 StreamSlice stream_slice,
void *local_data)
1891 static void *TestProtocolStateAlloc(
void *orig_state,
AppProto proto_orig)
1904 static void TestProtocolStateFree(
void *s)
1909 static uint64_t TestGetTxCnt(
void *state)
1915 static void TestStateTransactionFree(
void *state, uint64_t tx_id)
1920 static void *TestGetTx(
void *state, uint64_t tx_id)
1927 void (*RegisterUnittests)(
void))
1931 RegisterUnittests = RegisterUnittests;
1938 alp_ctx_backup_unittest = alp_ctx;
1939 memset(&alp_ctx, 0,
sizeof(alp_ctx));
1946 alp_ctx = alp_ctx_backup_unittest;
1947 memset(&alp_ctx_backup_unittest, 0,
sizeof(alp_ctx_backup_unittest));
1955 static int AppLayerParserTest01(
void)
1960 uint8_t testbuf[] = { 0x11 };
1961 uint32_t testlen =
sizeof(testbuf);
1965 memset(&ssn, 0,
sizeof(ssn));
1970 TestProtocolStateAlloc, TestProtocolStateFree);
1975 f =
UTHBuildFlow(AF_INET,
"1.2.3.4",
"4.3.2.1", 20, 40);
1979 f->
proto = IPPROTO_TCP;
1984 STREAM_TOSERVER | STREAM_EOF, testbuf,
2000 static int AppLayerParserTest02(
void)
2005 uint8_t testbuf[] = { 0x11 };
2006 uint32_t testlen =
sizeof(testbuf);
2011 TestProtocolParser);
2013 TestProtocolStateAlloc, TestProtocolStateFree);
2018 f =
UTHBuildFlow(AF_INET,
"1.2.3.4",
"4.3.2.1", 20, 40);
2021 f->
proto = IPPROTO_UDP;
2027 STREAM_TOSERVER | STREAM_EOF, testbuf,
2047 for (alproto = 0; alproto <
ALPROTO_MAX; alproto++) {
2048 ctx = &alp_ctx.
ctxs[ip][alproto];
void(* Truncate)(void *, uint8_t)
void AppLayerParserRegisterGetStateProgressFunc(uint8_t ipproto, AppProto alproto, int(*StateGetProgress)(void *alstate, uint8_t direction))
int AppLayerParserDeSetup(void)
AppLayerStateData *(* GetStateData)(void *state)
void RegisterNTPParsers(void)
uint64_t(* StateGetTxCnt)(void *alstate)
enum ExceptionPolicy g_applayerparser_error_policy
AppLayerTxData *(* GetTxData)(void *tx)
#define FAIL_IF_NULL(expr)
Fail a test if expression evaluates to NULL.
AppLayerParserProtoCtx ctxs[FLOW_PROTO_MAX][ALPROTO_MAX]
void RegisterSMBParsers(void)
void RegisterIKEParsers(void)
int AppLayerParserIsEnabled(AppProto alproto)
simple way to globally test if a alproto is registered and fully enabled in the configuration.
void AppLayerParserRegisterLocalStorageFunc(uint8_t ipproto, AppProto alproto, void *(*LocalStorageAlloc)(void), void(*LocalStorageFree)(void *))
int AppLayerParserProtocolHasLogger(uint8_t ipproto, AppProto alproto)
void AppLayerParserRegisterOptionFlags(uint8_t ipproto, AppProto alproto, uint32_t flags)
void FramesFree(Frames *frames)
void AppLayerParserSetStreamDepthFlag(uint8_t ipproto, AppProto alproto, void *state, uint64_t tx_id, uint8_t flags)
void RegisterQuicParsers(void)
void AppLayerParserSetTransactionLogId(AppLayerParserState *pstate, uint64_t tx_id)
bool g_filedata_logger_enabled
void AppLayerParserSetStreamDepth(uint8_t ipproto, AppProto alproto, uint32_t stream_depth)
void AppLayerParserApplyTxConfig(uint8_t ipproto, AppProto alproto, void *state, void *tx, enum ConfigAction mode, AppLayerTxConfig config)
void AppLayerParserTransactionsCleanup(Flow *f, const uint8_t pkt_dir)
remove obsolete (inspected and logged) transactions
void * AppLayerParserGetProtocolParserLocalStorage(uint8_t ipproto, AppProto alproto)
void UtRegisterTest(const char *name, int(*TestFn)(void))
Register unit test.
void(* LocalStorageFree)(void *)
App layer protocol parser context.
void RegisterSSHParsers(void)
Function to register the SSH protocol parsers and other functions.
void *(* StateGetTx)(void *alstate, uint64_t tx_id)
void AppLayerParserSetTransactionInspectId(const Flow *f, AppLayerParserState *pstate, void *alstate, const uint8_t flags, bool tag_txs_as_inspected)
#define APP_LAYER_PARSER_BYPASS_READY
AppLayerDecoderEvents * AppLayerParserGetEventsByTx(uint8_t ipproto, AppProto alproto, void *tx)
AppLayerGetTxIteratorFunc AppLayerGetTxIterator(const uint8_t ipproto, const AppProto alproto)
struct HtpBodyChunk_ * next
void RegisterModbusParsers(void)
Function to register the Modbus protocol parser.
AppLayerGetFileState(* GetTxFiles)(void *, void *, uint8_t)
void StreamTcpSetDisableRawReassemblyFlag(TcpSession *, char)
Set the No reassembly flag for the given direction in given TCP session.
FramesContainer * AppLayerFramesSetupContainer(Flow *f)
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
int AppLayerParserGetStateProgress(uint8_t ipproto, AppProto alproto, void *alstate, uint8_t flags)
get the progress value for a tx/protocol
void AppLayerParserTriggerRawStreamReassembly(Flow *f, int direction)
ConfNode * ConfGetNode(const char *name)
Get a ConfNode by name.
uint32_t reassembly_depth
void AppLayerIncGapErrorCounter(ThreadVars *tv, Flow *f)
#define APP_LAYER_PARSER_INT_STREAM_DEPTH_SET
enum AppLayerEventType_ AppLayerEventType
void StreamTcpReassembleTriggerRawReassembly(TcpSession *ssn, int direction)
Trigger RAW stream reassembly.
uint64_t AppLayerParserGetTransactionLogId(AppLayerParserState *pstate)
const char * AppProtoToString(AppProto alproto)
Maps the ALPROTO_*, to its string equivalent.
void AppLayerParserRegisterTruncateFunc(uint8_t ipproto, AppProto alproto, void(*Truncate)(void *, uint8_t))
void AppLayerParserRegisterStateProgressCompletionStatus(AppProto alproto, const int ts, const int tc)
void AppLayerParserRegisterParserAcceptableDataDirection(uint8_t ipproto, AppProto alproto, uint8_t direction)
int AppLayerParserGetStateProgressCompletionStatus(AppProto alproto, uint8_t direction)
uint8_t AppLayerParserGetFirstDataDir(uint8_t ipproto, AppProto alproto)
int AppLayerParserProtoIsRegistered(uint8_t ipproto, AppProto alproto)
void AppLayerParserRegisterTxFreeFunc(uint8_t ipproto, AppProto alproto, void(*StateTransactionFree)(void *, uint64_t))
#define FLOW_NOPAYLOAD_INSPECTION
int AppLayerParserSupportsFiles(uint8_t ipproto, AppProto alproto)
void AppLayerParserStateProtoCleanup(uint8_t protomap, AppProto alproto, void *alstate, AppLayerParserState *pstate)
AppLayerGetTxIteratorFunc StateGetTxIterator
void AppLayerParserThreadCtxFree(AppLayerParserThreadCtx *tctx)
Destroys the app layer parser thread context obtained using AppLayerParserThreadCtxAlloc().
void AppLayerDecoderEventsFreeEvents(AppLayerDecoderEvents **events)
void StreamTcpUpdateAppLayerProgress(TcpSession *ssn, char direction, const uint32_t progress)
update reassembly progress
#define APP_LAYER_TX_INSPECTED_FLAG
uint32_t AppLayerParserGetOptionFlags(uint8_t protomap, AppProto alproto)
void AppLayerParserRegisterGetTxFilesFunc(uint8_t ipproto, AppProto alproto, AppLayerGetFileState(*GetTxFiles)(void *, void *, uint8_t))
AppLayerStateData * AppLayerParserGetStateData(uint8_t ipproto, AppProto alproto, void *state)
struct TestState_ TestState
void RegisterSIPParsers(void)
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
TcpStreamCnf stream_config
#define APP_LAYER_PARSER_EOF_TS
void AppLayerIncAllocErrorCounter(ThreadVars *tv, Flow *f)
void AppLayerParserRegisterUnittests(void)
uint64_t AppLayerParserGetTransactionInspectId(AppLayerParserState *pstate, uint8_t direction)
void RegisterKRB5Parsers(void)
Data structure to store app layer decoder events.
bool(* ApplyTxConfig)(void *state, void *tx, int mode, AppLayerTxConfig)
uint8_t FlowGetReverseProtoMapping(uint8_t rproto)
void RegisterDNP3Parsers(void)
Register the DNP3 application protocol parser.
int ConfValIsTrue(const char *val)
Check if a value is true.
void FTPParserCleanup(void)
Free memory allocated for global FTP parser state.
int AppLayerParserGetEventInfoById(uint8_t ipproto, AppProto alproto, int event_id, const char **event_name, AppLayerEventType *event_type)
const struct SigGroupHead_ * sgh_toserver
void AppLayerParserRestoreParserTable(void)
AppLayerResult(* AppLayerParserFPtr)(Flow *f, void *protocol_state, AppLayerParserState *pstate, StreamSlice stream_slice, void *local_storage)
Prototype for parsing functions.
struct AppLayerParserCtx_ AppLayerParserCtx
AppLayerParserState * alparser
void AppLayerParserRegisterProtocolParsers(void)
void RegisterRFBParsers(void)
void StreamTcpInitConfig(bool)
To initialize the stream global configuration data.
Flow * UTHBuildFlow(int family, const char *src, const char *dst, Port sp, Port dp)
#define APP_LAYER_PARSER_SFRAME_TS
#define PASS
Pass the test.
AppLayerParserGetFrameIdByNameFn GetFrameIdByName
const char * AppLayerParserGetFrameNameById(uint8_t ipproto, AppProto alproto, const uint8_t id)
uint64_t AppLayerParserGetTransactionActive(const Flow *f, AppLayerParserState *pstate, uint8_t direction)
void AppLayerFramesFreeContainer(Flow *f)
AppLayerParserThreadCtx * alp_tctx
void AppLayerParserRegisterLogger(uint8_t ipproto, AppProto alproto)
void AppLayerParserRegisterGetFrameFuncs(uint8_t ipproto, AppProto alproto, AppLayerParserGetFrameIdByNameFn GetIdByNameFunc, AppLayerParserGetFrameNameByIdFn GetNameByIdFunc)
void(* SetStreamDepthFlag)(void *tx, uint8_t flags)
void RegisterENIPTCPParsers(void)
Function to register the ENIP protocol parsers and other functions.
Per thread variable structure.
void AppLayerParserRegisterLoggerBits(uint8_t ipproto, AppProto alproto, LoggerId bits)
int(* StateGetEventInfo)(const char *event_name, int *event_id, AppLayerEventType *event_type)
void AppLayerParserRegisterStateFuncs(uint8_t ipproto, AppProto alproto, void *(*StateAlloc)(void *, AppProto), void(*StateFree)(void *))
#define APP_LAYER_PARSER_OPT_UNIDIR_TXS
#define APP_LAYER_PARSER_NO_REASSEMBLY
#define IS_DISRUPTED(flags)
void AppLayerParserSetEOF(AppLayerParserState *pstate)
void(* RegisterUnittests)(void)
void AppLayerParserStateFree(AppLayerParserState *pstate)
void AppLayerParserStateCleanup(const Flow *f, void *alstate, AppLayerParserState *pstate)
void AppLayerParserBackupParserTable(void)
int(* StateGetEventInfoById)(int event_id, const char **event_name, AppLayerEventType *event_type)
const struct SigGroupHead_ * sgh_toclient
void RegisterNFSTCPParsers(void)
AppLayerParserGetFrameNameByIdFn GetFrameNameById
struct AppLayerParserProtoCtx_ AppLayerParserProtoCtx
App layer protocol parser context.
int AppLayerParserSetup(void)
void RegisterFTPParsers(void)
void AppLayerParserRegisterProtocolUnittests(uint8_t ipproto, AppProto alproto, void(*RegisterUnittests)(void))
void *(* StateAlloc)(void *, AppProto)
uint8_t FlowGetProtoMapping(uint8_t proto)
Function to map the protocol to the defined FLOW_PROTO_* enumeration.
void RegisterTFTPParsers(void)
#define FLOW_PROTO_APPLAYER_MAX
#define APP_LAYER_PARSER_EOF_TC
#define DEBUG_ASSERT_FLOW_LOCKED(f)
#define BOTH_SET_OR_BOTH_UNSET(a, b)
void * alproto_local_storage[FLOW_PROTO_MAX][ALPROTO_MAX]
void AppLayerParserRegisterGetEventInfo(uint8_t ipproto, AppProto alproto, int(*StateGetEventInfo)(const char *event_name, int *event_id, AppLayerEventType *event_type))
void AppLayerParserSetDecoderEvents(AppLayerParserState *pstate, AppLayerDecoderEvents *devents)
#define SCReturnPtr(x, type)
void(* StateFree)(void *)
void AppLayerProtoDetectRegisterProtocol(AppProto alproto, const char *alproto_name)
Registers a protocol for protocol detection phase.
void AppLayerParserRegisterSetStreamDepthFlag(uint8_t ipproto, AppProto alproto, void(*SetStreamDepthFlag)(void *tx, uint8_t flags))
#define APP_LAYER_PARSER_SFRAME_TC
void AppLayerIncParserErrorCounter(ThreadVars *tv, Flow *f)
int RunmodeIsUnittests(void)
#define SCLogInfo(...)
Macro used to log INFORMATIONAL messages.
void RegisterRdpParsers(void)
#define APP_LAYER_PARSER_NO_INSPECTION
void * AppLayerParserGetTx(uint8_t ipproto, AppProto alproto, void *alstate, uint64_t tx_id)
int AppLayerParserRegisterParser(uint8_t ipproto, AppProto alproto, uint8_t direction, AppLayerParserFPtr Parser)
Register app layer parser for the protocol.
void UTHFreeFlow(Flow *flow)
AppLayerParserThreadCtx * AppLayerParserThreadCtxAlloc(void)
Gets a new app layer protocol's parser thread context.
void AppLayerParserRegisterGetTx(uint8_t ipproto, AppProto alproto, void *(StateGetTx)(void *alstate, uint64_t tx_id))
void AppLayerParserStateSetFlag(AppLayerParserState *pstate, uint16_t flag)
AppLayerParserFPtr Parser[2]
struct AppLayerTxData AppLayerTxData
void(* StateTransactionFree)(void *, uint64_t)
#define SCReturnStruct(x)
void RegisterSSLParsers(void)
Function to register the SSL protocol parser and other functions.
#define FAIL_IF(expr)
Fail a test if expression evaluates to true.
void StreamTcpSetSessionNoReassemblyFlag(TcpSession *, char)
disable reassembly
void StreamTcpFreeConfig(bool quiet)
enum ExceptionPolicy ExceptionPolicyParse(const char *option, const bool support_flow)
int AppLayerParserParse(ThreadVars *tv, AppLayerParserThreadCtx *alp_tctx, Flow *f, AppProto alproto, uint8_t flags, const uint8_t *input, uint32_t input_len)
const char *(* AppLayerParserGetFrameNameByIdFn)(const uint8_t id)
void StreamTcpDisableAppLayer(Flow *f)
int AppLayerParserGetFrameIdByName(uint8_t ipproto, AppProto alproto, const char *name)
void AppLayerParserRegisterApplyTxConfigFunc(uint8_t ipproto, AppProto alproto, bool(*ApplyTxConfig)(void *state, void *tx, int mode, AppLayerTxConfig))
void RegisterENIPUDPParsers(void)
Function to register the ENIP protocol parsers and other functions.
void AppLayerParserRegisterStateDataFunc(uint8_t ipproto, AppProto alproto, AppLayerStateData *(*GetStateData)(void *state))
void FilesPrune(FileContainer *fc, const StreamingBufferConfig *sbcfg, const bool trunc)
void AppLayerIncInternalErrorCounter(ThreadVars *tv, Flow *f)
AppLayerTxData * AppLayerParserGetTxData(uint8_t ipproto, AppProto alproto, void *tx)
void AppLayerParserRegisterTxDataFunc(uint8_t ipproto, AppProto alproto, AppLayerTxData *(*GetTxData)(void *tx))
uint32_t AppLayerParserGetStreamDepth(const Flow *f)
Frame * AppLayerFrameGetById(Flow *f, const int dir, const FrameId frame_id)
void RegisterSNMPParsers(void)
#define FRAME_STREAM_TYPE
#define APP_LAYER_PARSER_OPT_ACCEPT_GAPS
void AppLayerParserRegisterGetTxIterator(uint8_t ipproto, AppProto alproto, AppLayerGetTxIteratorFunc Func)
FramesContainer * AppLayerFramesGetContainer(Flow *f)
#define SCLogError(...)
Macro used to log ERROR messages.
void AppLayerParserPostStreamSetup(void)
AppLayerDecoderEvents * AppLayerParserGetDecoderEvents(AppLayerParserState *pstate)
#define THREE_SET(a, b, c)
void AppLayerParserRegisterGetEventInfoById(uint8_t ipproto, AppProto alproto, int(*StateGetEventInfoById)(int event_id, const char **event_name, AppLayerEventType *event_type))
const char * AppLayerGetProtoName(AppProto alproto)
Given the internal protocol id, returns a string representation of the protocol.
void UTHAppLayerParserStateGetIds(void *ptr, uint64_t *i1, uint64_t *i2, uint64_t *log, uint64_t *min)
int ConfValIsFalse(const char *val)
Check if a value is false.
void RegisterHTPParsers(void)
Register the HTTP protocol and state handling functions to APP layer of the engine.
void AppLayerIncTxCounter(ThreadVars *tv, Flow *f, uint64_t step)
#define FRAME_FLAG_ENDS_AT_EOF
#define APP_LAYER_PARSER_TRUNC_TC
void RegisterSMTPParsers(void)
Register the SMTP Protocol parser.
AppLayerParserState * AppLayerParserStateAlloc(void)
#define SCReturnCT(x, type)
#define STREAMTCP_FLAG_APP_LAYER_DISABLED
AppLayerDecoderEvents * decoder_events
void AppLayerParserRegisterGetTxCnt(uint8_t ipproto, AppProto alproto, uint64_t(*StateGetTxCnt)(void *alstate))
int(* StateGetProgress)(void *alstate, uint8_t direction)
LoggerId AppLayerParserProtocolGetLoggerBits(uint8_t ipproto, AppProto alproto)
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
bool g_file_logger_enabled
AppLayerGetFileState AppLayerParserGetTxFiles(const Flow *f, void *state, void *tx, const uint8_t direction)
void RegisterHTTP2Parsers(void)
#define STREAM_APP_PROGRESS(stream)
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.
#define APP_LAYER_PARSER_NO_INSPECTION_PAYLOAD
int FlowChangeProto(Flow *f)
Check if change proto flag is set for flow.
uint8_t FlowGetDisruptionFlags(const Flow *f, uint8_t flags)
get 'disruption' flags: GAP/DEPTH/PASS
#define APP_LAYER_PARSER_TRUNC_TS
uint16_t AppLayerParserStateIssetFlag(AppLayerParserState *pstate, uint16_t flag)
#define SCLogNotice(...)
Macro used to log NOTICE messages.
void RegisterNFSUDPParsers(void)
AppProto alproto
application level protocol
void AppLayerParserDestroyProtocolParserLocalStorage(uint8_t ipproto, AppProto alproto, void *local_data)
uint64_t AppLayerParserGetTxCnt(const Flow *f, void *alstate)
int AppLayerProtoDetectConfProtoDetectionEnabled(const char *ipproto, const char *alproto)
Given a protocol name, checks if proto detection is enabled in the conf file.
void SMTPParserCleanup(void)
Free memory allocated for global SMTP parser state.
bool AppLayerParserHasDecoderEvents(AppLayerParserState *pstate)
void RegisterMQTTParsers(void)
int(* AppLayerParserGetFrameIdByNameFn)(const char *frame_name)
void StreamTcpSetSessionBypassFlag(TcpSession *)
enable bypass
#define DEBUG_VALIDATE_BUG_ON(exp)
@ EXCEPTION_POLICY_NOT_SET
void *(* LocalStorageAlloc)(void)
int AppLayerParserGetEventInfo(uint8_t ipproto, AppProto alproto, const char *event_name, int *event_id, AppLayerEventType *event_type)