1279727Sgnn#!/usr/sbin/dtrace -s
2279727Sgnn/*
3279727Sgnn * Copyright (c) 2015 George V. Neville-Neil
4279727Sgnn * All rights reserved.
5279727Sgnn *
6279727Sgnn * Redistribution and use in source and binary forms, with or without
7279727Sgnn * modification, are permitted provided that the following conditions
8279727Sgnn * are met:
9279727Sgnn * 1. Redistributions of source code must retain the above copyright
10279727Sgnn *    notice, this list of conditions and the following disclaimer.
11279727Sgnn * 2. Redistributions in binary form must reproduce the above copyright
12279727Sgnn *    notice, this list of conditions and the following disclaimer in the
13279727Sgnn *    documentation and/or other materials provided with the distribution.
14279727Sgnn *
15279727Sgnn * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16279727Sgnn * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17279727Sgnn * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18279727Sgnn * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19279727Sgnn * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20279727Sgnn * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21279727Sgnn * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22279727Sgnn * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23279727Sgnn * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24279727Sgnn * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25279727Sgnn * SUCH DAMAGE.
26279727Sgnn *
27279727Sgnn * $FreeBSD: releng/11.0/share/dtrace/tcpstate 279765 2015-03-08 02:47:38Z gnn $
28279727Sgnn *
29279727Sgnn * The tcpstate D script shows TCP sockets transitioning between states.
30279727Sgnn *
31279727Sgnn * Usage: tcpstate
32279727Sgnn */
33279727Sgnn
34279727Sgnn#pragma D option quiet
35279727SgnnBEGIN
36279727Sgnn{
37279727Sgnn	printf("Old State\t\tNew State\n");
38279727Sgnn}
39279727Sgnn
40279727Sgnntcp:kernel::state-change
41279727Sgnn{
42279727Sgnn	newstate = args[3]->tcps_state;
43279727Sgnn	oldstate = args[5]->tcps_state;
44279765Sgnn	printf("%s\t\t%s\n", tcp_state_string[oldstate],
45279727Sgnn			     tcp_state_string[newstate]);
46279727Sgnn}
47