1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-12-26 16:58:28 +00:00

Merge pull request #1986 from GNS3/remove-qemu-legacy-networking

Remove Qemu legacy networking support
This commit is contained in:
Jeremy Grossmann 2021-10-20 15:44:31 +10:30 committed by GitHub
commit 16ac9358df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 33 additions and 104 deletions

View File

@ -146,7 +146,6 @@ class QemuVM(BaseNode):
self._initrd = "" self._initrd = ""
self._kernel_image = "" self._kernel_image = ""
self._kernel_command_line = "" self._kernel_command_line = ""
self._legacy_networking = False
self._replicate_network_connection_state = True self._replicate_network_connection_state = True
self._create_config_disk = False self._create_config_disk = False
self._on_close = "power_off" 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 @property
def replicate_network_connection_state(self): def replicate_network_connection_state(self):
""" """
@ -2208,16 +2183,6 @@ class QemuVM(BaseNode):
["-net", "none"] ["-net", "none"]
) # we do not want any user networking back-end if no adapter is connected. ) # 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 # 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_devices = 4 + len(self._ethernet_adapters) # 4 PCI devices are use by default by qemu
pci_bridges = math.floor(pci_devices / 32) pci_bridges = math.floor(pci_devices / 32)
@ -2244,72 +2209,40 @@ class QemuVM(BaseNode):
if custom_mac_address: if custom_mac_address:
mac = int_to_macaddress(macaddress_to_int(custom_mac_address)) mac = int_to_macaddress(macaddress_to_int(custom_mac_address))
if self._legacy_networking: device_string = f"{adapter_type},mac={mac}"
# legacy QEMU networking syntax (-net) bridge_id = math.floor(pci_device_id / 32)
if nio: if bridge_id > 0:
network_options.extend(["-net", f"nic,vlan={adapter_number},macaddr={mac},model={adapter_type}"]) if pci_bridges_created < bridge_id:
if isinstance(nio, NIOUDP): network_options.extend(["-device", f"i82801b11-bridge,id=dmi_pci_bridge{bridge_id}"])
if patched_qemu: network_options.extend(
# use patched Qemu syntax [
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(
"-net", bridge_id=bridge_id
"udp,vlan={},name=gns3-{},sport={},dport={},daddr={}".format( ),
adapter_number, adapter_number, nio.lport, nio.rport, nio.rhost ]
), )
] pci_bridges_created += 1
) addr = pci_device_id % 32
else: device_string = f"{device_string},bus=pci-bridge{bridge_id},addr=0x{addr:02x}"
# use UDP tunnel support added in Qemu 1.1.0 pci_device_id += 1
network_options.extend( if nio:
[ network_options.extend(["-device", f"{device_string},netdev=gns3-{adapter_number}"])
"-net", if isinstance(nio, NIOUDP):
"socket,vlan={},name=gns3-{},udp={}:{},localaddr={}:{}".format( network_options.extend(
adapter_number, adapter_number, nio.rhost, nio.rport, "127.0.0.1", nio.lport [
), "-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(["-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}"]) elif isinstance(nio, NIOTAP):
network_options.extend(
["-netdev", f"tap,id=gns3-{adapter_number},ifname={nio.tap_device},script=no,downscript=no"]
)
else: else:
# newer QEMU networking syntax network_options.extend(["-device", device_string])
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])
return network_options return network_options

View File

@ -201,7 +201,6 @@ class QemuTemplate(Template):
kernel_image = Column(String) kernel_image = Column(String)
bios_image = Column(String) bios_image = Column(String)
kernel_command_line = Column(String) kernel_command_line = Column(String)
legacy_networking = Column(Boolean)
replicate_network_connection_state = Column(Boolean) replicate_network_connection_state = Column(Boolean)
create_config_disk = Column(Boolean) create_config_disk = Column(Boolean)
on_close = Column(String) on_close = Column(String)

View File

@ -195,7 +195,6 @@ class QemuBase(BaseModel):
mac_address: Optional[str] = Field( mac_address: Optional[str] = Field(
None, description="QEMU MAC address", regex="^([0-9a-fA-F]{2}[:]){5}([0-9a-fA-F]{2})$" 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( replicate_network_connection_state: Optional[bool] = Field(
None, description="Replicate the network connection state for links in Qemu" None, description="Replicate the network connection state for links in Qemu"
) )

View File

@ -74,7 +74,6 @@ class QemuTemplate(TemplateBase):
kernel_image: Optional[str] = Field("", description="QEMU kernel image path") kernel_image: Optional[str] = Field("", description="QEMU kernel image path")
bios_image: Optional[str] = Field("", description="QEMU bios image path") bios_image: Optional[str] = Field("", description="QEMU bios image path")
kernel_command_line: Optional[str] = Field("", description="QEMU kernel command line") 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( replicate_network_connection_state: Optional[bool] = Field(
True, description="Replicate the network connection state for links in Qemu" True, description="Replicate the network connection state for links in Qemu"
) )

View File

@ -748,7 +748,6 @@ class TestQemuTemplate:
"initrd": "", "initrd": "",
"kernel_command_line": "", "kernel_command_line": "",
"kernel_image": "", "kernel_image": "",
"legacy_networking": False,
"linked_clone": True, "linked_clone": True,
"mac_address": "", "mac_address": "",
"name": "Qemu template", "name": "Qemu template",