1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
|
/* Copyright (C) 2007-2014 Open Information Security Foundation
*
* You can copy, redistribute or modify this Program under the terms of
* the GNU General Public License version 2 as published by the Free
* Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* version 2 along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*/
/**
* \file
*
* \author Victor Julien <victor@inliniac.net>
* \author Anoop Saldanha <anoopsaldanha@gmail.com>
*
* Application layer handling and protocols implementation
*/
#ifndef __APP_LAYER_H__
#define __APP_LAYER_H__
#include "threadvars.h"
#include "decode.h"
#include "flow.h"
#include "stream-tcp-private.h"
#include "stream-tcp-reassemble.h"
#include "rust.h"
#define APP_LAYER_DATA_ALREADY_SENT_TO_APP_LAYER \
(~STREAM_TOSERVER & ~STREAM_TOCLIENT)
/***** L7 layer dispatchers *****/
/**
* \brief Handles reassembled tcp stream.
*/
int AppLayerHandleTCPData(ThreadVars *tv, TcpReassemblyThreadCtx *ra_ctx, Packet *p, Flow *f,
TcpSession *ssn, TcpStream **stream, uint8_t *data, uint32_t data_len, uint8_t flags,
enum StreamUpdateDir dir);
/**
* \brief Handles an udp chunk.
*/
int AppLayerHandleUdp(ThreadVars *tv, AppLayerThreadCtx *app_tctx,
Packet *p, Flow *f);
/***** Utility *****/
/**
* \brief Given a protocol string, returns the corresponding internal
* protocol id.
*
* \param The internal protocol id.
*/
AppProto AppLayerGetProtoByName(char *alproto_name);
/**
* \brief Given the internal protocol id, returns a string representation
* of the protocol.
*
* \param alproto The internal protocol id.
*
* \retval String representation of the protocol.
*/
const char *AppLayerGetProtoName(AppProto alproto);
void AppLayerListSupportedProtocols(void);
/***** Setup/General Registration *****/
/**
* \brief Setup the app layer.
*
* Includes protocol detection setup and the protocol parser setup.
*
* \retval 0 On success.
* \retval -1 On failure.
*/
int AppLayerSetup(void);
/**
* \brief De initializes the app layer.
*
* Includes de initializing protocol detection and the protocol parser.
*/
int AppLayerDeSetup(void);
/**
* \brief Creates a new app layer thread context.
*
* \retval Pointer to the newly create thread context, on success;
* NULL, on failure.
*/
AppLayerThreadCtx *AppLayerGetCtxThread(ThreadVars *tv);
/**
* \brief Destroys the context created by AppLayerGetCtxThread().
*
* \param tctx Pointer to the thread context to destroy.
*/
void AppLayerDestroyCtxThread(AppLayerThreadCtx *tctx);
/**
* \brief Registers per flow counters for all protocols
*
*/
void AppLayerRegisterThreadCounters(ThreadVars *tv);
/***** Profiling *****/
void AppLayerProfilingResetInternal(AppLayerThreadCtx *app_tctx);
static inline void AppLayerProfilingReset(AppLayerThreadCtx *app_tctx)
{
#ifdef PROFILING
AppLayerProfilingResetInternal(app_tctx);
#endif
}
void AppLayerProfilingStoreInternal(AppLayerThreadCtx *app_tctx, Packet *p);
static inline void AppLayerProfilingStore(AppLayerThreadCtx *app_tctx, Packet *p)
{
#ifdef PROFILING
AppLayerProfilingStoreInternal(app_tctx, p);
#endif
}
void AppLayerRegisterGlobalCounters(void);
/***** Unittests *****/
#ifdef UNITTESTS
void AppLayerUnittestsRegister(void);
#endif
void AppLayerIncTxCounter(ThreadVars *tv, Flow *f, uint64_t step);
void AppLayerIncGapErrorCounter(ThreadVars *tv, Flow *f);
void AppLayerIncAllocErrorCounter(ThreadVars *tv, Flow *f);
void AppLayerIncParserErrorCounter(ThreadVars *tv, Flow *f);
void AppLayerIncInternalErrorCounter(ThreadVars *tv, Flow *f);
static inline const uint8_t *StreamSliceGetData(const StreamSlice *stream_slice)
{
return stream_slice->input;
}
static inline uint32_t StreamSliceGetDataLen(const StreamSlice *stream_slice)
{
return stream_slice->input_len;
}
#endif
|