Skip to content

Commit cae1e6e

Browse files
committed
Revert "MINOR: quic: centralize padding for HP sampling on packet building"
This reverts commit 1529ec1.
1 parent 58b153b commit cae1e6e

File tree

2 files changed

+15
-26
lines changed

2 files changed

+15
-26
lines changed

include/haproxy/quic_conn-t.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,6 @@ enum quic_pkt_type {
145145
#define QUIC_PACKET_PNL_BITMASK 0x03
146146
#define QUIC_PACKET_PN_MAXLEN 4
147147

148-
/* TLS algo supported by QUIC uses a 16-bytes sample for HP. */
149-
#define QUIC_HP_SAMPLE_LEN 16
150-
151148
/*
152149
* 0 1 2 3
153150
* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1

src/quic_tx.c

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1957,6 +1957,13 @@ static int qc_do_build_pkt(unsigned char *pos, const unsigned char *end,
19571957
add_ping_frm = 1;
19581958
len += 1;
19591959
dglen += 1;
1960+
1961+
/* Ensure packet is big enough so that header protection sample
1962+
* decryption can be performed. Note that +1 is for the PING
1963+
* frame.
1964+
*/
1965+
if (!padding && *pn_len + 1 < QUIC_PACKET_PN_MAXLEN)
1966+
len += padding_len = QUIC_PACKET_PN_MAXLEN - *pn_len - 1;
19601967
}
19611968

19621969
/* Handle Initial packet padding if necessary. */
@@ -1974,29 +1981,14 @@ static int qc_do_build_pkt(unsigned char *pos, const unsigned char *end,
19741981
}
19751982
}
19761983
}
1977-
1978-
/* RFC 9001 5.4.2. Header Protection Sample
1979-
*
1980-
* To ensure that sufficient data is available for sampling, packets are
1981-
* padded so that the combined lengths of the encoded packet number and
1982-
* protected payload is at least 4 bytes longer than the sample required
1983-
* for header protection. The cipher suites defined in [TLS13] -- other
1984-
* than TLS_AES_128_CCM_8_SHA256, for which a header protection scheme
1985-
* is not defined in this document -- have 16-byte expansions and 16-
1986-
* byte header protection samples. This results in needing at least 3
1987-
* bytes of frames in the unprotected payload if the packet number is
1988-
* encoded on a single byte, or 2 bytes of frames for a 2-byte packet
1989-
* number encoding.
1990-
*/
1991-
1992-
/* Add padding if packet is too small for HP sampling as specified
1993-
* above. QUIC TLS algos relies on 16 bytes sample extracted 4 bytes
1994-
* after PN offset. Thus, pn and payload must be at least 4 bytes long,
1995-
* so that the sample will be extracted as the AEAD tag.
1996-
*/
1997-
if (*pn_len + len < QUIC_PACKET_PN_MAXLEN + QUIC_HP_SAMPLE_LEN) {
1998-
padding_len = QUIC_PACKET_PN_MAXLEN + QUIC_HP_SAMPLE_LEN - (*pn_len + len);
1999-
len += padding_len;
1984+
else if (len_frms && len_frms < QUIC_PACKET_PN_MAXLEN) {
1985+
len += padding_len = QUIC_PACKET_PN_MAXLEN - len_frms;
1986+
}
1987+
/* TODO qc_do_build_pkt() must rely on its <probe> argument instead of using QEL <pto_probe> field. */
1988+
else if (LIST_ISEMPTY(&frm_list) && !cc && !qel->pktns->tx.pto_probe) {
1989+
/* If there is no frame at all to follow, add at least a PADDING frame. */
1990+
if (!ack_frm_len)
1991+
len += padding_len = QUIC_PACKET_PN_MAXLEN - *pn_len;
20001992
}
20011993

20021994
if (pkt->type != QUIC_PACKET_TYPE_SHORT && !quic_enc_int(&pos, end, len))

0 commit comments

Comments
 (0)