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

proxy: add android proxy monitor #2416

Merged
merged 180 commits into from
Sep 20, 2022
Merged
Show file tree
Hide file tree
Changes from 174 commits
Commits
Show all changes
180 commits
Select commit Hold shift + click to select a range
5be8661
Add proxy monitor
Augustyniak Jul 13, 2022
7f2df89
fix mem leak
Augustyniak Jul 14, 2022
47bdba3
Wire up up to the connectivity manager
Augustyniak Jul 14, 2022
45cb9b9
lint fixes
Augustyniak Jul 14, 2022
4c696fc
first changes in the filter chain
Augustyniak Jul 14, 2022
eafeda7
Merge branch 'main' into add-proxy-monitor
Augustyniak Jul 14, 2022
600fd31
update connectivity filter so that it passes proxy settings
Augustyniak Jul 14, 2022
b48e044
Merge branch 'main' into add-proxy-monitor
Augustyniak Jul 15, 2022
2b4b14e
wire up
Augustyniak Jul 15, 2022
2e21d5f
register config proto
Augustyniak Jul 15, 2022
a55fa3c
handle null case
Augustyniak Jul 15, 2022
b359d1d
wrap existing socket with proxy socket
Augustyniak Jul 15, 2022
9a0284b
Merge branch 'main' into add-proxy-monitor
Augustyniak Jul 18, 2022
3361c49
Merge branch 'main' into add-proxy-monitor
Augustyniak Aug 2, 2022
1834fbf
Merge branch 'main' into add-proxy-monitor
Augustyniak Aug 3, 2022
cd7a3d2
compiles with host and port
Augustyniak Aug 4, 2022
31bba6a
Lint fixes
Augustyniak Aug 4, 2022
9f9b034
Check authority header
Augustyniak Aug 4, 2022
7990561
parse IP address only once
Augustyniak Aug 4, 2022
b1310ed
Wrap base's cluster socket with proxy socket
Augustyniak Aug 5, 2022
81e6108
Add trace logs for when proxy request info is set
Augustyniak Aug 5, 2022
0212d3f
Merge branch 'main' into add-proxy-monitor
Augustyniak Aug 5, 2022
060e5ff
Merge branch 'main' into add-proxy-monitor
Augustyniak Aug 23, 2022
6936f53
wrap base_clear socket with proxy socket
Augustyniak Aug 24, 2022
ecf8922
local patch for main activity and clear text
Augustyniak Aug 24, 2022
ab34acc
Merge branch 'main' into add-proxy-monitor
Augustyniak Sep 2, 2022
2d5640e
Merge branch 'main' into add-proxy-monitor
Augustyniak Sep 7, 2022
9dc806e
Gate the initialization of AndroidProxyMonitor with a flag
Augustyniak Sep 8, 2022
2ba43b0
initial proxy state
Augustyniak Sep 8, 2022
5090476
test runs
Augustyniak Sep 8, 2022
067dd6b
modifications in test
Augustyniak Sep 8, 2022
e8f7e76
finish playing with tests
Augustyniak Sep 8, 2022
8632b38
Revert "finish playing with tests"
Augustyniak Sep 8, 2022
2d79376
Revert "modifications in test"
Augustyniak Sep 8, 2022
4fe1ff9
Revert "test runs"
Augustyniak Sep 8, 2022
92f4236
Revert debugging changes
Augustyniak Sep 9, 2022
b1d0e88
enable proxy support in example apps
Augustyniak Sep 9, 2022
d99ca51
lint fix
Augustyniak Sep 9, 2022
6c6fdf6
revert property addition
Augustyniak Sep 9, 2022
e2e68cc
add missing argument
Augustyniak Sep 9, 2022
8664b60
revert upstream headers change
Augustyniak Sep 12, 2022
9ce44c7
Merge branch 'main' into add-proxy-monitor
Augustyniak Sep 12, 2022
fc3fe67
test works
Augustyniak Sep 12, 2022
88b028a
working test
Augustyniak Sep 12, 2022
3d53d21
working dfp cluster
Augustyniak Sep 12, 2022
03c7dc1
clean up test
Augustyniak Sep 12, 2022
970bf41
tmp
Augustyniak Sep 13, 2022
505cd2e
first test works
Augustyniak Sep 13, 2022
4464687
WIP
Augustyniak Sep 13, 2022
2b8865a
working new test
Augustyniak Sep 13, 2022
2e53594
Working http proxy
Augustyniak Sep 13, 2022
8457f74
cleaned up tests
Augustyniak Sep 13, 2022
f47cb20
connect matcher
Augustyniak Sep 13, 2022
cf298ae
working https test
Augustyniak Sep 13, 2022
4ba1b0e
update tests
Augustyniak Sep 13, 2022
e990100
revert example app changes
Augustyniak Sep 13, 2022
0819c67
update docs and version history
Augustyniak Sep 13, 2022
53b296e
revert
Augustyniak Sep 13, 2022
3d262ab
revert example app changes
Augustyniak Sep 13, 2022
f269117
format fixes
Augustyniak Sep 13, 2022
b7b16b5
tmp rename
Augustyniak Sep 13, 2022
fa02685
revert rename
Augustyniak Sep 13, 2022
379c97b
move stuff around
Augustyniak Sep 13, 2022
d12971a
lint fix
Augustyniak Sep 13, 2022
345e8ed
lint fix
Augustyniak Sep 13, 2022
93a1d09
lint fix
Augustyniak Sep 13, 2022
1f5fed0
remove dependency
Augustyniak Sep 13, 2022
2c1a800
fix lint issue
Augustyniak Sep 13, 2022
3bcee74
fix compilation and add docs
Augustyniak Sep 13, 2022
8cc194a
lint fix
Augustyniak Sep 13, 2022
92dbdbc
trying setup android
Augustyniak Sep 13, 2022
592efd6
diff version
Augustyniak Sep 13, 2022
bdf68cc
Add == checks and tests
Augustyniak Sep 13, 2022
1d462c9
Fix cronet engine
Augustyniak Sep 13, 2022
8b707f7
lint fix
Augustyniak Sep 13, 2022
6d71a6f
try using mac_ci_setup
Augustyniak Sep 14, 2022
79fa59b
install brew
Augustyniak Sep 14, 2022
380eebf
another approach at bash
Augustyniak Sep 14, 2022
cd2d1e7
one more
Augustyniak Sep 14, 2022
f1b8d9f
one more
Augustyniak Sep 14, 2022
23b218b
one one more
Augustyniak Sep 14, 2022
5413154
add to PATH
Augustyniak Sep 14, 2022
fd5b758
one one more
Augustyniak Sep 14, 2022
f20be8a
one one more
Augustyniak Sep 14, 2022
aae1262
“:hammer:”
Augustyniak Sep 14, 2022
d2a1050
hardcode 7.0
Augustyniak Sep 14, 2022
ff0ea6e
one one one more
Augustyniak Sep 14, 2022
186d29f
one oine one one more
Augustyniak Sep 14, 2022
5ae43c9
bump sdk version
Augustyniak Sep 14, 2022
485275c
fix version
Augustyniak Sep 14, 2022
a7a7e1d
use ipv4 instead
Augustyniak Sep 14, 2022
cda97dd
try to fix crashes
Augustyniak Sep 14, 2022
b7dd496
add exec properties
Augustyniak Sep 14, 2022
7a34cd1
try cares
Augustyniak Sep 14, 2022
20ef8cb
revert dns change
Augustyniak Sep 14, 2022
7c486e3
trying
Augustyniak Sep 14, 2022
6c4c4e7
add sandbox to other bazel kotlin
Augustyniak Sep 14, 2022
cfd3808
fix
Augustyniak Sep 15, 2022
d680ac7
split into 2 separate files
Augustyniak Sep 15, 2022
1f520e0
lint fix
Augustyniak Sep 15, 2022
d695226
setting dockernetwork to standard
Augustyniak Sep 15, 2022
78d67ba
remove termination
Augustyniak Sep 15, 2022
3208bdc
renames
Augustyniak Sep 15, 2022
f3d27d2
ci fixes
Augustyniak Sep 15, 2022
50003c2
script improvements
Augustyniak Sep 15, 2022
cd5d710
script fix
Augustyniak Sep 15, 2022
5cf47e9
re-add terminate
Augustyniak Sep 15, 2022
0f249eb
script clean up
Augustyniak Sep 15, 2022
7bc258a
clean up script
Augustyniak Sep 15, 2022
4c38f2b
create directory
Augustyniak Sep 15, 2022
3a45064
lint fixes
Augustyniak Sep 15, 2022
a66c914
fix
Augustyniak Sep 15, 2022
ddf039f
fix
Augustyniak Sep 15, 2022
d87080e
fix
Augustyniak Sep 15, 2022
e6c8f8b
debug print
Augustyniak Sep 15, 2022
c96dc47
set NDK path
Augustyniak Sep 15, 2022
2b63cab
trying to fix
Augustyniak Sep 15, 2022
968643c
fix
Augustyniak Sep 15, 2022
a3f9c44
fix
Augustyniak Sep 15, 2022
ad6927a
move export down
Augustyniak Sep 15, 2022
d62d4e3
add one more to PATH
Augustyniak Sep 15, 2022
9263f01
re-add setup android action
Augustyniak Sep 15, 2022
de47e28
remove argument
Augustyniak Sep 15, 2022
1fd2524
revert
Augustyniak Sep 15, 2022
c047d6d
back
Augustyniak Sep 15, 2022
3402d21
fix
Augustyniak Sep 15, 2022
f99721a
add where needed
Augustyniak Sep 15, 2022
78f1fb7
add PATH log
Augustyniak Sep 15, 2022
cefb51d
rev rev
Augustyniak Sep 15, 2022
3717601
fix
Augustyniak Sep 15, 2022
f022091
readd
Augustyniak Sep 15, 2022
1cc477f
fix
Augustyniak Sep 15, 2022
a1e8f77
lint fix, test imp
Augustyniak Sep 15, 2022
442a735
fix
Augustyniak Sep 15, 2022
7ece60d
fix
Augustyniak Sep 15, 2022
8b97c46
fix
Augustyniak Sep 15, 2022
620f194
fix
Augustyniak Sep 15, 2022
d585e43
fix
Augustyniak Sep 15, 2022
260d125
fix
Augustyniak Sep 15, 2022
6c6f287
Merge branch 'main' into add-proxy-monitor
Augustyniak Sep 15, 2022
04fd11d
wrap base_h3 socket with http_11
Augustyniak Sep 15, 2022
4b744b7
disable global stats in proxy engine
Augustyniak Sep 15, 2022
94bcc4a
set up android ndk home
Augustyniak Sep 15, 2022
871a187
do not run gh action
Augustyniak Sep 15, 2022
00995fa
create directory
Augustyniak Sep 15, 2022
20778bb
revert script
Augustyniak Sep 15, 2022
3a9d60a
remove symlink
Augustyniak Sep 16, 2022
2852ca7
simplify exports
Augustyniak Sep 16, 2022
c496341
create dir and remove setup action
Augustyniak Sep 16, 2022
15c6b9a
change order
Augustyniak Sep 16, 2022
0fcf629
cleanup
Augustyniak Sep 16, 2022
50d4abf
home dir
Augustyniak Sep 16, 2022
84a7e1e
one more
Augustyniak Sep 16, 2022
f80fa98
revert path changes
Augustyniak Sep 16, 2022
7063188
Merge branch 'main' into add-proxy-monitor
Augustyniak Sep 16, 2022
38f58e5
improve logging of proxy changes
Augustyniak Sep 16, 2022
37c623f
improve log message
Augustyniak Sep 16, 2022
dec1d46
fix typo
Augustyniak Sep 16, 2022
60836ef
move properties
Augustyniak Sep 16, 2022
fe96dec
fix comparison
Augustyniak Sep 16, 2022
0acc98d
fix comparison one more time
Augustyniak Sep 16, 2022
d9f9766
simplify tests
Augustyniak Sep 16, 2022
6d4d6a2
Add docs
Augustyniak Sep 16, 2022
cadb81d
lint fix
Augustyniak Sep 16, 2022
cbd075b
fix typo
Augustyniak Sep 16, 2022
e166981
fix potential crash
Augustyniak Sep 16, 2022
351677d
rename enableProxySupport to enableProxying
Augustyniak Sep 18, 2022
843bdcf
change log level to info
Augustyniak Sep 18, 2022
4371e53
add more tests
Augustyniak Sep 18, 2022
7142d75
revert
Augustyniak Sep 19, 2022
63cdfa9
rename
Augustyniak Sep 19, 2022
6fa0935
improve the interface for passing proxy settings
Augustyniak Sep 19, 2022
ca590ee
reverting QUIC socket change
Augustyniak Sep 19, 2022
4399f59
register config
Augustyniak Sep 19, 2022
ea40993
fix lint
Augustyniak Sep 19, 2022
be64219
fix method name
Augustyniak Sep 19, 2022
263e618
fix method name v2
Augustyniak Sep 19, 2022
c59c002
fix method name v3
Augustyniak Sep 19, 2022
6038948
Merge branch 'main' into add-proxy-monitor
Augustyniak Sep 19, 2022
02b7e1a
lint fix
Augustyniak Sep 19, 2022
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
12 changes: 12 additions & 0 deletions docs/root/api/starting_envoy.rst
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,18 @@ to use IPv6. Note this is an experimental option and should be enabled with caut
builder.forceIPv6(true)


