]> git.ipfire.org Git - people/ms/suricata.git/blame - src/app-layer-htp.h
Small optimizations to IPV4 and TCP header parsing.
[people/ms/suricata.git] / src / app-layer-htp.h
CommitLineData
ce019275
WM
1/* Copyright (C) 2007-2010 Open Information Security Foundation
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.
0165b3f0 11 *
ce019275
WM
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
60a99915
EL
18/**
19 * \defgroup httplayer HTTP layer support
20 *
21 * @{
22 */
23
ce019275
WM
24/**
25 * \file
0165b3f0 26 *
07f7ba55 27 * \author Gurvinder Singh <gurvindersinghdahiya@gmail.com>
0165b3f0 28 * \author Pablo Rincon <pablo.rincon.crespo@gmail.com>
07f7ba55 29 *
ce019275 30 * This file provides a HTTP protocol support for the engine using HTP library.
07f7ba55
GS
31 */
32
48248687
VJ
33#ifndef __APP_LAYER_HTP_H__
34#define __APP_LAYER_HTP_H__
07f7ba55 35
a9cdd2bb
BR
36#include "util-radix-tree.h"
37
07f7ba55
GS
38#include <htp/htp.h>
39
6ebe7b7c
VJ
40/* default request body limit */
41#define HTP_CONFIG_DEFAULT_REQUEST_BODY_LIMIT 4096U
42
50f7d0a8 43#define HTP_FLAG_STATE_OPEN 0x01 /**< Flag to indicate that HTTP
0165b3f0 44 connection is open */
50f7d0a8 45#define HTP_FLAG_STATE_CLOSED 0x02 /**< Flag to indicate that HTTP
0165b3f0 46 connection is closed */
50f7d0a8 47#define HTP_FLAG_STATE_DATA 0x04 /**< Flag to indicate that HTTP
0165b3f0 48 connection needs more data */
50f7d0a8 49#define HTP_FLAG_STATE_ERROR 0x08 /**< Flag to indicate that an error
0165b3f0
PR
50 has been occured on HTTP
51 connection */
50f7d0a8 52#define HTP_FLAG_NEW_BODY_SET 0x10 /**< Flag to indicate that HTTP
0165b3f0
PR
53 has parsed a new body (for
54 pcre) */
0165b3f0
PR
55enum {
56 HTP_BODY_NONE, /**< Flag to indicate the current
57 operation */
58 HTP_BODY_REQUEST, /**< Flag to indicate that the
59 current operation is a request */
60 HTP_BODY_RESPONSE /**< Flag to indicate that the current
61 * operation is a response */
62};
63
64#define HTP_PCRE_NONE 0x00 /**< No pcre executed yet */
65#define HTP_PCRE_DONE 0x01 /**< Flag to indicate that pcre has
66 done some inspection in the
67 chunks */
68#define HTP_PCRE_HAS_MATCH 0x02 /**< Flag to indicate that the chunks
69 matched on some rule */
70
71/** Struct used to hold chunks of a body on a request */
7a8cd61f 72typedef struct HtpBodyChunk_ {
0165b3f0
PR
73 uint8_t *data; /**< Pointer to the data of the chunk */
74 uint32_t len; /**< Length of the chunk */
7a8cd61f 75 struct HtpBodyChunk_ *next; /**< Pointer to the next chunk */
0165b3f0 76 uint32_t id; /**< number of chunk of the current body */
7a8cd61f 77} HtpBodyChunk;
0165b3f0
PR
78
79/** Struct used to hold all the chunks of a body on a request */
7a8cd61f
VJ
80typedef struct HtpBody_ {
81 HtpBodyChunk *first; /**< Pointer to the first chunk */
82 HtpBodyChunk *last; /**< Pointer to the last chunk */
0165b3f0
PR
83 uint32_t nchunks; /**< Number of chunks in the current operation */
84 uint8_t operation; /**< This flag indicate if it's a request
85 or a response */
0165b3f0 86} HtpBody;
fc2f7f29 87
6ebe7b7c
VJ
88#define HTP_BODY_COMPLETE 0x01 /* body is complete or limit is reached,
89 either way, this is it. */
90
06a65cb4
PR
91/** Now the Body Chunks will be stored per transaction, at
92 * the tx user data */
93typedef struct SCHtpTxUserData_ {
5c6a65dc
AS
94 /* Body of the request (if any) */
95 HtpBody body;
96 /* Holds the length of the htp request body */
97 uint32_t content_len;
98 /* Holds the length of the htp request body seen so far */
99 uint32_t content_len_so_far;
6ebe7b7c 100 uint8_t flags;
06a65cb4
PR
101} SCHtpTxUserData;
102
07f7ba55 103typedef struct HtpState_ {
07f7ba55 104
7a8cd61f
VJ
105 htp_connp_t *connp; /**< Connection parser structure for
106 each connection */
fc2f7f29 107 uint8_t flags;
70b32f73
VJ
108 uint16_t transaction_cnt;
109 uint16_t transaction_done;
6ebe7b7c 110 uint32_t request_body_limit;
07f7ba55
GS
111} HtpState;
112
07f7ba55
GS
113void RegisterHTPParsers(void);
114void HTPParserRegisterTests(void);
fc2f7f29
GS
115void HTPAtExitPrintStats(void);
116void HTPFreeConfig(void);
48248687 117
0165b3f0
PR
118htp_tx_t *HTPTransactionMain(const HtpState *);
119
120int HTPCallbackRequestBodyData(htp_tx_data_t *);
4e44073c 121int HtpTransactionGetLoggableId(Flow *);
0165b3f0
PR
122void HtpBodyPrint(HtpBody *);
123void HtpBodyFree(HtpBody *);
124void AppLayerHtpRegisterExtraCallbacks(void);
25a3a5c6
PR
125/* To free the state from unittests using app-layer-htp */
126void HTPStateFree(void *);
97d49d8f 127void AppLayerHtpEnableRequestBodyCallback(void);
6fca55e0 128void AppLayerHtpPrintStats(void);
0165b3f0 129
48248687 130#endif /* __APP_LAYER_HTP_H__ */
07f7ba55 131
60a99915
EL
132/**
133 * @}
134 */