mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-10-13 14:05:36 +03:00
A VPCS node's single adapter anchors on a persistent TAP the server
creates (tap create + set_owner via uBridge) and the vpcs process
attaches to by name: -e -d <gp{id8}e0p0> -n, the same
server-creates/guest-attaches shape as QEMU's netdev. -n (a vpcs fork
feature) keeps the guest's ip command from ifconfig'ing the anchor on
the host; the vpcs build is probed once per binary identity
(vpcs_tap capability, usage scan) and gates kernel links together
with ubridge_tap — anything else keeps the node on the relay (the
legacy local UDP tunnel on a stock binary, an AF_PACKET endpoint on
the anchor with a capable one).
VPCSVM takes KernelDatapathMixin: _connect_nio dispatches kernel
(enslave into the per-link bridge) / relay-on-anchor / legacy,
captures pick capture start_kernel vs the bridge engine, stop runs
under an execute lock and terminates the process before deleting the
anchor TAPs (a held device refuses deletion), and the duplicate-port
guard backstops the controller's. The NIO routes accept nio_bridge
and write suspend back on update.
_delete_anchor_taps verifies each tap is gone from sysfs and retries
a bounded three times: a holder can release its fd a moment after its
process was reaped (vpcs's daemon parent kills its console child and
exits first), so the unconditional delete raced EBUSY and leaked the
anchor intermittently.
The vpcs side needs IFNAMSIZ (16) instead of its own IFNAMESIZ (12)
for the -d name buffer — anchor names are 14 chars and truncated to a
nonexistent device, which TUNSETIFF then tries to create without
CAP_NET_ADMIN (fixed in the vpcs fork).
e2e (tests/e2e/test_vpcs_kernel_datapath.py): kernel and relay
scenarios green against the real binary — real ICMP both ways, §E.1/§
E.2 on the anchors, delay/suspend/capture, link delete/re-create,
node stop/restart self-heal, zero leftovers; the relay control passes
with both the fork binary and a stock one.
93 lines
3.5 KiB
Python
93 lines
3.5 KiB
Python
#
|
|
# Copyright (C) 2026 GNS3 Technologies Inc.
|
|
#
|
|
# This program is free software: you can redistribute it and/or modify
|
|
# it under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
#
|
|
|
|
"""
|
|
Standalone VPCS tap-mode probe.
|
|
|
|
A VPCS node anchors a kernel-datapath link on a persistent TAP the vpcs
|
|
process attaches to by name (``-e -d <anchor>``). That shape needs a vpcs
|
|
build that also refuses to auto-configure the host side of the TAP (``-n``):
|
|
without the flag every ``ip`` command inside the guest runs
|
|
``ifconfig <tap> … up`` on the anchor — the server owns the anchor's
|
|
addresses and bridge membership, so a vpcs touching them ranges from noise
|
|
(an ifconfig on a name that cannot resolve) to sabotage (reconfiguring an
|
|
interface that does exist).
|
|
|
|
The probe asks the configured binary for its usage (``vpcs -h``) and looks
|
|
for the ``-n`` line, caching the answer by binary identity (path, mtime,
|
|
size, ctime) exactly like the uBridge probes — the same binary never
|
|
answers differently, but replacing it must re-probe. This feeds the compute
|
|
``/capabilities`` payload (``vpcs_tap``) so the controller can gate VPCS
|
|
kernel links on it. Never raises: any failure (missing binary, timeout)
|
|
means unknown, reported as None and cached as such — the safe answer keeps
|
|
the node on the relay datapath.
|
|
"""
|
|
|
|
import asyncio
|
|
import logging
|
|
import os
|
|
import shutil
|
|
|
|
from gns3server.config import Config
|
|
from gns3server.utils.asyncio import subprocess_check_output
|
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
# binary identity (path, mtime, size, ctime) -> whether -n is available
|
|
# (None = probed and unknown)
|
|
_cache: dict[tuple[str, int, int, int], bool | None] = {}
|
|
_lock = asyncio.Lock()
|
|
|
|
# The stable tail of the -n usage line (the flag itself is wrapped in ANSI
|
|
# escapes, the description is not).
|
|
_NO_HOSTCONF_NEEDLE = "do not auto-configure"
|
|
|
|
|
|
async def probe_vpcs_tap(timeout: float = 5.0) -> bool | None:
|
|
"""
|
|
Whether this host's VPCS binary can anchor a kernel link (tap mode with
|
|
``-n``), probed once per binary identity.
|
|
|
|
:returns: True when the usage advertises ``-n``, False when it does not
|
|
(an upstream build), None when the probe failed (unknown binary).
|
|
"""
|
|
|
|
config = Config.instance()
|
|
vpcs_path = config.settings.VPCS.vpcs_path
|
|
if not os.path.isabs(vpcs_path):
|
|
vpcs_path = shutil.which(vpcs_path)
|
|
if not vpcs_path or not os.path.isfile(vpcs_path):
|
|
return None
|
|
try:
|
|
stat = os.stat(vpcs_path)
|
|
key = (vpcs_path, stat.st_mtime_ns, stat.st_size, stat.st_ctime_ns)
|
|
except OSError:
|
|
return None
|
|
|
|
async with _lock:
|
|
if key in _cache:
|
|
return _cache[key]
|
|
try:
|
|
output = await asyncio.wait_for(subprocess_check_output(vpcs_path, "-h"), timeout=timeout)
|
|
except (OSError, asyncio.TimeoutError, ValueError) as e:
|
|
log.debug("VPCS tap-mode probe failed: %s", e)
|
|
supported = None
|
|
else:
|
|
supported = _NO_HOSTCONF_NEEDLE in output
|
|
_cache[key] = supported
|
|
return supported
|