]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
af-packet: clean APFPacketVar before release.
authorEric Leblond <eric@regit.org>
Wed, 19 Sep 2012 14:40:14 +0000 (16:40 +0200)
committerVictor Julien <victor@inliniac.net>
Mon, 24 Sep 2012 08:13:28 +0000 (10:13 +0200)
This patch resets the AFPPacketVar linked to a Packet in the release
function to avoid any side effect when the packet is reused. To do
so a new AFPV_CLEANUP macro has been introduced.

src/source-af-packet.c
src/source-af-packet.h

index f86617fc26c01a10cbe40e0926a6d5becae26c62..f91a39ce7f519f6cec1f818e6fc9f5d25c53104b 100644 (file)
@@ -648,15 +648,17 @@ TmEcode AFPReleaseDataFromRing(ThreadVars *t, Packet *p)
     }
 
     if (AFPDerefSocket(p->afp_v.mpeer) == 0)
-        return ret;
+        goto cleanup;
 
     if (p->afp_v.relptr) {
         union thdr h;
         h.raw = p->afp_v.relptr;
         h.h2->tp_status = TP_STATUS_KERNEL;
-        return ret;
     }
-    return TM_ECODE_FAILED;
+
+cleanup:
+    AFPV_CLEANUP(&p->afp_v);
+    return ret;
 }
 
 /**
index 0fcd2cb863401602f8aedd3c53717228af4d5298..e65a1f2a7a96f781b918d0d8f7a5d4f967a45844 100644 (file)
@@ -93,7 +93,12 @@ typedef struct AFPPeer_ {
     TAILQ_ENTRY(AFPPeer_) next;
 } AFPPeer;
 
-/* per packet AF_PACKET vars */
+/**
+ * \brief per packet AF_PACKET vars
+ *
+ * This structure is used y the release data system and is cleaned
+ * up by the AFPV_CLEANUP macro below.
+ */
 typedef struct AFPPacketVars_
 {
     void *relptr;
@@ -105,6 +110,13 @@ typedef struct AFPPacketVars_
     AFPPeer *mpeer;
 } AFPPacketVars;
 
+#define AFPV_CLEANUP(afpv) do {           \
+    (afpv)->relptr = NULL;                \
+    (afpv)->copy_mode = 0;                \
+    (afpv)->peer = NULL;                  \
+    (afpv)->mpeer = NULL;                 \
+} while(0)
+
 /**
  * @}
  */