xref: /freebsd/cddl/usr.sbin/dwatch/libexec/udplite (revision 18054d0220cfc8df9c9568c437bd6fbb59d53c3c)
1# -*- tab-width: 4 -*- ;; Emacs
2# vi: set filetype=sh tabstop=8 shiftwidth=8 noexpandtab :: Vi/ViM
3############################################################ IDENT(1)
4#
5# $Title: dwatch(8) module for dtrace_udplite(4) $
6# $Copyright: 2014-2018 Devin Teske. All rights reserved. $
7# $FreeBSD$
8#
9############################################################ DESCRIPTION
10#
11# Display local/remote UDP addresses/ports and bytes sent/received for UDP I/O
12#
13############################################################ PROBE
14
15case "$PROFILE" in
16udplite) : ${PROBE:=udplite:::send, udplite:::receive} ;;
17  *) : ${PROBE:=udplite:::${PROFILE#udplite-}}
18esac
19
20############################################################ ACTIONS
21
22exec 9<<EOF
23this string	flow;
24this string	local;
25this string	remote;
26this u_char	local6;
27this u_char	recv;
28this u_char	remote6;
29this uint16_t	coverage;
30this uint16_t	lport;
31this uint16_t	rport;
32
33$PROBE /* probe ID $ID */
34{${TRACE:+
35	printf("<$ID>");
36}
37	/*
38	 * dtrace_udplite(4)
39	 */
40	this->recv = probename == "receive" ? 1 : 0;
41	this->flow = this->recv ? "<-" : "->";
42
43	/*
44	 * ipinfo_t *
45	 */
46	this->local  = this->recv ? args[2]->ip_daddr : args[2]->ip_saddr;
47	this->remote = this->recv ? args[2]->ip_saddr : args[2]->ip_daddr;
48
49	/*
50	 * udpliteinfo_t *
51	 */
52	this->coverage = (uint16_t)args[4]->udplite_coverage;
53	this->lport  = this->recv ? args[4]->udplite_dport : args[4]->udplite_sport;
54	this->rport  = this->recv ? args[4]->udplite_sport : args[4]->udplite_dport;
55
56	/*
57	 * IPv6 support
58	 */
59	this->local6 = strstr(this->local, ":") != NULL ? 1 : 0;
60	this->remote6 = strstr(this->remote, ":") != NULL ? 1 : 0;
61	this->local = strjoin(strjoin(this->local6 ? "[" : "",
62		this->local), this->local6 ? "]" : "");
63	this->remote = strjoin(strjoin(this->remote6 ? "[" : "",
64		this->remote), this->remote6 ? "]" : "");
65}
66EOF
67ACTIONS=$( cat <&9 )
68ID=$(( $ID + 1 ))
69
70############################################################ EVENT DETAILS
71
72if [ ! "$CUSTOM_DETAILS" ]; then
73exec 9<<EOF
74	/*
75	 * Print network I/O details
76	 */
77	printf("%s:%u %s %s:%u %d byte%s",
78		this->local, this->lport,
79		this->flow,
80		this->remote, this->rport,
81		this->coverage,
82		this->coverage == 1 ? "" : "s");
83EOF
84EVENT_DETAILS=$( cat <&9 )
85fi
86
87################################################################################
88# END
89################################################################################
90