Commit Graph
304 Commits
Author SHA1 Message Date
YueGuobin 1542a222f4 refactor: share the anchor-TAP lifecycle in the kernel-datapath mixin
The persistent-TAP lifecycle — probe, sweep, create, register, delete —
was implemented four times, once per node type, and the copies had drifted
(probe mechanism, _tap_datapath reset, keep-vs-recreate policy). The
mechanical half moves into KernelDatapathMixin:

- _probe_persistent_taps(probe_name): the scratch-TAP probe, returning the
  refusal for the caller's own warning (QEMU, Dynamips);
- _create_anchor_taps(ports, set_owner, keep_existing): sweep + create +
  optional ownership handover + carrier down + registry, with the ports
  enumerated by the node type and named through the new _tap_name hook;
- _delete_anchor_taps(): the suppressed tap sweep + per-link bridge
  cleanup + registry clear.

Each node type keeps what its fd holder dictates: the release step before
the tap sweep (the QEMU process, the IOL bridge, the hypervisor's NIO
bindings, the container port bridges), its probe policy, and its registry
lifetime. QEMU's now-unconditional registry clear aligns it with the other
three; everything else is behavior-preserving.
2026-10-06 21:17:50 +08:00
YueGuobin c3c025ab2a fix: resolve the code-review findings on the kernel datapath
Compute:
- Track the anchor that owns uBridge's single AF_PACKET capture slot: a
  second kernel port's capture is refused with a clear error (its flag
  rolled back), a failed start no longer wedges the port, and only the
  owning port's stop issues the process-wide `capture stop_kernel`
  (docker/qemu/iou/dynamips/switch, via the mixin's slot helpers).
- Unwind failed starts instead of leaking uBridge and the anchor TAPs:
  QEMU's stop body runs under try/finally, QEMU and IOU start the datapath
  inside the launch try, Dynamips undoes a half-attached port (the retry
  used to be short-circuited into a silent black hole), and Docker deletes
  the veth pair when the namespace move fails.
- Restore the relay filter guard on IOU (kernel-only filters raise
  NodeError, an uncompilable BPF line degrades to a warning), validate the
  eBPF/quota/window/bpf filter shapes before touching the bridge (short or
  non-numeric values surfaced as 500s after partial state), and refuse a
  second NIO on an occupied Docker/QEMU port (the guard IOU and Dynamips
  already had).
- Probe fixes: `_probe_bridge_tap` survives a failing uBridge start, and
  the probe caches key on ctime too, so a chmod/setcap remedy re-probes.

Controller:
- Parse GNS3_UNIX_SOCKET_NIO like the compute does (line-anchored, truthy
  value) and mirror the compute's class selection in kernel_anchor_type.
- Read partial capability reports defensively; make BridgeNIO.bridge
  required-but-nullable so an omitted key is a 422 rather than a KeyError.
- Strip the packet_loss correlation slot even when it is zero: the relay
  filter takes exactly one argument and rejected `packet_loss 10 0`.

Ethernet switch: skip ports whose absorbed anchor does not exist yet (the
join is deferred by design) and roll the ports_mapping back when the VLAN
reconcile fails, so a retry still diffs against the old mapping.

Agent: reject device config entries without a device_name instead of
silently dropping them (a malformed batch used to execute partially while
reporting success).

Also split the netem builder to clear C901 and drop the two per-file ruff
ignores the PR had added, keeping the remove-only policy.
2026-10-06 19:55:21 +08:00
YueGuobin 87ca2138e3 chore(lint): apply the 3.1 f-string wave to the kernel-datapath code
The rebase onto 65c858d45 brought upstream's UP032 enforcement; the
conflict resolution kept this branch's semantics on the overlapping
lines, so their .format() calls needed the conversion afterwards
(ruff check --fix, 41 sites) plus the formatter's rewrap (7 files).

Replicates the CI recipe locally: pip check, ruff check/format, mypy
2.3.1 (clean, 434 files), unit suite 2216 passed.
2026-10-06 00:28:06 +08:00
YueGuobin 7d04d08dba fix: repair imports lost in the 3.1 rebase and meet the new lint baseline
The rebase onto upstream 3.1 (mypy + ruff I001/F401 waves) left the tree
short of the newly enforced baselines in three ways:

* contextlib / UbridgeError imports dropped as false duplicates during
  conflict resolution left NameErrors in iou_vm and qemu_vm (F821);
  the Dynamips router grabbed the compute-level NIOTAP instead of the
  hypervisor one, breaking TAP anchoring (test failure).
* unused imports (KERNEL_UNSUPPORTED_FILTERS, UbridgeError, List) and
  unsorted blocks left behind where the stack's later commits moved the
  last usage elsewhere — ruff I001/F401/RUF022 now enforce these.
* mypy, now baseline-free: cache dict annotations in tc_probe, the
  locators candidate list, the resolved-params None branch in the MCP
  runner, and validate_bpf_syntax keeps the upstream Dict[str, Any]
  return (the strict Optional[str] was wrong for the "valid" bool entry).

The e2e raw-frame probe resolves its compiler via shutil.which (S607)
and zips with strict= (B905); the remaining subprocess call is S603 by
nature and gets a per-file ignore like other test files.

ruff check/format clean, mypy at upstream parity (no new errors),
full unit suite 2167 passed.
2026-10-06 00:21:11 +08:00
YueGuobin a40503e44b fix(qemu): release the datapath under the execution lock
QEMU's process monitor calls stop() by itself when the process dies, so an
API stop and a process-death stop run concurrently in the normal case — and
the datapath release sat outside _execute_lock, letting both stops sweep the
adapter TAP map at the same time. Whichever finished first cleared
_kernel_taps under the other's iterator, which died with "dictionary changed
size during iteration" (the monitor's task, so it surfaced as "Task exception
was never retrieved") with the rest of its sweep, the orphan-bridge removal
and uBridge's shutdown skipped.

Keep the previous fix's ordering (process side first, then the devices) and
hold the lock across the release: serialized, the second stop finds uBridge
gone and sweeps nothing. Reproduced deterministically with two concurrent
stop() calls, the first parked mid-sweep — it raised at qemu_vm.py:1659
before the change, and every TAP is swept exactly once after it.
2026-10-06 00:21:09 +08:00
YueGuobin 0b78d313eb fix(qemu): release the datapath after the process is gone
QEMU is the guest side of every adapter TAP, and uBridge's tap delete
refuses a device another process holds open ('Device or resource busy') —
a best-effort delete whose failure is suppressed. QEMU's stop did the
delete first and stopped the process after, so every node stop or project
delete leaked the persistent TAPs: found by inspecting the host after a
project delete (16 taps left behind, carrier down, no holder), and the
held-tap behaviour reproduced against uBridge directly.

Stop the QEMU process first, then remove the TAPs and the per-link kernel
bridges — process side first, then the devices, the same lesson as IOU's
reverse stop order. Verified live: node stop and project delete now leave
no taps and no processes behind, while a restart recreates the TAPs.

The adapter anchor naming also goes through the shared
utils.kernel_anchor helper, like the other node types.
2026-10-06 00:21:09 +08:00
YueGuobin a1fcd29bce fix(qemu): build a command line for a headless node
_console_options() fell through the "none" branch and returned None, so
_build_command() blew up on `command.extend(None)`: a QEMU node with
console_type "none" -- offered by the GUI, and what API/MCP-driven labs use
to skip the console entirely -- failed to start with a 500 and a traceback.

Return an empty list, exactly like _aux_options() already does, and cover it
with a test that builds the command line for a headless node. Verified on a
live instance: such a node now starts (204) with `console: null` and no
-serial device in the QEMU command line.
2026-10-06 00:21:08 +08:00
YueGuobin 7d2d8c6747 feat(qemu): anchor QEMU adapters on a persistent TAP
QEMU had no host-side interface at all: every adapter was a local UDP tunnel
into uBridge (-netdev socket plus two UDP ports per adapter), so a link could
only ever be a userspace relay. Each adapter now owns a persistent TAP
(gq{node_id[:8]}e{adapter}p{port}), created by uBridge before QEMU is launched
and handed to this user, and the netdev is that TAP -- the anchor role Docker's
veth host end plays. Links attach to it:

* kernel link (NIOBridge): brctl create/up/addif enslaves the TAP into the
  per-link bridge and capture, markers and tc filters are installed on it,
  verbatim through the shared KernelDatapathMixin -- a TAP and a veth host end
  are interchangeable there (an egress qdisc on either impairs traffic entering
  the node, and PACKET_OUTGOING on either is the node receiving);
* relay link: bridge add_nio_ethernet plus add_nio_udp -- AF_PACKET, never the
  TAP NIO, which would take the fd QEMU itself holds.

The netdev type is fixed at launch, so this is all-or-nothing per VM: on the
TAP datapath every link type attaches to (or detaches from) a running VM,
including switching a link between the two datapaths. Stop un-persists the
TAPs (QEMU's open fd keeps each device alive until it exits) and removes the
per-link bridges; start sweeps leftovers first. A uBridge without the tap
module keeps the previous socket-netdev datapath, so an unupgraded install is
unaffected -- such a node simply cannot carry kernel links.
2026-10-06 00:21:08 +08:00
Mark Paronyan d5ad4c67c6 refactor: use f-strings in qemu compute modules 2026-10-03 19:44:00 +03:00
Mark Paronyan 1ed8320e31 Merge branch '3.1' into ruff/pr01-imports 2026-10-03 14:21:22 +03:00
grossmj 64e2a62a04 fix: improve warning message for missing mtools in config disk creation. Ref #2778 2026-10-02 16:08:38 +02:00
Mark Paronyan 38e9ddca09 style: sort imports in compute node modules 2026-10-02 12:43:26 +03:00
Mark Paronyan 95ada23395 refactor: replace percent formatting with format specifiers 2026-10-01 19:57:47 +03:00
Mark Paronyan 06899c92fc refactor: use iterable unpacking instead of concatenation 2026-10-01 19:57:46 +03:00
Mark Paronyan 2dc7479d11 style: remove f-strings without placeholders 2026-10-01 19:57:46 +03:00
Mark Paronyan 1a495ab318 refactor: replace getattr with attribute access 2026-10-01 19:57:42 +03:00
Mark Paronyan 525ef8ca57 fix(typing): resolve mypy errors in compute.qemu.qemu_vm 2026-09-28 12:37:28 +03:00
Mark Paronyan a0450b6bce refactor: ruff autofixes 2026-09-27 15:55:10 +03:00
Cristi da16dc9874 fix(qemu): Fixed missing image replacement for linked-clone nodes 2026-09-18 23:58:49 +03:00
YueGuobin f9f1a4d4d8 log: demote all per-node lifecycle INFO logs to DEBUG
Extend the docker_vm / base_node demotion to the remaining node types
and supporting layers:

  qemu_vm: MAC, adapters, disk image, RAM, priority, NIO added, created
  iou_vm:  application ID, adapters, serial, image, RAM, NIO added
  dynamips router: created, adapter, RAM, NVRAM, IOS, idle-PC, disk,
    MAC, NIO bound; hypervisor create/start/connect; nio_udp created
  builtin: ethernet_switch/hub, cloud, nat — created, NIO bound
  ubridge: hypervisor start/connect

At multi-node scale these per-node lines flood the log. Only the
project-open progress summary (loaded N nodes / creating N links)
now remains at INFO alongside genuinely exceptional events.
2026-08-11 01:05:53 +08:00
grossmj 544d15c87e fix: tests after merging 2026-08-08 16:50:19 +02:00
grossmj dff79f65d3 Merge branch '2.2' into 3.1
# Conflicts:
#	gns3server/compute/qemu/qemu_vm.py
#	gns3server/controller/import_project.py
#	gns3server/controller/project.py
#	gns3server/crash_report.py
#	gns3server/version.py
#	tests/compute/docker/test_docker_vm.py
#	tests/controller/test_import_project.py
#	tests/controller/test_project.py
2026-08-08 16:27:14 +02:00
YueGuobin b6959f8214 qemu: demote QEMU monitor connect and set_link logs to DEBUG 2026-08-03 00:17:34 +08:00
Jeremy Grossmann 7efef28d4f Merge branch '2.2' into bugfix/2838 2026-07-29 17:50:01 +02:00
grossmj d9140d2f8c fix(qemu): move the bios options after the network ones 2026-07-29 17:47:03 +02:00
grossmj e2657febf0 fix(qemu): fix addition of QEMU RNG device causes interface names to change 2026-07-29 17:23:28 +02:00
Iskander Nafikov 9562c9d828 fix(qemu): remove trailing space from RNG object argument 2026-07-28 00:27:55 +08:00
grossmj 7bc9ae4aa8 Fix typo with ovmf_firmware_dir 2026-07-21 17:34:05 +02:00
grossmj 1f6e00d29f Fix issues after merging 2026-07-21 17:20:46 +02:00
grossmj 7487ec14e0 Merge branch '2.2' into 3.1
# Conflicts:
#	CHANGELOG
#	conf/gns3_server.conf
#	gns3server/compute/docker/__init__.py
#	gns3server/compute/docker/docker_vm.py
#	gns3server/compute/qemu/qemu_vm.py
#	gns3server/controller/import_project.py
#	gns3server/crash_report.py
#	gns3server/version.py
2026-07-21 17:03:00 +02:00
grossmj 61c7f4469d Search for system UEFI that is compatible with Python < 3.12 2026-07-13 11:34:29 +02:00
grossmj 896b4fc56a UEFI improvements for Qemu VMs
* Add OVMF firmware directory configuration
* Automatically add a Random Number Generator (RNG) device when using uefi option is enabled
2026-07-13 11:08:17 +02:00
Jeremy Grossmann c3d202abc9 Merge branch '3.0' into ssh-console-support 2026-05-02 22:10:28 +08:00
YueGuobinandClaude Opus 4.6 ba220780a9 fix: improve hostname validation error messages with allowed characters
When a hostname validation fails, the error message now includes
the allowed character set to help users provide valid names.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-05-02 13:09:04 +08:00
Cristi d64eca0418 feat(compute): add SSH console type support 2026-04-30 15:52:47 +03:00
grossmj 8b245c96f8 Qemu VMs: only compute MD5 checksums for existing disks 2026-03-04 18:54:52 +08:00
grossmj c66e851498 Fix for resizing Qemu VM disks 2026-02-23 17:10:15 +08:00
grossmj 60abbade27 Revert merged changes from 2.2 introduced by PR #2607 2026-02-21 21:35:12 +08:00
grossmj c5b9f379fe Merge remote-tracking branch 'origin/2.2' into 3.0
# Conflicts:
#	Dockerfile
#	dev-requirements.txt
#	gns3server/compute/qemu/qemu_vm.py
#	gns3server/version.py
#	requirements.txt
2026-02-20 16:28:53 +08:00
Patrik Olsson fe2014854e Take populated disks into consideration when calculating PCI device ID 2026-02-05 15:10:57 +01:00
grossmj 2cdaa1cd06 Fix tests 2025-05-14 17:19:18 +02:00
grossmj f2080979a1 Fix tests 2025-05-14 16:56:46 +02:00
grossmj df576f0668 Merge remote-tracking branch 'origin/2.2' into 3.0
# Conflicts:
#	gns3server/compute/qemu/qemu_vm.py
#	gns3server/schemas/template.py
2025-05-14 16:42:59 +02:00
grossmj 2b96e54629 Fix tests and require Qemu version >= 2.4 2025-04-30 13:38:52 +07:00
Tobias Stein cdf819f820 Fix adding pci_bridges to qemu vms
* Offset pci_device_id for network devices by 32 (formerly 4)
  to reserve first 32 IDs for non-netdev devices
  * This implies a new pci_bridge for the netdevs and
    the pci_device_ids starting at 0 (using modulo)
  * Fixes a bug in the creation of the qemu command
    when the number of qemu pcie devices (storage_controller, disks, …)
    was greater than 4 and the number of network devices
    saturated the 32 pcie ids of the root bridge
    causing qemu not to start.
2025-04-28 21:07:52 +02:00
Emmanuel Ferdman c05e6f4de4 Resolve deprecation warnings of regex library
Signed-off-by: Emmanuel Ferdman <emmanuelferdman@gmail.com>
2025-04-26 00:15:16 -07:00
grossmj d9dcc2738d Merge remote-tracking branch 'origin/2.2' into 3.0
# Conflicts:
#	CHANGELOG
#	Dockerfile
#	README.md
#	gns3server/appliances/infix.gns3a
#	gns3server/compute/docker/docker_vm.py
#	gns3server/compute/qemu/qemu_vm.py
#	gns3server/controller/gns3vm/virtualbox_gns3_vm.py
#	gns3server/crash_report.py
#	gns3server/static/web-ui/index.html
#	gns3server/static/web-ui/main.9bcf455e62558dedfd48.js
#	gns3server/version.py
2025-04-21 20:13:31 +07:00
grossmj a5a663bc99 Remove OVMF_CODE_4M.secboot.fd and associated code 2025-04-18 17:31:31 +07:00
grossmj 2b7eb91694 Add edk2-stable202502 UEFI firmwares and try to first use firmwares from the ovmf package if installed. Fixes #2494 2025-04-18 17:13:29 +07:00
grossmj 684770a220 Prettify TPM error message 2025-04-18 15:25:50 +07:00