Undo tunnel reference counting using atomic operations. Revert to mutex based code.

remotes/origin/master-1.1.x
Victor Julien 14 years ago
parent 63f834d9a7
commit c590bba4a4

@ -410,9 +410,15 @@ typedef struct Packet_
/** packet number in the pcap file, matches wireshark */
uint64_t pcap_cnt;
/** mutex to protect access to:
* - tunnel_rtv_cnt
* - tunnel_tpr_cnt
*/
SCMutex tunnel_mutex;
/* ready to set verdict counter, only set in root */
SC_ATOMIC_DECLARE(unsigned short, tunnel_rtv_cnt);
SC_ATOMIC_DECLARE(unsigned short, tunnel_tpr_cnt);
uint16_t tunnel_rtv_cnt;
/* tunnel packet ref count */
uint16_t tunnel_tpr_cnt;
/* engine events */
PacketEngineEvents events;
@ -547,16 +553,14 @@ typedef struct DecodeThreadVars_
#ifndef __SC_CUDA_SUPPORT__
#define PACKET_INITIALIZE(p) { \
memset((p), 0x00, SIZE_OF_PACKET); \
SC_ATOMIC_INIT(p->tunnel_rtv_cnt); \
SC_ATOMIC_INIT(p->tunnel_tpr_cnt); \
SCMutexInit(&(p)->tunnel_mutex, NULL); \
PACKET_RESET_CHECKSUMS((p)); \
(p)->pkt = ((uint8_t *)(p)) + sizeof(Packet); \
}
#else
#define PACKET_INITIALIZE(p) { \
memset((p), 0x00, SIZE_OF_PACKET); \
SC_ATOMIC_INIT(p->tunnel_rtv_cnt); \
SC_ATOMIC_INIT(p->tunnel_tpr_cnt); \
SCMutexInit(&(p)->tunnel_mutex, NULL); \
PACKET_RESET_CHECKSUMS((p)); \
SCMutexInit(&(p)->cuda_mutex, NULL); \
SCCondInit(&(p)->cuda_cond, NULL); \
@ -619,8 +623,10 @@ typedef struct DecodeThreadVars_
(p)->pktlen = 0; \
(p)->alerts.cnt = 0; \
(p)->pcap_cnt = 0; \
SC_ATOMIC_RESET((p)->tunnel_rtv_cnt); \
SC_ATOMIC_RESET((p)->tunnel_tpr_cnt); \
(p)->tunnel_rtv_cnt = 0; \
(p)->tunnel_tpr_cnt = 0; \
SCMutexDestroy(&(p)->tunnel_mutex); \
SCMutexInit(&(p)->tunnel_mutex, NULL); \
(p)->events.cnt = 0; \
(p)->next = NULL; \
(p)->prev = NULL; \
@ -650,16 +656,14 @@ typedef struct DecodeThreadVars_
if ((p)->pktvar != NULL) { \
PktVarFree((p)->pktvar); \
} \
SC_ATOMIC_DESTROY((p)->tunnel_rtv_cnt); \
SC_ATOMIC_DESTROY((p)->tunnel_tpr_cnt); \
SCMutexDestroy(&(p)->tunnel_mutex); \
} while (0)
#else
#define PACKET_CLEANUP(p) do { \
if ((p)->pktvar != NULL) { \
PktVarFree((p)->pktvar); \
} \
SC_ATOMIC_DESTROY((p)->tunnel_rtv_cnt); \
SC_ATOMIC_DESTROY((p)->tunnel_tpr_cnt); \
SCMutexDestroy(&(p)->tunnel_mutex); \
SCMutexDestroy(&(p)->cuda_mutex); \
SCCondDestroy(&(p)->cuda_cond); \
} while(0)
@ -712,35 +716,29 @@ typedef struct DecodeThreadVars_
} while (0)
#define TUNNEL_INCR_PKT_RTV(p) do { \
if ((p)->root != NULL) { \
SC_ATOMIC_ADD((p)->root->tunnel_rtv_cnt, 1); \
} else { \
SC_ATOMIC_ADD((p)->tunnel_rtv_cnt, 1); \
} \
SCMutexLock((p)->root ? &(p)->root->tunnel_mutex : &(p)->tunnel_mutex); \
((p)->root ? (p)->root->tunnel_rtv_cnt++ : (p)->tunnel_rtv_cnt++); \
SCMutexUnlock((p)->root ? &(p)->root->tunnel_mutex : &(p)->tunnel_mutex); \
} while (0)
#define TUNNEL_INCR_PKT_TPR(p) do { \
if ((p)->root != NULL) { \
SC_ATOMIC_ADD((p)->root->tunnel_tpr_cnt, 1); \
} else { \
SC_ATOMIC_ADD((p)->tunnel_tpr_cnt, 1); \
} \
SCMutexLock((p)->root ? &(p)->root->tunnel_mutex : &(p)->tunnel_mutex); \
((p)->root ? (p)->root->tunnel_tpr_cnt++ : (p)->tunnel_tpr_cnt++); \
SCMutexUnlock((p)->root ? &(p)->root->tunnel_mutex : &(p)->tunnel_mutex); \
} while (0)
#define TUNNEL_DECR_PKT_TPR(p) do { \
if ((p)->root != NULL) { \
SC_ATOMIC_SUB((p)->root->tunnel_tpr_cnt, 1); \
} else { \
SC_ATOMIC_SUB((p)->tunnel_tpr_cnt, 1); \
} \
SCMutexLock((p)->root ? &(p)->root->tunnel_mutex : &(p)->tunnel_mutex); \
((p)->root ? (p)->root->tunnel_tpr_cnt-- : (p)->tunnel_tpr_cnt--); \
SCMutexUnlock((p)->root ? &(p)->root->tunnel_mutex : &(p)->tunnel_mutex); \
} while (0)
#define TUNNEL_PKT_RTV(p) ((p)->root ? \
SC_ATOMIC_GET((p)->root->tunnel_rtv_cnt) : \
SC_ATOMIC_GET((p)->tunnel_rtv_cnt))
#define TUNNEL_PKT_TPR(p) ((p)->root ? \
SC_ATOMIC_GET((p)->root->tunnel_tpr_cnt) : \
SC_ATOMIC_GET((p)->tunnel_tpr_cnt))
#define TUNNEL_DECR_PKT_TPR_NOLOCK(p) do { \
((p)->root ? (p)->root->tunnel_tpr_cnt-- : (p)->tunnel_tpr_cnt--); \
} while (0)
#define TUNNEL_PKT_RTV(p) ((p)->root ? (p)->root->tunnel_rtv_cnt : (p)->tunnel_rtv_cnt)
#define TUNNEL_PKT_TPR(p) ((p)->root ? (p)->root->tunnel_tpr_cnt : (p)->tunnel_tpr_cnt)
#define IS_TUNNEL_PKT(p) (((p)->flags & PKT_TUNNEL))
#define SET_TUNNEL_PKT(p) ((p)->flags |= PKT_TUNNEL)

