Skip to content

Commit

Permalink
TODO reorganization quic
Browse files Browse the repository at this point in the history
  • Loading branch information
a-denoyelle committed Nov 23, 2023
1 parent 7fc5235 commit c27b26a
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 23 deletions.
8 changes: 8 additions & 0 deletions include/haproxy/quic_conn-t.h
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ extern const struct quic_version *preferred_version;
* So do not change the order of the member of quic_cid struct.
* <data> member must be the first one.
*/
/* TODO move in quic_cid ? */
struct quic_cid {
unsigned char data[QUIC_CID_MAXLEN];
unsigned char len; /* size of QUIC CID */
Expand All @@ -235,6 +236,7 @@ struct quic_cid {
* This structure is used to match received packets DCIDs with the
* corresponding QUIC connection.
*/
/* TODO move in quic_cid ? */
struct quic_connection_id {
struct eb64_node seq_num;
uint64_t retire_prior_to;
Expand All @@ -261,6 +263,7 @@ struct quic_connection_id {
#define QUIC_MAX_NB_PTO_DGRAMS 2

/* QUIC datagram */
/* TODO move in quic_sock */
struct quic_dgram {
void *owner;
unsigned char *buf;
Expand All @@ -279,12 +282,14 @@ struct quic_dgram {
#define QUIC_MAX_PACKET_NUM ((1ULL << 62) - 1)

/* QUIC datagram handler */
/* TODO move in quic_sock */
struct quic_dghdlr {
struct mt_list dgrams;
struct tasklet *task;
};

/* Structure to store enough information about the RX CRYPTO frames. */
/* TODO move in quic_trace */
struct quic_rx_crypto_frm {
struct eb64_node offset_node;
uint64_t len;
Expand All @@ -304,12 +309,14 @@ struct quic_rx_crypto_frm {
* CRYPTO buffer struct.
* Such buffers are used to send CRYPTO data.
*/
/* TODO move in quic_ssl + pool definition */
struct quic_crypto_buf {
unsigned char data[QUIC_CRYPTO_BUF_SZ];
size_t sz;
};

/* Crypto data stream (one by encryption level) */
/* TODO move in quic_cstream ? */
struct quic_cstream {
struct {
uint64_t offset; /* absolute current base offset of ncbuf */
Expand All @@ -324,6 +331,7 @@ struct quic_cstream {
struct qc_stream_desc *desc;
};

/* TODO move in quic_cc */
struct quic_path {
/* Control congestion. */
struct quic_cc cc;
Expand Down
44 changes: 25 additions & 19 deletions include/haproxy/quic_conn.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ int quic_stateless_reset_token_cpy(unsigned char *pos, size_t len,
const unsigned char *salt, size_t saltlen);

/* Return the long packet type matching with <qv> version and <type> */
/* TODO move in quic_tx */
static inline int quic_pkt_type(int type, uint32_t version)
{
if (version != QUIC_PROTOCOL_VERSION_2)
Expand Down Expand Up @@ -114,6 +115,7 @@ static inline int qc_is_listener(struct quic_conn *qc)
* <dst> to copy <src>.
* Always succeeds.
*/
/* TODO move in quic_cid */
static inline void quic_cid_cpy(struct quic_cid *dst, const struct quic_cid *src)
{
memcpy(dst->data, src->data, src->len);
Expand All @@ -125,6 +127,7 @@ static inline void quic_cid_cpy(struct quic_cid *dst, const struct quic_cid *src
* enough to contain these socket address data.
* Return the number of bytes copied.
*/
/* TODO move in quic_tx */
static inline size_t quic_saddr_cpy(unsigned char *buf,
const struct sockaddr_storage *saddr)
{
Expand Down Expand Up @@ -157,6 +160,7 @@ static inline size_t quic_saddr_cpy(unsigned char *buf,
* debugging purposes.
* Always succeeds.
*/
/* TODO move in quic_cid */
static inline void quic_cid_dump(struct buffer *buf,
const struct quic_cid *cid)
{
Expand All @@ -171,18 +175,21 @@ static inline void quic_cid_dump(struct buffer *buf,
}

/* Return tree index where <cid> is stored. */
/* TODO move in quic_cid */
static inline uchar _quic_cid_tree_idx(const unsigned char *cid)
{
return cid[0];
}

/* Return tree index where <cid> is stored. */
/* TODO move in quic_cid */
static inline uchar quic_cid_tree_idx(const struct quic_cid *cid)
{
return _quic_cid_tree_idx(cid->data);
}

/* Insert <conn_id> into global CID tree as a thread-safe operation. */
/* TODO move in quic_cid */
static inline void quic_cid_insert(struct quic_connection_id *conn_id)
{
const uchar idx = quic_cid_tree_idx(&conn_id->cid);
Expand All @@ -194,6 +201,7 @@ static inline void quic_cid_insert(struct quic_connection_id *conn_id)
}

/* Remove <conn_id> from global CID tree as a thread-safe operation. */
/* TODO move in quic_cid */
static inline void quic_cid_delete(struct quic_connection_id *conn_id)
{
const uchar idx = quic_cid_tree_idx(&conn_id->cid);
Expand Down Expand Up @@ -229,6 +237,7 @@ static inline void free_quic_conn_cids(struct quic_conn *conn)
}

/* Move all the connection IDs from <conn> QUIC connection to <cc_conn> */
/* TODO move in quic_cid */
static inline void quic_conn_mv_cids_to_cc_conn(struct quic_cc_conn *cc_conn,
struct quic_conn *conn)
{
Expand All @@ -248,6 +257,7 @@ static inline void quic_conn_mv_cids_to_cc_conn(struct quic_cc_conn *cc_conn,
/* Copy <src> new connection ID information to <dst> NEW_CONNECTION_ID frame.
* Always succeeds.
*/
/* TODO move with qc_build_new_connection_id_frm */
static inline void quic_connection_id_to_frm_cpy(struct quic_frame *dst,
struct quic_connection_id *src)
{
Expand All @@ -265,6 +275,7 @@ static inline void quic_connection_id_to_frm_cpy(struct quic_frame *dst,
* Note that these 32-bits integers are network bytes ordered.
* Returns 0 if failed (not enough data in the buffer), 1 if succeeded.
*/
/* TODO move in quic_rx */
static inline int quic_read_uint32(uint32_t *val,
const unsigned char **buf,
const unsigned char *end)
Expand All @@ -283,6 +294,7 @@ static inline int quic_read_uint32(uint32_t *val,
* Note that these 32-bits integers are networkg bytes ordered.
* Returns 0 if failed (not enough room in the buffer), 1 if succeeded.
*/
/* TODO move in quic_tx */
static inline int quic_write_uint32(unsigned char **buf,
const unsigned char *end, uint32_t val)
{
Expand All @@ -303,6 +315,7 @@ static inline int quic_write_uint32(unsigned char **buf,
* So after returning from this function we have : <*len_sz> + <ret> <= <sz>
* (<*len_sz> = { max(i), i + ret <= <sz> }) .
*/
/* TODO move in quic_tx */
static inline size_t max_available_room(size_t sz, size_t *len_sz)
{
size_t sz_sz, ret;
Expand Down Expand Up @@ -349,6 +362,7 @@ static inline size_t max_available_room(size_t sz, size_t *len_sz)
* much as possible a QUIC packet made of only one CRYPTO or STREAM frames.
* Returns this computed size if there is enough room in the buffer, 0 if not.
*/
/* TODO move in quic_tx */
static inline size_t max_stream_data_size(size_t sz, size_t ilen, size_t dlen)
{
size_t ret, len_sz, dlen_sz;
Expand Down Expand Up @@ -380,6 +394,7 @@ static inline size_t max_stream_data_size(size_t sz, size_t ilen, size_t dlen)
/* Return the length in bytes of <pn> packet number depending on
* <largest_acked_pn> the largest ackownledged packet number.
*/
/* TODO move in quic_tx */
static inline size_t quic_packet_number_length(int64_t pn,
int64_t largest_acked_pn)
{
Expand Down Expand Up @@ -407,6 +422,7 @@ static inline size_t quic_packet_number_length(int64_t pn,
* enough room in the buffer to copy <pn_len> bytes.
* Never fails.
*/
/* TODO move in quic_tx */
static inline int quic_packet_number_encode(unsigned char **buf,
const unsigned char *end,
uint64_t pn, size_t pn_len)
Expand Down Expand Up @@ -440,6 +456,7 @@ static inline int quic_packet_number_encode(unsigned char **buf,
* <conn> QUIC connection. Note that the value of <ack_delay> coming from
* ACK frame is in microseconds.
*/
/* TODO move in quic_rx */
static inline unsigned int quic_ack_delay_ms(struct qf_ack *ack_frm,
struct quic_conn *conn)
{
Expand All @@ -449,6 +466,7 @@ static inline unsigned int quic_ack_delay_ms(struct qf_ack *ack_frm,
/* Returns the <ack_delay> field value in microsecond to be set in an ACK frame
* depending on the time the packet with a new largest packet number was received.
*/
/* TODO move in quic_tx */
static inline uint64_t quic_compute_ack_delay_us(unsigned int time_received,
struct quic_conn *conn)
{
Expand All @@ -458,6 +476,7 @@ static inline uint64_t quic_compute_ack_delay_us(unsigned int time_received,
/* Initialize <p> QUIC network path depending on <ipv4> boolean
* which is true for an IPv4 path, if not false for an IPv6 path.
*/
/* TODO move in quic_cc.c */
static inline void quic_path_init(struct quic_path *path, int ipv4, unsigned long max_cwnd,
struct quic_cc_algo *algo, struct quic_conn *qc)
{
Expand All @@ -480,6 +499,7 @@ static inline void quic_path_init(struct quic_path *path, int ipv4, unsigned lon
* (before being sent). Almost the same that for the QUIC path room, except that
* here this is the data which have been prepared which are taken into an account.
*/
/* TODO move in quic_cc.c */
static inline size_t quic_path_prep_data(struct quic_path *path)
{
if (path->prep_in_flight > path->cwnd)
Expand All @@ -498,26 +518,8 @@ static inline size_t quic_may_send_bytes(struct quic_conn *qc)
return 3 * qc->bytes.rx - qc->bytes.prep;
}

/* CRYPTO data buffer handling functions. */
static inline unsigned char *c_buf_getpos(struct quic_enc_level *qel, uint64_t offset)
{
int idx;
unsigned char *data;

idx = offset >> QUIC_CRYPTO_BUF_SHIFT;
data = qel->tx.crypto.bufs[idx]->data;
return data + (offset & QUIC_CRYPTO_BUF_MASK);
}

/* Returns 1 if the CRYPTO buffer at <qel> encryption level has been
* consumed (sent to the peer), 0 if not.
*/
static inline int c_buf_consumed(struct quic_enc_level *qel)
{
return qel->tx.crypto.offset == qel->tx.crypto.sz;
}

/* Return 1 if <pkt> header form is long, 0 if not. */
/* TODO move in quic_rx */
static inline int qc_pkt_long(const struct quic_rx_packet *pkt)
{
return pkt->type != QUIC_PACKET_TYPE_SHORT;
Expand All @@ -534,19 +536,22 @@ static inline int qc_el_rx_pkts(struct quic_enc_level *qel)
}

/* Increment the reference counter of <pkt> */
/* TODO move in quic_rx */
static inline void quic_rx_packet_refinc(struct quic_rx_packet *pkt)
{
pkt->refcnt++;
}

/* Decrement the reference counter of <pkt> while remaining positive */
/* TODO move in quic_rx */
static inline void quic_rx_packet_refdec(struct quic_rx_packet *pkt)
{
if (pkt->refcnt)
pkt->refcnt--;
}

/* Delete all RX packets for <qel> QUIC encryption level */
/* TODO move in quic_rx */
static inline void qc_el_rx_pkts_del(struct quic_enc_level *qel)
{
struct eb64_node *node;
Expand All @@ -562,6 +567,7 @@ static inline void qc_el_rx_pkts_del(struct quic_enc_level *qel)
}
}

/* TODO move in quic_rx */
static inline void qc_list_qel_rx_pkts(struct quic_enc_level *qel)
{
struct eb64_node *node;
Expand Down
15 changes: 12 additions & 3 deletions src/quic_conn.c
Original file line number Diff line number Diff line change
Expand Up @@ -299,9 +299,6 @@ void qc_check_close_on_released_mux(struct quic_conn *qc)
TRACE_LEAVE(QUIC_EV_CONN_CLOSE, qc);
}

int ssl_sock_get_alpn(const struct connection *conn, void *xprt_ctx,
const char **str, int *len);

/* Finalize <qc> QUIC connection:
* MUST be called after having received the remote transport parameters which
Expand Down Expand Up @@ -332,6 +329,7 @@ int qc_conn_finalize(struct quic_conn *qc, int server)
return ret;
}

/* TODO rename */
void qc_cc_err_count_inc(struct quic_conn *qc, struct quic_frame *frm)
{
TRACE_ENTER(QUIC_EV_CONN_CLOSE, qc);
Expand Down Expand Up @@ -472,6 +470,7 @@ void qc_detach_th_ctx_list(struct quic_conn *qc, int closing)
* as HKDF input secret to generate this token.
* Return 1 if succeeded, 0 if not.
*/
/* TODO move in a new file quic_token ? */
int quic_stateless_reset_token_cpy(unsigned char *pos, size_t len,
const unsigned char *salt, size_t saltlen)
{
Expand All @@ -491,6 +490,7 @@ int quic_stateless_reset_token_cpy(unsigned char *pos, size_t len,
/* Initialize the stateless reset token attached to <conn_id> connection ID.
* Returns 1 if succeeded, 0 if not.
*/
/* TODO move in a new file quic_token ? */
static int quic_stateless_reset_token_init(struct quic_connection_id *conn_id)
{
/* Output secret */
Expand All @@ -507,6 +507,7 @@ static int quic_stateless_reset_token_init(struct quic_connection_id *conn_id)
*
* Returns the derived CID.
*/
/* TODO create a new quic_cid ? */
struct quic_cid quic_derive_cid(const struct quic_cid *orig,
const struct sockaddr_storage *addr)
{
Expand Down Expand Up @@ -569,6 +570,7 @@ struct quic_cid quic_derive_cid(const struct quic_cid *orig,
*
* Returns the thread ID or a negative error code.
*/
/* TODO move in a new file quic_cid */
int quic_get_cid_tid(const unsigned char *cid, size_t cid_len,
const struct sockaddr_storage *cli_addr,
unsigned char *pos, size_t len)
Expand Down Expand Up @@ -622,6 +624,7 @@ int quic_get_cid_tid(const unsigned char *cid, size_t cid_len,
*
* Returns the new CID if succeeded, NULL if not.
*/
/* TODO move in a new file quic_cid */
struct quic_connection_id *new_quic_cid(struct eb_root *root,
struct quic_conn *qc,
const struct quic_cid *orig,
Expand Down Expand Up @@ -1005,6 +1008,7 @@ void quic_cstream_free(struct quic_cstream *cs)
/* Allocate a new QUIC stream for <qc>.
* Return it if succeeded, NULL if not.
*/
/* TODO move in a new file quic_cstream / or quic_tls ? */
struct quic_cstream *quic_cstream_new(struct quic_conn *qc)
{
struct quic_cstream *cs, *ret_cs = NULL;
Expand Down Expand Up @@ -1134,6 +1138,7 @@ struct task *qc_process_timer(struct task *task, void *ctx, unsigned int state)
/* Try to increment <l> handshake current counter. If listener limit is
* reached, incrementation is rejected and 0 is returned.
*/
/* TODO move in quic_sock voir listener ? */
static int quic_increment_curr_handshake(struct listener *l)
{
unsigned int count, next;
Expand Down Expand Up @@ -1802,12 +1807,14 @@ const struct quic_version *qc_supported_version(uint32_t version)
return NULL;
}

/* TODO move in quic_ssl */
static void __quic_conn_init(void)
{
ha_quic_meth = BIO_meth_new(0x666, "ha QUIC methods");
}
INITCALL0(STG_REGISTER, __quic_conn_init);

/* TODO move in quic_ssl */
static void __quic_conn_deinit(void)
{
BIO_meth_free(ha_quic_meth);
Expand Down Expand Up @@ -1859,6 +1866,7 @@ int qc_check_dcid(struct quic_conn *qc, unsigned char *dcid, size_t dcid_len)
* <end> being at one byte past the end of this datagram.
* Returns 1 if succeeded, 0 if not.
*/
/* TODO move in quic_sock */
int quic_get_dgram_dcid(unsigned char *pos, const unsigned char *end,
unsigned char **dcid, size_t *dcid_len)
{
Expand Down Expand Up @@ -2051,6 +2059,7 @@ void qc_finalize_affinity_rebind(struct quic_conn *qc)
TRACE_LEAVE(QUIC_EV_CONN_SET_AFFINITY, qc);
}

/* TODO move in quic_cli */
static void init_quic()
{
int thr;
Expand Down
Loading

0 comments on commit c27b26a

Please sign in to comment.