]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - cddl/usr.sbin/dwatch/libexec/udp
Import libedit 2019-09-10
[FreeBSD/FreeBSD.git] / cddl / usr.sbin / dwatch / libexec / udp
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_udp(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
15 case "$PROFILE" in
16 udp) : ${PROBE:=udp:::send, udp:::receive} ;;
17   *) : ${PROBE:=udp:::${PROFILE#udp-}}
18 esac
19
20 ############################################################ ACTIONS
21
22 exec 9<<EOF
23 this string     flow;
24 this string     local;
25 this string     remote;
26 this u_char     local6;
27 this u_char     recv;
28 this u_char     remote6;
29 this uint16_t   length;
30 this uint16_t   lport;
31 this uint16_t   rport;
32
33 $PROBE /* probe ID $ID */
34 {${TRACE:+
35         printf("<$ID>");
36 }
37         /*
38          * dtrace_udp(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          * udpinfo_t *
51          */
52         this->length = (uint16_t)args[4]->udp_length;
53         this->lport  = this->recv ? args[4]->udp_dport : args[4]->udp_sport;
54         this->rport  = this->recv ? args[4]->udp_sport : args[4]->udp_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 }
66 EOF
67 ACTIONS=$( cat <&9 )
68 ID=$(( $ID + 1 ))
69
70 ############################################################ EVENT DETAILS
71
72 if [ ! "$CUSTOM_DETAILS" ]; then
73 exec 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->length,
82                 this->length == 1 ? "" : "s");
83 EOF
84 EVENT_DETAILS=$( cat <&9 )
85 fi
86
87 ################################################################################
88 # END
89 ################################################################################