From 771a9a5ddbee5f8fa8695bbfb12ef3fef9550eba Mon Sep 17 00:00:00 2001 From: grossmj Date: Mon, 2 Jan 2023 15:26:59 +0800 Subject: [PATCH 1/2] Require Dynamips 0.2.23 and bind Dynamips hypervisor on 127.0.0.1 --- gns3server/compute/dynamips/__init__.py | 14 ++++++++++---- gns3server/compute/dynamips/hypervisor.py | 9 ++++----- gns3server/compute/port_manager.py | 7 +++++++ 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/gns3server/compute/dynamips/__init__.py b/gns3server/compute/dynamips/__init__.py index f4f1fd9f..11efc428 100644 --- a/gns3server/compute/dynamips/__init__.py +++ b/gns3server/compute/dynamips/__init__.py @@ -278,10 +278,14 @@ class Dynamips(BaseManager): if not working_dir: working_dir = tempfile.gettempdir() - # FIXME: hypervisor should always listen to 127.0.0.1 - # See https://github.com/GNS3/dynamips/issues/62 - server_config = self.config.get_section_config("Server") - server_host = server_config.get("host") + if not sys.platform.startswith("win"): + # Hypervisor should always listen to 127.0.0.1 + # See https://github.com/GNS3/dynamips/issues/62 + # This was fixed in Dynamips v0.2.23 which hasn't been built for Windows + server_host = "127.0.0.1" + else: + server_config = self.config.get_section_config("Server") + server_host = server_config.get("host") try: info = socket.getaddrinfo(server_host, 0, socket.AF_UNSPEC, socket.SOCK_STREAM, 0, socket.AI_PASSIVE) @@ -306,6 +310,8 @@ class Dynamips(BaseManager): await hypervisor.connect() if parse_version(hypervisor.version) < parse_version('0.2.11'): raise DynamipsError("Dynamips version must be >= 0.2.11, detected version is {}".format(hypervisor.version)) + if not sys.platform.startswith("win") and parse_version(hypervisor.version) < parse_version('0.2.23'): + raise DynamipsError("Dynamips version must be >= 0.2.23 on Linux/macOS, detected version is {}".format(hypervisor.version)) return hypervisor diff --git a/gns3server/compute/dynamips/hypervisor.py b/gns3server/compute/dynamips/hypervisor.py index d0ef0a2d..23a67a71 100644 --- a/gns3server/compute/dynamips/hypervisor.py +++ b/gns3server/compute/dynamips/hypervisor.py @@ -24,6 +24,7 @@ import os import subprocess import asyncio +from gns3server.utils import parse_version from gns3server.utils.asyncio import wait_for_process_termination from .dynamips_hypervisor import DynamipsHypervisor from .dynamips_error import DynamipsError @@ -204,11 +205,9 @@ class Hypervisor(DynamipsHypervisor): command = [self._path] command.extend(["-N1"]) # use instance IDs for filenames command.extend(["-l", "dynamips_i{}_log.txt".format(self._id)]) # log file - # Dynamips cannot listen for hypervisor commands and for console connections on - # 2 different IP addresses. - # See https://github.com/GNS3/dynamips/issues/62 - if self._console_host != "0.0.0.0" and self._console_host != "::": - command.extend(["-H", "{}:{}".format(self._host, self._port)]) + if parse_version(self.version) >= parse_version('0.2.23'): + command.extend(["-H", "{}:{}".format(self._host, self._port), "--console-binding-addr", self._console_host]) else: command.extend(["-H", str(self._port)]) + return command diff --git a/gns3server/compute/port_manager.py b/gns3server/compute/port_manager.py index bc91a435..cf58203c 100644 --- a/gns3server/compute/port_manager.py +++ b/gns3server/compute/port_manager.py @@ -16,6 +16,7 @@ # along with this program. If not, see . import socket +import ipaddress from aiohttp.web import HTTPConflict from gns3server.config import Config @@ -91,6 +92,12 @@ class PortManager: if remote_console_connections: log.warning("Remote console connections are allowed") self._console_host = "0.0.0.0" + try: + ip = ipaddress.ip_address(new_host) + if isinstance(ip, ipaddress.IPv6Address): + self._console_host = "::" + except ValueError: + log.warning("Could not determine IP address type for console host") else: self._console_host = new_host From 9132002b80345f79afd51558f1a059e3280cbee5 Mon Sep 17 00:00:00 2001 From: grossmj Date: Wed, 4 Jan 2023 09:08:40 +0800 Subject: [PATCH 2/2] Fix typos --- gns3server/compute/port_manager.py | 2 +- gns3server/controller/node.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/gns3server/compute/port_manager.py b/gns3server/compute/port_manager.py index cf58203c..fc7a5088 100644 --- a/gns3server/compute/port_manager.py +++ b/gns3server/compute/port_manager.py @@ -84,7 +84,7 @@ class PortManager: @console_host.setter def console_host(self, new_host): """ - Bind console host to 0.0.0.0 if remote connections are allowed. + Bind console host to 0.0.0.0 or :: if remote connections are allowed. """ server_config = Config.instance().get_section_config("Server") diff --git a/gns3server/controller/node.py b/gns3server/controller/node.py index ba1bc28d..906556b8 100644 --- a/gns3server/controller/node.py +++ b/gns3server/controller/node.py @@ -34,7 +34,7 @@ log = logging.getLogger(__name__) class Node: - # This properties are used only on controller and are not forwarded to the compute + # These properties are used only on controller and are not forwarded to computes CONTROLLER_ONLY_PROPERTIES = ["x", "y", "z", "locked", "width", "height", "symbol", "label", "console_host", "port_name_format", "first_port_name", "port_segment_size", "ports", "category", "console_auto_start"]