suricata
runmode.c
Go to the documentation of this file.
1 /* Copyright (C) 2024 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 #include "suricata-common.h"
19 #include "runmodes.h"
20 #include "tm-threads.h"
21 #include "util-affinity.h"
22 
23 #include "runmode.h"
24 
26 {
27  return "autofp";
28 }
29 
30 static int RunModeSingle(void)
31 {
32  SCLogNotice("...");
33 
34  char thread_name[TM_THREAD_NAME_MAX];
35  snprintf(thread_name, sizeof(thread_name), "%s#01", thread_name_single);
37  thread_name, "packetpool", "packetpool", "packetpool", "packetpool", "pktacqloop");
38  if (tv == NULL) {
39  SCLogError("TmThreadCreatePacketHandler failed");
40  return -1;
41  }
42 
43  TmModule *tm_module = TmModuleGetByName("ReceiveCiCapture");
44  if (tm_module == NULL) {
45  FatalError("TmModuleGetByName failed for ReceiveCiCapture");
46  }
47  TmSlotSetFuncAppend(tv, tm_module, NULL);
48 
49  tm_module = TmModuleGetByName("DecodeCiCapture");
50  if (tm_module == NULL) {
51  FatalError("TmModuleGetByName DecodeCiCapture failed");
52  }
53  TmSlotSetFuncAppend(tv, tm_module, NULL);
54 
55  tm_module = TmModuleGetByName("FlowWorker");
56  if (tm_module == NULL) {
57  FatalError("TmModuleGetByName for FlowWorker failed");
58  }
59  TmSlotSetFuncAppend(tv, tm_module, NULL);
60 
62 
63  if (TmThreadSpawn(tv) != TM_ECODE_OK) {
64  FatalError("TmThreadSpawn failed");
65  }
66 
67  return 0;
68 }
69 
70 void CiCaptureIdsRegister(int slot)
71 {
72  RunModeRegisterNewRunMode(slot, "single", "Single threaded", RunModeSingle, NULL);
73 }
tm-threads.h
TmThreadSpawn
TmEcode TmThreadSpawn(ThreadVars *tv)
Spawns a thread associated with the ThreadVars instance tv.
Definition: tm-threads.c:1660
TmThreadCreatePacketHandler
ThreadVars * TmThreadCreatePacketHandler(const char *name, const char *inq_name, const char *inqh_name, const char *outq_name, const char *outqh_name, const char *slots)
Creates and returns a TV instance for a Packet Processing Thread. This function doesn't support custo...
Definition: tm-threads.c:1036
thread_name_single
const char * thread_name_single
Definition: runmodes.c:69
TM_THREAD_NAME_MAX
#define TM_THREAD_NAME_MAX
Definition: tm-threads.h:49
TM_ECODE_OK
@ TM_ECODE_OK
Definition: tm-threads-common.h:84
TmModuleGetByName
TmModule * TmModuleGetByName(const char *name)
get a tm module ptr by name
Definition: tm-modules.c:53
CiCaptureIdsRegister
void CiCaptureIdsRegister(int slot)
Definition: runmode.c:70
RunModeRegisterNewRunMode
void RunModeRegisterNewRunMode(enum RunModes runmode, const char *name, const char *description, int(*RunModeFunc)(void), int(*RunModeIsIPSEnabled)(void))
Registers a new runmode.
Definition: runmodes.c:490
ThreadVars_
Per thread variable structure.
Definition: threadvars.h:57
util-affinity.h
CiCaptureIdsGetDefaultRunMode
const char * CiCaptureIdsGetDefaultRunMode(void)
Definition: runmode.c:25
runmodes.h
TmModule_
Definition: tm-modules.h:44
TmSlotSetFuncAppend
void TmSlotSetFuncAppend(ThreadVars *tv, TmModule *tm, const void *data)
Appends a new entry to the slots.
Definition: tm-threads.c:642
suricata-common.h
TmThreadSetCPU
TmEcode TmThreadSetCPU(ThreadVars *tv, uint8_t type)
Definition: tm-threads.c:816
FatalError
#define FatalError(...)
Definition: util-debug.h:502
tv
ThreadVars * tv
Definition: fuzz_decodepcapfile.c:32
SCLogError
#define SCLogError(...)
Macro used to log ERROR messages.
Definition: util-debug.h:261
runmode.h
WORKER_CPU_SET
@ WORKER_CPU_SET
Definition: util-affinity.h:53
SCLogNotice
#define SCLogNotice(...)
Macro used to log NOTICE messages.
Definition: util-debug.h:237