Skip to content

Commit 43d6be7

Browse files
Fix failure setting default locator in empty multicast locator list (#6351)
* Fix failure when setting default locator in empty multicast locator lists. Only the port was being set to default, IP was initialized to 0 Signed-off-by: Emilio Cuesta <emiliocuesta@eprosima.com> * Trying a cleaner approach Signed-off-by: Emilio Cuesta <emiliocuesta@eprosima.com> * Replicate unicast stack of functions to treat default addresses Signed-off-by: Emilio Cuesta <emiliocuesta@eprosima.com> * Uncrustify Signed-off-by: Emilio Cuesta <emiliocuesta@eprosima.com> * Batch of suggestion from code review Co-authored-by: Carlos Ferreira González <carloos.499@gmail.com> Signed-off-by: Emilio Cuesta Fernandez <emiliocuesta@eprosima.com> * Apply review Signed-off-by: Emilio Cuesta <emiliocuesta@eprosima.com> * Uncrustify Signed-off-by: Emilio Cuesta <emiliocuesta@eprosima.com> * Fix compilation issue Signed-off-by: Emilio Cuesta <emiliocuesta@eprosima.com> * Avoid ABI/API break by adding new private interface Signed-off-by: Emilio Cuesta <emiliocuesta@eprosima.com> * Fix cmake in tests Signed-off-by: Emilio Cuesta <emiliocuesta@eprosima.com> * Apply revision Signed-off-by: Emilio Cuesta <emiliocuesta@eprosima.com> --------- Signed-off-by: Emilio Cuesta <emiliocuesta@eprosima.com> Signed-off-by: Emilio Cuesta Fernandez <emiliocuesta@eprosima.com> Co-authored-by: Carlos Ferreira González <carloos.499@gmail.com>
1 parent 24ab81e commit 43d6be7

23 files changed

Lines changed: 345 additions & 15 deletions

include/fastdds/rtps/transport/TransportInterface.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,11 @@ class FASTDDS_EXPORTED_API TransportInterface
262262
uint32_t domainId,
263263
LocatorList& list) const = 0;
264264

265-
//! Assign port to the given unicast locator if not already defined
265+
/**
266+
* Assign only the port to the given unicast locator if not already defined
267+
* Note: As the default address is usually valid for unicast, this method
268+
* does not assign a new value
269+
*/
266270
virtual bool fillUnicastLocator(
267271
Locator& locator,
268272
uint32_t well_known_port) const = 0;

src/cpp/rtps/network/NetworkFactory.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <fastdds/utils/IPLocator.hpp>
2727

2828
#include <rtps/network/NetworkConfiguration.hpp>
29+
#include <rtps/transport/MulticastTransportInterface.hpp>
2930
#include <rtps/transport/TCPTransportInterface.h>
3031

3132
using namespace std;
@@ -489,6 +490,23 @@ bool NetworkFactory::getDefaultUnicastLocators(
489490
return result;
490491
}
491492

493+
bool NetworkFactory::getDefaultMulticastLocators(
494+
LocatorList_t& locators,
495+
uint32_t port) const
496+
{
497+
bool result = false;
498+
for (auto& transport : mRegisteredTransports)
499+
{
500+
const MulticastTransportInterface* multicast_transport =
501+
dynamic_cast<const MulticastTransportInterface*>(transport.get());
502+
if (multicast_transport)
503+
{
504+
result |= multicast_transport->getDefaultMulticastLocators(locators, port);
505+
}
506+
}
507+
return result;
508+
}
509+
492510
bool NetworkFactory::fill_default_locator_port(
493511
Locator_t& locator,
494512
uint32_t port) const
@@ -504,6 +522,26 @@ bool NetworkFactory::fill_default_locator_port(
504522
return result;
505523
}
506524

525+
bool NetworkFactory::fill_default_multicast_locator(
526+
Locator_t& locator,
527+
uint32_t port) const
528+
{
529+
bool result = false;
530+
for (auto& transport : mRegisteredTransports)
531+
{
532+
if (transport->IsLocatorSupported(locator))
533+
{
534+
const MulticastTransportInterface* multicast_transport =
535+
dynamic_cast<const MulticastTransportInterface*>(transport.get());
536+
if (multicast_transport)
537+
{
538+
result |= multicast_transport->fillMulticastLocator(locator, port);
539+
}
540+
}
541+
}
542+
return result;
543+
}
544+
507545
void NetworkFactory::Shutdown()
508546
{
509547
for (auto& transport : mRegisteredTransports)

src/cpp/rtps/network/NetworkFactory.hpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,13 +297,30 @@ class NetworkFactory
297297
LocatorList_t& locators,
298298
uint32_t port) const;
299299

