[Spice-devel] [PATCH spice] reds: Cancel unexpected xfer messages

Pavel Grunt pgrunt at redhat.com
Wed Dec 21 14:57:41 UTC 2016


Inform client that transfer will not work, instead of only
dropping the agent messages.

The file transfer messages can be disabled using qemu cli option:
 "disable-agent-file-xfer"

Resolves:
https://bugzilla.redhat.com/show_bug.cgi?id=1373725

Signed-off-by: Pavel Grunt <pgrunt at redhat.com>
---
 server/reds.c | 34 +++++++++++++++++++++++++++++++++-
 1 file changed, 33 insertions(+), 1 deletion(-)

diff --git a/server/reds.c b/server/reds.c
index 3b30928a..ed4c2935 100644
--- a/server/reds.c
+++ b/server/reds.c
@@ -1099,6 +1099,32 @@ static void reds_on_main_agent_monitors_config(RedsState *reds,
     reds_client_monitors_config_cleanup(reds);
 }
 
+static void agent_data_free(uint8_t *data, void *opaque G_GNUC_UNUSED)
+{
+    free(data);
+}
+
+static void agent_xfer_error(MainChannelClient *mcc, const VDAgentMessage *message)
+{
+    VDAgentMessage *xfer_msg;
+    VDAgentFileXferStatusMessage *xfer_status;
+    size_t len = sizeof(VDAgentMessage) + sizeof(VDAgentFileXferStatusMessage);
+ 
+    g_return_if_fail(message->type >= VD_AGENT_FILE_XFER_START &&
+                     message->type <= VD_AGENT_FILE_XFER_DATA);
+
+    xfer_msg = spice_malloc0(len);
+    xfer_msg->protocol = VD_AGENT_PROTOCOL;
+    xfer_msg->type = VD_AGENT_FILE_XFER_STATUS;
+    xfer_msg->size = sizeof(VDAgentFileXferStatusMessage);
+    xfer_status = (VDAgentFileXferStatusMessage *) xfer_msg->data;
+    xfer_status->id = *((uint32_t *) message->data);
+    xfer_status->result = VD_AGENT_FILE_XFER_STATUS_ERROR;
+
+    spice_printerr("received xfer message on disabled file transfer, xfer id %u", xfer_status->id);
+    main_channel_client_push_agent_data(mcc, (uint8_t *) xfer_msg, len, agent_data_free, NULL);
+}
+
 void reds_on_main_agent_data(RedsState *reds, MainChannelClient *mcc, void *message, size_t size)
 {
     RedCharDeviceVDIPort *dev = reds->agent_dev;
@@ -1110,8 +1136,14 @@ void reds_on_main_agent_data(RedsState *reds, MainChannelClient *mcc, void *mess
     switch (res) {
     case AGENT_MSG_FILTER_OK:
         break;
-    case AGENT_MSG_FILTER_DISCARD:
+    case AGENT_MSG_FILTER_DISCARD: {
+        const VDAgentMessage *agent_message = message;
+        if (agent_message->type >= VD_AGENT_FILE_XFER_START &&
+            agent_message->type <= VD_AGENT_FILE_XFER_DATA) {
+            agent_xfer_error(mcc, agent_message);
+        }
         return;
+    }
     case AGENT_MSG_FILTER_MONITORS_CONFIG:
         reds_on_main_agent_monitors_config(reds, mcc, message, size);
         return;
-- 
2.11.0



More information about the Spice-devel mailing list