tcp_var.h revision 122922
11541Srgrimes/*
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 * 3. All advertising materials mentioning features or use of this software
141541Srgrimes *    must display the following acknowledgement:
151541Srgrimes *	This product includes software developed by the University of
161541Srgrimes *	California, Berkeley and its contributors.
171541Srgrimes * 4. Neither the name of the University nor the names of its contributors
181541Srgrimes *    may be used to endorse or promote products derived from this software
191541Srgrimes *    without specific prior written permission.
201541Srgrimes *
211541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
221541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
231541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
241541Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
251541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
261541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
271541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
281541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
291541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
301541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
311541Srgrimes * SUCH DAMAGE.
321541Srgrimes *
3310937Swollman *	@(#)tcp_var.h	8.4 (Berkeley) 5/24/95
3450477Speter * $FreeBSD: head/sys/netinet/tcp_var.h 122922 2003-11-20 20:07:39Z andre $
351541Srgrimes */
361541Srgrimes
372169Spaul#ifndef _NETINET_TCP_VAR_H_
382169Spaul#define _NETINET_TCP_VAR_H_
3986764Sjlemon
4086764Sjlemon#include <netinet/in_pcb.h>		/* needed for in_conninfo, inp_gen_t */
4198102Shsu#include <netinet/tcp.h>
4286764Sjlemon
431541Srgrimes/*
441541Srgrimes * Kernel variables for tcp.
451541Srgrimes */
4686764Sjlemonextern int	tcp_do_rfc1323;
4786764Sjlemonextern int	tcp_do_rfc1644;
481541Srgrimes
4955679Sshin/* TCP segment queue entry */
5055679Sshinstruct tseg_qent {
5160938Sjake	LIST_ENTRY(tseg_qent) tqe_q;
5255679Sshin	int	tqe_len;		/* TCP segment data length */
5355679Sshin	struct	tcphdr *tqe_th;		/* a pointer to tcp header */
5455679Sshin	struct	mbuf	*tqe_m;		/* mbuf contains packet */
5555679Sshin};
5660938SjakeLIST_HEAD(tsegqe_head, tseg_qent);
5755679Sshin#ifdef MALLOC_DECLARE
5855679SshinMALLOC_DECLARE(M_TSEGQ);
5955679Sshin#endif
6055679Sshin
6155679Sshinstruct tcptemp {
6255679Sshin	u_char	tt_ipgen[40]; /* the size must be of max ip header, now IPv6 */
6355679Sshin	struct	tcphdr tt_t;
6455679Sshin};
6555679Sshin
6655679Sshin#define tcp6cb		tcpcb  /* for KAME src sync over BSD*'s */
6755679Sshin
681541Srgrimes/*
691541Srgrimes * Tcp control block, one per tcp; fields:
7032821Sdg * Organized for 16 byte cacheline efficiency.
711541Srgrimes */
721541Srgrimesstruct tcpcb {
7355679Sshin	struct	tsegqe_head t_segq;
7432821Sdg	int	t_dupacks;		/* consecutive dup acks recd */
7578642Ssilby	struct	tcptemp	*unused;	/* unused */
7632821Sdg
7750673Sjlemon	struct	callout *tt_rexmt;	/* retransmit timer */
7850673Sjlemon	struct	callout *tt_persist;	/* retransmit persistence */
7950673Sjlemon	struct	callout *tt_keep;	/* keepalive */
8050673Sjlemon	struct	callout *tt_2msl;	/* 2*msl TIME_WAIT timer */
8150673Sjlemon	struct	callout *tt_delack;	/* delayed ACK timer */
8232821Sdg
8332821Sdg	struct	inpcb *t_inpcb;		/* back pointer to internet pcb */
8411187Swollman	int	t_state;		/* state of this connection */
8511187Swollman	u_int	t_flags;
86117650Shsu#define	TF_ACKNOW	0x000001	/* ack peer immediately */
87117650Shsu#define	TF_DELACK	0x000002	/* ack, but try to delay it */
88117650Shsu#define	TF_NODELAY	0x000004	/* don't delay packets to coalesce */
89117650Shsu#define	TF_NOOPT	0x000008	/* don't use tcp options */
90117650Shsu#define	TF_SENTFIN	0x000010	/* have sent FIN */
91117650Shsu#define	TF_REQ_SCALE	0x000020	/* have/will request window scaling */
92117650Shsu#define	TF_RCVD_SCALE	0x000040	/* other side has requested scaling */
93117650Shsu#define	TF_REQ_TSTMP	0x000080	/* have/will request timestamps */
94117650Shsu#define	TF_RCVD_TSTMP	0x000100	/* a timestamp was received in SYN */
95117650Shsu#define	TF_SACK_PERMIT	0x000200	/* other side said I could SACK */
96117650Shsu#define	TF_NEEDSYN	0x000400	/* send SYN (implicit state) */
97117650Shsu#define	TF_NEEDFIN	0x000800	/* send FIN (implicit state) */
98117650Shsu#define	TF_NOPUSH	0x001000	/* don't push */
99117650Shsu#define	TF_REQ_CC	0x002000	/* have/will request CC */
100117650Shsu#define	TF_RCVD_CC	0x004000	/* a CC was received in SYN */
101117650Shsu#define	TF_SENDCCNEW	0x008000	/* send CCnew instead of CC in SYN */
102117650Shsu#define	TF_MORETOCOME	0x010000	/* More data to be appended to sock */
103117650Shsu#define	TF_LQ_OVERFLOW	0x020000	/* listen queue overflow */
104117650Shsu#define	TF_LASTIDLE	0x040000	/* connection was previously idle */
105117650Shsu#define	TF_RXWIN0SENT	0x080000	/* sent a receiver win 0 in response */
106117650Shsu#define	TF_FASTRECOVERY	0x100000	/* in NewReno Fast Recovery */
107117650Shsu#define	TF_WASFRECOVERY	0x200000	/* was in NewReno Fast Recovery */
10832821Sdg	int	t_force;		/* 1 if forcing out a byte */
1091541Srgrimes
1101541Srgrimes	tcp_seq	snd_una;		/* send unacknowledged */
11132821Sdg	tcp_seq	snd_max;		/* highest sequence number sent;
11232821Sdg					 * used to recognize retransmits
11332821Sdg					 */
1141541Srgrimes	tcp_seq	snd_nxt;		/* send next */
1151541Srgrimes	tcp_seq	snd_up;			/* send urgent pointer */
11632821Sdg
1171541Srgrimes	tcp_seq	snd_wl1;		/* window update seg seq number */
1181541Srgrimes	tcp_seq	snd_wl2;		/* window update seg ack number */
1191541Srgrimes	tcp_seq	iss;			/* initial send sequence number */
12032821Sdg	tcp_seq	irs;			/* initial receive sequence number */
12132821Sdg
12232821Sdg	tcp_seq	rcv_nxt;		/* receive next */
12332821Sdg	tcp_seq	rcv_adv;		/* advertised window */
1241541Srgrimes	u_long	rcv_wnd;		/* receive window */
1251541Srgrimes	tcp_seq	rcv_up;			/* receive urgent pointer */
12632821Sdg
12732821Sdg	u_long	snd_wnd;		/* send window */
1281541Srgrimes	u_long	snd_cwnd;		/* congestion-controlled window */
129102017Sdillon	u_long	snd_bwnd;		/* bandwidth-controlled window */
13013765Smpp	u_long	snd_ssthresh;		/* snd_cwnd size threshold for
1311541Srgrimes					 * for slow start exponential to
1321541Srgrimes					 * linear switch
1331541Srgrimes					 */
134102017Sdillon	u_long	snd_bandwidth;		/* calculated bandwidth or 0 */
135109175Shsu	tcp_seq	snd_recover;		/* for use in NewReno Fast Recovery */
13660067Sjlemon
13732821Sdg	u_int	t_maxopd;		/* mss plus options */
13832821Sdg
13950673Sjlemon	u_long	t_rcvtime;		/* inactivity time */
14050673Sjlemon	u_long	t_starttime;		/* time connection was established */
14150673Sjlemon	int	t_rtttime;		/* round trip time */
1421541Srgrimes	tcp_seq	t_rtseq;		/* sequence number being timed */
14332821Sdg
144102017Sdillon	int	t_bw_rtttime;		/* used for bandwidth calculation */
145102017Sdillon	tcp_seq	t_bw_rtseq;		/* used for bandwidth calculation */
146102017Sdillon
14750673Sjlemon	int	t_rxtcur;		/* current retransmit value (ticks) */
14832821Sdg	u_int	t_maxseg;		/* maximum segment size */
14911187Swollman	int	t_srtt;			/* smoothed round-trip time */
15011187Swollman	int	t_rttvar;		/* variance in round-trip time */
15132821Sdg
15232821Sdg	int	t_rxtshift;		/* log(2) of rexmt exp. backoff */
15311187Swollman	u_int	t_rttmin;		/* minimum rtt allowed */
154102017Sdillon	u_int	t_rttbest;		/* best rtt we've seen */
15532821Sdg	u_long	t_rttupdated;		/* number of times rtt sampled */
1561541Srgrimes	u_long	max_sndwnd;		/* largest window peer has offered */
1571541Srgrimes
15832821Sdg	int	t_softerror;		/* possible error not yet reported */
1591541Srgrimes/* out-of-band data */
1601541Srgrimes	char	t_oobflags;		/* have some */
1611541Srgrimes	char	t_iobc;			/* input character */
1621541Srgrimes#define	TCPOOB_HAVEDATA	0x01
1631541Srgrimes#define	TCPOOB_HADDATA	0x02
1641541Srgrimes/* RFC 1323 variables */
1651541Srgrimes	u_char	snd_scale;		/* window scaling for send window */
1661541Srgrimes	u_char	rcv_scale;		/* window scaling for recv window */
1671541Srgrimes	u_char	request_r_scale;	/* pending window scaling */
1681541Srgrimes	u_char	requested_s_scale;
1691541Srgrimes	u_long	ts_recent;		/* timestamp echo data */
17032821Sdg
1711541Srgrimes	u_long	ts_recent_age;		/* when last updated */
1721541Srgrimes	tcp_seq	last_ack_sent;
1736247Swollman/* RFC 1644 variables */
1746247Swollman	tcp_cc	cc_send;		/* send connection count */
1756247Swollman	tcp_cc	cc_recv;		/* receive connection count */
17650673Sjlemon/* experimental */
17750673Sjlemon	u_long	snd_cwnd_prev;		/* cwnd prior to retransmit */
17850673Sjlemon	u_long	snd_ssthresh_prev;	/* ssthresh prior to retransmit */
179117650Shsu	tcp_seq	snd_recover_prev;	/* snd_recover prior to retransmit */
18050673Sjlemon	u_long	t_badrxtwin;		/* window for retransmit recovery */
181112957Shsu	u_char	snd_limited;		/* segments limited transmitted */
1821541Srgrimes};
1831541Srgrimes
184117650Shsu#define IN_FASTRECOVERY(tp)	(tp->t_flags & TF_FASTRECOVERY)
185117650Shsu#define ENTER_FASTRECOVERY(tp)	tp->t_flags |= TF_FASTRECOVERY
186117650Shsu#define EXIT_FASTRECOVERY(tp)	tp->t_flags &= ~TF_FASTRECOVERY
187117650Shsu
1886247Swollman/*
1896247Swollman * Structure to hold TCP options that are only used during segment
1906247Swollman * processing (in tcp_input), but not held in the tcpcb.
1916247Swollman * It's basically used to reduce the number of parameters
1926247Swollman * to tcp_dooptions.
1936247Swollman */
1946247Swollmanstruct tcpopt {
19586764Sjlemon	u_long		to_flags;	/* which options are present */
1966247Swollman#define TOF_TS		0x0001		/* timestamp */
1976247Swollman#define TOF_CC		0x0002		/* CC and CCnew are exclusive */
1986247Swollman#define TOF_CCNEW	0x0004
1996247Swollman#define	TOF_CCECHO	0x0008
20086764Sjlemon#define	TOF_MSS		0x0010
20186764Sjlemon#define	TOF_SCALE	0x0020
20286764Sjlemon	u_int32_t	to_tsval;
20386764Sjlemon	u_int32_t	to_tsecr;
20486764Sjlemon	tcp_cc		to_cc;		/* holds CC or CCnew */
20586764Sjlemon	tcp_cc		to_ccecho;
20686764Sjlemon	u_int16_t	to_mss;
20786764Sjlemon	u_int8_t 	to_requested_s_scale;
20886764Sjlemon	u_int8_t 	to_pad;
2096247Swollman};
2106247Swollman
21186764Sjlemonstruct syncache {
21286764Sjlemon	inp_gen_t	sc_inp_gencnt;		/* pointer check */
21386764Sjlemon	struct 		tcpcb *sc_tp;		/* tcb for listening socket */
21486764Sjlemon	struct		mbuf *sc_ipopts;	/* source route */
21586764Sjlemon	struct 		in_conninfo sc_inc;	/* addresses */
21686764Sjlemon	u_int32_t	sc_tsrecent;
21786764Sjlemon	tcp_cc		sc_cc_send;		/* holds CC or CCnew */
21886764Sjlemon	tcp_cc		sc_cc_recv;
21986764Sjlemon	tcp_seq 	sc_irs;			/* seq from peer */
22086764Sjlemon	tcp_seq 	sc_iss;			/* our ISS */
22186764Sjlemon	u_long		sc_rxttime;		/* retransmit time */
22286764Sjlemon	u_int16_t	sc_rxtslot; 		/* retransmit counter */
22386764Sjlemon	u_int16_t	sc_peer_mss;		/* peer's MSS */
22486764Sjlemon	u_int16_t	sc_wnd;			/* advertised window */
22586764Sjlemon	u_int8_t 	sc_requested_s_scale:4,
22686764Sjlemon			sc_request_r_scale:4;
22786764Sjlemon	u_int8_t	sc_flags;
22886764Sjlemon#define SCF_NOOPT	0x01			/* no TCP options */
22986764Sjlemon#define SCF_WINSCALE	0x02			/* negotiated window scaling */
23086764Sjlemon#define SCF_TIMESTAMP	0x04			/* negotiated timestamps */
23186764Sjlemon#define SCF_CC		0x08			/* negotiated CC */
23286764Sjlemon#define SCF_UNREACH	0x10			/* icmp unreachable received */
23386764Sjlemon	TAILQ_ENTRY(syncache)	sc_hash;
23486764Sjlemon	TAILQ_ENTRY(syncache)	sc_timerq;
23586764Sjlemon};
23686764Sjlemon
23786764Sjlemonstruct syncache_head {
23886764Sjlemon	TAILQ_HEAD(, syncache)	sch_bucket;
23986764Sjlemon	u_int		sch_length;
24086764Sjlemon};
241111145Sjlemon
242122922Sandrestruct hc_metrics_lite {	/* must stay in sync with hc_metrics */
243122922Sandre	u_long	rmx_mtu;	/* MTU for this path */
244122922Sandre	u_long	rmx_ssthresh;	/* outbound gateway buffer limit */
245122922Sandre	u_long	rmx_rtt;	/* estimated round trip time */
246122922Sandre	u_long	rmx_rttvar;	/* estimated rtt variance */
247122922Sandre	u_long	rmx_bandwidth;	/* estimated bandwidth */
248122922Sandre	u_long	rmx_cwnd;	/* congestion window */
249122922Sandre	u_long	rmx_sendpipe;   /* outbound delay-bandwidth product */
250122922Sandre	u_long	rmx_recvpipe;   /* inbound delay-bandwidth product */
251122922Sandre};
252122922Sandre
253111145Sjlemonstruct tcptw {
254111145Sjlemon	struct inpcb	*tw_inpcb;	/* XXX back pointer to internet pcb */
255111145Sjlemon	tcp_seq		snd_nxt;
256111145Sjlemon	tcp_seq		rcv_nxt;
257121850Ssilby	tcp_seq		iss;
258121884Ssilby	tcp_seq		irs;
259111145Sjlemon	tcp_cc		cc_recv;
260111145Sjlemon	tcp_cc		cc_send;
261111145Sjlemon	u_short		last_win;	/* cached window value */
262111145Sjlemon	u_short		tw_so_options;	/* copy of so_options */
263111145Sjlemon	struct ucred	*tw_cred;	/* user credentials */
264111145Sjlemon	u_long 		t_recent;
265111145Sjlemon	u_long		t_starttime;
266112009Sjlemon	int		tw_time;
267112009Sjlemon	LIST_ENTRY(tcptw) tw_2msl;
268111145Sjlemon};
26986764Sjlemon
2706247Swollman/*
271122922Sandre * The TAO cache entry which is stored in the tcp hostcache.
2726247Swollman */
2736247Swollmanstruct rmxp_tao {
2746247Swollman	tcp_cc	tao_cc;			/* latest CC in valid SYN */
2756247Swollman	tcp_cc	tao_ccsent;		/* latest CC sent to peer */
2766247Swollman	u_short	tao_mssopt;		/* peer's cached MSS */
2776247Swollman#ifdef notyet
2786247Swollman	u_short	tao_flags;		/* cache status flags */
2796247Swollman#define	TAOF_DONT	0x0001		/* peer doesn't understand rfc1644 */
2806247Swollman#define	TAOF_OK		0x0002		/* peer does understand rfc1644 */
2816247Swollman#define	TAOF_UNDEF	0		/* we don't know yet */
2826247Swollman#endif /* notyet */
2836247Swollman};
2846247Swollman
2851541Srgrimes#define	intotcpcb(ip)	((struct tcpcb *)(ip)->inp_ppcb)
286111145Sjlemon#define	intotw(ip)	((struct tcptw *)(ip)->inp_ppcb)
2871541Srgrimes#define	sototcpcb(so)	(intotcpcb(sotoinpcb(so)))
2881541Srgrimes
2891541Srgrimes/*
2901541Srgrimes * The smoothed round-trip time and estimated variance
2911541Srgrimes * are stored as fixed point numbers scaled by the values below.
2921541Srgrimes * For convenience, these scales are also used in smoothing the average
2931541Srgrimes * (smoothed = (1/scale)sample + ((scale-1)/scale)smoothed).
2941541Srgrimes * With these scales, srtt has 3 bits to the right of the binary point,
2951541Srgrimes * and thus an "ALPHA" of 0.875.  rttvar has 2 bits to the right of the
2961541Srgrimes * binary point, and is smoothed with an ALPHA of 0.75.
2971541Srgrimes */
29814753Swollman#define	TCP_RTT_SCALE		32	/* multiplier for srtt; 3 bits frac. */
29914753Swollman#define	TCP_RTT_SHIFT		5	/* shift for srtt; 3 bits frac. */
30014753Swollman#define	TCP_RTTVAR_SCALE	16	/* multiplier for rttvar; 2 bits */
30114753Swollman#define	TCP_RTTVAR_SHIFT	4	/* shift for rttvar; 2 bits */
30214753Swollman#define	TCP_DELTA_SHIFT		2	/* see tcp_input.c */
3031541Srgrimes
3041541Srgrimes/*
3051541Srgrimes * The initial retransmission should happen at rtt + 4 * rttvar.
3061541Srgrimes * Because of the way we do the smoothing, srtt and rttvar
3071541Srgrimes * will each average +1/2 tick of bias.  When we compute
3081541Srgrimes * the retransmit timer, we want 1/2 tick of rounding and
3091541Srgrimes * 1 extra tick because of +-1/2 tick uncertainty in the
3101541Srgrimes * firing of the timer.  The bias will give us exactly the
3111541Srgrimes * 1.5 tick we need.  But, because the bias is
3121541Srgrimes * statistical, we have to test that we don't drop below
3131541Srgrimes * the minimum feasible timer (which is 2 ticks).
31414753Swollman * This version of the macro adapted from a paper by Lawrence
31514753Swollman * Brakmo and Larry Peterson which outlines a problem caused
31614753Swollman * by insufficient precision in the original implementation,
31714753Swollman * which results in inappropriately large RTO values for very
31814753Swollman * fast networks.
3191541Srgrimes */
3201541Srgrimes#define	TCP_REXMTVAL(tp) \
32135419Sdg	max((tp)->t_rttmin, (((tp)->t_srtt >> (TCP_RTT_SHIFT - TCP_DELTA_SHIFT))  \
32216141Swollman	  + (tp)->t_rttvar) >> TCP_DELTA_SHIFT)
3231541Srgrimes
3241541Srgrimes/*
3251541Srgrimes * TCP statistics.
3261541Srgrimes * Many of these should be kept per connection,
3271541Srgrimes * but that's inconvenient at the moment.
3281541Srgrimes */
3291541Srgrimesstruct	tcpstat {
3301541Srgrimes	u_long	tcps_connattempt;	/* connections initiated */
3311541Srgrimes	u_long	tcps_accepts;		/* connections accepted */
3321541Srgrimes	u_long	tcps_connects;		/* connections established */
3331541Srgrimes	u_long	tcps_drops;		/* connections dropped */
3341541Srgrimes	u_long	tcps_conndrops;		/* embryonic connections dropped */
3351541Srgrimes	u_long	tcps_closed;		/* conn. closed (includes drops) */
3361541Srgrimes	u_long	tcps_segstimed;		/* segs where we tried to get rtt */
3371541Srgrimes	u_long	tcps_rttupdated;	/* times we succeeded */
3381541Srgrimes	u_long	tcps_delack;		/* delayed acks sent */
3391541Srgrimes	u_long	tcps_timeoutdrop;	/* conn. dropped in rxmt timeout */
3401541Srgrimes	u_long	tcps_rexmttimeo;	/* retransmit timeouts */
3411541Srgrimes	u_long	tcps_persisttimeo;	/* persist timeouts */
3421541Srgrimes	u_long	tcps_keeptimeo;		/* keepalive timeouts */
3431541Srgrimes	u_long	tcps_keepprobe;		/* keepalive probes sent */
3441541Srgrimes	u_long	tcps_keepdrops;		/* connections dropped in keepalive */
3451541Srgrimes
3461541Srgrimes	u_long	tcps_sndtotal;		/* total packets sent */
3471541Srgrimes	u_long	tcps_sndpack;		/* data packets sent */
3481541Srgrimes	u_long	tcps_sndbyte;		/* data bytes sent */
3491541Srgrimes	u_long	tcps_sndrexmitpack;	/* data packets retransmitted */
3501541Srgrimes	u_long	tcps_sndrexmitbyte;	/* data bytes retransmitted */
351100373Sdillon	u_long	tcps_sndrexmitbad;	/* unnecessary packet retransmissions */
3521541Srgrimes	u_long	tcps_sndacks;		/* ack-only packets sent */
3531541Srgrimes	u_long	tcps_sndprobe;		/* window probes sent */
3541541Srgrimes	u_long	tcps_sndurg;		/* packets sent with URG only */
3551541Srgrimes	u_long	tcps_sndwinup;		/* window update-only packets sent */
3561541Srgrimes	u_long	tcps_sndctrl;		/* control (SYN|FIN|RST) packets sent */
3571541Srgrimes
3581541Srgrimes	u_long	tcps_rcvtotal;		/* total packets received */
3591541Srgrimes	u_long	tcps_rcvpack;		/* packets received in sequence */
3601541Srgrimes	u_long	tcps_rcvbyte;		/* bytes received in sequence */
3611541Srgrimes	u_long	tcps_rcvbadsum;		/* packets received with ccksum errs */
3621541Srgrimes	u_long	tcps_rcvbadoff;		/* packets received with bad offset */
36352904Sshin	u_long	tcps_rcvmemdrop;	/* packets dropped for lack of memory */
3641541Srgrimes	u_long	tcps_rcvshort;		/* packets received too short */
3651541Srgrimes	u_long	tcps_rcvduppack;	/* duplicate-only packets received */
3661541Srgrimes	u_long	tcps_rcvdupbyte;	/* duplicate-only bytes received */
3671541Srgrimes	u_long	tcps_rcvpartduppack;	/* packets with some duplicate data */
3681541Srgrimes	u_long	tcps_rcvpartdupbyte;	/* dup. bytes in part-dup. packets */
3691541Srgrimes	u_long	tcps_rcvoopack;		/* out-of-order packets received */
3701541Srgrimes	u_long	tcps_rcvoobyte;		/* out-of-order bytes received */
3711541Srgrimes	u_long	tcps_rcvpackafterwin;	/* packets with data after window */
3721541Srgrimes	u_long	tcps_rcvbyteafterwin;	/* bytes rcvd after window */
3731541Srgrimes	u_long	tcps_rcvafterclose;	/* packets rcvd after "close" */
3741541Srgrimes	u_long	tcps_rcvwinprobe;	/* rcvd window probe packets */
3751541Srgrimes	u_long	tcps_rcvdupack;		/* rcvd duplicate acks */
3761541Srgrimes	u_long	tcps_rcvacktoomuch;	/* rcvd acks for unsent data */
3771541Srgrimes	u_long	tcps_rcvackpack;	/* rcvd ack packets */
3781541Srgrimes	u_long	tcps_rcvackbyte;	/* bytes acked by rcvd acks */
3791541Srgrimes	u_long	tcps_rcvwinupd;		/* rcvd window update packets */
3801541Srgrimes	u_long	tcps_pawsdrop;		/* segments dropped due to PAWS */
3811541Srgrimes	u_long	tcps_predack;		/* times hdr predict ok for acks */
3821541Srgrimes	u_long	tcps_preddat;		/* times hdr predict ok for data pkts */
3831541Srgrimes	u_long	tcps_pcbcachemiss;
3849263Swollman	u_long	tcps_cachedrtt;		/* times cached RTT in route updated */
3859263Swollman	u_long	tcps_cachedrttvar;	/* times cached rttvar updated */
3869263Swollman	u_long	tcps_cachedssthresh;	/* times cached ssthresh updated */
3879470Swollman	u_long	tcps_usedrtt;		/* times RTT initialized from route */
3889470Swollman	u_long	tcps_usedrttvar;	/* times RTTVAR initialized from rt */
3899470Swollman	u_long	tcps_usedssthresh;	/* times ssthresh initialized from rt*/
39010937Swollman	u_long	tcps_persistdrop;	/* timeout in persist state */
39110937Swollman	u_long	tcps_badsyn;		/* bogus SYN, e.g. premature ACK */
39211415Swollman	u_long	tcps_mturesent;		/* resends due to MTU discovery */
39314281Sbde	u_long	tcps_listendrop;	/* listen queue overflows */
39486764Sjlemon
39586764Sjlemon	u_long	tcps_sc_added;		/* entry added to syncache */
39686764Sjlemon	u_long	tcps_sc_retransmitted;	/* syncache entry was retransmitted */
39786764Sjlemon	u_long	tcps_sc_dupsyn;		/* duplicate SYN packet */
39886764Sjlemon	u_long	tcps_sc_dropped;	/* could not reply to packet */
39986764Sjlemon	u_long	tcps_sc_completed;	/* successful extraction of entry */
40086764Sjlemon	u_long	tcps_sc_bucketoverflow;	/* syncache per-bucket limit hit */
40186764Sjlemon	u_long	tcps_sc_cacheoverflow;	/* syncache cache limit hit */
40286764Sjlemon	u_long	tcps_sc_reset;		/* RST removed entry from syncache */
40386764Sjlemon	u_long	tcps_sc_stale;		/* timed out or listen socket gone */
40486764Sjlemon	u_long	tcps_sc_aborted;	/* syncache entry aborted */
40586764Sjlemon	u_long	tcps_sc_badack;		/* removed due to bad ACK */
40686764Sjlemon	u_long	tcps_sc_unreach;	/* ICMP unreachable received */
40786764Sjlemon	u_long	tcps_sc_zonefail;	/* zalloc() failed */
40886764Sjlemon	u_long	tcps_sc_sendcookie;	/* SYN cookie sent */
40986764Sjlemon	u_long	tcps_sc_recvcookie;	/* SYN cookie received */
410122922Sandre
411122922Sandre	u_long	tcps_hc_added;		/* entry added to hostcache */
412122922Sandre	u_long	tcps_hc_bucketoverflow;	/* hostcache per bucket limit hit */
4131541Srgrimes};
4141541Srgrimes
4156247Swollman/*
41636079Swollman * TCB structure exported to user-land via sysctl(3).
41737183Sjhay * Evil hack: declare only if in_pcb.h and sys/socketvar.h have been
41837183Sjhay * included.  Not all of our clients do.
41936079Swollman */
42037183Sjhay#if defined(_NETINET_IN_PCB_H_) && defined(_SYS_SOCKETVAR_H_)
42136079Swollmanstruct	xtcpcb {
42236079Swollman	size_t	xt_len;
42336079Swollman	struct	inpcb	xt_inp;
42436079Swollman	struct	tcpcb	xt_tp;
42536079Swollman	struct	xsocket	xt_socket;
42636079Swollman	u_quad_t	xt_alignment_hack;
42736079Swollman};
42836079Swollman#endif
42936079Swollman
43036079Swollman/*
4316247Swollman * Names for TCP sysctl objects
4326247Swollman */
4336247Swollman#define	TCPCTL_DO_RFC1323	1	/* use RFC-1323 extensions */
4346247Swollman#define	TCPCTL_DO_RFC1644	2	/* use RFC-1644 extensions */
4356247Swollman#define	TCPCTL_MSSDFLT		3	/* MSS default */
4366472Swollman#define TCPCTL_STATS		4	/* statistics (read-only) */
4376472Swollman#define	TCPCTL_RTTDFLT		5	/* default RTT estimate */
4386472Swollman#define	TCPCTL_KEEPIDLE		6	/* keepalive idle timer */
4396472Swollman#define	TCPCTL_KEEPINTVL	7	/* interval to send keepalives */
44018281Spst#define	TCPCTL_SENDSPACE	8	/* send buffer space */
44118281Spst#define	TCPCTL_RECVSPACE	9	/* receive buffer space */
44263431Ssheldonh#define	TCPCTL_KEEPINIT		10	/* timeout for establishing syn */
44336079Swollman#define	TCPCTL_PCBLIST		11	/* list of all outstanding PCBs */
44450673Sjlemon#define	TCPCTL_DELACKTIME	12	/* time before sending delayed ACK */
44552904Sshin#define	TCPCTL_V6MSSDFLT	13	/* MSS default for IPv6 */
44652904Sshin#define	TCPCTL_MAXID		14
4476247Swollman
4486247Swollman#define TCPCTL_NAMES { \
4496247Swollman	{ 0, 0 }, \
4506348Swollman	{ "rfc1323", CTLTYPE_INT }, \
4516348Swollman	{ "rfc1644", CTLTYPE_INT }, \
4526247Swollman	{ "mssdflt", CTLTYPE_INT }, \
4536472Swollman	{ "stats", CTLTYPE_STRUCT }, \
4546472Swollman	{ "rttdflt", CTLTYPE_INT }, \
4556472Swollman	{ "keepidle", CTLTYPE_INT }, \
4566472Swollman	{ "keepintvl", CTLTYPE_INT }, \
4576472Swollman	{ "sendspace", CTLTYPE_INT }, \
4586472Swollman	{ "recvspace", CTLTYPE_INT }, \
45918281Spst	{ "keepinit", CTLTYPE_INT }, \
46036079Swollman	{ "pcblist", CTLTYPE_STRUCT }, \
46150673Sjlemon	{ "delacktime", CTLTYPE_INT }, \
46252904Sshin	{ "v6mssdflt", CTLTYPE_INT }, \
463122922Sandre	{ "maxid", CTLTYPE_INT }, \
4646247Swollman}
4656247Swollman
46644078Sdfr
46755205Speter#ifdef _KERNEL
46844078Sdfr#ifdef SYSCTL_DECL
46944078SdfrSYSCTL_DECL(_net_inet_tcp);
47044078Sdfr#endif
47144078Sdfr
4727684Sdgextern	struct inpcbhead tcb;		/* head of queue of active tcpcb's */
4737684Sdgextern	struct inpcbinfo tcbinfo;
4746348Swollmanextern	struct tcpstat tcpstat;	/* tcp statistics */
4757090Sbdeextern	int tcp_mssdflt;	/* XXX */
47633846Sdgextern	int tcp_delack_enabled;
47760067Sjlemonextern	int tcp_do_newreno;
47898204Ssilbyextern	int path_mtu_discovery;
47950673Sjlemonextern	int ss_fltsz;
48050673Sjlemonextern	int ss_fltsz_local;
4811541Srgrimes
48292723Salfredvoid	 tcp_canceltimers(struct tcpcb *);
4831541Srgrimesstruct tcpcb *
48492723Salfred	 tcp_close(struct tcpcb *);
485111145Sjlemonvoid	 tcp_twstart(struct tcpcb *);
486121850Ssilbyint	 tcp_twrecycleable(struct tcptw *tw);
487112009Sjlemonstruct tcptw *
488112009Sjlemon	 tcp_twclose(struct tcptw *_tw, int _reuse);
48992723Salfredvoid	 tcp_ctlinput(int, struct sockaddr *, void *);
49092723Salfredint	 tcp_ctloutput(struct socket *, struct sockopt *);
4911541Srgrimesstruct tcpcb *
49292723Salfred	 tcp_drop(struct tcpcb *, int);
49392723Salfredvoid	 tcp_drain(void);
49492723Salfredvoid	 tcp_fasttimo(void);
49592723Salfredvoid	 tcp_init(void);
49692723Salfredvoid	 tcp_input(struct mbuf *, int);
497122922Sandreu_long	 tcp_maxmtu(struct in_conninfo *);
498122922Sandreu_long	 tcp_maxmtu6(struct in_conninfo *);
49992723Salfredvoid	 tcp_mss(struct tcpcb *, int);
500122922Sandreint	 tcp_mssopt(struct in_conninfo *);
50198211Shsustruct inpcb *
50298211Shsu	 tcp_drop_syn_sent(struct inpcb *, int);
50398211Shsustruct inpcb *
50498211Shsu	 tcp_mtudisc(struct inpcb *, int);
5051541Srgrimesstruct tcpcb *
50692723Salfred	 tcp_newtcpcb(struct inpcb *);
50792723Salfredint	 tcp_output(struct tcpcb *);
50898211Shsustruct inpcb *
50998211Shsu	 tcp_quench(struct inpcb *, int);
51092723Salfredvoid	 tcp_respond(struct tcpcb *, void *,
51192723Salfred	    struct tcphdr *, struct mbuf *, tcp_seq, tcp_seq, int);
512114794Srwatsonint	 tcp_twrespond(struct tcptw *, struct socket *, struct mbuf *, int);
51392723Salfredvoid	 tcp_setpersist(struct tcpcb *);
51492723Salfredvoid	 tcp_slowtimo(void);
51555679Sshinstruct tcptemp *
516111144Sjlemon	 tcpip_maketemplate(struct inpcb *);
517111144Sjlemonvoid	 tcpip_fillheaders(struct inpcb *, void *, void *);
5181541Srgrimesstruct tcpcb *
51992723Salfred	 tcp_timers(struct tcpcb *, int);
52092723Salfredvoid	 tcp_trace(int, int, struct tcpcb *, void *, struct tcphdr *, int);
521102017Sdillonvoid	 tcp_xmit_bandwidth_limit(struct tcpcb *tp, tcp_seq ack_seq);
52286764Sjlemonvoid	 syncache_init(void);
52386764Sjlemonvoid	 syncache_unreach(struct in_conninfo *, struct tcphdr *);
52486764Sjlemonint	 syncache_expand(struct in_conninfo *, struct tcphdr *,
52586764Sjlemon	     struct socket **, struct mbuf *);
52686764Sjlemonint	 syncache_add(struct in_conninfo *, struct tcpopt *,
52786764Sjlemon	     struct tcphdr *, struct socket **, struct mbuf *);
52886764Sjlemonvoid	 syncache_chkrst(struct in_conninfo *, struct tcphdr *);
52986764Sjlemonvoid	 syncache_badack(struct in_conninfo *);
530122922Sandre/*
531122922Sandre * All tcp_hc_* functions are IPv4 and IPv6 (via in_conninfo)
532122922Sandre */
533122922Sandrevoid	 tcp_hc_init(void);
534122922Sandrevoid	 tcp_hc_get(struct in_conninfo *, struct hc_metrics_lite *);
535122922Sandreu_long	 tcp_hc_getmtu(struct in_conninfo *);
536122922Sandrevoid	 tcp_hc_gettao(struct in_conninfo *, struct rmxp_tao *);
537122922Sandrevoid	 tcp_hc_updatemtu(struct in_conninfo *, u_long);
538122922Sandrevoid	 tcp_hc_update(struct in_conninfo *, struct hc_metrics_lite *);
539122922Sandrevoid	 tcp_hc_updatetao(struct in_conninfo *, int, tcp_cc, u_short);
540122922Sandre/* update which tao field */
541122922Sandre#define	TCP_HC_TAO_CC		0x1
542122922Sandre#define TCP_HC_TAO_CCSENT	0x2
543122922Sandre#define TCP_HC_TAO_MSSOPT	0x3
5449470Swollman
54517096Swollmanextern	struct pr_usrreqs tcp_usrreqs;
5469470Swollmanextern	u_long tcp_sendspace;
5479470Swollmanextern	u_long tcp_recvspace;
54892723Salfredtcp_seq tcp_new_isn(struct tcpcb *);
5499470Swollman
55055205Speter#endif /* _KERNEL */
5512169Spaul
5526348Swollman#endif /* _NETINET_TCP_VAR_H_ */
553