300+
/**
301+
* Add the default multicast locator to the given locator list.
302+
*
303+
* @param locators List to be filled with the default multicast locator.
304+
* @param port Port to be used in the default multicast locator.
305+
* */
306+
bool getDefaultMulticastLocators(
307+
LocatorList_t& locators,
308+
uint32_t port) const;
309+
300310
/**
301311
* Fill the locator with the default unicast configuration.
302312
* */
303313
bool fill_default_locator_port(
304314
Locator_t& locator,
305315
uint32_t port) const;
306316

317+
/**
318+
* Fill the locator with the default multicast configuration.
319+
* */
320+
bool fill_default_multicast_locator(
321+
Locator_t& locator,
322+
uint32_t port) const;
323+
307324
/**
308325
* Shutdown method to close the connections of the transports.
309326
*/

src/cpp/rtps/participant/RTPSParticipantImpl.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,7 @@ void RTPSParticipantImpl::setup_user_traffic()
682682
std::for_each(m_att.defaultUnicastLocatorList.begin(), m_att.defaultUnicastLocatorList.end(),
683683
[&](Locator_t& loc)
684684
{
685+
// This methods always leaves the address unchanged
685686
m_network_Factory.fill_default_locator_port(loc, default_unicast_port_);
686687
});
687688
m_network_Factory.NormalizeLocators(m_att.defaultUnicastLocatorList);
@@ -691,7 +692,8 @@ void RTPSParticipantImpl::setup_user_traffic()
691692
std::for_each(m_att.defaultMulticastLocatorList.begin(), m_att.defaultMulticastLocatorList.end(),
692693
[&](Locator_t& loc)
693694
{
694-
m_network_Factory.fill_default_locator_port(loc, multicast_port);
695+
// This methods leaves the address unchanged if it was already set
696+
m_network_Factory.fill_default_multicast_locator(loc, multicast_port);
695697
});
696698
}
697699

