Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restrict traffic to localhost only if env var is provided #331

Merged
merged 4 commits into from
Oct 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions rmw_fastrtps_cpp/src/rmw_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ rmw_create_node(
const char * name,
const char * namespace_,
size_t domain_id,
const rmw_node_security_options_t * security_options)
const rmw_node_security_options_t * security_options,
bool localhost_only)
{
RCUTILS_CHECK_ARGUMENT_FOR_NULL(context, NULL);
RMW_CHECK_TYPE_IDENTIFIERS_MATCH(
Expand All @@ -47,7 +48,7 @@ rmw_create_node(
// TODO(wjwwood): replace this with RMW_RET_INCORRECT_RMW_IMPLEMENTATION when refactored
return NULL);
return rmw_fastrtps_shared_cpp::__rmw_create_node(
eprosima_fastrtps_identifier, name, namespace_, domain_id, security_options);
eprosima_fastrtps_identifier, name, namespace_, domain_id, security_options, localhost_only);
}

rmw_ret_t
Expand Down
5 changes: 3 additions & 2 deletions rmw_fastrtps_dynamic_cpp/src/rmw_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ rmw_create_node(
const char * name,
const char * namespace_,
size_t domain_id,
const rmw_node_security_options_t * security_options)
const rmw_node_security_options_t * security_options,
bool localhost_only)
{
RCUTILS_CHECK_ARGUMENT_FOR_NULL(context, NULL);
RMW_CHECK_TYPE_IDENTIFIERS_MATCH(
Expand All @@ -47,7 +48,7 @@ rmw_create_node(
// TODO(wjwwood): replace this with RMW_RET_INCORRECT_RMW_IMPLEMENTATION when refactored
return NULL);
return rmw_fastrtps_shared_cpp::__rmw_create_node(
eprosima_fastrtps_identifier, name, namespace_, domain_id, security_options);
eprosima_fastrtps_identifier, name, namespace_, domain_id, security_options, localhost_only);
}

rmw_ret_t
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ __rmw_create_node(
const char * name,
const char * namespace_,
size_t domain_id,
const rmw_node_security_options_t * security_options);
const rmw_node_security_options_t * security_options,
bool localhost_only);

RMW_FASTRTPS_SHARED_CPP_PUBLIC
rmw_ret_t
Expand Down
17 changes: 16 additions & 1 deletion rmw_fastrtps_shared_cpp/src/rmw_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

#include "fastrtps/config.h"
#include "fastrtps/Domain.h"
#include "fastrtps/rtps/common/Locator.h"
#include "fastrtps/participant/Participant.h"
#include "fastrtps/attributes/ParticipantAttributes.h"
#include "fastrtps/publisher/Publisher.h"
Expand All @@ -36,6 +37,7 @@
#include "fastrtps/subscriber/SubscriberListener.h"
#include "fastrtps/subscriber/SampleInfo.h"
#include "fastrtps/attributes/SubscriberAttributes.h"
#include "fastrtps/utils/IPLocator.h"

#include "fastrtps/rtps/RTPSDomain.h"

Expand All @@ -48,6 +50,8 @@
#include "rmw_fastrtps_shared_cpp/rmw_common.hpp"

using Domain = eprosima::fastrtps::Domain;
using IPLocator = eprosima::fastrtps::rtps::IPLocator;
using Locator_t = eprosima::fastrtps::rtps::Locator_t;
using Participant = eprosima::fastrtps::Participant;
using ParticipantAttributes = eprosima::fastrtps::ParticipantAttributes;
using StatefulReader = eprosima::fastrtps::rtps::StatefulReader;
Expand Down Expand Up @@ -216,7 +220,8 @@ __rmw_create_node(
const char * name,
const char * namespace_,
size_t domain_id,
const rmw_node_security_options_t * security_options)
const rmw_node_security_options_t * security_options,
bool localhost_only)
{
if (!name) {
RMW_SET_ERROR_MSG("name is null");
Expand All @@ -236,6 +241,16 @@ __rmw_create_node(
// since the participant name is not part of the DDS spec
participantAttrs.rtps.setName(name);

if (localhost_only) {
Locator_t local_network_interface_locator;
static const std::string local_ip_name("127.0.0.1");
local_network_interface_locator.kind = 1;
local_network_interface_locator.port = 0;
IPLocator::setIPv4(local_network_interface_locator, local_ip_name);
participantAttrs.rtps.builtin.metatrafficUnicastLocatorList.push_back(
local_network_interface_locator);
participantAttrs.rtps.builtin.initialPeersList.push_back(local_network_interface_locator);
}
bool leave_middleware_default_qos = false;
const char * env_var = "RMW_FASTRTPS_USE_QOS_FROM_XML";
// Check if the configuration from XML has been enabled from
Expand Down