Make s_client -quic -debug work
authorMatt Caswell <matt@openssl.org>
Fri, 13 Oct 2023 11:19:40 +0000 (12:19 +0100)
committerMatt Caswell <matt@openssl.org>
Wed, 25 Oct 2023 08:40:48 +0000 (09:40 +0100)
The callback that makes -debug print the data sent/received needed extending
for the new QUIC callback codes.

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Hugo Landau <hlandau@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/22480)

apps/lib/s_cb.c
crypto/bio/bio_lib.c

index dcfea55dc5696e1fe80fdc1be7a83708939600a0..743d88993f4f52c7232273ab0be69eabd38bc754 100644 (file)
@@ -434,12 +434,15 @@ long bio_dump_callback(BIO *bio, int cmd, const char *argp, size_t len,
                        int argi, long argl, int ret, size_t *processed)
 {
     BIO *out;
+    BIO_MMSG_CB_ARGS *mmsgargs;
+    size_t i;
 
     out = (BIO *)BIO_get_callback_arg(bio);
     if (out == NULL)
         return ret;
 
-    if (cmd == (BIO_CB_READ | BIO_CB_RETURN)) {
+    switch (cmd) {
+    case (BIO_CB_READ | BIO_CB_RETURN):
         if (ret > 0 && processed != NULL) {
             BIO_printf(out, "read from %p [%p] (%zu bytes => %zu (0x%zX))\n",
                        (void *)bio, (void *)argp, len, *processed, *processed);
@@ -448,7 +451,9 @@ long bio_dump_callback(BIO *bio, int cmd, const char *argp, size_t len,
             BIO_printf(out, "read from %p [%p] (%zu bytes => %d)\n",
                        (void *)bio, (void *)argp, len, ret);
         }
-    } else if (cmd == (BIO_CB_WRITE | BIO_CB_RETURN)) {
+        break;
+
+    case (BIO_CB_WRITE | BIO_CB_RETURN):
         if (ret > 0 && processed != NULL) {
             BIO_printf(out, "write to %p [%p] (%zu bytes => %zu (0x%zX))\n",
                        (void *)bio, (void *)argp, len, *processed, *processed);
@@ -457,6 +462,51 @@ long bio_dump_callback(BIO *bio, int cmd, const char *argp, size_t len,
             BIO_printf(out, "write to %p [%p] (%zu bytes => %d)\n",
                        (void *)bio, (void *)argp, len, ret);
         }
+        break;
+
+    case (BIO_CB_RECVMMSG | BIO_CB_RETURN):
+        mmsgargs = (BIO_MMSG_CB_ARGS *)argp;
+        if (ret > 0) {
+            for (i = 0; i < *(mmsgargs->msgs_processed); i++) {
+                BIO_MSG *msg = (BIO_MSG *)((char *)mmsgargs->msg
+                                           + (i * mmsgargs->stride));
+
+                BIO_printf(out, "read from %p [%p] (%zu bytes => %zu (0x%zX))\n",
+                           (void *)bio, (void *)msg->data, msg->data_len,
+                           msg->data_len, msg->data_len);
+                BIO_dump(out, msg->data, msg->data_len);
+            }
+        } else if (mmsgargs->num_msg > 0) {
+            BIO_MSG *msg = mmsgargs->msg;
+
+            BIO_printf(out, "read from %p [%p] (%zu bytes => %d)\n",
+                       (void *)bio, (void *)msg->data, msg->data_len, ret);
+        }
+        break;
+
+    case (BIO_CB_SENDMMSG | BIO_CB_RETURN):
+        mmsgargs = (BIO_MMSG_CB_ARGS *)argp;
+        if (ret > 0) {
+            for (i = 0; i < *(mmsgargs->msgs_processed); i++) {
+                BIO_MSG *msg = (BIO_MSG *)((char *)mmsgargs->msg
+                                           + (i * mmsgargs->stride));
+
+                BIO_printf(out, "write to %p [%p] (%zu bytes => %zu (0x%zX))\n",
+                           (void *)bio, (void *)msg->data, msg->data_len,
+                           msg->data_len, msg->data_len);
+                BIO_dump(out, msg->data, msg->data_len);
+            }
+        } else if (mmsgargs->num_msg > 0) {
+            BIO_MSG *msg = mmsgargs->msg;
+
+            BIO_printf(out, "write to %p [%p] (%zu bytes => %d)\n",
+                       (void *)bio, (void *)msg->data, msg->data_len, ret);
+        }
+        break;
+
+    default:
+        /* do nothing */
+        break;
     }
     return ret;
 }
index dc7f1b7b9eb89c3488267e9e45a53f698e088185..e4f72bcd1b8a140cd85f5cfc0f39d47bd28dc7d9 100644 (file)
@@ -418,8 +418,8 @@ int BIO_sendmmsg(BIO *b, BIO_MSG *msg,
         args.msgs_processed = msgs_processed;
 
         ret = (size_t)bio_call_callback(b, BIO_CB_SENDMMSG, (void *)&args,
-                                        0, 0, 0, 0, NULL);
-        if (ret == 0)
+                                        0, 0, 0, 1, NULL);
+        if (ret <= 0)
             return 0;
     }
 
@@ -433,7 +433,7 @@ int BIO_sendmmsg(BIO *b, BIO_MSG *msg,
 
     if (HAS_CALLBACK(b))
         ret = (size_t)bio_call_callback(b, BIO_CB_SENDMMSG | BIO_CB_RETURN,
-                                        (void *)&args, ret, 0, 0, 0, NULL);
+                                        (void *)&args, ret, 0, 0, ret, NULL);
 
     return ret;
 }
@@ -465,8 +465,8 @@ int BIO_recvmmsg(BIO *b, BIO_MSG *msg,
         args.msgs_processed = msgs_processed;
 
         ret = bio_call_callback(b, BIO_CB_RECVMMSG, (void *)&args,
-                                0, 0, 0, 0, NULL);
-        if (ret == 0)
+                                0, 0, 0, 1, NULL);
+        if (ret <= 0)
             return 0;
     }
 
@@ -480,7 +480,7 @@ int BIO_recvmmsg(BIO *b, BIO_MSG *msg,
 
     if (HAS_CALLBACK(b))
         ret = (size_t)bio_call_callback(b, BIO_CB_RECVMMSG | BIO_CB_RETURN,
-                                        (void *)&args, ret, 0, 0, 0, NULL);
+                                        (void *)&args, ret, 0, 0, ret, NULL);
 
     return ret;
 }