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 __TM_MODULES_H__
25 #define __TM_MODULES_H__
26 
27 #include "tm-threads-common.h"
28 #include "threadvars.h"
29 
30 /* thread flags */
31 #define TM_FLAG_RECEIVE_TM 0x01
32 #define TM_FLAG_DECODE_TM 0x02
33 #define TM_FLAG_STREAM_TM 0x04
34 #define TM_FLAG_DETECT_TM 0x08
35 #define TM_FLAG_LOGAPI_TM 0x10 /**< TM is run by Log API */
36 #define TM_FLAG_MANAGEMENT_TM 0x20
37 #define TM_FLAG_COMMAND_TM 0x40
38 
39 typedef TmEcode (*ThreadInitFunc)(ThreadVars *, const void *, void **);
40 typedef TmEcode (*ThreadDeinitFunc)(ThreadVars *, void *);
41 typedef void (*ThreadExitPrintStatsFunc)(ThreadVars *, void *);
42 
43 typedef struct TmModule_ {
44  const char *name;
45 
46  /** thread handling */
47  TmEcode (*ThreadInit)(ThreadVars *, const void *, void **);
48  void (*ThreadExitPrintStats)(ThreadVars *, void *);
50 
51  /** the packet processing function */
52  TmEcode (*Func)(ThreadVars *, Packet *, void *, PacketQueue *, PacketQueue *);
53 
54  TmEcode (*PktAcqLoop)(ThreadVars *, void *, void *);
55 
56  /** terminates the capture loop in PktAcqLoop */
58 
59  TmEcode (*Management)(ThreadVars *, void *);
60 
61  /** global Init/DeInit */
62  TmEcode (*Init)(void);
63  TmEcode (*DeInit)(void);
64 
65  void (*RegisterTests)(void);
66 
67  uint8_t cap_flags; /**< Flags to indicate the capability requierment of
68  the given TmModule */
69  /* Other flags used by the module */
70  uint8_t flags;
71 } TmModule;
72 
74 
75 /**
76  * Structure that output modules use to maintain private data.
77  */
78 typedef struct OutputCtx_ {
79 
80  /** Pointer to data private to the output. */
81  void *data;
82 
83  /** Pointer to a cleanup function. */
84  void (*DeInit)(struct OutputCtx_ *);
85 
86  TAILQ_HEAD(, OutputModule_) submodules;
87 } OutputCtx;
88 
89 TmModule *TmModuleGetByName(const char *name);
90 TmModule *TmModuleGetById(int id);
91 int TmModuleGetIdByName(const char *name);
93 TmEcode TmModuleRegister(char *name, int (*module_func)(ThreadVars *, Packet *, void *));
94 void TmModuleDebugList(void);
95 void TmModuleRegisterTests(void);
96 const char * TmModuleTmmIdToString(TmmId id);
97 
98 void TmModuleRunInit(void);
99 void TmModuleRunDeInit(void);
100 
101 #endif /* __TM_MODULES_H__ */
102 
void TmModuleRegisterTests(void)
register all unittests for the tm modules
Definition: tm-modules.c:163
uint8_t cap_flags
Definition: tm-modules.h:67
uint8_t flags
Definition: tm-modules.h:70
void(* ThreadExitPrintStatsFunc)(ThreadVars *, void *)
Definition: tm-modules.h:41
TmEcode(* Func)(ThreadVars *, Packet *, void *, PacketQueue *, PacketQueue *)
Definition: tm-modules.h:52
void TmModuleRunDeInit(void)
Definition: tm-modules.c:144
#define TAILQ_HEAD(name, type)
Definition: queue.h:321
TmEcode(* PktAcqLoop)(ThreadVars *, void *, void *)
Definition: tm-modules.h:54
TmmId
Thread Model Module id&#39;s.
int TmModuleGetIDForTM(TmModule *tm)
Given a TM Module, returns its id.
Definition: tm-modules.c:107
TmEcode(* PktAcqBreakLoop)(ThreadVars *, void *)
Definition: tm-modules.h:57
TmEcode(* ThreadDeinitFunc)(ThreadVars *, void *)
Definition: tm-modules.h:40
void TmModuleRunInit(void)
Definition: tm-modules.c:126
TmEcode(* Management)(ThreadVars *, void *)
Definition: tm-modules.h:59
struct TmModule_ TmModule
void(* RegisterTests)(void)
Definition: tm-modules.h:65
TmEcode(* ThreadDeinit)(ThreadVars *, void *)
Definition: tm-modules.h:49
const char * TmModuleTmmIdToString(TmmId id)
Maps the TmmId, to its string equivalent.
Definition: tm-modules.c:199
void(* ThreadExitPrintStats)(ThreadVars *, void *)
Definition: tm-modules.h:48
TmModule * TmModuleGetById(int id)
Returns a TM Module by its id.
Definition: tm-modules.c:88
TmEcode(* Init)(void)
Definition: tm-modules.h:62
const char * name
Definition: tm-modules.h:44
TmModule tmm_modules[TMM_SIZE]
Definition: tm-modules.h:73
void * data
Definition: tm-modules.h:81
TmEcode(* ThreadInit)(ThreadVars *, const void *, void **)
Definition: tm-modules.h:47
TmModule * TmModuleGetByName(const char *name)
get a tm module ptr by name
Definition: tm-modules.c:51
TmEcode TmModuleRegister(char *name, int(*module_func)(ThreadVars *, Packet *, void *))
TmEcode(* DeInit)(void)
Definition: tm-modules.h:63
Per thread variable structure.
Definition: threadvars.h:57
TmEcode(* ThreadInitFunc)(ThreadVars *, const void *, void **)
Definition: tm-modules.h:39
void TmModuleDebugList(void)
Definition: tm-modules.c:33
int TmModuleGetIdByName(const char *name)
get the id of a module from it&#39;s name
Definition: tm-modules.c:72