Go to the documentation of this file.
85 void *(*LocalStorageAlloc)(void);
94 void *(*StateGetTx)(
void *alstate, uint64_t tx_id);
157 static void AppLayerConfig(
void)
169 if (frames != NULL) {
186 if (f == NULL || f->
alparser == NULL)
232 return (alp_ctx.
ctxs[alproto][ipproto_map].
StateAlloc != NULL) ? 1 : 0;
253 AppLayerParserFramesFreeContainer(pstate->
frames);
351 bool g_enabled =
false;
352 bool i_enabled =
false;
358 r = snprintf(param,
sizeof(param),
"%s%s%s%s%s",
"app-layer.protocols.", alproto_name,
".",
359 ipproto,
".enabled");
362 }
else if (r > (
int)
sizeof(param)) {
363 FatalError(
"buffer not big enough to write param.");
368 if (i_proto && i_proto->
val) {
373 }
else if (strcasecmp(i_proto->
val,
"detection-only") == 0) {
376 FatalError(
"Invalid value found for %s.", param);
380 r = snprintf(param,
sizeof(param),
"%s%s%s",
"app-layer.protocols.", alproto_name,
".enabled");
383 }
else if (r > (
int)
sizeof(param)) {
384 FatalError(
"buffer not big enough to write param.");
389 if (g_proto && g_proto->
val) {
394 }
else if (strcasecmp(g_proto->
val,
"detection-only") == 0) {
397 FatalError(
"Invalid value found for %s", param);
401 if ((i_proto && g_proto) && (i_enabled ^ g_enabled)) {
403 SCLogDebug(
"Inconsistent global (%s) and respective ipproto (%s) settings found for "
404 "alproto %s and ipproto %s",
405 g_enabled ?
"TRUE" :
"FALSE", i_enabled ?
"TRUE" :
"FALSE", alproto_name, ipproto);
427 .
Parser[(direction & STREAM_TOSERVER) ? 0 : 1] = Parser;
433 uint8_t ipproto,
AppProto alproto, uint8_t direction)
438 (direction & (STREAM_TOSERVER | STREAM_TOCLIENT));
454 void *(*StateAlloc)(
void *,
AppProto),
void (*StateFree)(
void *))
465 void *(*LocalStorageAlloc)(
void),
466 void (*LocalStorageFree)(
void *))
505 int (*StateGetProgress)(
void *alstate, uint8_t direction))
515 void (*StateTransactionFree)(
void *, uint64_t))
525 uint64_t (*StateGetTxCnt)(
void *alstate))
535 void *(StateGetTx)(
void *alstate, uint64_t tx_id))
557 BUG_ON(!AppProtoIsValid(alproto));
568 int (*StateGetEventInfoById)(
574 StateGetEventInfoById;
600 int (*StateGetEventInfo)(
641 void (*SetStreamDepthFlag)(
void *tx, uint8_t
flags))
685 const uint8_t ipproto,
const AppProto alproto,
686 void *alstate, uint64_t min_tx_id, uint64_t max_tx_id,
689 uint64_t ustate = *(uint64_t *)state;
690 uint64_t tx_id =
MAX(min_tx_id, ustate);
691 for ( ; tx_id < max_tx_id; tx_id++) {
693 if (tx_ptr != NULL) {
699 .has_next = (tx_id + 1 < max_tx_id),
716 return Func ? Func : AppLayerDefaultGetTxIterator;
779 void *alstate,
const uint8_t
flags,
780 bool tag_txs_as_inspected)
784 const int direction = (
flags & STREAM_TOSERVER) ? 0 : 1;
788 const uint8_t ipproto = f->
proto;
794 SCLogDebug(
"called: %s, tag_txs_as_inspected %s",direction==0?
"toserver":
"toclient",
795 tag_txs_as_inspected?
"true":
"false");
808 if (state_progress < state_done_progress)
812 if (tag_txs_as_inspected) {
815 if (txd->
flags & inspected_flag) {
816 txd->
flags |= inspected_flag;
817 SCLogDebug(
"%p/%" PRIu64
" in-order tx is done for direction %s. Flags %02x", tx,
818 idx,
flags & STREAM_TOSERVER ?
"toserver" :
"toclient", txd->
flags);
830 if (tag_txs_as_inspected) {
847 if (state_progress < state_done_progress)
854 if (txd->
flags & inspected_flag) {
855 txd->
flags |= inspected_flag;
856 SCLogDebug(
"%p/%" PRIu64
" out of order tx is done for direction %s. Flag %02x", tx,
857 idx,
flags & STREAM_TOSERVER ?
"toserver" :
"toclient", txd->
flags);
859 SCLogDebug(
"%p/%" PRIu64
" out of order tx. Update inspect_id? %" PRIu64, tx, idx,
878 "AppLayerDecoderEvents *");
890 if (txd->
events != NULL) {
909 static void AppLayerParserFileTxHousekeeping(
910 const Flow *f,
void *tx,
const uint8_t pkt_dir,
const bool trunc)
918 #define IS_DISRUPTED(flags) ((flags) & (STREAM_DEPTH | STREAM_GAP))
933 if (
unlikely(
p->StateTransactionFree == NULL))
937 const uint8_t ipproto = f->
proto;
939 void *
const alstate = f->
alstate;
942 if (alstate == NULL || alparser == NULL)
945 const uint64_t min = alparser->
min_id;
953 int pkt_dir_trunc = -1;
957 memset(&state, 0,
sizeof(state));
959 uint64_t new_min = min;
961 bool skipped =
false;
969 bool tx_skipped =
false;
976 if (pkt_dir_trunc == -1)
978 (pkt_dir == STREAM_TOSERVER) ? ts_disrupt_flags : tc_disrupt_flags);
979 AppLayerParserFileTxHousekeeping(f, tx, pkt_dir, (
bool)pkt_dir_trunc);
982 if (pkt_dir & STREAM_TOSERVER) {
987 const int tx_progress_tc =
989 if (tx_progress_tc < tx_end_state_tc) {
990 SCLogDebug(
"%p/%"PRIu64
" skipping: tc parser not done", tx, i);
994 const int tx_progress_ts =
996 if (tx_progress_ts < tx_end_state_ts) {
997 SCLogDebug(
"%p/%"PRIu64
" skipping: ts parser not done", tx, i);
1008 SCLogDebug(
"%p/%" PRIu64
" skipping: TS inspect not done: ts:%02x", tx, i,
1017 SCLogDebug(
"%p/%" PRIu64
" skipping: TC inspect not done: ts:%02x", tx, i,
1025 SCLogDebug(
"%p/%" PRIu64
" tx_skipped", tx, i);
1030 if (logger_expectation != 0) {
1031 LoggerId tx_logged = GetTxLogged(txd);
1032 if (tx_logged != logger_expectation) {
1033 SCLogDebug(
"%p/%"PRIu64
" skipping: logging not done: want:%"PRIx32
", have:%"PRIx32,
1034 tx, i, logger_expectation, tx_logged);
1057 p->StateTransactionFree(alstate, i);
1061 SCLogDebug(
"skipped? %s i %"PRIu64
", new_min %"PRIu64, skipped ?
"true" :
"false", i, new_min);
1064 SCLogDebug(
"final i %"PRIu64
", new_min %"PRIu64, i, new_min);
1071 SCLogDebug(
"no next: cur tx i %"PRIu64
", total %"PRIu64, i, total_txs);
1073 new_min = total_txs;
1074 SCLogDebug(
"no next: cur tx i %"PRIu64
", total %"PRIu64
": "
1075 "new_min updated to %"PRIu64, i, total_txs, new_min);
1083 SCLogDebug(
"update f->alparser->min_id? %"PRIu64
" vs %"PRIu64, new_min, alparser->
min_id);
1084 if (new_min > alparser->
min_id) {
1085 const uint64_t next_id = new_min;
1086 alparser->
min_id = next_id;
1095 static inline int StateGetProgressCompletionStatus(
const AppProto alproto,
const uint8_t
flags)
1097 if (
flags & STREAM_TOSERVER) {
1099 }
else if (
flags & STREAM_TOCLIENT) {
1113 void *alstate, uint8_t
flags)
1118 r = StateGetProgressCompletionStatus(alproto,
flags);
1120 uint8_t direction =
flags & (STREAM_TOCLIENT | STREAM_TOSERVER);
1122 alstate, direction);
1145 int r = StateGetProgressCompletionStatus(alproto, direction);
1157 event_name, event_id, event_type);
1166 *event_name = (
const char *)NULL;
1170 event_id, event_name, event_type);
1241 if ((
flags & (STREAM_EOF|STREAM_TOSERVER)) == (STREAM_EOF|STREAM_TOSERVER)) {
1242 SCLogDebug(
"setting APP_LAYER_PARSER_EOF_TS");
1244 }
else if ((
flags & (STREAM_EOF|STREAM_TOCLIENT)) == (STREAM_EOF|STREAM_TOCLIENT)) {
1245 SCLogDebug(
"setting APP_LAYER_PARSER_EOF_TC");
1254 static void HandleStreamFrames(
Flow *f,
StreamSlice stream_slice,
const uint8_t *input,
1255 const uint32_t input_len,
const uint8_t
flags)
1257 const uint8_t direction = (
flags & STREAM_TOSERVER) ? 0 : 1;
1261 if (((direction == 0 && (pstate->
flags & APP_LAYER_PARSER_SFRAME_TS) == 0) ||
1262 (direction == 1 && (pstate->
flags & APP_LAYER_PARSER_SFRAME_TC) == 0)) &&
1263 input != NULL && f->
proto == IPPROTO_TCP) {
1265 if (frame == NULL) {
1266 int64_t frame_len = -1;
1267 if (
flags & STREAM_EOF)
1268 frame_len = input_len;
1273 SCLogDebug(
"opened: frame %p id %" PRIi64, frame, frame->
id);
1278 if (direction == 0) {
1279 pstate->
flags |= APP_LAYER_PARSER_SFRAME_TS;
1281 pstate->
flags |= APP_LAYER_PARSER_SFRAME_TC;
1284 }
else if (
flags & STREAM_EOF) {
1289 int64_t slice_o = (int64_t)stream_slice.
offset - (int64_t)frame->
offset;
1290 int64_t frame_len = slice_o + (int64_t)input_len;
1291 SCLogDebug(
"%s: EOF frame->offset %" PRIu64
" -> %" PRIi64
": o %" PRIi64,
1293 frame->
len = frame_len;
1298 static void Setup(
Flow *f,
const uint8_t direction,
const uint8_t *input, uint32_t input_len,
1301 memset(as, 0,
sizeof(*as));
1317 uint8_t
flags,
const uint8_t *input, uint32_t input_len)
1320 #ifdef DEBUG_VALIDATION
1326 void *alstate = NULL;
1327 uint64_t p_tx_cnt = 0;
1328 uint32_t consumed = input_len;
1329 const uint8_t direction = (
flags & STREAM_TOSERVER) ? 0 : 1;
1332 if (
p->StateAlloc == NULL) {
1333 if (f->
proto == IPPROTO_TCP) {
1339 if (
flags & STREAM_GAP) {
1340 if (!(
p->option_flags & APP_LAYER_PARSER_OPT_ACCEPT_GAPS)) {
1341 SCLogDebug(
"app-layer parser does not accept gaps");
1351 if (pstate == NULL) {
1353 if (pstate == NULL) {
1359 SetEOFFlags(pstate,
flags);
1364 if (alstate == NULL) {
1368 SCLogDebug(
"alloced new app layer state %p (name %s)",
1376 SCLogDebug(
"state data: updating file_flags %04x with flow file_flags %04x",
1383 SCLogDebug(
"using existing app layer state %p (name %s))",
1390 if (input_len > 0 || (
flags & STREAM_EOF)) {
1391 Setup(f,
flags & (STREAM_TOSERVER | STREAM_TOCLIENT), input, input_len,
flags,
1393 HandleStreamFrames(f, stream_slice, input, input_len,
flags);
1395 #ifdef QA_SIMULATION
1396 if (((stream_slice.
flags & STREAM_TOSERVER) &&
1397 stream_slice.
offset >= g_eps_applayer_error_offset_ts)) {
1398 SCLogNotice(
"putting parser %s into an error state from toserver offset %" PRIu64,
1403 if (((stream_slice.
flags & STREAM_TOCLIENT) &&
1404 stream_slice.
offset >= g_eps_applayer_error_offset_tc)) {
1405 SCLogNotice(
"putting parser %s into an error state from toclient offset %" PRIu64,
1412 AppLayerResult res =
p->Parser[direction](f, alstate, pstate, stream_slice,
1417 }
else if (res.
status > 0) {
1434 (
flags & STREAM_TOSERVER) ?
"toserver" :
"toclient");
1435 if (direction == 0) {
1454 if (pstate->
flags & APP_LAYER_PARSER_NO_INSPECTION) {
1457 if (f->
proto == IPPROTO_TCP) {
1461 if (pstate->
flags & APP_LAYER_PARSER_NO_REASSEMBLY) {
1470 if (pstate->
flags & APP_LAYER_PARSER_BYPASS_READY) {
1479 FlowSetNoPayloadInspectionFlag(f);
1485 FlowSetNoPayloadInspectionFlag(f);
1487 if (f->
proto == IPPROTO_TCP) {
1499 if (cur_tx_cnt > p_tx_cnt &&
tv) {
1505 if (consumed != input_len && f->
proto == IPPROTO_TCP && f->
protoctx != NULL) {
1515 if (f->
proto == IPPROTO_TCP) {
1529 SCLogDebug(
"setting APP_LAYER_PARSER_EOF_TC and APP_LAYER_PARSER_EOF_TS");
1570 int r = (!alp_ctx.
ctxs[alproto][ipproto_map].
logger) ? 0 : 1;
1587 if (f != NULL && f->
protoctx != NULL)
1613 if (state != NULL) {
1628 uint8_t ipproto,
AppProto alproto,
const char *
name,
const uint8_t direction)
1643 uint8_t ipproto,
AppProto alproto,
const int id,
const uint8_t direction)
1679 if (
ctx->StateFree != NULL && alstate != NULL)
1680 ctx->StateFree(alstate);
1694 static void ValidateParserProtoDump(
AppProto alproto, uint8_t ipproto)
1698 printf(
"ERROR: incomplete app-layer registration\n");
1699 printf(
"AppLayer protocol %s ipproto %u\n",
AppProtoToString(alproto), ipproto);
1700 printf(
"- option flags %"PRIx32
"\n",
ctx->option_flags);
1701 printf(
"- first_data_dir %"PRIx8
"\n",
ctx->first_data_dir);
1702 printf(
"Mandatory:\n");
1703 printf(
"- Parser[0] %p Parser[1] %p\n",
ctx->Parser[0],
ctx->Parser[1]);
1704 printf(
"- StateAlloc %p StateFree %p\n",
ctx->StateAlloc,
ctx->StateFree);
1705 printf(
"- StateGetTx %p StateGetTxCnt %p StateTransactionFree %p\n",
1706 ctx->StateGetTx,
ctx->StateGetTxCnt,
ctx->StateTransactionFree);
1707 printf(
"- GetTxData %p\n",
ctx->GetTxData);
1708 printf(
"- GetStateData %p\n",
ctx->GetStateData);
1709 printf(
"- StateGetProgress %p\n",
ctx->StateGetProgress);
1710 printf(
"Optional:\n");
1711 printf(
"- LocalStorageAlloc %p LocalStorageFree %p\n",
ctx->LocalStorageAlloc,
ctx->LocalStorageFree);
1712 printf(
"- StateGetEventInfo %p StateGetEventInfoById %p\n",
ctx->StateGetEventInfo,
1713 ctx->StateGetEventInfoById);
1716 #define BOTH_SET(a, b) ((a) != NULL && (b) != NULL)
1717 #define BOTH_SET_OR_BOTH_UNSET(a, b) (((a) == NULL && (b) == NULL) || ((a) != NULL && (b) != NULL))
1718 #define THREE_SET(a, b, c) ((a) != NULL && (b) != NULL && (c) != NULL)
1720 static void ValidateParserProto(
AppProto alproto, uint8_t ipproto)
1725 if (
ctx->Parser[0] == NULL &&
ctx->Parser[1] == NULL)
1737 if (
ctx->StateGetProgress == NULL) {
1744 if (
ctx->GetTxData == NULL) {
1747 if (
ctx->GetStateData == NULL) {
1752 ValidateParserProtoDump(alproto, ipproto);
1756 #undef BOTH_SET_OR_BOTH_UNSET
1759 static void ValidateParser(
AppProto alproto)
1761 ValidateParserProto(alproto, IPPROTO_TCP);
1762 ValidateParserProto(alproto, IPPROTO_UDP);
1765 static void ValidateParsers(
void)
1773 #define ARRAY_CAP_STEP 16
1774 static void (**PreRegisteredCallbacks)(void) = NULL;
1775 static size_t preregistered_callbacks_nb = 0;
1776 static size_t preregistered_callbacks_cap = 0;
1786 FatalError(
"Unable to realloc alp_ctx.ctxs.");
1798 if (preregistered_callbacks_nb == preregistered_callbacks_cap) {
1799 void *tmp =
SCRealloc(PreRegisteredCallbacks,
1800 sizeof(
void *) * (preregistered_callbacks_cap +
ARRAY_CAP_STEP));
1805 PreRegisteredCallbacks = tmp;
1807 PreRegisteredCallbacks[preregistered_callbacks_nb] = Register;
1808 preregistered_callbacks_nb++;
1820 SCRegisterDcerpcParser();
1821 SCRegisterDcerpcUdpParser();
1826 SCRegisterDnsUdpParser();
1827 SCRegisterDnsTcpParser();
1828 SCRegisterBittorrentDhtUdpParser();
1830 SCEnipRegisterParsers();
1834 SCRegisterNtpParser();
1837 SCRegisterKrb5Parser();
1838 SCRegisterDhcpParser();
1839 SCRegisterSnmpParser();
1840 SCRegisterSipParser();
1841 SCRegisterQuicParser();
1842 SCRegisterWebSocketParser();
1843 SCRegisterLdapTcpParser();
1844 SCRegisterLdapUdpParser();
1845 SCRegisterMdnsParser();
1846 SCRegisterTemplateParser();
1847 SCRfbRegisterParser();
1848 SCMqttRegisterParser();
1849 SCRegisterPgsqlParser();
1850 SCRegisterPop3Parser();
1851 SCRegisterRdpParser();
1853 SCRegisterTelnetParser();
1855 SCRegisterLLMNRUdpParser();
1856 SCRegisterLLMNRTcpParser();
1858 for (
size_t i = 0; i < preregistered_callbacks_nb; i++) {
1859 PreRegisteredCallbacks[i]();
1869 pstate->
flags |= flag;
1886 void (*RegisterUnittests)(
void))
1903 ctx = &alp_ctx.
ctxs[alproto][ip];
1904 if (
ctx->RegisterUnittests == NULL)
1906 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)
int AppLayerParserGetStateProgress(uint8_t ipproto, AppProto alproto, void *alstate, uint8_t flags)
get the progress value for a tx/protocol
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)
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 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)
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 *))
#define IS_DISRUPTED(flags)
void AppLayerParserSetEOF(AppLayerParserState *pstate)
void(* RegisterUnittests)(void)
void AppLayerParserStateFree(AppLayerParserState *pstate)
void AppLayerParserStateCleanup(const Flow *f, void *alstate, AppLayerParserState *pstate)
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)
#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]
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)
AppLayerTxData * AppLayerParserGetTxData(uint8_t ipproto, AppProto alproto, void *tx)
void AppLayerParserRegisterTxDataFunc(uint8_t ipproto, AppProto alproto, AppLayerTxData *(*GetTxData)(void *tx))
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
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)
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)
#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
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)