14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#!/usr/bin/ksh
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync# CDDL HEADER START
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync# The contents of this file are subject to the terms of the
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync# Common Development and Distribution License (the "License").
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync# You may not use this file except in compliance with the License.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync# or http://www.opensolaris.org/os/licensing.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync# See the License for the specific language governing permissions
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync# and limitations under the License.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync# When distributing Covered Code, include this CDDL HEADER in each
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync# If applicable, add the following below this CDDL HEADER, with the
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync# fields enclosed by brackets "[]" replaced with your own identifying
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync# information: Portions Copyright [yyyy] [name of copyright owner]
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync# CDDL HEADER END
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync# Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync# Test tcp:::state-change and tcp:::{send,receive} by connecting to
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync# the remote ssh service and sending a test message. This should result
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync# in a "Protocol mismatch" response and a close of the connection.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync# A number of state transition events along with tcp send and receive
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync# events for the message should result.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync# This may fail due to:
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync# 1. A change to the ip stack breaking expected probe behavior,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync# which is the reason we are testing.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync# 2. The lo0 interface missing or not up.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync# 3. The remote ssh service is not online.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync# 4. An unlikely race causes the unlocked global send/receive
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync# variables to be corrupted.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync# This test performs a TCP connection to the ssh service (port 22) and
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync# checks that at least the following packet counts were traced:
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync# 4 x ip:::send (2 during the TCP handshake, the message, then a FIN)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync# 4 x tcp:::send (2 during the TCP handshake, the messages, then a FIN)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync# 3 x ip:::receive (1 during the TCP handshake, the response, then the FIN ACK)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync# 3 x tcp:::receive (1 during the TCP handshake, the response, then the FIN ACK)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync# For this test to work, we are assuming that the TCP handshake and
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync# TCP close will enter the IP code path and not use tcp fusion.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncif (( $# != 1 )); then
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync print -u2 "expected one argument: <dtrace-path>"
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync exit 2
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncfi
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncdtrace=$1
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncgetaddr=./get.ipv4remote.pl
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsynctcpport=22
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncDIR=/var/tmp/dtest.$$
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncif [[ ! -x $getaddr ]]; then
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync print -u2 "could not find or execute sub program: $getaddr"
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync exit 3
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncfi
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync$getaddr $tcpport | read source dest
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncif (( $? != 0 )); then
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync exit 4
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncfi
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncmkdir $DIR
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsynccd $DIR
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsynccat > test.pl <<-EOPERL
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync use IO::Socket;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync my \$s = IO::Socket::INET->new(
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync Proto => "tcp",
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync PeerAddr => "$dest",
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync PeerPort => $tcpport,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync Timeout => 3);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync die "Could not connect to host $dest port $tcpport" unless \$s;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync print \$s "testing state machine transitions";
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync close \$s;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncEOPERL
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync$dtrace -c '/usr/bin/perl test.pl' -qs /dev/stdin <<EODTRACE
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncBEGIN
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync ipsend = tcpsend = ipreceive = tcpreceive = 0;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync connreq = connest = 0;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync}
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncip:::send
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/args[2]->ip_saddr == "$source" && args[2]->ip_daddr == "$dest" &&
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync args[4]->ipv4_protocol == IPPROTO_TCP/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync ipsend++;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync}
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsynctcp:::send
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/args[2]->ip_saddr == "$source" && args[2]->ip_daddr == "$dest" &&
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync args[4]->tcp_dport == $tcpport/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync tcpsend++;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync}
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncip:::receive
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/args[2]->ip_saddr == "$dest" && args[2]->ip_daddr == "$source" &&
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync args[4]->ipv4_protocol == IPPROTO_TCP/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync ipreceive++;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync}
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsynctcp:::receive
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/args[2]->ip_saddr == "$dest" && args[2]->ip_daddr == "$source" &&
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync args[4]->tcp_sport == $tcpport/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync tcpreceive++;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync}
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsynctcp:::state-change
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync state_event[args[3]->tcps_state]++;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync}
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsynctcp:::connect-request
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/args[2]->ip_saddr == "$source" && args[2]->ip_daddr == "$dest" &&
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync args[4]->tcp_dport == $tcpport/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync connreq++;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync}
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsynctcp:::connect-established
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/args[2]->ip_saddr == "$dest" && args[2]->ip_daddr == "$source" &&
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync args[4]->tcp_sport == $tcpport/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync connest++;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync}
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncEND
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync printf("Minimum TCP events seen\n\n");
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync printf("ip:::send - %s\n", ipsend >= 4 ? "yes" : "no");
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync printf("ip:::receive - %s\n", ipreceive >= 3 ? "yes" : "no");
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync printf("tcp:::send - %s\n", tcpsend >= 4 ? "yes" : "no");
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync printf("tcp:::receive - %s\n", tcpreceive >= 3 ? "yes" : "no");
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync printf("tcp:::state-change to syn-sent - %s\n",
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync state_event[TCP_STATE_SYN_SENT] >=1 ? "yes" : "no");
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync printf("tcp:::state-change to established - %s\n",
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync state_event[TCP_STATE_ESTABLISHED] >= 1 ? "yes" : "no");
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync printf("tcp:::state-change to fin-wait-1 - %s\n",
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync state_event[TCP_STATE_FIN_WAIT_1] >= 1 ? "yes" : "no");
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync printf("tcp:::state-change to fin-wait-2 - %s\n",
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync state_event[TCP_STATE_FIN_WAIT_2] >= 1 ? "yes" : "no");
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync printf("tcp:::state-change to time-wait - %s\n",
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync state_event[TCP_STATE_TIME_WAIT] >= 1 ? "yes" : "no");
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync printf("tcp:::connect-request - %s\n",
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync connreq >=1 ? "yes" : "no");
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync printf("tcp:::connect-established - %s\n",
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync connest >=1 ? "yes" : "no");
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync}
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncEODTRACE
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncstatus=$?
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsynccd /
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/usr/bin/rm -rf $DIR
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncexit $status