/* Decode into <p> struct a transport parameter found in <*buf> buffer with
* <type> as type and <len> as length. The boolean argument <server> must be
* set according to the origin of the parameters.
+ *
+ * Returns 1 on success else 0 if decoding is truncated.
*/
-static enum quic_tp_dec_err
+static int
quic_transport_param_decode(struct quic_transport_params *p, int server,
uint64_t type, const unsigned char **buf, size_t len)
{
switch (type) {
case QUIC_TP_ORIGINAL_DESTINATION_CONNECTION_ID:
if (len > sizeof p->original_destination_connection_id.data)
- return QUIC_TP_DEC_ERR_TRUNC;
+ return 0;
if (len)
memcpy(p->original_destination_connection_id.data, *buf, len);
p->original_destination_connection_id.len = len;
break;
case QUIC_TP_INITIAL_SOURCE_CONNECTION_ID:
if (len > sizeof p->initial_source_connection_id.data)
- return QUIC_TP_DEC_ERR_TRUNC;
+ return 0;
if (len)
memcpy(p->initial_source_connection_id.data, *buf, len);
break;
case QUIC_TP_STATELESS_RESET_TOKEN:
if (len != sizeof p->stateless_reset_token)
- return QUIC_TP_DEC_ERR_TRUNC;
+ return 0;
memcpy(p->stateless_reset_token, *buf, len);
*buf += len;
p->with_stateless_reset_token = 1;
break;
case QUIC_TP_PREFERRED_ADDRESS:
if (!quic_transport_param_dec_pref_addr(&p->preferred_address, buf, *buf + len))
- return QUIC_TP_DEC_ERR_TRUNC;
+ return 0;
p->with_preferred_address = 1;
break;
case QUIC_TP_MAX_IDLE_TIMEOUT:
if (!quic_dec_int(&p->max_idle_timeout, buf, end))
- return QUIC_TP_DEC_ERR_TRUNC;
+ return 0;
break;
case QUIC_TP_MAX_UDP_PAYLOAD_SIZE:
if (!quic_dec_int(&p->max_udp_payload_size, buf, end))
- return QUIC_TP_DEC_ERR_TRUNC;
+ return 0;
break;
case QUIC_TP_INITIAL_MAX_DATA:
if (!quic_dec_int(&p->initial_max_data, buf, end))
- return QUIC_TP_DEC_ERR_TRUNC;
+ return 0;
break;
case QUIC_TP_INITIAL_MAX_STREAM_DATA_BIDI_LOCAL:
if (!quic_dec_int(&p->initial_max_stream_data_bidi_local, buf, end))
- return QUIC_TP_DEC_ERR_TRUNC;
+ return 0;
break;
case QUIC_TP_INITIAL_MAX_STREAM_DATA_BIDI_REMOTE:
if (!quic_dec_int(&p->initial_max_stream_data_bidi_remote, buf, end))
- return QUIC_TP_DEC_ERR_TRUNC;
+ return 0;
break;
case QUIC_TP_INITIAL_MAX_STREAM_DATA_UNI:
if (!quic_dec_int(&p->initial_max_stream_data_uni, buf, end))
- return QUIC_TP_DEC_ERR_TRUNC;
+ return 0;
break;
case QUIC_TP_INITIAL_MAX_STREAMS_BIDI:
if (!quic_dec_int(&p->initial_max_streams_bidi, buf, end))
- return QUIC_TP_DEC_ERR_TRUNC;
+ return 0;
break;
case QUIC_TP_INITIAL_MAX_STREAMS_UNI:
if (!quic_dec_int(&p->initial_max_streams_uni, buf, end))
- return QUIC_TP_DEC_ERR_TRUNC;
+ return 0;
break;
case QUIC_TP_ACK_DELAY_EXPONENT:
if (!quic_dec_int(&p->ack_delay_exponent, buf, end))
- return QUIC_TP_DEC_ERR_TRUNC;
+ return 0;
break;
case QUIC_TP_MAX_ACK_DELAY:
if (!quic_dec_int(&p->max_ack_delay, buf, end))
- return QUIC_TP_DEC_ERR_TRUNC;
+ return 0;
break;
case QUIC_TP_DISABLE_ACTIVE_MIGRATION:
/* Zero-length parameter type. */
if (len != 0)
- return QUIC_TP_DEC_ERR_TRUNC;
+ return 0;
p->disable_active_migration = 1;
break;
case QUIC_TP_ACTIVE_CONNECTION_ID_LIMIT:
if (!quic_dec_int(&p->active_connection_id_limit, buf, end))
- return QUIC_TP_DEC_ERR_TRUNC;
+ return 0;
break;
case QUIC_TP_VERSION_INFORMATION:
if (!quic_transport_param_dec_version_info(&p->version_information,
buf, *buf + len, server))
- return QUIC_TP_DEC_ERR_TRUNC;
+ return 0;
break;
case QUIC_TP_RETRY_SOURCE_CONNECTION_ID:
if (len > sizeof p->retry_source_connection_id.data)
- return QUIC_TP_DEC_ERR_TRUNC;
+ return 0;
if (len)
memcpy(p->retry_source_connection_id.data, *buf, len);
*buf += len;
};
- return *buf == end ? QUIC_TP_DEC_ERR_NONE : QUIC_TP_DEC_ERR_TRUNC;
+ return *buf == end;
}
/* Encode <type> and <len> variable length values in <buf>.
/* Decode transport parameters found in <buf> buffer into <p>. The boolean
* argument <server> must be set according to the origin of the parameters.
- * Returns 1 if succeeded, 0 if not.
+ *
+ * Returns 1 on success else 0 if decoding is truncated.
*/
-static enum quic_tp_dec_err
-quic_transport_params_decode(struct quic_transport_params *p, int server,
- const unsigned char *buf, const unsigned char *end)
+static int quic_transport_params_decode(struct quic_transport_params *p, int server,
+ const unsigned char *buf, const unsigned char *end)
{
- enum quic_tp_dec_err err;
const unsigned char *pos;
uint64_t type, len = 0;
+ int ret;
pos = buf;
while (pos != end) {
if (!quic_transport_param_decode_type_len(&type, &len, &pos, end))
- return QUIC_TP_DEC_ERR_TRUNC;
+ return 0;
if (end - pos < len)
- return QUIC_TP_DEC_ERR_TRUNC;
+ return 0;
- err = quic_transport_param_decode(p, server, type, &pos, len);
- if (err != QUIC_TP_DEC_ERR_NONE)
- return err;
+ ret = quic_transport_param_decode(p, server, type, &pos, len);
+ if (!ret)
+ return 0;
}
- return QUIC_TP_DEC_ERR_NONE;
+ return 1;
}
/* Check validity of decoded <p> transport parameters. The boolean argument
* Returns 1 if params are valid, else 0 if TRANSPORT_PARAMETER_ERROR must be
* emitted.
*/
-static enum quic_tp_dec_err
-quic_transport_params_check(const struct quic_transport_params *p, int server)
+static int quic_transport_params_check(const struct quic_transport_params *p, int server)
{
/* RFC 9000 7.3. Authenticating Connection IDs
*
*/
if (!p->initial_source_connection_id_present ||
(server && !p->original_destination_connection_id_present)) {
- return QUIC_TP_DEC_ERR_INVAL;
+ return 0;
}
/* RFC 9000 18.2. Transport Parameter Definitions
p->retry_source_connection_id.len ||
p->with_stateless_reset_token ||
p->with_preferred_address)) {
- return QUIC_TP_DEC_ERR_INVAL;
+ return 0;
}
/* RFC 9000 18.2. Transport Parameter Definitions
* payload of 65527. Values below 1200 are invalid.
*/
if (p->max_udp_payload_size < 1200)
- return QUIC_TP_DEC_ERR_INVAL;
+ return 0;
/* RFC 9000 18.2. Transport Parameter Definitions
*
* Values above 20 are invalid.
*/
if (p->ack_delay_exponent > QUIC_TP_ACK_DELAY_EXPONENT_LIMIT)
- return QUIC_TP_DEC_ERR_INVAL;
+ return 0;
/* RFC 9000 18.2. Transport Parameter Definitions
*
* Values of 2^14 or greater are invalid.
*/
if (p->max_ack_delay >= QUIC_TP_MAX_ACK_DELAY_LIMIT)
- return QUIC_TP_DEC_ERR_INVAL;
+ return 0;
/* RFC 9000 18.2. Transport Parameter Definitions
*
* connection with an error of type TRANSPORT_PARAMETER_ERROR.
*/
if (p->active_connection_id_limit < QUIC_TP_DFLT_ACTIVE_CONNECTION_ID_LIMIT)
- return QUIC_TP_DEC_ERR_INVAL;
+ return 0;
- return QUIC_TP_DEC_ERR_NONE;
+ return 1;
}
/* Store transport parameters found in <buf> buffer into <qc> QUIC connection.
const unsigned char *buf,
const unsigned char *end, int edata_accepted)
{
- enum quic_tp_dec_err err;
struct quic_transport_params *tx_params = &qc->tx.params;
struct quic_transport_params *rx_params = &qc->rx.params;
/* Initial source connection ID */
/* initialize peer TPs to RFC default value */
quic_dflt_transport_params_cpy(tx_params);
- err = quic_transport_params_decode(tx_params, server, buf, end);
- if (err != QUIC_TP_DEC_ERR_NONE) {
+ if (!quic_transport_params_decode(tx_params, server, buf, end)) {
TRACE_ERROR("error on transport parameters decoding", QUIC_EV_TRANSP_PARAMS, qc);
return 0;
}
- err = quic_transport_params_check(tx_params, server);
- if (err != QUIC_TP_DEC_ERR_NONE) {
+ if (!quic_transport_params_check(tx_params, server)) {
TRACE_ERROR("invalid transport parameter value", QUIC_EV_TRANSP_PARAMS, qc);
quic_set_connection_close(qc, quic_err_transport(QC_ERR_TRANSPORT_PARAMETER_ERROR));
return 1;