tcp_var.h revision 98211
1177633Sdfr/*
2177633Sdfr * Copyright (c) 1982, 1986, 1993, 1994, 1995
3177633Sdfr *	The Regents of the University of California.  All rights reserved.
4177633Sdfr *
5177633Sdfr * Redistribution and use in source and binary forms, with or without
6177633Sdfr * modification, are permitted provided that the following conditions
7177633Sdfr * are met:
8177633Sdfr * 1. Redistributions of source code must retain the above copyright
9177633Sdfr *    notice, this list of conditions and the following disclaimer.
10177633Sdfr * 2. Redistributions in binary form must reproduce the above copyright
11177685Sdfr *    notice, this list of conditions and the following disclaimer in the
12177633Sdfr *    documentation and/or other materials provided with the distribution.
13177633Sdfr * 3. All advertising materials mentioning features or use of this software
14177633Sdfr *    must display the following acknowledgement:
15177633Sdfr *	This product includes software developed by the University of
16177633Sdfr *	California, Berkeley and its contributors.
17177633Sdfr * 4. Neither the name of the University nor the names of its contributors
18177633Sdfr *    may be used to endorse or promote products derived from this software
19177633Sdfr *    without specific prior written permission.
20177633Sdfr *
21180025Sdfr * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22177633Sdfr * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23180025Sdfr * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24177633Sdfr * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25177633Sdfr * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26180025Sdfr * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27177633Sdfr * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28177633Sdfr * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29177633Sdfr * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30180025Sdfr * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31177633Sdfr * SUCH DAMAGE.
32180025Sdfr *
33177633Sdfr *	@(#)tcp_var.h	8.4 (Berkeley) 5/24/95
34177633Sdfr * $FreeBSD: head/sys/netinet/tcp_var.h 98211 2002-06-14 08:35:21Z hsu $
35180025Sdfr */
36177633Sdfr
37177633Sdfr#ifndef _NETINET_TCP_VAR_H_
38177633Sdfr#define _NETINET_TCP_VAR_H_
39180025Sdfr
40177633Sdfr#include <netinet/in_pcb.h>		/* needed for in_conninfo, inp_gen_t */
41180025Sdfr#include <netinet/tcp.h>
42177633Sdfr
43177633Sdfr/*
44180025Sdfr * Kernel variables for tcp.
45177633Sdfr */
46177633Sdfrextern int	tcp_do_rfc1323;
47177633Sdfrextern int	tcp_do_rfc1644;
48180025Sdfr
49177633Sdfr/* TCP segment queue entry */
50180025Sdfrstruct tseg_qent {
51177633Sdfr	LIST_ENTRY(tseg_qent) tqe_q;
52177633Sdfr	int	tqe_len;		/* TCP segment data length */
53180025Sdfr	struct	tcphdr *tqe_th;		/* a pointer to tcp header */
54177633Sdfr	struct	mbuf	*tqe_m;		/* mbuf contains packet */
55177633Sdfr};
56177633SdfrLIST_HEAD(tsegqe_head, tseg_qent);
57180025Sdfr#ifdef MALLOC_DECLARE
58177633SdfrMALLOC_DECLARE(M_TSEGQ);
59180025Sdfr#endif
60177633Sdfr
61177633Sdfrstruct tcptemp {
62180025Sdfr	u_char	tt_ipgen[40]; /* the size must be of max ip header, now IPv6 */
63177633Sdfr	struct	tcphdr tt_t;
64177633Sdfr};
65177633Sdfr
66180025Sdfr#define tcp6cb		tcpcb  /* for KAME src sync over BSD*'s */
67177633Sdfr
68180025Sdfr/*
69177633Sdfr * Tcp control block, one per tcp; fields:
70177633Sdfr * Organized for 16 byte cacheline efficiency.
71180025Sdfr */
72177633Sdfrstruct tcpcb {
73177633Sdfr	struct	tsegqe_head t_segq;
74177633Sdfr	int	t_dupacks;		/* consecutive dup acks recd */
75180025Sdfr	struct	tcptemp	*unused;	/* unused */
76177633Sdfr
77180025Sdfr	struct	callout *tt_rexmt;	/* retransmit timer */
78177633Sdfr	struct	callout *tt_persist;	/* retransmit persistence */
79177633Sdfr	struct	callout *tt_keep;	/* keepalive */
80180025Sdfr	struct	callout *tt_2msl;	/* 2*msl TIME_WAIT timer */
81177633Sdfr	struct	callout *tt_delack;	/* delayed ACK timer */
82177633Sdfr
83177633Sdfr	struct	inpcb *t_inpcb;		/* back pointer to internet pcb */
84180025Sdfr	int	t_state;		/* state of this connection */
85177633Sdfr	u_int	t_flags;
86180025Sdfr#define	TF_ACKNOW	0x00001		/* ack peer immediately */
87177633Sdfr#define	TF_DELACK	0x00002		/* ack, but try to delay it */
88177633Sdfr#define	TF_NODELAY	0x00004		/* don't delay packets to coalesce */
89180025Sdfr#define	TF_NOOPT	0x00008		/* don't use tcp options */
90177633Sdfr#define	TF_SENTFIN	0x00010		/* have sent FIN */
91177633Sdfr#define	TF_REQ_SCALE	0x00020		/* have/will request window scaling */
92177633Sdfr#define	TF_RCVD_SCALE	0x00040		/* other side has requested scaling */
93180025Sdfr#define	TF_REQ_TSTMP	0x00080		/* have/will request timestamps */
94177633Sdfr#define	TF_RCVD_TSTMP	0x00100		/* a timestamp was received in SYN */
95180025Sdfr#define	TF_SACK_PERMIT	0x00200		/* other side said I could SACK */
96177633Sdfr#define	TF_NEEDSYN	0x00400		/* send SYN (implicit state) */
97177633Sdfr#define	TF_NEEDFIN	0x00800		/* send FIN (implicit state) */
98180025Sdfr#define	TF_NOPUSH	0x01000		/* don't push */
99177633Sdfr#define	TF_REQ_CC	0x02000		/* have/will request CC */
100177633Sdfr#define	TF_RCVD_CC	0x04000		/* a CC was received in SYN */
101177633Sdfr#define	TF_SENDCCNEW	0x08000		/* send CCnew instead of CC in SYN */
102180025Sdfr#define	TF_MORETOCOME	0x10000		/* More data to be appended to sock */
103177633Sdfr#define	TF_LQ_OVERFLOW	0x20000		/* listen queue overflow */
104180025Sdfr#define	TF_LASTIDLE	0x40000		/* connection was previously idle */
105177633Sdfr#define TF_RXWIN0SENT	0x80000		/* sent a receiver win 0 in response */
106177633Sdfr	int	t_force;		/* 1 if forcing out a byte */
107180025Sdfr
108177633Sdfr	tcp_seq	snd_una;		/* send unacknowledged */
109177633Sdfr	tcp_seq	snd_max;		/* highest sequence number sent;
110177633Sdfr					 * used to recognize retransmits
111180025Sdfr					 */
112177633Sdfr	tcp_seq	snd_nxt;		/* send next */
113180025Sdfr	tcp_seq	snd_up;			/* send urgent pointer */
114177633Sdfr
115177633Sdfr	tcp_seq	snd_wl1;		/* window update seg seq number */
116180025Sdfr	tcp_seq	snd_wl2;		/* window update seg ack number */
117177633Sdfr	tcp_seq	iss;			/* initial send sequence number */
118177633Sdfr	tcp_seq	irs;			/* initial receive sequence number */
119177633Sdfr
120180025Sdfr	tcp_seq	rcv_nxt;		/* receive next */
121177633Sdfr	tcp_seq	rcv_adv;		/* advertised window */
122180025Sdfr	u_long	rcv_wnd;		/* receive window */
123177633Sdfr	tcp_seq	rcv_up;			/* receive urgent pointer */
124177633Sdfr
125180025Sdfr	u_long	snd_wnd;		/* send window */
126177633Sdfr	u_long	snd_cwnd;		/* congestion-controlled window */
127177633Sdfr	u_long	snd_ssthresh;		/* snd_cwnd size threshold for
128177633Sdfr					 * for slow start exponential to
129180025Sdfr					 * linear switch
130177633Sdfr					 */
131180025Sdfr	tcp_seq	snd_recover;		/* for use in fast recovery */
132177633Sdfr
133177633Sdfr	u_int	t_maxopd;		/* mss plus options */
134180025Sdfr
135177633Sdfr	u_long	t_rcvtime;		/* inactivity time */
136177633Sdfr	u_long	t_starttime;		/* time connection was established */
137177633Sdfr	int	t_rtttime;		/* round trip time */
138180025Sdfr	tcp_seq	t_rtseq;		/* sequence number being timed */
139177633Sdfr
140180025Sdfr	int	t_rxtcur;		/* current retransmit value (ticks) */
141177633Sdfr	u_int	t_maxseg;		/* maximum segment size */
142177633Sdfr	int	t_srtt;			/* smoothed round-trip time */
143180025Sdfr	int	t_rttvar;		/* variance in round-trip time */
144177633Sdfr
145177633Sdfr	int	t_rxtshift;		/* log(2) of rexmt exp. backoff */
146177633Sdfr	u_int	t_rttmin;		/* minimum rtt allowed */
147180025Sdfr	u_long	t_rttupdated;		/* number of times rtt sampled */
148177633Sdfr	u_long	max_sndwnd;		/* largest window peer has offered */
149180025Sdfr
150177633Sdfr	int	t_softerror;		/* possible error not yet reported */
151177633Sdfr/* out-of-band data */
152180025Sdfr	char	t_oobflags;		/* have some */
153177633Sdfr	char	t_iobc;			/* input character */
154177633Sdfr#define	TCPOOB_HAVEDATA	0x01
155177633Sdfr#define	TCPOOB_HADDATA	0x02
156180025Sdfr/* RFC 1323 variables */
157177633Sdfr	u_char	snd_scale;		/* window scaling for send window */
158180025Sdfr	u_char	rcv_scale;		/* window scaling for recv window */
159177633Sdfr	u_char	request_r_scale;	/* pending window scaling */
160177633Sdfr	u_char	requested_s_scale;
161180025Sdfr	u_long	ts_recent;		/* timestamp echo data */
162177633Sdfr
163177633Sdfr	u_long	ts_recent_age;		/* when last updated */
164177633Sdfr	tcp_seq	last_ack_sent;
165180025Sdfr/* RFC 1644 variables */
166177633Sdfr	tcp_cc	cc_send;		/* send connection count */
167180025Sdfr	tcp_cc	cc_recv;		/* receive connection count */
168177633Sdfr/* experimental */
169177633Sdfr	u_long	snd_cwnd_prev;		/* cwnd prior to retransmit */
170180025Sdfr	u_long	snd_ssthresh_prev;	/* ssthresh prior to retransmit */
171177633Sdfr	u_long	t_badrxtwin;		/* window for retransmit recovery */
172177633Sdfr};
173177633Sdfr
174180025Sdfr/*
175177633Sdfr * Structure to hold TCP options that are only used during segment
176180025Sdfr * processing (in tcp_input), but not held in the tcpcb.
177177633Sdfr * It's basically used to reduce the number of parameters
178177633Sdfr * to tcp_dooptions.
179180025Sdfr */
180177633Sdfrstruct tcpopt {
181177633Sdfr	u_long		to_flags;	/* which options are present */
182177633Sdfr#define TOF_TS		0x0001		/* timestamp */
183180025Sdfr#define TOF_CC		0x0002		/* CC and CCnew are exclusive */
184177633Sdfr#define TOF_CCNEW	0x0004
185180025Sdfr#define	TOF_CCECHO	0x0008
186177633Sdfr#define	TOF_MSS		0x0010
187177633Sdfr#define	TOF_SCALE	0x0020
188180025Sdfr	u_int32_t	to_tsval;
189177633Sdfr	u_int32_t	to_tsecr;
190177633Sdfr	tcp_cc		to_cc;		/* holds CC or CCnew */
191177633Sdfr	tcp_cc		to_ccecho;
192180025Sdfr	u_int16_t	to_mss;
193177633Sdfr	u_int8_t 	to_requested_s_scale;
194180025Sdfr	u_int8_t 	to_pad;
195177633Sdfr};
196177633Sdfr
197180025Sdfrstruct syncache {
198177633Sdfr	inp_gen_t	sc_inp_gencnt;		/* pointer check */
199177633Sdfr	struct 		tcpcb *sc_tp;		/* tcb for listening socket */
200177633Sdfr	struct		mbuf *sc_ipopts;	/* source route */
201180025Sdfr	struct 		in_conninfo sc_inc;	/* addresses */
202177633Sdfr#define sc_route	sc_inc.inc_route
203180025Sdfr#define sc_route6	sc_inc.inc6_route
204177633Sdfr	u_int32_t	sc_tsrecent;
205177633Sdfr	tcp_cc		sc_cc_send;		/* holds CC or CCnew */
206180025Sdfr	tcp_cc		sc_cc_recv;
207177633Sdfr	tcp_seq 	sc_irs;			/* seq from peer */
208177633Sdfr	tcp_seq 	sc_iss;			/* our ISS */
209177633Sdfr	u_long		sc_rxttime;		/* retransmit time */
210180025Sdfr	u_int16_t	sc_rxtslot; 		/* retransmit counter */
211177633Sdfr	u_int16_t	sc_peer_mss;		/* peer's MSS */
212180025Sdfr	u_int16_t	sc_wnd;			/* advertised window */
213177633Sdfr	u_int8_t 	sc_requested_s_scale:4,
214177633Sdfr			sc_request_r_scale:4;
215180025Sdfr	u_int8_t	sc_flags;
216177633Sdfr#define SCF_NOOPT	0x01			/* no TCP options */
217177633Sdfr#define SCF_WINSCALE	0x02			/* negotiated window scaling */
218177633Sdfr#define SCF_TIMESTAMP	0x04			/* negotiated timestamps */
219180025Sdfr#define SCF_CC		0x08			/* negotiated CC */
220177633Sdfr#define SCF_UNREACH	0x10			/* icmp unreachable received */
221180025Sdfr#define SCF_KEEPROUTE	0x20			/* keep cloned route */
222177633Sdfr	TAILQ_ENTRY(syncache)	sc_hash;
223177633Sdfr	TAILQ_ENTRY(syncache)	sc_timerq;
224180025Sdfr};
225177633Sdfr
226177633Sdfrstruct syncache_head {
227177633Sdfr	TAILQ_HEAD(, syncache)	sch_bucket;
228180025Sdfr	u_int		sch_length;
229177633Sdfr};
230180025Sdfr
231177633Sdfr/*
232177633Sdfr * The TAO cache entry which is stored in the protocol family specific
233180025Sdfr * portion of the route metrics.
234177633Sdfr */
235177633Sdfrstruct rmxp_tao {
236177633Sdfr	tcp_cc	tao_cc;			/* latest CC in valid SYN */
237180025Sdfr	tcp_cc	tao_ccsent;		/* latest CC sent to peer */
238177633Sdfr	u_short	tao_mssopt;		/* peer's cached MSS */
239180025Sdfr#ifdef notyet
240177633Sdfr	u_short	tao_flags;		/* cache status flags */
241177633Sdfr#define	TAOF_DONT	0x0001		/* peer doesn't understand rfc1644 */
242180025Sdfr#define	TAOF_OK		0x0002		/* peer does understand rfc1644 */
243177633Sdfr#define	TAOF_UNDEF	0		/* we don't know yet */
244177633Sdfr#endif /* notyet */
245177633Sdfr};
246180025Sdfr#define rmx_taop(r)	((struct rmxp_tao *)(r).rmx_filler)
247177633Sdfr
248180025Sdfr#define	intotcpcb(ip)	((struct tcpcb *)(ip)->inp_ppcb)
249177633Sdfr#define	sototcpcb(so)	(intotcpcb(sotoinpcb(so)))
250177633Sdfr
251180025Sdfr/*
252177633Sdfr * The smoothed round-trip time and estimated variance
253177633Sdfr * are stored as fixed point numbers scaled by the values below.
254177633Sdfr * For convenience, these scales are also used in smoothing the average
255180025Sdfr * (smoothed = (1/scale)sample + ((scale-1)/scale)smoothed).
256177633Sdfr * With these scales, srtt has 3 bits to the right of the binary point,
257180025Sdfr * and thus an "ALPHA" of 0.875.  rttvar has 2 bits to the right of the
258177633Sdfr * binary point, and is smoothed with an ALPHA of 0.75.
259177633Sdfr */
260180025Sdfr#define	TCP_RTT_SCALE		32	/* multiplier for srtt; 3 bits frac. */
261177633Sdfr#define	TCP_RTT_SHIFT		5	/* shift for srtt; 3 bits frac. */
262177633Sdfr#define	TCP_RTTVAR_SCALE	16	/* multiplier for rttvar; 2 bits */
263177633Sdfr#define	TCP_RTTVAR_SHIFT	4	/* shift for rttvar; 2 bits */
264180025Sdfr#define	TCP_DELTA_SHIFT		2	/* see tcp_input.c */
265177633Sdfr
266180025Sdfr/*
267177633Sdfr * The initial retransmission should happen at rtt + 4 * rttvar.
268177633Sdfr * Because of the way we do the smoothing, srtt and rttvar
269180025Sdfr * will each average +1/2 tick of bias.  When we compute
270177633Sdfr * the retransmit timer, we want 1/2 tick of rounding and
271177633Sdfr * 1 extra tick because of +-1/2 tick uncertainty in the
272177633Sdfr * firing of the timer.  The bias will give us exactly the
273180025Sdfr * 1.5 tick we need.  But, because the bias is
274177633Sdfr * statistical, we have to test that we don't drop below
275180025Sdfr * the minimum feasible timer (which is 2 ticks).
276177633Sdfr * This version of the macro adapted from a paper by Lawrence
277177633Sdfr * Brakmo and Larry Peterson which outlines a problem caused
278180025Sdfr * by insufficient precision in the original implementation,
279177633Sdfr * which results in inappropriately large RTO values for very
280177633Sdfr * fast networks.
281177633Sdfr */
282180025Sdfr#define	TCP_REXMTVAL(tp) \
283177633Sdfr	max((tp)->t_rttmin, (((tp)->t_srtt >> (TCP_RTT_SHIFT - TCP_DELTA_SHIFT))  \
284180025Sdfr	  + (tp)->t_rttvar) >> TCP_DELTA_SHIFT)
285177633Sdfr
286177633Sdfr/*
287180025Sdfr * TCP statistics.
288177633Sdfr * Many of these should be kept per connection,
289177633Sdfr * but that's inconvenient at the moment.
290177633Sdfr */
291180025Sdfrstruct	tcpstat {
292177633Sdfr	u_long	tcps_connattempt;	/* connections initiated */
293180025Sdfr	u_long	tcps_accepts;		/* connections accepted */
294177633Sdfr	u_long	tcps_connects;		/* connections established */
295177633Sdfr	u_long	tcps_drops;		/* connections dropped */
296180025Sdfr	u_long	tcps_conndrops;		/* embryonic connections dropped */
297177633Sdfr	u_long	tcps_closed;		/* conn. closed (includes drops) */
298177633Sdfr	u_long	tcps_segstimed;		/* segs where we tried to get rtt */
299177633Sdfr	u_long	tcps_rttupdated;	/* times we succeeded */
300180025Sdfr	u_long	tcps_delack;		/* delayed acks sent */
301177633Sdfr	u_long	tcps_timeoutdrop;	/* conn. dropped in rxmt timeout */
302180025Sdfr	u_long	tcps_rexmttimeo;	/* retransmit timeouts */
303177633Sdfr	u_long	tcps_persisttimeo;	/* persist timeouts */
304177633Sdfr	u_long	tcps_keeptimeo;		/* keepalive timeouts */
305180025Sdfr	u_long	tcps_keepprobe;		/* keepalive probes sent */
306177633Sdfr	u_long	tcps_keepdrops;		/* connections dropped in keepalive */
307177633Sdfr
308177633Sdfr	u_long	tcps_sndtotal;		/* total packets sent */
309180025Sdfr	u_long	tcps_sndpack;		/* data packets sent */
310177633Sdfr	u_long	tcps_sndbyte;		/* data bytes sent */
311180025Sdfr	u_long	tcps_sndrexmitpack;	/* data packets retransmitted */
312177633Sdfr	u_long	tcps_sndrexmitbyte;	/* data bytes retransmitted */
313177633Sdfr	u_long	tcps_sndacks;		/* ack-only packets sent */
314180025Sdfr	u_long	tcps_sndprobe;		/* window probes sent */
315177633Sdfr	u_long	tcps_sndurg;		/* packets sent with URG only */
316177633Sdfr	u_long	tcps_sndwinup;		/* window update-only packets sent */
317177633Sdfr	u_long	tcps_sndctrl;		/* control (SYN|FIN|RST) packets sent */
318180025Sdfr
319177633Sdfr	u_long	tcps_rcvtotal;		/* total packets received */
320180025Sdfr	u_long	tcps_rcvpack;		/* packets received in sequence */
321177633Sdfr	u_long	tcps_rcvbyte;		/* bytes received in sequence */
322177633Sdfr	u_long	tcps_rcvbadsum;		/* packets received with ccksum errs */
323180025Sdfr	u_long	tcps_rcvbadoff;		/* packets received with bad offset */
324177633Sdfr	u_long	tcps_rcvmemdrop;	/* packets dropped for lack of memory */
325177633Sdfr	u_long	tcps_rcvshort;		/* packets received too short */
326177633Sdfr	u_long	tcps_rcvduppack;	/* duplicate-only packets received */
327180025Sdfr	u_long	tcps_rcvdupbyte;	/* duplicate-only bytes received */
328177633Sdfr	u_long	tcps_rcvpartduppack;	/* packets with some duplicate data */
329180025Sdfr	u_long	tcps_rcvpartdupbyte;	/* dup. bytes in part-dup. packets */
330177633Sdfr	u_long	tcps_rcvoopack;		/* out-of-order packets received */
331177633Sdfr	u_long	tcps_rcvoobyte;		/* out-of-order bytes received */
332180025Sdfr	u_long	tcps_rcvpackafterwin;	/* packets with data after window */
333177633Sdfr	u_long	tcps_rcvbyteafterwin;	/* bytes rcvd after window */
334177633Sdfr	u_long	tcps_rcvafterclose;	/* packets rcvd after "close" */
335177633Sdfr	u_long	tcps_rcvwinprobe;	/* rcvd window probe packets */
336180025Sdfr	u_long	tcps_rcvdupack;		/* rcvd duplicate acks */
337177633Sdfr	u_long	tcps_rcvacktoomuch;	/* rcvd acks for unsent data */
338180025Sdfr	u_long	tcps_rcvackpack;	/* rcvd ack packets */
339177633Sdfr	u_long	tcps_rcvackbyte;	/* bytes acked by rcvd acks */
340177633Sdfr	u_long	tcps_rcvwinupd;		/* rcvd window update packets */
341180025Sdfr	u_long	tcps_pawsdrop;		/* segments dropped due to PAWS */
342177633Sdfr	u_long	tcps_predack;		/* times hdr predict ok for acks */
343177633Sdfr	u_long	tcps_preddat;		/* times hdr predict ok for data pkts */
344177633Sdfr	u_long	tcps_pcbcachemiss;
345180025Sdfr	u_long	tcps_cachedrtt;		/* times cached RTT in route updated */
346177633Sdfr	u_long	tcps_cachedrttvar;	/* times cached rttvar updated */
347180025Sdfr	u_long	tcps_cachedssthresh;	/* times cached ssthresh updated */
348177633Sdfr	u_long	tcps_usedrtt;		/* times RTT initialized from route */
349177633Sdfr	u_long	tcps_usedrttvar;	/* times RTTVAR initialized from rt */
350180025Sdfr	u_long	tcps_usedssthresh;	/* times ssthresh initialized from rt*/
351177633Sdfr	u_long	tcps_persistdrop;	/* timeout in persist state */
352177633Sdfr	u_long	tcps_badsyn;		/* bogus SYN, e.g. premature ACK */
353177633Sdfr	u_long	tcps_mturesent;		/* resends due to MTU discovery */
354180025Sdfr	u_long	tcps_listendrop;	/* listen queue overflows */
355177633Sdfr
356180025Sdfr	u_long	tcps_sc_added;		/* entry added to syncache */
357177633Sdfr	u_long	tcps_sc_retransmitted;	/* syncache entry was retransmitted */
358177633Sdfr	u_long	tcps_sc_dupsyn;		/* duplicate SYN packet */
359180025Sdfr	u_long	tcps_sc_dropped;	/* could not reply to packet */
360177633Sdfr	u_long	tcps_sc_completed;	/* successful extraction of entry */
361177633Sdfr	u_long	tcps_sc_bucketoverflow;	/* syncache per-bucket limit hit */
362177633Sdfr	u_long	tcps_sc_cacheoverflow;	/* syncache cache limit hit */
363180025Sdfr	u_long	tcps_sc_reset;		/* RST removed entry from syncache */
364177633Sdfr	u_long	tcps_sc_stale;		/* timed out or listen socket gone */
365180025Sdfr	u_long	tcps_sc_aborted;	/* syncache entry aborted */
366177633Sdfr	u_long	tcps_sc_badack;		/* removed due to bad ACK */
367177633Sdfr	u_long	tcps_sc_unreach;	/* ICMP unreachable received */
368180025Sdfr	u_long	tcps_sc_zonefail;	/* zalloc() failed */
369177633Sdfr	u_long	tcps_sc_sendcookie;	/* SYN cookie sent */
370	u_long	tcps_sc_recvcookie;	/* SYN cookie received */
371};
372
373/*
374 * TCB structure exported to user-land via sysctl(3).
375 * Evil hack: declare only if in_pcb.h and sys/socketvar.h have been
376 * included.  Not all of our clients do.
377 */
378#if defined(_NETINET_IN_PCB_H_) && defined(_SYS_SOCKETVAR_H_)
379struct	xtcpcb {
380	size_t	xt_len;
381	struct	inpcb	xt_inp;
382	struct	tcpcb	xt_tp;
383	struct	xsocket	xt_socket;
384	u_quad_t	xt_alignment_hack;
385};
386#endif
387
388/*
389 * Names for TCP sysctl objects
390 */
391#define	TCPCTL_DO_RFC1323	1	/* use RFC-1323 extensions */
392#define	TCPCTL_DO_RFC1644	2	/* use RFC-1644 extensions */
393#define	TCPCTL_MSSDFLT		3	/* MSS default */
394#define TCPCTL_STATS		4	/* statistics (read-only) */
395#define	TCPCTL_RTTDFLT		5	/* default RTT estimate */
396#define	TCPCTL_KEEPIDLE		6	/* keepalive idle timer */
397#define	TCPCTL_KEEPINTVL	7	/* interval to send keepalives */
398#define	TCPCTL_SENDSPACE	8	/* send buffer space */
399#define	TCPCTL_RECVSPACE	9	/* receive buffer space */
400#define	TCPCTL_KEEPINIT		10	/* timeout for establishing syn */
401#define	TCPCTL_PCBLIST		11	/* list of all outstanding PCBs */
402#define	TCPCTL_DELACKTIME	12	/* time before sending delayed ACK */
403#define	TCPCTL_V6MSSDFLT	13	/* MSS default for IPv6 */
404#define	TCPCTL_MAXID		14
405
406#define TCPCTL_NAMES { \
407	{ 0, 0 }, \
408	{ "rfc1323", CTLTYPE_INT }, \
409	{ "rfc1644", CTLTYPE_INT }, \
410	{ "mssdflt", CTLTYPE_INT }, \
411	{ "stats", CTLTYPE_STRUCT }, \
412	{ "rttdflt", CTLTYPE_INT }, \
413	{ "keepidle", CTLTYPE_INT }, \
414	{ "keepintvl", CTLTYPE_INT }, \
415	{ "sendspace", CTLTYPE_INT }, \
416	{ "recvspace", CTLTYPE_INT }, \
417	{ "keepinit", CTLTYPE_INT }, \
418	{ "pcblist", CTLTYPE_STRUCT }, \
419	{ "delacktime", CTLTYPE_INT }, \
420	{ "v6mssdflt", CTLTYPE_INT }, \
421}
422
423
424#ifdef _KERNEL
425#ifdef SYSCTL_DECL
426SYSCTL_DECL(_net_inet_tcp);
427#endif
428
429extern	struct inpcbhead tcb;		/* head of queue of active tcpcb's */
430extern	struct inpcbinfo tcbinfo;
431extern	struct tcpstat tcpstat;	/* tcp statistics */
432extern	int tcp_mssdflt;	/* XXX */
433extern	int tcp_delack_enabled;
434extern	int tcp_do_newreno;
435extern	int path_mtu_discovery;
436extern	int ss_fltsz;
437extern	int ss_fltsz_local;
438
439void	 tcp_canceltimers(struct tcpcb *);
440struct tcpcb *
441	 tcp_close(struct tcpcb *);
442void	 tcp_ctlinput(int, struct sockaddr *, void *);
443int	 tcp_ctloutput(struct socket *, struct sockopt *);
444struct tcpcb *
445	 tcp_drop(struct tcpcb *, int);
446void	 tcp_drain(void);
447void	 tcp_fasttimo(void);
448struct rmxp_tao *
449	 tcp_gettaocache(struct in_conninfo *);
450void	 tcp_init(void);
451void	 tcp_input(struct mbuf *, int);
452void	 tcp_mss(struct tcpcb *, int);
453int	 tcp_mssopt(struct tcpcb *);
454struct inpcb *
455	 tcp_drop_syn_sent(struct inpcb *, int);
456struct inpcb *
457	 tcp_mtudisc(struct inpcb *, int);
458struct tcpcb *
459	 tcp_newtcpcb(struct inpcb *);
460int	 tcp_output(struct tcpcb *);
461struct inpcb *
462	 tcp_quench(struct inpcb *, int);
463void	 tcp_respond(struct tcpcb *, void *,
464	    struct tcphdr *, struct mbuf *, tcp_seq, tcp_seq, int);
465struct rtentry *
466	 tcp_rtlookup(struct in_conninfo *);
467void	 tcp_setpersist(struct tcpcb *);
468void	 tcp_slowtimo(void);
469struct tcptemp *
470	 tcp_maketemplate(struct tcpcb *);
471void	 tcp_fillheaders(struct tcpcb *, void *, void *);
472struct tcpcb *
473	 tcp_timers(struct tcpcb *, int);
474void	 tcp_trace(int, int, struct tcpcb *, void *, struct tcphdr *, int);
475void	 syncache_init(void);
476void	 syncache_unreach(struct in_conninfo *, struct tcphdr *);
477int	 syncache_expand(struct in_conninfo *, struct tcphdr *,
478	     struct socket **, struct mbuf *);
479int	 syncache_add(struct in_conninfo *, struct tcpopt *,
480	     struct tcphdr *, struct socket **, struct mbuf *);
481void	 syncache_chkrst(struct in_conninfo *, struct tcphdr *);
482void	 syncache_badack(struct in_conninfo *);
483
484extern	struct pr_usrreqs tcp_usrreqs;
485extern	u_long tcp_sendspace;
486extern	u_long tcp_recvspace;
487tcp_seq tcp_new_isn(struct tcpcb *);
488
489#endif /* _KERNEL */
490
491#endif /* _NETINET_TCP_VAR_H_ */
492