Skip to content

Commit

Permalink
Accept v6 interfaces and interface names in whitelist (#128)
Browse files Browse the repository at this point in the history
Signed-off-by: Juan Lopez Fernandez <[email protected]>
(cherry picked from commit ac61a84)

# Conflicts:
#	ddspipe_participants/src/cpp/participant/rtps/CommonParticipant.cpp
  • Loading branch information
juanlofer-eprosima authored and mergify[bot] committed Sep 13, 2024
1 parent 68162ec commit 54f4b19
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ struct SimpleParticipantConfiguration : public ParticipantConfiguration

core::types::DomainId domain {0u};

std::set<participants::types::IpType> whitelist {};
std::set<participants::types::WhitelistType> whitelist {};

core::types::TransportDescriptors transport {core::types::TransportDescriptors::builtin};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ class CommonParticipant
template<typename T>
DDSPIPE_PARTICIPANTS_DllAPI
static std::shared_ptr<T> create_descriptor(
std::set<types::IpType> whitelist = {});
std::set<types::WhitelistType> whitelist = {});

protected:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ namespace types {
using LocatorType = uint32_t;
// Data Type for IP
using IpType = std::string;
// Data Type for an interfaces whitelist entry
using WhitelistType = std::string;
// Data Type for Domain name (DNS)
using DomainType = std::string;
// Data Type for Port
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,6 @@ bool SimpleParticipantConfiguration::is_valid(
return false;
}

// Check whitelist interfaces
for (types::IpType ip : whitelist)
{
if (!types::Address::is_ipv4_correct(ip))
{
error_msg << "Incorrect IPv4 address " << ip << " in whitelist interfaces. ";
return false;
}
}

return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,13 +204,14 @@ template<>
DDSPIPE_PARTICIPANTS_DllAPI
std::shared_ptr<eprosima::fastdds::rtps::UDPv4TransportDescriptor>
CommonParticipant::create_descriptor(
std::set<types::IpType> whitelist)
std::set<types::WhitelistType> whitelist)
{
std::shared_ptr<eprosima::fastdds::rtps::UDPv4TransportDescriptor> udp_transport =
std::make_shared<eprosima::fastdds::rtps::UDPv4TransportDescriptor>();

for (const types::IpType& ip : whitelist)
for (const types::WhitelistType& iface : whitelist)
{
<<<<<<< HEAD
if (types::Address::is_ipv4_correct(ip))
{
udp_transport->interfaceWhiteList.emplace_back(ip);
Expand All @@ -223,6 +224,11 @@ CommonParticipant::create_descriptor(
logWarning(DDSPIPE_COMMON_PARTICIPANT,
"Not valid IPv4. Discarding UDP whitelist interface " << ip << ".");
}
=======
udp_transport->interfaceWhiteList.emplace_back(iface);
EPROSIMA_LOG_INFO(DDSPIPE_COMMON_PARTICIPANT,
"Adding " << iface << " to UDP whitelist interfaces.");
>>>>>>> ac61a84 (Accept v6 interfaces and interface names in whitelist (#128))
}

return udp_transport;
Expand All @@ -232,13 +238,14 @@ template<>
DDSPIPE_PARTICIPANTS_DllAPI
std::shared_ptr<eprosima::fastdds::rtps::UDPv6TransportDescriptor>
CommonParticipant::create_descriptor(
std::set<types::IpType> whitelist)
std::set<types::WhitelistType> whitelist)
{
std::shared_ptr<eprosima::fastdds::rtps::UDPv6TransportDescriptor> udp_transport =
std::make_shared<eprosima::fastdds::rtps::UDPv6TransportDescriptor>();

for (const types::IpType& ip : whitelist)
for (const types::WhitelistType& iface : whitelist)
{
<<<<<<< HEAD
if (types::Address::is_ipv6_correct(ip))
{
udp_transport->interfaceWhiteList.emplace_back(ip);
Expand All @@ -251,6 +258,11 @@ CommonParticipant::create_descriptor(
logWarning(DDSPIPE_COMMON_PARTICIPANT,
"Not valid IPv6. Discarding UDP whitelist interface " << ip << ".");
}
=======
udp_transport->interfaceWhiteList.emplace_back(iface);
EPROSIMA_LOG_INFO(DDSPIPE_COMMON_PARTICIPANT,
"Adding " << iface << " to UDP whitelist interfaces.");
>>>>>>> ac61a84 (Accept v6 interfaces and interface names in whitelist (#128))
}

return udp_transport;
Expand All @@ -260,13 +272,14 @@ template<>
DDSPIPE_PARTICIPANTS_DllAPI
std::shared_ptr<eprosima::fastdds::rtps::TCPv4TransportDescriptor>
CommonParticipant::create_descriptor(
std::set<types::IpType> whitelist)
std::set<types::WhitelistType> whitelist)
{
std::shared_ptr<eprosima::fastdds::rtps::TCPv4TransportDescriptor> tcp_transport =
std::make_shared<eprosima::fastdds::rtps::TCPv4TransportDescriptor>();

for (const types::IpType& ip : whitelist)
for (const types::WhitelistType& iface : whitelist)
{
<<<<<<< HEAD
if (types::Address::is_ipv4_correct(ip))
{
tcp_transport->interfaceWhiteList.emplace_back(ip);
Expand All @@ -279,6 +292,11 @@ CommonParticipant::create_descriptor(
logWarning(DDSPIPE_COMMON_PARTICIPANT,
"Not valid IPv4. Discarding TCP whitelist interface " << ip << ".");
}
=======
tcp_transport->interfaceWhiteList.emplace_back(iface);
EPROSIMA_LOG_INFO(DDSPIPE_COMMON_PARTICIPANT,
"Adding " << iface << " to TCP whitelist interfaces.");
>>>>>>> ac61a84 (Accept v6 interfaces and interface names in whitelist (#128))
}

return tcp_transport;
Expand All @@ -288,13 +306,14 @@ template<>
DDSPIPE_PARTICIPANTS_DllAPI
std::shared_ptr<eprosima::fastdds::rtps::TCPv6TransportDescriptor>
CommonParticipant::create_descriptor(
std::set<types::IpType> whitelist)
std::set<types::WhitelistType> whitelist)
{
std::shared_ptr<eprosima::fastdds::rtps::TCPv6TransportDescriptor> tcp_transport =
std::make_shared<eprosima::fastdds::rtps::TCPv6TransportDescriptor>();

for (const types::IpType& ip : whitelist)
for (const types::WhitelistType& iface : whitelist)
{
<<<<<<< HEAD
if (types::Address::is_ipv6_correct(ip))
{
tcp_transport->interfaceWhiteList.emplace_back(ip);
Expand All @@ -307,6 +326,11 @@ CommonParticipant::create_descriptor(
logWarning(DDSPIPE_COMMON_PARTICIPANT,
"Not valid IPv6. Discarding TCP whitelist interface " << ip << ".");
}
=======
tcp_transport->interfaceWhiteList.emplace_back(iface);
EPROSIMA_LOG_INFO(DDSPIPE_COMMON_PARTICIPANT,
"Adding " << iface << " to TCP whitelist interfaces.");
>>>>>>> ac61a84 (Accept v6 interfaces and interface names in whitelist (#128))
}

return tcp_transport;
Expand Down
9 changes: 6 additions & 3 deletions ddspipe_yaml/src/cpp/YamlReader_participants.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ void YamlReader::fill(
// Optional whitelist interfaces
if (YamlReader::is_tag_present(yml, WHITELIST_INTERFACES_TAG))
{
object.whitelist = YamlReader::get_set<participants::types::IpType>(yml, WHITELIST_INTERFACES_TAG, version);
object.whitelist = YamlReader::get_set<participants::types::WhitelistType>(yml, WHITELIST_INTERFACES_TAG,
version);
}

// Optional get Transport descriptors
Expand Down Expand Up @@ -194,7 +195,8 @@ void YamlReader::fill(
// Optional whitelist interfaces
if (YamlReader::is_tag_present(yml, WHITELIST_INTERFACES_TAG))
{
object.whitelist = YamlReader::get_set<participants::types::IpType>(yml, WHITELIST_INTERFACES_TAG, version);
object.whitelist = YamlReader::get_set<participants::types::WhitelistType>(yml, WHITELIST_INTERFACES_TAG,
version);
}

// Optional listening addresses
Expand Down Expand Up @@ -262,7 +264,8 @@ void YamlReader::fill(
// Optional whitelist interfaces
if (YamlReader::is_tag_present(yml, WHITELIST_INTERFACES_TAG))
{
object.whitelist = YamlReader::get_set<participants::types::IpType>(yml, WHITELIST_INTERFACES_TAG, version);
object.whitelist = YamlReader::get_set<participants::types::WhitelistType>(yml, WHITELIST_INTERFACES_TAG,
version);
}

// Optional listening addresses
Expand Down

0 comments on commit 54f4b19

Please sign in to comment.