Commits

brendan  committed 360e73e

PSARC 2008/302 DTrace IP Provider
6640019 DTrace IP Provider
6655707 sdt arguments are off-by-one past the 5th
6667364 /usr/demo/dtrace/index.html: URLs to dtrace guide chapters wrong

  • Participants
  • Parent commits 4caf76f

Comments (0)

Files changed (50)

File deleted_files/usr/src/lib/libdtrace/common/net.d

+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#pragma ident	"%Z%%M%	%I%	%E% SMI"
+
+/*
+ * The conninfo_t structure should be used by all application protocal
+ * providers as the first arguments to indicate some basic information
+ * about the connection. This structure may be augmented to accomodate
+ * the particularities of additional protocols in the future.
+ */
+typedef struct conninfo {
+	string ci_local;	/* local host address */
+	string ci_remote;	/* remote host address */
+	string ci_protocol;	/* protocol (ipv4, ipv6, etc) */
+} conninfo_t;

File usr/src/cmd/dtrace/demo/Makefile

 	iosnoop.d \
 	iothrough.d \
 	iotime.d \
+	ipio.d \
+	ipproto.d \
 	iprb.d \
 	kstat.d \
 	ksyms.d \

File usr/src/cmd/dtrace/demo/chapters

 name: book
 title: Solaris Dynamic Tracing Guide
-number: 0
-url: http://docs.sun.com/db/doc/817-6223?a=view
+index: 0
+url: http://wikis.sun.com/display/DTrace/Documentation
 
 name: act
 title: Actions and Subroutines
-number: 10
-url: http://docs.sun.com/db/doc/817-6223?a=view
+index: 10
+url: http://wikis.sun.com/display/DTrace/Actions+and+Subroutines
 
 name: agg
 title: Aggregations
-number: 9
-url: http://docs.sun.com/db/doc/817-6223?a=view
+index: 9
+url: http://wikis.sun.com/display/DTrace/Aggregations
 
 name: anon
 title: Anonymous Tracing
-number: 34
-url: http://docs.sun.com/db/doc/817-6223?a=view
+index: 34
+url: http://wikis.sun.com/display/DTrace/Anonymous+Tracing
 
 name: buf
 title: Buffers and Buffering
-number: 11
-url: http://docs.sun.com/db/doc/817-6223?a=view
+index: 11
+url: http://wikis.sun.com/display/DTrace/Buffers+and+Buffering
 
 name: dtrace
 title: dtrace Provider
-number: 17
-url: http://docs.sun.com/db/doc/817-6223?a=view
+index: 17
+url: http://wikis.sun.com/display/DTrace/dtrace+Provider
 
 name: fbt
 title: fbt Provider
-number: 20
-url: http://docs.sun.com/db/doc/817-6223?a=view
+index: 20
+url: http://wikis.sun.com/display/DTrace/fbt+Provider
 
 name: intro
 title: Introduction
-number: 1
-url: http://docs.sun.com/db/doc/817-6223?a=view
+index: 1
+url: http://wikis.sun.com/display/DTrace/Introduction
 
 name: io
 title: io Provider
-number: 27
-url: http://docs.sun.com/db/doc/817-6223?a=view
+index: 27
+url: http://wikis.sun.com/display/DTrace/io+Provider
 
 name: lockstat
 title: lockstat Provider
-number: 18
-url: http://docs.sun.com/db/doc/817-6223?a=view
+index: 18
+url: http://wikis.sun.com/display/DTrace/lockstat+Provider
 
 name: out
 title: Output Formatting
-number: 12
-url: http://docs.sun.com/db/doc/817-6223?a=view
+index: 12
+url: http://wikis.sun.com/display/DTrace/Output+Formatting
 
 name: proc
 title: proc Provider
-number: 25
-url: http://docs.sun.com/db/doc/817-6223?a=view
+index: 25
+url: http://wikis.sun.com/display/DTrace/proc+Provider
 
 name: profile
 title: profile Provider
-number: 19
-url: http://docs.sun.com/db/doc/817-6223?a=view
+index: 19
+url: http://wikis.sun.com/display/DTrace/profile+Provider
 
 name: sched
 title: sched Provider
-number: 26
-url: http://docs.sun.com/db/doc/817-6223?a=view
+index: 26
+url: http://wikis.sun.com/display/DTrace/sched+Provider
 
 name: script
 title: Scripting
-number: 15
-url: http://docs.sun.com/db/doc/817-6223?a=view
+index: 15
+url: http://wikis.sun.com/display/DTrace/Scripting
 
 name: sdt
 title: sdt Provider
-number: 22
-url: http://docs.sun.com/db/doc/817-6223?a=view
+index: 22
+url: http://wikis.sun.com/display/DTrace/sdt+Provider
 
 name: spec
 title: Speculative Tracing
-number: 13
-url: http://docs.sun.com/db/doc/817-6223?a=view
+index: 13
+url: http://wikis.sun.com/display/DTrace/Speculative+Tracing
 
 name: struct
 title: Structs and Unions
-number: 7
-url: http://docs.sun.com/db/doc/817-6223?a=view
+index: 7
+url: http://wikis.sun.com/display/DTrace/Structs+and+Unions
 
 name: sysinfo
 title: sysinfo Provider
-number: 23
-url: http://docs.sun.com/db/doc/817-6223?a=view
+index: 23
+url: http://wikis.sun.com/display/DTrace/sysinfo+Provider
 
 name: user
 title: User Process Tracing
-number: 32
-url: http://docs.sun.com/db/doc/817-6223?a=view
+index: 32
+url: http://wikis.sun.com/display/DTrace/User+Process+Tracing
 
 name: vars
 title: Variables
-number: 3
-url: http://docs.sun.com/db/doc/817-6223?a=view
+index: 3
+url: http://wikis.sun.com/display/DTrace/Variables
 
 name: vminfo
 title: vminfo Provider
-number: 24
-url: http://docs.sun.com/db/doc/817-6223?a=view
+index: 24
+url: http://wikis.sun.com/display/DTrace/vminfo+Provider
 
+name: ip
+title: ip Provider
+index: 101
+url: http://wikis.sun.com/display/DTrace/ip+Provider
+

File usr/src/cmd/dtrace/demo/ip/ipio.d

