xref: /onnv-gate/usr/src/cmd/dtrace/test/tst/common/ip/tst.ipv4localudp.ksh (revision 12507:501806a754d2)
16878Sbrendan#!/usr/bin/ksh
26878Sbrendan#
36878Sbrendan# CDDL HEADER START
46878Sbrendan#
56878Sbrendan# The contents of this file are subject to the terms of the
66878Sbrendan# Common Development and Distribution License (the "License").
76878Sbrendan# You may not use this file except in compliance with the License.
86878Sbrendan#
96878Sbrendan# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
106878Sbrendan# or http://www.opensolaris.org/os/licensing.
116878Sbrendan# See the License for the specific language governing permissions
126878Sbrendan# and limitations under the License.
136878Sbrendan#
146878Sbrendan# When distributing Covered Code, include this CDDL HEADER in each
156878Sbrendan# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
166878Sbrendan# If applicable, add the following below this CDDL HEADER, with the
176878Sbrendan# fields enclosed by brackets "[]" replaced with your own identifying
186878Sbrendan# information: Portions Copyright [yyyy] [name of copyright owner]
196878Sbrendan#
206878Sbrendan# CDDL HEADER END
216878Sbrendan#
226878Sbrendan
236878Sbrendan#
24*12507SAlan.Maguire@Sun.COM# Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
256878Sbrendan#
266878Sbrendan
276878Sbrendan#
286878Sbrendan# Test ip:::{send,receive} of IPv4 UDP to a local address.
296878Sbrendan#
306878Sbrendan# This may fail due to:
316878Sbrendan#
326878Sbrendan# 1. A change to the ip stack breaking expected probe behavior,
336878Sbrendan#    which is the reason we are testing.
346878Sbrendan# 2. No physical network interface is plumbed and up.
356878Sbrendan# 3. No other hosts on this subnet are reachable and listening on rpcbind.
366878Sbrendan# 4. An unlikely race causes the unlocked global send/receive
376878Sbrendan#    variables to be corrupted.
386878Sbrendan#
396878Sbrendan# This test sends a UDP message using ping and checks that at least the
406878Sbrendan# following counts were traced:
416878Sbrendan#
426878Sbrendan# 1 x ip:::send (UDP sent to ping's base UDP port)
43*12507SAlan.Maguire@Sun.COM# 1 x udp:::send (UDP sent to ping's base UDP port)
446878Sbrendan# 1 x ip:::receive (UDP received)
456878Sbrendan#
46*12507SAlan.Maguire@Sun.COM# No udp:::receive event is expected as the response ping -U elicits is
47*12507SAlan.Maguire@Sun.COM# an ICMP PORT_UNREACHABLE response rather than a UDP packet, and locally
48*12507SAlan.Maguire@Sun.COM# the echo request UDP packet only reaches IP, so the udp:::receive probe
49*12507SAlan.Maguire@Sun.COM# is not triggered by it.
50*12507SAlan.Maguire@Sun.COM#
516878Sbrendan
526878Sbrendanif (( $# != 1 )); then
536878Sbrendan	print -u2 "expected one argument: <dtrace-path>"
546878Sbrendan	exit 2
556878Sbrendanfi
566878Sbrendan
576878Sbrendandtrace=$1
586878Sbrendanlocal=127.0.0.1
596878Sbrendan
606878Sbrendan$dtrace -c "/usr/sbin/ping -U $local" -qs /dev/stdin <<EOF | grep -v 'is alive'
616878SbrendanBEGIN
626878Sbrendan{
63*12507SAlan.Maguire@Sun.COM	ipsend = udpsend = ipreceive = 0;
646878Sbrendan}
656878Sbrendan
666878Sbrendanip:::send
676878Sbrendan/args[2]->ip_saddr == "$local" && args[2]->ip_daddr == "$local" &&
686878Sbrendan    args[4]->ipv4_protocol == IPPROTO_UDP/
696878Sbrendan{
70*12507SAlan.Maguire@Sun.COM	ipsend++;
71*12507SAlan.Maguire@Sun.COM}
72*12507SAlan.Maguire@Sun.COM
73*12507SAlan.Maguire@Sun.COMudp:::send
74*12507SAlan.Maguire@Sun.COM/args[2]->ip_saddr == "$local" && args[2]->ip_daddr == "$local"/
75*12507SAlan.Maguire@Sun.COM{
76*12507SAlan.Maguire@Sun.COM	udpsend++;
776878Sbrendan}
786878Sbrendan
796878Sbrendanip:::receive
806878Sbrendan/args[2]->ip_saddr == "$local" && args[2]->ip_daddr == "$local" &&
816878Sbrendan    args[4]->ipv4_protocol == IPPROTO_UDP/
826878Sbrendan{
83*12507SAlan.Maguire@Sun.COM	ipreceive++;
846878Sbrendan}
856878Sbrendan
866878SbrendanEND
876878Sbrendan{
886878Sbrendan	printf("Minimum UDP events seen\n\n");
89*12507SAlan.Maguire@Sun.COM	printf("ip:::send - %s\n", ipsend >= 1 ? "yes" : "no");
90*12507SAlan.Maguire@Sun.COM	printf("ip:::receive - %s\n", ipreceive >= 1 ? "yes" : "no");
91*12507SAlan.Maguire@Sun.COM	printf("udp:::send - %s\n", udpsend >= 1 ? "yes" : "no");
926878Sbrendan}
936878SbrendanEOF
94