Skip to content

Commit

Permalink
Fix asymmetric whitelist matching (#3733)
Browse files Browse the repository at this point in the history
* Refs #18854: Asymmetric whitelist regression test

Signed-off-by: JesusPoderoso <[email protected]>

* Refs #18854: Fix Windows build error

Signed-off-by: JesusPoderoso <[email protected]>

* Refs #18854: Apply rev suggestions

Signed-off-by: JesusPoderoso <[email protected]>

* Refs #19203: Add more test cases

Signed-off-by: Juan López Fernández <[email protected]>

* Refs #19203: Asymmetric whitelist matching fix: transform_remote_locators refactor

Signed-off-by: Juan López Fernández <[email protected]>

* Refs #19203: Tiny fixes

Signed-off-by: Juan Lopez Fernandez <[email protected]>

* Refs #19203: Add warnings for non-localhost local address in initial peers and discovery server

Signed-off-by: Juan Lopez Fernandez <[email protected]>

* Refs #19203: Bonus fix: TCPv6 + whitelist

Signed-off-by: Juan Lopez Fernandez <[email protected]>

* Refs #19203: Avoid API/ABI break

Signed-off-by: Juan Lopez Fernandez <[email protected]>

* Refs #19203: Fix TCP when no whitelist and initial peer != localhost

Signed-off-by: Eduardo Ponz <[email protected]>

* Refs #19203: Improve some comments

Signed-off-by: Eduardo Ponz <[email protected]>

* Refs #19203: Uncrustify

Signed-off-by: Eduardo Ponz <[email protected]>

* Refs #19203: Fix missing include

Signed-off-by: Eduardo Ponz <[email protected]>

* Refs #19203: Revert locator scope append in TCPChannelResourceBasic::connect

Signed-off-by: Juan Lopez Fernandez <[email protected]>

* Refs #19203: Disable (almost) all IPv6 tests

Signed-off-by: Juan Lopez Fernandez <[email protected]>

---------

Signed-off-by: JesusPoderoso <[email protected]>
Signed-off-by: Juan López Fernández <[email protected]>
Signed-off-by: Juan Lopez Fernandez <[email protected]>
Signed-off-by: Eduardo Ponz <[email protected]>
Co-authored-by: JesusPoderoso <[email protected]>
Co-authored-by: Eduardo Ponz <[email protected]>
  • Loading branch information
3 people authored Sep 21, 2023
1 parent e00b8e3 commit c8ab860
Show file tree
Hide file tree
Showing 40 changed files with 790 additions and 135 deletions.
36 changes: 36 additions & 0 deletions include/fastdds/dds/core/policy/ParameterTypes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ enum ParameterId_t : uint16_t
PID_CUSTOM_RELATED_SAMPLE_IDENTITY = 0x800f,
PID_DISABLE_POSITIVE_ACKS = 0x8005,
PID_DATASHARING = 0x8006,
PID_NETWORK_CONFIGURATION_SET = 0x8007,
};

/*!
Expand Down Expand Up @@ -886,6 +887,41 @@ class ParameterBuiltinEndpointSet_t : public Parameter_t

#define PARAMETER_BUILTINENDPOINTSET_LENGTH 4

/**
* @ingroup PARAMETER_MODULE
*/
class ParameterNetworkConfigSet_t : public Parameter_t
{
public:

//!Network Config Set <br> By default, 0.
fastrtps::rtps::NetworkConfigSet_t netconfigSet;

/**
* @brief Constructor without parameters
*/
ParameterNetworkConfigSet_t()
: netconfigSet(0)
{
}

/**
* Constructor using a parameter PID and the parameter length
*
* @param pid Pid of the parameter
* @param in_length Its associated length
*/
ParameterNetworkConfigSet_t(
ParameterId_t pid,
uint16_t in_length)
: Parameter_t(pid, in_length)
, netconfigSet(0)
{
}

};

#define PARAMETER_NETWORKCONFIGSET_LENGTH 4

