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]
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 connection setup, 2 during connection teardown)
47 # 4 x tcp:::send (2 during connection setup, 2 during connection teardown)
48 # 5 x ip:::receive (1 during connection setup, the response, 1 window update,
49 # 1 banner line, 2 during connection teardown)
50 # 5 x tcp:::receive (1 during connection setup, the response, 1 window update,
51 # 1 banner line, 2 during connection teardown)
54 if (( $# != 1 )); then
55 print -u2 "expected one argument: <dtrace-path>"
60 getaddr=./get.ipv4remote.pl
64 if [[ ! -x $getaddr ]]; then
65 print -u2 "could not find or execute sub program: $getaddr"
68 $getaddr $tcpport | read source dest
69 if (( $? != 0 )); then
76 cat > test.pl <<-EOPERL
78 my \$s = IO::Socket::INET->new(
83 die "Could not connect to host $dest port $tcpport" unless \$s;
89 $dtrace -c 'perl test.pl' -qs /dev/stdin <<EODTRACE
92 ipsend = tcpsend = ipreceive = tcpreceive = 0;
93 connreq = connest = 0;
97 /args[2]->ip_saddr == "$source" && args[2]->ip_daddr == "$dest" &&
98 args[4]->ipv4_protocol == IPPROTO_TCP/
104 /args[2]->ip_saddr == "$source" && args[2]->ip_daddr == "$dest" &&
105 args[4]->tcp_dport == $tcpport/
111 /args[2]->ip_saddr == "$dest" && args[2]->ip_daddr == "$source" &&
112 args[4]->ipv4_protocol == IPPROTO_TCP/
118 /args[2]->ip_saddr == "$dest" && args[2]->ip_daddr == "$source" &&
119 args[4]->tcp_sport == $tcpport/
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/
136 tcp:::connect-established
137 /args[2]->ip_saddr == "$dest" && args[2]->ip_daddr == "$source" &&
138 args[4]->tcp_sport == $tcpport/
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 >= 5 ? "yes" : "no");
148 printf("tcp:::send - %s\n", tcpsend >= 4 ? "yes" : "no");
149 printf("tcp:::receive - %s\n", tcpreceive >= 5 ? "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");