@ -548,6 +548,9 @@ TmEcode VerdictIPFW(ThreadVars *tv, Packet *p, void *data, PacketQueue *pq, Pack
if (IS_TUNNEL_PKT(p)) {
char verdict = 1;
SCMutex *m = p->root ? &p->root->tunnel_mutex : &p->tunnel_mutex;
SCMutexLock(m);
/* if there are more tunnel packets than ready to verdict packets,
* we won't verdict this one
*/
@ -558,6 +561,8 @@ TmEcode VerdictIPFW(ThreadVars *tv, Packet *p, void *data, PacketQueue *pq, Pack
verdict = 0;
}
SCMutexUnlock(m);
/* don't verdict if we are not ready */
if (verdict == 1) {
SCLogDebug("Setting verdict on tunnel");

@ -922,6 +922,9 @@ TmEcode VerdictNFQ(ThreadVars *tv, Packet *p, void *data, PacketQueue *pq, Packe
char verdict = 1;
//printf("VerdictNFQ: tunnel pkt: %p %s\n", p, p->root ? "upper layer" : "root");
SCMutex *m = p->root ? &p->root->tunnel_mutex : &p->tunnel_mutex;
SCMutexLock(m);
/* if there are more tunnel packets than ready to verdict packets,
* we won't verdict this one */
if (TUNNEL_PKT_TPR(p) > TUNNEL_PKT_RTV(p)) {
@ -931,6 +934,8 @@ TmEcode VerdictNFQ(ThreadVars *tv, Packet *p, void *data, PacketQueue *pq, Packe
verdict = 0;
}
SCMutexUnlock(m);
/* don't verdict if we are not ready */
if (verdict == 1) {
//printf("VerdictNFQ: setting verdict\n");

@ -124,12 +124,11 @@ Packet *TmqhInputPacketpool(ThreadVars *t)
void TmqhOutputPacketpool(ThreadVars *t, Packet *p)
{
SCEnter();
int proot = 0;
SCEnter();
SCLogDebug("Packet %p, p->root %p, alloced %s", p, p->root, p->flags & PKT_ALLOC ? "true" : "false");
char proot = 0;
/* final alerts cleanup... return smsgs to pool if needed */
if (p->alerts.alert_msgs != NULL) {
StreamMsgReturnListToPool(p->alerts.alert_msgs);
@ -140,22 +139,31 @@ void TmqhOutputPacketpool(ThreadVars *t, Packet *p)
SCLogDebug("Packet %p is a tunnel packet: %s",
p,p->root ? "upper layer" : "tunnel root");
/* get a lock to access root packet fields */
SCMutex *m = p->root ? &p->root->tunnel_mutex : &p->tunnel_mutex;
SCMutexLock(m);
if (IS_TUNNEL_ROOT_PKT(p)) {
SCLogDebug("IS_TUNNEL_ROOT_PKT == TRUE");
if (TUNNEL_PKT_TPR(p) == 0) {
SCLogDebug("TUNNEL_PKT_TPR(p) == 0, no more tunnel packet depending on this root");
SCLogDebug("TUNNEL_PKT_TPR(p) == 0, no more tunnel packet "
"depending on this root");
/* if this packet is the root and there are no
* more tunnel packets, enqueue it */
* more tunnel packets, return it to the pool */
/* fall through */
} else {
SCLogDebug("tunnel root Packet %p: TUNNEL_PKT_TPR(p) > 0, packets are still depending on this root, setting p->tunnel_verdicted == 1", p);
SCLogDebug("tunnel root Packet %p: TUNNEL_PKT_TPR(p) > 0, so "
"packets are still depending on this root, setting "
"p->tunnel_verdicted == 1", p);
/* if this is the root and there are more tunnel
* packets, don't add this. It's still referenced
* by the tunnel packets, and we will enqueue it
* packets, return this to the pool. It's still referenced
* by the tunnel packets, and we will return it
* when we handle them */
SET_TUNNEL_PKT_VERDICTED(p);
SCMutexUnlock(m);
PACKET_PROFILING_END(p);
SCReturn;
}
@ -173,22 +181,27 @@ void TmqhOutputPacketpool(ThreadVars *t, Packet *p)
SCLogDebug("p->root->tunnel_verdicted == 1 && TUNNEL_PKT_TPR(p) == 1");
/* the root is ready and we are the last tunnel packet,
* lets enqueue them both. */
TUNNEL_DECR_PKT_TPR(p);
TUNNEL_DECR_PKT_TPR_NOLOCK(p);
/* handle the root */
SCLogDebug("calling PacketEnqueue for root pkt, p->root %p (tunnel packet %p)", p->root, p);
SCLogDebug("setting proot = 1 for root pkt, p->root %p "
"(tunnel packet %p)", p->root, p);
proot = 1;
/* fall through */
} else {
/* root not ready yet, so get rid of the tunnel pkt only */
SCLogDebug("NOT p->root->tunnel_verdicted == 1 && TUNNEL_PKT_TPR(p) == 1 (%" PRIu32 ")", TUNNEL_PKT_TPR(p));
TUNNEL_DECR_PKT_TPR(p);
SCLogDebug("NOT p->root->tunnel_verdicted == 1 && "
"TUNNEL_PKT_TPR(p) == 1 (%" PRIu32 ")", TUNNEL_PKT_TPR(p));
TUNNEL_DECR_PKT_TPR_NOLOCK(p);
/* fall through */
}
}
SCMutexUnlock(m);
SCLogDebug("tunnel stuff done, move on (proot %d)", proot);
}

Loading…
Cancel
Save