Fix tunneled and defrag reassembled packets with the new pending limits.

remotes/origin/master-1.0.x
Victor Julien 16 years ago
parent ccf22cf563
commit 19584d0416

@ -540,6 +540,7 @@ void AddressDebugPrint(Address *);
/*Packet Flags*/
#define PKT_NOPACKET_INSPECTION 0x01 /**< Flag to indicate that packet header or contents should not be inspected*/
#define PKT_NOPAYLOAD_INSPECTION 0x02 /**< Flag to indicate that packet contents should not be inspected*/
#define PKT_ALLOC 0x04 /**< Packet was alloc'd this run, needs to be freed */
#endif /* __DECODE_H__ */

@ -47,13 +47,8 @@ void PacketEnqueue (PacketQueue *q, Packet *p) {
}
Packet *PacketDequeue (PacketQueue *q) {
/* if the queue is empty there are no packets left.
* In that case we sleep and try again. */
/* if the queue is empty there are no packets left. */
if (q->len == 0) {
// printf("PacketDequeue: queue is empty, waiting...\n");
// TmqDebugList();
// usleep(100000); /* sleep 100ms */
// return PacketDequeue(q);
return NULL;
}
@ -64,17 +59,12 @@ Packet *PacketDequeue (PacketQueue *q) {
/* pull the bottom packet from the queue */
Packet *p = q->bot;
#ifdef OS_DARWIN
/* Weird issue in OS_DARWIN
* Sometimes it looks that two thread arrive here at the same time
* so the bot ptr is NULL
/* Weird issue: sometimes it looks that two thread arrive
* here at the same time so the bot ptr is NULL
*/
if (p == NULL) {
printf("No packet to dequeue!\n");
return NULL;
}
#endif
/* more packets in queue */
if (q->bot->prev != NULL) {

@ -119,12 +119,6 @@ void PcapCallback(char *user, struct pcap_pkthdr *h, u_char *pkt) {
PcapThreadVars *ptv = (PcapThreadVars *)user;
ThreadVars *tv = ptv->tv;
SCMutexLock(&mutex_pending);
if (pending > max_pending_packets) {
SCondWait(&cond_pending, &mutex_pending);
}
SCMutexUnlock(&mutex_pending);
Packet *p = tv->tmqh_in(tv);
p->ts.tv_sec = h->ts.tv_sec;
p->ts.tv_usec = h->ts.tv_usec;

@ -216,6 +216,36 @@ Packet *SetupPktWait (void)
return p;
}
Packet *SetupTunnelPkt (void)
{
Packet *p = NULL;
SCMutexLock(&packet_q.mutex_q);
p = PacketDequeue(&packet_q);
SCMutexUnlock(&packet_q.mutex_q);
if (p == NULL) {
p = SCMalloc(sizeof(Packet));
if (p == NULL) {
printf("ERROR: SCMalloc failed: %s\n", strerror(errno));
exit(EXIT_FAILURE);
}
memset(p, 0, sizeof(Packet));
SCMutexInit(&p->mutex_rtv_cnt, NULL);
p->flags |= PKT_ALLOC;
SCLogDebug("allocated a new packet...");
}
/* reset the packet csum fields */
RESET_PACKET_CSUMS(p);
return p;
}
Packet *SetupPkt (void)
{
Packet *p = NULL;
@ -265,8 +295,8 @@ void GlobalInits()
exit(EXIT_FAILURE);
}
SCMutexInit(&mutex_pending, NULL);
SCCondInit(&cond_pending, NULL);
//SCMutexInit(&mutex_pending, NULL);
//SCCondInit(&cond_pending, NULL);
/* initialize packet queues Here! */
memset(&packet_q,0,sizeof(packet_q));
@ -280,7 +310,7 @@ Packet *TunnelPktSetup(ThreadVars *t, DecodeThreadVars *dtv, Packet *parent, uin
//printf("TunnelPktSetup: pkt %p, len %" PRIu32 ", proto %" PRIu32 "\n", pkt, len, proto);
/* get us a packet */
Packet *p = SetupPkt();
Packet *p = SetupTunnelPkt();
/* set the root ptr to the lowest layer */
if (parent->root != NULL)

@ -37,12 +37,12 @@
* XXX this should be turned into an api located
* in the packetpool code
*/
intmax_t pending;
//intmax_t pending;
#ifdef DBG_PERF
uint32_t dbg_maxpending;
//uint32_t dbg_maxpending;
#endif /* DBG_PERF */
SCMutex mutex_pending;
SCCondT cond_pending;
//SCMutex mutex_pending;
//SCCondT cond_pending;
/* Run mode */

@ -1036,7 +1036,7 @@ void TmThreadKillThreads(void) {
//printf("TmThreadKillThreads: (t->inq->reader_cnt + t->inq->writer_cnt) %" PRIu32 "\n", (t->inq->reader_cnt + t->inq->writer_cnt));
/* make sure our packet pending counter doesn't block */
SCCondSignal(&cond_pending);
//SCCondSignal(&cond_pending);
/* signal the queue for the number of users */

@ -50,7 +50,7 @@ Packet *TmqhInputPacketpool(ThreadVars *t)
{
/* XXX */
Packet *p = SetupPkt();
#if 0
SCMutexLock(&mutex_pending);
pending++;
//printf("PcapFileCallback: pending %" PRIu32 "\n", pending);
@ -59,7 +59,7 @@ Packet *TmqhInputPacketpool(ThreadVars *t)
dbg_maxpending = pending;
#endif /* DBG_PERF */
SCMutexUnlock(&mutex_pending);
#endif
/*
* Disabled because it can enter a 'wait' state, while
* keeping the nfq queue locked thus making it impossble
@ -143,20 +143,29 @@ void TmqhOutputPacketpool(ThreadVars *t, Packet *p)
FlowDecrUsecnt(t,p);
if (proot && p->root != NULL) {
CLEAR_PACKET(p->root);
if (p->root->flags & PKT_ALLOC) {
SCMutexDestroy(&p->root->mutex_rtv_cnt);
CLEAR_PACKET(p->root);
SCFree(p->root);
} else {
SCMutexLock(&q->mutex_q);
PacketEnqueue(q, p->root);
SCCondSignal(&q->cond_q);
SCMutexUnlock(&q->mutex_q);
}
}
if (p->flags & PKT_ALLOC) {
SCMutexDestroy(&p->mutex_rtv_cnt);
CLEAR_PACKET(p);
SCFree(p);
} else {
CLEAR_PACKET(p);
SCMutexLock(&q->mutex_q);
PacketEnqueue(q, p->root);
PacketEnqueue(q, p);
SCCondSignal(&q->cond_q);
SCMutexUnlock(&q->mutex_q);
}
CLEAR_PACKET(p);
SCMutexLock(&q->mutex_q);
PacketEnqueue(q, p);
SCCondSignal(&q->cond_q);
SCMutexUnlock(&q->mutex_q);
}
/**

Loading…
Cancel
Save