]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
af-packet: fetch mtu info once
authorShivani Bhardwaj <shivani@oisf.net>
Thu, 10 Aug 2023 15:35:45 +0000 (21:05 +0530)
committerVictor Julien <victor@inliniac.net>
Fri, 15 Sep 2023 15:08:59 +0000 (17:08 +0200)
With the current layout and fn calls, it was seen that once in the
beginning after the MTU was found and displayed to the user, when the
threads spawned, each thread displayed MTU info as a part of
AFPPeersListAdd fn. This happened in AF_PACKET IPS mode and led to
excessive MTU logs.
Save this info in the LiveDevice struct and avoid calling the unneeded
fns later on.

Bug 5831

src/source-af-packet.c
src/util-device.h
src/util-ioctl.c

index 317c8704e5af0c2d620422d7f57fd7cc4b67cbf2..6112cb9d8869c97affed0f810bc02aa0e8c7dcdd 100644 (file)
@@ -492,7 +492,6 @@ static TmEcode AFPPeersListAdd(AFPThreadVars *ptv)
     SCEnter();
     AFPPeer *peer = SCMalloc(sizeof(AFPPeer));
     AFPPeer *pitem;
-    int mtu, out_mtu;
 
     if (unlikely(peer == NULL)) {
         SCReturnInt(TM_ECODE_FAILED);
@@ -527,12 +526,18 @@ static TmEcode AFPPeersListAdd(AFPThreadVars *ptv)
                 continue;
             peer->peer = pitem;
             pitem->peer = peer;
-            mtu = GetIfaceMTU(ptv->iface);
-            out_mtu = GetIfaceMTU(ptv->out_iface);
-            if (mtu != out_mtu) {
-                SCLogWarning("MTU on %s (%d) and %s (%d) are not equal, "
-                             "transmission of packets bigger than %d will fail.",
-                        ptv->iface, mtu, ptv->out_iface, out_mtu, MIN(out_mtu, mtu));
+
+            LiveDevice *iface = ptv->livedev;
+            DEBUG_VALIDATE_BUG_ON(iface == NULL);
+            DEBUG_VALIDATE_BUG_ON(strcmp(iface->dev, ptv->iface) != 0);
+            LiveDevice *out_iface = LiveGetDevice(ptv->out_iface);
+            if (out_iface == NULL)
+                FatalError("AF_PACKET device %s not found. Aborting..", ptv->out_iface);
+            if (iface->mtu != out_iface->mtu) {
+                SCLogWarning("MTU on %s (%d) and %s (%d) are not equal, transmission of packets "
+                             "bigger than %d will fail.",
+                        iface->dev, iface->mtu, out_iface->dev, out_iface->mtu,
+                        MIN(out_iface->mtu, iface->mtu));
             }
             peerslist.peered += 2;
             break;
index 51ddf7d5257a1b56054906d7ac1d41ab3acf5675..0f756b78ca3a153220d1f6374130007a707aa33c 100644 (file)
@@ -49,6 +49,7 @@ typedef struct {
 typedef struct LiveDevice_ {
     char *dev;  /**< the device (e.g. "eth0") */
     char dev_short[MAX_DEVNAME + 1];
+    int mtu; /* MTU of the device */
     bool tenant_id_set;
 
     uint16_t id;
index 399751b05679c8ea9e9cb9780c6d05d81c6ea089..f39662bd4d47e3a604d5669dbe7428a653be754f 100644 (file)
@@ -132,6 +132,7 @@ int GetIfaceMaxPacketSize(LiveDevice *ld)
         case -1:
             return 0;
     }
+    ld->mtu = mtu;
     int ll_header = GetIfaceMaxHWHeaderLength(dev);
     return ll_header + mtu;
 }