~~~~~~~~~~~~~~~~~~~~~~~~~~
``enableProxying``
~~~~~~~~~~~~~~~~~~~~~~~~~~
Specify whether to respect system Proxy settings when establishing connections.
alyssawilk marked this conversation as resolved.
Show resolved Hide resolved
Available on Andorid only.

**Example**::

// Kotlin
builder.enableProxying(true)


----------------------
Advanced configuration
----------------------
Expand Down
2 changes: 1 addition & 1 deletion docs/root/intro/version_history.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Bugfixes:

Features:

-
- kotlin: add a way to tell Envoy Mobile to respect system proxy settings by calling an ``enableProxying(true)`` method on the engine builder. (:issue:`#2416 <2416>`)


0.5.0 (September 2, 2022)
Expand Down
1 change: 1 addition & 0 deletions envoy_build_config/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ envoy_cc_library(
"@envoy//source/extensions/stat_sinks/statsd:config",
"@envoy//source/extensions/transport_sockets/raw_buffer:config",
"@envoy//source/extensions/transport_sockets/tls:config",
"@envoy//source/extensions/transport_sockets/http_11_proxy:upstream_config",
"@envoy//source/extensions/transport_sockets/tls/cert_validator:cert_validator_lib",
"@envoy//source/extensions/upstreams/http/generic:config",
"@envoy_mobile//library/common/extensions/filters/http/assertion:config",
Expand Down
2 changes: 2 additions & 0 deletions envoy_build_config/extension_registry.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "source/extensions/transport_sockets/raw_buffer/config.h"
#include "source/extensions/transport_sockets/tls/cert_validator/default_validator.h"
#include "source/extensions/transport_sockets/tls/config.h"
#include "source/extensions/transport_sockets/http_11_proxy/config.h"
#include "source/extensions/upstreams/http/generic/config.h"

#include "extension_registry_platform_additions.h"
Expand Down Expand Up @@ -58,6 +59,7 @@ void ExtensionRegistry::registerFactories() {
Envoy::Extensions::StatSinks::MetricsService::forceRegisterMetricsServiceSinkFactory();
Envoy::Extensions::TransportSockets::RawBuffer::forceRegisterUpstreamRawBufferSocketFactory();
Envoy::Extensions::TransportSockets::Tls::forceRegisterUpstreamSslSocketFactory();
Envoy::Extensions::TransportSockets::Http11Connect::forceUpstreamHttp11ConnectSocketConfigFactory();
Envoy::Extensions::TransportSockets::Tls::forceRegisterDefaultCertValidatorFactory();
Envoy::Extensions::Upstreams::Http::Generic::forceRegisterGenericGenericConnPoolFactory();
Envoy::Upstream::forceRegisterLogicalDnsClusterFactory();
Expand Down
1 change: 1 addition & 0 deletions envoy_build_config/extensions_build_config.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ EXTENSIONS = {
"envoy.network.dns_resolver.getaddrinfo": "//source/extensions/network/dns_resolver/getaddrinfo:config",
"envoy.retry.options.network_configuration": "@envoy_mobile//library/common/extensions/retry/options/network_configuration:config",
"envoy.stat_sinks.metrics_service": "//source/extensions/stat_sinks/metrics_service:config",
"envoy.transport_sockets.http_11_proxy": "//source/extensions/transport_sockets/http_11_proxy:upstream_config",
"envoy.transport_sockets.raw_buffer": "//source/extensions/transport_sockets/raw_buffer:config",
"envoy.transport_sockets.tls": "//source/extensions/transport_sockets/tls:config",
"envoy.http.stateful_header_formatters.preserve_case": "//source/extensions/http/header_formatters/preserve_case:config",
Expand Down
1 change: 1 addition & 0 deletions examples/kotlin/hello_world/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class MainActivity : Activity() {

engine = AndroidEngineBuilder(application)
.addLogLevel(LogLevel.DEBUG)
.enableProxying(true)
.addPlatformFilter(::DemoFilter)
.addPlatformFilter(::BufferDemoFilter)
.addPlatformFilter(::AsyncDemoFilter)
Expand Down
52 changes: 32 additions & 20 deletions library/common/config/config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -153,15 +153,19 @@ R"(

!ignore tls_socket_defs:
- &base_tls_socket
name: envoy.transport_sockets.tls
name: envoy.transport_sockets.http_11_proxy
typed_config:
"@type": type.googleapis.com/envoy.extensions.transport_sockets.tls.v3.UpstreamTlsContext
common_tls_context:
tls_params:
tls_maximum_protocol_version: TLSv1_3
validation_context:
trusted_ca:
inline_string: *tls_root_certs
"@type": type.googleapis.com/envoy.extensions.transport_sockets.http_11_proxy.v3.Http11ProxyUpstreamTransport
transport_socket:
name: envoy.transport_sockets.tls
typed_config:
"@type": type.googleapis.com/envoy.extensions.transport_sockets.tls.v3.UpstreamTlsContext
common_tls_context:
tls_params:
tls_maximum_protocol_version: TLSv1_3
validation_context:
trusted_ca:
inline_string: *tls_root_certs
)";

const char* config_template = R"(
Expand Down Expand Up @@ -406,9 +410,13 @@ const char* config_template = R"(
lb_policy: CLUSTER_PROVIDED
cluster_type: *base_cluster_type
transport_socket:
name: envoy.transport_sockets.raw_buffer
name: envoy.transport_sockets.http_11_proxy
typed_config:
"@type": type.googleapis.com/envoy.extensions.transport_sockets.raw_buffer.v3.RawBuffer
"@type": type.googleapis.com/envoy.extensions.transport_sockets.http_11_proxy.v3.Http11ProxyUpstreamTransport
transport_socket:
name: envoy.transport_sockets.raw_buffer
typed_config:
"@type": type.googleapis.com/envoy.extensions.transport_sockets.raw_buffer.v3.RawBuffer
upstream_connection_options: *upstream_opts
circuit_breakers: *circuit_breakers_settings
typed_extension_protocol_options: *h1_protocol_options
Expand All @@ -422,17 +430,21 @@ const char* config_template = R"(
lb_policy: CLUSTER_PROVIDED
cluster_type: *base_cluster_type
transport_socket:
name: envoy.transport_sockets.tls
name: envoy.transport_sockets.http_11_proxy
typed_config:
"@type": type.googleapis.com/envoy.extensions.transport_sockets.tls.v3.UpstreamTlsContext
common_tls_context:
alpn_protocols: [h2]
tls_params:
tls_maximum_protocol_version: TLSv1_3
validation_context:
trusted_ca:
inline_string: *tls_root_certs
trust_chain_verification: *trust_chain_verification
"@type": type.googleapis.com/envoy.extensions.transport_sockets.http_11_proxy.v3.Http11ProxyUpstreamTransport
transport_socket:
name: envoy.transport_sockets.tls
typed_config:
"@type": type.googleapis.com/envoy.extensions.transport_sockets.tls.v3.UpstreamTlsContext
common_tls_context:
alpn_protocols: [h2]
tls_params:
tls_maximum_protocol_version: TLSv1_3
validation_context:
trusted_ca:
inline_string: *tls_root_certs
trust_chain_verification: *trust_chain_verification
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when I try to add http_11_proxy socket wrapper to base_h3 cluster's socket:

[2022-09-13 15:22:01.739][2555087][critical][main] [external/envoy/source/server/server.cc:117] error initializing configuration '': HTTP3 requires a QuicUpstreamTransport transport socket: base_h3

cc @alyssawilk

upstream_connection_options: *upstream_opts
circuit_breakers: *circuit_breakers_settings
typed_extension_protocol_options: *h2_protocol_options
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ envoy_cc_extension(
"@envoy//source/common/http:header_map_lib",
"@envoy//source/common/http:headers_lib",
"@envoy//source/common/http:utility_lib",
"@envoy//source/common/network:filter_state_proxy_info_lib",
"@envoy//source/extensions/filters/http/common:pass_through_filter_lib",
],
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@

#include "envoy/server/filter_config.h"

#include "source/common/network/filter_state_proxy_info.h"

namespace Envoy {
namespace Extensions {
namespace HttpFilters {
namespace NetworkConfiguration {

const Http::LowerCaseString AuthorityHeaderName{":authority"};

void NetworkConfigurationFilter::setDecoderFilterCallbacks(
Http::StreamDecoderFilterCallbacks& callbacks) {
ENVOY_LOG(debug, "NetworkConfigurationFilter::setDecoderFilterCallbacks");
Expand All @@ -26,6 +30,36 @@ void NetworkConfigurationFilter::setDecoderFilterCallbacks(
decoder_callbacks_->addUpstreamSocketOptions(options);
}

Http::FilterHeadersStatus
NetworkConfigurationFilter::decodeHeaders(Http::RequestHeaderMap& request_headers, bool) {
const auto proxy_settings = connectivity_manager_->getProxySettings();

ENVOY_LOG(trace, "NetworkConfigurationFilter::decodeHeaders", request_headers);
if (proxy_settings == nullptr) {
return Http::FilterHeadersStatus::Continue;
}

const auto proxy_address = proxy_settings->address();

if (proxy_address != nullptr) {
const auto authorityHeader = request_headers.get(AuthorityHeaderName);
if (authorityHeader.empty()) {
return Http::FilterHeadersStatus::Continue;
}

const auto authority = authorityHeader[0]->value().getStringView();

ENVOY_LOG(trace, "netconf_filter_set_proxy_for_request", proxy_settings->asString());
decoder_callbacks_->streamInfo().filterState()->setData(
Network::Http11ProxyInfoFilterState::key(),
std::make_unique<Network::Http11ProxyInfoFilterState>(authority, proxy_address),
StreamInfo::FilterState::StateType::ReadOnly,
StreamInfo::FilterState::LifeSpan::FilterChain);
}

return Http::FilterHeadersStatus::Continue;
}

Http::FilterHeadersStatus NetworkConfigurationFilter::encodeHeaders(Http::ResponseHeaderMap&,
bool) {
ENVOY_LOG(debug, "NetworkConfigurationFilter::encodeHeaders");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class NetworkConfigurationFilter final : public Http::PassThroughFilter,

// Http::StreamDecoderFilter
void setDecoderFilterCallbacks(Http::StreamDecoderFilterCallbacks& callbacks) override;
Http::FilterHeadersStatus decodeHeaders(Http::RequestHeaderMap& request_headers, bool) override;
// Http::StreamEncoderFilter
Http::FilterHeadersStatus encodeHeaders(Http::ResponseHeaderMap&, bool) override;
// Http::StreamFilterBase
Expand Down
16 changes: 16 additions & 0 deletions library/common/jni/jni_interface.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1132,6 +1132,22 @@ Java_io_envoyproxy_envoymobile_engine_JniLibrary_setPreferredNetwork(JNIEnv* env
static_cast<envoy_network_t>(network));
}

extern "C" JNIEXPORT jint JNICALL Java_io_envoyproxy_envoymobile_engine_JniLibrary_setProxySettings(
JNIEnv* env,
jclass, // class
jlong engine, jstring host, jint port) {
jni_log("[Envoy]", "setProxySettings");

const char* native_host = env->GetStringUTFChars(host, nullptr);
const uint16_t native_port = static_cast<uint16_t>(port);

envoy_status_t result =
set_proxy_settings(static_cast<envoy_engine_t>(engine), native_host, native_port);

env->ReleaseStringUTFChars(host, native_host);
return result;
}

bool jvm_cert_is_issued_by_known_root(JNIEnv* env, jobject result) {
jclass jcls_AndroidCertVerifyResult = env->FindClass("org/chromium/net/AndroidCertVerifyResult");
jmethodID jmid_isIssuedByKnownRoot =
Expand Down
7 changes: 7 additions & 0 deletions library/common/main_interface.cc
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ envoy_status_t set_preferred_network(envoy_engine_t engine, envoy_network_t netw
return ENVOY_SUCCESS;
}

envoy_status_t set_proxy_settings(envoy_engine_t e, const char* host, const uint16_t port) {
return Envoy::EngineHandle::runOnEngineDispatcher(
e,
[proxy_settings = Envoy::Network::ProxySettings::parseHostAndPort(host, port)](auto& engine)
-> void { engine.networkConnectivityManager().setProxySettings(proxy_settings); });
}

envoy_status_t record_counter_inc(envoy_engine_t e, const char* elements, envoy_stats_tags tags,
uint64_t count) {
return Envoy::EngineHandle::runOnEngineDispatcher(
Expand Down
10 changes: 10 additions & 0 deletions library/common/main_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,16 @@ envoy_status_t reset_stream(envoy_engine_t engine, envoy_stream_t stream);
*/
envoy_status_t set_preferred_network(envoy_engine_t engine, envoy_network_t network);

/**
* @brief Update the currently active proxy settings.
*
* @param engine, the engine whose proxy settings should be updated.
* @param host, the proxy host.
* @param port, the proxy port.
* @return envoy_status_t, the resulting status of the operation.
*/
envoy_status_t set_proxy_settings(envoy_engine_t engine, const char* host, const uint16_t port);

/**
* Increment a counter with the given elements and by the given count.
* @param engine, the engine that owns the counter.
Expand Down
1 change: 1 addition & 0 deletions library/common/network/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ envoy_cc_library(
hdrs = [
"android.h",
"connectivity_manager.h",
"proxy_settings.h",
],
copts = select({
"//bazel:include_ifaddrs": ["-DINCLUDE_IFADDRS"],
Expand Down
18 changes: 18 additions & 0 deletions library/common/network/connectivity_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,24 @@ envoy_netconf_t ConnectivityManager::setPreferredNetwork(envoy_network_t network
return network_state_.configuration_key_;
}

void ConnectivityManager::setProxySettings(ProxySettingsConstSharedPtr new_proxy_settings) {
if (proxy_settings_ == nullptr && new_proxy_settings != nullptr) {
ENVOY_LOG_EVENT(info, "netconf_proxy_change", new_proxy_settings->asString());
proxy_settings_ = new_proxy_settings;
} else if (proxy_settings_ != nullptr && new_proxy_settings == nullptr) {
ENVOY_LOG_EVENT(info, "netconf_proxy_change", "no_proxy_configured");
proxy_settings_ = new_proxy_settings;
} else if (proxy_settings_ != nullptr && new_proxy_settings != nullptr &&
*proxy_settings_ != *new_proxy_settings) {
ENVOY_LOG_EVENT(info, "netconf_proxy_change", new_proxy_settings->asString());
proxy_settings_ = new_proxy_settings;
}

return;
}

ProxySettingsConstSharedPtr ConnectivityManager::getProxySettings() { return proxy_settings_; }

envoy_network_t ConnectivityManager::getPreferredNetwork() {
Thread::LockGuard lock{network_state_.mutex_};
return network_state_.network_;
Expand Down
15 changes: 15 additions & 0 deletions library/common/network/connectivity_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "source/extensions/common/dynamic_forward_proxy/dns_cache.h"
#include "source/extensions/common/dynamic_forward_proxy/dns_cache_impl.h"

#include "library/common/network/proxy_settings.h"
#include "library/common/types/c_types.h"

/**
Expand Down Expand Up @@ -128,6 +129,12 @@ class ConnectivityManager
*/
envoy_netconf_t getConfigurationKey();

/**
*
* @return the current proxy settings.
*/
Envoy::Network::ProxySettingsConstSharedPtr getProxySettings();

/**
* Call to report on the current viability of the passed network configuration after an attempt
* at transmission (e.g., an HTTP request).
Expand All @@ -143,6 +150,13 @@ class ConnectivityManager
*/
static envoy_netconf_t setPreferredNetwork(envoy_network_t network);

/**
* @brief Sets the current proxy settings.
*
* @param host The proxy settings. `nullptr` if there is no proxy configured on a device.
*/
void setProxySettings(ProxySettingsConstSharedPtr proxy_settings);

/**
* Configure whether connections should be drained after a triggered DNS refresh. Currently this
* may happen either due to an external call to refreshConnectivityState or an update to
Expand Down Expand Up @@ -211,6 +225,7 @@ class ConnectivityManager
dns_callbacks_handle_{nullptr};
Upstream::ClusterManager& cluster_manager_;
DnsCacheManagerSharedPtr dns_cache_manager_;
ProxySettingsConstSharedPtr proxy_settings_;
static NetworkState network_state_;
};

Expand Down
Loading