1210753Srpaulo#!/usr/bin/ksh
2210753Srpaulo#
3210753Srpaulo# CDDL HEADER START
4210753Srpaulo#
5210753Srpaulo# The contents of this file are subject to the terms of the
6210753Srpaulo# Common Development and Distribution License (the "License").
7210753Srpaulo# You may not use this file except in compliance with the License.
8210753Srpaulo#
9210753Srpaulo# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10210753Srpaulo# or http://www.opensolaris.org/os/licensing.
11210753Srpaulo# See the License for the specific language governing permissions
12210753Srpaulo# and limitations under the License.
13210753Srpaulo#
14210753Srpaulo# When distributing Covered Code, include this CDDL HEADER in each
15210753Srpaulo# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16210753Srpaulo# If applicable, add the following below this CDDL HEADER, with the
17210753Srpaulo# fields enclosed by brackets "[]" replaced with your own identifying
18210753Srpaulo# information: Portions Copyright [yyyy] [name of copyright owner]
19210753Srpaulo#
20210753Srpaulo# CDDL HEADER END
21210753Srpaulo#
22210753Srpaulo
23210753Srpaulo#
24210753Srpaulo# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
25210753Srpaulo# Use is subject to license terms.
26210753Srpaulo#
27210753Srpaulo#pragma ident	"%Z%%M%	%I%	%E% SMI"
28210753Srpaulo
29210753Srpaulo#
30210753Srpaulo# Test ip:::{send,receive} of IPv4 ICMP to a remote host.
31210753Srpaulo#
32210753Srpaulo# This may fail due to:
33210753Srpaulo#
34210753Srpaulo# 1. A change to the ip stack breaking expected probe behavior,
35210753Srpaulo#    which is the reason we are testing.
36210753Srpaulo# 2. No physical network interface is plumbed and up.
37210753Srpaulo# 3. No other hosts on this subnet are reachable.
38210753Srpaulo# 4. An unrelated ICMP between these hosts was traced by accident.
39210753Srpaulo#
40210753Srpaulo
41210753Srpauloif (( $# != 1 )); then
42210753Srpaulo        print -u2 "expected one argument: <dtrace-path>"
43210753Srpaulo        exit 2
44210753Srpaulofi
45210753Srpaulo
46210753Srpaulodtrace=$1
47210753Srpaulogetaddr=./get.ipv4remote.pl
48210753Srpaulo
49210753Srpauloif [[ ! -x $getaddr ]]; then
50210753Srpaulo	print -u2 "could not find or execute sub program: $getaddr"
51210753Srpaulo	exit 3
52210753Srpaulofi
53210753Srpaulo$getaddr | read source dest
54210753Srpauloif (( $? != 0 )); then
55210753Srpaulo	exit 4
56210753Srpaulofi
57210753Srpaulo
58211545Srpaulo$dtrace -c "/sbin/ping $dest 3" -qs /dev/stdin <<EOF | \
59210753Srpaulo    grep -v 'is alive' | sort -n
60210753Srpauloip:::send
61210753Srpaulo/args[2]->ip_saddr == "$source" && args[2]->ip_daddr == "$dest" &&
62210753Srpaulo    args[4]->ipv4_protocol == IPPROTO_ICMP/
63210753Srpaulo{
64210753Srpaulo	printf("1 ip:::send    (");
65210753Srpaulo	printf("args[2]: %d %d, ", args[2]->ip_ver, args[2]->ip_plength);
66210753Srpaulo	printf("args[4]: %d %d %d %d %d)\n",
67210753Srpaulo	    args[4]->ipv4_ver, args[4]->ipv4_length, args[4]->ipv4_flags,
68210753Srpaulo	    args[4]->ipv4_offset, args[4]->ipv4_ttl);
69210753Srpaulo}
70210753Srpaulo
71210753Srpauloip:::receive
72210753Srpaulo/args[2]->ip_saddr == "$dest" && args[2]->ip_daddr == "$source" &&
73210753Srpaulo    args[4]->ipv4_protocol == IPPROTO_ICMP/
74210753Srpaulo{
75210753Srpaulo	printf("2 ip:::receive (");
76210753Srpaulo	printf("args[2]: %d %d, ", args[2]->ip_ver, args[2]->ip_plength);
77210753Srpaulo	printf("args[4]: %d %d %d %d %d)\n",
78210753Srpaulo	    args[4]->ipv4_ver, args[4]->ipv4_length, args[4]->ipv4_flags,
79210753Srpaulo	    args[4]->ipv4_offset, args[4]->ipv4_ttl);
80210753Srpaulo}
81210753SrpauloEOF
82