xref: /freebsd/sys/netinet/tcp_log_buf.h (revision 60bc1957)
12529f56eSJonathan T. Looney /*-
24d846d26SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
32529f56eSJonathan T. Looney  *
469c7c811SRandall Stewart  * Copyright (c) 2016-2020 Netflix, Inc.
52529f56eSJonathan T. Looney  *
62529f56eSJonathan T. Looney  * Redistribution and use in source and binary forms, with or without
72529f56eSJonathan T. Looney  * modification, are permitted provided that the following conditions
82529f56eSJonathan T. Looney  * are met:
92529f56eSJonathan T. Looney  * 1. Redistributions of source code must retain the above copyright
102529f56eSJonathan T. Looney  *    notice, this list of conditions and the following disclaimer.
112529f56eSJonathan T. Looney  * 2. Redistributions in binary form must reproduce the above copyright
122529f56eSJonathan T. Looney  *    notice, this list of conditions and the following disclaimer in the
132529f56eSJonathan T. Looney  *    documentation and/or other materials provided with the distribution.
142529f56eSJonathan T. Looney  *
152529f56eSJonathan T. Looney  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
162529f56eSJonathan T. Looney  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
172529f56eSJonathan T. Looney  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
182529f56eSJonathan T. Looney  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
192529f56eSJonathan T. Looney  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
202529f56eSJonathan T. Looney  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
212529f56eSJonathan T. Looney  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
222529f56eSJonathan T. Looney  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
232529f56eSJonathan T. Looney  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
242529f56eSJonathan T. Looney  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
252529f56eSJonathan T. Looney  * SUCH DAMAGE.
262529f56eSJonathan T. Looney  */
272529f56eSJonathan T. Looney 
282529f56eSJonathan T. Looney #ifndef __tcp_log_buf_h__
292529f56eSJonathan T. Looney #define __tcp_log_buf_h__
302529f56eSJonathan T. Looney 
312529f56eSJonathan T. Looney #define	TCP_LOG_REASON_LEN	32
32a9a08eceSRandall Stewart #define	TCP_LOG_TAG_LEN		32
33e854dd38SRandall Stewart #define	TCP_LOG_BUF_VER		(9)
342529f56eSJonathan T. Looney 
352529f56eSJonathan T. Looney /*
362529f56eSJonathan T. Looney  * Because the (struct tcp_log_buffer) includes 8-byte uint64_t's, it requires
372529f56eSJonathan T. Looney  * 8-byte alignment to work properly on all platforms. Therefore, we will
382529f56eSJonathan T. Looney  * enforce 8-byte alignment for all the structures that may appear by
392529f56eSJonathan T. Looney  * themselves (instead of being embedded in another structure) in a data
402529f56eSJonathan T. Looney  * stream.
412529f56eSJonathan T. Looney  */
422529f56eSJonathan T. Looney #define	ALIGN_TCP_LOG		__aligned(8)
432529f56eSJonathan T. Looney 
442529f56eSJonathan T. Looney /* Information about the socketbuffer state. */
452529f56eSJonathan T. Looney struct tcp_log_sockbuf
462529f56eSJonathan T. Looney {
472529f56eSJonathan T. Looney 	uint32_t	tls_sb_acc;	/* available chars (sb->sb_acc) */
482529f56eSJonathan T. Looney 	uint32_t	tls_sb_ccc;	/* claimed chars (sb->sb_ccc) */
492529f56eSJonathan T. Looney 	uint32_t	tls_sb_spare;	/* spare */
502529f56eSJonathan T. Looney };
512529f56eSJonathan T. Looney 
522529f56eSJonathan T. Looney /* Optional, verbose information that may be appended to an event log. */
532529f56eSJonathan T. Looney struct tcp_log_verbose
542529f56eSJonathan T. Looney {
552529f56eSJonathan T. Looney #define	TCP_FUNC_LEN	32
562529f56eSJonathan T. Looney 	char		tlv_snd_frm[TCP_FUNC_LEN]; /* tcp_output() caller */
572529f56eSJonathan T. Looney 	char		tlv_trace_func[TCP_FUNC_LEN]; /* Function that
582529f56eSJonathan T. Looney 							 generated trace */
592529f56eSJonathan T. Looney 	uint32_t	tlv_trace_line;	/* Line number that generated trace */
602529f56eSJonathan T. Looney 	uint8_t		_pad[4];
612529f56eSJonathan T. Looney } ALIGN_TCP_LOG;
622529f56eSJonathan T. Looney 
632529f56eSJonathan T. Looney /* Internal RACK state variables. */
642529f56eSJonathan T. Looney struct tcp_log_rack
652529f56eSJonathan T. Looney {
662529f56eSJonathan T. Looney 	uint32_t	tlr_rack_rtt;		/* rc_rack_rtt */
672529f56eSJonathan T. Looney 	uint8_t		tlr_state;		/* Internal RACK state */
682529f56eSJonathan T. Looney 	uint8_t		_pad[3];		/* Padding */
692529f56eSJonathan T. Looney };
702529f56eSJonathan T. Looney 
712529f56eSJonathan T. Looney struct tcp_log_bbr {
722529f56eSJonathan T. Looney 	uint64_t cur_del_rate;
732529f56eSJonathan T. Looney 	uint64_t delRate;
742529f56eSJonathan T. Looney 	uint64_t rttProp;
752529f56eSJonathan T. Looney 	uint64_t bw_inuse;
762529f56eSJonathan T. Looney 	uint32_t inflight;
772529f56eSJonathan T. Looney 	uint32_t applimited;
782529f56eSJonathan T. Looney 	uint32_t delivered;
792529f56eSJonathan T. Looney 	uint32_t timeStamp;
802529f56eSJonathan T. Looney 	uint32_t epoch;
812529f56eSJonathan T. Looney 	uint32_t lt_epoch;
822529f56eSJonathan T. Looney 	uint32_t pkts_out;
832529f56eSJonathan T. Looney 	uint32_t flex1;
842529f56eSJonathan T. Looney 	uint32_t flex2;
852529f56eSJonathan T. Looney 	uint32_t flex3;
862529f56eSJonathan T. Looney 	uint32_t flex4;
872529f56eSJonathan T. Looney 	uint32_t flex5;
882529f56eSJonathan T. Looney 	uint32_t flex6;
892529f56eSJonathan T. Looney 	uint32_t lost;
902529f56eSJonathan T. Looney 	uint16_t pacing_gain;
912529f56eSJonathan T. Looney 	uint16_t cwnd_gain;
922529f56eSJonathan T. Looney 	uint16_t flex7;
932529f56eSJonathan T. Looney 	uint8_t bbr_state;
942529f56eSJonathan T. Looney 	uint8_t bbr_substate;
9589e560f4SRandall Stewart 	uint8_t inhpts;
96a370832bSGleb Smirnoff 	uint8_t __spare;
972529f56eSJonathan T. Looney 	uint8_t use_lt_bw;
982529f56eSJonathan T. Looney 	uint8_t flex8;
992529f56eSJonathan T. Looney 	uint32_t pkt_epoch;
1002529f56eSJonathan T. Looney };
1012529f56eSJonathan T. Looney 
10269c7c811SRandall Stewart /* shadows tcp_log_bbr struct element sizes */
10369c7c811SRandall Stewart struct tcp_log_raw {
10469c7c811SRandall Stewart 	uint64_t u64_flex[4];
10569c7c811SRandall Stewart 	uint32_t u32_flex[14];
10669c7c811SRandall Stewart 	uint16_t u16_flex[3];
10769c7c811SRandall Stewart 	uint8_t u8_flex[6];
10869c7c811SRandall Stewart 	uint32_t u32_flex2[1];
10969c7c811SRandall Stewart };
11069c7c811SRandall Stewart 
11169c7c811SRandall Stewart struct tcp_log_uint64 {
11269c7c811SRandall Stewart 	uint64_t u64_flex[13];
11369c7c811SRandall Stewart };
11469c7c811SRandall Stewart 
11569c7c811SRandall Stewart struct tcp_log_sendfile {
11669c7c811SRandall Stewart 	uint64_t offset;
11769c7c811SRandall Stewart 	uint64_t length;
11869c7c811SRandall Stewart 	uint32_t flags;
11969c7c811SRandall Stewart };
12069c7c811SRandall Stewart 
12169c7c811SRandall Stewart /*
12269c7c811SRandall Stewart  * tcp_log_stackspecific is currently being used as "event specific" log
12369c7c811SRandall Stewart  * info by all stacks (i.e. struct tcp_log_bbr is used for generic event
12469c7c811SRandall Stewart  * logging). Until this is cleaned up more generically and throughout,
12569c7c811SRandall Stewart  * allow events to use the same space in the union.
12669c7c811SRandall Stewart  */
1272529f56eSJonathan T. Looney union tcp_log_stackspecific
1282529f56eSJonathan T. Looney {
1292529f56eSJonathan T. Looney 	struct tcp_log_rack u_rack;
1302529f56eSJonathan T. Looney 	struct tcp_log_bbr u_bbr;
13169c7c811SRandall Stewart 	struct tcp_log_sendfile u_sf;
13269c7c811SRandall Stewart 	struct tcp_log_raw u_raw;	/* "raw" log access */
13369c7c811SRandall Stewart 	struct tcp_log_uint64 u64_raw;	/* just u64's - used by process info */
1342529f56eSJonathan T. Looney };
1352529f56eSJonathan T. Looney 
13669c7c811SRandall Stewart typedef union tcp_log_stackspecific tcp_log_eventspecific_t;
13769c7c811SRandall Stewart 
1382529f56eSJonathan T. Looney struct tcp_log_buffer
1392529f56eSJonathan T. Looney {
1402529f56eSJonathan T. Looney 	/* Event basics */
1412529f56eSJonathan T. Looney 	struct timeval	tlb_tv;		/* Timestamp of trace */
1422529f56eSJonathan T. Looney 	uint32_t	tlb_ticks;	/* Timestamp of trace */
1432529f56eSJonathan T. Looney 	uint32_t	tlb_sn;		/* Serial number */
1442529f56eSJonathan T. Looney 	uint8_t		tlb_stackid;	/* Stack ID */
1452529f56eSJonathan T. Looney 	uint8_t		tlb_eventid;	/* Event ID */
1462529f56eSJonathan T. Looney 	uint16_t	tlb_eventflags;	/* Flags for the record */
1472529f56eSJonathan T. Looney #define	TLB_FLAG_RXBUF		0x0001	/* Includes receive buffer info */
1482529f56eSJonathan T. Looney #define	TLB_FLAG_TXBUF		0x0002	/* Includes send buffer info */
1492529f56eSJonathan T. Looney #define	TLB_FLAG_HDR		0x0004	/* Includes a TCP header */
1502529f56eSJonathan T. Looney #define	TLB_FLAG_VERBOSE	0x0008	/* Includes function/line numbers */
1512529f56eSJonathan T. Looney #define	TLB_FLAG_STACKINFO	0x0010	/* Includes stack-specific info */
1522529f56eSJonathan T. Looney 	int		tlb_errno;	/* Event error (if any) */
1532529f56eSJonathan T. Looney 
1542529f56eSJonathan T. Looney 	/* Internal session state */
1552529f56eSJonathan T. Looney 	struct tcp_log_sockbuf tlb_rxbuf; /* Receive buffer */
1562529f56eSJonathan T. Looney 	struct tcp_log_sockbuf tlb_txbuf; /* Send buffer */
1572529f56eSJonathan T. Looney 
1582529f56eSJonathan T. Looney 	int		tlb_state;	/* TCPCB t_state */
1592529f56eSJonathan T. Looney 	uint32_t	tlb_starttime;	/* TCPCB t_starttime */
1602529f56eSJonathan T. Looney 	uint32_t	tlb_iss;	/* TCPCB iss */
1612529f56eSJonathan T. Looney 	uint32_t	tlb_flags;	/* TCPCB flags */
1622529f56eSJonathan T. Looney 	uint32_t	tlb_snd_una;	/* TCPCB snd_una */
1632529f56eSJonathan T. Looney 	uint32_t	tlb_snd_max;	/* TCPCB snd_max */
1642529f56eSJonathan T. Looney 	uint32_t	tlb_snd_cwnd;	/* TCPCB snd_cwnd */
1652529f56eSJonathan T. Looney 	uint32_t	tlb_snd_nxt;	/* TCPCB snd_nxt */
1662529f56eSJonathan T. Looney 	uint32_t	tlb_snd_recover;/* TCPCB snd_recover */
1672529f56eSJonathan T. Looney 	uint32_t	tlb_snd_wnd;	/* TCPCB snd_wnd */
1682529f56eSJonathan T. Looney 	uint32_t	tlb_snd_ssthresh; /* TCPCB snd_ssthresh */
1692529f56eSJonathan T. Looney 	uint32_t	tlb_srtt;	/* TCPCB t_srtt */
1702529f56eSJonathan T. Looney 	uint32_t	tlb_rttvar;	/* TCPCB t_rttvar */
1712529f56eSJonathan T. Looney 	uint32_t	tlb_rcv_up;	/* TCPCB rcv_up */
1722529f56eSJonathan T. Looney 	uint32_t	tlb_rcv_adv;	/* TCPCB rcv_adv */
173e854dd38SRandall Stewart 	uint32_t	tlb_flags2;	/* TCPCB t_flags2 */
1742529f56eSJonathan T. Looney 	uint32_t	tlb_rcv_nxt;	/* TCPCB rcv_nxt */
1752529f56eSJonathan T. Looney 	uint32_t	tlb_rcv_wnd;	/* TCPCB rcv_wnd */
1762529f56eSJonathan T. Looney 	uint32_t	tlb_dupacks;	/* TCPCB t_dupacks */
1772529f56eSJonathan T. Looney 	int		tlb_segqlen;	/* TCPCB segqlen */
1782529f56eSJonathan T. Looney 	int		tlb_snd_numholes; /* TCPCB snd_numholes */
1792529f56eSJonathan T. Looney 	uint32_t	tlb_flex1;	/* Event specific information */
1802529f56eSJonathan T. Looney 	uint32_t	tlb_flex2;	/* Event specific information */
181e854dd38SRandall Stewart 	uint32_t	tlb_fbyte_in;	/* TCPCB first byte in time */
182e854dd38SRandall Stewart 	uint32_t	tlb_fbyte_out;	/* TCPCB first byte out time */
1832529f56eSJonathan T. Looney 	uint8_t		tlb_snd_scale:4, /* TCPCB snd_scale */
1842529f56eSJonathan T. Looney 			tlb_rcv_scale:4; /* TCPCB rcv_scale */
1852529f56eSJonathan T. Looney 	uint8_t		_pad[3];	/* Padding */
1862529f56eSJonathan T. Looney 	/* Per-stack info */
1872529f56eSJonathan T. Looney 	union tcp_log_stackspecific tlb_stackinfo;
1882529f56eSJonathan T. Looney #define	tlb_rack	tlb_stackinfo.u_rack
1892529f56eSJonathan T. Looney 
1902529f56eSJonathan T. Looney 	/* The packet */
1912529f56eSJonathan T. Looney 	uint32_t	tlb_len;	/* The packet's data length */
1922529f56eSJonathan T. Looney 	struct tcphdr	tlb_th;		/* The TCP header */
1932529f56eSJonathan T. Looney 	uint8_t		tlb_opts[TCP_MAXOLEN]; /* The TCP options */
1942529f56eSJonathan T. Looney 
1952529f56eSJonathan T. Looney 	/* Verbose information (optional) */
1962529f56eSJonathan T. Looney 	struct tcp_log_verbose tlb_verbose[0];
1972529f56eSJonathan T. Looney } ALIGN_TCP_LOG;
1982529f56eSJonathan T. Looney 
1992529f56eSJonathan T. Looney enum tcp_log_events {
2002529f56eSJonathan T. Looney 	TCP_LOG_IN = 1,		/* Incoming packet                   1 */
2012529f56eSJonathan T. Looney 	TCP_LOG_OUT,		/* Transmit (without other event)    2 */
2022529f56eSJonathan T. Looney 	TCP_LOG_RTO,		/* Retransmit timeout                3 */
2035d8fd932SRandall Stewart 	TCP_LOG_SB_WAKE,	/* Awaken socket buffer              4 */
2042529f56eSJonathan T. Looney 	TCP_LOG_BAD_RETRAN,	/* Detected bad retransmission       5 */
2052529f56eSJonathan T. Looney 	TCP_LOG_PRR,		/* Doing PRR                         6 */
2062529f56eSJonathan T. Looney 	TCP_LOG_REORDER,	/* Detected reorder                  7 */
2073b0b41e6SRandall Stewart 	TCP_LOG_HPTS,		/* Hpts sending a packet             8 */
2082529f56eSJonathan T. Looney 	BBR_LOG_BBRUPD,		/* We updated BBR info               9 */
2092529f56eSJonathan T. Looney 	BBR_LOG_BBRSND,		/* We did a slot calculation and sending is done 10 */
2102529f56eSJonathan T. Looney 	BBR_LOG_ACKCLEAR,	/* A ack clears all outstanding     11 */
2112529f56eSJonathan T. Looney 	BBR_LOG_INQUEUE,	/* The tcb had a packet input to it 12 */
2122529f56eSJonathan T. Looney 	BBR_LOG_TIMERSTAR,	/* Start a timer                    13 */
2132529f56eSJonathan T. Looney 	BBR_LOG_TIMERCANC,	/* Cancel a timer                   14 */
2142529f56eSJonathan T. Looney 	BBR_LOG_ENTREC,		/* Entered recovery                 15 */
2152529f56eSJonathan T. Looney 	BBR_LOG_EXITREC,	/* Exited recovery                  16 */
2162529f56eSJonathan T. Looney 	BBR_LOG_CWND,		/* Cwnd change                      17 */
2172529f56eSJonathan T. Looney 	BBR_LOG_BWSAMP,		/* LT B/W sample has been made      18 */
2182529f56eSJonathan T. Looney 	BBR_LOG_MSGSIZE,	/* We received a EMSGSIZE error     19 */
2192529f56eSJonathan T. Looney 	BBR_LOG_BBRRTT,		/* BBR RTT is updated               20 */
2202529f56eSJonathan T. Looney 	BBR_LOG_JUSTRET,	/* We just returned out of output   21 */
2215666643aSGordon Bergling 	BBR_LOG_STATE,		/* A BBR state change occurred      22 */
2225666643aSGordon Bergling 	BBR_LOG_PKT_EPOCH,      /* A BBR packet epoch occurred      23 */
2232529f56eSJonathan T. Looney 	BBR_LOG_PERSIST,        /* BBR changed to/from a persists   24 */
2242529f56eSJonathan T. Looney 	TCP_LOG_FLOWEND,        /* End of a flow                    25 */
2252529f56eSJonathan T. Looney 	BBR_LOG_RTO,            /* BBR's timeout includes BBR info  26 */
2263b0b41e6SRandall Stewart 	BBR_LOG_DOSEG_DONE,     /* hpts do_segment completes        27 */
2273b0b41e6SRandall Stewart 	BBR_LOG_EXIT_GAIN,      /* hpts do_segment completes        28 */
2282529f56eSJonathan T. Looney 	BBR_LOG_THRESH_CALC,    /* Doing threshold calculation      29 */
2295d8fd932SRandall Stewart 	TCP_LOG_MAPCHG,		/* Map Changes to the sendmap       30 */
2302529f56eSJonathan T. Looney 	TCP_LOG_USERSEND, 	/* User level sends data            31 */
2313b0b41e6SRandall Stewart 	BBR_RSM_CLEARED,	/* RSM cleared of ACK flags         32 */
2323b0b41e6SRandall Stewart 	BBR_LOG_STATE_TARGET, 	/* Log of target at state           33 */
2335666643aSGordon Bergling 	BBR_LOG_TIME_EPOCH, 	/* A timed based Epoch occurred     34 */
2342529f56eSJonathan T. Looney 	BBR_LOG_TO_PROCESS,	/* A to was processed               35 */
2352529f56eSJonathan T. Looney 	BBR_LOG_BBRTSO,		/* TSO update                       36 */
2363b0b41e6SRandall Stewart 	BBR_LOG_HPTSDIAG,	/* Hpts diag insert                 37 */
2372529f56eSJonathan T. Looney 	BBR_LOG_LOWGAIN,	/* Low gain accounting              38 */
2382529f56eSJonathan T. Looney 	BBR_LOG_PROGRESS,	/* Progress timer event             39 */
2392529f56eSJonathan T. Looney 	TCP_LOG_SOCKET_OPT,	/* A socket option is set           40 */
2402529f56eSJonathan T. Looney 	BBR_LOG_TIMERPREP,	/* A BBR var to debug out TLP issues  41 */
2412529f56eSJonathan T. Looney 	BBR_LOG_ENOBUF_JMP,	/* We had a enobuf jump             42 */
2423b0b41e6SRandall Stewart 	BBR_LOG_HPTSI_CALC,	/* calc the hptsi time              43 */
2432529f56eSJonathan T. Looney 	BBR_LOG_RTT_SHRINKS,	/* We had a log reduction of rttProp 44 */
2442529f56eSJonathan T. Looney 	BBR_LOG_BW_RED_EV,	/* B/W reduction events             45 */
2452529f56eSJonathan T. Looney 	BBR_LOG_REDUCE,		/* old bbr log reduce for 4.1 and earlier 46*/
2462529f56eSJonathan T. Looney 	TCP_LOG_RTT,		/* A rtt (in useconds) is being sampled and applied to the srtt algo 47 */
2472529f56eSJonathan T. Looney 	BBR_LOG_SETTINGS_CHG,	/* Settings changed for loss response 48 */
2483b0b41e6SRandall Stewart 	BBR_LOG_SRTT_GAIN_EVENT, /* SRTT gaining -- now not used    49 */
249c28440dbSRandall Stewart 	TCP_LOG_REASS,		/* Reassembly buffer logging        50 */
2501a714ff2SRandall Stewart 	TCP_HDWR_PACE_SIZE,	/*  TCP pacing size set (rl and rack uses this)  51 */
2513b0b41e6SRandall Stewart 	BBR_LOG_HDWR_PACE,	/* TCP Hardware pacing log          52 */
2523b0b41e6SRandall Stewart 	BBR_LOG_TSTMP_VAL,	/* Temp debug timestamp validation  53 */
2533b0b41e6SRandall Stewart 	TCP_LOG_CONNEND,	/* End of connection                54 */
2543b0b41e6SRandall Stewart 	TCP_LOG_LRO,		/* LRO entry                        55 */
2553b0b41e6SRandall Stewart 	TCP_SACK_FILTER_RES,	/* Results of SACK Filter           56 */
256945f9a7cSRandall Stewart 	TCP_SAD_DETECT,		/* Sack Attack Detection            57 */
257e570d231SRandall Stewart 	TCP_TIMELY_WORK,	/* Logs regarding Timely CC tweaks  58 */
258e570d231SRandall Stewart 	TCP_LOG_USER_EVENT,	/* User space event data            59 */
259e570d231SRandall Stewart 	TCP_LOG_SENDFILE,	/* sendfile() logging for TCP connections 60 */
26057a3a161SRandall Stewart 	TCP_LOG_REQ_T,		/* logging of request tracking 61 */
2615d8fd932SRandall Stewart 	TCP_LOG_ACCOUNTING,	/* Log of TCP Accounting data 62 */
2625d8fd932SRandall Stewart 	TCP_LOG_FSB,		/* FSB information 63 */
2635baf32c9SRandall Stewart 	RACK_DSACK_HANDLING,	/* Handling of DSACK in rack for reordering window 64 */
2644e4c84f8SRandall Stewart 	TCP_HYSTART,		/* TCP Hystart logging 65 */
26562ce18fcSRandall Stewart 	TCP_CHG_QUERY,		/* Change query during fnc_init() 66 */
26662ce18fcSRandall Stewart 	TCP_RACK_LOG_COLLAPSE,	/* Window collapse by peer 67 */
267b16a37edSMichael Tuexen 	TCP_RACK_TP_TRIGGERED,	/* A rack tracepoint is triggered 68 */
268b16a37edSMichael Tuexen 	TCP_HYBRID_PACING_LOG,	/* Hybrid pacing log 69 */
26900812bbdSMichael Tuexen 	TCP_LOG_PRU,		/* TCP protocol user request        70 */
270e18b97bdSRandall Stewart 	TCP_POLICER_DET,	/* TCP Policer detectionn 71 */
271e18b97bdSRandall Stewart 	TCP_PCM_MEASURE,	/* TCP Path Capacity Measurement 72 */
272e18b97bdSRandall Stewart 	TCP_LOG_END		/* End (keep at end)                72 */
2732529f56eSJonathan T. Looney };
2742529f56eSJonathan T. Looney 
2752529f56eSJonathan T. Looney enum tcp_log_states {
27669c7c811SRandall Stewart 	TCP_LOG_STATE_RATIO_OFF = -2,	/* Log ratio evaluation yielded an OFF
27769c7c811SRandall Stewart 					   result. Only used for tlb_logstate */
27869c7c811SRandall Stewart 	TCP_LOG_STATE_CLEAR = -1,	/* Deactivate and clear tracing. Passed
27969c7c811SRandall Stewart 					   to tcp_log_state_change() but never
28069c7c811SRandall Stewart 					   stored in any logstate variable */
2812529f56eSJonathan T. Looney 	TCP_LOG_STATE_OFF = 0,		/* Pause */
28269c7c811SRandall Stewart 
28369c7c811SRandall Stewart 	/* Positively numbered states represent active logging modes */
2842529f56eSJonathan T. Looney 	TCP_LOG_STATE_TAIL=1,		/* Keep the trailing events */
2852529f56eSJonathan T. Looney 	TCP_LOG_STATE_HEAD=2,		/* Keep the leading events */
2862529f56eSJonathan T. Looney 	TCP_LOG_STATE_HEAD_AUTO=3,	/* Keep the leading events, and
2872529f56eSJonathan T. Looney 					   automatically dump them to the
2882529f56eSJonathan T. Looney 					   device  */
2892529f56eSJonathan T. Looney 	TCP_LOG_STATE_CONTINUAL=4,	/* Continually dump the data when full */
2902529f56eSJonathan T. Looney 	TCP_LOG_STATE_TAIL_AUTO=5,	/* Keep the trailing events, and
2912529f56eSJonathan T. Looney 					   automatically dump them when the
2922529f56eSJonathan T. Looney 					   session ends */
29369c7c811SRandall Stewart 	TCP_LOG_VIA_BBPOINTS=6		/* Log only if the BB point has been configured */
2942529f56eSJonathan T. Looney };
2952529f56eSJonathan T. Looney 
2962529f56eSJonathan T. Looney /* Use this if we don't know whether the operation succeeded. */
2972529f56eSJonathan T. Looney #define	ERRNO_UNK	(-1)
2982529f56eSJonathan T. Looney 
2992529f56eSJonathan T. Looney /*
3002529f56eSJonathan T. Looney  * If the user included dev/tcp_log/tcp_log_dev.h, then include our private
3012529f56eSJonathan T. Looney  * headers. Otherwise, there is no reason to pollute all the files with an
3022529f56eSJonathan T. Looney  * additional include.
3032529f56eSJonathan T. Looney  *
3042529f56eSJonathan T. Looney  * This structure is aligned to an 8-byte boundary to match the alignment
3052529f56eSJonathan T. Looney  * requirements of (struct tcp_log_buffer).
3062529f56eSJonathan T. Looney  */
3072529f56eSJonathan T. Looney #ifdef __tcp_log_dev_h__
3082529f56eSJonathan T. Looney struct tcp_log_header {
3092529f56eSJonathan T. Looney 	struct tcp_log_common_header tlh_common;
3102529f56eSJonathan T. Looney #define	tlh_version	tlh_common.tlch_version
3112529f56eSJonathan T. Looney #define	tlh_type	tlh_common.tlch_type
3122529f56eSJonathan T. Looney #define	tlh_length	tlh_common.tlch_length
3132529f56eSJonathan T. Looney 	struct in_endpoints	tlh_ie;
3142529f56eSJonathan T. Looney 	struct timeval		tlh_offset;	/* Uptime -> UTC offset */
3152529f56eSJonathan T. Looney 	char			tlh_id[TCP_LOG_ID_LEN];
3162529f56eSJonathan T. Looney 	char			tlh_reason[TCP_LOG_REASON_LEN];
317a9a08eceSRandall Stewart 	char			tlh_tag[TCP_LOG_TAG_LEN];
3182529f56eSJonathan T. Looney 	uint8_t		tlh_af;
3192529f56eSJonathan T. Looney 	uint8_t		_pad[7];
3202529f56eSJonathan T. Looney } ALIGN_TCP_LOG;
3212529f56eSJonathan T. Looney 
3222529f56eSJonathan T. Looney #ifdef _KERNEL
3232529f56eSJonathan T. Looney struct tcp_log_dev_log_queue {
3242529f56eSJonathan T. Looney 	struct tcp_log_dev_queue tldl_common;
3252529f56eSJonathan T. Looney 	char			tldl_id[TCP_LOG_ID_LEN];
3262529f56eSJonathan T. Looney 	char			tldl_reason[TCP_LOG_REASON_LEN];
327a9a08eceSRandall Stewart 	char			tldl_tag[TCP_LOG_TAG_LEN];
3282529f56eSJonathan T. Looney 	struct in_endpoints	tldl_ie;
3292529f56eSJonathan T. Looney 	struct tcp_log_stailq	tldl_entries;
3302529f56eSJonathan T. Looney 	int			tldl_count;
3312529f56eSJonathan T. Looney 	uint8_t			tldl_af;
3322529f56eSJonathan T. Looney };
3332529f56eSJonathan T. Looney #endif /* _KERNEL */
3342529f56eSJonathan T. Looney #endif /* __tcp_log_dev_h__ */
3352529f56eSJonathan T. Looney 
33669c7c811SRandall Stewart /*
33769c7c811SRandall Stewart  * Defined BBPOINTS that can be used
33869c7c811SRandall Stewart  * with TCP_LOG_VIA_BBPOINTS.
33969c7c811SRandall Stewart  */
34069c7c811SRandall Stewart #define TCP_BBPOINT_NONE		0
34169c7c811SRandall Stewart #define TCP_BBPOINT_REQ_LEVEL_LOGGING	1
34269c7c811SRandall Stewart 
34369c7c811SRandall Stewart /*********************/
34469c7c811SRandall Stewart /* TCP Trace points */
34569c7c811SRandall Stewart /*********************/
34669c7c811SRandall Stewart /*
34769c7c811SRandall Stewart  * TCP trace points are interesting points within
34869c7c811SRandall Stewart  * the TCP code that the author/debugger may want
34969c7c811SRandall Stewart  * to have BB logging enabled if we hit that point.
35069c7c811SRandall Stewart  * In order to enable a trace point you set the
35169c7c811SRandall Stewart  * sysctl var net.inet.tcp.bb.tp.number to
35269c7c811SRandall Stewart  * one of the numbers listed below. You also
35369c7c811SRandall Stewart  * must make sure net.inet.tcp.bb.tp.bbmode is
35469c7c811SRandall Stewart  * non-zero, the default is 4 for continuous tracing.
35569c7c811SRandall Stewart  * You also set in the number of connections you want
35669c7c811SRandall Stewart  * have get BB logs in net.inet.tcp.bb.tp.count.
35769c7c811SRandall Stewart  *
35869c7c811SRandall Stewart  * Count will decrement every time BB logging is assigned
35969c7c811SRandall Stewart  * to a connection that hit your tracepoint.
36069c7c811SRandall Stewart  *
36169c7c811SRandall Stewart  * You can enable all trace points by setting the number
36269c7c811SRandall Stewart  * to 0xffffffff. You can disable all trace points by
36369c7c811SRandall Stewart  * setting number to zero (or count to 0).
36469c7c811SRandall Stewart  *
36569c7c811SRandall Stewart  * Below are the enumerated list of tracepoints that
36669c7c811SRandall Stewart  * have currently been defined in the code. Add more
36769c7c811SRandall Stewart  * as you add a call to rack_trace_point(rack, <name>);
36869c7c811SRandall Stewart  * where <name> is defined below.
36969c7c811SRandall Stewart  */
37069c7c811SRandall Stewart #define TCP_TP_HWENOBUF		0x00000001	/* When we are doing hardware pacing and hit enobufs */
37169c7c811SRandall Stewart #define TCP_TP_ENOBUF		0x00000002	/* When we hit enobufs with software pacing */
37269c7c811SRandall Stewart #define TCP_TP_COLLAPSED_WND	0x00000003	/* When a peer to collapses its rwnd on us */
37369c7c811SRandall Stewart #define TCP_TP_COLLAPSED_RXT	0x00000004	/* When we actually retransmit a collapsed window rsm */
37457a3a161SRandall Stewart #define TCP_TP_REQ_LOG_FAIL	0x00000005	/* We tried to allocate a Request log but had no space */
37569c7c811SRandall Stewart #define TCP_TP_RESET_RCV	0x00000006	/* Triggers when we receive a RST */
376e18b97bdSRandall Stewart #define TCP_TP_POLICER_DET	0x00000007	/* When we detect a policer */
377e18b97bdSRandall Stewart #define TCP_TP_EXCESS_RXT	TCP_TP_POLICER_DET	/* alias */
37869c7c811SRandall Stewart #define TCP_TP_SAD_TRIGGERED	0x00000008	/* Sack Attack Detection triggers */
37969c7c811SRandall Stewart #define TCP_TP_SAD_SUSPECT	0x0000000a	/* A sack has supicious information in it */
380e18b97bdSRandall Stewart #define TCP_TP_PACED_BOTTOM	0x0000000b	/* We have paced at the bottom */
38169c7c811SRandall Stewart 
3822529f56eSJonathan T. Looney #ifdef _KERNEL
3832529f56eSJonathan T. Looney 
38469c7c811SRandall Stewart extern uint32_t tcp_trace_point_config;
38569c7c811SRandall Stewart extern uint32_t tcp_trace_point_bb_mode;
38669c7c811SRandall Stewart extern int32_t tcp_trace_point_count;
38769c7c811SRandall Stewart 
38869c7c811SRandall Stewart /*
38969c7c811SRandall Stewart  * Returns true if any sort of BB logging is enabled,
39069c7c811SRandall Stewart  * commonly used throughout the codebase.
39169c7c811SRandall Stewart  */
39269c7c811SRandall Stewart static inline int
tcp_bblogging_on(struct tcpcb * tp)39369c7c811SRandall Stewart tcp_bblogging_on(struct tcpcb *tp)
39469c7c811SRandall Stewart {
39569c7c811SRandall Stewart 	if (tp->_t_logstate <= TCP_LOG_STATE_OFF)
39669c7c811SRandall Stewart 		return (0);
39769c7c811SRandall Stewart 	if (tp->_t_logstate == TCP_LOG_VIA_BBPOINTS)
39869c7c811SRandall Stewart 		return (0);
39969c7c811SRandall Stewart 	return (1);
40069c7c811SRandall Stewart }
40169c7c811SRandall Stewart 
40269c7c811SRandall Stewart /*
40369c7c811SRandall Stewart  * Returns true if we match a specific bbpoint when
40469c7c811SRandall Stewart  * in TCP_LOG_VIA_BBPOINTS, but also returns true
40569c7c811SRandall Stewart  * for all the other logging states.
40669c7c811SRandall Stewart  */
40769c7c811SRandall Stewart static inline int
tcp_bblogging_point_on(struct tcpcb * tp,uint8_t bbpoint)40869c7c811SRandall Stewart tcp_bblogging_point_on(struct tcpcb *tp, uint8_t bbpoint)
40969c7c811SRandall Stewart {
41069c7c811SRandall Stewart 	if (tp->_t_logstate <= TCP_LOG_STATE_OFF)
41169c7c811SRandall Stewart 		return (0);
41269c7c811SRandall Stewart 	if ((tp->_t_logstate == TCP_LOG_VIA_BBPOINTS) &&
41369c7c811SRandall Stewart 	    (tp->_t_logpoint == bbpoint))
41469c7c811SRandall Stewart 		return (1);
41569c7c811SRandall Stewart 	else if (tp->_t_logstate == TCP_LOG_VIA_BBPOINTS)
41669c7c811SRandall Stewart 		return (0);
41769c7c811SRandall Stewart 	return (1);
41869c7c811SRandall Stewart }
41969c7c811SRandall Stewart 
42069c7c811SRandall Stewart static inline void
tcp_set_bblog_state(struct tcpcb * tp,uint8_t ls,uint8_t bbpoint)42169c7c811SRandall Stewart tcp_set_bblog_state(struct tcpcb *tp, uint8_t ls, uint8_t bbpoint)
42269c7c811SRandall Stewart {
42369c7c811SRandall Stewart 	if ((ls == TCP_LOG_VIA_BBPOINTS) &&
42460bc1957SMichael Tuexen 	    (tp->_t_logstate == TCP_LOG_STATE_OFF)){
42569c7c811SRandall Stewart 		/*
42669c7c811SRandall Stewart 		 * We don't allow a BBPOINTS set to override
42769c7c811SRandall Stewart 		 * other types of BB logging set by other means such
42869c7c811SRandall Stewart 		 * as the bb_ratio/bb_state URL parameters. In other
42969c7c811SRandall Stewart 		 * words BBlogging must be *off* in order to turn on
43069c7c811SRandall Stewart 		 * a BBpoint.
43169c7c811SRandall Stewart 		 */
43269c7c811SRandall Stewart 		tp->_t_logpoint = bbpoint;
43369c7c811SRandall Stewart 		tp->_t_logstate = ls;
43460bc1957SMichael Tuexen 	} else if (ls < TCP_LOG_VIA_BBPOINTS) {
43560bc1957SMichael Tuexen 		tp->_t_logpoint = TCP_BBPOINT_NONE;
43669c7c811SRandall Stewart 		tp->_t_logstate = ls;
43769c7c811SRandall Stewart 	}
43869c7c811SRandall Stewart }
43969c7c811SRandall Stewart 
44069c7c811SRandall Stewart static inline uint32_t
tcp_get_bblog_state(struct tcpcb * tp)44169c7c811SRandall Stewart tcp_get_bblog_state(struct tcpcb *tp)
44269c7c811SRandall Stewart {
44369c7c811SRandall Stewart 	return (tp->_t_logstate);
44469c7c811SRandall Stewart }
44569c7c811SRandall Stewart 
44669c7c811SRandall Stewart static inline void
tcp_trace_point(struct tcpcb * tp,int num)44769c7c811SRandall Stewart tcp_trace_point(struct tcpcb *tp, int num)
44869c7c811SRandall Stewart {
449113f56baSMichael Tuexen #ifdef TCP_BLACKBOX
45069c7c811SRandall Stewart 	if (((tcp_trace_point_config == num)  ||
45169c7c811SRandall Stewart 	     (tcp_trace_point_config == 0xffffffff)) &&
45269c7c811SRandall Stewart 	    (tcp_trace_point_bb_mode != 0) &&
45369c7c811SRandall Stewart 	    (tcp_trace_point_count > 0) &&
45469c7c811SRandall Stewart 	    (tcp_bblogging_on(tp) == 0)) {
45569c7c811SRandall Stewart 		int res;
45669c7c811SRandall Stewart 		res = atomic_fetchadd_int(&tcp_trace_point_count, -1);
45769c7c811SRandall Stewart 		if (res > 0) {
45869c7c811SRandall Stewart 			tcp_set_bblog_state(tp, tcp_trace_point_bb_mode, TCP_BBPOINT_NONE);
45969c7c811SRandall Stewart 		} else {
46069c7c811SRandall Stewart 			/* Loss a race assure its zero now */
46169c7c811SRandall Stewart 			tcp_trace_point_count = 0;
46269c7c811SRandall Stewart 		}
46369c7c811SRandall Stewart 	}
464113f56baSMichael Tuexen #endif
46569c7c811SRandall Stewart }
46669c7c811SRandall Stewart 
4673b0b41e6SRandall Stewart #define	TCP_LOG_BUF_DEFAULT_SESSION_LIMIT	5000
4683b0b41e6SRandall Stewart #define	TCP_LOG_BUF_DEFAULT_GLOBAL_LIMIT	5000000
4692529f56eSJonathan T. Looney 
4702529f56eSJonathan T. Looney /*
4712529f56eSJonathan T. Looney  * TCP_LOG_EVENT_VERBOSE: The same as TCP_LOG_EVENT, except it always
4722529f56eSJonathan T. Looney  * tries to record verbose information.
4732529f56eSJonathan T. Looney  */
4742529f56eSJonathan T. Looney #define	TCP_LOG_EVENT_VERBOSE(tp, th, rxbuf, txbuf, eventid, errornum, len, stackinfo, th_hostorder, tv) \
4752529f56eSJonathan T. Looney 	do {								\
47669c7c811SRandall Stewart 		if (tcp_bblogging_on(tp)) \
47769c7c811SRandall Stewart 			tcp_log_event(tp, th, rxbuf, txbuf, eventid,	\
4782529f56eSJonathan T. Looney 			    errornum, len, stackinfo, th_hostorder,	\
4792529f56eSJonathan T. Looney 			    tp->t_output_caller, __func__, __LINE__, tv);\
4802529f56eSJonathan T. Looney 	} while (0)
4812529f56eSJonathan T. Looney 
4822529f56eSJonathan T. Looney /*
4832529f56eSJonathan T. Looney  * TCP_LOG_EVENT: This is a macro so we can capture function/line
48469c7c811SRandall Stewart  * information when needed. You can use the macro when you are not
48569c7c811SRandall Stewart  * doing a lot of prep in the stack specific information i.e. you
48669c7c811SRandall Stewart  * don't add extras (stackinfo). If you are adding extras which
48769c7c811SRandall Stewart  * means filling out a stack variable instead use the tcp_log_event()
48869c7c811SRandall Stewart  * function but enclose the call to the log (and all the setup) in a
48969c7c811SRandall Stewart  * if (tcp_bblogging_on(tp)) {
49069c7c811SRandall Stewart  *   ... setup and logging call ...
49169c7c811SRandall Stewart  * }
49269c7c811SRandall Stewart  *
49369c7c811SRandall Stewart  * Always use the macro tcp_bblogging_on() since sometimes the defintions
49469c7c811SRandall Stewart  * do change.
49569c7c811SRandall Stewart  *
49669c7c811SRandall Stewart  * BBlogging also supports the concept of a BBpoint. The idea behind this
49769c7c811SRandall Stewart  * is that when you set a specific BBpoint on and turn the logging into
49869c7c811SRandall Stewart  * the BBpoint mode (TCP_LOG_VIA_BBPOINTS) you will be defining very very
49969c7c811SRandall Stewart  * few of these points to come out. The point is specific to a code you
50069c7c811SRandall Stewart  * want tied to that one BB logging. This allows you to turn on a much broader
50169c7c811SRandall Stewart  * scale set of limited logging on more connections without overwhelming the
50269c7c811SRandall Stewart  * I/O system with too much BBlogs. This of course means you need to be quite
50369c7c811SRandall Stewart  * careful on how many BBlogs go with each point, but you can have multiple points
50469c7c811SRandall Stewart  * only one of which is active at a time.
50569c7c811SRandall Stewart  *
50669c7c811SRandall Stewart  * To define a point you add it above under the define for TCP_BBPOINT_NONE (which
50769c7c811SRandall Stewart  * is the default i.e. no point is defined. You then, for your point use the
50869c7c811SRandall Stewart  * tcp_bblogging_point_on(struct tcpcb *tp, uint8_t bbpoint) inline to enclose
50969c7c811SRandall Stewart  * your call to tcp_log_event.  Do not use one of the TCP_LOGGING macros else
51069c7c811SRandall Stewart  * your point will never come out. You specify your defined point in the bbpoint
51169c7c811SRandall Stewart  * side of the inline. An example of this you can find in rack where the
51269c7c811SRandall Stewart  * TCP_BBPOINT_REQ_LEVEL_LOGGING is used. There a specific set of logs are generated
51357a3a161SRandall Stewart  * for each request that tcp is tracking.
51469c7c811SRandall Stewart  *
51569c7c811SRandall Stewart  * When turning on BB logging use the inline:
51669c7c811SRandall Stewart  * tcp_set_bblog_state(struct tcpcb *tp, uint8_t ls, uint8_t bbpoint)
51769c7c811SRandall Stewart  * the ls field is the logging state TCP_LOG_STATE_CONTINUAL etc. The
51869c7c811SRandall Stewart  * bbpoint field is ignored unless the ls field is set to TCP_LOG_VIA_BBPOINTS.
51969c7c811SRandall Stewart  * Currently there is only a socket option that turns on the non-BBPOINT
52069c7c811SRandall Stewart  * logging.
5212529f56eSJonathan T. Looney  *
5222529f56eSJonathan T. Looney  * Prototype:
5232529f56eSJonathan T. Looney  * TCP_LOG_EVENT(struct tcpcb *tp, struct tcphdr *th, struct sockbuf *rxbuf,
5242529f56eSJonathan T. Looney  *     struct sockbuf *txbuf, uint8_t eventid, int errornum,
5252529f56eSJonathan T. Looney  *     union tcp_log_stackspecific *stackinfo)
5262529f56eSJonathan T. Looney  *
5272529f56eSJonathan T. Looney  * tp is mandatory and must be write locked.
5282529f56eSJonathan T. Looney  * th is optional; if present, it will appear in the record.
5292529f56eSJonathan T. Looney  * rxbuf and txbuf are optional; if present, they will appear in the record.
5302529f56eSJonathan T. Looney  * eventid is mandatory.
5312529f56eSJonathan T. Looney  * errornum is mandatory (it indicates the success or failure of the
5322529f56eSJonathan T. Looney  *     operation associated with the event).
5332529f56eSJonathan T. Looney  * len indicates the length of the packet. If no packet, use 0.
5342529f56eSJonathan T. Looney  * stackinfo is optional; if present, it will appear in the record.
5352529f56eSJonathan T. Looney  */
536326f4556SGleb Smirnoff struct tcpcb;
5372529f56eSJonathan T. Looney #ifdef TCP_LOG_FORCEVERBOSE
5382529f56eSJonathan T. Looney #define	TCP_LOG_EVENT	TCP_LOG_EVENT_VERBOSE
5392529f56eSJonathan T. Looney #else
5402529f56eSJonathan T. Looney #define	TCP_LOG_EVENT(tp, th, rxbuf, txbuf, eventid, errornum, len, stackinfo, th_hostorder) \
5412529f56eSJonathan T. Looney 	do {								\
5422529f56eSJonathan T. Looney 		if (tcp_log_verbose)					\
5432529f56eSJonathan T. Looney 			TCP_LOG_EVENT_VERBOSE(tp, th, rxbuf, txbuf,	\
5442529f56eSJonathan T. Looney 			    eventid, errornum, len, stackinfo,		\
5452529f56eSJonathan T. Looney 			    th_hostorder, NULL);			\
54669c7c811SRandall Stewart 		else if (tcp_bblogging_on(tp))				\
54769c7c811SRandall Stewart 			tcp_log_event(tp, th, rxbuf, txbuf, eventid,	\
5482529f56eSJonathan T. Looney 			    errornum, len, stackinfo, th_hostorder,	\
5492529f56eSJonathan T. Looney 			    NULL, NULL, 0, NULL);			\
5502529f56eSJonathan T. Looney 	} while (0)
5512529f56eSJonathan T. Looney #endif /* TCP_LOG_FORCEVERBOSE */
5522529f56eSJonathan T. Looney #define	TCP_LOG_EVENTP(tp, th, rxbuf, txbuf, eventid, errornum, len, stackinfo, th_hostorder, tv) \
5532529f56eSJonathan T. Looney 	do {								\
55469c7c811SRandall Stewart 		if (tcp_bblogging_on(tp))				\
55569c7c811SRandall Stewart 			tcp_log_event(tp, th, rxbuf, txbuf, eventid,	\
5562529f56eSJonathan T. Looney 			    errornum, len, stackinfo, th_hostorder,	\
5572529f56eSJonathan T. Looney 			    NULL, NULL, 0, tv);				\
5582529f56eSJonathan T. Looney 	} while (0)
5592529f56eSJonathan T. Looney 
560e24e5683SJonathan T. Looney #ifdef TCP_BLACKBOX
5612529f56eSJonathan T. Looney extern bool tcp_log_verbose;
5622529f56eSJonathan T. Looney void tcp_log_drain(struct tcpcb *tp);
5632529f56eSJonathan T. Looney int tcp_log_dump_tp_logbuf(struct tcpcb *tp, char *reason, int how, bool force);
5642529f56eSJonathan T. Looney void tcp_log_dump_tp_bucket_logbufs(struct tcpcb *tp, char *reason);
56569c7c811SRandall Stewart struct tcp_log_buffer *tcp_log_event(struct tcpcb *tp, struct tcphdr *th, struct sockbuf *rxbuf,
5662529f56eSJonathan T. Looney     struct sockbuf *txbuf, uint8_t eventid, int errornum, uint32_t len,
5672529f56eSJonathan T. Looney     union tcp_log_stackspecific *stackinfo, int th_hostorder,
5682529f56eSJonathan T. Looney     const char *output_caller, const char *func, int line, const struct timeval *tv);
5692529f56eSJonathan T. Looney size_t tcp_log_get_id(struct tcpcb *tp, char *buf);
570a9a08eceSRandall Stewart size_t tcp_log_get_tag(struct tcpcb *tp, char *buf);
5712529f56eSJonathan T. Looney u_int tcp_log_get_id_cnt(struct tcpcb *tp);
5722529f56eSJonathan T. Looney int tcp_log_getlogbuf(struct sockopt *sopt, struct tcpcb *tp);
5732529f56eSJonathan T. Looney void tcp_log_init(void);
5742529f56eSJonathan T. Looney int tcp_log_set_id(struct tcpcb *tp, char *id);
575a9a08eceSRandall Stewart int tcp_log_set_tag(struct tcpcb *tp, char *tag);
5762529f56eSJonathan T. Looney int tcp_log_state_change(struct tcpcb *tp, int state);
5772529f56eSJonathan T. Looney void tcp_log_tcpcbinit(struct tcpcb *tp);
5782529f56eSJonathan T. Looney void tcp_log_tcpcbfini(struct tcpcb *tp);
5792529f56eSJonathan T. Looney void tcp_log_flowend(struct tcpcb *tp);
58069c7c811SRandall Stewart void tcp_log_sendfile(struct socket *so, off_t offset, size_t nbytes,
58169c7c811SRandall Stewart     int flags);
58269c7c811SRandall Stewart int tcp_log_apply_ratio(struct tcpcb *tp, int ratio);
583e24e5683SJonathan T. Looney #else /* !TCP_BLACKBOX */
584e24e5683SJonathan T. Looney #define tcp_log_verbose	(false)
585e24e5683SJonathan T. Looney 
586e24e5683SJonathan T. Looney static inline struct tcp_log_buffer *
tcp_log_event(struct tcpcb * tp,struct tcphdr * th,struct sockbuf * rxbuf,struct sockbuf * txbuf,uint8_t eventid,int errornum,uint32_t len,union tcp_log_stackspecific * stackinfo,int th_hostorder,const char * output_caller,const char * func,int line,const struct timeval * tv)58769c7c811SRandall Stewart tcp_log_event(struct tcpcb *tp, struct tcphdr *th, struct sockbuf *rxbuf,
588e24e5683SJonathan T. Looney     struct sockbuf *txbuf, uint8_t eventid, int errornum, uint32_t len,
589e24e5683SJonathan T. Looney     union tcp_log_stackspecific *stackinfo, int th_hostorder,
590e24e5683SJonathan T. Looney     const char *output_caller, const char *func, int line,
591e24e5683SJonathan T. Looney     const struct timeval *tv)
592e24e5683SJonathan T. Looney {
593e24e5683SJonathan T. Looney 
594e24e5683SJonathan T. Looney 	return (NULL);
595e24e5683SJonathan T. Looney }
596e24e5683SJonathan T. Looney #endif /* TCP_BLACKBOX */
5972529f56eSJonathan T. Looney 
5982529f56eSJonathan T. Looney #endif	/* _KERNEL */
5992529f56eSJonathan T. Looney #endif	/* __tcp_log_buf_h__ */
600