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 317375 2017-04-24 16:31:28Z smh $
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 */
76293709Shiren	int             sacked_bytes;	/*
77293709Shiren					 * Total sacked bytes reported by the
78293709Shiren					 * receiver via sack option
79293709Shiren					 */
80293709Shiren	uint32_t	_pad1[1];	/* TBD */
81293709Shiren	uint64_t	_pad[1];	/* TBD */
82146123Sps};
83146123Sps
8455679Sshinstruct tcptemp {
8555679Sshin	u_char	tt_ipgen[40]; /* the size must be of max ip header, now IPv6 */
8655679Sshin	struct	tcphdr tt_t;
8755679Sshin};
8855679Sshin
8955679Sshin#define tcp6cb		tcpcb  /* for KAME src sync over BSD*'s */
9055679Sshin
91169541Sandre/* Neighbor Discovery, Neighbor Unreachability Detection Upper layer hint. */
92169541Sandre#ifdef INET6
93169541Sandre#define ND6_HINT(tp)						\
94169541Sandredo {								\
95169541Sandre	if ((tp) && (tp)->t_inpcb &&				\
96169541Sandre	    ((tp)->t_inpcb->inp_vflag & INP_IPV6) != 0)		\
97169541Sandre		nd6_nud_hint(NULL, NULL, 0);			\
98169541Sandre} while (0)
99169541Sandre#else
100169541Sandre#define ND6_HINT(tp)
101169541Sandre#endif
102169541Sandre
1031541Srgrimes/*
1041541Srgrimes * Tcp control block, one per tcp; fields:
10532821Sdg * Organized for 16 byte cacheline efficiency.
1061541Srgrimes */
1071541Srgrimesstruct tcpcb {
108126193Sandre	struct	tsegqe_head t_segq;	/* segment reassembly queue */
109195634Slstewart	void	*t_pspare[2];		/* new reassembly queue */
110126193Sandre	int	t_segqlen;		/* segment reassembly queue length */
11132821Sdg	int	t_dupacks;		/* consecutive dup acks recd */
11232821Sdg
113172309Ssilby	struct tcp_timer *t_timers;	/* All the TCP timers in one struct */
11432821Sdg
11532821Sdg	struct	inpcb *t_inpcb;		/* back pointer to internet pcb */
11611187Swollman	int	t_state;		/* state of this connection */
11711187Swollman	u_int	t_flags;
1181541Srgrimes
119191688Szec	struct	vnet *t_vnet;		/* back pointer to parent vnet */
120191688Szec
1211541Srgrimes	tcp_seq	snd_una;		/* send unacknowledged */
12232821Sdg	tcp_seq	snd_max;		/* highest sequence number sent;
12332821Sdg					 * used to recognize retransmits
12432821Sdg					 */
1251541Srgrimes	tcp_seq	snd_nxt;		/* send next */
1261541Srgrimes	tcp_seq	snd_up;			/* send urgent pointer */
12732821Sdg
1281541Srgrimes	tcp_seq	snd_wl1;		/* window update seg seq number */
1291541Srgrimes	tcp_seq	snd_wl2;		/* window update seg ack number */
1301541Srgrimes	tcp_seq	iss;			/* initial send sequence number */
13132821Sdg	tcp_seq	irs;			/* initial receive sequence number */
13232821Sdg
13332821Sdg	tcp_seq	rcv_nxt;		/* receive next */
13432821Sdg	tcp_seq	rcv_adv;		/* advertised window */
1351541Srgrimes	u_long	rcv_wnd;		/* receive window */
1361541Srgrimes	tcp_seq	rcv_up;			/* receive urgent pointer */
13732821Sdg
13832821Sdg	u_long	snd_wnd;		/* send window */
1391541Srgrimes	u_long	snd_cwnd;		/* congestion-controlled window */
140212765Sandre	u_long	snd_spare1;		/* unused */
14113765Smpp	u_long	snd_ssthresh;		/* snd_cwnd size threshold for
1421541Srgrimes					 * for slow start exponential to
1431541Srgrimes					 * linear switch
1441541Srgrimes					 */
145212765Sandre	u_long	snd_spare2;		/* unused */
146109175Shsu	tcp_seq	snd_recover;		/* for use in NewReno Fast Recovery */
14760067Sjlemon
14832821Sdg	u_int	t_maxopd;		/* mss plus options */
14932821Sdg
150194303Sjhb	u_int	t_rcvtime;		/* inactivity time */
151194303Sjhb	u_int	t_starttime;		/* time connection was established */
152194303Sjhb	u_int	t_rtttime;		/* RTT measurement start time */
1531541Srgrimes	tcp_seq	t_rtseq;		/* sequence number being timed */
15432821Sdg
155212765Sandre	u_int	t_bw_spare1;		/* unused */
156212765Sandre	tcp_seq	t_bw_spare2;		/* unused */
157102017Sdillon
15850673Sjlemon	int	t_rxtcur;		/* current retransmit value (ticks) */
15932821Sdg	u_int	t_maxseg;		/* maximum segment size */
16011187Swollman	int	t_srtt;			/* smoothed round-trip time */
16111187Swollman	int	t_rttvar;		/* variance in round-trip time */
16232821Sdg
16332821Sdg	int	t_rxtshift;		/* log(2) of rexmt exp. backoff */
16411187Swollman	u_int	t_rttmin;		/* minimum rtt allowed */
165102017Sdillon	u_int	t_rttbest;		/* best rtt we've seen */
16632821Sdg	u_long	t_rttupdated;		/* number of times rtt sampled */
1671541Srgrimes	u_long	max_sndwnd;		/* largest window peer has offered */
1681541Srgrimes
16932821Sdg	int	t_softerror;		/* possible error not yet reported */
1701541Srgrimes/* out-of-band data */
1711541Srgrimes	char	t_oobflags;		/* have some */
1721541Srgrimes	char	t_iobc;			/* input character */
1731541Srgrimes/* RFC 1323 variables */
1741541Srgrimes	u_char	snd_scale;		/* window scaling for send window */
1751541Srgrimes	u_char	rcv_scale;		/* window scaling for recv window */
1761541Srgrimes	u_char	request_r_scale;	/* pending window scaling */
177162277Sandre	u_int32_t  ts_recent;		/* timestamp echo data */
178194303Sjhb	u_int	ts_recent_age;		/* when last updated */
179162277Sandre	u_int32_t  ts_offset;		/* our timestamp offset */
18032821Sdg
1811541Srgrimes	tcp_seq	last_ack_sent;
18250673Sjlemon/* experimental */
18350673Sjlemon	u_long	snd_cwnd_prev;		/* cwnd prior to retransmit */
18450673Sjlemon	u_long	snd_ssthresh_prev;	/* ssthresh prior to retransmit */
185117650Shsu	tcp_seq	snd_recover_prev;	/* snd_recover prior to retransmit */
186215434Sgnn	int	t_sndzerowin;		/* zero-window updates sent */
187194303Sjhb	u_int	t_badrxtwin;		/* window for retransmit recovery */
188112957Shsu	u_char	snd_limited;		/* segments limited transmitted */
189131078Sbms/* SACK related state */
190130989Sps	int	snd_numholes;		/* number of holes seen by sender */
191146953Sps	TAILQ_HEAD(sackhole_head, sackhole) snd_holes;
192146953Sps					/* SACK scoreboard (sorted) */
193146630Sps	tcp_seq	snd_fack;		/* last seq number(+1) sack'd by rcv'r*/
194130989Sps	int	rcv_numsacks;		/* # distinct sack blks present */
195130989Sps	struct sackblk sackblks[MAX_SACK_BLKS]; /* seq nos. of sack blocks */
196136151Sps	tcp_seq sack_newdata;		/* New data xmitted in this recovery
197136151Sps					   episode starts at this seq number */
198146123Sps	struct sackhint	sackhint;	/* SACK scoreboard hint */
199155767Sandre	int	t_rttlow;		/* smallest observerved RTT */
200166405Sandre	u_int32_t	rfbuf_ts;	/* recv buffer autoscaling timestamp */
201166405Sandre	int	rfbuf_cnt;		/* recv buffer autoscaling byte count */
202237263Snp	struct toedev	*tod;		/* toedev handling this connection */
203215434Sgnn	int	t_sndrexmitpack;	/* retransmit packets sent */
204215434Sgnn	int	t_rcvoopack;		/* out-of-order packets received */
205174560Skmacy	void	*t_toe;			/* TOE pcb pointer */
206187289Slstewart	int	t_bytes_acked;		/* # bytes acked during current RTT */
207215166Slstewart	struct cc_algo	*cc_algo;	/* congestion control algorithm */
208216760Slstewart	struct cc_var	*ccv;		/* congestion control specific vars */
209216758Slstewart	struct osd	*osd;		/* storage for Khelp module data */
210195634Slstewart
211231025Sglebius	u_int	t_keepinit;		/* time to establish connection */
212231025Sglebius	u_int	t_keepidle;		/* time before keepalive probes begin */
213231025Sglebius	u_int	t_keepintvl;		/* interval between keepalives */
214231025Sglebius	u_int	t_keepcnt;		/* number of keepalives before close */
215231025Sglebius
216274043Shselasky	u_int	t_tsomax;		/* TSO total burst length limit in bytes */
217273838Ssbruno	u_int	t_pmtud_saved_maxopd;	/* pre-blackhole MSS */
218273838Ssbruno	u_int	t_flags2;		/* More tcpcb flags storage */
219251296Sandre
220273838Ssbruno	uint32_t t_ispare[6];		/* 5 UTO, 1 TBD */
221292823Spkelsey#if defined(_KERNEL) && defined(TCP_RFC7413)
222292823Spkelsey	void	*t_pspare2[3];		/* 1 TCP_SIGNATURE, 2 TBD */
223292823Spkelsey	unsigned int *t_tfo_pending;	/* TCP Fast Open pending counter */
224292823Spkelsey#else
225255759Sbz	void	*t_pspare2[4];		/* 1 TCP_SIGNATURE, 3 TBD */
226292823Spkelsey#endif
227292823Spkelsey#if defined(_KERNEL) && defined(TCP_RFC7413)
228292823Spkelsey	uint64_t _pad[4];		/* 4 TBD (1-2 CC/RTT?) */
229292823Spkelsey	uint64_t t_tfo_cookie;		/* TCP Fast Open cookie */
230292823Spkelsey#else
231274043Shselasky	uint64_t _pad[5];		/* 5 TBD (1-2 CC/RTT?) */
232292823Spkelsey#endif
233274043Shselasky	uint32_t t_tsomaxsegcount;	/* TSO maximum segment count */
234274043Shselasky	uint32_t t_tsomaxsegsize;	/* TSO maximum segment size in bytes */
2351541Srgrimes};
2361541Srgrimes
237185855Srwatson/*
238185855Srwatson * Flags and utility macros for the t_flags field.
239185855Srwatson */
240185855Srwatson#define	TF_ACKNOW	0x000001	/* ack peer immediately */
241185855Srwatson#define	TF_DELACK	0x000002	/* ack, but try to delay it */
242185855Srwatson#define	TF_NODELAY	0x000004	/* don't delay packets to coalesce */
243185855Srwatson#define	TF_NOOPT	0x000008	/* don't use tcp options */
244185855Srwatson#define	TF_SENTFIN	0x000010	/* have sent FIN */
245185855Srwatson#define	TF_REQ_SCALE	0x000020	/* have/will request window scaling */
246185855Srwatson#define	TF_RCVD_SCALE	0x000040	/* other side has requested scaling */
247185855Srwatson#define	TF_REQ_TSTMP	0x000080	/* have/will request timestamps */
248185855Srwatson#define	TF_RCVD_TSTMP	0x000100	/* a timestamp was received in SYN */
249185855Srwatson#define	TF_SACK_PERMIT	0x000200	/* other side said I could SACK */
250185855Srwatson#define	TF_NEEDSYN	0x000400	/* send SYN (implicit state) */
251185855Srwatson#define	TF_NEEDFIN	0x000800	/* send FIN (implicit state) */
252185855Srwatson#define	TF_NOPUSH	0x001000	/* don't push */
253221209Sjhb#define	TF_PREVVALID	0x002000	/* saved values for bad rxmit valid */
254185855Srwatson#define	TF_MORETOCOME	0x010000	/* More data to be appended to sock */
255185855Srwatson#define	TF_LQ_OVERFLOW	0x020000	/* listen queue overflow */
256185855Srwatson#define	TF_LASTIDLE	0x040000	/* connection was previously idle */
257185855Srwatson#define	TF_RXWIN0SENT	0x080000	/* sent a receiver win 0 in response */
258185855Srwatson#define	TF_FASTRECOVERY	0x100000	/* in NewReno Fast Recovery */
259185855Srwatson#define	TF_WASFRECOVERY	0x200000	/* was in NewReno Fast Recovery */
260185855Srwatson#define	TF_SIGNATURE	0x400000	/* require MD5 digests (RFC2385) */
261185855Srwatson#define	TF_FORCEDATA	0x800000	/* force out a byte */
262185855Srwatson#define	TF_TSO		0x1000000	/* TSO enabled on this connection */
263185855Srwatson#define	TF_TOE		0x2000000	/* this connection is offloaded */
264185855Srwatson#define	TF_ECN_PERMIT	0x4000000	/* connection ECN-ready */
265185855Srwatson#define	TF_ECN_SND_CWR	0x8000000	/* ECN CWR in queue */
266185855Srwatson#define	TF_ECN_SND_ECE	0x10000000	/* ECN ECE in queue */
267215166Slstewart#define	TF_CONGRECOVERY	0x20000000	/* congestion recovery mode */
268215166Slstewart#define	TF_WASCRECOVERY	0x40000000	/* was in congestion recovery */
269292823Spkelsey#define	TF_FASTOPEN	0x80000000	/* TCP Fast Open indication */
270185855Srwatson
271215166Slstewart#define	IN_FASTRECOVERY(t_flags)	(t_flags & TF_FASTRECOVERY)
272215166Slstewart#define	ENTER_FASTRECOVERY(t_flags)	t_flags |= TF_FASTRECOVERY
273215166Slstewart#define	EXIT_FASTRECOVERY(t_flags)	t_flags &= ~TF_FASTRECOVERY
274117650Shsu
275215166Slstewart#define	IN_CONGRECOVERY(t_flags)	(t_flags & TF_CONGRECOVERY)
276215166Slstewart#define	ENTER_CONGRECOVERY(t_flags)	t_flags |= TF_CONGRECOVERY
277215166Slstewart#define	EXIT_CONGRECOVERY(t_flags)	t_flags &= ~TF_CONGRECOVERY
278215166Slstewart
279215166Slstewart#define	IN_RECOVERY(t_flags) (t_flags & (TF_CONGRECOVERY | TF_FASTRECOVERY))
280215166Slstewart#define	ENTER_RECOVERY(t_flags) t_flags |= (TF_CONGRECOVERY | TF_FASTRECOVERY)
281215166Slstewart#define	EXIT_RECOVERY(t_flags) t_flags &= ~(TF_CONGRECOVERY | TF_FASTRECOVERY)
282215166Slstewart
283215166Slstewart#define	BYTES_THIS_ACK(tp, th)	(th->th_ack - tp->snd_una)
284215166Slstewart
285185855Srwatson/*
286185855Srwatson * Flags for the t_oobflags field.
287185855Srwatson */
288185855Srwatson#define	TCPOOB_HAVEDATA	0x01
289185855Srwatson#define	TCPOOB_HADDATA	0x02
290185855Srwatson
291125680Sbms#ifdef TCP_SIGNATURE
2926247Swollman/*
293125680Sbms * Defines which are needed by the xform_tcp module and tcp_[in|out]put
294125680Sbms * for SADB verification and lookup.
295125680Sbms */
296125680Sbms#define	TCP_SIGLEN	16	/* length of computed digest in bytes */
297125680Sbms#define	TCP_KEYLEN_MIN	1	/* minimum length of TCP-MD5 key */
298125680Sbms#define	TCP_KEYLEN_MAX	80	/* maximum length of TCP-MD5 key */
299125680Sbms/*
300125680Sbms * Only a single SA per host may be specified at this time. An SPI is
301125680Sbms * needed in order for the KEY_ALLOCSA() lookup to work.
302125680Sbms */
303125680Sbms#define	TCP_SIG_SPI	0x1000
304125680Sbms#endif /* TCP_SIGNATURE */
305125680Sbms
306125680Sbms/*
307273838Ssbruno * Flags for PLPMTU handling, t_flags2
308273838Ssbruno */
309273838Ssbruno#define	TF2_PLPMTU_BLACKHOLE	0x00000001 /* Possible PLPMTUD Black Hole. */
310273838Ssbruno#define	TF2_PLPMTU_PMTUD	0x00000002 /* Allowed to attempt PLPMTUD. */
311273838Ssbruno#define	TF2_PLPMTU_MAXSEGSNT	0x00000004 /* Last seg sent was full seg. */
312273838Ssbruno
313273838Ssbruno/*
3146247Swollman * Structure to hold TCP options that are only used during segment
3156247Swollman * processing (in tcp_input), but not held in the tcpcb.
3166247Swollman * It's basically used to reduce the number of parameters
317167606Sandre * to tcp_dooptions and tcp_addoptions.
318167606Sandre * The binary order of the to_flags is relevant for packing of the
319167606Sandre * options in tcp_addoptions.
3206247Swollman */
3216247Swollmanstruct tcpopt {
322195654Slstewart	u_int64_t	to_flags;	/* which options are present */
323167606Sandre#define	TOF_MSS		0x0001		/* maximum segment size */
324167606Sandre#define	TOF_SCALE	0x0002		/* window scaling */
325178349Sbz#define	TOF_SACKPERM	0x0004		/* SACK permitted */
326167606Sandre#define	TOF_TS		0x0010		/* timestamp */
327178349Sbz#define	TOF_SIGNATURE	0x0040		/* TCP-MD5 signature option (RFC2385) */
328168906Sandre#define	TOF_SACK	0x0080		/* Peer sent SACK option */
329292823Spkelsey#define	TOF_FASTOPEN	0x0100		/* TCP Fast Open (TFO) cookie */
330292823Spkelsey#define	TOF_MAXOPT	0x0200
331168906Sandre	u_int32_t	to_tsval;	/* new timestamp */
332167606Sandre	u_int32_t	to_tsecr;	/* reflected timestamp */
333195654Slstewart	u_char		*to_sacks;	/* pointer to the first SACK blocks */
334195654Slstewart	u_char		*to_signature;	/* pointer to the TCP-MD5 signature */
335292823Spkelsey	u_char		*to_tfo_cookie; /* pointer to the TFO cookie */
336167606Sandre	u_int16_t	to_mss;		/* maximum segment size */
337167606Sandre	u_int8_t	to_wscale;	/* window scaling */
338147637Sps	u_int8_t	to_nsacks;	/* number of SACK blocks */
339292823Spkelsey	u_int8_t	to_tfo_len;	/* TFO cookie length */
340224151Sbz	u_int32_t	to_spare;	/* UTO */
3416247Swollman};
3426247Swollman
343159949Sandre/*
344159949Sandre * Flags for tcp_dooptions.
345159949Sandre */
346159949Sandre#define	TO_SYN		0x01		/* parse SYN-only options */
347159949Sandre
348122922Sandrestruct hc_metrics_lite {	/* must stay in sync with hc_metrics */
349122922Sandre	u_long	rmx_mtu;	/* MTU for this path */
350122922Sandre	u_long	rmx_ssthresh;	/* outbound gateway buffer limit */
351122922Sandre	u_long	rmx_rtt;	/* estimated round trip time */
352122922Sandre	u_long	rmx_rttvar;	/* estimated rtt variance */
353122922Sandre	u_long	rmx_bandwidth;	/* estimated bandwidth */
354122922Sandre	u_long	rmx_cwnd;	/* congestion window */
355122922Sandre	u_long	rmx_sendpipe;   /* outbound delay-bandwidth product */
356122922Sandre	u_long	rmx_recvpipe;   /* inbound delay-bandwidth product */
357122922Sandre};
358122922Sandre
359251296Sandre/*
360251296Sandre * Used by tcp_maxmtu() to communicate interface specific features
361251296Sandre * and limits at the time of connection setup.
362251296Sandre */
363251296Sandrestruct tcp_ifcap {
364251296Sandre	int	ifcap;
365251296Sandre	u_int	tsomax;
366274043Shselasky	u_int	tsomaxsegcount;
367274043Shselasky	u_int	tsomaxsegsize;
368251296Sandre};
369251296Sandre
370159725Sandre#ifndef _NETINET_IN_PCB_H_
371159725Sandrestruct in_conninfo;
372159725Sandre#endif /* _NETINET_IN_PCB_H_ */
373159725Sandre
374111145Sjlemonstruct tcptw {
375111145Sjlemon	struct inpcb	*tw_inpcb;	/* XXX back pointer to internet pcb */
376111145Sjlemon	tcp_seq		snd_nxt;
377111145Sjlemon	tcp_seq		rcv_nxt;
378121850Ssilby	tcp_seq		iss;
379121884Ssilby	tcp_seq		irs;
380111145Sjlemon	u_short		last_win;	/* cached window value */
381111145Sjlemon	u_short		tw_so_options;	/* copy of so_options */
382111145Sjlemon	struct ucred	*tw_cred;	/* user credentials */
383194303Sjhb	u_int32_t	t_recent;
384169477Sandre	u_int32_t	ts_offset;	/* our timestamp offset */
385194303Sjhb	u_int		t_starttime;
386112009Sjlemon	int		tw_time;
387162111Sru	TAILQ_ENTRY(tcptw) tw_2msl;
388255759Sbz	void		*tw_pspare;	/* TCP_SIGNATURE */
389255759Sbz	u_int		*tw_spare;	/* TCP_SIGNATURE */
390111145Sjlemon};
391133874Srwatson
3921541Srgrimes#define	intotcpcb(ip)	((struct tcpcb *)(ip)->inp_ppcb)
393111145Sjlemon#define	intotw(ip)	((struct tcptw *)(ip)->inp_ppcb)
3941541Srgrimes#define	sototcpcb(so)	(intotcpcb(sotoinpcb(so)))
3951541Srgrimes
3961541Srgrimes/*
3971541Srgrimes * The smoothed round-trip time and estimated variance
3981541Srgrimes * are stored as fixed point numbers scaled by the values below.
3991541Srgrimes * For convenience, these scales are also used in smoothing the average
4001541Srgrimes * (smoothed = (1/scale)sample + ((scale-1)/scale)smoothed).
4011541Srgrimes * With these scales, srtt has 3 bits to the right of the binary point,
4021541Srgrimes * and thus an "ALPHA" of 0.875.  rttvar has 2 bits to the right of the
4031541Srgrimes * binary point, and is smoothed with an ALPHA of 0.75.
4041541Srgrimes */
40514753Swollman#define	TCP_RTT_SCALE		32	/* multiplier for srtt; 3 bits frac. */
40614753Swollman#define	TCP_RTT_SHIFT		5	/* shift for srtt; 3 bits frac. */
40714753Swollman#define	TCP_RTTVAR_SCALE	16	/* multiplier for rttvar; 2 bits */
40814753Swollman#define	TCP_RTTVAR_SHIFT	4	/* shift for rttvar; 2 bits */
40914753Swollman#define	TCP_DELTA_SHIFT		2	/* see tcp_input.c */
4101541Srgrimes
4111541Srgrimes/*
4121541Srgrimes * The initial retransmission should happen at rtt + 4 * rttvar.
4131541Srgrimes * Because of the way we do the smoothing, srtt and rttvar
4141541Srgrimes * will each average +1/2 tick of bias.  When we compute
4151541Srgrimes * the retransmit timer, we want 1/2 tick of rounding and
4161541Srgrimes * 1 extra tick because of +-1/2 tick uncertainty in the
4171541Srgrimes * firing of the timer.  The bias will give us exactly the
4181541Srgrimes * 1.5 tick we need.  But, because the bias is
4191541Srgrimes * statistical, we have to test that we don't drop below
4201541Srgrimes * the minimum feasible timer (which is 2 ticks).
42114753Swollman * This version of the macro adapted from a paper by Lawrence
42214753Swollman * Brakmo and Larry Peterson which outlines a problem caused
42314753Swollman * by insufficient precision in the original implementation,
42414753Swollman * which results in inappropriately large RTO values for very
42514753Swollman * fast networks.
4261541Srgrimes */
4271541Srgrimes#define	TCP_REXMTVAL(tp) \
42835419Sdg	max((tp)->t_rttmin, (((tp)->t_srtt >> (TCP_RTT_SHIFT - TCP_DELTA_SHIFT))  \
42916141Swollman	  + (tp)->t_rttvar) >> TCP_DELTA_SHIFT)
4301541Srgrimes
4311541Srgrimes/*
4321541Srgrimes * TCP statistics.
4331541Srgrimes * Many of these should be kept per connection,
4341541Srgrimes * but that's inconvenient at the moment.
4351541Srgrimes */
4361541Srgrimesstruct	tcpstat {
437249276Sglebius	uint64_t tcps_connattempt;	/* connections initiated */
438249276Sglebius	uint64_t tcps_accepts;		/* connections accepted */
439249276Sglebius	uint64_t tcps_connects;		/* connections established */
440249276Sglebius	uint64_t tcps_drops;		/* connections dropped */
441249276Sglebius	uint64_t tcps_conndrops;	/* embryonic connections dropped */
442249276Sglebius	uint64_t tcps_minmssdrops;	/* average minmss too low drops */
443249276Sglebius	uint64_t tcps_closed;		/* conn. closed (includes drops) */
444249276Sglebius	uint64_t tcps_segstimed;	/* segs where we tried to get rtt */
445249276Sglebius	uint64_t tcps_rttupdated;	/* times we succeeded */
446249276Sglebius	uint64_t tcps_delack;		/* delayed acks sent */
447249276Sglebius	uint64_t tcps_timeoutdrop;	/* conn. dropped in rxmt timeout */
448249276Sglebius	uint64_t tcps_rexmttimeo;	/* retransmit timeouts */
449249276Sglebius	uint64_t tcps_persisttimeo;	/* persist timeouts */
450249276Sglebius	uint64_t tcps_keeptimeo;	/* keepalive timeouts */
451249276Sglebius	uint64_t tcps_keepprobe;	/* keepalive probes sent */
452249276Sglebius	uint64_t tcps_keepdrops;	/* connections dropped in keepalive */
4531541Srgrimes
454249276Sglebius	uint64_t tcps_sndtotal;		/* total packets sent */
455249276Sglebius	uint64_t tcps_sndpack;		/* data packets sent */
456249276Sglebius	uint64_t tcps_sndbyte;		/* data bytes sent */
457249276Sglebius	uint64_t tcps_sndrexmitpack;	/* data packets retransmitted */
458249276Sglebius	uint64_t tcps_sndrexmitbyte;	/* data bytes retransmitted */
459249276Sglebius	uint64_t tcps_sndrexmitbad;	/* unnecessary packet retransmissions */
460249276Sglebius	uint64_t tcps_sndacks;		/* ack-only packets sent */
461249276Sglebius	uint64_t tcps_sndprobe;		/* window probes sent */
462249276Sglebius	uint64_t tcps_sndurg;		/* packets sent with URG only */
463249276Sglebius	uint64_t tcps_sndwinup;		/* window update-only packets sent */
464249276Sglebius	uint64_t tcps_sndctrl;		/* control (SYN|FIN|RST) packets sent */
4651541Srgrimes
466249276Sglebius	uint64_t tcps_rcvtotal;		/* total packets received */
467249276Sglebius	uint64_t tcps_rcvpack;		/* packets received in sequence */
468249276Sglebius	uint64_t tcps_rcvbyte;		/* bytes received in sequence */
469249276Sglebius	uint64_t tcps_rcvbadsum;	/* packets received with ccksum errs */
470249276Sglebius	uint64_t tcps_rcvbadoff;	/* packets received with bad offset */
471249276Sglebius	uint64_t tcps_rcvmemdrop;	/* packets dropped for lack of memory */
472249276Sglebius	uint64_t tcps_rcvshort;		/* packets received too short */
473249276Sglebius	uint64_t tcps_rcvduppack;	/* duplicate-only packets received */
474249276Sglebius	uint64_t tcps_rcvdupbyte;	/* duplicate-only bytes received */
475249276Sglebius	uint64_t tcps_rcvpartduppack;	/* packets with some duplicate data */
476249276Sglebius	uint64_t tcps_rcvpartdupbyte;	/* dup. bytes in part-dup. packets */
477249276Sglebius	uint64_t tcps_rcvoopack;	/* out-of-order packets received */
478249276Sglebius	uint64_t tcps_rcvoobyte;	/* out-of-order bytes received */
479249276Sglebius	uint64_t tcps_rcvpackafterwin;	/* packets with data after window */
480249276Sglebius	uint64_t tcps_rcvbyteafterwin;	/* bytes rcvd after window */
481249276Sglebius	uint64_t tcps_rcvafterclose;	/* packets rcvd after "close" */
482249276Sglebius	uint64_t tcps_rcvwinprobe;	/* rcvd window probe packets */
483249276Sglebius	uint64_t tcps_rcvdupack;	/* rcvd duplicate acks */
484249276Sglebius	uint64_t tcps_rcvacktoomuch;	/* rcvd acks for unsent data */
485249276Sglebius	uint64_t tcps_rcvackpack;	/* rcvd ack packets */
486249276Sglebius	uint64_t tcps_rcvackbyte;	/* bytes acked by rcvd acks */
487249276Sglebius	uint64_t tcps_rcvwinupd;	/* rcvd window update packets */
488249276Sglebius	uint64_t tcps_pawsdrop;		/* segments dropped due to PAWS */
489249276Sglebius	uint64_t tcps_predack;		/* times hdr predict ok for acks */
490249276Sglebius	uint64_t tcps_preddat;		/* times hdr predict ok for data pkts */
491249276Sglebius	uint64_t tcps_pcbcachemiss;
492249276Sglebius	uint64_t tcps_cachedrtt;	/* times cached RTT in route updated */
493249276Sglebius	uint64_t tcps_cachedrttvar;	/* times cached rttvar updated */
494249276Sglebius	uint64_t tcps_cachedssthresh;	/* times cached ssthresh updated */
495249276Sglebius	uint64_t tcps_usedrtt;		/* times RTT initialized from route */
496249276Sglebius	uint64_t tcps_usedrttvar;	/* times RTTVAR initialized from rt */
497249276Sglebius	uint64_t tcps_usedssthresh;	/* times ssthresh initialized from rt*/
498249276Sglebius	uint64_t tcps_persistdrop;	/* timeout in persist state */
499249276Sglebius	uint64_t tcps_badsyn;		/* bogus SYN, e.g. premature ACK */
500249276Sglebius	uint64_t tcps_mturesent;	/* resends due to MTU discovery */
501249276Sglebius	uint64_t tcps_listendrop;	/* listen queue overflows */
502249276Sglebius	uint64_t tcps_badrst;		/* ignored RSTs in the window */
50386764Sjlemon
504249276Sglebius	uint64_t tcps_sc_added;		/* entry added to syncache */
505249276Sglebius	uint64_t tcps_sc_retransmitted;	/* syncache entry was retransmitted */
506249276Sglebius	uint64_t tcps_sc_dupsyn;	/* duplicate SYN packet */
507249276Sglebius	uint64_t tcps_sc_dropped;	/* could not reply to packet */
508249276Sglebius	uint64_t tcps_sc_completed;	/* successful extraction of entry */
509249276Sglebius	uint64_t tcps_sc_bucketoverflow;/* syncache per-bucket limit hit */
510249276Sglebius	uint64_t tcps_sc_cacheoverflow;	/* syncache cache limit hit */
511249276Sglebius	uint64_t tcps_sc_reset;		/* RST removed entry from syncache */
512249276Sglebius	uint64_t tcps_sc_stale;		/* timed out or listen socket gone */
513249276Sglebius	uint64_t tcps_sc_aborted;	/* syncache entry aborted */
514249276Sglebius	uint64_t tcps_sc_badack;	/* removed due to bad ACK */
515249276Sglebius	uint64_t tcps_sc_unreach;	/* ICMP unreachable received */
516249276Sglebius	uint64_t tcps_sc_zonefail;	/* zalloc() failed */
517249276Sglebius	uint64_t tcps_sc_sendcookie;	/* SYN cookie sent */
518249276Sglebius	uint64_t tcps_sc_recvcookie;	/* SYN cookie received */
519122922Sandre
520249276Sglebius	uint64_t tcps_hc_added;		/* entry added to hostcache */
521249276Sglebius	uint64_t tcps_hc_bucketoverflow;/* hostcache per bucket limit hit */
522130989Sps
523249276Sglebius	uint64_t tcps_finwait2_drops;    /* Drop FIN_WAIT_2 connection after time limit */
524167036Smohans
525130989Sps	/* SACK related stats */
526249276Sglebius	uint64_t tcps_sack_recovery_episode; /* SACK recovery episodes */
527249276Sglebius	uint64_t tcps_sack_rexmits;	    /* SACK rexmit segments   */
528249276Sglebius	uint64_t tcps_sack_rexmit_bytes;    /* SACK rexmit bytes      */
529249276Sglebius	uint64_t tcps_sack_rcv_blocks;	    /* SACK blocks (options) received */
530249276Sglebius	uint64_t tcps_sack_send_blocks;	    /* SACK blocks (options) sent     */
531249276Sglebius	uint64_t tcps_sack_sboverflow;	    /* times scoreboard overflowed */
532181056Srpaulo
533181056Srpaulo	/* ECN related stats */
534249276Sglebius	uint64_t tcps_ecn_ce;		/* ECN Congestion Experienced */
535249276Sglebius	uint64_t tcps_ecn_ect0;		/* ECN Capable Transport */
536249276Sglebius	uint64_t tcps_ecn_ect1;		/* ECN Capable Transport */
537249276Sglebius	uint64_t tcps_ecn_shs;		/* ECN successful handshakes */
538249276Sglebius	uint64_t tcps_ecn_rcwnd;	/* # times ECN reduced the cwnd */
539195634Slstewart
540221023Sattilio	/* TCP_SIGNATURE related stats */
541249276Sglebius	uint64_t tcps_sig_rcvgoodsig;	/* Total matching signature received */
542249276Sglebius	uint64_t tcps_sig_rcvbadsig;	/* Total bad signature received */
543249276Sglebius	uint64_t tcps_sig_err_buildsig;	/* Mismatching signature received */
544249276Sglebius	uint64_t tcps_sig_err_sigopt;	/* No signature expected by socket */
545249276Sglebius	uint64_t tcps_sig_err_nosigopt;	/* No signature provided by segment */
546221023Sattilio
547249276Sglebius	uint64_t _pad[12];		/* 6 UTO, 6 TBD */
5481541Srgrimes};
5491541Srgrimes
550190978Srwatson#ifdef _KERNEL
551249276Sglebius#include <sys/counter.h>
552249276Sglebius
553253083SaeVNET_PCPUSTAT_DECLARE(struct tcpstat, tcpstat);	/* tcp statistics */
554196039Srwatson/*
555196039Srwatson * In-kernel consumers can use these accessor macros directly to update
556196039Srwatson * stats.
557196039Srwatson */
558253083Sae#define	TCPSTAT_ADD(name, val)	\
559253083Sae    VNET_PCPUSTAT_ADD(struct tcpstat, tcpstat, name, (val))
560190948Srwatson#define	TCPSTAT_INC(name)	TCPSTAT_ADD(name, 1)
561196039Srwatson
562196039Srwatson/*
563196039Srwatson * Kernel module consumers must use this accessor macro.
564196039Srwatson */
565196039Srwatsonvoid	kmod_tcpstat_inc(int statnum);
566196039Srwatson#define	KMOD_TCPSTAT_INC(name)						\
567253083Sae    kmod_tcpstat_inc(offsetof(struct tcpstat, name) / sizeof(uint64_t))
568216758Slstewart
569216758Slstewart/*
570216758Slstewart * TCP specific helper hook point identifiers.
571216758Slstewart */
572216758Slstewart#define	HHOOK_TCP_EST_IN		0
573216758Slstewart#define	HHOOK_TCP_EST_OUT		1
574216758Slstewart#define	HHOOK_TCP_LAST			HHOOK_TCP_EST_OUT
575216758Slstewart
576216758Slstewartstruct tcp_hhook_data {
577217252Slstewart	struct tcpcb	*tp;
578217252Slstewart	struct tcphdr	*th;
579217252Slstewart	struct tcpopt	*to;
580217252Slstewart	long		len;
581217252Slstewart	int		tso;
582217252Slstewart	tcp_seq		curack;
583216758Slstewart};
584190978Srwatson#endif
585190948Srwatson
5866247Swollman/*
58736079Swollman * TCB structure exported to user-land via sysctl(3).
58837183Sjhay * Evil hack: declare only if in_pcb.h and sys/socketvar.h have been
58937183Sjhay * included.  Not all of our clients do.
59036079Swollman */
59137183Sjhay#if defined(_NETINET_IN_PCB_H_) && defined(_SYS_SOCKETVAR_H_)
592197244Ssilbystruct xtcp_timer {
593197244Ssilby	int tt_rexmt;	/* retransmit timer */
594197244Ssilby	int tt_persist;	/* retransmit persistence */
595197244Ssilby	int tt_keep;	/* keepalive */
596197244Ssilby	int tt_2msl;	/* 2*msl TIME_WAIT timer */
597197244Ssilby	int tt_delack;	/* delayed ACK timer */
598217126Sjhb	int t_rcvtime;	/* Time since last packet received */
599197244Ssilby};
60036079Swollmanstruct	xtcpcb {
60136079Swollman	size_t	xt_len;
60236079Swollman	struct	inpcb	xt_inp;
60336079Swollman	struct	tcpcb	xt_tp;
60436079Swollman	struct	xsocket	xt_socket;
605197244Ssilby	struct	xtcp_timer xt_timer;
60636079Swollman	u_quad_t	xt_alignment_hack;
60736079Swollman};
60836079Swollman#endif
60936079Swollman
61036079Swollman/*
6116247Swollman * Names for TCP sysctl objects
6126247Swollman */
6136247Swollman#define	TCPCTL_DO_RFC1323	1	/* use RFC-1323 extensions */
6146247Swollman#define	TCPCTL_MSSDFLT		3	/* MSS default */
6156472Swollman#define TCPCTL_STATS		4	/* statistics (read-only) */
6166472Swollman#define	TCPCTL_RTTDFLT		5	/* default RTT estimate */
6176472Swollman#define	TCPCTL_KEEPIDLE		6	/* keepalive idle timer */
6186472Swollman#define	TCPCTL_KEEPINTVL	7	/* interval to send keepalives */
61918281Spst#define	TCPCTL_SENDSPACE	8	/* send buffer space */
62018281Spst#define	TCPCTL_RECVSPACE	9	/* receive buffer space */
62163431Ssheldonh#define	TCPCTL_KEEPINIT		10	/* timeout for establishing syn */
62236079Swollman#define	TCPCTL_PCBLIST		11	/* list of all outstanding PCBs */
62350673Sjlemon#define	TCPCTL_DELACKTIME	12	/* time before sending delayed ACK */
62452904Sshin#define	TCPCTL_V6MSSDFLT	13	/* MSS default for IPv6 */
625130989Sps#define	TCPCTL_SACK		14	/* Selective Acknowledgement,rfc 2018 */
626141381Smaxim#define	TCPCTL_DROP		15	/* drop tcp connection */
627141381Smaxim#define	TCPCTL_MAXID		16
628167036Smohans#define TCPCTL_FINWAIT2_TIMEOUT        17
6296247Swollman
63055205Speter#ifdef _KERNEL
63144078Sdfr#ifdef SYSCTL_DECL
63244078SdfrSYSCTL_DECL(_net_inet_tcp);
633136151SpsSYSCTL_DECL(_net_inet_tcp_sack);
634169683SandreMALLOC_DECLARE(M_TCPLOG);
63544078Sdfr#endif
63644078Sdfr
637195699SrwatsonVNET_DECLARE(struct inpcbhead, tcb);		/* queue of active tcpcb's */
638195699SrwatsonVNET_DECLARE(struct inpcbinfo, tcbinfo);
639207369Sbzextern	int tcp_log_in_vain;
640195699SrwatsonVNET_DECLARE(int, tcp_mssdflt);	/* XXX */
641195699SrwatsonVNET_DECLARE(int, tcp_minmss);
642195699SrwatsonVNET_DECLARE(int, tcp_delack_enabled);
643211464SandreVNET_DECLARE(int, tcp_do_rfc3390);
644242266SandreVNET_DECLARE(int, tcp_do_initcwnd10);
645226437SandreVNET_DECLARE(int, tcp_sendspace);
646226437SandreVNET_DECLARE(int, tcp_recvspace);
647195699SrwatsonVNET_DECLARE(int, path_mtu_discovery);
648215166SlstewartVNET_DECLARE(int, tcp_do_rfc3465);
649215166SlstewartVNET_DECLARE(int, tcp_abc_l_var);
650195727Srwatson#define	V_tcb			VNET(tcb)
651195727Srwatson#define	V_tcbinfo		VNET(tcbinfo)
652195727Srwatson#define	V_tcp_mssdflt		VNET(tcp_mssdflt)
653195727Srwatson#define	V_tcp_minmss		VNET(tcp_minmss)
654195727Srwatson#define	V_tcp_delack_enabled	VNET(tcp_delack_enabled)
655211464Sandre#define	V_tcp_do_rfc3390	VNET(tcp_do_rfc3390)
656242266Sandre#define	V_tcp_do_initcwnd10	VNET(tcp_do_initcwnd10)
657226437Sandre#define	V_tcp_sendspace		VNET(tcp_sendspace)
658226437Sandre#define	V_tcp_recvspace		VNET(tcp_recvspace)
659195727Srwatson#define	V_path_mtu_discovery	VNET(path_mtu_discovery)
660215166Slstewart#define	V_tcp_do_rfc3465	VNET(tcp_do_rfc3465)
661215166Slstewart#define	V_tcp_abc_l_var		VNET(tcp_abc_l_var)
662185088Szec
663195699SrwatsonVNET_DECLARE(int, tcp_do_sack);			/* SACK enabled/disabled */
664195699SrwatsonVNET_DECLARE(int, tcp_sc_rst_sock_fail);	/* RST on sock alloc failure */
665207369Sbz#define	V_tcp_do_sack		VNET(tcp_do_sack)
666207369Sbz#define	V_tcp_sc_rst_sock_fail	VNET(tcp_sc_rst_sock_fail)
667207369Sbz
668195699SrwatsonVNET_DECLARE(int, tcp_do_ecn);			/* TCP ECN enabled/disabled */
669195699SrwatsonVNET_DECLARE(int, tcp_ecn_maxretries);
670195727Srwatson#define	V_tcp_do_ecn		VNET(tcp_do_ecn)
671195727Srwatson#define	V_tcp_ecn_maxretries	VNET(tcp_ecn_maxretries)
672195699Srwatson
673217252SlstewartVNET_DECLARE(struct hhook_head *, tcp_hhh[HHOOK_TCP_LAST + 1]);
674216758Slstewart#define	V_tcp_hhh		VNET(tcp_hhh)
675216758Slstewart
676293709ShirenVNET_DECLARE(int, tcp_do_rfc6675_pipe);
677293709Shiren#define V_tcp_do_rfc6675_pipe	VNET(tcp_do_rfc6675_pipe)
678293709Shiren
679167606Sandreint	 tcp_addoptions(struct tcpopt *, u_char *);
680215392Slstewartint	 tcp_ccalgounload(struct cc_algo *unload_algo);
6811541Srgrimesstruct tcpcb *
68292723Salfred	 tcp_close(struct tcpcb *);
683157376Srwatsonvoid	 tcp_discardcb(struct tcpcb *);
684111145Sjlemonvoid	 tcp_twstart(struct tcpcb *);
685162064Sglebius#if 0
686121850Ssilbyint	 tcp_twrecycleable(struct tcptw *tw);
687162064Sglebius#endif
688275402Sjchvoid	 tcp_twclose(struct tcptw *, int);
68992723Salfredvoid	 tcp_ctlinput(int, struct sockaddr *, void *);
69092723Salfredint	 tcp_ctloutput(struct socket *, struct sockopt *);
6911541Srgrimesstruct tcpcb *
69292723Salfred	 tcp_drop(struct tcpcb *, int);
69392723Salfredvoid	 tcp_drain(void);
69492723Salfredvoid	 tcp_init(void);
695193731Szec#ifdef VIMAGE
696193731Szecvoid	 tcp_destroy(void);
697193731Szec#endif
698128452Ssilbyvoid	 tcp_fini(void *);
699217126Sjhbchar	*tcp_log_addrs(struct in_conninfo *, struct tcphdr *, void *,
700171229Speter	    const void *);
701211462Sandrechar	*tcp_log_vain(struct in_conninfo *, struct tcphdr *, void *,
702211462Sandre	    const void *);
703169541Sandreint	 tcp_reass(struct tcpcb *, struct tcphdr *, int *, struct mbuf *);
704285976Sdelphijvoid	 tcp_reass_global_init(void);
705213158Slstewartvoid	 tcp_reass_flush(struct tcpcb *);
70692723Salfredvoid	 tcp_input(struct mbuf *, int);
707317375Ssmhint	 tcp_autorcvbuf(struct mbuf *, struct tcphdr *, struct socket *,
708317375Ssmh	    struct tcpcb *, int);
709251296Sandreu_long	 tcp_maxmtu(struct in_conninfo *, struct tcp_ifcap *);
710251296Sandreu_long	 tcp_maxmtu6(struct in_conninfo *, struct tcp_ifcap *);
711234342Sglebiusvoid	 tcp_mss_update(struct tcpcb *, int, int, struct hc_metrics_lite *,
712251296Sandre	    struct tcp_ifcap *);
71392723Salfredvoid	 tcp_mss(struct tcpcb *, int);
714122922Sandreint	 tcp_mssopt(struct in_conninfo *);
715133874Srwatsonstruct inpcb *
71698211Shsu	 tcp_drop_syn_sent(struct inpcb *, int);
71798211Shsustruct inpcb *
71898211Shsu	 tcp_mtudisc(struct inpcb *, int);
7191541Srgrimesstruct tcpcb *
72092723Salfred	 tcp_newtcpcb(struct inpcb *);
72192723Salfredint	 tcp_output(struct tcpcb *);
722254889Smarkjvoid	 tcp_state_change(struct tcpcb *, int);
72392723Salfredvoid	 tcp_respond(struct tcpcb *, void *,
72492723Salfred	    struct tcphdr *, struct mbuf *, tcp_seq, tcp_seq, int);
725169541Sandrevoid	 tcp_tw_init(void);
726193731Szec#ifdef VIMAGE
727193731Szecvoid	 tcp_tw_destroy(void);
728193731Szec#endif
729169541Sandrevoid	 tcp_tw_zone_change(void);
730169608Sandreint	 tcp_twcheck(struct inpcb *, struct tcpopt *, struct tcphdr *,
731169608Sandre	    struct mbuf *, int);
73292723Salfredvoid	 tcp_setpersist(struct tcpcb *);
733125783Sbms#ifdef TCP_SIGNATURE
734125783Sbmsint	 tcp_signature_compute(struct mbuf *, int, int, int, u_char *, u_int);
735221023Sattilioint	 tcp_signature_verify(struct mbuf *, int, int, int, struct tcpopt *,
736221023Sattilio	    struct tcphdr *, u_int);
737125783Sbms#endif
73892723Salfredvoid	 tcp_slowtimo(void);
73955679Sshinstruct tcptemp *
740111144Sjlemon	 tcpip_maketemplate(struct inpcb *);
741111144Sjlemonvoid	 tcpip_fillheaders(struct inpcb *, void *, void *);
742282964Sjchvoid	 tcp_timer_activate(struct tcpcb *, uint32_t, u_int);
743282964Sjchint	 tcp_timer_active(struct tcpcb *, uint32_t);
744282964Sjchvoid	 tcp_timer_stop(struct tcpcb *, uint32_t);
745169272Srwatsonvoid	 tcp_trace(short, short, struct tcpcb *, void *, struct tcphdr *, int);
746122922Sandre/*
747122922Sandre * All tcp_hc_* functions are IPv4 and IPv6 (via in_conninfo)
748122922Sandre */
749122922Sandrevoid	 tcp_hc_init(void);
750193731Szec#ifdef VIMAGE
751193731Szecvoid	 tcp_hc_destroy(void);
752193731Szec#endif
753122922Sandrevoid	 tcp_hc_get(struct in_conninfo *, struct hc_metrics_lite *);
754122922Sandreu_long	 tcp_hc_getmtu(struct in_conninfo *);
755122922Sandrevoid	 tcp_hc_updatemtu(struct in_conninfo *, u_long);
756122922Sandrevoid	 tcp_hc_update(struct in_conninfo *, struct hc_metrics_lite *);
7579470Swollman
75817096Swollmanextern	struct pr_usrreqs tcp_usrreqs;
75992723Salfredtcp_seq tcp_new_isn(struct tcpcb *);
7609470Swollman
761293710Shirenint	 tcp_sack_doack(struct tcpcb *, struct tcpopt *, tcp_seq);
762142031Spsvoid	 tcp_update_sack_list(struct tcpcb *tp, tcp_seq rcv_laststart, tcp_seq rcv_lastend);
763130989Spsvoid	 tcp_clean_sackreport(struct tcpcb *tp);
764130989Spsvoid	 tcp_sack_adjust(struct tcpcb *tp);
765136151Spsstruct sackhole *tcp_sack_output(struct tcpcb *tp, int *sack_bytes_rexmt);
766130989Spsvoid	 tcp_sack_partialack(struct tcpcb *, struct tcphdr *);
767130989Spsvoid	 tcp_free_sackholes(struct tcpcb *tp);
768130989Spsint	 tcp_newreno(struct tcpcb *, struct tcphdr *);
769293709Shirenint	 tcp_compute_pipe(struct tcpcb *);
770130989Sps
771215166Slstewartvoid	cc_cong_signal(struct tcpcb *tp, struct tcphdr *th, uint32_t type);
772215166Slstewart
773270051Sbzstatic inline void
774270051Sbztcp_fields_to_host(struct tcphdr *th)
775270051Sbz{
776270051Sbz
777270051Sbz	th->th_seq = ntohl(th->th_seq);
778270051Sbz	th->th_ack = ntohl(th->th_ack);
779270051Sbz	th->th_win = ntohs(th->th_win);
780270051Sbz	th->th_urp = ntohs(th->th_urp);
781270051Sbz}
782270051Sbz
783270051Sbz#ifdef TCP_SIGNATURE
784270051Sbzstatic inline void
785270051Sbztcp_fields_to_net(struct tcphdr *th)
786270051Sbz{
787270051Sbz
788270051Sbz	th->th_seq = htonl(th->th_seq);
789270051Sbz	th->th_ack = htonl(th->th_ack);
790270051Sbz	th->th_win = htons(th->th_win);
791270051Sbz	th->th_urp = htons(th->th_urp);
792270051Sbz}
793270051Sbz#endif
79455205Speter#endif /* _KERNEL */
7952169Spaul
7966348Swollman#endif /* _NETINET_TCP_VAR_H_ */
797