/**
* @ingroup PARAMETER_MODULE
Expand Down
5 changes: 5 additions & 0 deletions include/fastdds/rtps/attributes/RTPSParticipantAttributes.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <fastdds/rtps/common/Locator.h>
#include <fastdds/rtps/common/PortParameters.h>
#include <fastdds/rtps/common/Time_t.h>
#include <fastdds/rtps/common/Types.h>
#include <fastdds/rtps/flowcontrol/FlowControllerDescriptor.hpp>
#include <fastdds/rtps/flowcontrol/ThroughputControllerDescriptor.h>
#include <fastdds/rtps/resources/ResourceManagement.h>
Expand Down Expand Up @@ -381,6 +382,9 @@ class BuiltinAttributes
//! TypeLookup Service settings
TypeLookupSettings typelookup_config;

//! Network Configuration
NetworkConfigSet_t network_configuration;

//! Metatraffic Unicast Locator List
LocatorList_t metatrafficUnicastLocatorList;

Expand Down Expand Up @@ -424,6 +428,7 @@ class BuiltinAttributes
(this->use_WriterLivelinessProtocol == b.use_WriterLivelinessProtocol) &&
(typelookup_config.use_client == b.typelookup_config.use_client) &&
(typelookup_config.use_server == b.typelookup_config.use_server) &&
(this->network_configuration == b.network_configuration) &&
(this->metatrafficUnicastLocatorList == b.metatrafficUnicastLocatorList) &&
(this->metatrafficMulticastLocatorList == b.metatrafficMulticastLocatorList) &&
(this->metatraffic_external_unicast_locators == b.metatraffic_external_unicast_locators) &&
Expand Down
7 changes: 3 additions & 4 deletions include/fastdds/rtps/builtin/BuiltinProtocols.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,10 @@ class BuiltinProtocols
LocatorList_t& loclist);

/**
* Traverses the list of discover servers translating from remote to local locators
* if possible
* @param nf NetworkFactory used to make the translation
* Traverses the list of discover servers filtering out unsupported or not allowed remote locators
* @param nf NetworkFactory used to make the filtering
*/
void transform_server_remote_locators(
void filter_server_remote_locators(
NetworkFactory& nf);

//!BuiltinAttributes of the builtin protocols.
Expand Down
24 changes: 24 additions & 0 deletions include/fastdds/rtps/builtin/data/NetworkConfiguration.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// 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_BUILTIN_DATA__NETWORKCONFIGURATION_HPP
#define FASTDDS_RTPS_BUILTIN_DATA__NETWORKCONFIGURATION_HPP

#define DISC_NETWORK_CONFIGURATION_LISTENING_LOCALHOST_ALL (0x0000000F)

#endif // FASTDDS_RTPS_BUILTIN_DATA__NETWORKCONFIGURATION_HPP
2 changes: 2 additions & 0 deletions include/fastdds/rtps/builtin/data/ParticipantProxyData.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ class ParticipantProxyData
bool m_expectsInlineQos;
//!Available builtin endpoints
BuiltinEndpointSet_t m_availableBuiltinEndpoints;
//!Network configuration
NetworkConfigSet_t m_networkConfiguration;
//!Metatraffic locators
RemoteLocatorList metatraffic_locators;
//!Default locators
Expand Down
24 changes: 24 additions & 0 deletions include/fastdds/rtps/builtin/data/ReaderProxyData.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,28 @@ class ReaderProxyData
return m_guid;
}

RTPS_DllAPI void networkConfiguration(
const NetworkConfigSet_t& networkConfiguration)
{
m_networkConfiguration = networkConfiguration;
}

RTPS_DllAPI void networkConfiguration(
NetworkConfigSet_t&& networkConfiguration)
{
m_networkConfiguration = std::move(networkConfiguration);
}

RTPS_DllAPI const NetworkConfigSet_t& networkConfiguration() const
{
return m_networkConfiguration;
}

RTPS_DllAPI NetworkConfigSet_t& networkConfiguration()
{
return m_networkConfiguration;
}

RTPS_DllAPI bool has_locators() const
{
return !remote_locators_.unicast.empty() || !remote_locators_.multicast.empty();
Expand Down Expand Up @@ -459,6 +481,8 @@ class ReaderProxyData

//!GUID
GUID_t m_guid;
//!Network configuration
NetworkConfigSet_t m_networkConfiguration;
//!Holds locator information
RemoteLocatorList remote_locators_;
//!GUID_t of the Reader converted to InstanceHandle_t
Expand Down
25 changes: 25 additions & 0 deletions include/fastdds/rtps/builtin/data/WriterProxyData.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,28 @@ class WriterProxyData
return m_guid;
}

