1*e7be843bSPierre Pronchery /* 2*e7be843bSPierre Pronchery * Copyright 2022-2024 The OpenSSL Project Authors. All Rights Reserved. 3*e7be843bSPierre Pronchery * 4*e7be843bSPierre Pronchery * Licensed under the Apache License 2.0 (the "License"). You may not use 5*e7be843bSPierre Pronchery * this file except in compliance with the License. You can obtain a copy 6*e7be843bSPierre Pronchery * in the file LICENSE in the source distribution or at 7*e7be843bSPierre Pronchery * https://www.openssl.org/source/license.html 8*e7be843bSPierre Pronchery */ 9*e7be843bSPierre Pronchery 10*e7be843bSPierre Pronchery #ifndef OSSL_QUIC_TXPIM_H 11*e7be843bSPierre Pronchery # define OSSL_QUIC_TXPIM_H 12*e7be843bSPierre Pronchery 13*e7be843bSPierre Pronchery # include <openssl/ssl.h> 14*e7be843bSPierre Pronchery # include "internal/quic_types.h" 15*e7be843bSPierre Pronchery # include "internal/quic_predef.h" 16*e7be843bSPierre Pronchery # include "internal/quic_cfq.h" 17*e7be843bSPierre Pronchery # include "internal/quic_ackm.h" 18*e7be843bSPierre Pronchery 19*e7be843bSPierre Pronchery # ifndef OPENSSL_NO_QUIC 20*e7be843bSPierre Pronchery 21*e7be843bSPierre Pronchery /* 22*e7be843bSPierre Pronchery * QUIC Transmitted Packet Information Manager 23*e7be843bSPierre Pronchery * =========================================== 24*e7be843bSPierre Pronchery */ 25*e7be843bSPierre Pronchery 26*e7be843bSPierre Pronchery typedef struct quic_txpim_pkt_st { 27*e7be843bSPierre Pronchery /* ACKM-specific data. Caller should fill this. */ 28*e7be843bSPierre Pronchery OSSL_ACKM_TX_PKT ackm_pkt; 29*e7be843bSPierre Pronchery 30*e7be843bSPierre Pronchery /* Linked list of CFQ items in this packet. */ 31*e7be843bSPierre Pronchery QUIC_CFQ_ITEM *retx_head; 32*e7be843bSPierre Pronchery 33*e7be843bSPierre Pronchery /* Reserved for FIFD use. */ 34*e7be843bSPierre Pronchery QUIC_FIFD *fifd; 35*e7be843bSPierre Pronchery 36*e7be843bSPierre Pronchery /* QUIC_PKT_TYPE value. For diagnostic use only. */ 37*e7be843bSPierre Pronchery unsigned char pkt_type; 38*e7be843bSPierre Pronchery 39*e7be843bSPierre Pronchery /* Regenerate-strategy frames. */ 40*e7be843bSPierre Pronchery unsigned int had_handshake_done_frame : 1; 41*e7be843bSPierre Pronchery unsigned int had_max_data_frame : 1; 42*e7be843bSPierre Pronchery unsigned int had_max_streams_bidi_frame : 1; 43*e7be843bSPierre Pronchery unsigned int had_max_streams_uni_frame : 1; 44*e7be843bSPierre Pronchery unsigned int had_ack_frame : 1; 45*e7be843bSPierre Pronchery unsigned int had_conn_close : 1; 46*e7be843bSPierre Pronchery 47*e7be843bSPierre Pronchery /* Private data follows. */ 48*e7be843bSPierre Pronchery } QUIC_TXPIM_PKT; 49*e7be843bSPierre Pronchery 50*e7be843bSPierre Pronchery /* Represents a range of bytes in an application or CRYPTO stream. */ 51*e7be843bSPierre Pronchery typedef struct quic_txpim_chunk_st { 52*e7be843bSPierre Pronchery /* The stream ID, or UINT64_MAX for the CRYPTO stream. */ 53*e7be843bSPierre Pronchery uint64_t stream_id; 54*e7be843bSPierre Pronchery /* 55*e7be843bSPierre Pronchery * The inclusive range of bytes in the stream. Exceptionally, if end < 56*e7be843bSPierre Pronchery * start, designates a frame of zero length (used for FIN-only frames). In 57*e7be843bSPierre Pronchery * this case end is the number of the final byte (i.e., one less than the 58*e7be843bSPierre Pronchery * final size of the stream). 59*e7be843bSPierre Pronchery */ 60*e7be843bSPierre Pronchery uint64_t start, end; 61*e7be843bSPierre Pronchery /* 62*e7be843bSPierre Pronchery * Whether a FIN was sent for this stream in the packet. Not valid for 63*e7be843bSPierre Pronchery * CRYPTO stream. 64*e7be843bSPierre Pronchery */ 65*e7be843bSPierre Pronchery unsigned int has_fin : 1; 66*e7be843bSPierre Pronchery /* 67*e7be843bSPierre Pronchery * If set, a STOP_SENDING frame was sent for this stream ID. (If no data was 68*e7be843bSPierre Pronchery * sent for the stream, set end < start.) 69*e7be843bSPierre Pronchery */ 70*e7be843bSPierre Pronchery unsigned int has_stop_sending : 1; 71*e7be843bSPierre Pronchery /* 72*e7be843bSPierre Pronchery * If set, a RESET_STREAM frame was sent for this stream ID. (If no data was 73*e7be843bSPierre Pronchery * sent for the stream, set end < start.) 74*e7be843bSPierre Pronchery */ 75*e7be843bSPierre Pronchery unsigned int has_reset_stream : 1; 76*e7be843bSPierre Pronchery } QUIC_TXPIM_CHUNK; 77*e7be843bSPierre Pronchery 78*e7be843bSPierre Pronchery QUIC_TXPIM *ossl_quic_txpim_new(void); 79*e7be843bSPierre Pronchery 80*e7be843bSPierre Pronchery /* 81*e7be843bSPierre Pronchery * Frees the TXPIM. All QUIC_TXPIM_PKTs which have been handed out by the TXPIM 82*e7be843bSPierre Pronchery * must be released via a call to ossl_quic_txpim_pkt_release() before calling 83*e7be843bSPierre Pronchery * this function. 84*e7be843bSPierre Pronchery */ 85*e7be843bSPierre Pronchery void ossl_quic_txpim_free(QUIC_TXPIM *txpim); 86*e7be843bSPierre Pronchery 87*e7be843bSPierre Pronchery /* 88*e7be843bSPierre Pronchery * Allocates a new QUIC_TXPIM_PKT structure from the pool. Returns NULL on 89*e7be843bSPierre Pronchery * failure. The returned structure is cleared of all data and is in a fresh 90*e7be843bSPierre Pronchery * initial state. 91*e7be843bSPierre Pronchery */ 92*e7be843bSPierre Pronchery QUIC_TXPIM_PKT *ossl_quic_txpim_pkt_alloc(QUIC_TXPIM *txpim); 93*e7be843bSPierre Pronchery 94*e7be843bSPierre Pronchery /* 95*e7be843bSPierre Pronchery * Releases the TXPIM packet, returning it to the pool. 96*e7be843bSPierre Pronchery */ 97*e7be843bSPierre Pronchery void ossl_quic_txpim_pkt_release(QUIC_TXPIM *txpim, QUIC_TXPIM_PKT *fpkt); 98*e7be843bSPierre Pronchery 99*e7be843bSPierre Pronchery /* Clears the chunk list of the packet, removing all entries. */ 100*e7be843bSPierre Pronchery void ossl_quic_txpim_pkt_clear_chunks(QUIC_TXPIM_PKT *fpkt); 101*e7be843bSPierre Pronchery 102*e7be843bSPierre Pronchery /* Appends a chunk to the packet. The structure is copied. */ 103*e7be843bSPierre Pronchery int ossl_quic_txpim_pkt_append_chunk(QUIC_TXPIM_PKT *fpkt, 104*e7be843bSPierre Pronchery const QUIC_TXPIM_CHUNK *chunk); 105*e7be843bSPierre Pronchery 106*e7be843bSPierre Pronchery /* Adds a CFQ item to the packet by prepending it to the retx_head list. */ 107*e7be843bSPierre Pronchery void ossl_quic_txpim_pkt_add_cfq_item(QUIC_TXPIM_PKT *fpkt, 108*e7be843bSPierre Pronchery QUIC_CFQ_ITEM *item); 109*e7be843bSPierre Pronchery 110*e7be843bSPierre Pronchery /* 111*e7be843bSPierre Pronchery * Returns a pointer to an array of stream chunk information structures for the 112*e7be843bSPierre Pronchery * given packet. The caller must call ossl_quic_txpim_pkt_get_num_chunks() to 113*e7be843bSPierre Pronchery * determine the length of this array. The returned pointer is invalidated 114*e7be843bSPierre Pronchery * if the chunk list is mutated, for example via a call to 115*e7be843bSPierre Pronchery * ossl_quic_txpim_pkt_append_chunk() or ossl_quic_txpim_pkt_clear_chunks(). 116*e7be843bSPierre Pronchery * 117*e7be843bSPierre Pronchery * The chunks are sorted by (stream_id, start) in ascending order. 118*e7be843bSPierre Pronchery */ 119*e7be843bSPierre Pronchery const QUIC_TXPIM_CHUNK *ossl_quic_txpim_pkt_get_chunks(const QUIC_TXPIM_PKT *fpkt); 120*e7be843bSPierre Pronchery 121*e7be843bSPierre Pronchery /* 122*e7be843bSPierre Pronchery * Returns the number of entries in the array returned by 123*e7be843bSPierre Pronchery * ossl_quic_txpim_pkt_get_chunks(). 124*e7be843bSPierre Pronchery */ 125*e7be843bSPierre Pronchery size_t ossl_quic_txpim_pkt_get_num_chunks(const QUIC_TXPIM_PKT *fpkt); 126*e7be843bSPierre Pronchery 127*e7be843bSPierre Pronchery /* 128*e7be843bSPierre Pronchery * Returns the number of QUIC_TXPIM_PKTs allocated by the given TXPIM that have 129*e7be843bSPierre Pronchery * yet to be returned to the TXPIM. 130*e7be843bSPierre Pronchery */ 131*e7be843bSPierre Pronchery size_t ossl_quic_txpim_get_in_use(const QUIC_TXPIM *txpim); 132*e7be843bSPierre Pronchery 133*e7be843bSPierre Pronchery # endif 134*e7be843bSPierre Pronchery 135*e7be843bSPierre Pronchery #endif 136