suricata
respond-reject.c
Go to the documentation of this file.
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.
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 William Metcalf <william.metcalf@gmail.com>
22  *
23  * RespondReject is a threaded wrapper for sending Rejects
24  *
25  * \todo RespondRejectFunc returns 1 on error, 0 on ok... why? For now it should
26  * just return 0 always, error handling is a TODO in the threading model (VJ)
27  */
28 
29 #include "suricata-common.h"
30 #include "decode.h"
31 #include "packet-queue.h"
32 #include "threads.h"
33 #include "threadvars.h"
34 #include "tm-queuehandlers.h"
35 #include "tm-threads.h"
36 #include "action-globals.h"
37 
38 #include "respond-reject.h"
40 
41 #include "util-debug.h"
42 #include "util-privs.h"
43 
44 int RejectSendIPv4TCP(ThreadVars *, Packet *, void *);
45 int RejectSendIPv4ICMP(ThreadVars *, Packet *, void *);
46 int RejectSendIPv6TCP(ThreadVars *, Packet *, void *);
47 int RejectSendIPv6ICMP(ThreadVars *, Packet *, void *);
48 
50 {
51  tmm_modules[TMM_RESPONDREJECT].name = "RespondReject";
56  tmm_modules[TMM_RESPONDREJECT].cap_flags = 0; /* libnet is not compat with caps */
57 }
58 
60 {
61  int ret = 0;
62 
63  /* ACTION_REJECT defaults to rejecting the SRC */
64  if (!(PACKET_TEST_ACTION(p, ACTION_REJECT)) &&
67  return TM_ECODE_OK;
68  }
69 
70  if (PKT_IS_IPV4(p)) {
71  if (PKT_IS_TCP(p)) {
72  ret = RejectSendIPv4TCP(tv, p, data);
73  } else {
74  ret = RejectSendIPv4ICMP(tv, p, data);
75  }
76  } else if (PKT_IS_IPV6(p)) {
77  if (PKT_IS_TCP(p)) {
78  ret = RejectSendIPv6TCP(tv, p, data);
79  } else {
80  ret = RejectSendIPv6ICMP(tv, p, data);
81  }
82  } else {
83  /* we're only supporting IPv4 and IPv6 */
84  return TM_ECODE_OK;
85  }
86 
87  if (ret)
88  return TM_ECODE_FAILED;
89  else
90  return TM_ECODE_OK;
91 }
92 
93 int RejectSendIPv4TCP(ThreadVars *tv, Packet *p, void *data)
94 {
95  SCEnter();
96  int r = 0;
99  SCReturnInt(r);
100  } else if (PACKET_TEST_ACTION(p, ACTION_REJECT_DST)) {
102  SCReturnInt(r);
103  } else if(PACKET_TEST_ACTION(p, ACTION_REJECT_BOTH)) {
104  int ret;
105  ret = RejectSendLibnet11L3IPv4TCP(tv, p, data, REJECT_DIR_SRC);
106  if (RejectSendLibnet11L3IPv4TCP(tv, p, data, REJECT_DIR_DST) == 0) {
107  SCReturnInt(0);
108  } else {
109  SCReturnInt(ret);
110  }
111  }
112  SCReturnInt(0);
113 }
114 
115 int RejectSendIPv4ICMP(ThreadVars *tv, Packet *p, void *data)
116 {
117  SCEnter();
118  int r = 0;
121  SCReturnInt(r);
122  } else if (PACKET_TEST_ACTION(p, ACTION_REJECT_DST)) {
124  SCReturnInt(r);
125  } else if(PACKET_TEST_ACTION(p, ACTION_REJECT_BOTH)) {
126  int ret;
127  ret = RejectSendLibnet11L3IPv4ICMP(tv, p, data, REJECT_DIR_SRC);
128  if (RejectSendLibnet11L3IPv4ICMP(tv, p, data, REJECT_DIR_DST) == 0) {
129  SCReturnInt(0);
130  } else {
131  SCReturnInt(ret);
132  }
133  }
134  SCReturnInt(0);
135 }
136 
137 int RejectSendIPv6TCP(ThreadVars *tv, Packet *p, void *data)
138 {
139  SCEnter();
140  int r = 0;
143  SCReturnInt(r);
144  } else if (PACKET_TEST_ACTION(p, ACTION_REJECT_DST)) {
146  SCReturnInt(r);
147  } else if(PACKET_TEST_ACTION(p, ACTION_REJECT_BOTH)) {
148  int ret;
149  ret = RejectSendLibnet11L3IPv6TCP(tv, p, data, REJECT_DIR_SRC);
150  if (RejectSendLibnet11L3IPv6TCP(tv, p, data, REJECT_DIR_DST) == 0) {
151  SCReturnInt(0);
152  } else {
153  SCReturnInt(ret);
154  }
155  }
156  SCReturnInt(0);
157 }
158 
159 int RejectSendIPv6ICMP(ThreadVars *tv, Packet *p, void *data)
160 {
161  SCEnter();
162  int r = 0;
165  SCReturnInt(r);
166  } else if (PACKET_TEST_ACTION(p, ACTION_REJECT_DST)) {
168  SCReturnInt(r);
169  } else if(PACKET_TEST_ACTION(p, ACTION_REJECT_BOTH)) {
170  int ret;
171  ret = RejectSendLibnet11L3IPv6ICMP(tv, p, data, REJECT_DIR_SRC);
172  if (RejectSendLibnet11L3IPv6ICMP(tv, p, data, REJECT_DIR_DST) == 0) {
173  SCReturnInt(0);
174  } else {
175  SCReturnInt(ret);
176  }
177  }
178  SCReturnInt(0);
179 }
180 
int RejectSendIPv4ICMP(ThreadVars *, Packet *, void *)
int RejectSendIPv4TCP(ThreadVars *, Packet *, void *)
#define REJECT_DIR_DST
uint8_t cap_flags
Definition: tm-modules.h:67
#define ACTION_REJECT_DST
#define PACKET_TEST_ACTION(p, a)
Definition: decode.h:858
TmEcode(* Func)(ThreadVars *, Packet *, void *, PacketQueue *, PacketQueue *)
Definition: tm-modules.h:52
#define ACTION_REJECT
#define PKT_IS_IPV6(p)
Definition: decode.h:253
int RejectSendLibnet11L3IPv4ICMP(ThreadVars *tv, Packet *p, void *data, int dir)
#define PKT_IS_IPV4(p)
Definition: decode.h:252
int RejectSendIPv6TCP(ThreadVars *, Packet *, void *)
#define ACTION_REJECT_BOTH
void(* RegisterTests)(void)
Definition: tm-modules.h:65
TmEcode(* ThreadDeinit)(ThreadVars *, void *)
Definition: tm-modules.h:49
#define SCEnter(...)
Definition: util-debug.h:337
#define SCReturnInt(x)
Definition: util-debug.h:341
#define REJECT_DIR_SRC
int RejectSendIPv6ICMP(ThreadVars *, Packet *, void *)
const char * name
Definition: tm-modules.h:44
void TmModuleRespondRejectRegister(void)
#define PKT_IS_TCP(p)
Definition: decode.h:254
TmModule tmm_modules[TMM_SIZE]
Definition: tm-modules.h:73
TmEcode(* ThreadInit)(ThreadVars *, const void *, void **)
Definition: tm-modules.h:47
int RejectSendLibnet11L3IPv4TCP(ThreadVars *tv, Packet *p, void *data, int dir)
Per thread variable structure.
Definition: threadvars.h:57
TmEcode RespondRejectFunc(ThreadVars *tv, Packet *p, void *data, PacketQueue *pq, PacketQueue *postpq)
int RejectSendLibnet11L3IPv6ICMP(ThreadVars *tv, Packet *p, void *data, int dir)
int RejectSendLibnet11L3IPv6TCP(ThreadVars *tv, Packet *p, void *data, int dir)