tcp_var.h revision 121850
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 121850 2003-11-01 07:30:08Z silby $
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#define sc_route	sc_inc.inc_route
21786764Sjlemon#define sc_route6	sc_inc.inc6_route
21886764Sjlemon	u_int32_t	sc_tsrecent;
21986764Sjlemon	tcp_cc		sc_cc_send;		/* holds CC or CCnew */
22086764Sjlemon	tcp_cc		sc_cc_recv;
22186764Sjlemon	tcp_seq 	sc_irs;			/* seq from peer */
22286764Sjlemon	tcp_seq 	sc_iss;			/* our ISS */
22386764Sjlemon	u_long		sc_rxttime;		/* retransmit time */
22486764Sjlemon	u_int16_t	sc_rxtslot; 		/* retransmit counter */
22586764Sjlemon	u_int16_t	sc_peer_mss;		/* peer's MSS */
22686764Sjlemon	u_int16_t	sc_wnd;			/* advertised window */
22786764Sjlemon	u_int8_t 	sc_requested_s_scale:4,
22886764Sjlemon			sc_request_r_scale:4;
22986764Sjlemon	u_int8_t	sc_flags;
23086764Sjlemon#define SCF_NOOPT	0x01			/* no TCP options */
23186764Sjlemon#define SCF_WINSCALE	0x02			/* negotiated window scaling */
23286764Sjlemon#define SCF_TIMESTAMP	0x04			/* negotiated timestamps */
23386764Sjlemon#define SCF_CC		0x08			/* negotiated CC */
23486764Sjlemon#define SCF_UNREACH	0x10			/* icmp unreachable received */
23586764Sjlemon#define SCF_KEEPROUTE	0x20			/* keep cloned route */
23686764Sjlemon	TAILQ_ENTRY(syncache)	sc_hash;
23786764Sjlemon	TAILQ_ENTRY(syncache)	sc_timerq;
23886764Sjlemon};
23986764Sjlemon
24086764Sjlemonstruct syncache_head {
24186764Sjlemon	TAILQ_HEAD(, syncache)	sch_bucket;
24286764Sjlemon	u_int		sch_length;
24386764Sjlemon};
244111145Sjlemon
245111145Sjlemonstruct tcptw {
246111145Sjlemon	struct inpcb	*tw_inpcb;	/* XXX back pointer to internet pcb */
247111145Sjlemon	tcp_seq		snd_nxt;
248111145Sjlemon	tcp_seq		rcv_nxt;
249121850Ssilby	tcp_seq		iss;
250111145Sjlemon	tcp_cc		cc_recv;
251111145Sjlemon	tcp_cc		cc_send;
252111145Sjlemon	u_short		last_win;	/* cached window value */
253111145Sjlemon	u_short		tw_so_options;	/* copy of so_options */
254111145Sjlemon	struct ucred	*tw_cred;	/* user credentials */
255111145Sjlemon	u_long 		t_recent;
256111145Sjlemon	u_long		t_starttime;
257112009Sjlemon	int		tw_time;
258112009Sjlemon	LIST_ENTRY(tcptw) tw_2msl;
259111145Sjlemon};
26086764Sjlemon
2616247Swollman/*
2626247Swollman * The TAO cache entry which is stored in the protocol family specific
2636247Swollman * portion of the route metrics.
2646247Swollman */
2656247Swollmanstruct rmxp_tao {
2666247Swollman	tcp_cc	tao_cc;			/* latest CC in valid SYN */
2676247Swollman	tcp_cc	tao_ccsent;		/* latest CC sent to peer */
2686247Swollman	u_short	tao_mssopt;		/* peer's cached MSS */
2696247Swollman#ifdef notyet
2706247Swollman	u_short	tao_flags;		/* cache status flags */
2716247Swollman#define	TAOF_DONT	0x0001		/* peer doesn't understand rfc1644 */
2726247Swollman#define	TAOF_OK		0x0002		/* peer does understand rfc1644 */
2736247Swollman#define	TAOF_UNDEF	0		/* we don't know yet */
2746247Swollman#endif /* notyet */
2756247Swollman};
2766283Swollman#define rmx_taop(r)	((struct rmxp_tao *)(r).rmx_filler)
2776247Swollman
2781541Srgrimes#define	intotcpcb(ip)	((struct tcpcb *)(ip)->inp_ppcb)
279111145Sjlemon#define	intotw(ip)	((struct tcptw *)(ip)->inp_ppcb)
2801541Srgrimes#define	sototcpcb(so)	(intotcpcb(sotoinpcb(so)))
2811541Srgrimes
2821541Srgrimes/*
2831541Srgrimes * The smoothed round-trip time and estimated variance
2841541Srgrimes * are stored as fixed point numbers scaled by the values below.
2851541Srgrimes * For convenience, these scales are also used in smoothing the average
2861541Srgrimes * (smoothed = (1/scale)sample + ((scale-1)/scale)smoothed).
2871541Srgrimes * With these scales, srtt has 3 bits to the right of the binary point,
2881541Srgrimes * and thus an "ALPHA" of 0.875.  rttvar has 2 bits to the right of the
2891541Srgrimes * binary point, and is smoothed with an ALPHA of 0.75.
2901541Srgrimes */
29114753Swollman#define	TCP_RTT_SCALE		32	/* multiplier for srtt; 3 bits frac. */
29214753Swollman#define	TCP_RTT_SHIFT		5	/* shift for srtt; 3 bits frac. */
29314753Swollman#define	TCP_RTTVAR_SCALE	16	/* multiplier for rttvar; 2 bits */
29414753Swollman#define	TCP_RTTVAR_SHIFT	4	/* shift for rttvar; 2 bits */
29514753Swollman#define	TCP_DELTA_SHIFT		2	/* see tcp_input.c */
2961541Srgrimes
2971541Srgrimes/*
2981541Srgrimes * The initial retransmission should happen at rtt + 4 * rttvar.
2991541Srgrimes * Because of the way we do the smoothing, srtt and rttvar
3001541Srgrimes * will each average +1/2 tick of bias.  When we compute
3011541Srgrimes * the retransmit timer, we want 1/2 tick of rounding and
3021541Srgrimes * 1 extra tick because of +-1/2 tick uncertainty in the
3031541Srgrimes * firing of the timer.  The bias will give us exactly the
3041541Srgrimes * 1.5 tick we need.  But, because the bias is
3051541Srgrimes * statistical, we have to test that we don't drop below
3061541Srgrimes * the minimum feasible timer (which is 2 ticks).
30714753Swollman * This version of the macro adapted from a paper by Lawrence
30814753Swollman * Brakmo and Larry Peterson which outlines a problem caused
30914753Swollman * by insufficient precision in the original implementation,
31014753Swollman * which results in inappropriately large RTO values for very
31114753Swollman * fast networks.
3121541Srgrimes */
3131541Srgrimes#define	TCP_REXMTVAL(tp) \
31435419Sdg	max((tp)->t_rttmin, (((tp)->t_srtt >> (TCP_RTT_SHIFT - TCP_DELTA_SHIFT))  \
31516141Swollman	  + (tp)->t_rttvar) >> TCP_DELTA_SHIFT)
3161541Srgrimes
3171541Srgrimes/*
3181541Srgrimes * TCP statistics.
3191541Srgrimes * Many of these should be kept per connection,
3201541Srgrimes * but that's inconvenient at the moment.
3211541Srgrimes */
3221541Srgrimesstruct	tcpstat {
3231541Srgrimes	u_long	tcps_connattempt;	/* connections initiated */
3241541Srgrimes	u_long	tcps_accepts;		/* connections accepted */
3251541Srgrimes	u_long	tcps_connects;		/* connections established */
3261541Srgrimes	u_long	tcps_drops;		/* connections dropped */
3271541Srgrimes	u_long	tcps_conndrops;		/* embryonic connections dropped */
3281541Srgrimes	u_long	tcps_closed;		/* conn. closed (includes drops) */
3291541Srgrimes	u_long	tcps_segstimed;		/* segs where we tried to get rtt */
3301541Srgrimes	u_long	tcps_rttupdated;	/* times we succeeded */
3311541Srgrimes	u_long	tcps_delack;		/* delayed acks sent */
3321541Srgrimes	u_long	tcps_timeoutdrop;	/* conn. dropped in rxmt timeout */
3331541Srgrimes	u_long	tcps_rexmttimeo;	/* retransmit timeouts */
3341541Srgrimes	u_long	tcps_persisttimeo;	/* persist timeouts */
3351541Srgrimes	u_long	tcps_keeptimeo;		/* keepalive timeouts */
3361541Srgrimes	u_long	tcps_keepprobe;		/* keepalive probes sent */
3371541Srgrimes	u_long	tcps_keepdrops;		/* connections dropped in keepalive */
3381541Srgrimes
3391541Srgrimes	u_long	tcps_sndtotal;		/* total packets sent */
3401541Srgrimes	u_long	tcps_sndpack;		/* data packets sent */
3411541Srgrimes	u_long	tcps_sndbyte;		/* data bytes sent */
3421541Srgrimes	u_long	tcps_sndrexmitpack;	/* data packets retransmitted */
3431541Srgrimes	u_long	tcps_sndrexmitbyte;	/* data bytes retransmitted */
344100373Sdillon	u_long	tcps_sndrexmitbad;	/* unnecessary packet retransmissions */
3451541Srgrimes	u_long	tcps_sndacks;		/* ack-only packets sent */
3461541Srgrimes	u_long	tcps_sndprobe;		/* window probes sent */
3471541Srgrimes	u_long	tcps_sndurg;		/* packets sent with URG only */
3481541Srgrimes	u_long	tcps_sndwinup;		/* window update-only packets sent */
3491541Srgrimes	u_long	tcps_sndctrl;		/* control (SYN|FIN|RST) packets sent */
3501541Srgrimes
3511541Srgrimes	u_long	tcps_rcvtotal;		/* total packets received */
3521541Srgrimes	u_long	tcps_rcvpack;		/* packets received in sequence */
3531541Srgrimes	u_long	tcps_rcvbyte;		/* bytes received in sequence */
3541541Srgrimes	u_long	tcps_rcvbadsum;		/* packets received with ccksum errs */
3551541Srgrimes	u_long	tcps_rcvbadoff;		/* packets received with bad offset */
35652904Sshin	u_long	tcps_rcvmemdrop;	/* packets dropped for lack of memory */
3571541Srgrimes	u_long	tcps_rcvshort;		/* packets received too short */
3581541Srgrimes	u_long	tcps_rcvduppack;	/* duplicate-only packets received */
3591541Srgrimes	u_long	tcps_rcvdupbyte;	/* duplicate-only bytes received */
3601541Srgrimes	u_long	tcps_rcvpartduppack;	/* packets with some duplicate data */
3611541Srgrimes	u_long	tcps_rcvpartdupbyte;	/* dup. bytes in part-dup. packets */
3621541Srgrimes	u_long	tcps_rcvoopack;		/* out-of-order packets received */
3631541Srgrimes	u_long	tcps_rcvoobyte;		/* out-of-order bytes received */
3641541Srgrimes	u_long	tcps_rcvpackafterwin;	/* packets with data after window */
3651541Srgrimes	u_long	tcps_rcvbyteafterwin;	/* bytes rcvd after window */
3661541Srgrimes	u_long	tcps_rcvafterclose;	/* packets rcvd after "close" */
3671541Srgrimes	u_long	tcps_rcvwinprobe;	/* rcvd window probe packets */
3681541Srgrimes	u_long	tcps_rcvdupack;		/* rcvd duplicate acks */
3691541Srgrimes	u_long	tcps_rcvacktoomuch;	/* rcvd acks for unsent data */
3701541Srgrimes	u_long	tcps_rcvackpack;	/* rcvd ack packets */
3711541Srgrimes	u_long	tcps_rcvackbyte;	/* bytes acked by rcvd acks */
3721541Srgrimes	u_long	tcps_rcvwinupd;		/* rcvd window update packets */
3731541Srgrimes	u_long	tcps_pawsdrop;		/* segments dropped due to PAWS */
3741541Srgrimes	u_long	tcps_predack;		/* times hdr predict ok for acks */
3751541Srgrimes	u_long	tcps_preddat;		/* times hdr predict ok for data pkts */
3761541Srgrimes	u_long	tcps_pcbcachemiss;
3779263Swollman	u_long	tcps_cachedrtt;		/* times cached RTT in route updated */
3789263Swollman	u_long	tcps_cachedrttvar;	/* times cached rttvar updated */
3799263Swollman	u_long	tcps_cachedssthresh;	/* times cached ssthresh updated */
3809470Swollman	u_long	tcps_usedrtt;		/* times RTT initialized from route */
3819470Swollman	u_long	tcps_usedrttvar;	/* times RTTVAR initialized from rt */
3829470Swollman	u_long	tcps_usedssthresh;	/* times ssthresh initialized from rt*/
38310937Swollman	u_long	tcps_persistdrop;	/* timeout in persist state */
38410937Swollman	u_long	tcps_badsyn;		/* bogus SYN, e.g. premature ACK */
38511415Swollman	u_long	tcps_mturesent;		/* resends due to MTU discovery */
38614281Sbde	u_long	tcps_listendrop;	/* listen queue overflows */
38786764Sjlemon
38886764Sjlemon	u_long	tcps_sc_added;		/* entry added to syncache */
38986764Sjlemon	u_long	tcps_sc_retransmitted;	/* syncache entry was retransmitted */
39086764Sjlemon	u_long	tcps_sc_dupsyn;		/* duplicate SYN packet */
39186764Sjlemon	u_long	tcps_sc_dropped;	/* could not reply to packet */
39286764Sjlemon	u_long	tcps_sc_completed;	/* successful extraction of entry */
39386764Sjlemon	u_long	tcps_sc_bucketoverflow;	/* syncache per-bucket limit hit */
39486764Sjlemon	u_long	tcps_sc_cacheoverflow;	/* syncache cache limit hit */
39586764Sjlemon	u_long	tcps_sc_reset;		/* RST removed entry from syncache */
39686764Sjlemon	u_long	tcps_sc_stale;		/* timed out or listen socket gone */
39786764Sjlemon	u_long	tcps_sc_aborted;	/* syncache entry aborted */
39886764Sjlemon	u_long	tcps_sc_badack;		/* removed due to bad ACK */
39986764Sjlemon	u_long	tcps_sc_unreach;	/* ICMP unreachable received */
40086764Sjlemon	u_long	tcps_sc_zonefail;	/* zalloc() failed */
40186764Sjlemon	u_long	tcps_sc_sendcookie;	/* SYN cookie sent */
40286764Sjlemon	u_long	tcps_sc_recvcookie;	/* SYN cookie received */
4031541Srgrimes};
4041541Srgrimes
4056247Swollman/*
40636079Swollman * TCB structure exported to user-land via sysctl(3).
40737183Sjhay * Evil hack: declare only if in_pcb.h and sys/socketvar.h have been
40837183Sjhay * included.  Not all of our clients do.
40936079Swollman */
41037183Sjhay#if defined(_NETINET_IN_PCB_H_) && defined(_SYS_SOCKETVAR_H_)
41136079Swollmanstruct	xtcpcb {
41236079Swollman	size_t	xt_len;
41336079Swollman	struct	inpcb	xt_inp;
41436079Swollman	struct	tcpcb	xt_tp;
41536079Swollman	struct	xsocket	xt_socket;
41636079Swollman	u_quad_t	xt_alignment_hack;
41736079Swollman};
41836079Swollman#endif
41936079Swollman
42036079Swollman/*
4216247Swollman * Names for TCP sysctl objects
4226247Swollman */
4236247Swollman#define	TCPCTL_DO_RFC1323	1	/* use RFC-1323 extensions */
4246247Swollman#define	TCPCTL_DO_RFC1644	2	/* use RFC-1644 extensions */
4256247Swollman#define	TCPCTL_MSSDFLT		3	/* MSS default */
4266472Swollman#define TCPCTL_STATS		4	/* statistics (read-only) */
4276472Swollman#define	TCPCTL_RTTDFLT		5	/* default RTT estimate */
4286472Swollman#define	TCPCTL_KEEPIDLE		6	/* keepalive idle timer */
4296472Swollman#define	TCPCTL_KEEPINTVL	7	/* interval to send keepalives */
43018281Spst#define	TCPCTL_SENDSPACE	8	/* send buffer space */
43118281Spst#define	TCPCTL_RECVSPACE	9	/* receive buffer space */
43263431Ssheldonh#define	TCPCTL_KEEPINIT		10	/* timeout for establishing syn */
43336079Swollman#define	TCPCTL_PCBLIST		11	/* list of all outstanding PCBs */
43450673Sjlemon#define	TCPCTL_DELACKTIME	12	/* time before sending delayed ACK */
43552904Sshin#define	TCPCTL_V6MSSDFLT	13	/* MSS default for IPv6 */
43652904Sshin#define	TCPCTL_MAXID		14
4376247Swollman
4386247Swollman#define TCPCTL_NAMES { \
4396247Swollman	{ 0, 0 }, \
4406348Swollman	{ "rfc1323", CTLTYPE_INT }, \
4416348Swollman	{ "rfc1644", CTLTYPE_INT }, \
4426247Swollman	{ "mssdflt", CTLTYPE_INT }, \
4436472Swollman	{ "stats", CTLTYPE_STRUCT }, \
4446472Swollman	{ "rttdflt", CTLTYPE_INT }, \
4456472Swollman	{ "keepidle", CTLTYPE_INT }, \
4466472Swollman	{ "keepintvl", CTLTYPE_INT }, \
4476472Swollman	{ "sendspace", CTLTYPE_INT }, \
4486472Swollman	{ "recvspace", CTLTYPE_INT }, \
44918281Spst	{ "keepinit", CTLTYPE_INT }, \
45036079Swollman	{ "pcblist", CTLTYPE_STRUCT }, \
45150673Sjlemon	{ "delacktime", CTLTYPE_INT }, \
45252904Sshin	{ "v6mssdflt", CTLTYPE_INT }, \
4536247Swollman}
4546247Swollman
45544078Sdfr
45655205Speter#ifdef _KERNEL
45744078Sdfr#ifdef SYSCTL_DECL
45844078SdfrSYSCTL_DECL(_net_inet_tcp);
45944078Sdfr#endif
46044078Sdfr
4617684Sdgextern	struct inpcbhead tcb;		/* head of queue of active tcpcb's */
4627684Sdgextern	struct inpcbinfo tcbinfo;
4636348Swollmanextern	struct tcpstat tcpstat;	/* tcp statistics */
4647090Sbdeextern	int tcp_mssdflt;	/* XXX */
46533846Sdgextern	int tcp_delack_enabled;
46660067Sjlemonextern	int tcp_do_newreno;
46798204Ssilbyextern	int path_mtu_discovery;
46850673Sjlemonextern	int ss_fltsz;
46950673Sjlemonextern	int ss_fltsz_local;
4701541Srgrimes
47192723Salfredvoid	 tcp_canceltimers(struct tcpcb *);
4721541Srgrimesstruct tcpcb *
47392723Salfred	 tcp_close(struct tcpcb *);
474111145Sjlemonvoid	 tcp_twstart(struct tcpcb *);
475121850Ssilbyint	 tcp_twrecycleable(struct tcptw *tw);
476112009Sjlemonstruct tcptw *
477112009Sjlemon	 tcp_twclose(struct tcptw *_tw, int _reuse);
47892723Salfredvoid	 tcp_ctlinput(int, struct sockaddr *, void *);
47992723Salfredint	 tcp_ctloutput(struct socket *, struct sockopt *);
4801541Srgrimesstruct tcpcb *
48192723Salfred	 tcp_drop(struct tcpcb *, int);
48292723Salfredvoid	 tcp_drain(void);
48392723Salfredvoid	 tcp_fasttimo(void);
4846247Swollmanstruct rmxp_tao *
48592723Salfred	 tcp_gettaocache(struct in_conninfo *);
48692723Salfredvoid	 tcp_init(void);
48792723Salfredvoid	 tcp_input(struct mbuf *, int);
48892723Salfredvoid	 tcp_mss(struct tcpcb *, int);
48992723Salfredint	 tcp_mssopt(struct tcpcb *);
49098211Shsustruct inpcb *
49198211Shsu	 tcp_drop_syn_sent(struct inpcb *, int);
49298211Shsustruct inpcb *
49398211Shsu	 tcp_mtudisc(struct inpcb *, int);
4941541Srgrimesstruct tcpcb *
49592723Salfred	 tcp_newtcpcb(struct inpcb *);
49692723Salfredint	 tcp_output(struct tcpcb *);
49798211Shsustruct inpcb *
49898211Shsu	 tcp_quench(struct inpcb *, int);
49992723Salfredvoid	 tcp_respond(struct tcpcb *, void *,
50092723Salfred	    struct tcphdr *, struct mbuf *, tcp_seq, tcp_seq, int);
501114794Srwatsonint	 tcp_twrespond(struct tcptw *, struct socket *, struct mbuf *, int);
5026247Swollmanstruct rtentry *
50392723Salfred	 tcp_rtlookup(struct in_conninfo *);
50492723Salfredvoid	 tcp_setpersist(struct tcpcb *);
50592723Salfredvoid	 tcp_slowtimo(void);
50655679Sshinstruct tcptemp *
507111144Sjlemon	 tcpip_maketemplate(struct inpcb *);
508111144Sjlemonvoid	 tcpip_fillheaders(struct inpcb *, void *, void *);
5091541Srgrimesstruct tcpcb *
51092723Salfred	 tcp_timers(struct tcpcb *, int);
51192723Salfredvoid	 tcp_trace(int, int, struct tcpcb *, void *, struct tcphdr *, int);
512102017Sdillonvoid	 tcp_xmit_bandwidth_limit(struct tcpcb *tp, tcp_seq ack_seq);
51386764Sjlemonvoid	 syncache_init(void);
51486764Sjlemonvoid	 syncache_unreach(struct in_conninfo *, struct tcphdr *);
51586764Sjlemonint	 syncache_expand(struct in_conninfo *, struct tcphdr *,
51686764Sjlemon	     struct socket **, struct mbuf *);
51786764Sjlemonint	 syncache_add(struct in_conninfo *, struct tcpopt *,
51886764Sjlemon	     struct tcphdr *, struct socket **, struct mbuf *);
51986764Sjlemonvoid	 syncache_chkrst(struct in_conninfo *, struct tcphdr *);
52086764Sjlemonvoid	 syncache_badack(struct in_conninfo *);
5219470Swollman
52217096Swollmanextern	struct pr_usrreqs tcp_usrreqs;
5239470Swollmanextern	u_long tcp_sendspace;
5249470Swollmanextern	u_long tcp_recvspace;
52592723Salfredtcp_seq tcp_new_isn(struct tcpcb *);
5269470Swollman
52755205Speter#endif /* _KERNEL */
5282169Spaul
5296348Swollman#endif /* _NETINET_TCP_VAR_H_ */
530