xref: /illumos-gate/usr/src/cmd/dtrace/test/tst/common/ip/tst.ipv4remotetcp.ksh (revision 8c69cc8fbe729fa7b091e901c4b50508ccc6bb33)
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 (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
25#
26
27#
28# Test {tcp,ip}:::{send,receive} of IPv4 TCP to a remote host.
29#
30# This may fail due to:
31#
32# 1. A change to the ip stack breaking expected probe behavior,
33#    which is the reason we are testing.
34# 2. No physical network interface is plumbed and up.
35# 3. No other hosts on this subnet are reachable and listening on ssh.
36# 4. An unlikely race causes the unlocked global send/receive
37#    variables to be corrupted.
38#
39# This test performs a TCP connection and checks that at least the
40# following packet counts were traced:
41#
42# 3 x ip:::send (2 during the TCP handshake, then a FIN)
43# 3 x tcp:::send (2 during the TCP handshake, then a FIN)
44# 2 x ip:::receive (1 during the TCP handshake, then the FIN ACK)
45# 2 x tcp:::receive (1 during the TCP handshake, then the FIN ACK)
46#
47
48if (( $# != 1 )); then
49	print -u2 "expected one argument: <dtrace-path>"
50	exit 2
51fi
52
53dtrace=$1
54getaddr=./get.ipv4remote.pl
55tcpport=22
56DIR=/var/tmp/dtest.$$
57
58if [[ ! -x $getaddr ]]; then
59        print -u2 "could not find or execute sub program: $getaddr"
60        exit 3
61fi
62$getaddr $tcpport | read source dest
63if (( $? != 0 )); then
64        exit 4
65fi
66
67mkdir $DIR
68cd $DIR
69
70cat > test.pl <<-EOPERL
71	use IO::Socket;
72	my \$s = IO::Socket::INET->new(
73	    Proto => "tcp",
74	    PeerAddr => "$dest",
75	    PeerPort => $tcpport,
76	    Timeout => 3);
77	die "Could not connect to host $dest port $tcpport" unless \$s;
78	close \$s;
79EOPERL
80
81$dtrace -c 'perl test.pl' -qs /dev/stdin <<EODTRACE
82BEGIN
83{
84	ipsend = tcpsend = ipreceive = tcpreceive = 0;
85}
86
87ip:::send
88/args[2]->ip_saddr == "$source" && args[2]->ip_daddr == "$dest" &&
89    args[4]->ipv4_protocol == IPPROTO_TCP/
90{
91	ipsend++;
92}
93
94tcp:::send
95/args[2]->ip_saddr == "$source" && args[2]->ip_daddr == "$dest"/
96{
97	tcpsend++;
98}
99
100ip:::receive
101/args[2]->ip_saddr == "$dest" && args[2]->ip_daddr == "$source" &&
102    args[4]->ipv4_protocol == IPPROTO_TCP/
103{
104	ipreceive++;
105}
106
107tcp:::receive
108/args[2]->ip_saddr == "$dest" && args[2]->ip_daddr == "$source"/
109{
110	tcpreceive++;
111}
112
113END
114{
115	printf("Minimum TCP events seen\n\n");
116	printf("ip:::send - %s\n", ipsend >= 3 ? "yes" : "no");
117	printf("ip:::receive - %s\n", ipreceive >= 2 ? "yes" : "no");
118	printf("tcp:::send - %s\n", tcpsend >= 3 ? "yes" : "no");
119	printf("tcp:::receive - %s\n", tcpreceive >= 2 ? "yes" : "no");
120}
121EODTRACE
122
123status=$?
124
125cd /
126/usr/bin/rm -rf $DIR
127
128exit $?
129