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############################################################ 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 if_name; 39this string local; 40this string remote; 41this u_char recv; 42this 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} 66EOF 67ACTIONS=$( cat <&9 ) 68ID=$(( $ID + 1 )) 69 70############################################################ EVENT TAG 71 72exec 9<<EOF 73 printf("%s: ", "$PROFILE"); 74EOF 75EVENT_TAG=$( cat <&9 ) 76 77############################################################ EVENT DETAILS 78 79exec 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"); 90EOF 91EVENT_DETAILS=$( cat <&9 ) 92 93################################################################################ 94# END 95################################################################################ 96