1 /* Copyright (C) 2014 Open Information Security Foundation
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
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.
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
21 * \author Giuseppe Longo <giuseppelng@gmail.com>
23 #include "suricata-common.h"
24 #include "tm-threads.h"
27 #include "runmode-nflog.h"
29 #include "util-debug.h"
30 #include "util-device.h"
31 #include "util-runmodes.h"
32 #include "util-misc.h"
34 #include "source-nflog.h"
36 const char *RunModeIdsNflogGetDefaultMode(void)
41 void RunModeIdsNflogRegister(void)
43 RunModeRegisterNewRunMode(RUNMODE_NFLOG
, "autofp",
44 "Multi threaded nflog mode",
45 RunModeIdsNflogAutoFp
);
46 RunModeRegisterNewRunMode(RUNMODE_NFLOG
, "single",
47 "Single threaded nflog mode",
48 RunModeIdsNflogSingle
);
49 RunModeRegisterNewRunMode(RUNMODE_NFLOG
, "workers",
51 RunModeIdsNflogWorkers
);
56 static void NflogDerefConfig(void *data
)
58 NflogGroupConfig
*nflogconf
= (NflogGroupConfig
*)data
;
62 static void *ParseNflogConfig(const char *group
)
65 ConfNode
*group_default
= NULL
;
67 NflogGroupConfig
*nflogconf
= SCMalloc(sizeof(*nflogconf
));
74 if (unlikely(nflogconf
== NULL
))
82 nflogconf
->DerefFunc
= NflogDerefConfig
;
83 nflog_node
= ConfGetNode("nflog");
85 if (nflog_node
== NULL
) {
86 SCLogInfo("Unable to find nflog config using default value");
90 group_root
= ConfNodeLookupKeyValue(nflog_node
, "group", group
);
92 group_default
= ConfNodeLookupKeyValue(nflog_node
, "group", "default");
94 if (group_root
== NULL
&& group_default
== NULL
) {
95 SCLogInfo("Unable to find nflog config for "
96 "group \"%s\" or \"default\", using default value",
101 nflogconf
->nful_overrun_warned
= 0;
102 strlcpy(nflogconf
->numgroup
, group
, sizeof(nflogconf
->numgroup
));
104 if (ParseSizeStringU16(group
, &nflogconf
->group
) < 0) {
105 FatalError(SC_ERR_FATAL
, "NFLOG's group number invalid.");
108 boolval
= ConfGetChildValueIntWithDefault(group_root
, group_default
,
109 "buffer-size", &bufsize
);
112 nflogconf
->nlbufsiz
= bufsize
;
114 SCLogError(SC_ERR_INVALID_ARGUMENT
, "Invalid buffer-size value");
119 boolval
= ConfGetChildValueIntWithDefault(group_root
, group_default
,
120 "max-size", &bufsize_max
);
123 nflogconf
->nlbufsiz_max
= bufsize_max
;
125 SCLogError(SC_ERR_INVALID_ARGUMENT
, "Invalid max-size value");
130 if (nflogconf
->nlbufsiz
> nflogconf
->nlbufsiz_max
) {
131 SCLogWarning(SC_ERR_INVALID_ARGUMENT
, "buffer-size value larger "
132 "than max-size value, adjusting buffer-size");
133 nflogconf
->nlbufsiz
= nflogconf
->nlbufsiz_max
;
136 boolval
= ConfGetChildValueIntWithDefault(group_root
, group_default
,
137 "qthreshold", &qthreshold
);
140 nflogconf
->qthreshold
= qthreshold
;
142 SCLogError(SC_ERR_INVALID_ARGUMENT
, "Invalid qthreshold value");
147 boolval
= ConfGetChildValueIntWithDefault(group_root
, group_default
,
148 "qtimeout", &qtimeout
);
151 nflogconf
->qtimeout
= qtimeout
;
153 SCLogError(SC_ERR_INVALID_ARGUMENT
, "Invalid qtimeout value");
161 static int NflogConfigGeThreadsCount(void *conf
)
163 /* for each nflog group there is no reason to use more than 1 thread */
168 int RunModeIdsNflogAutoFp(void)
174 char *live_dev
= NULL
;
179 ret
= RunModeSetLiveCaptureAutoFp(ParseNflogConfig
,
180 NflogConfigGeThreadsCount
,
186 FatalError(SC_ERR_FATAL
, "Unable to start runmode");
189 SCLogInfo("RunModeIdsNflogAutoFp initialised");
190 #endif /* HAVE_NFLOG */
195 int RunModeIdsNflogSingle(void)
201 char *live_dev
= NULL
;
206 ret
= RunModeSetLiveCaptureSingle(ParseNflogConfig
,
207 NflogConfigGeThreadsCount
,
213 FatalError(SC_ERR_FATAL
, "Unable to start runmode");
216 SCLogInfo("RunModeIdsNflogSingle initialised");
217 #endif /* HAVE_NFLOG */
222 int RunModeIdsNflogWorkers(void)
228 char *live_dev
= NULL
;
233 ret
= RunModeSetLiveCaptureWorkers(ParseNflogConfig
,
234 NflogConfigGeThreadsCount
,
240 FatalError(SC_ERR_FATAL
, "Unable to start runmode");
243 SCLogInfo("RunModeIdsNflogWorkers initialised");
244 #endif /* HAVE_NFLOG */