+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+/*
+ * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#pragma D option quiet
+#pragma D option switchrate=10hz
+
+dtrace:::BEGIN
+{
+	printf(" %3s %10s %15s    %15s %8s %6s\n", "CPU", "DELTA(us)",
+	    "SOURCE", "DEST", "INT", "BYTES");
+	last = timestamp;
+}
+
+ip:::send
+{
+	this->elapsed = (timestamp - last) / 1000;
+	printf(" %3d %10d %15s -> %15s %8s %6d\n", cpu, this->elapsed,
+	    args[2]->ip_saddr, args[2]->ip_daddr, args[3]->if_name,
+	    args[2]->ip_plength);
+	last = timestamp;
+}
+
+ip:::receive
+{
+	this->elapsed = (timestamp - last) / 1000;
+	printf(" %3d %10d %15s <- %15s %8s %6d\n", cpu, this->elapsed,
+	    args[2]->ip_daddr, args[2]->ip_saddr, args[3]->if_name,
+	    args[2]->ip_plength);
+	last = timestamp;
+}

File usr/src/cmd/dtrace/demo/ip/ipproto.d

+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+/*
+ * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#pragma D option quiet
+
+dtrace:::BEGIN
+{
+	printf("Tracing... Hit Ctrl-C to end.\n");
+}
+
+ip:::send,
+ip:::receive
+{
+	this->protostr = args[2]->ip_ver == 4 ?
+	    args[4]->ipv4_protostr : args[5]->ipv6_nextstr;
+	@num[args[2]->ip_saddr, args[2]->ip_daddr, this->protostr] = count();
+}
+
+dtrace:::END
+{
+	printf("   %-28s %-28s %6s %8s\n", "SADDR", "DADDR", "PROTO", "COUNT");
+	printa("   %-28s %-28s %6s %@8d\n", @num);
+}

File usr/src/cmd/dtrace/demo/mkdemo.pl

 # CDDL HEADER END
 #
 #
-# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
 # Use is subject to license terms.
 #
 # ident	"%Z%%M%	%I%	%E% SMI"
 }	
 
 sub chaps_ascending {
-	$chaps{$a}{number} <=> $chaps{$b}{number};
+	$chaps{$a}{index} <=> $chaps{$b}{index};
 }
 
 sub demo_process {
 			print OUT <<EOF;
  *
  * This D script is used as an example in the Solaris Dynamic Tracing Guide
- * in Chapter $chaps{$chap}{number}, \"$chaps{$chap}{title}\".
+ * wiki in the \"$chaps{$chap}{title}\" Chapter.
  *
- * The full text of Chapter $chaps{$chap}{number} may be found here:
+ * The full text of the this chapter may be found here:
  *
  *   $chaps{$chap}{url}
  *
 EOF
 		}
 	}
+
+	close (DEMO);
+	close (OUT);
 }
 
 sub demo_find {
 		print HTML "<tr>\n";
 		print HTML "<td align=left>";
 		print HTML "<a href=\"$chaps{$chap}{url}\">";
-		print HTML "Chapter $chaps{$chap}{number}: ";
 		print HTML "$chaps{$chap}{title}</a></td>\n";
 
 		print HTML "<td><table border=0>\n";

File usr/src/cmd/dtrace/test/tst/Makefile.com

 
 TSTS :sh= find . -name tst.*.d -o -name err.*.d -o \
 	-name tst.*.d.out -o -name err.*.d.out -o -name tst.*.ksh \
-	-o -name err.*.ksh -o -name tst.*.ksh.out -o -name drp.*.d
+	-o -name err.*.ksh -o -name tst.*.ksh.out -o -name drp.*.d \
+	-o -name get.*.pl
 
-EXES :sh= find . -name SCCS -prune -o -name *.exe -print | cut -b3-
+EXES :sh= find . -name SCCS -prune -o \( -name *.exe -o -name \*.pl \) -print \
+    | cut -b3-
 EXES += $(CSRCS:%.c=%.exe)
 EXES += $(SSRCS:%.s=%.exe)
 

File usr/src/cmd/dtrace/test/tst/common/ip/get.ipv4remote.pl

+#!/usr/bin/perl -w
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+#pragma ident	"%Z%%M%	%I%	%E% SMI"
+
+#
+# get.ipv4remote.pl [tcpport]
+#
+# Find an IPv4 reachable remote host using both ifconfig(1M) and ping(1M).
+# If a tcpport is specified, return a host that is also listening on this
+# TCP port.  Print the local address and the remote address, or an
+# error message if no suitable remote host was found.  Exit status is 0 if
+# a host was found.
+#
+
+use strict;
+use IO::Socket;
+
+my $MAXHOSTS = 32;			# max hosts to port scan
+my $TIMEOUT = 3;			# connection timeout
+my $tcpport = @ARGV == 1 ? $ARGV[0] : 0;
+
+#
+# Determine local IP address
+#
+my $local = "";
+my $remote = "";
+my %Broadcast;
+my $up;
+open IFCONFIG, '/usr/sbin/ifconfig -a |' or die "Couldn't run ifconfig: $!\n";
+while (<IFCONFIG>) {
+	next if /^lo/;
+
+	# "UP" is always printed first (see print_flags() in ifconfig.c):
+	$up = 1 if /^[a-z].*<UP,/;
+	$up = 0 if /^[a-z].*<,/;
+
+	# assume output is "inet X ... broadcast Z":
+	if (/inet (\S+) .* broadcast (\S+)/) {
+		my ($addr, $bcast) = ($1, $2);
+		$Broadcast{$addr} = $bcast;
+		$local = $addr if $up and $local eq "";
+		$up = 0;
+	}
+}
+close IFCONFIG;
+die "Could not determine local IP address" if $local eq "";
+
+#
+# Find the first remote host that responds to an icmp echo,
+# which isn't a local address.
+#
+open PING, "/usr/sbin/ping -ns $Broadcast{$local} 56 $MAXHOSTS |" or
+    die "Couldn't run ping: $!\n";
+while (<PING>) {
+	if (/bytes from (.*): / and not defined $Broadcast{$1}) {
+		my $addr = $1;
+
+		if ($tcpport != 0) {
+			#
+			# Test TCP
+			#
+			my $socket = IO::Socket::INET->new(
+				Proto    => "tcp",
+				PeerAddr => $addr,
+				PeerPort => $tcpport,
+				Timeout  => $TIMEOUT,
+			);
+			next unless $socket;
+			close $socket;
+		}
+
+		$remote = $addr;
+		last;
+	}
+}
+close PING;
+die "Can't find a remote host for testing: No suitable response from " .
+    "$Broadcast{$local}\n" if $remote eq "";
+
+print "$local $remote\n";

File usr/src/cmd/dtrace/test/tst/common/ip/get.ipv6remote.pl

+#!/usr/bin/perl -w
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+#pragma ident	"%Z%%M%	%I%	%E% SMI"
+
+#
+# get.ipv6remote.pl
+#
+# Find an IPv6 reachable remote host using both ifconfig(1M) and ping(1M).
+# Print the local address and the remote address, or print nothing if either
+# no IPv6 interfaces or remote hosts were found.  (Remote IPv6 testing is
+# considered optional, and so not finding another IPv6 host is not an error
+# state we need to log.)  Exit status is 0 if a host was found.
+#
+
+use strict;
+use IO::Socket;
+
+my $MAXHOSTS = 32;			# max hosts to scan
+my $TIMEOUT = 3;			# connection timeout
+my $MULTICAST = "FF02::1";		# IPv6 multicast address
+
+#
+# Determine local IP address
+#
+my $local = "";
+my $remote = "";
+my %Local;
+my $up;
+open IFCONFIG, '/usr/sbin/ifconfig -a inet6 |'
+    or die "Couldn't run ifconfig: $!\n";
+while (<IFCONFIG>) {
+	next if /^lo/;
+
+	# "UP" is always printed first (see print_flags() in ifconfig.c):
+	$up = 1 if /^[a-z].*<UP,/;
+	$up = 0 if /^[a-z].*<,/;
+
+	# assume output is "inet6 ...":
+	if (m:inet6 (\S+)/:) {
+		my $addr = $1;
+                $Local{$addr} = 1;
+                $local = $addr if $up and $local eq "";
+		$up = 0;
+	}
+}
+close IFCONFIG;
+exit 1 if $local eq "";
+
+#
+# Find the first remote host that responds to an icmp echo,
+# which isn't a local address.
+#
+open PING, "/usr/sbin/ping -ns -A inet6 $MULTICAST 56 $MAXHOSTS |" or
+    die "Couldn't run ping: $!\n";
+while (<PING>) {
+	if (/bytes from (.*): / and not defined $Local{$1}) {
+		$remote = $1;
+		last;
+	}
+}
+close PING;
+exit 2 if $remote eq "";
+
+print "$local $remote\n";

File usr/src/cmd/dtrace/test/tst/common/ip/tst.ipv4localicmp.ksh

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

File usr/src/cmd/dtrace/test/tst/common/ip/tst.ipv4localicmp.ksh.out

+
+1 ip:::send    (args[2]: 4 64, args[4]: 4 84 0 0 255)
+1 ip:::send    (args[2]: 4 64, args[4]: 4 84 0 0 255)
+2 ip:::receive (args[2]: 4 64, args[4]: 4 84 0 0 255)
+2 ip:::receive (args[2]: 4 64, args[4]: 4 84 0 0 255)
+127.0.0.1 is alive

File usr/src/cmd/dtrace/test/tst/common/ip/tst.ipv4localtcp.ksh

+#!/usr/bin/ksh
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+#pragma ident	"%Z%%M%	%I%	%E% SMI"
+
+#
+# Test ip:::{send,receive} of IPv4 TCP to a remote host.
+#
+# This may fail due to:
+#
+# 1. A change to the ip stack breaking expected probe behavior,
+#    which is the reason we are testing.
+# 2. The lo0 interface missing or not up.
+# 3. The local ssh service is not online.
+# 4. An unlikely race causes the unlocked global send/receive
+#    variables to be corrupted.
+#
+# This test performs a TCP connection and checks that at least the
+# following packet counts were traced:
+#
+# 3 x ip:::send (2 during the TCP handshake, then a FIN)
+# 2 x ip:::receive (1 during the TCP handshake, then the FIN ACK)
+#
+# The actual count tested is 5 each way, since we are tracing both
+# source and destination events.
+#
+# For this test to work, we are assuming that the TCP handshake and
+# TCP close will enter the IP code path and not use tcp fusion.
+#
+
+if (( $# != 1 )); then
+	print -u2 "expected one argument: <dtrace-path>"
+	exit 2
+fi
+
+dtrace=$1
+local=127.0.0.1
+tcpport=22
+DIR=/var/tmp/dtest.$$
+
+mkdir $DIR
+cd $DIR
+
+cat > test.pl <<-EOPERL
+	use IO::Socket;
+	my \$s = IO::Socket::INET->new(
+	    Proto => "tcp",
+	    PeerAddr => "$local",
+	    PeerPort => $tcpport,
+	    Timeout => 3);
+	die "Could not connect to host $local port $tcpport" unless \$s;
+	close \$s;
+EOPERL
+
+$dtrace -c '/usr/bin/perl test.pl' -qs /dev/stdin <<EODTRACE
+BEGIN
+{
+	send = receive = 0;
+}
+
+ip:::send
+/args[2]->ip_saddr == "$local" && args[2]->ip_daddr == "$local" &&
+    args[4]->ipv4_protocol == IPPROTO_TCP/
+{
+	send++;
+}
+
+ip:::receive
+/args[2]->ip_saddr == "$local" && args[2]->ip_daddr == "$local" &&
+    args[4]->ipv4_protocol == IPPROTO_TCP/
+{
+	receive++;
+}
+
+END
+{
+	printf("Minimum TCP events seen\n\n");
+	printf("ip:::send - %s\n", send >= 5 ? "yes" : "no");
+	printf("ip:::receive - %s\n", receive >= 5 ? "yes" : "no");
+}
+EODTRACE
+
+status=$?
+
+cd /
+/usr/bin/rm -rf $DIR
+
+exit $status

File usr/src/cmd/dtrace/test/tst/common/ip/tst.ipv4localtcp.ksh.out

+Minimum TCP events seen
+
+ip:::send - yes
+ip:::receive - yes
+

File usr/src/cmd/dtrace/test/tst/common/ip/tst.ipv4localudp.ksh

+#!/usr/bin/ksh
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+#pragma ident	"%Z%%M%	%I%	%E% SMI"
+
+#
+# Test ip:::{send,receive} of IPv4 UDP to a local address.
+#
+# This may fail due to:
+#
+# 1. A change to the ip stack breaking expected probe behavior,
+#    which is the reason we are testing.
+# 2. No physical network interface is plumbed and up.
+# 3. No other hosts on this subnet are reachable and listening on rpcbind.
+# 4. An unlikely race causes the unlocked global send/receive
+#    variables to be corrupted.
+#
+# This test sends a UDP message using ping and checks that at least the
+# following counts were traced:
+#
+# 1 x ip:::send (UDP sent to ping's base UDP port)
+# 1 x ip:::receive (UDP received)
+# 
+
+if (( $# != 1 )); then
+	print -u2 "expected one argument: <dtrace-path>"
+	exit 2
+fi
+
+dtrace=$1
+local=127.0.0.1
+
+$dtrace -c "/usr/sbin/ping -U $local" -qs /dev/stdin <<EOF | grep -v 'is alive'
+BEGIN
+{
+	send = receive = 0;
+}
+
+ip:::send
+/args[2]->ip_saddr == "$local" && args[2]->ip_daddr == "$local" &&
+    args[4]->ipv4_protocol == IPPROTO_UDP/
+{
+	send++;
+}
+
+ip:::receive
+/args[2]->ip_saddr == "$local" && args[2]->ip_daddr == "$local" &&
+    args[4]->ipv4_protocol == IPPROTO_UDP/
+{
+	receive++;
+}
+
+END
+{
+	printf("Minimum UDP events seen\n\n");
+	printf("ip:::send - %s\n", send >= 1 ? "yes" : "no");
+	printf("ip:::receive - %s\n", receive >= 1 ? "yes" : "no");
+}
+EOF

File usr/src/cmd/dtrace/test/tst/common/ip/tst.ipv4localudp.ksh.out

+Minimum UDP events seen
+
+ip:::send - yes
+ip:::receive - yes
+

File usr/src/cmd/dtrace/test/tst/common/ip/tst.ipv4remoteicmp.ksh

+#!/usr/bin/ksh
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+#pragma ident	"%Z%%M%	%I%	%E% SMI"
+
+#
+# Test ip:::{send,receive} of IPv4 ICMP to a remote host.
+#
+# This may fail due to:
+#
+# 1. A change to the ip stack breaking expected probe behavior,
+#    which is the reason we are testing.
+# 2. No physical network interface is plumbed and up.
+# 3. No other hosts on this subnet are reachable.
+# 4. An unrelated ICMP between these hosts was traced by accident.
+#
+
+if (( $# != 1 )); then
+        print -u2 "expected one argument: <dtrace-path>"
+        exit 2
+fi
+
+dtrace=$1
+getaddr=./get.ipv4remote.pl
+
+if [[ ! -x $getaddr ]]; then
+	print -u2 "could not find or execute sub program: $getaddr"
+	exit 3
+fi
+$getaddr | read source dest
+if (( $? != 0 )); then
+	exit 4
+fi
+
+$dtrace -c "/usr/sbin/ping $dest 3" -qs /dev/stdin <<EOF | \
+    grep -v 'is alive' | sort -n
+ip:::send
+/args[2]->ip_saddr == "$source" && args[2]->ip_daddr == "$dest" &&
+    args[4]->ipv4_protocol == IPPROTO_ICMP/
+{
+	printf("1 ip:::send    (");
+	printf("args[2]: %d %d, ", args[2]->ip_ver, args[2]->ip_plength);
+	printf("args[4]: %d %d %d %d %d)\n",
+	    args[4]->ipv4_ver, args[4]->ipv4_length, args[4]->ipv4_flags,
+	    args[4]->ipv4_offset, args[4]->ipv4_ttl);
+}
+
+ip:::receive
+/args[2]->ip_saddr == "$dest" && args[2]->ip_daddr == "$source" &&
+    args[4]->ipv4_protocol == IPPROTO_ICMP/
+{
+	printf("2 ip:::receive (");
+	printf("args[2]: %d %d, ", args[2]->ip_ver, args[2]->ip_plength);
+	printf("args[4]: %d %d %d %d %d)\n",
+	    args[4]->ipv4_ver, args[4]->ipv4_length, args[4]->ipv4_flags,
+	    args[4]->ipv4_offset, args[4]->ipv4_ttl);
+}
+EOF

File usr/src/cmd/dtrace/test/tst/common/ip/tst.ipv4remoteicmp.ksh.out

+
+1 ip:::send    (args[2]: 4 64, args[4]: 4 84 0 0 255)
+2 ip:::receive (args[2]: 4 64, args[4]: 4 84 4 0 255)

File usr/src/cmd/dtrace/test/tst/common/ip/tst.ipv4remotetcp.ksh

+#!/usr/bin/ksh
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+#pragma ident	"%Z%%M%	%I%	%E% SMI"
+
+#
+# Test ip:::{send,receive} of IPv4 TCP to a remote host.
+#
+# This may fail due to:
+#
+# 1. A change to the ip stack breaking expected probe behavior,
+#    which is the reason we are testing.
+# 2. No physical network interface is plumbed and up.
+# 3. No other hosts on this subnet are reachable and listening on ssh.
+# 4. An unlikely race causes the unlocked global send/receive
+#    variables to be corrupted.
+#
+# This test performs a TCP connection and checks that at least the
+# following packet counts were traced:
+#
+# 3 x ip:::send (2 during the TCP handshake, then a FIN)
+# 2 x ip:::receive (1 during the TCP handshake, then the FIN ACK)
+# 
+
+if (( $# != 1 )); then
+	print -u2 "expected one argument: <dtrace-path>"
+	exit 2
+fi
+
+dtrace=$1
+getaddr=./get.ipv4remote.pl
+tcpport=22
+DIR=/var/tmp/dtest.$$
+
+if [[ ! -x $getaddr ]]; then
+        print -u2 "could not find or execute sub program: $getaddr"
+        exit 3
+fi
+$getaddr $tcpport | read source dest
+if (( $? != 0 )); then
+        exit 4
+fi
+
+mkdir $DIR
+cd $DIR
+
+cat > test.pl <<-EOPERL
+	use IO::Socket;
+	my \$s = IO::Socket::INET->new(
+	    Proto => "tcp",
+	    PeerAddr => "$dest",
+	    PeerPort => $tcpport,
+	    Timeout => 3);
+	die "Could not connect to host $dest port $tcpport" unless \$s;
+	close \$s;
+EOPERL
+
+$dtrace -c '/usr/bin/perl test.pl' -qs /dev/stdin <<EODTRACE
+BEGIN
+{
+	send = receive = 0;
+}
+
+ip:::send
+/args[2]->ip_saddr == "$source" && args[2]->ip_daddr == "$dest" &&
+    args[4]->ipv4_protocol == IPPROTO_TCP/
+{
+	send++;
+}
+
+ip:::receive
+/args[2]->ip_saddr == "$dest" && args[2]->ip_daddr == "$source" &&
+    args[4]->ipv4_protocol == IPPROTO_TCP/
+{
+	receive++;
+}
+
+END
+{
+	printf("Minimum TCP events seen\n\n");
+	printf("ip:::send - %s\n", send >= 3 ? "yes" : "no");
+	printf("ip:::receive - %s\n", receive >= 2 ? "yes" : "no");
+}
+EODTRACE
+
+status=$?
+
+cd /
+/usr/bin/rm -rf $DIR
+
+exit $?

File usr/src/cmd/dtrace/test/tst/common/ip/tst.ipv4remotetcp.ksh.out

+Minimum TCP events seen
+
+ip:::send - yes
+ip:::receive - yes
+

File usr/src/cmd/dtrace/test/tst/common/ip/tst.ipv4remoteudp.ksh

+#!/usr/bin/ksh
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+#pragma ident	"%Z%%M%	%I%	%E% SMI"
+
+#
+# Test ip:::{send,receive} of IPv4 UDP to a remote host.
+#
+# This may fail due to:
+#
+# 1. A change to the ip stack breaking expected probe behavior,
+#    which is the reason we are testing.
+# 2. No physical network interface is plumbed and up.
+# 3. No other hosts on this subnet are reachable and listening on rpcbind.
+# 4. An unlikely race causes the unlocked global send/receive
+#    variables to be corrupted.
+#
+# This test sends a UDP message using ping and checks that at least the
+# following counts were traced:
+#
+# 1 x ip:::send (UDP sent to ping's base UDP port)
+# 
+
+if (( $# != 1 )); then
+	print -u2 "expected one argument: <dtrace-path>"
+	exit 2
+fi
+
+dtrace=$1
+getaddr=./get.ipv4remote.pl
+
+if [[ ! -x $getaddr ]]; then
+	print -u2 "could not find or execute sub program: $getaddr"
+	exit 3
+fi
+$getaddr | read source dest
+if (( $? != 0 )); then
+	exit 4
+fi
+
+$dtrace -c "/usr/sbin/ping -U $dest" -qs /dev/stdin <<EOF | grep -v 'is alive'
+BEGIN
+{
+	send = 0;
+}
+
+ip:::send
+/args[2]->ip_saddr == "$source" && args[2]->ip_daddr == "$dest" &&
+    args[4]->ipv4_protocol == IPPROTO_UDP/
+{
+	send++;
+}
+
+END
+{
+	printf("Minimum UDP events seen\n\n");
+	printf("ip:::send - %s\n", send >= 1 ? "yes" : "no");
+}
+EOF

File usr/src/cmd/dtrace/test/tst/common/ip/tst.ipv4remoteudp.ksh.out

+Minimum UDP events seen
+
+ip:::send - yes
+

File usr/src/cmd/dtrace/test/tst/common/ip/tst.ipv6localicmp.ksh

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

File usr/src/cmd/dtrace/test/tst/common/ip/tst.ipv6localicmp.ksh.out

+
+::1 is alive
+1 ip:::send    (args[2]: 6 64, args[5]: 6 0 64)
+1 ip:::send    (args[2]: 6 64, args[5]: 6 0 64)
+2 ip:::receive (args[2]: 6 64, args[5]: 6 0 64)
+2 ip:::receive (args[2]: 6 64, args[5]: 6 0 64)

File usr/src/cmd/dtrace/test/tst/common/ip/tst.ipv6remoteicmp.ksh

+#!/usr/bin/ksh
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+#pragma ident	"%Z%%M%	%I%	%E% SMI"
+
+#
+# Test ip:::{send,receive} of IPv6 ICMP to a remote host.  This test is
+# skipped if there are no physical interfaces configured with IPv6, or no
+# other IPv6 hosts are reachable.
+#
+# This may fail due to:
+#
+# 1. A change to the ip stack breaking expected probe behavior,
+#    which is the reason we are testing.
+# 2. An unrelated ICMPv6 between these hosts was traced by accident.
+#
+
+if (( $# != 1 )); then
+	print -u2 "expected one argument: <dtrace-path>"
+	exit 2
+fi
+
+dtrace=$1
+getaddr=./get.ipv6remote.pl
+
+if [[ ! -x $getaddr ]]; then
+	print -u2 "could not find or execute sub program: $getaddr"
+	exit 3
+fi
+$getaddr | read source dest
+if (( $? != 0 )); then
+	print -nu2 "Could not find a local IPv6 interface and a remote IPv6 "
+	print -u2 "host.  Aborting test.\n"
+	print -nu2 "For this test to continue, a \"ping -ns -A inet6 FF02::1\" "
+	print -u2 "must respond with a\nremote IPv6 host."
+	exit 3
+fi
+
+#
+# Shake loose any ICMPv6 Neighbor advertisement messages before tracing.
+#
+/usr/sbin/ping $dest 3 > /dev/null 2>&1
+
+$dtrace -c "/usr/sbin/ping $dest 3" -qs /dev/stdin <<EOF | \
+    grep -v 'is alive' | sort -n
+ip:::send
+/args[2]->ip_saddr == "$source" && args[2]->ip_daddr == "$dest" &&
+    args[5]->ipv6_nexthdr == IPPROTO_ICMPV6/
+{
+	printf("1 ip:::send    (");
+	printf("args[2]: %d %d, ", args[2]->ip_ver, args[2]->ip_plength);
+	printf("args[5]: %d %d %d)\n",
+	    args[5]->ipv6_ver, args[5]->ipv6_tclass, args[5]->ipv6_plen);
+}
+
+ip:::receive
+/args[2]->ip_saddr == "$dest" && args[2]->ip_daddr == "$source" &&
+    args[5]->ipv6_nexthdr == IPPROTO_ICMPV6/
+{
+	printf("2 ip:::receive (");
+	printf("args[2]: %d %d, ", args[2]->ip_ver, args[2]->ip_plength);
+	printf("args[5]: %d %d %d)\n",
+	    args[5]->ipv6_ver, args[5]->ipv6_tclass, args[5]->ipv6_plen);
+}
+EOF

File usr/src/cmd/dtrace/test/tst/common/ip/tst.ipv6remoteicmp.ksh.out

+
+1 ip:::send    (args[2]: 6 64, args[5]: 6 0 64)
+2 ip:::receive (args[2]: 6 64, args[5]: 6 0 64)

File usr/src/cmd/dtrace/test/tst/common/sdt/tst.sdtargs.c

+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#pragma ident	"%Z%%M%	%I%	%E% SMI"
+
+#include <unistd.h>
+#include <sys/uadmin.h>
+
+int
+main(int argc, char **argv)
+{
+	while (1) {
+		if (uadmin(A_SDTTEST, 0, 0) < 0) {
+			perror("uadmin");
+			return (1);
+		}
+
+		sleep(1);
+	}
+
+	return (0);
+}

File usr/src/cmd/dtrace/test/tst/common/sdt/tst.sdtargs.d

+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#pragma ident	"%Z%%M%	%I%	%E% SMI"
+
+/*
+ * ASSERTION: Verify that argN (1..7) variables are properly remapped.
+ */
+
+BEGIN
+{
+	/* Timeout after 5 seconds */
+	timeout = timestamp + 5000000000;
+	ignore = $1;
+}
+
+sdt:::test
+/arg0 != 1 || arg1 != 2 || arg2 != 3 || arg3 != 4 || arg4 != 5 || arg5 != 6 ||
+    arg6 != 7/
+{
+	printf("sdt arg mismatch\n\n");
+	printf("args are  : %d, %d, %d, %d, %d, %d, %d\n", arg0, arg1, arg2,
+	    arg3, arg4, arg5, arg6);
+	printf("should be : 1, 2, 3, 4, 5, 6, 7\n");
+	exit(1);
+}
+
+sdt:::test
+{
+	exit(0);
+}
+
+profile:::tick-1
+/timestamp > timeout/
+{
+	trace("test timed out");
+	exit(1);
+}

