dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / cmd / dtrace / test / tst / common / ip / tst.remotetcpstate.ksh
blobcf6d1dcece847915a08ef86cc9d94fe6bb0c8e5e
1 #!/usr/bin/ksh
3 # CDDL HEADER START
5 # The contents of this file are subject to the terms of the
6 # Common Development and Distribution License (the "License").
7 # You may not use this file except in compliance with the License.
9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 # or http://www.opensolaris.org/os/licensing.
11 # See the License for the specific language governing permissions
12 # and limitations under the License.
14 # When distributing Covered Code, include this CDDL HEADER in each
15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 # If applicable, add the following below this CDDL HEADER, with the
17 # fields enclosed by brackets "[]" replaced with your own identifying
18 # information: Portions Copyright [yyyy] [name of copyright owner]
20 # CDDL HEADER END
24 # Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
28 # Test tcp:::state-change and tcp:::{send,receive} by connecting to
29 # the remote ssh service and sending a test message. This should result
30 # in a "Protocol mismatch" response and a close of the connection.
31 # A number of state transition events along with tcp send and receive
32 # events for the message should result.
34 # This may fail due to:
36 # 1. A change to the ip stack breaking expected probe behavior,
37 # which is the reason we are testing.
38 # 2. The lo0 interface missing or not up.
39 # 3. The remote ssh service is not online.
40 # 4. An unlikely race causes the unlocked global send/receive
41 # variables to be corrupted.
43 # This test performs a TCP connection to the ssh service (port 22) and
44 # checks that at least the following packet counts were traced:
46 # 4 x ip:::send (2 during the TCP handshake, the message, then a FIN)
47 # 4 x tcp:::send (2 during the TCP handshake, the messages, then a FIN)
48 # 3 x ip:::receive (1 during the TCP handshake, the response, then the FIN ACK)
49 # 3 x tcp:::receive (1 during the TCP handshake, the response, then the FIN ACK)
51 # For this test to work, we are assuming that the TCP handshake and
52 # TCP close will enter the IP code path and not use tcp fusion.
55 if (( $# != 1 )); then
56 print -u2 "expected one argument: <dtrace-path>"
57 exit 2
60 dtrace=$1
61 getaddr=./get.ipv4remote.pl
62 tcpport=22
63 DIR=/var/tmp/dtest.$$
65 if [[ ! -x $getaddr ]]; then
66 print -u2 "could not find or execute sub program: $getaddr"
67 exit 3
69 $getaddr $tcpport | read source dest
70 if (( $? != 0 )); then
71 exit 4
74 mkdir $DIR
75 cd $DIR
77 cat > test.pl <<-EOPERL
78 use IO::Socket;
79 my \$s = IO::Socket::INET->new(
80 Proto => "tcp",
81 PeerAddr => "$dest",
82 PeerPort => $tcpport,
83 Timeout => 3);
84 die "Could not connect to host $dest port $tcpport" unless \$s;
85 print \$s "testing state machine transitions";
86 close \$s;
87 EOPERL
89 $dtrace -c 'perl test.pl' -qs /dev/stdin <<EODTRACE
90 BEGIN
92 ipsend = tcpsend = ipreceive = tcpreceive = 0;
93 connreq = connest = 0;
96 ip:::send
97 /args[2]->ip_saddr == "$source" && args[2]->ip_daddr == "$dest" &&
98 args[4]->ipv4_protocol == IPPROTO_TCP/
100 ipsend++;
103 tcp:::send
104 /args[2]->ip_saddr == "$source" && args[2]->ip_daddr == "$dest" &&
105 args[4]->tcp_dport == $tcpport/
107 tcpsend++;
110 ip:::receive
111 /args[2]->ip_saddr == "$dest" && args[2]->ip_daddr == "$source" &&
112 args[4]->ipv4_protocol == IPPROTO_TCP/
114 ipreceive++;
117 tcp:::receive
118 /args[2]->ip_saddr == "$dest" && args[2]->ip_daddr == "$source" &&
119 args[4]->tcp_sport == $tcpport/
121 tcpreceive++;
124 tcp:::state-change
126 state_event[args[3]->tcps_state]++;
129 tcp:::connect-request
130 /args[2]->ip_saddr == "$source" && args[2]->ip_daddr == "$dest" &&
131 args[4]->tcp_dport == $tcpport/
133 connreq++;
136 tcp:::connect-established
137 /args[2]->ip_saddr == "$dest" && args[2]->ip_daddr == "$source" &&
138 args[4]->tcp_sport == $tcpport/
140 connest++;
145 printf("Minimum TCP events seen\n\n");
146 printf("ip:::send - %s\n", ipsend >= 4 ? "yes" : "no");
147 printf("ip:::receive - %s\n", ipreceive >= 3 ? "yes" : "no");
148 printf("tcp:::send - %s\n", tcpsend >= 4 ? "yes" : "no");
149 printf("tcp:::receive - %s\n", tcpreceive >= 3 ? "yes" : "no");
150 printf("tcp:::state-change to syn-sent - %s\n",
151 state_event[TCP_STATE_SYN_SENT] >=1 ? "yes" : "no");
152 printf("tcp:::state-change to established - %s\n",
153 state_event[TCP_STATE_ESTABLISHED] >= 1 ? "yes" : "no");
154 printf("tcp:::state-change to fin-wait-1 - %s\n",
155 state_event[TCP_STATE_FIN_WAIT_1] >= 1 ? "yes" : "no");
156 printf("tcp:::state-change to fin-wait-2 - %s\n",
157 state_event[TCP_STATE_FIN_WAIT_2] >= 1 ? "yes" : "no");
158 printf("tcp:::state-change to time-wait - %s\n",
159 state_event[TCP_STATE_TIME_WAIT] >= 1 ? "yes" : "no");
160 printf("tcp:::connect-request - %s\n",
161 connreq >=1 ? "yes" : "no");
162 printf("tcp:::connect-established - %s\n",
163 connest >=1 ? "yes" : "no");
165 EODTRACE
167 status=$?
169 cd /
170 /usr/bin/rm -rf $DIR
172 exit $status