2022-07-21 16:54:48 +08:00
|
|
|
/*
|
|
|
|
* Copyright 2022 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
|
|
|
|
*/
|
|
|
|
|
2022-11-11 23:18:48 +08:00
|
|
|
#include "internal/packet_quic.h"
|
2022-07-21 16:54:48 +08:00
|
|
|
#include "internal/nelem.h"
|
|
|
|
#include "internal/quic_wire.h"
|
|
|
|
#include "internal/quic_record_rx.h"
|
|
|
|
#include "internal/quic_ackm.h"
|
|
|
|
#include "internal/quic_rx_depack.h"
|
2022-10-27 00:35:04 +08:00
|
|
|
#include "internal/quic_error.h"
|
|
|
|
#include "internal/quic_fc.h"
|
2022-11-17 23:26:39 +08:00
|
|
|
#include "internal/quic_channel.h"
|
2022-10-05 16:20:35 +08:00
|
|
|
#include "internal/sockets.h"
|
2022-07-21 16:54:48 +08:00
|
|
|
|
|
|
|
#include "quic_local.h"
|
2022-11-17 23:26:39 +08:00
|
|
|
#include "quic_channel_local.h"
|
2022-07-21 16:54:48 +08:00
|
|
|
#include "../ssl_local.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Helper functions to process different frame types.
|
|
|
|
*
|
|
|
|
* Typically, those that are ACK eliciting will take an OSSL_ACKM_RX_PKT
|
|
|
|
* pointer argument, the few that aren't ACK eliciting will not. This makes
|
|
|
|
* them a verifiable pattern against tables where this is specified.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int depack_do_frame_padding(PACKET *pkt)
|
|
|
|
{
|
|
|
|
/* We ignore this frame */
|
2022-11-17 23:26:39 +08:00
|
|
|
ossl_quic_wire_decode_padding(pkt);
|
|
|
|
return 1;
|
2022-07-21 16:54:48 +08:00
|
|
|
}
|
|
|
|
|
2022-11-17 23:26:39 +08:00
|
|
|
static int depack_do_frame_ping(PACKET *pkt, QUIC_CHANNEL *ch,
|
|
|
|
OSSL_ACKM_RX_PKT *ackm_data)
|
2022-07-21 16:54:48 +08:00
|
|
|
{
|
|
|
|
/* We ignore this frame, apart from eliciting an ACK */
|
2022-11-17 23:26:39 +08:00
|
|
|
if (!ossl_quic_wire_decode_frame_ping(pkt)) {
|
|
|
|
ossl_quic_channel_raise_protocol_error(ch,
|
|
|
|
QUIC_ERR_FRAME_ENCODING_ERROR,
|
|
|
|
OSSL_QUIC_FRAME_TYPE_PING,
|
|
|
|
"decode error");
|
2022-07-21 16:54:48 +08:00
|
|
|
return 0;
|
2022-11-17 23:26:39 +08:00
|
|
|
}
|
|
|
|
|
2022-07-21 16:54:48 +08:00
|
|
|
/* This frame makes the packet ACK eliciting */
|
|
|
|
ackm_data->is_ack_eliciting = 1;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2022-11-17 23:26:39 +08:00
|
|
|
static int depack_do_frame_ack(PACKET *pkt, QUIC_CHANNEL *ch,
|
|
|
|
int packet_space, OSSL_TIME received,
|
|
|
|
uint64_t frame_type)
|
2022-07-21 16:54:48 +08:00
|
|
|
{
|
|
|
|
OSSL_QUIC_FRAME_ACK ack;
|
2022-11-17 23:26:39 +08:00
|
|
|
OSSL_QUIC_ACK_RANGE *ack_ranges = NULL;
|
2022-07-21 16:54:48 +08:00
|
|
|
uint64_t total_ranges = 0;
|
2022-11-17 23:26:39 +08:00
|
|
|
uint32_t ack_delay_exp = ch->rx_ack_delay_exp;
|
2022-07-21 16:54:48 +08:00
|
|
|
|
|
|
|
if (!ossl_quic_wire_peek_frame_ack_num_ranges(pkt, &total_ranges)
|
2022-10-05 16:52:59 +08:00
|
|
|
/* In case sizeof(uint64_t) > sizeof(size_t) */
|
|
|
|
|| total_ranges > SIZE_MAX / sizeof(ack_ranges[0])
|
2022-07-21 16:54:48 +08:00
|
|
|
|| (ack_ranges = OPENSSL_zalloc(sizeof(ack_ranges[0])
|
2022-10-05 16:52:59 +08:00
|
|
|
* (size_t)total_ranges)) == NULL)
|
2022-11-17 23:26:39 +08:00
|
|
|
goto malformed;
|
2022-07-21 16:54:48 +08:00
|
|
|
|
|
|
|
ack.ack_ranges = ack_ranges;
|
2022-10-05 16:52:59 +08:00
|
|
|
ack.num_ack_ranges = (size_t)total_ranges;
|
2022-07-21 16:54:48 +08:00
|
|
|
|
|
|
|
if (!ossl_quic_wire_decode_frame_ack(pkt, ack_delay_exp, &ack, NULL))
|
2022-11-17 23:26:39 +08:00
|
|
|
goto malformed;
|
|
|
|
|
|
|
|
if (!ossl_ackm_on_rx_ack_frame(ch->ackm, &ack,
|
|
|
|
packet_space, received))
|
|
|
|
goto malformed;
|
2022-07-21 16:54:48 +08:00
|
|
|
|
|
|
|
OPENSSL_free(ack_ranges);
|
|
|
|
return 1;
|
2022-11-17 23:26:39 +08:00
|
|
|
|
|
|
|
malformed:
|
|
|
|
ossl_quic_channel_raise_protocol_error(ch,
|
|
|
|
QUIC_ERR_FRAME_ENCODING_ERROR,
|
|
|
|
frame_type,
|
|
|
|
"decode error");
|
|
|
|
OPENSSL_free(ack_ranges);
|
|
|
|
return 0;
|
2022-07-21 16:54:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int depack_do_frame_reset_stream(PACKET *pkt,
|
2022-11-17 23:26:39 +08:00
|
|
|
QUIC_CHANNEL *ch,
|
2022-07-21 16:54:48 +08:00
|
|
|
OSSL_ACKM_RX_PKT *ackm_data)
|
|
|
|
{
|
|
|
|
OSSL_QUIC_FRAME_RESET_STREAM frame_data;
|
|
|
|
QUIC_STREAM *stream = NULL;
|
|
|
|
|
2022-11-17 23:26:39 +08:00
|
|
|
if (!ossl_quic_wire_decode_frame_reset_stream(pkt, &frame_data)) {
|
|
|
|
ossl_quic_channel_raise_protocol_error(ch,
|
|
|
|
QUIC_ERR_FRAME_ENCODING_ERROR,
|
|
|
|
OSSL_QUIC_FRAME_TYPE_RESET_STREAM,
|
|
|
|
"decode error");
|
2022-07-21 16:54:48 +08:00
|
|
|
return 0;
|
2022-11-17 23:26:39 +08:00
|
|
|
}
|
2022-07-21 16:54:48 +08:00
|
|
|
|
|
|
|
/* This frame makes the packet ACK eliciting */
|
|
|
|
ackm_data->is_ack_eliciting = 1;
|
|
|
|
|
2022-11-17 23:26:39 +08:00
|
|
|
stream = ossl_quic_stream_map_get_by_id(&ch->qsm, frame_data.stream_id);
|
2022-12-15 15:07:12 +08:00
|
|
|
if (stream == NULL) {
|
2022-11-17 23:26:39 +08:00
|
|
|
ossl_quic_channel_raise_protocol_error(ch,
|
|
|
|
QUIC_ERR_STREAM_STATE_ERROR,
|
|
|
|
OSSL_QUIC_FRAME_TYPE_RESET_STREAM,
|
2022-12-15 15:07:12 +08:00
|
|
|
"RESET_STREAM frame for "
|
|
|
|
"nonexistent stream");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (stream->rstream == NULL) {
|
|
|
|
ossl_quic_channel_raise_protocol_error(ch,
|
|
|
|
QUIC_ERR_STREAM_STATE_ERROR,
|
|
|
|
OSSL_QUIC_FRAME_TYPE_RESET_STREAM,
|
|
|
|
"RESET_STREAM frame for "
|
2022-11-17 23:26:39 +08:00
|
|
|
"TX only stream");
|
2022-07-21 16:54:48 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2022-11-17 23:26:39 +08:00
|
|
|
|
|
|
|
stream->peer_reset_stream = 1;
|
|
|
|
ossl_quic_stream_map_update_state(&ch->qsm, stream);
|
2022-07-21 16:54:48 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int depack_do_frame_stop_sending(PACKET *pkt,
|
2022-11-17 23:26:39 +08:00
|
|
|
QUIC_CHANNEL *ch,
|
2022-07-21 16:54:48 +08:00
|
|
|
OSSL_ACKM_RX_PKT *ackm_data)
|
|
|
|
{
|
|
|
|
OSSL_QUIC_FRAME_STOP_SENDING frame_data;
|
|
|
|
QUIC_STREAM *stream = NULL;
|
|
|
|
|
2022-11-17 23:26:39 +08:00
|
|
|
if (!ossl_quic_wire_decode_frame_stop_sending(pkt, &frame_data)) {
|
|
|
|
ossl_quic_channel_raise_protocol_error(ch,
|
|
|
|
QUIC_ERR_FRAME_ENCODING_ERROR,
|
|
|
|
OSSL_QUIC_FRAME_TYPE_STOP_SENDING,
|
|
|
|
"decode error");
|
2022-07-21 16:54:48 +08:00
|
|
|
return 0;
|
2022-11-17 23:26:39 +08:00
|
|
|
}
|
2022-07-21 16:54:48 +08:00
|
|
|
|
|
|
|
/* This frame makes the packet ACK eliciting */
|
|
|
|
ackm_data->is_ack_eliciting = 1;
|
|
|
|
|
2022-11-17 23:26:39 +08:00
|
|
|
stream = ossl_quic_stream_map_get_by_id(&ch->qsm, frame_data.stream_id);
|
2022-12-15 15:07:12 +08:00
|
|
|
if (stream == NULL) {
|
|
|
|
ossl_quic_channel_raise_protocol_error(ch,
|
|
|
|
QUIC_ERR_STREAM_STATE_ERROR,
|
|
|
|
OSSL_QUIC_FRAME_TYPE_STOP_SENDING,
|
|
|
|
"STOP_SENDING frame for "
|
|
|
|
"nonexistent stream");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (stream->sstream == NULL) {
|
2022-11-17 23:26:39 +08:00
|
|
|
ossl_quic_channel_raise_protocol_error(ch,
|
|
|
|
QUIC_ERR_STREAM_STATE_ERROR,
|
|
|
|
OSSL_QUIC_FRAME_TYPE_STOP_SENDING,
|
2022-12-15 15:07:12 +08:00
|
|
|
"STOP_SENDING frame for "
|
2022-11-17 23:26:39 +08:00
|
|
|
"RX only stream");
|
2022-07-21 16:54:48 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2022-11-17 23:26:39 +08:00
|
|
|
|
|
|
|
stream->peer_stop_sending = 1;
|
|
|
|
ossl_quic_stream_map_update_state(&ch->qsm, stream);
|
2022-07-21 16:54:48 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2022-11-17 23:26:39 +08:00
|
|
|
static int depack_do_frame_crypto(PACKET *pkt, QUIC_CHANNEL *ch,
|
|
|
|
OSSL_QRX_PKT *parent_pkt,
|
2022-07-21 16:54:48 +08:00
|
|
|
OSSL_ACKM_RX_PKT *ackm_data)
|
|
|
|
{
|
2022-11-17 23:26:39 +08:00
|
|
|
OSSL_QUIC_FRAME_CRYPTO f;
|
|
|
|
QUIC_RSTREAM *rstream;
|
|
|
|
|
|
|
|
if (!ossl_quic_wire_decode_frame_crypto(pkt, &f)) {
|
|
|
|
ossl_quic_channel_raise_protocol_error(ch,
|
|
|
|
QUIC_ERR_FRAME_ENCODING_ERROR,
|
|
|
|
OSSL_QUIC_FRAME_TYPE_CRYPTO,
|
|
|
|
"decode error");
|
2022-07-21 16:54:48 +08:00
|
|
|
return 0;
|
2022-11-17 23:26:39 +08:00
|
|
|
}
|
2022-07-21 16:54:48 +08:00
|
|
|
|
|
|
|
/* This frame makes the packet ACK eliciting */
|
|
|
|
ackm_data->is_ack_eliciting = 1;
|
|
|
|
|
2022-11-17 23:26:39 +08:00
|
|
|
rstream = ch->crypto_recv[ackm_data->pkt_space];
|
|
|
|
if (!ossl_assert(rstream != NULL))
|
|
|
|
/*
|
|
|
|
* This should not happen; we should only have a NULL stream here if
|
|
|
|
* the EL has been discarded, and if the EL has been discarded we
|
|
|
|
* shouldn't be here.
|
|
|
|
*/
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (!ossl_quic_rstream_queue_data(rstream, parent_pkt,
|
|
|
|
f.offset, f.data, f.len, 0))
|
|
|
|
return 0;
|
2022-07-21 16:54:48 +08:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2022-11-17 23:26:39 +08:00
|
|
|
static int depack_do_frame_new_token(PACKET *pkt, QUIC_CHANNEL *ch,
|
2022-07-21 16:54:48 +08:00
|
|
|
OSSL_ACKM_RX_PKT *ackm_data)
|
|
|
|
{
|
|
|
|
const uint8_t *token;
|
|
|
|
size_t token_len;
|
|
|
|
|
2022-11-17 23:26:39 +08:00
|
|
|
if (!ossl_quic_wire_decode_frame_new_token(pkt, &token, &token_len)) {
|
|
|
|
ossl_quic_channel_raise_protocol_error(ch,
|
|
|
|
QUIC_ERR_FRAME_ENCODING_ERROR,
|
|
|
|
OSSL_QUIC_FRAME_TYPE_NEW_TOKEN,
|
|
|
|
"decode error");
|
2022-07-21 16:54:48 +08:00
|
|
|
return 0;
|
2022-11-17 23:26:39 +08:00
|
|
|
}
|
2022-07-21 16:54:48 +08:00
|
|
|
|
|
|
|
/* This frame makes the packet ACK eliciting */
|
|
|
|
ackm_data->is_ack_eliciting = 1;
|
|
|
|
|
|
|
|
/* TODO(QUIC): ADD CODE to send |token| to the session manager */
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2022-11-17 23:26:39 +08:00
|
|
|
static int depack_do_frame_stream(PACKET *pkt, QUIC_CHANNEL *ch,
|
2022-10-31 22:39:13 +08:00
|
|
|
OSSL_QRX_PKT *parent_pkt,
|
2022-11-17 23:26:39 +08:00
|
|
|
OSSL_ACKM_RX_PKT *ackm_data,
|
|
|
|
uint64_t frame_type)
|
2022-07-21 16:54:48 +08:00
|
|
|
{
|
|
|
|
OSSL_QUIC_FRAME_STREAM frame_data;
|
|
|
|
QUIC_STREAM *stream;
|
2022-11-17 23:26:39 +08:00
|
|
|
uint64_t fce;
|
2022-07-21 16:54:48 +08:00
|
|
|
|
2022-11-17 23:26:39 +08:00
|
|
|
if (!ossl_quic_wire_decode_frame_stream(pkt, &frame_data)) {
|
|
|
|
ossl_quic_channel_raise_protocol_error(ch,
|
|
|
|
QUIC_ERR_FRAME_ENCODING_ERROR,
|
|
|
|
frame_type,
|
|
|
|
"decode error");
|
2022-07-21 16:54:48 +08:00
|
|
|
return 0;
|
2022-11-17 23:26:39 +08:00
|
|
|
}
|
2022-07-21 16:54:48 +08:00
|
|
|
|
|
|
|
/* This frame makes the packet ACK eliciting */
|
|
|
|
ackm_data->is_ack_eliciting = 1;
|
|
|
|
|
2022-11-17 23:26:39 +08:00
|
|
|
stream = ossl_quic_stream_map_get_by_id(&ch->qsm, frame_data.stream_id);
|
2022-12-15 15:07:12 +08:00
|
|
|
if (stream == NULL) {
|
2022-11-17 23:26:39 +08:00
|
|
|
ossl_quic_channel_raise_protocol_error(ch,
|
|
|
|
QUIC_ERR_STREAM_STATE_ERROR,
|
|
|
|
frame_type,
|
2022-12-15 15:07:12 +08:00
|
|
|
"STREAM frame for nonexistent "
|
|
|
|
"stream");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (stream->rstream == NULL) {
|
|
|
|
ossl_quic_channel_raise_protocol_error(ch,
|
|
|
|
QUIC_ERR_STREAM_STATE_ERROR,
|
|
|
|
frame_type,
|
|
|
|
"STREAM frame for TX only "
|
|
|
|
"stream");
|
2022-11-17 23:26:39 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Notify stream flow controller. */
|
|
|
|
if (!ossl_quic_rxfc_on_rx_stream_frame(&stream->rxfc,
|
|
|
|
frame_data.offset + frame_data.len,
|
|
|
|
frame_data.is_fin)) {
|
|
|
|
ossl_quic_channel_raise_protocol_error(ch,
|
|
|
|
QUIC_ERR_INTERNAL_ERROR,
|
|
|
|
frame_type,
|
|
|
|
"internal error (flow control)");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Has a flow control error occurred? */
|
|
|
|
fce = ossl_quic_rxfc_get_error(&stream->rxfc, 0);
|
|
|
|
if (fce != QUIC_ERR_NO_ERROR) {
|
|
|
|
ossl_quic_channel_raise_protocol_error(ch,
|
|
|
|
fce,
|
|
|
|
frame_type,
|
|
|
|
"flow control violation");
|
2022-07-21 16:54:48 +08:00
|
|
|
return 0;
|
2022-11-17 23:26:39 +08:00
|
|
|
}
|
|
|
|
|
2022-07-21 16:54:48 +08:00
|
|
|
/*
|
2022-11-17 23:26:39 +08:00
|
|
|
* The receive stream buffer may or may not choose to consume the data
|
|
|
|
* without copying by reffing the OSSL_QRX_PKT. In this case
|
|
|
|
* ossl_qrx_pkt_release() will be eventually called when the data is no
|
|
|
|
* longer needed.
|
2022-07-21 16:54:48 +08:00
|
|
|
*/
|
2022-11-17 23:26:39 +08:00
|
|
|
if (!ossl_quic_rstream_queue_data(stream->rstream, parent_pkt,
|
|
|
|
frame_data.offset,
|
|
|
|
frame_data.data,
|
|
|
|
frame_data.len,
|
|
|
|
frame_data.is_fin))
|
2022-07-21 16:54:48 +08:00
|
|
|
return 0;
|
2022-11-17 23:26:39 +08:00
|
|
|
|
2022-07-21 16:54:48 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2022-11-17 23:26:39 +08:00
|
|
|
static int depack_do_frame_max_data(PACKET *pkt, QUIC_CHANNEL *ch,
|
2022-07-21 16:54:48 +08:00
|
|
|
OSSL_ACKM_RX_PKT *ackm_data)
|
|
|
|
{
|
|
|
|
uint64_t max_data = 0;
|
|
|
|
|
2022-11-17 23:26:39 +08:00
|
|
|
if (!ossl_quic_wire_decode_frame_max_data(pkt, &max_data)) {
|
|
|
|
ossl_quic_channel_raise_protocol_error(ch,
|
|
|
|
QUIC_ERR_FRAME_ENCODING_ERROR,
|
|
|
|
OSSL_QUIC_FRAME_TYPE_MAX_DATA,
|
|
|
|
"decode error");
|
2022-07-21 16:54:48 +08:00
|
|
|
return 0;
|
2022-11-17 23:26:39 +08:00
|
|
|
}
|
2022-07-21 16:54:48 +08:00
|
|
|
|
|
|
|
/* This frame makes the packet ACK eliciting */
|
|
|
|
ackm_data->is_ack_eliciting = 1;
|
|
|
|
|
2022-11-17 23:26:39 +08:00
|
|
|
ossl_quic_txfc_bump_cwm(&ch->conn_txfc, max_data);
|
|
|
|
ossl_quic_stream_map_update_state(&ch->qsm, ch->stream0);
|
2022-07-21 16:54:48 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int depack_do_frame_max_stream_data(PACKET *pkt,
|
2022-11-17 23:26:39 +08:00
|
|
|
QUIC_CHANNEL *ch,
|
2022-07-21 16:54:48 +08:00
|
|
|
OSSL_ACKM_RX_PKT *ackm_data)
|
|
|
|
{
|
|
|
|
uint64_t stream_id = 0;
|
|
|
|
uint64_t max_stream_data = 0;
|
2022-11-17 23:26:39 +08:00
|
|
|
QUIC_STREAM *stream;
|
2022-07-21 16:54:48 +08:00
|
|
|
|
|
|
|
if (!ossl_quic_wire_decode_frame_max_stream_data(pkt, &stream_id,
|
2022-11-17 23:26:39 +08:00
|
|
|
&max_stream_data)) {
|
|
|
|
ossl_quic_channel_raise_protocol_error(ch,
|
|
|
|
QUIC_ERR_FRAME_ENCODING_ERROR,
|
|
|
|
OSSL_QUIC_FRAME_TYPE_MAX_STREAM_DATA,
|
|
|
|
"decode error");
|
2022-07-21 16:54:48 +08:00
|
|
|
return 0;
|
2022-11-17 23:26:39 +08:00
|
|
|
}
|
2022-07-21 16:54:48 +08:00
|
|
|
|
|
|
|
/* This frame makes the packet ACK eliciting */
|
|
|
|
ackm_data->is_ack_eliciting = 1;
|
|
|
|
|
2022-11-17 23:26:39 +08:00
|
|
|
stream = ossl_quic_stream_map_get_by_id(&ch->qsm, stream_id);
|
2022-12-15 15:07:12 +08:00
|
|
|
if (stream == NULL) {
|
|
|
|
ossl_quic_channel_raise_protocol_error(ch,
|
|
|
|
QUIC_ERR_STREAM_STATE_ERROR,
|
|
|
|
OSSL_QUIC_FRAME_TYPE_MAX_STREAM_DATA,
|
|
|
|
"MAX_STREAM_DATA for nonexistent "
|
|
|
|
"stream");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (stream->sstream == NULL) {
|
2022-11-17 23:26:39 +08:00
|
|
|
ossl_quic_channel_raise_protocol_error(ch,
|
|
|
|
QUIC_ERR_STREAM_STATE_ERROR,
|
|
|
|
OSSL_QUIC_FRAME_TYPE_MAX_STREAM_DATA,
|
2022-12-15 15:07:12 +08:00
|
|
|
"MAX_STREAM_DATA for TX only "
|
|
|
|
"stream");
|
2022-11-17 23:26:39 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2022-07-21 16:54:48 +08:00
|
|
|
|
2022-11-17 23:26:39 +08:00
|
|
|
ossl_quic_txfc_bump_cwm(&stream->txfc, max_stream_data);
|
|
|
|
ossl_quic_stream_map_update_state(&ch->qsm, stream);
|
2022-07-21 16:54:48 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int depack_do_frame_max_streams(PACKET *pkt,
|
2022-11-17 23:26:39 +08:00
|
|
|
QUIC_CHANNEL *ch,
|
|
|
|
OSSL_ACKM_RX_PKT *ackm_data,
|
|
|
|
uint64_t frame_type)
|
2022-07-21 16:54:48 +08:00
|
|
|
{
|
|
|
|
uint64_t max_streams = 0;
|
|
|
|
|
2022-11-17 23:26:39 +08:00
|
|
|
if (!ossl_quic_wire_decode_frame_max_streams(pkt, &max_streams)) {
|
|
|
|
ossl_quic_channel_raise_protocol_error(ch,
|
|
|
|
QUIC_ERR_FRAME_ENCODING_ERROR,
|
|
|
|
frame_type,
|
|
|
|
"decode error");
|
2022-07-21 16:54:48 +08:00
|
|
|
return 0;
|
2022-11-17 23:26:39 +08:00
|
|
|
}
|
2022-07-21 16:54:48 +08:00
|
|
|
|
|
|
|
/* This frame makes the packet ACK eliciting */
|
|
|
|
ackm_data->is_ack_eliciting = 1;
|
|
|
|
|
2022-11-17 23:26:39 +08:00
|
|
|
if (max_streams > (((uint64_t)1) << 60)) {
|
|
|
|
ossl_quic_channel_raise_protocol_error(ch,
|
|
|
|
QUIC_ERR_FRAME_ENCODING_ERROR,
|
|
|
|
frame_type,
|
|
|
|
"invalid max streams value");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (frame_type) {
|
2023-01-09 19:17:42 +08:00
|
|
|
case OSSL_QUIC_FRAME_TYPE_MAX_STREAMS_BIDI:
|
|
|
|
if (max_streams > ch->max_local_streams_bidi)
|
|
|
|
ch->max_local_streams_bidi = max_streams;
|
|
|
|
|
|
|
|
/* Stream may now be able to send */
|
|
|
|
ossl_quic_stream_map_update_state(&ch->qsm,
|
|
|
|
ch->stream0);
|
|
|
|
break;
|
|
|
|
case OSSL_QUIC_FRAME_TYPE_MAX_STREAMS_UNI:
|
|
|
|
if (max_streams > ch->max_local_streams_uni)
|
|
|
|
ch->max_local_streams_uni = max_streams;
|
|
|
|
|
|
|
|
/* Stream may now be able to send */
|
|
|
|
ossl_quic_stream_map_update_state(&ch->qsm,
|
|
|
|
ch->stream0);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ossl_quic_channel_raise_protocol_error(ch,
|
|
|
|
QUIC_ERR_FRAME_ENCODING_ERROR,
|
|
|
|
frame_type,
|
|
|
|
"decode error");
|
|
|
|
return 0;
|
2022-11-17 23:26:39 +08:00
|
|
|
}
|
2022-07-21 16:54:48 +08:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int depack_do_frame_data_blocked(PACKET *pkt,
|
2022-11-17 23:26:39 +08:00
|
|
|
QUIC_CHANNEL *ch,
|
2022-07-21 16:54:48 +08:00
|
|
|
OSSL_ACKM_RX_PKT *ackm_data)
|
|
|
|
{
|
|
|
|
uint64_t max_data = 0;
|
|
|
|
|
2022-11-17 23:26:39 +08:00
|
|
|
if (!ossl_quic_wire_decode_frame_data_blocked(pkt, &max_data)) {
|
|
|
|
ossl_quic_channel_raise_protocol_error(ch,
|
|
|
|
QUIC_ERR_FRAME_ENCODING_ERROR,
|
|
|
|
OSSL_QUIC_FRAME_TYPE_DATA_BLOCKED,
|
|
|
|
"decode error");
|
2022-07-21 16:54:48 +08:00
|
|
|
return 0;
|
2022-11-17 23:26:39 +08:00
|
|
|
}
|
2022-07-21 16:54:48 +08:00
|
|
|
|
|
|
|
/* This frame makes the packet ACK eliciting */
|
|
|
|
ackm_data->is_ack_eliciting = 1;
|
|
|
|
|
2022-11-01 22:38:07 +08:00
|
|
|
/* No-op - informative/debugging frame. */
|
2022-07-21 16:54:48 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int depack_do_frame_stream_data_blocked(PACKET *pkt,
|
2022-11-17 23:26:39 +08:00
|
|
|
QUIC_CHANNEL *ch,
|
2022-07-21 16:54:48 +08:00
|
|
|
OSSL_ACKM_RX_PKT *ackm_data)
|
|
|
|
{
|
|
|
|
uint64_t stream_id = 0;
|
|
|
|
uint64_t max_data = 0;
|
|
|
|
|
|
|
|
if (!ossl_quic_wire_decode_frame_stream_data_blocked(pkt, &stream_id,
|
2022-11-17 23:26:39 +08:00
|
|
|
&max_data)) {
|
|
|
|
ossl_quic_channel_raise_protocol_error(ch,
|
|
|
|
QUIC_ERR_FRAME_ENCODING_ERROR,
|
|
|
|
OSSL_QUIC_FRAME_TYPE_STREAM_DATA_BLOCKED,
|
|
|
|
"decode error");
|
2022-07-21 16:54:48 +08:00
|
|
|
return 0;
|
2022-11-17 23:26:39 +08:00
|
|
|
}
|
2022-07-21 16:54:48 +08:00
|
|
|
|
|
|
|
/* This frame makes the packet ACK eliciting */
|
|
|
|
ackm_data->is_ack_eliciting = 1;
|
|
|
|
|
2022-11-17 23:26:39 +08:00
|
|
|
/* No-op - informative/debugging frame. */
|
2022-07-21 16:54:48 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int depack_do_frame_streams_blocked(PACKET *pkt,
|
2022-11-17 23:26:39 +08:00
|
|
|
QUIC_CHANNEL *ch,
|
|
|
|
OSSL_ACKM_RX_PKT *ackm_data,
|
|
|
|
uint64_t frame_type)
|
2022-07-21 16:54:48 +08:00
|
|
|
{
|
|
|
|
uint64_t max_data = 0;
|
|
|
|
|
2022-11-17 23:26:39 +08:00
|
|
|
if (!ossl_quic_wire_decode_frame_streams_blocked(pkt, &max_data)) {
|
|
|
|
ossl_quic_channel_raise_protocol_error(ch,
|
|
|
|
QUIC_ERR_FRAME_ENCODING_ERROR,
|
|
|
|
frame_type,
|
|
|
|
"decode error");
|
2022-07-21 16:54:48 +08:00
|
|
|
return 0;
|
2022-11-17 23:26:39 +08:00
|
|
|
}
|
2022-07-21 16:54:48 +08:00
|
|
|
|
|
|
|
/* This frame makes the packet ACK eliciting */
|
|
|
|
ackm_data->is_ack_eliciting = 1;
|
|
|
|
|
2022-11-01 22:38:07 +08:00
|
|
|
/* No-op - informative/debugging frame. */
|
2022-07-21 16:54:48 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int depack_do_frame_new_conn_id(PACKET *pkt,
|
2022-11-17 23:26:39 +08:00
|
|
|
QUIC_CHANNEL *ch,
|
2022-07-21 16:54:48 +08:00
|
|
|
OSSL_ACKM_RX_PKT *ackm_data)
|
|
|
|
{
|
|
|
|
OSSL_QUIC_FRAME_NEW_CONN_ID frame_data;
|
|
|
|
|
2022-11-17 23:26:39 +08:00
|
|
|
if (!ossl_quic_wire_decode_frame_new_conn_id(pkt, &frame_data)) {
|
|
|
|
ossl_quic_channel_raise_protocol_error(ch,
|
|
|
|
QUIC_ERR_FRAME_ENCODING_ERROR,
|
|
|
|
OSSL_QUIC_FRAME_TYPE_NEW_CONN_ID,
|
|
|
|
"decode error");
|
2022-07-21 16:54:48 +08:00
|
|
|
return 0;
|
2022-11-17 23:26:39 +08:00
|
|
|
}
|
2022-07-21 16:54:48 +08:00
|
|
|
|
|
|
|
/* This frame makes the packet ACK eliciting */
|
|
|
|
ackm_data->is_ack_eliciting = 1;
|
|
|
|
|
2022-11-17 23:26:39 +08:00
|
|
|
/* TODO(QUIC): ADD CODE to send |frame_data.data| to the ch manager */
|
2022-07-21 16:54:48 +08:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int depack_do_frame_retire_conn_id(PACKET *pkt,
|
2022-11-17 23:26:39 +08:00
|
|
|
QUIC_CHANNEL *ch,
|
2022-07-21 16:54:48 +08:00
|
|
|
OSSL_ACKM_RX_PKT *ackm_data)
|
|
|
|
{
|
|
|
|
uint64_t seq_num;
|
|
|
|
|
2022-11-17 23:26:39 +08:00
|
|
|
if (!ossl_quic_wire_decode_frame_retire_conn_id(pkt, &seq_num)) {
|
|
|
|
ossl_quic_channel_raise_protocol_error(ch,
|
|
|
|
QUIC_ERR_FRAME_ENCODING_ERROR,
|
|
|
|
OSSL_QUIC_FRAME_TYPE_RETIRE_CONN_ID,
|
|
|
|
"decode error");
|
2022-07-21 16:54:48 +08:00
|
|
|
return 0;
|
2022-11-17 23:26:39 +08:00
|
|
|
}
|
2022-07-21 16:54:48 +08:00
|
|
|
|
|
|
|
/* This frame makes the packet ACK eliciting */
|
|
|
|
ackm_data->is_ack_eliciting = 1;
|
|
|
|
|
2022-11-17 23:26:39 +08:00
|
|
|
/* TODO(QUIC): ADD CODE to send |seq_num| to the ch manager */
|
2022-07-21 16:54:48 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int depack_do_frame_path_challenge(PACKET *pkt,
|
2022-11-17 23:26:39 +08:00
|
|
|
QUIC_CHANNEL *ch,
|
2022-07-21 16:54:48 +08:00
|
|
|
OSSL_ACKM_RX_PKT *ackm_data)
|
|
|
|
{
|
|
|
|
uint64_t frame_data = 0;
|
|
|
|
|
2022-11-17 23:26:39 +08:00
|
|
|
if (!ossl_quic_wire_decode_frame_path_challenge(pkt, &frame_data)) {
|
|
|
|
ossl_quic_channel_raise_protocol_error(ch,
|
|
|
|
QUIC_ERR_FRAME_ENCODING_ERROR,
|
|
|
|
OSSL_QUIC_FRAME_TYPE_PATH_CHALLENGE,
|
|
|
|
"decode error");
|
2022-07-21 16:54:48 +08:00
|
|
|
return 0;
|
2022-11-17 23:26:39 +08:00
|
|
|
}
|
2022-07-21 16:54:48 +08:00
|
|
|
|
|
|
|
/* This frame makes the packet ACK eliciting */
|
|
|
|
ackm_data->is_ack_eliciting = 1;
|
|
|
|
|
2022-11-17 23:26:39 +08:00
|
|
|
/* TODO(QUIC): ADD CODE to send |frame_data| to the ch manager */
|
2022-07-21 16:54:48 +08:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int depack_do_frame_path_response(PACKET *pkt,
|
2022-11-17 23:26:39 +08:00
|
|
|
QUIC_CHANNEL *ch,
|
2022-07-21 16:54:48 +08:00
|
|
|
OSSL_ACKM_RX_PKT *ackm_data)
|
|
|
|
{
|
|
|
|
uint64_t frame_data = 0;
|
|
|
|
|
2022-11-17 23:26:39 +08:00
|
|
|
if (!ossl_quic_wire_decode_frame_path_response(pkt, &frame_data)) {
|
|
|
|
ossl_quic_channel_raise_protocol_error(ch,
|
|
|
|
QUIC_ERR_FRAME_ENCODING_ERROR,
|
|
|
|
OSSL_QUIC_FRAME_TYPE_PATH_RESPONSE,
|
|
|
|
"decode error");
|
2022-07-21 16:54:48 +08:00
|
|
|
return 0;
|
2022-11-17 23:26:39 +08:00
|
|
|
}
|
2022-07-21 16:54:48 +08:00
|
|
|
|
|
|
|
/* This frame makes the packet ACK eliciting */
|
|
|
|
ackm_data->is_ack_eliciting = 1;
|
|
|
|
|
2022-11-17 23:26:39 +08:00
|
|
|
/* TODO(QUIC): ADD CODE to send |frame_data| to the ch manager */
|
2022-07-21 16:54:48 +08:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2022-11-17 23:26:39 +08:00
|
|
|
static int depack_do_frame_conn_close(PACKET *pkt, QUIC_CHANNEL *ch)
|
2022-07-21 16:54:48 +08:00
|
|
|
{
|
|
|
|
OSSL_QUIC_FRAME_CONN_CLOSE frame_data;
|
|
|
|
|
|
|
|
if (!ossl_quic_wire_decode_frame_conn_close(pkt, &frame_data))
|
|
|
|
return 0;
|
|
|
|
|
2022-11-17 23:26:39 +08:00
|
|
|
ossl_quic_channel_on_remote_conn_close(ch, &frame_data);
|
2022-07-21 16:54:48 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int depack_do_frame_handshake_done(PACKET *pkt,
|
2022-11-17 23:26:39 +08:00
|
|
|
QUIC_CHANNEL *ch,
|
2022-07-21 16:54:48 +08:00
|
|
|
OSSL_ACKM_RX_PKT *ackm_data)
|
|
|
|
{
|
|
|
|
if (!ossl_quic_wire_decode_frame_handshake_done(pkt))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* This frame makes the packet ACK eliciting */
|
|
|
|
ackm_data->is_ack_eliciting = 1;
|
|
|
|
|
2022-11-17 23:26:39 +08:00
|
|
|
ossl_quic_channel_on_handshake_confirmed(ch);
|
2022-07-21 16:54:48 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int depack_do_frame_unknown_extension(PACKET *pkt,
|
2022-11-17 23:26:39 +08:00
|
|
|
QUIC_CHANNEL *ch,
|
2022-07-21 16:54:48 +08:00
|
|
|
OSSL_ACKM_RX_PKT *ackm_data)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* According to RFC 9000, 19.21. Extension Frames, extension frames
|
|
|
|
* should be ACK eliciting. It might be over zealous to do so for
|
|
|
|
* extensions OpenSSL doesn't know how to handle, but shouldn't hurt
|
|
|
|
* either.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* This frame makes the packet ACK eliciting */
|
|
|
|
ackm_data->is_ack_eliciting = 1;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Because we have no idea how to advance to the next frame, we return 0
|
|
|
|
* everywhere, thereby stopping the depacketizing process.
|
|
|
|
*/
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Main frame processor */
|
|
|
|
|
2022-11-17 23:26:39 +08:00
|
|
|
static int depack_process_frames(QUIC_CHANNEL *ch, PACKET *pkt,
|
2022-10-31 22:39:13 +08:00
|
|
|
OSSL_QRX_PKT *parent_pkt, int packet_space,
|
2022-07-21 16:54:48 +08:00
|
|
|
OSSL_TIME received, OSSL_ACKM_RX_PKT *ackm_data)
|
|
|
|
{
|
2022-10-31 22:39:13 +08:00
|
|
|
uint32_t pkt_type = parent_pkt->hdr->type;
|
2022-08-22 14:45:26 +08:00
|
|
|
|
2022-07-21 16:54:48 +08:00
|
|
|
while (PACKET_remaining(pkt) > 0) {
|
|
|
|
uint64_t frame_type;
|
|
|
|
|
|
|
|
if (!ossl_quic_wire_peek_frame_header(pkt, &frame_type))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
switch (frame_type) {
|
|
|
|
case OSSL_QUIC_FRAME_TYPE_PING:
|
2022-08-22 14:45:26 +08:00
|
|
|
/* Allowed in all packet types */
|
2022-11-17 23:26:39 +08:00
|
|
|
if (!depack_do_frame_ping(pkt, ch, ackm_data))
|
2022-07-21 16:54:48 +08:00
|
|
|
return 0;
|
|
|
|
break;
|
|
|
|
case OSSL_QUIC_FRAME_TYPE_PADDING:
|
2022-08-22 14:45:26 +08:00
|
|
|
/* Allowed in all packet types */
|
2022-07-21 16:54:48 +08:00
|
|
|
if (!depack_do_frame_padding(pkt))
|
|
|
|
return 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case OSSL_QUIC_FRAME_TYPE_ACK_WITHOUT_ECN:
|
|
|
|
case OSSL_QUIC_FRAME_TYPE_ACK_WITH_ECN:
|
2022-08-22 14:45:26 +08:00
|
|
|
/* ACK frames are valid everywhere except in 0RTT packets */
|
2022-11-17 23:26:39 +08:00
|
|
|
if (pkt_type == QUIC_PKT_TYPE_0RTT) {
|
|
|
|
ossl_quic_channel_raise_protocol_error(ch,
|
|
|
|
QUIC_ERR_PROTOCOL_VIOLATION,
|
|
|
|
frame_type,
|
|
|
|
"ACK not valid in 0-RTT");
|
2022-08-22 14:45:26 +08:00
|
|
|
return 0;
|
2022-11-17 23:26:39 +08:00
|
|
|
}
|
|
|
|
if (!depack_do_frame_ack(pkt, ch, packet_space, received,
|
|
|
|
frame_type))
|
2022-07-21 16:54:48 +08:00
|
|
|
return 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case OSSL_QUIC_FRAME_TYPE_RESET_STREAM:
|
2022-08-22 14:45:26 +08:00
|
|
|
/* RESET_STREAM frames are valid in 0RTT and 1RTT packets */
|
|
|
|
if (pkt_type != QUIC_PKT_TYPE_0RTT
|
2022-11-17 23:26:39 +08:00
|
|
|
&& pkt_type != QUIC_PKT_TYPE_1RTT) {
|
|
|
|
ossl_quic_channel_raise_protocol_error(ch,
|
|
|
|
QUIC_ERR_PROTOCOL_VIOLATION,
|
|
|
|
frame_type,
|
|
|
|
"RESET_STREAM not valid in "
|
|
|
|
"INITIAL/HANDSHAKE");
|
2022-08-22 14:45:26 +08:00
|
|
|
return 0;
|
2022-11-17 23:26:39 +08:00
|
|
|
}
|
|
|
|
if (!depack_do_frame_reset_stream(pkt, ch, ackm_data))
|
2022-07-21 16:54:48 +08:00
|
|
|
return 0;
|
|
|
|
break;
|
|
|
|
case OSSL_QUIC_FRAME_TYPE_STOP_SENDING:
|
2022-08-22 14:45:26 +08:00
|
|
|
/* STOP_SENDING frames are valid in 0RTT and 1RTT packets */
|
|
|
|
if (pkt_type != QUIC_PKT_TYPE_0RTT
|
2022-11-17 23:26:39 +08:00
|
|
|
&& pkt_type != QUIC_PKT_TYPE_1RTT) {
|
|
|
|
ossl_quic_channel_raise_protocol_error(ch,
|
|
|
|
QUIC_ERR_PROTOCOL_VIOLATION,
|
|
|
|
frame_type,
|
|
|
|
"STOP_SENDING not valid in "
|
|
|
|
"INITIAL/HANDSHAKE");
|
2022-08-22 14:45:26 +08:00
|
|
|
return 0;
|
2022-11-17 23:26:39 +08:00
|
|
|
}
|
|
|
|
if (!depack_do_frame_stop_sending(pkt, ch, ackm_data))
|
2022-07-21 16:54:48 +08:00
|
|
|
return 0;
|
|
|
|
break;
|
|
|
|
case OSSL_QUIC_FRAME_TYPE_CRYPTO:
|
2022-08-22 14:45:26 +08:00
|
|
|
/* CRYPTO frames are valid everywhere except in 0RTT packets */
|
2022-11-17 23:26:39 +08:00
|
|
|
if (pkt_type == QUIC_PKT_TYPE_0RTT) {
|
|
|
|
ossl_quic_channel_raise_protocol_error(ch,
|
|
|
|
QUIC_ERR_PROTOCOL_VIOLATION,
|
|
|
|
frame_type,
|
|
|
|
"CRYPTO frame not valid in 0-RTT");
|
2022-08-22 14:45:26 +08:00
|
|
|
return 0;
|
2022-11-17 23:26:39 +08:00
|
|
|
}
|
|
|
|
if (!depack_do_frame_crypto(pkt, ch, parent_pkt, ackm_data))
|
2022-07-21 16:54:48 +08:00
|
|
|
return 0;
|
|
|
|
break;
|
|
|
|
case OSSL_QUIC_FRAME_TYPE_NEW_TOKEN:
|
2022-08-22 14:45:26 +08:00
|
|
|
/* NEW_TOKEN frames are valid in 1RTT packets */
|
2022-11-17 23:26:39 +08:00
|
|
|
if (pkt_type != QUIC_PKT_TYPE_1RTT) {
|
|
|
|
ossl_quic_channel_raise_protocol_error(ch,
|
|
|
|
QUIC_ERR_PROTOCOL_VIOLATION,
|
|
|
|
frame_type,
|
|
|
|
"NEW_TOKEN valid only in 1-RTT");
|
2022-08-22 14:45:26 +08:00
|
|
|
return 0;
|
2022-11-17 23:26:39 +08:00
|
|
|
}
|
|
|
|
if (!depack_do_frame_new_token(pkt, ch, ackm_data))
|
2022-07-21 16:54:48 +08:00
|
|
|
return 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case OSSL_QUIC_FRAME_TYPE_STREAM:
|
|
|
|
case OSSL_QUIC_FRAME_TYPE_STREAM_FIN:
|
|
|
|
case OSSL_QUIC_FRAME_TYPE_STREAM_LEN:
|
|
|
|
case OSSL_QUIC_FRAME_TYPE_STREAM_LEN_FIN:
|
|
|
|
case OSSL_QUIC_FRAME_TYPE_STREAM_OFF:
|
|
|
|
case OSSL_QUIC_FRAME_TYPE_STREAM_OFF_FIN:
|
|
|
|
case OSSL_QUIC_FRAME_TYPE_STREAM_OFF_LEN:
|
|
|
|
case OSSL_QUIC_FRAME_TYPE_STREAM_OFF_LEN_FIN:
|
2022-08-22 14:45:26 +08:00
|
|
|
/* STREAM frames are valid in 0RTT and 1RTT packets */
|
|
|
|
if (pkt_type != QUIC_PKT_TYPE_0RTT
|
2022-11-17 23:26:39 +08:00
|
|
|
&& pkt_type != QUIC_PKT_TYPE_1RTT) {
|
|
|
|
ossl_quic_channel_raise_protocol_error(ch,
|
|
|
|
QUIC_ERR_PROTOCOL_VIOLATION,
|
|
|
|
frame_type,
|
|
|
|
"STREAM valid only in 0/1-RTT");
|
2022-08-22 14:45:26 +08:00
|
|
|
return 0;
|
2022-11-17 23:26:39 +08:00
|
|
|
}
|
|
|
|
if (!depack_do_frame_stream(pkt, ch, parent_pkt, ackm_data,
|
|
|
|
frame_type))
|
2022-07-21 16:54:48 +08:00
|
|
|
return 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case OSSL_QUIC_FRAME_TYPE_MAX_DATA:
|
2022-08-22 14:45:26 +08:00
|
|
|
/* MAX_DATA frames are valid in 0RTT and 1RTT packets */
|
|
|
|
if (pkt_type != QUIC_PKT_TYPE_0RTT
|
2022-11-17 23:26:39 +08:00
|
|
|
&& pkt_type != QUIC_PKT_TYPE_1RTT) {
|
|
|
|
ossl_quic_channel_raise_protocol_error(ch,
|
|
|
|
QUIC_ERR_PROTOCOL_VIOLATION,
|
|
|
|
frame_type,
|
|
|
|
"MAX_DATA valid only in 0/1-RTT");
|
2022-08-22 14:45:26 +08:00
|
|
|
return 0;
|
2022-11-17 23:26:39 +08:00
|
|
|
}
|
|
|
|
if (!depack_do_frame_max_data(pkt, ch, ackm_data))
|
2022-07-21 16:54:48 +08:00
|
|
|
return 0;
|
|
|
|
break;
|
|
|
|
case OSSL_QUIC_FRAME_TYPE_MAX_STREAM_DATA:
|
2022-08-22 14:45:26 +08:00
|
|
|
/* MAX_STREAM_DATA frames are valid in 0RTT and 1RTT packets */
|
|
|
|
if (pkt_type != QUIC_PKT_TYPE_0RTT
|
2022-11-17 23:26:39 +08:00
|
|
|
&& pkt_type != QUIC_PKT_TYPE_1RTT) {
|
|
|
|
ossl_quic_channel_raise_protocol_error(ch,
|
|
|
|
QUIC_ERR_PROTOCOL_VIOLATION,
|
|
|
|
frame_type,
|
|
|
|
"MAX_STREAM_DATA valid only in 0/1-RTT");
|
2022-08-22 14:45:26 +08:00
|
|
|
return 0;
|
2022-11-17 23:26:39 +08:00
|
|
|
}
|
|
|
|
if (!depack_do_frame_max_stream_data(pkt, ch, ackm_data))
|
2022-07-21 16:54:48 +08:00
|
|
|
return 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case OSSL_QUIC_FRAME_TYPE_MAX_STREAMS_BIDI:
|
|
|
|
case OSSL_QUIC_FRAME_TYPE_MAX_STREAMS_UNI:
|
2022-08-22 14:45:26 +08:00
|
|
|
/* MAX_STREAMS frames are valid in 0RTT and 1RTT packets */
|
|
|
|
if (pkt_type != QUIC_PKT_TYPE_0RTT
|
2022-11-17 23:26:39 +08:00
|
|
|
&& pkt_type != QUIC_PKT_TYPE_1RTT) {
|
|
|
|
ossl_quic_channel_raise_protocol_error(ch,
|
|
|
|
QUIC_ERR_PROTOCOL_VIOLATION,
|
|
|
|
frame_type,
|
|
|
|
"MAX_STREAMS valid only in 0/1-RTT");
|
2022-08-22 14:45:26 +08:00
|
|
|
return 0;
|
2022-11-17 23:26:39 +08:00
|
|
|
}
|
|
|
|
if (!depack_do_frame_max_streams(pkt, ch, ackm_data,
|
|
|
|
frame_type))
|
2022-07-21 16:54:48 +08:00
|
|
|
return 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case OSSL_QUIC_FRAME_TYPE_DATA_BLOCKED:
|
2022-08-22 14:45:26 +08:00
|
|
|
/* DATA_BLOCKED frames are valid in 0RTT and 1RTT packets */
|
|
|
|
if (pkt_type != QUIC_PKT_TYPE_0RTT
|
2022-11-17 23:26:39 +08:00
|
|
|
&& pkt_type != QUIC_PKT_TYPE_1RTT) {
|
|
|
|
ossl_quic_channel_raise_protocol_error(ch,
|
|
|
|
QUIC_ERR_PROTOCOL_VIOLATION,
|
|
|
|
frame_type,
|
|
|
|
"DATA_BLOCKED valid only in 0/1-RTT");
|
2022-08-22 14:45:26 +08:00
|
|
|
return 0;
|
2022-11-17 23:26:39 +08:00
|
|
|
}
|
|
|
|
if (!depack_do_frame_data_blocked(pkt, ch, ackm_data))
|
2022-07-21 16:54:48 +08:00
|
|
|
return 0;
|
|
|
|
break;
|
|
|
|
case OSSL_QUIC_FRAME_TYPE_STREAM_DATA_BLOCKED:
|
2022-08-22 14:45:26 +08:00
|
|
|
/* STREAM_DATA_BLOCKED frames are valid in 0RTT and 1RTT packets */
|
|
|
|
if (pkt_type != QUIC_PKT_TYPE_0RTT
|
2022-11-17 23:26:39 +08:00
|
|
|
&& pkt_type != QUIC_PKT_TYPE_1RTT) {
|
|
|
|
ossl_quic_channel_raise_protocol_error(ch,
|
|
|
|
QUIC_ERR_PROTOCOL_VIOLATION,
|
|
|
|
frame_type,
|
|
|
|
"STREAM_DATA_BLOCKED valid only in 0/1-RTT");
|
2022-08-22 14:45:26 +08:00
|
|
|
return 0;
|
2022-11-17 23:26:39 +08:00
|
|
|
}
|
|
|
|
if (!depack_do_frame_stream_data_blocked(pkt, ch, ackm_data))
|
2022-07-21 16:54:48 +08:00
|
|
|
return 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case OSSL_QUIC_FRAME_TYPE_STREAMS_BLOCKED_BIDI:
|
|
|
|
case OSSL_QUIC_FRAME_TYPE_STREAMS_BLOCKED_UNI:
|
2022-08-22 14:45:26 +08:00
|
|
|
/* STREAMS_BLOCKED frames are valid in 0RTT and 1RTT packets */
|
|
|
|
if (pkt_type != QUIC_PKT_TYPE_0RTT
|
2022-11-17 23:26:39 +08:00
|
|
|
&& pkt_type != QUIC_PKT_TYPE_1RTT) {
|
|
|
|
ossl_quic_channel_raise_protocol_error(ch,
|
|
|
|
QUIC_ERR_PROTOCOL_VIOLATION,
|
|
|
|
frame_type,
|
|
|
|
"STREAMS valid only in 0/1-RTT");
|
2022-08-22 14:45:26 +08:00
|
|
|
return 0;
|
2022-11-17 23:26:39 +08:00
|
|
|
}
|
|
|
|
if (!depack_do_frame_streams_blocked(pkt, ch, ackm_data,
|
|
|
|
frame_type))
|
2022-07-21 16:54:48 +08:00
|
|
|
return 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case OSSL_QUIC_FRAME_TYPE_NEW_CONN_ID:
|
2022-08-22 14:45:26 +08:00
|
|
|
/* NEW_CONN_ID frames are valid in 0RTT and 1RTT packets */
|
|
|
|
if (pkt_type != QUIC_PKT_TYPE_0RTT
|
2022-11-17 23:26:39 +08:00
|
|
|
&& pkt_type != QUIC_PKT_TYPE_1RTT) {
|
|
|
|
ossl_quic_channel_raise_protocol_error(ch,
|
|
|
|
QUIC_ERR_PROTOCOL_VIOLATION,
|
|
|
|
frame_type,
|
|
|
|
"NEW_CONN_ID valid only in 0/1-RTT");
|
|
|
|
}
|
|
|
|
if (!depack_do_frame_new_conn_id(pkt, ch, ackm_data))
|
2022-07-21 16:54:48 +08:00
|
|
|
return 0;
|
|
|
|
break;
|
|
|
|
case OSSL_QUIC_FRAME_TYPE_RETIRE_CONN_ID:
|
2022-08-22 14:45:26 +08:00
|
|
|
/* RETIRE_CONN_ID frames are valid in 0RTT and 1RTT packets */
|
|
|
|
if (pkt_type != QUIC_PKT_TYPE_0RTT
|
2022-11-17 23:26:39 +08:00
|
|
|
&& pkt_type != QUIC_PKT_TYPE_1RTT) {
|
|
|
|
ossl_quic_channel_raise_protocol_error(ch,
|
|
|
|
QUIC_ERR_PROTOCOL_VIOLATION,
|
|
|
|
frame_type,
|
|
|
|
"RETIRE_CONN_ID valid only in 0/1-RTT");
|
2022-08-22 14:45:26 +08:00
|
|
|
return 0;
|
2022-11-17 23:26:39 +08:00
|
|
|
}
|
|
|
|
if (!depack_do_frame_retire_conn_id(pkt, ch, ackm_data))
|
2022-07-21 16:54:48 +08:00
|
|
|
return 0;
|
|
|
|
break;
|
|
|
|
case OSSL_QUIC_FRAME_TYPE_PATH_CHALLENGE:
|
2022-08-22 14:45:26 +08:00
|
|
|
/* PATH_CHALLENGE frames are valid in 0RTT and 1RTT packets */
|
|
|
|
if (pkt_type != QUIC_PKT_TYPE_0RTT
|
2022-11-17 23:26:39 +08:00
|
|
|
&& pkt_type != QUIC_PKT_TYPE_1RTT) {
|
|
|
|
ossl_quic_channel_raise_protocol_error(ch,
|
|
|
|
QUIC_ERR_PROTOCOL_VIOLATION,
|
|
|
|
frame_type,
|
|
|
|
"PATH_CHALLENGE valid only in 0/1-RTT");
|
2022-08-22 14:45:26 +08:00
|
|
|
return 0;
|
2022-11-17 23:26:39 +08:00
|
|
|
}
|
|
|
|
if (!depack_do_frame_path_challenge(pkt, ch, ackm_data))
|
2022-07-21 16:54:48 +08:00
|
|
|
return 0;
|
|
|
|
break;
|
|
|
|
case OSSL_QUIC_FRAME_TYPE_PATH_RESPONSE:
|
2022-08-22 14:45:26 +08:00
|
|
|
/* PATH_RESPONSE frames are valid in 1RTT packets */
|
2022-11-17 23:26:39 +08:00
|
|
|
if (pkt_type != QUIC_PKT_TYPE_1RTT) {
|
|
|
|
ossl_quic_channel_raise_protocol_error(ch,
|
|
|
|
QUIC_ERR_PROTOCOL_VIOLATION,
|
|
|
|
frame_type,
|
|
|
|
"PATH_CHALLENGE valid only in 1-RTT");
|
2022-08-22 14:45:26 +08:00
|
|
|
return 0;
|
2022-11-17 23:26:39 +08:00
|
|
|
}
|
|
|
|
if (!depack_do_frame_path_response(pkt, ch, ackm_data))
|
2022-07-21 16:54:48 +08:00
|
|
|
return 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case OSSL_QUIC_FRAME_TYPE_CONN_CLOSE_APP:
|
2022-08-22 14:45:26 +08:00
|
|
|
/* CONN_CLOSE_APP frames are valid in 0RTT and 1RTT packets */
|
|
|
|
if (pkt_type != QUIC_PKT_TYPE_0RTT
|
2022-11-17 23:26:39 +08:00
|
|
|
&& pkt_type != QUIC_PKT_TYPE_1RTT) {
|
|
|
|
ossl_quic_channel_raise_protocol_error(ch,
|
|
|
|
QUIC_ERR_PROTOCOL_VIOLATION,
|
|
|
|
frame_type,
|
|
|
|
"CONN_CLOSE (APP) valid only in 0/1-RTT");
|
2022-08-22 14:45:26 +08:00
|
|
|
return 0;
|
2022-11-17 23:26:39 +08:00
|
|
|
}
|
2022-08-22 14:45:26 +08:00
|
|
|
/* FALLTHRU */
|
|
|
|
case OSSL_QUIC_FRAME_TYPE_CONN_CLOSE_TRANSPORT:
|
|
|
|
/* CONN_CLOSE_TRANSPORT frames are valid in all packets */
|
2022-11-17 23:26:39 +08:00
|
|
|
if (!depack_do_frame_conn_close(pkt, ch))
|
2022-07-21 16:54:48 +08:00
|
|
|
return 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case OSSL_QUIC_FRAME_TYPE_HANDSHAKE_DONE:
|
2022-08-22 14:45:26 +08:00
|
|
|
/* HANDSHAKE_DONE frames are valid in 1RTT packets */
|
2022-11-17 23:26:39 +08:00
|
|
|
if (pkt_type != QUIC_PKT_TYPE_1RTT) {
|
|
|
|
ossl_quic_channel_raise_protocol_error(ch,
|
|
|
|
QUIC_ERR_PROTOCOL_VIOLATION,
|
|
|
|
frame_type,
|
|
|
|
"HANDSHAKE_DONE valid only in 1-RTT");
|
2022-08-22 14:45:26 +08:00
|
|
|
return 0;
|
2022-11-17 23:26:39 +08:00
|
|
|
}
|
|
|
|
if (!depack_do_frame_handshake_done(pkt, ch, ackm_data))
|
2022-07-21 16:54:48 +08:00
|
|
|
return 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
/* Unknown frame type. */
|
2022-11-17 23:26:39 +08:00
|
|
|
if (!depack_do_frame_unknown_extension(pkt, ch, ackm_data))
|
2022-07-21 16:54:48 +08:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2022-11-17 23:26:39 +08:00
|
|
|
int ossl_quic_handle_frames(QUIC_CHANNEL *ch, OSSL_QRX_PKT *qpacket)
|
2022-07-21 16:54:48 +08:00
|
|
|
{
|
|
|
|
PACKET pkt;
|
|
|
|
OSSL_ACKM_RX_PKT ackm_data;
|
|
|
|
/*
|
|
|
|
* ok has three states:
|
|
|
|
* -1 error with ackm_data uninitialized
|
|
|
|
* 0 error with ackm_data initialized
|
|
|
|
* 1 success (ackm_data initialized)
|
|
|
|
*/
|
|
|
|
int ok = -1; /* Assume the worst */
|
|
|
|
|
2022-11-17 23:26:39 +08:00
|
|
|
if (ch == NULL)
|
2022-07-21 16:54:48 +08:00
|
|
|
goto end;
|
|
|
|
|
|
|
|
/* Initialize |ackm_data| (and reinitialize |ok|)*/
|
|
|
|
memset(&ackm_data, 0, sizeof(ackm_data));
|
|
|
|
/*
|
|
|
|
* TODO(QUIC): ASSUMPTION: All packets that aren't special case have a
|
|
|
|
* packet number
|
|
|
|
*/
|
|
|
|
ackm_data.pkt_num = qpacket->pn;
|
|
|
|
ackm_data.time = qpacket->time;
|
|
|
|
switch (qpacket->hdr->type) {
|
|
|
|
case QUIC_PKT_TYPE_INITIAL:
|
|
|
|
ackm_data.pkt_space = QUIC_PN_SPACE_INITIAL;
|
|
|
|
break;
|
|
|
|
case QUIC_PKT_TYPE_HANDSHAKE:
|
|
|
|
ackm_data.pkt_space = QUIC_PN_SPACE_HANDSHAKE;
|
|
|
|
break;
|
|
|
|
case QUIC_PKT_TYPE_0RTT:
|
|
|
|
case QUIC_PKT_TYPE_1RTT:
|
|
|
|
ackm_data.pkt_space = QUIC_PN_SPACE_APP;
|
|
|
|
break;
|
2022-11-17 23:26:39 +08:00
|
|
|
default:
|
|
|
|
/*
|
|
|
|
* Retry and Version Negotiation packets should not be passed to this
|
|
|
|
* function.
|
|
|
|
*/
|
|
|
|
goto end;
|
2022-07-21 16:54:48 +08:00
|
|
|
}
|
|
|
|
ok = 0; /* Still assume the worst */
|
|
|
|
|
|
|
|
/* Now that special cases are out of the way, parse frames */
|
|
|
|
if (!PACKET_buf_init(&pkt, qpacket->hdr->data, qpacket->hdr->len)
|
2022-11-17 23:26:39 +08:00
|
|
|
|| !depack_process_frames(ch, &pkt, qpacket,
|
2022-07-21 16:54:48 +08:00
|
|
|
ackm_data.pkt_space, qpacket->time,
|
|
|
|
&ackm_data))
|
|
|
|
goto end;
|
|
|
|
|
|
|
|
ok = 1;
|
|
|
|
end:
|
|
|
|
/*
|
|
|
|
* TODO(QUIC): ASSUMPTION: If this function is called at all, |qpacket| is
|
|
|
|
* a legitimate packet, even if its contents aren't.
|
|
|
|
* Therefore, we call ossl_ackm_on_rx_packet() unconditionally, as long as
|
|
|
|
* |ackm_data| has at least been initialized.
|
|
|
|
*/
|
|
|
|
if (ok >= 0)
|
2022-11-17 23:26:39 +08:00
|
|
|
ossl_ackm_on_rx_packet(ch->ackm, &ackm_data);
|
2022-07-21 16:54:48 +08:00
|
|
|
|
|
|
|
return ok > 0;
|
|
|
|
}
|