tcp_var.h revision 146953
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 146953 2005-06-04 08:03:28Z ps $
311541Srgrimes */
321541Srgrimes
332169Spaul#ifndef _NETINET_TCP_VAR_H_
342169Spaul#define _NETINET_TCP_VAR_H_
3586764Sjlemon
3698102Shsu#include <netinet/tcp.h>
3786764Sjlemon
381541Srgrimes/*
391541Srgrimes * Kernel variables for tcp.
401541Srgrimes */
4186764Sjlemonextern int	tcp_do_rfc1323;
421541Srgrimes
4355679Sshin/* TCP segment queue entry */
4455679Sshinstruct tseg_qent {
4560938Sjake	LIST_ENTRY(tseg_qent) tqe_q;
4655679Sshin	int	tqe_len;		/* TCP segment data length */
4755679Sshin	struct	tcphdr *tqe_th;		/* a pointer to tcp header */
4855679Sshin	struct	mbuf	*tqe_m;		/* mbuf contains packet */
4955679Sshin};
5060938SjakeLIST_HEAD(tsegqe_head, tseg_qent);
51126193Sandreextern int	tcp_reass_qsize;
52126225Sbdeextern struct uma_zone *tcp_reass_zone;
5355679Sshin
54130989Spsstruct sackblk {
55130989Sps	tcp_seq start;		/* start seq no. of sack block */
56131078Sbms	tcp_seq end;		/* end seq no. */
57130989Sps};
58130989Sps
59130989Spsstruct sackhole {
60130989Sps	tcp_seq start;		/* start seq no. of hole */
61130989Sps	tcp_seq end;		/* end seq no. */
62130989Sps	tcp_seq rxmit;		/* next seq. no in hole to be retransmitted */
63145370Sps	TAILQ_ENTRY(sackhole) scblink;	/* scoreboard linkage */
64130989Sps};
65131078Sbms
66146123Spsstruct sackhint {
67146123Sps	struct sackhole	*nexthole;
68146123Sps	int		sack_bytes_rexmit;
69146123Sps};
70146123Sps
7155679Sshinstruct tcptemp {
7255679Sshin	u_char	tt_ipgen[40]; /* the size must be of max ip header, now IPv6 */
7355679Sshin	struct	tcphdr tt_t;
7455679Sshin};
7555679Sshin
7655679Sshin#define tcp6cb		tcpcb  /* for KAME src sync over BSD*'s */
7755679Sshin
781541Srgrimes/*
791541Srgrimes * Tcp control block, one per tcp; fields:
8032821Sdg * Organized for 16 byte cacheline efficiency.
811541Srgrimes */
821541Srgrimesstruct tcpcb {
83126193Sandre	struct	tsegqe_head t_segq;	/* segment reassembly queue */
84126193Sandre	int	t_segqlen;		/* segment reassembly queue length */
8532821Sdg	int	t_dupacks;		/* consecutive dup acks recd */
8632821Sdg
8750673Sjlemon	struct	callout *tt_rexmt;	/* retransmit timer */
8850673Sjlemon	struct	callout *tt_persist;	/* retransmit persistence */
8950673Sjlemon	struct	callout *tt_keep;	/* keepalive */
9050673Sjlemon	struct	callout *tt_2msl;	/* 2*msl TIME_WAIT timer */
9150673Sjlemon	struct	callout *tt_delack;	/* delayed ACK timer */
9232821Sdg
9332821Sdg	struct	inpcb *t_inpcb;		/* back pointer to internet pcb */
9411187Swollman	int	t_state;		/* state of this connection */
9511187Swollman	u_int	t_flags;
96117650Shsu#define	TF_ACKNOW	0x000001	/* ack peer immediately */
97117650Shsu#define	TF_DELACK	0x000002	/* ack, but try to delay it */
98117650Shsu#define	TF_NODELAY	0x000004	/* don't delay packets to coalesce */
99117650Shsu#define	TF_NOOPT	0x000008	/* don't use tcp options */
100117650Shsu#define	TF_SENTFIN	0x000010	/* have sent FIN */
101117650Shsu#define	TF_REQ_SCALE	0x000020	/* have/will request window scaling */
102117650Shsu#define	TF_RCVD_SCALE	0x000040	/* other side has requested scaling */
103117650Shsu#define	TF_REQ_TSTMP	0x000080	/* have/will request timestamps */
104117650Shsu#define	TF_RCVD_TSTMP	0x000100	/* a timestamp was received in SYN */
105117650Shsu#define	TF_SACK_PERMIT	0x000200	/* other side said I could SACK */
106117650Shsu#define	TF_NEEDSYN	0x000400	/* send SYN (implicit state) */
107117650Shsu#define	TF_NEEDFIN	0x000800	/* send FIN (implicit state) */
108117650Shsu#define	TF_NOPUSH	0x001000	/* don't push */
109117650Shsu#define	TF_MORETOCOME	0x010000	/* More data to be appended to sock */
110117650Shsu#define	TF_LQ_OVERFLOW	0x020000	/* listen queue overflow */
111117650Shsu#define	TF_LASTIDLE	0x040000	/* connection was previously idle */
112117650Shsu#define	TF_RXWIN0SENT	0x080000	/* sent a receiver win 0 in response */
113117650Shsu#define	TF_FASTRECOVERY	0x100000	/* in NewReno Fast Recovery */
114117650Shsu#define	TF_WASFRECOVERY	0x200000	/* was in NewReno Fast Recovery */
115125680Sbms#define	TF_SIGNATURE	0x400000	/* require MD5 digests (RFC2385) */
116146463Sps#define	TF_FORCEDATA	0x800000	/* force out a byte */
1171541Srgrimes
1181541Srgrimes	tcp_seq	snd_una;		/* send unacknowledged */
11932821Sdg	tcp_seq	snd_max;		/* highest sequence number sent;
12032821Sdg					 * used to recognize retransmits
12132821Sdg					 */
1221541Srgrimes	tcp_seq	snd_nxt;		/* send next */
1231541Srgrimes	tcp_seq	snd_up;			/* send urgent pointer */
12432821Sdg
1251541Srgrimes	tcp_seq	snd_wl1;		/* window update seg seq number */
1261541Srgrimes	tcp_seq	snd_wl2;		/* window update seg ack number */
1271541Srgrimes	tcp_seq	iss;			/* initial send sequence number */
12832821Sdg	tcp_seq	irs;			/* initial receive sequence number */
12932821Sdg
13032821Sdg	tcp_seq	rcv_nxt;		/* receive next */
13132821Sdg	tcp_seq	rcv_adv;		/* advertised window */
1321541Srgrimes	u_long	rcv_wnd;		/* receive window */
1331541Srgrimes	tcp_seq	rcv_up;			/* receive urgent pointer */
13432821Sdg
13532821Sdg	u_long	snd_wnd;		/* send window */
1361541Srgrimes	u_long	snd_cwnd;		/* congestion-controlled window */
137102017Sdillon	u_long	snd_bwnd;		/* bandwidth-controlled window */
13813765Smpp	u_long	snd_ssthresh;		/* snd_cwnd size threshold for
1391541Srgrimes					 * for slow start exponential to
1401541Srgrimes					 * linear switch
1411541Srgrimes					 */
142102017Sdillon	u_long	snd_bandwidth;		/* calculated bandwidth or 0 */
143109175Shsu	tcp_seq	snd_recover;		/* for use in NewReno Fast Recovery */
14460067Sjlemon
14532821Sdg	u_int	t_maxopd;		/* mss plus options */
14632821Sdg
14750673Sjlemon	u_long	t_rcvtime;		/* inactivity time */
14850673Sjlemon	u_long	t_starttime;		/* time connection was established */
14950673Sjlemon	int	t_rtttime;		/* round trip time */
1501541Srgrimes	tcp_seq	t_rtseq;		/* sequence number being timed */
15132821Sdg
152102017Sdillon	int	t_bw_rtttime;		/* used for bandwidth calculation */
153102017Sdillon	tcp_seq	t_bw_rtseq;		/* used for bandwidth calculation */
154102017Sdillon
15550673Sjlemon	int	t_rxtcur;		/* current retransmit value (ticks) */
15632821Sdg	u_int	t_maxseg;		/* maximum segment size */
15711187Swollman	int	t_srtt;			/* smoothed round-trip time */
15811187Swollman	int	t_rttvar;		/* variance in round-trip time */
15932821Sdg
16032821Sdg	int	t_rxtshift;		/* log(2) of rexmt exp. backoff */
16111187Swollman	u_int	t_rttmin;		/* minimum rtt allowed */
162102017Sdillon	u_int	t_rttbest;		/* best rtt we've seen */
16332821Sdg	u_long	t_rttupdated;		/* number of times rtt sampled */
1641541Srgrimes	u_long	max_sndwnd;		/* largest window peer has offered */
1651541Srgrimes
16632821Sdg	int	t_softerror;		/* possible error not yet reported */
1671541Srgrimes/* out-of-band data */
1681541Srgrimes	char	t_oobflags;		/* have some */
1691541Srgrimes	char	t_iobc;			/* input character */
1701541Srgrimes#define	TCPOOB_HAVEDATA	0x01
1711541Srgrimes#define	TCPOOB_HADDATA	0x02
1721541Srgrimes/* RFC 1323 variables */
1731541Srgrimes	u_char	snd_scale;		/* window scaling for send window */
1741541Srgrimes	u_char	rcv_scale;		/* window scaling for recv window */
1751541Srgrimes	u_char	request_r_scale;	/* pending window scaling */
1761541Srgrimes	u_char	requested_s_scale;
1771541Srgrimes	u_long	ts_recent;		/* timestamp echo data */
17832821Sdg
1791541Srgrimes	u_long	ts_recent_age;		/* when last updated */
1801541Srgrimes	tcp_seq	last_ack_sent;
18150673Sjlemon/* experimental */
18250673Sjlemon	u_long	snd_cwnd_prev;		/* cwnd prior to retransmit */
18350673Sjlemon	u_long	snd_ssthresh_prev;	/* ssthresh prior to retransmit */
184117650Shsu	tcp_seq	snd_recover_prev;	/* snd_recover prior to retransmit */
18550673Sjlemon	u_long	t_badrxtwin;		/* window for retransmit recovery */
186112957Shsu	u_char	snd_limited;		/* segments limited transmitted */
187124258Sandre/* anti DoS counters */
188124258Sandre	u_long	rcv_second;		/* start of interval second */
189124258Sandre	u_long	rcv_pps;		/* received packets per second */
190124258Sandre	u_long	rcv_byps;		/* received bytes per second */
191131078Sbms/* SACK related state */
192130989Sps	int	sack_enable;		/* enable SACK for this connection */
193130989Sps	int	snd_numholes;		/* number of holes seen by sender */
194146953Sps	TAILQ_HEAD(sackhole_head, sackhole) snd_holes;
195146953Sps					/* SACK scoreboard (sorted) */
196146630Sps	tcp_seq	snd_fack;		/* last seq number(+1) sack'd by rcv'r*/
197130989Sps	int	rcv_numsacks;		/* # distinct sack blks present */
198130989Sps	struct sackblk sackblks[MAX_SACK_BLKS]; /* seq nos. of sack blocks */
199136151Sps	tcp_seq sack_newdata;		/* New data xmitted in this recovery
200136151Sps					   episode starts at this seq number */
201146123Sps	struct sackhint	sackhint;	/* SACK scoreboard hint */
2021541Srgrimes};
2031541Srgrimes
204117650Shsu#define IN_FASTRECOVERY(tp)	(tp->t_flags & TF_FASTRECOVERY)
205117650Shsu#define ENTER_FASTRECOVERY(tp)	tp->t_flags |= TF_FASTRECOVERY
206117650Shsu#define EXIT_FASTRECOVERY(tp)	tp->t_flags &= ~TF_FASTRECOVERY
207117650Shsu
208125680Sbms#ifdef TCP_SIGNATURE
2096247Swollman/*
210125680Sbms * Defines which are needed by the xform_tcp module and tcp_[in|out]put
211125680Sbms * for SADB verification and lookup.
212125680Sbms */
213125680Sbms#define	TCP_SIGLEN	16	/* length of computed digest in bytes */
214125680Sbms#define	TCP_KEYLEN_MIN	1	/* minimum length of TCP-MD5 key */
215125680Sbms#define	TCP_KEYLEN_MAX	80	/* maximum length of TCP-MD5 key */
216125680Sbms/*
217125680Sbms * Only a single SA per host may be specified at this time. An SPI is
218125680Sbms * needed in order for the KEY_ALLOCSA() lookup to work.
219125680Sbms */
220125680Sbms#define	TCP_SIG_SPI	0x1000
221125680Sbms#endif /* TCP_SIGNATURE */
222125680Sbms
223125680Sbms/*
2246247Swollman * Structure to hold TCP options that are only used during segment
2256247Swollman * processing (in tcp_input), but not held in the tcpcb.
2266247Swollman * It's basically used to reduce the number of parameters
2276247Swollman * to tcp_dooptions.
2286247Swollman */
2296247Swollmanstruct tcpopt {
23086764Sjlemon	u_long		to_flags;	/* which options are present */
2316247Swollman#define TOF_TS		0x0001		/* timestamp */
23286764Sjlemon#define	TOF_MSS		0x0010
23386764Sjlemon#define	TOF_SCALE	0x0020
234125680Sbms#define	TOF_SIGNATURE	0x0040		/* signature option present */
235128493Sbms#define	TOF_SIGLEN	0x0080		/* signature length valid (RFC2385) */
236130989Sps#define	TOF_SACK	0x0100		/* Peer sent SACK option */
23786764Sjlemon	u_int32_t	to_tsval;
23886764Sjlemon	u_int32_t	to_tsecr;
23986764Sjlemon	u_int16_t	to_mss;
240133874Srwatson	u_int8_t	to_requested_s_scale;
241133874Srwatson	u_int8_t	to_pad;
2426247Swollman};
2436247Swollman
244126226Sbde#ifdef _NETINET_IN_PCB_H_
24586764Sjlemonstruct syncache {
24686764Sjlemon	inp_gen_t	sc_inp_gencnt;		/* pointer check */
247133874Srwatson	struct		tcpcb *sc_tp;		/* tcb for listening socket */
24886764Sjlemon	struct		mbuf *sc_ipopts;	/* source route */
249133874Srwatson	struct		in_conninfo sc_inc;	/* addresses */
25086764Sjlemon	u_int32_t	sc_tsrecent;
251132307Sdwmalone	u_int32_t	sc_flowlabel;		/* IPv6 flowlabel */
252133874Srwatson	tcp_seq		sc_irs;			/* seq from peer */
253133874Srwatson	tcp_seq		sc_iss;			/* our ISS */
25486764Sjlemon	u_long		sc_rxttime;		/* retransmit time */
255133874Srwatson	u_int16_t	sc_rxtslot;		/* retransmit counter */
25686764Sjlemon	u_int16_t	sc_peer_mss;		/* peer's MSS */
25786764Sjlemon	u_int16_t	sc_wnd;			/* advertised window */
258133874Srwatson	u_int8_t	sc_requested_s_scale:4,
25986764Sjlemon			sc_request_r_scale:4;
26086764Sjlemon	u_int8_t	sc_flags;
26186764Sjlemon#define SCF_NOOPT	0x01			/* no TCP options */
26286764Sjlemon#define SCF_WINSCALE	0x02			/* negotiated window scaling */
26386764Sjlemon#define SCF_TIMESTAMP	0x04			/* negotiated timestamps */
26486764Sjlemon#define SCF_UNREACH	0x10			/* icmp unreachable received */
265125680Sbms#define SCF_SIGNATURE	0x20			/* send MD5 digests */
266130989Sps#define SCF_SACK	0x80			/* send SACK option */
26786764Sjlemon	TAILQ_ENTRY(syncache)	sc_hash;
26886764Sjlemon	TAILQ_ENTRY(syncache)	sc_timerq;
26986764Sjlemon};
27086764Sjlemon
27186764Sjlemonstruct syncache_head {
27286764Sjlemon	TAILQ_HEAD(, syncache)	sch_bucket;
27386764Sjlemon	u_int		sch_length;
27486764Sjlemon};
275126226Sbde#else
276126226Sbdestruct in_conninfo;
277126226Sbde#endif /* _NETINET_IN_PCB_H_ */
278111145Sjlemon
279122922Sandrestruct hc_metrics_lite {	/* must stay in sync with hc_metrics */
280122922Sandre	u_long	rmx_mtu;	/* MTU for this path */
281122922Sandre	u_long	rmx_ssthresh;	/* outbound gateway buffer limit */
282122922Sandre	u_long	rmx_rtt;	/* estimated round trip time */
283122922Sandre	u_long	rmx_rttvar;	/* estimated rtt variance */
284122922Sandre	u_long	rmx_bandwidth;	/* estimated bandwidth */
285122922Sandre	u_long	rmx_cwnd;	/* congestion window */
286122922Sandre	u_long	rmx_sendpipe;   /* outbound delay-bandwidth product */
287122922Sandre	u_long	rmx_recvpipe;   /* inbound delay-bandwidth product */
288122922Sandre};
289122922Sandre
290111145Sjlemonstruct tcptw {
291111145Sjlemon	struct inpcb	*tw_inpcb;	/* XXX back pointer to internet pcb */
292111145Sjlemon	tcp_seq		snd_nxt;
293111145Sjlemon	tcp_seq		rcv_nxt;
294121850Ssilby	tcp_seq		iss;
295121884Ssilby	tcp_seq		irs;
296111145Sjlemon	u_short		last_win;	/* cached window value */
297111145Sjlemon	u_short		tw_so_options;	/* copy of so_options */
298111145Sjlemon	struct ucred	*tw_cred;	/* user credentials */
299133874Srwatson	u_long		t_recent;
300111145Sjlemon	u_long		t_starttime;
301112009Sjlemon	int		tw_time;
302112009Sjlemon	LIST_ENTRY(tcptw) tw_2msl;
303111145Sjlemon};
304133874Srwatson
3051541Srgrimes#define	intotcpcb(ip)	((struct tcpcb *)(ip)->inp_ppcb)
306111145Sjlemon#define	intotw(ip)	((struct tcptw *)(ip)->inp_ppcb)
3071541Srgrimes#define	sototcpcb(so)	(intotcpcb(sotoinpcb(so)))
3081541Srgrimes
3091541Srgrimes/*
3101541Srgrimes * The smoothed round-trip time and estimated variance
3111541Srgrimes * are stored as fixed point numbers scaled by the values below.
3121541Srgrimes * For convenience, these scales are also used in smoothing the average
3131541Srgrimes * (smoothed = (1/scale)sample + ((scale-1)/scale)smoothed).
3141541Srgrimes * With these scales, srtt has 3 bits to the right of the binary point,
3151541Srgrimes * and thus an "ALPHA" of 0.875.  rttvar has 2 bits to the right of the
3161541Srgrimes * binary point, and is smoothed with an ALPHA of 0.75.
3171541Srgrimes */
31814753Swollman#define	TCP_RTT_SCALE		32	/* multiplier for srtt; 3 bits frac. */
31914753Swollman#define	TCP_RTT_SHIFT		5	/* shift for srtt; 3 bits frac. */
32014753Swollman#define	TCP_RTTVAR_SCALE	16	/* multiplier for rttvar; 2 bits */
32114753Swollman#define	TCP_RTTVAR_SHIFT	4	/* shift for rttvar; 2 bits */
32214753Swollman#define	TCP_DELTA_SHIFT		2	/* see tcp_input.c */
3231541Srgrimes
3241541Srgrimes/*
3251541Srgrimes * The initial retransmission should happen at rtt + 4 * rttvar.
3261541Srgrimes * Because of the way we do the smoothing, srtt and rttvar
3271541Srgrimes * will each average +1/2 tick of bias.  When we compute
3281541Srgrimes * the retransmit timer, we want 1/2 tick of rounding and
3291541Srgrimes * 1 extra tick because of +-1/2 tick uncertainty in the
3301541Srgrimes * firing of the timer.  The bias will give us exactly the
3311541Srgrimes * 1.5 tick we need.  But, because the bias is
3321541Srgrimes * statistical, we have to test that we don't drop below
3331541Srgrimes * the minimum feasible timer (which is 2 ticks).
33414753Swollman * This version of the macro adapted from a paper by Lawrence
33514753Swollman * Brakmo and Larry Peterson which outlines a problem caused
33614753Swollman * by insufficient precision in the original implementation,
33714753Swollman * which results in inappropriately large RTO values for very
33814753Swollman * fast networks.
3391541Srgrimes */
3401541Srgrimes#define	TCP_REXMTVAL(tp) \
34135419Sdg	max((tp)->t_rttmin, (((tp)->t_srtt >> (TCP_RTT_SHIFT - TCP_DELTA_SHIFT))  \
34216141Swollman	  + (tp)->t_rttvar) >> TCP_DELTA_SHIFT)
3431541Srgrimes
3441541Srgrimes/*
3451541Srgrimes * TCP statistics.
3461541Srgrimes * Many of these should be kept per connection,
3471541Srgrimes * but that's inconvenient at the moment.
3481541Srgrimes */
3491541Srgrimesstruct	tcpstat {
3501541Srgrimes	u_long	tcps_connattempt;	/* connections initiated */
3511541Srgrimes	u_long	tcps_accepts;		/* connections accepted */
3521541Srgrimes	u_long	tcps_connects;		/* connections established */
3531541Srgrimes	u_long	tcps_drops;		/* connections dropped */
3541541Srgrimes	u_long	tcps_conndrops;		/* embryonic connections dropped */
355124258Sandre	u_long	tcps_minmssdrops;	/* average minmss too low drops */
3561541Srgrimes	u_long	tcps_closed;		/* conn. closed (includes drops) */
3571541Srgrimes	u_long	tcps_segstimed;		/* segs where we tried to get rtt */
3581541Srgrimes	u_long	tcps_rttupdated;	/* times we succeeded */
3591541Srgrimes	u_long	tcps_delack;		/* delayed acks sent */
3601541Srgrimes	u_long	tcps_timeoutdrop;	/* conn. dropped in rxmt timeout */
3611541Srgrimes	u_long	tcps_rexmttimeo;	/* retransmit timeouts */
3621541Srgrimes	u_long	tcps_persisttimeo;	/* persist timeouts */
3631541Srgrimes	u_long	tcps_keeptimeo;		/* keepalive timeouts */
3641541Srgrimes	u_long	tcps_keepprobe;		/* keepalive probes sent */
3651541Srgrimes	u_long	tcps_keepdrops;		/* connections dropped in keepalive */
3661541Srgrimes
3671541Srgrimes	u_long	tcps_sndtotal;		/* total packets sent */
3681541Srgrimes	u_long	tcps_sndpack;		/* data packets sent */
3691541Srgrimes	u_long	tcps_sndbyte;		/* data bytes sent */
3701541Srgrimes	u_long	tcps_sndrexmitpack;	/* data packets retransmitted */
3711541Srgrimes	u_long	tcps_sndrexmitbyte;	/* data bytes retransmitted */
372100373Sdillon	u_long	tcps_sndrexmitbad;	/* unnecessary packet retransmissions */
3731541Srgrimes	u_long	tcps_sndacks;		/* ack-only packets sent */
3741541Srgrimes	u_long	tcps_sndprobe;		/* window probes sent */
3751541Srgrimes	u_long	tcps_sndurg;		/* packets sent with URG only */
3761541Srgrimes	u_long	tcps_sndwinup;		/* window update-only packets sent */
3771541Srgrimes	u_long	tcps_sndctrl;		/* control (SYN|FIN|RST) packets sent */
3781541Srgrimes
3791541Srgrimes	u_long	tcps_rcvtotal;		/* total packets received */
3801541Srgrimes	u_long	tcps_rcvpack;		/* packets received in sequence */
3811541Srgrimes	u_long	tcps_rcvbyte;		/* bytes received in sequence */
3821541Srgrimes	u_long	tcps_rcvbadsum;		/* packets received with ccksum errs */
3831541Srgrimes	u_long	tcps_rcvbadoff;		/* packets received with bad offset */
38452904Sshin	u_long	tcps_rcvmemdrop;	/* packets dropped for lack of memory */
3851541Srgrimes	u_long	tcps_rcvshort;		/* packets received too short */
3861541Srgrimes	u_long	tcps_rcvduppack;	/* duplicate-only packets received */
3871541Srgrimes	u_long	tcps_rcvdupbyte;	/* duplicate-only bytes received */
3881541Srgrimes	u_long	tcps_rcvpartduppack;	/* packets with some duplicate data */
3891541Srgrimes	u_long	tcps_rcvpartdupbyte;	/* dup. bytes in part-dup. packets */
3901541Srgrimes	u_long	tcps_rcvoopack;		/* out-of-order packets received */
3911541Srgrimes	u_long	tcps_rcvoobyte;		/* out-of-order bytes received */
3921541Srgrimes	u_long	tcps_rcvpackafterwin;	/* packets with data after window */
3931541Srgrimes	u_long	tcps_rcvbyteafterwin;	/* bytes rcvd after window */
3941541Srgrimes	u_long	tcps_rcvafterclose;	/* packets rcvd after "close" */
3951541Srgrimes	u_long	tcps_rcvwinprobe;	/* rcvd window probe packets */
3961541Srgrimes	u_long	tcps_rcvdupack;		/* rcvd duplicate acks */
3971541Srgrimes	u_long	tcps_rcvacktoomuch;	/* rcvd acks for unsent data */
3981541Srgrimes	u_long	tcps_rcvackpack;	/* rcvd ack packets */
3991541Srgrimes	u_long	tcps_rcvackbyte;	/* bytes acked by rcvd acks */
4001541Srgrimes	u_long	tcps_rcvwinupd;		/* rcvd window update packets */
4011541Srgrimes	u_long	tcps_pawsdrop;		/* segments dropped due to PAWS */
4021541Srgrimes	u_long	tcps_predack;		/* times hdr predict ok for acks */
4031541Srgrimes	u_long	tcps_preddat;		/* times hdr predict ok for data pkts */
4041541Srgrimes	u_long	tcps_pcbcachemiss;
4059263Swollman	u_long	tcps_cachedrtt;		/* times cached RTT in route updated */
4069263Swollman	u_long	tcps_cachedrttvar;	/* times cached rttvar updated */
4079263Swollman	u_long	tcps_cachedssthresh;	/* times cached ssthresh updated */
4089470Swollman	u_long	tcps_usedrtt;		/* times RTT initialized from route */
4099470Swollman	u_long	tcps_usedrttvar;	/* times RTTVAR initialized from rt */
4109470Swollman	u_long	tcps_usedssthresh;	/* times ssthresh initialized from rt*/
41110937Swollman	u_long	tcps_persistdrop;	/* timeout in persist state */
41210937Swollman	u_long	tcps_badsyn;		/* bogus SYN, e.g. premature ACK */
41311415Swollman	u_long	tcps_mturesent;		/* resends due to MTU discovery */
41414281Sbde	u_long	tcps_listendrop;	/* listen queue overflows */
415128653Ssilby	u_long	tcps_badrst;		/* ignored RSTs in the window */
41686764Sjlemon
41786764Sjlemon	u_long	tcps_sc_added;		/* entry added to syncache */
41886764Sjlemon	u_long	tcps_sc_retransmitted;	/* syncache entry was retransmitted */
41986764Sjlemon	u_long	tcps_sc_dupsyn;		/* duplicate SYN packet */
42086764Sjlemon	u_long	tcps_sc_dropped;	/* could not reply to packet */
42186764Sjlemon	u_long	tcps_sc_completed;	/* successful extraction of entry */
42286764Sjlemon	u_long	tcps_sc_bucketoverflow;	/* syncache per-bucket limit hit */
42386764Sjlemon	u_long	tcps_sc_cacheoverflow;	/* syncache cache limit hit */
42486764Sjlemon	u_long	tcps_sc_reset;		/* RST removed entry from syncache */
42586764Sjlemon	u_long	tcps_sc_stale;		/* timed out or listen socket gone */
42686764Sjlemon	u_long	tcps_sc_aborted;	/* syncache entry aborted */
42786764Sjlemon	u_long	tcps_sc_badack;		/* removed due to bad ACK */
42886764Sjlemon	u_long	tcps_sc_unreach;	/* ICMP unreachable received */
42986764Sjlemon	u_long	tcps_sc_zonefail;	/* zalloc() failed */
43086764Sjlemon	u_long	tcps_sc_sendcookie;	/* SYN cookie sent */
43186764Sjlemon	u_long	tcps_sc_recvcookie;	/* SYN cookie received */
432122922Sandre
433122922Sandre	u_long	tcps_hc_added;		/* entry added to hostcache */
434122922Sandre	u_long	tcps_hc_bucketoverflow;	/* hostcache per bucket limit hit */
435130989Sps
436130989Sps	/* SACK related stats */
437130989Sps	u_long	tcps_sack_recovery_episode; /* SACK recovery episodes */
438130989Sps	u_long  tcps_sack_rexmits;	    /* SACK rexmit segments   */
439133874Srwatson	u_long  tcps_sack_rexmit_bytes;	    /* SACK rexmit bytes      */
440130989Sps	u_long  tcps_sack_rcv_blocks;	    /* SACK blocks (options) received */
441130989Sps	u_long  tcps_sack_send_blocks;	    /* SACK blocks (options) sent     */
442143339Sps	u_long  tcps_sack_sboverflow; 	    /* times scoreboard overflowed */
4431541Srgrimes};
4441541Srgrimes
4456247Swollman/*
44636079Swollman * TCB structure exported to user-land via sysctl(3).
44737183Sjhay * Evil hack: declare only if in_pcb.h and sys/socketvar.h have been
44837183Sjhay * included.  Not all of our clients do.
44936079Swollman */
45037183Sjhay#if defined(_NETINET_IN_PCB_H_) && defined(_SYS_SOCKETVAR_H_)
45136079Swollmanstruct	xtcpcb {
45236079Swollman	size_t	xt_len;
45336079Swollman	struct	inpcb	xt_inp;
45436079Swollman	struct	tcpcb	xt_tp;
45536079Swollman	struct	xsocket	xt_socket;
45636079Swollman	u_quad_t	xt_alignment_hack;
45736079Swollman};
45836079Swollman#endif
45936079Swollman
46036079Swollman/*
4616247Swollman * Names for TCP sysctl objects
4626247Swollman */
4636247Swollman#define	TCPCTL_DO_RFC1323	1	/* use RFC-1323 extensions */
4646247Swollman#define	TCPCTL_MSSDFLT		3	/* MSS default */
4656472Swollman#define TCPCTL_STATS		4	/* statistics (read-only) */
4666472Swollman#define	TCPCTL_RTTDFLT		5	/* default RTT estimate */
4676472Swollman#define	TCPCTL_KEEPIDLE		6	/* keepalive idle timer */
4686472Swollman#define	TCPCTL_KEEPINTVL	7	/* interval to send keepalives */
46918281Spst#define	TCPCTL_SENDSPACE	8	/* send buffer space */
47018281Spst#define	TCPCTL_RECVSPACE	9	/* receive buffer space */
47163431Ssheldonh#define	TCPCTL_KEEPINIT		10	/* timeout for establishing syn */
47236079Swollman#define	TCPCTL_PCBLIST		11	/* list of all outstanding PCBs */
47350673Sjlemon#define	TCPCTL_DELACKTIME	12	/* time before sending delayed ACK */
47452904Sshin#define	TCPCTL_V6MSSDFLT	13	/* MSS default for IPv6 */
475130989Sps#define	TCPCTL_SACK		14	/* Selective Acknowledgement,rfc 2018 */
476141381Smaxim#define	TCPCTL_DROP		15	/* drop tcp connection */
477141381Smaxim#define	TCPCTL_MAXID		16
4786247Swollman
4796247Swollman#define TCPCTL_NAMES { \
4806247Swollman	{ 0, 0 }, \
4816348Swollman	{ "rfc1323", CTLTYPE_INT }, \
4826247Swollman	{ "mssdflt", CTLTYPE_INT }, \
4836472Swollman	{ "stats", CTLTYPE_STRUCT }, \
4846472Swollman	{ "rttdflt", CTLTYPE_INT }, \
4856472Swollman	{ "keepidle", CTLTYPE_INT }, \
4866472Swollman	{ "keepintvl", CTLTYPE_INT }, \
4876472Swollman	{ "sendspace", CTLTYPE_INT }, \
4886472Swollman	{ "recvspace", CTLTYPE_INT }, \
48918281Spst	{ "keepinit", CTLTYPE_INT }, \
49036079Swollman	{ "pcblist", CTLTYPE_STRUCT }, \
49150673Sjlemon	{ "delacktime", CTLTYPE_INT }, \
49252904Sshin	{ "v6mssdflt", CTLTYPE_INT }, \
493122922Sandre	{ "maxid", CTLTYPE_INT }, \
4946247Swollman}
4956247Swollman
49644078Sdfr
49755205Speter#ifdef _KERNEL
49844078Sdfr#ifdef SYSCTL_DECL
49944078SdfrSYSCTL_DECL(_net_inet_tcp);
500136151SpsSYSCTL_DECL(_net_inet_tcp_sack);
50144078Sdfr#endif
50244078Sdfr
5037684Sdgextern	struct inpcbhead tcb;		/* head of queue of active tcpcb's */
5047684Sdgextern	struct inpcbinfo tcbinfo;
5056348Swollmanextern	struct tcpstat tcpstat;	/* tcp statistics */
5067090Sbdeextern	int tcp_mssdflt;	/* XXX */
507124258Sandreextern	int tcp_minmss;
508124258Sandreextern	int tcp_minmssoverload;
50933846Sdgextern	int tcp_delack_enabled;
51060067Sjlemonextern	int tcp_do_newreno;
51198204Ssilbyextern	int path_mtu_discovery;
51250673Sjlemonextern	int ss_fltsz;
51350673Sjlemonextern	int ss_fltsz_local;
5141541Srgrimes
515130989Spsextern	int tcp_do_sack;	/* SACK enabled/disabled */
516130989Sps
5171541Srgrimesstruct tcpcb *
51892723Salfred	 tcp_close(struct tcpcb *);
519111145Sjlemonvoid	 tcp_twstart(struct tcpcb *);
520121850Ssilbyint	 tcp_twrecycleable(struct tcptw *tw);
521112009Sjlemonstruct tcptw *
522112009Sjlemon	 tcp_twclose(struct tcptw *_tw, int _reuse);
52392723Salfredvoid	 tcp_ctlinput(int, struct sockaddr *, void *);
52492723Salfredint	 tcp_ctloutput(struct socket *, struct sockopt *);
5251541Srgrimesstruct tcpcb *
52692723Salfred	 tcp_drop(struct tcpcb *, int);
52792723Salfredvoid	 tcp_drain(void);
52892723Salfredvoid	 tcp_fasttimo(void);
52992723Salfredvoid	 tcp_init(void);
530128452Ssilbyvoid	 tcp_fini(void *);
531126193Sandrevoid	 tcp_reass_init(void);
53292723Salfredvoid	 tcp_input(struct mbuf *, int);
533122922Sandreu_long	 tcp_maxmtu(struct in_conninfo *);
534122922Sandreu_long	 tcp_maxmtu6(struct in_conninfo *);
53592723Salfredvoid	 tcp_mss(struct tcpcb *, int);
536122922Sandreint	 tcp_mssopt(struct in_conninfo *);
537133874Srwatsonstruct inpcb *
53898211Shsu	 tcp_drop_syn_sent(struct inpcb *, int);
53998211Shsustruct inpcb *
54098211Shsu	 tcp_mtudisc(struct inpcb *, int);
5411541Srgrimesstruct tcpcb *
54292723Salfred	 tcp_newtcpcb(struct inpcb *);
54392723Salfredint	 tcp_output(struct tcpcb *);
54492723Salfredvoid	 tcp_respond(struct tcpcb *, void *,
54592723Salfred	    struct tcphdr *, struct mbuf *, tcp_seq, tcp_seq, int);
546126351Srwatsonint	 tcp_twrespond(struct tcptw *, int);
54792723Salfredvoid	 tcp_setpersist(struct tcpcb *);
548125783Sbms#ifdef TCP_SIGNATURE
549125783Sbmsint	 tcp_signature_compute(struct mbuf *, int, int, int, u_char *, u_int);
550125783Sbms#endif
55192723Salfredvoid	 tcp_slowtimo(void);
55255679Sshinstruct tcptemp *
553111144Sjlemon	 tcpip_maketemplate(struct inpcb *);
554111144Sjlemonvoid	 tcpip_fillheaders(struct inpcb *, void *, void *);
5551541Srgrimesstruct tcpcb *
55692723Salfred	 tcp_timers(struct tcpcb *, int);
55792723Salfredvoid	 tcp_trace(int, int, struct tcpcb *, void *, struct tcphdr *, int);
558102017Sdillonvoid	 tcp_xmit_bandwidth_limit(struct tcpcb *tp, tcp_seq ack_seq);
55986764Sjlemonvoid	 syncache_init(void);
56086764Sjlemonvoid	 syncache_unreach(struct in_conninfo *, struct tcphdr *);
56186764Sjlemonint	 syncache_expand(struct in_conninfo *, struct tcphdr *,
56286764Sjlemon	     struct socket **, struct mbuf *);
56386764Sjlemonint	 syncache_add(struct in_conninfo *, struct tcpopt *,
56486764Sjlemon	     struct tcphdr *, struct socket **, struct mbuf *);
56586764Sjlemonvoid	 syncache_chkrst(struct in_conninfo *, struct tcphdr *);
56686764Sjlemonvoid	 syncache_badack(struct in_conninfo *);
567122922Sandre/*
568122922Sandre * All tcp_hc_* functions are IPv4 and IPv6 (via in_conninfo)
569122922Sandre */
570122922Sandrevoid	 tcp_hc_init(void);
571122922Sandrevoid	 tcp_hc_get(struct in_conninfo *, struct hc_metrics_lite *);
572122922Sandreu_long	 tcp_hc_getmtu(struct in_conninfo *);
573122922Sandrevoid	 tcp_hc_updatemtu(struct in_conninfo *, u_long);
574122922Sandrevoid	 tcp_hc_update(struct in_conninfo *, struct hc_metrics_lite *);
5759470Swollman
57617096Swollmanextern	struct pr_usrreqs tcp_usrreqs;
5779470Swollmanextern	u_long tcp_sendspace;
5789470Swollmanextern	u_long tcp_recvspace;
57992723Salfredtcp_seq tcp_new_isn(struct tcpcb *);
5809470Swollman
581130989Spsint	 tcp_sack_option(struct tcpcb *,struct tcphdr *,u_char *,int);
582142031Spsvoid	 tcp_update_sack_list(struct tcpcb *tp, tcp_seq rcv_laststart, tcp_seq rcv_lastend);
583130989Spsvoid	 tcp_del_sackholes(struct tcpcb *, struct tcphdr *);
584130989Spsvoid	 tcp_clean_sackreport(struct tcpcb *tp);
585130989Spsvoid	 tcp_sack_adjust(struct tcpcb *tp);
586136151Spsstruct sackhole *tcp_sack_output(struct tcpcb *tp, int *sack_bytes_rexmt);
587130989Spsvoid	 tcp_sack_partialack(struct tcpcb *, struct tcphdr *);
588130989Spsvoid	 tcp_free_sackholes(struct tcpcb *tp);
589130989Spsint	 tcp_newreno(struct tcpcb *, struct tcphdr *);
590130989Spsu_long	 tcp_seq_subtract(u_long, u_long );
591130989Sps
59255205Speter#endif /* _KERNEL */
5932169Spaul
5946348Swollman#endif /* _NETINET_TCP_VAR_H_ */
595