From mboxrd@z Thu Jan 1 00:00:00 1970 Delivery-date: Mon, 26 Apr 2021 08:33:03 +0200 Received: from metis.ext.pengutronix.de ([2001:67c:670:201:290:27ff:fe1d:cc33]) by lore.white.stw.pengutronix.de with esmtp (Exim 4.92) (envelope-from ) id 1launn-0002jv-21 for lore@lore.pengutronix.de; Mon, 26 Apr 2021 08:33:03 +0200 Received: from localhost ([127.0.0.1] helo=metis.ext.pengutronix.de) by metis.ext.pengutronix.de with esmtp (Exim 4.92) (envelope-from ) id 1launm-0001t9-EN; Mon, 26 Apr 2021 08:33:02 +0200 Received: from ptx.hi.pengutronix.de ([2001:67c:670:100:1d::c0]) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1launk-0001sv-Lt; Mon, 26 Apr 2021 08:33:00 +0200 Received: from mol by ptx.hi.pengutronix.de with local (Exim 4.92) (envelope-from ) id 1launk-0000Al-Cs; Mon, 26 Apr 2021 08:33:00 +0200 Date: Mon, 26 Apr 2021 08:33:00 +0200 From: Michael Olbrich To: Roland Hieber Message-ID: <20210426063300.GE27464@pengutronix.de> Mail-Followup-To: Roland Hieber , distrokit@pengutronix.de References: <20210426060526.32029-1-rhi@pengutronix.de> <20210426060526.32029-5-rhi@pengutronix.de> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20210426060526.32029-5-rhi@pengutronix.de> X-Sent-From: Pengutronix Hildesheim X-URL: http://www.pengutronix.de/ X-IRC: #ptxdist @freenode X-Accept-Language: de,en X-Accept-Content-Type: text/plain X-Uptime: 08:31:41 up 67 days, 9:55, 81 users, load average: 0.16, 0.35, 0.39 User-Agent: Mutt/1.10.1 (2018-07-13) Subject: Re: [DistroKit] [PATCH 5/5] v7a: run: randomise the SSH forwarding port X-BeenThere: distrokit@pengutronix.de X-Mailman-Version: 2.1.29 Precedence: list List-Id: DistroKit Mailinglist List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: distrokit@pengutronix.de Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "DistroKit" X-SA-Exim-Connect-IP: 127.0.0.1 X-SA-Exim-Mail-From: distrokit-bounces@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false On Mon, Apr 26, 2021 at 08:05:26AM +0200, Roland Hieber wrote: > When multiple ./configs/platform-v7a/run scripts are run at the same > time, the first qemu process will open port 4445, and following runs > will fail. To prevent that, first look at the environment variable > QEMU_SSH_PORT to determine the port to be used (so that users can set > this in their shell to keep the port static), or fall back to a random > port between 1025 and 65025, which should have a good chance of being > unused. Also print the port forwarding before starting qemu, so we don't > have to bother with "ps -Af|grep qemu". > > Signed-off-by: Roland Hieber > --- > configs/platform-v7a/run | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/configs/platform-v7a/run b/configs/platform-v7a/run > index d180ccfa890d..cf529e968fb0 100755 > --- a/configs/platform-v7a/run > +++ b/configs/platform-v7a/run > @@ -39,7 +39,7 @@ fi > # the port which an sshd would connect to (in the emulated sysem) > SSH_INTERNAL_PORT=22 > # the port which QEMU opens at the host side to give access to the ${SSH_INTERNAL_PORT} > -SSH_EXTERNAL_PORT=4445 > +SSH_EXTERNAL_PORT=${QEMU_SSH_PORT:-${RANDOM%64000+1025}} This means I have to change the ssh command-line whenever I restart qemu. Not nice. How about '${PPID%64000+1025}'? Michael > > # check if vde is available for networking > if [ -z "${VDE_SOCKET}" ]; then > @@ -59,6 +59,7 @@ fi > # fall back to user network if necessary > if [ -z "${QEMU_NET}" ]; then > QEMU_NET=(-netdev user,id=net1,hostfwd=tcp:127.0.0.1:${SSH_EXTERNAL_PORT}-:${SSH_INTERNAL_PORT} ) > + echo "Forwarding SSH port 127.0.0.1:${SSH_EXTERNAL_PORT} -> qemu:${SSH_INTERNAL_PORT}" > fi > > BASE_CMDLINE="console=ttyAMA0,115200 loglevel=5 systemd.log_level=warning systemd.show_status=auto" > -- > 2.29.2 > > > _______________________________________________ > DistroKit mailing list > DistroKit@pengutronix.de > -- Pengutronix e.K. | | Steuerwalder Str. 21 | http://www.pengutronix.de/ | 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | _______________________________________________ DistroKit mailing list DistroKit@pengutronix.de