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 static TmEcode RespondRejectFunc(ThreadVars *tv, Packet *p, void *data);
49 
51 {
52  tmm_modules[TMM_RESPONDREJECT].name = "RespondReject";
54  tmm_modules[TMM_RESPONDREJECT].Func = RespondRejectFunc;
57  tmm_modules[TMM_RESPONDREJECT].cap_flags = 0; /* libnet is not compat with caps */
58 }
59 
60 static TmEcode RespondRejectFunc(ThreadVars *tv, Packet *p, void *data)
61 {
62  int ret = 0;
63 
64  /* ACTION_REJECT defaults to rejecting the SRC */
65  if (!(PACKET_TEST_ACTION(p, ACTION_REJECT)) &&
68  return TM_ECODE_OK;
69  }
70 
71  if (PKT_IS_IPV4(p)) {
72  if (PKT_IS_TCP(p)) {
73  ret = RejectSendIPv4TCP(tv, p, data);
74  } else {
75  ret = RejectSendIPv4ICMP(tv, p, data);
76  }
77  } else if (PKT_IS_IPV6(p)) {
78  if (PKT_IS_TCP(p)) {
79  ret = RejectSendIPv6TCP(tv, p, data);
80  } else {
81  ret = RejectSendIPv6ICMP(tv, p, data);
82  }
83  } else {
84  /* we're only supporting IPv4 and IPv6 */
85  return TM_ECODE_OK;
86  }
87 
88  if (ret)
89  return TM_ECODE_FAILED;
90  else
91  return TM_ECODE_OK;
92 }
93 
94 int RejectSendIPv4TCP(ThreadVars *tv, Packet *p, void *data)
95 {
96  SCEnter();
97  int r = 0;
100  SCReturnInt(r);
101  } else if (PACKET_TEST_ACTION(p, ACTION_REJECT_DST)) {
103  SCReturnInt(r);
104  } else if(PACKET_TEST_ACTION(p, ACTION_REJECT_BOTH)) {
105  int ret;
107  if (RejectSendLibnet11L3IPv4TCP(tv, p, data, REJECT_DIR_DST) == 0) {
108  SCReturnInt(0);
109  } else {
110  SCReturnInt(ret);
111  }
112  }
113  SCReturnInt(0);
114 }
115 
116 int RejectSendIPv4ICMP(ThreadVars *tv, Packet *p, void *data)
117 {
118  SCEnter();
119  int r = 0;
122  SCReturnInt(r);
123  } else if (PACKET_TEST_ACTION(p, ACTION_REJECT_DST)) {
125  SCReturnInt(r);
126  } else if(PACKET_TEST_ACTION(p, ACTION_REJECT_BOTH)) {
127  int ret;
129  if (RejectSendLibnet11L3IPv4ICMP(tv, p, data, REJECT_DIR_DST) == 0) {
130  SCReturnInt(0);
131  } else {
132  SCReturnInt(ret);
133  }
134  }
135  SCReturnInt(0);
136 }
137 
138 int RejectSendIPv6TCP(ThreadVars *tv, Packet *p, void *data)
139 {
140  SCEnter();
141  int r = 0;
144  SCReturnInt(r);
145  } else if (PACKET_TEST_ACTION(p, ACTION_REJECT_DST)) {
147  SCReturnInt(r);
148  } else if(PACKET_TEST_ACTION(p, ACTION_REJECT_BOTH)) {
149  int ret;
151  if (RejectSendLibnet11L3IPv6TCP(tv, p, data, REJECT_DIR_DST) == 0) {
152  SCReturnInt(0);
153  } else {
154  SCReturnInt(ret);
155  }
156  }
157  SCReturnInt(0);
158 }
159 
160 int RejectSendIPv6ICMP(ThreadVars *tv, Packet *p, void *data)
161 {
162  SCEnter();
163  int r = 0;
166  SCReturnInt(r);
167  } else if (PACKET_TEST_ACTION(p, ACTION_REJECT_DST)) {
169  SCReturnInt(r);
170  } else if(PACKET_TEST_ACTION(p, ACTION_REJECT_BOTH)) {
171  int ret;
173  if (RejectSendLibnet11L3IPv6ICMP(tv, p, data, REJECT_DIR_DST) == 0) {
174  SCReturnInt(0);
175  } else {
176  SCReturnInt(ret);
177  }
178  }
179  SCReturnInt(0);
180 }
181 
TmModule_::cap_flags
uint8_t cap_flags
Definition: tm-modules.h:67
RejectSendLibnet11L3IPv4ICMP
int RejectSendLibnet11L3IPv4ICMP(ThreadVars *tv, Packet *p, void *data, int dir)
Definition: respond-reject-libnet11.c:523
REJECT_DIR_DST
#define REJECT_DIR_DST
Definition: respond-reject.h:30
tm-threads.h
RejectSendIPv6TCP
int RejectSendIPv6TCP(ThreadVars *, Packet *, void *)
Definition: respond-reject.c:138
RejectSendIPv4TCP
int RejectSendIPv4TCP(ThreadVars *, Packet *, void *)
Definition: respond-reject.c:94
PKT_IS_IPV6
#define PKT_IS_IPV6(p)
Definition: decode.h:253
ACTION_REJECT
#define ACTION_REJECT
Definition: action-globals.h:31
RejectSendIPv4ICMP
int RejectSendIPv4ICMP(ThreadVars *, Packet *, void *)
Definition: respond-reject.c:116
action-globals.h
threads.h
REJECT_DIR_SRC
#define REJECT_DIR_SRC
Definition: respond-reject.h:29
packet-queue.h
RejectSendIPv6ICMP
int RejectSendIPv6ICMP(ThreadVars *, Packet *, void *)
Definition: respond-reject.c:160
util-privs.h
TM_ECODE_FAILED
@ TM_ECODE_FAILED
Definition: tm-threads-common.h:79
RejectSendLibnet11L3IPv6TCP
int RejectSendLibnet11L3IPv6TCP(ThreadVars *tv, Packet *p, void *data, int dir)
Definition: respond-reject-libnet11.c:531
TM_ECODE_OK
@ TM_ECODE_OK
Definition: tm-threads-common.h:78
TmModule_::ThreadDeinit
TmEcode(* ThreadDeinit)(ThreadVars *, void *)
Definition: tm-modules.h:49
ACTION_REJECT_DST
#define ACTION_REJECT_DST
Definition: action-globals.h:32
PKT_IS_TCP
#define PKT_IS_TCP(p)
Definition: decode.h:254
decode.h
util-debug.h
SCEnter
#define SCEnter(...)
Definition: util-debug.h:337
ThreadVars_
Per thread variable structure.
Definition: threadvars.h:57
TmModule_::Func
TmEcode(* Func)(ThreadVars *, Packet *, void *)
Definition: tm-modules.h:52
Packet_
Definition: decode.h:408
tmm_modules
TmModule tmm_modules[TMM_SIZE]
Definition: tm-modules.c:33
TmModule_::RegisterTests
void(* RegisterTests)(void)
Definition: tm-modules.h:65
TmEcode
TmEcode
Definition: tm-threads-common.h:77
TmModule_::name
const char * name
Definition: tm-modules.h:44
tm-queuehandlers.h
ACTION_REJECT_BOTH
#define ACTION_REJECT_BOTH
Definition: action-globals.h:33
suricata-common.h
respond-reject-libnet11.h
TMM_RESPONDREJECT
@ TMM_RESPONDREJECT
Definition: tm-threads-common.h:44
TmModule_::ThreadInit
TmEcode(* ThreadInit)(ThreadVars *, const void *, void **)
Definition: tm-modules.h:47
tv
ThreadVars * tv
Definition: fuzz_decodepcapfile.c:32
threadvars.h
RejectSendLibnet11L3IPv6ICMP
int RejectSendLibnet11L3IPv6ICMP(ThreadVars *tv, Packet *p, void *data, int dir)
Definition: respond-reject-libnet11.c:539
TmModuleRespondRejectRegister
void TmModuleRespondRejectRegister(void)
Definition: respond-reject.c:50
respond-reject.h
SCReturnInt
#define SCReturnInt(x)
Definition: util-debug.h:341
PKT_IS_IPV4
#define PKT_IS_IPV4(p)
Definition: decode.h:252
PACKET_TEST_ACTION
#define PACKET_TEST_ACTION(p, a)
Definition: decode.h:847
RejectSendLibnet11L3IPv4TCP
int RejectSendLibnet11L3IPv4TCP(ThreadVars *tv, Packet *p, void *data, int dir)
Definition: respond-reject-libnet11.c:515