RTPS_DllAPI void networkConfiguration(
const NetworkConfigSet_t& networkConfiguration)
{
m_networkConfiguration = networkConfiguration;
}

RTPS_DllAPI void networkConfiguration(
NetworkConfigSet_t&& networkConfiguration)
{
m_networkConfiguration = std::move(networkConfiguration);
}

RTPS_DllAPI const NetworkConfigSet_t& networkConfiguration() const
{
return m_networkConfiguration;
}

RTPS_DllAPI NetworkConfigSet_t& networkConfiguration()
{
return m_networkConfiguration;
}

RTPS_DllAPI void persistence_guid(
const GUID_t& guid)
{
Expand Down Expand Up @@ -440,6 +462,9 @@ class WriterProxyData
//!GUID
GUID_t m_guid;

//!Network configuration
NetworkConfigSet_t m_networkConfiguration;

//!Holds locator information
RemoteLocatorList remote_locators_;

Expand Down
1 change: 1 addition & 0 deletions include/fastdds/rtps/common/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ using octet = unsigned char;
//typedef unsigned short ushort;
using SubmessageFlag = unsigned char;
using BuiltinEndpointSet_t = uint32_t;
using NetworkConfigSet_t = uint32_t;
using Count_t = uint32_t;

#define BIT0 0x01u
Expand Down
32 changes: 27 additions & 5 deletions include/fastdds/rtps/transport/ChainingTransport.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,13 +161,12 @@ class ChainingTransport : public TransportInterface
}

/*!
* Call the low-level transport `is_locator_allowed()`.
* Must report whether the given locator is allowed by this transport.
* Call the low-level transport `is_localhost_allowed()`.
* Must report whether localhost locator is allowed
*/
RTPS_DllAPI bool is_locator_allowed(
const fastrtps::rtps::Locator_t& locator) const override
RTPS_DllAPI bool is_localhost_allowed() const override
{
return low_level_transport_->is_locator_allowed(locator);
return low_level_transport_->is_localhost_allowed();
}

/*!
Expand Down Expand Up @@ -351,6 +350,29 @@ class ChainingTransport : public TransportInterface
low_level_transport_->update_network_interfaces();
}

//! Call the low-level transport `transform_remote_locator()`.
//! Transforms a remote locator into a locator optimized for local communications,
//! if allowed by both local and remote transports.
RTPS_DllAPI bool transform_remote_locator(
const fastrtps::rtps::Locator_t& remote_locator,
fastrtps::rtps::Locator_t& result_locator,
bool allowed_remote_localhost,
bool allowed_local_localhost) const override
{
return low_level_transport_->transform_remote_locator(remote_locator, result_locator, allowed_remote_localhost,
allowed_local_localhost);
}

/*!
* Call the low-level transport `is_locator_allowed()`.
* Must report whether the given locator is allowed by this transport.
*/
RTPS_DllAPI bool is_locator_allowed(
const fastrtps::rtps::Locator_t& locator) const override
{
return low_level_transport_->is_locator_allowed(locator);
}

protected:

std::unique_ptr<TransportInterface> low_level_transport_;
Expand Down
32 changes: 31 additions & 1 deletion include/fastdds/rtps/transport/TransportInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
#include <fastdds/rtps/common/Locator.h>
#include <fastdds/rtps/common/LocatorSelector.hpp>
#include <fastdds/rtps/common/PortParameters.h>
#include <fastdds/rtps/transport/SenderResource.h>
#include <fastdds/rtps/transport/TransportDescriptorInterface.h>
#include <fastdds/rtps/transport/TransportReceiverInterface.h>
#include <fastdds/rtps/transport/SenderResource.h>

