tcp_var.h revision 178349
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 178349 2008-04-20 18:36:59Z bz $
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
78169541Sandre/* Neighbor Discovery, Neighbor Unreachability Detection Upper layer hint. */
79169541Sandre#ifdef INET6
80169541Sandre#define ND6_HINT(tp)						\
81169541Sandredo {								\
82169541Sandre	if ((tp) && (tp)->t_inpcb &&				\
83169541Sandre	    ((tp)->t_inpcb->inp_vflag & INP_IPV6) != 0)		\
84169541Sandre		nd6_nud_hint(NULL, NULL, 0);			\
85169541Sandre} while (0)
86169541Sandre#else
87169541Sandre#define ND6_HINT(tp)
88169541Sandre#endif
89169541Sandre
901541Srgrimes/*
911541Srgrimes * Tcp control block, one per tcp; fields:
9232821Sdg * Organized for 16 byte cacheline efficiency.
931541Srgrimes */
941541Srgrimesstruct tcpcb {
95126193Sandre	struct	tsegqe_head t_segq;	/* segment reassembly queue */
96126193Sandre	int	t_segqlen;		/* segment reassembly queue length */
9732821Sdg	int	t_dupacks;		/* consecutive dup acks recd */
9832821Sdg
99172309Ssilby	struct tcp_timer *t_timers;	/* All the TCP timers in one struct */
10032821Sdg
10132821Sdg	struct	inpcb *t_inpcb;		/* back pointer to internet pcb */
10211187Swollman	int	t_state;		/* state of this connection */
10311187Swollman	u_int	t_flags;
104117650Shsu#define	TF_ACKNOW	0x000001	/* ack peer immediately */
105117650Shsu#define	TF_DELACK	0x000002	/* ack, but try to delay it */
106117650Shsu#define	TF_NODELAY	0x000004	/* don't delay packets to coalesce */
107117650Shsu#define	TF_NOOPT	0x000008	/* don't use tcp options */
108117650Shsu#define	TF_SENTFIN	0x000010	/* have sent FIN */
109117650Shsu#define	TF_REQ_SCALE	0x000020	/* have/will request window scaling */
110117650Shsu#define	TF_RCVD_SCALE	0x000040	/* other side has requested scaling */
111117650Shsu#define	TF_REQ_TSTMP	0x000080	/* have/will request timestamps */
112117650Shsu#define	TF_RCVD_TSTMP	0x000100	/* a timestamp was received in SYN */
113117650Shsu#define	TF_SACK_PERMIT	0x000200	/* other side said I could SACK */
114117650Shsu#define	TF_NEEDSYN	0x000400	/* send SYN (implicit state) */
115117650Shsu#define	TF_NEEDFIN	0x000800	/* send FIN (implicit state) */
116117650Shsu#define	TF_NOPUSH	0x001000	/* don't push */
117117650Shsu#define	TF_MORETOCOME	0x010000	/* More data to be appended to sock */
118117650Shsu#define	TF_LQ_OVERFLOW	0x020000	/* listen queue overflow */
119117650Shsu#define	TF_LASTIDLE	0x040000	/* connection was previously idle */
120117650Shsu#define	TF_RXWIN0SENT	0x080000	/* sent a receiver win 0 in response */
121117650Shsu#define	TF_FASTRECOVERY	0x100000	/* in NewReno Fast Recovery */
122117650Shsu#define	TF_WASFRECOVERY	0x200000	/* was in NewReno Fast Recovery */
123125680Sbms#define	TF_SIGNATURE	0x400000	/* require MD5 digests (RFC2385) */
124146463Sps#define	TF_FORCEDATA	0x800000	/* force out a byte */
125162084Sandre#define	TF_TSO		0x1000000	/* TSO enabled on this connection */
126174556Skmacy#define	TF_TOE		0x2000000	/* this connection is offloaded */
1271541Srgrimes
1281541Srgrimes	tcp_seq	snd_una;		/* send unacknowledged */
12932821Sdg	tcp_seq	snd_max;		/* highest sequence number sent;
13032821Sdg					 * used to recognize retransmits
13132821Sdg					 */
1321541Srgrimes	tcp_seq	snd_nxt;		/* send next */
1331541Srgrimes	tcp_seq	snd_up;			/* send urgent pointer */
13432821Sdg
1351541Srgrimes	tcp_seq	snd_wl1;		/* window update seg seq number */
1361541Srgrimes	tcp_seq	snd_wl2;		/* window update seg ack number */
1371541Srgrimes	tcp_seq	iss;			/* initial send sequence number */
13832821Sdg	tcp_seq	irs;			/* initial receive sequence number */
13932821Sdg
14032821Sdg	tcp_seq	rcv_nxt;		/* receive next */
14132821Sdg	tcp_seq	rcv_adv;		/* advertised window */
1421541Srgrimes	u_long	rcv_wnd;		/* receive window */
1431541Srgrimes	tcp_seq	rcv_up;			/* receive urgent pointer */
14432821Sdg
14532821Sdg	u_long	snd_wnd;		/* send window */
1461541Srgrimes	u_long	snd_cwnd;		/* congestion-controlled window */
147102017Sdillon	u_long	snd_bwnd;		/* bandwidth-controlled window */
14813765Smpp	u_long	snd_ssthresh;		/* snd_cwnd size threshold for
1491541Srgrimes					 * for slow start exponential to
1501541Srgrimes					 * linear switch
1511541Srgrimes					 */
152102017Sdillon	u_long	snd_bandwidth;		/* calculated bandwidth or 0 */
153109175Shsu	tcp_seq	snd_recover;		/* for use in NewReno Fast Recovery */
15460067Sjlemon
15532821Sdg	u_int	t_maxopd;		/* mss plus options */
15632821Sdg
15750673Sjlemon	u_long	t_rcvtime;		/* inactivity time */
15850673Sjlemon	u_long	t_starttime;		/* time connection was established */
15950673Sjlemon	int	t_rtttime;		/* round trip time */
1601541Srgrimes	tcp_seq	t_rtseq;		/* sequence number being timed */
16132821Sdg
162102017Sdillon	int	t_bw_rtttime;		/* used for bandwidth calculation */
163102017Sdillon	tcp_seq	t_bw_rtseq;		/* used for bandwidth calculation */
164102017Sdillon
16550673Sjlemon	int	t_rxtcur;		/* current retransmit value (ticks) */
16632821Sdg	u_int	t_maxseg;		/* maximum segment size */
16711187Swollman	int	t_srtt;			/* smoothed round-trip time */
16811187Swollman	int	t_rttvar;		/* variance in round-trip time */
16932821Sdg
17032821Sdg	int	t_rxtshift;		/* log(2) of rexmt exp. backoff */
17111187Swollman	u_int	t_rttmin;		/* minimum rtt allowed */
172102017Sdillon	u_int	t_rttbest;		/* best rtt we've seen */
17332821Sdg	u_long	t_rttupdated;		/* number of times rtt sampled */
1741541Srgrimes	u_long	max_sndwnd;		/* largest window peer has offered */
1751541Srgrimes
17632821Sdg	int	t_softerror;		/* possible error not yet reported */
1771541Srgrimes/* out-of-band data */
1781541Srgrimes	char	t_oobflags;		/* have some */
1791541Srgrimes	char	t_iobc;			/* input character */
1801541Srgrimes#define	TCPOOB_HAVEDATA	0x01
1811541Srgrimes#define	TCPOOB_HADDATA	0x02
1821541Srgrimes/* RFC 1323 variables */
1831541Srgrimes	u_char	snd_scale;		/* window scaling for send window */
1841541Srgrimes	u_char	rcv_scale;		/* window scaling for recv window */
1851541Srgrimes	u_char	request_r_scale;	/* pending window scaling */
186162277Sandre	u_int32_t  ts_recent;		/* timestamp echo data */
187162277Sandre	u_long	ts_recent_age;		/* when last updated */
188162277Sandre	u_int32_t  ts_offset;		/* our timestamp offset */
18932821Sdg
1901541Srgrimes	tcp_seq	last_ack_sent;
19150673Sjlemon/* experimental */
19250673Sjlemon	u_long	snd_cwnd_prev;		/* cwnd prior to retransmit */
19350673Sjlemon	u_long	snd_ssthresh_prev;	/* ssthresh prior to retransmit */
194117650Shsu	tcp_seq	snd_recover_prev;	/* snd_recover prior to retransmit */
19550673Sjlemon	u_long	t_badrxtwin;		/* window for retransmit recovery */
196112957Shsu	u_char	snd_limited;		/* segments limited transmitted */
197131078Sbms/* SACK related state */
198130989Sps	int	snd_numholes;		/* number of holes seen by sender */
199146953Sps	TAILQ_HEAD(sackhole_head, sackhole) snd_holes;
200146953Sps					/* SACK scoreboard (sorted) */
201146630Sps	tcp_seq	snd_fack;		/* last seq number(+1) sack'd by rcv'r*/
202130989Sps	int	rcv_numsacks;		/* # distinct sack blks present */
203130989Sps	struct sackblk sackblks[MAX_SACK_BLKS]; /* seq nos. of sack blocks */
204136151Sps	tcp_seq sack_newdata;		/* New data xmitted in this recovery
205136151Sps					   episode starts at this seq number */
206146123Sps	struct sackhint	sackhint;	/* SACK scoreboard hint */
207155767Sandre	int	t_rttlow;		/* smallest observerved RTT */
208166405Sandre	u_int32_t	rfbuf_ts;	/* recv buffer autoscaling timestamp */
209166405Sandre	int	rfbuf_cnt;		/* recv buffer autoscaling byte count */
210174556Skmacy	void	*t_pspare[3];		/* toe usrreqs / toepcb * / congestion algo / vimage / 1 general use */
211174556Skmacy	struct toe_usrreqs *t_tu;       /* offload operations vector */
212174560Skmacy	void	*t_toe;			/* TOE pcb pointer */
2131541Srgrimes};
2141541Srgrimes
215117650Shsu#define IN_FASTRECOVERY(tp)	(tp->t_flags & TF_FASTRECOVERY)
216117650Shsu#define ENTER_FASTRECOVERY(tp)	tp->t_flags |= TF_FASTRECOVERY
217117650Shsu#define EXIT_FASTRECOVERY(tp)	tp->t_flags &= ~TF_FASTRECOVERY
218117650Shsu
219125680Sbms#ifdef TCP_SIGNATURE
2206247Swollman/*
221125680Sbms * Defines which are needed by the xform_tcp module and tcp_[in|out]put
222125680Sbms * for SADB verification and lookup.
223125680Sbms */
224125680Sbms#define	TCP_SIGLEN	16	/* length of computed digest in bytes */
225125680Sbms#define	TCP_KEYLEN_MIN	1	/* minimum length of TCP-MD5 key */
226125680Sbms#define	TCP_KEYLEN_MAX	80	/* maximum length of TCP-MD5 key */
227125680Sbms/*
228125680Sbms * Only a single SA per host may be specified at this time. An SPI is
229125680Sbms * needed in order for the KEY_ALLOCSA() lookup to work.
230125680Sbms */
231125680Sbms#define	TCP_SIG_SPI	0x1000
232125680Sbms#endif /* TCP_SIGNATURE */
233125680Sbms
234125680Sbms/*
2356247Swollman * Structure to hold TCP options that are only used during segment
2366247Swollman * processing (in tcp_input), but not held in the tcpcb.
2376247Swollman * It's basically used to reduce the number of parameters
238167606Sandre * to tcp_dooptions and tcp_addoptions.
239167606Sandre * The binary order of the to_flags is relevant for packing of the
240167606Sandre * options in tcp_addoptions.
2416247Swollman */
2426247Swollmanstruct tcpopt {
24386764Sjlemon	u_long		to_flags;	/* which options are present */
244167606Sandre#define	TOF_MSS		0x0001		/* maximum segment size */
245167606Sandre#define	TOF_SCALE	0x0002		/* window scaling */
246178349Sbz#define	TOF_SACKPERM	0x0004		/* SACK permitted */
247167606Sandre#define	TOF_TS		0x0010		/* timestamp */
248178349Sbz#define	TOF_SIGNATURE	0x0040		/* TCP-MD5 signature option (RFC2385) */
249168906Sandre#define	TOF_SACK	0x0080		/* Peer sent SACK option */
250168906Sandre#define	TOF_MAXOPT	0x0100
251168906Sandre	u_int32_t	to_tsval;	/* new timestamp */
252167606Sandre	u_int32_t	to_tsecr;	/* reflected timestamp */
253167606Sandre	u_int16_t	to_mss;		/* maximum segment size */
254167606Sandre	u_int8_t	to_wscale;	/* window scaling */
255147637Sps	u_int8_t	to_nsacks;	/* number of SACK blocks */
256147637Sps	u_char		*to_sacks;	/* pointer to the first SACK blocks */
257168906Sandre	u_char		*to_signature;	/* pointer to the TCP-MD5 signature */
2586247Swollman};
2596247Swollman
260159949Sandre/*
261159949Sandre * Flags for tcp_dooptions.
262159949Sandre */
263159949Sandre#define	TO_SYN		0x01		/* parse SYN-only options */
264159949Sandre
265122922Sandrestruct hc_metrics_lite {	/* must stay in sync with hc_metrics */
266122922Sandre	u_long	rmx_mtu;	/* MTU for this path */
267122922Sandre	u_long	rmx_ssthresh;	/* outbound gateway buffer limit */
268122922Sandre	u_long	rmx_rtt;	/* estimated round trip time */
269122922Sandre	u_long	rmx_rttvar;	/* estimated rtt variance */
270122922Sandre	u_long	rmx_bandwidth;	/* estimated bandwidth */
271122922Sandre	u_long	rmx_cwnd;	/* congestion window */
272122922Sandre	u_long	rmx_sendpipe;   /* outbound delay-bandwidth product */
273122922Sandre	u_long	rmx_recvpipe;   /* inbound delay-bandwidth product */
274122922Sandre};
275122922Sandre
276159725Sandre#ifndef _NETINET_IN_PCB_H_
277159725Sandrestruct in_conninfo;
278159725Sandre#endif /* _NETINET_IN_PCB_H_ */
279159725Sandre
280111145Sjlemonstruct tcptw {
281111145Sjlemon	struct inpcb	*tw_inpcb;	/* XXX back pointer to internet pcb */
282111145Sjlemon	tcp_seq		snd_nxt;
283111145Sjlemon	tcp_seq		rcv_nxt;
284121850Ssilby	tcp_seq		iss;
285121884Ssilby	tcp_seq		irs;
286111145Sjlemon	u_short		last_win;	/* cached window value */
287111145Sjlemon	u_short		tw_so_options;	/* copy of so_options */
288111145Sjlemon	struct ucred	*tw_cred;	/* user credentials */
289133874Srwatson	u_long		t_recent;
290169477Sandre	u_int32_t	ts_offset;	/* our timestamp offset */
291111145Sjlemon	u_long		t_starttime;
292112009Sjlemon	int		tw_time;
293162111Sru	TAILQ_ENTRY(tcptw) tw_2msl;
294111145Sjlemon};
295133874Srwatson
2961541Srgrimes#define	intotcpcb(ip)	((struct tcpcb *)(ip)->inp_ppcb)
297111145Sjlemon#define	intotw(ip)	((struct tcptw *)(ip)->inp_ppcb)
2981541Srgrimes#define	sototcpcb(so)	(intotcpcb(sotoinpcb(so)))
2991541Srgrimes
3001541Srgrimes/*
3011541Srgrimes * The smoothed round-trip time and estimated variance
3021541Srgrimes * are stored as fixed point numbers scaled by the values below.
3031541Srgrimes * For convenience, these scales are also used in smoothing the average
3041541Srgrimes * (smoothed = (1/scale)sample + ((scale-1)/scale)smoothed).
3051541Srgrimes * With these scales, srtt has 3 bits to the right of the binary point,
3061541Srgrimes * and thus an "ALPHA" of 0.875.  rttvar has 2 bits to the right of the
3071541Srgrimes * binary point, and is smoothed with an ALPHA of 0.75.
3081541Srgrimes */
30914753Swollman#define	TCP_RTT_SCALE		32	/* multiplier for srtt; 3 bits frac. */
31014753Swollman#define	TCP_RTT_SHIFT		5	/* shift for srtt; 3 bits frac. */
31114753Swollman#define	TCP_RTTVAR_SCALE	16	/* multiplier for rttvar; 2 bits */
31214753Swollman#define	TCP_RTTVAR_SHIFT	4	/* shift for rttvar; 2 bits */
31314753Swollman#define	TCP_DELTA_SHIFT		2	/* see tcp_input.c */
3141541Srgrimes
3151541Srgrimes/*
3161541Srgrimes * The initial retransmission should happen at rtt + 4 * rttvar.
3171541Srgrimes * Because of the way we do the smoothing, srtt and rttvar
3181541Srgrimes * will each average +1/2 tick of bias.  When we compute
3191541Srgrimes * the retransmit timer, we want 1/2 tick of rounding and
3201541Srgrimes * 1 extra tick because of +-1/2 tick uncertainty in the
3211541Srgrimes * firing of the timer.  The bias will give us exactly the
3221541Srgrimes * 1.5 tick we need.  But, because the bias is
3231541Srgrimes * statistical, we have to test that we don't drop below
3241541Srgrimes * the minimum feasible timer (which is 2 ticks).
32514753Swollman * This version of the macro adapted from a paper by Lawrence
32614753Swollman * Brakmo and Larry Peterson which outlines a problem caused
32714753Swollman * by insufficient precision in the original implementation,
32814753Swollman * which results in inappropriately large RTO values for very
32914753Swollman * fast networks.
3301541Srgrimes */
3311541Srgrimes#define	TCP_REXMTVAL(tp) \
33235419Sdg	max((tp)->t_rttmin, (((tp)->t_srtt >> (TCP_RTT_SHIFT - TCP_DELTA_SHIFT))  \
33316141Swollman	  + (tp)->t_rttvar) >> TCP_DELTA_SHIFT)
3341541Srgrimes
3351541Srgrimes/*
3361541Srgrimes * TCP statistics.
3371541Srgrimes * Many of these should be kept per connection,
3381541Srgrimes * but that's inconvenient at the moment.
3391541Srgrimes */
3401541Srgrimesstruct	tcpstat {
3411541Srgrimes	u_long	tcps_connattempt;	/* connections initiated */
3421541Srgrimes	u_long	tcps_accepts;		/* connections accepted */
3431541Srgrimes	u_long	tcps_connects;		/* connections established */
3441541Srgrimes	u_long	tcps_drops;		/* connections dropped */
3451541Srgrimes	u_long	tcps_conndrops;		/* embryonic connections dropped */
346124258Sandre	u_long	tcps_minmssdrops;	/* average minmss too low drops */
3471541Srgrimes	u_long	tcps_closed;		/* conn. closed (includes drops) */
3481541Srgrimes	u_long	tcps_segstimed;		/* segs where we tried to get rtt */
3491541Srgrimes	u_long	tcps_rttupdated;	/* times we succeeded */
3501541Srgrimes	u_long	tcps_delack;		/* delayed acks sent */
3511541Srgrimes	u_long	tcps_timeoutdrop;	/* conn. dropped in rxmt timeout */
3521541Srgrimes	u_long	tcps_rexmttimeo;	/* retransmit timeouts */
3531541Srgrimes	u_long	tcps_persisttimeo;	/* persist timeouts */
3541541Srgrimes	u_long	tcps_keeptimeo;		/* keepalive timeouts */
3551541Srgrimes	u_long	tcps_keepprobe;		/* keepalive probes sent */
3561541Srgrimes	u_long	tcps_keepdrops;		/* connections dropped in keepalive */
3571541Srgrimes
3581541Srgrimes	u_long	tcps_sndtotal;		/* total packets sent */
3591541Srgrimes	u_long	tcps_sndpack;		/* data packets sent */
3601541Srgrimes	u_long	tcps_sndbyte;		/* data bytes sent */
3611541Srgrimes	u_long	tcps_sndrexmitpack;	/* data packets retransmitted */
3621541Srgrimes	u_long	tcps_sndrexmitbyte;	/* data bytes retransmitted */
363100373Sdillon	u_long	tcps_sndrexmitbad;	/* unnecessary packet retransmissions */
3641541Srgrimes	u_long	tcps_sndacks;		/* ack-only packets sent */
3651541Srgrimes	u_long	tcps_sndprobe;		/* window probes sent */
3661541Srgrimes	u_long	tcps_sndurg;		/* packets sent with URG only */
3671541Srgrimes	u_long	tcps_sndwinup;		/* window update-only packets sent */
3681541Srgrimes	u_long	tcps_sndctrl;		/* control (SYN|FIN|RST) packets sent */
3691541Srgrimes
3701541Srgrimes	u_long	tcps_rcvtotal;		/* total packets received */
3711541Srgrimes	u_long	tcps_rcvpack;		/* packets received in sequence */
3721541Srgrimes	u_long	tcps_rcvbyte;		/* bytes received in sequence */
3731541Srgrimes	u_long	tcps_rcvbadsum;		/* packets received with ccksum errs */
3741541Srgrimes	u_long	tcps_rcvbadoff;		/* packets received with bad offset */
37552904Sshin	u_long	tcps_rcvmemdrop;	/* packets dropped for lack of memory */
3761541Srgrimes	u_long	tcps_rcvshort;		/* packets received too short */
3771541Srgrimes	u_long	tcps_rcvduppack;	/* duplicate-only packets received */
3781541Srgrimes	u_long	tcps_rcvdupbyte;	/* duplicate-only bytes received */
3791541Srgrimes	u_long	tcps_rcvpartduppack;	/* packets with some duplicate data */
3801541Srgrimes	u_long	tcps_rcvpartdupbyte;	/* dup. bytes in part-dup. packets */
3811541Srgrimes	u_long	tcps_rcvoopack;		/* out-of-order packets received */
3821541Srgrimes	u_long	tcps_rcvoobyte;		/* out-of-order bytes received */
3831541Srgrimes	u_long	tcps_rcvpackafterwin;	/* packets with data after window */
3841541Srgrimes	u_long	tcps_rcvbyteafterwin;	/* bytes rcvd after window */
3851541Srgrimes	u_long	tcps_rcvafterclose;	/* packets rcvd after "close" */
3861541Srgrimes	u_long	tcps_rcvwinprobe;	/* rcvd window probe packets */
3871541Srgrimes	u_long	tcps_rcvdupack;		/* rcvd duplicate acks */
3881541Srgrimes	u_long	tcps_rcvacktoomuch;	/* rcvd acks for unsent data */
3891541Srgrimes	u_long	tcps_rcvackpack;	/* rcvd ack packets */
3901541Srgrimes	u_long	tcps_rcvackbyte;	/* bytes acked by rcvd acks */
3911541Srgrimes	u_long	tcps_rcvwinupd;		/* rcvd window update packets */
3921541Srgrimes	u_long	tcps_pawsdrop;		/* segments dropped due to PAWS */
3931541Srgrimes	u_long	tcps_predack;		/* times hdr predict ok for acks */
3941541Srgrimes	u_long	tcps_preddat;		/* times hdr predict ok for data pkts */
3951541Srgrimes	u_long	tcps_pcbcachemiss;
3969263Swollman	u_long	tcps_cachedrtt;		/* times cached RTT in route updated */
3979263Swollman	u_long	tcps_cachedrttvar;	/* times cached rttvar updated */
3989263Swollman	u_long	tcps_cachedssthresh;	/* times cached ssthresh updated */
3999470Swollman	u_long	tcps_usedrtt;		/* times RTT initialized from route */
4009470Swollman	u_long	tcps_usedrttvar;	/* times RTTVAR initialized from rt */
4019470Swollman	u_long	tcps_usedssthresh;	/* times ssthresh initialized from rt*/
40210937Swollman	u_long	tcps_persistdrop;	/* timeout in persist state */
40310937Swollman	u_long	tcps_badsyn;		/* bogus SYN, e.g. premature ACK */
40411415Swollman	u_long	tcps_mturesent;		/* resends due to MTU discovery */
40514281Sbde	u_long	tcps_listendrop;	/* listen queue overflows */
406128653Ssilby	u_long	tcps_badrst;		/* ignored RSTs in the window */
40786764Sjlemon
40886764Sjlemon	u_long	tcps_sc_added;		/* entry added to syncache */
40986764Sjlemon	u_long	tcps_sc_retransmitted;	/* syncache entry was retransmitted */
41086764Sjlemon	u_long	tcps_sc_dupsyn;		/* duplicate SYN packet */
41186764Sjlemon	u_long	tcps_sc_dropped;	/* could not reply to packet */
41286764Sjlemon	u_long	tcps_sc_completed;	/* successful extraction of entry */
41386764Sjlemon	u_long	tcps_sc_bucketoverflow;	/* syncache per-bucket limit hit */
41486764Sjlemon	u_long	tcps_sc_cacheoverflow;	/* syncache cache limit hit */
41586764Sjlemon	u_long	tcps_sc_reset;		/* RST removed entry from syncache */
41686764Sjlemon	u_long	tcps_sc_stale;		/* timed out or listen socket gone */
41786764Sjlemon	u_long	tcps_sc_aborted;	/* syncache entry aborted */
41886764Sjlemon	u_long	tcps_sc_badack;		/* removed due to bad ACK */
41986764Sjlemon	u_long	tcps_sc_unreach;	/* ICMP unreachable received */
42086764Sjlemon	u_long	tcps_sc_zonefail;	/* zalloc() failed */
42186764Sjlemon	u_long	tcps_sc_sendcookie;	/* SYN cookie sent */
42286764Sjlemon	u_long	tcps_sc_recvcookie;	/* SYN cookie received */
423122922Sandre
424122922Sandre	u_long	tcps_hc_added;		/* entry added to hostcache */
425122922Sandre	u_long	tcps_hc_bucketoverflow;	/* hostcache per bucket limit hit */
426130989Sps
427167036Smohans	u_long  tcps_finwait2_drops;    /* Drop FIN_WAIT_2 connection after time limit */
428167036Smohans
429130989Sps	/* SACK related stats */
430130989Sps	u_long	tcps_sack_recovery_episode; /* SACK recovery episodes */
431130989Sps	u_long  tcps_sack_rexmits;	    /* SACK rexmit segments   */
432133874Srwatson	u_long  tcps_sack_rexmit_bytes;	    /* SACK rexmit bytes      */
433130989Sps	u_long  tcps_sack_rcv_blocks;	    /* SACK blocks (options) received */
434130989Sps	u_long  tcps_sack_send_blocks;	    /* SACK blocks (options) sent     */
435143339Sps	u_long  tcps_sack_sboverflow; 	    /* times scoreboard overflowed */
4361541Srgrimes};
4371541Srgrimes
4386247Swollman/*
43936079Swollman * TCB structure exported to user-land via sysctl(3).
44037183Sjhay * Evil hack: declare only if in_pcb.h and sys/socketvar.h have been
44137183Sjhay * included.  Not all of our clients do.
44236079Swollman */
44337183Sjhay#if defined(_NETINET_IN_PCB_H_) && defined(_SYS_SOCKETVAR_H_)
44436079Swollmanstruct	xtcpcb {
44536079Swollman	size_t	xt_len;
44636079Swollman	struct	inpcb	xt_inp;
44736079Swollman	struct	tcpcb	xt_tp;
44836079Swollman	struct	xsocket	xt_socket;
44936079Swollman	u_quad_t	xt_alignment_hack;
45036079Swollman};
45136079Swollman#endif
45236079Swollman
45336079Swollman/*
4546247Swollman * Names for TCP sysctl objects
4556247Swollman */
4566247Swollman#define	TCPCTL_DO_RFC1323	1	/* use RFC-1323 extensions */
4576247Swollman#define	TCPCTL_MSSDFLT		3	/* MSS default */
4586472Swollman#define TCPCTL_STATS		4	/* statistics (read-only) */
4596472Swollman#define	TCPCTL_RTTDFLT		5	/* default RTT estimate */
4606472Swollman#define	TCPCTL_KEEPIDLE		6	/* keepalive idle timer */
4616472Swollman#define	TCPCTL_KEEPINTVL	7	/* interval to send keepalives */
46218281Spst#define	TCPCTL_SENDSPACE	8	/* send buffer space */
46318281Spst#define	TCPCTL_RECVSPACE	9	/* receive buffer space */
46463431Ssheldonh#define	TCPCTL_KEEPINIT		10	/* timeout for establishing syn */
46536079Swollman#define	TCPCTL_PCBLIST		11	/* list of all outstanding PCBs */
46650673Sjlemon#define	TCPCTL_DELACKTIME	12	/* time before sending delayed ACK */
46752904Sshin#define	TCPCTL_V6MSSDFLT	13	/* MSS default for IPv6 */
468130989Sps#define	TCPCTL_SACK		14	/* Selective Acknowledgement,rfc 2018 */
469141381Smaxim#define	TCPCTL_DROP		15	/* drop tcp connection */
470141381Smaxim#define	TCPCTL_MAXID		16
471167036Smohans#define TCPCTL_FINWAIT2_TIMEOUT        17
4726247Swollman
4736247Swollman#define TCPCTL_NAMES { \
4746247Swollman	{ 0, 0 }, \
4756348Swollman	{ "rfc1323", CTLTYPE_INT }, \
4766247Swollman	{ "mssdflt", CTLTYPE_INT }, \
4776472Swollman	{ "stats", CTLTYPE_STRUCT }, \
4786472Swollman	{ "rttdflt", CTLTYPE_INT }, \
4796472Swollman	{ "keepidle", CTLTYPE_INT }, \
4806472Swollman	{ "keepintvl", CTLTYPE_INT }, \
4816472Swollman	{ "sendspace", CTLTYPE_INT }, \
4826472Swollman	{ "recvspace", CTLTYPE_INT }, \
48318281Spst	{ "keepinit", CTLTYPE_INT }, \
48436079Swollman	{ "pcblist", CTLTYPE_STRUCT }, \
48550673Sjlemon	{ "delacktime", CTLTYPE_INT }, \
48652904Sshin	{ "v6mssdflt", CTLTYPE_INT }, \
487122922Sandre	{ "maxid", CTLTYPE_INT }, \
4886247Swollman}
4896247Swollman
49044078Sdfr
49155205Speter#ifdef _KERNEL
49244078Sdfr#ifdef SYSCTL_DECL
49344078SdfrSYSCTL_DECL(_net_inet_tcp);
494136151SpsSYSCTL_DECL(_net_inet_tcp_sack);
495169683SandreMALLOC_DECLARE(M_TCPLOG);
49644078Sdfr#endif
49744078Sdfr
4987684Sdgextern	struct inpcbhead tcb;		/* head of queue of active tcpcb's */
4997684Sdgextern	struct inpcbinfo tcbinfo;
5006348Swollmanextern	struct tcpstat tcpstat;	/* tcp statistics */
501171640Sandreextern	int tcp_log_in_vain;
5027090Sbdeextern	int tcp_mssdflt;	/* XXX */
503124258Sandreextern	int tcp_minmss;
50433846Sdgextern	int tcp_delack_enabled;
50560067Sjlemonextern	int tcp_do_newreno;
50698204Ssilbyextern	int path_mtu_discovery;
50750673Sjlemonextern	int ss_fltsz;
50850673Sjlemonextern	int ss_fltsz_local;
5091541Srgrimes
510170055Sandreextern	int tcp_do_sack;		/* SACK enabled/disabled */
511170055Sandreextern	int tcp_sc_rst_sock_fail;	/* RST on sock alloc failure */
512130989Sps
513167606Sandreint	 tcp_addoptions(struct tcpopt *, u_char *);
5141541Srgrimesstruct tcpcb *
51592723Salfred	 tcp_close(struct tcpcb *);
516157376Srwatsonvoid	 tcp_discardcb(struct tcpcb *);
517111145Sjlemonvoid	 tcp_twstart(struct tcpcb *);
518162064Sglebius#if 0
519121850Ssilbyint	 tcp_twrecycleable(struct tcptw *tw);
520162064Sglebius#endif
521157376Srwatsonvoid	 tcp_twclose(struct tcptw *_tw, int _reuse);
52292723Salfredvoid	 tcp_ctlinput(int, struct sockaddr *, void *);
52392723Salfredint	 tcp_ctloutput(struct socket *, struct sockopt *);
5241541Srgrimesstruct tcpcb *
52592723Salfred	 tcp_drop(struct tcpcb *, int);
52692723Salfredvoid	 tcp_drain(void);
52792723Salfredvoid	 tcp_fasttimo(void);
52892723Salfredvoid	 tcp_init(void);
529128452Ssilbyvoid	 tcp_fini(void *);
530169683Sandrechar 	*tcp_log_addrs(struct in_conninfo *, struct tcphdr *, void *,
531171229Speter	    const void *);
532169541Sandreint	 tcp_reass(struct tcpcb *, struct tcphdr *, int *, struct mbuf *);
533126193Sandrevoid	 tcp_reass_init(void);
53492723Salfredvoid	 tcp_input(struct mbuf *, int);
535162084Sandreu_long	 tcp_maxmtu(struct in_conninfo *, int *);
536162084Sandreu_long	 tcp_maxmtu6(struct in_conninfo *, int *);
53792723Salfredvoid	 tcp_mss(struct tcpcb *, int);
538122922Sandreint	 tcp_mssopt(struct in_conninfo *);
539133874Srwatsonstruct inpcb *
54098211Shsu	 tcp_drop_syn_sent(struct inpcb *, int);
54198211Shsustruct inpcb *
54298211Shsu	 tcp_mtudisc(struct inpcb *, int);
5431541Srgrimesstruct tcpcb *
54492723Salfred	 tcp_newtcpcb(struct inpcb *);
54592723Salfredint	 tcp_output(struct tcpcb *);
54692723Salfredvoid	 tcp_respond(struct tcpcb *, void *,
54792723Salfred	    struct tcphdr *, struct mbuf *, tcp_seq, tcp_seq, int);
548169541Sandrevoid	 tcp_tw_init(void);
549169541Sandrevoid	 tcp_tw_zone_change(void);
550169608Sandreint	 tcp_twcheck(struct inpcb *, struct tcpopt *, struct tcphdr *,
551169608Sandre	    struct mbuf *, int);
552126351Srwatsonint	 tcp_twrespond(struct tcptw *, int);
55392723Salfredvoid	 tcp_setpersist(struct tcpcb *);
554125783Sbms#ifdef TCP_SIGNATURE
555125783Sbmsint	 tcp_signature_compute(struct mbuf *, int, int, int, u_char *, u_int);
556125783Sbms#endif
55792723Salfredvoid	 tcp_slowtimo(void);
55855679Sshinstruct tcptemp *
559111144Sjlemon	 tcpip_maketemplate(struct inpcb *);
560111144Sjlemonvoid	 tcpip_fillheaders(struct inpcb *, void *, void *);
561168615Sandrevoid	 tcp_timer_activate(struct tcpcb *, int, u_int);
562168615Sandreint	 tcp_timer_active(struct tcpcb *, int);
563169272Srwatsonvoid	 tcp_trace(short, short, struct tcpcb *, void *, struct tcphdr *, int);
564102017Sdillonvoid	 tcp_xmit_bandwidth_limit(struct tcpcb *tp, tcp_seq ack_seq);
565122922Sandre/*
566122922Sandre * All tcp_hc_* functions are IPv4 and IPv6 (via in_conninfo)
567122922Sandre */
568122922Sandrevoid	 tcp_hc_init(void);
569122922Sandrevoid	 tcp_hc_get(struct in_conninfo *, struct hc_metrics_lite *);
570122922Sandreu_long	 tcp_hc_getmtu(struct in_conninfo *);
571122922Sandrevoid	 tcp_hc_updatemtu(struct in_conninfo *, u_long);
572122922Sandrevoid	 tcp_hc_update(struct in_conninfo *, struct hc_metrics_lite *);
5739470Swollman
57417096Swollmanextern	struct pr_usrreqs tcp_usrreqs;
5759470Swollmanextern	u_long tcp_sendspace;
5769470Swollmanextern	u_long tcp_recvspace;
57792723Salfredtcp_seq tcp_new_isn(struct tcpcb *);
5789470Swollman
579147637Spsvoid	 tcp_sack_doack(struct tcpcb *, struct tcpopt *, tcp_seq);
580142031Spsvoid	 tcp_update_sack_list(struct tcpcb *tp, tcp_seq rcv_laststart, tcp_seq rcv_lastend);
581130989Spsvoid	 tcp_clean_sackreport(struct tcpcb *tp);
582130989Spsvoid	 tcp_sack_adjust(struct tcpcb *tp);
583136151Spsstruct sackhole *tcp_sack_output(struct tcpcb *tp, int *sack_bytes_rexmt);
584130989Spsvoid	 tcp_sack_partialack(struct tcpcb *, struct tcphdr *);
585130989Spsvoid	 tcp_free_sackholes(struct tcpcb *tp);
586130989Spsint	 tcp_newreno(struct tcpcb *, struct tcphdr *);
587130989Spsu_long	 tcp_seq_subtract(u_long, u_long );
588130989Sps
58955205Speter#endif /* _KERNEL */
5902169Spaul
5916348Swollman#endif /* _NETINET_TCP_VAR_H_ */
592