|
|
4a2fec |
From 6b05946c92a9fee7398d948be3505a294d27f76b Mon Sep 17 00:00:00 2001
|
|
|
4a2fec |
From: "Daniel P. Berrange" <berrange@redhat.com>
|
|
|
4a2fec |
Date: Wed, 20 Dec 2017 17:56:48 +0100
|
|
|
4a2fec |
Subject: [PATCH 08/42] io: Add support for fragmented websocket binary frames
|
|
|
4a2fec |
|
|
|
4a2fec |
RH-Author: Daniel P. Berrange <berrange@redhat.com>
|
|
|
4a2fec |
Message-id: <20171220175702.29663-7-berrange@redhat.com>
|
|
|
4a2fec |
Patchwork-id: 78461
|
|
|
4a2fec |
O-Subject: [RHV-7.5 qemu-kvm-rhev PATCH v2 06/20] io: Add support for fragmented websocket binary frames
|
|
|
4a2fec |
Bugzilla: 1518649
|
|
|
4a2fec |
RH-Acked-by: John Snow <jsnow@redhat.com>
|
|
|
4a2fec |
RH-Acked-by: Jeffrey Cody <jcody@redhat.com>
|
|
|
4a2fec |
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
4a2fec |
|
|
|
4a2fec |
From: Brandon Carpenter <brandon.carpenter@cypherpath.com>
|
|
|
4a2fec |
|
|
|
4a2fec |
Allows fragmented binary frames by saving the previous opcode. Handles
|
|
|
4a2fec |
the case where an intermediary (i.e., web proxy) fragments frames
|
|
|
4a2fec |
originally sent unfragmented by the client.
|
|
|
4a2fec |
|
|
|
4a2fec |
Signed-off-by: Brandon Carpenter <brandon.carpenter@cypherpath.com>
|
|
|
4a2fec |
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
|
|
|
4a2fec |
(cherry picked from commit ff1300e626949fa9850b0f91dc5e8c2cb45b6a88)
|
|
|
4a2fec |
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
4a2fec |
---
|
|
|
4a2fec |
include/io/channel-websock.h | 1 +
|
|
|
4a2fec |
io/channel-websock.c | 26 ++++++++++++++++++--------
|
|
|
4a2fec |
2 files changed, 19 insertions(+), 8 deletions(-)
|
|
|
4a2fec |
|
|
|
4a2fec |
diff --git a/include/io/channel-websock.h b/include/io/channel-websock.h
|
|
|
4a2fec |
index 3c9ff84..7c89655 100644
|
|
|
4a2fec |
--- a/include/io/channel-websock.h
|
|
|
4a2fec |
+++ b/include/io/channel-websock.h
|
|
|
4a2fec |
@@ -65,6 +65,7 @@ struct QIOChannelWebsock {
|
|
|
4a2fec |
guint io_tag;
|
|
|
4a2fec |
Error *io_err;
|
|
|
4a2fec |
gboolean io_eof;
|
|
|
4a2fec |
+ uint8_t opcode;
|
|
|
4a2fec |
};
|
|
|
4a2fec |
|
|
|
4a2fec |
/**
|
|
|
4a2fec |
diff --git a/io/channel-websock.c b/io/channel-websock.c
|
|
|
4a2fec |
index 4e5afb2..909d636 100644
|
|
|
4a2fec |
--- a/io/channel-websock.c
|
|
|
4a2fec |
+++ b/io/channel-websock.c
|
|
|
4a2fec |
@@ -636,28 +636,38 @@ static int qio_channel_websock_decode_header(QIOChannelWebsock *ioc,
|
|
|
4a2fec |
has_mask = header->b1 & QIO_CHANNEL_WEBSOCK_HEADER_FIELD_HAS_MASK;
|
|
|
4a2fec |
payload_len = header->b1 & QIO_CHANNEL_WEBSOCK_HEADER_FIELD_PAYLOAD_LEN;
|
|
|
4a2fec |
|
|
|
4a2fec |
+ /* Save or restore opcode. */
|
|
|
4a2fec |
+ if (opcode) {
|
|
|
4a2fec |
+ ioc->opcode = opcode;
|
|
|
4a2fec |
+ } else {
|
|
|
4a2fec |
+ opcode = ioc->opcode;
|
|
|
4a2fec |
+ }
|
|
|
4a2fec |
+
|
|
|
4a2fec |
if (opcode == QIO_CHANNEL_WEBSOCK_OPCODE_CLOSE) {
|
|
|
4a2fec |
/* disconnect */
|
|
|
4a2fec |
return 0;
|
|
|
4a2fec |
}
|
|
|
4a2fec |
|
|
|
4a2fec |
/* Websocket frame sanity check:
|
|
|
4a2fec |
- * * Websocket fragmentation is not supported.
|
|
|
4a2fec |
- * * All websockets frames sent by a client have to be masked.
|
|
|
4a2fec |
+ * * Fragmentation is only supported for binary frames.
|
|
|
4a2fec |
+ * * All frames sent by a client MUST be masked.
|
|
|
4a2fec |
* * Only binary encoding is supported.
|
|
|
4a2fec |
*/
|
|
|
4a2fec |
if (!fin) {
|
|
|
4a2fec |
- error_setg(errp, "websocket fragmentation is not supported");
|
|
|
4a2fec |
- return -1;
|
|
|
4a2fec |
+ if (opcode != QIO_CHANNEL_WEBSOCK_OPCODE_BINARY_FRAME) {
|
|
|
4a2fec |
+ error_setg(errp, "only binary websocket frames may be fragmented");
|
|
|
4a2fec |
+ return -1;
|
|
|
4a2fec |
+ }
|
|
|
4a2fec |
+ } else {
|
|
|
4a2fec |
+ if (opcode != QIO_CHANNEL_WEBSOCK_OPCODE_BINARY_FRAME) {
|
|
|
4a2fec |
+ error_setg(errp, "only binary websocket frames are supported");
|
|
|
4a2fec |
+ return -1;
|
|
|
4a2fec |
+ }
|
|
|
4a2fec |
}
|
|
|
4a2fec |
if (!has_mask) {
|
|
|
4a2fec |
error_setg(errp, "client websocket frames must be masked");
|
|
|
4a2fec |
return -1;
|
|
|
4a2fec |
}
|
|
|
4a2fec |
- if (opcode != QIO_CHANNEL_WEBSOCK_OPCODE_BINARY_FRAME) {
|
|
|
4a2fec |
- error_setg(errp, "only binary websocket frames are supported");
|
|
|
4a2fec |
- return -1;
|
|
|
4a2fec |
- }
|
|
|
4a2fec |
|
|
|
4a2fec |
if (payload_len < QIO_CHANNEL_WEBSOCK_PAYLOAD_LEN_MAGIC_16_BIT) {
|
|
|
4a2fec |
ioc->payload_remain = payload_len;
|
|
|
4a2fec |
--
|
|
|
4a2fec |
1.8.3.1
|
|
|
4a2fec |
|