]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
af-packet: don't check ifstate per send call in IPS
authorVictor Julien <victor@inliniac.net>
Thu, 4 Nov 2021 16:38:58 +0000 (17:38 +0100)
committerVictor Julien <vjulien@oisf.net>
Mon, 22 Nov 2021 12:56:07 +0000 (13:56 +0100)
Instead just accept that the socket state leads to `sendto` errors.
So print at most one error per socket.

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

index 64c9b1168991f1bdc5301f4f77321629e20dbd6b..1aa16cc8a6006a62721e2e850bc0f06fae942c0c 100644 (file)
@@ -417,6 +417,7 @@ static void AFPPeerUpdate(AFPThreadVars *ptv)
     (void)SC_ATOMIC_SET(ptv->mpeer->if_idx, AFPGetIfnumByDev(ptv->socket, ptv->iface, 0));
     (void)SC_ATOMIC_SET(ptv->mpeer->socket, ptv->socket);
     (void)SC_ATOMIC_SET(ptv->mpeer->state, ptv->afp_state);
+    (void)SC_ATOMIC_SET(ptv->mpeer->send_errors, 0);
 }
 
 /**
@@ -639,9 +640,6 @@ static void AFPWritePacket(Packet *p, int version)
         }
     }
 
-    if (SC_ATOMIC_GET(p->afp_v.peer->state) == AFP_STATE_DOWN)
-        return;
-
     if (p->ethh == NULL) {
         SCLogWarning(SC_ERR_INVALID_VALUE, "Should have an Ethernet header");
         return;
@@ -661,9 +659,10 @@ static void AFPWritePacket(Packet *p, int version)
 
     if (sendto(socket, GET_PKT_DATA(p), GET_PKT_LEN(p), 0, (struct sockaddr *)&socket_address,
                 sizeof(struct sockaddr_ll)) < 0) {
-        SCLogWarning(SC_ERR_SOCKET, "Sending packet failed on socket %d: %s",
-                  socket,
-                  strerror(errno));
+        if (SC_ATOMIC_ADD(p->afp_v.peer->send_errors, 1) == 0) {
+            SCLogWarning(SC_ERR_SOCKET, "sending packet failed on socket %d: %s", socket,
+                    strerror(errno));
+        }
     }
     if (p->afp_v.peer->flags & AFP_SOCK_PROTECT)
         SCMutexUnlock(&p->afp_v.peer->sock_protect);
index e8929f40cc36a0e33ed025c49a371db053ad20c5..e976b306500a405104f0b8dadef2c9ee41aa843b 100644 (file)
@@ -124,6 +124,7 @@ typedef struct AFPPeer_ {
     SC_ATOMIC_DECLARE(int, socket);
     SC_ATOMIC_DECLARE(int, sock_usage);
     SC_ATOMIC_DECLARE(int, if_idx);
+    SC_ATOMIC_DECLARE(uint64_t, send_errors);
     int flags;
     SCMutex sock_protect;
     int turn; /**< Field used to store initialisation order. */