14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#!/usr/bin/ksh
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync# CDDL HEADER START
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync# The contents of this file are subject to the terms of the
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync# Common Development and Distribution License (the "License").
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync# You may not use this file except in compliance with the License.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync# or http://www.opensolaris.org/os/licensing.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync# See the License for the specific language governing permissions
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync# and limitations under the License.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync# When distributing Covered Code, include this CDDL HEADER in each
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync# If applicable, add the following below this CDDL HEADER, with the
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync# fields enclosed by brackets "[]" replaced with your own identifying
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync# information: Portions Copyright [yyyy] [name of copyright owner]
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync# CDDL HEADER END
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync# Copyright 2008 Sun Microsystems, Inc. All rights reserved.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync# Use is subject to license terms.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#pragma ident "%Z%%M% %I% %E% SMI"
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync# Test ip:::{send,receive} of IPv6 ICMP to a local address. This creates a
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync# temporary lo0/inet6 interface if one doesn't already exist.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync# This may fail due to:
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync# 1. A change to the ip stack breaking expected probe behavior,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync# which is the reason we are testing.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync# 2. Unrelated ICMPv6 on lo0 traced by accident.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncif (( $# != 1 )); then
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync print -u2 "expected one argument: <dtrace-path>"
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync exit 2
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncfi
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncdtrace=$1
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsynclocal=::1
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncif ! ifconfig lo0 inet6 > /dev/null 2>&1; then
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if ! ifconfig lo0 inet6 plumb up; then
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync print -u2 "could not plumb lo0 inet6 for testing"
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync exit 3
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync fi
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync removeinet6=1
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncelse
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync removeinet6=0
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncfi
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync$dtrace -c "/usr/sbin/ping -A inet6 $local 3" -qs /dev/stdin <<EOF | sort -n
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncip:::send
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/args[2]->ip_saddr == "$local" && args[2]->ip_daddr == "$local" &&
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync args[5]->ipv6_nexthdr == IPPROTO_ICMPV6/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync printf("1 ip:::send (");
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync printf("args[2]: %d %d, ", args[2]->ip_ver, args[2]->ip_plength);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync printf("args[5]: %d %d %d)\n",
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync args[5]->ipv6_ver, args[5]->ipv6_tclass, args[5]->ipv6_plen);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync}
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncip:::receive
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/args[2]->ip_saddr == "$local" && args[2]->ip_daddr == "$local" &&
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync args[5]->ipv6_nexthdr == IPPROTO_ICMPV6/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync printf("2 ip:::receive (");
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync printf("args[2]: %d %d, ", args[2]->ip_ver, args[2]->ip_plength);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync printf("args[5]: %d %d %d)\n",
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync args[5]->ipv6_ver, args[5]->ipv6_tclass, args[5]->ipv6_plen);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync}
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncEOF
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncif (( removeinet6 )); then
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync ifconfig lo0 inet6 unplumb
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncfi