]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
af-packet: handle possible exit of capture loop.
authorEric Leblond <eric@regit.org>
Wed, 5 Sep 2012 13:32:11 +0000 (15:32 +0200)
committerVictor Julien <victor@inliniac.net>
Thu, 6 Sep 2012 08:24:05 +0000 (10:24 +0200)
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

index 94c2c19f3c2c53d38b367c283f7ce36c2fbb302e..bdad54048bd582ff88ed2cf774684fe12d505bbd 100644 (file)
@@ -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;
+    }
 }
 
 /**