diff --git a/gns3server/compute/qemu/qemu_vm.py b/gns3server/compute/qemu/qemu_vm.py index d9028f91..adec97db 100644 --- a/gns3server/compute/qemu/qemu_vm.py +++ b/gns3server/compute/qemu/qemu_vm.py @@ -146,7 +146,6 @@ class QemuVM(BaseNode): self._initrd = "" self._kernel_image = "" self._kernel_command_line = "" - self._legacy_networking = False self._replicate_network_connection_state = True self._create_config_disk = False self._on_close = "power_off" @@ -679,30 +678,6 @@ class QemuVM(BaseNode): ) ) - @property - def legacy_networking(self): - """ - Returns either QEMU legacy networking commands are used. - - :returns: boolean - """ - - return self._legacy_networking - - @legacy_networking.setter - def legacy_networking(self, legacy_networking): - """ - Sets either QEMU legacy networking commands are used. - - :param legacy_networking: boolean - """ - - if legacy_networking: - log.info(f'QEMU VM "{self._name}" [{self._id}] has enabled legacy networking') - else: - log.info(f'QEMU VM "{self._name}" [{self._id}] has disabled legacy networking') - self._legacy_networking = legacy_networking - @property def replicate_network_connection_state(self): """ @@ -2208,16 +2183,6 @@ class QemuVM(BaseNode): ["-net", "none"] ) # we do not want any user networking back-end if no adapter is connected. - patched_qemu = False - if self._legacy_networking: - qemu_version = await self.manager.get_qemu_version(self.qemu_path) - if qemu_version: - if parse_version(qemu_version) >= parse_version("2.9.0"): - raise QemuError("Qemu version 2.9.0 and later doesn't support legacy networking mode") - if parse_version(qemu_version) < parse_version("1.1.0"): - # this is a patched Qemu if version is below 1.1.0 - patched_qemu = True - # Each 32 PCI device we need to add a PCI bridge with max 9 bridges pci_devices = 4 + len(self._ethernet_adapters) # 4 PCI devices are use by default by qemu pci_bridges = math.floor(pci_devices / 32) @@ -2244,72 +2209,40 @@ class QemuVM(BaseNode): if custom_mac_address: mac = int_to_macaddress(macaddress_to_int(custom_mac_address)) - if self._legacy_networking: - # legacy QEMU networking syntax (-net) - if nio: - network_options.extend(["-net", f"nic,vlan={adapter_number},macaddr={mac},model={adapter_type}"]) - if isinstance(nio, NIOUDP): - if patched_qemu: - # use patched Qemu syntax - network_options.extend( - [ - "-net", - "udp,vlan={},name=gns3-{},sport={},dport={},daddr={}".format( - adapter_number, adapter_number, nio.lport, nio.rport, nio.rhost - ), - ] - ) - else: - # use UDP tunnel support added in Qemu 1.1.0 - network_options.extend( - [ - "-net", - "socket,vlan={},name=gns3-{},udp={}:{},localaddr={}:{}".format( - adapter_number, adapter_number, nio.rhost, nio.rport, "127.0.0.1", nio.lport - ), - ] - ) - elif isinstance(nio, NIOTAP): - network_options.extend(["-net", f"tap,name=gns3-{adapter_number},ifname={nio.tap_device}"]) - else: - network_options.extend(["-net", f"nic,vlan={adapter_number},macaddr={mac},model={adapter_type}"]) - + device_string = f"{adapter_type},mac={mac}" + bridge_id = math.floor(pci_device_id / 32) + if bridge_id > 0: + if pci_bridges_created < bridge_id: + network_options.extend(["-device", f"i82801b11-bridge,id=dmi_pci_bridge{bridge_id}"]) + network_options.extend( + [ + "-device", + "pci-bridge,id=pci-bridge{bridge_id},bus=dmi_pci_bridge{bridge_id},chassis_nr=0x1,addr=0x{bridge_id},shpc=off".format( + bridge_id=bridge_id + ), + ] + ) + pci_bridges_created += 1 + addr = pci_device_id % 32 + device_string = f"{device_string},bus=pci-bridge{bridge_id},addr=0x{addr:02x}" + pci_device_id += 1 + if nio: + network_options.extend(["-device", f"{device_string},netdev=gns3-{adapter_number}"]) + if isinstance(nio, NIOUDP): + network_options.extend( + [ + "-netdev", + "socket,id=gns3-{},udp={}:{},localaddr={}:{}".format( + adapter_number, nio.rhost, nio.rport, "127.0.0.1", nio.lport + ), + ] + ) + elif isinstance(nio, NIOTAP): + network_options.extend( + ["-netdev", f"tap,id=gns3-{adapter_number},ifname={nio.tap_device},script=no,downscript=no"] + ) else: - # newer QEMU networking syntax - device_string = f"{adapter_type},mac={mac}" - bridge_id = math.floor(pci_device_id / 32) - if bridge_id > 0: - if pci_bridges_created < bridge_id: - network_options.extend(["-device", f"i82801b11-bridge,id=dmi_pci_bridge{bridge_id}"]) - network_options.extend( - [ - "-device", - "pci-bridge,id=pci-bridge{bridge_id},bus=dmi_pci_bridge{bridge_id},chassis_nr=0x1,addr=0x{bridge_id},shpc=off".format( - bridge_id=bridge_id - ), - ] - ) - pci_bridges_created += 1 - addr = pci_device_id % 32 - device_string = f"{device_string},bus=pci-bridge{bridge_id},addr=0x{addr:02x}" - pci_device_id += 1 - if nio: - network_options.extend(["-device", f"{device_string},netdev=gns3-{adapter_number}"]) - if isinstance(nio, NIOUDP): - network_options.extend( - [ - "-netdev", - "socket,id=gns3-{},udp={}:{},localaddr={}:{}".format( - adapter_number, nio.rhost, nio.rport, "127.0.0.1", nio.lport - ), - ] - ) - elif isinstance(nio, NIOTAP): - network_options.extend( - ["-netdev", f"tap,id=gns3-{adapter_number},ifname={nio.tap_device},script=no,downscript=no"] - ) - else: - network_options.extend(["-device", device_string]) + network_options.extend(["-device", device_string]) return network_options diff --git a/gns3server/db/models/templates.py b/gns3server/db/models/templates.py index 3d5f939d..3086a15c 100644 --- a/gns3server/db/models/templates.py +++ b/gns3server/db/models/templates.py @@ -201,7 +201,6 @@ class QemuTemplate(Template): kernel_image = Column(String) bios_image = Column(String) kernel_command_line = Column(String) - legacy_networking = Column(Boolean) replicate_network_connection_state = Column(Boolean) create_config_disk = Column(Boolean) on_close = Column(String) diff --git a/gns3server/schemas/compute/qemu_nodes.py b/gns3server/schemas/compute/qemu_nodes.py index de464fef..2c9d33ed 100644 --- a/gns3server/schemas/compute/qemu_nodes.py +++ b/gns3server/schemas/compute/qemu_nodes.py @@ -195,7 +195,6 @@ class QemuBase(BaseModel): mac_address: Optional[str] = Field( None, description="QEMU MAC address", regex="^([0-9a-fA-F]{2}[:]){5}([0-9a-fA-F]{2})$" ) - legacy_networking: Optional[bool] = Field(None, description="Use QEMU legagy networking commands (-net syntax)") replicate_network_connection_state: Optional[bool] = Field( None, description="Replicate the network connection state for links in Qemu" ) diff --git a/gns3server/schemas/controller/templates/qemu_templates.py b/gns3server/schemas/controller/templates/qemu_templates.py index f69eb23a..68645595 100644 --- a/gns3server/schemas/controller/templates/qemu_templates.py +++ b/gns3server/schemas/controller/templates/qemu_templates.py @@ -74,7 +74,6 @@ class QemuTemplate(TemplateBase): kernel_image: Optional[str] = Field("", description="QEMU kernel image path") bios_image: Optional[str] = Field("", description="QEMU bios image path") kernel_command_line: Optional[str] = Field("", description="QEMU kernel command line") - legacy_networking: Optional[bool] = Field(False, description="Use QEMU legagy networking commands (-net syntax)") replicate_network_connection_state: Optional[bool] = Field( True, description="Replicate the network connection state for links in Qemu" ) diff --git a/tests/api/routes/controller/test_templates.py b/tests/api/routes/controller/test_templates.py index 2d357959..18545ada 100644 --- a/tests/api/routes/controller/test_templates.py +++ b/tests/api/routes/controller/test_templates.py @@ -748,7 +748,6 @@ class TestQemuTemplate: "initrd": "", "kernel_command_line": "", "kernel_image": "", - "legacy_networking": False, "linked_clone": True, "mac_address": "", "name": "Qemu template",