From: Ahmad Fatoum <a.fatoum@barebox.org>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@barebox.org>
Subject: [PATCH 2/3] netconsole: add support for binding to specific IP
Date: Sun, 3 May 2026 10:30:05 +0200 [thread overview]
Message-ID: <20260503083115.2763213-2-a.fatoum@barebox.org> (raw)
In-Reply-To: <20260503083115.2763213-1-a.fatoum@barebox.org>
If scripts/netconsole is already running when QEMU starts up, the host
forwarding rule may break QEMU startup:
qemu-system-aarch64: -nic user,id=net0,hostfwd=udp:127.0.0.2:6666-:6666,\
tftp=/src/build/barebox/imx8/testfs:
Could not set up host forwarding rule 'udp:127.0.0.2:6666-:6666'
This can be worked around by having QEMU bind to a different loopback
address than what's netcat is going to use.
Add a -s option to control this.
Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
scripts/netconsole | 33 ++++++++++++++++++++++++---------
1 file changed, 24 insertions(+), 9 deletions(-)
diff --git a/scripts/netconsole b/scripts/netconsole
index 7ab81a3a9191..1945de7f9381 100755
--- a/scripts/netconsole
+++ b/scripts/netconsole
@@ -2,9 +2,14 @@
usage() {
(
- echo "Usage: $0 <board IP> [board port]"
+ echo "Usage: $0 [-sh] <board IP> [board port]"
echo ""
echo "If port is not specified, '6666' will be used"
+ echo ""
+ echo "Options:"
+ echo " -s SADDR Bind to SADDR on host side"
+ echo " -h Show this help text and exit"
+
[ -z "$*" ] && exit 0
echo ""
echo "ERROR: $*"
@@ -13,16 +18,26 @@ usage() {
exit $?
}
-while [ -n "$1" ] ; do
- case $1 in
- -h|--help) usage;;
- --) break;;
- -*) usage "Invalid option $1";;
- *) break;;
+if [ "$1" = "--help" ]; then
+ usage
+fi
+
+while getopts ":hs:" opt; do
+ case "$opt" in
+ h) usage ;;
+ s) saddr="$OPTARG" ;;
+ \?) usage "Invalid option -$OPTARG" ;;
+ :) usage "Option -$OPTARG requires an argument" ;;
esac
- shift
done
+shift $((OPTIND - 1))
+
+# handle end-of-options marker
+if [ "$1" = "--" ]; then
+ shift
+fi
+
ip=$1
port=${2:-6666}
@@ -50,7 +65,7 @@ echo "NOTE: the interrupt signal (normally ^C) has been remapped to ^T"
stty -icanon -echo intr ^T
set -m
(
- while ${nc} -u -l -p ${port} < /dev/null ; do
+ while ${nc} ${saddr:+-s "$saddr"} -u -l -p ${port} < /dev/null ; do
:
done
) &
--
2.47.3
next prev 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 ` Ahmad Fatoum [this message]
2026-05-03 8:30 ` [PATCH 3/3] test: py: implement --port-forward option Ahmad Fatoum
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-2-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