xref: /illumos-gate/usr/src/cmd/dtrace/test/tst/common/ip/tst.ipv4localudp.ksh (revision 2bbdd445a21f9d61f4a0ca0faf05d5ceb2bd91f3)
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 (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
25#
26
27#
28# Test ip:::{send,receive} of IPv4 UDP to a local address.
29#
30# This may fail due to:
31#
32# 1. A change to the ip stack breaking expected probe behavior,
33#    which is the reason we are testing.
34# 2. No physical network interface is plumbed and up.
35# 3. No other hosts on this subnet are reachable and listening on rpcbind.
36# 4. An unlikely race causes the unlocked global send/receive
37#    variables to be corrupted.
38#
39# This test sends a UDP message using ping and checks that at least the
40# following counts were traced:
41#
42# 1 x ip:::send (UDP sent to ping's base UDP port)
43# 1 x udp:::send (UDP sent to ping's base UDP port)
44# 1 x ip:::receive (UDP received)
45#
46# No udp:::receive event is expected as the response ping -U elicits is
47# an ICMP PORT_UNREACHABLE response rather than a UDP packet, and locally
48# the echo request UDP packet only reaches IP, so the udp:::receive probe
49# is not triggered by it.
50#
51
52if (( $# != 1 )); then
53	print -u2 "expected one argument: <dtrace-path>"
54	exit 2
55fi
56
57dtrace=$1
58local=127.0.0.1
59
60$dtrace -c "/usr/sbin/ping -U $local" -qs /dev/stdin <<EOF | grep -v 'is alive'
61BEGIN
62{
63	ipsend = udpsend = ipreceive = 0;
64}
65
66ip:::send
67/args[2]->ip_saddr == "$local" && args[2]->ip_daddr == "$local" &&
68    args[4]->ipv4_protocol == IPPROTO_UDP/
69{
70	ipsend++;
71}
72
73udp:::send
74/args[2]->ip_saddr == "$local" && args[2]->ip_daddr == "$local"/
75{
76	udpsend++;
77}
78
79ip:::receive
80/args[2]->ip_saddr == "$local" && args[2]->ip_daddr == "$local" &&
81    args[4]->ipv4_protocol == IPPROTO_UDP/
82{
83	ipreceive++;
84}
85
86END
87{
88	printf("Minimum UDP events seen\n\n");
89	printf("ip:::send - %s\n", ipsend >= 1 ? "yes" : "no");
90	printf("ip:::receive - %s\n", ipreceive >= 1 ? "yes" : "no");
91	printf("udp:::send - %s\n", udpsend >= 1 ? "yes" : "no");
92}
93EOF
94