Blob Blame History Raw
From fe2d91f045188e5f58e33727741cff97793ad227 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= <fidencio@redhat.com>
Date: Wed, 11 Mar 2015 16:19:12 +0100
Subject: [PATCH] Take --direct into consideration when checking if a guest is
 reachable

When connecting to a remote host (using qemu+ssh://...) that has a
virtual machine listening to "127.0.0.1", virt_viewer_is_reachable() must
take --direct into account, otherwise it can end up connecting to a local
virtual machine listening to "0.0.0.0" instead of returning that the
guest is not reachable.

Resolves: rhbz#1085216
(cherry picked from commit 21306d13f931153a6eb13f455ca7d8fedc800f78)
---
 src/virt-viewer.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/src/virt-viewer.c b/src/virt-viewer.c
index ec7d875..aeed5c1 100644
--- a/src/virt-viewer.c
+++ b/src/virt-viewer.c
@@ -355,8 +355,10 @@ virt_viewer_is_loopback(const char *host)
 
 
 static gboolean
-virt_viewer_is_reachable(const gchar *host, const char *transport,
-                         const char *transport_host)
+virt_viewer_is_reachable(const gchar *host,
+                         const char *transport,
+                         const char *transport_host,
+                         gboolean direct)
 {
     gboolean host_is_loopback;
     gboolean transport_is_loopback;
@@ -367,7 +369,7 @@ virt_viewer_is_reachable(const gchar *host, const char *transport,
     if (!transport)
         return TRUE;
 
-    if (strcmp(transport, "ssh") == 0)
+    if (strcmp(transport, "ssh") == 0 && !direct)
         return TRUE;
 
     if (strcmp(transport, "unix") == 0)
@@ -402,6 +404,7 @@ virt_viewer_extract_connect_info(VirtViewer *self,
     gchar *user = NULL;
     gint port = 0;
     gchar *uri = NULL;
+    gboolean direct = virt_viewer_app_get_direct(app);
 
     virt_viewer_app_free_connect_info(app);
 
@@ -457,8 +460,7 @@ virt_viewer_extract_connect_info(VirtViewer *self,
      */
     if (virt_viewer_replace_host(ghost)) {
         gchar *replacement_host = NULL;
-        if ((g_strcmp0(transport, "ssh") == 0)
-                && !virt_viewer_app_get_direct(app)) {
+        if ((g_strcmp0(transport, "ssh") == 0) && !direct) {
             replacement_host = g_strdup("localhost");
         } else {
             replacement_host = g_strdup(host);
@@ -469,7 +471,7 @@ virt_viewer_extract_connect_info(VirtViewer *self,
         ghost = replacement_host;
     }
 
-    if (!virt_viewer_is_reachable(ghost, transport, host)) {
+    if (!virt_viewer_is_reachable(ghost, transport, host, direct)) {
         g_debug("graphics listen '%s' is not reachable from this machine",
                 ghost ? ghost : "");
         virt_viewer_app_simple_message_dialog(app, _("Guest '%s' is not reachable"),