1
#pragma once
2

            
3
#include <string>
4
#include <vector>
5

            
6
#include "envoy/common/exception.h"
7

            
8
#include "source/common/common/assert.h"
9
#include "source/common/common/regex.h"
10
#include "source/common/singleton/const_singleton.h"
11

            
12
namespace Envoy {
13
namespace Config {
14

            
15
bool doesTagNameValueMatchInvalidCharRegex(absl::string_view name);
16

            
17
/**
18
 * Well-known address resolver names.
19
 */
20
class AddressResolverNameValues {
21
public:
22
  // Basic IP resolver
23
  const std::string IP = "envoy.ip";
24
};
25

            
26
using AddressResolverNames = ConstSingleton<AddressResolverNameValues>;
27

            
28
/**
29
 * Well-known metadata filter namespaces.
30
 */
31
class MetadataFilterValues {
32
public:
33
  // Filter namespace for built-in load balancer.
34
  const std::string ENVOY_LB = "envoy.lb";
35
  // Filter namespace for built-in transport socket match in cluster.
36
  const std::string ENVOY_TRANSPORT_SOCKET_MATCH = "envoy.transport_socket_match";
37
  // Filter namespace for storing custom upstream PP TLVs in metadata.
38
  const std::string ENVOY_TRANSPORT_SOCKETS_PROXY_PROTOCOL =
39
      "envoy.transport_sockets.proxy_protocol";
40
  // Proxy address configuration namespace for HTTP/1.1 proxy transport sockets.
41
  const std::string ENVOY_HTTP11_PROXY_TRANSPORT_SOCKET_ADDR =
42
      "envoy.http11_proxy_transport_socket.proxy_address";
43
};
44

            
45
using MetadataFilters = ConstSingleton<MetadataFilterValues>;
46

            
47
/**
48
 * Keys for MetadataFilterValues::ENVOY_LB metadata.
49
 */
50
class MetadataEnvoyLbKeyValues {
51
public:
52
  // Key in envoy.lb filter namespace for endpoint canary bool value.
53
  const std::string CANARY = "canary";
54
  // Key in envoy.lb filter namespace for the key to use to hash an endpoint.
55
  const std::string HASH_KEY = "hash_key";
56
  // Key in envoy.lb filter namespace for providing fallback metadata
57
  const std::string FALLBACK_LIST = "fallback_list";
58
};
59

            
60
using MetadataEnvoyLbKeys = ConstSingleton<MetadataEnvoyLbKeyValues>;
61

            
62
/**
63
 * Well known tags values and a mapping from these names to the regexes they
64
 * represent. Note: when names are added to the list, they also must be added to
65
 * the regex map by adding an entry in the getRegexMapping function.
66
 */
67
class TagNameValues {
68
public:
69
  TagNameValues();
70

            
71
  /**
72
   * Represents a tag extraction. This structure may be extended to
73
   * allow for an faster pattern-matching engine to be used as an
74
   * alternative to regexes, on an individual tag basis. Some of the
75
   * tags, such as "_rq_(\\d)xx$", will probably stay as regexes.
76
   */
77
  struct Descriptor {
78
    const std::string name_;
79
    const std::string regex_;
80
    const std::string substr_;
81
    const std::string negative_match_; // A value that will not match as the extracted tag value.
82
    const Regex::Type re_type_;
83
  };
84

            
85
  struct TokenizedDescriptor {
86
    const std::string name_;
87
    const std::string pattern_;
88
  };
89

            
90
  // Cluster name tag
91
  const std::string CLUSTER_NAME = "envoy.cluster_name";
92
  // Listener port tag
93
  const std::string LISTENER_ADDRESS = "envoy.listener_address";
94
  // Stats prefix for HttpConnectionManager
95
  const std::string HTTP_CONN_MANAGER_PREFIX = "envoy.http_conn_manager_prefix";
96
  // User agent for a connection
97
  const std::string HTTP_USER_AGENT = "envoy.http_user_agent";
98
  // SSL cipher for a connection
99
  const std::string SSL_CIPHER = "envoy.ssl_cipher";
100
  // SSL curve for a connection
101
  const std::string SSL_CURVE = "envoy.ssl_curve";
102
  // SSL signature algorithm for a connection
103
  const std::string SSL_SIGALG = "envoy.ssl_sigalg";
104
  // SSL version for a connection
105
  const std::string SSL_VERSION = "envoy.ssl_version";
106
  // SSL cipher suite
107
  const std::string SSL_CIPHER_SUITE = "cipher_suite";
108
  // Stats prefix for the Client SSL Auth network filter
109
  const std::string CLIENTSSL_PREFIX = "envoy.clientssl_prefix";
110
  // Stats prefix for the Mongo Proxy network filter
111
  const std::string MONGO_PREFIX = "envoy.mongo_prefix";
112
  // Request command for the Mongo Proxy network filter
113
  const std::string MONGO_CMD = "envoy.mongo_cmd";
114
  // Request collection for the Mongo Proxy network filter
115
  const std::string MONGO_COLLECTION = "envoy.mongo_collection";
116
  // Request callsite for the Mongo Proxy network filter
117
  const std::string MONGO_CALLSITE = "envoy.mongo_callsite";
118
  // Stats prefix for the Ratelimit network filter
119
  const std::string RATELIMIT_PREFIX = "envoy.ratelimit_prefix";
120
  // Stats prefix for the Local Ratelimit network filter
121
  const std::string LOCAL_HTTP_RATELIMIT_PREFIX = "envoy.local_http_ratelimit_prefix";
122
  // Stats prefix for the Local Ratelimit network filter
123
  const std::string LOCAL_NETWORK_RATELIMIT_PREFIX = "envoy.local_network_ratelimit_prefix";
124
  // Stats prefix for the Local Ratelimit listener filter
125
  const std::string LOCAL_LISTENER_RATELIMIT_PREFIX = "envoy.local_listener_ratelimit_prefix";
126
  // Stats prefix for the dns filter
127
  const std::string DNS_FILTER_PREFIX = "envoy.dns_filter_prefix";
128
  // Stats prefix for the Connection limit filter
129
  const std::string CONNECTION_LIMIT_PREFIX = "envoy.connection_limit_prefix";
130
  // Stats prefix for the RBAC network filter
131
  const std::string RBAC_PREFIX = "envoy.rbac_prefix";
132
  // Stats prefix for the RBAC http filter
133
  const std::string RBAC_HTTP_PREFIX = "envoy.rbac_http_prefix";
134
  // Policy name for the RBAC http filter
135
  const std::string RBAC_POLICY_NAME = "envoy.rbac_policy_name";
136
  // Stats prefix for the TCP Proxy network filter
137
  const std::string TCP_PREFIX = "envoy.tcp_prefix";
138
  // Stats prefix for the UDP Proxy network filter
139
  const std::string UDP_PREFIX = "envoy.udp_prefix";
140
  // Downstream cluster for the Fault http filter
141
  const std::string FAULT_DOWNSTREAM_CLUSTER = "envoy.fault_downstream_cluster";
142
  // Operation name for the Dynamo http filter
143
  const std::string DYNAMO_OPERATION = "envoy.dynamo_operation";
144
  // Table name for the Dynamo http filter
145
  const std::string DYNAMO_TABLE = "envoy.dynamo_table";
146
  // Partition ID for the Dynamo http filter
147
  const std::string DYNAMO_PARTITION_ID = "envoy.dynamo_partition_id";
148
  // Request service name GRPC Bridge http filter
149
  const std::string GRPC_BRIDGE_SERVICE = "envoy.grpc_bridge_service";
150
  // Request method name for the GRPC Bridge http filter
151
  const std::string GRPC_BRIDGE_METHOD = "envoy.grpc_bridge_method";
152
  // Request virtual host given by the Router http filter
153
  const std::string VIRTUAL_HOST = "envoy.virtual_host";
154
  // Request virtual cluster given by the Router http filter
155
  const std::string VIRTUAL_CLUSTER = "envoy.virtual_cluster";
156
  // Request response code
157
  const std::string RESPONSE_CODE = "envoy.response_code";
158
  // Request response code class
159
  const std::string RESPONSE_CODE_CLASS = "envoy.response_code_class";
160
  // Route config name for RDS updates
161
  const std::string RDS_ROUTE_CONFIG = "envoy.rds_route_config";
162
  // Scoped route config name for RDS updates
163
  const std::string SCOPED_RDS_CONFIG = "envoy.scoped_rds_config";
164
  // Request route given by the Router http filter
165
  const std::string ROUTE = "envoy.route";
166
  // Stats prefix for the ext_authz HTTP filter
167
  const std::string EXT_AUTHZ_PREFIX = "envoy.ext_authz_prefix";
168
  // Listener manager worker id
169
  const std::string WORKER_ID = "envoy.worker_id";
170
  // Stats prefix for the Thrift Proxy network filter
171
  const std::string THRIFT_PREFIX = "envoy.thrift_prefix";
172
  // Stats prefix for the Redis Proxy network filter
173
  const std::string REDIS_PREFIX = "envoy.redis_prefix";
174
  // Proxy Protocol version for a connection (Proxy Protocol listener filter).
175
  const std::string PROXY_PROTOCOL_VERSION = "envoy.proxy_protocol_version";
176
  // Stats prefix for the proxy protocol listener filter.
177
  const std::string PROXY_PROTOCOL_PREFIX = "envoy.proxy_protocol_prefix";
178
  // Stats prefix for Google GRPC client connections (used by ADS).
179
  const std::string GOOGLE_GRPC_CLIENT_PREFIX = "envoy.google_grpc_client_prefix";
180
  // TLS certificate.
181
  const std::string TLS_CERTIFICATE = "envoy.tls_certificate";
182
  // XDS resource name
183
  const std::string XDS_RESOURCE_NAME = "envoy.xds_resource_name";
184

            
185
  // Mapping from the names above to their respective regex strings.
186
  const std::vector<std::pair<std::string, std::string>> name_regex_pairs_;
187

            
188
  // Returns the list of descriptors.
189
21544
  const std::vector<Descriptor>& descriptorVec() const { return descriptor_vec_; }
190

            
191
  // Returns the list of tokenized descriptors.
192
10744
  const std::vector<TokenizedDescriptor>& tokenizedDescriptorVec() const {
193
10744
    return tokenized_descriptor_vec_;
194
10744
  }
195

            
196
private:
197
  void addRe2(const std::string& name, const std::string& regex, const std::string& substr = "",
198
              const std::string& negative_matching_value = "");
199

            
200
  // See class doc for TagExtractorTokensImpl in
201
  // source/common/stats/tag_extractor_impl.h for details on the format of
202
  // tokens.
203
  void addTokenized(const std::string& name, const std::string& tokens);
204

            
205
  // Collection of tag descriptors.
206
  std::vector<Descriptor> descriptor_vec_;
207

            
208
  // Collection of tokenized tag descriptors.
209
  std::vector<TokenizedDescriptor> tokenized_descriptor_vec_;
210
};
211

            
212
using TagNames = ConstSingleton<TagNameValues>;
213

            
214
// This class holds extension points which will always be built into Envoy in
215
// server mode, but may be excluded from Envoy Mobile.
216
class ServerBuiltInExtensionValues {
217
public:
218
  // Extension point for the default listener.
219
  const std::string DEFAULT_LISTENER = "envoy.listener_manager_impl.default";
220
  // Extension point for the validation listener
221
  const std::string VALIDATION_LISTENER = "envoy.listener_manager_impl.validation";
222
};
223

            
224
using ServerExtensionValues = ConstSingleton<ServerBuiltInExtensionValues>;
225

            
226
} // namespace Config
227
} // namespace Envoy