xref: /freebsd/share/man/man4/dtrace_udp.4 (revision 02e9120893770924227138ba49df1edb3896112a)
1.\" Copyright (c) 2015 Mark Johnston <markj@FreeBSD.org>
2.\" All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\"    notice, this list of conditions and the following disclaimer.
9.\" 2. Redistributions in binary form must reproduce the above copyright
10.\"    notice, this list of conditions and the following disclaimer in the
11.\"    documentation and/or other materials provided with the distribution.
12.\"
13.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23.\" SUCH DAMAGE.
24.\"
25.Dd August 1, 2018
26.Dt DTRACE_UDP 4
27.Os
28.Sh NAME
29.Nm dtrace_udp
30.Nd a DTrace provider for tracing events related to the UDP protocol
31.Sh SYNOPSIS
32.Fn udp:::receive "pktinfo_t *" "csinfo_t *" "ipinfo_t *" "udpsinfo_t *" \
33    "udpinfo_t *"
34.Fn udp:::send "pktinfo_t *" "csinfo_t *" "ipinfo_t *" "udpsinfo_t *" \
35    "udpinfo_t *"
36.Sh DESCRIPTION
37The DTrace
38.Nm udp
39provider allows users to trace events in the
40.Xr udp 4
41protocol implementation.
42The
43.Fn udp:::send
44probe fires whenever the kernel prepares to transmit a UDP packet, and the
45.Fn udp:::receive
46probe fires whenever the kernel receives a UDP packet, unless
47the UDP header is incomplete,
48the destination port is 0,
49the length field is invalid,
50or the checksum is wrong.
51The arguments to these probes can be used to obtain detailed information about
52the IP and UDP headers of the corresponding packet.
53.Sh ARGUMENTS
54The
55.Vt pktinfo_t
56argument is currently unimplemented and is included for compatibility with other
57implementations of this provider.
58Its fields are:
59.Bl -tag -width "uintptr_t pkt_addr" -offset indent
60.It Vt uintptr_t pkt_addr
61Always set to 0.
62.El
63.Pp
64The
65.Vt csinfo_t
66argument is currently unimplemented and is included for compatibility with other
67implementations of this provider.
68Its fields are:
69.Bl -tag -width "uintptr_t cs_addr" -offset indent
70.It Vt uintptr_t cs_addr
71Always set to 0.
72.It Vt uint64_t cs_cid
73A pointer to the
74.Vt struct inpcb
75for this packet, or
76.Dv NULL .
77.It Vt pid_t cs_pid
78Always set to 0.
79.El
80.Pp
81The
82.Vt ipinfo_t
83argument contains IP fields common to both IPv4 and IPv6 packets.
84Its fields are:
85.Bl -tag -width "uint32_t ip_plength" -offset indent
86.It Vt uint8_t ip_ver
87IP version of the packet, 4 for IPv4 packets and 6 for IPv6 packets.
88.It Vt uint32_t ip_plength
89IP payload size.
90This does not include the size of the IP header or IPv6 option headers.
91.It Vt string ip_saddr
92IP source address.
93.It Vt string ip_daddr
94IP destination address.
95.El
96.Pp
97The
98.Vt udpsinfo_t
99argument contains the state of the UDP connection associated with the packet.
100Its fields are:
101.Bl -tag -width "uintptr_t udps_addr" -offset indent
102.It Vt uintptr_t udps_addr
103Pointer to the
104.Vt struct inpcb
105containing the IP state for the associated socket.
106.It Vt uint16_t udps_lport
107Local UDP port.
108.It Vt uint16_t udps_rport
109Remote UDP port.
110.It Vt string udps_laddr
111Local IPv4 or IPv6 address.
112.It Vt string udps_raddr
113Remote IPv4 or IPv6 address.
114.El
115.Pp
116The
117.Vt udpinfo_t
118argument is the raw UDP header of the packet, with all fields in host order.
119Its fields are:
120.Bl -tag -width "struct udphdr *udp_hdr" -offset indent
121.It Vt uint16_t udp_sport
122Source UDP port.
123.It Vt uint16_t udp_dport
124Destination UDP port.
125.It Vt uint16_t udp_length
126Length of the UDP header and payload, in bytes.
127.It Vt uint16_t udp_checksum
128A checksum of the UDP header and payload, or 0 if no checksum was calculated.
129.It Vt struct udphdr *udp_hdr
130A pointer to the raw UDP header.
131.El
132.Sh FILES
133.Bl -tag -width "/usr/lib/dtrace/udp.d" -compact
134.It Pa /usr/lib/dtrace/udp.d
135DTrace type and translator definitions for the
136.Nm udp
137provider.
138.El
139.Sh EXAMPLES
140The following script counts transmitted packets by destination port.
141.Bd -literal -offset indent
142udp:::send
143{
144        @num[args[4]->udp_dport] = count();
145}
146.Ed
147.Pp
148This script will print some details of each UDP packet as it is sent or received
149by the kernel:
150.Bd -literal -offset indent
151#pragma D option quiet
152#pragma D option switchrate=10Hz
153
154dtrace:::BEGIN
155{
156        printf(" %10s %36s    %-36s %6s\\n", "DELTA(us)", "SOURCE",
157            "DEST", "BYTES");
158        last = timestamp;
159}
160
161udp:::send
162{
163        this->elapsed = (timestamp - last) / 1000;
164        self->dest = strjoin(strjoin(args[2]->ip_daddr, ":"),
165             lltostr(args[4]->udp_dport));
166        printf(" %10d %30s:%-5d -> %-36s %6d\\n", this->elapsed,
167            args[2]->ip_saddr, args[4]->udp_sport,
168            self->dest, args[4]->udp_length);
169        last = timestamp;
170}
171
172udp:::receive
173{
174        this->elapsed = (timestamp - last) / 1000;
175        self->dest = strjoin(strjoin(args[2]->ip_saddr, ":"),
176             lltostr(args[4]->udp_sport));
177        printf(" %10d %30s:%-5d <- %-36s %6d\\n", this->elapsed,
178            args[2]->ip_daddr, args[4]->udp_dport,
179            self->dest, args[4]->udp_length);
180        last = timestamp;
181}
182.Ed
183.Sh COMPATIBILITY
184This provider is compatible with the
185.Nm udp
186provider in Solaris.
187.Sh SEE ALSO
188.Xr dtrace 1 ,
189.Xr dtrace_ip 4 ,
190.Xr dtrace_sctp 4 ,
191.Xr dtrace_tcp 4 ,
192.Xr dtrace_udplite 4 ,
193.Xr udp 4 ,
194.Xr SDT 9
195.Sh HISTORY
196The
197.Nm udp
198provider first appeared in
199.Fx
20010.0.
201.Sh AUTHORS
202This manual page was written by
203.An Mark Johnston Aq Mt markj@FreeBSD.org .
204