suricata
tm-modules.h
Go to the documentation of this file.
1 /* Copyright (C) 2007-2014 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 Victor Julien <victor@inliniac.net>
22  */
23 
24 #ifndef SURICATA_TM_MODULES_H
25 #define SURICATA_TM_MODULES_H
26 
27 #include "tm-threads-common.h"
28 #include "threadvars.h"
29 #include "decode.h"
30 
31 /* thread flags */
32 #define TM_FLAG_RECEIVE_TM 0x01
33 #define TM_FLAG_DECODE_TM 0x02
34 #define TM_FLAG_STREAM_TM 0x04
35 #define TM_FLAG_DETECT_TM 0x08
36 #define TM_FLAG_LOGAPI_TM 0x10 /**< TM is run by Log API */
37 #define TM_FLAG_MANAGEMENT_TM 0x20
38 #define TM_FLAG_COMMAND_TM 0x40
39 
40 typedef TmEcode (*ThreadInitFunc)(ThreadVars *, const void *, void **);
41 typedef TmEcode (*ThreadDeinitFunc)(ThreadVars *, void *);
42 typedef void (*ThreadExitPrintStatsFunc)(ThreadVars *, void *);
43 
44 typedef struct TmModule_ {
45  const char *name;
46 
47  /** thread handling */
48  TmEcode (*ThreadInit)(ThreadVars *, const void *, void **);
49  void (*ThreadExitPrintStats)(ThreadVars *, void *);
51 
52  /** the packet processing function */
53  TmEcode (*Func)(ThreadVars *, Packet *, void *);
54 
55  TmEcode (*PktAcqLoop)(ThreadVars *, void *, void *);
56 
57  /** terminates the capture loop in PktAcqLoop */
59 
60  /** does a thread still have tasks to complete before it can be killed?
61  * \retval bool
62  * \param tv threadvars
63  * \param thread_data thread module thread data (e.g. FlowWorkerThreadData for FlowWorker) */
64  bool (*ThreadBusy)(ThreadVars *tv, void *thread_data);
65 
66  TmEcode (*Management)(ThreadVars *, void *);
67 
68  /** global Init/DeInit */
69  TmEcode (*Init)(void);
70  TmEcode (*DeInit)(void);
71 #ifdef UNITTESTS
72  void (*RegisterTests)(void);
73 #endif
74  uint8_t cap_flags; /**< Flags to indicate the capability requirement of
75  the given TmModule */
76  /* Other flags used by the module */
77  uint8_t flags;
79 
81 
82 /**
83  * Structure that output modules use to maintain private data.
84  */
85 typedef struct OutputCtx_ {
86 
87  /** Pointer to data private to the output. */
88  void *data;
89 
90  /** Pointer to a cleanup function. */
91  void (*DeInit)(struct OutputCtx_ *);
92 
93  TAILQ_HEAD(, OutputModule_) submodules;
95 
96 TmModule *TmModuleGetByName(const char *name);
97 TmModule *TmModuleGetById(int id);
99 TmEcode TmModuleRegister(char *name, int (*module_func)(ThreadVars *, Packet *, void *));
100 void TmModuleDebugList(void);
101 void TmModuleRegisterTests(void);
102 #ifdef PROFILING
103 const char * TmModuleTmmIdToString(TmmId id);
104 #endif
105 void TmModuleRunInit(void);
106 void TmModuleRunDeInit(void);
107 
108 #endif /* SURICATA_TM_MODULES_H */
TmModule_::cap_flags
uint8_t cap_flags
Definition: tm-modules.h:74
TmModuleGetIDForTM
int TmModuleGetIDForTM(TmModule *tm)
Given a TM Module, returns its id.
Definition: tm-modules.c:99
TmModuleGetById
TmModule * TmModuleGetById(int id)
Returns a TM Module by its id.
Definition: tm-modules.c:79
tm-threads-common.h
TmModuleTmmIdToString
const char * TmModuleTmmIdToString(TmmId id)
Maps the TmmId, to its string equivalent.
Definition: tm-modules.c:193
TmModule_::ThreadBusy
bool(* ThreadBusy)(ThreadVars *tv, void *thread_data)
Definition: tm-modules.h:64
TmModuleGetByName
TmModule * TmModuleGetByName(const char *name)
get a tm module ptr by name
Definition: tm-modules.c:53
OutputCtx_::data
void * data
Definition: tm-modules.h:88
TmModule_::PktAcqLoop
TmEcode(* PktAcqLoop)(ThreadVars *, void *, void *)
Definition: tm-modules.h:55
OutputCtx_
Definition: tm-modules.h:85
TmModule_::ThreadDeinit
TmEcode(* ThreadDeinit)(ThreadVars *, void *)
Definition: tm-modules.h:50
TmModuleRegisterTests
void TmModuleRegisterTests(void)
register all unittests for the tm modules
Definition: tm-modules.c:155
decode.h
OutputCtx_::TAILQ_HEAD
TAILQ_HEAD(, OutputModule_) submodules
TmModule_::PktAcqBreakLoop
TmEcode(* PktAcqBreakLoop)(ThreadVars *, void *)
Definition: tm-modules.h:58
TmModule_::Init
TmEcode(* Init)(void)
Definition: tm-modules.h:69
ThreadVars_
Per thread variable structure.
Definition: threadvars.h:57
TmModuleRegister
TmEcode TmModuleRegister(char *name, int(*module_func)(ThreadVars *, Packet *, void *))
TmModule_::Management
TmEcode(* Management)(ThreadVars *, void *)
Definition: tm-modules.h:66
TmModule_::Func
TmEcode(* Func)(ThreadVars *, Packet *, void *)
Definition: tm-modules.h:53
ThreadInitFunc
TmEcode(* ThreadInitFunc)(ThreadVars *, const void *, void **)
Definition: tm-modules.h:40
Packet_
Definition: decode.h:437
TmModuleDebugList
void TmModuleDebugList(void)
Definition: tm-modules.c:35
TMM_SIZE
@ TMM_SIZE
Definition: tm-threads-common.h:79
TmModule_::RegisterTests
void(* RegisterTests)(void)
Definition: tm-modules.h:72
TmEcode
TmEcode
Definition: tm-threads-common.h:83
TmModuleRunDeInit
void TmModuleRunDeInit(void)
Definition: tm-modules.c:136
TmModule_::name
const char * name
Definition: tm-modules.h:45
TmModuleRunInit
void TmModuleRunInit(void)
Definition: tm-modules.c:118
TmModule_
Definition: tm-modules.h:44
OutputCtx_::DeInit
void(* DeInit)(struct OutputCtx_ *)
Definition: tm-modules.h:91
OutputCtx
struct OutputCtx_ OutputCtx
ThreadExitPrintStatsFunc
void(* ThreadExitPrintStatsFunc)(ThreadVars *, void *)
Definition: tm-modules.h:42
TmModule_::ThreadInit
TmEcode(* ThreadInit)(ThreadVars *, const void *, void **)
Definition: tm-modules.h:48
TmmId
TmmId
Thread Model Module id's.
Definition: tm-threads-common.h:33
tv
ThreadVars * tv
Definition: fuzz_decodepcapfile.c:32
TmModule_::ThreadExitPrintStats
void(* ThreadExitPrintStats)(ThreadVars *, void *)
Definition: tm-modules.h:49
threadvars.h
TmModule
struct TmModule_ TmModule
OutputModule_
Definition: output.h:56
tmm_modules
TmModule tmm_modules[TMM_SIZE]
Definition: tm-modules.c:33
TmModule_::flags
uint8_t flags
Definition: tm-modules.h:77
TmModule_::DeInit
TmEcode(* DeInit)(void)
Definition: tm-modules.h:70
ThreadDeinitFunc
TmEcode(* ThreadDeinitFunc)(ThreadVars *, void *)
Definition: tm-modules.h:41