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 15case "$PROFILE" in 16udp) : ${PROBE:=udp:::send, udp:::receive} ;; 17 *) : ${PROBE:=udp:::${PROFILE#udp-}} 18esac 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# 26unset EXECNAME # -k name 27unset EXECREGEX # -z regex 28unset GROUP # -g group 29unset PID # -p pid 30unset PSARGS # affects -d 31unset PSTREE # -R 32unset USER # -u user 33 34############################################################ ACTIONS 35 36exec 9<<EOF 37this string flow; 38this string local; 39this string remote; 40this u_char local6; 41this u_char recv; 42this u_char remote6; 43this uint16_t length; 44this uint16_t lport; 45this uint16_t rport; 46 47$PROBE /* probe ID $ID */ 48{${TRACE:+ 49 printf("<$ID>"); 50} 51 /* 52 * dtrace_udp(4) 53 */ 54 this->recv = probename == "receive" ? 1 : 0; 55 this->flow = this->recv ? "<-" : "->"; 56 57 /* 58 * ipinfo_t * 59 */ 60 this->local = this->recv ? args[2]->ip_daddr : args[2]->ip_saddr; 61 this->remote = this->recv ? args[2]->ip_saddr : args[2]->ip_daddr; 62 63 /* 64 * udpinfo_t * 65 */ 66 this->length = (uint16_t)args[4]->udp_length; 67 this->lport = this->recv ? args[4]->udp_dport : args[4]->udp_sport; 68 this->rport = this->recv ? args[4]->udp_sport : args[4]->udp_dport; 69 70 /* 71 * IPv6 support 72 */ 73 this->local6 = strstr(this->local, ":") != NULL ? 1 : 0; 74 this->remote6 = strstr(this->remote, ":") != NULL ? 1 : 0; 75 this->local = strjoin(strjoin(this->local6 ? "[" : "", 76 this->local), this->local6 ? "]" : ""); 77 this->remote = strjoin(strjoin(this->remote6 ? "[" : "", 78 this->remote), this->remote6 ? "]" : ""); 79} 80EOF 81ACTIONS=$( cat <&9 ) 82ID=$(( $ID + 1 )) 83 84############################################################ EVENT TAG 85 86exec 9<<EOF 87 printf("%s: ", "$PROFILE"); 88EOF 89EVENT_TAG=$( cat <&9 ) 90 91############################################################ EVENT DETAILS 92 93if [ ! "$CUSTOM_DETAILS" ]; then 94exec 9<<EOF 95 /* 96 * Print network I/O details 97 */ 98 printf("%s:%u %s %s:%u %d byte%s", 99 this->local, this->lport, 100 this->flow, 101 this->remote, this->rport, 102 this->length, 103 this->length == 1 ? "" : "s"); 104EOF 105EVENT_DETAILS=$( cat <&9 ) 106fi 107 108################################################################################ 109# END 110################################################################################ 111