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

address: use resolveProtoAddress to resolve listener addresses #3039

Merged
merged 4 commits into from
Apr 12, 2018
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
1 change: 1 addition & 0 deletions source/server/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ envoy_cc_library(
"//source/common/config:utility_lib",
"//source/common/config:well_known_names",
"//source/common/network:listen_socket_lib",
"//source/common/network:resolver_lib",
"//source/common/network:socket_option_lib",
"//source/common/network:utility_lib",
"//source/common/protobuf:utility_lib",
Expand Down
3 changes: 2 additions & 1 deletion source/server/listener_manager_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "common/config/utility.h"
#include "common/config/well_known_names.h"
#include "common/network/listen_socket_impl.h"
#include "common/network/resolver_impl.h"
#include "common/network/socket_option_impl.h"
#include "common/network/utility.h"
#include "common/protobuf/utility.h"
Expand Down Expand Up @@ -120,7 +121,7 @@ class ListenerSocketOption : public Network::SocketOptionImpl {
ListenerImpl::ListenerImpl(const envoy::api::v2::Listener& config, ListenerManagerImpl& parent,
const std::string& name, bool modifiable, bool workers_started,
uint64_t hash)
: parent_(parent), address_(Network::Utility::protobufAddressToAddress(config.address())),
: parent_(parent), address_(Network::Address::resolveProtoAddress(config.address())),
global_scope_(parent_.server_.stats().createScope("")),
listener_scope_(
parent_.server_.stats().createScope(fmt::format("listener.{}.", address_->asString()))),
Expand Down
2 changes: 2 additions & 0 deletions test/mocks/network/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ envoy_cc_mock(
"//include/envoy/network:connection_interface",
"//include/envoy/network:drain_decision_interface",
"//include/envoy/network:filter_interface",
"//include/envoy/network:resolver_interface",
"//include/envoy/network:transport_socket_interface",
"//include/envoy/server:listener_manager_interface",
"//source/common/network:address_lib",
"//source/common/network:utility_lib",
"//test/mocks/event:event_mocks",
"@envoy_api//envoy/api/v2/core:base_cc",
],
)
6 changes: 6 additions & 0 deletions test/mocks/network/mocks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@ MockDnsResolver::MockDnsResolver() {

MockDnsResolver::~MockDnsResolver() {}

MockAddressResolver::MockAddressResolver() {
ON_CALL(*this, name()).WillByDefault(Return("envoy.mock.resolver"));
}

MockAddressResolver::~MockAddressResolver() {}

MockReadFilterCallbacks::MockReadFilterCallbacks() {
ON_CALL(*this, connection()).WillByDefault(ReturnRef(connection_));
ON_CALL(*this, upstreamHost()).WillByDefault(ReturnPointee(&host_));
Expand Down
12 changes: 12 additions & 0 deletions test/mocks/network/mocks.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
#include <list>
#include <string>

#include "envoy/api/v2/core/address.pb.h"
#include "envoy/network/connection.h"
#include "envoy/network/drain_decision.h"
#include "envoy/network/filter.h"
#include "envoy/network/resolver.h"
#include "envoy/network/transport_socket.h"

#include "common/stats/stats_impl.h"
Expand Down Expand Up @@ -147,6 +149,16 @@ class MockDnsResolver : public DnsResolver {
testing::NiceMock<MockActiveDnsQuery> active_query_;
};

class MockAddressResolver : public Address::Resolver {
public:
MockAddressResolver();
~MockAddressResolver();

MOCK_METHOD1(resolve,
Address::InstanceConstSharedPtr(const envoy::api::v2::core::SocketAddress&));
MOCK_CONST_METHOD0(name, std::string());
};

class MockReadFilterCallbacks : public ReadFilterCallbacks {
public:
MockReadFilterCallbacks();
Expand Down
3 changes: 3 additions & 0 deletions test/server/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,16 @@ envoy_cc_test(
"//source/common/config:metadata_lib",
"//source/common/network:listen_socket_lib",
"//source/common/network:socket_option_lib",
"//source/common/network:utility_lib",
"//source/extensions/filters/listener/original_dst:config",
"//source/extensions/filters/network/http_connection_manager:config",
"//source/extensions/transport_sockets/raw_buffer:config",
"//source/extensions/transport_sockets/ssl:config",
"//source/server:listener_manager_lib",
"//test/mocks/network:network_mocks",
"//test/mocks/server:server_mocks",
"//test/test_common:environment_lib",
"//test/test_common:registry_lib",
"//test/test_common:threadsafe_singleton_injector_lib",
],
)
Expand Down
26 changes: 26 additions & 0 deletions test/server/listener_manager_impl_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,18 @@
#include "common/network/address_impl.h"
#include "common/network/listen_socket_impl.h"
#include "common/network/socket_option_impl.h"
#include "common/network/utility.h"

#include "server/configuration_impl.h"
#include "server/listener_manager_impl.h"

#include "extensions/filters/listener/original_dst/original_dst.h"

#include "test/mocks/network/mocks.h"
#include "test/mocks/server/mocks.h"
#include "test/server/utility.h"
#include "test/test_common/environment.h"
#include "test/test_common/registry.h"
#include "test/test_common/threadsafe_singleton_injector.h"
#include "test/test_common/utility.h"

Expand Down Expand Up @@ -1512,6 +1515,29 @@ TEST_F(ListenerManagerImplWithRealFiltersTest, FreebindListenerEnabled) {
}
}

// Set the resolver to the default IP resolver. The address resolver logic is unit tested in
// resolver_impl_test.cc.
TEST_F(ListenerManagerImplWithRealFiltersTest, AddressResolver) {
const std::string yaml = TestEnvironment::substitute(R"EOF(
name: AddressResolverdListener
address:
socket_address: { address: 127.0.0.1, port_value: 1111, resolver_name: envoy.mock.resolver }
filter_chains:
- filters:
)EOF",
Network::Address::IpVersion::v4);

NiceMock<Network::MockAddressResolver> mock_resolver;
EXPECT_CALL(mock_resolver, resolve(_))
.WillOnce(Return(Network::Utility::parseInternetAddress("127.0.0.1", 1111, false)));

Registry::InjectFactory<Network::Address::Resolver> register_resolver(mock_resolver);

EXPECT_CALL(listener_factory_, createListenSocket(_, _, true));
manager_->addOrUpdateListener(parseListenerFromV2Yaml(yaml), true);
EXPECT_EQ(1U, manager_->listeners().size());
}

TEST_F(ListenerManagerImplWithRealFiltersTest, CRLFilename) {
const std::string yaml = TestEnvironment::substitute(R"EOF(
address:
Expand Down