summaryrefslogtreecommitdiffstats
path: root/test/helpers/quictestlib.c
diff options
context:
space:
mode:
authorMatt Caswell <matt@openssl.org>2023-09-19 11:52:42 +0100
committerMatt Caswell <matt@openssl.org>2023-09-22 13:56:43 +0100
commit35bd8a60043bde500f777e465530076524d2534a (patch)
treebd31d264091952f4e37f3ba8527712c12b713f2a /test/helpers/quictestlib.c
parent5d3933eef0d937a4845a439d5fbfa76738592fc0 (diff)
Add a packet splitting BIO
Provide a BIO filter that can split QUIC datagrams containing multiple packets, such that each packet is in its own datagram. Reviewed-by: Tim Hudson <tjh@openssl.org> Reviewed-by: Paul Dale <pauli@openssl.org> (Merged from https://github.com/openssl/openssl/pull/22157)
Diffstat (limited to 'test/helpers/quictestlib.c')
-rw-r--r--test/helpers/quictestlib.c61
1 files changed, 61 insertions, 0 deletions
diff --git a/test/helpers/quictestlib.c b/test/helpers/quictestlib.c
index 28791267ed..6381d720ff 100644
--- a/test/helpers/quictestlib.c
+++ b/test/helpers/quictestlib.c
@@ -1044,3 +1044,64 @@ int qtest_fault_resize_datagram(QTEST_FAULT *fault, size_t newlen)
return 1;
}
+
+/* There isn't a public function to do BIO_ADDR_copy() so we create one */
+int bio_addr_copy(BIO_ADDR *dst, BIO_ADDR *src)
+{
+ size_t len;
+ void *data = NULL;
+ int res = 0;
+ int family;
+
+ if (src == NULL || dst == NULL)
+ return 0;
+
+ family = BIO_ADDR_family(src);
+ if (family == AF_UNSPEC) {
+ BIO_ADDR_clear(dst);
+ return 1;
+ }
+
+ if (!BIO_ADDR_rawaddress(src, NULL, &len))
+ return 0;
+
+ if (len > 0) {
+ data = OPENSSL_malloc(len);
+ if (!TEST_ptr(data))
+ return 0;
+ }
+
+ if (!BIO_ADDR_rawaddress(src, data, &len))
+ goto err;
+
+ if (!BIO_ADDR_rawmake(src, family, data, len, BIO_ADDR_rawport(src)))
+ goto err;
+
+ res = 1;
+ err:
+ OPENSSL_free(data);
+ return res;
+}
+
+int bio_msg_copy(BIO_MSG *dst, BIO_MSG *src)
+{
+ /*
+ * Note it is assumed that the originally allocated data sizes for dst and
+ * src are the same
+ */
+ memcpy(dst->data, src->data, src->data_len);
+ dst->data_len = src->data_len;
+ dst->flags = src->flags;
+ if (dst->local != NULL) {
+ if (src->local != NULL) {
+ if (!TEST_true(bio_addr_copy(dst->local, src->local)))
+ return 0;
+ } else {
+ BIO_ADDR_clear(dst->local);
+ }
+ }
+ if (!TEST_true(bio_addr_copy(dst->peer, src->peer)))
+ return 0;
+
+ return 1;
+}