namespace eprosima {
namespace fastdds {
Expand Down Expand Up @@ -246,6 +246,36 @@ class RTPS_DllAPI TransportInterface
return transport_kind_;
}

/**
* Transforms a remote locator into a locator optimized for local communications.
*
* If the remote locator corresponds to one of the local interfaces, it is converted
* to the corresponding local address if allowed by both local and remote transports.
*
* @param [in] remote_locator Locator to be converted.
* @param [out] result_locator Converted locator.
* @param [in] allowed_remote_localhost Whether localhost is allowed (and hence used) in the remote transport.
* @param [in] allowed_local_localhost Whether localhost is allowed locally (by this or other transport).
*
* @return false if the input locator is not supported/allowed by this transport, true otherwise.
*/
virtual bool transform_remote_locator(
const Locator& remote_locator,
Locator& result_locator,
bool allowed_remote_localhost,
bool allowed_local_localhost) const
{
static_cast<void>(allowed_remote_localhost);
static_cast<void>(allowed_local_localhost);
return transform_remote_locator(remote_locator, result_locator);
}

//! Must report whether localhost locator is allowed
virtual bool is_localhost_allowed() const
{
return true;
}

protected:

TransportInterface(
Expand Down
7 changes: 4 additions & 3 deletions include/fastrtps/qos/ParameterTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#if HAVE_SECURITY
#include <fastdds/rtps/security/accesscontrol/ParticipantSecurityAttributes.h>
#include <fastdds/rtps/security/accesscontrol/EndpointSecurityAttributes.h>
#endif
#endif // if HAVE_SECURITY

#include <string>
#include <vector>
Expand All @@ -54,16 +54,17 @@ using ParameterCount_t = fastdds::dds::ParameterCount_t;
using ParameterEntityId_t = fastdds::dds::ParameterEntityId_t;
using ParameterTime_t = fastdds::dds::ParameterTime_t;
using ParameterBuiltinEndpointSet_t = fastdds::dds::ParameterBuiltinEndpointSet_t;
using ParameterNetworkConfigSet_t = fastdds::dds::ParameterNetworkConfigSet_t;
using ParameterPropertyList_t = fastdds::dds::ParameterPropertyList_t;
using ParameterSampleIdentity_t = fastdds::dds::ParameterSampleIdentity_t;
#if HAVE_SECURITY
using ParameterToken_t = fastdds::dds::ParameterToken_t;
using ParameterParticipantSecurityInfo_t = fastdds::dds::ParameterParticipantSecurityInfo_t;
using ParameterEndpointSecurityInfo_t = fastdds::dds::ParameterEndpointSecurityInfo_t;
#endif
#endif // if HAVE_SECURITY

} //end of namespace
} //end of namespace eprosima

#endif
#endif // ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC
#endif /* PARAMETERTYPES_H_ */
22 changes: 22 additions & 0 deletions src/cpp/fastdds/core/policy/ParameterSerializer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,28 @@ inline bool ParameterSerializer<ParameterBuiltinEndpointSet_t>::read_content_fro
return fastrtps::rtps::CDRMessage::readUInt32(cdr_message, &parameter.endpointSet);
}

template<>
inline bool ParameterSerializer<ParameterNetworkConfigSet_t>::add_content_to_cdr_message(
const ParameterNetworkConfigSet_t& parameter,
fastrtps::rtps::CDRMessage_t* cdr_message)
{
return fastrtps::rtps::CDRMessage::addUInt32(cdr_message, parameter.netconfigSet);
}

template<>
inline bool ParameterSerializer<ParameterNetworkConfigSet_t>::read_content_from_cdr_message(
ParameterNetworkConfigSet_t& parameter,
fastrtps::rtps::CDRMessage_t* cdr_message,
const uint16_t parameter_length)
{
if (parameter_length != PARAMETER_NETWORKCONFIGSET_LENGTH)
{
return false;
}
parameter.length = parameter_length;
return fastrtps::rtps::CDRMessage::readUInt32(cdr_message, &parameter.netconfigSet);
}

template<>
inline uint32_t ParameterSerializer<ParameterPropertyList_t>::cdr_serialized_size(
const ParameterPropertyList_t& parameter)
Expand Down
2 changes: 2 additions & 0 deletions src/cpp/fastdds/domain/DomainParticipantImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2240,6 +2240,8 @@ bool DomainParticipantImpl::can_qos_be_updated(
from.wire_protocol().builtin.typelookup_config.use_client) ||
!(to.wire_protocol().builtin.typelookup_config.use_server ==
from.wire_protocol().builtin.typelookup_config.use_server) ||
!(to.wire_protocol().builtin.network_configuration ==
from.wire_protocol().builtin.network_configuration) ||
!(to.wire_protocol().builtin.metatrafficUnicastLocatorList ==
from.wire_protocol().builtin.metatrafficUnicastLocatorList) ||
!(to.wire_protocol().builtin.metatrafficMulticastLocatorList ==
Expand Down
Loading

0 comments on commit c8ab860

Please sign in to comment.