xref: /illumos-gate/usr/src/cmd/dtrace/test/tst/common/ip/tst.ipv4localtcp.ksh (revision 581cede61ac9c14d8d4ea452562a567189eead78)
1#!/usr/bin/ksh
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 2008 Sun Microsystems, Inc.  All rights reserved.
25# Use is subject to license terms.
26#
27#pragma ident	"%Z%%M%	%I%	%E% SMI"
28
29#
30# Test ip:::{send,receive} of IPv4 TCP to a remote host.
31#
32# This may fail due to:
33#
34# 1. A change to the ip stack breaking expected probe behavior,
35#    which is the reason we are testing.
36# 2. The lo0 interface missing or not up.
37# 3. The local ssh service is not online.
38# 4. An unlikely race causes the unlocked global send/receive
39#    variables to be corrupted.
40#
41# This test performs a TCP connection and checks that at least the
42# following packet counts were traced:
43#
44# 3 x ip:::send (2 during the TCP handshake, then a FIN)
45# 2 x ip:::receive (1 during the TCP handshake, then the FIN ACK)
46#
47# The actual count tested is 5 each way, since we are tracing both
48# source and destination events.
49#
50# For this test to work, we are assuming that the TCP handshake and
51# TCP close will enter the IP code path and not use tcp fusion.
52#
53
54if (( $# != 1 )); then
55	print -u2 "expected one argument: <dtrace-path>"
56	exit 2
57fi
58
59dtrace=$1
60local=127.0.0.1
61tcpport=22
62DIR=/var/tmp/dtest.$$
63
64mkdir $DIR
65cd $DIR
66
67cat > test.pl <<-EOPERL
68	use IO::Socket;
69	my \$s = IO::Socket::INET->new(
70	    Proto => "tcp",
71	    PeerAddr => "$local",
72	    PeerPort => $tcpport,
73	    Timeout => 3);
74	die "Could not connect to host $local port $tcpport" unless \$s;
75	close \$s;
76EOPERL
77
78$dtrace -c '/usr/bin/perl test.pl' -qs /dev/stdin <<EODTRACE
79BEGIN
80{
81	send = receive = 0;
82}
83
84ip:::send
85/args[2]->ip_saddr == "$local" && args[2]->ip_daddr == "$local" &&
86    args[4]->ipv4_protocol == IPPROTO_TCP/
87{
88	send++;
89}
90
91ip:::receive
92/args[2]->ip_saddr == "$local" && args[2]->ip_daddr == "$local" &&
93    args[4]->ipv4_protocol == IPPROTO_TCP/
94{
95	receive++;
96}
97
98END
99{
100	printf("Minimum TCP events seen\n\n");
101	printf("ip:::send - %s\n", send >= 5 ? "yes" : "no");
102	printf("ip:::receive - %s\n", receive >= 5 ? "yes" : "no");
103}
104EODTRACE
105
106status=$?
107
108cd /
109/usr/bin/rm -rf $DIR
110
111exit $status
112