forked from envoyproxy/envoy
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
quic: Add a DataSource option for server preferred address config
Signed-off-by: Greg Greenway <ggreenway@apple.com>
- Loading branch information
Showing
14 changed files
with
478 additions
and
44 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
api/envoy/extensions/quic/server_preferred_address/v3/datasource.proto
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
syntax = "proto3"; | ||
|
||
package envoy.extensions.quic.server_preferred_address.v3; | ||
|
||
import "envoy/config/core/v3/base.proto"; | ||
|
||
import "xds/annotations/v3/status.proto"; | ||
|
||
import "udpa/annotations/status.proto"; | ||
import "validate/validate.proto"; | ||
|
||
option java_package = "io.envoyproxy.envoy.extensions.quic.server_preferred_address.v3"; | ||
option java_outer_classname = "DataSourceServerPreferredAddressConfig"; | ||
option java_multiple_files = true; | ||
option go_package = "github.com/envoyproxy/go-control-plane/envoy/extensions/quic/server_preferred_address/v3;server_preferred_addressv3"; | ||
option (udpa.annotations.file_status).package_version_status = ACTIVE; | ||
|
||
// [#protodoc-title: QUIC DataSource server preferred address config] | ||
// [#extension: envoy.quic.server_preferred_address.datasource] | ||
|
||
// Configuration for DataSourceServerPreferredAddressConfig. | ||
message DataSourceServerPreferredAddressConfig { | ||
// [#comment:TODO(danzh2010): discuss with API shepherds before removing WiP status.] | ||
|
||
option (xds.annotations.v3.message_status).work_in_progress = true; | ||
|
||
// Addresses for server preferred address for a single address family (IPv4 or IPv6). | ||
message AddressFamilyConfig { | ||
// The server preferred address sent to clients. The data must contain an IP address string. | ||
envoy.config.core.v3.DataSource address = 1 [(validate.rules).message = {required: true}]; | ||
|
||
// The server preferred address port sent to clients. The data must contain a integer port value. | ||
// | ||
// If this is not specified, the listener's port is used. | ||
// | ||
// Note: Envoy currently must receive all packets for a QUIC connection on the same port, so unless | ||
// :ref:`dnat_address <envoy_v3_api_field_extensions.quic.server_preferred_address.v3.DataSourceServerPreferredAddressConfig.AddressFamilyConfig.dnat_address>` | ||
// is configured, this must be left unset. | ||
envoy.config.core.v3.DataSource port = 2; | ||
|
||
// If there is a DNAT between the client and Envoy, the address that Envoy will observe | ||
// server preferred address packets being sent to. If this is not specified, it is assumed | ||
// there is no DNAT and the server preferred address packets will be sent to the address advertised | ||
// to clients for server preferred address. | ||
envoy.config.core.v3.DataSource dnat_address = 3; | ||
} | ||
|
||
// The IPv4 address to advertise to clients for Server Preferred Address. | ||
AddressFamilyConfig ipv4_config = 1; | ||
|
||
// The IPv6 address to advertise to clients for Server Preferred Address. | ||
AddressFamilyConfig ipv6_config = 2; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 110 additions & 0 deletions
110
...ce/extensions/quic/server_preferred_address/datasource_server_preferred_address_config.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
#include "source/extensions/quic/server_preferred_address/datasource_server_preferred_address_config.h" | ||
|
||
#include "envoy/common/exception.h" | ||
|
||
#include "source/common/common/utility.h" | ||
#include "source/common/config/datasource.h" | ||
#include "source/common/network/utility.h" | ||
#include "source/common/quic/envoy_quic_utils.h" | ||
#include "source/extensions/quic/server_preferred_address/server_preferred_address.h" | ||
|
||
namespace Envoy { | ||
namespace Quic { | ||
|
||
namespace { | ||
|
||
quic::QuicIpAddress parseIp(const envoy::config::core::v3::DataSource& source, | ||
quiche::IpAddressFamily address_family, | ||
absl::string_view address_family_str, const Protobuf::Message& message, | ||
Server::Configuration::ServerFactoryContext& context) { | ||
std::string data = | ||
THROW_OR_RETURN_VALUE(Config::DataSource::read(source, false, context.api()), std::string); | ||
|
||
quic::QuicIpAddress ip; | ||
if (!ip.FromString(std::string(StringUtil::trim(data)))) { | ||
ProtoExceptionUtil::throwProtoValidationException( | ||
absl::StrCat("bad ", address_family_str, " server preferred address: ", data), message); | ||
} | ||
|
||
if (ip.address_family() != address_family) { | ||
ProtoExceptionUtil::throwProtoValidationException( | ||
absl::StrCat("wrong address family for ", address_family_str, | ||
" server preferred address: ", data), | ||
message); | ||
} | ||
return ip; | ||
} | ||
|
||
ServerPreferredAddressConfig::FamilyAddresses | ||
parseFamily(const envoy::extensions::quic::server_preferred_address::v3:: | ||
DataSourceServerPreferredAddressConfig::AddressFamilyConfig* addresses, | ||
quiche::IpAddressFamily address_family, absl::string_view address_family_str, | ||
const Protobuf::Message& message, | ||
Server::Configuration::ServerFactoryContext& context) { | ||
ServerPreferredAddressConfig::FamilyAddresses ret; | ||
if (addresses != nullptr) { | ||
const quic::QuicIpAddress spa_addr = | ||
parseIp(addresses->address(), address_family, address_family_str, message, context); | ||
|
||
if (!addresses->has_dnat_address() && addresses->has_port()) { | ||
ProtoExceptionUtil::throwProtoValidationException( | ||
fmt::format("port must be unset unless 'dnat_address' is set " | ||
"for address family {}", | ||
address_family_str), | ||
message); | ||
} | ||
|
||
uint16_t spa_port = 0; | ||
if (addresses->has_port()) { | ||
std::string port_str = THROW_OR_RETURN_VALUE( | ||
Config::DataSource::read(addresses->port(), false, context.api()), std::string); | ||
|
||
// absl::SimpleAtoi doesn't work with uint16_t, so first convert to uint32_t. | ||
uint32_t big_port = 0; | ||
const bool success = absl::SimpleAtoi(port_str, &big_port); | ||
if (!success || big_port > UINT16_MAX) { | ||
ProtoExceptionUtil::throwProtoValidationException( | ||
absl::StrCat("server preferred address ", address_family_str, | ||
" port was not a valid port: ", port_str), | ||
message); | ||
} | ||
|
||
spa_port = big_port; | ||
} | ||
ret.spa_ = quic::QuicSocketAddress(spa_addr, spa_port); | ||
|
||
if (addresses->has_dnat_address()) { | ||
ret.dnat_ = | ||
parseIp(addresses->dnat_address(), address_family, address_family_str, message, context); | ||
} | ||
} | ||
|
||
return ret; | ||
} | ||
|
||
} // namespace | ||
|
||
Quic::EnvoyQuicServerPreferredAddressConfigPtr | ||
DataSourceServerPreferredAddressConfigFactory::createServerPreferredAddressConfig( | ||
const Protobuf::Message& message, ProtobufMessage::ValidationVisitor& validation_visitor, | ||
Server::Configuration::ServerFactoryContext& context) { | ||
auto& config = | ||
MessageUtil::downcastAndValidate<const envoy::extensions::quic::server_preferred_address::v3:: | ||
DataSourceServerPreferredAddressConfig&>( | ||
message, validation_visitor); | ||
|
||
ServerPreferredAddressConfig::FamilyAddresses v4 = | ||
parseFamily(config.has_ipv4_config() ? &config.ipv4_config() : nullptr, | ||
quiche::IpAddressFamily::IP_V4, "v4", message, context); | ||
ServerPreferredAddressConfig::FamilyAddresses v6 = | ||
parseFamily(config.has_ipv6_config() ? &config.ipv6_config() : nullptr, | ||
quiche::IpAddressFamily::IP_V6, "v6", message, context); | ||
|
||
return std::make_unique<ServerPreferredAddressConfig>(v4, v6); | ||
} | ||
|
||
REGISTER_FACTORY(DataSourceServerPreferredAddressConfigFactory, | ||
Quic::EnvoyQuicServerPreferredAddressConfigFactory); | ||
|
||
} // namespace Quic | ||
} // namespace Envoy |
31 changes: 31 additions & 0 deletions
31
source/extensions/quic/server_preferred_address/datasource_server_preferred_address_config.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#pragma once | ||
|
||
#include "envoy/extensions/quic/server_preferred_address/v3/datasource.pb.h" | ||
#include "envoy/extensions/quic/server_preferred_address/v3/datasource.pb.validate.h" | ||
#include "envoy/registry/registry.h" | ||
|
||
#include "source/common/quic/envoy_quic_server_preferred_address_config_factory.h" | ||
|
||
namespace Envoy { | ||
namespace Quic { | ||
|
||
class DataSourceServerPreferredAddressConfigFactory | ||
: public Envoy::Quic::EnvoyQuicServerPreferredAddressConfigFactory { | ||
public: | ||
std::string name() const override { return "quic.server_preferred_address.datasource"; } | ||
|
||
Envoy::Quic::EnvoyQuicServerPreferredAddressConfigPtr | ||
createServerPreferredAddressConfig(const Protobuf::Message& message, | ||
ProtobufMessage::ValidationVisitor& validation_visitor, | ||
Server::Configuration::ServerFactoryContext& context) override; | ||
|
||
ProtobufTypes::MessagePtr createEmptyConfigProto() override { | ||
return ProtobufTypes::MessagePtr{new envoy::extensions::quic::server_preferred_address::v3:: | ||
DataSourceServerPreferredAddressConfig()}; | ||
} | ||
}; | ||
|
||
DECLARE_FACTORY(DataSourceServerPreferredAddressConfigFactory); | ||
|
||
} // namespace Quic | ||
} // namespace Envoy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.