Go to the documentation of this file.
25 #ifndef SURICATA_APP_LAYER_PARSER_H
26 #define SURICATA_APP_LAYER_PARSER_H
35 #define APP_LAYER_PARSER_NO_INSPECTION BIT_U16(1)
36 #define APP_LAYER_PARSER_NO_REASSEMBLY BIT_U16(2)
37 #define APP_LAYER_PARSER_NO_INSPECTION_PAYLOAD BIT_U16(3)
38 #define APP_LAYER_PARSER_BYPASS_READY BIT_U16(4)
39 #define APP_LAYER_PARSER_EOF_TS BIT_U16(5)
40 #define APP_LAYER_PARSER_EOF_TC BIT_U16(6)
42 #define APP_LAYER_PARSER_SFRAME_TS BIT_U16(9)
43 #define APP_LAYER_PARSER_SFRAME_TC BIT_U16(10)
46 #define APP_LAYER_PARSER_OPT_ACCEPT_GAPS BIT_U32(0)
48 #define APP_LAYER_PARSER_INT_STREAM_DEPTH_SET BIT_U32(0)
53 #define APP_LAYER_TX_RESERVED1_FLAG BIT_U64(48)
54 #define APP_LAYER_TX_RESERVED2_FLAG BIT_U64(49)
55 #define APP_LAYER_TX_RESERVED3_FLAG BIT_U64(50)
56 #define APP_LAYER_TX_RESERVED4_FLAG BIT_U64(51)
57 #define APP_LAYER_TX_RESERVED5_FLAG BIT_U64(52)
58 #define APP_LAYER_TX_RESERVED6_FLAG BIT_U64(53)
59 #define APP_LAYER_TX_RESERVED7_FLAG BIT_U64(54)
60 #define APP_LAYER_TX_RESERVED8_FLAG BIT_U64(55)
61 #define APP_LAYER_TX_RESERVED9_FLAG BIT_U64(56)
62 #define APP_LAYER_TX_RESERVED10_FLAG BIT_U64(57)
63 #define APP_LAYER_TX_RESERVED11_FLAG BIT_U64(58)
64 #define APP_LAYER_TX_RESERVED12_FLAG BIT_U64(59)
65 #define APP_LAYER_TX_RESERVED13_FLAG BIT_U64(60)
66 #define APP_LAYER_TX_RESERVED14_FLAG BIT_U64(61)
68 #define APP_LAYER_TX_RESERVED_FLAGS \
69 (APP_LAYER_TX_RESERVED1_FLAG | APP_LAYER_TX_RESERVED2_FLAG | APP_LAYER_TX_RESERVED3_FLAG | \
70 APP_LAYER_TX_RESERVED4_FLAG | APP_LAYER_TX_RESERVED5_FLAG | \
71 APP_LAYER_TX_RESERVED6_FLAG | APP_LAYER_TX_RESERVED7_FLAG | \
72 APP_LAYER_TX_RESERVED8_FLAG | APP_LAYER_TX_RESERVED9_FLAG | \
73 APP_LAYER_TX_RESERVED10_FLAG | APP_LAYER_TX_RESERVED11_FLAG | \
74 APP_LAYER_TX_RESERVED12_FLAG | APP_LAYER_TX_RESERVED13_FLAG | \
75 APP_LAYER_TX_RESERVED14_FLAG)
78 #define APP_LAYER_TX_SKIP_INSPECT_FLAG BIT_U64(62)
80 #define APP_LAYER_TX_INSPECTED_FLAG BIT_U64(63)
83 #define APP_LAYER_TX_PREFILTER_MASK ~(APP_LAYER_TX_INSPECTED_FLAG | APP_LAYER_TX_RESERVED_FLAGS)
87 #define APP_LAYER_OK (AppLayerResult) { 0, 0, 0 }
91 #define APP_LAYER_ERROR (AppLayerResult) { -1, 0, 0 }
99 #define APP_LAYER_INCOMPLETE(c,n) (AppLayerResult) { 1, (c), (n) }
137 const char *alproto_name);
152 (
const uint8_t ipproto,
const AppProto alproto,
153 void *alstate, uint64_t min_tx_id, uint64_t max_tx_id,
159 typedef const char *(*AppLayerParserGetFrameNameByIdFn)(
const uint8_t id);
176 void *(*StateAlloc)(
void *,
AppProto),
void (*StateFree)(
void *));
178 void *(*LocalStorageAlloc)(
void),
void (*LocalStorageFree)(
void *));
182 uint8_t ipproto,
AppProto alproto, AppLayerGetFileState (*GetTxFiles)(
void *, uint8_t));
186 int (*StateGetStateProgress)(
void *alstate, uint8_t direction));
188 void (*StateTransactionFree)(
void *, uint64_t));
190 uint64_t (*StateGetTxCnt)(
void *alstate));
192 void *(StateGetTx)(
void *alstate, uint64_t tx_id));
196 AppProto alproto,
const int ts,
const int tc);
198 int (*StateGetEventInfo)(
199 const char *event_name, uint8_t *event_id, AppLayerEventType *event_type));
201 int (*StateGetEventInfoById)(
202 uint8_t event_id,
const char **event_name, AppLayerEventType *event_type));
207 void (*SetStreamDepthFlag)(
void *tx, uint8_t
flags));
212 bool (*ApplyTxConfig)(
void *state,
void *tx,
int mode, AppLayerTxConfig));
214 uint8_t ipproto,
AppProto alproto, AppLayerStateData *(*GetStateData)(
void *state));
231 void *alstate,
const uint8_t
flags,
bool tag_txs_as_inspected);
237 void *alstate, uint8_t direction);
242 uint8_t *event_id, AppLayerEventType *event_type);
244 const char **event_name, AppLayerEventType *event_type);
256 void *state,
void *tx,
enum ConfigAction mode, AppLayerTxConfig);
258 static inline bool AppLayerParserIsFileTx(
const AppLayerTxData *txd)
260 if (txd->file_tx != 0) {
266 static inline bool AppLayerParserIsFileTxInDir(
const AppLayerTxData *txd,
const uint8_t direction)
268 if ((txd->file_tx & direction) != 0) {
275 static inline bool AppLayerParserHasFilesInDir(
const AppLayerTxData *txd,
const uint8_t direction)
277 return (txd->files_opened && AppLayerParserIsFileTxInDir(txd, direction));
283 uint8_t
flags,
const uint8_t *input, uint32_t input_len);
316 void (*RegisterUnittests)(
void));
int AppLayerParserGetStateProgress(uint8_t ipproto, AppProto alproto, void *alstate, uint8_t direction)
get the progress value for a tx/protocol
void AppLayerParserThreadCtxFree(AppLayerParserThreadCtx *tctx)
Destroys the app layer parser thread context obtained using AppLayerParserThreadCtxAlloc().
void * AppLayerParserGetTx(uint8_t ipproto, AppProto alproto, void *alstate, uint64_t tx_id)
void AppLayerParserPostStreamSetup(void)
AppLayerDecoderEvents * AppLayerParserGetDecoderEvents(AppLayerParserState *pstate)
void AppLayerParserRegisterGetTx(uint8_t ipproto, AppProto alproto, void *(StateGetTx)(void *alstate, uint64_t tx_id))
void AppLayerParserRegisterLogger(uint8_t ipproto, AppProto alproto)
void AppLayerParserRegisterLoggerBits(uint8_t ipproto, AppProto alproto, LoggerId bits)
AppLayerParserState * AppLayerParserStateAlloc(void)
void AppLayerParserSetEOF(AppLayerParserState *pstate)
void AppLayerParserRegisterGetTxCnt(uint8_t ipproto, AppProto alproto, uint64_t(*StateGetTxCnt)(void *alstate))
void AppLayerParserRegisterGetFrameFuncs(uint8_t ipproto, AppProto alproto, AppLayerParserGetFrameIdByNameFn GetFrameIdByName, AppLayerParserGetFrameNameByIdFn GetFrameNameById)
uint32_t AppLayerParserGetStreamDepth(const Flow *f)
void AppLayerParserRegisterSetStreamDepthFlag(uint8_t ipproto, AppProto alproto, void(*SetStreamDepthFlag)(void *tx, uint8_t flags))
uint64_t AppLayerParserGetTxDetectFlags(AppLayerTxData *txd, const uint8_t dir)
void UTHAppLayerParserStateGetIds(void *ptr, uint64_t *i1, uint64_t *i2, uint64_t *log, uint64_t *min)
LoggerId AppLayerParserProtocolGetLoggerBits(uint8_t ipproto, AppProto alproto)
int AppLayerParserGetFrameIdByName(uint8_t ipproto, AppProto alproto, const char *name)
void AppLayerParserRegisterGetEventInfoById(uint8_t ipproto, AppProto alproto, int(*StateGetEventInfoById)(uint8_t event_id, const char **event_name, AppLayerEventType *event_type))
int AppLayerParserSetup(void)
void AppLayerParserRegisterProtocolUnittests(uint8_t ipproto, AppProto alproto, void(*RegisterUnittests)(void))
Data structure to store app layer decoder events.
void AppLayerParserSetStreamDepth(uint8_t ipproto, AppProto alproto, uint32_t stream_depth)
uint16_t AppLayerParserStateIssetFlag(AppLayerParserState *pstate, uint16_t flag)
void * AppLayerParserGetProtocolParserLocalStorage(uint8_t ipproto, AppProto alproto)
void AppLayerParserRegisterGetTxFilesFunc(uint8_t ipproto, AppProto alproto, AppLayerGetFileState(*GetTxFiles)(void *, uint8_t))
AppLayerResult(* AppLayerParserFPtr)(Flow *f, void *protocol_state, AppLayerParserState *pstate, StreamSlice stream_slice, void *local_storage)
Prototype for parsing functions.
void FileApplyTxFlags(const AppLayerTxData *txd, const uint8_t direction, File *file)
int AppLayerParserConfParserEnabled(const char *ipproto, const char *alproto_name)
Given a protocol name, checks if the parser is enabled in the conf file.
void AppLayerParserTriggerRawStreamReassembly(Flow *f, int direction)
uint64_t AppLayerParserGetTransactionLogId(AppLayerParserState *pstate)
void AppLayerParserRegisterLocalStorageFunc(uint8_t ipproto, AppProto proto, void *(*LocalStorageAlloc)(void), void(*LocalStorageFree)(void *))
void AppLayerParserStateSetFlag(AppLayerParserState *pstate, uint16_t flag)
void AppLayerParserRegisterStateProgressCompletionStatus(AppProto alproto, const int ts, const int tc)
int AppLayerParserProtoIsRegistered(uint8_t ipproto, AppProto alproto)
Per thread variable structure.
void AppLayerParserRegisterOptionFlags(uint8_t ipproto, AppProto alproto, uint32_t flags)
void AppLayerParserRegisterStateDataFunc(uint8_t ipproto, AppProto alproto, AppLayerStateData *(*GetStateData)(void *state))
AppLayerTxData * AppLayerParserGetTxData(uint8_t ipproto, AppProto alproto, void *tx)
void AppLayerParserRegisterTxDataFunc(uint8_t ipproto, AppProto alproto, AppLayerTxData *(*GetTxData)(void *tx))
void AppLayerParserTransactionsCleanup(Flow *f, const uint8_t pkt_dir)
remove obsolete (inspected and logged) transactions
void AppLayerParserDestroyProtocolParserLocalStorage(uint8_t ipproto, AppProto alproto, void *local_data)
uint64_t AppLayerParserGetTransactionInspectId(AppLayerParserState *pstate, uint8_t direction)
bool AppLayerParserHasDecoderEvents(AppLayerParserState *pstate)
void AppLayerParserSetTransactionInspectId(const Flow *f, AppLayerParserState *pstate, void *alstate, const uint8_t flags, bool tag_txs_as_inspected)
void AppLayerParserRegisterGetTxIterator(uint8_t ipproto, AppProto alproto, AppLayerGetTxIteratorFunc Func)
AppLayerGetTxIteratorFunc AppLayerGetTxIterator(const uint8_t ipproto, const AppProto alproto)
AppLayerGetFileState AppLayerParserGetTxFiles(const Flow *f, void *tx, const uint8_t direction)
int AppLayerParserGetEventInfo(uint8_t ipproto, AppProto alproto, const char *event_name, uint8_t *event_id, AppLayerEventType *event_type)
struct AppLayerGetTxIterState AppLayerGetTxIterState
void AppLayerParserRegisterTxFreeFunc(uint8_t ipproto, AppProto alproto, void(*StateTransactionFree)(void *, uint64_t))
int AppLayerParserDeSetup(void)
const char * AppLayerParserGetFrameNameById(uint8_t ipproto, AppProto alproto, const uint8_t id)
void AppLayerFramesFreeContainer(Flow *f)
struct AppLayerTxData AppLayerTxData
int AppLayerParserIsEnabled(AppProto alproto)
simple way to globally test if a alproto is registered and fully enabled in the configuration.
const char *(* AppLayerParserGetFrameNameByIdFn)(const uint8_t id)
AppLayerStateData * AppLayerParserGetStateData(uint8_t ipproto, AppProto alproto, void *state)
void AppLayerParserApplyTxConfig(uint8_t ipproto, AppProto alproto, void *state, void *tx, enum ConfigAction mode, AppLayerTxConfig)
void AppLayerParserSetTransactionLogId(AppLayerParserState *pstate, uint64_t tx_id)
void AppLayerParserRegisterStateFuncs(uint8_t ipproto, AppProto alproto, void *(*StateAlloc)(void *, AppProto), void(*StateFree)(void *))
void AppLayerParserRegisterUnittests(void)
void AppLayerParserStateCleanup(const Flow *f, void *alstate, AppLayerParserState *pstate)
void AppLayerParserRegisterGetStateProgressFunc(uint8_t ipproto, AppProto alproto, int(*StateGetStateProgress)(void *alstate, uint8_t direction))
void AppLayerParserRegisterProtocolParsers(void)
uint8_t AppLayerParserGetFirstDataDir(uint8_t ipproto, AppProto alproto)
uint64_t AppLayerParserGetTxCnt(const Flow *, void *alstate)
int AppLayerParserRegisterParser(uint8_t ipproto, AppProto alproto, uint8_t direction, AppLayerParserFPtr Parser)
Register app layer parser for the protocol.
int AppLayerParserProtocolHasLogger(uint8_t ipproto, AppProto alproto)
AppLayerParserThreadCtx * AppLayerParserThreadCtxAlloc(void)
Gets a new app layer protocol's parser thread context.
void AppLayerParserSetStreamDepthFlag(uint8_t ipproto, AppProto alproto, void *state, uint64_t tx_id, uint8_t flags)
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
void AppLayerParserStateFree(AppLayerParserState *pstate)
AppLayerDecoderEvents * AppLayerParserGetEventsByTx(uint8_t ipproto, AppProto alproto, void *tx)
void AppLayerParserRegisterGetEventInfo(uint8_t ipproto, AppProto alproto, int(*StateGetEventInfo)(const char *event_name, uint8_t *event_id, AppLayerEventType *event_type))
void AppLayerParserRegisterApplyTxConfigFunc(uint8_t ipproto, AppProto alproto, bool(*ApplyTxConfig)(void *state, void *tx, int mode, AppLayerTxConfig))
union AppLayerGetTxIterState::@11 un
int AppLayerParserParse(ThreadVars *tv, AppLayerParserThreadCtx *tctx, Flow *f, AppProto alproto, uint8_t flags, const uint8_t *input, uint32_t input_len)
int(* AppLayerParserGetFrameIdByNameFn)(const char *frame_name)
bool AppLayerParserSupportsFiles(uint8_t ipproto, AppProto alproto)
void AppLayerParserRegisterParserAcceptableDataDirection(uint8_t ipproto, AppProto alproto, uint8_t direction)
int AppLayerParserGetStateProgressCompletionStatus(AppProto alproto, uint8_t direction)
int AppLayerParserGetEventInfoById(uint8_t ipproto, AppProto alproto, uint8_t event_id, const char **event_name, AppLayerEventType *event_type)
void AppLayerParserStateProtoCleanup(uint8_t protomap, AppProto alproto, void *alstate, AppLayerParserState *pstate)
uint64_t AppLayerParserGetTransactionActive(const Flow *f, AppLayerParserState *pstate, uint8_t direction)