xref: /freebsd/sys/netinet/tcp_log_buf.h (revision e24e5683361e88f6ac6f8b10b90ce87e07035512)
12529f56eSJonathan T. Looney /*-
22529f56eSJonathan T. Looney  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
32529f56eSJonathan T. Looney  *
42529f56eSJonathan T. Looney  * Copyright (c) 2016-2018
52529f56eSJonathan T. Looney  *	Netflix Inc.  All rights reserved.
62529f56eSJonathan T. Looney  *
72529f56eSJonathan T. Looney  * Redistribution and use in source and binary forms, with or without
82529f56eSJonathan T. Looney  * modification, are permitted provided that the following conditions
92529f56eSJonathan T. Looney  * are met:
102529f56eSJonathan T. Looney  * 1. Redistributions of source code must retain the above copyright
112529f56eSJonathan T. Looney  *    notice, this list of conditions and the following disclaimer.
122529f56eSJonathan T. Looney  * 2. Redistributions in binary form must reproduce the above copyright
132529f56eSJonathan T. Looney  *    notice, this list of conditions and the following disclaimer in the
142529f56eSJonathan T. Looney  *    documentation and/or other materials provided with the distribution.
152529f56eSJonathan T. Looney  *
162529f56eSJonathan T. Looney  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
172529f56eSJonathan T. Looney  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
182529f56eSJonathan T. Looney  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
192529f56eSJonathan T. Looney  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
202529f56eSJonathan T. Looney  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
212529f56eSJonathan T. Looney  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
222529f56eSJonathan T. Looney  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
232529f56eSJonathan T. Looney  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
242529f56eSJonathan T. Looney  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
252529f56eSJonathan T. Looney  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
262529f56eSJonathan T. Looney  * SUCH DAMAGE.
272529f56eSJonathan T. Looney  *
282529f56eSJonathan T. Looney  * $FreeBSD$
292529f56eSJonathan T. Looney  */
302529f56eSJonathan T. Looney 
312529f56eSJonathan T. Looney #ifndef __tcp_log_buf_h__
322529f56eSJonathan T. Looney #define __tcp_log_buf_h__
332529f56eSJonathan T. Looney 
342529f56eSJonathan T. Looney #define	TCP_LOG_REASON_LEN	32
352529f56eSJonathan T. Looney #define	TCP_LOG_BUF_VER		(6)
362529f56eSJonathan T. Looney 
372529f56eSJonathan T. Looney /*
382529f56eSJonathan T. Looney  * Because the (struct tcp_log_buffer) includes 8-byte uint64_t's, it requires
392529f56eSJonathan T. Looney  * 8-byte alignment to work properly on all platforms. Therefore, we will
402529f56eSJonathan T. Looney  * enforce 8-byte alignment for all the structures that may appear by
412529f56eSJonathan T. Looney  * themselves (instead of being embedded in another structure) in a data
422529f56eSJonathan T. Looney  * stream.
432529f56eSJonathan T. Looney  */
442529f56eSJonathan T. Looney #define	ALIGN_TCP_LOG		__aligned(8)
452529f56eSJonathan T. Looney 
462529f56eSJonathan T. Looney /* Information about the socketbuffer state. */
472529f56eSJonathan T. Looney struct tcp_log_sockbuf
482529f56eSJonathan T. Looney {
492529f56eSJonathan T. Looney 	uint32_t	tls_sb_acc;	/* available chars (sb->sb_acc) */
502529f56eSJonathan T. Looney 	uint32_t	tls_sb_ccc;	/* claimed chars (sb->sb_ccc) */
512529f56eSJonathan T. Looney 	uint32_t	tls_sb_spare;	/* spare */
522529f56eSJonathan T. Looney };
532529f56eSJonathan T. Looney 
542529f56eSJonathan T. Looney /* Optional, verbose information that may be appended to an event log. */
552529f56eSJonathan T. Looney struct tcp_log_verbose
562529f56eSJonathan T. Looney {
572529f56eSJonathan T. Looney #define	TCP_FUNC_LEN	32
582529f56eSJonathan T. Looney 	char		tlv_snd_frm[TCP_FUNC_LEN]; /* tcp_output() caller */
592529f56eSJonathan T. Looney 	char		tlv_trace_func[TCP_FUNC_LEN]; /* Function that
602529f56eSJonathan T. Looney 							 generated trace */
612529f56eSJonathan T. Looney 	uint32_t	tlv_trace_line;	/* Line number that generated trace */
622529f56eSJonathan T. Looney 	uint8_t		_pad[4];
632529f56eSJonathan T. Looney } ALIGN_TCP_LOG;
642529f56eSJonathan T. Looney 
652529f56eSJonathan T. Looney /* Internal RACK state variables. */
662529f56eSJonathan T. Looney struct tcp_log_rack
672529f56eSJonathan T. Looney {
682529f56eSJonathan T. Looney 	uint32_t	tlr_rack_rtt;		/* rc_rack_rtt */
692529f56eSJonathan T. Looney 	uint8_t		tlr_state;		/* Internal RACK state */
702529f56eSJonathan T. Looney 	uint8_t		_pad[3];		/* Padding */
712529f56eSJonathan T. Looney };
722529f56eSJonathan T. Looney 
732529f56eSJonathan T. Looney struct tcp_log_bbr {
742529f56eSJonathan T. Looney 	uint64_t cur_del_rate;
752529f56eSJonathan T. Looney 	uint64_t delRate;
762529f56eSJonathan T. Looney 	uint64_t rttProp;
772529f56eSJonathan T. Looney 	uint64_t bw_inuse;
782529f56eSJonathan T. Looney 	uint32_t inflight;
792529f56eSJonathan T. Looney 	uint32_t applimited;
802529f56eSJonathan T. Looney 	uint32_t delivered;
812529f56eSJonathan T. Looney 	uint32_t timeStamp;
822529f56eSJonathan T. Looney 	uint32_t epoch;
832529f56eSJonathan T. Looney 	uint32_t lt_epoch;
842529f56eSJonathan T. Looney 	uint32_t pkts_out;
852529f56eSJonathan T. Looney 	uint32_t flex1;
862529f56eSJonathan T. Looney 	uint32_t flex2;
872529f56eSJonathan T. Looney 	uint32_t flex3;
882529f56eSJonathan T. Looney 	uint32_t flex4;
892529f56eSJonathan T. Looney 	uint32_t flex5;
902529f56eSJonathan T. Looney 	uint32_t flex6;
912529f56eSJonathan T. Looney 	uint32_t lost;
922529f56eSJonathan T. Looney 	uint16_t pacing_gain;
932529f56eSJonathan T. Looney 	uint16_t cwnd_gain;
942529f56eSJonathan T. Looney 	uint16_t flex7;
952529f56eSJonathan T. Looney 	uint8_t bbr_state;
962529f56eSJonathan T. Looney 	uint8_t bbr_substate;
972529f56eSJonathan T. Looney 	uint8_t inpacer;
982529f56eSJonathan T. Looney 	uint8_t ininput;
992529f56eSJonathan T. Looney 	uint8_t use_lt_bw;
1002529f56eSJonathan T. Looney 	uint8_t flex8;
1012529f56eSJonathan T. Looney 	uint32_t pkt_epoch;
1022529f56eSJonathan T. Looney };
1032529f56eSJonathan T. Looney 
1042529f56eSJonathan T. Looney /* Per-stack stack-specific info. */
1052529f56eSJonathan T. Looney union tcp_log_stackspecific
1062529f56eSJonathan T. Looney {
1072529f56eSJonathan T. Looney 	struct tcp_log_rack u_rack;
1082529f56eSJonathan T. Looney 	struct tcp_log_bbr u_bbr;
1092529f56eSJonathan T. Looney };
1102529f56eSJonathan T. Looney 
1112529f56eSJonathan T. Looney struct tcp_log_buffer
1122529f56eSJonathan T. Looney {
1132529f56eSJonathan T. Looney 	/* Event basics */
1142529f56eSJonathan T. Looney 	struct timeval	tlb_tv;		/* Timestamp of trace */
1152529f56eSJonathan T. Looney 	uint32_t	tlb_ticks;	/* Timestamp of trace */
1162529f56eSJonathan T. Looney 	uint32_t	tlb_sn;		/* Serial number */
1172529f56eSJonathan T. Looney 	uint8_t		tlb_stackid;	/* Stack ID */
1182529f56eSJonathan T. Looney 	uint8_t		tlb_eventid;	/* Event ID */
1192529f56eSJonathan T. Looney 	uint16_t	tlb_eventflags;	/* Flags for the record */
1202529f56eSJonathan T. Looney #define	TLB_FLAG_RXBUF		0x0001	/* Includes receive buffer info */
1212529f56eSJonathan T. Looney #define	TLB_FLAG_TXBUF		0x0002	/* Includes send buffer info */
1222529f56eSJonathan T. Looney #define	TLB_FLAG_HDR		0x0004	/* Includes a TCP header */
1232529f56eSJonathan T. Looney #define	TLB_FLAG_VERBOSE	0x0008	/* Includes function/line numbers */
1242529f56eSJonathan T. Looney #define	TLB_FLAG_STACKINFO	0x0010	/* Includes stack-specific info */
1252529f56eSJonathan T. Looney 	int		tlb_errno;	/* Event error (if any) */
1262529f56eSJonathan T. Looney 
1272529f56eSJonathan T. Looney 	/* Internal session state */
1282529f56eSJonathan T. Looney 	struct tcp_log_sockbuf tlb_rxbuf; /* Receive buffer */
1292529f56eSJonathan T. Looney 	struct tcp_log_sockbuf tlb_txbuf; /* Send buffer */
1302529f56eSJonathan T. Looney 
1312529f56eSJonathan T. Looney 	int		tlb_state;	/* TCPCB t_state */
1322529f56eSJonathan T. Looney 	uint32_t	tlb_starttime;	/* TCPCB t_starttime */
1332529f56eSJonathan T. Looney 	uint32_t	tlb_iss;		/* TCPCB iss */
1342529f56eSJonathan T. Looney 	uint32_t	tlb_flags;	/* TCPCB flags */
1352529f56eSJonathan T. Looney 	uint32_t	tlb_snd_una;	/* TCPCB snd_una */
1362529f56eSJonathan T. Looney 	uint32_t	tlb_snd_max;	/* TCPCB snd_max */
1372529f56eSJonathan T. Looney 	uint32_t	tlb_snd_cwnd;	/* TCPCB snd_cwnd */
1382529f56eSJonathan T. Looney 	uint32_t	tlb_snd_nxt;	/* TCPCB snd_nxt */
1392529f56eSJonathan T. Looney 	uint32_t	tlb_snd_recover;/* TCPCB snd_recover */
1402529f56eSJonathan T. Looney 	uint32_t	tlb_snd_wnd;	/* TCPCB snd_wnd */
1412529f56eSJonathan T. Looney 	uint32_t	tlb_snd_ssthresh; /* TCPCB snd_ssthresh */
1422529f56eSJonathan T. Looney 	uint32_t	tlb_srtt;	/* TCPCB t_srtt */
1432529f56eSJonathan T. Looney 	uint32_t	tlb_rttvar;	/* TCPCB t_rttvar */
1442529f56eSJonathan T. Looney 	uint32_t	tlb_rcv_up;	/* TCPCB rcv_up */
1452529f56eSJonathan T. Looney 	uint32_t	tlb_rcv_adv;	/* TCPCB rcv_adv */
1462529f56eSJonathan T. Looney 	uint32_t	tlb_rcv_nxt;	/* TCPCB rcv_nxt */
1472529f56eSJonathan T. Looney 	tcp_seq		tlb_sack_newdata; /* TCPCB sack_newdata */
1482529f56eSJonathan T. Looney 	uint32_t       	tlb_rcv_wnd;	/* TCPCB rcv_wnd */
1492529f56eSJonathan T. Looney 	uint32_t	tlb_dupacks;	/* TCPCB t_dupacks */
1502529f56eSJonathan T. Looney 	int		tlb_segqlen;	/* TCPCB segqlen */
1512529f56eSJonathan T. Looney 	int		tlb_snd_numholes; /* TCPCB snd_numholes */
1522529f56eSJonathan T. Looney 	uint32_t 	tlb_flex1; /* Event specific information */
1532529f56eSJonathan T. Looney 	uint32_t 	tlb_flex2; /* Event specific information */
1542529f56eSJonathan T. Looney 	uint8_t		tlb_snd_scale:4, /* TCPCB snd_scale */
1552529f56eSJonathan T. Looney 			tlb_rcv_scale:4; /* TCPCB rcv_scale */
1562529f56eSJonathan T. Looney 	uint8_t		_pad[3];	/* Padding */
1572529f56eSJonathan T. Looney 
1582529f56eSJonathan T. Looney 	/* Per-stack info */
1592529f56eSJonathan T. Looney 	union tcp_log_stackspecific tlb_stackinfo;
1602529f56eSJonathan T. Looney #define	tlb_rack	tlb_stackinfo.u_rack
1612529f56eSJonathan T. Looney 
1622529f56eSJonathan T. Looney 	/* The packet */
1632529f56eSJonathan T. Looney 	uint32_t	tlb_len;	/* The packet's data length */
1642529f56eSJonathan T. Looney 	struct tcphdr	tlb_th;		/* The TCP header */
1652529f56eSJonathan T. Looney 	uint8_t		tlb_opts[TCP_MAXOLEN]; /* The TCP options */
1662529f56eSJonathan T. Looney 
1672529f56eSJonathan T. Looney 	/* Verbose information (optional) */
1682529f56eSJonathan T. Looney 	struct tcp_log_verbose tlb_verbose[0];
1692529f56eSJonathan T. Looney } ALIGN_TCP_LOG;
1702529f56eSJonathan T. Looney 
1712529f56eSJonathan T. Looney enum tcp_log_events {
1722529f56eSJonathan T. Looney 	TCP_LOG_IN = 1,	/* Incoming packet                 1 */
1732529f56eSJonathan T. Looney 	TCP_LOG_OUT,	/* Transmit (without other event)  2 */
1742529f56eSJonathan T. Looney 	TCP_LOG_RTO,	/* Retransmit timeout              3 */
1752529f56eSJonathan T. Looney 	TCP_LOG_TF_ACK,	/* Transmit due to TF_ACK          4 */
1762529f56eSJonathan T. Looney 	TCP_LOG_BAD_RETRAN, /* Detected bad retransmission 5 */
1772529f56eSJonathan T. Looney 	TCP_LOG_PRR,	/* Doing PRR                       6 */
1782529f56eSJonathan T. Looney 	TCP_LOG_REORDER,/* Detected reorder                7 */
1792529f56eSJonathan T. Looney 	TCP_LOG_PACER,	/* Pacer sending a packet          8 */
1802529f56eSJonathan T. Looney 	BBR_LOG_BBRUPD,		/* We updated BBR info     9 */
1812529f56eSJonathan T. Looney 	BBR_LOG_BBRSND,		/* We did a slot calculation and sending is done 10 */
1822529f56eSJonathan T. Looney 	BBR_LOG_ACKCLEAR,	/* A ack clears all outstanding     11 */
1832529f56eSJonathan T. Looney 	BBR_LOG_INQUEUE,	/* The tcb had a packet input to it 12 */
1842529f56eSJonathan T. Looney 	BBR_LOG_TIMERSTAR,	/* Start a timer                    13 */
1852529f56eSJonathan T. Looney 	BBR_LOG_TIMERCANC,	/* Cancel a timer                   14 */
1862529f56eSJonathan T. Looney 	BBR_LOG_ENTREC,		/* Entered recovery                 15 */
1872529f56eSJonathan T. Looney 	BBR_LOG_EXITREC,	/* Exited recovery                  16 */
1882529f56eSJonathan T. Looney 	BBR_LOG_CWND,		/* Cwnd change                      17 */
1892529f56eSJonathan T. Looney 	BBR_LOG_BWSAMP,		/* LT B/W sample has been made      18 */
1902529f56eSJonathan T. Looney 	BBR_LOG_MSGSIZE,	/* We received a EMSGSIZE error     19 */
1912529f56eSJonathan T. Looney 	BBR_LOG_BBRRTT,		/* BBR RTT is updated               20 */
1922529f56eSJonathan T. Looney 	BBR_LOG_JUSTRET,	/* We just returned out of output   21 */
1932529f56eSJonathan T. Looney 	BBR_LOG_STATE,		/* A BBR state change occured       22 */
1942529f56eSJonathan T. Looney 	BBR_LOG_PKT_EPOCH,      /* A BBR packet epoch occured       23 */
1952529f56eSJonathan T. Looney 	BBR_LOG_PERSIST,        /* BBR changed to/from a persists   24 */
1962529f56eSJonathan T. Looney 	TCP_LOG_FLOWEND,        /* End of a flow                    25 */
1972529f56eSJonathan T. Looney 	BBR_LOG_RTO,            /* BBR's timeout includes BBR info  26 */
1982529f56eSJonathan T. Looney 	BBR_LOG_DOSEG_DONE,     /* pacer do_segment completes       27 */
1992529f56eSJonathan T. Looney 	BBR_LOG_EXIT_GAIN,      /* pacer do_segment completes       28 */
2002529f56eSJonathan T. Looney 	BBR_LOG_THRESH_CALC,    /* Doing threshold calculation      29 */
2012529f56eSJonathan T. Looney 	BBR_LOG_EXTRACWNDGAIN,	/* Removed                          30 */
2022529f56eSJonathan T. Looney 	TCP_LOG_USERSEND, 	/* User level sends data            31 */
2032529f56eSJonathan T. Looney 	UNUSED_32,	 	/* Unused                           32 */
2042529f56eSJonathan T. Looney 	UNUSED_33, 		/* Unused                           33 */
2052529f56eSJonathan T. Looney 	BBR_LOG_TIME_EPOCH, 	/* A timed based Epoch occured      34 */
2062529f56eSJonathan T. Looney 	BBR_LOG_TO_PROCESS,	/* A to was processed               35 */
2072529f56eSJonathan T. Looney 	BBR_LOG_BBRTSO, 	/* TSO update	                    36 */
2082529f56eSJonathan T. Looney 	BBR_LOG_PACERDIAG,	/* Pacer diag insert                37 */
2092529f56eSJonathan T. Looney 	BBR_LOG_LOWGAIN,	/* Low gain accounting              38 */
2102529f56eSJonathan T. Looney 	BBR_LOG_PROGRESS,	/* Progress timer event             39 */
2112529f56eSJonathan T. Looney 	TCP_LOG_SOCKET_OPT,	/* A socket option is set	    40 */
2122529f56eSJonathan T. Looney 	BBR_LOG_TIMERPREP,	/* A BBR var to debug out TLP issues  41 */
2132529f56eSJonathan T. Looney 	BBR_LOG_ENOBUF_JMP,	/* We had a enobuf jump 42 */
2142529f56eSJonathan T. Looney 	BBR_LOG_PACING_CALC,	/* calc the pacing time 43 */
2152529f56eSJonathan T. Looney 	BBR_LOG_RTT_SHRINKS,	/* We had a log reduction of rttProp 44 */
2162529f56eSJonathan T. Looney 	BBR_LOG_BW_RED_EV,	/* B/W reduction events 45 */
2172529f56eSJonathan T. Looney 	BBR_LOG_REDUCE,		/* old bbr log reduce for 4.1 and earlier 46*/
2182529f56eSJonathan T. Looney 	TCP_LOG_RTT,		/* A rtt (in useconds) is being sampled and applied to the srtt algo 47 */
2192529f56eSJonathan T. Looney 	BBR_LOG_SETTINGS_CHG,   /* Settings changed for loss response 48 */
2202529f56eSJonathan T. Looney 	TCP_LOG_END		/* End (keep at end)	            49 */
2212529f56eSJonathan T. Looney };
2222529f56eSJonathan T. Looney 
2232529f56eSJonathan T. Looney enum tcp_log_states {
2242529f56eSJonathan T. Looney 	TCP_LOG_STATE_CLEAR = -1,	/* Deactivate and clear tracing */
2252529f56eSJonathan T. Looney 	TCP_LOG_STATE_OFF = 0,		/* Pause */
2262529f56eSJonathan T. Looney 	TCP_LOG_STATE_TAIL=1,		/* Keep the trailing events */
2272529f56eSJonathan T. Looney 	TCP_LOG_STATE_HEAD=2,		/* Keep the leading events */
2282529f56eSJonathan T. Looney 	TCP_LOG_STATE_HEAD_AUTO=3,	/* Keep the leading events, and
2292529f56eSJonathan T. Looney 					   automatically dump them to the
2302529f56eSJonathan T. Looney 					   device  */
2312529f56eSJonathan T. Looney 	TCP_LOG_STATE_CONTINUAL=4,	/* Continually dump the data when full */
2322529f56eSJonathan T. Looney 	TCP_LOG_STATE_TAIL_AUTO=5,	/* Keep the trailing events, and
2332529f56eSJonathan T. Looney 					   automatically dump them when the
2342529f56eSJonathan T. Looney 					   session ends */
2352529f56eSJonathan T. Looney };
2362529f56eSJonathan T. Looney 
2372529f56eSJonathan T. Looney /* Use this if we don't know whether the operation succeeded. */
2382529f56eSJonathan T. Looney #define	ERRNO_UNK	(-1)
2392529f56eSJonathan T. Looney 
2402529f56eSJonathan T. Looney /*
2412529f56eSJonathan T. Looney  * If the user included dev/tcp_log/tcp_log_dev.h, then include our private
2422529f56eSJonathan T. Looney  * headers. Otherwise, there is no reason to pollute all the files with an
2432529f56eSJonathan T. Looney  * additional include.
2442529f56eSJonathan T. Looney  *
2452529f56eSJonathan T. Looney  * This structure is aligned to an 8-byte boundary to match the alignment
2462529f56eSJonathan T. Looney  * requirements of (struct tcp_log_buffer).
2472529f56eSJonathan T. Looney  */
2482529f56eSJonathan T. Looney #ifdef __tcp_log_dev_h__
2492529f56eSJonathan T. Looney struct tcp_log_header {
2502529f56eSJonathan T. Looney 	struct tcp_log_common_header tlh_common;
2512529f56eSJonathan T. Looney #define	tlh_version	tlh_common.tlch_version
2522529f56eSJonathan T. Looney #define	tlh_type	tlh_common.tlch_type
2532529f56eSJonathan T. Looney #define	tlh_length	tlh_common.tlch_length
2542529f56eSJonathan T. Looney 	struct in_endpoints	tlh_ie;
2552529f56eSJonathan T. Looney 	struct timeval		tlh_offset;	/* Uptime -> UTC offset */
2562529f56eSJonathan T. Looney 	char			tlh_id[TCP_LOG_ID_LEN];
2572529f56eSJonathan T. Looney 	char			tlh_reason[TCP_LOG_REASON_LEN];
2582529f56eSJonathan T. Looney 	uint8_t		tlh_af;
2592529f56eSJonathan T. Looney 	uint8_t		_pad[7];
2602529f56eSJonathan T. Looney } ALIGN_TCP_LOG;
2612529f56eSJonathan T. Looney 
2622529f56eSJonathan T. Looney #ifdef _KERNEL
2632529f56eSJonathan T. Looney struct tcp_log_dev_log_queue {
2642529f56eSJonathan T. Looney 	struct tcp_log_dev_queue tldl_common;
2652529f56eSJonathan T. Looney 	char			tldl_id[TCP_LOG_ID_LEN];
2662529f56eSJonathan T. Looney 	char			tldl_reason[TCP_LOG_REASON_LEN];
2672529f56eSJonathan T. Looney 	struct in_endpoints	tldl_ie;
2682529f56eSJonathan T. Looney 	struct tcp_log_stailq	tldl_entries;
2692529f56eSJonathan T. Looney 	int			tldl_count;
2702529f56eSJonathan T. Looney 	uint8_t			tldl_af;
2712529f56eSJonathan T. Looney };
2722529f56eSJonathan T. Looney #endif /* _KERNEL */
2732529f56eSJonathan T. Looney #endif /* __tcp_log_dev_h__ */
2742529f56eSJonathan T. Looney 
2752529f56eSJonathan T. Looney #ifdef _KERNEL
2762529f56eSJonathan T. Looney 
2772529f56eSJonathan T. Looney #define	TCP_LOG_BUF_DEFAULT_SESSION_LIMIT	10000
2782529f56eSJonathan T. Looney #define	TCP_LOG_BUF_DEFAULT_GLOBAL_LIMIT	1000000
2792529f56eSJonathan T. Looney 
2802529f56eSJonathan T. Looney /*
2812529f56eSJonathan T. Looney  * TCP_LOG_EVENT_VERBOSE: The same as TCP_LOG_EVENT, except it always
2822529f56eSJonathan T. Looney  * tries to record verbose information.
2832529f56eSJonathan T. Looney  */
2842529f56eSJonathan T. Looney #define	TCP_LOG_EVENT_VERBOSE(tp, th, rxbuf, txbuf, eventid, errornum, len, stackinfo, th_hostorder, tv) \
2852529f56eSJonathan T. Looney 	do {								\
2862529f56eSJonathan T. Looney 		if (tp->t_logstate != TCP_LOG_STATE_OFF)		\
2872529f56eSJonathan T. Looney 			tcp_log_event_(tp, th, rxbuf, txbuf, eventid,	\
2882529f56eSJonathan T. Looney 	 	        errornum, len, stackinfo, th_hostorder,		\
2892529f56eSJonathan T. Looney 		        tp->t_output_caller, __func__, __LINE__, tv);	\
2902529f56eSJonathan T. Looney 	} while (0)
2912529f56eSJonathan T. Looney 
2922529f56eSJonathan T. Looney /*
2932529f56eSJonathan T. Looney  * TCP_LOG_EVENT: This is a macro so we can capture function/line
2942529f56eSJonathan T. Looney  * information when needed.
2952529f56eSJonathan T. Looney  *
2962529f56eSJonathan T. Looney  * Prototype:
2972529f56eSJonathan T. Looney  * TCP_LOG_EVENT(struct tcpcb *tp, struct tcphdr *th, struct sockbuf *rxbuf,
2982529f56eSJonathan T. Looney  *     struct sockbuf *txbuf, uint8_t eventid, int errornum,
2992529f56eSJonathan T. Looney  *     union tcp_log_stackspecific *stackinfo)
3002529f56eSJonathan T. Looney  *
3012529f56eSJonathan T. Looney  * tp is mandatory and must be write locked.
3022529f56eSJonathan T. Looney  * th is optional; if present, it will appear in the record.
3032529f56eSJonathan T. Looney  * rxbuf and txbuf are optional; if present, they will appear in the record.
3042529f56eSJonathan T. Looney  * eventid is mandatory.
3052529f56eSJonathan T. Looney  * errornum is mandatory (it indicates the success or failure of the
3062529f56eSJonathan T. Looney  *     operation associated with the event).
3072529f56eSJonathan T. Looney  * len indicates the length of the packet. If no packet, use 0.
3082529f56eSJonathan T. Looney  * stackinfo is optional; if present, it will appear in the record.
3092529f56eSJonathan T. Looney  */
3102529f56eSJonathan T. Looney #ifdef TCP_LOG_FORCEVERBOSE
3112529f56eSJonathan T. Looney #define	TCP_LOG_EVENT	TCP_LOG_EVENT_VERBOSE
3122529f56eSJonathan T. Looney #else
3132529f56eSJonathan T. Looney #define	TCP_LOG_EVENT(tp, th, rxbuf, txbuf, eventid, errornum, len, stackinfo, th_hostorder) \
3142529f56eSJonathan T. Looney 	do {								\
3152529f56eSJonathan T. Looney 		if (tcp_log_verbose)					\
3162529f56eSJonathan T. Looney 			TCP_LOG_EVENT_VERBOSE(tp, th, rxbuf, txbuf,	\
3172529f56eSJonathan T. Looney 			    eventid, errornum, len, stackinfo,		\
3182529f56eSJonathan T. Looney 			    th_hostorder, NULL);				\
3192529f56eSJonathan T. Looney 		else if (tp->t_logstate != TCP_LOG_STATE_OFF)		\
3202529f56eSJonathan T. Looney 			tcp_log_event_(tp, th, rxbuf, txbuf, eventid,	\
3212529f56eSJonathan T. Looney 			    errornum, len, stackinfo, th_hostorder,	\
3222529f56eSJonathan T. Looney 			    NULL, NULL, 0, NULL);				\
3232529f56eSJonathan T. Looney 	} while (0)
3242529f56eSJonathan T. Looney #endif /* TCP_LOG_FORCEVERBOSE */
3252529f56eSJonathan T. Looney #define	TCP_LOG_EVENTP(tp, th, rxbuf, txbuf, eventid, errornum, len, stackinfo, th_hostorder, tv) \
3262529f56eSJonathan T. Looney 	do {								\
3272529f56eSJonathan T. Looney 		if (tp->t_logstate != TCP_LOG_STATE_OFF)		\
3282529f56eSJonathan T. Looney 			tcp_log_event_(tp, th, rxbuf, txbuf, eventid,	\
3292529f56eSJonathan T. Looney 			    errornum, len, stackinfo, th_hostorder,	\
3302529f56eSJonathan T. Looney 			    NULL, NULL, 0, tv);				\
3312529f56eSJonathan T. Looney 	} while (0)
3322529f56eSJonathan T. Looney 
3332529f56eSJonathan T. Looney 
334*e24e5683SJonathan T. Looney #ifdef TCP_BLACKBOX
3352529f56eSJonathan T. Looney extern bool tcp_log_verbose;
3362529f56eSJonathan T. Looney void tcp_log_drain(struct tcpcb *tp);
3372529f56eSJonathan T. Looney int tcp_log_dump_tp_logbuf(struct tcpcb *tp, char *reason, int how, bool force);
3382529f56eSJonathan T. Looney void tcp_log_dump_tp_bucket_logbufs(struct tcpcb *tp, char *reason);
3392529f56eSJonathan T. Looney struct tcp_log_buffer *tcp_log_event_(struct tcpcb *tp, struct tcphdr *th, struct sockbuf *rxbuf,
3402529f56eSJonathan T. Looney     struct sockbuf *txbuf, uint8_t eventid, int errornum, uint32_t len,
3412529f56eSJonathan T. Looney     union tcp_log_stackspecific *stackinfo, int th_hostorder,
3422529f56eSJonathan T. Looney     const char *output_caller, const char *func, int line, const struct timeval *tv);
3432529f56eSJonathan T. Looney size_t tcp_log_get_id(struct tcpcb *tp, char *buf);
3442529f56eSJonathan T. Looney u_int tcp_log_get_id_cnt(struct tcpcb *tp);
3452529f56eSJonathan T. Looney int tcp_log_getlogbuf(struct sockopt *sopt, struct tcpcb *tp);
3462529f56eSJonathan T. Looney void tcp_log_init(void);
3472529f56eSJonathan T. Looney int tcp_log_set_id(struct tcpcb *tp, char *id);
3482529f56eSJonathan T. Looney int tcp_log_state_change(struct tcpcb *tp, int state);
3492529f56eSJonathan T. Looney void tcp_log_tcpcbinit(struct tcpcb *tp);
3502529f56eSJonathan T. Looney void tcp_log_tcpcbfini(struct tcpcb *tp);
3512529f56eSJonathan T. Looney void tcp_log_flowend(struct tcpcb *tp);
352*e24e5683SJonathan T. Looney #else /* !TCP_BLACKBOX */
353*e24e5683SJonathan T. Looney #define tcp_log_verbose	(false)
354*e24e5683SJonathan T. Looney 
355*e24e5683SJonathan T. Looney static inline struct tcp_log_buffer *
356*e24e5683SJonathan T. Looney tcp_log_event_(struct tcpcb *tp, struct tcphdr *th, struct sockbuf *rxbuf,
357*e24e5683SJonathan T. Looney     struct sockbuf *txbuf, uint8_t eventid, int errornum, uint32_t len,
358*e24e5683SJonathan T. Looney     union tcp_log_stackspecific *stackinfo, int th_hostorder,
359*e24e5683SJonathan T. Looney     const char *output_caller, const char *func, int line,
360*e24e5683SJonathan T. Looney     const struct timeval *tv)
361*e24e5683SJonathan T. Looney {
362*e24e5683SJonathan T. Looney 
363*e24e5683SJonathan T. Looney 	return (NULL);
364*e24e5683SJonathan T. Looney }
365*e24e5683SJonathan T. Looney #endif /* TCP_BLACKBOX */
3662529f56eSJonathan T. Looney 
3672529f56eSJonathan T. Looney #endif	/* _KERNEL */
3682529f56eSJonathan T. Looney #endif	/* __tcp_log_buf_h__ */
369