From b2691cbe889f138b0de0426740ae48dec77cdb8b Mon Sep 17 00:00:00 2001 From: Eric Leblond Date: Wed, 5 Sep 2012 15:32:11 +0200 Subject: [PATCH] af-packet: handle possible exit of capture loop. If a capture loop does exit, the thread needs to start without synchronization with the other threads. This patch fixes this by resetting the turn count on the peerslist structure and adding a test on this condition in the wait function. --- src/source-af-packet.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/source-af-packet.c b/src/source-af-packet.c index 94c2c19f3c..bdad54048b 100644 --- a/src/source-af-packet.c +++ b/src/source-af-packet.c @@ -389,6 +389,10 @@ TmEcode AFPPeersListAdd(AFPThreadVars *ptv) int AFPPeersListWaitTurn(AFPPeer *peer) { + /* If turn is zero, we already have started threads once */ + if (peerslist.turn == 0) + return 0; + if (peer->turn == SC_ATOMIC_GET(peerslist.reached)) return 0; return 1; @@ -396,7 +400,17 @@ int AFPPeersListWaitTurn(AFPPeer *peer) void AFPPeersListReachedInc() { - (void)SC_ATOMIC_ADD(peerslist.reached, 1); + if (peerslist.turn == 0) + return; + + if (SC_ATOMIC_ADD(peerslist.reached, 1) == peerslist.turn) { + SCLogInfo("All AFP capture threads are running."); + (void)SC_ATOMIC_SET(peerslist.reached, 0); + /* Set turn to 0 to skip syncrhonization when ReceiveAFPLoop is + * restarted. + */ + peerslist.turn = 0; + } } /**