]> git.ipfire.org Git - people/ms/suricata.git/commitdiff
af-packet: only ref mpeer if needed in tpacket v2
authorVictor Julien <victor@inliniac.net>
Fri, 5 Nov 2021 12:50:18 +0000 (13:50 +0100)
committerVictor Julien <vjulien@oisf.net>
Mon, 22 Nov 2021 12:56:07 +0000 (13:56 +0100)
We only use it in autofp mode, for reference counting purposes.

Removes 2 atomic operations per packet in the more common workers
runmode.

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

index c6d79966df8953d6a5e8c9f668673c02a4cc202b..ac0b570a9b6b0dc48b04a8fb01a9e66ea7516ac9 100644 (file)
@@ -679,6 +679,7 @@ finalize:
     if (active_runmode == NULL || strcmp("workers", active_runmode) != 0) {
         /* If we are using copy mode we need a lock */
         aconf->flags |= AFP_SOCK_PROTECT;
+        aconf->flags |= AFP_NEED_PEER;
     }
     return aconf;
 }
index eec02309bbff07a97c9aa55d01f9232cad4ba9b0..810c7cc0726d4714b7659a099c4baf91c2f563e9 100644 (file)
@@ -779,8 +779,12 @@ static void AFPReadFromRingSetupPacket(
 
     p->ReleasePacket = AFPReleasePacket;
     p->afp_v.relptr = h.raw;
-    p->afp_v.mpeer = ptv->mpeer;
-    AFPRefSocket(ptv->mpeer);
+    if (ptv->flags & AFP_NEED_PEER) {
+        p->afp_v.mpeer = ptv->mpeer;
+        AFPRefSocket(ptv->mpeer);
+    } else {
+        p->afp_v.mpeer = NULL;
+    }
     p->afp_v.copy_mode = ptv->copy_mode;
     p->afp_v.peer = (p->afp_v.copy_mode == AFP_COPY_MODE_NONE) ? NULL : ptv->mpeer->peer;
 
index e976b306500a405104f0b8dadef2c9ee41aa843b..de25ff244294e292f4a5e20dc9329ce15f3b91da 100644 (file)
@@ -55,7 +55,7 @@ struct ebpf_timeout_config {
 #endif
 
 /* value for flags */
-// (1<<0) vacant
+#define AFP_NEED_PEER (1 << 0)
 // (1<<1) vacant
 #define AFP_SOCK_PROTECT (1<<2)
 #define AFP_EMERGENCY_MODE (1<<3)