From 725f1c75af272d0b1335c5c755ce313116b6118c Mon Sep 17 00:00:00 2001 From: juanlofer-eprosima <88179026+juanlofer-eprosima@users.noreply.github.com> Date: Sun, 17 Mar 2024 08:48:05 +0100 Subject: [PATCH] Add netmask filter transport configuration + interface allowlist and blocklist (#4241) * Allowlist and blocklist implementation Signed-off-by: Juan Lopez Fernandez Signed-off-by: EduPonz * Update XML parser Signed-off-by: Juan Lopez Fernandez Signed-off-by: EduPonz * Update versions.md Signed-off-by: Juan Lopez Fernandez Signed-off-by: EduPonz * Fix linker errors in security and statistics tests Signed-off-by: Juan Lopez Fernandez Signed-off-by: EduPonz * Rename NetmaskFilterKind.h -> NetmaskFilterKind.hpp Signed-off-by: Juan Lopez Fernandez Signed-off-by: EduPonz * Add safety check Signed-off-by: Juan Lopez Fernandez Signed-off-by: EduPonz * Rebase fix Signed-off-by: Juan Lopez Fernandez Signed-off-by: EduPonz * Apply suggestions Signed-off-by: Juan Lopez Fernandez Signed-off-by: EduPonz * Minor changes Signed-off-by: Juan Lopez Fernandez Signed-off-by: EduPonz * Add IP string attribute to NetworkInterface and move implementation to cpp Signed-off-by: Juan Lopez Fernandez Signed-off-by: EduPonz * Windows fixes Signed-off-by: Juan Lopez Fernandez Signed-off-by: EduPonz * Uncrustify Signed-off-by: Juan Lopez Fernandez Signed-off-by: EduPonz * Add missing change: serialize writer GUID before locators Signed-off-by: Juan Lopez Fernandez Signed-off-by: EduPonz * Apply more suggestions Signed-off-by: Juan Lopez Fernandez Signed-off-by: EduPonz * One more suggestion Signed-off-by: Juan Lopez Fernandez Signed-off-by: EduPonz * Make NetmaskFilterKind optional in allowlist XML parsing Signed-off-by: Juan Lopez Fernandez Signed-off-by: EduPonz --------- Signed-off-by: Juan Lopez Fernandez Signed-off-by: EduPonz --- .../fastdds/dds/core/policy/QosPolicies.hpp | 7 + .../attributes/RTPSParticipantAttributes.h | 5 + include/fastdds/rtps/common/Guid.h | 30 ++- include/fastdds/rtps/common/GuidPrefix_t.hpp | 38 +++ .../fastdds/rtps/common/LocatorWithMask.hpp | 30 ++- .../rtps/participant/RTPSParticipant.h | 7 + .../rtps/transport/ChainingTransport.h | 9 + .../transport/SocketTransportDescriptor.h | 15 +- .../transport/TransportDescriptorInterface.h | 30 ++- .../rtps/transport/TransportInterface.h | 11 + .../network/AllowedNetworkInterface.hpp | 63 +++++ .../network/BlockedNetworkInterface.hpp | 63 +++++ .../transport/network/NetmaskFilterKind.hpp | 45 ++++ .../transport/network/NetworkInterface.hpp | 87 +++++++ .../network/NetworkInterfaceWithFilter.hpp | 93 +++++++ include/fastrtps/utils/IPFinder.h | 2 + .../collections/ResourceLimitedVector.hpp | 20 ++ include/fastrtps/xmlparser/XMLParser.h | 12 + include/fastrtps/xmlparser/XMLParserCommon.h | 4 + resources/xsd/fastRTPS_profiles.xsd | 120 +++++++-- src/cpp/CMakeLists.txt | 9 +- src/cpp/fastdds/publisher/PublisherImpl.cpp | 22 +- src/cpp/fastdds/subscriber/SubscriberImpl.cpp | 22 +- src/cpp/fastdds/utils/QosConverters.cpp | 2 + src/cpp/rtps/RTPSDomain.cpp | 4 +- .../builtin/data/ParticipantProxyData.cpp | 12 +- src/cpp/rtps/builtin/data/ReaderProxyData.cpp | 29 ++- src/cpp/rtps/builtin/data/WriterProxyData.cpp | 29 ++- .../rtps/builtin/discovery/endpoint/EDP.cpp | 6 +- .../DS/PDPSecurityInitiatorListener.cpp | 2 +- .../builtin/discovery/participant/PDP.cpp | 4 +- .../discovery/participant/PDPListener.cpp | 4 +- .../participant/PDPServerListener.cpp | 4 +- src/cpp/rtps/common/GuidPrefix_t.cpp | 51 ++++ src/cpp/rtps/common/GuidUtils.hpp | 10 + src/cpp/rtps/common/LocatorWithMask.cpp | 98 ++++++++ src/cpp/rtps/network/NetworkFactory.cpp | 53 ++++ src/cpp/rtps/network/NetworkFactory.h | 53 +++- .../external_locators.cpp} | 108 +++------ .../external_locators.hpp} | 16 +- src/cpp/rtps/network/utils/netmask_filter.cpp | 170 +++++++++++++ src/cpp/rtps/network/utils/netmask_filter.hpp | 109 +++++++++ src/cpp/rtps/network/utils/network.cpp | 53 ++++ src/cpp/rtps/network/utils/network.hpp | 48 ++++ src/cpp/rtps/participant/RTPSParticipant.cpp | 5 + .../rtps/participant/RTPSParticipantImpl.cpp | 100 ++++++-- .../rtps/participant/RTPSParticipantImpl.h | 7 + src/cpp/rtps/reader/WriterProxy.cpp | 6 +- src/cpp/rtps/transport/TCPAcceptor.cpp | 6 +- src/cpp/rtps/transport/TCPAcceptor.h | 2 +- src/cpp/rtps/transport/TCPAcceptorBasic.cpp | 6 +- src/cpp/rtps/transport/TCPAcceptorBasic.h | 4 +- src/cpp/rtps/transport/TCPAcceptorSecure.cpp | 4 +- src/cpp/rtps/transport/TCPAcceptorSecure.h | 4 +- .../rtps/transport/TCPTransportInterface.cpp | 17 +- .../rtps/transport/TCPTransportInterface.h | 16 +- src/cpp/rtps/transport/TCPv4Transport.cpp | 134 ++++++++-- src/cpp/rtps/transport/TCPv4Transport.h | 7 +- src/cpp/rtps/transport/TCPv6Transport.cpp | 138 +++++++++-- src/cpp/rtps/transport/TCPv6Transport.h | 11 +- src/cpp/rtps/transport/UDPChannelResource.h | 54 ++++- .../rtps/transport/UDPTransportInterface.cpp | 53 +++- .../rtps/transport/UDPTransportInterface.h | 20 +- src/cpp/rtps/transport/UDPv4Transport.cpp | 169 ++++++++++--- src/cpp/rtps/transport/UDPv4Transport.h | 7 +- src/cpp/rtps/transport/UDPv6Transport.cpp | 160 +++++++++--- src/cpp/rtps/transport/UDPv6Transport.h | 11 +- .../transport/network/NetmaskFilterKind.cpp | 54 +++++ .../transport/network/NetworkInterface.cpp | 52 ++++ .../network/NetworkInterfaceWithFilter.cpp | 66 +++++ .../rtps/transport/test_UDPv4Transport.cpp | 12 +- src/cpp/rtps/transport/test_UDPv4Transport.h | 5 +- src/cpp/rtps/writer/StatefulWriter.cpp | 4 +- src/cpp/rtps/writer/StatelessWriter.cpp | 4 +- src/cpp/rtps/xmlparser/XMLParser.cpp | 229 ++++++++++++++++++ src/cpp/rtps/xmlparser/XMLParserCommon.cpp | 4 + src/cpp/utils/IPFinder.cpp | 153 ++++++++---- src/cpp/utils/SystemInfo.cpp | 55 +++++ src/cpp/utils/SystemInfo.hpp | 30 +++ .../rtps/network/NetworkFactory.h | 28 +++ .../rtps/participant/RTPSParticipant.h | 5 + .../attributes/RTPSParticipantAttributes.h | 7 +- .../rtps/network/utils/external_locators.hpp} | 14 +- test/unittest/dds/collections/CMakeLists.txt | 12 + .../dds/core/condition/CMakeLists.txt | 45 ++++ test/unittest/dds/core/entity/CMakeLists.txt | 13 +- test/unittest/dds/publisher/CMakeLists.txt | 18 +- test/unittest/dds/status/CMakeLists.txt | 41 ++-- test/unittest/dds/subscriber/CMakeLists.txt | 25 +- .../dds/topic/DDSSQLFilter/CMakeLists.txt | 11 + test/unittest/dynamic_types/CMakeLists.txt | 36 +-- test/unittest/logging/CMakeLists.txt | 15 ++ .../logging/log_macros/CMakeLists.txt | 33 +++ test/unittest/rtps/builtin/CMakeLists.txt | 7 + test/unittest/rtps/common/CMakeLists.txt | 20 ++ test/unittest/rtps/discovery/CMakeLists.txt | 76 +++--- test/unittest/rtps/flowcontrol/CMakeLists.txt | 23 +- test/unittest/rtps/history/CMakeLists.txt | 58 ++++- test/unittest/rtps/network/CMakeLists.txt | 34 ++- ...sorTests.cpp => ExternalLocatorsTests.cpp} | 31 +-- test/unittest/rtps/persistence/CMakeLists.txt | 21 +- test/unittest/rtps/reader/CMakeLists.txt | 49 +++- .../rtps/resources/timedevent/CMakeLists.txt | 18 +- test/unittest/rtps/security/CMakeLists.txt | 31 ++- test/unittest/rtps/writer/CMakeLists.txt | 26 +- .../security/accesscontrol/CMakeLists.txt | 32 ++- .../security/authentication/CMakeLists.txt | 19 +- .../security/cryptography/CMakeLists.txt | 17 +- test/unittest/security/logging/CMakeLists.txt | 13 +- test/unittest/statistics/dds/CMakeLists.txt | 84 ++++--- test/unittest/statistics/rtps/CMakeLists.txt | 73 +++--- test/unittest/transport/CMakeLists.txt | 53 +++- test/unittest/utils/CMakeLists.txt | 36 +++ test/unittest/xmlparser/CMakeLists.txt | 26 +- ...P_transport_descriptors_config_profile.xml | 12 +- test/unittest/xmlparser/XMLParserTests.cpp | 69 +++++- .../xmlparser/XMLProfileParserTests.cpp | 17 +- test/unittest/xmlparser/test_xml_profile.xml | 1 + .../xmlparser/test_xml_profile_env_var.xml | 1 + test/unittest/xtypes/CMakeLists.txt | 32 ++- versions.md | 1 + 121 files changed, 3726 insertions(+), 675 deletions(-) create mode 100644 include/fastdds/rtps/transport/network/AllowedNetworkInterface.hpp create mode 100644 include/fastdds/rtps/transport/network/BlockedNetworkInterface.hpp create mode 100644 include/fastdds/rtps/transport/network/NetmaskFilterKind.hpp create mode 100644 include/fastdds/rtps/transport/network/NetworkInterface.hpp create mode 100644 include/fastdds/rtps/transport/network/NetworkInterfaceWithFilter.hpp create mode 100644 src/cpp/rtps/common/GuidPrefix_t.cpp create mode 100644 src/cpp/rtps/common/LocatorWithMask.cpp rename src/cpp/rtps/network/{ExternalLocatorsProcessor.cpp => utils/external_locators.cpp} (81%) rename src/cpp/rtps/network/{ExternalLocatorsProcessor.hpp => utils/external_locators.hpp} (93%) create mode 100644 src/cpp/rtps/network/utils/netmask_filter.cpp create mode 100644 src/cpp/rtps/network/utils/netmask_filter.hpp create mode 100644 src/cpp/rtps/network/utils/network.cpp create mode 100644 src/cpp/rtps/network/utils/network.hpp create mode 100644 src/cpp/rtps/transport/network/NetmaskFilterKind.cpp create mode 100644 src/cpp/rtps/transport/network/NetworkInterface.cpp create mode 100644 src/cpp/rtps/transport/network/NetworkInterfaceWithFilter.cpp rename test/mock/rtps/{ExternalLocatorsProcessor/rtps/network/ExternalLocatorsProcessor.hpp => external_locators/rtps/network/utils/external_locators.hpp} (94%) rename test/unittest/rtps/network/{ExternalLocatorsProcessorTests.cpp => ExternalLocatorsTests.cpp} (96%) diff --git a/include/fastdds/dds/core/policy/QosPolicies.hpp b/include/fastdds/dds/core/policy/QosPolicies.hpp index 453c6362bb4..5ac318e57db 100644 --- a/include/fastdds/dds/core/policy/QosPolicies.hpp +++ b/include/fastdds/dds/core/policy/QosPolicies.hpp @@ -33,6 +33,8 @@ #include #include #include +#include + #include #include @@ -2748,6 +2750,7 @@ class TransportConfigQos : public QosPolicy , send_socket_buffer_size(0) , listen_socket_buffer_size(0) , max_msg_size_no_frag(0) + , netmask_filter(fastdds::rtps::NetmaskFilterKind::AUTO) { } @@ -2765,6 +2768,7 @@ class TransportConfigQos : public QosPolicy (this->listen_socket_buffer_size == b.listen_socket_buffer_size) && (this->builtin_transports_reception_threads_ == b.builtin_transports_reception_threads_) && (this->max_msg_size_no_frag == b.max_msg_size_no_frag) && + (this->netmask_filter == b.netmask_filter) && QosPolicy::operator ==(b); } @@ -2799,6 +2803,9 @@ class TransportConfigQos : public QosPolicy * higher than 65500K. */ uint32_t max_msg_size_no_frag; + + //! Netmask filter configuration + fastdds::rtps::NetmaskFilterKind netmask_filter; }; //! Qos Policy to configure the endpoint diff --git a/include/fastdds/rtps/attributes/RTPSParticipantAttributes.h b/include/fastdds/rtps/attributes/RTPSParticipantAttributes.h index a79d86a1ed5..9a826b3933c 100644 --- a/include/fastdds/rtps/attributes/RTPSParticipantAttributes.h +++ b/include/fastdds/rtps/attributes/RTPSParticipantAttributes.h @@ -35,6 +35,7 @@ #include #include #include +#include #include #include #include @@ -467,6 +468,7 @@ class RTPSParticipantAttributes (this->ignore_non_matching_locators == b.ignore_non_matching_locators) && (this->sendSocketBufferSize == b.sendSocketBufferSize) && (this->listenSocketBufferSize == b.listenSocketBufferSize) && + (this->netmaskFilter == b.netmaskFilter) && (this->builtin == b.builtin) && (this->port == b.port) && (this->userData == b.userData) && @@ -530,6 +532,9 @@ class RTPSParticipantAttributes */ uint32_t listenSocketBufferSize = 0; + //! Netmask filter configuration + fastdds::rtps::NetmaskFilterKind netmaskFilter = fastdds::rtps::NetmaskFilterKind::AUTO; + //! Optionally allows user to define the GuidPrefix_t GuidPrefix_t prefix; diff --git a/include/fastdds/rtps/common/Guid.h b/include/fastdds/rtps/common/Guid.h index a105b1279d7..b82caac24bc 100644 --- a/include/fastdds/rtps/common/Guid.h +++ b/include/fastdds/rtps/common/Guid.h @@ -76,7 +76,9 @@ struct RTPS_DllAPI GUID_t } /** - * Checks whether this guid is for an entity on the same host as another guid. + * Checks whether this guid is from an entity on the same host as another guid. + * + * @note This method assumes the value of \c other_guid was originally assigned by Fast-DDS vendor. * * @param other_guid GUID_t to compare to. * @@ -85,12 +87,24 @@ struct RTPS_DllAPI GUID_t bool is_on_same_host_as( const GUID_t& other_guid) const { - return memcmp(guidPrefix.value, other_guid.guidPrefix.value, 4) == 0; + return guidPrefix.is_on_same_host_as(other_guid.guidPrefix); + } + + /** + * Checks whether this guid is from a (Fast-DDS) entity created on this host (from where this method is called). + * + * @return true when this guid is from a (Fast-DDS) entity created on this host, false otherwise. + */ + bool is_from_this_host() const + { + return guidPrefix.is_from_this_host(); } /** * Checks whether this guid is for an entity on the same host and process as another guid. * + * @note This method assumes the value of \c other_guid was originally assigned by Fast-DDS vendor. + * * @param other_guid GUID_t to compare to. * * @return true when this guid is on the same host and process, false otherwise. @@ -98,7 +112,17 @@ struct RTPS_DllAPI GUID_t bool is_on_same_process_as( const GUID_t& other_guid) const { - return memcmp(guidPrefix.value, other_guid.guidPrefix.value, 8) == 0; + return guidPrefix.is_on_same_process_as(other_guid.guidPrefix); + } + + /** + * Checks whether this guid is from a (Fast-DDS) entity created on this process (from where this method is called). + * + * @return true when this guid is from a (Fast-DDS) entity created on this process, false otherwise. + */ + bool is_from_this_process() const + { + return guidPrefix.is_from_this_process(); } /** diff --git a/include/fastdds/rtps/common/GuidPrefix_t.hpp b/include/fastdds/rtps/common/GuidPrefix_t.hpp index 82a18a7d354..b7a0be73d4e 100644 --- a/include/fastdds/rtps/common/GuidPrefix_t.hpp +++ b/include/fastdds/rtps/common/GuidPrefix_t.hpp @@ -44,6 +44,44 @@ struct RTPS_DllAPI GuidPrefix_t memset(value, 0, size); } + /** + * Checks whether this guid prefix is from an entity on the same host as another guid prefix. + * + * @note This method assumes the value of \c other_guid_prefix was originally assigned by Fast-DDS vendor. + * + * @param other_guid_prefix GuidPrefix_t to compare to. + * + * @return true when this guid prefix is on the same host, false otherwise. + */ + bool is_on_same_host_as( + const GuidPrefix_t& other_guid_prefix) const; + + /** + * Checks whether this guid prefix is from a (Fast-DDS) entity created on this host (from where this method is called). + * + * @return true when this guid prefix is from a (Fast-DDS) entity created on this host, false otherwise. + */ + bool is_from_this_host() const; + + /** + * Checks whether this guid prefix is for an entity on the same host and process as another guid prefix. + * + * @note This method assumes the value of \c other_guid_prefix was originally assigned by Fast-DDS vendor. + * + * @param other_guid_prefix GuidPrefix_t to compare to. + * + * @return true when this guid prefix is on the same host and process, false otherwise. + */ + bool is_on_same_process_as( + const GuidPrefix_t& other_guid_prefix) const; + + /** + * Checks whether this guid prefix is from a (Fast-DDS) entity created on this host and process (from where this method is called). + * + * @return true when this guid prefix is from a (Fast-DDS) entity created on this host and process, false otherwise. + */ + bool is_from_this_process() const; + static GuidPrefix_t unknown() { return GuidPrefix_t(); diff --git a/include/fastdds/rtps/common/LocatorWithMask.hpp b/include/fastdds/rtps/common/LocatorWithMask.hpp index 52a91d243e3..cc311c9b7a3 100644 --- a/include/fastdds/rtps/common/LocatorWithMask.hpp +++ b/include/fastdds/rtps/common/LocatorWithMask.hpp @@ -19,6 +19,8 @@ #ifndef _FASTDDS_RTPS_COMMON_LOCATORWITHMASK_HPP_ #define _FASTDDS_RTPS_COMMON_LOCATORWITHMASK_HPP_ +#include + #include #include @@ -39,10 +41,7 @@ class RTPS_DllAPI LocatorWithMask : public Locator * * @return number of significant bits on the address of this locator. */ - uint8_t mask() const - { - return mask_; - } + uint8_t mask() const; /** * Set the number of significant bits on the address of this locator. @@ -50,16 +49,31 @@ class RTPS_DllAPI LocatorWithMask : public Locator * @param mask number of significant bits on the address of this locator. */ void mask( - uint8_t mask) - { - mask_ = mask; - } + uint8_t mask); + + /** + * Check whether the given locator is from the same network as this locator. + * + * @param loc locator to check if belonging to the same network as this locator. + * + * @return true if the two locators are from the same network, false otherwise. + */ + bool matches( + const Locator& loc) const; + + //! Copy assignment + LocatorWithMask& operator =( + const Locator& loc); private: uint8_t mask_ = 24; }; +RTPS_DllAPI std::ostream& operator <<( + std::ostream& output, + const LocatorWithMask& loc); + } // namespace rtps } // namespace fastdds } // namespace eprosima diff --git a/include/fastdds/rtps/participant/RTPSParticipant.h b/include/fastdds/rtps/participant/RTPSParticipant.h index 06ea42d2ba9..1b3a19abd56 100644 --- a/include/fastdds/rtps/participant/RTPSParticipant.h +++ b/include/fastdds/rtps/participant/RTPSParticipant.h @@ -299,6 +299,13 @@ class RTPS_DllAPI RTPSParticipant bool ignore_reader( const GUID_t& reader_guid); + /** + * @brief Returns registered transports' netmask filter information (transport's netmask filter kind and allowlist). + * + * @return A vector with all registered transports' netmask filter information. + */ + std::vector get_netmask_filter_info() const; + #if HAVE_SECURITY /** diff --git a/include/fastdds/rtps/transport/ChainingTransport.h b/include/fastdds/rtps/transport/ChainingTransport.h index 20a46aa9a31..da3094ab958 100644 --- a/include/fastdds/rtps/transport/ChainingTransport.h +++ b/include/fastdds/rtps/transport/ChainingTransport.h @@ -171,6 +171,15 @@ class ChainingTransport : public TransportInterface return low_level_transport_->is_localhost_allowed(); } + /*! + * Call the low-level transport `netmask_filter_info()`. + * Returns netmask filter information (transport's netmask filter kind and allowlist) + */ + RTPS_DllAPI NetmaskFilterInfo netmask_filter_info() const override + { + return low_level_transport_->netmask_filter_info(); + } + /*! * Call the low-level transport `DoInputLocatorsMatch()`. * Must report whether two locators map to the same internal channel. diff --git a/include/fastdds/rtps/transport/SocketTransportDescriptor.h b/include/fastdds/rtps/transport/SocketTransportDescriptor.h index 0b03eabdb23..80c5a3a6a19 100644 --- a/include/fastdds/rtps/transport/SocketTransportDescriptor.h +++ b/include/fastdds/rtps/transport/SocketTransportDescriptor.h @@ -19,6 +19,9 @@ #include #include +#include +#include +#include #include namespace eprosima { @@ -50,6 +53,7 @@ struct SocketTransportDescriptor : public PortBasedTransportDescriptor : PortBasedTransportDescriptor(maximumMessageSize, maximumInitialPeersRange) , sendBufferSize(0) , receiveBufferSize(0) + , netmask_filter(NetmaskFilterKind::AUTO) , TTL(s_defaultTTL) { } @@ -77,6 +81,9 @@ struct SocketTransportDescriptor : public PortBasedTransportDescriptor return (this->sendBufferSize == t.min_send_buffer_size() && this->receiveBufferSize == t.receiveBufferSize && this->interfaceWhiteList == t.interfaceWhiteList && + this->netmask_filter == t.netmask_filter && + this->interface_allowlist == t.interface_allowlist && + this->interface_blocklist == t.interface_blocklist && this->TTL == t.TTL && PortBasedTransportDescriptor::operator ==(t)); } @@ -85,8 +92,14 @@ struct SocketTransportDescriptor : public PortBasedTransportDescriptor uint32_t sendBufferSize; //! Length of the receive buffer. uint32_t receiveBufferSize; - //! Allowed interfaces in an IP string format. + //! Allowed interfaces in an IP or device name string format. std::vector interfaceWhiteList; + //! Transport's netmask filter configuration. + NetmaskFilterKind netmask_filter; + //! Allowed interfaces in an IP or device name string format, each with a specific netmask filter configuration. + std::vector interface_allowlist; + //! Blocked interfaces in an IP or device name string format. + std::vector interface_blocklist; //! Specified time to live (8bit - 255 max TTL) uint8_t TTL; }; diff --git a/include/fastdds/rtps/transport/TransportDescriptorInterface.h b/include/fastdds/rtps/transport/TransportDescriptorInterface.h index 47a9fbfd609..255ac0c1e1b 100644 --- a/include/fastdds/rtps/transport/TransportDescriptorInterface.h +++ b/include/fastdds/rtps/transport/TransportDescriptorInterface.h @@ -16,6 +16,7 @@ #define _FASTDDS_TRANSPORT_DESCRIPTOR_INTERFACE_H_ #include +#include #include #include @@ -51,11 +52,20 @@ struct TransportDescriptorInterface //! Copy constructor RTPS_DllAPI TransportDescriptorInterface( - const TransportDescriptorInterface& t) = default; + const TransportDescriptorInterface& t) + : maxMessageSize(t.maxMessageSize) + , maxInitialPeersRange(t.maxInitialPeersRange) + { + } //! Copy assignment RTPS_DllAPI TransportDescriptorInterface& operator =( - const TransportDescriptorInterface& t) = default; + const TransportDescriptorInterface& t) + { + maxMessageSize = t.maxMessageSize; + maxInitialPeersRange = t.maxInitialPeersRange; + return *this; + } //! Destructor virtual RTPS_DllAPI ~TransportDescriptorInterface() = default; @@ -92,11 +102,27 @@ struct TransportDescriptorInterface this->maxInitialPeersRange == t.max_initial_peers_range()); } + //! Lock internal mutex (for Fast-DDS internal use) + RTPS_DllAPI void lock() + { + mtx_.lock(); + } + + //! Unlock internal mutex (for Fast-DDS internal use) + RTPS_DllAPI void unlock() + { + mtx_.unlock(); + } + //! Maximum size of a single message in the transport uint32_t maxMessageSize; //! Number of channels opened with each initial remote peer. uint32_t maxInitialPeersRange; + +private: + + mutable std::mutex mtx_; }; } // namespace rtps diff --git a/include/fastdds/rtps/transport/TransportInterface.h b/include/fastdds/rtps/transport/TransportInterface.h index cea85d619bf..8ff96ee76f7 100644 --- a/include/fastdds/rtps/transport/TransportInterface.h +++ b/include/fastdds/rtps/transport/TransportInterface.h @@ -22,7 +22,10 @@ #include #include #include +#include #include +#include +#include #include #include #include @@ -43,6 +46,8 @@ static const std::string s_IPv4AddressAny = "0.0.0.0"; static const std::string s_IPv6AddressAny = "::"; using SendResourceList = std::vector>; +using NetmaskFilterInfo = std::pair>; +using TransportNetmaskFilterInfo = std::pair; /** * Interface against which to implement a transport layer, decoupled from FastRTPS internals. @@ -302,6 +307,12 @@ class RTPS_DllAPI TransportInterface return true; } + //! Returns netmask filter information (transport's netmask filter kind and allowlist) + virtual NetmaskFilterInfo netmask_filter_info() const + { + return {NetmaskFilterKind::AUTO, {}}; + } + protected: TransportInterface( diff --git a/include/fastdds/rtps/transport/network/AllowedNetworkInterface.hpp b/include/fastdds/rtps/transport/network/AllowedNetworkInterface.hpp new file mode 100644 index 00000000000..3b832ff10ba --- /dev/null +++ b/include/fastdds/rtps/transport/network/AllowedNetworkInterface.hpp @@ -0,0 +1,63 @@ +// Copyright 2024 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 AllowedNetworkInterface.hpp + */ + +#ifndef _FASTDDS_RTPS_TRANSPORT_NETWORK_ALLOWEDNETWORKINTERFACE_HPP_ +#define _FASTDDS_RTPS_TRANSPORT_NETWORK_ALLOWEDNETWORKINTERFACE_HPP_ + +#include +#include + +namespace eprosima { +namespace fastdds { +namespace rtps { + +/** + * Structure extending \c NetworkInterfaceWithFilter with information specific to allowed interfaces. + * + * @note When using this structure to interact with Fast-DDS, \c name is the only attribute the user needs to provide. + * The rest of the attributes are internally filled, and are in fact ignored even if already provided by the user. + */ +struct AllowedNetworkInterface : public NetworkInterfaceWithFilter +{ + using NetworkInterfaceWithFilter::NetworkInterfaceWithFilter; + + //! Destructor + virtual RTPS_DllAPI ~AllowedNetworkInterface() = default; + + //! Copy constructor + RTPS_DllAPI AllowedNetworkInterface( + const AllowedNetworkInterface& iface) = default; + + //! Copy assignment + RTPS_DllAPI AllowedNetworkInterface& operator =( + const AllowedNetworkInterface& iface) = default; + + //! Move constructor + RTPS_DllAPI AllowedNetworkInterface( + AllowedNetworkInterface&& iface) = default; + + //! Move assignment + RTPS_DllAPI AllowedNetworkInterface& operator =( + AllowedNetworkInterface&& iface) = default; +}; + +} // namespace rtps +} // namespace fastdds +} // namespace eprosima + +#endif // _FASTDDS_RTPS_TRANSPORT_NETWORK_ALLOWEDNETWORKINTERFACE_HPP_ diff --git a/include/fastdds/rtps/transport/network/BlockedNetworkInterface.hpp b/include/fastdds/rtps/transport/network/BlockedNetworkInterface.hpp new file mode 100644 index 00000000000..b9ef6f7eb70 --- /dev/null +++ b/include/fastdds/rtps/transport/network/BlockedNetworkInterface.hpp @@ -0,0 +1,63 @@ +// Copyright 2024 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 BlockedNetworkInterface.hpp + */ + +#ifndef _FASTDDS_RTPS_TRANSPORT_NETWORK_BLOCKEDNETWORKINTERFACE_HPP_ +#define _FASTDDS_RTPS_TRANSPORT_NETWORK_BLOCKEDNETWORKINTERFACE_HPP_ + +#include +#include + +namespace eprosima { +namespace fastdds { +namespace rtps { + +/** + * Structure extending \c NetworkInterface with information specific to blocked interfaces. + * + * @note When using this structure to interact with Fast-DDS, \c name is the only attribute the user needs to provide. + * The rest of the attributes are internally filled, and are in fact ignored even if already provided by the user. + */ +struct BlockedNetworkInterface : public NetworkInterface +{ + using NetworkInterface::NetworkInterface; + + //! Destructor + virtual RTPS_DllAPI ~BlockedNetworkInterface() = default; + + //! Copy constructor + RTPS_DllAPI BlockedNetworkInterface( + const BlockedNetworkInterface& iface) = default; + + //! Copy assignment + RTPS_DllAPI BlockedNetworkInterface& operator =( + const BlockedNetworkInterface& iface) = default; + + //! Move constructor + RTPS_DllAPI BlockedNetworkInterface( + BlockedNetworkInterface&& iface) = default; + + //! Move assignment + RTPS_DllAPI BlockedNetworkInterface& operator =( + BlockedNetworkInterface&& iface) = default; +}; + +} // namespace rtps +} // namespace fastdds +} // namespace eprosima + +#endif // _FASTDDS_RTPS_TRANSPORT_NETWORK_BLOCKEDNETWORKINTERFACE_HPP_ diff --git a/include/fastdds/rtps/transport/network/NetmaskFilterKind.hpp b/include/fastdds/rtps/transport/network/NetmaskFilterKind.hpp new file mode 100644 index 00000000000..f2ec8e67c32 --- /dev/null +++ b/include/fastdds/rtps/transport/network/NetmaskFilterKind.hpp @@ -0,0 +1,45 @@ +// Copyright 2024 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 NetmaskFilterKind.hpp + */ + +#ifndef _FASTDDS_RTPS_TRANSPORT_NETWORK_NETMASKFILTER_HPP_ +#define _FASTDDS_RTPS_TRANSPORT_NETWORK_NETMASKFILTER_HPP_ + +#include + +#include + +namespace eprosima { +namespace fastdds { +namespace rtps { + +enum class NetmaskFilterKind +{ + OFF, + AUTO, + ON +}; + +RTPS_DllAPI std::ostream& operator <<( + std::ostream& output, + const NetmaskFilterKind& netmask_filter_kind); + +} // namespace rtps +} // namespace fastdds +} // namespace eprosima + +#endif // _FASTDDS_RTPS_TRANSPORT_NETWORK_NETMASKFILTER_HPP_ diff --git a/include/fastdds/rtps/transport/network/NetworkInterface.hpp b/include/fastdds/rtps/transport/network/NetworkInterface.hpp new file mode 100644 index 00000000000..15fd5188827 --- /dev/null +++ b/include/fastdds/rtps/transport/network/NetworkInterface.hpp @@ -0,0 +1,87 @@ +// Copyright 2024 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 NetworkInterface.hpp + */ + +#ifndef _FASTDDS_RTPS_TRANSPORT_NETWORK_NETWORKINTERFACE_HPP_ +#define _FASTDDS_RTPS_TRANSPORT_NETWORK_NETWORKINTERFACE_HPP_ + +#include + +#include +#include + +namespace eprosima { +namespace fastdds { +namespace rtps { + +/** + * Structure encapsulating relevant network interface information. + * + * @note When using this structure to interact with Fast-DDS, \c name is the only attribute the user needs to provide. + * The rest of the attributes are internally filled, and are in fact ignored even if already provided by the user. + */ +struct NetworkInterface +{ + //! Constructor by name + RTPS_DllAPI NetworkInterface( + const std::string& name); + + //! Constructor by device name, IP address string and locator with mask + RTPS_DllAPI NetworkInterface( + const std::string& device, + const std::string& ip, + const LocatorWithMask& locator); + + //! Destructor + virtual RTPS_DllAPI ~NetworkInterface() = default; + + //! Copy constructor + RTPS_DllAPI NetworkInterface( + const NetworkInterface& iface) = default; + + //! Copy assignment + RTPS_DllAPI NetworkInterface& operator =( + const NetworkInterface& iface) = default; + + //! Move constructor + RTPS_DllAPI NetworkInterface( + NetworkInterface&& iface) = default; + + //! Move assignment + RTPS_DllAPI NetworkInterface& operator =( + NetworkInterface&& iface) = default; + + //! Comparison operator + RTPS_DllAPI bool operator ==( + const NetworkInterface& iface) const; + + //! Interface device name or IP address in string format (to be filled by the user) + std::string name; + + //! Interface device name + std::string device; + //! IP address in string format (includes scope ID in the IPv6 case) + std::string ip; + //! IP address with network mask + LocatorWithMask locator; +}; + +} // namespace rtps +} // namespace fastdds +} // namespace eprosima + +#endif // _FASTDDS_RTPS_TRANSPORT_NETWORK_NETWORKINTERFACE_HPP_ diff --git a/include/fastdds/rtps/transport/network/NetworkInterfaceWithFilter.hpp b/include/fastdds/rtps/transport/network/NetworkInterfaceWithFilter.hpp new file mode 100644 index 00000000000..a37113b8e0d --- /dev/null +++ b/include/fastdds/rtps/transport/network/NetworkInterfaceWithFilter.hpp @@ -0,0 +1,93 @@ +// Copyright 2024 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 NetworkInterfaceWithFilter.hpp + */ + +#ifndef _FASTDDS_RTPS_TRANSPORT_NETWORK_NETWORKINTERFACEWITHFILTER_HPP_ +#define _FASTDDS_RTPS_TRANSPORT_NETWORK_NETWORKINTERFACEWITHFILTER_HPP_ + +#include + +#include +#include +#include + +namespace eprosima { +namespace fastdds { +namespace rtps { + +/** + * Structure extending \c NetworkInterface with netmask filter information. + * + * @note When using this structure to interact with Fast-DDS, \c name is the only attribute the user needs to provide. + * The rest of the attributes are internally filled, and are in fact ignored even if already provided by the user. + */ +struct NetworkInterfaceWithFilter : public NetworkInterface +{ + //! Constructor by name and netmask filter + RTPS_DllAPI NetworkInterfaceWithFilter( + const std::string& name, + NetmaskFilterKind netmask_filter); + + //! Constructor by name + RTPS_DllAPI NetworkInterfaceWithFilter( + const std::string& name); + + //! Constructor by device name, IP address string, locator with mask and netmask filter + NetworkInterfaceWithFilter( + const std::string& device, + const std::string& ip, + const LocatorWithMask& locator, + NetmaskFilterKind netmask_filter); + + //! Constructor by device name, IP address string and locator with mask + RTPS_DllAPI NetworkInterfaceWithFilter( + const std::string& device, + const std::string& ip, + const LocatorWithMask& locator); + + //! Destructor + virtual RTPS_DllAPI ~NetworkInterfaceWithFilter() = default; + + //! Copy constructor + RTPS_DllAPI NetworkInterfaceWithFilter( + const NetworkInterfaceWithFilter& iface) = default; + + //! Copy assignment + RTPS_DllAPI NetworkInterfaceWithFilter& operator =( + const NetworkInterfaceWithFilter& iface) = default; + + //! Move constructor + RTPS_DllAPI NetworkInterfaceWithFilter( + NetworkInterfaceWithFilter&& iface) = default; + + //! Move assignment + RTPS_DllAPI NetworkInterfaceWithFilter& operator =( + NetworkInterfaceWithFilter&& iface) = default; + + //! Comparison operator + RTPS_DllAPI bool operator ==( + const NetworkInterfaceWithFilter& iface) const; + + //! Netmask filter configuration + NetmaskFilterKind netmask_filter; +}; + +} // namespace rtps +} // namespace fastdds +} // namespace eprosima + +#endif // _FASTDDS_RTPS_TRANSPORT_NETWORK_NETWORKINTERFACEWITHFILTER_HPP_ diff --git a/include/fastrtps/utils/IPFinder.h b/include/fastrtps/utils/IPFinder.h index d9958b8696e..c0ce5010975 100644 --- a/include/fastrtps/utils/IPFinder.h +++ b/include/fastrtps/utils/IPFinder.h @@ -26,6 +26,7 @@ #include #include +#include namespace eprosima { namespace fastrtps { @@ -58,6 +59,7 @@ class IPFinder std::string name; std::string dev; Locator_t locator; + fastdds::rtps::LocatorWithMask masked_locator; }info_IP; /** diff --git a/include/fastrtps/utils/collections/ResourceLimitedVector.hpp b/include/fastrtps/utils/collections/ResourceLimitedVector.hpp index bd314c33ac4..cbdcb387622 100644 --- a/include/fastrtps/utils/collections/ResourceLimitedVector.hpp +++ b/include/fastrtps/utils/collections/ResourceLimitedVector.hpp @@ -280,6 +280,26 @@ class ResourceLimitedVector return false; } + /** + * Contains element. + * + * Checks whether the given element is present in the collection (at least once). + * + * @param val Value to look for. + * + * @return true if the element is present in the collection (at least once), false otherwise. + */ + bool contains( + const value_type& val) + { + iterator it = std::find(collection_.begin(), collection_.end(), val); + if (it != collection_.end()) + { + return true; + } + return false; + } + /** * Assign vector content. * diff --git a/include/fastrtps/xmlparser/XMLParser.h b/include/fastrtps/xmlparser/XMLParser.h index 2e7b8e26971..62ce937eee4 100644 --- a/include/fastrtps/xmlparser/XMLParser.h +++ b/include/fastrtps/xmlparser/XMLParser.h @@ -235,6 +235,18 @@ class XMLParser tinyxml2::XMLElement* p_root, std::shared_ptr p_transport); + RTPS_DllAPI static XMLP_ret parseXMLInterfaces( + tinyxml2::XMLElement* p_root, + std::shared_ptr p_transport); + + RTPS_DllAPI static XMLP_ret parseXMLAllowlist( + tinyxml2::XMLElement* p_root, + std::shared_ptr p_transport); + + RTPS_DllAPI static XMLP_ret parseXMLBlocklist( + tinyxml2::XMLElement* p_root, + std::shared_ptr p_transport); + RTPS_DllAPI static XMLP_ret parseXMLCommonTCPTransportData( tinyxml2::XMLElement* p_root, sp_transport_t p_transport); diff --git a/include/fastrtps/xmlparser/XMLParserCommon.h b/include/fastrtps/xmlparser/XMLParserCommon.h index 308cd8c205e..972c863dfef 100644 --- a/include/fastrtps/xmlparser/XMLParserCommon.h +++ b/include/fastrtps/xmlparser/XMLParserCommon.h @@ -62,6 +62,10 @@ extern const char* TTL; extern const char* NON_BLOCKING_SEND; extern const char* WHITE_LIST; extern const char* INTERFACE; +extern const char* NETMASK_FILTER; +extern const char* INTERFACES; +extern const char* ALLOWLIST; +extern const char* BLOCKLIST; extern const char* MAX_MESSAGE_SIZE; extern const char* MAX_INITIAL_PEERS_RANGE; extern const char* KEEP_ALIVE_FREQUENCY; diff --git a/resources/xsd/fastRTPS_profiles.xsd b/resources/xsd/fastRTPS_profiles.xsd index 285e575eb48..0fc7ac8a5b8 100644 --- a/resources/xsd/fastRTPS_profiles.xsd +++ b/resources/xsd/fastRTPS_profiles.xsd @@ -123,6 +123,7 @@ ├ ignore_non_matching_locators [bool], ├ sendSocketBufferSize [uint32], ├ listenSocketBufferSize [uint32], + ├ netmask_filter [string] ("OFF", "AUTO", "ON"), ├ builtin [0~1], ├ port [0~1], ├ participantID [int32], @@ -153,6 +154,15 @@ + + + + + + + + + @@ -856,33 +866,35 @@ ├ receiveBufferSize [uint32], ├ maxMessageSize [uint32], ├ maxInitialPeersRange [uint32], - ├ interfaceWhiteList [0~*], (NOT available for SHM type) + ├ interfaceWhiteList [0~*], (NOT available for SHM type) | └ address [ipv4Address|ipv6Address] - ├ TTL [uint8], (ONLY available for UDP type) - ├ non_blocking_send [boolean], (NOT available for SHM type) - ├ output_port [uint16], (ONLY available for UDP type) - ├ wan_addr [ipv4AddressFormat], (ONLY available for TCPv4 type) - ├ keep_alive_frequency_ms [uint32], (ONLY available for TCP type) - ├ keep_alive_timeout_ms [uint32], (ONLY available for TCP type) - ├ max_logical_port [uint16], (ONLY available for TCP type) - ├ logical_port_range [uint16], (ONLY available for TCP type) - ├ logical_port_increment [uint16], (ONLY available for TCP type) - ├ listening_ports [0~*], (ONLY available for TCP type) - | └ port [uint16] (ONLY available for TCP type) - ├ tls [0~1], (ONLY available for TCP type) - ├ calculate_crc [bool], (ONLY available for TCP type) - ├ check_crc [bool], (ONLY available for TCP type) - ├ enable_tcp_nodelay [bool], (ONLY available for TCP type) - ├ keep_alive_thread [threadSettingsType], (ONLY available for TCP type) - ├ accept_thread [threadSettingsType], (ONLY available for TCP type) - ├ tcp_negotiation_timeout [uint32], (ONLY available for TCP type) - ├ segment_size [uint32], (ONLY available for SHM type) - ├ port_queue_capacity [uint32], (ONLY available for SHM type) - ├ healthy_check_timeout_ms [uint32], (ONLY available for SHM type) - ├ rtps_dump_file [string] (ONLY available for SHM type) + | └ interface [string] + ├ netmask_filter [string] ("OFF", "AUTO", "ON"), (NOT available for SHM type) + ├ interfaces [interfacesType], (NOT available for SHM type) + ├ TTL [uint8], (ONLY available for UDP type) + ├ non_blocking_send [boolean], (NOT available for SHM type) + ├ output_port [uint16], (ONLY available for UDP type) + ├ wan_addr [ipv4AddressFormat], (ONLY available for TCPv4 type) + ├ keep_alive_frequency_ms [uint32], (ONLY available for TCP type) + ├ keep_alive_timeout_ms [uint32], (ONLY available for TCP type) + ├ max_logical_port [uint16], (ONLY available for TCP type) + ├ logical_port_range [uint16], (ONLY available for TCP type) + ├ logical_port_increment [uint16], (ONLY available for TCP type) + ├ listening_ports [0~*], (ONLY available for TCP type) + | └ port [uint16] (ONLY available for TCP type) + ├ tls [0~1], (ONLY available for TCP type) + ├ calculate_crc [bool], (ONLY available for TCP type) + ├ check_crc [bool], (ONLY available for TCP type) + ├ enable_tcp_nodelay [bool], (ONLY available for TCP type) + ├ keep_alive_thread [threadSettingsType], (ONLY available for TCP type) + ├ accept_thread [threadSettingsType], (ONLY available for TCP type) + ├ segment_size [uint32], (ONLY available for SHM type) + ├ port_queue_capacity [uint32], (ONLY available for SHM type) + ├ healthy_check_timeout_ms [uint32], (ONLY available for SHM type) + ├ rtps_dump_file [string] (ONLY available for SHM type) ├ default_reception_threads [threadSettingsType] - ├ reception_threads [receptionThreadsListType] (ONLY available for SHM type) - └ dump_thread [threadSettingsType] (ONLY available for SHM type) --> + ├ reception_threads [receptionThreadsListType] (ONLY available for SHM type) + └ dump_thread [threadSettingsType] (ONLY available for SHM type) --> @@ -904,7 +916,7 @@ - + @@ -916,6 +928,16 @@ + + + + + + + + + + @@ -949,6 +971,52 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +