Skip to content

Commit 079dde6

Browse files
Add netmask filter transport configuration + interface allowlist and blocklist (#659)
* Add documentation for interfaces configuration (netmask_filter/allowlist/blocklist) Signed-off-by: Juan Lopez Fernandez <juanlopez@eprosima.com> * Update after Fast-DDS branch changes Signed-off-by: Juan Lopez Fernandez <juanlopez@eprosima.com> * Apply suggestions Signed-off-by: Juan Lopez Fernandez <juanlopez@eprosima.com> * Minor changes Signed-off-by: Juan Lopez Fernandez <juanlopez@eprosima.com> * Add example with explicit NetworkInterface construction + minor changes Signed-off-by: Juan Lopez Fernandez <juanlopez@eprosima.com> --------- Signed-off-by: Juan Lopez Fernandez <juanlopez@eprosima.com>
1 parent 4011cfd commit 079dde6

13 files changed

Lines changed: 481 additions & 6 deletions

File tree

code/DDSCodeTester.cpp

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@
3434
#include <fastdds/rtps/attributes/ThreadSettings.hpp>
3535
#include <fastdds/rtps/transport/ChainingTransport.h>
3636
#include <fastdds/rtps/transport/ChainingTransportDescriptor.h>
37+
#include <fastdds/rtps/transport/network/AllowedNetworkInterface.hpp>
38+
#include <fastdds/rtps/transport/network/BlockedNetworkInterface.hpp>
39+
#include <fastdds/rtps/transport/network/NetmaskFilterKind.hpp>
3740
#include <fastdds/rtps/transport/shared_mem/SharedMemTransportDescriptor.h>
3841
#include <fastdds/rtps/transport/TCPTransportDescriptor.h>
3942
#include <fastdds/rtps/transport/TCPv4TransportDescriptor.h>
@@ -4909,6 +4912,85 @@ void dds_transport_examples ()
49094912
//!--
49104913
}
49114914

