From: Shivani Bhardwaj Date: Thu, 10 Aug 2023 15:35:45 +0000 (+0530) Subject: af-packet: fetch mtu info once X-Git-Tag: suricata-7.0.2~34 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2fa0fac2897628a8c1e4c11c888447a5d55b8df8;p=thirdparty%2Fsuricata.git af-packet: fetch mtu info once 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 --- diff --git a/src/source-af-packet.c b/src/source-af-packet.c index 317c8704e5..6112cb9d88 100644 --- a/src/source-af-packet.c +++ b/src/source-af-packet.c @@ -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; diff --git a/src/util-device.h b/src/util-device.h index 51ddf7d525..0f756b78ca 100644 --- a/src/util-device.h +++ b/src/util-device.h @@ -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; diff --git a/src/util-ioctl.c b/src/util-ioctl.c index 399751b056..f39662bd4d 100644 --- a/src/util-ioctl.c +++ b/src/util-ioctl.c @@ -132,6 +132,7 @@ int GetIfaceMaxPacketSize(LiveDevice *ld) case -1: return 0; } + ld->mtu = mtu; int ll_header = GetIfaceMaxHWHeaderLength(dev); return ll_header + mtu; }