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