]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
util/ioctl: use LiveDevice to retrieve name
authorShivani Bhardwaj <shivani@oisf.net>
Thu, 10 Aug 2023 15:34:56 +0000 (21:04 +0530)
committerVictor Julien <victor@inliniac.net>
Fri, 15 Sep 2023 15:08:59 +0000 (17:08 +0200)
The fn GetIfaceMaxPacketSize now uses LiveDevice object as a param
instead of a string. This was done to keep the logic of checking for the
device to this function itself instead of having callers first determine
whether the device exists or not.
This also falls in line with the changes made to avoid excessive MTU
logs in the following commit.

Related to redmine ticket 5831.

src/source-af-packet.c
src/source-pcap.c
src/suricata.c
src/util-ioctl.c
src/util-ioctl.h

index 0c50ed219aa661c0c3478ed75e48b3ca53472307..317c8704e5af0c2d620422d7f57fd7cc4b67cbf2 100644 (file)
@@ -1573,7 +1573,7 @@ sockaddr_ll) + ETH_HLEN) - ETH_HLEN);
     int snaplen = default_packet_size;
 
     if (snaplen == 0) {
-        snaplen = GetIfaceMaxPacketSize(ptv->iface);
+        snaplen = GetIfaceMaxPacketSize(ptv->livedev);
         if (snaplen <= 0) {
             SCLogWarning("%s: unable to get MTU, setting snaplen default of 1514", ptv->iface);
             snaplen = 1514;
@@ -1607,7 +1607,7 @@ static int AFPComputeRingParamsV3(AFPThreadVars *ptv)
     int snaplen = default_packet_size;
 
     if (snaplen == 0) {
-        snaplen = GetIfaceMaxPacketSize(ptv->iface);
+        snaplen = GetIfaceMaxPacketSize(ptv->livedev);
         if (snaplen <= 0) {
             SCLogWarning("%s: unable to get MTU, setting snaplen default of 1514", ptv->iface);
             snaplen = 1514;
index a36c2b646faad362f48e93b488b65bdedbcc24df..f916d69354c7fab1d50c63df62f2c0eaea3781ac 100644 (file)
@@ -514,7 +514,7 @@ static TmEcode ReceivePcapThreadInit(ThreadVars *tv, const void *initdata, void
 
     if (pcapconfig->snaplen == 0) {
         /* We set snaplen if we can get the MTU */
-        ptv->pcap_snaplen = GetIfaceMaxPacketSize(pcapconfig->iface);
+        ptv->pcap_snaplen = GetIfaceMaxPacketSize(ptv->livedev);
     } else {
         ptv->pcap_snaplen = pcapconfig->snaplen;
     }
index 7fe469acf24d04061acf63947fe576d35b7b8e43..d9adcaf07b26bff5a4c5d8c9b652d93bf6efe0f2 100644 (file)
@@ -2486,7 +2486,8 @@ static int ConfigGetCaptureValue(SCInstance *suri)
                             dev[len-1] = '\0';
                         }
                     }
-                    unsigned int iface_max_packet_size = GetIfaceMaxPacketSize(dev);
+                    LiveDevice *ld = LiveGetDevice(dev);
+                    unsigned int iface_max_packet_size = GetIfaceMaxPacketSize(ld);
                     if (iface_max_packet_size > default_packet_size)
                         default_packet_size = iface_max_packet_size;
                 }
index 97f8dd378f718c1ee47cb8bbad4ae4eae0e8bad4..399751b05679c8ea9e9cb9780c6d05d81c6ea089 100644 (file)
@@ -114,11 +114,15 @@ int GetIfaceMTU(const char *dev)
  * for the link. In case of uncertainty, it will output a
  * majorant to be sure avoid the cost of dynamic allocation.
  *
- * \param Name of a network interface
+ * \param LiveDevice object
  * \retval 0 in case of error
  */
-int GetIfaceMaxPacketSize(const char *dev)
+int GetIfaceMaxPacketSize(LiveDevice *ld)
 {
+    if (ld == NULL)
+        return 0;
+
+    const char *dev = ld->dev;
     if ((dev == NULL) || strlen(dev) == 0)
         return 0;
 
index 2d0c74740dd88b941c9ee1c33aa4a9b2f66296e3..24f89748751195b357da77cf800649f875eb5234 100644 (file)
@@ -25,7 +25,7 @@
 #include "util-device.h"
 
 int GetIfaceMTU(const char *pcap_dev);
-int GetIfaceMaxPacketSize(const char *pcap_dev);
+int GetIfaceMaxPacketSize(LiveDevice *ld);
 int GetIfaceOffloading(const char *dev, int csum, int other);
 int GetIfaceRSSQueuesNum(const char *pcap_dev);
 #ifdef SIOCGIFFLAGS