Blame SOURCES/kvm-io-add-trace-events-for-websockets-frame-handling.patch

9bac43
From 3b740258b14da87d647beb87275bf16136a00985 Mon Sep 17 00:00:00 2001
9bac43
From: "Daniel P. Berrange" <berrange@redhat.com>
9bac43
Date: Wed, 20 Dec 2017 17:56:53 +0100
9bac43
Subject: [PATCH 13/42] io: add trace events for websockets frame handling
9bac43
9bac43
RH-Author: Daniel P. Berrange <berrange@redhat.com>
9bac43
Message-id: <20171220175702.29663-12-berrange@redhat.com>
9bac43
Patchwork-id: 78464
9bac43
O-Subject: [RHV-7.5 qemu-kvm-rhev PATCH v2 11/20] io: add trace events for websockets frame handling
9bac43
Bugzilla: 1518649
9bac43
RH-Acked-by: John Snow <jsnow@redhat.com>
9bac43
RH-Acked-by: Jeffrey Cody <jcody@redhat.com>
9bac43
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
9bac43
9bac43
It is useful to trace websockets frame encoding/decoding when debugging
9bac43
problems.
9bac43
9bac43
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
9bac43
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
9bac43
(cherry picked from commit 59f183bbd54eecffb8915bffe03f9c2720b28bcc)
9bac43
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
9bac43
---
9bac43
 io/channel-websock.c | 23 ++++++++++++++++++-----
9bac43
 io/trace-events      |  5 +++++
9bac43
 2 files changed, 23 insertions(+), 5 deletions(-)
9bac43
9bac43
diff --git a/io/channel-websock.c b/io/channel-websock.c
9bac43
index 3195eb2..d1d471f 100644
9bac43
--- a/io/channel-websock.c
9bac43
+++ b/io/channel-websock.c
9bac43
@@ -582,7 +582,8 @@ static gboolean qio_channel_websock_handshake_io(QIOChannel *ioc,
9bac43
 }
9bac43
 
9bac43
 
9bac43
-static void qio_channel_websock_encode_buffer(Buffer *output,
9bac43
+static void qio_channel_websock_encode_buffer(QIOChannelWebsock *ioc,
9bac43
+                                              Buffer *output,
9bac43
                                               uint8_t opcode, Buffer *buffer)
9bac43
 {
9bac43
     size_t header_size;
9bac43
@@ -608,6 +609,7 @@ static void qio_channel_websock_encode_buffer(Buffer *output,
9bac43
     }
9bac43
     header_size -= QIO_CHANNEL_WEBSOCK_HEADER_LEN_MASK;
9bac43
 
9bac43
+    trace_qio_channel_websock_encode(ioc, opcode, header_size, buffer->offset);
9bac43
     buffer_reserve(output, header_size + buffer->offset);
9bac43
     buffer_append(output, header.buf, header_size);
9bac43
     buffer_append(output, buffer->buffer, buffer->offset);
9bac43
@@ -620,7 +622,7 @@ static void qio_channel_websock_encode(QIOChannelWebsock *ioc)
9bac43
         return;
9bac43
     }
9bac43
     qio_channel_websock_encode_buffer(
9bac43
-        &ioc->encoutput, QIO_CHANNEL_WEBSOCK_OPCODE_BINARY_FRAME,
9bac43
+        ioc, &ioc->encoutput, QIO_CHANNEL_WEBSOCK_OPCODE_BINARY_FRAME,
9bac43
         &ioc->rawoutput);
9bac43
     buffer_reset(&ioc->rawoutput);
9bac43
 }
9bac43
@@ -640,7 +642,8 @@ static void qio_channel_websock_write_close(QIOChannelWebsock *ioc,
9bac43
         buffer_append(&ioc->rawoutput, reason, strlen(reason));
9bac43
     }
9bac43
     qio_channel_websock_encode_buffer(
9bac43
-        &ioc->encoutput, QIO_CHANNEL_WEBSOCK_OPCODE_CLOSE, &ioc->rawoutput);
9bac43
+        ioc, &ioc->encoutput, QIO_CHANNEL_WEBSOCK_OPCODE_CLOSE,
9bac43
+        &ioc->rawoutput);
9bac43
     buffer_reset(&ioc->rawoutput);
9bac43
     qio_channel_websock_write_wire(ioc, NULL);
9bac43
     qio_channel_shutdown(ioc->master, QIO_CHANNEL_SHUTDOWN_BOTH, NULL);
9bac43
@@ -682,6 +685,9 @@ static int qio_channel_websock_decode_header(QIOChannelWebsock *ioc,
9bac43
         opcode = ioc->opcode;
9bac43
     }
9bac43
 