File usr/src/lib/libdtrace/Makefile.com

 # CDDL HEADER END
 #
 #
-# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
 # Use is subject to license terms.
 #
 # ident	"%Z%%M%	%I%	%E% SMI"
 CLEANFILES += ../common/procfs.sed ../common/procfs.d
 CLEANFILES += ../common/io.sed ../common/io.d
 CLEANFILES += ../common/ip.sed ../common/ip.d
+CLEANFILES += ../common/net.sed ../common/net.d
 CLEANFILES += ../common/errno.d ../common/signal.d
 CLEANFILES += ../common/dt_errtags.c ../common/dt_names.c
 CLEANFILES += ../common/sysevent.sed ../common/sysevent.d
 ../common/ip.d: ../common/ip.sed ../common/ip.d.in
 	sed -f ../common/ip.sed < ../common/ip.d.in > $@
 
+../common/net.d: ../common/net.sed ../common/net.d.in
+	sed -f ../common/net.sed < ../common/net.d.in > $@
+
 ../common/sysevent.d: ../common/sysevent.sed ../common/sysevent.d.in
 	sed -f ../common/sysevent.sed < ../common/sysevent.d.in > $@
 

File usr/src/lib/libdtrace/common/ip.d.in

 
 #pragma ident	"%Z%%M%	%I%	%E% SMI"
 
