1N/A#!/usr/bin/ksh
1N/A#
1N/A# CDDL HEADER START
1N/A#
1N/A# The contents of this file are subject to the terms of the
1N/A# Common Development and Distribution License (the "License").
1N/A# You may not use this file except in compliance with the License.
1N/A#
1N/A# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
1N/A# or http://www.opensolaris.org/os/licensing.
1N/A# See the License for the specific language governing permissions
1N/A# and limitations under the License.
1N/A#
1N/A# When distributing Covered Code, include this CDDL HEADER in each
1N/A# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
1N/A# If applicable, add the following below this CDDL HEADER, with the
1N/A# fields enclosed by brackets "[]" replaced with your own identifying
1N/A# information: Portions Copyright [yyyy] [name of copyright owner]
1N/A#
1N/A# CDDL HEADER END
1N/A#
1N/A
1N/A#
1N/A# Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
1N/A#
1N/A
1N/A#
1N/A# Test {ip,tcp}:::{send,receive} of IPv4 TCP to local host.
1N/A#
1N/A# This may fail due to:
1N/A#
1N/A# 1. A change to the ip stack breaking expected probe behavior,
1N/A# which is the reason we are testing.
1N/A# 2. The lo0 interface missing or not up.
1N/A# 3. The local ssh service is not online.
1N/A# 4. An unlikely race causes the unlocked global send/receive
1N/A# variables to be corrupted.
1N/A#
1N/A# This test performs a TCP connection and checks that at least the
1N/A# following packet counts were traced:
1N/A#
1N/A# 3 x ip:::send (2 during the TCP handshake, then a FIN)
1N/A# 3 x tcp:::send (2 during the TCP handshake, then a FIN)
1N/A# 2 x ip:::receive (1 during the TCP handshake, then the FIN ACK)
1N/A# 2 x tcp:::receive (1 during the TCP handshake, then the FIN ACK)
1N/A
1N/A# The actual count tested is 5 each way, since we are tracing both
1N/A# source and destination events.
1N/A#
1N/A# For this test to work, we are assuming that the TCP handshake and
1N/A# TCP close will enter the IP code path and not use tcp fusion.
1N/A#
1N/A
1N/Aif (( $# != 1 )); then
1N/A print -u2 "expected one argument: <dtrace-path>"
1N/A exit 2
1N/Afi
1N/A
1N/Adtrace=$1
1N/Alocal=127.0.0.1
1N/Atcpport=22
1N/ADIR=/var/tmp/dtest.$$
1N/A
1N/Amkdir $DIR
1N/Acd $DIR
1N/A
1N/Acat > test.pl <<-EOPERL
1N/A use IO::Socket;
1N/A my \$s = IO::Socket::INET->new(
1N/A Proto => "tcp",
1N/A PeerAddr => "$local",
1N/A PeerPort => $tcpport,
Timeout => 3);
die "Could not connect to host $local port $tcpport" unless \$s;
close \$s;
EOPERL
$dtrace -c 'perl test.pl' -qs /dev/stdin <<EODTRACE
BEGIN
{
ipsend = tcpsend = ipreceive = tcpreceive = 0;
}
ip:::send
/args[2]->ip_saddr == "$local" && args[2]->ip_daddr == "$local" &&
args[4]->ipv4_protocol == IPPROTO_TCP/
{
ipsend++;
}
tcp:::send
/args[2]->ip_saddr == "$local" && args[2]->ip_daddr == "$local"/
{
tcpsend++;
}
ip:::receive
/args[2]->ip_saddr == "$local" && args[2]->ip_daddr == "$local" &&
args[4]->ipv4_protocol == IPPROTO_TCP/
{
ipreceive++;
}
tcp:::receive
/args[2]->ip_saddr == "$local" && args[2]->ip_daddr == "$local"/
{
tcpreceive++;
}
END
{
printf("Minimum TCP events seen\n\n");
printf("ip:::send - %s\n", ipsend >= 5 ? "yes" : "no");
printf("ip:::receive - %s\n", ipreceive >= 5 ? "yes" : "no");
printf("tcp:::send - %s\n", tcpsend >= 5 ? "yes" : "no");
printf("tcp:::receive - %s\n", tcpreceive >= 5 ? "yes" : "no");
}
EODTRACE
status=$?
cd /
/usr/bin/rm -rf $DIR
exit $status