Go to the documentation of this file.
91 void *(*LocalStorageAlloc)(void);
100 void *(*StateGetTx)(
void *alstate, uint64_t tx_id);
168 static inline uint8_t GetTxEndProgress(uint8_t ipproto,
AppProto alproto,
void *tx, uint8_t
flags);
169 static inline uint8_t GetTxdEndProgress(uint8_t ipproto,
AppProto alproto,
174 static void AppLayerConfig(
void)
186 if (frames != NULL) {
203 if (f == NULL || f->
alparser == NULL)
249 return (alp_ctx.
ctxs[alproto][ipproto_map].
StateAlloc != NULL) ? 1 : 0;
270 AppLayerParserFramesFreeContainer(pstate->
frames);
383 bool g_enabled =
false;
384 bool i_enabled =
false;
390 r = snprintf(param,
sizeof(param),
"%s%s%s%s%s",
"app-layer.protocols.", alproto_name,
".",
391 ipproto,
".enabled");
394 }
else if (r > (
int)
sizeof(param)) {
395 FatalError(
"buffer not big enough to write param.");
400 if (i_proto && i_proto->
val) {
405 }
else if (strcasecmp(i_proto->
val,
"detection-only") == 0) {
408 FatalError(
"Invalid value found for %s.", param);
412 r = snprintf(param,
sizeof(param),
"%s%s%s",
"app-layer.protocols.", alproto_name,
".enabled");
415 }
else if (r > (
int)
sizeof(param)) {
416 FatalError(
"buffer not big enough to write param.");
421 if (g_proto && g_proto->
val) {
426 }
else if (strcasecmp(g_proto->
val,
"detection-only") == 0) {
429 FatalError(
"Invalid value found for %s", param);
433 if ((i_proto && g_proto) && (i_enabled ^ g_enabled)) {
435 SCLogDebug(
"Inconsistent global (%s) and respective ipproto (%s) settings found for "
436 "alproto %s and ipproto %s",
437 g_enabled ?
"TRUE" :
"FALSE", i_enabled ?
"TRUE" :
"FALSE", alproto_name, ipproto);
459 .
Parser[(direction & STREAM_TOSERVER) ? 0 : 1] = Parser;
465 uint8_t ipproto,
AppProto alproto, uint8_t direction)
470 (direction & (STREAM_TOSERVER | STREAM_TOCLIENT));
486 void *(*StateAlloc)(
void *,
AppProto),
void (*StateFree)(
void *))
497 void *(*LocalStorageAlloc)(
void),
498 void (*LocalStorageFree)(
void *))
537 int (*StateGetProgress)(
void *alstate, uint8_t direction))
547 void (*StateTransactionFree)(
void *, uint64_t))
557 uint64_t (*StateGetTxCnt)(
void *alstate))
567 void *(StateGetTx)(
void *alstate, uint64_t tx_id))
589 BUG_ON(!AppProtoIsValid(alproto));
600 int (*StateGetEventInfoById)(
606 StateGetEventInfoById;
618 BUG_ON(GetIdByNameFunc == NULL);
619 BUG_ON(GetNameByIdFunc == NULL);
631 m->GetStateIdByName = GetIdByNameFunc;
632 m->GetStateNameById = GetNameByIdFunc;
633 m->next =
p->sub_state_mappings;
634 p->sub_state_mappings =
m;
638 sub_state,
p->max_sub_state,
m->GetStateIdByName,
m->GetStateNameById);
664 int (*StateGetEventInfo)(
705 void (*SetStreamDepthFlag)(
void *tx, uint8_t
flags))
749 const uint8_t ipproto,
const AppProto alproto,
750 void *alstate, uint64_t min_tx_id, uint64_t max_tx_id,
753 uint64_t ustate = *(uint64_t *)state;
754 uint64_t tx_id =
MAX(min_tx_id, ustate);
755 for ( ; tx_id < max_tx_id; tx_id++) {
757 if (tx_ptr != NULL) {
763 .has_next = (tx_id + 1 < max_tx_id),
780 return Func ? Func : AppLayerDefaultGetTxIterator;
837 void *alstate,
const uint8_t
flags,
838 bool tag_txs_as_inspected)
842 const int direction = (
flags & STREAM_TOSERVER) ? 0 : 1;
846 const uint8_t ipproto = f->
proto;
852 SCLogDebug(
"called: %s, tag_txs_as_inspected %s",direction==0?
"toserver":
"toclient",
853 tag_txs_as_inspected?
"true":
"false");
866 const int tx_end_state =
867 GetTxdEndProgress(ipproto, alproto, txd,
flags, (uint8_t)state_done_progress);
869 if (state_progress < tx_end_state)
872 if (tag_txs_as_inspected) {
875 if (!(txd->
flags & inspected_flag)) {
876 txd->
flags |= inspected_flag;
877 SCLogDebug(
"%p/%" PRIu64
" in-order tx is done for direction %s. Flags %02x", tx,
878 idx,
flags & STREAM_TOSERVER ?
"toserver" :
"toclient", txd->
flags);
890 if (tag_txs_as_inspected) {
907 const int tx_end_state =
908 GetTxdEndProgress(ipproto, alproto, txd,
flags, (uint8_t)state_done_progress);
910 if (state_progress < tx_end_state)
915 if (!(txd->
flags & inspected_flag)) {
916 txd->
flags |= inspected_flag;
917 SCLogDebug(
"%p/%" PRIu64
" out of order tx is done for direction %s. Flag %02x", tx,
918 idx,
flags & STREAM_TOSERVER ?
"toserver" :
"toclient", txd->
flags);
920 SCLogDebug(
"%p/%" PRIu64
" out of order tx. Update inspect_id? %" PRIu64, tx, idx,
939 "AppLayerDecoderEvents *");
951 if (txd->
events != NULL) {
970 static void AppLayerParserFileTxHousekeeping(
971 const Flow *f,
void *tx,
const uint8_t pkt_dir,
const bool trunc)
979 #define IS_DISRUPTED(flags) ((flags) & (STREAM_DEPTH | STREAM_GAP | STREAM_ASYNC))
994 if (
unlikely(
p->StateTransactionFree == NULL))
998 const uint8_t ipproto = f->
proto;
1000 void *
const alstate = f->
alstate;
1003 if (alstate == NULL || alparser == NULL)
1006 const uint64_t min = alparser->
min_id;
1014 int pkt_dir_trunc = -1;
1018 memset(&state, 0,
sizeof(state));
1020 uint64_t new_min = min;
1022 bool skipped =
false;
1030 bool tx_skipped =
false;
1037 if (pkt_dir_trunc == -1)
1039 (pkt_dir == STREAM_TOSERVER) ? ts_disrupt_flags : tc_disrupt_flags);
1040 AppLayerParserFileTxHousekeeping(f, tx, pkt_dir, (
bool)pkt_dir_trunc);
1043 if (pkt_dir & STREAM_TOSERVER) {
1048 const int tx_progress_tc =
1050 const int end_state_tc =
1051 GetTxdEndProgress(ipproto, alproto, txd, STREAM_TOCLIENT, (uint8_t)tx_end_state_tc);
1052 if (tx_progress_tc < end_state_tc) {
1053 SCLogDebug(
"%p/%"PRIu64
" skipping: tc parser not done", tx, i);
1057 const int end_state_ts =
1058 GetTxdEndProgress(ipproto, alproto, txd, STREAM_TOSERVER, (uint8_t)tx_end_state_ts);
1059 const int tx_progress_ts =
1061 if (tx_progress_ts < end_state_ts) {
1062 SCLogDebug(
"%p/%"PRIu64
" skipping: ts parser not done", tx, i);
1067 if (has_tx_detect_flags) {
1072 SCLogDebug(
"%p/%" PRIu64
" skipping: TS inspect not done: ts:%02x", tx, i,
1081 SCLogDebug(
"%p/%" PRIu64
" skipping: TC inspect not done: ts:%02x", tx, i,
1089 SCLogDebug(
"%p/%" PRIu64
" tx_skipped", tx, i);
1094 if (logger_expectation != 0) {
1095 LoggerId tx_logged = GetTxLogged(txd);
1096 if (tx_logged != logger_expectation) {
1097 SCLogDebug(
"%p/%"PRIu64
" skipping: logging not done: want:%"PRIx32
", have:%"PRIx32,
1098 tx, i, logger_expectation, tx_logged);
1121 p->StateTransactionFree(alstate, i);
1125 SCLogDebug(
"skipped? %s i %"PRIu64
", new_min %"PRIu64, skipped ?
"true" :
"false", i, new_min);
1128 SCLogDebug(
"final i %"PRIu64
", new_min %"PRIu64, i, new_min);
1135 SCLogDebug(
"no next: cur tx i %"PRIu64
", total %"PRIu64, i, total_txs);
1137 new_min = total_txs;
1138 SCLogDebug(
"no next: cur tx i %"PRIu64
", total %"PRIu64
": "
1139 "new_min updated to %"PRIu64, i, total_txs, new_min);
1147 SCLogDebug(
"update f->alparser->min_id? %"PRIu64
" vs %"PRIu64, new_min, alparser->
min_id);
1148 if (new_min > alparser->
min_id) {
1149 const uint64_t next_id = new_min;
1150 alparser->
min_id = next_id;
1159 static inline int StateGetProgressCompletionStatus(
const AppProto alproto,
const uint8_t
flags)
1161 if (
flags & STREAM_TOSERVER) {
1163 }
else if (
flags & STREAM_TOCLIENT) {
1176 static inline uint8_t GetTxEndProgress(uint8_t ipproto,
AppProto alproto,
void *tx, uint8_t
flags)
1180 uint8_t tx_end_state;
1184 if (
flags & STREAM_TOSERVER)
1189 return tx_end_state;
1201 static inline uint8_t GetTxdEndProgress(uint8_t ipproto,
AppProto alproto,
1205 uint8_t tx_end_state;
1208 tx_end_state = complete;
1212 if (
flags & STREAM_TOSERVER)
1217 return tx_end_state;
1230 r = (int)GetTxEndProgress(ipproto, alproto, tx,
flags);
1232 const uint8_t direction =
flags & (STREAM_TOCLIENT | STREAM_TOSERVER);
1255 int r = StateGetProgressCompletionStatus(alproto, direction);
1271 const AppProto alproto,
const uint8_t
sub_state,
const char *state,
const uint8_t dir_flag)
1280 BUG_ON(dir_flag != STREAM_TOSERVER && dir_flag != STREAM_TOCLIENT);
1284 m != NULL;
m =
m->next) {
1286 BUG_ON(
m->GetStateNameById == NULL);
1287 BUG_ON(
m->GetStateIdByName == NULL);
1289 int v =
m->GetStateIdByName(state, dir_flag);
1304 const uint8_t state,
const uint8_t dir_flag)
1313 BUG_ON(dir_flag != STREAM_TOSERVER && dir_flag != STREAM_TOCLIENT);
1317 m != NULL;
m =
m->next) {
1319 BUG_ON(
m->GetStateNameById == NULL);
1320 BUG_ON(
m->GetStateIdByName == NULL);
1322 return m->GetStateNameById(state, dir_flag);
1395 event_name, event_id, event_type);
1404 *event_name = (
const char *)NULL;
1408 event_id, event_name, event_type);
1425 uint64_t log_id = pstate->
log_id;
1426 uint64_t inspect_id = pstate->
inspect_id[(direction & STREAM_TOSERVER) ? 0 : 1];
1428 active_id =
MIN(log_id, inspect_id);
1430 active_id = inspect_id;
1479 if ((
flags & (STREAM_EOF|STREAM_TOSERVER)) == (STREAM_EOF|STREAM_TOSERVER)) {
1480 SCLogDebug(
"setting APP_LAYER_PARSER_EOF_TS");
1482 }
else if ((
flags & (STREAM_EOF|STREAM_TOCLIENT)) == (STREAM_EOF|STREAM_TOCLIENT)) {
1483 SCLogDebug(
"setting APP_LAYER_PARSER_EOF_TC");
1492 static void HandleStreamFrames(
Flow *f,
StreamSlice stream_slice,
const uint8_t *input,
1493 const uint32_t input_len,
const uint8_t
flags)
1495 const uint8_t direction = (
flags & STREAM_TOSERVER) ? 0 : 1;
1499 if (((direction == 0 && (pstate->
flags & APP_LAYER_PARSER_SFRAME_TS) == 0) ||
1500 (direction == 1 && (pstate->
flags & APP_LAYER_PARSER_SFRAME_TC) == 0)) &&
1501 input != NULL && f->
proto == IPPROTO_TCP) {
1503 if (frame == NULL) {
1504 int64_t frame_len = -1;
1505 if (
flags & STREAM_EOF)
1506 frame_len = input_len;
1511 SCLogDebug(
"opened: frame %p id %" PRIi64, frame, frame->
id);
1516 if (direction == 0) {
1517 pstate->
flags |= APP_LAYER_PARSER_SFRAME_TS;
1519 pstate->
flags |= APP_LAYER_PARSER_SFRAME_TC;
1522 }
else if (
flags & STREAM_EOF) {
1527 int64_t slice_o = (int64_t)stream_slice.
offset - (int64_t)frame->
offset;
1528 int64_t frame_len = slice_o + (int64_t)input_len;
1529 SCLogDebug(
"%s: EOF frame->offset %" PRIu64
" -> %" PRIi64
": o %" PRIi64,
1531 frame->
len = frame_len;
1536 static void Setup(
Flow *f,
const uint8_t direction,
const uint8_t *input, uint32_t input_len,
1539 memset(as, 0,
sizeof(*as));
1555 uint8_t
flags,
const uint8_t *input, uint32_t input_len)
1558 #ifdef DEBUG_VALIDATION
1564 void *alstate = NULL;
1565 uint64_t p_tx_cnt = 0;
1566 uint32_t consumed = input_len;
1567 const uint8_t direction = (
flags & STREAM_TOSERVER) ? 0 : 1;
1570 if (
p->StateAlloc == NULL) {
1571 if (f->
proto == IPPROTO_TCP) {
1577 if (
flags & STREAM_GAP) {
1578 if (!(
p->option_flags & APP_LAYER_PARSER_OPT_ACCEPT_GAPS)) {
1579 SCLogDebug(
"app-layer parser does not accept gaps");
1589 if (pstate == NULL) {
1591 if (pstate == NULL) {
1597 SetEOFFlags(pstate,
flags);
1602 if (alstate == NULL) {
1606 SCLogDebug(
"alloced new app layer state %p (name %s)",
1614 SCLogDebug(
"state data: updating file_flags %04x with flow file_flags %04x",
1621 SCLogDebug(
"using existing app layer state %p (name %s))",
1628 if (input_len > 0 || (
flags & STREAM_EOF)) {
1629 Setup(f,
flags & (STREAM_TOSERVER | STREAM_TOCLIENT), input, input_len,
flags,
1631 HandleStreamFrames(f, stream_slice, input, input_len,
flags);
1633 #ifdef QA_SIMULATION
1634 if (((stream_slice.
flags & STREAM_TOSERVER) &&
1635 stream_slice.
offset >= g_eps_applayer_error_offset_ts)) {
1636 SCLogNotice(
"putting parser %s into an error state from toserver offset %" PRIu64,
1641 if (((stream_slice.
flags & STREAM_TOCLIENT) &&
1642 stream_slice.
offset >= g_eps_applayer_error_offset_tc)) {
1643 SCLogNotice(
"putting parser %s into an error state from toclient offset %" PRIu64,
1650 AppLayerResult res =
p->Parser[direction](f, alstate, pstate, stream_slice,
1655 }
else if (res.
status > 0) {
1672 (
flags & STREAM_TOSERVER) ?
"toserver" :
"toclient");
1673 if (direction == 0) {
1692 if (pstate->
flags & APP_LAYER_PARSER_NO_INSPECTION) {
1695 if (f->
proto == IPPROTO_TCP) {
1699 if (pstate->
flags & APP_LAYER_PARSER_NO_REASSEMBLY) {
1708 if (pstate->
flags & APP_LAYER_PARSER_BYPASS_READY) {
1717 FlowSetNoPayloadInspectionFlag(f);
1723 FlowSetNoPayloadInspectionFlag(f);
1725 if (f->
proto == IPPROTO_TCP) {
1737 if (cur_tx_cnt > p_tx_cnt &&
tv) {
1743 if (consumed != input_len && f->
proto == IPPROTO_TCP && f->
protoctx != NULL) {
1753 if (f->
proto == IPPROTO_TCP) {
1756 if (pstate != NULL) {
1766 SCLogDebug(
"setting APP_LAYER_PARSER_EOF_TC and APP_LAYER_PARSER_EOF_TS");
1776 if (pstate != NULL) {
1778 return (decoder_events && decoder_events->
cnt);
1801 int r = (!alp_ctx.
ctxs[alproto][ipproto_map].
logger) ? 0 : 1;
1818 if (f != NULL && f->
protoctx != NULL)
1844 if (state != NULL) {
1859 uint8_t ipproto,
AppProto alproto,
const char *
name,
const uint8_t direction)
1874 uint8_t ipproto,
AppProto alproto,
const int id,
const uint8_t direction)
1910 if (
ctx->StateFree != NULL && alstate != NULL)
1911 ctx->StateFree(alstate);
1925 static void ValidateParserProtoDump(
AppProto alproto, uint8_t ipproto)
1929 printf(
"ERROR: incomplete app-layer registration\n");
1930 printf(
"AppLayer protocol %s ipproto %u\n",
AppProtoToString(alproto), ipproto);
1931 printf(
"- option flags %"PRIx32
"\n",
ctx->option_flags);
1932 printf(
"- first_data_dir %"PRIx8
"\n",
ctx->first_data_dir);
1933 printf(
"Mandatory:\n");
1934 printf(
"- Parser[0] %p Parser[1] %p\n",
ctx->Parser[0],
ctx->Parser[1]);
1935 printf(
"- StateAlloc %p StateFree %p\n",
ctx->StateAlloc,
ctx->StateFree);
1936 printf(
"- StateGetTx %p StateGetTxCnt %p StateTransactionFree %p\n",
1937 ctx->StateGetTx,
ctx->StateGetTxCnt,
ctx->StateTransactionFree);
1938 printf(
"- GetTxData %p\n",
ctx->GetTxData);
1939 printf(
"- GetStateData %p\n",
ctx->GetStateData);
1940 printf(
"- StateGetProgress %p\n",
ctx->StateGetProgress);
1941 printf(
"Optional:\n");
1942 printf(
"- LocalStorageAlloc %p LocalStorageFree %p\n",
ctx->LocalStorageAlloc,
ctx->LocalStorageFree);
1943 printf(
"- StateGetEventInfo %p StateGetEventInfoById %p\n",
ctx->StateGetEventInfo,
1944 ctx->StateGetEventInfoById);
1947 #define BOTH_SET(a, b) ((a) != NULL && (b) != NULL)
1948 #define BOTH_SET_OR_BOTH_UNSET(a, b) (((a) == NULL && (b) == NULL) || ((a) != NULL && (b) != NULL))
1949 #define THREE_SET(a, b, c) ((a) != NULL && (b) != NULL && (c) != NULL)
1951 static void ValidateParserProto(
AppProto alproto, uint8_t ipproto)
1956 if (
ctx->Parser[0] == NULL &&
ctx->Parser[1] == NULL)
1968 if (
ctx->StateGetProgress == NULL) {
1975 if (
ctx->GetTxData == NULL) {
1978 if (
ctx->GetStateData == NULL) {
1983 ValidateParserProtoDump(alproto, ipproto);
1987 #undef BOTH_SET_OR_BOTH_UNSET
1990 static void ValidateParser(
AppProto alproto)
1992 ValidateParserProto(alproto, IPPROTO_TCP);
1993 ValidateParserProto(alproto, IPPROTO_UDP);
1996 static void ValidateParsers(
void)
2004 #define ARRAY_CAP_STEP 16
2005 static void (**PreRegisteredCallbacks)(void) = NULL;
2006 static size_t preregistered_callbacks_nb = 0;
2007 static size_t preregistered_callbacks_cap = 0;
2017 FatalError(
"Unable to realloc alp_ctx.ctxs.");
2029 if (preregistered_callbacks_nb == preregistered_callbacks_cap) {
2030 void *tmp =
SCRealloc(PreRegisteredCallbacks,
2031 sizeof(
void *) * (preregistered_callbacks_cap +
ARRAY_CAP_STEP));
2036 PreRegisteredCallbacks = tmp;
2038 PreRegisteredCallbacks[preregistered_callbacks_nb] = Register;
2039 preregistered_callbacks_nb++;
2051 SCRegisterDcerpcParser();
2052 SCRegisterDcerpcUdpParser();
2057 SCRegisterDnsUdpParser();
2058 SCRegisterDnsTcpParser();
2059 SCRegisterBittorrentDhtUdpParser();
2061 SCEnipRegisterParsers();
2065 SCRegisterNtpParser();
2068 SCRegisterKrb5Parser();
2069 SCRegisterDhcpParser();
2070 SCRegisterSnmpParser();
2071 SCRegisterSipParser();
2072 SCRegisterQuicParser();
2073 SCRegisterWebSocketParser();
2074 SCRegisterLdapTcpParser();
2075 SCRegisterLdapUdpParser();
2076 SCRegisterMdnsParser();
2077 SCRegisterTemplateParser();
2078 SCRfbRegisterParser();
2079 SCMqttRegisterParser();
2080 SCRegisterPgsqlParser();
2081 SCRegisterPop3Parser();
2082 SCRegisterRdpParser();
2084 SCRegisterTelnetParser();
2086 SCRegisterLLMNRUdpParser();
2087 SCRegisterLLMNRTcpParser();
2089 for (
size_t i = 0; i < preregistered_callbacks_nb; i++) {
2090 PreRegisteredCallbacks[i]();
2100 pstate->
flags |= flag;
2117 void (*RegisterUnittests)(
void))
2134 ctx = &alp_ctx.
ctxs[alproto][ip];
2135 if (
ctx->RegisterUnittests == NULL)
2137 ctx->RegisterUnittests();
#define AppLayerParserHasFilesInDir(txd, direction)
check if tx (possibly) has files in this tx for the direction
void AppLayerParserRegisterGetStateProgressFunc(uint8_t ipproto, AppProto alproto, int(*StateGetProgress)(void *alstate, uint8_t direction))
int AppLayerParserDeSetup(void)
AppLayerStateData *(* GetStateData)(void *state)
uint64_t(* StateGetTxCnt)(void *alstate)
enum ExceptionPolicy g_applayerparser_error_policy
uint16_t SCAppLayerParserStateIssetFlag(AppLayerParserState *pstate, uint16_t flag)
int SCConfValIsTrue(const char *val)
Check if a value is true.
AppLayerTxData *(* GetTxData)(void *tx)
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)
const char * AppLayerParserGetStateNameById(uint8_t ipproto, AppProto alproto, const int id, const uint8_t direction)
void FramesFree(Frames *frames)
void AppLayerParserSetStreamDepthFlag(uint8_t ipproto, AppProto alproto, void *state, uint64_t tx_id, uint8_t flags)
void AppLayerParserSetTransactionLogId(AppLayerParserState *pstate, uint64_t tx_id)
bool g_filedata_logger_enabled
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(* 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)
#define FLOW_SGH_TOCLIENT
void AppLayerParserSetTransactionInspectId(const Flow *f, AppLayerParserState *pstate, void *alstate, const uint8_t flags, bool tag_txs_as_inspected)
void SCAppLayerTxDataCleanup(AppLayerTxData *txd)
void(* ApplyTxConfig)(void *state, void *tx, int mode, AppLayerTxConfig)
AppLayerDecoderEvents * AppLayerParserGetEventsByTx(uint8_t ipproto, AppProto alproto, void *tx)
AppLayerGetTxIteratorFunc AppLayerGetTxIterator(const uint8_t ipproto, const AppProto alproto)
struct HtpBodyChunk_ * next
DetectEngineState * de_state
void RegisterModbusParsers(void)
Function to register the Modbus protocol parser.
uint8_t AppLayerParserGetTxDetectProgress(AppLayerTxData *txd, const uint8_t dir)
void StreamTcpSetDisableRawReassemblyFlag(TcpSession *, char)
Set the No reassembly flag for the given direction in given TCP session.
FramesContainer * AppLayerFramesSetupContainer(Flow *f)
uint8_t AppLayerParserGetStateProgressCompletionStatus(AppProto alproto, uint8_t direction)
void SCAppLayerParserStateSetFlag(AppLayerParserState *pstate, uint16_t flag)
uint32_t reassembly_depth
AppLayerParserGetStateNameByIdFn GetStateNameById
void AppLayerIncGapErrorCounter(ThreadVars *tv, Flow *f)
#define APP_LAYER_PARSER_INT_STREAM_DEPTH_SET
void SCAppLayerParserSetStreamDepth(uint8_t ipproto, AppProto alproto, uint32_t stream_depth)
uint64_t AppLayerParserGetTransactionLogId(AppLayerParserState *pstate)
const char * AppProtoToString(AppProto alproto)
Maps the ALPROTO_*, to its string equivalent.
bool AppLayerParserSupportsFiles(uint8_t ipproto, AppProto alproto)
void AppLayerParserRegisterStateProgressCompletionStatus(AppProto alproto, const int ts, const int tc)
uint8_t AppLayerParserGetFirstDataDir(uint8_t ipproto, AppProto alproto)
int8_t AppLayerParserGetSubStateProgressId(const AppProto alproto, const uint8_t sub_state, const char *state, const uint8_t dir_flag)
Translate name to progress value for a substate sub_state. Calls the registered callbacks.
int AppLayerParserProtoIsRegistered(uint8_t ipproto, AppProto alproto)
void AppLayerParserRegisterTxFreeFunc(uint8_t ipproto, AppProto alproto, void(*StateTransactionFree)(void *, uint64_t))
#define FLOW_NOPAYLOAD_INSPECTION
int AppLayerParserGetStateIdByName(uint8_t ipproto, AppProto alproto, const char *name, const uint8_t direction)
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 StreamTcpUpdateAppLayerProgress(TcpSession *ssn, char direction, const uint32_t progress)
update reassembly progress
void AppLayerParserRegisterGetStateFuncs(uint8_t ipproto, AppProto alproto, AppLayerParserGetStateIdByNameFn GetIdByNameFunc, AppLayerParserGetStateNameByIdFn GetNameByIdFunc)
int SCConfValIsFalse(const char *val)
Check if a value is false.
AppLayerStateData * AppLayerParserGetStateData(uint8_t ipproto, AppProto alproto, void *state)
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
Frame * AppLayerFrameGetLastOpenByType(Flow *f, const int dir, const uint8_t frame_type)
TcpStreamCnf stream_config
void AppLayerIncAllocErrorCounter(ThreadVars *tv, Flow *f)
@ EXCEPTION_POLICY_NOT_SET
enum ExceptionPolicy ExceptionPolicyParse(const char *option, bool support_flow)
void AppLayerParserRegisterUnittests(void)
uint64_t AppLayerParserGetTransactionInspectId(AppLayerParserState *pstate, uint8_t direction)
void AppLayerParserRegisterApplyTxConfigFunc(uint8_t ipproto, AppProto alproto, void(*ApplyTxConfig)(void *state, void *tx, int mode, AppLayerTxConfig))
uint8_t flags
STREAM_* flags.
Data structure to store app layer decoder events.
struct AppLayerTxConfig AppLayerTxConfig
uint8_t FlowGetReverseProtoMapping(uint8_t rproto)
void RegisterDNP3Parsers(void)
Register the DNP3 application protocol parser.
int(* StateGetEventInfoById)(uint8_t event_id, const char **event_name, AppLayerEventType *event_type)
void FTPParserCleanup(void)
Free memory allocated for global FTP parser state.
AppLayerGetFileState AppLayerParserGetTxFiles(const Flow *f, void *tx, const uint8_t direction)
const struct SigGroupHead_ * sgh_toserver
void StreamTcpReassembleTriggerRawInspection(TcpSession *ssn, int direction)
Trigger RAW stream inspection.
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 SCAppLayerParserTriggerRawStreamInspection(Flow *f, int direction)
struct AppLayerParserSubStateMapping * next
uint8_t AppLayerParserGetSubStateCompletion(const AppProto alproto, const uint8_t sub_state)
int AppLayerParserGetEventInfoById(uint8_t ipproto, AppProto alproto, uint8_t event_id, const char **event_name, AppLayerEventType *event_type)
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)
int SCAppLayerParserConfParserEnabled(const char *ipproto, const char *alproto_name)
check if a parser is enabled in the config Returns enabled always if: were running unittests
void AppLayerFramesFreeContainer(Flow *f)
void SCAppLayerParserRegisterLogger(uint8_t ipproto, AppProto alproto)
void AppLayerIncTxCounter(ThreadVars *tv, Flow *f, int64_t step)
void *(* alproto_local_storage)[FLOW_PROTO_MAX]
struct AppLayerGetFileState AppLayerGetFileState
int(* StateGetEventInfo)(const char *event_name, uint8_t *event_id, AppLayerEventType *event_type)
AppLayerParserThreadCtx * alp_tctx
void SCDetectEngineStateFree(DetectEngineState *state)
Frees a DetectEngineState object.
void AppLayerParserRegisterGetFrameFuncs(uint8_t ipproto, AppProto alproto, AppLayerParserGetFrameIdByNameFn GetIdByNameFunc, AppLayerParserGetFrameNameByIdFn GetNameByIdFunc)
void(* SetStreamDepthFlag)(void *tx, uint8_t flags)
FramesContainer * AppLayerFramesGetContainer(const Flow *f)
Per thread variable structure.
void AppLayerParserRegisterLoggerBits(uint8_t ipproto, AppProto alproto, LoggerId bits)
void AppLayerParserRegisterStateFuncs(uint8_t ipproto, AppProto alproto, void *(*StateAlloc)(void *, AppProto), void(*StateFree)(void *))
AppLayerParserGetStateIdByNameFn GetStateIdByName
#define IS_DISRUPTED(flags)
void AppLayerParserSetEOF(AppLayerParserState *pstate)
void(* RegisterUnittests)(void)
void AppLayerParserStateFree(AppLayerParserState *pstate)
void AppLayerParserStateCleanup(const Flow *f, void *alstate, AppLayerParserState *pstate)
int AppLayerParserGetStateProgress(uint8_t ipproto, AppProto alproto, void *tx, uint8_t flags)
get the progress value for a tx/protocol
const struct SigGroupHead_ * sgh_toclient
void RegisterNFSTCPParsers(void)
void AppLayerParserRegisterGetEventInfo(uint8_t ipproto, AppProto alproto, int(*StateGetEventInfo)(const char *event_name, uint8_t *event_id, AppLayerEventType *event_type))
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 DEBUG_ASSERT_FLOW_LOCKED(f)
void SCAppLayerParserRegisterGetTxSubStateFuncs(AppProto alproto, const uint8_t sub_state, AppLayerParserGetStateIdByNameFn GetIdByNameFunc, AppLayerParserGetStateNameByIdFn GetNameByIdFunc)
register state<>name funcs for a substate
#define BOTH_SET_OR_BOTH_UNSET(a, b)
#define SCReturnPtr(x, type)
void(* StateFree)(void *)
void AppLayerParserRegisterGetTxFilesFunc(uint8_t ipproto, AppProto alproto, AppLayerGetFileState(*GetTxFiles)(void *, uint8_t))
void AppLayerParserRegisterSetStreamDepthFlag(uint8_t ipproto, AppProto alproto, void(*SetStreamDepthFlag)(void *tx, uint8_t flags))
void AppLayerIncParserErrorCounter(ThreadVars *tv, Flow *f)
uint8_t detect_progress_ts
uint32_t logged
logger flags for tx logging api
int RunmodeIsUnittests(void)
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.
#define SCRealloc(ptr, sz)
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))
enum ExceptionPolicy AppLayerErrorGetExceptionPolicy(void)
AppLayerParserFPtr Parser[2]
#define APP_LAYER_MAX_PROGRESS
void(* StateTransactionFree)(void *, uint64_t)
int AppLayerParserPreRegister(void(*Register)(void))
void RegisterSSLParsers(void)
Function to register the SSL protocol parser and other functions.
void StreamTcpSetSessionNoReassemblyFlag(TcpSession *, char)
disable reassembly
void SCGenericVarFree(GenericVar *gv)
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)
AppLayerParserProtoCtx(* ctxs)[FLOW_PROTO_MAX]
int AppLayerParserGetFrameIdByName(uint8_t ipproto, AppProto alproto, const char *name)
void SCAppLayerParserRegisterParserAcceptableDataDirection(uint8_t ipproto, AppProto alproto, uint8_t direction)
uint32_t files_opened
track file open/logs so we can know how long to keep the tx
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)
const char *(* AppLayerParserGetStateNameByIdFn)(const int id, const uint8_t direction)
const char * AppLayerParserGetSubStateProgressName(const AppProto alproto, const uint8_t sub_state, const uint8_t state, const uint8_t dir_flag)
AppLayerTxData * AppLayerParserGetTxData(uint8_t ipproto, AppProto alproto, void *tx)
void AppLayerParserRegisterTxDataFunc(uint8_t ipproto, AppProto alproto, AppLayerTxData *(*GetTxData)(void *tx))
uint8_t tx_type_eop_tc
toclient end of tx progress value
uint8_t detect_progress_tc
void SCAppLayerDecoderEventsFreeEvents(AppLayerDecoderEvents **events)
uint32_t AppLayerParserGetStreamDepth(const Flow *f)
void RegisterIMAPParsers(void)
AppLayerGetFileState(* GetTxFiles)(void *, uint8_t)
AppLayerParserGetStateIdByNameFn GetStateIdByName
const StreamingBufferConfig * cfg
#define FRAME_STREAM_TYPE
#define APP_LAYER_TX_INSPECTED_TS
void AppLayerParserRegisterGetTxIterator(uint8_t ipproto, AppProto alproto, AppLayerGetTxIteratorFunc Func)
SCConfNode * SCConfGetNode(const char *name)
Get a SCConfNode by name.
#define FLOW_SGH_TOSERVER
const char * AppLayerParserGetSubStateName(const AppProto alproto, const uint8_t sub_state)
void AppLayerParserPostStreamSetup(void)
AppLayerDecoderEvents * AppLayerParserGetDecoderEvents(AppLayerParserState *pstate)
#define THREE_SET(a, b, c)
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)
void RegisterHTPParsers(void)
Register the HTTP protocol and state handling functions to APP layer of the engine.
int(* AppLayerParserGetStateIdByNameFn)(const char *name, const uint8_t direction)
#define FRAME_FLAG_ENDS_AT_EOF
void RegisterSMTPParsers(void)
Register the SMTP Protocol parser.
AppLayerParserState * AppLayerParserStateAlloc(void)
#define SCReturnCT(x, type)
AppLayerDecoderEvents * decoder_events
void AppLayerParserRegisterGetTxCnt(uint8_t ipproto, AppProto alproto, uint64_t(*StateGetTxCnt)(void *alstate))
int(* StateGetProgress)(void *alstate, uint8_t direction)
uint8_t AppLayerParserGetMaxSubState(const AppProto alproto)
LoggerId AppLayerParserProtocolGetLoggerBits(uint8_t ipproto, AppProto alproto)
AppLayerDecoderEvents * events
void AppLayerParserRegisterGetEventInfoById(uint8_t ipproto, AppProto alproto, int(*StateGetEventInfoById)(uint8_t event_id, const char **event_name, AppLayerEventType *event_type))
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
void RegisterHTTP2Parsers(void)
bool AppLayerParserSupportsSubStates(const AppProto alproto)
#define STREAM_APP_PROGRESS(stream)
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
struct AppLayerParserSubStateMapping * sub_state_mappings
int SCAppLayerParserReallocCtx(AppProto alproto)
#define SCLogNotice(...)
Macro used to log NOTICE messages.
void RegisterNFSUDPParsers(void)
uint64_t AppLayerParserGetMinId(AppLayerParserState *pstate)
AppProto alproto
application level protocol
void AppLayerParserDestroyProtocolParserLocalStorage(uint8_t ipproto, AppProto alproto, void *local_data)
uint64_t AppLayerParserGetTxCnt(const Flow *f, void *alstate)
void SMTPParserCleanup(void)
Free memory allocated for global SMTP parser state.
bool AppLayerParserHasDecoderEvents(AppLayerParserState *pstate)
int(* AppLayerParserGetFrameIdByNameFn)(const char *frame_name)
void StreamTcpSetSessionBypassFlag(TcpSession *)
enable bypass
#define DEBUG_VALIDATE_BUG_ON(exp)
#define APP_LAYER_TX_INSPECTED_TC
void *(* LocalStorageAlloc)(void)
int AppLayerParserGetEventInfo(uint8_t ipproto, AppProto alproto, const char *event_name, uint8_t *event_id, AppLayerEventType *event_type)
AppLayerParserGetStateNameByIdFn GetStateNameById