1 1.1 christos #!/usr/bin/ksh 2 1.1 christos # 3 1.1 christos # tcpsnoop_snv - snoop TCP network packets by process. 4 1.1 christos # Written using DTrace (Solaris Nevada) 5 1.1 christos # 6 1.1 christos # This analyses TCP network packets and prints the responsible PID and UID, 7 1.1 christos # plus standard details such as IP address and port. This captures traffic 8 1.1 christos # of newly created TCP connections that were established while this program 9 1.1 christos # was running. It can help identify which processes is causing TCP traffic. 10 1.1 christos # 11 1.1 christos # WARNING: This script may only work on Solaris Nevada and OpenSolaris 12 1.1 christos # of the late 2007 vintage, since it uses the fbt provider to trace the raw 13 1.1 christos # operation of a specific version of the kernel. In the future, a 'stable' 14 1.1 christos # network provider should exist which will allow this to be written for that 15 1.1 christos # and subsequent versions of the kernel. In the meantime, check for other 16 1.1 christos # versions of this script in the /Net directory, and read the 17 1.1 christos # Notes/ALLfbt_notes.txt for more background on fbt. 18 1.1 christos # 19 1.1 christos # $Id: tcpsnoop_snv,v 1.1.1.1 2015/09/30 22:01:07 christos Exp $ 20 1.1 christos # 21 1.1 christos # USAGE: tcpsnoop [-a|hjsvZ] [-n name] [-p pid] 22 1.1 christos # 23 1.1 christos # -a # print all data 24 1.1 christos # -j # print project ID 25 1.1 christos # -s # print time, us 26 1.1 christos # -v # print time, string 27 1.1 christos # -Z # print zone ID 28 1.1 christos # -n name # command name to snoop 29 1.1 christos # -p pid # PID to snoop 30 1.1 christos # eg, 31 1.1 christos # tcpsnoop -v # human readable timestamps 32 1.1 christos # tcpsnoop -Z # print zonename 33 1.1 christos # tcpsnoop -n sshd # snoop sshd traffic only 34 1.1 christos # 35 1.1 christos # FIELDS: 36 1.1 christos # UID user ID 37 1.1 christos # PID process ID 38 1.1 christos # CMD command 39 1.1 christos # LADDR local IP address 40 1.1 christos # RADDR remote IP address 41 1.1 christos # LPORT local port number 42 1.1 christos # RPORT remote port number 43 1.1 christos # DR direction 44 1.1 christos # SIZE packet size, bytes 45 1.1 christos # TIME timestamp, us 46 1.1 christos # STRTIME human readable timestamp, string 47 1.1 christos # ZONE zone ID 48 1.1 christos # PROJ project ID 49 1.1 christos # 50 1.1 christos # SEE ALSO: snoop -rS 51 1.1 christos # 52 1.1 christos # COPYRIGHT: Copyright (c) 2005, 2006 Brendan Gregg. 53 1.1 christos # 54 1.1 christos # CDDL HEADER START 55 1.1 christos # 56 1.1 christos # The contents of this file are subject to the terms of the 57 1.1 christos # Common Development and Distribution License, Version 1.0 only 58 1.1 christos # (the "License"). You may not use this file except in compliance 59 1.1 christos # with the License. 60 1.1 christos # 61 1.1 christos # You can obtain a copy of the license at Docs/cddl1.txt 62 1.1 christos # or http://www.opensolaris.org/os/licensing. 63 1.1 christos # See the License for the specific language governing permissions 64 1.1 christos # and limitations under the License. 65 1.1 christos # 66 1.1 christos # CDDL HEADER END 67 1.1 christos # 68 1.1 christos # Author: Brendan Gregg [Sydney, Australia] 69 1.1 christos # 70 1.1 christos # TODO: IPv6 71 1.1 christos # 72 1.1 christos # CODE: 73 1.1 christos # The FILTER syntax matches on packets rather than initial 74 1.1 christos # connections, so that it can follow inetd connections properly. 75 1.1 christos # 76 1.1 christos # 09-Jul-2004 Brendan Gregg Created this. 77 1.1 christos # 12-Mar-2005 " " Changed probes, size info now printed. 78 1.1 christos # 02-Jul-2005 " " Many more probes. Renamed "tcpsnoop.d". 79 1.1 christos # 04-Jul-2005 " " Now wrapped in shell, called "tcpsnoop". 80 1.1 christos # 03-Dec-2005 " " Fixed tcp_accept_finish bug, now 100% correct 81 1.1 christos # execname. Thanks Kias Belgaied for expertise. 82 1.1 christos # 20-Apr-2006 " " Fixed SS_TCP_FAST_ACCEPT bug in build 31+. 83 1.1 christos # 20-Apr-2006 " " Last update. 84 1.1 christos # 30-Sep-2007 " " Bumped this for recent OpenSolaris/Nevada. 85 1.1 christos # 86 1.1 christos 87 1.1 christos ############################## 88 1.1 christos # --- Process Arguments --- 89 1.1 christos # 90 1.1 christos 91 1.1 christos ### default variables 92 1.1 christos opt_name=0; opt_time=0; opt_timestr=0; filter=0; pname=. 93 1.1 christos opt_zone=0; opt_proj=0; opt_pid=0; pid=0 94 1.1 christos 95 1.1 christos ### process options 96 1.1 christos while getopts ahjsvZn:p: name 97 1.1 christos do 98 1.1 christos case $name in 99 1.1 christos a) opt_time=1; opt_timestr=1; opt_zone=1; opt_proj=1 ;; 100 1.1 christos n) opt_name=1; pname=$OPTARG ;; 101 1.1 christos p) opt_pid=1; pid=$OPTARG ;; 102 1.1 christos j) opt_proj=1 ;; 103 1.1 christos s) opt_time=1 ;; 104 1.1 christos v) opt_timestr=1 ;; 105 1.1 christos Z) opt_zone=1 ;; 106 1.1 christos h|?) cat <<-END >&2 107 1.1 christos USAGE: tcpsnoop [-a|hjsvZ] [-n name] [-p pid] 108 1.1 christos tcpsnoop # default output 109 1.1 christos -a # print all data 110 1.1 christos -j # print project ID 111 1.1 christos -s # print start time, us 112 1.1 christos -v # print start time, string 113 1.1 christos -Z # print zonename 114 1.1 christos -n name # command name to snoop 115 1.1 christos -p pid # PID to snoop 116 1.1 christos eg, 117 1.1 christos tcpsnoop -v # human readable timestamps 118 1.1 christos tcpsnoop -Z # print zonename 119 1.1 christos tcpsnoop -n sshd # snoop sshd traffic only 120 1.1 christos END 121 1.1 christos exit 1 122 1.1 christos esac 123 1.1 christos done 124 1.1 christos 125 1.1 christos ### option logic 126 1.1 christos if (( opt_name || opt_pid )); then 127 1.1 christos filter=1 128 1.1 christos fi 129 1.1 christos 130 1.1 christos ################################# 131 1.1 christos # --- Main Program, DTrace --- 132 1.1 christos # 133 1.1 christos /usr/sbin/dtrace -Cs <( print -r ' 134 1.1 christos /* 135 1.1 christos * Command line arguments 136 1.1 christos */ 137 1.1 christos inline int OPT_name = '$opt_name'; 138 1.1 christos inline int OPT_pid = '$opt_pid'; 139 1.1 christos inline int OPT_time = '$opt_time'; 140 1.1 christos inline int OPT_timestr = '$opt_timestr'; 141 1.1 christos inline int OPT_zone = '$opt_zone'; 142 1.1 christos inline int OPT_proj = '$opt_proj'; 143 1.1 christos inline int PID = '$pid'; 144 1.1 christos inline int FILTER = '$filter'; 145 1.1 christos inline string NAME = "'$pname'"; 146 1.1 christos 147 1.1 christos #pragma D option quiet 148 1.1 christos #pragma D option switchrate=10hz 149 1.1 christos 150 1.1 christos #include <sys/file.h> 151 1.1 christos #include <inet/common.h> 152 1.1 christos #include <sys/byteorder.h> 153 1.1 christos #include <sys/socket.h> 154 1.1 christos #include <sys/socketvar.h> 155 1.1 christos 156 1.1 christos /* 157 1.1 christos * Print header 158 1.1 christos */ 159 1.1 christos dtrace:::BEGIN 160 1.1 christos { 161 1.1 christos /* print optional headers */ 162 1.1 christos OPT_time ? printf("%-14s ", "TIME") : 1; 163 1.1 christos OPT_timestr ? printf("%-20s ", "STRTIME") : 1; 164 1.1 christos OPT_zone ? printf("%4s ", "ZONE") : 1; 165 1.1 christos OPT_proj ? printf("%4s ", "PROJ") : 1; 166 1.1 christos 167 1.1 christos /* print main headers */ 168 1.1 christos printf("%5s %6s %-15s %5s %2s %-15s %5s %5s %s\n", 169 1.1 christos "UID", "PID", "LADDR", "LPORT", "DR", "RADDR", "RPORT", 170 1.1 christos "SIZE", "CMD"); 171 1.1 christos } 172 1.1 christos 173 1.1 christos 174 1.1 christos /* 175 1.1 christos * TCP Process inbound connections 176 1.1 christos * 177 1.1 christos * 0x00200000 has been hardcoded. It was SS_TCP_FAST_ACCEPT, but was 178 1.1 christos * renamed to SS_DIRECT around build 31. 179 1.1 christos */ 180 1.1 christos fbt:sockfs:sotpi_accept:entry 181 1.1 christos /(arg1 & FREAD) && (arg1 & FWRITE) && (args[0]->so_state & 0x00200000)/ 182 1.1 christos { 183 1.1 christos self->sop = args[0]; 184 1.1 christos } 185 1.1 christos 186 1.1 christos fbt:sockfs:sotpi_create:return 187 1.1 christos /self->sop/ 188 1.1 christos { 189 1.1 christos self->nsop = (struct sonode *)arg1; 190 1.1 christos } 191 1.1 christos 192 1.1 christos fbt:sockfs:sotpi_accept:return 193 1.1 christos /self->nsop/ 194 1.1 christos { 195 1.1 christos this->tcpp = (tcp_t *)self->nsop->so_priv; 196 1.1 christos self->connp = (conn_t *)this->tcpp->tcp_connp; 197 1.1 christos tname[(int)self->connp] = execname; 198 1.1 christos tpid[(int)self->connp] = pid; 199 1.1 christos tuid[(int)self->connp] = uid; 200 1.1 christos } 201 1.1 christos 202 1.1 christos fbt:sockfs:sotpi_accept:return 203 1.1 christos { 204 1.1 christos self->nsop = 0; 205 1.1 christos self->sop = 0; 206 1.1 christos } 207 1.1 christos 208 1.1 christos /* 209 1.1 christos * TCP Process outbound connections 210 1.1 christos */ 211 1.1 christos fbt:ip:tcp_connect:entry 212 1.1 christos { 213 1.1 christos this->tcpp = (tcp_t *)arg0; 214 1.1 christos self->connp = (conn_t *)this->tcpp->tcp_connp; 215 1.1 christos tname[(int)self->connp] = execname; 216 1.1 christos tpid[(int)self->connp] = pid; 217 1.1 christos tuid[(int)self->connp] = uid; 218 1.1 christos OPT_proj ? tproj[(int)self->connp] = curpsinfo->pr_projid : 1; 219 1.1 christos } 220 1.1 christos 221 1.1 christos /* 222 1.1 christos * TCP Data translations 223 1.1 christos */ 224 1.1 christos fbt:sockfs:sotpi_accept:return, 225 1.1 christos fbt:ip:tcp_connect:return 226 1.1 christos /self->connp/ 227 1.1 christos { 228 1.1 christos /* fetch ports */ 229 1.1 christos #if defined(_BIG_ENDIAN) 230 1.1 christos self->lport = self->connp->u_port.tcpu_ports.tcpu_lport; 231 1.1 christos self->fport = self->connp->u_port.tcpu_ports.tcpu_fport; 232 1.1 christos #else 233 1.1 christos self->lport = BSWAP_16(self->connp->u_port.tcpu_ports.tcpu_lport); 234 1.1 christos self->fport = BSWAP_16(self->connp->u_port.tcpu_ports.tcpu_fport); 235 1.1 christos #endif 236 1.1 christos 237 1.1 christos /* fetch IPv4 addresses */ 238 1.1 christos this->fad12 = 239 1.1 christos (int)self->connp->connua_v6addr.connua_faddr._S6_un._S6_u8[12]; 240 1.1 christos this->fad13 = 241 1.1 christos (int)self->connp->connua_v6addr.connua_faddr._S6_un._S6_u8[13]; 242 1.1 christos this->fad14 = 243 1.1 christos (int)self->connp->connua_v6addr.connua_faddr._S6_un._S6_u8[14]; 244 1.1 christos this->fad15 = 245 1.1 christos (int)self->connp->connua_v6addr.connua_faddr._S6_un._S6_u8[15]; 246 1.1 christos this->lad12 = 247 1.1 christos (int)self->connp->connua_v6addr.connua_laddr._S6_un._S6_u8[12]; 248 1.1 christos this->lad13 = 249 1.1 christos (int)self->connp->connua_v6addr.connua_laddr._S6_un._S6_u8[13]; 250 1.1 christos this->lad14 = 251 1.1 christos (int)self->connp->connua_v6addr.connua_laddr._S6_un._S6_u8[14]; 252 1.1 christos this->lad15 = 253 1.1 christos (int)self->connp->connua_v6addr.connua_laddr._S6_un._S6_u8[15]; 254 1.1 christos 255 1.1 christos /* convert type for use with lltostr() */ 256 1.1 christos this->fad12 = this->fad12 < 0 ? 256 + this->fad12 : this->fad12; 257 1.1 christos this->fad13 = this->fad13 < 0 ? 256 + this->fad13 : this->fad13; 258 1.1 christos this->fad14 = this->fad14 < 0 ? 256 + this->fad14 : this->fad14; 259 1.1 christos this->fad15 = this->fad15 < 0 ? 256 + this->fad15 : this->fad15; 260 1.1 christos this->lad12 = this->lad12 < 0 ? 256 + this->lad12 : this->lad12; 261 1.1 christos this->lad13 = this->lad13 < 0 ? 256 + this->lad13 : this->lad13; 262 1.1 christos this->lad14 = this->lad14 < 0 ? 256 + this->lad14 : this->lad14; 263 1.1 christos this->lad15 = this->lad15 < 0 ? 256 + this->lad15 : this->lad15; 264 1.1 christos 265 1.1 christos /* stringify addresses */ 266 1.1 christos self->faddr = strjoin(lltostr(this->fad12), "."); 267 1.1 christos self->faddr = strjoin(self->faddr, strjoin(lltostr(this->fad13), ".")); 268 1.1 christos self->faddr = strjoin(self->faddr, strjoin(lltostr(this->fad14), ".")); 269 1.1 christos self->faddr = strjoin(self->faddr, lltostr(this->fad15 + 0)); 270 1.1 christos self->laddr = strjoin(lltostr(this->lad12), "."); 271 1.1 christos self->laddr = strjoin(self->laddr, strjoin(lltostr(this->lad13), ".")); 272 1.1 christos self->laddr = strjoin(self->laddr, strjoin(lltostr(this->lad14), ".")); 273 1.1 christos self->laddr = strjoin(self->laddr, lltostr(this->lad15 + 0)); 274 1.1 christos 275 1.1 christos /* fix direction and save values */ 276 1.1 christos tladdr[(int)self->connp] = self->laddr; 277 1.1 christos tfaddr[(int)self->connp] = self->faddr; 278 1.1 christos tlport[(int)self->connp] = self->lport; 279 1.1 christos tfport[(int)self->connp] = self->fport; 280 1.1 christos 281 1.1 christos /* all systems go */ 282 1.1 christos tok[(int)self->connp] = 1; 283 1.1 christos } 284 1.1 christos 285 1.1 christos /* 286 1.1 christos * TCP Clear connp 287 1.1 christos */ 288 1.1 christos fbt:ip:tcp_get_conn:return 289 1.1 christos { 290 1.1 christos /* Q_TO_CONN */ 291 1.1 christos this->connp = (conn_t *)arg1; 292 1.1 christos tok[(int)this->connp] = 0; 293 1.1 christos tpid[(int)this->connp] = 0; 294 1.1 christos tuid[(int)this->connp] = 0; 295 1.1 christos tname[(int)this->connp] = 0; 296 1.1 christos tproj[(int)this->connp] = 0; 297 1.1 christos } 298 1.1 christos 299 1.1 christos /* 300 1.1 christos * TCP Process "port closed" 301 1.1 christos */ 302 1.1 christos fbt:ip:tcp_xmit_early_reset:entry 303 1.1 christos /FILTER == 0/ 304 1.1 christos { 305 1.1 christos this->queuep = args[7]->tcps_g_q; 306 1.1 christos this->connp = (conn_t *)this->queuep->q_ptr; 307 1.1 christos this->tcpp = (tcp_t *)this->connp->conn_tcp; 308 1.1 christos self->zoneid = this->connp->conn_zoneid; 309 1.1 christos 310 1.1 christos /* split addresses */ 311 1.1 christos this->ipha = (ipha_t *)args[1]->b_rptr; 312 1.1 christos this->fad15 = (this->ipha->ipha_src & 0xff000000) >> 24; 313 1.1 christos this->fad14 = (this->ipha->ipha_src & 0x00ff0000) >> 16; 314 1.1 christos this->fad13 = (this->ipha->ipha_src & 0x0000ff00) >> 8; 315 1.1 christos this->fad12 = (this->ipha->ipha_src & 0x000000ff); 316 1.1 christos this->lad15 = (this->ipha->ipha_dst & 0xff000000) >> 24; 317 1.1 christos this->lad14 = (this->ipha->ipha_dst & 0x00ff0000) >> 16; 318 1.1 christos this->lad13 = (this->ipha->ipha_dst & 0x0000ff00) >> 8; 319 1.1 christos this->lad12 = (this->ipha->ipha_dst & 0x000000ff); 320 1.1 christos 321 1.1 christos /* stringify addresses */ 322 1.1 christos self->faddr = strjoin(lltostr(this->fad12), "."); 323 1.1 christos self->faddr = strjoin(self->faddr, strjoin(lltostr(this->fad13), ".")); 324 1.1 christos self->faddr = strjoin(self->faddr, strjoin(lltostr(this->fad14), ".")); 325 1.1 christos self->faddr = strjoin(self->faddr, lltostr(this->fad15 + 0)); 326 1.1 christos self->laddr = strjoin(lltostr(this->lad12), "."); 327 1.1 christos self->laddr = strjoin(self->laddr, strjoin(lltostr(this->lad13), ".")); 328 1.1 christos self->laddr = strjoin(self->laddr, strjoin(lltostr(this->lad14), ".")); 329 1.1 christos self->laddr = strjoin(self->laddr, lltostr(this->lad15 + 0)); 330 1.1 christos 331 1.1 christos self->reset = 1; 332 1.1 christos } 333 1.1 christos 334 1.1 christos /* 335 1.1 christos * TCP Fetch "port closed" ports 336 1.1 christos */ 337 1.1 christos fbt:ip:tcp_xchg:entry 338 1.1 christos /self->reset/ 339 1.1 christos { 340 1.1 christos #if defined(_BIG_ENDIAN) 341 1.1 christos self->lport = (uint16_t)arg0; 342 1.1 christos self->fport = (uint16_t)arg1; 343 1.1 christos #else 344 1.1 christos self->lport = BSWAP_16((uint16_t)arg0); 345 1.1 christos self->fport = BSWAP_16((uint16_t)arg1); 346 1.1 christos #endif 347 1.1 christos self->lport = BE16_TO_U16(arg0); 348 1.1 christos self->fport = BE16_TO_U16(arg1); 349 1.1 christos } 350 1.1 christos 351 1.1 christos /* 352 1.1 christos * TCP Print "port closed" 353 1.1 christos */ 354 1.1 christos fbt:ip:tcp_xmit_early_reset:return 355 1.1 christos /FILTER == 0/ 356 1.1 christos { 357 1.1 christos self->name = "<closed>"; 358 1.1 christos self->pid = 0; 359 1.1 christos self->uid = 0; 360 1.1 christos self->proj = 0; 361 1.1 christos self->size = 54; /* should check trailers */ 362 1.1 christos self->dir = "<-"; 363 1.1 christos OPT_time ? printf("%-14d ", timestamp/1000) : 1; 364 1.1 christos OPT_timestr ? printf("%-20Y ", walltimestamp) : 1; 365 1.1 christos OPT_zone ? printf("%4d ", self->zoneid) : 1; 366 1.1 christos OPT_proj ? printf("%4d ", self->proj) : 1; 367 1.1 christos printf("%5d %6d %-15s %5d %2s %-15s %5d %5d %s\n", 368 1.1 christos self->uid, self->pid, self->laddr, self->lport, self->dir, 369 1.1 christos self->faddr, self->fport, self->size, self->name); 370 1.1 christos self->dir = "->"; 371 1.1 christos OPT_time ? printf("%-14d ", timestamp/1000) : 1; 372 1.1 christos OPT_timestr ? printf("%-20Y ", walltimestamp) : 1; 373 1.1 christos OPT_zone ? printf("%4d ", self->zoneid) : 1; 374 1.1 christos OPT_proj ? printf("%4d ", self->proj) : 1; 375 1.1 christos printf("%5d %6d %-15s %5d %2s %-15s %5d %5d %s\n", 376 1.1 christos self->uid, self->pid, self->laddr, self->lport, self->dir, 377 1.1 christos self->faddr, self->fport, self->size, self->name); 378 1.1 christos self->reset = 0; 379 1.1 christos self->size = 0; 380 1.1 christos self->name = 0; 381 1.1 christos self->zoneid = 0; 382 1.1 christos } 383 1.1 christos 384 1.1 christos /* 385 1.1 christos * TCP Process Write 386 1.1 christos */ 387 1.1 christos fbt:ip:tcp_send_data:entry 388 1.1 christos { 389 1.1 christos self->conn_p = (conn_t *)args[0]->tcp_connp; 390 1.1 christos } 391 1.1 christos 392 1.1 christos fbt:ip:tcp_send_data:entry 393 1.1 christos /tok[(int)self->conn_p]/ 394 1.1 christos { 395 1.1 christos self->dir = "->"; 396 1.1 christos self->size = msgdsize(args[2]) + 14; /* should check trailers */ 397 1.1 christos self->uid = tuid[(int)self->conn_p]; 398 1.1 christos self->laddr = tladdr[(int)self->conn_p]; 399 1.1 christos self->faddr = tfaddr[(int)self->conn_p]; 400 1.1 christos self->lport = tlport[(int)self->conn_p]; 401 1.1 christos self->fport = tfport[(int)self->conn_p]; 402 1.1 christos OPT_proj ? self->proj = tproj[(int)self->conn_p] : 1; 403 1.1 christos self->zoneid = self->conn_p->conn_zoneid; 404 1.1 christos self->ok = 2; 405 1.1 christos 406 1.1 christos /* follow inetd -> in.* transitions */ 407 1.1 christos self->name = pid && (tname[(int)self->conn_p] == "inetd") ? 408 1.1 christos execname : tname[(int)self->conn_p]; 409 1.1 christos self->pid = pid && (tname[(int)self->conn_p] == "inetd") ? 410 1.1 christos pid : tpid[(int)self->conn_p]; 411 1.1 christos tname[(int)self->conn_p] = self->name; 412 1.1 christos tpid[(int)self->conn_p] = self->pid; 413 1.1 christos } 414 1.1 christos 415 1.1 christos /* 416 1.1 christos * TCP Process Read 417 1.1 christos */ 418 1.1 christos fbt:ip:tcp_rput_data:entry 419 1.1 christos { 420 1.1 christos self->conn_p = (conn_t *)arg0; 421 1.1 christos self->size = msgdsize(args[1]) + 14; /* should check trailers */ 422 1.1 christos } 423 1.1 christos 424 1.1 christos fbt:ip:tcp_rput_data:entry 425 1.1 christos /tok[(int)self->conn_p]/ 426 1.1 christos { 427 1.1 christos self->dir = "<-"; 428 1.1 christos self->uid = tuid[(int)self->conn_p]; 429 1.1 christos self->laddr = tladdr[(int)self->conn_p]; 430 1.1 christos self->faddr = tfaddr[(int)self->conn_p]; 431 1.1 christos self->lport = tlport[(int)self->conn_p]; 432 1.1 christos self->fport = tfport[(int)self->conn_p]; 433 1.1 christos OPT_proj ? self->proj = tproj[(int)self->conn_p] : 1; 434 1.1 christos self->zoneid = self->conn_p->conn_zoneid; 435 1.1 christos self->ok = 2; 436 1.1 christos 437 1.1 christos /* follow inetd -> in.* transitions */ 438 1.1 christos self->name = pid && (tname[(int)self->conn_p] == "inetd") ? 439 1.1 christos execname : tname[(int)self->conn_p]; 440 1.1 christos self->pid = pid && (tname[(int)self->conn_p] == "inetd") ? 441 1.1 christos pid : tpid[(int)self->conn_p]; 442 1.1 christos tname[(int)self->conn_p] = self->name; 443 1.1 christos tpid[(int)self->conn_p] = self->pid; 444 1.1 christos } 445 1.1 christos 446 1.1 christos /* 447 1.1 christos * TCP Complete printing outbound handshake 448 1.1 christos */ 449 1.1 christos fbt:ip:tcp_connect:return 450 1.1 christos /self->connp/ 451 1.1 christos { 452 1.1 christos self->name = tname[(int)self->connp]; 453 1.1 christos self->pid = tpid[(int)self->connp]; 454 1.1 christos self->uid = tuid[(int)self->connp]; 455 1.1 christos self->zoneid = self->connp->conn_zoneid; 456 1.1 christos OPT_proj ? self->proj = tproj[(int)self->connp] : 1; 457 1.1 christos self->size = 54; /* should check trailers */ 458 1.1 christos self->dir = "->"; 459 1.1 christos } 460 1.1 christos 461 1.1 christos fbt:ip:tcp_connect:return 462 1.1 christos /(self->connp) && 463 1.1 christos ((FILTER == 0) || 464 1.1 christos (OPT_pid && self->pid == PID) || 465 1.1 christos (OPT_name && self->name == NAME))/ 466 1.1 christos { 467 1.1 christos /* this packet occured before connp was fully established */ 468 1.1 christos OPT_time ? printf("%-14d ", timestamp/1000) : 1; 469 1.1 christos OPT_timestr ? printf("%-20Y ", walltimestamp) : 1; 470 1.1 christos OPT_zone ? printf("%4d ", self->zoneid) : 1; 471 1.1 christos OPT_proj ? printf("%4d ", self->proj) : 1; 472 1.1 christos printf("%5d %6d %-15s %5d %2s %-15s %5d %5d %s\n", 473 1.1 christos self->uid, self->pid, self->laddr, self->lport, self->dir, 474 1.1 christos self->faddr, self->fport, self->size, self->name); 475 1.1 christos } 476 1.1 christos 477 1.1 christos /* 478 1.1 christos * TCP Complete printing inbound handshake 479 1.1 christos */ 480 1.1 christos fbt:sockfs:sotpi_accept:return 481 1.1 christos /self->connp/ 482 1.1 christos { 483 1.1 christos self->name = tname[(int)self->connp]; 484 1.1 christos self->pid = tpid[(int)self->connp]; 485 1.1 christos self->uid = tuid[(int)self->connp]; 486 1.1 christos self->zoneid = self->connp->conn_zoneid; 487 1.1 christos OPT_proj ? self->proj = tproj[(int)self->connp] : 1; 488 1.1 christos self->size = 54; /* should check trailers */ 489 1.1 christos self->dir = "<-"; 490 1.1 christos } 491 1.1 christos 492 1.1 christos fbt:sockfs:sotpi_accept:return 493 1.1 christos /(self->connp) && 494 1.1 christos ((FILTER == 0) || 495 1.1 christos (OPT_pid && self->pid == PID) || 496 1.1 christos (OPT_name && self->name == NAME))/ 497 1.1 christos { 498 1.1 christos /* these packets occured before connp was fully established */ 499 1.1 christos OPT_time ? printf("%-14d ", timestamp/1000) : 1; 500 1.1 christos OPT_timestr ? printf("%-20Y ", walltimestamp) : 1; 501 1.1 christos OPT_zone ? printf("%4d ", self->zoneid) : 1; 502 1.1 christos OPT_proj ? printf("%4d ", self->proj) : 1; 503 1.1 christos printf("%5d %6d %-15s %5d %2s %-15s %5d %5d %s\n", 504 1.1 christos self->uid, self->pid, self->laddr, self->lport, self->dir, 505 1.1 christos self->faddr, self->fport, self->size, self->name); 506 1.1 christos self->dir = "->"; 507 1.1 christos OPT_time ? printf("%-14d ", timestamp/1000) : 1; 508 1.1 christos OPT_timestr ? printf("%-20Y ", walltimestamp) : 1; 509 1.1 christos OPT_zone ? printf("%4d ", self->zoneid) : 1; 510 1.1 christos OPT_proj ? printf("%4d ", self->proj) : 1; 511 1.1 christos printf("%5d %6d %-15s %5d %2s %-15s %5d %5d %s\n", 512 1.1 christos self->uid, self->pid, self->laddr, self->lport, self->dir, 513 1.1 christos self->faddr, self->fport, self->size, self->name); 514 1.1 christos self->dir = "<-"; 515 1.1 christos OPT_time ? printf("%-14d ", timestamp/1000) : 1; 516 1.1 christos OPT_timestr ? printf("%-20Y ", walltimestamp) : 1; 517 1.1 christos OPT_zone ? printf("%4d ", self->zoneid) : 1; 518 1.1 christos OPT_proj ? printf("%4d ", self->proj) : 1; 519 1.1 christos printf("%5d %6d %-15s %5d %2s %-15s %5d %5d %s\n", 520 1.1 christos self->uid, self->pid, self->laddr, self->lport, self->dir, 521 1.1 christos self->faddr, self->fport, self->size, self->name); 522 1.1 christos } 523 1.1 christos 524 1.1 christos /* 525 1.1 christos * Print output 526 1.1 christos */ 527 1.1 christos fbt:ip:tcp_send_data:entry, 528 1.1 christos fbt:ip:tcp_rput_data:entry 529 1.1 christos /(self->ok == 2) && 530 1.1 christos ((FILTER == 0) || 531 1.1 christos (OPT_pid && self->pid == PID) || 532 1.1 christos (OPT_name && self->name == NAME))/ 533 1.1 christos { 534 1.1 christos /* print optional fields */ 535 1.1 christos OPT_time ? printf("%-14d ", timestamp/1000) : 1; 536 1.1 christos OPT_timestr ? printf("%-20Y ", walltimestamp) : 1; 537 1.1 christos OPT_zone ? printf("%4d ", self->zoneid) : 1; 538 1.1 christos OPT_proj ? printf("%4d ", self->proj) : 1; 539 1.1 christos 540 1.1 christos /* print output line */ 541 1.1 christos printf("%5d %6d %-15s %5d %2s %-15s %5d %5d %s\n", 542 1.1 christos self->uid, self->pid, self->laddr, self->lport, self->dir, 543 1.1 christos self->faddr, self->fport, self->size, self->name); 544 1.1 christos } 545 1.1 christos 546 1.1 christos /* 547 1.1 christos * TCP Clear connect variables 548 1.1 christos */ 549 1.1 christos fbt:sockfs:sotpi_accept:return, 550 1.1 christos fbt:ip:tcp_connect:return 551 1.1 christos /self->connp/ 552 1.1 christos { 553 1.1 christos self->faddr = 0; 554 1.1 christos self->laddr = 0; 555 1.1 christos self->fport = 0; 556 1.1 christos self->lport = 0; 557 1.1 christos self->connp = 0; 558 1.1 christos self->name = 0; 559 1.1 christos self->pid = 0; 560 1.1 christos self->uid = 0; 561 1.1 christos } 562 1.1 christos 563 1.1 christos /* 564 1.1 christos * TCP Clear r/w variables 565 1.1 christos */ 566 1.1 christos fbt:ip:tcp_send_data:entry, 567 1.1 christos fbt:ip:tcp_rput_data:entry 568 1.1 christos { 569 1.1 christos self->ok = 0; 570 1.1 christos self->dir = 0; 571 1.1 christos self->uid = 0; 572 1.1 christos self->pid = 0; 573 1.1 christos self->size = 0; 574 1.1 christos self->name = 0; 575 1.1 christos self->lport = 0; 576 1.1 christos self->fport = 0; 577 1.1 christos self->laddr = 0; 578 1.1 christos self->faddr = 0; 579 1.1 christos self->conn_p = 0; 580 1.1 christos self->zoneid = 0; 581 1.1 christos self->proj = 0; 582 1.1 christos } 583 1.1 christos ') 584