]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
flow-bypass: registration of non periodic check
authorEric Leblond <eric@regit.org>
Tue, 11 Jun 2019 22:40:23 +0000 (00:40 +0200)
committerVictor Julien <victor@inliniac.net>
Tue, 18 Jun 2019 05:07:02 +0000 (07:07 +0200)
This patch adds the capability to register a set of functions
without providing a periodic check function. This permit to
run a task only at init.

src/flow-bypass.c

index 5c8445a016e1e63b3c874436d930048e8d534cc4..fb00d40398d2d1accffcb5489ecd7fcbdb3fba85 100644 (file)
@@ -73,6 +73,17 @@ static TmEcode BypassedFlowManager(ThreadVars *th_v, void *thread_data)
         }
     }
 
+    /* check if we have a periodic check function */
+    bool found = false;
+    for (i = 0; i < g_bypassed_func_max_index; i++) {
+        if (bypassedfunclist[i].FuncInit) {
+            found = true;
+            break;
+        }
+    }
+    if (!found)
+        return TM_ECODE_OK;
+
     while (1) {
         SCLogDebug("Dumping the table");
         if (clock_gettime(CLOCK_REALTIME, &curtime) != 0) {
@@ -81,6 +92,8 @@ static TmEcode BypassedFlowManager(ThreadVars *th_v, void *thread_data)
         }
         for (i = 0; i < g_bypassed_func_max_index; i++) {
             struct flows_stats bypassstats = { 0, 0, 0};
+            if (bypassedfunclist[i].Func == NULL)
+                continue;
             tcount = bypassedfunclist[i].Func(th_v, &bypassstats, &curtime, bypassedfunclist[i].data);
             if (tcount) {
                 StatsAddUI64(th_v, ftd->flow_bypassed_cnt_clo, (uint64_t)bypassstats.count);
@@ -164,9 +177,6 @@ int BypassedFlowManagerRegisterCheckFunc(BypassedCheckFunc CheckFunc,
                                          BypassedCheckFuncInit CheckFuncInit,
                                          void *data)
 {
-    if (!CheckFunc) {
-        return -1;
-    }
     if (g_bypassed_func_max_index < BYPASSFUNCMAX) {
         bypassedfunclist[g_bypassed_func_max_index].Func = CheckFunc;
         bypassedfunclist[g_bypassed_func_max_index].FuncInit = CheckFuncInit;