@@ -2348,7 +2350,7 @@ void RTPSParticipantImpl::normalize_endpoint_locators(
23482350
uint32_t multicast_port = m_network_Factory.calculate_well_known_port(domain_id_, m_att, true);
23492351
for (Locator_t& loc : endpoint_att.multicastLocatorList)
23502352
{
2351-
m_network_Factory.fill_default_locator_port(loc, multicast_port);
2353+
m_network_Factory.fill_default_multicast_locator(loc, multicast_port);
23522354
}
23532355

23542356
// Normalize unicast locators
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Copyright 2026 Proyectos y Sistemas de Mantenimiento SL (eProsima).
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#include <rtps/transport/MulticastTransportInterface.hpp>
16+
17+
#include <fastdds/utils/IPLocator.hpp>
18+
19+
namespace eprosima {
20+
namespace fastdds {
21+
namespace rtps {
22+
23+
bool MulticastTransportInterface::fillMulticastLocator(
24+
Locator& locator,
25+
uint32_t well_known_port) const
26+
{
27+
LocatorList defaults;
28+
getDefaultMulticastLocators(defaults, well_known_port);
29+
if (!defaults.empty())
30+
{
31+
const Locator& default_loc = *defaults.begin();
32+
if (locator.port == 0)
33+
{
34+
locator.port = default_loc.port;
35+
}
36+
if (!IsAddressDefined(locator))
37+
{
38+
IPLocator::copy_address(default_loc, locator);
39+
}
40+
}
41+
42+
return true;
43+
}
44+
45+
} // namespace rtps
46+
} // namespace fastdds
47+
} // namespace eprosima
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Copyright 2026 Proyectos y Sistemas de Mantenimiento SL (eProsima).
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#ifndef _FASTDDS_MULTICAST_TRANSPORT_INTERFACE_HPP_
16+
#define _FASTDDS_MULTICAST_TRANSPORT_INTERFACE_HPP_
17+
18+
#include <cstdint>
19+
20+
#include <fastdds/rtps/common/Locator.hpp>
21+
#include <fastdds/rtps/common/LocatorList.hpp>
22+
23+
namespace eprosima {
24+
namespace fastdds {
25+
namespace rtps {
26+
27+
class MulticastTransportInterface
28+
{
29+
public:
30+
31+
virtual ~MulticastTransportInterface() = default;
32+
33+
virtual bool getDefaultMulticastLocators(
34+
LocatorList& locators,
35+
uint32_t multicast_port) const = 0;
36+
37+
virtual bool fillMulticastLocator(
38+
Locator& locator,
39+
uint32_t well_known_port) const;
40+
};
41+
42+
} // namespace rtps
43+
} // namespace fastdds
44+
} // namespace eprosima
45+
46+
#endif // _FASTDDS_MULTICAST_TRANSPORT_INTERFACE_HPP_

src/cpp/rtps/transport/TCPTransportInterface.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1690,7 +1690,7 @@ bool TCPTransportInterface::getDefaultMetatrafficMulticastLocators(
16901690
uint32_t ) const
16911691
{
16921692
// TCP doesn't have multicast support
1693-
return true;
1693+
return false;
16941694
}
16951695

16961696
bool TCPTransportInterface::getDefaultMetatrafficUnicastLocators(
@@ -1722,7 +1722,7 @@ bool TCPTransportInterface::fillMetatrafficMulticastLocator(
17221722
uint32_t) const
17231723
{
17241724
// TCP doesn't have multicast support
1725-
return true;
1725+
return false;
17261726
}
17271727

17281728
bool TCPTransportInterface::fillMetatrafficUnicastLocator(

src/cpp/rtps/transport/TCPTransportInterface.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,10 @@ class TCPTransportInterface : public TransportInterface
452452
*/
453453
virtual std::vector<std::string> get_binding_interfaces_list() = 0;
454454

455+
/**
456+
* This method should never be called because TCP interfaces do not support
457+
* multicast locators. It always returns false
458+
*/
455459
bool getDefaultMetatrafficMulticastLocators(
456460
LocatorList& locators,
457461
uint32_t metatraffic_multicast_port) const override;
@@ -464,6 +468,10 @@ class TCPTransportInterface : public TransportInterface
464468
LocatorList& locators,
465469
uint32_t unicast_port) const override;
466470

471+
/**
472+
* This method should never be called because TCP interfaces do not support
473+
* multicast locators. It always returns false
474+
*/
467475
bool fillMetatrafficMulticastLocator(
468476
Locator& locator,
469477
uint32_t metatraffic_multicast_port) const override;

src/cpp/rtps/transport/UDPTransportInterface.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -724,9 +724,19 @@ bool UDPTransportInterface::fillMetatrafficMulticastLocator(
724724
Locator& locator,
725725
uint32_t metatraffic_multicast_port) const
726726
{
727-
if (locator.port == 0)
727+
LocatorList defaults;
728+
getDefaultMetatrafficMulticastLocators(defaults, metatraffic_multicast_port);
729+
if (!defaults.empty())
728730
{
729-
locator.port = metatraffic_multicast_port;
731+
const Locator& default_loc = *defaults.begin();
732+
if (locator.port == 0)
733+
{
734+
locator.port = default_loc.port;
735+
}
736+
if (!IsAddressDefined(locator))
737+
{
738+
IPLocator::copy_address(default_loc, locator);
739+
}
730740
}
731741
return true;
732742
}

src/cpp/rtps/transport/UDPTransportInterface.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,17 @@
2929
#include <fastdds/rtps/transport/UDPTransportDescriptor.hpp>
3030
#include <fastdds/utils/IPFinder.hpp>
3131

32+
#include <rtps/transport/MulticastTransportInterface.hpp>
3233
#include <rtps/transport/UDPChannelResource.h>
3334
#include <statistics/rtps/messages/OutputTrafficManager.hpp>
3435

3536
namespace eprosima {
3637
namespace fastdds {
3738
namespace rtps {
3839

39-
class UDPTransportInterface : public TransportInterface
40+
class UDPTransportInterface
41+
: public TransportInterface
42+
, public MulticastTransportInterface
4043
{
4144
friend class UDPSenderResource;
4245
friend struct TSN_UDPSender;

0 commit comments

Comments
 (0)