ZBLOG

6.11.2. Allowlist Using Fast DDS, it is possible to limit the network interfaces used by TCP Transport and UDP Transport. This is achieved by adding the interfaces to the allowlist field in the TCPTransportDescriptor or UDPTransportDescriptor. Th...

这段文本介绍了在使用 Fast DDS (Fast Data Distribution Service) 时如何通过允许列表(allowlist)和阻止列表(blocklist)来限制 TCP 和 UDP 传输所用的网络接口。

1. 允许列表(Allowlist)

定义: 允许列表是一种机制,用于指定哪些网络接口可以用于通信。如果一个 DomainParticipant 的传输描述符(TransportDescriptorInterface)定义了一个允许列表,则该参与者只能使用列入该列表的接口进行通信,避免使用系统中可用的其他网络接口。

实现示例:

DomainParticipantQos qos;

// 创建新的传输描述符
auto udp_transport = std::make_shared<UDPv4TransportDescriptor>();

// 按设备名称添加允许的接口
udp_transport->interface_allowlist.emplace_back("eth0", NetmaskFilterKind::OFF);

// 按 IP 地址添加允许的接口(使用默认子网掩码过滤器 AUTO)
udp_transport->interface_allowlist.emplace_back("127.0.0.1");

// 使用显式 AllowedNetworkInterface 构造函数添加允许的接口
AllowedNetworkInterface another_allowed_interface("docker0", NetmaskFilterKind::OFF);
udp_transport->interface_allowlist.emplace_back(another_allowed_interface);

// 将传输层链接到参与者
qos.transport().user_transports.push_back(udp_transport);

// 避免使用内置传输
qos.transport().use_builtin_transports = false;

重要注意事项:

  • 如果传输描述符中的允许列表与主机上的任何接口不匹配,则所有界面都将被过滤,从而无法通过该传输建立通信。

2. 阻止列表(Blocklist)

定义: 阻止列表用于指定哪些网络接口应被阻止。这是通过 TCPTransportDescriptorUDPTransportDescriptor 中的 blocklist 字段来实现的。阻止列表优先于允许列表,因此如果某个网络接口同时在两个列表中,它将被阻止。

实现示例:

DomainParticipantQos qos;

// 创建新的传输描述符
auto udp_transport = std::make_shared<UDPv4TransportDescriptor>();

// 按设备名称添加被阻止的接口
udp_transport->interface_blocklist.emplace_back("docker0");

// 按 IP 地址添加被阻止的接口
udp_transport->interface_blocklist.emplace_back("127.0.0.1");

// 使用显式 BlockedNetworkInterface 构造函数添加被阻止的接口
BlockedNetworkInterface another_blocked_interface("eth0");
udp_transport->interface_blocklist.emplace_back(another_blocked_interface);

// 将传输层链接到参与者
qos.transport().user_transports.push_back(udp_transport);

// 避免使用内置传输
qos.transport().use_builtin_transports = false;

总结

通过设置允许和阻止列表,开发人员能够精确控制 Fast DDS 通信时使用哪些网络接口,从而增强系统安全性和管理网络资源。


内容由零声教学AI助手提供,问题来源于学员提问

本站部分文章来源于网络,版权归原作者所有,如有侵权请联系站长删除。
转载请注明出处:https://golang.0voice.com/?id=21471

分享:
扫描分享到社交APP
上一篇
下一篇
发表列表
游客 游客
此处应有掌声~
评论列表

还没有评论,快来说点什么吧~

联系我们

在线咨询: 点击这里给我发消息

微信号:3007537140

上班时间: 10:30-22:30

关注我们
x

注册

已经有帐号?