]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - cddl/usr.sbin/dwatch/libexec/ip
Introduce dwatch(1) as a tool for making DTrace more useful
[FreeBSD/FreeBSD.git] / cddl / usr.sbin / dwatch / libexec / ip
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
15 case "$PROFILE" in
16 ip) : ${PROBE:=ip:::send, ip:::receive} ;;
17  *) : ${PROBE:=ip:::${PROFILE#ip-}}
18 esac
19
20 ############################################################ GLOBALS
21
22 #
23 # This profile does not support these dwatch features
24 # NB: They are disabled here so they have no effect when profile is loaded
25 #
26 unset EXECNAME          # -k name
27 unset EXECREGEX         # -z regex
28 unset GROUP             # -g group
29 unset PID               # -p pid
30 unset PSARGS            # affects -d
31 unset PSTREE            # -R
32 unset USER              # -u user
33
34 ############################################################ ACTIONS
35
36 exec 9<<EOF
37 this string     flow;
38 this string     if_name;
39 this string     local;
40 this string     remote;
41 this u_char     recv;
42 this uint32_t   length;
43
44 $PROBE /* probe ID $ID */
45 {${TRACE:+
46         printf("<$ID>");
47 }
48         /*
49          * dtrace_ip(4)
50          */
51         this->recv = probename == "receive" ? 1 : 0;
52         this->flow = this->recv ? "<-" : "->";
53
54         /*
55          * ipinfo_t *
56          */
57         this->length = (uint32_t)args[2]->ip_plength;
58         this->local  = this->recv ? args[2]->ip_daddr : args[2]->ip_saddr;
59         this->remote = this->recv ? args[2]->ip_saddr : args[2]->ip_daddr;
60
61         /*
62          * ifinfo_t *
63          */
64         this->if_name = args[3]->if_name;
65 }
66 EOF
67 ACTIONS=$( cat <&9 )
68 ID=$(( $ID + 1 ))
69
70 ############################################################ EVENT TAG
71
72 exec 9<<EOF
73         printf("%s: ", "$PROFILE");
74 EOF
75 EVENT_TAG=$( cat <&9 )
76
77 ############################################################ EVENT DETAILS
78
79 exec 9<<EOF
80         /*
81          * Print network I/O details
82          */
83         printf("%s %s %s %s %u byte%s",
84                 this->if_name,
85                 this->local,
86                 this->flow,
87                 this->remote,
88                 this->length,
89                 this->length == 1 ? "" : "s");
90 EOF
91 EVENT_DETAILS=$( cat <&9 )
92
93 ################################################################################
94 # END
95 ################################################################################