]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
Fix pfring so that zero-copy mode can work. 717/head
authorKen Steele <ken@tilera.com>
Mon, 11 Nov 2013 18:11:39 +0000 (13:11 -0500)
committerKen Steele <ken@tilera.com>
Wed, 11 Dec 2013 18:16:07 +0000 (13:16 -0500)
Detect when default_packet_size is zero, which enables zero-copy mode for
pfring and in that case, do what AF Packet does and set pkt_ext pointer to
the data and set PKT_ZERO_COPY flag.

src/detect.c
src/source-pfring.c

index f1ce18c97328295211da83434f3a6ea36a07501c..7c8f55a92293212f942ff28c878a0ef329ef1136 100644 (file)
@@ -6536,8 +6536,8 @@ int SigTest24IPV4Keyword(void)
     memset(&th_v, 0, sizeof(ThreadVars));
     memset(p1, 0, SIZE_OF_PACKET);
     memset(p2, 0, SIZE_OF_PACKET);
-    p1->ip4vars.comp_csum = -1;
-    p2->ip4vars.comp_csum = -1;
+    PACKET_RESET_CHECKSUMS(p1);
+    PACKET_RESET_CHECKSUMS(p2);
 
     p1->ip4h = (IPV4Hdr *)valid_raw_ipv4;
 
@@ -6640,8 +6640,8 @@ int SigTest25NegativeIPV4Keyword(void)
     memset(&th_v, 0, sizeof(ThreadVars));
     memset(p1, 0, SIZE_OF_PACKET);
     memset(p2, 0, SIZE_OF_PACKET);
-    p1->ip4vars.comp_csum = -1;
-    p2->ip4vars.comp_csum = -1;
+    PACKET_RESET_CHECKSUMS(p1);
+    PACKET_RESET_CHECKSUMS(p2);
 
     p1->ip4h = (IPV4Hdr *)valid_raw_ipv4;
 
@@ -6861,9 +6861,7 @@ static int SigTest26TCPV4AndNegativeIPV4Keyword(void)
 
     memset(&th_v, 0, sizeof(ThreadVars));
     memset(p1, 0, SIZE_OF_PACKET);
-    p1->pkt = (uint8_t *)(p1 + 1);
     memset(p2, 0, SIZE_OF_PACKET);
-    p2->pkt = (uint8_t *)(p2 + 1);
 
     PacketCopyData(p1, raw_ipv4, sizeof(raw_ipv4));
     PacketCopyDataOffset(p1, GET_PKT_LEN(p1), valid_raw_tcp, sizeof(valid_raw_tcp));
@@ -6989,9 +6987,7 @@ static int SigTest26TCPV4AndIPV4Keyword(void)
 
     memset(&th_v, 0, sizeof(ThreadVars));
     memset(p1, 0, SIZE_OF_PACKET);
-    p1->pkt = (uint8_t *)(p1 + 1);
     memset(p2, 0, SIZE_OF_PACKET);
-    p2->pkt = (uint8_t *)(p2 + 1);
 
     PacketCopyData(p1, raw_ipv4, sizeof(raw_ipv4));
     PacketCopyDataOffset(p1, GET_PKT_LEN(p1), valid_raw_tcp, sizeof(valid_raw_tcp));
index 90e8ef8af296b0df04193559aec2edeb97ba0bee..92992f99bcde9aca35a55b2d20d5c26a1021868a 100644 (file)
@@ -303,10 +303,17 @@ TmEcode ReceivePfringLoop(ThreadVars *tv, void *data, void *slot)
 
         /* Depending on what compile time options are used for pfring we either return 0 or -1 on error and always 1 for success */
 #ifdef HAVE_PFRING_RECV_UCHAR
-        int r = pfring_recv(ptv->pd, (u_char**)&GET_PKT_DIRECT_DATA(p),
-                (u_int)GET_PKT_DIRECT_MAX_SIZE(p),
+        u_char *pkt_buffer = GET_PKT_DIRECT_DATA(p);
+        u_int buffer_size = GET_PKT_DIRECT_MAX_SIZE(p);
+        int r = pfring_recv(ptv->pd, &pkt_buffer,
+                buffer_size,
                 &hdr,
                 LIBPFRING_WAIT_FOR_INCOMING);
+
+        /* Check for Zero-copy if buffer size is zero */
+        if (buffer_size == 0) {
+            PacketSetData(p, pkt_buffer, hdr.caplen);
+        }
 #else
         int r = pfring_recv(ptv->pd, (char *)GET_PKT_DIRECT_DATA(p),
                 (u_int)GET_PKT_DIRECT_MAX_SIZE(p),