]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: quic: new_quic_cid() code moving
authorFrédéric Lécaille <flecaille@haproxy.com>
Fri, 6 May 2022 12:18:53 +0000 (14:18 +0200)
committerFrédéric Lécaille <flecaille@haproxy.com>
Thu, 12 May 2022 15:48:35 +0000 (17:48 +0200)
This function will have to call another one from quic_tls.[ch] soon.
As we do not want to include quic_tls.h from xprt_quic.h because
quic_tls.h already includes xprt_quic.h, let's moving it into
xprt_quic.c.

include/haproxy/xprt_quic.h
src/xprt_quic.c

index 2c98ed602878c97b18b31290c6f6f616f57a7ab0..dc90f3d205abec8c4e7f1ddedaaeae7fa7011afc 100644 (file)
@@ -179,49 +179,6 @@ static inline void quic_pin_cid_to_tid(unsigned char *cid, int target_tid)
        cid[0] = cid[0] - (cid[0] % global.nbthread) + target_tid;
 }
 
-/* Allocate a new CID with <seq_num> as sequence number and attach it to <root>
- * ebtree.
- *
- * The CID is randomly generated in part with the result altered to be
- * associated with the current thread ID. This means this function must only
- * be called by the quic_conn thread.
- *
- * Returns the new CID if succeeded, NULL if not.
- */
-static inline struct quic_connection_id *new_quic_cid(struct eb_root *root,
-                                                      struct quic_conn *qc,
-                                                      int seq_num)
-{
-       struct quic_connection_id *cid;
-
-       cid = pool_alloc(pool_head_quic_connection_id);
-       if (!cid)
-               return NULL;
-
-       cid->cid.len = QUIC_HAP_CID_LEN;
-       if (RAND_bytes(cid->cid.data, cid->cid.len) != 1 ||
-           RAND_bytes(cid->stateless_reset_token,
-                      sizeof cid->stateless_reset_token) != 1) {
-               fprintf(stderr, "Could not generate %d random bytes\n", cid->cid.len);
-               goto err;
-       }
-
-       quic_pin_cid_to_tid(cid->cid.data, tid);
-
-       cid->qc = qc;
-
-       cid->seq_num.key = seq_num;
-       cid->retire_prior_to = 0;
-       /* insert the allocated CID in the quic_conn tree */
-       eb64_insert(root, &cid->seq_num);
-
-       return cid;
-
- err:
-       pool_free(pool_head_quic_connection_id, cid);
-       return NULL;
-}
-
 /* The maximum size of a variable-length QUIC integer encoded with 1 byte */
 #define QUIC_VARINT_1_BYTE_MAX       ((1UL <<  6) - 1)
 /* The maximum size of a variable-length QUIC integer encoded with 2 bytes */
index 66c3555a4891901d586aa708b0b93cb1e9e72aeb..0d598ce4635dffa68b163f350e286d1b11e669e5 100644 (file)
@@ -3262,6 +3262,49 @@ int qc_send_ppkts(struct qring *qr, struct ssl_sock_ctx *ctx)
        return 1;
 }
 
+/* Allocate a new CID with <seq_num> as sequence number and attach it to <root>
+ * ebtree.
+ *
+ * The CID is randomly generated in part with the result altered to be
+ * associated with the current thread ID. This means this function must only
+ * be called by the quic_conn thread.
+ *
+ * Returns the new CID if succeeded, NULL if not.
+ */
+static struct quic_connection_id *new_quic_cid(struct eb_root *root,
+                                               struct quic_conn *qc,
+                                               int seq_num)
+{
+       struct quic_connection_id *cid;
+
+       cid = pool_alloc(pool_head_quic_connection_id);
+       if (!cid)
+               return NULL;
+
+       cid->cid.len = QUIC_HAP_CID_LEN;
+       if (RAND_bytes(cid->cid.data, cid->cid.len) != 1 ||
+           RAND_bytes(cid->stateless_reset_token,
+                      sizeof cid->stateless_reset_token) != 1) {
+               fprintf(stderr, "Could not generate %d random bytes\n", cid->cid.len);
+               goto err;
+       }
+
+       quic_pin_cid_to_tid(cid->cid.data, tid);
+
+       cid->qc = qc;
+
+       cid->seq_num.key = seq_num;
+       cid->retire_prior_to = 0;
+       /* insert the allocated CID in the quic_conn tree */
+       eb64_insert(root, &cid->seq_num);
+
+       return cid;
+
+ err:
+       pool_free(pool_head_quic_connection_id, cid);
+       return NULL;
+}
+
 /* Build all the frames which must be sent just after the handshake have succeeded.
  * This is essentially NEW_CONNECTION_ID frames. A QUIC server must also send
  * a HANDSHAKE_DONE frame.