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: 221 221 100.0 %
Date: 2026-03-25 05:50:20 Functions: 1 37 2.7 %

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

Generated by: LCOV version 1.14