1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef QUICHE_QUIC_CORE_QUIC_ERROR_CODES_H_
6 #define QUICHE_QUIC_CORE_QUIC_ERROR_CODES_H_
7 
8 #include <cstdint>
9 #include <limits>
10 #include <string>
11 
12 #include "net/third_party/quiche/src/quic/platform/api/quic_export.h"
13 
14 namespace quic {
15 
16 enum QuicRstStreamErrorCode {
17   // Complete response has been sent, sending a RST to ask the other endpoint
18   // to stop sending request data without discarding the response.
19   QUIC_STREAM_NO_ERROR = 0,
20 
21   // There was some error which halted stream processing.
22   QUIC_ERROR_PROCESSING_STREAM = 1,
23   // We got two fin or reset offsets which did not match.
24   QUIC_MULTIPLE_TERMINATION_OFFSETS = 2,
25   // We got bad payload and can not respond to it at the protocol level.
26   QUIC_BAD_APPLICATION_PAYLOAD = 3,
27   // Stream closed due to connection error. No reset frame is sent when this
28   // happens.
29   QUIC_STREAM_CONNECTION_ERROR = 4,
30   // GoAway frame sent. No more stream can be created.
31   QUIC_STREAM_PEER_GOING_AWAY = 5,
32   // The stream has been cancelled.
33   QUIC_STREAM_CANCELLED = 6,
34   // Closing stream locally, sending a RST to allow for proper flow control
35   // accounting. Sent in response to a RST from the peer.
36   QUIC_RST_ACKNOWLEDGEMENT = 7,
37   // Receiver refused to create the stream (because its limit on open streams
38   // has been reached).  The sender should retry the request later (using
39   // another stream).
40   QUIC_REFUSED_STREAM = 8,
41   // Invalid URL in PUSH_PROMISE request header.
42   QUIC_INVALID_PROMISE_URL = 9,
43   // Server is not authoritative for this URL.
44   QUIC_UNAUTHORIZED_PROMISE_URL = 10,
45   // Can't have more than one active PUSH_PROMISE per URL.
46   QUIC_DUPLICATE_PROMISE_URL = 11,
47   // Vary check failed.
48   QUIC_PROMISE_VARY_MISMATCH = 12,
49   // Only GET and HEAD methods allowed.
50   QUIC_INVALID_PROMISE_METHOD = 13,
51   // The push stream is unclaimed and timed out.
52   QUIC_PUSH_STREAM_TIMED_OUT = 14,
53   // Received headers were too large.
54   QUIC_HEADERS_TOO_LARGE = 15,
55   // The data is not likely arrive in time.
56   QUIC_STREAM_TTL_EXPIRED = 16,
57   // The stream received data that goes beyond its close offset.
58   QUIC_DATA_AFTER_CLOSE_OFFSET = 17,
59   // Peer violated protocol requirements in a way which does not match a more
60   // specific error code, or endpoint declines to use the more specific error
61   // code.
62   QUIC_STREAM_GENERAL_PROTOCOL_ERROR = 18,
63   // An internal error has occurred.
64   QUIC_STREAM_INTERNAL_ERROR = 19,
65   // Peer created a stream that will not be accepted.
66   QUIC_STREAM_STREAM_CREATION_ERROR = 20,
67   // A stream required by the connection was closed or reset.
68   QUIC_STREAM_CLOSED_CRITICAL_STREAM = 21,
69   // A frame was received which was not permitted in the current state or on the
70   // current stream.
71   QUIC_STREAM_FRAME_UNEXPECTED = 22,
72   // A frame that fails to satisfy layout requirements or with an invalid size
73   // was received.
74   QUIC_STREAM_FRAME_ERROR = 23,
75   // Peer exhibits a behavior that might be generating excessive load.
76   QUIC_STREAM_EXCESSIVE_LOAD = 24,
77   // A Stream ID or Push ID was used incorrectly, such as exceeding a limit,
78   // reducing a limit, or being reused.
79   QUIC_STREAM_ID_ERROR = 25,
80   // Error in the payload of a SETTINGS frame.
81   QUIC_STREAM_SETTINGS_ERROR = 26,
82   // No SETTINGS frame was received at the beginning of the control stream.
83   QUIC_STREAM_MISSING_SETTINGS = 27,
84   // A server rejected a request without performing any application processing.
85   QUIC_STREAM_REQUEST_REJECTED = 28,
86   // The client's stream terminated without containing a fully-formed request.
87   QUIC_STREAM_REQUEST_INCOMPLETE = 29,
88   // The connection established in response to a CONNECT request was reset or
89   // abnormally closed.
90   QUIC_STREAM_CONNECT_ERROR = 30,
91   // The requested operation cannot be served over HTTP/3.
92   // The peer should retry over HTTP/1.1.
93   QUIC_STREAM_VERSION_FALLBACK = 31,
94   // The QPACK decoder failed to interpret a header block and is not able to
95   // continue decoding that header block.
96   QUIC_STREAM_DECOMPRESSION_FAILED = 32,
97   // The QPACK decoder failed to interpret an encoder instruction received on
98   // the encoder stream.
99   QUIC_STREAM_ENCODER_STREAM_ERROR = 33,
100   // The QPACK encoder failed to interpret a decoder instruction received on the
101   // decoder stream.
102   QUIC_STREAM_DECODER_STREAM_ERROR = 34,
103   // IETF RESET_FRAME application error code not matching any HTTP/3 or QPACK
104   // error codes.
105   QUIC_STREAM_UNKNOWN_APPLICATION_ERROR_CODE = 35,
106   // No error. Used as bound while iterating.
107   QUIC_STREAM_LAST_ERROR = 36,
108 };
109 // QuicRstStreamErrorCode is encoded as a single octet on-the-wire.
110 static_assert(static_cast<int>(QUIC_STREAM_LAST_ERROR) <=
111                   std::numeric_limits<uint8_t>::max(),
112               "QuicRstStreamErrorCode exceeds single octet");
113 
114 // These values must remain stable as they are uploaded to UMA histograms.
115 // To add a new error code, use the current value of QUIC_LAST_ERROR and
116 // increment QUIC_LAST_ERROR.
117 enum QuicErrorCode {
118   QUIC_NO_ERROR = 0,
119 
120   // Connection has reached an invalid state.
121   QUIC_INTERNAL_ERROR = 1,
122   // There were data frames after the a fin or reset.
123   QUIC_STREAM_DATA_AFTER_TERMINATION = 2,
124   // Control frame is malformed.
125   QUIC_INVALID_PACKET_HEADER = 3,
126   // Frame data is malformed.
127   QUIC_INVALID_FRAME_DATA = 4,
128   // The packet contained no payload.
129   QUIC_MISSING_PAYLOAD = 48,
130   // FEC data is malformed.
131   QUIC_INVALID_FEC_DATA = 5,
132   // STREAM frame data is malformed.
133   QUIC_INVALID_STREAM_DATA = 46,
134   // STREAM frame data overlaps with buffered data.
135   QUIC_OVERLAPPING_STREAM_DATA = 87,
136   // Received STREAM frame data is not encrypted.
137   QUIC_UNENCRYPTED_STREAM_DATA = 61,
138   // Attempt to send unencrypted STREAM frame.
139   QUIC_ATTEMPT_TO_SEND_UNENCRYPTED_STREAM_DATA = 88,
140   // Received a frame which is likely the result of memory corruption.
141   QUIC_MAYBE_CORRUPTED_MEMORY = 89,
142   // FEC frame data is not encrypted.
143   QUIC_UNENCRYPTED_FEC_DATA = 77,
144   // RST_STREAM frame data is malformed.
145   QUIC_INVALID_RST_STREAM_DATA = 6,
146   // CONNECTION_CLOSE frame data is malformed.
147   QUIC_INVALID_CONNECTION_CLOSE_DATA = 7,
148   // GOAWAY frame data is malformed.
149   QUIC_INVALID_GOAWAY_DATA = 8,
150   // WINDOW_UPDATE frame data is malformed.
151   QUIC_INVALID_WINDOW_UPDATE_DATA = 57,
152   // BLOCKED frame data is malformed.
153   QUIC_INVALID_BLOCKED_DATA = 58,
154   // STOP_WAITING frame data is malformed.
155   QUIC_INVALID_STOP_WAITING_DATA = 60,
156   // PATH_CLOSE frame data is malformed.
157   QUIC_INVALID_PATH_CLOSE_DATA = 78,
158   // ACK frame data is malformed.
159   QUIC_INVALID_ACK_DATA = 9,
160   // Message frame data is malformed.
161   QUIC_INVALID_MESSAGE_DATA = 112,
162 
163   // Version negotiation packet is malformed.
164   QUIC_INVALID_VERSION_NEGOTIATION_PACKET = 10,
165   // Public RST packet is malformed.
166   QUIC_INVALID_PUBLIC_RST_PACKET = 11,
167   // There was an error decrypting.
168   QUIC_DECRYPTION_FAILURE = 12,
169   // There was an error encrypting.
170   QUIC_ENCRYPTION_FAILURE = 13,
171   // The packet exceeded kMaxOutgoingPacketSize.
172   QUIC_PACKET_TOO_LARGE = 14,
173   // The peer is going away.  May be a client or server.
174   QUIC_PEER_GOING_AWAY = 16,
175   // A stream ID was invalid.
176   QUIC_INVALID_STREAM_ID = 17,
177   // A priority was invalid.
178   QUIC_INVALID_PRIORITY = 49,
179   // Too many streams already open.
180   QUIC_TOO_MANY_OPEN_STREAMS = 18,
181   // The peer created too many available streams.
182   QUIC_TOO_MANY_AVAILABLE_STREAMS = 76,
183   // Received public reset for this connection.
184   QUIC_PUBLIC_RESET = 19,
185   // Invalid protocol version.
186   QUIC_INVALID_VERSION = 20,
187 
188   // The Header ID for a stream was too far from the previous.
189   QUIC_INVALID_HEADER_ID = 22,
190   // Negotiable parameter received during handshake had invalid value.
191   QUIC_INVALID_NEGOTIATED_VALUE = 23,
192   // There was an error decompressing data.
193   QUIC_DECOMPRESSION_FAILURE = 24,
194   // The connection timed out due to no network activity.
195   QUIC_NETWORK_IDLE_TIMEOUT = 25,
196   // The connection timed out waiting for the handshake to complete.
197   QUIC_HANDSHAKE_TIMEOUT = 67,
198   // There was an error encountered migrating addresses.
199   QUIC_ERROR_MIGRATING_ADDRESS = 26,
200   // There was an error encountered migrating port only.
201   QUIC_ERROR_MIGRATING_PORT = 86,
202   // There was an error while writing to the socket.
203   QUIC_PACKET_WRITE_ERROR = 27,
204   // There was an error while reading from the socket.
205   QUIC_PACKET_READ_ERROR = 51,
206   // We received a STREAM_FRAME with no data and no fin flag set.
207   QUIC_EMPTY_STREAM_FRAME_NO_FIN = 50,
208   // We received invalid data on the headers stream.
209   QUIC_INVALID_HEADERS_STREAM_DATA = 56,
210   // Invalid data on the headers stream received because of decompression
211   // failure.
212   QUIC_HEADERS_STREAM_DATA_DECOMPRESS_FAILURE = 97,
213   // The peer received too much data, violating flow control.
214   QUIC_FLOW_CONTROL_RECEIVED_TOO_MUCH_DATA = 59,
215   // The peer sent too much data, violating flow control.
216   QUIC_FLOW_CONTROL_SENT_TOO_MUCH_DATA = 63,
217   // The peer received an invalid flow control window.
218   QUIC_FLOW_CONTROL_INVALID_WINDOW = 64,
219   // The connection has been IP pooled into an existing connection.
220   QUIC_CONNECTION_IP_POOLED = 62,
221   // The connection has too many outstanding sent packets.
222   QUIC_TOO_MANY_OUTSTANDING_SENT_PACKETS = 68,
223   // The connection has too many outstanding received packets.
224   QUIC_TOO_MANY_OUTSTANDING_RECEIVED_PACKETS = 69,
225   // The quic connection has been cancelled.
226   QUIC_CONNECTION_CANCELLED = 70,
227   // Disabled QUIC because of high packet loss rate.
228   QUIC_BAD_PACKET_LOSS_RATE = 71,
229   // Disabled QUIC because of too many PUBLIC_RESETs post handshake.
230   QUIC_PUBLIC_RESETS_POST_HANDSHAKE = 73,
231   // Closed because we failed to serialize a packet.
232   QUIC_FAILED_TO_SERIALIZE_PACKET = 75,
233   // QUIC timed out after too many RTOs.
234   QUIC_TOO_MANY_RTOS = 85,
235 
236   // Crypto errors.
237 
238   // Handshake failed.
239   QUIC_HANDSHAKE_FAILED = 28,
240   // Handshake message contained out of order tags.
241   QUIC_CRYPTO_TAGS_OUT_OF_ORDER = 29,
242   // Handshake message contained too many entries.
243   QUIC_CRYPTO_TOO_MANY_ENTRIES = 30,
244   // Handshake message contained an invalid value length.
245   QUIC_CRYPTO_INVALID_VALUE_LENGTH = 31,
246   // A crypto message was received after the handshake was complete.
247   QUIC_CRYPTO_MESSAGE_AFTER_HANDSHAKE_COMPLETE = 32,
248   // A crypto message was received with an illegal message tag.
249   QUIC_INVALID_CRYPTO_MESSAGE_TYPE = 33,
250   // A crypto message was received with an illegal parameter.
251   QUIC_INVALID_CRYPTO_MESSAGE_PARAMETER = 34,
252   // An invalid channel id signature was supplied.
253   QUIC_INVALID_CHANNEL_ID_SIGNATURE = 52,
254   // A crypto message was received with a mandatory parameter missing.
255   QUIC_CRYPTO_MESSAGE_PARAMETER_NOT_FOUND = 35,
256   // A crypto message was received with a parameter that has no overlap
257   // with the local parameter.
258   QUIC_CRYPTO_MESSAGE_PARAMETER_NO_OVERLAP = 36,
259   // A crypto message was received that contained a parameter with too few
260   // values.
261   QUIC_CRYPTO_MESSAGE_INDEX_NOT_FOUND = 37,
262   // A demand for an unsupport proof type was received.
263   QUIC_UNSUPPORTED_PROOF_DEMAND = 94,
264   // An internal error occurred in crypto processing.
265   QUIC_CRYPTO_INTERNAL_ERROR = 38,
266   // A crypto handshake message specified an unsupported version.
267   QUIC_CRYPTO_VERSION_NOT_SUPPORTED = 39,
268   // (Deprecated) A crypto handshake message resulted in a stateless reject.
269   // QUIC_CRYPTO_HANDSHAKE_STATELESS_REJECT = 72,
270   // There was no intersection between the crypto primitives supported by the
271   // peer and ourselves.
272   QUIC_CRYPTO_NO_SUPPORT = 40,
273   // The server rejected our client hello messages too many times.
274   QUIC_CRYPTO_TOO_MANY_REJECTS = 41,
275   // The client rejected the server's certificate chain or signature.
276   QUIC_PROOF_INVALID = 42,
277   // A crypto message was received with a duplicate tag.
278   QUIC_CRYPTO_DUPLICATE_TAG = 43,
279   // A crypto message was received with the wrong encryption level (i.e. it
280   // should have been encrypted but was not.)
281   QUIC_CRYPTO_ENCRYPTION_LEVEL_INCORRECT = 44,
282   // The server config for a server has expired.
283   QUIC_CRYPTO_SERVER_CONFIG_EXPIRED = 45,
284   // We failed to setup the symmetric keys for a connection.
285   QUIC_CRYPTO_SYMMETRIC_KEY_SETUP_FAILED = 53,
286   // A handshake message arrived, but we are still validating the
287   // previous handshake message.
288   QUIC_CRYPTO_MESSAGE_WHILE_VALIDATING_CLIENT_HELLO = 54,
289   // A server config update arrived before the handshake is complete.
290   QUIC_CRYPTO_UPDATE_BEFORE_HANDSHAKE_COMPLETE = 65,
291   // CHLO cannot fit in one packet.
292   QUIC_CRYPTO_CHLO_TOO_LARGE = 90,
293   // This connection involved a version negotiation which appears to have been
294   // tampered with.
295   QUIC_VERSION_NEGOTIATION_MISMATCH = 55,
296 
297   // Multipath errors.
298   // Multipath is not enabled, but a packet with multipath flag on is received.
299   QUIC_BAD_MULTIPATH_FLAG = 79,
300   // A path is supposed to exist but does not.
301   QUIC_MULTIPATH_PATH_DOES_NOT_EXIST = 91,
302   // A path is supposed to be active but is not.
303   QUIC_MULTIPATH_PATH_NOT_ACTIVE = 92,
304 
305   // IP address changed causing connection close.
306   QUIC_IP_ADDRESS_CHANGED = 80,
307 
308   // Connection migration errors.
309   // Network changed, but connection had no migratable streams.
310   QUIC_CONNECTION_MIGRATION_NO_MIGRATABLE_STREAMS = 81,
311   // Connection changed networks too many times.
312   QUIC_CONNECTION_MIGRATION_TOO_MANY_CHANGES = 82,
313   // Connection migration was attempted, but there was no new network to
314   // migrate to.
315   QUIC_CONNECTION_MIGRATION_NO_NEW_NETWORK = 83,
316   // Network changed, but connection had one or more non-migratable streams.
317   QUIC_CONNECTION_MIGRATION_NON_MIGRATABLE_STREAM = 84,
318   // Network changed, but connection migration was disabled by config.
319   QUIC_CONNECTION_MIGRATION_DISABLED_BY_CONFIG = 99,
320   // Network changed, but error was encountered on the alternative network.
321   QUIC_CONNECTION_MIGRATION_INTERNAL_ERROR = 100,
322   // Network changed, but handshake is not confirmed yet.
323   QUIC_CONNECTION_MIGRATION_HANDSHAKE_UNCONFIRMED = 111,
324 
325   // Stream frames arrived too discontiguously so that stream sequencer buffer
326   // maintains too many intervals.
327   QUIC_TOO_MANY_STREAM_DATA_INTERVALS = 93,
328 
329   // Sequencer buffer get into weird state where continuing read/write will lead
330   // to crash.
331   QUIC_STREAM_SEQUENCER_INVALID_STATE = 95,
332 
333   // Connection closed because of server hits max number of sessions allowed.
334   QUIC_TOO_MANY_SESSIONS_ON_SERVER = 96,
335 
336   // Receive a RST_STREAM with offset larger than kMaxStreamLength.
337   QUIC_STREAM_LENGTH_OVERFLOW = 98,
338   // Received a MAX DATA frame with errors.
339   QUIC_INVALID_MAX_DATA_FRAME_DATA = 102,
340   // Received a MAX STREAM DATA frame with errors.
341   QUIC_INVALID_MAX_STREAM_DATA_FRAME_DATA = 103,
342   // Received a MAX_STREAMS frame with bad data
343   QUIC_MAX_STREAMS_DATA = 104,
344   // Received a STREAMS_BLOCKED frame with bad data
345   QUIC_STREAMS_BLOCKED_DATA = 105,
346   // Error deframing a STREAM BLOCKED frame.
347   QUIC_INVALID_STREAM_BLOCKED_DATA = 106,
348   // NEW CONNECTION ID frame data is malformed.
349   QUIC_INVALID_NEW_CONNECTION_ID_DATA = 107,
350   // Received a MAX STREAM DATA frame with errors.
351   QUIC_INVALID_STOP_SENDING_FRAME_DATA = 108,
352   // Error deframing PATH CHALLENGE or PATH RESPONSE frames.
353   QUIC_INVALID_PATH_CHALLENGE_DATA = 109,
354   QUIC_INVALID_PATH_RESPONSE_DATA = 110,
355   // This is used to indicate an IETF QUIC PROTOCOL VIOLATION
356   // transport error within Google (pre-v99) QUIC.
357   IETF_QUIC_PROTOCOL_VIOLATION = 113,
358   QUIC_INVALID_NEW_TOKEN = 114,
359 
360   // Received stream data on a WRITE_UNIDIRECTIONAL stream.
361   QUIC_DATA_RECEIVED_ON_WRITE_UNIDIRECTIONAL_STREAM = 115,
362   // Try to send stream data on a READ_UNIDIRECTIONAL stream.
363   QUIC_TRY_TO_WRITE_DATA_ON_READ_UNIDIRECTIONAL_STREAM = 116,
364 
365   // RETIRE CONNECTION ID frame data is malformed.
366   QUIC_INVALID_RETIRE_CONNECTION_ID_DATA = 117,
367 
368   // Error in a received STREAMS BLOCKED frame.
369   QUIC_STREAMS_BLOCKED_ERROR = 118,
370   // Error in a received MAX STREAMS frame
371   QUIC_MAX_STREAMS_ERROR = 119,
372   // Error in Http decoder
373   QUIC_HTTP_DECODER_ERROR = 120,
374   // Connection from stale host needs to be cancelled.
375   QUIC_STALE_CONNECTION_CANCELLED = 121,
376 
377   // A pseudo error, used as an extended error reason code in the error_details
378   // of IETF-QUIC CONNECTION_CLOSE frames. It is used in
379   // OnConnectionClosed upcalls to indicate that extended error information was
380   // not available in a received CONNECTION_CLOSE frame.
381   QUIC_IETF_GQUIC_ERROR_MISSING = 122,
382 
383   // Received WindowUpdate on a READ_UNIDIRECTIONAL stream.
384   QUIC_WINDOW_UPDATE_RECEIVED_ON_READ_UNIDIRECTIONAL_STREAM = 123,
385 
386   // There are too many buffered control frames in control frame manager.
387   QUIC_TOO_MANY_BUFFERED_CONTROL_FRAMES = 124,
388 
389   // QuicTransport received invalid client indication.
390   QUIC_TRANSPORT_INVALID_CLIENT_INDICATION = 125,
391 
392   // Internal error codes for QPACK errors.
393   QUIC_QPACK_DECOMPRESSION_FAILED = 126,
394 
395   // Obsolete generic QPACK encoder and decoder stream error codes.
396   // (Obsoleted by gfe2_reloadable_flag_quic_granular_qpack_error_codes.)
397   QUIC_QPACK_ENCODER_STREAM_ERROR = 127,
398   QUIC_QPACK_DECODER_STREAM_ERROR = 128,
399 
400   // QPACK encoder stream errors.
401 
402   // Variable integer exceeding 2^64-1 received.
403   QUIC_QPACK_ENCODER_STREAM_INTEGER_TOO_LARGE = 174,
404   // String literal exceeding kStringLiteralLengthLimit in length received.
405   QUIC_QPACK_ENCODER_STREAM_STRING_LITERAL_TOO_LONG = 175,
406   // String literal with invalid Huffman encoding received.
407   QUIC_QPACK_ENCODER_STREAM_HUFFMAN_ENCODING_ERROR = 176,
408   // Invalid static table index in Insert With Name Reference instruction.
409   QUIC_QPACK_ENCODER_STREAM_INVALID_STATIC_ENTRY = 177,
410   // Error inserting entry with static name reference in Insert With Name
411   // Reference instruction due to entry size exceeding dynamic table capacity.
412   QUIC_QPACK_ENCODER_STREAM_ERROR_INSERTING_STATIC = 178,
413   // Invalid relative index in Insert With Name Reference instruction.
414   QUIC_QPACK_ENCODER_STREAM_INSERTION_INVALID_RELATIVE_INDEX = 179,
415   // Dynamic entry not found in Insert With Name Reference instruction.
416   QUIC_QPACK_ENCODER_STREAM_INSERTION_DYNAMIC_ENTRY_NOT_FOUND = 180,
417   // Error inserting entry with dynamic name reference in Insert With Name
418   // Reference instruction due to entry size exceeding dynamic table capacity.
419   QUIC_QPACK_ENCODER_STREAM_ERROR_INSERTING_DYNAMIC = 181,
420   // Error inserting entry in Insert With Literal Name instruction due to entry
421   // size exceeding dynamic table capacity.
422   QUIC_QPACK_ENCODER_STREAM_ERROR_INSERTING_LITERAL = 182,
423   // Invalid relative index in Duplicate instruction.
424   QUIC_QPACK_ENCODER_STREAM_DUPLICATE_INVALID_RELATIVE_INDEX = 183,
425   // Dynamic entry not found in Duplicate instruction.
426   QUIC_QPACK_ENCODER_STREAM_DUPLICATE_DYNAMIC_ENTRY_NOT_FOUND = 184,
427   // Error in Set Dynamic Table Capacity instruction due to new capacity
428   // exceeding maximum dynamic table capacity.
429   QUIC_QPACK_ENCODER_STREAM_SET_DYNAMIC_TABLE_CAPACITY = 185,
430 
431   // QPACK decoder stream errors.
432 
433   // Variable integer exceeding 2^64-1 received.
434   QUIC_QPACK_DECODER_STREAM_INTEGER_TOO_LARGE = 186,
435   // Insert Count Increment instruction received with invalid 0 increment.
436   QUIC_QPACK_DECODER_STREAM_INVALID_ZERO_INCREMENT = 187,
437   // Insert Count Increment instruction causes uint64_t overflow.
438   QUIC_QPACK_DECODER_STREAM_INCREMENT_OVERFLOW = 188,
439   // Insert Count Increment instruction increases Known Received Count beyond
440   // inserted entry cound.
441   QUIC_QPACK_DECODER_STREAM_IMPOSSIBLE_INSERT_COUNT = 189,
442   // Header Acknowledgement received for stream that has no outstanding header
443   // blocks.
444   QUIC_QPACK_DECODER_STREAM_INCORRECT_ACKNOWLEDGEMENT = 190,
445 
446   // Received stream data beyond close offset.
447   QUIC_STREAM_DATA_BEYOND_CLOSE_OFFSET = 129,
448 
449   // Received multiple close offset.
450   QUIC_STREAM_MULTIPLE_OFFSET = 130,
451 
452   // Internal error codes for HTTP/3 errors.
453   QUIC_HTTP_FRAME_TOO_LARGE = 131,
454   QUIC_HTTP_FRAME_ERROR = 132,
455   // A frame that is never allowed on a request stream is received.
456   QUIC_HTTP_FRAME_UNEXPECTED_ON_SPDY_STREAM = 133,
457   // A frame that is never allowed on the control stream is received.
458   QUIC_HTTP_FRAME_UNEXPECTED_ON_CONTROL_STREAM = 134,
459   // An invalid sequence of frames normally allowed on a request stream is
460   // received.
461   QUIC_HTTP_INVALID_FRAME_SEQUENCE_ON_SPDY_STREAM = 151,
462   // A second SETTINGS frame is received on the control stream.
463   QUIC_HTTP_INVALID_FRAME_SEQUENCE_ON_CONTROL_STREAM = 152,
464   // A second instance of a unidirectional stream of a certain type is created.
465   QUIC_HTTP_DUPLICATE_UNIDIRECTIONAL_STREAM = 153,
466   // Client receives a server-initiated bidirectional stream.
467   QUIC_HTTP_SERVER_INITIATED_BIDIRECTIONAL_STREAM = 154,
468   // Server opens stream with stream ID corresponding to client-initiated
469   // stream or vice versa.
470   QUIC_HTTP_STREAM_WRONG_DIRECTION = 155,
471   // Peer closes one of the six critical unidirectional streams (control, QPACK
472   // encoder or decoder, in either direction).
473   QUIC_HTTP_CLOSED_CRITICAL_STREAM = 156,
474   // The first frame received on the control stream is not a SETTINGS frame.
475   QUIC_HTTP_MISSING_SETTINGS_FRAME = 157,
476   // The received SETTINGS frame contains duplicate setting identifiers.
477   QUIC_HTTP_DUPLICATE_SETTING_IDENTIFIER = 158,
478   // MAX_PUSH_ID frame received with push ID value smaller than a previously
479   // received value.
480   QUIC_HTTP_INVALID_MAX_PUSH_ID = 159,
481   // Received unidirectional stream limit is lower than required by HTTP/3.
482   QUIC_HTTP_STREAM_LIMIT_TOO_LOW = 160,
483   // Received mismatched SETTINGS frame from HTTP/3 connection where early data
484   // is accepted. Server violated the HTTP/3 spec.
485   QUIC_HTTP_ZERO_RTT_RESUMPTION_SETTINGS_MISMATCH = 164,
486   // Received mismatched SETTINGS frame from HTTP/3 connection where early data
487   // is rejected. Our implementation currently doesn't support it.
488   QUIC_HTTP_ZERO_RTT_REJECTION_SETTINGS_MISMATCH = 165,
489   // Client received GOAWAY frame with stream ID that is not for a
490   // client-initiated bidirectional stream.
491   QUIC_HTTP_GOAWAY_INVALID_STREAM_ID = 166,
492   // Received GOAWAY frame with ID that is greater than previously received ID.
493   QUIC_HTTP_GOAWAY_ID_LARGER_THAN_PREVIOUS = 167,
494   // HTTP/3 session received SETTINGS frame which contains HTTP/2 specific
495   // settings.
496   QUIC_HTTP_RECEIVE_SPDY_SETTING = 169,
497   // HTTP/3 session received an HTTP/2 only frame.
498   QUIC_HTTP_RECEIVE_SPDY_FRAME = 171,
499 
500   // HPACK header block decoding errors.
501   // Index varint beyond implementation limit.
502   QUIC_HPACK_INDEX_VARINT_ERROR = 135,
503   // Name length varint beyond implementation limit.
504   QUIC_HPACK_NAME_LENGTH_VARINT_ERROR = 136,
505   // Value length varint beyond implementation limit.
506   QUIC_HPACK_VALUE_LENGTH_VARINT_ERROR = 137,
507   // Name length exceeds buffer limit.
508   QUIC_HPACK_NAME_TOO_LONG = 138,
509   // Value length exceeds buffer limit.
510   QUIC_HPACK_VALUE_TOO_LONG = 139,
511   // Name Huffman encoding error.
512   QUIC_HPACK_NAME_HUFFMAN_ERROR = 140,
513   // Value Huffman encoding error.
514   QUIC_HPACK_VALUE_HUFFMAN_ERROR = 141,
515   // Next instruction should have been a dynamic table size update.
516   QUIC_HPACK_MISSING_DYNAMIC_TABLE_SIZE_UPDATE = 142,
517   // Invalid index in indexed header field representation.
518   QUIC_HPACK_INVALID_INDEX = 143,
519   // Invalid index in literal header field with indexed name representation.
520   QUIC_HPACK_INVALID_NAME_INDEX = 144,
521   // Dynamic table size update not allowed.
522   QUIC_HPACK_DYNAMIC_TABLE_SIZE_UPDATE_NOT_ALLOWED = 145,
523   // Initial dynamic table size update is above low water mark.
524   QUIC_HPACK_INITIAL_TABLE_SIZE_UPDATE_IS_ABOVE_LOW_WATER_MARK = 146,
525   // Dynamic table size update is above acknowledged setting.
526   QUIC_HPACK_TABLE_SIZE_UPDATE_IS_ABOVE_ACKNOWLEDGED_SETTING = 147,
527   // HPACK block ends in the middle of an instruction.
528   QUIC_HPACK_TRUNCATED_BLOCK = 148,
529   // Incoming data fragment exceeds buffer limit.
530   QUIC_HPACK_FRAGMENT_TOO_LONG = 149,
531   // Total compressed HPACK data size exceeds limit.
532   QUIC_HPACK_COMPRESSED_HEADER_SIZE_EXCEEDS_LIMIT = 150,
533 
534   // Stream/flow control limit from 1-RTT handshake is too low to retransmit
535   // 0-RTT data. This is our implentation error. We could in theory keep the
536   // connection alive but chose not to for simplicity.
537   QUIC_ZERO_RTT_UNRETRANSMITTABLE = 161,
538   // Stream/flow control limit from 0-RTT rejection reduces cached limit.
539   // This is our implentation error. We could in theory keep the connection
540   // alive but chose not to for simplicity.
541   QUIC_ZERO_RTT_REJECTION_LIMIT_REDUCED = 162,
542   // Stream/flow control limit from 0-RTT resumption reduces cached limit.
543   // This is the peer violating QUIC spec.
544   QUIC_ZERO_RTT_RESUMPTION_LIMIT_REDUCED = 163,
545 
546   // The connection silently timed out due to no network activity.
547   QUIC_SILENT_IDLE_TIMEOUT = 168,
548 
549   // Try to write data without the right write keys.
550   QUIC_MISSING_WRITE_KEYS = 170,
551 
552   // An endpoint detected errors in performing key updates.
553   QUIC_KEY_UPDATE_ERROR = 172,
554 
555   // An endpoint has reached the confidentiality or integrity limit for the
556   // AEAD algorithm used by the given connection.
557   QUIC_AEAD_LIMIT_REACHED = 173,
558 
559   // Connection reached maximum age (regardless of activity), no new requests
560   // are accepted.  This error code is sent in transport layer GOAWAY frame when
561   // using gQUIC, and only used internally when using HTTP/3.  Active requests
562   // are still served, after which connection will be closed due to idle
563   // timeout.
564   QUIC_MAX_AGE_TIMEOUT = 191,
565 
566   // No error. Used as bound while iterating.
567   QUIC_LAST_ERROR = 192,
568 };
569 // QuicErrorCodes is encoded as four octets on-the-wire when doing Google QUIC,
570 // or a varint62 when doing IETF QUIC. Ensure that its value does not exceed
571 // the smaller of the two limits.
572 static_assert(static_cast<uint64_t>(QUIC_LAST_ERROR) <=
573                   static_cast<uint64_t>(std::numeric_limits<uint32_t>::max()),
574               "QuicErrorCode exceeds four octets");
575 
576 // Returns the name of the QuicRstStreamErrorCode as a char*
577 QUIC_EXPORT_PRIVATE const char* QuicRstStreamErrorCodeToString(
578     QuicRstStreamErrorCode error);
579 
580 // Returns the name of the QuicErrorCode as a char*
581 QUIC_EXPORT_PRIVATE const char* QuicErrorCodeToString(QuicErrorCode error);
582 
583 // Wire values for QUIC transport errors.
584 // https://quicwg.org/base-drafts/draft-ietf-quic-transport.html#name-transport-error-codes
585 enum QuicIetfTransportErrorCodes : uint64_t {
586   NO_IETF_QUIC_ERROR = 0x0,
587   INTERNAL_ERROR = 0x1,
588   SERVER_BUSY_ERROR = 0x2,
589   FLOW_CONTROL_ERROR = 0x3,
590   STREAM_LIMIT_ERROR = 0x4,
591   STREAM_STATE_ERROR = 0x5,
592   FINAL_SIZE_ERROR = 0x6,
593   FRAME_ENCODING_ERROR = 0x7,
594   TRANSPORT_PARAMETER_ERROR = 0x8,
595   CONNECTION_ID_LIMIT_ERROR = 0x9,
596   PROTOCOL_VIOLATION = 0xA,
597   INVALID_TOKEN = 0xB,
598   CRYPTO_BUFFER_EXCEEDED = 0xD,
599   KEY_UPDATE_ERROR = 0xE,
600   AEAD_LIMIT_REACHED = 0xF,
601   CRYPTO_ERROR_FIRST = 0x100,
602   CRYPTO_ERROR_LAST = 0x1FF,
603 };
604 
605 QUIC_EXPORT_PRIVATE std::string QuicIetfTransportErrorCodeString(
606     QuicIetfTransportErrorCodes c);
607 
608 QUIC_EXPORT_PRIVATE std::ostream& operator<<(
609     std::ostream& os,
610     const QuicIetfTransportErrorCodes& c);
611 
612 // A transport error code (if is_transport_close is true) or application error
613 // code (if is_transport_close is false) to be used in CONNECTION_CLOSE frames.
614 struct QUIC_EXPORT_PRIVATE QuicErrorCodeToIetfMapping {
615   bool is_transport_close;
616   uint64_t error_code;
617 };
618 
619 // Convert QuicErrorCode to transport or application IETF error code
620 // to be used in CONNECTION_CLOSE frames.
621 QUIC_EXPORT_PRIVATE QuicErrorCodeToIetfMapping
622 QuicErrorCodeToTransportErrorCode(QuicErrorCode error);
623 
624 // Wire values for HTTP/3 errors.
625 // https://quicwg.org/base-drafts/draft-ietf-quic-http.html#http-error-codes
626 enum class QuicHttp3ErrorCode {
627   // NO_ERROR is defined as a C preprocessor macro on Windows.
628   HTTP3_NO_ERROR = 0x100,
629   GENERAL_PROTOCOL_ERROR = 0x101,
630   INTERNAL_ERROR = 0x102,
631   STREAM_CREATION_ERROR = 0x103,
632   CLOSED_CRITICAL_STREAM = 0x104,
633   FRAME_UNEXPECTED = 0x105,
634   FRAME_ERROR = 0x106,
635   EXCESSIVE_LOAD = 0x107,
636   ID_ERROR = 0x108,
637   SETTINGS_ERROR = 0x109,
638   MISSING_SETTINGS = 0x10A,
639   REQUEST_REJECTED = 0x10B,
640   REQUEST_CANCELLED = 0x10C,
641   REQUEST_INCOMPLETE = 0x10D,
642   CONNECT_ERROR = 0x10F,
643   VERSION_FALLBACK = 0x110,
644 };
645 
646 // Wire values for QPACK errors.
647 // https://quicwg.org/base-drafts/draft-ietf-quic-qpack.html#error-code-registration
648 enum class QuicHttpQpackErrorCode {
649   DECOMPRESSION_FAILED = 0x200,
650   ENCODER_STREAM_ERROR = 0x201,
651   DECODER_STREAM_ERROR = 0x202
652 };
653 
654 // Convert a QuicRstStreamErrorCode to an application error code to be used in
655 // an IETF QUIC RESET_STREAM frame
656 QUIC_EXPORT_PRIVATE uint64_t RstStreamErrorCodeToIetfResetStreamErrorCode(
657     QuicRstStreamErrorCode rst_stream_error_code);
658 
659 // Convert the application error code of an IETF QUIC RESET_STREAM frame
660 // to QuicRstStreamErrorCode.
661 QUIC_EXPORT_PRIVATE QuicRstStreamErrorCode
662 IetfResetStreamErrorCodeToRstStreamErrorCode(uint64_t ietf_error_code);
663 
HistogramEnumString(QuicErrorCode enum_value)664 QUIC_EXPORT_PRIVATE inline std::string HistogramEnumString(
665     QuicErrorCode enum_value) {
666   return QuicErrorCodeToString(enum_value);
667 }
668 
HistogramEnumDescription(QuicErrorCode)669 QUIC_EXPORT_PRIVATE inline std::string HistogramEnumDescription(
670     QuicErrorCode /*dummy*/) {
671   return "cause";
672 }
673 
674 }  // namespace quic
675 
676 #endif  // QUICHE_QUIC_CORE_QUIC_ERROR_CODES_H_
677