tcp_var.h revision 273838
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: stable/10/sys/netinet/tcp_var.h 273838 2014-10-29 22:17:45Z sbruno $
311541Srgrimes */
321541Srgrimes
332169Spaul#ifndef _NETINET_TCP_VAR_H_
342169Spaul#define _NETINET_TCP_VAR_H_
3586764Sjlemon
3698102Shsu#include <netinet/tcp.h>
3786764Sjlemon
38195699Srwatson#ifdef _KERNEL
39195699Srwatson#include <net/vnet.h>
40191688Szec
411541Srgrimes/*
421541Srgrimes * Kernel variables for tcp.
431541Srgrimes */
44195699SrwatsonVNET_DECLARE(int, tcp_do_rfc1323);
45207369Sbz#define	V_tcp_do_rfc1323	VNET(tcp_do_rfc1323)
46207369Sbz
47195699Srwatson#endif /* _KERNEL */
48195699Srwatson
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
58130989Spsstruct sackblk {
59130989Sps	tcp_seq start;		/* start seq no. of sack block */
60131078Sbms	tcp_seq end;		/* end seq no. */
61130989Sps};
62130989Sps
63130989Spsstruct sackhole {
64130989Sps	tcp_seq start;		/* start seq no. of hole */
65130989Sps	tcp_seq end;		/* end seq no. */
66130989Sps	tcp_seq rxmit;		/* next seq. no in hole to be retransmitted */
67145370Sps	TAILQ_ENTRY(sackhole) scblink;	/* scoreboard linkage */
68130989Sps};
69131078Sbms
70146123Spsstruct sackhint {
71146123Sps	struct sackhole	*nexthole;
72146123Sps	int		sack_bytes_rexmit;
73216753Slstewart	tcp_seq		last_sack_ack;	/* Most recent/largest sacked ack */
74195634Slstewart
75195634Slstewart	int		ispare;		/* explicit pad for 64bit alignment */
76195634Slstewart	uint64_t	_pad[2];	/* 1 sacked_bytes, 1 TBD */
77146123Sps};
78146123Sps
7955679Sshinstruct tcptemp {
8055679Sshin	u_char	tt_ipgen[40]; /* the size must be of max ip header, now IPv6 */
8155679Sshin	struct	tcphdr tt_t;
8255679Sshin};
8355679Sshin
8455679Sshin#define tcp6cb		tcpcb  /* for KAME src sync over BSD*'s */
8555679Sshin
86169541Sandre/* Neighbor Discovery, Neighbor Unreachability Detection Upper layer hint. */
87169541Sandre#ifdef INET6
88169541Sandre#define ND6_HINT(tp)						\
89169541Sandredo {								\
90169541Sandre	if ((tp) && (tp)->t_inpcb &&				\
91169541Sandre	    ((tp)->t_inpcb->inp_vflag & INP_IPV6) != 0)		\
92169541Sandre		nd6_nud_hint(NULL, NULL, 0);			\
93169541Sandre} while (0)
94169541Sandre#else
95169541Sandre#define ND6_HINT(tp)
96169541Sandre#endif
97169541Sandre
981541Srgrimes/*
991541Srgrimes * Tcp control block, one per tcp; fields:
10032821Sdg * Organized for 16 byte cacheline efficiency.
1011541Srgrimes */
1021541Srgrimesstruct tcpcb {
103126193Sandre	struct	tsegqe_head t_segq;	/* segment reassembly queue */
104195634Slstewart	void	*t_pspare[2];		/* new reassembly queue */
105126193Sandre	int	t_segqlen;		/* segment reassembly queue length */
10632821Sdg	int	t_dupacks;		/* consecutive dup acks recd */
10732821Sdg
108172309Ssilby	struct tcp_timer *t_timers;	/* All the TCP timers in one struct */
10932821Sdg
11032821Sdg	struct	inpcb *t_inpcb;		/* back pointer to internet pcb */
11111187Swollman	int	t_state;		/* state of this connection */
11211187Swollman	u_int	t_flags;
1131541Srgrimes
114191688Szec	struct	vnet *t_vnet;		/* back pointer to parent vnet */
115191688Szec
1161541Srgrimes	tcp_seq	snd_una;		/* send unacknowledged */
11732821Sdg	tcp_seq	snd_max;		/* highest sequence number sent;
11832821Sdg					 * used to recognize retransmits
11932821Sdg					 */
1201541Srgrimes	tcp_seq	snd_nxt;		/* send next */
1211541Srgrimes	tcp_seq	snd_up;			/* send urgent pointer */
12232821Sdg
1231541Srgrimes	tcp_seq	snd_wl1;		/* window update seg seq number */
1241541Srgrimes	tcp_seq	snd_wl2;		/* window update seg ack number */
1251541Srgrimes	tcp_seq	iss;			/* initial send sequence number */
12632821Sdg	tcp_seq	irs;			/* initial receive sequence number */
12732821Sdg
12832821Sdg	tcp_seq	rcv_nxt;		/* receive next */
12932821Sdg	tcp_seq	rcv_adv;		/* advertised window */
1301541Srgrimes	u_long	rcv_wnd;		/* receive window */
1311541Srgrimes	tcp_seq	rcv_up;			/* receive urgent pointer */
13232821Sdg
13332821Sdg	u_long	snd_wnd;		/* send window */
1341541Srgrimes	u_long	snd_cwnd;		/* congestion-controlled window */
135212765Sandre	u_long	snd_spare1;		/* unused */
13613765Smpp	u_long	snd_ssthresh;		/* snd_cwnd size threshold for
1371541Srgrimes					 * for slow start exponential to
1381541Srgrimes					 * linear switch
1391541Srgrimes					 */
140212765Sandre	u_long	snd_spare2;		/* unused */
141109175Shsu	tcp_seq	snd_recover;		/* for use in NewReno Fast Recovery */
14260067Sjlemon
14332821Sdg	u_int	t_maxopd;		/* mss plus options */
14432821Sdg
145194303Sjhb	u_int	t_rcvtime;		/* inactivity time */
146194303Sjhb	u_int	t_starttime;		/* time connection was established */
147194303Sjhb	u_int	t_rtttime;		/* RTT measurement start time */
1481541Srgrimes	tcp_seq	t_rtseq;		/* sequence number being timed */
14932821Sdg
150212765Sandre	u_int	t_bw_spare1;		/* unused */
151212765Sandre	tcp_seq	t_bw_spare2;		/* unused */
152102017Sdillon
15350673Sjlemon	int	t_rxtcur;		/* current retransmit value (ticks) */
15432821Sdg	u_int	t_maxseg;		/* maximum segment size */
15511187Swollman	int	t_srtt;			/* smoothed round-trip time */
15611187Swollman	int	t_rttvar;		/* variance in round-trip time */
15732821Sdg
15832821Sdg	int	t_rxtshift;		/* log(2) of rexmt exp. backoff */
15911187Swollman	u_int	t_rttmin;		/* minimum rtt allowed */
160102017Sdillon	u_int	t_rttbest;		/* best rtt we've seen */
16132821Sdg	u_long	t_rttupdated;		/* number of times rtt sampled */
1621541Srgrimes	u_long	max_sndwnd;		/* largest window peer has offered */
1631541Srgrimes
16432821Sdg	int	t_softerror;		/* possible error not yet reported */
1651541Srgrimes/* out-of-band data */
1661541Srgrimes	char	t_oobflags;		/* have some */
1671541Srgrimes	char	t_iobc;			/* input character */
1681541Srgrimes/* RFC 1323 variables */
1691541Srgrimes	u_char	snd_scale;		/* window scaling for send window */
1701541Srgrimes	u_char	rcv_scale;		/* window scaling for recv window */
1711541Srgrimes	u_char	request_r_scale;	/* pending window scaling */
172162277Sandre	u_int32_t  ts_recent;		/* timestamp echo data */
173194303Sjhb	u_int	ts_recent_age;		/* when last updated */
174162277Sandre	u_int32_t  ts_offset;		/* our timestamp offset */
17532821Sdg
1761541Srgrimes	tcp_seq	last_ack_sent;
17750673Sjlemon/* experimental */
17850673Sjlemon	u_long	snd_cwnd_prev;		/* cwnd prior to retransmit */
17950673Sjlemon	u_long	snd_ssthresh_prev;	/* ssthresh prior to retransmit */
180117650Shsu	tcp_seq	snd_recover_prev;	/* snd_recover prior to retransmit */
181215434Sgnn	int	t_sndzerowin;		/* zero-window updates sent */
182194303Sjhb	u_int	t_badrxtwin;		/* window for retransmit recovery */
183112957Shsu	u_char	snd_limited;		/* segments limited transmitted */
184131078Sbms/* SACK related state */
185130989Sps	int	snd_numholes;		/* number of holes seen by sender */
186146953Sps	TAILQ_HEAD(sackhole_head, sackhole) snd_holes;
187146953Sps					/* SACK scoreboard (sorted) */
188146630Sps	tcp_seq	snd_fack;		/* last seq number(+1) sack'd by rcv'r*/
189130989Sps	int	rcv_numsacks;		/* # distinct sack blks present */
190130989Sps	struct sackblk sackblks[MAX_SACK_BLKS]; /* seq nos. of sack blocks */
191136151Sps	tcp_seq sack_newdata;		/* New data xmitted in this recovery
192136151Sps					   episode starts at this seq number */
193146123Sps	struct sackhint	sackhint;	/* SACK scoreboard hint */
194155767Sandre	int	t_rttlow;		/* smallest observerved RTT */
195166405Sandre	u_int32_t	rfbuf_ts;	/* recv buffer autoscaling timestamp */
196166405Sandre	int	rfbuf_cnt;		/* recv buffer autoscaling byte count */
197237263Snp	struct toedev	*tod;		/* toedev handling this connection */
198215434Sgnn	int	t_sndrexmitpack;	/* retransmit packets sent */
199215434Sgnn	int	t_rcvoopack;		/* out-of-order packets received */
200174560Skmacy	void	*t_toe;			/* TOE pcb pointer */
201187289Slstewart	int	t_bytes_acked;		/* # bytes acked during current RTT */
202215166Slstewart	struct cc_algo	*cc_algo;	/* congestion control algorithm */
203216760Slstewart	struct cc_var	*ccv;		/* congestion control specific vars */
204216758Slstewart	struct osd	*osd;		/* storage for Khelp module data */
205195634Slstewart
206231025Sglebius	u_int	t_keepinit;		/* time to establish connection */
207231025Sglebius	u_int	t_keepidle;		/* time before keepalive probes begin */
208231025Sglebius	u_int	t_keepintvl;		/* interval between keepalives */
209231025Sglebius	u_int	t_keepcnt;		/* number of keepalives before close */
210231025Sglebius
211251296Sandre	u_int	t_tsomax;		/* tso burst length limit */
212273838Ssbruno	u_int	t_pmtud_saved_maxopd;	/* pre-blackhole MSS */
213273838Ssbruno	u_int	t_flags2;		/* More tcpcb flags storage */
214251296Sandre
215273838Ssbruno	uint32_t t_ispare[6];		/* 5 UTO, 1 TBD */
216255759Sbz	void	*t_pspare2[4];		/* 1 TCP_SIGNATURE, 3 TBD */
217224151Sbz	uint64_t _pad[6];		/* 6 TBD (1-2 CC/RTT?) */
2181541Srgrimes};
2191541Srgrimes
220185855Srwatson/*
221185855Srwatson * Flags and utility macros for the t_flags field.
222185855Srwatson */
223185855Srwatson#define	TF_ACKNOW	0x000001	/* ack peer immediately */
224185855Srwatson#define	TF_DELACK	0x000002	/* ack, but try to delay it */
225185855Srwatson#define	TF_NODELAY	0x000004	/* don't delay packets to coalesce */
226185855Srwatson#define	TF_NOOPT	0x000008	/* don't use tcp options */
227185855Srwatson#define	TF_SENTFIN	0x000010	/* have sent FIN */
228185855Srwatson#define	TF_REQ_SCALE	0x000020	/* have/will request window scaling */
229185855Srwatson#define	TF_RCVD_SCALE	0x000040	/* other side has requested scaling */
230185855Srwatson#define	TF_REQ_TSTMP	0x000080	/* have/will request timestamps */
231185855Srwatson#define	TF_RCVD_TSTMP	0x000100	/* a timestamp was received in SYN */
232185855Srwatson#define	TF_SACK_PERMIT	0x000200	/* other side said I could SACK */
233185855Srwatson#define	TF_NEEDSYN	0x000400	/* send SYN (implicit state) */
234185855Srwatson#define	TF_NEEDFIN	0x000800	/* send FIN (implicit state) */
235185855Srwatson#define	TF_NOPUSH	0x001000	/* don't push */
236221209Sjhb#define	TF_PREVVALID	0x002000	/* saved values for bad rxmit valid */
237185855Srwatson#define	TF_MORETOCOME	0x010000	/* More data to be appended to sock */
238185855Srwatson#define	TF_LQ_OVERFLOW	0x020000	/* listen queue overflow */
239185855Srwatson#define	TF_LASTIDLE	0x040000	/* connection was previously idle */
240185855Srwatson#define	TF_RXWIN0SENT	0x080000	/* sent a receiver win 0 in response */
241185855Srwatson#define	TF_FASTRECOVERY	0x100000	/* in NewReno Fast Recovery */
242185855Srwatson#define	TF_WASFRECOVERY	0x200000	/* was in NewReno Fast Recovery */
243185855Srwatson#define	TF_SIGNATURE	0x400000	/* require MD5 digests (RFC2385) */
244185855Srwatson#define	TF_FORCEDATA	0x800000	/* force out a byte */
245185855Srwatson#define	TF_TSO		0x1000000	/* TSO enabled on this connection */
246185855Srwatson#define	TF_TOE		0x2000000	/* this connection is offloaded */
247185855Srwatson#define	TF_ECN_PERMIT	0x4000000	/* connection ECN-ready */
248185855Srwatson#define	TF_ECN_SND_CWR	0x8000000	/* ECN CWR in queue */
249185855Srwatson#define	TF_ECN_SND_ECE	0x10000000	/* ECN ECE in queue */
250215166Slstewart#define	TF_CONGRECOVERY	0x20000000	/* congestion recovery mode */
251215166Slstewart#define	TF_WASCRECOVERY	0x40000000	/* was in congestion recovery */
252185855Srwatson
253215166Slstewart#define	IN_FASTRECOVERY(t_flags)	(t_flags & TF_FASTRECOVERY)
254215166Slstewart#define	ENTER_FASTRECOVERY(t_flags)	t_flags |= TF_FASTRECOVERY
255215166Slstewart#define	EXIT_FASTRECOVERY(t_flags)	t_flags &= ~TF_FASTRECOVERY
256117650Shsu
257215166Slstewart#define	IN_CONGRECOVERY(t_flags)	(t_flags & TF_CONGRECOVERY)
258215166Slstewart#define	ENTER_CONGRECOVERY(t_flags)	t_flags |= TF_CONGRECOVERY
259215166Slstewart#define	EXIT_CONGRECOVERY(t_flags)	t_flags &= ~TF_CONGRECOVERY
260215166Slstewart
261215166Slstewart#define	IN_RECOVERY(t_flags) (t_flags & (TF_CONGRECOVERY | TF_FASTRECOVERY))
262215166Slstewart#define	ENTER_RECOVERY(t_flags) t_flags |= (TF_CONGRECOVERY | TF_FASTRECOVERY)
263215166Slstewart#define	EXIT_RECOVERY(t_flags) t_flags &= ~(TF_CONGRECOVERY | TF_FASTRECOVERY)
264215166Slstewart
265215166Slstewart#define	BYTES_THIS_ACK(tp, th)	(th->th_ack - tp->snd_una)
266215166Slstewart
267185855Srwatson/*
268185855Srwatson * Flags for the t_oobflags field.
269185855Srwatson */
270185855Srwatson#define	TCPOOB_HAVEDATA	0x01
271185855Srwatson#define	TCPOOB_HADDATA	0x02
272185855Srwatson
273125680Sbms#ifdef TCP_SIGNATURE
2746247Swollman/*
275125680Sbms * Defines which are needed by the xform_tcp module and tcp_[in|out]put
276125680Sbms * for SADB verification and lookup.
277125680Sbms */
278125680Sbms#define	TCP_SIGLEN	16	/* length of computed digest in bytes */
279125680Sbms#define	TCP_KEYLEN_MIN	1	/* minimum length of TCP-MD5 key */
280125680Sbms#define	TCP_KEYLEN_MAX	80	/* maximum length of TCP-MD5 key */
281125680Sbms/*
282125680Sbms * Only a single SA per host may be specified at this time. An SPI is
283125680Sbms * needed in order for the KEY_ALLOCSA() lookup to work.
284125680Sbms */
285125680Sbms#define	TCP_SIG_SPI	0x1000
286125680Sbms#endif /* TCP_SIGNATURE */
287125680Sbms
288125680Sbms/*
289273838Ssbruno * Flags for PLPMTU handling, t_flags2
290273838Ssbruno */
291273838Ssbruno#define	TF2_PLPMTU_BLACKHOLE	0x00000001 /* Possible PLPMTUD Black Hole. */
292273838Ssbruno#define	TF2_PLPMTU_PMTUD	0x00000002 /* Allowed to attempt PLPMTUD. */
293273838Ssbruno#define	TF2_PLPMTU_MAXSEGSNT	0x00000004 /* Last seg sent was full seg. */
294273838Ssbruno
295273838Ssbruno/*
2966247Swollman * Structure to hold TCP options that are only used during segment
2976247Swollman * processing (in tcp_input), but not held in the tcpcb.
2986247Swollman * It's basically used to reduce the number of parameters
299167606Sandre * to tcp_dooptions and tcp_addoptions.
300167606Sandre * The binary order of the to_flags is relevant for packing of the
301167606Sandre * options in tcp_addoptions.
3026247Swollman */
3036247Swollmanstruct tcpopt {
304195654Slstewart	u_int64_t	to_flags;	/* which options are present */
305167606Sandre#define	TOF_MSS		0x0001		/* maximum segment size */
306167606Sandre#define	TOF_SCALE	0x0002		/* window scaling */
307178349Sbz#define	TOF_SACKPERM	0x0004		/* SACK permitted */
308167606Sandre#define	TOF_TS		0x0010		/* timestamp */
309178349Sbz#define	TOF_SIGNATURE	0x0040		/* TCP-MD5 signature option (RFC2385) */
310168906Sandre#define	TOF_SACK	0x0080		/* Peer sent SACK option */
311168906Sandre#define	TOF_MAXOPT	0x0100
312168906Sandre	u_int32_t	to_tsval;	/* new timestamp */
313167606Sandre	u_int32_t	to_tsecr;	/* reflected timestamp */
314195654Slstewart	u_char		*to_sacks;	/* pointer to the first SACK blocks */
315195654Slstewart	u_char		*to_signature;	/* pointer to the TCP-MD5 signature */
316167606Sandre	u_int16_t	to_mss;		/* maximum segment size */
317167606Sandre	u_int8_t	to_wscale;	/* window scaling */
318147637Sps	u_int8_t	to_nsacks;	/* number of SACK blocks */
319224151Sbz	u_int32_t	to_spare;	/* UTO */
3206247Swollman};
3216247Swollman
322159949Sandre/*
323159949Sandre * Flags for tcp_dooptions.
324159949Sandre */
325159949Sandre#define	TO_SYN		0x01		/* parse SYN-only options */
326159949Sandre
327122922Sandrestruct hc_metrics_lite {	/* must stay in sync with hc_metrics */
328122922Sandre	u_long	rmx_mtu;	/* MTU for this path */
329122922Sandre	u_long	rmx_ssthresh;	/* outbound gateway buffer limit */
330122922Sandre	u_long	rmx_rtt;	/* estimated round trip time */
331122922Sandre	u_long	rmx_rttvar;	/* estimated rtt variance */
332122922Sandre	u_long	rmx_bandwidth;	/* estimated bandwidth */
333122922Sandre	u_long	rmx_cwnd;	/* congestion window */
334122922Sandre	u_long	rmx_sendpipe;   /* outbound delay-bandwidth product */
335122922Sandre	u_long	rmx_recvpipe;   /* inbound delay-bandwidth product */
336122922Sandre};
337122922Sandre
338251296Sandre/*
339251296Sandre * Used by tcp_maxmtu() to communicate interface specific features
340251296Sandre * and limits at the time of connection setup.
341251296Sandre */
342251296Sandrestruct tcp_ifcap {
343251296Sandre	int	ifcap;
344251296Sandre	u_int	tsomax;
345251296Sandre};
346251296Sandre
347159725Sandre#ifndef _NETINET_IN_PCB_H_
348159725Sandrestruct in_conninfo;
349159725Sandre#endif /* _NETINET_IN_PCB_H_ */
350159725Sandre
351111145Sjlemonstruct tcptw {
352111145Sjlemon	struct inpcb	*tw_inpcb;	/* XXX back pointer to internet pcb */
353111145Sjlemon	tcp_seq		snd_nxt;
354111145Sjlemon	tcp_seq		rcv_nxt;
355121850Ssilby	tcp_seq		iss;
356121884Ssilby	tcp_seq		irs;
357111145Sjlemon	u_short		last_win;	/* cached window value */
358111145Sjlemon	u_short		tw_so_options;	/* copy of so_options */
359111145Sjlemon	struct ucred	*tw_cred;	/* user credentials */
360194303Sjhb	u_int32_t	t_recent;
361169477Sandre	u_int32_t	ts_offset;	/* our timestamp offset */
362194303Sjhb	u_int		t_starttime;
363112009Sjlemon	int		tw_time;
364162111Sru	TAILQ_ENTRY(tcptw) tw_2msl;
365255759Sbz	void		*tw_pspare;	/* TCP_SIGNATURE */
366255759Sbz	u_int		*tw_spare;	/* TCP_SIGNATURE */
367111145Sjlemon};
368133874Srwatson
3691541Srgrimes#define	intotcpcb(ip)	((struct tcpcb *)(ip)->inp_ppcb)
370111145Sjlemon#define	intotw(ip)	((struct tcptw *)(ip)->inp_ppcb)
3711541Srgrimes#define	sototcpcb(so)	(intotcpcb(sotoinpcb(so)))
3721541Srgrimes
3731541Srgrimes/*
3741541Srgrimes * The smoothed round-trip time and estimated variance
3751541Srgrimes * are stored as fixed point numbers scaled by the values below.
3761541Srgrimes * For convenience, these scales are also used in smoothing the average
3771541Srgrimes * (smoothed = (1/scale)sample + ((scale-1)/scale)smoothed).
3781541Srgrimes * With these scales, srtt has 3 bits to the right of the binary point,
3791541Srgrimes * and thus an "ALPHA" of 0.875.  rttvar has 2 bits to the right of the
3801541Srgrimes * binary point, and is smoothed with an ALPHA of 0.75.
3811541Srgrimes */
38214753Swollman#define	TCP_RTT_SCALE		32	/* multiplier for srtt; 3 bits frac. */
38314753Swollman#define	TCP_RTT_SHIFT		5	/* shift for srtt; 3 bits frac. */
38414753Swollman#define	TCP_RTTVAR_SCALE	16	/* multiplier for rttvar; 2 bits */
38514753Swollman#define	TCP_RTTVAR_SHIFT	4	/* shift for rttvar; 2 bits */
38614753Swollman#define	TCP_DELTA_SHIFT		2	/* see tcp_input.c */
3871541Srgrimes
3881541Srgrimes/*
3891541Srgrimes * The initial retransmission should happen at rtt + 4 * rttvar.
3901541Srgrimes * Because of the way we do the smoothing, srtt and rttvar
3911541Srgrimes * will each average +1/2 tick of bias.  When we compute
3921541Srgrimes * the retransmit timer, we want 1/2 tick of rounding and
3931541Srgrimes * 1 extra tick because of +-1/2 tick uncertainty in the
3941541Srgrimes * firing of the timer.  The bias will give us exactly the
3951541Srgrimes * 1.5 tick we need.  But, because the bias is
3961541Srgrimes * statistical, we have to test that we don't drop below
3971541Srgrimes * the minimum feasible timer (which is 2 ticks).
39814753Swollman * This version of the macro adapted from a paper by Lawrence
39914753Swollman * Brakmo and Larry Peterson which outlines a problem caused
40014753Swollman * by insufficient precision in the original implementation,
40114753Swollman * which results in inappropriately large RTO values for very
40214753Swollman * fast networks.
4031541Srgrimes */
4041541Srgrimes#define	TCP_REXMTVAL(tp) \
40535419Sdg	max((tp)->t_rttmin, (((tp)->t_srtt >> (TCP_RTT_SHIFT - TCP_DELTA_SHIFT))  \
40616141Swollman	  + (tp)->t_rttvar) >> TCP_DELTA_SHIFT)
4071541Srgrimes
4081541Srgrimes/*
4091541Srgrimes * TCP statistics.
4101541Srgrimes * Many of these should be kept per connection,
4111541Srgrimes * but that's inconvenient at the moment.
4121541Srgrimes */
4131541Srgrimesstruct	tcpstat {
414249276Sglebius	uint64_t tcps_connattempt;	/* connections initiated */
415249276Sglebius	uint64_t tcps_accepts;		/* connections accepted */
416249276Sglebius	uint64_t tcps_connects;		/* connections established */
417249276Sglebius	uint64_t tcps_drops;		/* connections dropped */
418249276Sglebius	uint64_t tcps_conndrops;	/* embryonic connections dropped */
419249276Sglebius	uint64_t tcps_minmssdrops;	/* average minmss too low drops */
420249276Sglebius	uint64_t tcps_closed;		/* conn. closed (includes drops) */
421249276Sglebius	uint64_t tcps_segstimed;	/* segs where we tried to get rtt */
422249276Sglebius	uint64_t tcps_rttupdated;	/* times we succeeded */
423249276Sglebius	uint64_t tcps_delack;		/* delayed acks sent */
424249276Sglebius	uint64_t tcps_timeoutdrop;	/* conn. dropped in rxmt timeout */
425249276Sglebius	uint64_t tcps_rexmttimeo;	/* retransmit timeouts */
426249276Sglebius	uint64_t tcps_persisttimeo;	/* persist timeouts */
427249276Sglebius	uint64_t tcps_keeptimeo;	/* keepalive timeouts */
428249276Sglebius	uint64_t tcps_keepprobe;	/* keepalive probes sent */
429249276Sglebius	uint64_t tcps_keepdrops;	/* connections dropped in keepalive */
4301541Srgrimes
431249276Sglebius	uint64_t tcps_sndtotal;		/* total packets sent */
432249276Sglebius	uint64_t tcps_sndpack;		/* data packets sent */
433249276Sglebius	uint64_t tcps_sndbyte;		/* data bytes sent */
434249276Sglebius	uint64_t tcps_sndrexmitpack;	/* data packets retransmitted */
435249276Sglebius	uint64_t tcps_sndrexmitbyte;	/* data bytes retransmitted */
436249276Sglebius	uint64_t tcps_sndrexmitbad;	/* unnecessary packet retransmissions */
437249276Sglebius	uint64_t tcps_sndacks;		/* ack-only packets sent */
438249276Sglebius	uint64_t tcps_sndprobe;		/* window probes sent */
439249276Sglebius	uint64_t tcps_sndurg;		/* packets sent with URG only */
440249276Sglebius	uint64_t tcps_sndwinup;		/* window update-only packets sent */
441249276Sglebius	uint64_t tcps_sndctrl;		/* control (SYN|FIN|RST) packets sent */
4421541Srgrimes
443249276Sglebius	uint64_t tcps_rcvtotal;		/* total packets received */
444249276Sglebius	uint64_t tcps_rcvpack;		/* packets received in sequence */
445249276Sglebius	uint64_t tcps_rcvbyte;		/* bytes received in sequence */
446249276Sglebius	uint64_t tcps_rcvbadsum;	/* packets received with ccksum errs */
447249276Sglebius	uint64_t tcps_rcvbadoff;	/* packets received with bad offset */
448249276Sglebius	uint64_t tcps_rcvmemdrop;	/* packets dropped for lack of memory */
449249276Sglebius	uint64_t tcps_rcvshort;		/* packets received too short */
450249276Sglebius	uint64_t tcps_rcvduppack;	/* duplicate-only packets received */
451249276Sglebius	uint64_t tcps_rcvdupbyte;	/* duplicate-only bytes received */
452249276Sglebius	uint64_t tcps_rcvpartduppack;	/* packets with some duplicate data */
453249276Sglebius	uint64_t tcps_rcvpartdupbyte;	/* dup. bytes in part-dup. packets */
454249276Sglebius	uint64_t tcps_rcvoopack;	/* out-of-order packets received */
455249276Sglebius	uint64_t tcps_rcvoobyte;	/* out-of-order bytes received */
456249276Sglebius	uint64_t tcps_rcvpackafterwin;	/* packets with data after window */
457249276Sglebius	uint64_t tcps_rcvbyteafterwin;	/* bytes rcvd after window */
458249276Sglebius	uint64_t tcps_rcvafterclose;	/* packets rcvd after "close" */
459249276Sglebius	uint64_t tcps_rcvwinprobe;	/* rcvd window probe packets */
460249276Sglebius	uint64_t tcps_rcvdupack;	/* rcvd duplicate acks */
461249276Sglebius	uint64_t tcps_rcvacktoomuch;	/* rcvd acks for unsent data */
462249276Sglebius	uint64_t tcps_rcvackpack;	/* rcvd ack packets */
463249276Sglebius	uint64_t tcps_rcvackbyte;	/* bytes acked by rcvd acks */
464249276Sglebius	uint64_t tcps_rcvwinupd;	/* rcvd window update packets */
465249276Sglebius	uint64_t tcps_pawsdrop;		/* segments dropped due to PAWS */
466249276Sglebius	uint64_t tcps_predack;		/* times hdr predict ok for acks */
467249276Sglebius	uint64_t tcps_preddat;		/* times hdr predict ok for data pkts */
468249276Sglebius	uint64_t tcps_pcbcachemiss;
469249276Sglebius	uint64_t tcps_cachedrtt;	/* times cached RTT in route updated */
470249276Sglebius	uint64_t tcps_cachedrttvar;	/* times cached rttvar updated */
471249276Sglebius	uint64_t tcps_cachedssthresh;	/* times cached ssthresh updated */
472249276Sglebius	uint64_t tcps_usedrtt;		/* times RTT initialized from route */
473249276Sglebius	uint64_t tcps_usedrttvar;	/* times RTTVAR initialized from rt */
474249276Sglebius	uint64_t tcps_usedssthresh;	/* times ssthresh initialized from rt*/
475249276Sglebius	uint64_t tcps_persistdrop;	/* timeout in persist state */
476249276Sglebius	uint64_t tcps_badsyn;		/* bogus SYN, e.g. premature ACK */
477249276Sglebius	uint64_t tcps_mturesent;	/* resends due to MTU discovery */
478249276Sglebius	uint64_t tcps_listendrop;	/* listen queue overflows */
479249276Sglebius	uint64_t tcps_badrst;		/* ignored RSTs in the window */
48086764Sjlemon
481249276Sglebius	uint64_t tcps_sc_added;		/* entry added to syncache */
482249276Sglebius	uint64_t tcps_sc_retransmitted;	/* syncache entry was retransmitted */
483249276Sglebius	uint64_t tcps_sc_dupsyn;	/* duplicate SYN packet */
484249276Sglebius	uint64_t tcps_sc_dropped;	/* could not reply to packet */
485249276Sglebius	uint64_t tcps_sc_completed;	/* successful extraction of entry */
486249276Sglebius	uint64_t tcps_sc_bucketoverflow;/* syncache per-bucket limit hit */
487249276Sglebius	uint64_t tcps_sc_cacheoverflow;	/* syncache cache limit hit */
488249276Sglebius	uint64_t tcps_sc_reset;		/* RST removed entry from syncache */
489249276Sglebius	uint64_t tcps_sc_stale;		/* timed out or listen socket gone */
490249276Sglebius	uint64_t tcps_sc_aborted;	/* syncache entry aborted */
491249276Sglebius	uint64_t tcps_sc_badack;	/* removed due to bad ACK */
492249276Sglebius	uint64_t tcps_sc_unreach;	/* ICMP unreachable received */
493249276Sglebius	uint64_t tcps_sc_zonefail;	/* zalloc() failed */
494249276Sglebius	uint64_t tcps_sc_sendcookie;	/* SYN cookie sent */
495249276Sglebius	uint64_t tcps_sc_recvcookie;	/* SYN cookie received */
496122922Sandre
497249276Sglebius	uint64_t tcps_hc_added;		/* entry added to hostcache */
498249276Sglebius	uint64_t tcps_hc_bucketoverflow;/* hostcache per bucket limit hit */
499130989Sps
500249276Sglebius	uint64_t tcps_finwait2_drops;    /* Drop FIN_WAIT_2 connection after time limit */
501167036Smohans
502130989Sps	/* SACK related stats */
503249276Sglebius	uint64_t tcps_sack_recovery_episode; /* SACK recovery episodes */
504249276Sglebius	uint64_t tcps_sack_rexmits;	    /* SACK rexmit segments   */
505249276Sglebius	uint64_t tcps_sack_rexmit_bytes;    /* SACK rexmit bytes      */
506249276Sglebius	uint64_t tcps_sack_rcv_blocks;	    /* SACK blocks (options) received */
507249276Sglebius	uint64_t tcps_sack_send_blocks;	    /* SACK blocks (options) sent     */
508249276Sglebius	uint64_t tcps_sack_sboverflow;	    /* times scoreboard overflowed */
509181056Srpaulo
510181056Srpaulo	/* ECN related stats */
511249276Sglebius	uint64_t tcps_ecn_ce;		/* ECN Congestion Experienced */
512249276Sglebius	uint64_t tcps_ecn_ect0;		/* ECN Capable Transport */
513249276Sglebius	uint64_t tcps_ecn_ect1;		/* ECN Capable Transport */
514249276Sglebius	uint64_t tcps_ecn_shs;		/* ECN successful handshakes */
515249276Sglebius	uint64_t tcps_ecn_rcwnd;	/* # times ECN reduced the cwnd */
516195634Slstewart
517221023Sattilio	/* TCP_SIGNATURE related stats */
518249276Sglebius	uint64_t tcps_sig_rcvgoodsig;	/* Total matching signature received */
519249276Sglebius	uint64_t tcps_sig_rcvbadsig;	/* Total bad signature received */
520249276Sglebius	uint64_t tcps_sig_err_buildsig;	/* Mismatching signature received */
521249276Sglebius	uint64_t tcps_sig_err_sigopt;	/* No signature expected by socket */
522249276Sglebius	uint64_t tcps_sig_err_nosigopt;	/* No signature provided by segment */
523221023Sattilio
524249276Sglebius	uint64_t _pad[12];		/* 6 UTO, 6 TBD */
5251541Srgrimes};
5261541Srgrimes
527190978Srwatson#ifdef _KERNEL
528249276Sglebius#include <sys/counter.h>
529249276Sglebius
530253083SaeVNET_PCPUSTAT_DECLARE(struct tcpstat, tcpstat);	/* tcp statistics */
531196039Srwatson/*
532196039Srwatson * In-kernel consumers can use these accessor macros directly to update
533196039Srwatson * stats.
534196039Srwatson */
535253083Sae#define	TCPSTAT_ADD(name, val)	\
536253083Sae    VNET_PCPUSTAT_ADD(struct tcpstat, tcpstat, name, (val))
537190948Srwatson#define	TCPSTAT_INC(name)	TCPSTAT_ADD(name, 1)
538196039Srwatson
539196039Srwatson/*
540196039Srwatson * Kernel module consumers must use this accessor macro.
541196039Srwatson */
542196039Srwatsonvoid	kmod_tcpstat_inc(int statnum);
543196039Srwatson#define	KMOD_TCPSTAT_INC(name)						\
544253083Sae    kmod_tcpstat_inc(offsetof(struct tcpstat, name) / sizeof(uint64_t))
545216758Slstewart
546216758Slstewart/*
547216758Slstewart * TCP specific helper hook point identifiers.
548216758Slstewart */
549216758Slstewart#define	HHOOK_TCP_EST_IN		0
550216758Slstewart#define	HHOOK_TCP_EST_OUT		1
551216758Slstewart#define	HHOOK_TCP_LAST			HHOOK_TCP_EST_OUT
552216758Slstewart
553216758Slstewartstruct tcp_hhook_data {
554217252Slstewart	struct tcpcb	*tp;
555217252Slstewart	struct tcphdr	*th;
556217252Slstewart	struct tcpopt	*to;
557217252Slstewart	long		len;
558217252Slstewart	int		tso;
559217252Slstewart	tcp_seq		curack;
560216758Slstewart};
561190978Srwatson#endif
562190948Srwatson
5636247Swollman/*
56436079Swollman * TCB structure exported to user-land via sysctl(3).
56537183Sjhay * Evil hack: declare only if in_pcb.h and sys/socketvar.h have been
56637183Sjhay * included.  Not all of our clients do.
56736079Swollman */
56837183Sjhay#if defined(_NETINET_IN_PCB_H_) && defined(_SYS_SOCKETVAR_H_)
569197244Ssilbystruct xtcp_timer {
570197244Ssilby	int tt_rexmt;	/* retransmit timer */
571197244Ssilby	int tt_persist;	/* retransmit persistence */
572197244Ssilby	int tt_keep;	/* keepalive */
573197244Ssilby	int tt_2msl;	/* 2*msl TIME_WAIT timer */
574197244Ssilby	int tt_delack;	/* delayed ACK timer */
575217126Sjhb	int t_rcvtime;	/* Time since last packet received */
576197244Ssilby};
57736079Swollmanstruct	xtcpcb {
57836079Swollman	size_t	xt_len;
57936079Swollman	struct	inpcb	xt_inp;
58036079Swollman	struct	tcpcb	xt_tp;
58136079Swollman	struct	xsocket	xt_socket;
582197244Ssilby	struct	xtcp_timer xt_timer;
58336079Swollman	u_quad_t	xt_alignment_hack;
58436079Swollman};
58536079Swollman#endif
58636079Swollman
58736079Swollman/*
5886247Swollman * Names for TCP sysctl objects
5896247Swollman */
5906247Swollman#define	TCPCTL_DO_RFC1323	1	/* use RFC-1323 extensions */
5916247Swollman#define	TCPCTL_MSSDFLT		3	/* MSS default */
5926472Swollman#define TCPCTL_STATS		4	/* statistics (read-only) */
5936472Swollman#define	TCPCTL_RTTDFLT		5	/* default RTT estimate */
5946472Swollman#define	TCPCTL_KEEPIDLE		6	/* keepalive idle timer */
5956472Swollman#define	TCPCTL_KEEPINTVL	7	/* interval to send keepalives */
59618281Spst#define	TCPCTL_SENDSPACE	8	/* send buffer space */
59718281Spst#define	TCPCTL_RECVSPACE	9	/* receive buffer space */
59863431Ssheldonh#define	TCPCTL_KEEPINIT		10	/* timeout for establishing syn */
59936079Swollman#define	TCPCTL_PCBLIST		11	/* list of all outstanding PCBs */
60050673Sjlemon#define	TCPCTL_DELACKTIME	12	/* time before sending delayed ACK */
60152904Sshin#define	TCPCTL_V6MSSDFLT	13	/* MSS default for IPv6 */
602130989Sps#define	TCPCTL_SACK		14	/* Selective Acknowledgement,rfc 2018 */
603141381Smaxim#define	TCPCTL_DROP		15	/* drop tcp connection */
604141381Smaxim#define	TCPCTL_MAXID		16
605167036Smohans#define TCPCTL_FINWAIT2_TIMEOUT        17
6066247Swollman
60755205Speter#ifdef _KERNEL
60844078Sdfr#ifdef SYSCTL_DECL
60944078SdfrSYSCTL_DECL(_net_inet_tcp);
610136151SpsSYSCTL_DECL(_net_inet_tcp_sack);
611169683SandreMALLOC_DECLARE(M_TCPLOG);
61244078Sdfr#endif
61344078Sdfr
614195699SrwatsonVNET_DECLARE(struct inpcbhead, tcb);		/* queue of active tcpcb's */
615195699SrwatsonVNET_DECLARE(struct inpcbinfo, tcbinfo);
616207369Sbzextern	int tcp_log_in_vain;
617195699SrwatsonVNET_DECLARE(int, tcp_mssdflt);	/* XXX */
618195699SrwatsonVNET_DECLARE(int, tcp_minmss);
619195699SrwatsonVNET_DECLARE(int, tcp_delack_enabled);
620211464SandreVNET_DECLARE(int, tcp_do_rfc3390);
621242266SandreVNET_DECLARE(int, tcp_do_initcwnd10);
622226437SandreVNET_DECLARE(int, tcp_sendspace);
623226437SandreVNET_DECLARE(int, tcp_recvspace);
624195699SrwatsonVNET_DECLARE(int, path_mtu_discovery);
625215166SlstewartVNET_DECLARE(int, tcp_do_rfc3465);
626215166SlstewartVNET_DECLARE(int, tcp_abc_l_var);
627195727Srwatson#define	V_tcb			VNET(tcb)
628195727Srwatson#define	V_tcbinfo		VNET(tcbinfo)
629195727Srwatson#define	V_tcp_mssdflt		VNET(tcp_mssdflt)
630195727Srwatson#define	V_tcp_minmss		VNET(tcp_minmss)
631195727Srwatson#define	V_tcp_delack_enabled	VNET(tcp_delack_enabled)
632211464Sandre#define	V_tcp_do_rfc3390	VNET(tcp_do_rfc3390)
633242266Sandre#define	V_tcp_do_initcwnd10	VNET(tcp_do_initcwnd10)
634226437Sandre#define	V_tcp_sendspace		VNET(tcp_sendspace)
635226437Sandre#define	V_tcp_recvspace		VNET(tcp_recvspace)
636195727Srwatson#define	V_path_mtu_discovery	VNET(path_mtu_discovery)
637215166Slstewart#define	V_tcp_do_rfc3465	VNET(tcp_do_rfc3465)
638215166Slstewart#define	V_tcp_abc_l_var		VNET(tcp_abc_l_var)
639185088Szec
640195699SrwatsonVNET_DECLARE(int, tcp_do_sack);			/* SACK enabled/disabled */
641195699SrwatsonVNET_DECLARE(int, tcp_sc_rst_sock_fail);	/* RST on sock alloc failure */
642207369Sbz#define	V_tcp_do_sack		VNET(tcp_do_sack)
643207369Sbz#define	V_tcp_sc_rst_sock_fail	VNET(tcp_sc_rst_sock_fail)
644207369Sbz
645195699SrwatsonVNET_DECLARE(int, tcp_do_ecn);			/* TCP ECN enabled/disabled */
646195699SrwatsonVNET_DECLARE(int, tcp_ecn_maxretries);
647195727Srwatson#define	V_tcp_do_ecn		VNET(tcp_do_ecn)
648195727Srwatson#define	V_tcp_ecn_maxretries	VNET(tcp_ecn_maxretries)
649195699Srwatson
650217252SlstewartVNET_DECLARE(struct hhook_head *, tcp_hhh[HHOOK_TCP_LAST + 1]);
651216758Slstewart#define	V_tcp_hhh		VNET(tcp_hhh)
652216758Slstewart
653167606Sandreint	 tcp_addoptions(struct tcpopt *, u_char *);
654215392Slstewartint	 tcp_ccalgounload(struct cc_algo *unload_algo);
6551541Srgrimesstruct tcpcb *
65692723Salfred	 tcp_close(struct tcpcb *);
657157376Srwatsonvoid	 tcp_discardcb(struct tcpcb *);
658111145Sjlemonvoid	 tcp_twstart(struct tcpcb *);
659162064Sglebius#if 0
660121850Ssilbyint	 tcp_twrecycleable(struct tcptw *tw);
661162064Sglebius#endif
662157376Srwatsonvoid	 tcp_twclose(struct tcptw *_tw, int _reuse);
66392723Salfredvoid	 tcp_ctlinput(int, struct sockaddr *, void *);
66492723Salfredint	 tcp_ctloutput(struct socket *, struct sockopt *);
6651541Srgrimesstruct tcpcb *
66692723Salfred	 tcp_drop(struct tcpcb *, int);
66792723Salfredvoid	 tcp_drain(void);
66892723Salfredvoid	 tcp_init(void);
669193731Szec#ifdef VIMAGE
670193731Szecvoid	 tcp_destroy(void);
671193731Szec#endif
672128452Ssilbyvoid	 tcp_fini(void *);
673217126Sjhbchar	*tcp_log_addrs(struct in_conninfo *, struct tcphdr *, void *,
674171229Speter	    const void *);
675211462Sandrechar	*tcp_log_vain(struct in_conninfo *, struct tcphdr *, void *,
676211462Sandre	    const void *);
677169541Sandreint	 tcp_reass(struct tcpcb *, struct tcphdr *, int *, struct mbuf *);
678126193Sandrevoid	 tcp_reass_init(void);
679213158Slstewartvoid	 tcp_reass_flush(struct tcpcb *);
680204838Sbz#ifdef VIMAGE
681204838Sbzvoid	 tcp_reass_destroy(void);
682204838Sbz#endif
68392723Salfredvoid	 tcp_input(struct mbuf *, int);
684251296Sandreu_long	 tcp_maxmtu(struct in_conninfo *, struct tcp_ifcap *);
685251296Sandreu_long	 tcp_maxmtu6(struct in_conninfo *, struct tcp_ifcap *);
686234342Sglebiusvoid	 tcp_mss_update(struct tcpcb *, int, int, struct hc_metrics_lite *,
687251296Sandre	    struct tcp_ifcap *);
68892723Salfredvoid	 tcp_mss(struct tcpcb *, int);
689122922Sandreint	 tcp_mssopt(struct in_conninfo *);
690133874Srwatsonstruct inpcb *
69198211Shsu	 tcp_drop_syn_sent(struct inpcb *, int);
69298211Shsustruct inpcb *
69398211Shsu	 tcp_mtudisc(struct inpcb *, int);
6941541Srgrimesstruct tcpcb *
69592723Salfred	 tcp_newtcpcb(struct inpcb *);
69692723Salfredint	 tcp_output(struct tcpcb *);
697254889Smarkjvoid	 tcp_state_change(struct tcpcb *, int);
69892723Salfredvoid	 tcp_respond(struct tcpcb *, void *,
69992723Salfred	    struct tcphdr *, struct mbuf *, tcp_seq, tcp_seq, int);
700169541Sandrevoid	 tcp_tw_init(void);
701193731Szec#ifdef VIMAGE
702193731Szecvoid	 tcp_tw_destroy(void);
703193731Szec#endif
704169541Sandrevoid	 tcp_tw_zone_change(void);
705169608Sandreint	 tcp_twcheck(struct inpcb *, struct tcpopt *, struct tcphdr *,
706169608Sandre	    struct mbuf *, int);
70792723Salfredvoid	 tcp_setpersist(struct tcpcb *);
708125783Sbms#ifdef TCP_SIGNATURE
709125783Sbmsint	 tcp_signature_compute(struct mbuf *, int, int, int, u_char *, u_int);
710221023Sattilioint	 tcp_signature_verify(struct mbuf *, int, int, int, struct tcpopt *,
711221023Sattilio	    struct tcphdr *, u_int);
712125783Sbms#endif
71392723Salfredvoid	 tcp_slowtimo(void);
71455679Sshinstruct tcptemp *
715111144Sjlemon	 tcpip_maketemplate(struct inpcb *);
716111144Sjlemonvoid	 tcpip_fillheaders(struct inpcb *, void *, void *);
717168615Sandrevoid	 tcp_timer_activate(struct tcpcb *, int, u_int);
718168615Sandreint	 tcp_timer_active(struct tcpcb *, int);
719169272Srwatsonvoid	 tcp_trace(short, short, struct tcpcb *, void *, struct tcphdr *, int);
720122922Sandre/*
721122922Sandre * All tcp_hc_* functions are IPv4 and IPv6 (via in_conninfo)
722122922Sandre */
723122922Sandrevoid	 tcp_hc_init(void);
724193731Szec#ifdef VIMAGE
725193731Szecvoid	 tcp_hc_destroy(void);
726193731Szec#endif
727122922Sandrevoid	 tcp_hc_get(struct in_conninfo *, struct hc_metrics_lite *);
728122922Sandreu_long	 tcp_hc_getmtu(struct in_conninfo *);
729122922Sandrevoid	 tcp_hc_updatemtu(struct in_conninfo *, u_long);
730122922Sandrevoid	 tcp_hc_update(struct in_conninfo *, struct hc_metrics_lite *);
7319470Swollman
73217096Swollmanextern	struct pr_usrreqs tcp_usrreqs;
73392723Salfredtcp_seq tcp_new_isn(struct tcpcb *);
7349470Swollman
735147637Spsvoid	 tcp_sack_doack(struct tcpcb *, struct tcpopt *, tcp_seq);
736142031Spsvoid	 tcp_update_sack_list(struct tcpcb *tp, tcp_seq rcv_laststart, tcp_seq rcv_lastend);
737130989Spsvoid	 tcp_clean_sackreport(struct tcpcb *tp);
738130989Spsvoid	 tcp_sack_adjust(struct tcpcb *tp);
739136151Spsstruct sackhole *tcp_sack_output(struct tcpcb *tp, int *sack_bytes_rexmt);
740130989Spsvoid	 tcp_sack_partialack(struct tcpcb *, struct tcphdr *);
741130989Spsvoid	 tcp_free_sackholes(struct tcpcb *tp);
742130989Spsint	 tcp_newreno(struct tcpcb *, struct tcphdr *);
743130989Spsu_long	 tcp_seq_subtract(u_long, u_long );
744130989Sps
745215166Slstewartvoid	cc_cong_signal(struct tcpcb *tp, struct tcphdr *th, uint32_t type);
746215166Slstewart
747270051Sbzstatic inline void
748270051Sbztcp_fields_to_host(struct tcphdr *th)
749270051Sbz{
750270051Sbz
751270051Sbz	th->th_seq = ntohl(th->th_seq);
752270051Sbz	th->th_ack = ntohl(th->th_ack);
753270051Sbz	th->th_win = ntohs(th->th_win);
754270051Sbz	th->th_urp = ntohs(th->th_urp);
755270051Sbz}
756270051Sbz
757270051Sbz#ifdef TCP_SIGNATURE
758270051Sbzstatic inline void
759270051Sbztcp_fields_to_net(struct tcphdr *th)
760270051Sbz{
761270051Sbz
762270051Sbz	th->th_seq = htonl(th->th_seq);
763270051Sbz	th->th_ack = htonl(th->th_ack);
764270051Sbz	th->th_win = htons(th->th_win);
765270051Sbz	th->th_urp = htons(th->th_urp);
766270051Sbz}
767270051Sbz#endif
76855205Speter#endif /* _KERNEL */
7692169Spaul
7706348Swollman#endif /* _NETINET_TCP_VAR_H_ */
771