unix-socket: cleanup host table instead of destroying it

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.
pull/230/head
Eric Leblond 12 years ago
parent d9eaa0d340
commit 12fd60b545

@ -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:

@ -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 *);

@ -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();

@ -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();

Loading…
Cancel
Save