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