diff --git a/server/device.cpp b/server/device.cpp index d06548e..1594b4b 100644 --- a/server/device.cpp +++ b/server/device.cpp @@ -186,10 +186,10 @@ void Device::transmitPacket(PacketBuffer *pktBuf) void Device::resolveGateway() { - if (hasIp4_) + if (hasIp4_ && !isResolved(ip4Gateway_)) sendArpRequest(ip4Gateway_); - if (hasIp6_) + if (hasIp6_ && !isResolved(ip6Gateway_)) sendNeighborSolicit(ip6Gateway_); } @@ -368,7 +368,8 @@ void Device::sendArpRequest(PacketBuffer *pktBuf) tgtIp = ((dstIp & ip4Mask_) == ip4Subnet_) ? dstIp : ip4Gateway_; - sendArpRequest(tgtIp); + if (!isResolved(tgtIp)) + sendArpRequest(tgtIp); } @@ -390,7 +391,18 @@ void Device::sendNeighborSolicit(PacketBuffer *pktBuf) tgtIp = ((dstIp & ip6Mask_) == ip6Subnet_) ? dstIp : ip6Gateway_; - sendNeighborSolicit(tgtIp); + if (!isResolved(tgtIp)) + sendNeighborSolicit(tgtIp); +} + +bool Device::isResolved(quint32 ip) +{ + return arpLookup(ip) > 0; +} + +bool Device::isResolved(UInt128 ip) +{ + return ndpLookup(ip) > 0; } // diff --git a/server/device.h b/server/device.h index d38a4a0..25b8649 100644 --- a/server/device.h +++ b/server/device.h @@ -106,6 +106,8 @@ protected: // data private: // methods void sendArpRequest(PacketBuffer *pktBuf); void sendNeighborSolicit(PacketBuffer *pktBuf); + bool isResolved(quint32 ip); + bool isResolved(UInt128 ip); }; diff --git a/server/emuldevice.cpp b/server/emuldevice.cpp index 71bb99e..1e3760d 100644 --- a/server/emuldevice.cpp +++ b/server/emuldevice.cpp @@ -303,14 +303,14 @@ void EmulDevice::sendArpRequest(quint32 tgtIp) if (!tgtIp) return; + // FIXME: Now that the caller does a isResolved check, re-evaluate + // the below behaviour // This function will be called once per unique stream - which // may all have the same dst IP; even if dst IP are different the // gateway for the different dst IP may all be same. However, // we don't want to send duplicate ARP requests, so we check // if the tgtIP is already in the cache (resolved or unresolved) // and if so, we don't resend it - // FIXME: this check needs to happen at caller so that HostDevices - // can also benefit from this check if (arpTable_.contains(tgtIp)) return;