Commit Graph

15936 Commits

Author SHA1 Message Date
Frédéric Lécaille
98ad56a049 MINOR: quic_tls: Make use of the QUIC V1 salt.
This salt is used to derive the Initial secrets.
2021-09-23 15:27:25 +02:00
Frédéric Lécaille
c5b0c93c26 MINOR: quic: Make use of TX ring buffers to send QUIC packets
We modify the functions responsible of building packets to put these latters
in ring buffers (qc_build_hdshk_pkt() during the handshake step, and
qc_build_phdshk_apkt() during the post-handshake step). These functions
remove a ring buffer from its list to build as much as possible datagrams.
Eache datagram is prepended of two field: the datagram length and the
first packet in the datagram. We chain the packets belonging to the same datagram
in a singly linked list to reach them from the first one: indeed we must
modify some members of each packet when we really send them from send_ppkts().
This function is also modified to retrieved the datagram from ring buffers.
2021-09-23 15:27:25 +02:00
Frédéric Lécaille
6b19764e3c MINOR: quic: Initialize pointers to TX ring buffer list
We initialize the pointer to the listener TX ring buffer list.
Note that this is not done for QUIC clients  as we do not fully support them:
we only have to allocate the list and attach it to server struct I guess.
2021-09-23 15:27:25 +02:00
Frédéric Lécaille
48f8e1925b MINOR: proto_quic: Allocate TX ring buffers for listeners
We allocate an array of QUIC ring buffer, one by thread, and arranges them in a
MT_LIST. Everything is allocated or nothing: we do not want to usse an incomplete
array of ring buffers to ensure that each thread may safely acquire one of these
buffers.
2021-09-23 15:27:25 +02:00
Frédéric Lécaille
22cfdf8d0e MINOR: quic: Add ring buffer definition (struct qring) for QUIC
A ring buffer is made of a circular buffer (->cbuf) and must be arrange
in a MT_LIST (->mt_list).
2021-09-23 15:27:25 +02:00
Frédéric Lécaille
9621565b74 MINOR: net_helper: add functions for pointers
Add two functions to read/write pointer values to/from vectors.
2021-09-23 15:27:25 +02:00
Frédéric Lécaille
ed9119f39e BUG/MINOR: quic: Too much reduced computed space to build handshake packets
Before this patch we reserved 16 bytes (QUIC_TLS_TAG_LEN) before building the
handshake packet to be sure to be able to add the tag which comes with the
the packet encryption, decreasing the end offset of the building buffer by 16 bytes.
But this tag length was taken into an account when calling qc_build_frms() which
computes and build crypto frames for the remaining available room thanks to <*len>
parameter which is the length of the already present bytes in the building buffer
before adding CRYPTO frames. This leaded us to waste the 16 last bytes of the buffer
which were not used.
2021-09-23 15:27:25 +02:00
Frédéric Lécaille
82d1daa268 MINOR: quic: Add the QUIC v1 initial salt.
See initial_salt value for QUIC-TLS RFC 9001 at
https://www.rfc-editor.org/rfc/rfc9001.html#name-initial-secrets
2021-09-23 15:27:25 +02:00
Frédéric Lécaille
4b1fddcfcf MINOR: quic: Prefer x25519 as ECDH preferred parametes.
This make at least our listeners answer to ngtcp2 clients without
HelloRetryRequest message. It seems the server choses the first
group in the group list ordered by preference and set by
SSL_CTX_set1_curves_list() which match the client ones.
2021-09-23 15:27:25 +02:00
Frédéric Lécaille
c6bc185c18 MINOR: quic: Add a ring buffer implementation for QUIC
This implementation is inspired from Linux kernel circular buffer implementation
(see include/linux/circ-buf.h). Such buffers may be used at the same time both
by writer and reader (lock-free).
2021-09-23 15:27:25 +02:00
Frédéric Lécaille
f3d078d22e MINOR: quic: Make qc_lstnr_pkt_rcv() be thread safe.
Modify the I/O dgram handler principal function used to parse QUIC packets
be thread safe. Its role is at least to create new incoming connections
add to two trees protected by the same RW lock. The packets are for now on
fully parsed before possibly creating new connections.
2021-09-23 15:27:25 +02:00
Frédéric Lécaille
01ab6618fe MINOR: quic: Move conn_prepare() to ->accept_conn() callback
The xprt context must be initialized before receiving further packets from
the I/O dgram handler.
2021-09-23 15:27:25 +02:00
Frédéric Lécaille
6de7287cc7 MINOR: quic: Connection allocations rework
Allocate everything needed for a connection (struct quic_conn) from the same
function.
Rename qc_new_conn_init() to qc_new_conn() to reflect these modifications.
Insert these connection objects in their tree after returning from this function.
2021-09-23 15:27:25 +02:00
Frédéric Lécaille
7fd59789f2 MINOR: quic: Do not wakeup the xprt task on ACK receipt
This is an old statement which was there before implemeting the PTO and
packet loss detection. There is no reason to keep for now on.
2021-09-23 15:27:25 +02:00
Frédéric Lécaille
2e7ffc9d31 MINOR: quic: Add useful traces for I/O dgram handler
This traces have already help in diagnosing multithreading issues.
2021-09-23 15:27:25 +02:00
Frédéric Lécaille
a11d0e26d4 MINOR: quic: Replace the RX unprotected packet list by a thread safety one.
This list is shared between the I/O dgram handler and the task responsible
for processing the QUIC packets inside.
2021-09-23 15:27:25 +02:00
Frédéric Lécaille
c28aba2a8d MINOR: quic: Replace the RX list of packet by a thread safety one.
This list is shared between the I/O dgram handler and the task responsible
for processing the QUIC packets.
2021-09-23 15:27:25 +02:00
Frédéric Lécaille
1eaec33cb5 MINOR: quic: Replace quic_conn_ctx struct by ssl_sock_ctx struct
Some SSL call may be called with pointer to ssl_sock_ctx struct as parameter
which does not match the quic_conn_ctx struct type (see ssl_sock_infocb()).
I am not sure we have to keep such callbacks for QUIC but we must ensure
the SSL and QUIC xprts use the same data structure as context.
2021-09-23 15:27:25 +02:00
Frédéric Lécaille
a5fe49f44a MINOR: quic: Move the connection state
Move the connection state from quic_conn_ctx struct to quic_conn struct which
is the structure which is used to store the QUIC connection part information.
This structure is initialized by the I/O dgram handler for each new connection
to QUIC listeners. This is needed for the multithread support so that to not
to have to depend on the connection context potentially initialized by another
thread.
2021-09-23 15:27:25 +02:00
Frédéric Lécaille
9fccace8b0 MINOR: quic: Add a lock for RX packets
We must protect from concurrent the tree which stores the QUIC packets received
by the dgram I/O handler, these packets being also parsed by the xprt task.
2021-09-23 15:27:25 +02:00
Frédéric Lécaille
654c691731 MINOR: quic: Do not stop the packet parsing too early in qc_treat_rx_packets()
Continue to parse the packets even if we will not be able to acknowledge them.
2021-09-23 15:27:25 +02:00
Frédéric Lécaille
6fe21b0dec BUG/MINOR: quic: Wrong RX packet reference counter usage
No need to call free_quic_rx_packet() after calling quic_rx_packet_eb64_delete()
as this latter already calls quic_rx_packet_refdec() also called by
free_quic_rx_packet().
2021-09-23 15:27:25 +02:00
Frédéric Lécaille
c4b93ea57d CLEAUNUP: quic: Usage of a useless variable in qc_treat_rx_pkts()
The usage of a <drop> variable is unnecessary here.
2021-09-23 15:27:25 +02:00
Frédéric Lécaille
8ba4276d13 BUG/MINOR: quic: Missing cases treatement when updating ACK ranges
Let's say that we have to insert a range R between to others A and B
with A->first <= R->first <= B->first. We have to remove the ranges
which are overlapsed by R during. This was correctly done when
the intersection between A and R was not empty, but not when the
intersection between R and B was not empty. If this latter case
after having inserting a new range R we set <new> variable as the
node to consider to check the overlaping between R and its following
ranges.
2021-09-23 15:27:25 +02:00
Frédéric Lécaille
c825eba5f9 MINOR: quic: Remove a useless variable in quic_update_ack_ranges_list()
This very minor modification is there to ease the readibilyt of this function.
2021-09-23 15:27:25 +02:00
Frédéric Lécaille
d3f4dd8014 MINOR: quic: Useless test in quic_update_ack_ranges_list()
At this place, the condition "le_ar->first.key <= ar->first" is true because
<le_ar> is the ack-range just below <ar> ack range.
2021-09-23 15:27:25 +02:00
Frédéric Lécaille
9ef64cd078 MINOR: quic: quic_update_ack_ranges_list() code factorization
Very minor modification to avoid repeating the same code section in this function
when allocation new ack range.
2021-09-23 15:27:25 +02:00
Frédéric Lécaille
baea284c3c BUG/MINOR: quic: Wrong memory free in quic_update_ack_ranges_list()
Wrong call to free() in place of pool_free() for an object allocated from a pool
memory.
2021-09-23 15:27:25 +02:00
Frédéric Lécaille
1a5e88c86a MINOR: quic: Remove header protection also for Initial packets
Make qc_try_rm_hp() be able to remove the header protection of Initial packets
which are the first incoming packets of a connection without context.
2021-09-23 15:27:25 +02:00
Frédéric Lécaille
497fa78ad8 MINOR: quic: Derive the initial secrets asap
Make depends qc_new_isecs() only on quic_conn struct initialization only (no more
dependency on connection struct initialization) to be able to run it as soon as
the quic_conn struct is initialized (from the I/O handler) before running ->accept()
quic proto callback.
2021-09-23 15:27:25 +02:00
Frédéric Lécaille
d24c2ecb16 MINOR: quic: Remove header protection for conn with context
We remove the header protection of packet only for connection with already
initialized context. This latter keep traces of the connection state.
Furthermore, we enqueue the first Initial packet for a new connection
after having completely parsed the packet so that to not start the accept
process for nothing.
2021-09-23 15:27:25 +02:00
Frédéric Lécaille
3d77fa754d MINOR: quic: QUIC conn initialization from I/O handler
Move the QUIC conn (struct quic_conn) initialization from quic_sock_accept_conn()
to qc_lstnr_pkt_rcv() as this is done for the server part.
Move the timer initialization to ->start xprt callback to ensure the connection
context is done : it is initialized by the ->accept callback which may be run
by another thread than the one for the I/O handler which also run ->start.
2021-09-23 15:27:25 +02:00
Frédéric Lécaille
de935f34e5 BUG/MINOR: quic: Do not check the acception of a new conn from I/O handler.
As the ->conn member of quic_conn struct is reset to NULL value by the ->accept
callback potentially run by another thread, this check is irrelevant.
2021-09-23 15:27:25 +02:00
Frédéric Lécaille
ecb5872012 MINOR: quic: Initialize the session before starting the xprt.
We must ensure the session and the mux are initialized before starting the xprt.
2021-09-23 15:27:25 +02:00
Frédéric Lécaille
1e1aad4ff4 MINOR: quic: Move an SSL func call from QUIC I/O handler to the xprt init.
Move the call to SSL_set_quic_transport_params() from the listener I/O dgram
handler to the ->init() callback of the xprt (qc_conn_init()) which initializes
its context where is stored the SSL context itself, needed by
SSL_set_quic_transport_params(). Furthermore this is already what is done for the
server counterpart of ->init() QUIC xprt callback. As the ->init() may be run
by another thread than the one for the I/O handler, the xprt context could
not be potentially already initialized before calling SSL_set_quic_transport_params()
from the I/O handler.
2021-09-23 15:27:25 +02:00
Frédéric Lécaille
11c304da0a MINOR: quic: Enable some quic, h3 and qpack modules compilation.
Enable src/h3.c compilation for h3, src/qpack-dec.c and sr/qpack-tbl.c
compilation for qpack, and src/mux_quic.c for the QUIC mux.
2021-09-23 15:27:25 +02:00
Frédéric Lécaille
785c9c998a MINOR: quic: Replace max_packet_size by max_udp_payload size.
The name the maximum packet size transport parameter was ambiguous and replaced
by maximum UDP payload size. Our code would be also ambiguous if it does not
reflect this change.
2021-09-23 15:27:25 +02:00
Frédéric Lécaille
8648c7c995 MINOR: quic: Avoid header collisions
Extract the QUIC varints encoding functions from xprt_quic.h to avoid
header collisions.
2021-09-23 15:27:25 +02:00
Frédéric Lécaille
0faf8078a8 MINOR: quic: Update the streams transport parameters.
Set the streams transport parameters which could not be initialized because they
were not available during initializations. Indeed, the streams transport parameters
are provided by the peer during the handshake.
2021-09-23 15:27:25 +02:00
Frédéric Lécaille
738397065c MINOR: quic: Add a wrapper function to update transport parameters.
This function calls quic_mux_transport_params_update() to update the related
streams transport parameter of the mux. It is there only so that not to have
to include mux_quic.h to update these parameters.
2021-09-23 15:27:25 +02:00
Frédéric Lécaille
e8139f3b37 BUG/MINOR: quic: Wrong ->accept() error handling
Really signal the caller that ->accept() has failed if the session could not
be initialized because conn_complete_session() has failed. This is the case
if the mux could not be initialized too.
When it fails an ->accept() must returns -1 in case of resource shortage.
2021-09-23 15:27:25 +02:00
Frédéric Lécaille
7a668f5acb MINOR: quic: Variable-length integer encoding/decoding into/from buffer struct.
Add a function to encode a QUIC varint into a buffer struct. Samething for the
deconding part.
2021-09-23 15:27:25 +02:00
Frédéric Lécaille
422a39cf2c MINOR: quic: Add callbacks for (un)scribing to QUIC xprt.
Add these callbacks so that the QUIC mux may (un)scribe to the read/write xprt
events.
2021-09-23 15:27:25 +02:00
Frédéric Lécaille
fbe3b77c4e MINOR: quic: Disable the action of ->rcv_buf() xprt callback
Deactivate the action of this callback at this time. I am not sure
we will keep it for QUIC as it does not really make sense for QUIC:
the QUIC packet are already recvfrom()'ed by the low level I/O handler
used for all the connections.
2021-09-23 15:27:25 +02:00
Frédéric Lécaille
27faba7240 MINOR: quic_sock: Finalize the QUIC connections.
Add a call to conn_connection_complete() so that to install the mux any
QUIC connection.
2021-09-23 15:27:25 +02:00
Frédéric Lécaille
b4672fb6f0 MINOR: qpack: Add QPACK compression.
Implement QPACK used for HTTP header compression by h3.
2021-09-23 15:27:25 +02:00
Frédéric Lécaille
ccac11f35a MINOR: h3: Add HTTP/3 definitions.
Add all the definitions for HTTP/3 implementation.
2021-09-23 15:27:25 +02:00
Frédéric Lécaille
b8f60b3c66 MINOR: quic: Add a new definition to store STREAM frames.
Add a new structure to store enough information about STREAM frames which
must be stored before being delivered to the application layer, for any
reason.
2021-09-23 15:27:25 +02:00
Frédéric Lécaille
65bc43434a MINOR: quic: Attach QUIC mux connection objet to QUIC connection.
This add a qcc struct for QUIC mux/demux connection layer to quic_conn struct
at low level connection layer.
2021-09-23 15:27:25 +02:00
Frédéric Lécaille
2abe74f39c MINOR: connection: Add callbacks definitions for QUIC.
The flow control at stream level is organized by types (client bidi, server bidi,
client uni, server uni). Adds at least callback to retrieve the number
of available streams by direction.
2021-09-23 15:27:25 +02:00