diff --git a/source/common/network/BUILD b/source/common/network/BUILD index 6ea2da5de64b..f74ab0f256aa 100644 --- a/source/common/network/BUILD +++ b/source/common/network/BUILD @@ -17,9 +17,9 @@ envoy_cc_library( "//include/envoy/network:address_interface", "//source/common/api:os_sys_calls_lib", "//source/common/common:assert_lib", + "//source/common/common:safe_memcpy_lib", "//source/common/common:statusor_lib", "//source/common/common:thread_lib", - "//source/common/common:safe_memcpy_lib", "//source/common/common:utility_lib", ], ) diff --git a/source/common/network/address_impl.cc b/source/common/network/address_impl.cc index 38afc5f17c96..94d9fdc6e322 100644 --- a/source/common/network/address_impl.cc +++ b/source/common/network/address_impl.cc @@ -4,13 +4,13 @@ #include #include -#include "common/common/thread.h" #include "envoy/common/exception.h" #include "envoy/common/platform.h" #include "common/common/assert.h" #include "common/common/fmt.h" #include "common/common/safe_memcpy.h" +#include "common/common/thread.h" #include "common/common/utility.h" #include "common/network/socket_interface.h" @@ -63,8 +63,8 @@ const SocketInterface* sockInterfaceOrDefault(const SocketInterface* sock_interf } // namespace -StatusOr addressFromSockAddr(const sockaddr_storage& ss, socklen_t ss_len, - bool v6only) { +StatusOr addressFromSockAddr(const sockaddr_storage& ss, + socklen_t ss_len, bool v6only) { RELEASE_ASSERT(ss_len == 0 || static_cast(ss_len) >= sizeof(sa_family_t), ""); switch (ss.ss_family) { case AF_INET: { @@ -107,10 +107,9 @@ StatusOr addressFromSockAddr(const sockaddr_sto NOT_REACHED_GCOVR_EXCL_LINE; } - Ipv4Instance::Ipv4Instance(const sockaddr_in* address, const SocketInterface* sock_interface) : InstanceBase(Type::Ip, sockInterfaceOrDefault(sock_interface)) { - //ASSERT(Thread::MainThread::isMainThread()); + // ASSERT(Thread::MainThread::isMainThread()); memset(&ip_.ipv4_.address_, 0, sizeof(ip_.ipv4_.address_)); ip_.ipv4_.address_ = *address; ip_.friendly_address_ = sockaddrToString(*address); @@ -132,7 +131,7 @@ Ipv4Instance::Ipv4Instance(const std::string& address, const SocketInterface* so Ipv4Instance::Ipv4Instance(const std::string& address, uint32_t port, const SocketInterface* sock_interface) : InstanceBase(Type::Ip, sockInterfaceOrDefault(sock_interface)) { - //ASSERT(Thread::MainThread::isMainThread()); + // ASSERT(Thread::MainThread::isMainThread()); memset(&ip_.ipv4_.address_, 0, sizeof(ip_.ipv4_.address_)); ip_.ipv4_.address_.sin_family = AF_INET; ip_.ipv4_.address_.sin_port = htons(port); @@ -150,7 +149,7 @@ Ipv4Instance::Ipv4Instance(const std::string& address, uint32_t port, Ipv4Instance::Ipv4Instance(uint32_t port, const SocketInterface* sock_interface) : InstanceBase(Type::Ip, sockInterfaceOrDefault(sock_interface)) { - //ASSERT(Thread::MainThread::isMainThread()); + // ASSERT(Thread::MainThread::isMainThread()); memset(&ip_.ipv4_.address_, 0, sizeof(ip_.ipv4_.address_)); ip_.ipv4_.address_.sin_family = AF_INET; ip_.ipv4_.address_.sin_port = htons(port); @@ -162,7 +161,8 @@ Ipv4Instance::Ipv4Instance(uint32_t port, const SocketInterface* sock_interface) ip_.friendly_address_ = "0.0.0.0"; } -Ipv4Instance::Ipv4Instance(absl::Status&, const sockaddr_in* address, const SocketInterface* sock_interface) +Ipv4Instance::Ipv4Instance(absl::Status&, const sockaddr_in* address, + const SocketInterface* sock_interface) : InstanceBase(Type::Ip, sockInterfaceOrDefault(sock_interface)) { memset(&ip_.ipv4_.address_, 0, sizeof(ip_.ipv4_.address_)); ip_.ipv4_.address_ = *address; @@ -176,8 +176,8 @@ Ipv4Instance::Ipv4Instance(absl::Status&, const sockaddr_in* address, const Sock friendly_name_.append(port.data(), port.size()); } - -Ipv4Instance::Ipv4Instance(absl::Status& error, const std::string& address, const SocketInterface* sock_interface) +Ipv4Instance::Ipv4Instance(absl::Status& error, const std::string& address, + const SocketInterface* sock_interface) : Ipv4Instance(error, address, 0, sockInterfaceOrDefault(sock_interface)) {} Ipv4Instance::Ipv4Instance(absl::Status& error, const std::string& address, uint32_t port, @@ -267,7 +267,7 @@ std::string Ipv6Instance::Ipv6Helper::makeFriendlyAddress() const { Ipv6Instance::Ipv6Instance(const sockaddr_in6& address, bool v6only, const SocketInterface* sock_interface) : InstanceBase(Type::Ip, sockInterfaceOrDefault(sock_interface)) { - //ASSERT(Thread::MainThread::isMainThread()); + // ASSERT(Thread::MainThread::isMainThread()); ip_.ipv6_.address_ = address; ip_.friendly_address_ = ip_.ipv6_.makeFriendlyAddress(); ip_.ipv6_.v6only_ = v6only; @@ -283,7 +283,7 @@ Ipv6Instance::Ipv6Instance(const std::string& address, const SocketInterface* so Ipv6Instance::Ipv6Instance(const std::string& address, uint32_t port, const SocketInterface* sock_interface) : InstanceBase(Type::Ip, sockInterfaceOrDefault(sock_interface)) { - //ASSERT(Thread::MainThread::isMainThread()); + // ASSERT(Thread::MainThread::isMainThread()); ip_.ipv6_.address_.sin6_family = AF_INET6; ip_.ipv6_.address_.sin6_port = htons(port); if (!address.empty()) { @@ -353,7 +353,8 @@ Ipv6Instance::Ipv6Instance(absl::Status&, const sockaddr_in6& address, bool v6on friendly_name_ = fmt::format("[{}]:{}", ip_.friendly_address_, ip_.port()); } -Ipv6Instance::Ipv6Instance(absl::Status& error, const std::string& address, const SocketInterface* sock_interface) +Ipv6Instance::Ipv6Instance(absl::Status& error, const std::string& address, + const SocketInterface* sock_interface) : Ipv6Instance(error, address, 0, sockInterfaceOrDefault(sock_interface)) {} Ipv6Instance::Ipv6Instance(absl::Status& error, const std::string& address, uint32_t port, @@ -375,7 +376,8 @@ Ipv6Instance::Ipv6Instance(absl::Status& error, const std::string& address, uint friendly_name_ = fmt::format("[{}]:{}", ip_.friendly_address_, ip_.port()); } -Ipv6Instance::Ipv6Instance(absl::Status& error, uint32_t port, const SocketInterface* sock_interface) +Ipv6Instance::Ipv6Instance(absl::Status& error, uint32_t port, + const SocketInterface* sock_interface) : Ipv6Instance(error, "", port, sockInterfaceOrDefault(sock_interface)) {} PipeInstance::PipeInstance(const std::string& pipe_path, mode_t mode, @@ -421,13 +423,12 @@ PipeInstance::PipeInstance(const std::string& pipe_path, mode_t mode, pipe_.mode_ = mode; } -PipeInstance::PipeInstance(absl::Status& error, const sockaddr_un* address, socklen_t ss_len, mode_t mode, - const SocketInterface* sock_interface) +PipeInstance::PipeInstance(absl::Status& error, const sockaddr_un* address, socklen_t ss_len, + mode_t mode, const SocketInterface* sock_interface) : InstanceBase(Type::Pipe, sockInterfaceOrDefault(sock_interface)) { if (address->sun_path[0] == '\0') { #if !defined(__linux__) - error = - absl::FailedPreconditionError("Abstract AF_UNIX sockets are only supported on linux."); + error = absl::FailedPreconditionError("Abstract AF_UNIX sockets are only supported on linux."); return; #endif RELEASE_ASSERT(static_cast(ss_len) >= offsetof(struct sockaddr_un, sun_path) + 1, @@ -468,8 +469,7 @@ PipeInstance::PipeInstance(absl::Status& error, const std::string& pipe_path, mo // be null terminated. The friendly name is the address path with embedded nulls replaced with // '@' for consistency with the first character. #if !defined(__linux__) - error = - absl::FailedPreconditionError("Abstract AF_UNIX sockets are only supported on linux."); + error = absl::FailedPreconditionError("Abstract AF_UNIX sockets are only supported on linux."); return; #endif if (mode != 0) { diff --git a/source/common/network/address_impl.h b/source/common/network/address_impl.h index 390d61534458..1ac38586786f 100644 --- a/source/common/network/address_impl.h +++ b/source/common/network/address_impl.h @@ -115,6 +115,29 @@ class Ipv4Instance : public InstanceBase { */ explicit Ipv4Instance(uint32_t port, const SocketInterface* sock_interface = nullptr); + // Network::Address::Instance + bool operator==(const Instance& rhs) const override; + const Ip* ip() const override { return &ip_; } + const Pipe* pipe() const override { return nullptr; } + const EnvoyInternalAddress* envoyInternalAddress() const override { return nullptr; } + const sockaddr* sockAddr() const override { + return reinterpret_cast(&ip_.ipv4_.address_); + } + socklen_t sockAddrLen() const override { return sizeof(sockaddr_in); } + + /** + * Convenience function to convert an IPv4 address to canonical string format. + * @note This works similarly to inet_ntop() but is faster. + * @param addr address to format. + * @return the address in dotted-decimal string format. + */ + static std::string sockaddrToString(const sockaddr_in& addr); + + // Validate that IPv4 is supported on this platform, raise an exception for the + // given address if not. + static absl::Status validateProtocolSupported(); + +private: /** * Construct from an existing unix IPv4 socket address (IP v4 address and port). */ @@ -140,29 +163,6 @@ class Ipv4Instance : public InstanceBase { explicit Ipv4Instance(absl::Status& error, uint32_t port, const SocketInterface* sock_interface = nullptr); - // Network::Address::Instance - bool operator==(const Instance& rhs) const override; - const Ip* ip() const override { return &ip_; } - const Pipe* pipe() const override { return nullptr; } - const EnvoyInternalAddress* envoyInternalAddress() const override { return nullptr; } - const sockaddr* sockAddr() const override { - return reinterpret_cast(&ip_.ipv4_.address_); - } - socklen_t sockAddrLen() const override { return sizeof(sockaddr_in); } - - /** - * Convenience function to convert an IPv4 address to canonical string format. - * @note This works similarly to inet_ntop() but is faster. - * @param addr address to format. - * @return the address in dotted-decimal string format. - */ - static std::string sockaddrToString(const sockaddr_in& addr); - - // Validate that IPv4 is supported on this platform, raise an exception for the - // given address if not. - static absl::Status validateProtocolSupported(); - -private: struct Ipv4Helper : public Ipv4 { uint32_t address() const override { return address_.sin_addr.s_addr; } @@ -187,6 +187,7 @@ class Ipv4Instance : public InstanceBase { }; IpHelper ip_; + friend class InstanceFactory; }; /** @@ -218,6 +219,20 @@ class Ipv6Instance : public InstanceBase { */ explicit Ipv6Instance(uint32_t port, const SocketInterface* sock_interface = nullptr); + // Network::Address::Instance + bool operator==(const Instance& rhs) const override; + const Ip* ip() const override { return &ip_; } + const Pipe* pipe() const override { return nullptr; } + const EnvoyInternalAddress* envoyInternalAddress() const override { return nullptr; } + const sockaddr* sockAddr() const override { + return reinterpret_cast(&ip_.ipv6_.address_); + } + socklen_t sockAddrLen() const override { return sizeof(sockaddr_in6); } + + // Validate that IPv6 is supported on this platform + static absl::Status validateProtocolSupported(); + +private: /** * Construct from an existing unix IPv6 socket address (IP v6 address and port). */ @@ -243,20 +258,6 @@ class Ipv6Instance : public InstanceBase { explicit Ipv6Instance(absl::Status& error, uint32_t port, const SocketInterface* sock_interface = nullptr); - // Network::Address::Instance - bool operator==(const Instance& rhs) const override; - const Ip* ip() const override { return &ip_; } - const Pipe* pipe() const override { return nullptr; } - const EnvoyInternalAddress* envoyInternalAddress() const override { return nullptr; } - const sockaddr* sockAddr() const override { - return reinterpret_cast(&ip_.ipv6_.address_); - } - socklen_t sockAddrLen() const override { return sizeof(sockaddr_in6); } - - // Validate that IPv6 is supported on this platform - static absl::Status validateProtocolSupported(); - -private: struct Ipv6Helper : public Ipv6 { Ipv6Helper() { memset(&address_, 0, sizeof(address_)); } absl::uint128 address() const override; @@ -290,6 +291,7 @@ class Ipv6Instance : public InstanceBase { }; IpHelper ip_; + friend class InstanceFactory; }; /** @@ -309,18 +311,6 @@ class PipeInstance : public InstanceBase { explicit PipeInstance(const std::string& pipe_path, mode_t mode = 0, const SocketInterface* sock_interface = nullptr); - /** - * Construct from an existing unix address. - */ - explicit PipeInstance(absl::Status& error, const sockaddr_un* address, socklen_t ss_len, - mode_t mode = 0, const SocketInterface* sock_interface = nullptr); - - /** - * Construct from a string pipe path. - */ - explicit PipeInstance(absl::Status& error, const std::string& pipe_path, mode_t mode = 0, - const SocketInterface* sock_interface = nullptr); - static absl::Status validateProtocolSupported() { return absl::OkStatus(); } // Network::Address::Instance @@ -340,6 +330,17 @@ class PipeInstance : public InstanceBase { } private: + /** + * Construct from an existing unix address. + */ + explicit PipeInstance(absl::Status& error, const sockaddr_un* address, socklen_t ss_len, + mode_t mode = 0, const SocketInterface* sock_interface = nullptr); + + /** + * Construct from a string pipe path. + */ + explicit PipeInstance(absl::Status& error, const std::string& pipe_path, mode_t mode = 0, + const SocketInterface* sock_interface = nullptr); struct PipeHelper : public Pipe { bool abstractNamespace() const override { return abstract_namespace_; } @@ -353,6 +354,7 @@ class PipeInstance : public InstanceBase { }; PipeHelper pipe_; + friend class InstanceFactory; }; class EnvoyInternalInstance : public InstanceBase { diff --git a/source/common/network/io_socket_handle_impl.cc b/source/common/network/io_socket_handle_impl.cc index 627b7dad3137..22987bee2119 100644 --- a/source/common/network/io_socket_handle_impl.cc +++ b/source/common/network/io_socket_handle_impl.cc @@ -9,7 +9,6 @@ #include "absl/container/fixed_array.h" #include "absl/types/optional.h" -#include "source/common/common/_virtual_includes/statusor_lib/common/common/statusor.h" using Envoy::Api::SysCallIntResult; using Envoy::Api::SysCallSizeResult; @@ -604,7 +603,8 @@ Address::InstanceConstSharedPtr IoSocketHandleImpl::localAddress() { throw EnvoyException(fmt::format("getsockname failed for '{}': ({}) {}", fd_, result.errno_, errorDetails(result.errno_))); } - StatusOr error_or_address = Address::addressFromSockAddr(ss, ss_len, socket_v6only_); + StatusOr error_or_address = + Address::addressFromSockAddr(ss, ss_len, socket_v6only_); ASSERT(error_or_address.ok()); return *error_or_address; } @@ -631,7 +631,8 @@ Address::InstanceConstSharedPtr IoSocketHandleImpl::peerAddress() { fmt::format("getsockname failed for '{}': {}", fd_, errorDetails(result.errno_))); } } - StatusOr error_or_address = Address::addressFromSockAddr(ss, ss_len); + StatusOr error_or_address = + Address::addressFromSockAddr(ss, ss_len); ASSERT(error_or_address.ok()); return *error_or_address; } diff --git a/source/common/network/utility.cc b/source/common/network/utility.cc index b9df458b45b8..c0a40105da7b 100644 --- a/source/common/network/utility.cc +++ b/source/common/network/utility.cc @@ -28,7 +28,6 @@ #include "absl/container/fixed_array.h" #include "absl/strings/match.h" #include "absl/strings/string_view.h" -#include "source/common/common/_virtual_includes/statusor_lib/common/common/statusor.h" namespace Envoy { namespace Network { @@ -391,7 +390,7 @@ Utility::getAddressWithPort(const Address::Instance& address, uint32_t port) { address.ip()->addressAsString(), port); case Address::IpVersion::v6: return Address::InstanceFactory::createInstancePtr( - address.ip()->addressAsString(), port); + address.ip()->addressAsString(), port); } NOT_REACHED_GCOVR_EXCL_LINE; } diff --git a/source/common/network/utility.h b/source/common/network/utility.h index 2ef610bb2542..a97e7f8173b6 100644 --- a/source/common/network/utility.h +++ b/source/common/network/utility.h @@ -8,6 +8,7 @@ #include "envoy/config/core/v3/address.pb.h" #include "envoy/network/connection.h" #include "envoy/network/listener.h" + #include "common/common/statusor.h" #include "absl/strings/string_view.h" @@ -265,8 +266,8 @@ class Utility { */ static const std::string& getIpv6CidrCatchAllAddress(); - static StatusOr getAddressWithPort(const Address::Instance& address, - uint32_t port); + static StatusOr + getAddressWithPort(const Address::Instance& address, uint32_t port); /** * @param address IP address instance. @@ -274,8 +275,7 @@ class Utility { * @return Address::InstanceConstSharedPtr a new address instance with updated port. */ static Address::InstanceConstSharedPtr getAddressWithPortOrThrow(const Address::Instance& address, - uint32_t port); - + uint32_t port); /** * Retrieve the original destination address from an accepted socket. diff --git a/source/common/upstream/logical_host.h b/source/common/upstream/logical_host.h index f6ccc9abe481..288db374b78a 100644 --- a/source/common/upstream/logical_host.h +++ b/source/common/upstream/logical_host.h @@ -37,7 +37,8 @@ class LogicalHost : public HostImpl { const envoy::config::endpoint::v3::LbEndpoint& lb_endpoint) { const auto& port_value = lb_endpoint.endpoint().health_check_config().port_value(); auto health_check_address = - port_value == 0 ? address : Network::Utility::getAddressWithPortOrThrow(*address, port_value); + port_value == 0 ? address + : Network::Utility::getAddressWithPortOrThrow(*address, port_value); absl::WriterMutexLock lock(&address_lock_); setAddress(address); diff --git a/source/common/upstream/strict_dns_cluster.cc b/source/common/upstream/strict_dns_cluster.cc index 54706b293f67..bbe52617a454 100644 --- a/source/common/upstream/strict_dns_cluster.cc +++ b/source/common/upstream/strict_dns_cluster.cc @@ -131,17 +131,15 @@ void StrictDnsClusterImpl::ResolveTarget::startResolve() { // for SRV. ASSERT(resp.address_ != nullptr); - StatusOr error_or_address = - Network::Utility::getAddressWithPort(*(resp.address_), - port_); - if (!error_or_address.ok()) { - ENVOY_LOG(debug, "Fail to create new address."); - return; - } - Network::Address::InstanceConstSharedPtr new_address = *error_or_address; + StatusOr error_or_address = + Network::Utility::getAddressWithPort(*(resp.address_), port_); + if (!error_or_address.ok()) { + ENVOY_LOG(debug, "Fail to create new address."); + return; + } + Network::Address::InstanceConstSharedPtr new_address = *error_or_address; new_hosts.emplace_back(new HostImpl( - parent_.info_, hostname_, - new_address, + parent_.info_, hostname_, new_address, // TODO(zyfjeff): Created through metadata shared pool std::make_shared(lb_endpoint_.metadata()), lb_endpoint_.load_balancing_weight().value(), locality_lb_endpoints_.locality(), diff --git a/source/common/upstream/upstream_impl.cc b/source/common/upstream/upstream_impl.cc index 55b9fa7976c3..d62994d40ed2 100644 --- a/source/common/upstream/upstream_impl.cc +++ b/source/common/upstream/upstream_impl.cc @@ -264,10 +264,10 @@ HostDescriptionImpl::HostDescriptionImpl( throw EnvoyException( fmt::format("Invalid host configuration: non-zero port for non-IP address")); } - health_check_address_ = - health_check_config.port_value() == 0 - ? dest_address - : Network::Utility::getAddressWithPortOrThrow(*dest_address, health_check_config.port_value()); + health_check_address_ = health_check_config.port_value() == 0 + ? dest_address + : Network::Utility::getAddressWithPortOrThrow( + *dest_address, health_check_config.port_value()); } Network::TransportSocketFactory& HostDescriptionImpl::resolveTransportSocketFactory( diff --git a/source/extensions/clusters/redis/redis_cluster.cc b/source/extensions/clusters/redis/redis_cluster.cc index 4871ce7085a6..f0dee5658902 100644 --- a/source/extensions/clusters/redis/redis_cluster.cc +++ b/source/extensions/clusters/redis/redis_cluster.cc @@ -261,7 +261,8 @@ void RedisCluster::RedisDiscoverySession::registerDiscoveryAddress( // port in it. for (const Network::DnsResponse& res : response) { ASSERT(res.address_ != nullptr); - discovery_address_list_.push_back(Network::Utility::getAddressWithPortOrThrow(*(res.address_), port)); + discovery_address_list_.push_back( + Network::Utility::getAddressWithPortOrThrow(*(res.address_), port)); } } diff --git a/source/extensions/common/dynamic_forward_proxy/dns_cache_impl.cc b/source/extensions/common/dynamic_forward_proxy/dns_cache_impl.cc index 443c2cee548c..adfc13c9842a 100644 --- a/source/extensions/common/dynamic_forward_proxy/dns_cache_impl.cc +++ b/source/extensions/common/dynamic_forward_proxy/dns_cache_impl.cc @@ -242,10 +242,10 @@ void DnsCacheImpl::finishResolve(const std::string& host, // If the DNS resolver successfully resolved with an empty response list, the dns cache does not // update. This ensures that a potentially previously resolved address does not stabilize back to // 0 hosts. - const auto new_address = !response.empty() - ? Network::Utility::getAddressWithPortOrThrow(*(response.front().address_), + const auto new_address = + !response.empty() ? Network::Utility::getAddressWithPortOrThrow(*(response.front().address_), primary_host_info->port_) - : nullptr; + : nullptr; if (status == Network::DnsResolver::ResolutionStatus::Failure) { stats_.dns_query_failure_.inc(); diff --git a/test/common/network/address_impl_test.cc b/test/common/network/address_impl_test.cc index 8e87f8d7284d..b72b8cb11f8d 100644 --- a/test/common/network/address_impl_test.cc +++ b/test/common/network/address_impl_test.cc @@ -494,8 +494,10 @@ TEST(AddressFromSockAddrDeathTest, IPv6) { // Test that IPv4-mapped IPv6 address is returned as an Ipv4Instance when 'v6only' parameter is // 'false', but not otherwise. EXPECT_EQ(1, inet_pton(AF_INET6, "::ffff:192.0.2.128", &sin6.sin6_addr)); - EXPECT_EQ(IpVersion::v4, (*addressFromSockAddr(ss, sizeof(sockaddr_in6), false))->ip()->version()); - EXPECT_EQ("192.0.2.128:32000", (*addressFromSockAddr(ss, sizeof(sockaddr_in6), false))->asString()); + EXPECT_EQ(IpVersion::v4, + (*addressFromSockAddr(ss, sizeof(sockaddr_in6), false))->ip()->version()); + EXPECT_EQ("192.0.2.128:32000", + (*addressFromSockAddr(ss, sizeof(sockaddr_in6), false))->asString()); EXPECT_EQ(IpVersion::v6, (*addressFromSockAddr(ss, sizeof(sockaddr_in6), true))->ip()->version()); EXPECT_EQ("[::ffff:192.0.2.128]:32000", (*addressFromSockAddr(ss, sizeof(sockaddr_in6), true))->asString()); diff --git a/test/common/network/dns_impl_test.cc b/test/common/network/dns_impl_test.cc index 44314bff395a..c637a6389f41 100644 --- a/test/common/network/dns_impl_test.cc +++ b/test/common/network/dns_impl_test.cc @@ -667,7 +667,7 @@ TEST_P(DnsImplTest, DestroyChannelOnRefused) { // If that flag needs to be set, or c-ares changes its handling this test will need to be updated // to create another condition where c-ares invokes onAresGetAddrInfoCallback with status == // ARES_ECONNREFUSED. - + EXPECT_TRUE(peer_->isChannelDirty()); server_->setRefused(false); diff --git a/test/common/network/listener_impl_test.cc b/test/common/network/listener_impl_test.cc index b8b9feb66388..541f7b8b0787 100644 --- a/test/common/network/listener_impl_test.cc +++ b/test/common/network/listener_impl_test.cc @@ -226,9 +226,9 @@ TEST_P(TcpListenerImplTest, WildcardListenerUseActualDst) { Network::TestTcpListenerImpl listener(dispatcherImpl(), random_generator, socket, listener_callbacks, true); - auto local_dst_address = - Network::Utility::getAddressWithPortOrThrow(*Network::Test::getCanonicalLoopbackAddress(version_), - socket->addressProvider().localAddress()->ip()->port()); + auto local_dst_address = Network::Utility::getAddressWithPortOrThrow( + *Network::Test::getCanonicalLoopbackAddress(version_), + socket->addressProvider().localAddress()->ip()->port()); Network::ClientConnectionPtr client_connection = dispatcher_->createClientConnection( local_dst_address, Network::Address::InstanceConstSharedPtr(), Network::Test::createRawBufferSocket(), nullptr); @@ -270,12 +270,12 @@ TEST_P(TcpListenerImplTest, WildcardListenerIpv4Compat) { Network::TestTcpListenerImpl listener(dispatcherImpl(), random_generator, socket, listener_callbacks, true); - auto listener_address = - Network::Utility::getAddressWithPortOrThrow(*Network::Test::getCanonicalLoopbackAddress(version_), - socket->addressProvider().localAddress()->ip()->port()); - auto local_dst_address = - Network::Utility::getAddressWithPortOrThrow(*Network::Utility::getCanonicalIpv4LoopbackAddress(), - socket->addressProvider().localAddress()->ip()->port()); + auto listener_address = Network::Utility::getAddressWithPortOrThrow( + *Network::Test::getCanonicalLoopbackAddress(version_), + socket->addressProvider().localAddress()->ip()->port()); + auto local_dst_address = Network::Utility::getAddressWithPortOrThrow( + *Network::Utility::getCanonicalIpv4LoopbackAddress(), + socket->addressProvider().localAddress()->ip()->port()); Network::ClientConnectionPtr client_connection = dispatcher_->createClientConnection( local_dst_address, Network::Address::InstanceConstSharedPtr(), Network::Test::createRawBufferSocket(), nullptr); diff --git a/test/common/quic/envoy_quic_client_session_test.cc b/test/common/quic/envoy_quic_client_session_test.cc index f1efdf572184..a392b967c669 100644 --- a/test/common/quic/envoy_quic_client_session_test.cc +++ b/test/common/quic/envoy_quic_client_session_test.cc @@ -102,10 +102,10 @@ class EnvoyQuicClientSessionTest : public testing::TestWithParam { SetQuicReloadableFlag(quic_disable_version_draft_29, !GetParam()); return quic::ParsedVersionOfIndex(quic::CurrentSupportedVersions(), 0); }()), - peer_addr_(Network::Utility::getAddressWithPortOrThrow(*Network::Utility::getIpv6LoopbackAddress(), - 12345)), - self_addr_(Network::Utility::getAddressWithPortOrThrow(*Network::Utility::getIpv6LoopbackAddress(), - 54321)), + peer_addr_(Network::Utility::getAddressWithPortOrThrow( + *Network::Utility::getIpv6LoopbackAddress(), 12345)), + self_addr_(Network::Utility::getAddressWithPortOrThrow( + *Network::Utility::getIpv6LoopbackAddress(), 54321)), quic_connection_(new TestEnvoyQuicClientConnection( quic::test::TestConnectionId(), connection_helper_, alarm_factory_, writer_, quic_version_, *dispatcher_, createConnectionSocket(peer_addr_, self_addr_, nullptr))), diff --git a/test/common/quic/envoy_quic_client_stream_test.cc b/test/common/quic/envoy_quic_client_stream_test.cc index 98d67d183354..6d0884fa26af 100644 --- a/test/common/quic/envoy_quic_client_stream_test.cc +++ b/test/common/quic/envoy_quic_client_stream_test.cc @@ -28,10 +28,10 @@ class EnvoyQuicClientStreamTest : public testing::TestWithParam { SetQuicReloadableFlag(quic_disable_version_draft_29, !GetParam()); return quic::CurrentSupportedVersions()[0]; }()), - peer_addr_(Network::Utility::getAddressWithPortOrThrow(*Network::Utility::getIpv6LoopbackAddress(), - 12345)), - self_addr_(Network::Utility::getAddressWithPortOrThrow(*Network::Utility::getIpv6LoopbackAddress(), - 54321)), + peer_addr_(Network::Utility::getAddressWithPortOrThrow( + *Network::Utility::getIpv6LoopbackAddress(), 12345)), + self_addr_(Network::Utility::getAddressWithPortOrThrow( + *Network::Utility::getIpv6LoopbackAddress(), 54321)), quic_connection_(new EnvoyQuicClientConnection( quic::test::TestConnectionId(), connection_helper_, alarm_factory_, &writer_, /*owns_writer=*/false, {quic_version_}, *dispatcher_, diff --git a/test/common/quic/envoy_quic_writer_test.cc b/test/common/quic/envoy_quic_writer_test.cc index ae784ed06fee..6aee9476b2a6 100644 --- a/test/common/quic/envoy_quic_writer_test.cc +++ b/test/common/quic/envoy_quic_writer_test.cc @@ -33,10 +33,11 @@ class EnvoyQuicWriterTest : public ::testing::Test { } void verifySendData(const std::string& content, const msghdr* message) { - EXPECT_EQ(peer_address_.ToString(), (*Network::Address::addressFromSockAddr( - *reinterpret_cast(message->msg_name), - message->msg_namelen, /*v6only=*/false) - )->asString()); + EXPECT_EQ(peer_address_.ToString(), + (*Network::Address::addressFromSockAddr( + *reinterpret_cast(message->msg_name), message->msg_namelen, + /*v6only=*/false)) + ->asString()); cmsghdr* const cmsg = CMSG_FIRSTHDR(message); auto pktinfo = reinterpret_cast(CMSG_DATA(cmsg)); EXPECT_EQ(0, memcmp(self_address_.GetIPv6().s6_addr, pktinfo->ipi6_addr.s6_addr, diff --git a/test/server/connection_handler_test.cc b/test/server/connection_handler_test.cc index d207c9f53757..06fca2b76e3a 100644 --- a/test/server/connection_handler_test.cc +++ b/test/server/connection_handler_test.cc @@ -261,8 +261,9 @@ class ConnectionHandlerTest : public testing::Test, protected Logger::Loggableip()->port()); + Network::Address::InstanceConstSharedPtr any_address = + Network::Utility::getAddressWithPortOrThrow(*Network::Utility::getIpv4AnyAddress(), + normal_address->ip()->port()); EXPECT_CALL(*socket_factory_, localAddress()).WillRepeatedly(ReturnRef(any_address)); handler_->addListener(absl::nullopt, *test_listener); @@ -772,8 +773,9 @@ TEST_F(ConnectionHandlerTest, WildcardListenerWithNoOriginalDst) { Network::Address::InstanceConstSharedPtr normal_address( new Network::Address::Ipv4Instance("127.0.0.1", 80)); - Network::Address::InstanceConstSharedPtr any_address = Network::Utility::getAddressWithPortOrThrow( - *Network::Utility::getIpv4AnyAddress(), normal_address->ip()->port()); + Network::Address::InstanceConstSharedPtr any_address = + Network::Utility::getAddressWithPortOrThrow(*Network::Utility::getIpv4AnyAddress(), + normal_address->ip()->port()); EXPECT_CALL(*socket_factory_, localAddress()).WillRepeatedly(ReturnRef(any_address)); handler_->addListener(absl::nullopt, *test_listener1);