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

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

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

@ -132,6 +132,7 @@ int GetIfaceMaxPacketSize(LiveDevice *ld)
case -1:
return 0;
}
ld->mtu = mtu;
int ll_header = GetIfaceMaxHWHeaderLength(dev);
return ll_header + mtu;
}

Loading…
Cancel
Save