]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
tests: Optionally start telnet server inside VMs
authorJohannes Berg <johannes.berg@intel.com>
Tue, 5 Feb 2019 11:26:58 +0000 (12:26 +0100)
committerJouni Malinen <j@w1.fi>
Tue, 5 Feb 2019 12:26:36 +0000 (14:26 +0200)
If telnetd is installed and --telnet <port> is passed on the
vm-run.sh command line, start a telnet server (directly connected
to bash, no login) inside the VM(s) to be able to look into them
when something is wrong. Use a user network in qemu with a single
host forward from the specified port for this, listening only on
'localhost'.

Please note that this provides unauthenticated access to the guest
system from anything that can open a TCP connection on the host system.
The guess system does have access to reading all files on the host that
the user account running kvm has access to (and even write access if the
default ROTAG ,readonly parameter is cleared). In other words, this
option should not be used on any multiuser systems where kvm is run
under user accounts that are not dedicated for testing purposes (i.e.,
do not have access to any files that should not be readable to
everyone).

This needs CONFIG_VIRTIO_NET=y in the guest kernel.

For parallel-vm.py, the --telnet argument specifies the base port
and each VM index (0, 1, ...) is added to it.

Signed-off-by: Johannes Berg <johannes.berg@intel.com>
tests/hwsim/vm/inside.sh
tests/hwsim/vm/parallel-vm.py
tests/hwsim/vm/vm-run.sh

index accc0ddec6e2f5412b789174710bf507923da1ab..c22289cc35ee3c98fd17dce99a01eacbab0d227a 100755 (executable)
@@ -12,6 +12,10 @@ mount sysfs -t sysfs /sys
 # needed for tracing
 mount debugfs -t debugfs /sys/kernel/debug
 
+# for inside telnet
+mkdir /dev/pts
+mount devpts -t devpts /dev/pts
+
 export PATH=/usr/sbin:$PATH
 
 # reboot on any sort of crash
@@ -22,10 +26,12 @@ sysctl kernel.panic=1
 TESTDIR=$(sed 's/.*testdir=\([^ ]*\) .*/\1/' /proc/cmdline)
 TIMEWARP=$(sed 's/.*timewarp=\([^ ]*\) .*/\1/' /proc/cmdline)
 EPATH=$(sed 's/.*EPATH=\([^ ]*\) .*/\1/' /proc/cmdline)
+TELNET=$(sed 's/.*TELNET=\([^ ]*\) .*/\1/' /proc/cmdline)
 ARGS=$(sed 's/.*ARGS=\([^ ]*\)\( \|$\).*/\1/' /proc/cmdline)
 
 # create /dev entries we need
 mknod -m 660 /dev/ttyS0 c 4 64
+mknod -m 666 /dev/ptmx c 5 2
 mknod -m 660 /dev/random c 1 8
 mknod -m 660 /dev/urandom c 1 9
 mknod -m 666 /dev/null c 1 3
@@ -92,8 +98,27 @@ if [ "$TIMEWARP" = "1" ] ; then
     ) &
 fi
 
+echo hwsimvm > /proc/sys/kernel/hostname
 echo 8 8 8 8 > /proc/sys/kernel/printk
 
+cat > /tmp/bin/login <<EOF
+#!/bin/sh
+
+export PS1='\h:\w\$ '
+exec bash
+EOF
+chmod +x /tmp/bin/login
+
+if [ "$TELNET" = "1" ] ; then
+  ip link set eth0 up
+  ip addr add 172.16.0.15/24 dev eth0
+  which in.telnetd >/dev/null && (
+    while true ; do
+      in.telnetd -debug 23 -L /tmp/bin/login
+    done
+  ) &
+fi
+
 # check if we're rebooting due to a kernel panic ...
 if grep -q 'Kernel panic' /tmp/logs/console ; then
        echo "KERNEL CRASHED!" >/dev/ttyS0
index c9baf5a6c2e1d5229869b0236d6e8254730078fb..cf7f8df658020829c428143247837f2031650a3c 100755 (executable)
@@ -356,6 +356,8 @@ def main():
     p.add_argument('--valgrind', dest='valgrind', action='store_const',
                    const=True, default=False,
                    help="run tests under valgrind")
+    p.add_argument('--telnet', dest='telnet', metavar='<baseport>', type=int,
+                   help="enable telnet server inside VMs, specify the base port here")
     p.add_argument('params', nargs='*')
     args = p.parse_args()
 
@@ -435,6 +437,8 @@ def main():
                '--timestamp', str(timestamp),
                '--ext', 'srv.%d' % (i + 1),
                '-i'] + codecov_args + extra_args
+        if args.telnet:
+            cmd += [ '--telnet', str(args.telnet + i) ]
         vm[i] = {}
         vm[i]['first_run_done'] = False
         vm[i]['proc'] = subprocess.Popen(cmd,
index 2972fb1b0786220d3ce815791d94d706462d0f8f..c68e5568d24f279d485bd04a6ef49e2f3e7410dc 100755 (executable)
@@ -51,6 +51,8 @@ TIMESTAMP=$(date +%s)
 DATE=$TIMESTAMP
 CODECOV=no
 TIMEWARP=0
+TELNET_QEMU=
+TELNET_ARG=0
 DELAY=0
 CODECOV_DIR=
 while [ "$1" != "" ]; do
@@ -73,6 +75,11 @@ while [ "$1" != "" ]; do
                --timewrap ) shift
                        TIMEWARP=1
                        ;;
+               --telnet ) shift
+                       TELNET_ARG=1
+                       TELNET_QEMU="-net nic,model=virtio -net user,id=telnet,restrict=on,net=172.16.0.0/24,hostfwd=tcp:127.0.0.1:$1-:23"
+                       shift
+                       ;;
                --delay ) shift
                        DELAY=$1
                        shift
@@ -134,7 +141,8 @@ $KVM \
        -fsdev local,security_model=none,id=fsdev-logs,path="$LOGDIR",writeout=immediate \
        -device virtio-9p-pci,id=fs-logs,fsdev=fsdev-logs,mount_tag=logshare \
        -monitor null -serial stdio -serial file:$LOGDIR/console \
-       -append "mac80211_hwsim.support_p2p_device=0 mac80211_hwsim.channels=$CHANNELS mac80211_hwsim.radios=7 cfg80211.dyndbg=+p mac80211.dyndbg=+p mac80211_hwsim.dyndbg=+p init=$CMD testdir=$TESTDIR timewarp=$TIMEWARP console=$KVMOUT root=/dev/root rootflags=trans=virtio,version=9p2000.u ro rootfstype=9p EPATH=$EPATH ARGS=$argsfile" | \
+       $TELNET_QEMU \
+       -append "mac80211_hwsim.support_p2p_device=0 mac80211_hwsim.channels=$CHANNELS mac80211_hwsim.radios=7 cfg80211.dyndbg=+p mac80211.dyndbg=+p mac80211_hwsim.dyndbg=+p init=$CMD testdir=$TESTDIR timewarp=$TIMEWARP TELNET=$TELNET_ARG console=$KVMOUT root=/dev/root rootflags=trans=virtio,version=9p2000.u ro rootfstype=9p EPATH=$EPATH ARGS=$argsfile" | \
        sed -u '0,/VM has started up/d'
 
 if [ $CODECOV = "yes" ]; then