--- /dev/null Fri Aug 29 10:35:08 2008 +++ new/usr/src/lib/libdtrace/common/tcp.d.in Fri Aug 29 10:35:06 2008 @@ -0,0 +1,149 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma D depends_on module unix +#pragma D depends_on provider tcp + +inline int TH_FIN = @TH_FIN@; +#pragma D binding "1.0" TH_FIN +inline int TH_SYN = @TH_SYN@; +#pragma D binding "1.0" TH_SYN +inline int TH_RST = @TH_RST@; +#pragma D binding "1.0" TH_RST +inline int TH_PUSH = @TH_PUSH@; +#pragma D binding "1.0" TH_PUSH +inline int TH_ACK = @TH_ACK@; +#pragma D binding "1.0" TH_ACK +inline int TH_URG = @TH_URG@; +#pragma D binding "1.0" TH_URG +inline int TH_ECE = @TH_ECE@; +#pragma D binding "1.0" TH_ECE +inline int TH_CWR = @TH_CWR@; +#pragma D binding "1.0" TH_CWR + +/* + * tcpinfo is the TCP header fields. + */ +typedef struct tcpinfo { + uint16_t tcp_sport; /* source port */ + uint16_t tcp_dport; /* destination port */ + uint32_t tcp_seq; /* sequence number */ + uint32_t tcp_ack; /* acknowledgment number */ + uint8_t tcp_offset; /* data offset, in bytes */ + uint8_t tcp_flags; /* flags */ + uint16_t tcp_window; /* window size */ + uint16_t tcp_checksum; /* checksum */ + uint16_t tcp_urgent; /* urgent data pointer */ + tcph_t *tcp_hdr; /* raw TCP header */ +} tcpinfo_t; + +/* + * tcpsinfo contains stable TCP details from tcp_t. + */ +typedef struct tcpsinfo { + int tcps_local; /* is delivered locally, boolean */ + int tcps_active; /* active open (from here), boolean */ + string tcps_state; /* TCP state, as a string */ +} tcpsinfo_t; + +/* + * tcpnsinfo provides the new tcp state for state changes. + */ +typedef struct tcpnsinfo { + string tcps_state; /* TCP state, as a string */ +} tcpnsinfo_t; + +/* + * tcpfinfo contains additional TCP details from tcp_t, that are stable + * for local (tcp-fusion) connections. + */ +typedef struct tcpfinfo { + uint16_t tcpf_sport; /* source port */ + uint16_t tcpf_dport; /* destination port */ +} tcpfinfo_t; + +#pragma D binding "1.0" translator +translator tcpinfo_t < tcph_t *T > { + tcp_sport = ntohs(*(uint16_t *)T->th_lport); + tcp_dport = ntohs(*(uint16_t *)T->th_fport); + tcp_seq = ntohl(*(uint32_t *)T->th_seq); + tcp_ack = ntohl(*(uint32_t *)T->th_ack); + tcp_offset = (*(uint8_t *)T->th_offset_and_rsrvd & 0xf0) >> 2; + tcp_flags = *(uint8_t *)T->th_flags; + tcp_window = ntohs(*(uint16_t *)T->th_win); + tcp_checksum = ntohs(*(uint16_t *)T->th_sum); + tcp_urgent = ntohs(*(uint16_t *)T->th_urp); + tcp_hdr = T; +}; + +#pragma D binding "1.0" translator +translator tcpsinfo_t < tcp_t *T > { + tcps_local = T ? T->tcp_loopback : 0; + tcps_active = T ? T->tcp_active_open : 0; + tcps_state = T ? + T->tcp_state == @TCPS_CLOSED@ ? "state-closed" : + T->tcp_state == @TCPS_IDLE@ ? "state-idle" : + T->tcp_state == @TCPS_BOUND@ ? "state-bound" : + T->tcp_state == @TCPS_LISTEN@ ? "state-listen" : + T->tcp_state == @TCPS_SYN_SENT@ ? "state-syn-sent" : + T->tcp_state == @TCPS_SYN_RCVD@ ? "state-syn-received" : + T->tcp_state == @TCPS_ESTABLISHED@ ? "state-established" : + T->tcp_state == @TCPS_CLOSE_WAIT@ ? "state-close-wait" : + T->tcp_state == @TCPS_FIN_WAIT_1@ ? "state-fin-wait1" : + T->tcp_state == @TCPS_CLOSING@ ? "state-closing" : + T->tcp_state == @TCPS_LAST_ACK@ ? "state-last-ack" : + T->tcp_state == @TCPS_FIN_WAIT_2@ ? "state-fin-wait2" : + T->tcp_state == @TCPS_TIME_WAIT@ ? "state-time-wait" : + "" : "unknown"; +}; + +#pragma D binding "1.0" translator +translator tcpnsinfo_t < int32_t I > { + tcps_state = + I == @TCPS_CLOSED@ ? "state-closed" : + I == @TCPS_IDLE@ ? "state-idle" : + I == @TCPS_BOUND@ ? "state-bound" : + I == @TCPS_LISTEN@ ? "state-listen" : + I == @TCPS_SYN_SENT@ ? "state-syn-sent" : + I == @TCPS_SYN_RCVD@ ? "state-syn-received" : + I == @TCPS_ESTABLISHED@ ? "state-established" : + I == @TCPS_CLOSE_WAIT@ ? "state-close-wait" : + I == @TCPS_FIN_WAIT_1@ ? "state-fin-wait1" : + I == @TCPS_CLOSING@ ? "state-closing" : + I == @TCPS_LAST_ACK@ ? "state-last-ack" : + I == @TCPS_FIN_WAIT_2@ ? "state-fin-wait2" : + I == @TCPS_TIME_WAIT@ ? "state-time-wait" : + ""; +}; + +#pragma D binding "1.0" translator +translator tcpfinfo_t < tcp_t *T > { + tcpf_sport = probename == "send" ? + ntohs(T->tcp_connp->u_port.tcpu_ports.tcpu_lport) : + ntohs(T->tcp_connp->u_port.tcpu_ports.tcpu_fport); + tcpf_dport = probename == "send" ? + ntohs(T->tcp_connp->u_port.tcpu_ports.tcpu_fport) : + ntohs(T->tcp_connp->u_port.tcpu_ports.tcpu_lport); +};