1210753Srpaulo#!/usr/bin/ksh 2210753Srpaulo# 3210753Srpaulo# CDDL HEADER START 4210753Srpaulo# 5210753Srpaulo# The contents of this file are subject to the terms of the 6210753Srpaulo# Common Development and Distribution License (the "License"). 7210753Srpaulo# You may not use this file except in compliance with the License. 8210753Srpaulo# 9210753Srpaulo# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10210753Srpaulo# or http://www.opensolaris.org/os/licensing. 11210753Srpaulo# See the License for the specific language governing permissions 12210753Srpaulo# and limitations under the License. 13210753Srpaulo# 14210753Srpaulo# When distributing Covered Code, include this CDDL HEADER in each 15210753Srpaulo# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16210753Srpaulo# If applicable, add the following below this CDDL HEADER, with the 17210753Srpaulo# fields enclosed by brackets "[]" replaced with your own identifying 18210753Srpaulo# information: Portions Copyright [yyyy] [name of copyright owner] 19210753Srpaulo# 20210753Srpaulo# CDDL HEADER END 21210753Srpaulo# 22210753Srpaulo 23210753Srpaulo# 24210753Srpaulo# Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. 25210753Srpaulo# 26210753Srpaulo 27210753Srpaulo# 28210753Srpaulo# Test tcp:::state-change and tcp:::{send,receive} by connecting to 29210753Srpaulo# the local ssh service and sending a test message. This should result 30210753Srpaulo# in a "Protocol mismatch" response and a close of the connection. 31210753Srpaulo# A number of state transition events along with tcp fusion send and 32210753Srpaulo# receive events for the message should result. 33210753Srpaulo# 34210753Srpaulo# This may fail due to: 35210753Srpaulo# 36210753Srpaulo# 1. A change to the ip stack breaking expected probe behavior, 37210753Srpaulo# which is the reason we are testing. 38210753Srpaulo# 2. The lo0 interface missing or not up. 39210753Srpaulo# 3. The local ssh service is not online. 40210753Srpaulo# 4. An unlikely race causes the unlocked global send/receive 41210753Srpaulo# variables to be corrupted. 42210753Srpaulo# 43210753Srpaulo# This test performs a TCP connection to the ssh service (port 22) and 44210753Srpaulo# checks that at least the following packet counts were traced: 45210753Srpaulo# 46210753Srpaulo# 3 x ip:::send (2 during the TCP handshake, then a FIN) 47210753Srpaulo# 4 x tcp:::send (2 during the TCP handshake, 1 message then a FIN) 48210753Srpaulo# 2 x ip:::receive (1 during the TCP handshake, then the FIN ACK) 49210753Srpaulo# 3 x tcp:::receive (1 during the TCP handshake, 1 message then the FIN ACK) 50210753Srpaulo# 51210753Srpaulo# The actual ip count tested is 5 each way, since we are tracing both 52210753Srpaulo# source and destination events. The actual tcp count tested is 7 53210753Srpaulo# each way, since the TCP fusion send/receive events will not reach IP. 54210753Srpaulo# 55210753Srpaulo# For this test to work, we are assuming that the TCP handshake and 56210753Srpaulo# TCP close will enter the IP code path and not use tcp fusion. 57210753Srpaulo# 58210753Srpaulo 59210753Srpauloif (( $# != 1 )); then 60210753Srpaulo print -u2 "expected one argument: <dtrace-path>" 61210753Srpaulo exit 2 62210753Srpaulofi 63210753Srpaulo 64210753Srpaulodtrace=$1 65210753Srpaulolocal=127.0.0.1 66210753Srpaulotcpport=22 67210753SrpauloDIR=/var/tmp/dtest.$$ 68210753Srpaulo 69210753Srpaulomkdir $DIR 70210753Srpaulocd $DIR 71210753Srpaulo 72210753Srpaulocat > test.pl <<-EOPERL 73210753Srpaulo use IO::Socket; 74210753Srpaulo my \$s = IO::Socket::INET->new( 75210753Srpaulo Proto => "tcp", 76210753Srpaulo PeerAddr => "$local", 77210753Srpaulo PeerPort => $tcpport, 78210753Srpaulo Timeout => 3); 79210753Srpaulo die "Could not connect to host $local port $tcpport" unless \$s; 80210753Srpaulo print \$s "testing state machine transitions"; 81210753Srpaulo close \$s; 82210753SrpauloEOPERL 83210753Srpaulo 84210753Srpaulo$dtrace -c '/usr/bin/perl test.pl' -qs /dev/stdin <<EODTRACE 85210753SrpauloBEGIN 86210753Srpaulo{ 87210753Srpaulo ipsend = tcpsend = ipreceive = tcpreceive = 0; 88210753Srpaulo connreq = connest = connaccept = 0; 89210753Srpaulo} 90210753Srpaulo 91210753Srpauloip:::send 92210753Srpaulo/args[2]->ip_saddr == "$local" && args[2]->ip_daddr == "$local" && 93210753Srpaulo args[4]->ipv4_protocol == IPPROTO_TCP/ 94210753Srpaulo{ 95210753Srpaulo ipsend++; 96210753Srpaulo} 97210753Srpaulo 98210753Srpaulotcp:::send 99210753Srpaulo/args[2]->ip_saddr == "$local" && args[2]->ip_daddr == "$local" && 100210753Srpaulo (args[4]->tcp_sport == $tcpport || args[4]->tcp_dport == $tcpport)/ 101210753Srpaulo{ 102210753Srpaulo tcpsend++; 103210753Srpaulo} 104210753Srpaulo 105210753Srpauloip:::receive 106210753Srpaulo/args[2]->ip_saddr == "$local" && args[2]->ip_daddr == "$local" && 107210753Srpaulo args[4]->ipv4_protocol == IPPROTO_TCP/ 108210753Srpaulo{ 109210753Srpaulo ipreceive++; 110210753Srpaulo} 111210753Srpaulo 112210753Srpaulotcp:::receive 113210753Srpaulo/args[2]->ip_saddr == "$local" && args[2]->ip_daddr == "$local" && 114210753Srpaulo (args[4]->tcp_sport == $tcpport || args[4]->tcp_dport == $tcpport)/ 115210753Srpaulo{ 116210753Srpaulo tcpreceive++; 117210753Srpaulo} 118210753Srpaulo 119210753Srpaulotcp:::state-change 120210753Srpaulo{ 121210753Srpaulo state_event[args[3]->tcps_state]++; 122210753Srpaulo} 123210753Srpaulo 124210753Srpaulotcp:::connect-request 125210753Srpaulo/args[2]->ip_saddr == "$local" && args[2]->ip_daddr == "$local" && 126210753Srpaulo args[4]->tcp_dport == $tcpport/ 127210753Srpaulo{ 128210753Srpaulo connreq++; 129210753Srpaulo} 130210753Srpaulo 131210753Srpaulotcp:::connect-established 132210753Srpaulo/args[2]->ip_saddr == "$local" && args[2]->ip_daddr == "$local" && 133210753Srpaulo args[4]->tcp_sport == $tcpport/ 134210753Srpaulo{ 135210753Srpaulo connest++; 136210753Srpaulo} 137210753Srpaulo 138210753Srpaulotcp:::accept-established 139210753Srpaulo/args[2]->ip_saddr == "$local" && args[2]->ip_daddr == "$local" && 140210753Srpaulo args[4]->tcp_dport == $tcpport/ 141210753Srpaulo{ 142210753Srpaulo connaccept++; 143210753Srpaulo} 144210753Srpaulo 145210753SrpauloEND 146210753Srpaulo{ 147210753Srpaulo printf("Minimum TCP events seen\n\n"); 148210753Srpaulo printf("ip:::send - %s\n", ipsend >= 5 ? "yes" : "no"); 149210753Srpaulo printf("ip:::receive - %s\n", ipreceive >= 5 ? "yes" : "no"); 150210753Srpaulo printf("tcp:::send - %s\n", tcpsend >= 7 ? "yes" : "no"); 151210753Srpaulo printf("tcp:::receive - %s\n", tcpreceive >= 7 ? "yes" : "no"); 152210753Srpaulo printf("tcp:::state-change to syn-sent - %s\n", 153210753Srpaulo state_event[TCP_STATE_SYN_SENT] >=1 ? "yes" : "no"); 154210753Srpaulo printf("tcp:::state-change to syn-received - %s\n", 155210753Srpaulo state_event[TCP_STATE_SYN_RECEIVED] >=1 ? "yes" : "no"); 156210753Srpaulo printf("tcp:::state-change to established - %s\n", 157210753Srpaulo state_event[TCP_STATE_ESTABLISHED] >= 2 ? "yes" : "no"); 158210753Srpaulo printf("tcp:::state-change to fin-wait-1 - %s\n", 159210753Srpaulo state_event[TCP_STATE_FIN_WAIT_1] >= 1 ? "yes" : "no"); 160210753Srpaulo printf("tcp:::state-change to close-wait - %s\n", 161210753Srpaulo state_event[TCP_STATE_CLOSE_WAIT] >= 1 ? "yes" : "no"); 162210753Srpaulo printf("tcp:::state-change to fin-wait-2 - %s\n", 163210753Srpaulo state_event[TCP_STATE_FIN_WAIT_2] >= 1 ? "yes" : "no"); 164210753Srpaulo printf("tcp:::state-change to last-ack - %s\n", 165210753Srpaulo state_event[TCP_STATE_LAST_ACK] >= 1 ? "yes" : "no"); 166210753Srpaulo printf("tcp:::state-change to time-wait - %s\n", 167210753Srpaulo state_event[TCP_STATE_TIME_WAIT] >= 1 ? "yes" : "no"); 168210753Srpaulo printf("tcp:::connect-request - %s\n", 169210753Srpaulo connreq >=1 ? "yes" : "no"); 170210753Srpaulo printf("tcp:::connect-established - %s\n", 171210753Srpaulo connest >=1 ? "yes" : "no"); 172210753Srpaulo printf("tcp:::accept-established - %s\n", 173210753Srpaulo connaccept >=1 ? "yes" : "no"); 174210753Srpaulo} 175210753SrpauloEODTRACE 176210753Srpaulo 177210753Srpaulostatus=$? 178210753Srpaulo 179210753Srpaulocd / 180211545Srpaulo/bin/rm -rf $DIR 181210753Srpaulo 182210753Srpauloexit $status 183