Skip to content

Commit

Permalink
Refs #5041. Filter non-local addresses on whitelist.
Browse files Browse the repository at this point in the history
Signed-off-by: Miguel Company <MiguelCompany@eprosima.com>
  • Loading branch information
MiguelCompany committed Apr 2, 2019
1 parent 30021b7 commit fd84e5a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 42 deletions.
3 changes: 1 addition & 2 deletions src/cpp/transport/UDPTransportInterface.cpp
Expand Up @@ -629,7 +629,6 @@ LocatorList_t UDPTransportInterface::ShrinkLocatorLists(const std::vector<Locato
// Loopback locator
IPLocator::setPhysicalPort(loopbackLocator, IPLocator::getPhysicalPort(*it));
pendingUnicast.push_back(loopbackLocator);
break;
}
else
{
Expand All @@ -638,9 +637,9 @@ LocatorList_t UDPTransportInterface::ShrinkLocatorLists(const std::vector<Locato
{
// Custom Loopback locator
pendingUnicast.push_back(*it);
break;
}
}
break;
}
}

Expand Down
66 changes: 26 additions & 40 deletions src/cpp/transport/UDPv4Transport.cpp
Expand Up @@ -83,8 +83,21 @@ UDPv4Transport::UDPv4Transport(const UDPv4TransportDescriptor& descriptor)
transport_kind_ = LOCATOR_KIND_UDPv4;
mSendBufferSize = descriptor.sendBufferSize;
mReceiveBufferSize = descriptor.receiveBufferSize;
for (const auto& interface : descriptor.interfaceWhiteList)
interface_whitelist_.emplace_back(ip::address_v4::from_string(interface));
if (!descriptor.interfaceWhiteList.empty())
{
const auto white_begin = descriptor.interfaceWhiteList.begin();
const auto white_end = descriptor.interfaceWhiteList.end();

std::vector<IPFinder::info_IP> local_interfaces;
get_ipv4s(local_interfaces, true);
for (const IPFinder::info_IP& infoIP : local_interfaces)
{
if(std::find(white_begin, white_end, infoIP.name) != white_end)
{
interface_whitelist_.emplace_back(ip::address_v4::from_string(infoIP.name));
}
}
}
}

UDPv4TransportDescriptor::UDPv4TransportDescriptor()
Expand Down Expand Up @@ -128,25 +141,11 @@ bool UDPv4Transport::getDefaultMetatrafficUnicastLocators(
LocatorList_t &locators,
uint32_t metatraffic_unicast_port) const
{
if (interface_whitelist_.empty())
{
Locator_t locator;
locator.kind = LOCATOR_KIND_UDPv4;
locator.port = static_cast<uint16_t>(metatraffic_unicast_port);
locator.set_Invalid_Address();
locators.push_back(locator);
}
else
{
for (auto& it : interface_whitelist_)
{
Locator_t locator;
locator.kind = LOCATOR_KIND_UDPv4;
locator.port = static_cast<uint16_t>(metatraffic_unicast_port);
IPLocator::setIPv4(locator, it.to_string());
locators.push_back(locator);
}
}
Locator_t locator;
locator.kind = LOCATOR_KIND_UDPv4;
locator.port = static_cast<uint16_t>(metatraffic_unicast_port);
locator.set_Invalid_Address();
locators.push_back(locator);

return true;
}
Expand All @@ -155,25 +154,12 @@ bool UDPv4Transport::getDefaultUnicastLocators(
LocatorList_t &locators,
uint32_t unicast_port) const
{
if (interface_whitelist_.empty())
{
Locator_t locator;
locator.kind = LOCATOR_KIND_UDPv4;
locator.set_Invalid_Address();
fillUnicastLocator(locator, unicast_port);
locators.push_back(locator);
}
else
{
for (auto& it : interface_whitelist_)
{
Locator_t locator;
locator.kind = LOCATOR_KIND_UDPv4;
IPLocator::setIPv4(locator, it.to_string());
fillUnicastLocator(locator, unicast_port);
locators.push_back(locator);
}
}
Locator_t locator;
locator.kind = LOCATOR_KIND_UDPv4;
locator.set_Invalid_Address();
fillUnicastLocator(locator, unicast_port);
locators.push_back(locator);

return true;
}

Expand Down

0 comments on commit fd84e5a

Please sign in to comment.