9bac43
+    trace_qio_channel_websock_header_partial_decode(ioc, payload_len,
9bac43
+                                                    fin, opcode, (int)has_mask);
9bac43
+
9bac43
     if (opcode == QIO_CHANNEL_WEBSOCK_OPCODE_CLOSE) {
9bac43
         /* disconnect */
9bac43
         return 0;
9bac43
@@ -746,6 +752,8 @@ static int qio_channel_websock_decode_header(QIOChannelWebsock *ioc,
9bac43
         return QIO_CHANNEL_ERR_BLOCK;
9bac43
     }
9bac43
 
9bac43
+    trace_qio_channel_websock_header_full_decode(
9bac43
+        ioc, header_size, ioc->payload_remain, ioc->mask.u);
9bac43
     buffer_advance(&ioc->encinput, header_size);
9bac43
     return 0;
9bac43
 }
9bac43
@@ -791,6 +799,9 @@ static int qio_channel_websock_decode_payload(QIOChannelWebsock *ioc,
9bac43
         }
9bac43
     }
9bac43
 
9bac43
+    trace_qio_channel_websock_payload_decode(
9bac43
+        ioc, ioc->opcode, ioc->payload_remain);
9bac43
+
9bac43
     if (ioc->opcode == QIO_CHANNEL_WEBSOCK_OPCODE_BINARY_FRAME) {
9bac43
         if (payload_len) {
9bac43
             /* binary frames are passed on */
9bac43
@@ -803,7 +814,7 @@ static int qio_channel_websock_decode_payload(QIOChannelWebsock *ioc,
9bac43
         if (payload_len) {
9bac43
             /* echo client status */
9bac43
             qio_channel_websock_encode_buffer(
9bac43
-                &ioc->encoutput, QIO_CHANNEL_WEBSOCK_OPCODE_CLOSE,
9bac43
+                ioc, &ioc->encoutput, QIO_CHANNEL_WEBSOCK_OPCODE_CLOSE,
9bac43
                 &ioc->encinput);
9bac43
             qio_channel_websock_write_wire(ioc, NULL);
9bac43
             qio_channel_shutdown(ioc->master, QIO_CHANNEL_SHUTDOWN_BOTH, NULL);
9bac43
@@ -817,7 +828,8 @@ static int qio_channel_websock_decode_payload(QIOChannelWebsock *ioc,
9bac43
         /* ping frames produce an immediate reply */
9bac43
         buffer_reset(&ioc->ping_reply);
9bac43
         qio_channel_websock_encode_buffer(
9bac43
-            &ioc->ping_reply, QIO_CHANNEL_WEBSOCK_OPCODE_PONG, &ioc->encinput);
9bac43
+            ioc, &ioc->ping_reply, QIO_CHANNEL_WEBSOCK_OPCODE_PONG,
9bac43
+            &ioc->encinput);
9bac43
     }   /* pong frames are ignored */
9bac43
 
9bac43
     if (payload_len) {
9bac43
@@ -1176,6 +1188,7 @@ static int qio_channel_websock_close(QIOChannel *ioc,
9bac43
 {
9bac43
     QIOChannelWebsock *wioc = QIO_CHANNEL_WEBSOCK(ioc);
9bac43
 
9bac43
+    trace_qio_channel_websock_close(ioc);
9bac43
     return qio_channel_close(wioc->master, errp);
9bac43
 }
9bac43
 
9bac43
diff --git a/io/trace-events b/io/trace-events
9bac43
index 6459f71..801b5dc 100644
9bac43
--- a/io/trace-events
9bac43
+++ b/io/trace-events
9bac43
@@ -48,6 +48,11 @@ qio_channel_websock_handshake_pending(void *ioc, int status) "Websock handshake
9bac43
 qio_channel_websock_handshake_reply(void *ioc) "Websock handshake reply ioc=%p"
9bac43
 qio_channel_websock_handshake_fail(void *ioc, const char *msg) "Websock handshake fail ioc=%p err=%s"
9bac43
 qio_channel_websock_handshake_complete(void *ioc) "Websock handshake complete ioc=%p"
9bac43
+qio_channel_websock_header_partial_decode(void *ioc, size_t payloadlen, unsigned char fin, unsigned char opcode, unsigned char has_mask) "Websocket header decoded ioc=%p payload-len=%zu fin=0x%x opcode=0x%x has_mask=0x%x"
9bac43
+qio_channel_websock_header_full_decode(void *ioc, size_t headerlen, size_t payloadlen, uint32_t mask) "Websocket header decoded ioc=%p header-len=%zu payload-len=%zu mask=0x%x"
9bac43
+qio_channel_websock_payload_decode(void *ioc, uint8_t opcode, size_t payload_remain) "Websocket header decoded ioc=%p opcode=0x%x payload-remain=%zu"
9bac43
+qio_channel_websock_encode(void *ioc, uint8_t opcode, size_t payloadlen, size_t headerlen) "Websocket encoded ioc=%p opcode=0x%x header-len=%zu payload-len=%zu"
9bac43
+qio_channel_websock_close(void *ioc) "Websocket close ioc=%p"
9bac43
 
9bac43
 # io/channel-command.c
9bac43
 qio_channel_command_new_pid(void *ioc, int writefd, int readfd, int pid) "Command new pid ioc=%p writefd=%d readfd=%d pid=%d"
9bac43
-- 
9bac43
1.8.3.1
9bac43