• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
27. test_net.sh
28
29# Temporary directory to store sshd setting or ssh key
30# Note: ssh doesn't work when those directory is under /tmp.
31TMPDIR="/root"
32
33cleanup()
34{
35	# Stop the ssh daemon
36	test -s sshd.pid && kill $(cat sshd.pid)
37	pkill 'netstress$'
38	tst_rmdir
39	[ "$rtmpdir" ] && tst_rhost_run -c "rm -rf $rtmpdir"
40	TMPDIR=
41}
42
43setup()
44{
45	trap "tst_brkm TBROK 'test interrupted'" INT
46
47	tst_require_root
48	tst_check_cmds pkill sshd ssh od
49
50	ipver=${TST_IPV6:-"4"}
51
52	# Get the sshd command with absolute path
53	SSHD=$(which sshd)
54	test "$SSHD" || tst_brkm TBROK "sshd daemon is not found"
55
56	check_icmpv${ipver}_connectivity $(tst_iface) $(tst_ipaddr rhost) || \
57		tst_brkm TBROK "Failed to ping to $(tst_ipaddr rhost)"
58
59	port=$(tst_rhost_run -c "tst_get_unused_port ipv${ipver} stream")
60
61	tst_tmpdir
62
63	tmpdir=$TST_TMPDIR
64
65	cat << EOD > $tmpdir/sshd_config
66Port $port
67ListenAddress $(tst_ipaddr)
68PermitRootLogin yes
69AuthorizedKeysFile $tmpdir/authorized_keys
70PasswordAuthentication no
71AllowTcpForwarding yes
72TCPKeepAlive yes
73UseDNS no
74PidFile $tmpdir/sshd.pid
75EOD
76
77	$SSHD -f $tmpdir/sshd_config || \
78		tst_brkm TBROK "Failed to run sshd daemon"
79
80	tst_resm TINFO "Generate configuration file and key at the remote host"
81	rtmpdir=$(tst_rhost_run -c "mktemp -d -p $TMPDIR")
82	tst_rhost_run -s -c "ssh-keygen -t rsa -N \"\" -f $rtmpdir/id_rsa > /dev/null"
83
84	rconfig=$rtmpdir/ssh_config
85
86	tst_rhost_run -s -c "printf \"\
87Port $port\n\
88StrictHostKeyChecking no\n\
89PasswordAuthentication no\n\
90UserKnownHostsFile $rtmpdir/known_hosts\n\
91IdentityFile $rtmpdir/id_rsa\n\" > $rconfig"
92
93	tst_rhost_run -s -c "chmod 700 $rtmpdir; chmod 600 $rtmpdir/*"
94
95	tst_resm TINFO "Generate authorized_keys"
96	tst_rhost_run -c "cat ${rtmpdir}/id_rsa.pub" > $tmpdir/authorized_keys
97
98	tst_resm TINFO "restore context of authorized_keys"
99	local rc=$(which restorecon)
100	test "$rc" && $rc $tmpdir/authorized_keys
101
102	chmod 700 $tmpdir
103	chmod 600 $tmpdir/*
104}
105
106test01()
107{
108	tst_resm TINFO "Creating '$CONNECTION_TOTAL' ssh sessions"
109
110	tst_rhost_run -s -c "ssh-stress01-rmt $ipver $(tst_ipaddr) \
111		$rconfig $CONNECTION_TOTAL"
112
113	tst_resm TPASS "Test is finished successfully"
114}
115
116test02()
117{
118	tst_resm TINFO "Log in/out by many clients asynchronously"
119	tst_resm TINFO "'$CONNECTION_TOTAL' clients, time $NS_DURATION sec"
120
121	tst_rhost_run -s -c "ssh-stress02-rmt $ipver $(tst_ipaddr) \
122		$rconfig $CONNECTION_TOTAL $NS_DURATION"
123
124	tst_resm TPASS "Test is finished successfully"
125}
126
127test03()
128{
129	tst_resm TINFO "Forwarding TCP traffic with $NS_TIMES requests"
130
131	# Run a TCP traffic server
132	port=$(tst_get_unused_port ipv${ipver} stream)
133
134	netstress -R 3 -g $port > tcp_server.log 2>&1 &
135
136	tst_rhost_run -s -c "ssh-stress03-rmt $ipver $(tst_ipaddr) \
137		$rconfig $port $NS_TIMES"
138
139	tst_resm TPASS "Test is finished successfully"
140}
141
142setup
143
144test01
145test02
146test03
147
148tst_exit
149