xref: /freebsd/cddl/usr.sbin/dwatch/libexec/ip (revision ab393e9548f8cc0ee28499c411963b798ebb38a5)
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_ip(4) $
6# $Copyright: 2014-2018 Devin Teske. All rights reserved. $
7#
8############################################################ DESCRIPTION
9#
10# Display interface name and bytes sent/received when IP I/O occurs
11#
12############################################################ PROBE
13
14case "$PROFILE" in
15ip) : ${PROBE:=ip:::send, ip:::receive} ;;
16 *) : ${PROBE:=ip:::${PROFILE#ip-}}
17esac
18
19############################################################ ACTIONS
20
21exec 9<<EOF
22this string	flow;
23this string	if_name;
24this string	local;
25this string	remote;
26this u_char	recv;
27this uint32_t	length;
28
29$PROBE /* probe ID $ID */
30{${TRACE:+
31	printf("<$ID>");
32}
33	/*
34	 * dtrace_ip(4)
35	 */
36	this->recv = probename == "receive" ? 1 : 0;
37	this->flow = this->recv ? "<-" : "->";
38
39	/*
40	 * ipinfo_t *
41	 */
42	this->length = (uint32_t)args[2]->ip_plength;
43	this->local  = this->recv ? args[2]->ip_daddr : args[2]->ip_saddr;
44	this->remote = this->recv ? args[2]->ip_saddr : args[2]->ip_daddr;
45
46	/*
47	 * ifinfo_t *
48	 */
49	this->if_name = args[3]->if_name;
50}
51EOF
52ACTIONS=$( cat <&9 )
53ID=$(( $ID + 1 ))
54
55############################################################ EVENT DETAILS
56
57if [ ! "$CUSTOM_DETAILS" ]; then
58exec 9<<EOF
59	/*
60	 * Print network I/O details
61	 */
62	printf("%s %s %s %s %u byte%s",
63		this->if_name,
64		this->local,
65		this->flow,
66		this->remote,
67		this->length,
68		this->length == 1 ? "" : "s");
69EOF
70EVENT_DETAILS=$( cat <&9 )
71fi
72
73################################################################################
74# END
75################################################################################
76