From 572f8a3da6241a71aecc1cd5d5b6e75035cf426d Mon Sep 17 00:00:00 2001 From: Shivani Bhardwaj Date: Thu, 10 Aug 2023 21:04:56 +0530 Subject: [PATCH] util/ioctl: use LiveDevice to retrieve name 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 | 4 ++-- src/source-pcap.c | 2 +- src/suricata.c | 3 ++- src/util-ioctl.c | 8 ++++++-- src/util-ioctl.h | 2 +- 5 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/source-af-packet.c b/src/source-af-packet.c index 0c50ed219a..317c8704e5 100644 --- a/src/source-af-packet.c +++ b/src/source-af-packet.c @@ -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; diff --git a/src/source-pcap.c b/src/source-pcap.c index a36c2b646f..f916d69354 100644 --- a/src/source-pcap.c +++ b/src/source-pcap.c @@ -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; } diff --git a/src/suricata.c b/src/suricata.c index 7fe469acf2..d9adcaf07b 100644 --- a/src/suricata.c +++ b/src/suricata.c @@ -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; } diff --git a/src/util-ioctl.c b/src/util-ioctl.c index 97f8dd378f..399751b056 100644 --- a/src/util-ioctl.c +++ b/src/util-ioctl.c @@ -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; diff --git a/src/util-ioctl.h b/src/util-ioctl.h index 2d0c74740d..24f8974875 100644 --- a/src/util-ioctl.h +++ b/src/util-ioctl.h @@ -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