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