Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/fastdds/rtps/transport/TransportInterface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ class FASTDDS_EXPORTED_API TransportInterface
//! Must report whether localhost locator is allowed
virtual bool is_localhost_allowed() const
{
return true;
return false;
}

//! Returns netmask filter information (transport's netmask filter kind and allowlist)
Expand Down
1 change: 1 addition & 0 deletions src/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ set(${PROJECT_NAME}_source_files
rtps/messages/submessages/GapMsg.hpp
rtps/messages/submessages/HeartbeatMsg.hpp
rtps/network/NetworkBuffer.cpp
rtps/network/NetworkConfiguration.cpp
rtps/network/NetworkFactory.cpp
rtps/network/ReceiverResource.cpp
rtps/network/utils/external_locators.cpp
Expand Down
24 changes: 0 additions & 24 deletions src/cpp/rtps/builtin/data/NetworkConfiguration.hpp

This file was deleted.

2 changes: 1 addition & 1 deletion src/cpp/rtps/builtin/discovery/participant/PDPSimple.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@

#include <fastdds/builtin/type_lookup_service/TypeLookupManager.hpp>
#include <rtps/builtin/BuiltinProtocols.h>
#include <rtps/builtin/data/NetworkConfiguration.hpp>
#include <rtps/builtin/data/ParticipantProxyData.hpp>
#include <rtps/builtin/data/ReaderProxyData.hpp>
#include <rtps/builtin/data/WriterProxyData.hpp>
Expand All @@ -42,6 +41,7 @@
#include <rtps/builtin/discovery/participant/simple/SimplePDPEndpointsSecure.hpp>
#include <rtps/builtin/liveliness/WLP.hpp>
#include <rtps/history/TopicPayloadPoolRegistry.hpp>
#include <rtps/network/NetworkConfiguration.hpp>
#include <rtps/participant/RTPSParticipantImpl.hpp>
#include <rtps/reader/BaseReader.hpp>
#include <rtps/reader/StatefulReader.hpp>
Expand Down
44 changes: 44 additions & 0 deletions src/cpp/rtps/network/NetworkConfiguration.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright 2025 Proyectos y Sistemas de Mantenimiento SL (eProsima).
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include <cassert>

#include <fastdds/rtps/common/Locator.hpp>

#include <rtps/network/NetworkConfiguration.hpp>

namespace eprosima {
namespace fastdds {
namespace rtps {
namespace network {

void add_localhost_capability(
int32_t kind,
NetworkConfigSet_t& network_config)
{
// Only add localhost capability for transports that support it
if (kind == LOCATOR_KIND_UDPv4 || kind == LOCATOR_KIND_UDPv6 ||
kind == LOCATOR_KIND_TCPv4 || kind == LOCATOR_KIND_TCPv6)
{
// Ensure the kind is a power of two to perform safe bitwise operations
assert(kind > 0 && (kind & (kind - 1)) == 0);

network_config |= kind;
}
}

} // namespace network
} // namespace rtps
} // namespace fastdds
} // namespace eprosima
49 changes: 49 additions & 0 deletions src/cpp/rtps/network/NetworkConfiguration.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright 2023 Proyectos y Sistemas de Mantenimiento SL (eProsima).
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

/**
* @file NetworkConfiguration.hpp
*/

#ifndef FASTDDS_RTPS_NETWORK__NETWORKCONFIGURATION_HPP
#define FASTDDS_RTPS_NETWORK__NETWORKCONFIGURATION_HPP

#include <fastdds/rtps/common/Types.hpp>

#define DISC_NETWORK_CONFIGURATION_LISTENING_LOCALHOST_ALL (0x0000000F)

namespace eprosima {
namespace fastdds {
namespace rtps {
namespace network {

/**
* @brief Add the capability to use localhost for the given transport kind.
*
* This function adds the capability to use localhost for the given transport kind
* in the provided network configuration.
*
* @param kind The transport kind to add the localhost capability for.
* @param network_config The network configuration to modify.
*/
void add_localhost_capability(
int32_t kind,
NetworkConfigSet_t& network_config);

} // namespace network
} // namespace rtps
} // namespace fastdds
} // namespace eprosima

#endif // FASTDDS_RTPS_NETWORK__NETWORKCONFIGURATION_HPP
5 changes: 4 additions & 1 deletion src/cpp/rtps/network/NetworkFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <fastdds/utils/IPFinder.hpp>
#include <fastdds/utils/IPLocator.hpp>

#include <rtps/network/NetworkConfiguration.hpp>
#include <rtps/transport/TCPTransportInterface.h>

using namespace std;
Expand Down Expand Up @@ -166,7 +167,9 @@ bool NetworkFactory::RegisterTransport(

if (is_localhost_allowed)
{
network_configuration_ |= kind;
network::add_localhost_capability(
kind,
network_configuration_);
}
}
}
Expand Down
85 changes: 78 additions & 7 deletions test/blackbox/common/BlackboxTestsNetworkConf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,8 @@ TEST_P(NetworkConfig, PubSubInterfaceWhitelistLocalhost)
void interface_whitelist_test(
const std::vector<IPFinder::info_IP>& pub_interfaces,
const std::vector<IPFinder::info_IP>& sub_interfaces,
bool interface_name = false)
bool interface_name = false,
bool add_shm_descriptor = false)
{
PubSubReader<HelloWorldPubSubType> reader(TEST_TOPIC_NAME);
PubSubWriter<HelloWorldPubSubType> writer(TEST_TOPIC_NAME);
Expand All @@ -378,7 +379,7 @@ void interface_whitelist_test(
pub_udp_descriptor = std::make_shared<UDPv6TransportDescriptor>();
}

// include the interfaces in the transport descriptor
// include the interfaces in the UDP transport descriptor
for (const auto& network_interface : pub_interfaces)
{
if (!interface_name)
Expand All @@ -391,10 +392,26 @@ void interface_whitelist_test(
}
}

// Set the transport descriptor WITH interfaces in the writer
std::shared_ptr<SharedMemTransportDescriptor> pub_shm_descriptor;

if (add_shm_descriptor)
{
pub_shm_descriptor = std::make_shared<SharedMemTransportDescriptor>();
}

// Set the UDP transport descriptor WITH interfaces in the writer
writer.reliability(eprosima::fastdds::dds::RELIABLE_RELIABILITY_QOS).history_depth(10).
disable_builtin_transport().
add_user_transport_to_pparams(pub_udp_descriptor).init();
add_user_transport_to_pparams(pub_udp_descriptor);

// If shared memory is requested, add it as well
if (add_shm_descriptor)
{
writer.add_user_transport_to_pparams(pub_shm_descriptor);
}

// Initialize the writer
writer.init();

ASSERT_TRUE(writer.isInitialized());

Expand All @@ -409,7 +426,7 @@ void interface_whitelist_test(
sub_udp_descriptor = std::make_shared<UDPv6TransportDescriptor>();
}

// include the interfaces in the transport descriptor
// include the interfaces in the UDP transport descriptor
for (const auto& network_interface : sub_interfaces)
{
if (!interface_name)
Expand All @@ -422,10 +439,26 @@ void interface_whitelist_test(
}
}

// Set the transport descriptor WITH interfaces in the reader
std::shared_ptr<SharedMemTransportDescriptor> sub_shm_descriptor;

if (add_shm_descriptor)
{
sub_shm_descriptor = std::make_shared<SharedMemTransportDescriptor>();
}

// Set the UDP transport descriptor WITH interfaces in the reader
reader.reliability(eprosima::fastdds::dds::RELIABLE_RELIABILITY_QOS).history_depth(10).
disable_builtin_transport().
add_user_transport_to_pparams(sub_udp_descriptor).init();
add_user_transport_to_pparams(sub_udp_descriptor);

// If shared memory is requested, add it as well
if (add_shm_descriptor)
{
reader.add_user_transport_to_pparams(sub_shm_descriptor);
}

// Initialize the reader
reader.init();

ASSERT_TRUE(reader.isInitialized());

Expand Down Expand Up @@ -622,6 +655,44 @@ TEST_P(NetworkConfig, PubSubAsymmetricInterfaceWhitelistAllExceptLocalhost)
}
}

