Skip to content

Commit

Permalink
mobile: Adds an EngineBuilder API to configure UDP GRO (envoyproxy#34013
Browse files Browse the repository at this point in the history
)

Signed-off-by: Ali Beyad <[email protected]>
  • Loading branch information
abeyad authored May 7, 2024
1 parent d809b86 commit 8937b3d
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 8 deletions.
7 changes: 7 additions & 0 deletions mobile/library/cc/engine_builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,11 @@ EngineBuilder& EngineBuilder::enableInterfaceBinding(bool interface_binding_on)
return *this;
}

EngineBuilder& EngineBuilder::setUseGroIfAvailable(bool use_gro_if_available) {
use_gro_if_available_ = use_gro_if_available;
return *this;
}

EngineBuilder& EngineBuilder::enableDrainPostDnsRefresh(bool drain_post_dns_refresh_on) {
enable_drain_post_dns_refresh_ = drain_post_dns_refresh_on;
return *this;
Expand Down Expand Up @@ -882,6 +887,8 @@ std::unique_ptr<envoy::config::bootstrap::v3::Bootstrap> EngineBuilder::generate
guard_and_value.second);
}
(*reloadable_features.mutable_fields())["always_use_v6"].set_bool_value(always_use_v6_);
(*reloadable_features.mutable_fields())["prefer_quic_client_udp_gro"].set_bool_value(
use_gro_if_available_);
ProtobufWkt::Struct& restart_features =
*(*runtime_values.mutable_fields())["restart_features"].mutable_struct_value();
// TODO(abeyad): This runtime flag is set because https://github.com/envoyproxy/envoy/pull/32370
Expand Down
3 changes: 3 additions & 0 deletions mobile/library/cc/engine_builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ class EngineBuilder {
#endif
EngineBuilder& enableInterfaceBinding(bool interface_binding_on);
EngineBuilder& enableDrainPostDnsRefresh(bool drain_post_dns_refresh_on);
// Sets whether to use GRO for upstream UDP sockets (QUIC/HTTP3).
EngineBuilder& setUseGroIfAvailable(bool use_gro_if_available);
EngineBuilder& enforceTrustChainVerification(bool trust_chain_verification_on);
EngineBuilder& setUpstreamTlsSni(std::string sni);
EngineBuilder& enablePlatformCertificatesValidation(bool platform_certificates_validation_on);
Expand Down Expand Up @@ -279,6 +281,7 @@ class EngineBuilder {

std::vector<std::pair<std::string, bool>> runtime_guards_;
absl::flat_hash_map<std::string, StringAccessorSharedPtr> string_accessors_;
bool use_gro_if_available_ = false;

#ifdef ENVOY_MOBILE_XDS
absl::optional<XdsBuilder> xds_builder_ = absl::nullopt;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public enum TrustChainVerification {
public final Boolean enableDrainPostDnsRefresh;
public final Boolean enableHttp3;
public final Boolean useCares;
public final Boolean useGro;
public final String http3ConnectionOptions;
public final String http3ClientConnectionOptions;
public final Map<String, String> quicHints;
Expand Down Expand Up @@ -103,6 +104,8 @@ public enum TrustChainVerification {
* @param enableHttp3 whether to enable experimental support for
* HTTP/3 (QUIC).
* @param useCares whether to use the c_ares library for DNS
* @param useGro whether to use UDP GRO on upstream QUIC
* connections, if available.
* @param http3ConnectionOptions connection options to be used in HTTP/3.
* @param http3ClientConnectionOptions client connection options to be used in
* HTTP/3.
Expand Down Expand Up @@ -160,7 +163,7 @@ public EnvoyConfiguration(
int connectTimeoutSeconds, int dnsRefreshSeconds, int dnsFailureRefreshSecondsBase,
int dnsFailureRefreshSecondsMax, int dnsQueryTimeoutSeconds, int dnsMinRefreshSeconds,
List<String> dnsPreresolveHostnames, boolean enableDNSCache, int dnsCacheSaveIntervalSeconds,
boolean enableDrainPostDnsRefresh, boolean enableHttp3, boolean useCares,
boolean enableDrainPostDnsRefresh, boolean enableHttp3, boolean useCares, boolean useGro,
String http3ConnectionOptions, String http3ClientConnectionOptions,
Map<String, Integer> quicHints, List<String> quicCanonicalSuffixes,
boolean enableGzipDecompression, boolean enableBrotliDecompression,
Expand Down Expand Up @@ -190,6 +193,7 @@ public EnvoyConfiguration(
this.enableDrainPostDnsRefresh = enableDrainPostDnsRefresh;
this.enableHttp3 = enableHttp3;
this.useCares = useCares;
this.useGro = useGro;
this.http3ConnectionOptions = http3ConnectionOptions;
this.http3ClientConnectionOptions = http3ClientConnectionOptions;
this.quicHints = new HashMap<>();
Expand Down Expand Up @@ -264,8 +268,8 @@ public long createBootstrap() {
connectTimeoutSeconds, dnsRefreshSeconds, dnsFailureRefreshSecondsBase,
dnsFailureRefreshSecondsMax, dnsQueryTimeoutSeconds, dnsMinRefreshSeconds, dnsPreresolve,
enableDNSCache, dnsCacheSaveIntervalSeconds, enableDrainPostDnsRefresh, enableHttp3,
useCares, http3ConnectionOptions, http3ClientConnectionOptions, quicHints, quicSuffixes,
enableGzipDecompression, enableBrotliDecompression, enablePortMigration,
useCares, useGro, http3ConnectionOptions, http3ClientConnectionOptions, quicHints,
quicSuffixes, enableGzipDecompression, enableBrotliDecompression, enablePortMigration,
enableSocketTagging, enableInterfaceBinding, h2ConnectionKeepaliveIdleIntervalMilliseconds,
h2ConnectionKeepaliveTimeoutSeconds, maxConnectionsPerHost, streamIdleTimeoutSeconds,
perTryIdleTimeoutSeconds, appVersion, appId, enforceTrustChainVerification, filterChain,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ public static native long createBootstrap(
long connectTimeoutSeconds, long dnsRefreshSeconds, long dnsFailureRefreshSecondsBase,
long dnsFailureRefreshSecondsMax, long dnsQueryTimeoutSeconds, long dnsMinRefreshSeconds,
byte[][] dnsPreresolveHostnames, boolean enableDNSCache, long dnsCacheSaveIntervalSeconds,
boolean enableDrainPostDnsRefresh, boolean enableHttp3, boolean useCares,
boolean enableDrainPostDnsRefresh, boolean enableHttp3, boolean useCares, boolean useGro,
String http3ConnectionOptions, String http3ClientConnectionOptions, byte[][] quicHints,
byte[][] quicCanonicalSuffixes, boolean enableGzipDecompression,
boolean enableBrotliDecompression, boolean enablePortMigration, boolean enableSocketTagging,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public class NativeCronvoyEngineBuilderImpl extends CronvoyEngineBuilderImpl {
private final List<String> mDnsFallbackNameservers = Collections.emptyList();
private final boolean mEnableDnsFilterUnroutableFamilies = true;
private boolean mUseCares = false;
private boolean mUseGro = false;
private boolean mEnableDrainPostDnsRefresh = false;
private final boolean mEnableGzipDecompression = true;
private final boolean mEnableSocketTag = true;
Expand Down Expand Up @@ -94,6 +95,18 @@ public NativeCronvoyEngineBuilderImpl setUseCares(boolean enable) {
mUseCares = enable;
return this;
}

/**
* Specify whether to use UDP GRO for upstream QUIC/HTTP3 sockets, if GRO is available on the
* system.
*
* @param enable If true, use UDP GRO.
*/
public NativeCronvoyEngineBuilderImpl setUseGro(boolean enable) {
mUseGro = enable;
return this;
}

/**
* Set the DNS query timeout, in seconds, which ensures that DNS queries succeed or fail
* within that time range. See the DnsCacheConfig.dns_query_timeout proto field for details.
Expand Down Expand Up @@ -211,7 +224,7 @@ private EnvoyConfiguration createEnvoyConfiguration() {
mConnectTimeoutSeconds, mDnsRefreshSeconds, mDnsFailureRefreshSecondsBase,
mDnsFailureRefreshSecondsMax, mDnsQueryTimeoutSeconds, mDnsMinRefreshSeconds,
mDnsPreresolveHostnames, mEnableDNSCache, mDnsCacheSaveIntervalSeconds,
mEnableDrainPostDnsRefresh, quicEnabled(), mUseCares, quicConnectionOptions(),
mEnableDrainPostDnsRefresh, quicEnabled(), mUseCares, mUseGro, quicConnectionOptions(),
quicClientConnectionOptions(), quicHints(), quicCanonicalSuffixes(),
mEnableGzipDecompression, brotliEnabled(), portMigrationEnabled(), mEnableSocketTag,
mEnableInterfaceBinding, mH2ConnectionKeepaliveIdleIntervalMilliseconds,
Expand Down
7 changes: 4 additions & 3 deletions mobile/library/jni/jni_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1092,7 +1092,7 @@ void configureBuilder(Envoy::JNI::JniHelper& jni_helper, jlong connect_timeout_s
jlong dns_min_refresh_seconds, jobjectArray dns_preresolve_hostnames,
jboolean enable_dns_cache, jlong dns_cache_save_interval_seconds,
jboolean enable_drain_post_dns_refresh, jboolean enable_http3,
jboolean use_cares, jstring http3_connection_options,
jboolean use_cares, jboolean use_gro, jstring http3_connection_options,
jstring http3_client_connection_options, jobjectArray quic_hints,
jobjectArray quic_canonical_suffixes, jboolean enable_gzip_decompression,
jboolean enable_brotli_decompression, jboolean enable_port_migration,
Expand Down Expand Up @@ -1146,6 +1146,7 @@ void configureBuilder(Envoy::JNI::JniHelper& jni_helper, jlong connect_timeout_s

#endif
builder.setUseCares(use_cares == JNI_TRUE);
builder.setUseGroIfAvailable(use_gro == JNI_TRUE);
builder.enableInterfaceBinding(enable_interface_binding == JNI_TRUE);
builder.enableDrainPostDnsRefresh(enable_drain_post_dns_refresh == JNI_TRUE);
builder.enforceTrustChainVerification(trust_chain_verification == JNI_TRUE);
Expand Down Expand Up @@ -1202,7 +1203,7 @@ extern "C" JNIEXPORT jlong JNICALL Java_io_envoyproxy_envoymobile_engine_JniLibr
jlong dns_query_timeout_seconds, jlong dns_min_refresh_seconds,
jobjectArray dns_preresolve_hostnames, jboolean enable_dns_cache,
jlong dns_cache_save_interval_seconds, jboolean enable_drain_post_dns_refresh,
jboolean enable_http3, jboolean use_cares, jstring http3_connection_options,
jboolean enable_http3, jboolean use_cares, jboolean use_gro, jstring http3_connection_options,
jstring http3_client_connection_options, jobjectArray quic_hints,
jobjectArray quic_canonical_suffixes, jboolean enable_gzip_decompression,
jboolean enable_brotli_decompression, jboolean enable_port_migration,
Expand All @@ -1224,7 +1225,7 @@ extern "C" JNIEXPORT jlong JNICALL Java_io_envoyproxy_envoymobile_engine_JniLibr
jni_helper, connect_timeout_seconds, dns_refresh_seconds, dns_failure_refresh_seconds_base,
dns_failure_refresh_seconds_max, dns_query_timeout_seconds, dns_min_refresh_seconds,
dns_preresolve_hostnames, enable_dns_cache, dns_cache_save_interval_seconds,
enable_drain_post_dns_refresh, enable_http3, use_cares, http3_connection_options,
enable_drain_post_dns_refresh, enable_http3, use_cares, use_gro, http3_connection_options,
http3_client_connection_options, quic_hints, quic_canonical_suffixes,
enable_gzip_decompression, enable_brotli_decompression, enable_port_migration,
enable_socket_tagging, enable_interface_binding,
Expand Down
14 changes: 14 additions & 0 deletions mobile/library/kotlin/io/envoyproxy/envoymobile/EngineBuilder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ open class EngineBuilder() {
private var enableDrainPostDnsRefresh = false
internal var enableHttp3 = true
internal var useCares = false
private var useGro = false
private var http3ConnectionOptions = ""
private var http3ClientConnectionOptions = ""
private var quicHints = mutableMapOf<String, Int>()
Expand Down Expand Up @@ -313,6 +314,18 @@ open class EngineBuilder() {
return this
}

/**
* Specify whether to use UDP GRO for upstream QUIC/HTTP3 sockets, if GRO is available on the
* system.
*
* @param useGro whether or not to use UDP GRO
* @return This builder.
*/
fun useGro(useGro: Boolean): EngineBuilder {
this.useGro = useGro
return this
}

/**
* Specify whether to do brotli response decompression or not. Defaults to false.
*
Expand Down Expand Up @@ -673,6 +686,7 @@ open class EngineBuilder() {
enableDrainPostDnsRefresh,
enableHttp3,
useCares,
useGro,
http3ConnectionOptions,
http3ClientConnectionOptions,
quicHints,
Expand Down
2 changes: 2 additions & 0 deletions mobile/test/cc/unit/envoy_config_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ TEST(TestConfig, ConfigIsApplied) {
.enableDnsCache(true, /* save_interval_seconds */ 101)
.addDnsPreresolveHostnames({"lyft.com", "google.com"})
.setForceAlwaysUsev6(true)
.setUseGroIfAvailable(true)
.setDeviceOs("probably-ubuntu-on-CI");

std::unique_ptr<Bootstrap> bootstrap = engine_builder.generateBootstrap();
Expand All @@ -112,6 +113,7 @@ TEST(TestConfig, ConfigIsApplied) {
#endif
"key: \"dns_persistent_cache\" save_interval { seconds: 101 }",
"key: \"always_use_v6\" value { bool_value: true }",
"key: \"prefer_quic_client_udp_gro\" value { bool_value: true }",
"key: \"test_feature_false\" value { bool_value: true }",
"key: \"allow_client_socket_creation_failure\" value { bool_value: true }",
"key: \"device_os\" value { string_value: \"probably-ubuntu-on-CI\" } }",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class EnvoyConfigurationTest {
enableDrainPostDnsRefresh: Boolean = false,
enableHttp3: Boolean = true,
enableCares: Boolean = false,
enableGro: Boolean = false,
http3ConnectionOptions: String = "5RTO",
http3ClientConnectionOptions: String = "MPQC",
quicHints: Map<String, Int> = mapOf("www.abc.com" to 443, "www.def.com" to 443),
Expand Down Expand Up @@ -129,6 +130,7 @@ class EnvoyConfigurationTest {
enableDrainPostDnsRefresh,
enableHttp3,
enableCares,
enableGro,
http3ConnectionOptions,
http3ClientConnectionOptions,
quicHints,
Expand Down Expand Up @@ -252,6 +254,7 @@ class EnvoyConfigurationTest {
dnsCacheSaveIntervalSeconds = 101,
enableHttp3 = false,
enableCares = true,
enableGro = true,
enableGzipDecompression = false,
enableBrotliDecompression = true,
enableSocketTagging = true,
Expand All @@ -274,6 +277,9 @@ class EnvoyConfigurationTest {
// enableCares = true
assertThat(resolvedTemplate).contains("envoy.network.dns_resolver.cares")

// enableGro = true
assertThat(resolvedTemplate).contains("key: \"prefer_quic_client_udp_gro\" value { bool_value: true }")

// enableDNSCache = true
assertThat(resolvedTemplate).contains("key: \"dns_persistent_cache\"")
// dnsCacheSaveIntervalSeconds = 101
Expand Down

0 comments on commit 8937b3d

Please sign in to comment.