1#!/usr/bin/env ksh93 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) 2008, 2010, Oracle and/or its affiliates. All rights reserved. 25# 26 27# 28# Test {tcp,ip}:::{send,receive} of IPv4 TCP to a remote host. 29# 30# This may fail due to: 31# 32# 1. A change to the ip stack breaking expected probe behavior, 33# which is the reason we are testing. 34# 2. No physical network interface is plumbed and up. 35# 3. No other hosts on this subnet are reachable and listening on ssh. 36# 4. An unlikely race causes the unlocked global send/receive 37# variables to be corrupted. 38# 39# This test performs a TCP connection and checks that at least the 40# following packet counts were traced: 41# 42# 4 x ip:::send (2 during connection setup, 2 during connection teardown) 43# 4 x tcp:::send (2 during connection setup, 2 during connection teardown) 44# 5 x ip:::receive (1 during connection setup, the response, 1 window update, 45# 1 banner line, 2 during connection teardown) 46# 5 x tcp:::receive (1 during connection setup, the response, 1 window update, 47# 1 banner line, 2 during connection teardown) 48 49if (( $# != 1 )); then 50 print -u2 "expected one argument: <dtrace-path>" 51 exit 2 52fi 53 54dtrace=$1 55getaddr=./get.ipv4remote.pl 56tcpport=22 57DIR=/var/tmp/dtest.$$ 58 59if [[ ! -x $getaddr ]]; then 60 print -u2 "could not find or execute sub program: $getaddr" 61 exit 3 62fi 63$getaddr $tcpport | read source dest 64if (( $? != 0 )); then 65 exit 4 66fi 67 68mkdir $DIR 69cd $DIR 70 71cat > test.pl <<-EOPERL 72 use IO::Socket; 73 my \$s = IO::Socket::INET->new( 74 Proto => "tcp", 75 PeerAddr => "$dest", 76 PeerPort => $tcpport, 77 Timeout => 3); 78 die "Could not connect to host $dest port $tcpport" unless \$s; 79 readline \$s; 80 close \$s; 81 sleep(2); 82EOPERL 83 84$dtrace -c 'perl test.pl' -qs /dev/stdin <<EODTRACE 85BEGIN 86{ 87 ipsend = tcpsend = ipreceive = tcpreceive = 0; 88} 89 90ip:::send 91/args[2]->ip_saddr == "$source" && args[2]->ip_daddr == "$dest" && 92 args[4]->ipv4_protocol == IPPROTO_TCP/ 93{ 94 ipsend++; 95} 96 97tcp:::send 98/args[2]->ip_saddr == "$source" && args[2]->ip_daddr == "$dest"/ 99{ 100 tcpsend++; 101} 102 103ip:::receive 104/args[2]->ip_saddr == "$dest" && args[2]->ip_daddr == "$source" && 105 args[4]->ipv4_protocol == IPPROTO_TCP/ 106{ 107 ipreceive++; 108} 109 110tcp:::receive 111/args[2]->ip_saddr == "$dest" && args[2]->ip_daddr == "$source"/ 112{ 113 tcpreceive++; 114} 115 116END 117{ 118 printf("Minimum TCP events seen\n\n"); 119 printf("ip:::send - %s\n", ipsend >= 4 ? "yes" : "no"); 120 printf("ip:::receive - %s\n", ipreceive >= 5 ? "yes" : "no"); 121 printf("tcp:::send - %s\n", tcpsend >= 4 ? "yes" : "no"); 122 printf("tcp:::receive - %s\n", tcpreceive >= 5 ? "yes" : "no"); 123} 124EODTRACE 125 126status=$? 127 128cd / 129/bin/rm -rf $DIR 130 131exit $status 132