suricata
runmode-lib.c
Go to the documentation of this file.
1/* Copyright (C) 2023-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/** \file
19 *
20 * \author Angelo Mirabella <angelo.mirabella@broadcom.com>
21 *
22 * Library runmode.
23 */
24#include "suricata-common.h"
25#include "runmode-lib.h"
26#include "runmodes.h"
27#include "tm-threads.h"
28
29/** \brief register runmodes for suricata as a library */
31{
32 RunModeRegisterNewRunMode(RUNMODE_LIB, "offline", "Library offline mode (pcap replaying)",
34 RunModeRegisterNewRunMode(RUNMODE_LIB, "live", "Library live mode", SCRunModeLibIdsLive, NULL);
35 return;
36}
37
38/** \brief runmode for offline packet processing (pcap files) */
40{
42
43 return 0;
44}
45
46/** \brief runmode for live packet processing */
48{
50
51 return 0;
52}
53
55{
56 return "live";
57}
58
60{
61 char tname[TM_THREAD_NAME_MAX];
62 TmModule *tm_module = NULL;
63 snprintf(tname, sizeof(tname), "%s#%02d", thread_name_workers, worker_id);
64
66 tname, "packetpool", "packetpool", "packetpool", "packetpool", "lib");
67 if (tv == NULL) {
68 SCLogError("TmThreadsCreate failed");
69 return NULL;
70 }
71
72 tm_module = TmModuleGetByName("DecodeLib");
73 if (tm_module == NULL) {
74 SCLogError("TmModuleGetByName DecodeLib failed");
75 return NULL;
76 }
77 TmSlotSetFuncAppend(tv, tm_module, NULL);
78
79 tm_module = TmModuleGetByName("FlowWorker");
80 if (tm_module == NULL) {
81 SCLogError("TmModuleGetByName for FlowWorker failed");
82 return NULL;
83 }
84 TmSlotSetFuncAppend(tv, tm_module, NULL);
85
87
88 return tv;
89}
90
91/** \brief start the "fake" worker.
92 *
93 * This method performs all the initialization tasks.
94 */
96{
97 ThreadVars *tv = (ThreadVars *)td;
98
100 SCLogError("TmThreadLibSpawn failed");
101 return -1;
102 }
103
105 return 0;
106}
ThreadVars * tv
int SCRunModeLibIdsLive(void)
runmode for live packet processing
Definition runmode-lib.c:47
int SCRunModeLibIdsOffline(void)
runmode for offline packet processing (pcap files)
Definition runmode-lib.c:39
ThreadVars * SCRunModeLibCreateThreadVars(int worker_id)
Create ThreadVars for use by a user provided thread.
Definition runmode-lib.c:59
int SCRunModeLibSpawnWorker(void *td)
start the "fake" worker.
Definition runmode-lib.c:95
void SCRunModeLibIdsRegister(void)
register runmodes for suricata as a library
Definition runmode-lib.c:30
const char * SCRunModeLibGetDefaultMode(void)
runmode default mode (live)
Definition runmode-lib.c:54
void RunModeRegisterNewRunMode(enum SCRunModes runmode, const char *name, const char *description, int(*RunModeFunc)(void), int(*RunModeIsIPSEnabled)(void))
Registers a new runmode.
Definition runmodes.c:486
const char * thread_name_workers
Definition runmodes.c:68
@ RUNMODE_LIB
Definition runmodes.h:40
Per thread variable structure.
Definition threadvars.h:58
uint8_t type
Definition threadvars.h:72
#define THV_RUNNING
Definition threadvars.h:55
TmModule * TmModuleGetByName(const char *name)
get a tm module ptr by name
Definition tm-modules.c:46
@ TM_ECODE_OK
void TmSlotSetFuncAppend(ThreadVars *tv, TmModule *tm, const void *data)
Appends a new entry to the slots.
Definition tm-threads.c:658
void TmThreadAppend(ThreadVars *tv, int type)
Appends this TV to tv_root based on its type.
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...
TmEcode TmThreadLibSpawn(ThreadVars *tv)
Spawns a "fake" lib thread associated with the ThreadVars instance tv.
void TmThreadsSetFlag(ThreadVars *tv, uint32_t flag)
Set a thread flag.
Definition tm-threads.c:101
#define TM_THREAD_NAME_MAX
Definition tm-threads.h:49
#define SCLogError(...)
Macro used to log ERROR messages.
Definition util-debug.h:267
void TimeModeSetLive(void)
Definition util-time.c:99
void TimeModeSetOffline(void)
Definition util-time.c:105