From 391e69e69932826b2e4c93fac6779708415cad22 Mon Sep 17 00:00:00 2001 From: Victor Julien Date: Sun, 23 Aug 2009 14:55:57 +0200 Subject: [PATCH] Fix tunnel packet handling. --- src/eidps.c | 8 +++++--- src/tmqh-packetpool.c | 19 ++++++++++++++----- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/eidps.c b/src/eidps.c index 25b10c7fa7..34e080e261 100644 --- a/src/eidps.c +++ b/src/eidps.c @@ -126,7 +126,8 @@ Packet *SetupPktWait (void) * we can exit on signals received */ } } while (p == NULL); - memset(p, 0, sizeof(Packet)); + + memset(p, 0, sizeof(Packet)); return p; } @@ -161,7 +162,8 @@ 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 = NULL; + Packet *p = SetupPkt(); +#if 0 do { mutex_lock(&packet_q.mutex_q); p = PacketDequeue(&packet_q); @@ -175,7 +177,7 @@ Packet *TunnelPktSetup(ThreadVars *t, DecodeThreadVars *dtv, Packet *parent, uin * we can exit on signals received */ } } while (p == NULL); - +#endif mutex_lock(&mutex_pending); pending++; #ifdef DBG_PERF diff --git a/src/tmqh-packetpool.c b/src/tmqh-packetpool.c index f466b11afb..98a1be3678 100644 --- a/src/tmqh-packetpool.c +++ b/src/tmqh-packetpool.c @@ -90,7 +90,7 @@ void TmqhOutputPacketpool(ThreadVars *t, Packet *p) TUNNEL_DECR_PKT_TPR_NOLOCK(p); /* handle the root */ - //printf("TmqhOutputPacketpool: calling PacketEnqueue for root pkt\n"); + //printf("TmqhOutputPacketpool: calling PacketEnqueue for root pkt, p->root %p (%p)\n", p->root, p); proot = 1; /* fall through */ @@ -107,15 +107,17 @@ void TmqhOutputPacketpool(ThreadVars *t, Packet *p) FlowDecrUsecnt(t,p); - if (proot) { + if (proot && p->root != NULL) { CLEAR_PACKET(p->root); + + mutex_lock(&q->mutex_q); + PacketEnqueue(q, p->root); + mutex_unlock(&q->mutex_q); } + CLEAR_PACKET(p); mutex_lock(&q->mutex_q); - if (proot) { - PacketEnqueue(q, p->root); - } PacketEnqueue(q, p); mutex_unlock(&q->mutex_q); @@ -123,6 +125,13 @@ void TmqhOutputPacketpool(ThreadVars *t, Packet *p) //printf("TmqhOutputPacketpool: pending %" PRIu32 "\n", pending); if (pending > 0) { pending--; + if (proot) { + if (pending > 0) { + pending--; + } else { + printf("TmqhOutputPacketpool: warning, trying to subtract from 0 pending counter (tunnel root).\n"); + } + } } else { printf("TmqhOutputPacketpool: warning, trying to subtract from 0 pending counter.\n"); }