xref: /illumos-gate/usr/src/cmd/dtrace/test/tst/common/ip/tst.ipv6localicmp.ksh (revision 2983dda76a6d296fdb560c88114fe41caad1b84f)
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 2008 Sun Microsystems, Inc.  All rights reserved.
25# Use is subject to license terms.
26#
27#pragma ident	"%Z%%M%	%I%	%E% SMI"
28
29#
30# Test ip:::{send,receive} of IPv6 ICMP to a local address.  This creates a
31# temporary lo0/inet6 interface if one doesn't already exist.
32#
33# This may fail due to:
34#
35# 1. A change to the ip stack breaking expected probe behavior,
36#    which is the reason we are testing.
37# 2. Unrelated ICMPv6 on lo0 traced by accident.
38#
39
40if (( $# != 1 )); then
41	print -u2 "expected one argument: <dtrace-path>"
42	exit 2
43fi
44
45dtrace=$1
46local=::1
47
48if ! ifconfig lo0 inet6 > /dev/null 2>&1; then
49	if ! ifconfig lo0 inet6 plumb up; then
50		print -u2 "could not plumb lo0 inet6 for testing"
51		exit 3
52	fi
53	removeinet6=1
54else
55	removeinet6=0
56fi
57
58$dtrace -c "/usr/sbin/ping -A inet6 $local 3" -qs /dev/stdin <<EOF | sort -n
59ip:::send
60/args[2]->ip_saddr == "$local" && args[2]->ip_daddr == "$local" &&
61    args[5]->ipv6_nexthdr == IPPROTO_ICMPV6/
62{
63	printf("1 ip:::send    (");
64	printf("args[2]: %d %d, ", args[2]->ip_ver, args[2]->ip_plength);
65	printf("args[5]: %d %d %d)\n",
66	    args[5]->ipv6_ver, args[5]->ipv6_tclass, args[5]->ipv6_plen);
67}
68
69ip:::receive
70/args[2]->ip_saddr == "$local" && args[2]->ip_daddr == "$local" &&
71    args[5]->ipv6_nexthdr == IPPROTO_ICMPV6/
72{
73	printf("2 ip:::receive (");
74	printf("args[2]: %d %d, ", args[2]->ip_ver, args[2]->ip_plength);
75	printf("args[5]: %d %d %d)\n",
76	    args[5]->ipv6_ver, args[5]->ipv6_tclass, args[5]->ipv6_plen);
77}
78EOF
79
80if (( removeinet6 )); then
81	ifconfig lo0 inet6 unplumb
82fi
83