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