]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
af-packet: avoid test for each packet
authorEric Leblond <eric@regit.org>
Thu, 3 Jan 2013 19:29:54 +0000 (20:29 +0100)
committerVictor Julien <victor@inliniac.net>
Fri, 20 May 2016 10:32:39 +0000 (12:32 +0200)
src/source-af-packet.c

index 942391dd4f0209060e30882221ef4eda80dc8de7..f9c368a40db2d66b5fa35bc58dec3ec305070502 100644 (file)
@@ -1128,9 +1128,16 @@ TmEcode ReceiveAFPLoop(ThreadVars *tv, void *data, void *slot)
     TmSlot *s = (TmSlot *)slot;
     time_t last_dump = 0;
     struct timeval current_time;
+    int (*AFPReadFunc) (AFPThreadVars *);
 
     ptv->slot = s->slot_next;
 
+    if (ptv->flags & AFP_RING_MODE) {
+        AFPReadFunc = AFPReadFromRing;
+    } else {
+        AFPReadFunc = AFPRead;
+    }
+
     if (ptv->afp_state == AFP_STATE_DOWN) {
         /* Wait for our turn, threads before us must have opened the socket */
         while (AFPPeersListWaitTurn(ptv->mpeer)) {
@@ -1211,12 +1218,7 @@ TmEcode ReceiveAFPLoop(ThreadVars *tv, void *data, void *slot)
                 continue;
             }
         } else if (r > 0) {
-            if (ptv->flags & AFP_RING_MODE) {
-                r = AFPReadFromRing(ptv);
-            } else {
-                /* AFPRead will call TmThreadsSlotProcessPkt on read packets */
-                r = AFPRead(ptv);
-            }
+            r = AFPReadFunc(ptv);
             switch (r) {
                 case AFP_READ_FAILURE:
                     /* AFPRead in error: best to reset the socket */