]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
unix-socket: cleanup host table instead of destroying it
authorEric Leblond <eric@regit.org>
Mon, 26 Nov 2012 18:36:09 +0000 (19:36 +0100)
committerEric Leblond <eric@regit.org>
Tue, 27 Nov 2012 12:45:57 +0000 (13:45 +0100)
This patch should fix the bug #637. Between pcap files, it uses a
new function HostCleanup() to clear tag and threshold on host with
an IP regputation. An other consequence of this modification is
that Host init and shutdown are now init and shutdown unconditionaly.

src/host.c
src/host.h
src/runmode-unix-socket.c
src/suricata.c

index 63b3ef3cfe42230f02297cf555381fdc41ab826d..a86fd4250862f4ba0d676b418e5bf772d136dbd3 100644 (file)
@@ -286,6 +286,58 @@ void HostShutdown(void)
     return;
 }
 
+/** \brief Cleanup the host engine
+ *
+ * Cleanup the host engine from tag and threshold.
+ *
+ */
+void HostCleanup(void)
+{
+    Host *h;
+    uint32_t u;
+
+    if (host_hash != NULL) {
+        for (u = 0; u < host_config.hash_size; u++) {
+            h = host_hash[u].head;
+            HostHashRow *hb = &host_hash[u];
+            HRLOCK_LOCK(hb);
+            while (h) {
+                if ((SC_ATOMIC_GET(h->use_cnt) > 0) && (h->iprep != NULL)) {
+                    /* iprep is attached to host only clear tag and threshold */
+                    if (h->tag != NULL) {
+                        DetectTagDataListFree(h->tag);
+                        h->tag = NULL;
+                    }
+                    if (h->threshold != NULL) {
+                        ThresholdListFree(h->threshold);
+                        h->threshold = NULL;
+                    }
+                    h = h->hnext;
+                } else {
+                    Host *n = h->hnext;
+                    /* remove from the hash */
+                    if (h->hprev != NULL)
+                        h->hprev->hnext = h->hnext;
+                    if (h->hnext != NULL)
+                        h->hnext->hprev = h->hprev;
+                    if (hb->head == h)
+                        hb->head = h->hnext;
+                    if (hb->tail == h)
+                        hb->tail = h->hprev;
+                    h->hnext = NULL;
+                    h->hprev = NULL;
+                    HostClearMemory(h);
+                    HostMoveToSpare(h);
+                    h = n;
+                }
+            }
+            HRLOCK_UNLOCK(hb);
+        }
+    }
+
+    return;
+}
+
 /* calculate the hash key for this packet
  *
  * we're using:
index ee835319f89b14202f1cc55f03f3dcee59f90ba1..49b3b7280db5831c73073de1ace72b5f017c8c30 100644 (file)
@@ -133,6 +133,7 @@ SC_ATOMIC_DECLARE(unsigned int,host_prune_idx);
 
 void HostInitConfig(char quiet);
 void HostShutdown(void);
+void HostCleanup(void);
 
 Host *HostLookupHostFromHash (Address *);
 Host *HostGetHostFromHash (Address *);
index 870fa34a4f63167bb32f652a52d546860af77c8f..7ab8717dd2afe67c142c225774d38e8806324ceb 100644 (file)
@@ -273,7 +273,7 @@ TmEcode UnixSocketPcapFilesCheck(void *data)
         SCPerfReleaseResources();
         /* thread killed, we can run non thread-safe shutdown functions */
         FlowShutdown();
-        HostShutdown();
+        HostCleanup();
         StreamTcpFreeConfig(STREAM_VERBOSE);
         DefragDestroy();
         TmqResetQueues();
@@ -299,7 +299,6 @@ TmEcode UnixSocketPcapFilesCheck(void *data)
         PcapFilesFree(cfile);
         SCPerfInitCounterApi();
         DefragInit();
-        HostInitConfig(HOST_QUIET);
         FlowInitConfig(FLOW_QUIET);
         StreamTcpInitConfig(STREAM_VERBOSE);
         RunModeInitializeOutputs();
index 73d7932c9d6b704041d8f3442c1396833b2a57f1..5ef181f9cd08185806994e286443e49d9a4a5b20 100644 (file)
@@ -1805,8 +1805,8 @@ int main(int argc, char **argv)
 #endif /* OS_WIN32 */
 
     PacketPoolInit(max_pending_packets);
+    HostInitConfig(HOST_VERBOSE);
     if (run_mode != RUNMODE_UNIX_SOCKET) {
-        HostInitConfig(HOST_VERBOSE);
         FlowInitConfig(FLOW_VERBOSE);
     }
 
@@ -2076,9 +2076,9 @@ int main(int argc, char **argv)
     if (run_mode != RUNMODE_UNIX_SOCKET) {
         SCPerfReleaseResources();
         FlowShutdown();
-        HostShutdown();
         StreamTcpFreeConfig(STREAM_VERBOSE);
     }
+    HostShutdown();
 
     HTPFreeConfig();
     HTPAtExitPrintStats();