// Regression test for redmine issue #23213 to check in UDP that setting the interface whitelist in one
// of the endpoints, but not in the other, connection is established anyways.
// All available interfaces except loopback case.
// This test verifies that adding a SHM transport descriptor does not affect the communication in this concrete case.
TEST_P(NetworkConfig, PubSubAsymmetricInterfaceWhitelistAllExceptLocalhostSHM)
{
std::vector<IPFinder::info_IP> no_interfaces;

std::vector<IPFinder::info_IP> all_interfaces_except_localhost;
use_udpv4 ? GetIP4s(all_interfaces_except_localhost, false) : GetIP6s(all_interfaces_except_localhost, false);

{
// IP address
{
// Whitelist only in publisher
interface_whitelist_test(all_interfaces_except_localhost, no_interfaces, false, true);
}

{
// Whitelist only in subscriber
interface_whitelist_test(no_interfaces, all_interfaces_except_localhost, false, true);
}
}

{
// Interface name
{
// Whitelist only in publisher
interface_whitelist_test(all_interfaces_except_localhost, no_interfaces, true, true);
}

{
// Whitelist only in subscriber
interface_whitelist_test(no_interfaces, all_interfaces_except_localhost, true, true);
}
}
}

TEST_P(NetworkConfig, SubGetListeningLocators)
{
PubSubReader<HelloWorldPubSubType> reader(TEST_TOPIC_NAME);
Expand Down
2 changes: 1 addition & 1 deletion test/blackbox/common/DDSBlackboxTestsMonitorService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2944,7 +2944,7 @@ TEST(DDSMonitorServiceTest, monitor_service_proxy_optional_qos)
expected_participant_builtin_topic_data.wire_protocol->prefix =
expected_participant_builtin_topic_data.guid.guidPrefix;
expected_participant_builtin_topic_data.wire_protocol->participant_id = 0;
expected_participant_builtin_topic_data.wire_protocol->builtin.network_configuration = LOCATOR_KIND_SHM;
expected_participant_builtin_topic_data.wire_protocol->builtin.network_configuration = LOCATOR_KIND_UDPv4;

validator->register_remote_participant_builtin_topic_data(expected_participant_builtin_topic_data);

Expand Down
1 change: 1 addition & 0 deletions test/unittest/dds/publisher/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ set(DATAWRITERTESTS_SOURCE DataWriterTests.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/messages/RTPSMessageGroup.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/messages/SendBuffersManager.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/network/NetworkBuffer.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/network/NetworkConfiguration.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/network/NetworkFactory.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/network/ReceiverResource.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/network/utils/external_locators.cpp
Expand Down
1 change: 1 addition & 0 deletions test/unittest/rtps/discovery/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ set(PDPTESTS_SOURCE PDPTests.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/common/Time_t.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/flowcontrol/FlowControllerConsts.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/network/NetworkBuffer.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/network/NetworkConfiguration.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/network/NetworkFactory.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/network/utils/netmask_filter.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/network/utils/network.cpp
Expand Down
1 change: 1 addition & 0 deletions test/unittest/rtps/network/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ set(NETWORKFACTORYTESTS_SOURCE
${PROJECT_SOURCE_DIR}/src/cpp/rtps/messages/CDRMessage.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/messages/RTPSMessageCreator.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/network/NetworkBuffer.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/network/NetworkConfiguration.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/network/NetworkFactory.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/network/utils/netmask_filter.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/network/utils/network.cpp
Expand Down
1 change: 1 addition & 0 deletions test/unittest/rtps/reader/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ set(STATEFUL_READER_TESTS_SOURCE StatefulReaderTests.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/messages/RTPSMessageGroup.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/messages/SendBuffersManager.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/network/NetworkBuffer.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/network/NetworkConfiguration.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/network/NetworkFactory.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/network/ReceiverResource.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/network/utils/external_locators.cpp
Expand Down
2 changes: 2 additions & 0 deletions test/unittest/statistics/dds/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ if (SQLITE3_SUPPORT AND FASTDDS_STATISTICS AND NOT QNX)
${PROJECT_SOURCE_DIR}/src/cpp/rtps/messages/RTPSMessageGroup.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/messages/SendBuffersManager.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/network/NetworkBuffer.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/network/NetworkConfiguration.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/network/NetworkFactory.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/network/ReceiverResource.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/network/utils/external_locators.cpp
Expand Down Expand Up @@ -425,6 +426,7 @@ if (SQLITE3_SUPPORT AND FASTDDS_STATISTICS AND NOT QNX)
${PROJECT_SOURCE_DIR}/src/cpp/rtps/messages/RTPSMessageGroup.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/messages/SendBuffersManager.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/network/NetworkBuffer.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/network/NetworkConfiguration.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/network/NetworkFactory.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/network/ReceiverResource.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/network/utils/external_locators.cpp
Expand Down
1 change: 1 addition & 0 deletions test/unittest/statistics/rtps/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ set(STATISTICS_RTPS_MONITORSERVICETESTS_SOURCE
${PROJECT_SOURCE_DIR}/src/cpp/rtps/history/TopicPayloadPoolRegistry.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/messages/CDRMessage.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/network/NetworkBuffer.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/network/NetworkConfiguration.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/network/NetworkFactory.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/network/utils/netmask_filter.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/network/utils/network.cpp
Expand Down
Loading
Loading