From nobody Tue Nov 4 05:31:16 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1505988455735736.0329460014315; Thu, 21 Sep 2017 03:07:35 -0700 (PDT) Received: from localhost ([::1]:52715 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1duyOM-0003Y7-9P for importer@patchew.org; Thu, 21 Sep 2017 06:07:34 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39610) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1duyMV-0002Lq-50 for qemu-devel@nongnu.org; Thu, 21 Sep 2017 06:05:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1duyMR-0000oF-Uq for qemu-devel@nongnu.org; Thu, 21 Sep 2017 06:05:39 -0400 Received: from mx1.redhat.com ([209.132.183.28]:48996) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1duyMR-0000ix-MW for qemu-devel@nongnu.org; Thu, 21 Sep 2017 06:05:35 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A73DA804E3 for ; Thu, 21 Sep 2017 10:05:34 +0000 (UTC) Received: from t460.redhat.com (unknown [10.33.36.51]) by smtp.corp.redhat.com (Postfix) with ESMTP id AFC185EDFE; Thu, 21 Sep 2017 10:05:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com A73DA804E3 Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=berrange@redhat.com From: "Daniel P. Berrange" To: qemu-devel@nongnu.org Date: Thu, 21 Sep 2017 11:05:29 +0100 Message-Id: <20170921100529.2462-1-berrange@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Thu, 21 Sep 2017 10:05:34 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH] io: add trace events for websockets frame handling X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" It is useful to trace websockets frame encoding/decoding when debugging problems. Signed-off-by: Daniel P. Berrange Reviewed-by: Stefan Hajnoczi --- io/channel-websock.c | 23 ++++++++++++++++++----- io/trace-events | 5 +++++ 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/io/channel-websock.c b/io/channel-websock.c index 3195eb2eb8..d1d471f86e 100644 --- a/io/channel-websock.c +++ b/io/channel-websock.c @@ -582,7 +582,8 @@ static gboolean qio_channel_websock_handshake_io(QIOCha= nnel *ioc, } =20 =20 -static void qio_channel_websock_encode_buffer(Buffer *output, +static void qio_channel_websock_encode_buffer(QIOChannelWebsock *ioc, + Buffer *output, uint8_t opcode, Buffer *buff= er) { size_t header_size; @@ -608,6 +609,7 @@ static void qio_channel_websock_encode_buffer(Buffer *o= utput, } header_size -=3D QIO_CHANNEL_WEBSOCK_HEADER_LEN_MASK; =20 + trace_qio_channel_websock_encode(ioc, opcode, header_size, buffer->off= set); buffer_reserve(output, header_size + buffer->offset); buffer_append(output, header.buf, header_size); buffer_append(output, buffer->buffer, buffer->offset); @@ -620,7 +622,7 @@ static void qio_channel_websock_encode(QIOChannelWebsoc= k *ioc) return; } qio_channel_websock_encode_buffer( - &ioc->encoutput, QIO_CHANNEL_WEBSOCK_OPCODE_BINARY_FRAME, + ioc, &ioc->encoutput, QIO_CHANNEL_WEBSOCK_OPCODE_BINARY_FRAME, &ioc->rawoutput); buffer_reset(&ioc->rawoutput); } @@ -640,7 +642,8 @@ static void qio_channel_websock_write_close(QIOChannelW= ebsock *ioc, buffer_append(&ioc->rawoutput, reason, strlen(reason)); } qio_channel_websock_encode_buffer( - &ioc->encoutput, QIO_CHANNEL_WEBSOCK_OPCODE_CLOSE, &ioc->rawoutput= ); + ioc, &ioc->encoutput, QIO_CHANNEL_WEBSOCK_OPCODE_CLOSE, + &ioc->rawoutput); buffer_reset(&ioc->rawoutput); qio_channel_websock_write_wire(ioc, NULL); qio_channel_shutdown(ioc->master, QIO_CHANNEL_SHUTDOWN_BOTH, NULL); @@ -682,6 +685,9 @@ static int qio_channel_websock_decode_header(QIOChannel= Websock *ioc, opcode =3D ioc->opcode; } =20 + trace_qio_channel_websock_header_partial_decode(ioc, payload_len, + fin, opcode, (int)has_= mask); + if (opcode =3D=3D QIO_CHANNEL_WEBSOCK_OPCODE_CLOSE) { /* disconnect */ return 0; @@ -746,6 +752,8 @@ static int qio_channel_websock_decode_header(QIOChannel= Websock *ioc, return QIO_CHANNEL_ERR_BLOCK; } =20 + trace_qio_channel_websock_header_full_decode( + ioc, header_size, ioc->payload_remain, ioc->mask.u); buffer_advance(&ioc->encinput, header_size); return 0; } @@ -791,6 +799,9 @@ static int qio_channel_websock_decode_payload(QIOChanne= lWebsock *ioc, } } =20 + trace_qio_channel_websock_payload_decode( + ioc, ioc->opcode, ioc->payload_remain); + if (ioc->opcode =3D=3D QIO_CHANNEL_WEBSOCK_OPCODE_BINARY_FRAME) { if (payload_len) { /* binary frames are passed on */ @@ -803,7 +814,7 @@ static int qio_channel_websock_decode_payload(QIOChanne= lWebsock *ioc, if (payload_len) { /* echo client status */ qio_channel_websock_encode_buffer( - &ioc->encoutput, QIO_CHANNEL_WEBSOCK_OPCODE_CLOSE, + ioc, &ioc->encoutput, QIO_CHANNEL_WEBSOCK_OPCODE_CLOSE, &ioc->encinput); qio_channel_websock_write_wire(ioc, NULL); qio_channel_shutdown(ioc->master, QIO_CHANNEL_SHUTDOWN_BOTH, N= ULL); @@ -817,7 +828,8 @@ static int qio_channel_websock_decode_payload(QIOChanne= lWebsock *ioc, /* ping frames produce an immediate reply */ buffer_reset(&ioc->ping_reply); qio_channel_websock_encode_buffer( - &ioc->ping_reply, QIO_CHANNEL_WEBSOCK_OPCODE_PONG, &ioc->encin= put); + ioc, &ioc->ping_reply, QIO_CHANNEL_WEBSOCK_OPCODE_PONG, + &ioc->encinput); } /* pong frames are ignored */ =20 if (payload_len) { @@ -1176,6 +1188,7 @@ static int qio_channel_websock_close(QIOChannel *ioc, { QIOChannelWebsock *wioc =3D QIO_CHANNEL_WEBSOCK(ioc); =20 + trace_qio_channel_websock_close(ioc); return qio_channel_close(wioc->master, errp); } =20 diff --git a/io/trace-events b/io/trace-events index 6459f71f5b..801b5dcb61 100644 --- a/io/trace-events +++ b/io/trace-events @@ -48,6 +48,11 @@ qio_channel_websock_handshake_pending(void *ioc, int sta= tus) "Websock handshake qio_channel_websock_handshake_reply(void *ioc) "Websock handshake reply io= c=3D%p" qio_channel_websock_handshake_fail(void *ioc, const char *msg) "Websock ha= ndshake fail ioc=3D%p err=3D%s" qio_channel_websock_handshake_complete(void *ioc) "Websock handshake compl= ete ioc=3D%p" +qio_channel_websock_header_partial_decode(void *ioc, size_t payloadlen, un= signed char fin, unsigned char opcode, unsigned char has_mask) "Websocket h= eader decoded ioc=3D%p payload-len=3D%zu fin=3D0x%x opcode=3D0x%x has_mask= =3D0x%x" +qio_channel_websock_header_full_decode(void *ioc, size_t headerlen, size_t= payloadlen, uint32_t mask) "Websocket header decoded ioc=3D%p header-len= =3D%zu payload-len=3D%zu mask=3D0x%x" +qio_channel_websock_payload_decode(void *ioc, uint8_t opcode, size_t paylo= ad_remain) "Websocket header decoded ioc=3D%p opcode=3D0x%x payload-remain= =3D%zu" +qio_channel_websock_encode(void *ioc, uint8_t opcode, size_t payloadlen, s= ize_t headerlen) "Websocket encoded ioc=3D%p opcode=3D0x%x header-len=3D%zu= payload-len=3D%zu" +qio_channel_websock_close(void *ioc) "Websocket close ioc=3D%p" =20 # io/channel-command.c qio_channel_command_new_pid(void *ioc, int writefd, int readfd, int pid) "= Command new pid ioc=3D%p writefd=3D%d readfd=3D%d pid=3D%d" --=20 2.13.5