32#ifdef CAPTURE_OFFLOAD_MANAGER
34#define FLOW_BYPASS_DELAY 10
36#ifndef TIMEVAL_TO_TIMESPEC
37#define TIMEVAL_TO_TIMESPEC(tv, ts) { \
38 (ts)->tv_sec = (tv)->tv_sec; \
39 (ts)->tv_nsec = (tv)->tv_usec * 1000; \
43typedef struct BypassedFlowManagerThreadData_ {
44 uint16_t flow_bypassed_cnt_clo;
45 uint16_t flow_bypassed_pkts;
46 uint16_t flow_bypassed_bytes;
47} BypassedFlowManagerThreadData;
49#define BYPASSFUNCMAX 4
51typedef struct BypassedCheckFuncItem_ {
55} BypassedCheckFuncItem;
57int g_bypassed_func_max_index = 0;
58BypassedCheckFuncItem bypassedfunclist[BYPASSFUNCMAX];
60typedef struct BypassedUpdateFuncItem_ {
63} BypassedUpdateFuncItem;
65int g_bypassed_update_max_index = 0;
66BypassedUpdateFuncItem updatefunclist[BYPASSFUNCMAX];
72 BypassedFlowManagerThreadData *ftd = thread_data;
73 struct timespec curtime = {0, 0};
76 gettimeofday(&
tv, NULL);
77 TIMEVAL_TO_TIMESPEC(&
tv, &curtime);
79 for (i = 0; i < g_bypassed_func_max_index; i++) {
80 if (bypassedfunclist[i].FuncInit) {
81 bypassedfunclist[i].FuncInit(th_v, &curtime, bypassedfunclist[i].data);
87 for (i = 0; i < g_bypassed_func_max_index; i++) {
88 if (bypassedfunclist[i].FuncInit) {
101 gettimeofday(&
tv, NULL);
102 TIMEVAL_TO_TIMESPEC(&
tv, &curtime);
104 for (i = 0; i < g_bypassed_func_max_index; i++) {
106 if (bypassedfunclist[i].Func == NULL)
108 tcount = bypassedfunclist[i].Func(th_v, &bypassstats, &curtime, bypassedfunclist[i].data);
120 for (i = 0; i < FLOW_BYPASS_DELAY * 100; i++) {
132static TmEcode BypassedFlowManagerThreadInit(
ThreadVars *t,
const void *initdata,
void **data)
134 BypassedFlowManagerThreadData *ftd =
SCCalloc(1,
sizeof(BypassedFlowManagerThreadData));
158 if (g_bypassed_func_max_index < BYPASSFUNCMAX) {
159 bypassedfunclist[g_bypassed_func_max_index].Func = CheckFunc;
160 bypassedfunclist[g_bypassed_func_max_index].FuncInit = CheckFuncInit;
161 bypassedfunclist[g_bypassed_func_max_index].data = data;
162 g_bypassed_func_max_index++;
175 if (g_bypassed_update_max_index < BYPASSFUNCMAX) {
176 updatefunclist[g_bypassed_update_max_index].Func = UpdateFunc;
177 updatefunclist[g_bypassed_update_max_index].data = data;
178 g_bypassed_update_max_index++;
189#ifdef CAPTURE_OFFLOAD_MANAGER
193 "BypassedFlowManager", 0);
194 BUG_ON(tv_flowmgr == NULL);
196 if (tv_flowmgr == NULL) {
197 printf(
"ERROR: TmThreadsCreate failed\n");
201 printf(
"ERROR: TmThreadSpawn failed\n");
209#ifdef CAPTURE_OFFLOAD_MANAGER
210 for (
int i = 0; i < g_bypassed_update_max_index; i++) {
211 if (updatefunclist[i].Func(f, p, updatefunclist[i].data)) {
220#ifdef CAPTURE_OFFLOAD_MANAGER
void StatsSyncCounters(ThreadVars *tv)
uint16_t StatsRegisterCounter(const char *name, struct ThreadVars_ *tv)
Registers a normal, unqualified counter.
void StatsSyncCountersIfSignalled(ThreadVars *tv)
void StatsAddUI64(ThreadVars *tv, uint16_t id, uint64_t x)
Adds a value of type uint64_t to the local counter.
void BypassedFlowManagerThreadSpawn(void)
spawn the flow bypass manager thread
void BypassedFlowUpdate(Flow *f, Packet *p)
void TmModuleBypassedFlowManagerRegister(void)
int(* BypassedCheckFuncInit)(ThreadVars *th_v, struct timespec *curtime, void *data)
int(* BypassedCheckFunc)(ThreadVars *th_v, struct flows_stats *bypassstats, struct timespec *curtime, void *data)
int BypassedFlowManagerRegisterUpdateFunc(BypassedUpdateFunc UpdateFunc, void *data)
int BypassedFlowManagerRegisterCheckFunc(BypassedCheckFunc CheckFunc, BypassedCheckFuncInit CheckFuncInit, void *data)
int(* BypassedUpdateFunc)(Flow *f, Packet *p, void *data)
const char * thread_name_flow_bypass
Per thread variable structure.
TmEcode(* ThreadDeinit)(ThreadVars *, void *)
TmEcode(* ThreadInit)(ThreadVars *, const void *, void **)
TmEcode(* Management)(ThreadVars *, void *)
TmModule tmm_modules[TMM_SIZE]
#define TM_FLAG_MANAGEMENT_TM
@ TMM_BYPASSEDFLOWMANAGER
int TmThreadsCheckFlag(ThreadVars *tv, uint32_t flag)
Check if a thread flag is set.
ThreadVars * TmThreadCreateMgmtThreadByName(const char *name, const char *module, int mucond)
Creates and returns the TV instance for a Management thread(MGMT). This function supports only custom...
bool TmThreadsWaitForUnpause(ThreadVars *tv)
Wait for a thread to become unpaused.
void TmThreadsSetFlag(ThreadVars *tv, uint32_t flag)
Set a thread flag.
TmEcode TmThreadSpawn(ThreadVars *tv)
Spawns a thread associated with the ThreadVars instance tv.