From: Frédéric Lécaille Date: Mon, 27 Nov 2023 11:01:36 +0000 (+0100) Subject: REORG: quic: Move the QUIC DCID parser to quic_sock.c X-Git-Tag: v2.9-dev12~63 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f74d882ef041c9b9c8bd20c436cda17fa3ada39f;p=thirdparty%2Fhaproxy.git REORG: quic: Move the QUIC DCID parser to quic_sock.c Move quic_get_dgram_dcid() from quic_conn.c to quic_sock.c because only used in this file and define it as static. --- diff --git a/include/haproxy/quic_conn.h b/include/haproxy/quic_conn.h index 9ff559646c..725633f3d5 100644 --- a/include/haproxy/quic_conn.h +++ b/include/haproxy/quic_conn.h @@ -191,8 +191,6 @@ void quic_set_connection_close(struct quic_conn *qc, const struct quic_err err); void quic_set_tls_alert(struct quic_conn *qc, int alert); int quic_set_app_ops(struct quic_conn *qc, const unsigned char *alpn, size_t alpn_len); int qc_check_dcid(struct quic_conn *qc, unsigned char *dcid, size_t dcid_len); -int quic_get_dgram_dcid(unsigned char *buf, const unsigned char *end, - unsigned char **dcid, size_t *dcid_len); struct quic_cid quic_derive_cid(const struct quic_cid *orig, const struct sockaddr_storage *addr); int quic_get_cid_tid(const unsigned char *cid, size_t cid_len, diff --git a/src/quic_conn.c b/src/quic_conn.c index 92d48fe2a3..7f9837f827 100644 --- a/src/quic_conn.c +++ b/src/quic_conn.c @@ -1592,47 +1592,6 @@ int qc_check_dcid(struct quic_conn *qc, unsigned char *dcid, size_t dcid_len) return 0; } -/* Retrieve the DCID from a QUIC datagram or packet at position, - * being at one byte past the end of this datagram. - * Returns 1 if succeeded, 0 if not. - */ -int quic_get_dgram_dcid(unsigned char *pos, const unsigned char *end, - unsigned char **dcid, size_t *dcid_len) -{ - int ret = 0, long_header; - size_t minlen, skip; - - TRACE_ENTER(QUIC_EV_CONN_RXPKT); - - if (!(*pos & QUIC_PACKET_FIXED_BIT)) { - TRACE_PROTO("fixed bit not set", QUIC_EV_CONN_RXPKT); - goto err; - } - - long_header = *pos & QUIC_PACKET_LONG_HEADER_BIT; - minlen = long_header ? QUIC_LONG_PACKET_MINLEN : - QUIC_SHORT_PACKET_MINLEN + QUIC_HAP_CID_LEN + QUIC_TLS_TAG_LEN; - skip = long_header ? QUIC_LONG_PACKET_DCID_OFF : QUIC_SHORT_PACKET_DCID_OFF; - if (end - pos < minlen) - goto err; - - pos += skip; - *dcid_len = long_header ? *pos++ : QUIC_HAP_CID_LEN; - if (*dcid_len > QUIC_CID_MAXLEN || end - pos <= *dcid_len) - goto err; - - *dcid = pos; - - ret = 1; - leave: - TRACE_LEAVE(QUIC_EV_CONN_RXPKT); - return ret; - - err: - TRACE_PROTO("wrong datagram", QUIC_EV_CONN_RXPKT); - goto leave; -} - /* Notify upper layer of a fatal error which forces to close the connection. */ void qc_notify_err(struct quic_conn *qc) { diff --git a/src/quic_sock.c b/src/quic_sock.c index 323fe6cbde..c479249b74 100644 --- a/src/quic_sock.c +++ b/src/quic_sock.c @@ -208,6 +208,48 @@ struct task *quic_lstnr_dghdlr(struct task *t, void *ctx, unsigned int state) return t; } +/* Retrieve the DCID from a QUIC datagram or packet at position, + * being at one byte past the end of this datagram. + * Returns 1 if succeeded, 0 if not. + */ +static int quic_get_dgram_dcid(unsigned char *pos, const unsigned char *end, + unsigned char **dcid, size_t *dcid_len) +{ + int ret = 0, long_header; + size_t minlen, skip; + + TRACE_ENTER(QUIC_EV_CONN_RXPKT); + + if (!(*pos & QUIC_PACKET_FIXED_BIT)) { + TRACE_PROTO("fixed bit not set", QUIC_EV_CONN_RXPKT); + goto err; + } + + long_header = *pos & QUIC_PACKET_LONG_HEADER_BIT; + minlen = long_header ? QUIC_LONG_PACKET_MINLEN : + QUIC_SHORT_PACKET_MINLEN + QUIC_HAP_CID_LEN + QUIC_TLS_TAG_LEN; + skip = long_header ? QUIC_LONG_PACKET_DCID_OFF : QUIC_SHORT_PACKET_DCID_OFF; + if (end - pos < minlen) + goto err; + + pos += skip; + *dcid_len = long_header ? *pos++ : QUIC_HAP_CID_LEN; + if (*dcid_len > QUIC_CID_MAXLEN || end - pos <= *dcid_len) + goto err; + + *dcid = pos; + + ret = 1; + leave: + TRACE_LEAVE(QUIC_EV_CONN_RXPKT); + return ret; + + err: + TRACE_PROTO("wrong datagram", QUIC_EV_CONN_RXPKT); + goto leave; +} + + /* Retrieve the DCID from the datagram found at position and deliver it to the * correct datagram handler. * Return 1 if a correct datagram could be found, 0 if not.