diff --git a/include/haproxy/quic_tp-t.h b/include/haproxy/quic_tp-t.h
index 45f188ec3..e4424efe1 100644
--- a/include/haproxy/quic_tp-t.h
+++ b/include/haproxy/quic_tp-t.h
@@ -124,12 +124,5 @@ struct quic_early_transport_params {
uint64_t initial_max_streams_uni;
};
-/* Return type for QUIC TP decode function */
-enum quic_tp_dec_err {
- QUIC_TP_DEC_ERR_NONE = 0, /* no error */
- QUIC_TP_DEC_ERR_INVAL, /* invalid value as per RFC 9000 */
- QUIC_TP_DEC_ERR_TRUNC, /* field encoding too small or too large */
-};
-
#endif /* USE_QUIC */
#endif /* _HAPROXY_QUIC_TP_T_H */
diff --git a/src/quic_tp.c b/src/quic_tp.c
index fd20d2c92..64f990e76 100644
--- a/src/quic_tp.c
+++ b/src/quic_tp.c
@@ -258,8 +258,10 @@ static int quic_transport_param_dec_version_info(struct tp_version_information *
/* Decode into
struct a transport parameter found in <*buf> buffer with
* as type and as length. The boolean argument 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)
{
@@ -268,7 +270,7 @@ quic_transport_param_decode(struct quic_transport_params *p, int server,
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;
@@ -277,7 +279,7 @@ quic_transport_param_decode(struct quic_transport_params *p, int server,
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);
@@ -287,77 +289,77 @@ quic_transport_param_decode(struct quic_transport_params *p, int server,
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);
@@ -368,7 +370,7 @@ quic_transport_param_decode(struct quic_transport_params *p, int server,
*buf += len;
};
- return *buf == end ? QUIC_TP_DEC_ERR_NONE : QUIC_TP_DEC_ERR_TRUNC;
+ return *buf == end;
}
/* Encode and variable length values in .
@@ -628,31 +630,31 @@ int quic_transport_params_encode(unsigned char *buf,
/* Decode transport parameters found in buffer into . The boolean
* argument 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 transport parameters. The boolean argument
@@ -661,8 +663,7 @@ quic_transport_params_decode(struct quic_transport_params *p, int server,
* 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
*
@@ -674,7 +675,7 @@ quic_transport_params_check(const struct quic_transport_params *p, int server)
*/
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
@@ -688,7 +689,7 @@ quic_transport_params_check(const struct quic_transport_params *p, int server)
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
@@ -698,7 +699,7 @@ quic_transport_params_check(const struct quic_transport_params *p, int server)
* 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
*
@@ -706,7 +707,7 @@ quic_transport_params_check(const struct quic_transport_params *p, int server)
* 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
*
@@ -714,7 +715,7 @@ quic_transport_params_check(const struct quic_transport_params *p, int server)
* 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
*
@@ -725,9 +726,9 @@ quic_transport_params_check(const struct quic_transport_params *p, int server)
* 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 buffer into QUIC connection.
@@ -747,7 +748,6 @@ int quic_transport_params_store(struct quic_conn *qc, int server,
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 */
@@ -763,14 +763,12 @@ int quic_transport_params_store(struct quic_conn *qc, int server,
/* 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;