quick way to make max_pending configurable.

remotes/origin/master-1.0.x
Jason Ish 17 years ago committed by Victor Julien
parent 187949b9ad
commit 7142fdb780

@ -25,6 +25,7 @@
#include "util-debug.h" #include "util-debug.h"
#include "conf.h" #include "conf.h"
extern int max_pending_packets;
typedef struct PcapFileGlobalVars_ { typedef struct PcapFileGlobalVars_ {
pcap_t *pcap_handle; pcap_t *pcap_handle;
@ -81,7 +82,7 @@ void PcapFileCallback(char *user, struct pcap_pkthdr *h, u_char *pkt) {
//ThreadVars *tv = ptv->tv; //ThreadVars *tv = ptv->tv;
SCMutexLock(&mutex_pending); SCMutexLock(&mutex_pending);
if (pending > MAX_PENDING) { if (pending > max_pending_packets) {
SCondWait(&cond_pending, &mutex_pending); SCondWait(&cond_pending, &mutex_pending);
} }
SCMutexUnlock(&mutex_pending); SCMutexUnlock(&mutex_pending);

@ -19,6 +19,8 @@
#include "conf.h" #include "conf.h"
#include "util-debug.h" #include "util-debug.h"
extern int max_pending_packets;
/** /**
* \brief Structure to hold thread specific variables. * \brief Structure to hold thread specific variables.
*/ */
@ -91,7 +93,7 @@ void PcapCallback(char *user, struct pcap_pkthdr *h, u_char *pkt) {
ThreadVars *tv = ptv->tv; ThreadVars *tv = ptv->tv;
SCMutexLock(&mutex_pending); SCMutexLock(&mutex_pending);
if (pending > MAX_PENDING) { if (pending > max_pending_packets) {
SCondWait(&cond_pending, &mutex_pending); SCondWait(&cond_pending, &mutex_pending);
} }
SCMutexUnlock(&mutex_pending); SCMutexUnlock(&mutex_pending);

@ -25,6 +25,8 @@ TmEcode ReceivePfringThreadDeinit(ThreadVars *, void *);
TmEcode DecodePfringThreadInit(ThreadVars *, void *, void **); TmEcode DecodePfringThreadInit(ThreadVars *, void *, void **);
TmEcode DecodePfring(ThreadVars *, Packet *, void *, PacketQueue *); TmEcode DecodePfring(ThreadVars *, Packet *, void *, PacketQueue *);
extern int max_pending_packets;
#ifndef HAVE_PFRING #ifndef HAVE_PFRING
/*Handle cases where we don't have PF_RING support built-in*/ /*Handle cases where we don't have PF_RING support built-in*/
@ -128,7 +130,7 @@ void PfringProcessPacket(void *user, struct pfring_pkthdr *h, u_char *pkt, Packe
/* We need this otherwise the other queues can't seem to keep up on busy networks */ /* We need this otherwise the other queues can't seem to keep up on busy networks */
SCMutexLock(&mutex_pending); SCMutexLock(&mutex_pending);
if (pending > MAX_PENDING) { if (pending > max_pending_packets) {
SCondWait(&cond_pending, &mutex_pending); SCondWait(&cond_pending, &mutex_pending);
} }
SCMutexUnlock(&mutex_pending); SCMutexUnlock(&mutex_pending);
@ -260,7 +262,7 @@ void ReceivePfringThreadExitStats(ThreadVars *tv, void *data) {
pfring_stat pfring_s; pfring_stat pfring_s;
if(pfring_stats(ptv->pd, &pfring_s) < 0) { if(pfring_stats(ptv->pd, &pfring_s) < 0) {
SCLogError(SC_ERR_STAT_ERROR,"(%s) Failed to get pfring stats", tv->name); SCLogError(SC_ERR_STAT, "(%s) Failed to get pfring stats", tv->name);
SCLogInfo("(%s) Packets %" PRIu32 ", bytes %" PRIu64 "", tv->name, ptv->pkts, ptv->bytes); SCLogInfo("(%s) Packets %" PRIu32 ", bytes %" PRIu64 "", tv->name, ptv->pkts, ptv->bytes);
return; return;

@ -102,6 +102,9 @@ volatile sig_atomic_t sigint_count = 0;
volatile sig_atomic_t sighup_count = 0; volatile sig_atomic_t sighup_count = 0;
volatile sig_atomic_t sigterm_count = 0; volatile sig_atomic_t sigterm_count = 0;
/* Max packets processed simultaniously. */
#define DEFAULT_MAX_PENDING_PACKETS 50
#define SURICATA_SIGINT 0x01 #define SURICATA_SIGINT 0x01
#define SURICATA_SIGHUP 0x02 #define SURICATA_SIGHUP 0x02
#define SURICATA_SIGTERM 0x04 #define SURICATA_SIGTERM 0x04
@ -113,6 +116,9 @@ static uint8_t sigflags = 0;
/* Run mode selected */ /* Run mode selected */
int run_mode = MODE_UNKNOWN; int run_mode = MODE_UNKNOWN;
/* Maximum packets to simultaneously process. */
intmax_t max_pending_packets;
int RunmodeIsUnittests(void) { int RunmodeIsUnittests(void) {
if (run_mode == MODE_UNITTEST) if (run_mode == MODE_UNITTEST)
return 1; return 1;
@ -578,6 +584,12 @@ int main(int argc, char **argv)
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
/* Pull the max pending packets from the config, if not found fall
* back on a sane default. */
if (ConfGetInt("max-pending-packets", &max_pending_packets) != 1)
max_pending_packets = DEFAULT_MAX_PENDING_PACKETS;
SCLogDebug("Max pending packets set to %"PRIiMAX, max_pending_packets);
/* Since our config is now loaded we can finish configurating the /* Since our config is now loaded we can finish configurating the
* logging module. */ * logging module. */
SCLogLoadConfig(); SCLogLoadConfig();
@ -721,7 +733,7 @@ int main(int argc, char **argv)
/* pre allocate packets */ /* pre allocate packets */
SCLogInfo("preallocating packets... packet size %" PRIuMAX "", (uintmax_t)sizeof(Packet)); SCLogInfo("preallocating packets... packet size %" PRIuMAX "", (uintmax_t)sizeof(Packet));
int i = 0; int i = 0;
for (i = 0; i < MAX_PENDING; i++) { for (i = 0; i < max_pending_packets; i++) {
/* XXX pkt alloc function */ /* XXX pkt alloc function */
Packet *p = malloc(sizeof(Packet)); Packet *p = malloc(sizeof(Packet));
if (p == NULL) { if (p == NULL) {
@ -733,7 +745,7 @@ int main(int argc, char **argv)
PacketEnqueue(&packet_q,p); PacketEnqueue(&packet_q,p);
} }
SCLogInfo("preallocating packets... done: total memory %"PRIuMAX"", (uintmax_t)(MAX_PENDING*sizeof(Packet))); SCLogInfo("preallocating packets... done: total memory %"PRIuMAX"", (uintmax_t)(max_pending_packets*sizeof(Packet)));
FlowInitConfig(FLOW_VERBOSE); FlowInitConfig(FLOW_VERBOSE);

@ -16,16 +16,13 @@
#define PROG_NAME "Suricata" #define PROG_NAME "Suricata"
#define PROG_VER "0.8.0" #define PROG_VER "0.8.0"
/* max packets processed simultaniously */
#define MAX_PENDING 50
/* number of packets in processing right now /* number of packets in processing right now
* This is the diff between recv'd and verdicted * This is the diff between recv'd and verdicted
* pkts * pkts
* XXX this should be turned into an api located * XXX this should be turned into an api located
* in the packetpool code * in the packetpool code
*/ */
uint32_t pending; intmax_t pending;
#ifdef DBG_PERF #ifdef DBG_PERF
uint32_t dbg_maxpending; uint32_t dbg_maxpending;
#endif /* DBG_PERF */ #endif /* DBG_PERF */

@ -15,6 +15,8 @@
#include "tmqh-packetpool.h" #include "tmqh-packetpool.h"
extern int max_pending_packets;
void TmqhPacketpoolRegister (void) { void TmqhPacketpoolRegister (void) {
tmqh_table[TMQH_PACKETPOOL].name = "packetpool"; tmqh_table[TMQH_PACKETPOOL].name = "packetpool";
tmqh_table[TMQH_PACKETPOOL].InHandler = TmqhInputPacketpool; tmqh_table[TMQH_PACKETPOOL].InHandler = TmqhInputPacketpool;
@ -137,7 +139,7 @@ void TmqhOutputPacketpool(ThreadVars *t, Packet *p)
} else { } else {
printf("TmqhOutputPacketpool: warning, trying to subtract from 0 pending counter.\n"); printf("TmqhOutputPacketpool: warning, trying to subtract from 0 pending counter.\n");
} }
if (pending <= MAX_PENDING) if (pending <= max_pending_packets)
SCCondSignal(&cond_pending); SCCondSignal(&cond_pending);
SCMutexUnlock(&mutex_pending); SCMutexUnlock(&mutex_pending);
} }

@ -1,6 +1,10 @@
%YAML 1.1 %YAML 1.1
--- ---
# Number of packets allowed to be processed simultaneously. Default is a
# conservative 50.
#max-pending-packets: 50
# The default logging directory. Any log or output file will be # The default logging directory. Any log or output file will be
# placed here if its not specified with a full path name. This can be # placed here if its not specified with a full path name. This can be
# overridden with the -l command line parameter. # overridden with the -l command line parameter.

Loading…
Cancel
Save