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 
30 {
31  char tname[TM_THREAD_NAME_MAX];
32  TmModule *tm_module = NULL;
33  snprintf(tname, sizeof(tname), "%s#%02d", thread_name_workers, worker_id);
34 
36  tname, "packetpool", "packetpool", "packetpool", "packetpool", "lib");
37  if (tv == NULL) {
38  SCLogError("TmThreadsCreate failed");
39  return NULL;
40  }
41 
42  tm_module = TmModuleGetByName("DecodeLib");
43  if (tm_module == NULL) {
44  SCLogError("TmModuleGetByName DecodeLib failed");
45  return NULL;
46  }
47  TmSlotSetFuncAppend(tv, tm_module, NULL);
48 
49  tm_module = TmModuleGetByName("FlowWorker");
50  if (tm_module == NULL) {
51  SCLogError("TmModuleGetByName for FlowWorker failed");
52  return NULL;
53  }
54  TmSlotSetFuncAppend(tv, tm_module, NULL);
55 
57 
58  return tv;
59 }
60 
61 /** \brief start the "fake" worker.
62  *
63  * This method performs all the initialization tasks.
64  */
66 {
67  ThreadVars *tv = (ThreadVars *)td;
68 
70  SCLogError("TmThreadLibSpawn failed");
71  return -1;
72  }
73 
75  return 0;
76 }
thread_name_workers
const char * thread_name_workers
Definition: runmodes.c:68
tm-threads.h
TmThreadLibSpawn
TmEcode TmThreadLibSpawn(ThreadVars *tv)
Spawns a "fake" lib thread associated with the ThreadVars instance tv.
Definition: tm-threads.c:1759
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:1070
TmThreadsSetFlag
void TmThreadsSetFlag(ThreadVars *tv, uint32_t flag)
Set a thread flag.
Definition: tm-threads.c:103
THV_RUNNING
#define THV_RUNNING
Definition: threadvars.h:55
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:81
TmModuleGetByName
TmModule * TmModuleGetByName(const char *name)
get a tm module ptr by name
Definition: tm-modules.c:46
ThreadVars_
Per thread variable structure.
Definition: threadvars.h:58
SCRunModeLibSpawnWorker
int SCRunModeLibSpawnWorker(void *td)
start the "fake" worker.
Definition: runmode-lib.c:65
ThreadVars_::type
uint8_t type
Definition: threadvars.h:71
runmodes.h
TmModule_
Definition: tm-modules.h:47
TmSlotSetFuncAppend
void TmSlotSetFuncAppend(ThreadVars *tv, TmModule *tm, const void *data)
Appends a new entry to the slots.
Definition: tm-threads.c:660
TmThreadAppend
void TmThreadAppend(ThreadVars *tv, int type)
Appends this TV to tv_root based on its type.
Definition: tm-threads.c:1186
suricata-common.h
tv
ThreadVars * tv
Definition: fuzz_decodepcapfile.c:33
SCLogError
#define SCLogError(...)
Macro used to log ERROR messages.
Definition: util-debug.h:274
SCRunModeLibCreateThreadVars
ThreadVars * SCRunModeLibCreateThreadVars(int worker_id)
Create ThreadVars for use by a user provided thread.
Definition: runmode-lib.c:29
runmode-lib.h