suricata
stream.c
Go to the documentation of this file.
1 /* Copyright (C) 2007-2017 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.
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>
22  */
23 
24 #include "suricata-common.h"
25 #include "decode.h"
26 #include "threads.h"
27 #include "stream.h"
28 #include "util-pool.h"
29 #include "util-debug.h"
30 #include "stream-tcp.h"
31 #include "flow-util.h"
32 
33 /** \brief Run callback for all segments in a single direction.
34  *
35  * Must be called under flow lock.
36  * \var flag determines the direction to run callback on (either to server or to client).
37  *
38  * \return -1 in case of error, the number of segment in case of success
39  */
40 int StreamSegmentForEach(const Packet *p, uint8_t flag, StreamSegmentCallback CallbackFunc, void *data)
41 {
42  switch(p->proto) {
43  case IPPROTO_TCP:
44  return StreamTcpSegmentForEach(p, flag, CallbackFunc, data);
45  break;
46 #ifdef DEBUG
47  case IPPROTO_UDP:
48  SCLogWarning("UDP is currently unsupported");
49  break;
50  default:
51  SCLogWarning("This protocol is currently unsupported");
52  break;
53 #endif
54  }
55  return 0;
56 }
57 
58 /** \brief Run callback for all segments on both directions of the session
59  *
60  * Must be called under flow lock.
61  *
62  * \return -1 in case of error, the number of segments in case of success.
63  */
65  const Packet *p, uint8_t flag, StreamSegmentCallback CallbackFunc, void *data)
66 {
67  switch (p->proto) {
68  case IPPROTO_TCP:
69  return StreamTcpSegmentForSession(p, flag, CallbackFunc, data);
70  break;
71 #ifdef DEBUG
72  case IPPROTO_UDP:
73  SCLogWarning("UDP is currently unsupported");
74  break;
75  default:
76  SCLogWarning("This protocol is currently unsupported");
77  break;
78 #endif
79  }
80  return 0;
81 }
StreamSegmentCallback
int(* StreamSegmentCallback)(const Packet *, TcpSegment *, void *, const uint8_t *, uint32_t)
Definition: stream.h:36
Packet_::proto
uint8_t proto
Definition: decode.h:498
flow-util.h
stream-tcp.h
StreamSegmentForEach
int StreamSegmentForEach(const Packet *p, uint8_t flag, StreamSegmentCallback CallbackFunc, void *data)
Definition: stream.c:40
threads.h
decode.h
util-debug.h
StreamTcpSegmentForSession
int StreamTcpSegmentForSession(const Packet *p, uint8_t flag, StreamSegmentCallback CallbackFunc, void *data)
Run callback function on each TCP segment in both directions of a session.
Definition: stream-tcp.c:7043
StreamTcpSegmentForEach
int StreamTcpSegmentForEach(const Packet *p, uint8_t flag, StreamSegmentCallback CallbackFunc, void *data)
Definition: stream-tcp.c:6984
SCLogWarning
#define SCLogWarning(...)
Macro used to log WARNING messages.
Definition: util-debug.h:249
stream.h
Packet_
Definition: decode.h:476
StreamSegmentForSession
int StreamSegmentForSession(const Packet *p, uint8_t flag, StreamSegmentCallback CallbackFunc, void *data)
Run callback for all segments on both directions of the session.
Definition: stream.c:64
suricata-common.h
util-pool.h