Napatech code formatting fixes.

remotes/origin/HEAD
Victor Julien 14 years ago
parent 95a5bebb6a
commit e1a309a6b2

@ -48,14 +48,12 @@ void RunModeNapatechRegister(void)
#ifdef HAVE_NAPATECH
default_mode = "auto";
RunModeRegisterNewRunMode(RUNMODE_NAPATECH, "auto",
"Multi threaded Napatech mode",
RunModeNapatechAuto2);
"Multi threaded Napatech mode",
RunModeNapatechAuto2);
return;
#endif
}
#define MAX_NAPATECH_DETECT 2
int RunModeNapatechAuto(DetectEngineCtx *de_ctx) {
#ifdef HAVE_NAPATECH
int i;
@ -106,33 +104,33 @@ int RunModeNapatechAuto(DetectEngineCtx *de_ctx) {
/* create the threads */
ThreadVars *tv_napatechFeed = TmThreadCreatePacketHandler(threadName,"packetpool",
"packetpool",outQueueName,
"simple","pktacqloop");
"packetpool",outQueueName,
"simple","pktacqloop");
if (tv_napatechFeed == NULL) {
fprintf(stderr, "ERROR: TmThreadsCreate failed\n");
exit(EXIT_FAILURE);
fprintf(stderr, "ERROR: TmThreadsCreate failed\n");
exit(EXIT_FAILURE);
}
TmModule *tm_module = TmModuleGetByName("NapatechFeed");
if (tm_module == NULL) {
fprintf(stderr, "ERROR: TmModuleGetByName failed for NapatechFeed\n");
exit(EXIT_FAILURE);
fprintf(stderr, "ERROR: TmModuleGetByName failed for NapatechFeed\n");
exit(EXIT_FAILURE);
}
TmSlotSetFuncAppend (tv_napatechFeed,tm_module,feedName);
tm_module = TmModuleGetByName("NapatechDecode");
if (tm_module == NULL) {
fprintf(stderr, "ERROR: TmModuleGetByName failed for NapatechDecode\n");
exit(EXIT_FAILURE);
fprintf(stderr, "ERROR: TmModuleGetByName failed for NapatechDecode\n");
exit(EXIT_FAILURE);
}
TmSlotSetFuncAppend(tv_napatechFeed,tm_module,feedName);
if (threading_set_cpu_affinity) {
TmThreadSetCPUAffinity(tv_napatechFeed, feed);
TmThreadSetCPUAffinity(tv_napatechFeed, feed);
}
if (TmThreadSpawn(tv_napatechFeed) != TM_ECODE_OK) {
printf("ERROR: TmThreadSpawn failed\n");
exit(EXIT_FAILURE);
printf("ERROR: TmThreadSpawn failed\n");
exit(EXIT_FAILURE);
}
/*
* -------------------------------------------
@ -141,60 +139,60 @@ int RunModeNapatechAuto(DetectEngineCtx *de_ctx) {
/* hard code it for now */
uint16_t detect=0;
/* always create at least one thread */
int thread_max = TmThreadGetNbThreads(DETECT_CPU_SET);
if (thread_max == 0)
thread_max = ncpus * threading_detect_ratio;
if (thread_max < 1)
thread_max = 1;
int thread_max = TmThreadGetNbThreads(DETECT_CPU_SET);
if (thread_max == 0)
thread_max = ncpus * threading_detect_ratio;
if (thread_max < 1)
thread_max = 1;
for (i=0; i< thread_max; i++)
{
snprintf(tname, sizeof(tname),"Detect%"PRIu16"/%"PRIu16,feed,detect++);
threadName = SCStrdup(tname);
snprintf(tname, sizeof(tname),"feed-queue%"PRIu16,feed);
inQueueName = SCStrdup(tname);
ThreadVars *tv_detect = TmThreadCreatePacketHandler(threadName,
inQueueName,"simple",
"packetpool","packetpool","varslot");
if (tv_detect == NULL) {
fprintf(stderr,"ERROR: TmThreadsCreate failed\n");
exit(EXIT_FAILURE);
}
tm_module = TmModuleGetByName("StreamTcp");
if (tm_module == NULL) {
fprintf(stderr, "ERROR: TmModuleGetByName StreamTcp failed\n");
exit(EXIT_FAILURE);
}
TmSlotSetFuncAppend(tv_detect,tm_module,NULL);
tm_module = TmModuleGetByName("Detect");
if (tm_module == NULL) {
fprintf(stderr, "ERROR: TmModuleGetByName Detect failed\n");
exit(EXIT_FAILURE);
}
TmSlotSetFuncAppend(tv_detect,tm_module,(void *)de_ctx);
thread_group_name = SCStrdup("Detect");
if (thread_group_name == NULL) {
fprintf(stderr, "Error allocating memory\n");
exit(EXIT_FAILURE);
}
tv_detect->thread_group_name = thread_group_name;
SetupOutputs(tv_detect);
thread_group_name = SCStrdup("Outputs");
if (thread_group_name == NULL) {
fprintf(stderr, "Error allocating memory\n");
exit(EXIT_FAILURE);
}
tv_detect->thread_group_name = thread_group_name;
if (TmThreadSpawn(tv_detect) != TM_ECODE_OK) {
fprintf(stderr, "ERROR: TmThreadSpawn failed\n");
exit(EXIT_FAILURE);
}
snprintf(tname, sizeof(tname),"Detect%"PRIu16"/%"PRIu16,feed,detect++);
threadName = SCStrdup(tname);
snprintf(tname, sizeof(tname),"feed-queue%"PRIu16,feed);
inQueueName = SCStrdup(tname);
ThreadVars *tv_detect = TmThreadCreatePacketHandler(threadName,
inQueueName,"simple",
"packetpool","packetpool","varslot");
if (tv_detect == NULL) {
fprintf(stderr,"ERROR: TmThreadsCreate failed\n");
exit(EXIT_FAILURE);
}
tm_module = TmModuleGetByName("StreamTcp");
if (tm_module == NULL) {
fprintf(stderr, "ERROR: TmModuleGetByName StreamTcp failed\n");
exit(EXIT_FAILURE);
}
TmSlotSetFuncAppend(tv_detect,tm_module,NULL);
tm_module = TmModuleGetByName("Detect");
if (tm_module == NULL) {
fprintf(stderr, "ERROR: TmModuleGetByName Detect failed\n");
exit(EXIT_FAILURE);
}
TmSlotSetFuncAppend(tv_detect,tm_module,(void *)de_ctx);
thread_group_name = SCStrdup("Detect");
if (thread_group_name == NULL) {
fprintf(stderr, "Error allocating memory\n");
exit(EXIT_FAILURE);
}
tv_detect->thread_group_name = thread_group_name;
SetupOutputs(tv_detect);
thread_group_name = SCStrdup("Outputs");
if (thread_group_name == NULL) {
fprintf(stderr, "Error allocating memory\n");
exit(EXIT_FAILURE);
}
tv_detect->thread_group_name = thread_group_name;
if (TmThreadSpawn(tv_detect) != TM_ECODE_OK) {
fprintf(stderr, "ERROR: TmThreadSpawn failed\n");
exit(EXIT_FAILURE);
}
}
}
@ -252,62 +250,62 @@ int RunModeNapatechAuto2(DetectEngineCtx *de_ctx) {
/* create the threads */
ThreadVars *tv_napatechFeed = TmThreadCreatePacketHandler(threadName,"packetpool",
"packetpool","packetpool",
"packetpool","pktacqloop");
"packetpool","packetpool",
"packetpool","pktacqloop");
if (tv_napatechFeed == NULL) {
fprintf(stderr, "ERROR: TmThreadsCreate failed\n");
exit(EXIT_FAILURE);
fprintf(stderr, "ERROR: TmThreadsCreate failed\n");
exit(EXIT_FAILURE);
}
TmModule *tm_module = TmModuleGetByName("NapatechFeed");
if (tm_module == NULL) {
fprintf(stderr, "ERROR: TmModuleGetByName failed for NapatechFeed\n");
exit(EXIT_FAILURE);
fprintf(stderr, "ERROR: TmModuleGetByName failed for NapatechFeed\n");
exit(EXIT_FAILURE);
}
TmSlotSetFuncAppend (tv_napatechFeed,tm_module,feedName);
tm_module = TmModuleGetByName("NapatechDecode");
if (tm_module == NULL) {
fprintf(stderr, "ERROR: TmModuleGetByName failed for NapatechDecode\n");
exit(EXIT_FAILURE);
fprintf(stderr, "ERROR: TmModuleGetByName failed for NapatechDecode\n");
exit(EXIT_FAILURE);
}
TmSlotSetFuncAppend(tv_napatechFeed,tm_module,feedName);
if (threading_set_cpu_affinity) {
TmThreadSetCPUAffinity(tv_napatechFeed, feed);
TmThreadSetCPUAffinity(tv_napatechFeed, feed);
}
tm_module = TmModuleGetByName("StreamTcp");
if (tm_module == NULL) {
fprintf(stderr, "ERROR: TmModuleGetByName StreamTcp failed\n");
exit(EXIT_FAILURE);
}
TmSlotSetFuncAppend(tv_napatechFeed,tm_module,NULL);
tm_module = TmModuleGetByName("Detect");
if (tm_module == NULL) {
fprintf(stderr, "ERROR: TmModuleGetByName Detect failed\n");
exit(EXIT_FAILURE);
}
TmSlotSetFuncAppend(tv_napatechFeed,tm_module,(void *)de_ctx);
tm_module = TmModuleGetByName("StreamTcp");
if (tm_module == NULL) {
fprintf(stderr, "ERROR: TmModuleGetByName StreamTcp failed\n");
exit(EXIT_FAILURE);
}
TmSlotSetFuncAppend(tv_napatechFeed,tm_module,NULL);
tm_module = TmModuleGetByName("Detect");
if (tm_module == NULL) {
fprintf(stderr, "ERROR: TmModuleGetByName Detect failed\n");
exit(EXIT_FAILURE);
}
TmSlotSetFuncAppend(tv_napatechFeed,tm_module,(void *)de_ctx);
thread_group_name = SCStrdup("Detect");
if (thread_group_name == NULL) {
fprintf(stderr, "Error allocating memory\n");
exit(EXIT_FAILURE);
}
tv_napatechFeed->thread_group_name = thread_group_name;
SetupOutputs(tv_napatechFeed);
thread_group_name = SCStrdup("Outputs");
if (thread_group_name == NULL) {
fprintf(stderr, "Error allocating memory\n");
exit(EXIT_FAILURE);
}
tv_napatechFeed->thread_group_name = thread_group_name;
thread_group_name = SCStrdup("Detect");
if (thread_group_name == NULL) {
fprintf(stderr, "Error allocating memory\n");
exit(EXIT_FAILURE);
}
tv_napatechFeed->thread_group_name = thread_group_name;
SetupOutputs(tv_napatechFeed);
thread_group_name = SCStrdup("Outputs");
if (thread_group_name == NULL) {
fprintf(stderr, "Error allocating memory\n");
exit(EXIT_FAILURE);
}
tv_napatechFeed->thread_group_name = thread_group_name;
if (TmThreadSpawn(tv_napatechFeed) != TM_ECODE_OK) {
printf("ERROR: TmThreadSpawn failed\n");
exit(EXIT_FAILURE);
printf("ERROR: TmThreadSpawn failed\n");
exit(EXIT_FAILURE);
}
#if 0
@ -318,60 +316,60 @@ int RunModeNapatechAuto2(DetectEngineCtx *de_ctx) {
/* hard code it for now */
uint16_t detect=0;
/* always create at least one thread */
int thread_max = TmThreadGetNbThreads(DETECT_CPU_SET);
if (thread_max == 0)
thread_max = ncpus * threading_detect_ratio;
if (thread_max < 1)
thread_max = 1;
int thread_max = TmThreadGetNbThreads(DETECT_CPU_SET);
if (thread_max == 0)
thread_max = ncpus * threading_detect_ratio;
if (thread_max < 1)
thread_max = 1;
for (i=0; i< thread_max; i++)
{
snprintf(tname, sizeof(tname),"Detect%"PRIu16"/%"PRIu16,feed,detect++);
threadName = SCStrdup(tname);
snprintf(tname, sizeof(tname),"feed-queue%"PRIu16,feed);
inQueueName = SCStrdup(tname);
ThreadVars *tv_detect = TmThreadCreatePacketHandler(threadName,
inQueueName,"simple",
"packetpool","packetpool","varslot");
if (tv_detect == NULL) {
fprintf(stderr,"ERROR: TmThreadsCreate failed\n");
exit(EXIT_FAILURE);
}
tm_module = TmModuleGetByName("StreamTcp");
if (tm_module == NULL) {
fprintf(stderr, "ERROR: TmModuleGetByName StreamTcp failed\n");
exit(EXIT_FAILURE);
}
TmSlotSetFuncAppend(tv_detect,tm_module,NULL);
tm_module = TmModuleGetByName("Detect");
if (tm_module == NULL) {
fprintf(stderr, "ERROR: TmModuleGetByName Detect failed\n");
exit(EXIT_FAILURE);
}
TmSlotSetFuncAppend(tv_detect,tm_module,(void *)de_ctx);
thread_group_name = SCStrdup("Detect");
if (thread_group_name == NULL) {
fprintf(stderr, "Error allocating memory\n");
exit(EXIT_FAILURE);
}
tv_detect->thread_group_name = thread_group_name;
SetupOutputs(tv_detect);
thread_group_name = SCStrdup("Outputs");
if (thread_group_name == NULL) {
fprintf(stderr, "Error allocating memory\n");
exit(EXIT_FAILURE);
}
tv_detect->thread_group_name = thread_group_name;
if (TmThreadSpawn(tv_detect) != TM_ECODE_OK) {
fprintf(stderr, "ERROR: TmThreadSpawn failed\n");
exit(EXIT_FAILURE);
}
snprintf(tname, sizeof(tname),"Detect%"PRIu16"/%"PRIu16,feed,detect++);
threadName = SCStrdup(tname);
snprintf(tname, sizeof(tname),"feed-queue%"PRIu16,feed);
inQueueName = SCStrdup(tname);
ThreadVars *tv_detect = TmThreadCreatePacketHandler(threadName,
inQueueName,"simple",
"packetpool","packetpool","varslot");
if (tv_detect == NULL) {
fprintf(stderr,"ERROR: TmThreadsCreate failed\n");
exit(EXIT_FAILURE);
}
tm_module = TmModuleGetByName("StreamTcp");
if (tm_module == NULL) {
fprintf(stderr, "ERROR: TmModuleGetByName StreamTcp failed\n");
exit(EXIT_FAILURE);
}
TmSlotSetFuncAppend(tv_detect,tm_module,NULL);
tm_module = TmModuleGetByName("Detect");
if (tm_module == NULL) {
fprintf(stderr, "ERROR: TmModuleGetByName Detect failed\n");
exit(EXIT_FAILURE);
}
TmSlotSetFuncAppend(tv_detect,tm_module,(void *)de_ctx);
thread_group_name = SCStrdup("Detect");
if (thread_group_name == NULL) {
fprintf(stderr, "Error allocating memory\n");
exit(EXIT_FAILURE);
}
tv_detect->thread_group_name = thread_group_name;
SetupOutputs(tv_detect);
thread_group_name = SCStrdup("Outputs");
if (thread_group_name == NULL) {
fprintf(stderr, "Error allocating memory\n");
exit(EXIT_FAILURE);
}
tv_detect->thread_group_name = thread_group_name;
if (TmThreadSpawn(tv_detect) != TM_ECODE_OK) {
fprintf(stderr, "ERROR: TmThreadSpawn failed\n");
exit(EXIT_FAILURE);
}
}
#endif
}

