Deleted Added
full compact
tst.localtcpstate.ksh (211545) tst.localtcpstate.ksh (280773)
1#!/usr/bin/ksh
2#
3# CDDL HEADER START
4#
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.
8#
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.
13#
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]
19#
20# CDDL HEADER END
21#
22
23#
24# Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
25#
26
27#
28# Test tcp:::state-change and tcp:::{send,receive} by connecting to
29# the local 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 fusion send and
32# receive events for the message should result.
33#
34# This may fail due to:
35#
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 local ssh service is not online.
40# 4. An unlikely race causes the unlocked global send/receive
41# variables to be corrupted.
42#
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:
45#
46# 3 x ip:::send (2 during the TCP handshake, then a FIN)
47# 4 x tcp:::send (2 during the TCP handshake, 1 message then a FIN)
48# 2 x ip:::receive (1 during the TCP handshake, then the FIN ACK)
49# 3 x tcp:::receive (1 during the TCP handshake, 1 message then the FIN ACK)
50#
51# The actual ip count tested is 5 each way, since we are tracing both
52# source and destination events. The actual tcp count tested is 7
53# each way, since the TCP fusion send/receive events will not reach IP.
54#
55# For this test to work, we are assuming that the TCP handshake and
56# TCP close will enter the IP code path and not use tcp fusion.
57#
58
59if (( $# != 1 )); then
60 print -u2 "expected one argument: <dtrace-path>"
61 exit 2
62fi
63
64dtrace=$1
65local=127.0.0.1
66tcpport=22
67DIR=/var/tmp/dtest.$$
68
69mkdir $DIR
70cd $DIR
71
72cat > test.pl <<-EOPERL
73 use IO::Socket;
74 my \$s = IO::Socket::INET->new(
75 Proto => "tcp",
76 PeerAddr => "$local",
77 PeerPort => $tcpport,
78 Timeout => 3);
79 die "Could not connect to host $local port $tcpport" unless \$s;
80 print \$s "testing state machine transitions";
81 close \$s;
1#!/usr/bin/ksh
2#
3# CDDL HEADER START
4#
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.
8#
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.
13#
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]
19#
20# CDDL HEADER END
21#
22
23#
24# Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
25#
26
27#
28# Test tcp:::state-change and tcp:::{send,receive} by connecting to
29# the local 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 fusion send and
32# receive events for the message should result.
33#
34# This may fail due to:
35#
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 local ssh service is not online.
40# 4. An unlikely race causes the unlocked global send/receive
41# variables to be corrupted.
42#
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:
45#
46# 3 x ip:::send (2 during the TCP handshake, then a FIN)
47# 4 x tcp:::send (2 during the TCP handshake, 1 message then a FIN)
48# 2 x ip:::receive (1 during the TCP handshake, then the FIN ACK)
49# 3 x tcp:::receive (1 during the TCP handshake, 1 message then the FIN ACK)
50#
51# The actual ip count tested is 5 each way, since we are tracing both
52# source and destination events. The actual tcp count tested is 7
53# each way, since the TCP fusion send/receive events will not reach IP.
54#
55# For this test to work, we are assuming that the TCP handshake and
56# TCP close will enter the IP code path and not use tcp fusion.
57#
58
59if (( $# != 1 )); then
60 print -u2 "expected one argument: <dtrace-path>"
61 exit 2
62fi
63
64dtrace=$1
65local=127.0.0.1
66tcpport=22
67DIR=/var/tmp/dtest.$$
68
69mkdir $DIR
70cd $DIR
71
72cat > test.pl <<-EOPERL
73 use IO::Socket;
74 my \$s = IO::Socket::INET->new(
75 Proto => "tcp",
76 PeerAddr => "$local",
77 PeerPort => $tcpport,
78 Timeout => 3);
79 die "Could not connect to host $local port $tcpport" unless \$s;
80 print \$s "testing state machine transitions";
81 close \$s;
82 sleep(2);
82EOPERL
83
84$dtrace -c '/usr/bin/perl test.pl' -qs /dev/stdin <<EODTRACE
85BEGIN
86{
87 ipsend = tcpsend = ipreceive = tcpreceive = 0;
88 connreq = connest = connaccept = 0;
89}
90
91ip:::send
92/args[2]->ip_saddr == "$local" && args[2]->ip_daddr == "$local" &&
93 args[4]->ipv4_protocol == IPPROTO_TCP/
94{
95 ipsend++;
96}
97
98tcp:::send
99/args[2]->ip_saddr == "$local" && args[2]->ip_daddr == "$local" &&
100 (args[4]->tcp_sport == $tcpport || args[4]->tcp_dport == $tcpport)/
101{
102 tcpsend++;
103}
104
105ip:::receive
106/args[2]->ip_saddr == "$local" && args[2]->ip_daddr == "$local" &&
107 args[4]->ipv4_protocol == IPPROTO_TCP/
108{
109 ipreceive++;
110}
111
112tcp:::receive
113/args[2]->ip_saddr == "$local" && args[2]->ip_daddr == "$local" &&
114 (args[4]->tcp_sport == $tcpport || args[4]->tcp_dport == $tcpport)/
115{
116 tcpreceive++;
117}
118
119tcp:::state-change
120{
121 state_event[args[3]->tcps_state]++;
122}
123
124tcp:::connect-request
125/args[2]->ip_saddr == "$local" && args[2]->ip_daddr == "$local" &&
126 args[4]->tcp_dport == $tcpport/
127{
128 connreq++;
129}
130
131tcp:::connect-established
132/args[2]->ip_saddr == "$local" && args[2]->ip_daddr == "$local" &&
133 args[4]->tcp_sport == $tcpport/
134{
135 connest++;
136}
137
138tcp:::accept-established
139/args[2]->ip_saddr == "$local" && args[2]->ip_daddr == "$local" &&
140 args[4]->tcp_dport == $tcpport/
141{
142 connaccept++;
143}
144
145END
146{
147 printf("Minimum TCP events seen\n\n");
148 printf("ip:::send - %s\n", ipsend >= 5 ? "yes" : "no");
149 printf("ip:::receive - %s\n", ipreceive >= 5 ? "yes" : "no");
150 printf("tcp:::send - %s\n", tcpsend >= 7 ? "yes" : "no");
151 printf("tcp:::receive - %s\n", tcpreceive >= 7 ? "yes" : "no");
152 printf("tcp:::state-change to syn-sent - %s\n",
153 state_event[TCP_STATE_SYN_SENT] >=1 ? "yes" : "no");
154 printf("tcp:::state-change to syn-received - %s\n",
155 state_event[TCP_STATE_SYN_RECEIVED] >=1 ? "yes" : "no");
156 printf("tcp:::state-change to established - %s\n",
157 state_event[TCP_STATE_ESTABLISHED] >= 2 ? "yes" : "no");
158 printf("tcp:::state-change to fin-wait-1 - %s\n",
159 state_event[TCP_STATE_FIN_WAIT_1] >= 1 ? "yes" : "no");
160 printf("tcp:::state-change to close-wait - %s\n",
161 state_event[TCP_STATE_CLOSE_WAIT] >= 1 ? "yes" : "no");
162 printf("tcp:::state-change to fin-wait-2 - %s\n",
163 state_event[TCP_STATE_FIN_WAIT_2] >= 1 ? "yes" : "no");
164 printf("tcp:::state-change to last-ack - %s\n",
165 state_event[TCP_STATE_LAST_ACK] >= 1 ? "yes" : "no");
166 printf("tcp:::state-change to time-wait - %s\n",
167 state_event[TCP_STATE_TIME_WAIT] >= 1 ? "yes" : "no");
168 printf("tcp:::connect-request - %s\n",
169 connreq >=1 ? "yes" : "no");
170 printf("tcp:::connect-established - %s\n",
171 connest >=1 ? "yes" : "no");
172 printf("tcp:::accept-established - %s\n",
173 connaccept >=1 ? "yes" : "no");
174}
175EODTRACE
176
177status=$?
178
179cd /
180/bin/rm -rf $DIR
181
182exit $status
83EOPERL
84
85$dtrace -c '/usr/bin/perl test.pl' -qs /dev/stdin <<EODTRACE
86BEGIN
87{
88 ipsend = tcpsend = ipreceive = tcpreceive = 0;
89 connreq = connest = connaccept = 0;
90}
91
92ip:::send
93/args[2]->ip_saddr == "$local" && args[2]->ip_daddr == "$local" &&
94 args[4]->ipv4_protocol == IPPROTO_TCP/
95{
96 ipsend++;
97}
98
99tcp:::send
100/args[2]->ip_saddr == "$local" && args[2]->ip_daddr == "$local" &&
101 (args[4]->tcp_sport == $tcpport || args[4]->tcp_dport == $tcpport)/
102{
103 tcpsend++;
104}
105
106ip:::receive
107/args[2]->ip_saddr == "$local" && args[2]->ip_daddr == "$local" &&
108 args[4]->ipv4_protocol == IPPROTO_TCP/
109{
110 ipreceive++;
111}
112
113tcp:::receive
114/args[2]->ip_saddr == "$local" && args[2]->ip_daddr == "$local" &&
115 (args[4]->tcp_sport == $tcpport || args[4]->tcp_dport == $tcpport)/
116{
117 tcpreceive++;
118}
119
120tcp:::state-change
121{
122 state_event[args[3]->tcps_state]++;
123}
124
125tcp:::connect-request
126/args[2]->ip_saddr == "$local" && args[2]->ip_daddr == "$local" &&
127 args[4]->tcp_dport == $tcpport/
128{
129 connreq++;
130}
131
132tcp:::connect-established
133/args[2]->ip_saddr == "$local" && args[2]->ip_daddr == "$local" &&
134 args[4]->tcp_sport == $tcpport/
135{
136 connest++;
137}
138
139tcp:::accept-established
140/args[2]->ip_saddr == "$local" && args[2]->ip_daddr == "$local" &&
141 args[4]->tcp_dport == $tcpport/
142{
143 connaccept++;
144}
145
146END
147{
148 printf("Minimum TCP events seen\n\n");
149 printf("ip:::send - %s\n", ipsend >= 5 ? "yes" : "no");
150 printf("ip:::receive - %s\n", ipreceive >= 5 ? "yes" : "no");
151 printf("tcp:::send - %s\n", tcpsend >= 7 ? "yes" : "no");
152 printf("tcp:::receive - %s\n", tcpreceive >= 7 ? "yes" : "no");
153 printf("tcp:::state-change to syn-sent - %s\n",
154 state_event[TCP_STATE_SYN_SENT] >=1 ? "yes" : "no");
155 printf("tcp:::state-change to syn-received - %s\n",
156 state_event[TCP_STATE_SYN_RECEIVED] >=1 ? "yes" : "no");
157 printf("tcp:::state-change to established - %s\n",
158 state_event[TCP_STATE_ESTABLISHED] >= 2 ? "yes" : "no");
159 printf("tcp:::state-change to fin-wait-1 - %s\n",
160 state_event[TCP_STATE_FIN_WAIT_1] >= 1 ? "yes" : "no");
161 printf("tcp:::state-change to close-wait - %s\n",
162 state_event[TCP_STATE_CLOSE_WAIT] >= 1 ? "yes" : "no");
163 printf("tcp:::state-change to fin-wait-2 - %s\n",
164 state_event[TCP_STATE_FIN_WAIT_2] >= 1 ? "yes" : "no");
165 printf("tcp:::state-change to last-ack - %s\n",
166 state_event[TCP_STATE_LAST_ACK] >= 1 ? "yes" : "no");
167 printf("tcp:::state-change to time-wait - %s\n",
168 state_event[TCP_STATE_TIME_WAIT] >= 1 ? "yes" : "no");
169 printf("tcp:::connect-request - %s\n",
170 connreq >=1 ? "yes" : "no");
171 printf("tcp:::connect-established - %s\n",
172 connest >=1 ? "yes" : "no");
173 printf("tcp:::accept-established - %s\n",
174 connaccept >=1 ? "yes" : "no");
175}
176EODTRACE
177
178status=$?
179
180cd /
181/bin/rm -rf $DIR
182
183exit $status