-inline int AF_INET = @AF_INET@;
-#pragma D binding "1.0" AF_INET
-inline int AF_INET6 = @AF_INET6@;
-#pragma D binding "1.0" AF_INET6
+#pragma D depends_on module ip
+#pragma D depends_on provider ip
+
+inline int IPH_DF = @IPH_DF@;
+#pragma D binding "1.0" IPH_DF
+inline int IPH_MF = @IPH_MF@;
+#pragma D binding "1.0" IPH_MF
+
+#pragma D binding "1.0" IPPROTO_IP
+inline int IPPROTO_IP = @IPPROTO_IP@;
+#pragma D binding "1.0" IPPROTO_HOPOPTS
+inline int IPPROTO_HOPOPTS = @IPPROTO_HOPOPTS@;
+#pragma D binding "1.0" IPPROTO_ICMP
+inline int IPPROTO_ICMP = @IPPROTO_ICMP@;
+#pragma D binding "1.0" IPPROTO_IGMP
+inline int IPPROTO_IGMP = @IPPROTO_IGMP@;
+#pragma D binding "1.0" IPPROTO_GGP
+inline int IPPROTO_GGP = @IPPROTO_GGP@;
+#pragma D binding "1.0" IPPROTO_ENCAP
+inline int IPPROTO_ENCAP = @IPPROTO_ENCAP@;
+#pragma D binding "1.0" IPPROTO_TCP
+inline int IPPROTO_TCP = @IPPROTO_TCP@;
+#pragma D binding "1.0" IPPROTO_EGP
+inline int IPPROTO_EGP = @IPPROTO_EGP@;
+#pragma D binding "1.0" IPPROTO_PUP
+inline int IPPROTO_PUP = @IPPROTO_PUP@;
+#pragma D binding "1.0" IPPROTO_UDP
+inline int IPPROTO_UDP = @IPPROTO_UDP@;
+#pragma D binding "1.0" IPPROTO_IDP
+inline int IPPROTO_IDP = @IPPROTO_IDP@;
+#pragma D binding "1.0" IPPROTO_IPV6
+inline int IPPROTO_IPV6 = @IPPROTO_IPV6@;
+#pragma D binding "1.0" IPPROTO_ROUTING
+inline int IPPROTO_ROUTING = @IPPROTO_ROUTING@;
+#pragma D binding "1.0" IPPROTO_FRAGMENT
+inline int IPPROTO_FRAGMENT = @IPPROTO_FRAGMENT@;
+#pragma D binding "1.0" IPPROTO_RSVP
+inline int IPPROTO_RSVP = @IPPROTO_RSVP@;
+#pragma D binding "1.0" IPPROTO_ESP
+inline int IPPROTO_ESP = @IPPROTO_ESP@;
+#pragma D binding "1.0" IPPROTO_AH
+inline int IPPROTO_AH = @IPPROTO_AH@;
+#pragma D binding "1.0" IPPROTO_ICMPV6
+inline int IPPROTO_ICMPV6 = @IPPROTO_ICMPV6@;
+#pragma D binding "1.0" IPPROTO_NONE
+inline int IPPROTO_NONE = @IPPROTO_NONE@;
+#pragma D binding "1.0" IPPROTO_DSTOPTS
+inline int IPPROTO_DSTOPTS = @IPPROTO_DSTOPTS@;
+#pragma D binding "1.0" IPPROTO_HELLO
+inline int IPPROTO_HELLO = @IPPROTO_HELLO@;
+#pragma D binding "1.0" IPPROTO_ND
+inline int IPPROTO_ND = @IPPROTO_ND@;
+#pragma D binding "1.0" IPPROTO_EON
+inline int IPPROTO_EON = @IPPROTO_EON@;
+#pragma D binding "1.0" IPPROTO_OSPF
+inline int IPPROTO_OSPF = @IPPROTO_OSPF@;
+#pragma D binding "1.0" IPPROTO_PIM
+inline int IPPROTO_PIM = @IPPROTO_PIM@;
+#pragma D binding "1.0" IPPROTO_SCTP
+inline int IPPROTO_SCTP = @IPPROTO_SCTP@;
+#pragma D binding "1.0" IPPROTO_RAW
+inline int IPPROTO_RAW = @IPPROTO_RAW@;
+#pragma D binding "1.0" IPPROTO_MAX
+inline int IPPROTO_MAX = @IPPROTO_MAX@;
+
+/*
+ * pktinfo is where packet ID info can be made available for deeper
+ * analysis if packet IDs become supported by the kernel in the future.
+ * The pkt_addr member is currently always NULL.
+ */
+typedef struct pktinfo {
+	uintptr_t pkt_addr;
+} pktinfo_t;
+
+/*
+ * csinfo is where connection state info can be made available if
+ * connection IDs become supported by the kernel in the future.
+ * The cs_addr member is currently always NULL.
+ */
+typedef struct csinfo {
+	uintptr_t cs_addr;
+} csinfo_t;
+
+/*
+ * ipinfo contains common IP info for both IPv4 and IPv6.
+ */
+typedef struct ipinfo {
+	uint8_t ip_ver;			/* IP version (4, 6) */
+	uint32_t ip_plength;		/* payload length */
+	string ip_saddr;		/* source address */
+	string ip_daddr;		/* destination address */
+} ipinfo_t;
+
+/*
+ * ifinfo contains network interface info.
+ */
+typedef struct ifinfo {
+	string if_name;			/* interface name */
+	int8_t if_local;		/* is delivered locally */
+	netstackid_t if_ipstack;	/* ipstack ID */
+	uintptr_t if_addr;		/* pointer to raw ill_t */
+} ifinfo_t;
+
+/*
+ * ipv4info is a translated version of the IPv4 header (with raw pointer).
+ * These values are NULL if the packet is not IPv4.
+ */
+typedef struct ipv4info {
+	uint8_t ipv4_ver;		/* IP version (4) */
+	uint8_t ipv4_ihl;		/* header length, bytes */
+	uint8_t ipv4_tos;		/* type of service field */
+	uint16_t ipv4_length;		/* length (header + payload) */
+	uint16_t ipv4_ident;		/* identification */
+	uint8_t ipv4_flags;		/* IP flags */
+	uint16_t ipv4_offset;		/* fragment offset */
+	uint8_t ipv4_ttl;		/* time to live */
+	uint8_t ipv4_protocol;		/* next level protocol */
+	string ipv4_protostr;		/* next level protocol, as a string */
+	uint16_t ipv4_checksum;		/* header checksum */
+	ipaddr_t ipv4_src;		/* source address */
+	ipaddr_t ipv4_dst;		/* destination address */
+	string ipv4_saddr;		/* source address, string */
+	string ipv4_daddr;		/* destination address, string */
+	ipha_t *ipv4_hdr;		/* pointer to raw header */
+} ipv4info_t;
+
+/*
+ * ipv6info is a translated version of the IPv6 header (with raw pointer).
+ * These values are NULL if the packet is not IPv6.
+ */
+typedef struct ipv6info {
+	uint8_t ipv6_ver;		/* IP version (6) */
+	uint8_t ipv6_tclass;		/* traffic class */
+	uint32_t ipv6_flow;		/* flow label */
+	uint16_t ipv6_plen;		/* payload length */
+	uint8_t ipv6_nexthdr;		/* next header protocol */
+	string ipv6_nextstr;		/* next header protocol, as a string */
+	uint8_t ipv6_hlim;		/* hop limit */
+	in6_addr_t *ipv6_src;		/* source address */
+	in6_addr_t *ipv6_dst;		/* destination address */
+	string ipv6_saddr;		/* source address, string */
+	string ipv6_daddr;		/* destination address, string */
+	ip6_t *ipv6_hdr;		/* pointer to raw header */
+} ipv6info_t;
+
+/*
+ * void_ip_t is a void pointer to either an IPv4 or IPv6 header.  It has
+ * its own type name so that a translator can be determined.
+ */
+typedef uintptr_t void_ip_t;
+
+/*
+ * __dtrace_ipsr_ill_t is used by the translator to take an ill_t plus an
+ * additional arg6 from the ip:::send and ip:::recieve probes, and translate
+ * them to an ifinfo_t.
+ */
+typedef ill_t __dtrace_ipsr_ill_t;
+
+#pragma D binding "1.0" translator
+translator pktinfo_t < mblk_t *M > {
+	pkt_addr = NULL;
+};
+
+#pragma D binding "1.0" translator
+translator csinfo_t < conn_t *C > {
+	cs_addr = NULL;
+};
+
+#pragma D binding "1.0" translator
+translator ipinfo_t < ipha_t *I > {
+	ip_ver = I->ipha_version_and_hdr_length >> 4;
+	ip_plength = ntohs(I->ipha_length) -
+	    ((I->ipha_version_and_hdr_length & 0xf) << 2);
+	ip_saddr = inet_ntoa(&I->ipha_src);
+	ip_daddr = inet_ntoa(&I->ipha_dst);
+};
+
+#pragma D binding "1.0" translator
+translator ipinfo_t < ip6_t *I > {
+	ip_ver = *(uint8_t *)I >> 4;
+	ip_plength = ntohs(I->ip6_ctlun.ip6_un1.ip6_un1_plen);
+	ip_saddr = inet_ntoa6(&I->ip6_src);
+	ip_daddr = inet_ntoa6(&I->ip6_dst);
+};
+
+#pragma D binding "1.0" translator
+translator ipinfo_t < void_ip_t *I > {
+	ip_ver = I != NULL ? *(uint8_t *)I >> 4 : 0;
+	ip_plength = I != NULL ? (*(uint8_t *)I >> 4 == 4 ?
+	    ntohs(((ipha_t *)I)->ipha_length) -
+	    ((((ipha_t *)I)->ipha_version_and_hdr_length & 0xf) << 2) :
+	    *(uint8_t *)I >> 4 == 6 ?
+	    ntohs(((ip6_t *)I)->ip6_ctlun.ip6_un1.ip6_un1_plen) : 0) : 0;
+	ip_saddr = I != NULL ? (*(uint8_t *)I >> 4 == 4 ?
+	    inet_ntoa(&((ipha_t *)I)->ipha_src) : *(uint8_t *)I >> 4 == 6 ?
+	    inet_ntoa6(&((ip6_t *)I)->ip6_src) : "<unknown>") : "<unknown>";
+	ip_daddr = I != NULL ? (*(uint8_t *)I >> 4 == 4 ?
+	    inet_ntoa(&((ipha_t *)I)->ipha_dst) : *(uint8_t *)I >> 4 == 6 ?
+	    inet_ntoa6(&((ip6_t *)I)->ip6_dst) : "<unknown>") : "<unknown>";
+};
+
+#pragma D binding "1.0" translator
+translator ifinfo_t < __dtrace_ipsr_ill_t *I > {
+	if_name = I != NULL ? stringof(I->ill_name) : "<null>";
+	if_ipstack = I != NULL ? I->ill_ipst->ips_netstack->netstack_stackid
+	    : 0;
+	if_local = arg6;		/* probe dependent */
+	if_addr = (uintptr_t)I;
+};
+
+#pragma D binding "1.0" translator
+translator ipv4info_t < ipha_t *I > {
+	ipv4_ver = I != NULL ? I->ipha_version_and_hdr_length >> 4 : 0;
+	ipv4_ihl = I != NULL ? (I->ipha_version_and_hdr_length & 0xf) << 2 : 0;
+	ipv4_tos = I != NULL ? I->ipha_type_of_service : 0;
+	ipv4_length = I != NULL ? ntohs(I->ipha_length) : 0;
+	ipv4_ident = I != NULL ? ntohs(I->ipha_ident) : 0;
+	ipv4_flags = I != NULL ? ntohs(I->ipha_fragment_offset_and_flags) >>
+	    12 : 0;
+	ipv4_offset = I != NULL ? ntohs(I->ipha_fragment_offset_and_flags) &
+	    0x0fff : 0;
+	ipv4_ttl = I != NULL ? I->ipha_ttl : 0;
+	ipv4_protocol = I != NULL ? I->ipha_protocol : 0;
+	ipv4_protostr = I == NULL ? "<null>" :
+	    I->ipha_protocol == IPPROTO_TCP     ? "TCP"    :
+	    I->ipha_protocol == IPPROTO_UDP     ? "UDP"    :
+	    I->ipha_protocol == IPPROTO_IP      ? "IP"     :
+	    I->ipha_protocol == IPPROTO_ICMP    ? "ICMP"   :
+	    I->ipha_protocol == IPPROTO_IGMP    ? "IGMP"   :
+	    I->ipha_protocol == IPPROTO_EGP     ? "EGP"    :
+	    I->ipha_protocol == IPPROTO_IPV6    ? "IPv6"   :
+	    I->ipha_protocol == IPPROTO_ROUTING ? "ROUTE"  :
+	    I->ipha_protocol == IPPROTO_ESP     ? "ESP"    :
+	    I->ipha_protocol == IPPROTO_AH      ? "AH"     :
+	    I->ipha_protocol == IPPROTO_ICMPV6  ? "ICMPv6" :
+	    I->ipha_protocol == IPPROTO_OSPF    ? "OSPF"   :
+	    I->ipha_protocol == IPPROTO_SCTP    ? "SCTP"   :
+	    I->ipha_protocol == IPPROTO_RAW     ? "RAW"    :
+	    lltostr((uint64_t)I->ipha_protocol);
+	ipv4_checksum = I != NULL ? ntohs(I->ipha_hdr_checksum) : 0;
+	ipv4_src = I != NULL ? I->ipha_src : 0;
+	ipv4_dst = I != NULL ? I->ipha_dst : 0;
+	ipv4_saddr = I != NULL ? inet_ntoa(&I->ipha_src) : "<null>";
+	ipv4_daddr = I != NULL ? inet_ntoa(&I->ipha_dst) : "<null>";
+	ipv4_hdr = I;
+};
+
+#pragma D binding "1.0" translator
+translator ipv6info_t < ip6_t *I > {
+	ipv6_ver = I != NULL ? I->ip6_ctlun.ip6_un2_vfc >> 4 : 0;
+	ipv6_tclass = I != NULL ? ((I->ip6_ctlun.ip6_un1.ip6_un1_flow &&
+	    0x0fffffff) >> 20) : 0;
+	ipv6_flow = I != NULL ? I->ip6_ctlun.ip6_un1.ip6_un1_flow &&
+	    0x000fffff : 0;
+	ipv6_plen = I != NULL ? ntohs(I->ip6_ctlun.ip6_un1.ip6_un1_plen) : 0;
+	ipv6_nexthdr = I != NULL ? I->ip6_ctlun.ip6_un1.ip6_un1_nxt : 0;
+	ipv6_nextstr = I == NULL ? "<null>" :
+	    I->ip6_ctlun.ip6_un1.ip6_un1_nxt == IPPROTO_TCP     ? "TCP"    :
+	    I->ip6_ctlun.ip6_un1.ip6_un1_nxt == IPPROTO_UDP     ? "UDP"    :
+	    I->ip6_ctlun.ip6_un1.ip6_un1_nxt == IPPROTO_IP      ? "IP"     :
+	    I->ip6_ctlun.ip6_un1.ip6_un1_nxt == IPPROTO_ICMP    ? "ICMP"   :
+	    I->ip6_ctlun.ip6_un1.ip6_un1_nxt == IPPROTO_IGMP    ? "IGMP"   :
+	    I->ip6_ctlun.ip6_un1.ip6_un1_nxt == IPPROTO_EGP     ? "EGP"    :
+	    I->ip6_ctlun.ip6_un1.ip6_un1_nxt == IPPROTO_IPV6    ? "IPv6"   :
+	    I->ip6_ctlun.ip6_un1.ip6_un1_nxt == IPPROTO_ROUTING ? "ROUTE"  :
+	    I->ip6_ctlun.ip6_un1.ip6_un1_nxt == IPPROTO_ESP     ? "ESP"    :
+	    I->ip6_ctlun.ip6_un1.ip6_un1_nxt == IPPROTO_AH      ? "AH"     :
+	    I->ip6_ctlun.ip6_un1.ip6_un1_nxt == IPPROTO_ICMPV6  ? "ICMPv6" :
+	    I->ip6_ctlun.ip6_un1.ip6_un1_nxt == IPPROTO_OSPF    ? "OSPF"   :
+	    I->ip6_ctlun.ip6_un1.ip6_un1_nxt == IPPROTO_SCTP    ? "SCTP"   :
+	    I->ip6_ctlun.ip6_un1.ip6_un1_nxt == IPPROTO_RAW     ? "RAW"    :
+	    lltostr((uint64_t)I->ip6_ctlun.ip6_un1.ip6_un1_nxt);
+	ipv6_hlim = I != NULL ? I->ip6_ctlun.ip6_un1.ip6_un1_hlim : 0;
+	ipv6_src = I != NULL ? &I->ip6_src : 0;
+	ipv6_dst = I != NULL ? &I->ip6_dst : 0;
+	ipv6_saddr = I != NULL ? inet_ntoa6(&I->ip6_src) : "<null>";
+	ipv6_daddr = I != NULL ? inet_ntoa6(&I->ip6_dst) : "<null>";
+	ipv6_hdr = I;
+};

