console: Handle ipv6 addresses (bz 974126)

This commit is contained in:
Cole Robinson 2014-01-29 11:02:54 -05:00
parent 6042d762b5
commit 0a77093cbc
3 changed files with 32 additions and 9 deletions

View File

@ -384,6 +384,8 @@ class vmmConnection(vmmGObject):
(scheme, username, hostname,
path, ignore, ignore) = util.uri_split(self.get_uri())
hostname, port = self.get_backend().get_uri_host_port()
port = port or ""
hv = ""
rest = ""

View File

@ -71,23 +71,32 @@ class ConnectionInfo(object):
self.gtlsport = gdev.tlsPort or None
self.transport, self.connuser = conn.get_transport()
self._connhost = conn.get_uri_hostname() or "127.0.0.1"
self._connport = None
if self._connhost.count(":"):
self._connhost, self._connport = self._connhost.split(":", 1)
(self._connhost,
self._connport) = conn.get_backend().get_uri_host_port()
if self._connhost == "localhost":
self._connhost = "127.0.0.1"
def _is_listen_localhost(self, host=None):
return (host or self.gaddr) in ["127.0.0.1", "::1"]
def _is_listen_any(self):
return self.gaddr in ["0.0.0.0", "::"]
def need_tunnel(self):
if self.gaddr != "127.0.0.1":
if not self._is_listen_localhost():
return False
return self.transport in ["ssh", "ext"]
def is_bad_localhost(self):
"""
Return True if the guest is listening on localhost, but the libvirt
URI doesn't give us any way to tunnel the connection
"""
host = self.get_conn_host()[0]
if self.need_tunnel():
return False
return self.transport and host == "127.0.0.1"
return self.transport and self._is_listen_localhost(host)
def get_conn_host(self):
host = self._connhost
@ -97,7 +106,7 @@ class ConnectionInfo(object):
if not self.need_tunnel():
port = self.gport
tlsport = self.gtlsport
if self.gaddr != "0.0.0.0":
if not self._is_listen_any():
host = self.gaddr
return host, port, tlsport
@ -1353,7 +1362,7 @@ class vmmConsolePages(vmmGObjectUI):
if ginfo.is_bad_localhost():
self.activate_unavailable_page(
_("Guest is on a remote host with transport '%s'\n"
"but is only configured to listen on 127.0.0.1.\n"
"but is only configured to listen on locally.\n"
"Connect using 'ssh' transport or change the\n"
"guest's listen address." % ginfo.transport))
return

View File

@ -304,6 +304,18 @@ class VirtualConnection(object):
def get_uri_hostname(self):
return self._urisplits[2] or "localhost"
def get_uri_host_port(self):
hostname = self.get_uri_hostname()
port = None
if hostname.startswith("[") and "]" in hostname:
if "]:" in hostname:
hostname, port = hostname.rsplit(":", 1)
hostname = "".join(hostname[1:].split("]", 1))
elif ":" in hostname:
hostname, port = hostname.split(":", 1)
return hostname, port
def get_uri_transport(self):
scheme = self._urisplits[0]
username = self._urisplits[1]