From 2fa0fac2897628a8c1e4c11c888447a5d55b8df8 Mon Sep 17 00:00:00 2001 From: Shivani Bhardwaj Date: Thu, 10 Aug 2023 21:05:45 +0530 Subject: [PATCH] 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 --- src/source-af-packet.c | 19 ++++++++++++------- src/util-device.h | 1 + src/util-ioctl.c | 1 + 3 files changed, 14 insertions(+), 7 deletions(-) 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; } -- 2.47.2