1174704Skmacy#!/usr/bin/ksh 2237263Snp# 3174704Skmacy# CDDL HEADER START 4174704Skmacy# 5174704Skmacy# The contents of this file are subject to the terms of the 6237263Snp# Common Development and Distribution License (the "License"). 7237263Snp# You may not use this file except in compliance with the License. 8237263Snp# 9237263Snp# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10237263Snp# or http://www.opensolaris.org/os/licensing. 11237263Snp# See the License for the specific language governing permissions 12237263Snp# and limitations under the License. 13174704Skmacy# 14237263Snp# When distributing Covered Code, include this CDDL HEADER in each 15237263Snp# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16174704Skmacy# If applicable, add the following below this CDDL HEADER, with the 17237263Snp# fields enclosed by brackets "[]" replaced with your own identifying 18237263Snp# information: Portions Copyright [yyyy] [name of copyright owner] 19237263Snp# 20237263Snp# CDDL HEADER END 21237263Snp# 22237263Snp 23237263Snp# 24237263Snp# Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. 25174704Skmacy# 26174704Skmacy 27174704Skmacy# 28174704Skmacy# Test {tcp,ip}:::{send,receive} of IPv4 TCP to a remote host. 29174704Skmacy# 30237263Snp# This may fail due to: 31237263Snp# 32174704Skmacy# 1. A change to the ip stack breaking expected probe behavior, 33174704Skmacy# which is the reason we are testing. 34174704Skmacy# 2. No physical network interface is plumbed and up. 35174704Skmacy# 3. No other hosts on this subnet are reachable and listening on ssh. 36174704Skmacy# 4. An unlikely race causes the unlocked global send/receive 37174704Skmacy# variables to be corrupted. 38237263Snp# 39174704Skmacy# This test performs a TCP connection and checks that at least the 40257176Sglebius# following packet counts were traced: 41194739Sbz# 42174704Skmacy# 3 x ip:::send (2 during the TCP handshake, then a FIN) 43174704Skmacy# 3 x tcp:::send (2 during the TCP handshake, then a FIN) 44174704Skmacy# 2 x ip:::receive (1 during the TCP handshake, then the FIN ACK) 45174704Skmacy# 2 x tcp:::receive (1 during the TCP handshake, then the FIN ACK) 46237263Snp# 47237263Snp 48294869Sglebiusif (( $# != 1 )); then 49237263Snp print -u2 "expected one argument: <dtrace-path>" 50174704Skmacy exit 2 51237263Snpfi 52182591Skmacy 53237263Snpdtrace=$1 54237263Snpgetaddr=./get.ipv4remote.pl 55237263Snptcpport=22 56174704SkmacyDIR=/var/tmp/dtest.$$ 57174704Skmacy 58174704Skmacyif [[ ! -x $getaddr ]]; then 59174704Skmacy print -u2 "could not find or execute sub program: $getaddr" 60237263Snp exit 3 61174704Skmacyfi 62237263Snp$getaddr $tcpport | read source dest 63174704Skmacyif (( $? != 0 )); then 64237263Snp exit 4 65237263Snpfi 66237263Snp 67237263Snpmkdir $DIR 68237263Snpcd $DIR 69237263Snp 70237263Snpcat > test.pl <<-EOPERL 71237263Snp use IO::Socket; 72237263Snp my \$s = IO::Socket::INET->new( 73174704Skmacy Proto => "tcp", 74237263Snp PeerAddr => "$dest", 75174704Skmacy PeerPort => $tcpport, 76174704Skmacy Timeout => 3); 77174704Skmacy die "Could not connect to host $dest port $tcpport" unless \$s; 78237263Snp close \$s; 79237263Snp sleep(2); 80237263SnpEOPERL 81237263Snp 82237263Snp$dtrace -c 'perl test.pl' -qs /dev/stdin <<EODTRACE 83237263SnpBEGIN 84237263Snp{ 85237263Snp ipsend = tcpsend = ipreceive = tcpreceive = 0; 86237263Snp} 87237263Snp 88174704Skmacyip:::send 89174704Skmacy/args[2]->ip_saddr == "$source" && args[2]->ip_daddr == "$dest" && 90174704Skmacy args[4]->ipv4_protocol == IPPROTO_TCP/ 91180648Skmacy{ 92237263Snp ipsend++; 93237263Snp} 94237263Snp 95180648Skmacytcp:::send 96237263Snp/args[2]->ip_saddr == "$source" && args[2]->ip_daddr == "$dest"/ 97180648Skmacy{ 98237263Snp tcpsend++; 99237263Snp} 100237263Snp 101180648Skmacyip:::receive 102237263Snp/args[2]->ip_saddr == "$dest" && args[2]->ip_daddr == "$source" && 103180648Skmacy args[4]->ipv4_protocol == IPPROTO_TCP/ 104180648Skmacy{ 105237263Snp ipreceive++; 106237263Snp} 107237263Snp 108180648Skmacytcp:::receive 109180648Skmacy/args[2]->ip_saddr == "$dest" && args[2]->ip_daddr == "$source"/ 110237263Snp{ 111237263Snp tcpreceive++; 112180648Skmacy} 113237263Snp 114195699SrwatsonEND 115237263Snp{ 116237263Snp printf("Minimum TCP events seen\n\n"); 117180648Skmacy printf("ip:::send - %s\n", ipsend >= 3 ? "yes" : "no"); 118237263Snp printf("ip:::receive - %s\n", ipreceive >= 2 ? "yes" : "no"); 119180648Skmacy printf("tcp:::send - %s\n", tcpsend >= 3 ? "yes" : "no"); 120180648Skmacy printf("tcp:::receive - %s\n", tcpreceive >= 2 ? "yes" : "no"); 121237263Snp} 122237263SnpEODTRACE 123180648Skmacy 124237263Snpstatus=$? 125237263Snp 126195699Srwatsoncd / 127237263Snp/bin/rm -rf $DIR 128237263Snp 129180648Skmacyexit $? 130237263Snp