• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 {
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   // Handshake message contained out of order tags.
253   QUIC_CRYPTO_TAGS_OUT_OF_ORDER = 29,
254   // Handshake message contained too many entries.
255   QUIC_CRYPTO_TOO_MANY_ENTRIES = 30,
256   // Handshake message contained an invalid value length.
257   QUIC_CRYPTO_INVALID_VALUE_LENGTH = 31,
258   // A crypto message was received after the handshake was complete.
259   QUIC_CRYPTO_MESSAGE_AFTER_HANDSHAKE_COMPLETE = 32,
260   // A crypto message was received with an illegal message tag.
261   QUIC_INVALID_CRYPTO_MESSAGE_TYPE = 33,
262   // A crypto message was received with an illegal parameter.
263   QUIC_INVALID_CRYPTO_MESSAGE_PARAMETER = 34,
264   // An invalid channel id signature was supplied.
265   QUIC_INVALID_CHANNEL_ID_SIGNATURE = 52,
266   // A crypto message was received with a mandatory parameter missing.
267   QUIC_CRYPTO_MESSAGE_PARAMETER_NOT_FOUND = 35,
268   // A crypto message was received with a parameter that has no overlap
269   // with the local parameter.
270   QUIC_CRYPTO_MESSAGE_PARAMETER_NO_OVERLAP = 36,
271   // A crypto message was received that contained a parameter with too few
272   // values.
273   QUIC_CRYPTO_MESSAGE_INDEX_NOT_FOUND = 37,
274   // A demand for an unsupport proof type was received.
275   QUIC_UNSUPPORTED_PROOF_DEMAND = 94,
276   // An internal error occurred in crypto processing.
277   QUIC_CRYPTO_INTERNAL_ERROR = 38,
278   // A crypto handshake message specified an unsupported version.
279   QUIC_CRYPTO_VERSION_NOT_SUPPORTED = 39,
280   // (Deprecated) A crypto handshake message resulted in a stateless reject.
281   // QUIC_CRYPTO_HANDSHAKE_STATELESS_REJECT = 72,
282   // There was no intersection between the crypto primitives supported by the
283   // peer and ourselves.
284   QUIC_CRYPTO_NO_SUPPORT = 40,
285   // The server rejected our client hello messages too many times.
286   QUIC_CRYPTO_TOO_MANY_REJECTS = 41,
287   // The client rejected the server's certificate chain or signature.
288   QUIC_PROOF_INVALID = 42,
289   // A crypto message was received with a duplicate tag.
290   QUIC_CRYPTO_DUPLICATE_TAG = 43,
291   // A crypto message was received with the wrong encryption level (i.e. it
292   // should have been encrypted but was not.)
293   QUIC_CRYPTO_ENCRYPTION_LEVEL_INCORRECT = 44,
294   // The server config for a server has expired.
295   QUIC_CRYPTO_SERVER_CONFIG_EXPIRED = 45,
296   // We failed to setup the symmetric keys for a connection.
297   QUIC_CRYPTO_SYMMETRIC_KEY_SETUP_FAILED = 53,
298   // A handshake message arrived, but we are still validating the
299   // previous handshake message.
300   QUIC_CRYPTO_MESSAGE_WHILE_VALIDATING_CLIENT_HELLO = 54,
301   // A server config update arrived before the handshake is complete.
302   QUIC_CRYPTO_UPDATE_BEFORE_HANDSHAKE_COMPLETE = 65,
303   // CHLO cannot fit in one packet.
304   QUIC_CRYPTO_CHLO_TOO_LARGE = 90,
305   // This connection involved a version negotiation which appears to have been
306   // tampered with.
307   QUIC_VERSION_NEGOTIATION_MISMATCH = 55,
308 
309   // Multipath errors.
310   // Multipath is not enabled, but a packet with multipath flag on is received.
311   QUIC_BAD_MULTIPATH_FLAG = 79,
312   // A path is supposed to exist but does not.
313   QUIC_MULTIPATH_PATH_DOES_NOT_EXIST = 91,
314   // A path is supposed to be active but is not.
315   QUIC_MULTIPATH_PATH_NOT_ACTIVE = 92,
316 
317   // IP address changed causing connection close.
318   QUIC_IP_ADDRESS_CHANGED = 80,
319 
320   // Connection migration errors.
321   // Network changed, but connection had no migratable streams.
322   QUIC_CONNECTION_MIGRATION_NO_MIGRATABLE_STREAMS = 81,
323   // Connection changed networks too many times.
324   QUIC_CONNECTION_MIGRATION_TOO_MANY_CHANGES = 82,
325   // Connection migration was attempted, but there was no new network to
326   // migrate to.
327   QUIC_CONNECTION_MIGRATION_NO_NEW_NETWORK = 83,
328   // Network changed, but connection had one or more non-migratable streams.
329   QUIC_CONNECTION_MIGRATION_NON_MIGRATABLE_STREAM = 84,
330   // Network changed, but connection migration was disabled by config.
331   QUIC_CONNECTION_MIGRATION_DISABLED_BY_CONFIG = 99,
332   // Network changed, but error was encountered on the alternative network.
333   QUIC_CONNECTION_MIGRATION_INTERNAL_ERROR = 100,
334   // Network changed, but handshake is not confirmed yet.
335   QUIC_CONNECTION_MIGRATION_HANDSHAKE_UNCONFIRMED = 111,
336   QUIC_PEER_PORT_CHANGE_HANDSHAKE_UNCONFIRMED = 194,
337 
338   // Stream frames arrived too discontiguously so that stream sequencer buffer
339   // maintains too many intervals.
340   QUIC_TOO_MANY_STREAM_DATA_INTERVALS = 93,
341 
342   // Sequencer buffer get into weird state where continuing read/write will lead
343   // to crash.
344   QUIC_STREAM_SEQUENCER_INVALID_STATE = 95,
345 
346   // Connection closed because of server hits max number of sessions allowed.
347   QUIC_TOO_MANY_SESSIONS_ON_SERVER = 96,
348 
349   // Receive a RST_STREAM with offset larger than kMaxStreamLength.
350   QUIC_STREAM_LENGTH_OVERFLOW = 98,
351   // Received a MAX DATA frame with errors.
352   QUIC_INVALID_MAX_DATA_FRAME_DATA = 102,
353   // Received a MAX STREAM DATA frame with errors.
354   QUIC_INVALID_MAX_STREAM_DATA_FRAME_DATA = 103,
355   // Received a MAX_STREAMS frame with bad data
356   QUIC_MAX_STREAMS_DATA = 104,
357   // Received a STREAMS_BLOCKED frame with bad data
358   QUIC_STREAMS_BLOCKED_DATA = 105,
359   // Error deframing a STREAM BLOCKED frame.
360   QUIC_INVALID_STREAM_BLOCKED_DATA = 106,
361   // NEW CONNECTION ID frame data is malformed.
362   QUIC_INVALID_NEW_CONNECTION_ID_DATA = 107,
363   // More connection IDs than allowed are issued.
364   QUIC_CONNECTION_ID_LIMIT_ERROR = 203,
365   // The peer retires connection IDs too quickly.
366   QUIC_TOO_MANY_CONNECTION_ID_WAITING_TO_RETIRE = 204,
367   // Received a MAX STREAM DATA frame with errors.
368   QUIC_INVALID_STOP_SENDING_FRAME_DATA = 108,
369   // Error deframing PATH CHALLENGE or PATH RESPONSE frames.
370   QUIC_INVALID_PATH_CHALLENGE_DATA = 109,
371   QUIC_INVALID_PATH_RESPONSE_DATA = 110,
372   // This is used to indicate an IETF QUIC PROTOCOL VIOLATION
373   // transport error within Google (pre-v99) QUIC.
374   IETF_QUIC_PROTOCOL_VIOLATION = 113,
375   QUIC_INVALID_NEW_TOKEN = 114,
376 
377   // Received stream data on a WRITE_UNIDIRECTIONAL stream.
378   QUIC_DATA_RECEIVED_ON_WRITE_UNIDIRECTIONAL_STREAM = 115,
379   // Try to send stream data on a READ_UNIDIRECTIONAL stream.
380   QUIC_TRY_TO_WRITE_DATA_ON_READ_UNIDIRECTIONAL_STREAM = 116,
381 
382   // RETIRE CONNECTION ID frame data is malformed.
383   QUIC_INVALID_RETIRE_CONNECTION_ID_DATA = 117,
384 
385   // Error in a received STREAMS BLOCKED frame.
386   QUIC_STREAMS_BLOCKED_ERROR = 118,
387   // Error in a received MAX STREAMS frame
388   QUIC_MAX_STREAMS_ERROR = 119,
389   // Error in Http decoder
390   QUIC_HTTP_DECODER_ERROR = 120,
391   // Connection from stale host needs to be cancelled.
392   QUIC_STALE_CONNECTION_CANCELLED = 121,
393 
394   // A pseudo error, used as an extended error reason code in the error_details
395   // of IETF-QUIC CONNECTION_CLOSE frames. It is used in
396   // OnConnectionClosed upcalls to indicate that extended error information was
397   // not available in a received CONNECTION_CLOSE frame.
398   QUIC_IETF_GQUIC_ERROR_MISSING = 122,
399 
400   // Received WindowUpdate on a READ_UNIDIRECTIONAL stream.
401   QUIC_WINDOW_UPDATE_RECEIVED_ON_READ_UNIDIRECTIONAL_STREAM = 123,
402 
403   // There are too many buffered control frames in control frame manager.
404   QUIC_TOO_MANY_BUFFERED_CONTROL_FRAMES = 124,
405 
406   // QuicTransport received invalid client indication.
407   QUIC_TRANSPORT_INVALID_CLIENT_INDICATION = 125,
408 
409   // Internal error codes for QPACK errors.
410   QUIC_QPACK_DECOMPRESSION_FAILED = 126,
411 
412   // Obsolete generic QPACK encoder and decoder stream error codes.
413   QUIC_QPACK_ENCODER_STREAM_ERROR = 127,
414   QUIC_QPACK_DECODER_STREAM_ERROR = 128,
415 
416   // QPACK encoder stream errors.
417 
418   // Variable integer exceeding 2^64-1 received.
419   QUIC_QPACK_ENCODER_STREAM_INTEGER_TOO_LARGE = 174,
420   // String literal exceeding kStringLiteralLengthLimit in length received.
421   QUIC_QPACK_ENCODER_STREAM_STRING_LITERAL_TOO_LONG = 175,
422   // String literal with invalid Huffman encoding received.
423   QUIC_QPACK_ENCODER_STREAM_HUFFMAN_ENCODING_ERROR = 176,
424   // Invalid static table index in Insert With Name Reference instruction.
425   QUIC_QPACK_ENCODER_STREAM_INVALID_STATIC_ENTRY = 177,
426   // Error inserting entry with static name reference in Insert With Name
427   // Reference instruction due to entry size exceeding dynamic table capacity.
428   QUIC_QPACK_ENCODER_STREAM_ERROR_INSERTING_STATIC = 178,
429   // Invalid relative index in Insert With Name Reference instruction.
430   QUIC_QPACK_ENCODER_STREAM_INSERTION_INVALID_RELATIVE_INDEX = 179,
431   // Dynamic entry not found in Insert With Name Reference instruction.
432   QUIC_QPACK_ENCODER_STREAM_INSERTION_DYNAMIC_ENTRY_NOT_FOUND = 180,
433   // Error inserting entry with dynamic name reference in Insert With Name
434   // Reference instruction due to entry size exceeding dynamic table capacity.
435   QUIC_QPACK_ENCODER_STREAM_ERROR_INSERTING_DYNAMIC = 181,
436   // Error inserting entry in Insert With Literal Name instruction due to entry
437   // size exceeding dynamic table capacity.
438   QUIC_QPACK_ENCODER_STREAM_ERROR_INSERTING_LITERAL = 182,
439   // Invalid relative index in Duplicate instruction.
440   QUIC_QPACK_ENCODER_STREAM_DUPLICATE_INVALID_RELATIVE_INDEX = 183,
441   // Dynamic entry not found in Duplicate instruction.
442   QUIC_QPACK_ENCODER_STREAM_DUPLICATE_DYNAMIC_ENTRY_NOT_FOUND = 184,
443   // Error in Set Dynamic Table Capacity instruction due to new capacity
444   // exceeding maximum dynamic table capacity.
445   QUIC_QPACK_ENCODER_STREAM_SET_DYNAMIC_TABLE_CAPACITY = 185,
446 
447   // QPACK decoder stream errors.
448 
449   // Variable integer exceeding 2^64-1 received.
450   QUIC_QPACK_DECODER_STREAM_INTEGER_TOO_LARGE = 186,
451   // Insert Count Increment instruction received with invalid 0 increment.
452   QUIC_QPACK_DECODER_STREAM_INVALID_ZERO_INCREMENT = 187,
453   // Insert Count Increment instruction causes uint64_t overflow.
454   QUIC_QPACK_DECODER_STREAM_INCREMENT_OVERFLOW = 188,
455   // Insert Count Increment instruction increases Known Received Count beyond
456   // inserted entry cound.
457   QUIC_QPACK_DECODER_STREAM_IMPOSSIBLE_INSERT_COUNT = 189,
458   // Header Acknowledgement received for stream that has no outstanding header
459   // blocks.
460   QUIC_QPACK_DECODER_STREAM_INCORRECT_ACKNOWLEDGEMENT = 190,
461 
462   // Received stream data beyond close offset.
463   QUIC_STREAM_DATA_BEYOND_CLOSE_OFFSET = 129,
464 
465   // Received multiple close offset.
466   QUIC_STREAM_MULTIPLE_OFFSET = 130,
467 
468   // HTTP/3 errors.
469 
470   // Frame payload larger than what HttpDecoder is willing to buffer.
471   QUIC_HTTP_FRAME_TOO_LARGE = 131,
472   // Malformed HTTP/3 frame, or PUSH_PROMISE or CANCEL_PUSH received (which is
473   // an error because MAX_PUSH_ID is never sent).
474   QUIC_HTTP_FRAME_ERROR = 132,
475   // A frame that is never allowed on a request stream is received.
476   QUIC_HTTP_FRAME_UNEXPECTED_ON_SPDY_STREAM = 133,
477   // A frame that is never allowed on the control stream is received.
478   QUIC_HTTP_FRAME_UNEXPECTED_ON_CONTROL_STREAM = 134,
479   // An invalid sequence of frames normally allowed on a request stream is
480   // received.
481   QUIC_HTTP_INVALID_FRAME_SEQUENCE_ON_SPDY_STREAM = 151,
482   // A second SETTINGS frame is received on the control stream.
483   QUIC_HTTP_INVALID_FRAME_SEQUENCE_ON_CONTROL_STREAM = 152,
484   // A second instance of a unidirectional stream of a certain type is created.
485   QUIC_HTTP_DUPLICATE_UNIDIRECTIONAL_STREAM = 153,
486   // Client receives a server-initiated bidirectional stream.
487   QUIC_HTTP_SERVER_INITIATED_BIDIRECTIONAL_STREAM = 154,
488   // Server opens stream with stream ID corresponding to client-initiated
489   // stream or vice versa.
490   QUIC_HTTP_STREAM_WRONG_DIRECTION = 155,
491   // Peer closes one of the six critical unidirectional streams (control, QPACK
492   // encoder or decoder, in either direction).
493   QUIC_HTTP_CLOSED_CRITICAL_STREAM = 156,
494   // The first frame received on the control stream is not a SETTINGS frame.
495   QUIC_HTTP_MISSING_SETTINGS_FRAME = 157,
496   // The received SETTINGS frame contains duplicate setting identifiers.
497   QUIC_HTTP_DUPLICATE_SETTING_IDENTIFIER = 158,
498   // MAX_PUSH_ID frame received with push ID value smaller than a previously
499   // received value.
500   QUIC_HTTP_INVALID_MAX_PUSH_ID = 159,
501   // Received unidirectional stream limit is lower than required by HTTP/3.
502   QUIC_HTTP_STREAM_LIMIT_TOO_LOW = 160,
503   // Received mismatched SETTINGS frame from HTTP/3 connection where early data
504   // is accepted. Server violated the HTTP/3 spec.
505   QUIC_HTTP_ZERO_RTT_RESUMPTION_SETTINGS_MISMATCH = 164,
506   // Received mismatched SETTINGS frame from HTTP/3 connection where early data
507   // is rejected. Our implementation currently doesn't support it.
508   QUIC_HTTP_ZERO_RTT_REJECTION_SETTINGS_MISMATCH = 165,
509   // Client received GOAWAY frame with stream ID that is not for a
510   // client-initiated bidirectional stream.
511   QUIC_HTTP_GOAWAY_INVALID_STREAM_ID = 166,
512   // Received GOAWAY frame with ID that is greater than previously received ID.
513   QUIC_HTTP_GOAWAY_ID_LARGER_THAN_PREVIOUS = 167,
514   // HTTP/3 session received SETTINGS frame which contains HTTP/2 specific
515   // settings.
516   QUIC_HTTP_RECEIVE_SPDY_SETTING = 169,
517   // HTTP/3 session received an HTTP/2 only frame.
518   QUIC_HTTP_RECEIVE_SPDY_FRAME = 171,
519   // HTTP/3 session received SERVER_PUSH stream, which is an error because
520   // PUSH_PROMISE is not accepted.
521   QUIC_HTTP_RECEIVE_SERVER_PUSH = 205,
522   // HTTP/3 session received invalid SETTING value.
523   QUIC_HTTP_INVALID_SETTING_VALUE = 207,
524 
525   // HPACK header block decoding errors.
526   // Index varint beyond implementation limit.
527   QUIC_HPACK_INDEX_VARINT_ERROR = 135,
528   // Name length varint beyond implementation limit.
529   QUIC_HPACK_NAME_LENGTH_VARINT_ERROR = 136,
530   // Value length varint beyond implementation limit.
531   QUIC_HPACK_VALUE_LENGTH_VARINT_ERROR = 137,
532   // Name length exceeds buffer limit.
533   QUIC_HPACK_NAME_TOO_LONG = 138,
534   // Value length exceeds buffer limit.
535   QUIC_HPACK_VALUE_TOO_LONG = 139,
536   // Name Huffman encoding error.
537   QUIC_HPACK_NAME_HUFFMAN_ERROR = 140,
538   // Value Huffman encoding error.
539   QUIC_HPACK_VALUE_HUFFMAN_ERROR = 141,
540   // Next instruction should have been a dynamic table size update.
541   QUIC_HPACK_MISSING_DYNAMIC_TABLE_SIZE_UPDATE = 142,
542   // Invalid index in indexed header field representation.
543   QUIC_HPACK_INVALID_INDEX = 143,
544   // Invalid index in literal header field with indexed name representation.
545   QUIC_HPACK_INVALID_NAME_INDEX = 144,
546   // Dynamic table size update not allowed.
547   QUIC_HPACK_DYNAMIC_TABLE_SIZE_UPDATE_NOT_ALLOWED = 145,
548   // Initial dynamic table size update is above low water mark.
549   QUIC_HPACK_INITIAL_TABLE_SIZE_UPDATE_IS_ABOVE_LOW_WATER_MARK = 146,
550   // Dynamic table size update is above acknowledged setting.
551   QUIC_HPACK_TABLE_SIZE_UPDATE_IS_ABOVE_ACKNOWLEDGED_SETTING = 147,
552   // HPACK block ends in the middle of an instruction.
553   QUIC_HPACK_TRUNCATED_BLOCK = 148,
554   // Incoming data fragment exceeds buffer limit.
555   QUIC_HPACK_FRAGMENT_TOO_LONG = 149,
556   // Total compressed HPACK data size exceeds limit.
557   QUIC_HPACK_COMPRESSED_HEADER_SIZE_EXCEEDS_LIMIT = 150,
558 
559   // Stream/flow control limit from 1-RTT handshake is too low to retransmit
560   // 0-RTT data. This is our implentation error. We could in theory keep the
561   // connection alive but chose not to for simplicity.
562   QUIC_ZERO_RTT_UNRETRANSMITTABLE = 161,
563   // Stream/flow control limit from 0-RTT rejection reduces cached limit.
564   // This is our implentation error. We could in theory keep the connection
565   // alive but chose not to for simplicity.
566   QUIC_ZERO_RTT_REJECTION_LIMIT_REDUCED = 162,
567   // Stream/flow control limit from 0-RTT resumption reduces cached limit.
568   // This is the peer violating QUIC spec.
569   QUIC_ZERO_RTT_RESUMPTION_LIMIT_REDUCED = 163,
570 
571   // The connection silently timed out due to no network activity.
572   QUIC_SILENT_IDLE_TIMEOUT = 168,
573 
574   // Try to write data without the right write keys.
575   QUIC_MISSING_WRITE_KEYS = 170,
576 
577   // An endpoint detected errors in performing key updates.
578   QUIC_KEY_UPDATE_ERROR = 172,
579 
580   // An endpoint has reached the confidentiality or integrity limit for the
581   // AEAD algorithm used by the given connection.
582   QUIC_AEAD_LIMIT_REACHED = 173,
583 
584   // Connection reached maximum age (regardless of activity), no new requests
585   // are accepted.  This error code is sent in transport layer GOAWAY frame when
586   // using gQUIC, and only used internally when using HTTP/3.  Active requests
587   // are still served, after which connection will be closed due to idle
588   // timeout.
589   QUIC_MAX_AGE_TIMEOUT = 191,
590 
591   // Decrypted a 0-RTT packet with a higher packet number than a 1-RTT packet.
592   QUIC_INVALID_0RTT_PACKET_NUMBER_OUT_OF_ORDER = 192,
593 
594   // Received PRIORITY_UPDATE frame with invalid payload.
595   QUIC_INVALID_PRIORITY_UPDATE = 193,
596 
597   // Maps to specific errors from the CRYPTO_ERROR range from
598   // https://quicwg.org/base-drafts/draft-ietf-quic-transport.html#name-transport-error-codes
599   // This attempts to choose a subset of the most interesting errors rather
600   // than mapping every possible CRYPTO_ERROR code.
601   QUIC_TLS_BAD_CERTIFICATE = 195,
602   QUIC_TLS_UNSUPPORTED_CERTIFICATE = 196,
603   QUIC_TLS_CERTIFICATE_REVOKED = 197,
604   QUIC_TLS_CERTIFICATE_EXPIRED = 198,
605   QUIC_TLS_CERTIFICATE_UNKNOWN = 199,
606   QUIC_TLS_INTERNAL_ERROR = 200,
607   QUIC_TLS_UNRECOGNIZED_NAME = 201,
608   QUIC_TLS_CERTIFICATE_REQUIRED = 202,
609 
610   // An HTTP field value containing an invalid character has been received.
611   QUIC_INVALID_CHARACTER_IN_FIELD_VALUE = 206,
612 
613   // Error code related to the usage of TLS keying material export.
614   QUIC_TLS_UNEXPECTED_KEYING_MATERIAL_EXPORT_LABEL = 208,
615   QUIC_TLS_KEYING_MATERIAL_EXPORTS_MISMATCH = 209,
616   QUIC_TLS_KEYING_MATERIAL_EXPORT_NOT_AVAILABLE = 210,
617   QUIC_UNEXPECTED_DATA_BEFORE_ENCRYPTION_ESTABLISHED = 211,
618 
619   // Error code related to backend health-check.
620   QUIC_SERVER_UNHEALTHY = 213,
621 
622   // No error. Used as bound while iterating.
623   QUIC_LAST_ERROR = 214,
624 };
625 // QuicErrorCodes is encoded as four octets on-the-wire when doing Google QUIC,
626 // or a varint62 when doing IETF QUIC. Ensure that its value does not exceed
627 // the smaller of the two limits.
628 static_assert(static_cast<uint64_t>(QUIC_LAST_ERROR) <=
629                   static_cast<uint64_t>(std::numeric_limits<uint32_t>::max()),
630               "QuicErrorCode exceeds four octets");
631 
632 // Wire values for HTTP/3 errors.
633 // https://www.rfc-editor.org/rfc/rfc9114.html#http-error-codes
634 enum class QuicHttp3ErrorCode {
635   // NO_ERROR is defined as a C preprocessor macro on Windows.
636   HTTP3_NO_ERROR = 0x100,
637   GENERAL_PROTOCOL_ERROR = 0x101,
638   INTERNAL_ERROR = 0x102,
639   STREAM_CREATION_ERROR = 0x103,
640   CLOSED_CRITICAL_STREAM = 0x104,
641   FRAME_UNEXPECTED = 0x105,
642   FRAME_ERROR = 0x106,
643   EXCESSIVE_LOAD = 0x107,
644   ID_ERROR = 0x108,
645   SETTINGS_ERROR = 0x109,
646   MISSING_SETTINGS = 0x10A,
647   REQUEST_REJECTED = 0x10B,
648   REQUEST_CANCELLED = 0x10C,
649   REQUEST_INCOMPLETE = 0x10D,
650   MESSAGE_ERROR = 0x10E,
651   CONNECT_ERROR = 0x10F,
652   VERSION_FALLBACK = 0x110,
653 };
654 
655 // Wire values for QPACK errors.
656 // https://www.rfc-editor.org/rfc/rfc9204.html#error-code-registration
657 enum class QuicHttpQpackErrorCode {
658   DECOMPRESSION_FAILED = 0x200,
659   ENCODER_STREAM_ERROR = 0x201,
660   DECODER_STREAM_ERROR = 0x202
661 };
662 
663 // Represents a reason for resetting a stream in both gQUIC and IETF error code
664 // space.  Both error codes have to be present.
665 class QUIC_EXPORT_PRIVATE QuicResetStreamError {
666  public:
667   // Constructs a QuicResetStreamError from QuicRstStreamErrorCode; the IETF
668   // error code is inferred.
669   static QuicResetStreamError FromInternal(QuicRstStreamErrorCode code);
670   // Constructs a QuicResetStreamError from an IETF error code; the internal
671   // error code is inferred.
672   static QuicResetStreamError FromIetf(uint64_t code);
673   static QuicResetStreamError FromIetf(QuicHttp3ErrorCode code);
674   static QuicResetStreamError FromIetf(QuicHttpQpackErrorCode code);
675   // Constructs a QuicResetStreamError with no error.
NoError()676   static QuicResetStreamError NoError() {
677     return FromInternal(QUIC_STREAM_NO_ERROR);
678   }
679 
QuicResetStreamError(QuicRstStreamErrorCode internal_code,uint64_t ietf_application_code)680   QuicResetStreamError(QuicRstStreamErrorCode internal_code,
681                        uint64_t ietf_application_code)
682       : internal_code_(internal_code),
683         ietf_application_code_(ietf_application_code) {}
684 
internal_code()685   QuicRstStreamErrorCode internal_code() const { return internal_code_; }
ietf_application_code()686   uint64_t ietf_application_code() const { return ietf_application_code_; }
687 
688   bool operator==(const QuicResetStreamError& other) const {
689     return internal_code() == other.internal_code() &&
690            ietf_application_code() == other.ietf_application_code();
691   }
692 
693   // Returns true if the object holds no error.
ok()694   bool ok() const { return internal_code() == QUIC_STREAM_NO_ERROR; }
695 
696  private:
697   // Error code used in gQUIC.  Even when IETF QUIC is in use, this needs to be
698   // populated as we use those internally.
699   QuicRstStreamErrorCode internal_code_;
700   // Application error code used in IETF QUIC.
701   uint64_t ietf_application_code_;
702 };
703 
704 // Convert TLS alert code to QuicErrorCode.
705 QUIC_EXPORT_PRIVATE QuicErrorCode TlsAlertToQuicErrorCode(uint8_t desc);
706 
707 // Returns the name of the QuicRstStreamErrorCode as a char*
708 QUIC_EXPORT_PRIVATE const char* QuicRstStreamErrorCodeToString(
709     QuicRstStreamErrorCode error);
710 
711 // Returns the name of the QuicErrorCode as a char*
712 QUIC_EXPORT_PRIVATE const char* QuicErrorCodeToString(QuicErrorCode error);
713 
714 // Wire values for QUIC transport errors.
715 // https://quicwg.org/base-drafts/draft-ietf-quic-transport.html#name-transport-error-codes
716 enum QuicIetfTransportErrorCodes : uint64_t {
717   NO_IETF_QUIC_ERROR = 0x0,
718   INTERNAL_ERROR = 0x1,
719   SERVER_BUSY_ERROR = 0x2,
720   FLOW_CONTROL_ERROR = 0x3,
721   STREAM_LIMIT_ERROR = 0x4,
722   STREAM_STATE_ERROR = 0x5,
723   FINAL_SIZE_ERROR = 0x6,
724   FRAME_ENCODING_ERROR = 0x7,
725   TRANSPORT_PARAMETER_ERROR = 0x8,
726   CONNECTION_ID_LIMIT_ERROR = 0x9,
727   PROTOCOL_VIOLATION = 0xA,
728   INVALID_TOKEN = 0xB,
729   CRYPTO_BUFFER_EXCEEDED = 0xD,
730   KEY_UPDATE_ERROR = 0xE,
731   AEAD_LIMIT_REACHED = 0xF,
732   CRYPTO_ERROR_FIRST = 0x100,
733   CRYPTO_ERROR_LAST = 0x1FF,
734 };
735 
736 QUIC_EXPORT_PRIVATE std::string QuicIetfTransportErrorCodeString(
737     QuicIetfTransportErrorCodes c);
738 
739 QUIC_EXPORT_PRIVATE std::ostream& operator<<(
740     std::ostream& os, const QuicIetfTransportErrorCodes& c);
741 
742 // A transport error code (if is_transport_close is true) or application error
743 // code (if is_transport_close is false) to be used in CONNECTION_CLOSE frames.
744 struct QUIC_EXPORT_PRIVATE QuicErrorCodeToIetfMapping {
745   bool is_transport_close;
746   uint64_t error_code;
747 };
748 
749 // Convert QuicErrorCode to transport or application IETF error code
750 // to be used in CONNECTION_CLOSE frames.
751 QUIC_EXPORT_PRIVATE QuicErrorCodeToIetfMapping
752 QuicErrorCodeToTransportErrorCode(QuicErrorCode error);
753 
754 // Convert a QuicRstStreamErrorCode to an application error code to be used in
755 // an IETF QUIC RESET_STREAM frame
756 QUIC_EXPORT_PRIVATE uint64_t RstStreamErrorCodeToIetfResetStreamErrorCode(
757     QuicRstStreamErrorCode rst_stream_error_code);
758 
759 // Convert the application error code of an IETF QUIC RESET_STREAM frame
760 // to QuicRstStreamErrorCode.
761 QUIC_EXPORT_PRIVATE QuicRstStreamErrorCode
762 IetfResetStreamErrorCodeToRstStreamErrorCode(uint64_t ietf_error_code);
763 
HistogramEnumString(QuicErrorCode enum_value)764 QUIC_EXPORT_PRIVATE inline std::string HistogramEnumString(
765     QuicErrorCode enum_value) {
766   return QuicErrorCodeToString(enum_value);
767 }
768 
HistogramEnumDescription(QuicErrorCode)769 QUIC_EXPORT_PRIVATE inline std::string HistogramEnumDescription(
770     QuicErrorCode /*dummy*/) {
771   return "cause";
772 }
773 
774 }  // namespace quic
775 
776 #endif  // QUICHE_QUIC_CORE_QUIC_ERROR_CODES_H_
777