]> git.ipfire.org Git - people/ms/suricata.git/blame - src/app-layer-parser.h
app-layer API optimizations and cleanups
[people/ms/suricata.git] / src / app-layer-parser.h
CommitLineData
429c6388 1/* Copyright (C) 2007-2013 Open Information Security Foundation
ce019275
WM
2 *
3 * You can copy, redistribute or modify this Program under the terms of
4 * the GNU General Public License version 2 as published by the Free
5 * Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * version 2 along with this program; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
15 * 02110-1301, USA.
16 */
17
18/**
19 * \file
20 *
21 * \author Victor Julien <victor@inliniac.net>
429c6388 22 * \author Anoop Saldanha <anoopsaldanha@gmail.com>
ce019275
WM
23 */
24
59327e0f
VJ
25#ifndef __APP_LAYER_PARSER_H__
26#define __APP_LAYER_PARSER_H__
8e10844f 27
347c0df9 28#include "app-layer-events.h"
1cf02560 29#include "detect-engine-state.h"
e1022ee5 30#include "util-file.h"
b160c49e 31#include "stream-tcp-private.h"
e1022ee5 32
26169ad8
WM
33#define APP_LAYER_PARSER_EOF 0x01
34#define APP_LAYER_PARSER_NO_INSPECTION 0x02
35#define APP_LAYER_PARSER_NO_REASSEMBLY 0x04
36#define APP_LAYER_PARSER_NO_INSPECTION_PAYLOAD 0x08
2c857087 37
5908dd08 38int AppLayerParserProtoIsRegistered(uint8_t ipproto, AppProto alproto);
2c857087
VJ
39
40/***** transaction handling *****/
41
42/** \brief Function ptr type for getting active TxId from a flow
43 * Used by AppLayerTransactionGetActive.
44 */
45typedef uint64_t (*GetActiveTxIdFunc)(Flow *f, uint8_t flags);
46
47/** \brief Register GetActiveTxId Function
48 *
49 */
50void RegisterAppLayerGetActiveTxIdFunc(GetActiveTxIdFunc FuncPtr);
51
52/** \brief active TX retrieval for normal ops: so with detection and logging
53 *
54 * \retval tx_id lowest tx_id that still needs work
55 *
56 * This is the default function.
57 */
58uint64_t AppLayerTransactionGetActiveDetectLog(Flow *f, uint8_t flags);
59
5cc880c5
VJ
60/** \brief active TX retrieval for logging only ops
61 *
62 * \retval tx_id lowest tx_id that still needs work
63 */
64uint64_t AppLayerTransactionGetActiveLogOnly(Flow *f, uint8_t flags);
65
66
429c6388 67int AppLayerParserSetup(void);
6d562f3b 68void AppLayerParserPostStreamSetup(void);
429c6388
AS
69int AppLayerParserDeSetup(void);
70
9634e60e
VJ
71typedef struct AppLayerParserThreadCtx_ AppLayerParserThreadCtx;
72
429c6388
AS
73/**
74 * \brief Gets a new app layer protocol's parser thread context.
75 *
76 * \retval Non-NULL pointer on success.
77 * NULL pointer on failure.
78 */
9634e60e 79AppLayerParserThreadCtx *AppLayerParserThreadCtxAlloc(void);
429c6388
AS
80
81/**
82 * \brief Destroys the app layer parser thread context obtained
fdefb65b 83 * using AppLayerParserThreadCtxAlloc().
429c6388
AS
84 *
85 * \param tctx Pointer to the thread context to be destroyed.
86 */
9634e60e 87void AppLayerParserThreadCtxFree(AppLayerParserThreadCtx *tctx);
429c6388
AS
88
89/**
90 * \brief Given a protocol name, checks if the parser is enabled in
91 * the conf file.
92 *
93 * \param alproto_name Name of the app layer protocol.
94 *
95 * \retval 1 If enabled.
96 * \retval 0 If disabled.
d4d18e31 97 */
429c6388
AS
98int AppLayerParserConfParserEnabled(const char *ipproto,
99 const char *alproto_name);
d4d18e31 100
429c6388 101/***** Parser related registration *****/
d4d18e31
AS
102
103/**
429c6388 104 * \brief Register app layer parser for the protocol.
d4d18e31 105 *
429c6388
AS
106 * \retval 0 On success.
107 * \retval -1 On failure.
d4d18e31 108 */
5cdeadb3 109int AppLayerParserRegisterParser(uint8_t ipproto, AppProto alproto,
429c6388
AS
110 uint8_t direction,
111 int (*Parser)(Flow *f, void *protocol_state,
9634e60e 112 AppLayerParserState *pstate,
429c6388
AS
113 uint8_t *buf, uint32_t buf_len,
114 void *local_storage));
5cdeadb3 115void AppLayerParserRegisterParserAcceptableDataDirection(uint8_t ipproto,
429c6388
AS
116 AppProto alproto,
117 uint8_t direction);
5cdeadb3 118void AppLayerParserRegisterStateFuncs(uint8_t ipproto, AppProto alproto,
429c6388
AS
119 void *(*StateAlloc)(void),
120 void (*StateFree)(void *));
5cdeadb3 121void AppLayerParserRegisterLocalStorageFunc(uint8_t ipproto, AppProto proto,
429c6388
AS
122 void *(*LocalStorageAlloc)(void),
123 void (*LocalStorageFree)(void *));
5cdeadb3 124void AppLayerParserRegisterGetFilesFunc(uint8_t ipproto, AppProto alproto,
429c6388 125 FileContainer *(*StateGetFiles)(void *, uint8_t));
5cdeadb3 126void AppLayerParserRegisterGetEventsFunc(uint8_t ipproto, AppProto proto,
429c6388 127 AppLayerDecoderEvents *(*StateGetEvents)(void *, uint64_t));
5cdeadb3 128void AppLayerParserRegisterHasEventsFunc(uint8_t ipproto, AppProto alproto,
429c6388 129 int (*StateHasEvents)(void *));
f3599323
MK
130void AppLayerParserRegisterLoggerFuncs(uint8_t ipproto, AppProto alproto,
131 int (*StateGetTxLogged)(void *, void *, uint32_t),
132 void (*StateSetTxLogged)(void *, void *, uint32_t));
5cdeadb3
VJ
133void AppLayerParserRegisterLogger(uint8_t ipproto, AppProto alproto);
134void AppLayerParserRegisterTruncateFunc(uint8_t ipproto, AppProto alproto,
429c6388 135 void (*Truncate)(void *, uint8_t));
5cdeadb3 136void AppLayerParserRegisterGetStateProgressFunc(uint8_t ipproto, AppProto alproto,
429c6388 137 int (*StateGetStateProgress)(void *alstate, uint8_t direction));
5cdeadb3 138void AppLayerParserRegisterTxFreeFunc(uint8_t ipproto, AppProto alproto,
429c6388 139 void (*StateTransactionFree)(void *, uint64_t));
5cdeadb3 140void AppLayerParserRegisterGetTxCnt(uint8_t ipproto, AppProto alproto,
429c6388 141 uint64_t (*StateGetTxCnt)(void *alstate));
5cdeadb3 142void AppLayerParserRegisterGetTx(uint8_t ipproto, AppProto alproto,
429c6388 143 void *(StateGetTx)(void *alstate, uint64_t tx_id));
c4b918b6 144void AppLayerParserRegisterGetStateProgressCompletionStatus(AppProto alproto,
429c6388 145 int (*StateGetStateProgressCompletionStatus)(uint8_t direction));
5cdeadb3 146void AppLayerParserRegisterGetEventInfo(uint8_t ipproto, AppProto alproto,
429c6388
AS
147 int (*StateGetEventInfo)(const char *event_name, int *event_id,
148 AppLayerEventType *event_type));
1cf02560 149void AppLayerParserRegisterDetectStateFuncs(uint8_t ipproto, AppProto alproto,
f536099a 150 int (*StateHasTxDetectState)(void *alstate),
1cf02560 151 DetectEngineState *(*GetTxDetectState)(void *tx),
f536099a 152 int (*SetTxDetectState)(void *alstate, void *tx, DetectEngineState *));
b160c49e
GL
153void AppLayerParserRegisterGetStreamDepth(uint8_t ipproto,
154 AppProto alproto,
155 uint32_t (*GetStreamDepth)(void));
a0fad6bb
VJ
156void AppLayerParserRegisterMpmIDsFuncs(uint8_t ipproto, AppProto alproto,
157 uint64_t (*GetTxMpmIDs)(void *tx),
158 int (*SetTxMpmIDs)(void *tx, uint64_t));
d4d18e31 159
429c6388 160/***** Get and transaction functions *****/
16cfae2f 161
5cdeadb3
VJ
162void *AppLayerParserGetProtocolParserLocalStorage(uint8_t ipproto, AppProto alproto);
163void AppLayerParserDestroyProtocolParserLocalStorage(uint8_t ipproto, AppProto alproto,
429c6388 164 void *local_data);
6cb00142 165
6cb00142 166
9634e60e 167uint64_t AppLayerParserGetTransactionLogId(AppLayerParserState *pstate);
e9fccfa6 168void AppLayerParserSetTransactionLogId(AppLayerParserState *pstate, uint64_t tx_id);
f3599323
MK
169void AppLayerParserSetTxLogged(uint8_t ipproto, AppProto alproto, void *alstate,
170 void *tx, uint32_t logger);
171int AppLayerParserGetTxLogged(uint8_t ipproto, AppProto alproto, void *alstate,
172 void *tx, uint32_t logger);
9634e60e
VJ
173uint64_t AppLayerParserGetTransactionInspectId(AppLayerParserState *pstate, uint8_t direction);
174void AppLayerParserSetTransactionInspectId(AppLayerParserState *pstate,
6946e0be
VJ
175 const uint8_t ipproto, const AppProto alproto, void *alstate,
176 const uint8_t flags);
9634e60e
VJ
177AppLayerDecoderEvents *AppLayerParserGetDecoderEvents(AppLayerParserState *pstate);
178void AppLayerParserSetDecoderEvents(AppLayerParserState *pstate, AppLayerDecoderEvents *devents);
5cdeadb3 179AppLayerDecoderEvents *AppLayerParserGetEventsByTx(uint8_t ipproto, AppProto alproto, void *alstate,
429c6388 180 uint64_t tx_id);
5cdeadb3 181FileContainer *AppLayerParserGetFiles(uint8_t ipproto, AppProto alproto,
429c6388 182 void *alstate, uint8_t direction);
5cdeadb3 183int AppLayerParserGetStateProgress(uint8_t ipproto, AppProto alproto,
429c6388 184 void *alstate, uint8_t direction);
5cdeadb3
VJ
185uint64_t AppLayerParserGetTxCnt(uint8_t ipproto, AppProto alproto, void *alstate);
186void *AppLayerParserGetTx(uint8_t ipproto, AppProto alproto, void *alstate, uint64_t tx_id);
c4b918b6 187int AppLayerParserGetStateProgressCompletionStatus(AppProto alproto, uint8_t direction);
5cdeadb3 188int AppLayerParserGetEventInfo(uint8_t ipproto, AppProto alproto, const char *event_name,
429c6388 189 int *event_id, AppLayerEventType *event_type);
6cb00142 190
3148ff34 191uint64_t AppLayerParserGetTransactionActive(const Flow *f, AppLayerParserState *pstate, uint8_t direction);
6cb00142 192
f5f14880 193uint8_t AppLayerParserGetFirstDataDir(uint8_t ipproto, AppProto alproto);
ddde572f 194
bcfa484b 195int AppLayerParserSupportsFiles(uint8_t ipproto, AppProto alproto);
1cf02560 196int AppLayerParserSupportsTxDetectState(uint8_t ipproto, AppProto alproto);
f536099a 197int AppLayerParserHasTxDetectState(uint8_t ipproto, AppProto alproto, void *alstate);
1cf02560 198DetectEngineState *AppLayerParserGetTxDetectState(uint8_t ipproto, AppProto alproto, void *tx);
3148ff34 199int AppLayerParserSetTxDetectState(const Flow *f, void *alstate, void *tx, DetectEngineState *s);
1cf02560 200
a0fad6bb
VJ
201uint64_t AppLayerParserGetTxMpmIDs(uint8_t ipproto, AppProto alproto, void *tx);
202int AppLayerParserSetTxMpmIDs(uint8_t ipproto, AppProto alproto, void *tx, uint64_t);
203
429c6388
AS
204/***** General *****/
205
675fa564 206int AppLayerParserParse(ThreadVars *tv, AppLayerParserThreadCtx *tctx, Flow *f, AppProto alproto,
429c6388 207 uint8_t flags, uint8_t *input, uint32_t input_len);
9634e60e 208void AppLayerParserSetEOF(AppLayerParserState *pstate);
3148ff34 209int AppLayerParserHasDecoderEvents(const Flow *f, void *alstate, AppLayerParserState *pstate,
429c6388 210 uint8_t flags);
01913f6a 211int AppLayerParserIsTxAware(AppProto alproto);
b2d420be 212int AppLayerParserProtocolIsTxAware(uint8_t ipproto, AppProto alproto);
5cdeadb3
VJ
213int AppLayerParserProtocolIsTxEventAware(uint8_t ipproto, AppProto alproto);
214int AppLayerParserProtocolSupportsTxs(uint8_t ipproto, AppProto alproto);
078ff0c0 215int AppLayerParserProtocolHasLogger(uint8_t ipproto, AppProto alproto);
2d223b69 216void AppLayerParserTriggerRawStreamReassembly(Flow *f, int direction);
b160c49e 217void AppLayerParserSetStreamDepth(uint8_t ipproto, AppProto alproto, uint32_t stream_depth);
3148ff34 218uint32_t AppLayerParserGetStreamDepth(const Flow *f);
429c6388
AS
219
220/***** Cleanup *****/
221
3148ff34 222void AppLayerParserStateCleanup(const Flow *f, void *alstate, AppLayerParserState *pstate);
429c6388
AS
223
224void AppLayerParserRegisterProtocolParsers(void);
225
226
9634e60e
VJ
227void AppLayerParserStateSetFlag(AppLayerParserState *pstate, uint8_t flag);
228int AppLayerParserStateIssetFlag(AppLayerParserState *pstate, uint8_t flag);
429c6388 229
5cdeadb3 230void AppLayerParserStreamTruncated(uint8_t ipproto, AppProto alproto, void *alstate,
429c6388
AS
231 uint8_t direction);
232
233
234
9634e60e
VJ
235AppLayerParserState *AppLayerParserStateAlloc(void);
236void AppLayerParserStateFree(AppLayerParserState *pstate);
429c6388
AS
237
238
239
240#ifdef DEBUG
9634e60e 241void AppLayerParserStatePrintDetails(AppLayerParserState *pstate);
429c6388 242#endif
6cb00142 243
077ac816 244#ifdef AFLFUZZ_APPLAYER
4683b0e6
VJ
245int AppLayerParserRequestFromFile(uint8_t ipproto, AppProto alproto, char *filename);
246int AppLayerParserFromFile(uint8_t ipproto, AppProto alproto, char *filename);
077ac816
VJ
247#endif
248
6cb00142
AS
249/***** Unittests *****/
250
429c6388 251#ifdef UNITTESTS
5cdeadb3 252void AppLayerParserRegisterProtocolUnittests(uint8_t ipproto, AppProto alproto,
429c6388
AS
253 void (*RegisterUnittests)(void));
254void AppLayerParserRegisterUnittests(void);
255void AppLayerParserBackupParserTable(void);
256void AppLayerParserRestoreParserTable(void);
257#endif
6cb00142 258
59327e0f 259#endif /* __APP_LAYER_PARSER_H__ */