tcp_trace.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (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
* 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 1998, 2003 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <inet/tcp_trace.h>
#include <inet/ipclassifier.h>
/*
* Get TCP trace buffer address.
*/
/*
* Get TCP module id.
* NOTE: TCP module id is defined in tcp.c.
*/
/*
* MAKE_DIGIT(), and its friend, MAKE_DIGIT_20() format an unsigned integer
* value (cookie) into a buffer, taking base into account. Their behavior is
* quite similar to sprintf(buf, "%u", cookie) or sprintf(buf, "%x", cookie).
*
* The string is assumed to contain '0's in the appropriate places, so we need
* only call make_digit() when cookie has a nonzero value.
*/
if (cookie) { \
} \
}
/*
* Both IP header length which has no optional field (IP_SIMPLE_HDR_LENGTH)
* and TCP header length which has no optional field (TCP_MIN_HEADER_LENGTH)
* are 20(0x14) bytes so we set the default value (0x14) in the initial buffer
* call make_digit() only when necessary.
*/
if (cookie != TCP_MIN_HEADER_LENGTH) { \
} \
}
/*
*/
void
{
int iph_length;
int tcph_length;
int trace_rec_pos;
struct tcp_trace_header *traceinfo;
struct tcp_trace_rec *trace_evt_p;
/*
* XXX This module currently has no support for IPv6.
* XXX It explicitly assumes IPv4 and will panic the system
* XXX while tracing v6 connections if it explicitly dereferences
* XXX
* XXX To avoid this until v6 support is added,
* XXX return immediately if tcp->tcp_ipversion == IPV6_VERSION
*/
return;
/*
* If this is a segment needing TCP-directed IPsec protection
* (e.g. a segment from a detached connection), make sure the
* IPsec info is bypassed for tracing.
*/
if (flag == TCP_TRACE_SEND_PKT) {
} else {
/* TCP_TRACE_RECV_PKT */
}
/*
* When the RST packet is transmitted or received,
* information on as many as 10 packets which were
* transmited or received is saved on the DISK by
* calling tcp_report_trace().
*/
if (tcph_flags & TH_RST) {
}
if (++trace_rec_pos == TCP_TRACE_NREC) {
trace_rec_pos = 0;
}
}
/*
* TCP trace output data fromat.
*
* char logbuf[] = \
* 01234567
* "TCP TAS\n
* 8901234567890123456789012345678901234567890123456789012345678901234
* Local 000.000.000.000:00000 <--> Remote 000.000.000.000:00000\n\
* 567890123456789012345678901234567890123456789012345678901234567
* Conn time 0000/00/00 00:00:00 GMT. Wscale snd 00. rcv 00.\n\
* 8901234567890123456789012345678901234567890123456789012345678901234567
* iss 00000000, irs 00000000. Pcnt snd 0000000000. rcv 0000000000.\n\
* 8901234567890123456789012345678901234567890123456789012345678901234
* 56789012345678901234567890123456789012345678901234567890123456789
* 00:00:00.000.000 R 00000000 00000000 0000 0000 00 00 00\n"
*/
static const char log_format[] = \
"TCP RAS\n" \
" Local 000.000.000.000:00000 <--> Remote 000.000.000.000:00000\n" \
" Conn time 0000/00/00 00:00:00 GMT. Wscale snd 00. rcv 00.\n" \
" iss 00000000, irs 00000000. Pcnt snd 0000000000. rcv 0000000000.\n" \
" 00:00:00.000.000 R 00000000 00000000 0000 0000 14 14 00\n" \
" 00:00:00.000.000 R 00000000 00000000 0000 0000 14 14 00\n" \
" 00:00:00.000.000 R 00000000 00000000 0000 0000 14 14 00\n" \
" 00:00:00.000.000 R 00000000 00000000 0000 0000 14 14 00\n" \
" 00:00:00.000.000 R 00000000 00000000 0000 0000 14 14 00\n" \
" 00:00:00.000.000 R 00000000 00000000 0000 0000 14 14 00\n" \
" 00:00:00.000.000 R 00000000 00000000 0000 0000 14 14 00\n" \
" 00:00:00.000.000 R 00000000 00000000 0000 0000 14 14 00\n" \
" 00:00:00.000.000 R 00000000 00000000 0000 0000 14 14 00\n" \
" 00:00:00.000.000 R 00000000 00000000 0000 0000 14 14 00\n";
/*
* Offset (within the log_format string) of the beginning of tcp_t and
* tcp_trace_header data. For example,
*
* " Local 000.000.000.000:00000 <--> Remote 000.000.000.000:00000\n"
* ^ ^
* | |
* &log_format[LOC_IPADDR] |
* &log_format[LOC_PORTN]
* and so on.
*
* N.B.: these values are truly hardwired and the danger in changing them is
* extreme, since they are used directly as offsets into which bytes of
* formatted data are stuffed.
*/
/*
* Offset (within a single trace line) of tcp_trace_rec data. For example, in
* this line,
*
* " 00:00:00.000.000 R 00000000 00000000 0000 0000 14 14 00\n";
* -----> this length is TRC_DATA_TIME
* -----------------------> this length is TRC_DATA_SR
*
* and so on.
*
* N.B.: these values are truly hardwired and the danger in changing them is
* extreme, since they are used directly as offsets into which bytes of
* formatted data are stuffed.
*/
/*
* Make printable trace data and log it using strlog().
*/
static void
{
short sid = 0;
short mid = 0;
char *cur_logbuf_ptr;
int cur_pos;
int rec_no;
int nrecords; /* # of packet trace lines to print */
int rec_start; /* where to start in evts[] array */
cur_hrtime = gethrtime();
/*
* trace report header construct
*/
/* Initialize log format data */
/* Local IP address */
/* Local Port number */
/* Remote IP address */
/* Remote Port number */
/* Connection date & time */
/* Wscale snd & rcv */
/* Initial send seq number */
/* Initial recv seq number */
/* total traced sent packets */
/* total traced recv packets */
/*
* The evts[] array contains information about up to TCP_TRACE_NREC
* packets. We assume that the information is either recorded in
* slots 0 through traceinfo->tcptrh_currec (in which case, slots
* traceinfo->tcptrh_currec + 1 through TCP_TRACE_NREC - 1 must be
* unused) or wraparound has occurred and all TCP_TRACE_NREC slots
* are in use.
*/
if ((cur_pos < TCP_TRACE_NREC) &&
TCP_TRACE_NOENT)) {
/* Log records 0 through traceinfo->tcptrh_currec */
rec_start = 0;
#ifdef DEBUG
/* test the assumption outlined above */
}
#endif /* DEBUG */
} else {
/*
* Log TCP_TRACE_NREC records starting at
* traceinfo->tcptrh_currec + 1, wrapping,
* and ending at traceinfo->tcptrh_currec
*/
}
}
/* overwrite last '\n' */
/*
* We use strlog() to log trace data. mi_strlog()'s buffer
* size is only 200 bytes. We need more than 928 bytes buffer.
* strlog() has 1024 bytes buffer, so we use strlog().
*/
}
/*
* Formatting event data.
*/
static void
{
/*
* calculate trace time
*/
/*
* Time
* NOTE: The separators of time field which are ":" and "." are
* statically set in buffer.
*/
/*
* Event (Send or Recv flag)
* NOTE: The default value of event field is "R"
* which is statically set in buffer.
*/
}
/*
* Sequence number, Acknowledge number, Packet data length,
* and Window size
*/
/*
* IP and TCP Header length
*/
2);
/*
* Control flags
*/
/*
* NOTE: Newline code "\n" per lines are statically set in buffer.
*/
}
/*
* make_digit() formats an unsigned integer value (cookie) into a buffer,
* taking base into account. Its behavior is quite similar to
* sprintf(buf, "%u", cookie) or sprintf(buf, "%x", cookie).
*/
static void
{
static char hex_val[] = "0123456789abcdef";
do {
if (--scale == 0) {
break;
}
}