-
Notifications
You must be signed in to change notification settings - Fork 84
Update Envoy to 70a5f29 #1962
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
Update Envoy to 70a5f29 #1962
Changes from all commits
3c3003b
fbe07ca
b0b3651
fd869bf
d0cb5f0
276f06b
bcef26b
e1627eb
d77d0cd
84ad815
59e50e4
19af482
e9ab305
07e3ee4
eb6a57b
0f766e5
c392464
ccd0130
5588b27
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| #include "library/common/network/android.h" | ||
|
|
||
| #include <net/if.h> | ||
|
|
||
| #include "envoy/common/platform.h" | ||
|
|
||
| #include "source/common/api/os_sys_calls_impl.h" | ||
| #include "source/common/common/assert.h" | ||
| #include "source/common/common/scalar_to_byte_vector.h" | ||
| #include "source/common/common/utility.h" | ||
| #include "source/common/network/addr_family_aware_socket_option_impl.h" | ||
| #include "source/common/network/address_impl.h" | ||
| #include "source/extensions/common/dynamic_forward_proxy/dns_cache_manager_impl.h" | ||
|
|
||
| #include "library/common/network/src_addr_socket_option_impl.h" | ||
|
|
||
| namespace Envoy { | ||
| namespace Network { | ||
| namespace Android { | ||
| namespace Utility { | ||
|
|
||
| #if defined(INCLUDE_IFADDRS) | ||
| #pragma clang diagnostic push | ||
| #pragma clang diagnostic ignored "-Wold-style-cast" | ||
| namespace { | ||
| #include "third_party/android/ifaddrs-android.h" | ||
| } | ||
| #pragma clang diagnostic pop | ||
| #endif | ||
|
|
||
| void setAlternateGetifaddrs() { | ||
| #if defined(INCLUDE_IFADDRS) | ||
| auto& os_syscalls = Api::OsSysCallsSingleton::get(); | ||
| ENVOY_BUG(!os_syscalls.supportsGetifaddrs(), | ||
| "setAlternateGetifaddrs should only be called when supportsGetifaddrs is false"); | ||
|
|
||
| Api::AlternateGetifaddrs android_getifaddrs = | ||
| [](Api::InterfaceAddressVector& interfaces) -> Api::SysCallIntResult { | ||
| struct ifaddrs* ifaddr; | ||
| struct ifaddrs* ifa; | ||
|
|
||
| const int rc = getifaddrs(&ifaddr); | ||
| if (rc == -1) { | ||
| return {rc, errno}; | ||
| } | ||
|
|
||
| for (ifa = ifaddr; ifa != nullptr; ifa = ifa->ifa_next) { | ||
| if (ifa->ifa_addr == nullptr) { | ||
| continue; | ||
| } | ||
|
|
||
| if (ifa->ifa_addr->sa_family == AF_INET || ifa->ifa_addr->sa_family == AF_INET6) { | ||
| const sockaddr_storage* ss = reinterpret_cast<sockaddr_storage*>(ifa->ifa_addr); | ||
| size_t ss_len = | ||
| ifa->ifa_addr->sa_family == AF_INET ? sizeof(sockaddr_in) : sizeof(sockaddr_in6); | ||
| StatusOr<Address::InstanceConstSharedPtr> address = | ||
| Address::addressFromSockAddr(*ss, ss_len, ifa->ifa_addr->sa_family == AF_INET6); | ||
| if (address.ok()) { | ||
| interfaces.emplace_back(ifa->ifa_name, ifa->ifa_flags, *address); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| if (ifaddr) { | ||
| freeifaddrs(ifaddr); | ||
| } | ||
|
|
||
| return {rc, 0}; | ||
| }; | ||
|
|
||
| os_syscalls.setAlternateGetifaddrs(android_getifaddrs); | ||
| #endif | ||
| } | ||
|
|
||
| } // namespace Utility | ||
| } // namespace Android | ||
| } // namespace Network | ||
| } // namespace Envoy |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| #pragma once | ||
|
|
||
| namespace Envoy { | ||
| namespace Network { | ||
| namespace Android { | ||
| namespace Utility { | ||
| /** | ||
| * Sets an alternate `getifaddrs` implementation than the one defined | ||
| * in Envoy by default. | ||
| */ | ||
| void setAlternateGetifaddrs(); | ||
| } // namespace Utility | ||
| } // namespace Android | ||
| } // namespace Network | ||
| } // namespace Envoy |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ | |
|
|
||
| #include "envoy/common/platform.h" | ||
|
|
||
| #include "source/common/api/os_sys_calls_impl.h" | ||
| #include "source/common/common/assert.h" | ||
| #include "source/common/common/scalar_to_byte_vector.h" | ||
| #include "source/common/common/utility.h" | ||
|
|
@@ -49,10 +50,6 @@ | |
|
|
||
| #define DEFAULT_IP_TTL 64 | ||
|
|
||
| #ifdef SUPPORTS_GETIFADDRS | ||
| #include <ifaddrs.h> | ||
| #endif | ||
|
|
||
| // Prefixes used to prefer well-known interface names. | ||
| #if defined(__APPLE__) | ||
| constexpr absl::string_view WlanPrefix = "en"; | ||
|
|
@@ -69,16 +66,6 @@ constexpr absl::string_view WwanPrefix = ""; | |
| namespace Envoy { | ||
| namespace Network { | ||
|
|
||
| #if !defined(SUPPORTS_GETIFADDRS) && defined(INCLUDE_IFADDRS) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In my version of this work I had then created a network/android/utility namespace where I created a function that sets the android getifaddrs impl. Then I called that function early in the engine's lifecycle before the network configurator is constructed. This was my implementation:
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for saving me the trouble of writing this 😄 I've pushed it up with minor modifications and addressing the TODO in eb6a57b. I'm working on running the Android sample app locally to confirm this works.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've confirmed that this ifaddrs implementation is used on Android by manually adding logs and confirming they're emitted when running the sample app locally. |
||
| #pragma clang diagnostic push | ||
| #pragma clang diagnostic ignored "-Wold-style-cast" | ||
| namespace { | ||
| #include "third_party/android/ifaddrs-android.h" | ||
| } | ||
| #pragma clang diagnostic pop | ||
| #define SUPPORTS_GETIFADDRS | ||
| #endif | ||
|
|
||
| SINGLETON_MANAGER_REGISTRATION(network_configurator); | ||
|
|
||
| constexpr absl::string_view BaseDnsCache = "base_dns_cache"; | ||
|
|
@@ -329,33 +316,28 @@ Configurator::enumerateInterfaces([[maybe_unused]] unsigned short family, | |
| [[maybe_unused]] unsigned int reject_flags) { | ||
| std::vector<InterfacePair> pairs{}; | ||
|
|
||
| #ifdef SUPPORTS_GETIFADDRS | ||
| struct ifaddrs* interfaces = nullptr; | ||
| struct ifaddrs* ifa = nullptr; | ||
| if (!Api::OsSysCallsSingleton::get().supportsGetifaddrs()) { | ||
| return pairs; | ||
| } | ||
|
|
||
| const int rc = getifaddrs(&interfaces); | ||
| RELEASE_ASSERT(!rc, "getifaddrs failed"); | ||
| Api::InterfaceAddressVector interface_addresses{}; | ||
| const Api::SysCallIntResult rc = Api::OsSysCallsSingleton::get().getifaddrs(interface_addresses); | ||
| RELEASE_ASSERT(!rc.return_value_, fmt::format("getiffaddrs error: {}", rc.errno_)); | ||
|
|
||
| for (ifa = interfaces; ifa != nullptr; ifa = ifa->ifa_next) { | ||
| if (!ifa->ifa_addr || ifa->ifa_addr->sa_family != family) { | ||
| continue; | ||
| } | ||
| if ((ifa->ifa_flags & (select_flags ^ reject_flags)) != select_flags) { | ||
| for (const auto& interface_address : interface_addresses) { | ||
| const auto family_version = family == AF_INET ? Envoy::Network::Address::IpVersion::v4 | ||
| : Envoy::Network::Address::IpVersion::v6; | ||
| if (interface_address.interface_addr_->ip()->version() != family_version) { | ||
| continue; | ||
| } | ||
|
|
||
| const sockaddr_storage* ss = reinterpret_cast<sockaddr_storage*>(ifa->ifa_addr); | ||
| size_t ss_len = family == AF_INET ? sizeof(sockaddr_in) : sizeof(sockaddr_in6); | ||
| StatusOr<Address::InstanceConstSharedPtr> address = | ||
| Address::addressFromSockAddr(*ss, ss_len, family == AF_INET6); | ||
| if (!address.ok()) { | ||
| if ((interface_address.interface_flags_ & (select_flags ^ reject_flags)) != select_flags) { | ||
| continue; | ||
| } | ||
| pairs.push_back(std::make_pair(std::string{ifa->ifa_name}, *address)); | ||
| } | ||
|
|
||
| freeifaddrs(interfaces); | ||
| #endif // SUPPORTS_GETIFADDRS | ||
| pairs.push_back( | ||
| std::make_pair(interface_address.interface_name_, interface_address.interface_addr_)); | ||
| } | ||
|
|
||
| return pairs; | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To account for envoyproxy/envoy#18997
Considering it's designed to be off by default, I imagine that we can disable it for our use cases until we have reason to do otherwise.