16878Sbrendan#!/usr/bin/ksh 26878Sbrendan# 36878Sbrendan# CDDL HEADER START 46878Sbrendan# 56878Sbrendan# The contents of this file are subject to the terms of the 66878Sbrendan# Common Development and Distribution License (the "License"). 76878Sbrendan# You may not use this file except in compliance with the License. 86878Sbrendan# 96878Sbrendan# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 106878Sbrendan# or http://www.opensolaris.org/os/licensing. 116878Sbrendan# See the License for the specific language governing permissions 126878Sbrendan# and limitations under the License. 136878Sbrendan# 146878Sbrendan# When distributing Covered Code, include this CDDL HEADER in each 156878Sbrendan# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 166878Sbrendan# If applicable, add the following below this CDDL HEADER, with the 176878Sbrendan# fields enclosed by brackets "[]" replaced with your own identifying 186878Sbrendan# information: Portions Copyright [yyyy] [name of copyright owner] 196878Sbrendan# 206878Sbrendan# CDDL HEADER END 216878Sbrendan# 226878Sbrendan 236878Sbrendan# 24*12507SAlan.Maguire@Sun.COM# Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. 256878Sbrendan# 266878Sbrendan 276878Sbrendan# 28*12507SAlan.Maguire@Sun.COM# Test {tcp,ip}:::{send,receive} of IPv4 TCP to a remote host. 296878Sbrendan# 306878Sbrendan# This may fail due to: 316878Sbrendan# 326878Sbrendan# 1. A change to the ip stack breaking expected probe behavior, 336878Sbrendan# which is the reason we are testing. 346878Sbrendan# 2. No physical network interface is plumbed and up. 356878Sbrendan# 3. No other hosts on this subnet are reachable and listening on ssh. 366878Sbrendan# 4. An unlikely race causes the unlocked global send/receive 376878Sbrendan# variables to be corrupted. 386878Sbrendan# 396878Sbrendan# This test performs a TCP connection and checks that at least the 406878Sbrendan# following packet counts were traced: 416878Sbrendan# 426878Sbrendan# 3 x ip:::send (2 during the TCP handshake, then a FIN) 43*12507SAlan.Maguire@Sun.COM# 3 x tcp:::send (2 during the TCP handshake, then a FIN) 446878Sbrendan# 2 x ip:::receive (1 during the TCP handshake, then the FIN ACK) 45*12507SAlan.Maguire@Sun.COM# 2 x tcp:::receive (1 during the TCP handshake, then the FIN ACK) 466878Sbrendan# 476878Sbrendan 486878Sbrendanif (( $# != 1 )); then 496878Sbrendan print -u2 "expected one argument: <dtrace-path>" 506878Sbrendan exit 2 516878Sbrendanfi 526878Sbrendan 536878Sbrendandtrace=$1 546878Sbrendangetaddr=./get.ipv4remote.pl 556878Sbrendantcpport=22 566878SbrendanDIR=/var/tmp/dtest.$$ 576878Sbrendan 586878Sbrendanif [[ ! -x $getaddr ]]; then 596878Sbrendan print -u2 "could not find or execute sub program: $getaddr" 606878Sbrendan exit 3 616878Sbrendanfi 626878Sbrendan$getaddr $tcpport | read source dest 636878Sbrendanif (( $? != 0 )); then 646878Sbrendan exit 4 656878Sbrendanfi 666878Sbrendan 676878Sbrendanmkdir $DIR 686878Sbrendancd $DIR 696878Sbrendan 706878Sbrendancat > test.pl <<-EOPERL 716878Sbrendan use IO::Socket; 726878Sbrendan my \$s = IO::Socket::INET->new( 736878Sbrendan Proto => "tcp", 746878Sbrendan PeerAddr => "$dest", 756878Sbrendan PeerPort => $tcpport, 766878Sbrendan Timeout => 3); 776878Sbrendan die "Could not connect to host $dest port $tcpport" unless \$s; 786878Sbrendan close \$s; 796878SbrendanEOPERL 806878Sbrendan 816878Sbrendan$dtrace -c '/usr/bin/perl test.pl' -qs /dev/stdin <<EODTRACE 826878SbrendanBEGIN 836878Sbrendan{ 84*12507SAlan.Maguire@Sun.COM ipsend = tcpsend = ipreceive = tcpreceive = 0; 856878Sbrendan} 866878Sbrendan 876878Sbrendanip:::send 886878Sbrendan/args[2]->ip_saddr == "$source" && args[2]->ip_daddr == "$dest" && 896878Sbrendan args[4]->ipv4_protocol == IPPROTO_TCP/ 906878Sbrendan{ 91*12507SAlan.Maguire@Sun.COM ipsend++; 92*12507SAlan.Maguire@Sun.COM} 93*12507SAlan.Maguire@Sun.COM 94*12507SAlan.Maguire@Sun.COMtcp:::send 95*12507SAlan.Maguire@Sun.COM/args[2]->ip_saddr == "$source" && args[2]->ip_daddr == "$dest"/ 96*12507SAlan.Maguire@Sun.COM{ 97*12507SAlan.Maguire@Sun.COM tcpsend++; 986878Sbrendan} 996878Sbrendan 1006878Sbrendanip:::receive 1016878Sbrendan/args[2]->ip_saddr == "$dest" && args[2]->ip_daddr == "$source" && 1026878Sbrendan args[4]->ipv4_protocol == IPPROTO_TCP/ 1036878Sbrendan{ 104*12507SAlan.Maguire@Sun.COM ipreceive++; 105*12507SAlan.Maguire@Sun.COM} 106*12507SAlan.Maguire@Sun.COM 107*12507SAlan.Maguire@Sun.COMtcp:::receive 108*12507SAlan.Maguire@Sun.COM/args[2]->ip_saddr == "$dest" && args[2]->ip_daddr == "$source"/ 109*12507SAlan.Maguire@Sun.COM{ 110*12507SAlan.Maguire@Sun.COM tcpreceive++; 1116878Sbrendan} 1126878Sbrendan 1136878SbrendanEND 1146878Sbrendan{ 1156878Sbrendan printf("Minimum TCP events seen\n\n"); 116*12507SAlan.Maguire@Sun.COM printf("ip:::send - %s\n", ipsend >= 3 ? "yes" : "no"); 117*12507SAlan.Maguire@Sun.COM printf("ip:::receive - %s\n", ipreceive >= 2 ? "yes" : "no"); 118*12507SAlan.Maguire@Sun.COM printf("tcp:::send - %s\n", tcpsend >= 3 ? "yes" : "no"); 119*12507SAlan.Maguire@Sun.COM printf("tcp:::receive - %s\n", tcpreceive >= 2 ? "yes" : "no"); 1206878Sbrendan} 1216878SbrendanEODTRACE 1226878Sbrendan 1236878Sbrendanstatus=$? 1246878Sbrendan 1256878Sbrendancd / 1266878Sbrendan/usr/bin/rm -rf $DIR 1276878Sbrendan 1286878Sbrendanexit $? 129