]> git.ipfire.org Git - thirdparty/knot-dns.git/commitdiff
libknot/quic: code cleanup
authorDaniel Salzman <daniel.salzman@nic.cz>
Mon, 25 Jul 2022 10:39:17 +0000 (12:39 +0200)
committerDaniel Salzman <daniel.salzman@nic.cz>
Mon, 25 Jul 2022 15:32:04 +0000 (17:32 +0200)
src/knot/server/xdp-handler.c
src/libknot/xdp/quic.h
src/libknot/xdp/quic_conn.c
src/libknot/xdp/quic_conn.h
src/utils/kxdpgun/main.c

index d41729761b4bd5625f1780a494af8cbc239892c8..dd195c8535e85ed7245bcfc3c67cef9f7ce6fd9f 100644 (file)
@@ -184,7 +184,7 @@ xdp_handle_ctx_t *xdp_handle_init(struct server *server, knot_xdp_socket_t *xdp_
 #ifdef ENABLE_QUIC
                conf_t *pconf = conf();
                size_t udp_pl = MIN(pconf->cache.srv_udp_max_payload_ipv4, pconf->cache.srv_udp_max_payload_ipv6);
-               ctx->quic_table = knot_xquic_table_new(true, ctx->quic_max_conns, ctx->quic_max_inbufs,
+               ctx->quic_table = knot_xquic_table_new(ctx->quic_max_conns, ctx->quic_max_inbufs,
                                                       ctx->quic_max_obufs, udp_pl, server->quic_creds);
                if (ctx->quic_table == NULL) {
                        xdp_handle_free(ctx);
index c2b6769b0b34663f27877974f2bfa8896c239560..943a2f371ce9dac426978fd5f33e28533d80e743 100644 (file)
     along with this program.  If not, see <https://www.gnu.org/licenses/>.
  */
 
+/*!
+ * \file
+ *
+ * \brief General QUIC functionality.
+ *
+ * \addtogroup xdp
+ * @{
+ */
+
 #pragma once
 
 #include "libknot/xdp/quic_conn.h"
@@ -34,8 +43,8 @@ struct knot_quic_session *knot_xquic_session_save(knot_xquic_conn_t *conn);
 /*!
  * \brief Loads data needed for session resumption.
  *
- * \param conn   QUIC connection.
- * \param conn   QUIC session context.
+ * \param conn     QUIC connection.
+ * \param session  QUIC session context.
  *
  * \return KNOT_E*
  */
@@ -58,13 +67,17 @@ struct knot_quic_creds *knot_xquic_init_creds(bool server, const char *tls_cert,
  */
 void knot_xquic_free_creds(struct knot_quic_creds *creds);
 
+/*!
+ * \brief Returns timeout value for the connection.
+ */
 uint64_t xquic_conn_get_timeout(knot_xquic_conn_t *conn);
 
 /*!
  * \brief Check if connection timed out due to inactivity.
  *
  * \param conn   QUIC connection.
- * \param now    In/out: current monotonic time. Use zero first and reuse for next calls for optimization.
+ * \param now    In/out: current monotonic time. Use zero first and reuse for
+ *               next calls for optimization.
  *
  * \return True if the connection timed out idle.
  */
@@ -117,3 +130,5 @@ int knot_xquic_handle(knot_xquic_table_t *table, knot_xdp_msg_t *msg,
 int knot_xquic_send(knot_xquic_table_t *quic_table, knot_xquic_conn_t *relay,
                     knot_xdp_socket_t *sock, knot_xdp_msg_t *in_msg,
                     int handle_ret, unsigned max_msgs, bool ignore_lastbyte);
+
+/*! @} */
index af169cde5c7654428cb126634d754b0dc4d68f7b..a9683fd8834a1d8c9ae7c4d99181351186b8dc5e 100644 (file)
@@ -35,8 +35,8 @@
 #define BUCKETS_PER_CONNS 8 // Each connecion has several dCIDs, and each CID takes one hash table bucket.
 
 _public_
-knot_xquic_table_t *knot_xquic_table_new(bool server, size_t max_conns, size_t max_ibufs, size_t max_obufs,
-                                         size_t udp_pl, struct knot_quic_creds *creds)
+knot_xquic_table_t *knot_xquic_table_new(size_t max_conns, size_t max_ibufs, size_t max_obufs,
+                                         size_t udp_payload, struct knot_quic_creds *creds)
 {
        size_t table_size = max_conns * BUCKETS_PER_CONNS;
 
@@ -49,7 +49,7 @@ knot_xquic_table_t *knot_xquic_table_new(bool server, size_t max_conns, size_t m
        res->max_conns = max_conns;
        res->ibufs_max = max_ibufs;
        res->obufs_max = max_obufs;
-       res->udp_payload_limit = udp_pl;
+       res->udp_payload_limit = udp_payload;
        init_list((list_t *)&res->timeout);
 
        res->creds = creds;
@@ -146,7 +146,8 @@ knot_xquic_cid_t **xquic_table_insert(knot_xquic_conn_t *xconn, const ngtcp2_cid
        return addto;
 }
 
-knot_xquic_conn_t *xquic_table_add(ngtcp2_conn *conn, const ngtcp2_cid *cid, knot_xquic_table_t *table)
+knot_xquic_conn_t *xquic_table_add(ngtcp2_conn *conn, const ngtcp2_cid *cid,
+                                   knot_xquic_table_t *table)
 {
        knot_xquic_conn_t *xconn = calloc(1, sizeof(*xconn));
        if (xconn == NULL) {
@@ -185,7 +186,8 @@ knot_xquic_conn_t *xquic_table_lookup(const ngtcp2_cid *cid, knot_xquic_table_t
        return *pcid == NULL ? NULL : (*pcid)->conn;
 }
 
-void xquic_conn_mark_used(knot_xquic_conn_t *conn, knot_xquic_table_t *table, uint64_t now)
+void xquic_conn_mark_used(knot_xquic_conn_t *conn, knot_xquic_table_t *table,
+                          uint64_t now)
 {
        node_t *n = (node_t *)&conn->timeout;
        list_t *l = (list_t *)&table->timeout;
@@ -248,7 +250,8 @@ void xquic_table_rem(knot_xquic_conn_t *conn, knot_xquic_table_t *table)
 }
 
 _public_
-knot_xquic_stream_t *knot_xquic_conn_get_stream(knot_xquic_conn_t *xconn, int64_t stream_id, bool create)
+knot_xquic_stream_t *knot_xquic_conn_get_stream(knot_xquic_conn_t *xconn,
+                                                int64_t stream_id, bool create)
 {
        if (stream_id % 4 != 0) {
                return NULL;
@@ -284,7 +287,8 @@ knot_xquic_stream_t *knot_xquic_conn_get_stream(knot_xquic_conn_t *xconn, int64_
                        }
                }
 
-               for (knot_xquic_stream_t *si = new_streams + xconn->streams_count; si < new_streams + new_streams_count; si++) {
+               for (knot_xquic_stream_t *si = new_streams + xconn->streams_count;
+                    si < new_streams + new_streams_count; si++) {
                        memset(si, 0, sizeof(*si));
                        init_list((list_t *)&si->outbufs);
                }
@@ -322,7 +326,8 @@ static void stream_outprocess(knot_xquic_conn_t *xconn, knot_xquic_stream_t *str
        xconn->stream_inprocess = -1;
 }
 
-int knot_xquic_stream_recv_data(knot_xquic_conn_t *xconn, int64_t stream_id, const uint8_t *data, size_t len, bool fin)
+int knot_xquic_stream_recv_data(knot_xquic_conn_t *xconn, int64_t stream_id,
+                                const uint8_t *data, size_t len, bool fin)
 {
        if (len == 0) {
                return KNOT_EINVAL;
@@ -335,7 +340,8 @@ int knot_xquic_stream_recv_data(knot_xquic_conn_t *xconn, int64_t stream_id, con
 
        struct iovec in = { (void *)data, len }, *outs;
        size_t outs_count;
-       int ret = knot_tcp_inbuf_update(&stream->inbuf, in, &outs, &outs_count, &xconn->ibufs_size);
+       int ret = knot_tcp_inbuf_update(&stream->inbuf, in, &outs, &outs_count,
+                                       &xconn->ibufs_size);
        if (ret != KNOT_EOK || (outs_count == 0 && !fin)) {
                return ret;
        }
@@ -352,7 +358,8 @@ int knot_xquic_stream_recv_data(knot_xquic_conn_t *xconn, int64_t stream_id, con
 }
 
 _public_
-knot_xquic_stream_t *knot_xquic_stream_get_process(knot_xquic_conn_t *xconn, int64_t *stream_id)
+knot_xquic_stream_t *knot_xquic_stream_get_process(knot_xquic_conn_t *xconn,
+                                                   int64_t *stream_id)
 {
        if (xconn->stream_inprocess < 0) {
                return NULL;
@@ -365,7 +372,8 @@ knot_xquic_stream_t *knot_xquic_stream_get_process(knot_xquic_conn_t *xconn, int
 }
 
 _public_
-uint8_t *knot_xquic_stream_add_data(knot_xquic_conn_t *xconn, int64_t stream_id, uint8_t *data, size_t len)
+uint8_t *knot_xquic_stream_add_data(knot_xquic_conn_t *xconn, int64_t stream_id,
+                                    uint8_t *data, size_t len)
 {
        knot_xquic_stream_t *s = knot_xquic_conn_get_stream(xconn, stream_id, true);
        if (s == NULL) {
@@ -397,7 +405,8 @@ uint8_t *knot_xquic_stream_add_data(knot_xquic_conn_t *xconn, int64_t stream_id,
        return obuf->buf + prefix;
 }
 
-void knot_xquic_stream_ack_data(knot_xquic_conn_t *xconn, int64_t stream_id, size_t end_acked, bool keep_stream)
+void knot_xquic_stream_ack_data(knot_xquic_conn_t *xconn, int64_t stream_id,
+                                size_t end_acked, bool keep_stream)
 {
        knot_xquic_stream_t *s = knot_xquic_conn_get_stream(xconn, stream_id, false);
        if (s == NULL) {
@@ -443,7 +452,8 @@ void knot_xquic_stream_ack_data(knot_xquic_conn_t *xconn, int64_t stream_id, siz
        }
 }
 
-void knot_xquic_stream_mark_sent(knot_xquic_conn_t *xconn, int64_t stream_id, size_t amount_sent)
+void knot_xquic_stream_mark_sent(knot_xquic_conn_t *xconn, int64_t stream_id,
+                                 size_t amount_sent)
 {
        knot_xquic_stream_t *s = knot_xquic_conn_get_stream(xconn, stream_id, false);
        if (s == NULL) {
index 89732ca2af73e5b3230c474db3b4f56c0f9e854f..39cdbfbae2218bcfe16493d4c8830a5599d458d9 100644 (file)
     along with this program.  If not, see <https://www.gnu.org/licenses/>.
  */
 
+/*!
+ * \file
+ *
+ * \brief QUIC connection management.
+ *
+ * \addtogroup xdp
+ * @{
+ */
+
 #pragma once
 
 #include <linux/if_ether.h>
@@ -106,7 +115,6 @@ typedef struct knot_xquic_table {
 /*!
  * \brief Allocate QUIC connections hash table.
  *
- * \param server       Initialize server-side QUIC conn table.
  * \param max_conns    Maximum nuber of connections.
  * \param max_ibufs    Maximum size of buffers for fragmented incomming DNS msgs.
  * \param max_obufs    Maximum size of buffers for un-ACKed outgoing data.
@@ -115,8 +123,8 @@ typedef struct knot_xquic_table {
  *
  * \return Allocated table, or NULL.
  */
-knot_xquic_table_t *knot_xquic_table_new(bool server, size_t max_conns, size_t max_ibufs, size_t max_obufs,
-                                         size_t udp_pl, struct knot_quic_creds *creds);
+knot_xquic_table_t *knot_xquic_table_new(size_t max_conns, size_t max_ibufs, size_t max_obufs,
+                                         size_t udp_payload, struct knot_quic_creds *creds);
 
 /*!
  * \brief Free QUIC table including its contents.
@@ -129,15 +137,13 @@ void knot_xquic_table_free(knot_xquic_table_t *table);
  * \brief Close timed out connections and some oldest ones if table full.
  *
  * \param table            QUIC table to be cleaned up.
- * \param max_conns        Limit for connections count in table.
- * \param max_obufs        Limit of allocated outgiong payload buffers.
  * \param timed_out        Out: number of closed connections due to timeout.
  * \param force_closed     Out: number of closed connections due to overfull.
  *
  * \return KNOT_E*
  */
-int knot_xquic_table_sweep(knot_xquic_table_t *table,
-                           uint32_t *timed_out, uint32_t *force_closed);
+int knot_xquic_table_sweep(knot_xquic_table_t *table, uint32_t *timed_out,
+                           uint32_t *force_closed);
 
 /*!
  * \brief Add new connection/CID link to table.
@@ -148,7 +154,8 @@ int knot_xquic_table_sweep(knot_xquic_table_t *table,
  *
  * \return Pointer on the CID reference in table, or NULL.
  */
-knot_xquic_cid_t **xquic_table_insert(knot_xquic_conn_t *xconn, const struct ngtcp2_cid *cid,
+knot_xquic_cid_t **xquic_table_insert(knot_xquic_conn_t *xconn,
+                                      const struct ngtcp2_cid *cid,
                                       knot_xquic_table_t *table);
 
 /*!
@@ -160,7 +167,9 @@ knot_xquic_cid_t **xquic_table_insert(knot_xquic_conn_t *xconn, const struct ngt
  *
  * \return Allocated (and linked) Knot conn struct, or NULL.
  */
-knot_xquic_conn_t *xquic_table_add(struct ngtcp2_conn *conn, const struct ngtcp2_cid *cid, knot_xquic_table_t *table);
+knot_xquic_conn_t *xquic_table_add(struct ngtcp2_conn *conn,
+                                   const struct ngtcp2_cid *cid,
+                                   knot_xquic_table_t *table);
 
 /*!
  * \brief Lookup connection/CID link in table.
@@ -170,7 +179,8 @@ knot_xquic_conn_t *xquic_table_add(struct ngtcp2_conn *conn, const struct ngtcp2
  *
  * \return Pointer on the CID reference in table, or NULL.
  */
-knot_xquic_cid_t **xquic_table_lookup2(const struct ngtcp2_cid *cid, knot_xquic_table_t *table);
+knot_xquic_cid_t **xquic_table_lookup2(const struct ngtcp2_cid *cid,
+                                       knot_xquic_table_t *table);
 
 /*!
  * \brief Lookup QUIC connection in table.
@@ -180,12 +190,14 @@ knot_xquic_cid_t **xquic_table_lookup2(const struct ngtcp2_cid *cid, knot_xquic_
  *
  * \return Connection that the CID belongs to, or NULL.
  */
-knot_xquic_conn_t *xquic_table_lookup(const struct ngtcp2_cid *cid, knot_xquic_table_t *table);
+knot_xquic_conn_t *xquic_table_lookup(const struct ngtcp2_cid *cid,
+                                      knot_xquic_table_t *table);
 
 /*!
  * \brief Put the connection on the end of timeout queue.
  */
-void xquic_conn_mark_used(knot_xquic_conn_t *conn, knot_xquic_table_t *table, uint64_t now);
+void xquic_conn_mark_used(knot_xquic_conn_t *conn, knot_xquic_table_t *table,
+                          uint64_t now);
 
 /*!
  * \brief Remove connection/CID link from table.
@@ -220,7 +232,8 @@ void xquic_table_rem(knot_xquic_conn_t *conn, knot_xquic_table_t *table);
  *
  * \return Stream or NULL.
  */
-knot_xquic_stream_t *knot_xquic_conn_get_stream(knot_xquic_conn_t *xconn, int64_t stream_id, bool create);
+knot_xquic_stream_t *knot_xquic_conn_get_stream(knot_xquic_conn_t *xconn,
+                                                int64_t stream_id, bool create);
 
 /*!
  * \brief Process incomming stream data to stream structure.
@@ -233,7 +246,8 @@ knot_xquic_stream_t *knot_xquic_conn_get_stream(knot_xquic_conn_t *xconn, int64_
  *
  * \return KNOT_E*
  */
-int knot_xquic_stream_recv_data(knot_xquic_conn_t *xconn, int64_t stream_id, const uint8_t *data, size_t len, bool fin);
+int knot_xquic_stream_recv_data(knot_xquic_conn_t *xconn, int64_t stream_id,
+                                const uint8_t *data, size_t len, bool fin);
 
 /*!
  * \brief Get next stream which has pending incomming data to be processed.
@@ -243,7 +257,8 @@ int knot_xquic_stream_recv_data(knot_xquic_conn_t *xconn, int64_t stream_id, con
  *
  * \return Stream with incomming data.
  */
-knot_xquic_stream_t *knot_xquic_stream_get_process(knot_xquic_conn_t *xconn, int64_t *stream_id);
+knot_xquic_stream_t *knot_xquic_stream_get_process(knot_xquic_conn_t *xconn,
+                                                   int64_t *stream_id);
 
 /*!
  * \brief Add outgiong data to the stream for sending.
@@ -255,7 +270,8 @@ knot_xquic_stream_t *knot_xquic_stream_get_process(knot_xquic_conn_t *xconn, int
  *
  * \return NULL if error, or pinter at the data in outgiong buffer.
  */
-uint8_t *knot_xquic_stream_add_data(knot_xquic_conn_t *xconn, int64_t stream_id, uint8_t *data, size_t len);
+uint8_t *knot_xquic_stream_add_data(knot_xquic_conn_t *xconn, int64_t stream_id,
+                                    uint8_t *data, size_t len);
 
 /*!
  * \brief Mark outgiong data as acknowledged after ACK received.
@@ -265,7 +281,8 @@ uint8_t *knot_xquic_stream_add_data(knot_xquic_conn_t *xconn, int64_t stream_id,
  * \param end_acked      Offset of ACKed data + ACKed length.
  * \param keep_stream    Don't free the stream even when ACKed all outgoing data.
  */
-void knot_xquic_stream_ack_data(knot_xquic_conn_t *xconn, int64_t stream_id, size_t end_acked, bool keep_stream);
+void knot_xquic_stream_ack_data(knot_xquic_conn_t *xconn, int64_t stream_id,
+                                size_t end_acked, bool keep_stream);
 
 /*!
  * \brief Mark outgoing data as sent.
@@ -274,13 +291,17 @@ void knot_xquic_stream_ack_data(knot_xquic_conn_t *xconn, int64_t stream_id, siz
  * \param stream_id      Stream ID of sent data.
  * \param amount_sent    Length of sent data.
  */
-void knot_xquic_stream_mark_sent(knot_xquic_conn_t *xconn, int64_t stream_id, size_t amount_sent);
+void knot_xquic_stream_mark_sent(knot_xquic_conn_t *xconn, int64_t stream_id,
+                                 size_t amount_sent);
 
 /*!
  * \brief Toggle sending Retry packet as a reaction to Initial packet of new connection.
  *
  * \param table       Connection table.
  *
- * \return True if instead of continuing handshake, Retry packet shall be sent to verify counterpart's address.
+ * \return True if instead of continuing handshake, Retry packet shall be sent
+ *              to verify counterpart's address.
  */
 bool xquic_require_retry(knot_xquic_table_t *table);
+
+/*! @} */
index d668514de3653d7ac91acbe67797aaee96980857..a18186ece981f69d17fc46cf745901ce40d017b1 100644 (file)
@@ -444,7 +444,7 @@ void *xdp_gun_thread(void *_ctx)
                        ERR2("failed to initialize QUIC context\n");
                        return NULL;
                }
-               quic_table = knot_xquic_table_new(false, ctx->qps * 100, SIZE_MAX, SIZE_MAX, 1232, quic_creds);
+               quic_table = knot_xquic_table_new(ctx->qps * 100, SIZE_MAX, SIZE_MAX, 1232, quic_creds);
                if (quic_table == NULL) {
                        ERR2("failed to allocate QUIC connection table\n");
                        return NULL;