File usr/src/lib/libdtrace/common/ip.sed.in

  */
 
 #include <sys/socket.h>
+#include <netinet/in.h>
+#include <inet/ip.h>
 
 #define	SED_REPLACE(x)	s/#x/x/g
 
 SED_REPLACE(AF_INET)
 SED_REPLACE(AF_INET6)
+
+SED_REPLACE(IPH_DF)
+SED_REPLACE(IPH_MF)
+
+SED_REPLACE(IPPROTO_IP)
+SED_REPLACE(IPPROTO_HOPOPTS)
+SED_REPLACE(IPPROTO_ICMP)
+SED_REPLACE(IPPROTO_IGMP)
+SED_REPLACE(IPPROTO_GGP)
+SED_REPLACE(IPPROTO_ENCAP)
+SED_REPLACE(IPPROTO_TCP)
+SED_REPLACE(IPPROTO_EGP)
+SED_REPLACE(IPPROTO_PUP)
+SED_REPLACE(IPPROTO_UDP)
+SED_REPLACE(IPPROTO_IDP)
+SED_REPLACE(IPPROTO_IPV6)
+SED_REPLACE(IPPROTO_ROUTING)
+SED_REPLACE(IPPROTO_FRAGMENT)
+SED_REPLACE(IPPROTO_RSVP)
+SED_REPLACE(IPPROTO_ESP)
+SED_REPLACE(IPPROTO_AH)
+SED_REPLACE(IPPROTO_ICMPV6)