4915+
{
4916+
using namespace eprosima::fastdds::rtps;
4917+
//CONF-NETMASK-FILTER
4918+
DomainParticipantQos qos;
4919+
4920+
// Configure netmask filtering at participant level
4921+
qos.transport().netmask_filter = NetmaskFilterKind::AUTO;
4922+
qos.wire_protocol().ignore_non_matching_locators = true; // Required if not defining an allowlist or blocklist
4923+
4924+
// Create a descriptor for the new transport.
4925+
auto udp_transport = std::make_shared<UDPv4TransportDescriptor>();
4926+
4927+
// Configure netmask filtering at transport level
4928+
udp_transport->netmask_filter = NetmaskFilterKind::AUTO;
4929+
qos.wire_protocol().ignore_non_matching_locators = true; // Required if not defining an allowlist or blocklist
4930+
4931+
// Configure netmask filtering at interface level
4932+
udp_transport->interface_allowlist.emplace_back("wlp59s0", NetmaskFilterKind::ON);
4933+
4934+
// Link the Transport Layer to the Participant.
4935+
qos.transport().user_transports.push_back(udp_transport);
4936+
4937+
// Avoid using the builtin transports
4938+
qos.transport().use_builtin_transports = false;
4939+
//!--
4940+
}
4941+
4942+
{
4943+
using namespace eprosima::fastdds::rtps;
4944+
//CONF-INTERFACES-ALLOWLIST
4945+
DomainParticipantQos qos;
4946+
4947+
// Create a descriptor for the new transport.
4948+
auto udp_transport = std::make_shared<UDPv4TransportDescriptor>();
4949+
4950+
// Add allowed interface by device name
4951+
udp_transport->interface_allowlist.emplace_back("eth0", NetmaskFilterKind::OFF);
4952+
4953+
// Add allowed interface by IP address (using default netmask filter AUTO)
4954+
udp_transport->interface_allowlist.emplace_back("127.0.0.1");
4955+
4956+
// Add allowed interface with explicit AllowedNetworkInterface construction
4957+
AllowedNetworkInterface another_allowed_interface("docker0", NetmaskFilterKind::OFF);
4958+
udp_transport->interface_allowlist.emplace_back(another_allowed_interface);
4959+
4960+
// Link the Transport Layer to the Participant.
4961+
qos.transport().user_transports.push_back(udp_transport);
4962+
4963+
// Avoid using the builtin transports
4964+
qos.transport().use_builtin_transports = false;
4965+
//!--
4966+
}
4967+
4968+
{
4969+
using namespace eprosima::fastdds::rtps;
4970+
//CONF-INTERFACES-BLOCKLIST
4971+
DomainParticipantQos qos;
4972+
4973+
// Create a descriptor for the new transport.
4974+
auto udp_transport = std::make_shared<UDPv4TransportDescriptor>();
4975+
4976+
// Add blocked interface by device name
4977+
udp_transport->interface_blocklist.emplace_back("docker0");
4978+
4979+
// Add blocked interface by IP address
4980+
udp_transport->interface_blocklist.emplace_back("127.0.0.1");
4981+
4982+
// Add blocked interface with explicit BlockedNetworkInterface construction
4983+
BlockedNetworkInterface another_blocked_interface("eth0");
4984+
udp_transport->interface_blocklist.emplace_back(another_blocked_interface);
4985+
4986+
// Link the Transport Layer to the Participant.
4987+
qos.transport().user_transports.push_back(udp_transport);
4988+
4989+
// Avoid using the builtin transports
4990+
qos.transport().use_builtin_transports = false;
4991+
//!--
4992+
}
4993+
49124994
{
49134995
//CONF-DISABLE-MULTICAST
49144996
DomainParticipantQos qos;

code/XMLTester.xml

Lines changed: 109 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,6 +1004,99 @@
10041004
</participant>
10051005
<!--><-->
10061006

1007+
<!-->PARTICIPANT-NETMASK-FILTER<-->
1008+
<!--
1009+
<?xml version="1.0" encoding="UTF-8" ?>
1010+
<profiles xmlns="http://www.eprosima.com/XMLSchemas/fastRTPS_Profiles">
1011+
-->
1012+
<participant profile_name="CustomTcpParticipantNetmaskFilterParticipant">
1013+
<rtps>
1014+
<ignore_non_matching_locators>true</ignore_non_matching_locators>
1015+
<netmask_filter>ON</netmask_filter>
1016+
</rtps>
1017+
</participant>
1018+
<!--><-->
1019+
1020+
<!-->TRANSPORT-NETMASK-FILTER<-->
1021+
<!--
1022+
<?xml version="1.0" encoding="UTF-8" ?>
1023+
<profiles xmlns="http://www.eprosima.com/XMLSchemas/fastRTPS_Profiles">
1024+
-->
1025+
<transport_descriptors>
1026+
<transport_descriptor>
1027+
<transport_id>CustomTcpTransportNetmaskFilter</transport_id>
1028+
<type>TCPv4</type>
1029+
<netmask_filter>ON</netmask_filter>
1030+
</transport_descriptor>
1031+
</transport_descriptors>
1032+
1033+
<participant profile_name="CustomTcpTransportNetmaskFilterParticipant">
1034+
<rtps>
1035+
<useBuiltinTransports>false</useBuiltinTransports>
1036+
<userTransports>
1037+
<transport_id>CustomTcpTransportNetmaskFilter</transport_id>
1038+
</userTransports>
1039+
<ignore_non_matching_locators>true</ignore_non_matching_locators>
1040+
</rtps>
1041+
</participant>
1042+
<!--><-->
1043+
1044+
<!-->INTERFACES-ALLOWLIST<-->
1045+
<!--
1046+
<?xml version="1.0" encoding="UTF-8" ?>
1047+
<profiles xmlns="http://www.eprosima.com/XMLSchemas/fastRTPS_Profiles">
1048+
-->
1049+
<transport_descriptors>
1050+
<transport_descriptor>
1051+
<transport_id>CustomTcpTransportAllowlist</transport_id>
1052+
<type>TCPv4</type>
1053+
<interfaces>
1054+
<allowlist>
1055+
<interface name="wlp59s0" netmask_filter="ON"/>
1056+
<interface name="192.168.1.10" netmask_filter="OFF"/>
1057+
</allowlist>
1058+
</interfaces>
1059+
</transport_descriptor>
1060+
</transport_descriptors>
1061+
1062+
<participant profile_name="CustomTcpTransportAllowlistParticipant">
1063+
<rtps>
1064+
<useBuiltinTransports>false</useBuiltinTransports>
1065+
<userTransports>
1066+
<transport_id>CustomTcpTransportAllowlist</transport_id>
1067+
</userTransports>
1068+
</rtps>
1069+
</participant>
1070+
<!--><-->
1071+
1072+
<!-->INTERFACES-BLOCKLIST<-->
1073+
<!--
1074+
<?xml version="1.0" encoding="UTF-8" ?>
1075+
<profiles xmlns="http://www.eprosima.com/XMLSchemas/fastRTPS_Profiles">
1076+
-->
1077+
<transport_descriptors>
1078+
<transport_descriptor>
1079+
<transport_id>CustomTcpTransportBlocklist</transport_id>
1080+
<type>TCPv4</type>
1081+
<interfaces>
1082+
<blocklist>
1083+
<interface name="127.0.0.1"/>
1084+
<interface name="docker0"/>
1085+
</blocklist>
1086+
</interfaces>
1087+
</transport_descriptor>
1088+
</transport_descriptors>
1089+
1090+
<participant profile_name="CustomTcpTransportBlocklistParticipant">
1091+
<rtps>
1092+
<useBuiltinTransports>false</useBuiltinTransports>
1093+
<userTransports>
1094+
<transport_id>CustomTcpTransportBlocklist</transport_id>
1095+
</userTransports>
1096+
</rtps>
1097+
</participant>
1098+
<!--><-->
1099+
10071100
<!-->CONF-TRANSPORT_METAMULTICASTLOCATOR<-->
10081101
<!--
10091102
<?xml version="1.0" encoding="UTF-8" ?>
@@ -1094,7 +1187,8 @@
10941187
<transport_id>CustomTransport</transport_id>
10951188
<type>UDPv4</type>
10961189
<interfaceWhiteList>
1097-
<address>127.0.0.1</address>
1190+
<address>192.168.1.10</address>
1191+
<interface>lo</interface>
10981192
</interfaceWhiteList>
10991193
</transport_descriptor>
11001194

@@ -1110,7 +1204,7 @@
11101204
<maxInitialPeersRange>100</maxInitialPeersRange>
11111205
<interfaceWhiteList>
11121206
<address>192.168.1.41</address>
1113-
<address>127.0.0.1</address>
1207+
<interface>lo</interface>
11141208
</interfaceWhiteList>
11151209
<wan_addr>80.80.55.44</wan_addr>
11161210
<output_port>5101</output_port>
@@ -1279,6 +1373,8 @@
12791373

12801374
<listenSocketBufferSize>8192</listenSocketBufferSize>
12811375

1376+
<netmask_filter>ON</netmask_filter>
1377+
12821378
<builtin>
12831379
<!-- BUILTIN -->
12841380
</builtin>
@@ -3803,9 +3899,19 @@
38033899
<receiveBufferSize>8192</receiveBufferSize>
38043900
<maxMessageSize>16384</maxMessageSize>
38053901
<maxInitialPeersRange>100</maxInitialPeersRange>
3902+
<netmask_filter>AUTO</netmask_filter>
3903+
<interfaces>
3904+
<allowlist>
3905+
<interface name="wlp59s0" netmask_filter="ON"/>
3906+
</allowlist>
3907+
<blocklist>
3908+
<interface name="127.0.0.1"/>
3909+
<interface name="docker0"/>
3910+
</blocklist>
3911+
</interfaces>
38063912
<interfaceWhiteList>
38073913
<address>192.168.1.41</address>
3808-
<address>127.0.0.1</address>
3914+
<interface>lo</interface>
38093915
</interfaceWhiteList>
38103916
<TTL>250</TTL>
38113917
<non_blocking_send>false</non_blocking_send>

code/XMLTesterExample.xml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,19 @@
1010
<receiveBufferSize>8192</receiveBufferSize>
1111
<maxMessageSize>16384</maxMessageSize>
1212
<maxInitialPeersRange>100</maxInitialPeersRange>
13+
<netmask_filter>AUTO</netmask_filter>
14+
<interfaces>
15+
<allowlist>
16+
<interface name="wlp59s0" netmask_filter="ON"/>
17+
</allowlist>
18+
<blocklist>
19+
<interface name="127.0.0.1"/>
20+
<interface name="docker0"/>
21+
</blocklist>
22+
</interfaces>
1323
<interfaceWhiteList>
1424
<address>192.168.1.41</address>
15-
<address>127.0.0.1</address>
25+
<interface>lo</interface>
1626
</interfaceWhiteList>
1727
<wan_addr>80.80.55.44</wan_addr>
1828
<keep_alive_frequency_ms>5000</keep_alive_frequency_ms>
@@ -212,6 +222,7 @@
212222
<ignore_non_matching_locators>true</ignore_non_matching_locators>
213223
<sendSocketBufferSize>8192</sendSocketBufferSize>
214224
<listenSocketBufferSize>8192</listenSocketBufferSize>
225+
<netmask_filter>AUTO</netmask_filter>
215226

216227
<builtin>
217228
<discovery_config>

docs/03-exports/aliases-api.include

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,15 @@
612612
.. |SocketTransportDescriptor::interfaceWhiteList-api| replace:: :cpp:var:`interfaceWhiteList<eprosima::fastdds::rtps::SocketTransportDescriptor::interfaceWhiteList>`
613613
.. |SocketTransportDescriptor::TTL-api| replace:: :cpp:var:`TTL<eprosima::fastdds::rtps::SocketTransportDescriptor::TTL>`
614614

615+
.. |NetmaskFilterKind-api| replace:: :cpp:enum:`NetmaskFilterKind<eprosima::fastdds::rtps::NetmaskFilterKind>`
616+
.. |NetmaskFilterKind::ON-api| replace:: :cpp:enumerator:`ON<eprosima::fastdds::rtps::NetmaskFilterKind::ON>`
617+
.. |NetmaskFilterKind::OFF-api| replace:: :cpp:enumerator:`OFF<eprosima::fastdds::rtps::NetmaskFilterKind::OFF>`
618+
.. |NetmaskFilterKind::AUTO-api| replace:: :cpp:enumerator:`AUTO<eprosima::fastdds::rtps::NetmaskFilterKind::AUTO>`
619+
.. |SocketTransportDescriptor::netmask_filter-api| replace:: :cpp:var:`netmask_filter<eprosima::fastdds::rtps::SocketTransportDescriptor::netmask_filter>`
620+
.. |SocketTransportDescriptor::interface_allowlist-api| replace:: :cpp:var:`allowlist<eprosima::fastdds::rtps::SocketTransportDescriptor::interface_allowlist>`
621+
.. |SocketTransportDescriptor::interface_blocklist-api| replace:: :cpp:var:`blocklist<eprosima::fastdds::rtps::SocketTransportDescriptor::interface_blocklist>`
622+
623+
615624
.. |UDPTransportDescriptor::m_output_udp_socket-api| replace:: :cpp:var:`m_output_udp_socket<eprosima::fastdds::rtps::UDPTransportDescriptor::m_output_udp_socket>`
616625
.. |UDPTransportDescriptor::non_blocking_send-api| replace:: :cpp:var:`non_blocking_send<eprosima::fastdds::rtps::UDPTransportDescriptor::non_blocking_send>`
617626
.. |UDPv4TransportDescriptor-api| replace:: :cpp:struct:`UDPv4TransportDescriptor<eprosima::fastdds::rtps::UDPv4TransportDescriptor>`

docs/fastdds/api_reference/spelling_wordlist.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ ACKs
33
addReaderLocator
44
addReaderProxy
55
addWriterProxy
6+
allowlist
67
assignability
78
autodispose
89
autoenable
910
autopurge
1011
behaviour
12+
blocklist
1113
booleans
1214
bytesPerPeriod
1315
cacheChange
@@ -93,6 +95,7 @@ mutexes
9395
myFilterFactory
9496
nackResponseDelay
9597
nackSupressionDuration
98+
netmask
9699
NonConstEnabler
97100
NoOpDomainParticipantListener
98101
nullptr
@@ -150,6 +153,7 @@ Struct
150153
Subclassed
151154
subclasses
152155
subentities
156+
subnetwork
153157
SubscriberListener
154158
SubscriptionMatchedStatus
155159
synchronism

0 commit comments

Comments
 (0)