1279739Sgnn#!/usr/sbin/dtrace -s 2279739Sgnn/* 3279739Sgnn * Copyright (c) 2015 George V. Neville-Neil 4279739Sgnn * All rights reserved. 5279739Sgnn * 6279739Sgnn * Redistribution and use in source and binary forms, with or without 7279739Sgnn * modification, are permitted provided that the following conditions 8279739Sgnn * are met: 9279739Sgnn * 1. Redistributions of source code must retain the above copyright 10279739Sgnn * notice, this list of conditions and the following disclaimer. 11279739Sgnn * 2. Redistributions in binary form must reproduce the above copyright 12279739Sgnn * notice, this list of conditions and the following disclaimer in the 13279739Sgnn * documentation and/or other materials provided with the distribution. 14279739Sgnn * 15279739Sgnn * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16279739Sgnn * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17279739Sgnn * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18279739Sgnn * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19279739Sgnn * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20279739Sgnn * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21279739Sgnn * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22279739Sgnn * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23279739Sgnn * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24279739Sgnn * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25279739Sgnn * SUCH DAMAGE. 26279739Sgnn * 27279739Sgnn * $FreeBSD$ 28279739Sgnn * 29279739Sgnn * The tcptrack D script shows various information about TCP 30279739Sgnn * connections including acceptance and refusal of inbound and 31279739Sgnn * outbound connections as well as state changes. 32279739Sgnn * 33279739Sgnn * Usage: tcptrack 34279739Sgnn */ 35279739Sgnn 36279739Sgnn#pragma D option quiet 37279739Sgnntcp:kernel::accept-established 38279739Sgnn{ 39279739Sgnn printf("Accept connection from %s:%d\tto %s:%d\n", 40279739Sgnn args[2]->ip_saddr, 41279739Sgnn args[4]->tcp_sport, 42279739Sgnn args[2]->ip_daddr, 43279739Sgnn args[4]->tcp_dport); 44279739Sgnn 45279739Sgnn} 46279739Sgnn 47279739Sgnntcp:kernel::accept-refused 48279739Sgnn{ 49279739Sgnn printf("Refused connection from %s:%d\tto %s:%d\n", 50279739Sgnn args[2]->ip_daddr, 51279739Sgnn args[4]->tcp_dport, 52279739Sgnn args[2]->ip_saddr, 53279739Sgnn args[4]->tcp_sport); 54279739Sgnn 55279739Sgnn} 56279739Sgnn 57279739Sgnntcp:kernel::connect-established 58279739Sgnn{ 59279739Sgnn printf("Connection established to %s:%d from %s:%d\n", 60279739Sgnn args[2]->ip_saddr, 61279739Sgnn args[4]->tcp_sport, 62279739Sgnn args[2]->ip_daddr, 63279739Sgnn args[4]->tcp_dport); 64279739Sgnn 65279739Sgnn} 66279739Sgnn 67279739Sgnntcp:kernel::connect-refused 68279739Sgnn{ 69279739Sgnn printf("Connection refused by %s:%d from %s:%d\n", 70279739Sgnn args[2]->ip_saddr, 71279739Sgnn args[4]->tcp_sport, 72279739Sgnn args[2]->ip_daddr, 73279739Sgnn args[4]->tcp_dport); 74279739Sgnn} 75279739Sgnn 76279739Sgnntcp:kernel::state-change 77279739Sgnn{ 78279739Sgnn newstate = args[3]->tcps_state; 79279739Sgnn oldstate = args[5]->tcps_state; 80279739Sgnn printf("State changed from %s\t\t%s\n", tcp_state_string[oldstate], 81279739Sgnn tcp_state_string[newstate]); 82279739Sgnn} 83279739Sgnn 84