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) 2010, Oracle and/or its affiliates. All rights reserved. 25# 26 27# 28# Test sctp:::state-change and sctp:::{send,receive} by connecting to 29# the remote http service. 30# A number of state transition events along with sctp send and receive 31# events for the message should result. 32# 33# This may fail due to: 34# 35# 1. A change to the ip stack breaking expected probe behavior, 36# which is the reason we are testing. 37# 2. The lo0 interface missing or not up. 38# 3. The remote ssh service is not online. 39# 4. An unlikely race causes the unlocked global send/receive 40# variables to be corrupted. 41# 42# This test performs a SCTP association to the http service (port 80) and 43# checks that at least the following packet counts were traced: 44# 45# 4 x ip:::send (2 during setup, 2 during teardown) 46# 4 x sctp:::send (2 during setup, 2 during teardown) 47# 3 x ip:::receive (2 during setup, 1 during teardown) 48# 3 x sctp:::receive (2 during setup, 1 during teardown) 49# 50 51if (( $# != 1 )); then 52 print -u2 "expected one argument: <dtrace-path>" 53 exit 2 54fi 55 56dtrace=$1 57getaddr=./get.ipv4remote.pl 58sctpport=80 59DIR=/var/tmp/dtest.$$ 60 61if [[ ! -x $getaddr ]]; then 62 print -u2 "could not find or execute sub program: $getaddr" 63 exit 3 64fi 65$getaddr $sctpport sctp | read source dest 66if (( $? != 0 )); then 67 exit 4 68fi 69 70mkdir $DIR 71cd $DIR 72 73cat > test.pl <<-EOPERL 74 use IO::Socket; 75 my \$s = IO::Socket::INET->new( 76 Type => SOCK_STREAM, 77 Proto => "sctp", 78 LocalAddr => "$source", 79 PeerAddr => "$dest", 80 PeerPort => $sctpport, 81 Timeout => 3); 82 die "Could not connect to host $dest port $sctpport \$@" unless \$s; 83 close \$s; 84 sleep(2); 85EOPERL 86 87$dtrace -c 'perl test.pl' -qs /dev/stdin <<EODTRACE 88BEGIN 89{ 90 ipsend = sctpsend = ipreceive = sctpreceive = 0; 91} 92 93ip:::send 94/args[2]->ip_saddr == "$source" && args[2]->ip_daddr == "$dest" && 95 args[4]->ipv4_protocol == IPPROTO_SCTP/ 96{ 97 ipsend++; 98} 99 100sctp:::send 101/args[2]->ip_saddr == "$source" && args[2]->ip_daddr == "$dest" && 102 args[4]->sctp_dport == $sctpport/ 103{ 104 sctpsend++; 105} 106 107ip:::receive 108/args[2]->ip_saddr == "$dest" && args[2]->ip_daddr == "$source" && 109 args[4]->ipv4_protocol == IPPROTO_SCTP/ 110{ 111 ipreceive++; 112} 113 114sctp:::receive 115/args[2]->ip_saddr == "$dest" && args[2]->ip_daddr == "$source" && 116 args[4]->sctp_sport == $sctpport/ 117{ 118 sctpreceive++; 119} 120 121sctp:::state-change 122{ 123 state_event[args[3]->sctps_state]++; 124} 125 126END 127{ 128 printf("Minimum SCTP events seen\n\n"); 129 printf("ip:::send - %s\n", ipsend >= 4 ? "yes" : "no"); 130 printf("ip:::receive - %s\n", ipreceive >= 3 ? "yes" : "no"); 131 printf("sctp:::send - %s\n", sctpsend >= 4 ? "yes" : "no"); 132 printf("sctp:::receive - %s\n", sctpreceive >= 3 ? "yes" : "no"); 133 printf("sctp:::state-change to cookie-wait - %s\n", 134 state_event[SCTP_STATE_COOKIE_WAIT] >=1 ? "yes" : "no"); 135 printf("sctp:::state-change to cookie-echoed - %s\n", 136 state_event[SCTP_STATE_COOKIE_ECHOED] >= 1 ? "yes" : "no"); 137 printf("sctp:::state-change to established - %s\n", 138 state_event[SCTP_STATE_ESTABLISHED] >= 1 ? "yes" : "no"); 139 printf("sctp:::state-change to shutdown-sent - %s\n", 140 state_event[SCTP_STATE_SHUTDOWN-SENT] >= 1 ? "yes" : "no"); 141} 142EODTRACE 143 144status=$? 145 146cd / 147/bin/rm -rf $DIR 148 149exit $status 150