mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@barebox.org>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@barebox.org>
Subject: [PATCH 3/3] test: py: implement --port-forward option
Date: Sun,  3 May 2026 10:30:06 +0200	[thread overview]
Message-ID: <20260503083115.2763213-3-a.fatoum@barebox.org> (raw)
In-Reply-To: <20260503083115.2763213-1-a.fatoum@barebox.org>

Unsolicited host-to-guest UDP requires an explicit port forward.
As we already have a -nic option, the easiest way is to have a
barebox-specific option that's expanded to the correct QEMU
incantations, so implement it.

Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
 Documentation/boards/emulated.rst | 25 +++++++++++++++++++++++++
 Documentation/user/networking.rst |  2 ++
 conftest.py                       | 13 ++++++++++++-
 3 files changed, 39 insertions(+), 1 deletion(-)

diff --git a/Documentation/boards/emulated.rst b/Documentation/boards/emulated.rst
index e3f7f78ab258..0d6dd85dc759 100644
--- a/Documentation/boards/emulated.rst
+++ b/Documentation/boards/emulated.rst
@@ -34,3 +34,28 @@ Emulated targets can be started interactively with ``pytest --interactive``::
 The test suite can be run by omitting the ``--interactive``.
 For more information, see the :ref:`labgrid` section in the
 :ref:`contributing` guide.
+
+Netconsole over QEMU user networking
+------------------------------------
+
+barebox' UDP-based :ref:`network console <network_console>` can also
+be used in combination with QEMU. With user-mode networking (SLIRP),
+guest-to-host UDP works via NAT out of the box,
+but unsolicited host-to-guest UDP requires an explicit port forward::
+
+  pytest --lg-env test/arm/multi_v8_defconfig.yaml --interactive \
+    --env nv/dev.netconsole.ip=10.0.2.2                          \
+    --env nv/dev.netconsole.port=6666                            \
+    --env init/netconsole="ifup -a1; netconsole.active=ioe"      \
+    --port-forward=6666
+
+This will point netconsole at the SLIRP gateway (``10.0.2.2`` is the host
+as seen from the guest) and bring up the interface::
+
+  netconsole: netconsole initialized with 10.0.2.2:6666
+
+The ``i`` flag in ``netconsole.active`` is required for input; without it
+only output reaches the host. On the host, you can then interact with
+the netconsole via::
+
+  scripts/netconsole -s 127.0.0.1 127.0.0.2 6666
diff --git a/Documentation/user/networking.rst b/Documentation/user/networking.rst
index d1db2768ad20..99ab4d8a3fda 100644
--- a/Documentation/user/networking.rst
+++ b/Documentation/user/networking.rst
@@ -173,6 +173,8 @@ variables:
   ``-o port=${global.nfs.port},mountport=${global.nfs.port}`` as argument
   to the :ref:`mount command <command_mount>`.
 
+.. _network_console:
+
 Network console
 ---------------
 
diff --git a/conftest.py b/conftest.py
index 72d2df792e6d..6f76586e010b 100644
--- a/conftest.py
+++ b/conftest.py
@@ -144,6 +144,8 @@ def pytest_addoption(parser):
                      help=('Pass all remaining options to QEMU as is'))
     parser.addoption('--bootarg', action='append', dest='bootarg', default=[],
                      help=('Pass boot arguments to barebox for debugging purposes'))
+    parser.addoption('--port-forward', metavar="PORT", action='append', dest='qemu_port', default=[],
+                     help=('Forward incoming TCP or UDP connections on specified PORT'))
 
 
 @pytest.fixture(scope="session")
@@ -258,12 +260,21 @@ def strategy(request, target, pytestconfig):  # noqa: max-complexity=30
     for arg in pytestconfig.option.qemu_arg:
         strategy.append_qemu_args(arg)
 
+    qemu_nic = "user,id=net0"
+
+    for port in pytestconfig.option.qemu_port:
+        qemu_nic += f",hostfwd=udp:127.0.0.2:{port}-:{port}"
+        qemu_nic += f",hostfwd=tcp:127.0.0.2:{port}-:{port}"
+
     if "testfs" in features:
         if not any(fs and fs[0] == "testfs" for fs in pytestconfig.option.qemu_fs):
             testfs_path = os.path.join(os.environ["LG_BUILDDIR"], "testfs")
             pytestconfig.option.qemu_fs.append(["testfs", testfs_path])
             os.makedirs(testfs_path, exist_ok=True)
-            strategy.append_qemu_args("-nic", f"user,id=net0,tftp={testfs_path}")
+            qemu_nic += f",tftp={testfs_path}"
+
+    if "qemu" in features:
+        strategy.append_qemu_args("-nic", qemu_nic)
 
     for i, fs in enumerate(pytestconfig.option.qemu_fs):
         if virtio:
-- 
2.47.3




  parent reply	other threads:[~2026-05-03  8:31 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-03  8:30 [PATCH 1/3] netconsole: terminate netcat background process on exit Ahmad Fatoum
2026-05-03  8:30 ` [PATCH 2/3] netconsole: add support for binding to specific IP Ahmad Fatoum
2026-05-03  8:30 ` Ahmad Fatoum [this message]
2026-05-07 10:38 ` [PATCH 1/3] netconsole: terminate netcat background process on exit Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260503083115.2763213-3-a.fatoum@barebox.org \
    --to=a.fatoum@barebox.org \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox