/*
* Copyright 2022-2023 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the Apache License 2.0 (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/
#include <openssl/ssl.h>
#include "internal/quic_record_rx.h"
#include "quic_record_shared.h"
#include "internal/common.h"
#include "internal/list.h"
#include "../ssl_local.h"
/*
* Mark a packet in a bitfield.
*
* pkt_idx: index of packet within datagram.
*/
static ossl_inline void pkt_mark(uint64_t *bitf, size_t pkt_idx)
{
assert(pkt_idx < QUIC_MAX_PKT_PER_URXE);
*bitf |= ((uint64_t)1) << pkt_idx;
}
/* Returns 1 if a packet is in the bitfield. */
static ossl_inline int pkt_is_marked(const uint64_t *bitf, size_t pkt_idx)
{
assert(pkt_idx < QUIC_MAX_PKT_PER_URXE);
return (*bitf & (((uint64_t)1) << pkt_idx)) != 0;
}
/*
* RXE
* ===
*
* RX Entries (RXEs) store processed (i.e., decrypted) data received from the
* network. One RXE is used per received QUIC packet.
*/
typedef struct rxe_st RXE;
struct rxe_st {
OSSL_QRX_PKT pkt;
OSSL_LIST_MEMBER(rxe, RXE);
size_t data_len, alloc_len, refcount;
/* Extra fields for per-packet information. */
QUIC_PKT_HDR hdr; /* data/len are decrypted payload */
/* Decoded packet number. */
QUIC_PN pn;
/* Addresses copied from URXE. */
BIO_ADDR peer, local;
/* Time we received the packet (not when we processed it). */
OSSL_TIME time;
/* Total length of the datagram which contained this packet. */
size_t datagram_len;
/*
* The key epoch the packet was received with. Always 0 for non-1-RTT
* packets.
*/
uint64_t key_epoch;
/*
* alloc_len allocated bytes (of which data_len bytes are valid) follow this
* structure.
*/
};
DEFINE_LIST_OF(rxe, RXE);
typedef OSSL_LIST(rxe) RXE_LIST;
static ossl_inline<