110e6dadfSbrendan#!/usr/bin/ksh 210e6dadfSbrendan# 310e6dadfSbrendan# CDDL HEADER START 410e6dadfSbrendan# 510e6dadfSbrendan# The contents of this file are subject to the terms of the 610e6dadfSbrendan# Common Development and Distribution License (the "License"). 710e6dadfSbrendan# You may not use this file except in compliance with the License. 810e6dadfSbrendan# 910e6dadfSbrendan# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 1010e6dadfSbrendan# or http://www.opensolaris.org/os/licensing. 1110e6dadfSbrendan# See the License for the specific language governing permissions 1210e6dadfSbrendan# and limitations under the License. 1310e6dadfSbrendan# 1410e6dadfSbrendan# When distributing Covered Code, include this CDDL HEADER in each 1510e6dadfSbrendan# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 1610e6dadfSbrendan# If applicable, add the following below this CDDL HEADER, with the 1710e6dadfSbrendan# fields enclosed by brackets "[]" replaced with your own identifying 1810e6dadfSbrendan# information: Portions Copyright [yyyy] [name of copyright owner] 1910e6dadfSbrendan# 2010e6dadfSbrendan# CDDL HEADER END 2110e6dadfSbrendan# 2210e6dadfSbrendan 2310e6dadfSbrendan# 24*9cd928feSAlan Maguire# Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. 2510e6dadfSbrendan# 2610e6dadfSbrendan 2710e6dadfSbrendan# 2810e6dadfSbrendan# Test ip:::{send,receive} of IPv4 UDP to a local address. 2910e6dadfSbrendan# 3010e6dadfSbrendan# This may fail due to: 3110e6dadfSbrendan# 3210e6dadfSbrendan# 1. A change to the ip stack breaking expected probe behavior, 3310e6dadfSbrendan# which is the reason we are testing. 3410e6dadfSbrendan# 2. No physical network interface is plumbed and up. 3510e6dadfSbrendan# 3. No other hosts on this subnet are reachable and listening on rpcbind. 3610e6dadfSbrendan# 4. An unlikely race causes the unlocked global send/receive 3710e6dadfSbrendan# variables to be corrupted. 3810e6dadfSbrendan# 3910e6dadfSbrendan# This test sends a UDP message using ping and checks that at least the 4010e6dadfSbrendan# following counts were traced: 4110e6dadfSbrendan# 4210e6dadfSbrendan# 1 x ip:::send (UDP sent to ping's base UDP port) 43*9cd928feSAlan Maguire# 1 x udp:::send (UDP sent to ping's base UDP port) 4410e6dadfSbrendan# 1 x ip:::receive (UDP received) 4510e6dadfSbrendan# 46*9cd928feSAlan Maguire# No udp:::receive event is expected as the response ping -U elicits is 47*9cd928feSAlan Maguire# an ICMP PORT_UNREACHABLE response rather than a UDP packet, and locally 48*9cd928feSAlan Maguire# the echo request UDP packet only reaches IP, so the udp:::receive probe 49*9cd928feSAlan Maguire# is not triggered by it. 50*9cd928feSAlan Maguire# 5110e6dadfSbrendan 5210e6dadfSbrendanif (( $# != 1 )); then 5310e6dadfSbrendan print -u2 "expected one argument: <dtrace-path>" 5410e6dadfSbrendan exit 2 5510e6dadfSbrendanfi 5610e6dadfSbrendan 5710e6dadfSbrendandtrace=$1 5810e6dadfSbrendanlocal=127.0.0.1 5910e6dadfSbrendan 6010e6dadfSbrendan$dtrace -c "/usr/sbin/ping -U $local" -qs /dev/stdin <<EOF | grep -v 'is alive' 6110e6dadfSbrendanBEGIN 6210e6dadfSbrendan{ 63*9cd928feSAlan Maguire ipsend = udpsend = ipreceive = 0; 6410e6dadfSbrendan} 6510e6dadfSbrendan 6610e6dadfSbrendanip:::send 6710e6dadfSbrendan/args[2]->ip_saddr == "$local" && args[2]->ip_daddr == "$local" && 6810e6dadfSbrendan args[4]->ipv4_protocol == IPPROTO_UDP/ 6910e6dadfSbrendan{ 70*9cd928feSAlan Maguire ipsend++; 71*9cd928feSAlan Maguire} 72*9cd928feSAlan Maguire 73*9cd928feSAlan Maguireudp:::send 74*9cd928feSAlan Maguire/args[2]->ip_saddr == "$local" && args[2]->ip_daddr == "$local"/ 75*9cd928feSAlan Maguire{ 76*9cd928feSAlan Maguire udpsend++; 7710e6dadfSbrendan} 7810e6dadfSbrendan 7910e6dadfSbrendanip:::receive 8010e6dadfSbrendan/args[2]->ip_saddr == "$local" && args[2]->ip_daddr == "$local" && 8110e6dadfSbrendan args[4]->ipv4_protocol == IPPROTO_UDP/ 8210e6dadfSbrendan{ 83*9cd928feSAlan Maguire ipreceive++; 8410e6dadfSbrendan} 8510e6dadfSbrendan 8610e6dadfSbrendanEND 8710e6dadfSbrendan{ 8810e6dadfSbrendan printf("Minimum UDP events seen\n\n"); 89*9cd928feSAlan Maguire printf("ip:::send - %s\n", ipsend >= 1 ? "yes" : "no"); 90*9cd928feSAlan Maguire printf("ip:::receive - %s\n", ipreceive >= 1 ? "yes" : "no"); 91*9cd928feSAlan Maguire printf("udp:::send - %s\n", udpsend >= 1 ? "yes" : "no"); 9210e6dadfSbrendan} 9310e6dadfSbrendanEOF 94