tcp_var.h revision 212765
1139823Simp/*-
210937Swollman * Copyright (c) 1982, 1986, 1993, 1994, 1995
31541Srgrimes *	The Regents of the University of California.  All rights reserved.
41541Srgrimes *
51541Srgrimes * Redistribution and use in source and binary forms, with or without
61541Srgrimes * modification, are permitted provided that the following conditions
71541Srgrimes * are met:
81541Srgrimes * 1. Redistributions of source code must retain the above copyright
91541Srgrimes *    notice, this list of conditions and the following disclaimer.
101541Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
111541Srgrimes *    notice, this list of conditions and the following disclaimer in the
121541Srgrimes *    documentation and/or other materials provided with the distribution.
131541Srgrimes * 4. Neither the name of the University nor the names of its contributors
141541Srgrimes *    may be used to endorse or promote products derived from this software
151541Srgrimes *    without specific prior written permission.
161541Srgrimes *
171541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
181541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
191541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
201541Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
211541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
221541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
231541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
241541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
251541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
261541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
271541Srgrimes * SUCH DAMAGE.
281541Srgrimes *
2910937Swollman *	@(#)tcp_var.h	8.4 (Berkeley) 5/24/95
3050477Speter * $FreeBSD: head/sys/netinet/tcp_var.h 212765 2010-09-16 21:06:45Z andre $
311541Srgrimes */
321541Srgrimes
332169Spaul#ifndef _NETINET_TCP_VAR_H_
342169Spaul#define _NETINET_TCP_VAR_H_
3586764Sjlemon
3698102Shsu#include <netinet/tcp.h>
3786764Sjlemon
38195699Srwatson#ifdef _KERNEL
39195699Srwatson#include <net/vnet.h>
40191688Szec
411541Srgrimes/*
421541Srgrimes * Kernel variables for tcp.
431541Srgrimes */
44195699SrwatsonVNET_DECLARE(int, tcp_do_rfc1323);
45207369Sbz#define	V_tcp_do_rfc1323	VNET(tcp_do_rfc1323)
46207369Sbz
47195699SrwatsonVNET_DECLARE(int, tcp_reass_qsize);
48195699SrwatsonVNET_DECLARE(struct uma_zone *, tcp_reass_zone);
49195727Srwatson#define	V_tcp_reass_qsize	VNET(tcp_reass_qsize)
50195727Srwatson#define	V_tcp_reass_zone	VNET(tcp_reass_zone)
51195699Srwatson#endif /* _KERNEL */
52195699Srwatson
5355679Sshin/* TCP segment queue entry */
5455679Sshinstruct tseg_qent {
5560938Sjake	LIST_ENTRY(tseg_qent) tqe_q;
5655679Sshin	int	tqe_len;		/* TCP segment data length */
5755679Sshin	struct	tcphdr *tqe_th;		/* a pointer to tcp header */
5855679Sshin	struct	mbuf	*tqe_m;		/* mbuf contains packet */
5955679Sshin};
6060938SjakeLIST_HEAD(tsegqe_head, tseg_qent);
6155679Sshin
62130989Spsstruct sackblk {
63130989Sps	tcp_seq start;		/* start seq no. of sack block */
64131078Sbms	tcp_seq end;		/* end seq no. */
65130989Sps};
66130989Sps
67130989Spsstruct sackhole {
68130989Sps	tcp_seq start;		/* start seq no. of hole */
69130989Sps	tcp_seq end;		/* end seq no. */
70130989Sps	tcp_seq rxmit;		/* next seq. no in hole to be retransmitted */
71145370Sps	TAILQ_ENTRY(sackhole) scblink;	/* scoreboard linkage */
72130989Sps};
73131078Sbms
74146123Spsstruct sackhint {
75146123Sps	struct sackhole	*nexthole;
76146123Sps	int		sack_bytes_rexmit;
77195634Slstewart
78195634Slstewart	int		ispare;		/* explicit pad for 64bit alignment */
79195634Slstewart	uint64_t	_pad[2];	/* 1 sacked_bytes, 1 TBD */
80146123Sps};
81146123Sps
8255679Sshinstruct tcptemp {
8355679Sshin	u_char	tt_ipgen[40]; /* the size must be of max ip header, now IPv6 */
8455679Sshin	struct	tcphdr tt_t;
8555679Sshin};
8655679Sshin
8755679Sshin#define tcp6cb		tcpcb  /* for KAME src sync over BSD*'s */
8855679Sshin
89169541Sandre/* Neighbor Discovery, Neighbor Unreachability Detection Upper layer hint. */
90169541Sandre#ifdef INET6
91169541Sandre#define ND6_HINT(tp)						\
92169541Sandredo {								\
93169541Sandre	if ((tp) && (tp)->t_inpcb &&				\
94169541Sandre	    ((tp)->t_inpcb->inp_vflag & INP_IPV6) != 0)		\
95169541Sandre		nd6_nud_hint(NULL, NULL, 0);			\
96169541Sandre} while (0)
97169541Sandre#else
98169541Sandre#define ND6_HINT(tp)
99169541Sandre#endif
100169541Sandre
1011541Srgrimes/*
1021541Srgrimes * Tcp control block, one per tcp; fields:
10332821Sdg * Organized for 16 byte cacheline efficiency.
1041541Srgrimes */
1051541Srgrimesstruct tcpcb {
106126193Sandre	struct	tsegqe_head t_segq;	/* segment reassembly queue */
107195634Slstewart	void	*t_pspare[2];		/* new reassembly queue */
108126193Sandre	int	t_segqlen;		/* segment reassembly queue length */
10932821Sdg	int	t_dupacks;		/* consecutive dup acks recd */
11032821Sdg
111172309Ssilby	struct tcp_timer *t_timers;	/* All the TCP timers in one struct */
11232821Sdg
11332821Sdg	struct	inpcb *t_inpcb;		/* back pointer to internet pcb */
11411187Swollman	int	t_state;		/* state of this connection */
11511187Swollman	u_int	t_flags;
1161541Srgrimes
117191688Szec	struct	vnet *t_vnet;		/* back pointer to parent vnet */
118191688Szec
1191541Srgrimes	tcp_seq	snd_una;		/* send unacknowledged */
12032821Sdg	tcp_seq	snd_max;		/* highest sequence number sent;
12132821Sdg					 * used to recognize retransmits
12232821Sdg					 */
1231541Srgrimes	tcp_seq	snd_nxt;		/* send next */
1241541Srgrimes	tcp_seq	snd_up;			/* send urgent pointer */
12532821Sdg
1261541Srgrimes	tcp_seq	snd_wl1;		/* window update seg seq number */
1271541Srgrimes	tcp_seq	snd_wl2;		/* window update seg ack number */
1281541Srgrimes	tcp_seq	iss;			/* initial send sequence number */
12932821Sdg	tcp_seq	irs;			/* initial receive sequence number */
13032821Sdg
13132821Sdg	tcp_seq	rcv_nxt;		/* receive next */
13232821Sdg	tcp_seq	rcv_adv;		/* advertised window */
1331541Srgrimes	u_long	rcv_wnd;		/* receive window */
1341541Srgrimes	tcp_seq	rcv_up;			/* receive urgent pointer */
13532821Sdg
13632821Sdg	u_long	snd_wnd;		/* send window */
1371541Srgrimes	u_long	snd_cwnd;		/* congestion-controlled window */
138212765Sandre	u_long	snd_spare1;		/* unused */
13913765Smpp	u_long	snd_ssthresh;		/* snd_cwnd size threshold for
1401541Srgrimes					 * for slow start exponential to
1411541Srgrimes					 * linear switch
1421541Srgrimes					 */
143212765Sandre	u_long	snd_spare2;		/* unused */
144109175Shsu	tcp_seq	snd_recover;		/* for use in NewReno Fast Recovery */
14560067Sjlemon
14632821Sdg	u_int	t_maxopd;		/* mss plus options */
14732821Sdg
148194303Sjhb	u_int	t_rcvtime;		/* inactivity time */
149194303Sjhb	u_int	t_starttime;		/* time connection was established */
150194303Sjhb	u_int	t_rtttime;		/* RTT measurement start time */
1511541Srgrimes	tcp_seq	t_rtseq;		/* sequence number being timed */
15232821Sdg
153212765Sandre	u_int	t_bw_spare1;		/* unused */
154212765Sandre	tcp_seq	t_bw_spare2;		/* unused */
155102017Sdillon
15650673Sjlemon	int	t_rxtcur;		/* current retransmit value (ticks) */
15732821Sdg	u_int	t_maxseg;		/* maximum segment size */
15811187Swollman	int	t_srtt;			/* smoothed round-trip time */
15911187Swollman	int	t_rttvar;		/* variance in round-trip time */
16032821Sdg
16132821Sdg	int	t_rxtshift;		/* log(2) of rexmt exp. backoff */
16211187Swollman	u_int	t_rttmin;		/* minimum rtt allowed */
163102017Sdillon	u_int	t_rttbest;		/* best rtt we've seen */
16432821Sdg	u_long	t_rttupdated;		/* number of times rtt sampled */
1651541Srgrimes	u_long	max_sndwnd;		/* largest window peer has offered */
1661541Srgrimes
16732821Sdg	int	t_softerror;		/* possible error not yet reported */
1681541Srgrimes/* out-of-band data */
1691541Srgrimes	char	t_oobflags;		/* have some */
1701541Srgrimes	char	t_iobc;			/* input character */
1711541Srgrimes/* RFC 1323 variables */
1721541Srgrimes	u_char	snd_scale;		/* window scaling for send window */
1731541Srgrimes	u_char	rcv_scale;		/* window scaling for recv window */
1741541Srgrimes	u_char	request_r_scale;	/* pending window scaling */
175162277Sandre	u_int32_t  ts_recent;		/* timestamp echo data */
176194303Sjhb	u_int	ts_recent_age;		/* when last updated */
177162277Sandre	u_int32_t  ts_offset;		/* our timestamp offset */
17832821Sdg
1791541Srgrimes	tcp_seq	last_ack_sent;
18050673Sjlemon/* experimental */
18150673Sjlemon	u_long	snd_cwnd_prev;		/* cwnd prior to retransmit */
18250673Sjlemon	u_long	snd_ssthresh_prev;	/* ssthresh prior to retransmit */
183117650Shsu	tcp_seq	snd_recover_prev;	/* snd_recover prior to retransmit */
184194303Sjhb	u_int	t_badrxtwin;		/* window for retransmit recovery */
185112957Shsu	u_char	snd_limited;		/* segments limited transmitted */
186131078Sbms/* SACK related state */
187130989Sps	int	snd_numholes;		/* number of holes seen by sender */
188146953Sps	TAILQ_HEAD(sackhole_head, sackhole) snd_holes;
189146953Sps					/* SACK scoreboard (sorted) */
190146630Sps	tcp_seq	snd_fack;		/* last seq number(+1) sack'd by rcv'r*/
191130989Sps	int	rcv_numsacks;		/* # distinct sack blks present */
192130989Sps	struct sackblk sackblks[MAX_SACK_BLKS]; /* seq nos. of sack blocks */
193136151Sps	tcp_seq sack_newdata;		/* New data xmitted in this recovery
194136151Sps					   episode starts at this seq number */
195146123Sps	struct sackhint	sackhint;	/* SACK scoreboard hint */
196155767Sandre	int	t_rttlow;		/* smallest observerved RTT */
197166405Sandre	u_int32_t	rfbuf_ts;	/* recv buffer autoscaling timestamp */
198166405Sandre	int	rfbuf_cnt;		/* recv buffer autoscaling byte count */
199191688Szec	struct toe_usrreqs *t_tu;	/* offload operations vector */
200174560Skmacy	void	*t_toe;			/* TOE pcb pointer */
201187289Slstewart	int	t_bytes_acked;		/* # bytes acked during current RTT */
202195634Slstewart
203195634Slstewart	int	t_ispare;		/* explicit pad for 64bit alignment */
204195634Slstewart	void	*t_pspare2[6];		/* 2 CC / 4 TBD */
205195634Slstewart	uint64_t _pad[12];		/* 7 UTO, 5 TBD (1-2 CC/RTT?) */
2061541Srgrimes};
2071541Srgrimes
208185855Srwatson/*
209185855Srwatson * Flags and utility macros for the t_flags field.
210185855Srwatson */
211185855Srwatson#define	TF_ACKNOW	0x000001	/* ack peer immediately */
212185855Srwatson#define	TF_DELACK	0x000002	/* ack, but try to delay it */
213185855Srwatson#define	TF_NODELAY	0x000004	/* don't delay packets to coalesce */
214185855Srwatson#define	TF_NOOPT	0x000008	/* don't use tcp options */
215185855Srwatson#define	TF_SENTFIN	0x000010	/* have sent FIN */
216185855Srwatson#define	TF_REQ_SCALE	0x000020	/* have/will request window scaling */
217185855Srwatson#define	TF_RCVD_SCALE	0x000040	/* other side has requested scaling */
218185855Srwatson#define	TF_REQ_TSTMP	0x000080	/* have/will request timestamps */
219185855Srwatson#define	TF_RCVD_TSTMP	0x000100	/* a timestamp was received in SYN */
220185855Srwatson#define	TF_SACK_PERMIT	0x000200	/* other side said I could SACK */
221185855Srwatson#define	TF_NEEDSYN	0x000400	/* send SYN (implicit state) */
222185855Srwatson#define	TF_NEEDFIN	0x000800	/* send FIN (implicit state) */
223185855Srwatson#define	TF_NOPUSH	0x001000	/* don't push */
224185855Srwatson#define	TF_MORETOCOME	0x010000	/* More data to be appended to sock */
225185855Srwatson#define	TF_LQ_OVERFLOW	0x020000	/* listen queue overflow */
226185855Srwatson#define	TF_LASTIDLE	0x040000	/* connection was previously idle */
227185855Srwatson#define	TF_RXWIN0SENT	0x080000	/* sent a receiver win 0 in response */
228185855Srwatson#define	TF_FASTRECOVERY	0x100000	/* in NewReno Fast Recovery */
229185855Srwatson#define	TF_WASFRECOVERY	0x200000	/* was in NewReno Fast Recovery */
230185855Srwatson#define	TF_SIGNATURE	0x400000	/* require MD5 digests (RFC2385) */
231185855Srwatson#define	TF_FORCEDATA	0x800000	/* force out a byte */
232185855Srwatson#define	TF_TSO		0x1000000	/* TSO enabled on this connection */
233185855Srwatson#define	TF_TOE		0x2000000	/* this connection is offloaded */
234185855Srwatson#define	TF_ECN_PERMIT	0x4000000	/* connection ECN-ready */
235185855Srwatson#define	TF_ECN_SND_CWR	0x8000000	/* ECN CWR in queue */
236185855Srwatson#define	TF_ECN_SND_ECE	0x10000000	/* ECN ECE in queue */
237185855Srwatson
238117650Shsu#define IN_FASTRECOVERY(tp)	(tp->t_flags & TF_FASTRECOVERY)
239117650Shsu#define ENTER_FASTRECOVERY(tp)	tp->t_flags |= TF_FASTRECOVERY
240117650Shsu#define EXIT_FASTRECOVERY(tp)	tp->t_flags &= ~TF_FASTRECOVERY
241117650Shsu
242185855Srwatson/*
243185855Srwatson * Flags for the t_oobflags field.
244185855Srwatson */
245185855Srwatson#define	TCPOOB_HAVEDATA	0x01
246185855Srwatson#define	TCPOOB_HADDATA	0x02
247185855Srwatson
248125680Sbms#ifdef TCP_SIGNATURE
2496247Swollman/*
250125680Sbms * Defines which are needed by the xform_tcp module and tcp_[in|out]put
251125680Sbms * for SADB verification and lookup.
252125680Sbms */
253125680Sbms#define	TCP_SIGLEN	16	/* length of computed digest in bytes */
254125680Sbms#define	TCP_KEYLEN_MIN	1	/* minimum length of TCP-MD5 key */
255125680Sbms#define	TCP_KEYLEN_MAX	80	/* maximum length of TCP-MD5 key */
256125680Sbms/*
257125680Sbms * Only a single SA per host may be specified at this time. An SPI is
258125680Sbms * needed in order for the KEY_ALLOCSA() lookup to work.
259125680Sbms */
260125680Sbms#define	TCP_SIG_SPI	0x1000
261125680Sbms#endif /* TCP_SIGNATURE */
262125680Sbms
263125680Sbms/*
2646247Swollman * Structure to hold TCP options that are only used during segment
2656247Swollman * processing (in tcp_input), but not held in the tcpcb.
2666247Swollman * It's basically used to reduce the number of parameters
267167606Sandre * to tcp_dooptions and tcp_addoptions.
268167606Sandre * The binary order of the to_flags is relevant for packing of the
269167606Sandre * options in tcp_addoptions.
2706247Swollman */
2716247Swollmanstruct tcpopt {
272195654Slstewart	u_int64_t	to_flags;	/* which options are present */
273167606Sandre#define	TOF_MSS		0x0001		/* maximum segment size */
274167606Sandre#define	TOF_SCALE	0x0002		/* window scaling */
275178349Sbz#define	TOF_SACKPERM	0x0004		/* SACK permitted */
276167606Sandre#define	TOF_TS		0x0010		/* timestamp */
277178349Sbz#define	TOF_SIGNATURE	0x0040		/* TCP-MD5 signature option (RFC2385) */
278168906Sandre#define	TOF_SACK	0x0080		/* Peer sent SACK option */
279168906Sandre#define	TOF_MAXOPT	0x0100
280168906Sandre	u_int32_t	to_tsval;	/* new timestamp */
281167606Sandre	u_int32_t	to_tsecr;	/* reflected timestamp */
282195654Slstewart	u_char		*to_sacks;	/* pointer to the first SACK blocks */
283195654Slstewart	u_char		*to_signature;	/* pointer to the TCP-MD5 signature */
284167606Sandre	u_int16_t	to_mss;		/* maximum segment size */
285167606Sandre	u_int8_t	to_wscale;	/* window scaling */
286147637Sps	u_int8_t	to_nsacks;	/* number of SACK blocks */
2876247Swollman};
2886247Swollman
289159949Sandre/*
290159949Sandre * Flags for tcp_dooptions.
291159949Sandre */
292159949Sandre#define	TO_SYN		0x01		/* parse SYN-only options */
293159949Sandre
294122922Sandrestruct hc_metrics_lite {	/* must stay in sync with hc_metrics */
295122922Sandre	u_long	rmx_mtu;	/* MTU for this path */
296122922Sandre	u_long	rmx_ssthresh;	/* outbound gateway buffer limit */
297122922Sandre	u_long	rmx_rtt;	/* estimated round trip time */
298122922Sandre	u_long	rmx_rttvar;	/* estimated rtt variance */
299122922Sandre	u_long	rmx_bandwidth;	/* estimated bandwidth */
300122922Sandre	u_long	rmx_cwnd;	/* congestion window */
301122922Sandre	u_long	rmx_sendpipe;   /* outbound delay-bandwidth product */
302122922Sandre	u_long	rmx_recvpipe;   /* inbound delay-bandwidth product */
303122922Sandre};
304122922Sandre
305159725Sandre#ifndef _NETINET_IN_PCB_H_
306159725Sandrestruct in_conninfo;
307159725Sandre#endif /* _NETINET_IN_PCB_H_ */
308159725Sandre
309111145Sjlemonstruct tcptw {
310111145Sjlemon	struct inpcb	*tw_inpcb;	/* XXX back pointer to internet pcb */
311111145Sjlemon	tcp_seq		snd_nxt;
312111145Sjlemon	tcp_seq		rcv_nxt;
313121850Ssilby	tcp_seq		iss;
314121884Ssilby	tcp_seq		irs;
315111145Sjlemon	u_short		last_win;	/* cached window value */
316111145Sjlemon	u_short		tw_so_options;	/* copy of so_options */
317111145Sjlemon	struct ucred	*tw_cred;	/* user credentials */
318194303Sjhb	u_int32_t	t_recent;
319169477Sandre	u_int32_t	ts_offset;	/* our timestamp offset */
320194303Sjhb	u_int		t_starttime;
321112009Sjlemon	int		tw_time;
322162111Sru	TAILQ_ENTRY(tcptw) tw_2msl;
323111145Sjlemon};
324133874Srwatson
3251541Srgrimes#define	intotcpcb(ip)	((struct tcpcb *)(ip)->inp_ppcb)
326111145Sjlemon#define	intotw(ip)	((struct tcptw *)(ip)->inp_ppcb)
3271541Srgrimes#define	sototcpcb(so)	(intotcpcb(sotoinpcb(so)))
3281541Srgrimes
3291541Srgrimes/*
3301541Srgrimes * The smoothed round-trip time and estimated variance
3311541Srgrimes * are stored as fixed point numbers scaled by the values below.
3321541Srgrimes * For convenience, these scales are also used in smoothing the average
3331541Srgrimes * (smoothed = (1/scale)sample + ((scale-1)/scale)smoothed).
3341541Srgrimes * With these scales, srtt has 3 bits to the right of the binary point,
3351541Srgrimes * and thus an "ALPHA" of 0.875.  rttvar has 2 bits to the right of the
3361541Srgrimes * binary point, and is smoothed with an ALPHA of 0.75.
3371541Srgrimes */
33814753Swollman#define	TCP_RTT_SCALE		32	/* multiplier for srtt; 3 bits frac. */
33914753Swollman#define	TCP_RTT_SHIFT		5	/* shift for srtt; 3 bits frac. */
34014753Swollman#define	TCP_RTTVAR_SCALE	16	/* multiplier for rttvar; 2 bits */
34114753Swollman#define	TCP_RTTVAR_SHIFT	4	/* shift for rttvar; 2 bits */
34214753Swollman#define	TCP_DELTA_SHIFT		2	/* see tcp_input.c */
3431541Srgrimes
3441541Srgrimes/*
3451541Srgrimes * The initial retransmission should happen at rtt + 4 * rttvar.
3461541Srgrimes * Because of the way we do the smoothing, srtt and rttvar
3471541Srgrimes * will each average +1/2 tick of bias.  When we compute
3481541Srgrimes * the retransmit timer, we want 1/2 tick of rounding and
3491541Srgrimes * 1 extra tick because of +-1/2 tick uncertainty in the
3501541Srgrimes * firing of the timer.  The bias will give us exactly the
3511541Srgrimes * 1.5 tick we need.  But, because the bias is
3521541Srgrimes * statistical, we have to test that we don't drop below
3531541Srgrimes * the minimum feasible timer (which is 2 ticks).
35414753Swollman * This version of the macro adapted from a paper by Lawrence
35514753Swollman * Brakmo and Larry Peterson which outlines a problem caused
35614753Swollman * by insufficient precision in the original implementation,
35714753Swollman * which results in inappropriately large RTO values for very
35814753Swollman * fast networks.
3591541Srgrimes */
3601541Srgrimes#define	TCP_REXMTVAL(tp) \
36135419Sdg	max((tp)->t_rttmin, (((tp)->t_srtt >> (TCP_RTT_SHIFT - TCP_DELTA_SHIFT))  \
36216141Swollman	  + (tp)->t_rttvar) >> TCP_DELTA_SHIFT)
3631541Srgrimes
3641541Srgrimes/*
3651541Srgrimes * TCP statistics.
3661541Srgrimes * Many of these should be kept per connection,
3671541Srgrimes * but that's inconvenient at the moment.
3681541Srgrimes */
3691541Srgrimesstruct	tcpstat {
3701541Srgrimes	u_long	tcps_connattempt;	/* connections initiated */
3711541Srgrimes	u_long	tcps_accepts;		/* connections accepted */
3721541Srgrimes	u_long	tcps_connects;		/* connections established */
3731541Srgrimes	u_long	tcps_drops;		/* connections dropped */
3741541Srgrimes	u_long	tcps_conndrops;		/* embryonic connections dropped */
375124258Sandre	u_long	tcps_minmssdrops;	/* average minmss too low drops */
3761541Srgrimes	u_long	tcps_closed;		/* conn. closed (includes drops) */
3771541Srgrimes	u_long	tcps_segstimed;		/* segs where we tried to get rtt */
3781541Srgrimes	u_long	tcps_rttupdated;	/* times we succeeded */
3791541Srgrimes	u_long	tcps_delack;		/* delayed acks sent */
3801541Srgrimes	u_long	tcps_timeoutdrop;	/* conn. dropped in rxmt timeout */
3811541Srgrimes	u_long	tcps_rexmttimeo;	/* retransmit timeouts */
3821541Srgrimes	u_long	tcps_persisttimeo;	/* persist timeouts */
3831541Srgrimes	u_long	tcps_keeptimeo;		/* keepalive timeouts */
3841541Srgrimes	u_long	tcps_keepprobe;		/* keepalive probes sent */
3851541Srgrimes	u_long	tcps_keepdrops;		/* connections dropped in keepalive */
3861541Srgrimes
3871541Srgrimes	u_long	tcps_sndtotal;		/* total packets sent */
3881541Srgrimes	u_long	tcps_sndpack;		/* data packets sent */
3891541Srgrimes	u_long	tcps_sndbyte;		/* data bytes sent */
3901541Srgrimes	u_long	tcps_sndrexmitpack;	/* data packets retransmitted */
3911541Srgrimes	u_long	tcps_sndrexmitbyte;	/* data bytes retransmitted */
392100373Sdillon	u_long	tcps_sndrexmitbad;	/* unnecessary packet retransmissions */
3931541Srgrimes	u_long	tcps_sndacks;		/* ack-only packets sent */
3941541Srgrimes	u_long	tcps_sndprobe;		/* window probes sent */
3951541Srgrimes	u_long	tcps_sndurg;		/* packets sent with URG only */
3961541Srgrimes	u_long	tcps_sndwinup;		/* window update-only packets sent */
3971541Srgrimes	u_long	tcps_sndctrl;		/* control (SYN|FIN|RST) packets sent */
3981541Srgrimes
3991541Srgrimes	u_long	tcps_rcvtotal;		/* total packets received */
4001541Srgrimes	u_long	tcps_rcvpack;		/* packets received in sequence */
4011541Srgrimes	u_long	tcps_rcvbyte;		/* bytes received in sequence */
4021541Srgrimes	u_long	tcps_rcvbadsum;		/* packets received with ccksum errs */
4031541Srgrimes	u_long	tcps_rcvbadoff;		/* packets received with bad offset */
40452904Sshin	u_long	tcps_rcvmemdrop;	/* packets dropped for lack of memory */
4051541Srgrimes	u_long	tcps_rcvshort;		/* packets received too short */
4061541Srgrimes	u_long	tcps_rcvduppack;	/* duplicate-only packets received */
4071541Srgrimes	u_long	tcps_rcvdupbyte;	/* duplicate-only bytes received */
4081541Srgrimes	u_long	tcps_rcvpartduppack;	/* packets with some duplicate data */
4091541Srgrimes	u_long	tcps_rcvpartdupbyte;	/* dup. bytes in part-dup. packets */
4101541Srgrimes	u_long	tcps_rcvoopack;		/* out-of-order packets received */
4111541Srgrimes	u_long	tcps_rcvoobyte;		/* out-of-order bytes received */
4121541Srgrimes	u_long	tcps_rcvpackafterwin;	/* packets with data after window */
4131541Srgrimes	u_long	tcps_rcvbyteafterwin;	/* bytes rcvd after window */
4141541Srgrimes	u_long	tcps_rcvafterclose;	/* packets rcvd after "close" */
4151541Srgrimes	u_long	tcps_rcvwinprobe;	/* rcvd window probe packets */
4161541Srgrimes	u_long	tcps_rcvdupack;		/* rcvd duplicate acks */
4171541Srgrimes	u_long	tcps_rcvacktoomuch;	/* rcvd acks for unsent data */
4181541Srgrimes	u_long	tcps_rcvackpack;	/* rcvd ack packets */
4191541Srgrimes	u_long	tcps_rcvackbyte;	/* bytes acked by rcvd acks */
4201541Srgrimes	u_long	tcps_rcvwinupd;		/* rcvd window update packets */
4211541Srgrimes	u_long	tcps_pawsdrop;		/* segments dropped due to PAWS */
4221541Srgrimes	u_long	tcps_predack;		/* times hdr predict ok for acks */
4231541Srgrimes	u_long	tcps_preddat;		/* times hdr predict ok for data pkts */
4241541Srgrimes	u_long	tcps_pcbcachemiss;
4259263Swollman	u_long	tcps_cachedrtt;		/* times cached RTT in route updated */
4269263Swollman	u_long	tcps_cachedrttvar;	/* times cached rttvar updated */
4279263Swollman	u_long	tcps_cachedssthresh;	/* times cached ssthresh updated */
4289470Swollman	u_long	tcps_usedrtt;		/* times RTT initialized from route */
4299470Swollman	u_long	tcps_usedrttvar;	/* times RTTVAR initialized from rt */
4309470Swollman	u_long	tcps_usedssthresh;	/* times ssthresh initialized from rt*/
43110937Swollman	u_long	tcps_persistdrop;	/* timeout in persist state */
43210937Swollman	u_long	tcps_badsyn;		/* bogus SYN, e.g. premature ACK */
43311415Swollman	u_long	tcps_mturesent;		/* resends due to MTU discovery */
43414281Sbde	u_long	tcps_listendrop;	/* listen queue overflows */
435128653Ssilby	u_long	tcps_badrst;		/* ignored RSTs in the window */
43686764Sjlemon
43786764Sjlemon	u_long	tcps_sc_added;		/* entry added to syncache */
43886764Sjlemon	u_long	tcps_sc_retransmitted;	/* syncache entry was retransmitted */
43986764Sjlemon	u_long	tcps_sc_dupsyn;		/* duplicate SYN packet */
44086764Sjlemon	u_long	tcps_sc_dropped;	/* could not reply to packet */
44186764Sjlemon	u_long	tcps_sc_completed;	/* successful extraction of entry */
44286764Sjlemon	u_long	tcps_sc_bucketoverflow;	/* syncache per-bucket limit hit */
44386764Sjlemon	u_long	tcps_sc_cacheoverflow;	/* syncache cache limit hit */
44486764Sjlemon	u_long	tcps_sc_reset;		/* RST removed entry from syncache */
44586764Sjlemon	u_long	tcps_sc_stale;		/* timed out or listen socket gone */
44686764Sjlemon	u_long	tcps_sc_aborted;	/* syncache entry aborted */
44786764Sjlemon	u_long	tcps_sc_badack;		/* removed due to bad ACK */
44886764Sjlemon	u_long	tcps_sc_unreach;	/* ICMP unreachable received */
44986764Sjlemon	u_long	tcps_sc_zonefail;	/* zalloc() failed */
45086764Sjlemon	u_long	tcps_sc_sendcookie;	/* SYN cookie sent */
45186764Sjlemon	u_long	tcps_sc_recvcookie;	/* SYN cookie received */
452122922Sandre
453122922Sandre	u_long	tcps_hc_added;		/* entry added to hostcache */
454122922Sandre	u_long	tcps_hc_bucketoverflow;	/* hostcache per bucket limit hit */
455130989Sps
456167036Smohans	u_long  tcps_finwait2_drops;    /* Drop FIN_WAIT_2 connection after time limit */
457167036Smohans
458130989Sps	/* SACK related stats */
459130989Sps	u_long	tcps_sack_recovery_episode; /* SACK recovery episodes */
460130989Sps	u_long  tcps_sack_rexmits;	    /* SACK rexmit segments   */
461133874Srwatson	u_long  tcps_sack_rexmit_bytes;	    /* SACK rexmit bytes      */
462130989Sps	u_long  tcps_sack_rcv_blocks;	    /* SACK blocks (options) received */
463130989Sps	u_long  tcps_sack_send_blocks;	    /* SACK blocks (options) sent     */
464143339Sps	u_long  tcps_sack_sboverflow; 	    /* times scoreboard overflowed */
465181056Srpaulo
466181056Srpaulo	/* ECN related stats */
467181056Srpaulo	u_long	tcps_ecn_ce;		/* ECN Congestion Experienced */
468181056Srpaulo	u_long	tcps_ecn_ect0;		/* ECN Capable Transport */
469181056Srpaulo	u_long	tcps_ecn_ect1;		/* ECN Capable Transport */
470181056Srpaulo	u_long	tcps_ecn_shs;		/* ECN successful handshakes */
471181056Srpaulo	u_long	tcps_ecn_rcwnd;		/* # times ECN reduced the cwnd */
472195634Slstewart
473195634Slstewart	u_long	_pad[12];		/* 6 UTO, 6 TBD */
4741541Srgrimes};
4751541Srgrimes
476190978Srwatson#ifdef _KERNEL
477196039Srwatson/*
478196039Srwatson * In-kernel consumers can use these accessor macros directly to update
479196039Srwatson * stats.
480196039Srwatson */
481190948Srwatson#define	TCPSTAT_ADD(name, val)	V_tcpstat.name += (val)
482190948Srwatson#define	TCPSTAT_INC(name)	TCPSTAT_ADD(name, 1)
483196039Srwatson
484196039Srwatson/*
485196039Srwatson * Kernel module consumers must use this accessor macro.
486196039Srwatson */
487196039Srwatsonvoid	kmod_tcpstat_inc(int statnum);
488196039Srwatson#define	KMOD_TCPSTAT_INC(name)						\
489196039Srwatson	kmod_tcpstat_inc(offsetof(struct tcpstat, name) / sizeof(u_long))
490190978Srwatson#endif
491190948Srwatson
4926247Swollman/*
49336079Swollman * TCB structure exported to user-land via sysctl(3).
49437183Sjhay * Evil hack: declare only if in_pcb.h and sys/socketvar.h have been
49537183Sjhay * included.  Not all of our clients do.
49636079Swollman */
49737183Sjhay#if defined(_NETINET_IN_PCB_H_) && defined(_SYS_SOCKETVAR_H_)
498197244Ssilbystruct xtcp_timer {
499197244Ssilby	int tt_rexmt;	/* retransmit timer */
500197244Ssilby	int tt_persist;	/* retransmit persistence */
501197244Ssilby	int tt_keep;	/* keepalive */
502197244Ssilby	int tt_2msl;	/* 2*msl TIME_WAIT timer */
503197244Ssilby	int tt_delack;	/* delayed ACK timer */
504197244Ssilby	int t_rcvtime; 	/* Time since last packet received */
505197244Ssilby};
50636079Swollmanstruct	xtcpcb {
50736079Swollman	size_t	xt_len;
50836079Swollman	struct	inpcb	xt_inp;
50936079Swollman	struct	tcpcb	xt_tp;
51036079Swollman	struct	xsocket	xt_socket;
511197244Ssilby	struct	xtcp_timer xt_timer;
51236079Swollman	u_quad_t	xt_alignment_hack;
51336079Swollman};
51436079Swollman#endif
51536079Swollman
51636079Swollman/*
5176247Swollman * Names for TCP sysctl objects
5186247Swollman */
5196247Swollman#define	TCPCTL_DO_RFC1323	1	/* use RFC-1323 extensions */
5206247Swollman#define	TCPCTL_MSSDFLT		3	/* MSS default */
5216472Swollman#define TCPCTL_STATS		4	/* statistics (read-only) */
5226472Swollman#define	TCPCTL_RTTDFLT		5	/* default RTT estimate */
5236472Swollman#define	TCPCTL_KEEPIDLE		6	/* keepalive idle timer */
5246472Swollman#define	TCPCTL_KEEPINTVL	7	/* interval to send keepalives */
52518281Spst#define	TCPCTL_SENDSPACE	8	/* send buffer space */
52618281Spst#define	TCPCTL_RECVSPACE	9	/* receive buffer space */
52763431Ssheldonh#define	TCPCTL_KEEPINIT		10	/* timeout for establishing syn */
52836079Swollman#define	TCPCTL_PCBLIST		11	/* list of all outstanding PCBs */
52950673Sjlemon#define	TCPCTL_DELACKTIME	12	/* time before sending delayed ACK */
53052904Sshin#define	TCPCTL_V6MSSDFLT	13	/* MSS default for IPv6 */
531130989Sps#define	TCPCTL_SACK		14	/* Selective Acknowledgement,rfc 2018 */
532141381Smaxim#define	TCPCTL_DROP		15	/* drop tcp connection */
533141381Smaxim#define	TCPCTL_MAXID		16
534167036Smohans#define TCPCTL_FINWAIT2_TIMEOUT        17
5356247Swollman
5366247Swollman#define TCPCTL_NAMES { \
5376247Swollman	{ 0, 0 }, \
5386348Swollman	{ "rfc1323", CTLTYPE_INT }, \
5396247Swollman	{ "mssdflt", CTLTYPE_INT }, \
5406472Swollman	{ "stats", CTLTYPE_STRUCT }, \
5416472Swollman	{ "rttdflt", CTLTYPE_INT }, \
5426472Swollman	{ "keepidle", CTLTYPE_INT }, \
5436472Swollman	{ "keepintvl", CTLTYPE_INT }, \
5446472Swollman	{ "sendspace", CTLTYPE_INT }, \
5456472Swollman	{ "recvspace", CTLTYPE_INT }, \
54618281Spst	{ "keepinit", CTLTYPE_INT }, \
54736079Swollman	{ "pcblist", CTLTYPE_STRUCT }, \
54850673Sjlemon	{ "delacktime", CTLTYPE_INT }, \
54952904Sshin	{ "v6mssdflt", CTLTYPE_INT }, \
550122922Sandre	{ "maxid", CTLTYPE_INT }, \
5516247Swollman}
5526247Swollman
55344078Sdfr
55455205Speter#ifdef _KERNEL
55544078Sdfr#ifdef SYSCTL_DECL
55644078SdfrSYSCTL_DECL(_net_inet_tcp);
557136151SpsSYSCTL_DECL(_net_inet_tcp_sack);
558169683SandreMALLOC_DECLARE(M_TCPLOG);
55944078Sdfr#endif
56044078Sdfr
561195699SrwatsonVNET_DECLARE(struct inpcbhead, tcb);		/* queue of active tcpcb's */
562195699SrwatsonVNET_DECLARE(struct inpcbinfo, tcbinfo);
563195699SrwatsonVNET_DECLARE(struct tcpstat, tcpstat);		/* tcp statistics */
564207369Sbzextern	int tcp_log_in_vain;
565195699SrwatsonVNET_DECLARE(int, tcp_mssdflt);	/* XXX */
566195699SrwatsonVNET_DECLARE(int, tcp_minmss);
567195699SrwatsonVNET_DECLARE(int, tcp_delack_enabled);
568211464SandreVNET_DECLARE(int, tcp_do_rfc3390);
569195699SrwatsonVNET_DECLARE(int, tcp_do_newreno);
570195699SrwatsonVNET_DECLARE(int, path_mtu_discovery);
571195699SrwatsonVNET_DECLARE(int, ss_fltsz);
572195699SrwatsonVNET_DECLARE(int, ss_fltsz_local);
573195727Srwatson#define	V_tcb			VNET(tcb)
574195727Srwatson#define	V_tcbinfo		VNET(tcbinfo)
575195727Srwatson#define	V_tcpstat		VNET(tcpstat)
576195727Srwatson#define	V_tcp_mssdflt		VNET(tcp_mssdflt)
577195727Srwatson#define	V_tcp_minmss		VNET(tcp_minmss)
578195727Srwatson#define	V_tcp_delack_enabled	VNET(tcp_delack_enabled)
579211464Sandre#define	V_tcp_do_rfc3390	VNET(tcp_do_rfc3390)
580195727Srwatson#define	V_tcp_do_newreno	VNET(tcp_do_newreno)
581195727Srwatson#define	V_path_mtu_discovery	VNET(path_mtu_discovery)
582195727Srwatson#define	V_ss_fltsz		VNET(ss_fltsz)
583195727Srwatson#define	V_ss_fltsz_local	VNET(ss_fltsz_local)
584185088Szec
585195699SrwatsonVNET_DECLARE(int, tcp_do_sack);			/* SACK enabled/disabled */
586195699SrwatsonVNET_DECLARE(int, tcp_sc_rst_sock_fail);	/* RST on sock alloc failure */
587207369Sbz#define	V_tcp_do_sack		VNET(tcp_do_sack)
588207369Sbz#define	V_tcp_sc_rst_sock_fail	VNET(tcp_sc_rst_sock_fail)
589207369Sbz
590195699SrwatsonVNET_DECLARE(int, tcp_do_ecn);			/* TCP ECN enabled/disabled */
591195699SrwatsonVNET_DECLARE(int, tcp_ecn_maxretries);
592195727Srwatson#define	V_tcp_do_ecn		VNET(tcp_do_ecn)
593195727Srwatson#define	V_tcp_ecn_maxretries	VNET(tcp_ecn_maxretries)
594195699Srwatson
595167606Sandreint	 tcp_addoptions(struct tcpopt *, u_char *);
5961541Srgrimesstruct tcpcb *
59792723Salfred	 tcp_close(struct tcpcb *);
598157376Srwatsonvoid	 tcp_discardcb(struct tcpcb *);
599111145Sjlemonvoid	 tcp_twstart(struct tcpcb *);
600162064Sglebius#if 0
601121850Ssilbyint	 tcp_twrecycleable(struct tcptw *tw);
602162064Sglebius#endif
603157376Srwatsonvoid	 tcp_twclose(struct tcptw *_tw, int _reuse);
60492723Salfredvoid	 tcp_ctlinput(int, struct sockaddr *, void *);
60592723Salfredint	 tcp_ctloutput(struct socket *, struct sockopt *);
6061541Srgrimesstruct tcpcb *
60792723Salfred	 tcp_drop(struct tcpcb *, int);
60892723Salfredvoid	 tcp_drain(void);
60992723Salfredvoid	 tcp_init(void);
610193731Szec#ifdef VIMAGE
611193731Szecvoid	 tcp_destroy(void);
612193731Szec#endif
613128452Ssilbyvoid	 tcp_fini(void *);
614169683Sandrechar 	*tcp_log_addrs(struct in_conninfo *, struct tcphdr *, void *,
615171229Speter	    const void *);
616211462Sandrechar	*tcp_log_vain(struct in_conninfo *, struct tcphdr *, void *,
617211462Sandre	    const void *);
618169541Sandreint	 tcp_reass(struct tcpcb *, struct tcphdr *, int *, struct mbuf *);
619126193Sandrevoid	 tcp_reass_init(void);
620204838Sbz#ifdef VIMAGE
621204838Sbzvoid	 tcp_reass_destroy(void);
622204838Sbz#endif
62392723Salfredvoid	 tcp_input(struct mbuf *, int);
624162084Sandreu_long	 tcp_maxmtu(struct in_conninfo *, int *);
625162084Sandreu_long	 tcp_maxmtu6(struct in_conninfo *, int *);
626184722Sbzvoid	 tcp_mss_update(struct tcpcb *, int, struct hc_metrics_lite *, int *);
62792723Salfredvoid	 tcp_mss(struct tcpcb *, int);
628122922Sandreint	 tcp_mssopt(struct in_conninfo *);
629133874Srwatsonstruct inpcb *
63098211Shsu	 tcp_drop_syn_sent(struct inpcb *, int);
63198211Shsustruct inpcb *
63298211Shsu	 tcp_mtudisc(struct inpcb *, int);
6331541Srgrimesstruct tcpcb *
63492723Salfred	 tcp_newtcpcb(struct inpcb *);
63592723Salfredint	 tcp_output(struct tcpcb *);
63692723Salfredvoid	 tcp_respond(struct tcpcb *, void *,
63792723Salfred	    struct tcphdr *, struct mbuf *, tcp_seq, tcp_seq, int);
638169541Sandrevoid	 tcp_tw_init(void);
639193731Szec#ifdef VIMAGE
640193731Szecvoid	 tcp_tw_destroy(void);
641193731Szec#endif
642169541Sandrevoid	 tcp_tw_zone_change(void);
643169608Sandreint	 tcp_twcheck(struct inpcb *, struct tcpopt *, struct tcphdr *,
644169608Sandre	    struct mbuf *, int);
645126351Srwatsonint	 tcp_twrespond(struct tcptw *, int);
64692723Salfredvoid	 tcp_setpersist(struct tcpcb *);
647125783Sbms#ifdef TCP_SIGNATURE
648125783Sbmsint	 tcp_signature_compute(struct mbuf *, int, int, int, u_char *, u_int);
649125783Sbms#endif
65092723Salfredvoid	 tcp_slowtimo(void);
65155679Sshinstruct tcptemp *
652111144Sjlemon	 tcpip_maketemplate(struct inpcb *);
653111144Sjlemonvoid	 tcpip_fillheaders(struct inpcb *, void *, void *);
654168615Sandrevoid	 tcp_timer_activate(struct tcpcb *, int, u_int);
655168615Sandreint	 tcp_timer_active(struct tcpcb *, int);
656169272Srwatsonvoid	 tcp_trace(short, short, struct tcpcb *, void *, struct tcphdr *, int);
657122922Sandre/*
658122922Sandre * All tcp_hc_* functions are IPv4 and IPv6 (via in_conninfo)
659122922Sandre */
660122922Sandrevoid	 tcp_hc_init(void);
661193731Szec#ifdef VIMAGE
662193731Szecvoid	 tcp_hc_destroy(void);
663193731Szec#endif
664122922Sandrevoid	 tcp_hc_get(struct in_conninfo *, struct hc_metrics_lite *);
665122922Sandreu_long	 tcp_hc_getmtu(struct in_conninfo *);
666122922Sandrevoid	 tcp_hc_updatemtu(struct in_conninfo *, u_long);
667122922Sandrevoid	 tcp_hc_update(struct in_conninfo *, struct hc_metrics_lite *);
6689470Swollman
66917096Swollmanextern	struct pr_usrreqs tcp_usrreqs;
6709470Swollmanextern	u_long tcp_sendspace;
6719470Swollmanextern	u_long tcp_recvspace;
67292723Salfredtcp_seq tcp_new_isn(struct tcpcb *);
6739470Swollman
674147637Spsvoid	 tcp_sack_doack(struct tcpcb *, struct tcpopt *, tcp_seq);
675142031Spsvoid	 tcp_update_sack_list(struct tcpcb *tp, tcp_seq rcv_laststart, tcp_seq rcv_lastend);
676130989Spsvoid	 tcp_clean_sackreport(struct tcpcb *tp);
677130989Spsvoid	 tcp_sack_adjust(struct tcpcb *tp);
678136151Spsstruct sackhole *tcp_sack_output(struct tcpcb *tp, int *sack_bytes_rexmt);
679130989Spsvoid	 tcp_sack_partialack(struct tcpcb *, struct tcphdr *);
680130989Spsvoid	 tcp_free_sackholes(struct tcpcb *tp);
681130989Spsint	 tcp_newreno(struct tcpcb *, struct tcphdr *);
682130989Spsu_long	 tcp_seq_subtract(u_long, u_long );
683130989Sps
68455205Speter#endif /* _KERNEL */
6852169Spaul
6866348Swollman#endif /* _NETINET_TCP_VAR_H_ */
687