suricata
respond-reject.c
Go to the documentation of this file.
1/* Copyright (C) 2007-2020 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 */
26
27#include "suricata-common.h"
28#include "packet.h"
29#include "decode.h"
30#include "packet-queue.h"
31#include "threads.h"
32#include "threadvars.h"
33#include "tm-queuehandlers.h"
34#include "tm-threads.h"
35#include "action-globals.h"
36
37#include "respond-reject.h"
39
40#include "util-debug.h"
41#include "util-privs.h"
42
43int RejectSendIPv4TCP(ThreadVars *, Packet *, void *);
44int RejectSendIPv4ICMP(ThreadVars *, Packet *, void *);
45int RejectSendIPv6TCP(ThreadVars *, Packet *, void *);
46int RejectSendIPv6ICMP(ThreadVars *, Packet *, void *);
47static TmEcode RespondRejectFunc(ThreadVars *tv, Packet *p, void *data);
48static TmEcode RespondRejectThreadDeinit(ThreadVars *tv, void *data);
49
51{
52 tmm_modules[TMM_RESPONDREJECT].name = "RespondReject";
54 tmm_modules[TMM_RESPONDREJECT].Func = RespondRejectFunc;
55 tmm_modules[TMM_RESPONDREJECT].ThreadDeinit = RespondRejectThreadDeinit;
56 tmm_modules[TMM_RESPONDREJECT].cap_flags = 0; /* libnet is not compat with caps */
57}
58
59static TmEcode RespondRejectThreadDeinit(ThreadVars *tv, void *data)
60{
62 return TM_ECODE_OK;
63}
64
65static TmEcode RespondRejectFunc(ThreadVars *tv, Packet *p, void *data)
66{
67 /* ACTION_REJECT defaults to rejecting the SRC */
69 return TM_ECODE_OK;
70 }
71
72 if (PacketIsTunnel(p)) {
73 return TM_ECODE_OK;
74 }
75
76 if (PacketIsIPv4(p)) {
77 if (PacketIsTCP(p)) {
78 (void)RejectSendIPv4TCP(tv, p, data);
79 } else {
80 (void)RejectSendIPv4ICMP(tv, p, data);
81 }
82 } else if (PacketIsIPv6(p)) {
83 if (PacketIsTCP(p)) {
84 (void)RejectSendIPv6TCP(tv, p, data);
85 } else {
86 (void)RejectSendIPv6ICMP(tv, p, data);
87 }
88 }
89
90 return TM_ECODE_OK;
91}
92
94{
95 SCEnter();
98 SCReturnInt(r);
99 } else if (PacketCheckAction(p, ACTION_REJECT_DST)) {
101 SCReturnInt(r);
102 } else if (PacketCheckAction(p, ACTION_REJECT_BOTH)) {
105 SCReturnInt(r);
106 }
107 SCReturnInt(0);
108}
109
111{
112 SCEnter();
115 SCReturnInt(r);
116 } else if (PacketCheckAction(p, ACTION_REJECT_DST)) {
118 SCReturnInt(r);
119 } else if (PacketCheckAction(p, ACTION_REJECT_BOTH)) {
122 SCReturnInt(r);
123 }
124 SCReturnInt(0);
125}
126
128{
129 SCEnter();
132 SCReturnInt(r);
133 } else if (PacketCheckAction(p, ACTION_REJECT_DST)) {
135 SCReturnInt(r);
136 } else if (PacketCheckAction(p, ACTION_REJECT_BOTH)) {
139 SCReturnInt(r);
140 }
141 SCReturnInt(0);
142}
143
145{
146 SCEnter();
149 SCReturnInt(r);
150 } else if (PacketCheckAction(p, ACTION_REJECT_DST)) {
152 SCReturnInt(r);
153 } else if (PacketCheckAction(p, ACTION_REJECT_BOTH)) {
156 SCReturnInt(r);
157 }
158 SCReturnInt(0);
159}
#define ACTION_REJECT
#define ACTION_REJECT_ANY
#define ACTION_REJECT_BOTH
#define ACTION_REJECT_DST
ThreadVars * tv
bool PacketCheckAction(const Packet *p, const uint8_t a)
Definition packet.c:49
void FreeCachedCtx(void)
int RejectSendLibnet11IPv6TCP(ThreadVars *tv, Packet *p, void *data, enum RejectDirection dir)
int RejectSendLibnet11IPv4TCP(ThreadVars *tv, Packet *p, void *data, enum RejectDirection dir)
int RejectSendLibnet11IPv6ICMP(ThreadVars *tv, Packet *p, void *data, enum RejectDirection dir)
int RejectSendLibnet11IPv4ICMP(ThreadVars *tv, Packet *p, void *data, enum RejectDirection dir)
void TmModuleRespondRejectRegister(void)
int RejectSendIPv6ICMP(ThreadVars *, Packet *, void *)
int RejectSendIPv6TCP(ThreadVars *, Packet *, void *)
int RejectSendIPv4ICMP(ThreadVars *, Packet *, void *)
int RejectSendIPv4TCP(ThreadVars *, Packet *, void *)
@ REJECT_DIR_DST
@ REJECT_DIR_SRC
Per thread variable structure.
Definition threadvars.h:58
const char * name
Definition tm-modules.h:48
TmEcode(* ThreadDeinit)(ThreadVars *, void *)
Definition tm-modules.h:53
uint8_t cap_flags
Definition tm-modules.h:77
TmEcode(* Func)(ThreadVars *, Packet *, void *)
Definition tm-modules.h:56
TmEcode(* ThreadInit)(ThreadVars *, const void *, void **)
Definition tm-modules.h:51
TmModule tmm_modules[TMM_SIZE]
Definition tm-modules.c:29
@ TMM_RESPONDREJECT
@ TM_ECODE_OK
#define SCEnter(...)
Definition util-debug.h:277
#define SCReturnInt(x)
Definition util-debug.h:281
#define likely(expr)