1
#pragma once
2

            
3
#include "envoy/config/typed_config.h"
4
#include "envoy/network/address.h"
5
#include "envoy/protobuf/message_validator.h"
6
#include "envoy/server/factory_context.h"
7

            
8
#include "quiche/quic/platform/api/quic_socket_address.h"
9

            
10
namespace Envoy {
11
namespace Quic {
12

            
13
// An interface to provide the server's preferred addresses at runtime.
14
class EnvoyQuicServerPreferredAddressConfig {
15
public:
16
19
  virtual ~EnvoyQuicServerPreferredAddressConfig() = default;
17

            
18
  // The set of addresses used to configure the server preferred addresses.
19
  struct Addresses {
20
    // Addresses that client is requested to use.
21
    quic::QuicSocketAddress ipv4_;
22
    quic::QuicSocketAddress ipv6_;
23

            
24
    // If destination NAT is applied between the client and Envoy, the addresses that
25
    // Envoy will see for client traffic to the server preferred address. If this is not
26
    // set, Envoy will expect to receive server preferred address traffic on the above addresses.
27
    //
28
    // A DNAT address will be ignored if the corresponding SPA address is not set.
29
    quic::QuicSocketAddress dnat_ipv4_;
30
    quic::QuicSocketAddress dnat_ipv6_;
31
  };
32

            
33
  /**
34
   * Called during config loading.
35
   * @param local_address the configured default listening address.
36
   * Returns a pair of the server preferred addresses in form of {IPv4, IPv6} which will be used for
37
   * the entire life time of the QUIC listener. An uninitialized address value means no preferred
38
   * address for that address family.
39
   */
40
  virtual Addresses
41
  getServerPreferredAddresses(const Network::Address::InstanceConstSharedPtr& local_address) PURE;
42
};
43

            
44
using EnvoyQuicServerPreferredAddressConfigPtr =
45
    std::unique_ptr<EnvoyQuicServerPreferredAddressConfig>;
46

            
47
class EnvoyQuicServerPreferredAddressConfigFactory : public Config::TypedFactory {
48
public:
49
27
  std::string category() const override { return "envoy.quic.server_preferred_address"; }
50

            
51
  /**
52
   * Returns an EnvoyQuicServerPreferredAddressConfig object according to the given server preferred
53
   * address config.
54
   */
55
  virtual EnvoyQuicServerPreferredAddressConfigPtr
56
  createServerPreferredAddressConfig(const Protobuf::Message& config,
57
                                     ProtobufMessage::ValidationVisitor& validation_visitor,
58
                                     Server::Configuration::ServerFactoryContext& context) PURE;
59
};
60

            
61
} // namespace Quic
62
} // namespace Envoy