* QUIC_MAX_CONN_ID_LEN), this function fails when trying to decode a short
* packet, but succeeds for long packets.
*
+ * fail_cause is a bitmask of the reasons decode might have failed
+ * as defined below, useful when you need to interrogate parts of
+ * a header even if its otherwise undecodeable. May be NULL.
+ *
* Returns 1 on success and 0 on failure.
*/
+
+# define QUIC_PKT_HDR_DECODE_DECODE_ERR (1 << 0)
+# define QUIC_PKT_HDR_DECODE_BAD_VERSION (1 << 1)
+
int ossl_quic_wire_decode_pkt_hdr(PACKET *pkt,
size_t short_conn_id_len,
int partial,
int nodata,
QUIC_PKT_HDR *hdr,
- QUIC_PKT_HDR_PTRS *ptrs);
+ QUIC_PKT_HDR_PTRS *ptrs,
+ uint64_t *fail_cause);
/*
* Encodes a packet header. The packet is written to pkt.
* operation to fail if we get a 1-RTT packet. This is fine since we only
* care about Initial packets.
*/
- if (!ossl_quic_wire_decode_pkt_hdr(&pkt, SIZE_MAX, 1, 0, &hdr, NULL))
+ if (!ossl_quic_wire_decode_pkt_hdr(&pkt, SIZE_MAX, 1, 0, &hdr, NULL, NULL))
goto undesirable;
switch (hdr.version) {
need_second_decode = !pkt_is_marked(&urxe->hpr_removed, pkt_idx);
if (!ossl_quic_wire_decode_pkt_hdr(pkt,
qrx->short_conn_id_len,
- need_second_decode, 0, &rxe->hdr, &ptrs))
+ need_second_decode, 0, &rxe->hdr, &ptrs,
+ NULL))
goto malformed;
/*
/* Decode the now unprotected header. */
if (ossl_quic_wire_decode_pkt_hdr(pkt, qrx->short_conn_id_len,
- 0, 0, &rxe->hdr, NULL) != 1)
+ 0, 0, &rxe->hdr, NULL, NULL) != 1)
goto malformed;
}
* TODO(QUIC SERVER): We need to query the short connection id len
* here, e.g. via some API SSL_get_short_conn_id_len()
*/
- if (ossl_quic_wire_decode_pkt_hdr(&pkt, 0, 0, 1, &hdr, NULL) != 1)
+ if (ossl_quic_wire_decode_pkt_hdr(&pkt, 0, 0, 1, &hdr, NULL,
+ NULL) != 1)
return 0;
BIO_puts(bio, write_p ? "Sent" : "Received");
int partial,
int nodata,
QUIC_PKT_HDR *hdr,
- QUIC_PKT_HDR_PTRS *ptrs)
+ QUIC_PKT_HDR_PTRS *ptrs,
+ uint64_t *fail_cause)
{
unsigned int b0;
unsigned char *pn = NULL;
size_t l = PACKET_remaining(pkt);
+ if (fail_cause != NULL)
+ *fail_cause = QUIC_PKT_HDR_DECODE_DECODE_ERR;
+
if (ptrs != NULL) {
ptrs->raw_start = (unsigned char *)PACKET_data(pkt);
ptrs->raw_sample = NULL;
if (!PACKET_forward(pkt, hdr->len))
return 0;
} else if (version != QUIC_VERSION_1) {
+ if (fail_cause != NULL)
+ *fail_cause |= QUIC_PKT_HDR_DECODE_BAD_VERSION;
/* Unknown version, do not decode. */
return 0;
} else {
}
}
+ /*
+ * Good decode, clear the generic DECODE_ERR flag
+ */
+ if (fail_cause != NULL)
+ *fail_cause &= ~QUIC_PKT_HDR_DECODE_DECODE_ERR;
+
return 1;
}
* TODO(QUIC SERVER): We need to query the short connection id len
* here, e.g. via some API SSL_get_short_conn_id_len()
*/
- if (ossl_quic_wire_decode_pkt_hdr(&pkt, 0, 0, 0, &hdr, NULL) != 1)
+ if (ossl_quic_wire_decode_pkt_hdr(&pkt, 0, 0, 0, &hdr, NULL, NULL) != 1)
return 0;
remain = PACKET_remaining(&pkt);
if (remain > 0) {
*/
0,
1,
- 0, &hdr, NULL))
+ 0, &hdr, NULL, NULL))
goto out;
/*
goto err;
if (!TEST_int_eq(ossl_quic_wire_decode_pkt_hdr(&pkt, t->short_conn_id_len,
- 0, 0, &hdr, &ptrs),
+ 0, 0, &hdr, &ptrs, NULL),
!expect_fail))
goto err;
if (!TEST_true(PACKET_buf_init(&pkt, retry_encoded, sizeof(retry_encoded))))
goto err;
- if (!TEST_true(ossl_quic_wire_decode_pkt_hdr(&pkt, 0, 0, 0, &hdr, NULL)))
+ if (!TEST_true(ossl_quic_wire_decode_pkt_hdr(&pkt, 0, 0, 0, &hdr, NULL, NULL)))
goto err;
if (!TEST_int_eq(hdr.type, QUIC_PKT_TYPE_RETRY))