1#!/bin/sh 2 3# Copyright (c) 2015 Oracle and/or its affiliates. All Rights Reserved. 4# Copyright (c) International Business Machines Corp., 2005 5# 6# This program is free software; you can redistribute it and/or 7# modify it under the terms of the GNU General Public License as 8# published by the Free Software Foundation; either version 2 of 9# the License, or (at your option) any later version. 10# 11# This program is distributed in the hope that it would be useful, 12# but WITHOUT ANY WARRANTY; without even the implied warranty of 13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14# GNU General Public License for more details. 15# 16# You should have received a copy of the GNU General Public License 17# along with this program; if not, write the Free Software Foundation, 18# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19# 20# Author: Mitsuru Chinen <mitch@jp.ibm.com> 21# 22 23TCID=ssh-stress 24TST_TOTAL=3 25TST_CLEANUP="cleanup" 26 27TST_USE_LEGACY_API=1 28. tst_net.sh 29 30# Temporary directory to store sshd setting or ssh key 31# Note: ssh doesn't work when those directory is under /tmp. 32TMPDIR="/root" 33 34cleanup() 35{ 36 # Stop the ssh daemon 37 test -s sshd.pid && kill $(cat sshd.pid) 38 pkill 'netstress$' 39 tst_rmdir 40 [ "$rtmpdir" ] && tst_rhost_run -c "rm -rf $rtmpdir" 41 TMPDIR= 42} 43 44setup() 45{ 46 trap "tst_brkm TBROK 'test interrupted'" INT 47 48 tst_require_root 49 tst_test_cmds pkill sshd ssh od 50 51 # Get the sshd command with absolute path 52 SSHD=$(which sshd) 53 test "$SSHD" || tst_brkm TBROK "sshd daemon is not found" 54 55 check_icmpv${TST_IPVER}_connectivity $(tst_iface) $(tst_ipaddr rhost) || \ 56 tst_brkm TBROK "Failed to ping to $(tst_ipaddr rhost)" 57 58 port=$(tst_rhost_run -c "tst_get_unused_port ipv${TST_IPVER} stream") 59 60 tst_tmpdir 61 62 tmpdir=$TST_TMPDIR 63 64 cat << EOD > $tmpdir/sshd_config 65Port $port 66ListenAddress $(tst_ipaddr) 67PermitRootLogin yes 68AuthorizedKeysFile $tmpdir/authorized_keys 69PasswordAuthentication no 70AllowTcpForwarding yes 71TCPKeepAlive yes 72UseDNS no 73PidFile $tmpdir/sshd.pid 74EOD 75 76 $SSHD -f $tmpdir/sshd_config || \ 77 tst_brkm TBROK "Failed to run sshd daemon" 78 79 tst_resm TINFO "Generate configuration file and key at the remote host" 80 rtmpdir=$(tst_rhost_run -c "mktemp -d -p $TMPDIR") 81 tst_rhost_run -s -c "ssh-keygen -t rsa -N \"\" -f $rtmpdir/id_rsa > /dev/null" 82 83 rconfig=$rtmpdir/ssh_config 84 85 tst_rhost_run -s -c "printf \"\ 86Port $port\n\ 87StrictHostKeyChecking no\n\ 88PasswordAuthentication no\n\ 89UserKnownHostsFile $rtmpdir/known_hosts\n\ 90IdentityFile $rtmpdir/id_rsa\n\" > $rconfig" 91 92 tst_rhost_run -s -c "chmod 700 $rtmpdir; chmod 600 $rtmpdir/*" 93 94 tst_resm TINFO "Generate authorized_keys" 95 tst_rhost_run -c "cat ${rtmpdir}/id_rsa.pub" > $tmpdir/authorized_keys 96 97 tst_resm TINFO "restore context of authorized_keys" 98 local rc=$(which restorecon) 99 test "$rc" && $rc $tmpdir/authorized_keys 100 101 chmod 700 $tmpdir 102 chmod 600 $tmpdir/* 103} 104 105test01() 106{ 107 tst_resm TINFO "Creating '$CONNECTION_TOTAL' ssh sessions" 108 109 tst_rhost_run -s -c "ssh-stress01-rmt $TST_IPVER $(tst_ipaddr) \ 110 $rconfig $CONNECTION_TOTAL" 111 112 tst_resm TPASS "Test is finished successfully" 113} 114 115test02() 116{ 117 tst_resm TINFO "Log in/out by many clients asynchronously" 118 tst_resm TINFO "'$CONNECTION_TOTAL' clients, time $NS_DURATION sec" 119 120 tst_rhost_run -s -c "ssh-stress02-rmt $TST_IPVER $(tst_ipaddr) \ 121 $rconfig $CONNECTION_TOTAL $NS_DURATION" 122 123 tst_resm TPASS "Test is finished successfully" 124} 125 126test03() 127{ 128 tst_resm TINFO "Forwarding TCP traffic with $NS_TIMES requests" 129 130 # Run a TCP traffic server 131 port=$(tst_get_unused_port ipv${TST_IPVER} stream) 132 133 netstress -R 3 -g $port > tcp_server.log 2>&1 & 134 135 tst_rhost_run -s -c "ssh-stress03-rmt $TST_IPVER $(tst_ipaddr) \ 136 $rconfig $port $NS_TIMES" 137 138 tst_resm TPASS "Test is finished successfully" 139} 140 141setup 142 143test01 144test02 145test03 146 147tst_exit 148