@ -65,8 +65,8 @@ void TmModuleNapatechDecodeRegister (void) {
TmEcode NoNapatechSupportExit(ThreadVars *tv, void *initdata, void **data)
{
SCLogError(SC_ERR_NAPATECH_NOSUPPORT,
"Error creating thread %s: you do not have support for Napatech adapter "
"enabled please recompile with --enable-napatech", tv->name);
"Error creating thread %s: you do not have support for Napatech adapter "
"enabled please recompile with --enable-napatech", tv->name);
exit(EXIT_FAILURE);
}
@ -102,7 +102,7 @@ TmEcode NapatechDecode(ThreadVars *, Packet *, void *, PacketQueue *, PacketQueu
/**
* \brief Register the Napatech receiver (reader) module.
*/
void
void
TmModuleNapatechFeedRegister(void)
{
tmm_modules[TMM_RECEIVENAPATECH].name = "NapatechFeed";
@ -118,7 +118,7 @@ TmModuleNapatechFeedRegister(void)
/**
* \brief Register the Napatech decoder module.
*/
void
void
TmModuleNapatechDecodeRegister(void)
{
tmm_modules[TMM_DECODENAPATECH].name = "NapatechDecode";
@ -146,7 +146,7 @@ TmModuleNapatechDecodeRegister(void)
* \param data data pointer gets populated with
*
*/
TmEcode
TmEcode
NapatechFeedThreadInit(ThreadVars *tv, void *initdata, void **data)
{
SCEnter();
@ -161,7 +161,7 @@ NapatechFeedThreadInit(ThreadVars *tv, void *initdata, void **data)
NapatechThreadVars *ntv = SCMalloc(sizeof(NapatechThreadVars));
if (ntv == NULL) {
SCLogError(SC_ERR_MEM_ALLOC,
"Failed to allocate memory for NAPATECH thread vars.");
"Failed to allocate memory for NAPATECH thread vars.");
exit(EXIT_FAILURE);
}
@ -171,7 +171,7 @@ NapatechFeedThreadInit(ThreadVars *tv, void *initdata, void **data)
ntv->tv = tv;
/* Use max_pending_packets as our maximum number of packets read
from the NAPATECH buffer.
from the NAPATECH buffer.
*/
ntv->max_read_packets = max_pending_packets;
SCLogInfo("Opening NAPATECH %d:%d for processing", ntv->adapter_number, ntv->feed_number);
@ -210,7 +210,7 @@ TmEcode NapatechFeedLoop(ThreadVars *tv, void *data, void *slot)
while (1) {
if (suricata_ctl_flags & SURICATA_STOP ||
suricata_ctl_flags & SURICATA_KILL)
suricata_ctl_flags & SURICATA_KILL)
{
SCReturnInt(TM_ECODE_OK);
}
@ -223,7 +223,7 @@ TmEcode NapatechFeedLoop(ThreadVars *tv, void *data, void *slot)
}
} while (packet_q_len == 0);
/*
/*
* Napatech returns frames in segment chunks. Function ntci_next_frame
* returns 1 for a frame, 0 if the segment is empty, and -1 on error
*/
@ -232,35 +232,35 @@ TmEcode NapatechFeedLoop(ThreadVars *tv, void *data, void *slot)
/*
* no frames currently available
*/
continue;
continue;
}
else if (status < 0) {
SCLogError(SC_ERR_NAPATECH_FEED_NEXT_FAILED,
"Failed to read from Napatech feed %d:%d",
ntv->adapter_number, ntv->feed_number);
"Failed to read from Napatech feed %d:%d",
ntv->adapter_number, ntv->feed_number);
SCReturnInt(TM_ECODE_FAILED);
}
// beware that storelen is aligned; therefore, it may be larger than "caplen"
caplen = (header->wireLen < header->storeLen) ? header->wireLen : header->storeLen;
Packet *p = PacketGetFromQueueOrAlloc();
if (unlikely(p == NULL)) {
// beware that storelen is aligned; therefore, it may be larger than "caplen"
caplen = (header->wireLen < header->storeLen) ? header->wireLen : header->storeLen;
Packet *p = PacketGetFromQueueOrAlloc();
if (unlikely(p == NULL)) {
SCReturnInt(TM_ECODE_FAILED);
}
}
p->ts.tv_sec = header->ts.tv_sec;
p->ts.tv_usec = header->ts.tv_usec;
SCLogDebug("p->ts.tv_sec %"PRIuMAX"", (uintmax_t)p->ts.tv_sec);
p->datalink = LINKTYPE_ETHERNET;
p->ts.tv_sec = header->ts.tv_sec;
p->ts.tv_usec = header->ts.tv_usec;
SCLogDebug("p->ts.tv_sec %"PRIuMAX"", (uintmax_t)p->ts.tv_sec);
p->datalink = LINKTYPE_ETHERNET;
ntv->pkts++;
ntv->bytes += caplen;
ntv->pkts++;
ntv->bytes += caplen;
if (unlikely(PacketCopyData(p, frame, caplen))) {
TmqhOutputPacketpool(ntv->tv, p);
SCReturnInt(TM_ECODE_FAILED);
}
if (unlikely(PacketCopyData(p, frame, caplen))) {
TmqhOutputPacketpool(ntv->tv, p);
SCReturnInt(TM_ECODE_FAILED);
}
TmThreadsSlotProcessPkt(ntv->tv, ntv->slot, p);
TmThreadsSlotProcessPkt(ntv->tv, ntv->slot, p);
}
@ -273,7 +273,7 @@ TmEcode NapatechFeedLoop(ThreadVars *tv, void *data, void *slot)
* \param tv Pointer to ThreadVars.
* \param data Pointer to data, ErfFileThreadVars.
*/
void
void
NapatechFeedThreadExitStats(ThreadVars *tv, void *data)
{
NapatechThreadVars *ntv = (NapatechThreadVars *)data;
@ -315,7 +315,7 @@ TmEcode NapatechFeedThreadDeinit(ThreadVars *tv, void *data)
* \param pq pointer to the current PacketQueue
*/
TmEcode NapatechDecode(ThreadVars *tv, Packet *p, void *data, PacketQueue *pq,
PacketQueue *postpq)
PacketQueue *postpq)
{
SCEnter();
@ -328,7 +328,7 @@ TmEcode NapatechDecode(ThreadVars *tv, Packet *p, void *data, PacketQueue *pq,
SCPerfCounterAddUI64(dtv->counter_bytes, tv->sc_perf_pca, p->pktlen);
SCPerfCounterAddDouble(dtv->counter_bytes_per_sec, tv->sc_perf_pca, p->pktlen);
SCPerfCounterAddDouble(dtv->counter_mbit_per_sec, tv->sc_perf_pca,
(p->pktlen * 8)/1000000.0);
(p->pktlen * 8)/1000000.0);
SCPerfCounterAddUI64(dtv->counter_avg_pkt_size, tv->sc_perf_pca, p->pktlen);
SCPerfCounterSetUI64(dtv->counter_max_pkt_size, tv->sc_perf_pca, p->pktlen);
@ -339,8 +339,8 @@ TmEcode NapatechDecode(ThreadVars *tv, Packet *p, void *data, PacketQueue *pq,
break;
default:
SCLogError(SC_ERR_DATALINK_UNIMPLEMENTED,
"Error: datalink type %" PRId32 " not yet supported in module DecodeNapatech",
p->datalink);
"Error: datalink type %" PRId32 " not yet supported in module DecodeNapatech",
p->datalink);
break;
}
SCReturnInt(TM_ECODE_OK);

Loading…
Cancel
Save