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