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 IPv6 ICMP to a remote host.  This test is
31210753Srpaulo# skipped if there are no physical interfaces configured with IPv6, or no
32210753Srpaulo# other IPv6 hosts are reachable.
33210753Srpaulo#
34210753Srpaulo# This may fail due to:
35210753Srpaulo#
36210753Srpaulo# 1. A change to the ip stack breaking expected probe behavior,
37210753Srpaulo#    which is the reason we are testing.
38210753Srpaulo# 2. An unrelated ICMPv6 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.ipv6remote.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	print -nu2 "Could not find a local IPv6 interface and a remote IPv6 "
56210753Srpaulo	print -u2 "host.  Aborting test.\n"
57210753Srpaulo	print -nu2 "For this test to continue, a \"ping -ns -A inet6 FF02::1\" "
58210753Srpaulo	print -u2 "must respond with a\nremote IPv6 host."
59210753Srpaulo	exit 3
60210753Srpaulofi
61210753Srpaulo
62210753Srpaulo#
63210753Srpaulo# Shake loose any ICMPv6 Neighbor advertisement messages before tracing.
64210753Srpaulo#
65211545Srpaulo/sbin/ping $dest 3 > /dev/null 2>&1
66210753Srpaulo
67211545Srpaulo$dtrace -c "/sbin/ping $dest 3" -qs /dev/stdin <<EOF | \
68210753Srpaulo    grep -v 'is alive' | sort -n
69210753Srpauloip:::send
70210753Srpaulo/args[2]->ip_saddr == "$source" && args[2]->ip_daddr == "$dest" &&
71210753Srpaulo    args[5]->ipv6_nexthdr == IPPROTO_ICMPV6/
72210753Srpaulo{
73210753Srpaulo	printf("1 ip:::send    (");
74210753Srpaulo	printf("args[2]: %d %d, ", args[2]->ip_ver, args[2]->ip_plength);
75210753Srpaulo	printf("args[5]: %d %d %d)\n",
76210753Srpaulo	    args[5]->ipv6_ver, args[5]->ipv6_tclass, args[5]->ipv6_plen);
77210753Srpaulo}
78210753Srpaulo
79210753Srpauloip:::receive
80210753Srpaulo/args[2]->ip_saddr == "$dest" && args[2]->ip_daddr == "$source" &&
81210753Srpaulo    args[5]->ipv6_nexthdr == IPPROTO_ICMPV6/
82210753Srpaulo{
83210753Srpaulo	printf("2 ip:::receive (");
84210753Srpaulo	printf("args[2]: %d %d, ", args[2]->ip_ver, args[2]->ip_plength);
85210753Srpaulo	printf("args[5]: %d %d %d)\n",
86210753Srpaulo	    args[5]->ipv6_ver, args[5]->ipv6_tclass, args[5]->ipv6_plen);
87210753Srpaulo}
88210753SrpauloEOF
89