From 4922cd2d3699a2dcb472adee7569894105f14083 Mon Sep 17 00:00:00 2001 From: Victor Julien Date: Tue, 25 Feb 2014 11:59:05 +0100 Subject: [PATCH] pcap-log: introduce PcapLogThreadData PcapLog uses the global data structure PcapLogData as thread data as well. This is possible because all operations on it are locked. This patch introduces PcapLogThreadData. It contains a pointer to the PcapLogData. Currently to the global instance, but in the future it may hold a thread-local instance of PcapLogData. --- src/log-pcap.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/log-pcap.c b/src/log-pcap.c index 54b59e0e09..c6192bd2f2 100644 --- a/src/log-pcap.c +++ b/src/log-pcap.c @@ -119,6 +119,10 @@ typedef struct PcapLogData_ { TAILQ_HEAD(, PcapFileName_) pcap_file_list; } PcapLogData; +typedef struct PcapLogThreadData_ { + PcapLogData *pcap_log; +} PcapLogThreadData; + static int PcapLogOpenFileCtx(PcapLogData *); static TmEcode PcapLog(ThreadVars *, Packet *, void *, PacketQueue *, PacketQueue *); static TmEcode PcapLogDataInit(ThreadVars *, void *, void **); @@ -308,14 +312,15 @@ static void PcapLogUnlock(PcapLogData *pl) * \retval TM_ECODE_OK on succes * \retval TM_ECODE_FAILED on serious error */ -static TmEcode PcapLog (ThreadVars *t, Packet *p, void *data, PacketQueue *pq, +static TmEcode PcapLog (ThreadVars *t, Packet *p, void *thread_data, PacketQueue *pq, PacketQueue *postpq) { size_t len; int rotate = 0; int ret = 0; - PcapLogData *pl = (PcapLogData *)data; + PcapLogThreadData *td = (PcapLogThreadData *)thread_data; + PcapLogData *pl = td->pcap_log; if ((p->flags & PKT_PSEUDO_STREAM_END) || ((p->flags & PKT_STREAM_NOPCAPLOG) && @@ -391,6 +396,12 @@ static TmEcode PcapLogDataInit(ThreadVars *t, void *initdata, void **data) PcapLogData *pl = ((OutputCtx *)initdata)->data; + PcapLogThreadData *td = SCCalloc(1, sizeof(*td)); + if (unlikely(td == NULL)) + return TM_ECODE_FAILED; + + td->pcap_log = pl; + SCMutexLock(&pl->plog_lock); /** Use the Ouptut Context (file pointer and mutex) */ @@ -406,9 +417,10 @@ static TmEcode PcapLogDataInit(ThreadVars *t, void *initdata, void **data) struct tm *tms = SCLocalTime(ts.tv_sec, &local_tm); pl->prev_day = tms->tm_mday; - *data = (void *)pl; - SCMutexUnlock(&pl->plog_lock); + + *data = (void *)td; + return TM_ECODE_OK; } @@ -421,9 +433,10 @@ static TmEcode PcapLogDataInit(ThreadVars *t, void *initdata, void **data) * \retval TM_ECODE_FAILED on failure */ -static TmEcode PcapLogDataDeinit(ThreadVars *t, void *data) +static TmEcode PcapLogDataDeinit(ThreadVars *t, void *thread_data) { - PcapLogData *pl = data; + PcapLogThreadData *td = (PcapLogThreadData *)thread_data; + PcapLogData *pl = td->pcap_log; if (pl->pcap_dumper != NULL) { if (PcapLogCloseFile(t,pl) < 0) {