1*10e6dadfSbrendan#!/usr/bin/ksh
2*10e6dadfSbrendan#
3*10e6dadfSbrendan# CDDL HEADER START
4*10e6dadfSbrendan#
5*10e6dadfSbrendan# The contents of this file are subject to the terms of the
6*10e6dadfSbrendan# Common Development and Distribution License (the "License").
7*10e6dadfSbrendan# You may not use this file except in compliance with the License.
8*10e6dadfSbrendan#
9*10e6dadfSbrendan# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*10e6dadfSbrendan# or http://www.opensolaris.org/os/licensing.
11*10e6dadfSbrendan# See the License for the specific language governing permissions
12*10e6dadfSbrendan# and limitations under the License.
13*10e6dadfSbrendan#
14*10e6dadfSbrendan# When distributing Covered Code, include this CDDL HEADER in each
15*10e6dadfSbrendan# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*10e6dadfSbrendan# If applicable, add the following below this CDDL HEADER, with the
17*10e6dadfSbrendan# fields enclosed by brackets "[]" replaced with your own identifying
18*10e6dadfSbrendan# information: Portions Copyright [yyyy] [name of copyright owner]
19*10e6dadfSbrendan#
20*10e6dadfSbrendan# CDDL HEADER END
21*10e6dadfSbrendan#
22*10e6dadfSbrendan
23*10e6dadfSbrendan#
24*10e6dadfSbrendan# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
25*10e6dadfSbrendan# Use is subject to license terms.
26*10e6dadfSbrendan#
27*10e6dadfSbrendan#pragma ident	"%Z%%M%	%I%	%E% SMI"
28*10e6dadfSbrendan
29*10e6dadfSbrendan#
30*10e6dadfSbrendan# Test ip:::{send,receive} of IPv6 ICMP to a local address.  This creates a
31*10e6dadfSbrendan# temporary lo0/inet6 interface if one doesn't already exist.
32*10e6dadfSbrendan#
33*10e6dadfSbrendan# This may fail due to:
34*10e6dadfSbrendan#
35*10e6dadfSbrendan# 1. A change to the ip stack breaking expected probe behavior,
36*10e6dadfSbrendan#    which is the reason we are testing.
37*10e6dadfSbrendan# 2. Unrelated ICMPv6 on lo0 traced by accident.
38*10e6dadfSbrendan#
39*10e6dadfSbrendan
40*10e6dadfSbrendanif (( $# != 1 )); then
41*10e6dadfSbrendan	print -u2 "expected one argument: <dtrace-path>"
42*10e6dadfSbrendan	exit 2
43*10e6dadfSbrendanfi
44*10e6dadfSbrendan
45*10e6dadfSbrendandtrace=$1
46*10e6dadfSbrendanlocal=::1
47*10e6dadfSbrendan
48*10e6dadfSbrendanif ! ifconfig lo0 inet6 > /dev/null 2>&1; then
49*10e6dadfSbrendan	if ! ifconfig lo0 inet6 plumb up; then
50*10e6dadfSbrendan		print -u2 "could not plumb lo0 inet6 for testing"
51*10e6dadfSbrendan		exit 3
52*10e6dadfSbrendan	fi
53*10e6dadfSbrendan	removeinet6=1
54*10e6dadfSbrendanelse
55*10e6dadfSbrendan	removeinet6=0
56*10e6dadfSbrendanfi
57*10e6dadfSbrendan
58*10e6dadfSbrendan$dtrace -c "/usr/sbin/ping -A inet6 $local 3" -qs /dev/stdin <<EOF | sort -n
59*10e6dadfSbrendanip:::send
60*10e6dadfSbrendan/args[2]->ip_saddr == "$local" && args[2]->ip_daddr == "$local" &&
61*10e6dadfSbrendan    args[5]->ipv6_nexthdr == IPPROTO_ICMPV6/
62*10e6dadfSbrendan{
63*10e6dadfSbrendan	printf("1 ip:::send    (");
64*10e6dadfSbrendan	printf("args[2]: %d %d, ", args[2]->ip_ver, args[2]->ip_plength);
65*10e6dadfSbrendan	printf("args[5]: %d %d %d)\n",
66*10e6dadfSbrendan	    args[5]->ipv6_ver, args[5]->ipv6_tclass, args[5]->ipv6_plen);
67*10e6dadfSbrendan}
68*10e6dadfSbrendan
69*10e6dadfSbrendanip:::receive
70*10e6dadfSbrendan/args[2]->ip_saddr == "$local" && args[2]->ip_daddr == "$local" &&
71*10e6dadfSbrendan    args[5]->ipv6_nexthdr == IPPROTO_ICMPV6/
72*10e6dadfSbrendan{
73*10e6dadfSbrendan	printf("2 ip:::receive (");
74*10e6dadfSbrendan	printf("args[2]: %d %d, ", args[2]->ip_ver, args[2]->ip_plength);
75*10e6dadfSbrendan	printf("args[5]: %d %d %d)\n",
76*10e6dadfSbrendan	    args[5]->ipv6_ver, args[5]->ipv6_tclass, args[5]->ipv6_plen);
77*10e6dadfSbrendan}
78*10e6dadfSbrendanEOF
79*10e6dadfSbrendan
80*10e6dadfSbrendanif (( removeinet6 )); then
81*10e6dadfSbrendan	ifconfig lo0 inet6 unplumb
82*10e6dadfSbrendanfi
83