From 6d5d5fc9a9f6b701fc5e17f05d3df464fe0bc56e Mon Sep 17 00:00:00 2001 From: Hugo Landau Date: Mon, 31 Oct 2022 14:39:13 +0000 Subject: QUIC RX: Support refcounted packets and eliminate wrapper Previously, the QRX filled in a OSSL_QRX_PKT structure provided by the caller. This necessitated the caller managing reference counting itself using a OSSL_QRX_PKT_WRAP structure. The need for this structure has been eliminated by adding refcounting support to the QRX itself. The QRX now outputs a pointer to an OSSL_QRX_PKT instead of filling in a structure provided by the caller. The OSSL_QRX_PKT_WRAP structure has been eliminated. Reviewed-by: Tomas Mraz Reviewed-by: Matt Caswell (Merged from https://github.com/openssl/openssl/pull/19703) --- include/internal/quic_record_rx.h | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) (limited to 'include/internal/quic_record_rx.h') diff --git a/include/internal/quic_record_rx.h b/include/internal/quic_record_rx.h index 53b7b7f458..6df4013533 100644 --- a/include/internal/quic_record_rx.h +++ b/include/internal/quic_record_rx.h @@ -197,9 +197,6 @@ int ossl_qrx_discard_enc_level(OSSL_QRX *qrx, uint32_t enc_level); /* Information about a received packet. */ typedef struct ossl_qrx_pkt_st { - /* Opaque handle to be passed to ossl_qrx_release_pkt. */ - void *handle; - /* * Points to a logical representation of the decoded QUIC packet header. The * data and len fields point to the decrypted QUIC payload (i.e., to a @@ -236,26 +233,35 @@ typedef struct ossl_qrx_pkt_st { * using a now() function. */ OSSL_TIME time; + + /* The QRX which was used to receive the packet. */ + OSSL_QRX *qrx; } OSSL_QRX_PKT; /* * Tries to read a new decrypted packet from the QRX. * - * On success, all fields of *pkt are filled and 1 is returned. - * Else, returns 0. + * On success, *pkt points to a OSSL_QRX_PKT structure. The structure should be + * freed when no longer needed by calling ossl_qrx_pkt_release(). The structure + * is refcounted; to gain extra references, call ossl_qrx_pkt_ref(). This will + * cause a corresponding number of calls to ossl_qrx_pkt_release() to be + * ignored. + * + * The resources referenced by (*pkt)->hdr, (*pkt)->hdr->data and (*pkt)->peer + * have the same lifetime as *pkt. * - * The resources referenced by pkt->hdr, pkt->hdr->data and pkt->peer will - * remain allocated at least until the user frees them by calling - * ossl_qrx_release_pkt, which must be called once you are done with the packet. + * Returns 1 on success and 0 on failure. */ -int ossl_qrx_read_pkt(OSSL_QRX *qrx, OSSL_QRX_PKT *pkt); +int ossl_qrx_read_pkt(OSSL_QRX *qrx, OSSL_QRX_PKT **pkt); /* - * Release the resources pointed to by an OSSL_QRX_PKT returned by - * ossl_qrx_read_pkt. Pass the opaque value pkt->handle returned in the - * structure. + * Decrement the reference count for the given packet and frees it if the + * reference count drops to zero. No-op if pkt is NULL. */ -void ossl_qrx_release_pkt(OSSL_QRX *qrx, void *handle); +void ossl_qrx_pkt_release(OSSL_QRX_PKT *pkt); + +/* Increments the reference count for the given packet. */ +void ossl_qrx_pkt_up_ref(OSSL_QRX_PKT *pkt); /* * Returns 1 if there are any already processed (i.e. decrypted) packets waiting -- cgit v1.2.1