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.
pull/9492/head
Shivani Bhardwaj 2 years ago committed by Victor Julien
parent 4639a62eb7
commit 572f8a3da6

@ -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;

@ -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;
}

@ -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;
}

@ -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;

@ -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

Loading…
Cancel
Save