From e6592c03a2475e3b2e4ef1e15ab8aee83a9e722b Mon Sep 17 00:00:00 2001 From: Srivats P Date: Wed, 12 Dec 2018 22:00:09 +0530 Subject: [PATCH] HostDev: Fix another bunch of FIXME/TODOs --- server/devicemanager.cpp | 2 +- server/devicemanager.h | 2 +- server/linuxport.cpp | 8 +++----- server/winhostdevice.cpp | 16 ++++++++++++++-- 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/server/devicemanager.cpp b/server/devicemanager.cpp index a206c8a..8ed527e 100644 --- a/server/devicemanager.cpp +++ b/server/devicemanager.cpp @@ -231,7 +231,7 @@ bool DeviceManager::modifyDeviceGroup(const OstProto::DeviceGroup *deviceGroup) int DeviceManager::deviceCount() { - return deviceList_.size() + 1; // FIXME: why +1 for hostdev? + return deviceList_.size() + hostDeviceList_.size(); } void DeviceManager::getDeviceList( diff --git a/server/devicemanager.h b/server/devicemanager.h index e3e0434..ff0cda9 100644 --- a/server/devicemanager.h +++ b/server/devicemanager.h @@ -80,7 +80,7 @@ private: QMultiHash bcastList_; QHash tpidList_; // Key: TPID, Value: RefCount - QList hostDeviceList_; // TODO: use to add/remove from devicelist on useHostDevice flag toggle + QList hostDeviceList_; }; #endif diff --git a/server/linuxport.cpp b/server/linuxport.cpp index 17d636e..2498a79 100644 --- a/server/linuxport.cpp +++ b/server/linuxport.cpp @@ -277,16 +277,14 @@ void LinuxPort::populateInterfaceInfo() // // Find self IP // - bool foundIp4 = false; // FIXME: needed? why? - bool foundIp6 = false; // FIXME: needed? why? if (!addressCache_) { qWarning("rtnetlink address cache empty for %s", name()); return; } rtnl_addr *l3addr = (rtnl_addr*) nl_cache_get_first(addressCache_); - while (l3addr && !foundIp4 && !foundIp6) { + while (l3addr) { if (rtnl_addr_get_ifindex(l3addr) == ifIndex) { - if (rtnl_addr_get_family(l3addr) == AF_INET && !foundIp4) { + if (rtnl_addr_get_family(l3addr) == AF_INET) { Ip4Config ip; ip.address = qFromBigEndian( nl_addr_get_binary_addr( @@ -295,7 +293,7 @@ void LinuxPort::populateInterfaceInfo() ip.gateway = gw4; interfaceInfo_->ip4.append(ip); } - else if (rtnl_addr_get_family(l3addr) == AF_INET6 && !foundIp6) { + else if (rtnl_addr_get_family(l3addr) == AF_INET6) { Ip6Config ip; ip.address = UInt128((quint8*)nl_addr_get_binary_addr( rtnl_addr_get_local(l3addr))); diff --git a/server/winhostdevice.cpp b/server/winhostdevice.cpp index 47c2db0..986d08b 100644 --- a/server/winhostdevice.cpp +++ b/server/winhostdevice.cpp @@ -78,8 +78,20 @@ void WindowsHostDevice::clearNeighbors(Device::NeighborSet set) void WindowsHostDevice::getNeighbors(OstEmul::DeviceNeighborList *neighbors) { PMIB_IPNET_TABLE2 nbrs = NULL; - // TODO: optimization: use AF_UNSPEC only if hasIp4 and hasIp6 - ulong status = GetIpNetTable2(AF_UNSPEC, &nbrs) != NO_ERROR; + ADDRESS_FAMILY af = AF_UNSPEC; + + // TODO: the following can potentially be used elsewhere + // but definition of AF_XXX may be different in different + // platforms + if (!hasIp4_) + if (!hasIp6_) + return; + else + af = AF_INET6; + else if (!hasIp6_) + af = AF_INET; + + ulong status = GetIpNetTable2(af, &nbrs) != NO_ERROR; if (status != NO_ERROR) { qWarning("Get ARP/ND table failed for LUID %llx: %s", luid_.Value, errMsg(status));