-
Notifications
You must be signed in to change notification settings - Fork 69
/
proxy_wasm_common.h
144 lines (136 loc) · 4.83 KB
/
proxy_wasm_common.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/*
* Copyright 2016-2019 Envoy Project Authors
* Copyright 2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* Common enumerations available to WASM modules and shared with sandbox.
*/
// NOLINT(namespace-envoy)
#pragma once
#include <cstdint>
#include <string>
// Return status of a Proxy-Wasm hostcall. Corresponds to Proxy-Wasm ABI
// `proxy_status_t`.
enum class WasmResult : uint32_t {
Ok = 0,
// The result could not be found, e.g. a provided key did not appear in a
// table.
NotFound = 1,
// An argument was bad, e.g. did not not conform to the required range.
BadArgument = 2,
// A protobuf could not be serialized.
SerializationFailure = 3,
// A protobuf could not be parsed.
ParseFailure = 4,
// A provided expression (e.g. "foo.bar") was illegal or unrecognized.
BadExpression = 5,
// A provided memory range was not legal.
InvalidMemoryAccess = 6,
// Data was requested from an empty container.
Empty = 7,
// The provided CAS did not match that of the stored data.
CasMismatch = 8,
// Returned result was unexpected, e.g. of the incorrect size.
ResultMismatch = 9,
// Internal failure: trying check logs of the surrounding system.
InternalFailure = 10,
// The connection/stream/pipe was broken/closed unexpectedly.
BrokenConnection = 11,
// Feature not implemented.
Unimplemented = 12,
};
#define _CASE(_e) \
case WasmResult::_e: \
return #_e
inline std::string toString(WasmResult r) {
switch (r) {
_CASE(Ok);
_CASE(NotFound);
_CASE(BadArgument);
_CASE(SerializationFailure);
_CASE(ParseFailure);
_CASE(BadExpression);
_CASE(InvalidMemoryAccess);
_CASE(Empty);
_CASE(CasMismatch);
_CASE(ResultMismatch);
_CASE(InternalFailure);
_CASE(BrokenConnection);
_CASE(Unimplemented);
}
return "Unknown";
}
#undef _CASE
// HTTP header type. Corresponds to Proxy-Wasm ABI `proxy_header_map_type_t`.
enum class WasmHeaderMapType : int32_t {
// HTTP request headers. During the `onLog` callback these are immutable.
RequestHeaders = 0,
// HTTP request trailers. During the `onLog` callback these are immutable.
RequestTrailers = 1,
// HTTP response headers. During the `onLog` callback these are immutable.
ResponseHeaders = 2,
// HTTP response trailers. During the `onLog` callback these are immutable.
ResponseTrailers = 3,
// Initial metadata for the response to a gRPC callout. Immutable.
GrpcReceiveInitialMetadata = 4,
// Trailing metadata for the response to a gRPC callout. Immutable.
GrpcReceiveTrailingMetadata = 5,
// HTTP response headers for the response to an HTTP callout. Immutable.
HttpCallResponseHeaders = 6,
// HTTP response trailers for the response to an HTTP callout. Immutable.
HttpCallResponseTrailers = 7,
MAX = 7,
};
// Data buffer types. Corresponds to Proxy-Wasm ABI `proxy_buffer_type_t`.
enum class WasmBufferType : int32_t {
// HTTP request body bytes. During the `onLog` callback these are immutable.
HttpRequestBody = 0,
// HTTP response body bytes. During the `onLog` callback these are immutable.
HttpResponseBody = 1,
// Bytes received from downstream TCP (or TCP-like) sender. During the `onLog`
// callback these are immutable.
NetworkDownstreamData = 2,
// Bytes received from upstream TCP (or TCP-like) sender. During the `onLog`
// callback these are immutable.
NetworkUpstreamData = 3,
// HTTP response body for the response to an HTTP callout. Immutable.
HttpCallResponseBody = 4,
// Response data for the response to a gRPC callout. Immutable.
GrpcReceiveBuffer = 5,
// VM configuration data. Immutable.
VmConfiguration = 6,
// Plugin configuration data. Immutable.
PluginConfiguration = 7,
// Foreign function call argument data. Immutable.
CallData = 8,
MAX = 8,
};
// Flags values for `getBufferStatus` hostcall.
enum class WasmBufferFlags : int32_t {
// These must be powers of 2.
EndOfStream = 1,
};
// Stream type. Corresponds to Proxy-Wasm ABI `proxy_stream_type_t`.
enum class WasmStreamType : int32_t {
// HTTP request.
Request = 0,
// HTTP response.
Response = 1,
// TCP(-like) data from downstream.
Downstream = 2,
// TCP(-like) data from upstream.
Upstream = 3,
MAX = 3,
};