xref: /openbsd-src/sys/netinet/tcp_var.h (revision a28daedfc357b214be5c701aa8ba8adb29a7f1c2)
1 /*	$OpenBSD: tcp_var.h,v 1.90 2008/11/08 12:54:58 dlg Exp $	*/
2 /*	$NetBSD: tcp_var.h,v 1.17 1996/02/13 23:44:24 christos Exp $	*/
3 
4 /*
5  * Copyright (c) 1982, 1986, 1993, 1994
6  *	The Regents of the University of California.  All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  * 3. Neither the name of the University nor the names of its contributors
17  *    may be used to endorse or promote products derived from this software
18  *    without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30  * SUCH DAMAGE.
31  *
32  *	@(#)tcp_var.h	8.3 (Berkeley) 4/10/94
33  */
34 
35 #ifndef _NETINET_TCP_VAR_H_
36 #define _NETINET_TCP_VAR_H_
37 
38 /*
39  * Kernel variables for tcp.
40  */
41 
42 struct sackblk {
43 	tcp_seq start;		/* start seq no. of sack block */
44 	tcp_seq end; 		/* end seq no. */
45 };
46 
47 struct sackhole {
48 	tcp_seq start;		/* start seq no. of hole */
49 	tcp_seq end;		/* end seq no. */
50 	int	dups;		/* number of dup(s)acks for this hole */
51 	tcp_seq rxmit;		/* next seq. no in hole to be retransmitted */
52 	struct sackhole *next;	/* next in list */
53 };
54 
55 /*
56  * TCP sequence queue structures.
57  */
58 TAILQ_HEAD(tcpqehead, tcpqent);
59 struct tcpqent {
60 	TAILQ_ENTRY(tcpqent) tcpqe_q;
61 	struct tcphdr	*tcpqe_tcp;
62 	struct mbuf	*tcpqe_m;	/* mbuf contains packet */
63 };
64 
65 /*
66  * Tcp control block, one per tcp; fields:
67  */
68 struct tcpcb {
69 	struct tcpqehead t_segq;		/* sequencing queue */
70 	struct timeout t_timer[TCPT_NTIMERS];	/* tcp timers */
71 	short	t_state;		/* state of this connection */
72 	short	t_rxtshift;		/* log(2) of rexmt exp. backoff */
73 	short	t_rxtcur;		/* current retransmit value */
74 	short	t_dupacks;		/* consecutive dup acks recd */
75 	u_short	t_maxseg;		/* maximum segment size */
76 	char	t_force;		/* 1 if forcing out a byte */
77 	u_int	t_flags;
78 #define	TF_ACKNOW	0x0001		/* ack peer immediately */
79 #define	TF_DELACK	0x0002		/* ack, but try to delay it */
80 #define	TF_NODELAY	0x0004		/* don't delay packets to coalesce */
81 #define	TF_NOOPT	0x0008		/* don't use tcp options */
82 #define	TF_SENTFIN	0x0010		/* have sent FIN */
83 #define	TF_REQ_SCALE	0x0020		/* have/will request window scaling */
84 #define	TF_RCVD_SCALE	0x0040		/* other side has requested scaling */
85 #define	TF_REQ_TSTMP	0x0080		/* have/will request timestamps */
86 #define	TF_RCVD_TSTMP	0x0100		/* a timestamp was received in SYN */
87 #define	TF_SACK_PERMIT	0x0200		/* other side said I could SACK */
88 #define	TF_SIGNATURE	0x0400		/* require TCP MD5 signature */
89 #ifdef TCP_ECN
90 #define TF_ECN_PERMIT	0x00008000	/* other side said I could ECN */
91 #define TF_RCVD_CE	0x00010000	/* send ECE in subsequent segs */
92 #define TF_SEND_CWR	0x00020000	/* send CWR in next seg */
93 #define TF_DISABLE_ECN	0x00040000	/* disable ECN for this connection */
94 #endif
95 #define TF_LASTIDLE	0x00100000	/* no outstanding ACK on last send */
96 #define TF_DEAD		0x00200000	/* dead and to-be-released */
97 #define TF_PMTUD_PEND	0x00400000	/* Path MTU Discovery pending */
98 
99 	struct	mbuf *t_template;	/* skeletal packet for transmit */
100 	struct	inpcb *t_inpcb;		/* back pointer to internet pcb */
101 	struct	timeout t_delack_to;	/* delayed ACK callback */
102 /*
103  * The following fields are used as in the protocol specification.
104  * See RFC793, Dec. 1981, page 21.
105  */
106 /* send sequence variables */
107 	tcp_seq	snd_una;		/* send unacknowledged */
108 	tcp_seq	snd_nxt;		/* send next */
109 	tcp_seq	snd_up;			/* send urgent pointer */
110 	tcp_seq	snd_wl1;		/* window update seg seq number */
111 	tcp_seq	snd_wl2;		/* window update seg ack number */
112 	tcp_seq	iss;			/* initial send sequence number */
113 	u_long	snd_wnd;		/* send window */
114 #if 1 /*def TCP_SACK*/
115 	int	sack_enable;		/* enable SACK for this connection */
116 	int	snd_numholes;		/* number of holes seen by sender */
117 	struct sackhole *snd_holes;	/* linked list of holes (sorted) */
118 #if 1 /*defined(TCP_SACK) && defined(TCP_FACK)*/
119 	tcp_seq snd_fack;		/* for FACK congestion control */
120 	u_long	snd_awnd;		/* snd_nxt - snd_fack + */
121 					/* retransmitted data */
122 	int retran_data;		/* amount of outstanding retx. data  */
123 #endif /* TCP_FACK */
124 #endif /* TCP_SACK */
125 #if 1 /*defined(TCP_SACK) || defined(TCP_ECN)*/
126 	tcp_seq snd_last;		/* for use in fast recovery */
127 #endif
128 /* receive sequence variables */
129 	u_long	rcv_wnd;		/* receive window */
130 	tcp_seq	rcv_nxt;		/* receive next */
131 	tcp_seq	rcv_up;			/* receive urgent pointer */
132 	tcp_seq	irs;			/* initial receive sequence number */
133 #if 1 /*def TCP_SACK*/
134 	tcp_seq rcv_lastsack;		/* last seq number(+1) sack'd by rcv'r*/
135 	int	rcv_numsacks;		/* # distinct sack blks present */
136 	struct sackblk sackblks[MAX_SACK_BLKS]; /* seq nos. of sack blocks */
137 #endif
138 
139 /*
140  * Additional variables for this implementation.
141  */
142 /* receive variables */
143 	tcp_seq	rcv_adv;		/* advertised window */
144 /* retransmit variables */
145 	tcp_seq	snd_max;		/* highest sequence number sent;
146 					 * used to recognize retransmits
147 					 */
148 /* congestion control (for slow start, source quench, retransmit after loss) */
149 	u_long	snd_cwnd;		/* congestion-controlled window */
150 	u_long	snd_ssthresh;		/* snd_cwnd size threshold for
151 					 * for slow start exponential to
152 					 * linear switch
153 					 */
154 	u_short	t_maxopd;		/* mss plus options */
155 	u_short	t_peermss;		/* peer's maximum segment size */
156 
157 /*
158  * transmit timing stuff.  See below for scale of srtt and rttvar.
159  * "Variance" is actually smoothed difference.
160  */
161 	uint32_t t_rcvtime;		/* time last segment received */
162 	uint32_t t_rtttime;		/* time we started measuring rtt */
163 	tcp_seq	t_rtseq;		/* sequence number being timed */
164 	short	t_srtt;			/* smoothed round-trip time */
165 	short	t_rttvar;		/* variance in round-trip time */
166 	u_short	t_rttmin;		/* minimum rtt allowed */
167 	u_long	max_sndwnd;		/* largest window peer has offered */
168 
169 /* out-of-band data */
170 	char	t_oobflags;		/* have some */
171 	char	t_iobc;			/* input character */
172 #define	TCPOOB_HAVEDATA	0x01
173 #define	TCPOOB_HADDATA	0x02
174 	short	t_softerror;		/* possible error not yet reported */
175 
176 /* RFC 1323 variables */
177 	u_char	snd_scale;		/* window scaling for send window */
178 	u_char	rcv_scale;		/* window scaling for recv window */
179 	u_char	request_r_scale;	/* pending window scaling */
180 	u_char	requested_s_scale;
181 	u_int32_t ts_recent;		/* timestamp echo data */
182 	u_int32_t ts_modulate;		/* modulation on timestamp */
183 	u_int32_t ts_recent_age;		/* when last updated */
184 	tcp_seq	last_ack_sent;
185 
186 /* pointer for syn cache entries*/
187 	LIST_HEAD(, syn_cache) t_sc;	/* list of entries by this tcb */
188 
189 /* Path-MTU Discovery Information */
190 	u_int	t_pmtud_mss_acked;	/* MSS acked, lower bound for MTU */
191 	u_int	t_pmtud_mtu_sent;	/* MTU used, upper bound for MTU */
192 	tcp_seq	t_pmtud_th_seq;		/* TCP SEQ from ICMP payload */
193 	u_int	t_pmtud_nextmtu;	/* Advertised Next-Hop MTU from ICMP */
194 	u_short	t_pmtud_ip_len;		/* IP length from ICMP payload */
195 	u_short	t_pmtud_ip_hl;		/* IP header length from ICMP payload */
196 
197 	int pf;
198 
199 	struct	timeout t_reap_to;	/* delayed cleanup timeout */
200 };
201 
202 #define	intotcpcb(ip)	((struct tcpcb *)(ip)->inp_ppcb)
203 #define	sototcpcb(so)	(intotcpcb(sotoinpcb(so)))
204 
205 #ifdef _KERNEL
206 extern int tcp_delack_ticks;
207 void	tcp_delack(void *);
208 
209 #define TCP_INIT_DELACK(tp)						\
210 	timeout_set(&(tp)->t_delack_to, tcp_delack, tp)
211 
212 #define TCP_RESTART_DELACK(tp)						\
213 	timeout_add(&(tp)->t_delack_to, tcp_delack_ticks)
214 
215 #define	TCP_SET_DELACK(tp)						\
216 do {									\
217 	if (((tp)->t_flags & TF_DELACK) == 0) {				\
218 		(tp)->t_flags |= TF_DELACK;				\
219 		TCP_RESTART_DELACK(tp);					\
220 	}								\
221 } while (/* CONSTCOND */ 0)
222 
223 #define	TCP_CLEAR_DELACK(tp)						\
224 do {									\
225 	if ((tp)->t_flags & TF_DELACK) {				\
226 		(tp)->t_flags &= ~TF_DELACK;				\
227 		timeout_del(&(tp)->t_delack_to);			\
228 	}								\
229 } while (/* CONSTCOND */ 0)
230 
231 /*
232  * Handy way of passing around TCP option info.
233  */
234 struct tcp_opt_info {
235 	int		ts_present;
236 	u_int32_t	ts_val;
237 	u_int32_t	ts_ecr;
238 	u_int16_t	maxseg;
239 };
240 
241 /*
242  * Data for the TCP compressed state engine.
243  */
244 union syn_cache_sa {
245 	struct sockaddr sa;
246 	struct sockaddr_in sin;
247 #if 1 /*def INET6*/
248 	struct sockaddr_in6 sin6;
249 #endif
250 };
251 
252 struct syn_cache {
253 	TAILQ_ENTRY(syn_cache) sc_bucketq;	/* link on bucket list */
254 	struct timeout sc_timer;		/* rexmt timer */
255 	union {					/* cached route */
256 		struct route route4;
257 #ifdef INET6
258 		struct route_in6 route6;
259 #endif
260 	} sc_route_u;
261 #define sc_route4	sc_route_u.route4
262 #ifdef INET6
263 #define sc_route6	sc_route_u.route6
264 #endif
265 	long sc_win;				/* advertised window */
266 	int sc_bucketidx;			/* our bucket index */
267 	u_int32_t sc_hash;
268 	u_int32_t sc_timestamp;			/* timestamp from SYN */
269 	u_int32_t sc_modulate;			/* our timestamp modulator */
270 #if 0
271 	u_int32_t sc_timebase;			/* our local timebase */
272 #endif
273 	union syn_cache_sa sc_src;
274 	union syn_cache_sa sc_dst;
275 	tcp_seq sc_irs;
276 	tcp_seq sc_iss;
277 	u_int sc_rxtcur;			/* current rxt timeout */
278 	u_int sc_rxttot;			/* total time spend on queues */
279 	u_short sc_rxtshift;			/* for computing backoff */
280 	u_short sc_flags;
281 
282 #define	SCF_UNREACH		0x0001		/* we've had an unreach error */
283 #define	SCF_TIMESTAMP		0x0002		/* peer will do timestamps */
284 #define	SCF_DEAD		0x0004		/* this entry to be released */
285 #define	SCF_SACK_PERMIT		0x0008		/* permit sack */
286 #define	SCF_ECN_PERMIT		0x0010		/* permit ecn */
287 #define	SCF_SIGNATURE		0x0020		/* enforce tcp signatures */
288 
289 	struct mbuf *sc_ipopts;			/* IP options */
290 	u_int16_t sc_peermaxseg;
291 	u_int16_t sc_ourmaxseg;
292 	u_int     sc_request_r_scale	: 4,
293 		  sc_requested_s_scale	: 4;
294 
295 	struct tcpcb *sc_tp;			/* tcb for listening socket */
296 	LIST_ENTRY(syn_cache) sc_tpq;		/* list of entries by same tp */
297 };
298 
299 struct syn_cache_head {
300 	TAILQ_HEAD(, syn_cache) sch_bucket;	/* bucket entries */
301 	u_short sch_length;			/* # entries in bucket */
302 };
303 
304 #endif /* _KERNEL */
305 
306 /*
307  * The smoothed round-trip time and estimated variance
308  * are stored as fixed point numbers scaled by the values below.
309  * For convenience, these scales are also used in smoothing the average
310  * (smoothed = (1/scale)sample + ((scale-1)/scale)smoothed).
311  * With these scales, srtt has 5 bits to the right of the binary point,
312  * and thus an "ALPHA" of 0.875.  rttvar has 4 bits to the right of the
313  * binary point, and is smoothed with an ALPHA of 0.75.
314  */
315 #define	TCP_RTT_SHIFT		3	/* shift for srtt; 5 bits frac. */
316 #define	TCP_RTTVAR_SHIFT	2	/* shift for rttvar; 4 bits */
317 #define	TCP_RTT_BASE_SHIFT	2	/* remaining 2 bit shift */
318 #define	TCP_RTT_MAX		(1<<9)	/* maximum rtt */
319 
320 /*
321  * The initial retransmission should happen at rtt + 4 * rttvar.
322  * Because of the way we do the smoothing, srtt and rttvar
323  * will each average +1/2 tick of bias.  When we compute
324  * the retransmit timer, we want 1/2 tick of rounding and
325  * 1 extra tick because of +-1/2 tick uncertainty in the
326  * firing of the timer.  The bias will give us exactly the
327  * 1.5 tick we need.  But, because the bias is
328  * statistical, we have to test that we don't drop below
329  * the minimum feasible timer (which is 2 ticks).
330  * This macro assumes that the value of (1 << TCP_RTTVAR_SHIFT)
331  * is the same as the multiplier for rttvar.
332  */
333 #define	TCP_REXMTVAL(tp) \
334 	((((tp)->t_srtt >> TCP_RTT_SHIFT) + (tp)->t_rttvar) >> TCP_RTT_BASE_SHIFT)
335 
336 /*
337  * TCP statistics.
338  * Many of these should be kept per connection,
339  * but that's inconvenient at the moment.
340  */
341 struct	tcpstat {
342 	u_int32_t tcps_connattempt;	/* connections initiated */
343 	u_int32_t tcps_accepts;		/* connections accepted */
344 	u_int32_t tcps_connects;	/* connections established */
345 	u_int32_t tcps_drops;		/* connections dropped */
346 	u_int32_t tcps_conndrops;	/* embryonic connections dropped */
347 	u_int32_t tcps_closed;		/* conn. closed (includes drops) */
348 	u_int32_t tcps_segstimed;	/* segs where we tried to get rtt */
349 	u_int32_t tcps_rttupdated;	/* times we succeeded */
350 	u_int32_t tcps_delack;		/* delayed acks sent */
351 	u_int32_t tcps_timeoutdrop;	/* conn. dropped in rxmt timeout */
352 	u_int32_t tcps_rexmttimeo;	/* retransmit timeouts */
353 	u_int32_t tcps_persisttimeo;	/* persist timeouts */
354 	u_int32_t tcps_persistdrop;	/* connections dropped in persist */
355 	u_int32_t tcps_keeptimeo;	/* keepalive timeouts */
356 	u_int32_t tcps_keepprobe;	/* keepalive probes sent */
357 	u_int32_t tcps_keepdrops;	/* connections dropped in keepalive */
358 
359 	u_int32_t tcps_sndtotal;		/* total packets sent */
360 	u_int32_t tcps_sndpack;		/* data packets sent */
361 	u_int64_t tcps_sndbyte;		/* data bytes sent */
362 	u_int32_t tcps_sndrexmitpack;	/* data packets retransmitted */
363 	u_int64_t tcps_sndrexmitbyte;	/* data bytes retransmitted */
364 	u_int64_t tcps_sndrexmitfast;	/* Fast retransmits */
365 	u_int32_t tcps_sndacks;		/* ack-only packets sent */
366 	u_int32_t tcps_sndprobe;	/* window probes sent */
367 	u_int32_t tcps_sndurg;		/* packets sent with URG only */
368 	u_int32_t tcps_sndwinup;	/* window update-only packets sent */
369 	u_int32_t tcps_sndctrl;		/* control (SYN|FIN|RST) packets sent */
370 
371 	u_int32_t tcps_rcvtotal;	/* total packets received */
372 	u_int32_t tcps_rcvpack;		/* packets received in sequence */
373 	u_int64_t tcps_rcvbyte;		/* bytes received in sequence */
374 	u_int32_t tcps_rcvbadsum;	/* packets received with ccksum errs */
375 	u_int32_t tcps_rcvbadoff;	/* packets received with bad offset */
376 	u_int32_t tcps_rcvmemdrop;	/* packets dropped for lack of memory */
377 	u_int32_t tcps_rcvnosec;	/* packets dropped for lack of ipsec */
378 	u_int32_t tcps_rcvshort;	/* packets received too short */
379 	u_int32_t tcps_rcvduppack;	/* duplicate-only packets received */
380 	u_int64_t tcps_rcvdupbyte;	/* duplicate-only bytes received */
381 	u_int32_t tcps_rcvpartduppack;	/* packets with some duplicate data */
382 	u_int64_t tcps_rcvpartdupbyte;	/* dup. bytes in part-dup. packets */
383 	u_int32_t tcps_rcvoopack;	/* out-of-order packets received */
384 	u_int64_t tcps_rcvoobyte;	/* out-of-order bytes received */
385 	u_int32_t tcps_rcvpackafterwin;	/* packets with data after window */
386 	u_int64_t tcps_rcvbyteafterwin;	/* bytes rcvd after window */
387 	u_int32_t tcps_rcvafterclose;	/* packets rcvd after "close" */
388 	u_int32_t tcps_rcvwinprobe;	/* rcvd window probe packets */
389 	u_int32_t tcps_rcvdupack;	/* rcvd duplicate acks */
390 	u_int32_t tcps_rcvacktoomuch;	/* rcvd acks for unsent data */
391 	u_int32_t tcps_rcvacktooold;	/* rcvd acks for old data */
392 	u_int32_t tcps_rcvackpack;	/* rcvd ack packets */
393 	u_int64_t tcps_rcvackbyte;	/* bytes acked by rcvd acks */
394 	u_int32_t tcps_rcvwinupd;	/* rcvd window update packets */
395 	u_int32_t tcps_pawsdrop;	/* segments dropped due to PAWS */
396 	u_int32_t tcps_predack;		/* times hdr predict ok for acks */
397 	u_int32_t tcps_preddat;		/* times hdr predict ok for data pkts */
398 
399 	u_int32_t tcps_pcbhashmiss;	/* input packets missing pcb hash */
400 	u_int32_t tcps_noport;		/* no socket on port */
401 	u_int32_t tcps_badsyn;		/* SYN packet with src==dst rcv'ed */
402 
403 	u_int32_t tcps_rcvbadsig;	/* rcvd bad/missing TCP signatures */
404 	u_int64_t tcps_rcvgoodsig;	/* rcvd good TCP signatures */
405 	u_int32_t tcps_inhwcsum;	/* input hardware-checksummed packets */
406 	u_int32_t tcps_outhwcsum;	/* output hardware-checksummed packets */
407 
408 	/* ECN stats */
409 	u_int32_t tcps_ecn_accepts;	/* ecn connections accepted */
410 	u_int32_t tcps_ecn_rcvece;	/* # of rcvd ece */
411 	u_int32_t tcps_ecn_rcvcwr;	/* # of rcvd cwr */
412 	u_int32_t tcps_ecn_rcvce;	/* # of rcvd ce in ip header */
413 	u_int32_t tcps_ecn_sndect;	/* # of cwr sent */
414 	u_int32_t tcps_ecn_sndece;	/* # of ece sent */
415 	u_int32_t tcps_ecn_sndcwr;	/* # of cwr sent */
416 	u_int32_t tcps_cwr_ecn;		/* # of cwnd reduced by ecn */
417 	u_int32_t tcps_cwr_frecovery;	/* # of cwnd reduced by fastrecovery */
418 	u_int32_t tcps_cwr_timeout;	/* # of cwnd reduced by timeout */
419 
420 	/* These statistics deal with the SYN cache. */
421 	u_int64_t tcps_sc_added;	/* # of entries added */
422 	u_int64_t tcps_sc_completed;	/* # of connections completed */
423 	u_int64_t tcps_sc_timed_out;	/* # of entries timed out */
424 	u_int64_t tcps_sc_overflowed;	/* # dropped due to overflow */
425 	u_int64_t tcps_sc_reset;	/* # dropped due to RST */
426 	u_int64_t tcps_sc_unreach;	/* # dropped due to ICMP unreach */
427 	u_int64_t tcps_sc_bucketoverflow;/* # dropped due to bucket overflow */
428 	u_int64_t tcps_sc_aborted;	/* # of entries aborted (no mem) */
429 	u_int64_t tcps_sc_dupesyn;	/* # of duplicate SYNs received */
430 	u_int64_t tcps_sc_dropped;	/* # of SYNs dropped (no route/mem) */
431 	u_int64_t tcps_sc_collisions;	/* # of hash collisions */
432 	u_int64_t tcps_sc_retransmitted;/* # of retransmissions */
433 
434 	u_int64_t tcps_conndrained;	/* # of connections drained */
435 
436 	u_int64_t tcps_sack_recovery_episode;	/* SACK recovery episodes */
437 	u_int64_t tcps_sack_rexmits;		/* SACK rexmit segments */
438 	u_int64_t tcps_sack_rexmit_bytes;	/* SACK rexmit bytes */
439 	u_int64_t tcps_sack_rcv_opts;		/* SACK options received */
440 	u_int64_t tcps_sack_snd_opts;		/* SACK options sent */
441 };
442 
443 /*
444  * Names for TCP sysctl objects.
445  */
446 
447 #define	TCPCTL_RFC1323		1 /* enable/disable RFC1323 timestamps/scaling */
448 #define	TCPCTL_KEEPINITTIME	2 /* TCPT_KEEP value */
449 #define TCPCTL_KEEPIDLE		3 /* allow tcp_keepidle to be changed */
450 #define TCPCTL_KEEPINTVL	4 /* allow tcp_keepintvl to be changed */
451 #define TCPCTL_SLOWHZ		5 /* return kernel idea of PR_SLOWHZ */
452 #define TCPCTL_BADDYNAMIC	6 /* return bad dynamic port bitmap */
453 #define	TCPCTL_RECVSPACE	7 /* receive buffer space */
454 #define	TCPCTL_SENDSPACE	8 /* send buffer space */
455 #define	TCPCTL_IDENT		9 /* get connection owner */
456 #define	TCPCTL_SACK	       10 /* selective acknowledgement, rfc 2018 */
457 #define TCPCTL_MSSDFLT	       11 /* Default maximum segment size */
458 #define	TCPCTL_RSTPPSLIMIT     12 /* RST pps limit */
459 #define	TCPCTL_ACK_ON_PUSH     13 /* ACK immediately on PUSH */
460 #define	TCPCTL_ECN	       14 /* RFC3168 ECN */
461 #define	TCPCTL_SYN_CACHE_LIMIT 15 /* max size of comp. state engine */
462 #define	TCPCTL_SYN_BUCKET_LIMIT	16 /* max size of hash bucket */
463 #define	TCPCTL_RFC3390	       17 /* enable/disable RFC3390 increased cwnd */
464 #define	TCPCTL_REASS_LIMIT     18 /* max entries for tcp reass queues */
465 #define	TCPCTL_DROP	       19 /* drop tcp connection */
466 #define	TCPCTL_SACKHOLE_LIMIT  20 /* max entries for tcp sack queues */
467 #define	TCPCTL_STATS	       21 /* TCP statistics */
468 #define	TCPCTL_MAXID	       22
469 
470 #define	TCPCTL_NAMES { \
471 	{ 0, 0 }, \
472 	{ "rfc1323",	CTLTYPE_INT }, \
473 	{ "keepinittime",	CTLTYPE_INT }, \
474 	{ "keepidle",	CTLTYPE_INT }, \
475 	{ "keepintvl",	CTLTYPE_INT }, \
476 	{ "slowhz",	CTLTYPE_INT }, \
477 	{ "baddynamic", CTLTYPE_STRUCT }, \
478 	{ "recvspace",	CTLTYPE_INT }, \
479 	{ "sendspace",	CTLTYPE_INT }, \
480 	{ "ident", 	CTLTYPE_STRUCT }, \
481 	{ "sack",	CTLTYPE_INT }, \
482 	{ "mssdflt",	CTLTYPE_INT }, \
483 	{ "rstppslimit",	CTLTYPE_INT }, \
484 	{ "ackonpush",	CTLTYPE_INT }, \
485 	{ "ecn", 	CTLTYPE_INT }, \
486 	{ "syncachelimit", 	CTLTYPE_INT }, \
487 	{ "synbucketlimit", 	CTLTYPE_INT }, \
488 	{ "rfc3390", 	CTLTYPE_INT }, \
489 	{ "reasslimit", 	CTLTYPE_INT }, \
490 	{ "drop", 	CTLTYPE_STRUCT }, \
491 	{ "sackholelimit", 	CTLTYPE_INT }, \
492 	{ "stats",	CTLTYPE_STRUCT } \
493 }
494 
495 #define	TCPCTL_VARS { \
496 	NULL, \
497 	&tcp_do_rfc1323, \
498 	&tcptv_keep_init, \
499 	&tcp_keepidle, \
500 	&tcp_keepintvl, \
501 	NULL, \
502 	NULL, \
503 	&tcp_recvspace, \
504 	&tcp_sendspace, \
505 	NULL, \
506 	NULL, \
507 	&tcp_mssdflt, \
508 	&tcp_rst_ppslim, \
509 	&tcp_ack_on_push, \
510 	NULL, \
511 	&tcp_syn_cache_limit, \
512 	&tcp_syn_bucket_limit, \
513 	&tcp_do_rfc3390, \
514 	NULL, \
515 	NULL, \
516 	NULL, \
517 	NULL \
518 }
519 
520 struct tcp_ident_mapping {
521 	struct sockaddr_storage faddr, laddr;
522 	int euid, ruid;
523 };
524 
525 #ifdef _KERNEL
526 extern	struct inpcbtable tcbtable;	/* head of queue of active tcpcb's */
527 extern	struct tcpstat tcpstat;	/* tcp statistics */
528 extern	u_int32_t tcp_now;		/* for RFC 1323 timestamps */
529 extern	int tcp_do_rfc1323;	/* enabled/disabled? */
530 extern	int tcp_mssdflt;	/* default maximum segment size */
531 extern	int tcp_ack_on_push;	/* ACK immediately on PUSH */
532 #ifdef TCP_SACK
533 extern	int tcp_do_sack;	/* SACK enabled/disabled */
534 extern	struct pool sackhl_pool;
535 extern	int tcp_sackhole_limit;	/* max entries for tcp sack queues */
536 #endif
537 extern	int tcp_do_ecn;		/* RFC3168 ECN enabled/disabled? */
538 extern	int tcp_do_rfc3390;	/* RFC3390 Increasing TCP's Initial Window */
539 
540 extern	struct pool tcpqe_pool;
541 extern	int tcp_reass_limit;	/* max entries for tcp reass queues */
542 
543 extern	int tcp_syn_cache_limit; /* max entries for compressed state engine */
544 extern	int tcp_syn_bucket_limit;/* max entries per hash bucket */
545 
546 extern	int tcp_syn_cache_size;
547 extern	struct syn_cache_head tcp_syn_cache[];
548 extern	u_long syn_cache_count;
549 
550 int	 tcp_attach(struct socket *);
551 void	 tcp_canceltimers(struct tcpcb *);
552 struct tcpcb *
553 	 tcp_close(struct tcpcb *);
554 void	 tcp_reaper(void *);
555 int	 tcp_freeq(struct tcpcb *);
556 #if defined(INET6) && !defined(TCP6)
557 void	 tcp6_ctlinput(int, struct sockaddr *, void *);
558 #endif
559 void	 *tcp_ctlinput(int, struct sockaddr *, void *);
560 int	 tcp_ctloutput(int, struct socket *, int, int, struct mbuf **);
561 struct tcpcb *
562 	 tcp_disconnect(struct tcpcb *);
563 struct tcpcb *
564 	 tcp_drop(struct tcpcb *, int);
565 int	 tcp_dooptions(struct tcpcb *, u_char *, int, struct tcphdr *,
566 		struct mbuf *, int, struct tcp_opt_info *);
567 void	 tcp_init(void);
568 #if defined(INET6) && !defined(TCP6)
569 int	 tcp6_input(struct mbuf **, int *, int);
570 #endif
571 void	 tcp_input(struct mbuf *, ...);
572 int	 tcp_mss(struct tcpcb *, int);
573 void	 tcp_mss_update(struct tcpcb *);
574 u_int	 tcp_hdrsz(struct tcpcb *);
575 void	 tcp_mtudisc(struct inpcb *, int);
576 void	 tcp_mtudisc_increase(struct inpcb *, int);
577 #ifdef INET6
578 void	tcp6_mtudisc(struct inpcb *, int);
579 void	tcp6_mtudisc_callback(struct in6_addr *);
580 #endif
581 struct tcpcb *
582 	 tcp_newtcpcb(struct inpcb *);
583 void	 tcp_notify(struct inpcb *, int);
584 int	 tcp_output(struct tcpcb *);
585 void	 tcp_pulloutofband(struct socket *, u_int, struct mbuf *, int);
586 int	 tcp_reass(struct tcpcb *, struct tcphdr *, struct mbuf *, int *);
587 void	 tcp_rscale(struct tcpcb *, u_long);
588 void	 tcp_respond(struct tcpcb *, caddr_t, struct tcphdr *, tcp_seq,
589 		tcp_seq, int);
590 void	 tcp_setpersist(struct tcpcb *);
591 void	 tcp_slowtimo(void);
592 struct mbuf *
593 	 tcp_template(struct tcpcb *);
594 void	 tcp_trace(short, short, struct tcpcb *, caddr_t, int, int);
595 struct tcpcb *
596 	 tcp_usrclosed(struct tcpcb *);
597 int	 tcp_sysctl(int *, u_int, void *, size_t *, void *, size_t);
598 int	 tcp_usrreq(struct socket *,
599 	    int, struct mbuf *, struct mbuf *, struct mbuf *, struct proc *);
600 void	 tcp_xmit_timer(struct tcpcb *, int);
601 void	 tcpdropoldhalfopen(struct tcpcb *, u_int16_t);
602 #ifdef TCP_SACK
603 void	 tcp_sack_option(struct tcpcb *,struct tcphdr *,u_char *,int);
604 void	 tcp_update_sack_list(struct tcpcb *tp, tcp_seq, tcp_seq);
605 void	 tcp_del_sackholes(struct tcpcb *, struct tcphdr *);
606 void	 tcp_clean_sackreport(struct tcpcb *tp);
607 void	 tcp_sack_adjust(struct tcpcb *tp);
608 struct sackhole *
609 	 tcp_sack_output(struct tcpcb *tp);
610 int	 tcp_sack_partialack(struct tcpcb *, struct tcphdr *);
611 #ifdef DEBUG
612 void	 tcp_print_holes(struct tcpcb *tp);
613 #endif
614 #endif /* TCP_SACK */
615 #if defined(TCP_SACK)
616 int	 tcp_newreno(struct tcpcb *, struct tcphdr *);
617 u_long	 tcp_seq_subtract(u_long, u_long );
618 #endif /* TCP_SACK */
619 #ifdef TCP_SIGNATURE
620 int	tcp_signature_apply(caddr_t, caddr_t, unsigned int);
621 int	tcp_signature(struct tdb *, int, struct mbuf *, struct tcphdr *,
622 	    int, int, char *);
623 #endif /* TCP_SIGNATURE */
624 void     tcp_set_iss_tsm(struct tcpcb *);
625 
626 int	 syn_cache_add(struct sockaddr *, struct sockaddr *,
627 		struct tcphdr *, unsigned int, struct socket *,
628 		struct mbuf *, u_char *, int, struct tcp_opt_info *, tcp_seq *);
629 void	 syn_cache_unreach(struct sockaddr *, struct sockaddr *,
630 	   struct tcphdr *);
631 struct socket *syn_cache_get(struct sockaddr *, struct sockaddr *,
632 		struct tcphdr *, unsigned int, unsigned int,
633 		struct socket *so, struct mbuf *);
634 void	 syn_cache_init(void);
635 void	 syn_cache_insert(struct syn_cache *, struct tcpcb *);
636 struct syn_cache *syn_cache_lookup(struct sockaddr *, struct sockaddr *,
637 		struct syn_cache_head **);
638 void	 syn_cache_reset(struct sockaddr *, struct sockaddr *,
639 		struct tcphdr *);
640 int	 syn_cache_respond(struct syn_cache *, struct mbuf *);
641 void	 syn_cache_timer(void *);
642 void	 syn_cache_cleanup(struct tcpcb *);
643 void	 syn_cache_reaper(void *);
644 
645 #endif /* _KERNEL */
646 #endif /* _NETINET_TCP_VAR_H_ */
647