1210753Srpaulo#!/usr/bin/ksh 2210753Srpaulo# 3210753Srpaulo# CDDL HEADER START 4210753Srpaulo# 5210753Srpaulo# The contents of this file are subject to the terms of the 6210753Srpaulo# Common Development and Distribution License (the "License"). 7210753Srpaulo# You may not use this file except in compliance with the License. 8210753Srpaulo# 9210753Srpaulo# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10210753Srpaulo# or http://www.opensolaris.org/os/licensing. 11210753Srpaulo# See the License for the specific language governing permissions 12210753Srpaulo# and limitations under the License. 13210753Srpaulo# 14210753Srpaulo# When distributing Covered Code, include this CDDL HEADER in each 15210753Srpaulo# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16210753Srpaulo# If applicable, add the following below this CDDL HEADER, with the 17210753Srpaulo# fields enclosed by brackets "[]" replaced with your own identifying 18210753Srpaulo# information: Portions Copyright [yyyy] [name of copyright owner] 19210753Srpaulo# 20210753Srpaulo# CDDL HEADER END 21210753Srpaulo# 22210753Srpaulo 23210753Srpaulo# 24210753Srpaulo# Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. 25210753Srpaulo# 26210753Srpaulo 27210753Srpaulo# 28210753Srpaulo# Test ip:::{send,receive} of IPv4 UDP to a local address. 29210753Srpaulo# 30210753Srpaulo# This may fail due to: 31210753Srpaulo# 32210753Srpaulo# 1. A change to the ip stack breaking expected probe behavior, 33210753Srpaulo# which is the reason we are testing. 34210753Srpaulo# 2. No physical network interface is plumbed and up. 35210753Srpaulo# 3. No other hosts on this subnet are reachable and listening on rpcbind. 36210753Srpaulo# 4. An unlikely race causes the unlocked global send/receive 37210753Srpaulo# variables to be corrupted. 38210753Srpaulo# 39210753Srpaulo# This test sends a UDP message using ping and checks that at least the 40210753Srpaulo# following counts were traced: 41210753Srpaulo# 42210753Srpaulo# 1 x ip:::send (UDP sent to ping's base UDP port) 43210753Srpaulo# 1 x udp:::send (UDP sent to ping's base UDP port) 44210753Srpaulo# 1 x ip:::receive (UDP received) 45210753Srpaulo# 46210753Srpaulo# No udp:::receive event is expected as the response ping -U elicits is 47210753Srpaulo# an ICMP PORT_UNREACHABLE response rather than a UDP packet, and locally 48210753Srpaulo# the echo request UDP packet only reaches IP, so the udp:::receive probe 49210753Srpaulo# is not triggered by it. 50210753Srpaulo# 51210753Srpaulo 52210753Srpauloif (( $# != 1 )); then 53210753Srpaulo print -u2 "expected one argument: <dtrace-path>" 54210753Srpaulo exit 2 55210753Srpaulofi 56210753Srpaulo 57210753Srpaulodtrace=$1 58210753Srpaulolocal=127.0.0.1 59210753Srpaulo 60211545Srpaulo$dtrace -c "/sbin/ping -U $local" -qs /dev/stdin <<EOF | grep -v 'is alive' 61210753SrpauloBEGIN 62210753Srpaulo{ 63210753Srpaulo ipsend = udpsend = ipreceive = 0; 64210753Srpaulo} 65210753Srpaulo 66210753Srpauloip:::send 67210753Srpaulo/args[2]->ip_saddr == "$local" && args[2]->ip_daddr == "$local" && 68210753Srpaulo args[4]->ipv4_protocol == IPPROTO_UDP/ 69210753Srpaulo{ 70210753Srpaulo ipsend++; 71210753Srpaulo} 72210753Srpaulo 73210753Srpauloudp:::send 74210753Srpaulo/args[2]->ip_saddr == "$local" && args[2]->ip_daddr == "$local"/ 75210753Srpaulo{ 76210753Srpaulo udpsend++; 77210753Srpaulo} 78210753Srpaulo 79210753Srpauloip:::receive 80210753Srpaulo/args[2]->ip_saddr == "$local" && args[2]->ip_daddr == "$local" && 81210753Srpaulo args[4]->ipv4_protocol == IPPROTO_UDP/ 82210753Srpaulo{ 83210753Srpaulo ipreceive++; 84210753Srpaulo} 85210753Srpaulo 86210753SrpauloEND 87210753Srpaulo{ 88210753Srpaulo printf("Minimum UDP events seen\n\n"); 89210753Srpaulo printf("ip:::send - %s\n", ipsend >= 1 ? "yes" : "no"); 90210753Srpaulo printf("ip:::receive - %s\n", ipreceive >= 1 ? "yes" : "no"); 91210753Srpaulo printf("udp:::send - %s\n", udpsend >= 1 ? "yes" : "no"); 92210753Srpaulo} 93210753SrpauloEOF 94