From f208b472a10f4c3b96ce0b3a7c331b4214629202 Mon Sep 17 00:00:00 2001 From: Jeremy Date: Mon, 27 Apr 2015 14:38:15 -0600 Subject: [PATCH] TAP interface support for QEMU VMs. Fixes #153. --- gns3server/handlers/api/qemu_handler.py | 2 +- gns3server/modules/base_manager.py | 5 ++-- gns3server/modules/qemu/qemu_vm.py | 33 +++++++++++++++---------- 3 files changed, 24 insertions(+), 16 deletions(-) diff --git a/gns3server/handlers/api/qemu_handler.py b/gns3server/handlers/api/qemu_handler.py index 704b02d7..6ffe59ba 100644 --- a/gns3server/handlers/api/qemu_handler.py +++ b/gns3server/handlers/api/qemu_handler.py @@ -247,7 +247,7 @@ class QEMUHandler: qemu_manager = Qemu.instance() vm = qemu_manager.get_vm(request.match_info["vm_id"], project_id=request.match_info["project_id"]) nio_type = request.json["type"] - if nio_type != "nio_udp": + if nio_type not in ("nio_udp", "nio_tap"): raise HTTPConflict(text="NIO of type {} is not supported".format(nio_type)) nio = qemu_manager.create_nio(vm.qemu_path, request.json) yield from vm.adapter_add_nio_binding(int(request.match_info["adapter_number"]), nio) diff --git a/gns3server/modules/base_manager.py b/gns3server/modules/base_manager.py index 9dbc6fb8..378b45d9 100644 --- a/gns3server/modules/base_manager.py +++ b/gns3server/modules/base_manager.py @@ -364,8 +364,9 @@ class BaseManager: nio = NIOUDP(lport, rhost, rport) elif nio_settings["type"] == "nio_tap": tap_device = nio_settings["tap_device"] - if not self._has_privileged_access(executable): - raise aiohttp.web.HTTPForbidden(text="{} has no privileged access to {}.".format(executable, tap_device)) + #FIXME: check for permissions on tap device + #if not self._has_privileged_access(executable): + # raise aiohttp.web.HTTPForbidden(text="{} has no privileged access to {}.".format(executable, tap_device)) nio = NIOTAP(tap_device) elif nio_settings["type"] == "nio_generic_ethernet": nio = NIOGenericEthernet(nio_settings["ethernet_device"]) diff --git a/gns3server/modules/qemu/qemu_vm.py b/gns3server/modules/qemu/qemu_vm.py index b63a6111..85788a80 100644 --- a/gns3server/modules/qemu/qemu_vm.py +++ b/gns3server/modules/qemu/qemu_vm.py @@ -32,6 +32,7 @@ import socket from .qemu_error import QemuError from ..adapters.ethernet_adapter import EthernetAdapter from ..nios.nio_udp import NIOUDP +from ..nios.nio_tap import NIOTAP from ..base_vm import BaseVM from ...schemas.qemu import QEMU_OBJECT_SCHEMA @@ -995,19 +996,25 @@ class QemuVM(BaseVM): else: network_options.extend(["-device", "{},mac={},netdev=gns3-{}".format(self._adapter_type, mac, adapter_number)]) nio = adapter.get_nio(0) - if nio and isinstance(nio, NIOUDP): - if self._legacy_networking: - network_options.extend(["-net", "udp,vlan={},name=gns3-{},sport={},dport={},daddr={}".format(adapter_number, - adapter_number, - nio.lport, - nio.rport, - nio.rhost)]) - else: - network_options.extend(["-netdev", "socket,id=gns3-{},udp={}:{},localaddr={}:{}".format(adapter_number, - nio.rhost, - nio.rport, - self._host, - nio.lport)]) + if nio: + if isinstance(nio, NIOUDP): + if self._legacy_networking: + network_options.extend(["-net", "udp,vlan={},name=gns3-{},sport={},dport={},daddr={}".format(adapter_number, + adapter_number, + nio.lport, + nio.rport, + nio.rhost)]) + else: + network_options.extend(["-netdev", "socket,id=gns3-{},udp={}:{},localaddr={}:{}".format(adapter_number, + nio.rhost, + nio.rport, + self._host, + nio.lport)]) + elif isinstance(nio, NIOTAP): + if self._legacy_networking: + network_options.extend(["-net", "tap,name=gns3-{},ifname={}".format(adapter_number, nio.tap_device)]) + else: + network_options.extend(["-netdev", "tap,id=gns3-{},ifname={}".format(adapter_number, nio.tap_device)]) else: if self._legacy_networking: network_options.extend(["-net", "user,vlan={},name=gns3-{}".format(adapter_number, adapter_number)])