LCOV - code coverage report
Current view: top level - waltz/quic/templ - fd_quic_transport_params.h (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 0 228 0.0 %
Date: 2026-11-26 02:16:43 Functions: 0 52 0.0 %

          Line data    Source code
       1             : #ifndef HEADER_fd_src_waltz_quic_templ_fd_quic_transport_params_h
       2             : #define HEADER_fd_src_waltz_quic_templ_fd_quic_transport_params_h
       3             : 
       4             : #include "../../../util/fd_util_base.h"
       5             : #include <stdio.h>
       6             : 
       7             : // TODO set proper defaults, and delete DFT_UNKNOWN
       8             : #define DFT_UNKNOWN 0
       9             : 
      10             : /* QUIC VARINT bounds - RFC 9000 variable-length integers can encode up to 2^62-1 */
      11           0 : #define FD_QUIC_VARINT_MAX ((1UL<<62)-1UL)
      12           0 : #define FD_QUIC_VARINT_MIN 0UL
      13             : 
      14             : /* RFC 9000 Section 19.11: Stream count maximum cannot exceed 2^60, as it is not possible to encode stream IDs larger than 2^62-1. */
      15           0 : #define FD_QUIC_STREAM_COUNT_MAX (1UL<<60)
      16             : 
      17             : /* RFC 9000 Section 18.2: ack_delay_exponent values above 20 are invalid */
      18             : #define FD_QUIC_ACK_DELAY_EXPONENT_MAX 20UL
      19             : 
      20             : /* RFC 9000 Section 18.2: max_ack_delay values of 2^14 or greater are invalid */
      21             : #define FD_QUIC_MAX_ACK_DELAY_MAX ((1UL<<14)-1UL)
      22             : 
      23             : /* RFC 9000 Section 18.2: max_udp_payload_size minimum is 1200 */
      24             : #define FD_QUIC_MAX_UDP_PAYLOAD_SIZE_MIN 1200UL
      25             : 
      26             : /* RFC 9000 Section 18.2: The value of the active_connection_id_limit parameter MUST be at least 2 */
      27             : #define FD_QUIC_ACTIVE_CONNECTION_ID_LIMIT_MIN 2UL
      28             : 
      29             : //23456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789
      30             : //........1.........2.........3.........4.........5.........6.........7.........8.........9.........0.........
      31             : // Fields: NAME, ID, TYPE, DFT, DESC, MIN, MAX (MIN and MAX ignored except for VARINT types)
      32           0 : #define FD_QUIC_TRANSPORT_PARAMS(X, ...)                                               \
      33           0 : X( original_destination_connection_id,                                                 \
      34           0 :   0x00,                                                                                \
      35           0 :   CONN_ID,                                                                             \
      36           0 :   DFT_UNKNOWN,                                                                         \
      37           0 :   "This parameter is the value of the Destination Connection ID field from the "       \
      38           0 :   "first Initial packet sent by the client; see Section 7.3. This transport "          \
      39           0 :   "parameter is only sent by a server.",                                               \
      40           0 :   0, 0,                                                                                \
      41           0 :   __VA_ARGS__ )                                                                        \
      42           0 : X( max_idle_timeout_ms,                                                                \
      43           0 :   0x01,                                                                                \
      44           0 :   VARINT,                                                                              \
      45           0 :   DFT_UNKNOWN,                                                                         \
      46           0 :   "The maximum idle timeout is a value in milliseconds that is encoded as an "         \
      47           0 :   "integer; see (Section 10.1). Idle timeout is disabled when both endpoints omit "    \
      48           0 :   "this transport parameter or specify a value of 0.",                                 \
      49           0 :   FD_QUIC_VARINT_MIN, FD_QUIC_VARINT_MAX,                                              \
      50           0 :   __VA_ARGS__ )                                                                        \
      51           0 : X( stateless_reset_token,                                                              \
      52           0 :   0x02,                                                                                \
      53           0 :   TOKEN,                                                                               \
      54           0 :   DFT_UNKNOWN,                                                                         \
      55           0 :   "A stateless reset token is used in verifying a stateless reset; see Section "       \
      56           0 :   "10.3. This parameter is a sequence of 16 bytes. This transport parameter MUST "     \
      57           0 :   "NOT be sent by a client but MAY be sent by a server. A server that does not send "  \
      58           0 :   "this transport parameter cannot use stateless reset (Section 10.3) for the "        \
      59           0 :   "connection ID negotiated during the handshake.",                                    \
      60           0 :   0, 0,                                                                                \
      61           0 :   __VA_ARGS__ )                                                                        \
      62           0 : X( max_udp_payload_size,                                                               \
      63           0 :   0x03,                                                                                \
      64           0 :   VARINT,                                                                              \
      65           0 :   65527,                                                                               \
      66           0 :   "The maximum UDP payload size parameter is an integer value that limits the size "   \
      67           0 :   "of UDP payloads that the endpoint is willing to receive. UDP datagrams with "       \
      68           0 :   "payloads larger than this limit are not likely to be processed by the receiver. "   \
      69           0 :   "The default for this parameter is the maximum permitted UDP payload of 65527. "     \
      70           0 :   "Values below 1200 are invalid.\n"                                                   \
      71           0 :   "This limit does act as an additional constraint on datagram size in the same way "  \
      72           0 :   "as the path MTU, but it is a property of the endpoint and not the path; see "       \
      73           0 :   "Section 14. It is expected that this is the space an endpoint dedicates to "        \
      74           0 :   "holding incoming packets.",                                                         \
      75           0 :   FD_QUIC_MAX_UDP_PAYLOAD_SIZE_MIN, FD_QUIC_VARINT_MAX,                                             \
      76           0 :   __VA_ARGS__ )                                                                        \
      77           0 : X( initial_max_data,                                                                   \
      78           0 :   0x04,                                                                                \
      79           0 :   VARINT,                                                                              \
      80           0 :   DFT_UNKNOWN,                                                                         \
      81           0 :   "The initial maximum data parameter is an integer value that contains the initial "  \
      82           0 :   "value for the maximum amount of data that can be sent on the connection. This is "  \
      83           0 :   "equivalent to sending a MAX_DATA (Section 19.9) for the connection immediately "    \
      84           0 :   "after completing the handshake.",                                                   \
      85           0 :   FD_QUIC_VARINT_MIN, FD_QUIC_VARINT_MAX,                                              \
      86           0 :   __VA_ARGS__ )                                                                        \
      87           0 : X( initial_max_stream_data_bidi_local,                                                 \
      88           0 :   0x05,                                                                                \
      89           0 :   VARINT,                                                                              \
      90           0 :   DFT_UNKNOWN,                                                                         \
      91           0 :   "This parameter is an integer value specifying the initial flow control limit for "  \
      92           0 :   "locally initiated bidirectional streams. This limit applies to newly created "      \
      93           0 :   "bidirectional streams opened by the endpoint that sends the transport parameter. "  \
      94           0 :   "In client transport parameters, this applies to streams with an identifier with "   \
      95           0 :   "the least significant two bits set to 0x00; in server transport parameters, this "  \
      96           0 :   "applies to streams with the least significant two bits set to 0x01.",               \
      97           0 :   FD_QUIC_VARINT_MIN, FD_QUIC_VARINT_MAX,                                              \
      98           0 :   __VA_ARGS__ )                                                                        \
      99           0 : X( initial_max_stream_data_bidi_remote,                                                \
     100           0 :   0x06,                                                                                \
     101           0 :   VARINT,                                                                              \
     102           0 :   DFT_UNKNOWN,                                                                         \
     103           0 :   "This parameter is an integer value specifying the initial flow control limit for "  \
     104           0 :   "peer-initiated bidirectional streams. This limit applies to newly created "         \
     105           0 :   "bidirectional streams opened by the endpoint that receives the transport "          \
     106           0 :   "parameter. In client transport parameters, this applies to streams with an "        \
     107           0 :   "identifier with the least significant two bits set to 0x01; in server transport "   \
     108           0 :   "parameters, this applies to streams with the least significant two bits set to "    \
     109           0 :   "0x00.",                                                                             \
     110           0 :   FD_QUIC_VARINT_MIN, FD_QUIC_VARINT_MAX,                                              \
     111           0 :   __VA_ARGS__ )                                                                        \
     112           0 : X( initial_max_stream_data_uni,                                                        \
     113           0 :   0x07,                                                                                \
     114           0 :   VARINT,                                                                              \
     115           0 :   DFT_UNKNOWN,                                                                         \
     116           0 :   "This parameter is an integer value specifying the initial flow control limit for "  \
     117           0 :   "unidirectional streams. This limit applies to newly created unidirectional "        \
     118           0 :   "streams opened by the endpoint that receives the transport parameter. In client "   \
     119           0 :   "transport parameters, this applies to streams with an identifier with the least "   \
     120           0 :   "significant two bits set to 0x03; in server transport parameters, this applies "    \
     121           0 :   "to streams with the least significant two bits set to 0x02.",                       \
     122           0 :   FD_QUIC_VARINT_MIN, FD_QUIC_VARINT_MAX,                                              \
     123           0 :   __VA_ARGS__ )                                                                        \
     124           0 : X( initial_max_streams_bidi,                                                           \
     125           0 :   0x08,                                                                                \
     126           0 :   VARINT,                                                                              \
     127           0 :   DFT_UNKNOWN,                                                                         \
     128           0 :   "The initial maximum bidirectional streams parameter is an integer value that "      \
     129           0 :   "contains the initial maximum number of bidirectional streams the endpoint that "    \
     130           0 :   "receives this transport parameter is permitted to initiate. If this parameter is "  \
     131           0 :   "absent or zero, the peer cannot open bidirectional streams until a MAX_STREAMS "    \
     132           0 :   "frame is sent. Setting this parameter is equivalent to sending a MAX_STREAMS "      \
     133           0 :   "(Section 19.11) of the corresponding type with the same value.",                    \
     134           0 :   FD_QUIC_VARINT_MIN, FD_QUIC_STREAM_COUNT_MAX,                                        \
     135           0 :   __VA_ARGS__ )                                                                        \
     136           0 : X( initial_max_streams_uni,                                                            \
     137           0 :   0x09,                                                                                \
     138           0 :   VARINT,                                                                              \
     139           0 :   DFT_UNKNOWN,                                                                         \
     140           0 :   "The initial maximum unidirectional streams parameter is an integer value that "     \
     141           0 :   "contains the initial maximum number of unidirectional streams the endpoint that "   \
     142           0 :   "receives this transport parameter is permitted to initiate. If this parameter is "  \
     143           0 :   "absent or zero, the peer cannot open unidirectional streams until a MAX_STREAMS "   \
     144           0 :   "frame is sent. Setting this parameter is equivalent to sending a MAX_STREAMS "      \
     145           0 :   "(Section 19.11) of the corresponding type with the same value.",                    \
     146           0 :   FD_QUIC_VARINT_MIN, FD_QUIC_STREAM_COUNT_MAX,                                        \
     147           0 :   __VA_ARGS__ )                                                                        \
     148           0 : X( ack_delay_exponent,                                                                 \
     149           0 :   0x0a,                                                                                \
     150           0 :   VARINT,                                                                              \
     151           0 :   DFT_UNKNOWN,                                                                         \
     152           0 :   "The acknowledgment delay exponent is an integer value indicating an exponent "      \
     153           0 :   "used to decode the ACK Delay field in the ACK frame (Section 19.3). If this "       \
     154           0 :   "value is absent, a default value of 3 is assumed (indicating a multiplier of 8).\n" \
     155           0 :   "Values above 20 are invalid.",                                                      \
     156           0 :   FD_QUIC_VARINT_MIN, FD_QUIC_ACK_DELAY_EXPONENT_MAX,                                  \
     157           0 :   __VA_ARGS__ )                                                                        \
     158           0 : X( max_ack_delay,                                                                      \
     159           0 :   0x0b,                                                                                \
     160           0 :   VARINT,                                                                              \
     161           0 :   25,                                                                                  \
     162           0 :   "The maximum acknowledgment delay is an integer value indicating the maximum "       \
     163           0 :   "amount of time in milliseconds by which the endpoint will delay sending "           \
     164           0 :   "acknowledgments. This value SHOULD include the receiver's expected delays in "      \
     165           0 :   "alarms firing. For example, if a receiver sets a timer for 5ms and alarms "         \
     166           0 :   "commonly fire up to 1ms late, then it should send a max_ack_delay of 6ms. If "      \
     167           0 :   "this value is absent, a default of 25 milliseconds is assumed. Values of 2^14 or "  \
     168           0 :   "greater are invalid.",                                                              \
     169           0 :   FD_QUIC_VARINT_MIN, FD_QUIC_MAX_ACK_DELAY_MAX,                                       \
     170           0 :   __VA_ARGS__ )                                                                        \
     171           0 : X( disable_active_migration,                                                           \
     172           0 :   0x0c,                                                                                \
     173           0 :   ZERO_LENGTH,                                                                         \
     174           0 :   DFT_UNKNOWN,                                                                         \
     175           0 :   "The disable active migration transport parameter is included if the endpoint "      \
     176           0 :   "does not support active connection migration (Section 9) on the address being "     \
     177           0 :   "used during the handshake. An endpoint that receives this transport parameter "     \
     178           0 :   "MUST NOT use a new local address when sending to the address that the peer used "   \
     179           0 :   "during the handshake. This transport parameter does not prohibit connection "       \
     180           0 :   "migration after a client has acted on a preferred_address transport parameter.\n"   \
     181           0 :   "This parameter is a zero-length value.",                                            \
     182           0 :   0, 0,                                                                                \
     183           0 :   __VA_ARGS__ )                                                                        \
     184           0 : X( preferred_address,                                                                  \
     185           0 :   0x0d,                                                                                \
     186           0 :   PREFERRED_ADDRESS,                                                                   \
     187           0 :   DFT_UNKNOWN,                                                                         \
     188           0 :   "The server's preferred address is used to effect a change in server address at "    \
     189           0 :   "the end of the handshake, as described in Section 9.6. This transport parameter "   \
     190           0 :   "is only sent by a server. Servers MAY choose to only send a preferred address of "  \
     191           0 :   "one address family by sending an all-zero address and port (0.0.0.0:0 or [::]:0) "  \
     192           0 :   "for the other family. IP addresses are encoded in network byte order.\n"            \
     193           0 :   "The preferred_address transport parameter contains an address and port for both "   \
     194           0 :   "IPv4 and IPv6. The four-byte IPv4 Address field is followed by the associated "     \
     195           0 :   "two-byte IPv4 Port field. This is followed by a 16-byte IPv6 Address field and "    \
     196           0 :   "two-byte IPv6 Port field. After address and port pairs, a Connection ID Length "    \
     197           0 :   "field describes the length of the following Connection ID field. Finally, a "       \
     198           0 :   "16-byte Stateless Reset Token field includes the stateless reset token "            \
     199           0 :   "associated with the connection ID. The format of this transport parameter is "      \
     200           0 :   "shown in Figure 22 below.",                                                         \
     201           0 :   0, 0,                                                                                \
     202           0 :   __VA_ARGS__ )                                                                        \
     203           0 : X( active_connection_id_limit,                                                         \
     204           0 :   0x0e,                                                                                \
     205           0 :   VARINT,                                                                              \
     206           0 :   2,                                                                                   \
     207           0 :   "This is an integer value specifying the maximum number of connection IDs from "     \
     208           0 :   "the peer that an endpoint is willing to store. This value includes the "            \
     209           0 :   "connection ID received during the handshake, that received in the "                 \
     210           0 :   "preferred_address transport parameter, and those received in NEW_CONNECTION_ID "    \
     211           0 :   "frames. The value of the active_connection_id_limit parameter MUST be at least "    \
     212           0 :   "2. An endpoint that receives a value less than 2 MUST close the connection with "   \
     213           0 :   "an error of type TRANSPORT_PARAMETER_ERROR. If this transport parameter is "        \
     214           0 :   "absent, a default of 2 is assumed. If an endpoint issues a zero-length "            \
     215           0 :   "connection ID, it will never send a NEW_CONNECTION_ID frame and therefore "         \
     216           0 :   "ignores the active_connection_id_limit value received from its peer.",              \
     217           0 :   FD_QUIC_ACTIVE_CONNECTION_ID_LIMIT_MIN, FD_QUIC_VARINT_MAX,                          \
     218           0 :   __VA_ARGS__ )                                                                        \
     219           0 : X( initial_source_connection_id,                                                       \
     220           0 :   0x0f,                                                                                \
     221           0 :   CONN_ID,                                                                             \
     222           0 :   DFT_UNKNOWN,                                                                         \
     223           0 :   "This is the value that the endpoint included in the Source Connection ID field "    \
     224           0 :   "of the first Initial packet it sends for the connection; see Section 7.3.",         \
     225           0 :   0, 0,                                                                                \
     226           0 :   __VA_ARGS__ )                                                                        \
     227           0 : X( retry_source_connection_id,                                                         \
     228           0 :   0x10,                                                                                \
     229           0 :   CONN_ID,                                                                             \
     230           0 :   DFT_UNKNOWN,                                                                         \
     231           0 :   "This is the value that the server included in the Source Connection ID field of "   \
     232           0 :   "a Retry packet; see Section 7.3. This transport parameter is only sent by a "       \
     233           0 :   "server.",                                                                           \
     234           0 :   0, 0,                                                                                \
     235           0 :   __VA_ARGS__ )                                                                        \
     236           0 : X( max_datagram_frame_size,                                                            \
     237           0 :   0x20,                                                                                \
     238           0 :   VARINT,                                                                              \
     239           0 :   DFT_UNKNOWN,                                                                         \
     240           0 :   "RFC 9221 maximum DATAGRAM frame size. Omitting this parameter disables DATAGRAM.",  \
     241           0 :   FD_QUIC_VARINT_MIN, FD_QUIC_VARINT_MAX,                                              \
     242           0 :   __VA_ARGS__ )
     243             : 
     244           0 : #define FD_QUIC_PREFERRED_ADDRESS_SZ_MAX (61)
     245             : 
     246             : void
     247             : fd_quic_dump_transport_param_desc( FILE * out );
     248             : 
     249             : // TODO verify max length on these - CONN_ID and TOKEN
     250             : // PREFERRED_ADDRESS is incomplete
     251             : #define FD_QUIC_MBR_TYPE_VARINT(NAME,TYPE)            \
     252             :   ulong  NAME;                                        \
     253             :   uchar  NAME##_present;
     254             : #define FD_QUIC_MBR_TYPE_CONN_ID(NAME,TYPE)           \
     255             :   uchar  NAME##_len;                                  \
     256             :   uchar  NAME[20];                                    \
     257             :   uchar  NAME##_present;
     258             : #define FD_QUIC_MBR_TYPE_ZERO_LENGTH(NAME,TYPE)       \
     259             :   uchar  NAME##_present;
     260             : #define FD_QUIC_MBR_TYPE_TOKEN(NAME,TYPE)             \
     261             :   uint   NAME##_len;                                  \
     262             :   uchar  NAME[16];                                    \
     263             :   uchar  NAME##_present;
     264             : #define FD_QUIC_MBR_TYPE_PREFERRED_ADDRESS(NAME,TYPE) \
     265             :   uint   NAME##_len;                                  \
     266             :   uchar  NAME[FD_QUIC_PREFERRED_ADDRESS_SZ_MAX];      \
     267             :   uchar  NAME##_present;
     268             : 
     269             : struct fd_quic_transport_params {
     270             : #define __( NAME, ID, TYPE, DFT, DESC, ... ) \
     271             :   FD_QUIC_MBR_TYPE_##TYPE(NAME,TYPE)
     272             :   FD_QUIC_TRANSPORT_PARAMS( __, _ )
     273             : #undef __
     274             : };
     275             : typedef struct fd_quic_transport_params fd_quic_transport_params_t;
     276             : 
     277             : #define FD_QUIC_TRANSPORT_PARAM_SET( TP, NAME, VALUE ) \
     278           0 :   do { (TP)->NAME##_present = 1; (TP)->NAME = VALUE; } while(0);
     279             : #define FD_QUIC_TRANSPORT_PARAM_UNSET( TP, NAME ) \
     280             :   do { (TP)->NAME##_present = 0;                     } while(0);
     281             : 
     282             : /* parses the varint at *buf (capacity *buf_sz)
     283             :    advances the *buf and reduces *buf_sz by the number of bytes
     284             :    consumed */
     285             : static inline ulong
     286             : fd_quic_tp_parse_varint( uchar const ** buf,
     287           0 :                          ulong *        buf_sz ) {
     288             : 
     289           0 :   if( FD_UNLIKELY( *buf_sz == 0    ) ) return ~(ulong)0;
     290             : 
     291           0 :   uint width = 1u << ( (uint)(*buf)[0] >> 6u );
     292           0 :   if( FD_UNLIKELY( *buf_sz < width ) ) return ~(ulong)0;
     293             : 
     294           0 :   ulong value = (ulong)( (*buf)[0] & 0x3f );
     295           0 :   for( ulong j=1; j<width; ++j ) {
     296           0 :     value = ( value<<8UL ) + (ulong)(*buf)[j];
     297           0 :   }
     298             : 
     299           0 :   *buf    += width;
     300           0 :   *buf_sz -= width;
     301             : 
     302           0 :   return value;
     303           0 : }
     304             : 
     305             : /* parse the entire buffer into the supplied transport parameters
     306             : 
     307             :    unknown transport parameters are ignored as per spec
     308             : 
     309             :    returns
     310             :      0  success
     311             :      -1 failed to parse */
     312             : int
     313             : fd_quic_decode_transport_params( fd_quic_transport_params_t * params,
     314             :                                  uchar const *                buf,
     315             :                                  ulong                        buf_sz );
     316             : 
     317             : /* dump all transport parameters to stdout */
     318             : void
     319             : fd_quic_dump_transport_params( fd_quic_transport_params_t const * params,
     320             :                                FILE * out );
     321             : 
     322             : 
     323             : /* encode transport parameters into a buffer
     324             :    args
     325             :      buf           the buffer to write encoded transport params into
     326             :      buf_sz        the size of buffer buf
     327             :      params        the parameters to be encoded
     328             : 
     329             :    returns the number of bytes written */
     330             : ulong
     331             : fd_quic_encode_transport_params( uchar *                            buf,
     332             :                                  ulong                              buf_sz,
     333             :                                  fd_quic_transport_params_t const * params );
     334             : 
     335             : #endif /* HEADER_fd_src_waltz_quic_templ_fd_quic_transport_params_h */

Generated by: LCOV version 1.14