ProtoCore v1.0.16
Deterministic, zero-heap network stack for embedded targets
Loading...
Searching...
No Matches
quic_tp.h
Go to the documentation of this file.
1// ProtoCore v1.0.16 - Copyright (C) 2026 Douglas Quigg (dstroy0) <dquigg123@gmail.com>
2// SPDX-License-Identifier: AGPL-3.0-or-later
3
4#ifndef PROTOCORE_QUIC_TP_H
5#define PROTOCORE_QUIC_TP_H
6
7#include "network_drivers/presentation/http/http3/quic_packet/quic_packet.h" // the complete type a public struct below holds by value
8#include "protocore_config.h" // the entry point: protocore_types.h for the widths
9
11
12/**
13 * @file quic_tp.h
14 * @brief QUIC transport parameters (RFC 9000 sec 18) carried in the TLS quic_transport_parameters
15extension (RFC 9001 sec 8.2).
16 *
17 * Each endpoint states its transport limits (flow-control windows, stream limits, idle timeout, and
18 * the connection IDs used during the handshake) as a sequence of `ID (varint) | Length (varint) |
19 * Value` parameters. The server carries its parameters in the EncryptedExtensions message and reads
20 * the client's from the ClientHello. This module encodes the set a minimal server advertises and
21 * parses a peer's, applying the RFC 9000 sec 18.2 defaults and rejecting malformed or illegal values
22 * (bad varints, oversized connection IDs, a duplicated parameter, out-of-range limits).
23 *
24 * Pure, zero heap, host-tested (round-trip + the spec defaults + malformed-input rejection).
25 *
26 * @c work is bytes the CALLER holds. This module reads none of them: it carries nothing
27 * between calls, so there is no state to keep and nothing to wipe. The parameter is there so
28 * a caller drives every namespace the same way.
29 *
30 * @author Douglas Quigg (dstroy0)
31 * @date 2026
32 */
33
34// PROTOCORE_QUIC_TP_BORROW - the bytes this module runs out of - is stated in protocore_config.h, which sums
35// it into its arena. Its size and its offset are each a static_assert, so a feature
36// combination that does not fit fails to compile rather than overrunning at run time.
37
38/** @brief Transport parameter identifiers (RFC 9000 sec 18.2 / Table 7). */
39#define QUIC_TP_ORIGINAL_DCID 0x00 ///< server: DCID of the client's first Initial
40#define QUIC_TP_MAX_IDLE_TIMEOUT 0x01 ///< varint, milliseconds (0 = disabled)
41#define QUIC_TP_STATELESS_RESET_TOKEN 0x02 ///< 16 bytes (server only)
42#define QUIC_TP_MAX_UDP_PAYLOAD_SIZE 0x03 ///< varint, default 65527, min 1200
43#define QUIC_TP_INITIAL_MAX_DATA 0x04 ///< varint, connection flow-control window
44#define QUIC_TP_INITIAL_MAX_SD_BIDI_LOCAL 0x05 ///< varint
45#define QUIC_TP_INITIAL_MAX_SD_BIDI_REMOTE 0x06 ///< varint
46#define QUIC_TP_INITIAL_MAX_SD_UNI 0x07 ///< varint
47#define QUIC_TP_INITIAL_MAX_STREAMS_BIDI 0x08 ///< varint
48#define QUIC_TP_INITIAL_MAX_STREAMS_UNI 0x09 ///< varint
49#define QUIC_TP_ACK_DELAY_EXPONENT 0x0a ///< varint, default 3, max 20
50#define QUIC_TP_MAX_ACK_DELAY 0x0b ///< varint, default 25, < 2^14
51#define QUIC_TP_DISABLE_ACTIVE_MIGRATION 0x0c ///< zero-length flag
52#define QUIC_TP_ACTIVE_CID_LIMIT 0x0e ///< varint, default 2, min 2
53#define QUIC_TP_INITIAL_SCID 0x0f ///< SCID of this endpoint's first Initial
54#define QUIC_TP_RETRY_SCID 0x10 ///< server: SCID of a Retry it sent
55
56/** @brief The transport parameters we encode / decode, with RFC 9000 sec 18.2 defaults applied. */
57typedef struct
58{
60 uint8_t original_dcid[QUIC_MAX_CID_LEN];
63 uint8_t initial_scid[QUIC_MAX_CID_LEN];
66 uint8_t retry_scid[QUIC_MAX_CID_LEN];
68
69 uint64_t max_idle_timeout; ///< default 0
70 uint64_t max_udp_payload_size; ///< default 65527
71 uint64_t initial_max_data; ///< default 0
72 uint64_t initial_max_sd_bidi_local; ///< default 0
73 uint64_t initial_max_sd_bidi_remote; ///< default 0
74 uint64_t initial_max_sd_uni; ///< default 0
75 uint64_t initial_max_streams_bidi; ///< default 0
76 uint64_t initial_max_streams_uni; ///< default 0
77 uint64_t ack_delay_exponent; ///< default 3
78 uint64_t max_ack_delay; ///< default 25 (ms)
79 uint64_t active_connection_id_limit; ///< default 2
82
83/** @brief Dispatch table. Addressed by offset, so the layout is asserted below. */
84typedef struct
85{
86 void (*defaults)(uint8_t *, QuicTransportParams *);
87 size_t (*encode)(uint8_t *, const QuicTransportParams *, uint8_t *, size_t);
88 proto_bool (*parse)(uint8_t *, const uint8_t *, size_t, QuicTransportParams *);
89} QuicTpNs;
90PROTOCORE_NS_LAYOUT(QuicTpNs, defaults, encode, parse);
91
92/**
93 * @brief Fill tp with the RFC 9000 sec 18.2 default values (all connection .
94 * @param work PROTOCORE_QUIC_TP_BORROW bytes the caller took. Not held past the call.
95 * @param tp Tp
96 */
98/**
99 * @brief Encode the server's transport parameters into out. Emits, in .
100 * @param work PROTOCORE_QUIC_TP_BORROW bytes the caller took. Not held past the call.
101 * @param tp Tp
102 * @param out Out
103 * @param cap Cap
104 * @return The size_t.
105 */
106size_t protocore_quic_tp_encode(uint8_t *work, const QuicTransportParams *tp, uint8_t *out, size_t cap);
107/**
108 * @brief Parse a peer's transport parameters (starting from the spec .
109 * @param work PROTOCORE_QUIC_TP_BORROW bytes the caller took. Not held past the call.
110 * @param buf Buf
111 * @param len Len
112 * @param tp Tp
113 * @return PROTO_TRUE on success.
114 */
115proto_bool protocore_quic_tp_parse(uint8_t *work, const uint8_t *buf, size_t len, QuicTransportParams *tp);
116
117/** @brief Module namespace. */
120
122
123#endif // PROTOCORE_QUIC_TP_H
#define PROTOCORE_NS_LAYOUT(T,...)
Pin every dispatch slot of a table that is nothing but function pointers.
#define PROTOCORE_NS
Storage for a dispatch table. The const is load bearing.
QUIC packet headers and packet-number coding (RFC 9000 sec 17).
#define QUIC_MAX_CID_LEN
maximum connection-ID length in QUIC version 1
Definition quic_packet.h:37
size_t protocore_quic_tp_encode(uint8_t *work, const QuicTransportParams *tp, uint8_t *out, size_t cap)
Encode the server's transport parameters into out. Emits, in .
PROTOCORE_NS QuicTpNs QuicTp PROTOCORE_UNUSED
Module namespace.
Definition quic_tp.h:118
proto_bool protocore_quic_tp_parse(uint8_t *work, const uint8_t *buf, size_t len, QuicTransportParams *tp)
Parse a peer's transport parameters (starting from the spec .
void protocore_quic_tp_defaults(uint8_t *work, QuicTransportParams *tp)
Fill tp with the RFC 9000 sec 18.2 default values (all connection .
Dispatch table. Addressed by offset, so the layout is asserted below.
Definition quic_tp.h:85
void(* defaults)(uint8_t *, QuicTransportParams *)
Definition quic_tp.h:86
The transport parameters we encode / decode, with RFC 9000 sec 18.2 defaults applied.
Definition quic_tp.h:58
uint64_t initial_max_streams_uni
default 0
Definition quic_tp.h:76
uint64_t initial_max_data
default 0
Definition quic_tp.h:71
uint8_t original_dcid_len
Definition quic_tp.h:61
uint64_t initial_max_sd_uni
default 0
Definition quic_tp.h:74
uint64_t max_idle_timeout
default 0
Definition quic_tp.h:69
proto_bool has_retry_scid
Definition quic_tp.h:65
uint64_t max_ack_delay
default 25 (ms)
Definition quic_tp.h:78
uint64_t initial_max_streams_bidi
default 0
Definition quic_tp.h:75
uint64_t initial_max_sd_bidi_remote
default 0
Definition quic_tp.h:73
proto_bool has_original_dcid
Definition quic_tp.h:59
uint64_t max_udp_payload_size
default 65527
Definition quic_tp.h:70
uint64_t initial_max_sd_bidi_local
default 0
Definition quic_tp.h:72
uint64_t active_connection_id_limit
default 2
Definition quic_tp.h:79
proto_bool has_initial_scid
Definition quic_tp.h:62
uint64_t ack_delay_exponent
default 3
Definition quic_tp.h:77
uint8_t retry_scid_len
Definition quic_tp.h:67
proto_bool disable_active_migration
default false
Definition quic_tp.h:80
uint8_t initial_scid_len
Definition quic_tp.h:64
#define PROTOCORE_BEGIN_DECLS
Give a header's declarations C linkage, so their symbol names carry no parameter types.
Definition types.h:96
_Bool proto_bool
The truth value.
Definition types.h:64
#define PROTOCORE_END_DECLS
Definition types.h:97