xref: /illumos-gate/usr/src/uts/common/inet/tcp_impl.h (revision 1d7382f724e745e00a005bae397cdb54a0179ceb)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef	_INET_TCP_IMPL_H
27 #define	_INET_TCP_IMPL_H
28 
29 /*
30  * TCP implementation private declarations.  These interfaces are
31  * used to build the IP module and are not meant to be accessed
32  * by any modules except IP itself.  They are undocumented and are
33  * subject to change without notice.
34  */
35 
36 #ifdef	__cplusplus
37 extern "C" {
38 #endif
39 
40 #ifdef _KERNEL
41 
42 #include <sys/cpuvar.h>
43 #include <sys/clock_impl.h>	/* For LBOLT_FASTPATH{,64} */
44 #include <inet/optcom.h>
45 #include <inet/tcp.h>
46 
47 #define	TCP_MOD_ID	5105
48 
49 extern struct qinit	tcp_sock_winit;
50 extern struct qinit	tcp_winit;
51 
52 extern sock_downcalls_t sock_tcp_downcalls;
53 
54 /*
55  * Bind hash list size and has function.  It has to be a power of 2 for
56  * hashing.
57  */
58 #define	TCP_BIND_FANOUT_SIZE	512
59 #define	TCP_BIND_HASH(lport) (ntohs(lport) & (TCP_BIND_FANOUT_SIZE - 1))
60 
61 /*
62  * This implementation follows the 4.3BSD interpretation of the urgent
63  * pointer and not RFC 1122. Switching to RFC 1122 behavior would cause
64  * incompatible changes in protocols like telnet and rlogin.
65  */
66 #define	TCP_OLD_URP_INTERPRETATION	1
67 
68 /* Handy time related macros. */
69 #define	MS	1L
70 #define	SECONDS	(1000 * MS)
71 #define	MINUTES	(60 * SECONDS)
72 #define	HOURS	(60 * MINUTES)
73 #define	DAYS	(24 * HOURS)
74 
75 /* TCP option length */
76 #define	TCPOPT_NOP_LEN		1
77 #define	TCPOPT_MAXSEG_LEN	4
78 #define	TCPOPT_WS_LEN		3
79 #define	TCPOPT_REAL_WS_LEN	(TCPOPT_WS_LEN+1)
80 #define	TCPOPT_TSTAMP_LEN	10
81 #define	TCPOPT_REAL_TS_LEN	(TCPOPT_TSTAMP_LEN+2)
82 #define	TCPOPT_SACK_OK_LEN	2
83 #define	TCPOPT_REAL_SACK_OK_LEN	(TCPOPT_SACK_OK_LEN+2)
84 #define	TCPOPT_REAL_SACK_LEN	4
85 #define	TCPOPT_MAX_SACK_LEN	36
86 #define	TCPOPT_HEADER_LEN	2
87 
88 /* Round up the value to the nearest mss. */
89 #define	MSS_ROUNDUP(value, mss)		((((value) - 1) / (mss) + 1) * (mss))
90 
91 /*
92  * Was this tcp created via socket() interface?
93  */
94 #define	TCP_IS_SOCKET(tcp)	((tcp)->tcp_issocket)
95 
96 /*
97  * Is this tcp not attached to any upper client?
98  */
99 #define	TCP_IS_DETACHED(tcp)	((tcp)->tcp_detached)
100 
101 /* TCP timers related data strucutres.  Refer to tcp_timers.c. */
102 typedef struct tcp_timer_s {
103 	conn_t	*connp;
104 	void 	(*tcpt_proc)(void *);
105 	callout_id_t   tcpt_tid;
106 } tcp_timer_t;
107 
108 extern kmem_cache_t *tcp_timercache;
109 
110 /*
111  * Macro for starting various timers.  Retransmission timer has its own macro,
112  * TCP_TIMER_RESTART().
113  */
114 #define	TCP_TIMER(tcp, f, tim)		\
115 	tcp_timeout(tcp->tcp_connp, f, tim)
116 #define	TCP_TIMER_CANCEL(tcp, id)	\
117 	tcp_timeout_cancel(tcp->tcp_connp, id)
118 
119 /*
120  * To restart the TCP retransmission timer.
121  */
122 #define	TCP_TIMER_RESTART(tcp, intvl) {					\
123 	if ((tcp)->tcp_timer_tid != 0)					\
124 		(void) TCP_TIMER_CANCEL((tcp), (tcp)->tcp_timer_tid);	\
125 	(tcp)->tcp_timer_tid = TCP_TIMER((tcp), tcp_timer,		\
126 	    MSEC_TO_TICK(intvl));					\
127 }
128 
129 /*
130  * For scalability, we must not run a timer for every TCP connection
131  * in TIME_WAIT state.  To see why, consider (for time wait interval of
132  * 1 minutes):
133  *	10,000 connections/sec * 60 seconds/time wait = 600,000 active conn's
134  *
135  * This list is ordered by time, so you need only delete from the head
136  * until you get to entries which aren't old enough to delete yet.
137  * The list consists of only the detached TIME_WAIT connections.
138  *
139  * When a tcp_t enters TIME_WAIT state, a timer is started (timeout is
140  * tcps_time_wait_interval).  When the tcp_t is detached (upper layer closes
141  * the end point), it is moved to the time wait list and another timer is
142  * started (expiry time is set at tcp_time_wait_expire, which is
143  * also calculated using tcps_time_wait_interval).  This means that the
144  * TIME_WAIT state can be extended (up to doubled) if the tcp_t doesn't
145  * become detached for a long time.
146  *
147  * The list manipulations (including tcp_time_wait_next/prev)
148  * are protected by the tcp_time_wait_lock. The content of the
149  * detached TIME_WAIT connections is protected by the normal perimeters.
150  *
151  * This list is per squeue and squeues are shared across the tcp_stack_t's.
152  * Things on tcp_time_wait_head remain associated with the tcp_stack_t
153  * and conn_netstack.
154  * The tcp_t's that are added to tcp_free_list are disassociated and
155  * have NULL tcp_tcps and conn_netstack pointers.
156  */
157 typedef struct tcp_squeue_priv_s {
158 	kmutex_t	tcp_time_wait_lock;
159 	callout_id_t	tcp_time_wait_tid;
160 	tcp_t		*tcp_time_wait_head;
161 	tcp_t		*tcp_time_wait_tail;
162 	tcp_t		*tcp_free_list;
163 	uint_t		tcp_free_list_cnt;
164 } tcp_squeue_priv_t;
165 
166 /*
167  * Parameters for TCP Initial Send Sequence number (ISS) generation.  When
168  * tcp_strong_iss is set to 1, which is the default, the ISS is calculated
169  * by adding three components: a time component which grows by 1 every 4096
170  * nanoseconds (versus every 4 microseconds suggested by RFC 793, page 27);
171  * a per-connection component which grows by 125000 for every new connection;
172  * and an "extra" component that grows by a random amount centered
173  * approximately on 64000.  This causes the ISS generator to cycle every
174  * 4.89 hours if no TCP connections are made, and faster if connections are
175  * made.
176  *
177  * When tcp_strong_iss is set to 0, ISS is calculated by adding two
178  * components: a time component which grows by 250000 every second; and
179  * a per-connection component which grows by 125000 for every new connections.
180  *
181  * A third method, when tcp_strong_iss is set to 2, for generating ISS is
182  * prescribed by Steve Bellovin.  This involves adding time, the 125000 per
183  * connection, and a one-way hash (MD5) of the connection ID <sport, dport,
184  * src, dst>, a "truly" random (per RFC 1750) number, and a console-entered
185  * password.
186  */
187 #define	ISS_INCR	250000
188 #define	ISS_NSEC_SHT	12
189 
190 /* Macros for timestamp comparisons */
191 #define	TSTMP_GEQ(a, b)	((int32_t)((a)-(b)) >= 0)
192 #define	TSTMP_LT(a, b)	((int32_t)((a)-(b)) < 0)
193 
194 /*
195  * Initialize cwnd according to RFC 3390.  def_max_init_cwnd is
196  * either tcp_slow_start_initial or tcp_slow_start_after idle
197  * depending on the caller.  If the upper layer has not used the
198  * TCP_INIT_CWND option to change the initial cwnd, tcp_init_cwnd
199  * should be 0 and we use the formula in RFC 3390 to set tcp_cwnd.
200  * If the upper layer has changed set the tcp_init_cwnd, just use
201  * it to calculate the tcp_cwnd.
202  */
203 #define	TCP_SET_INIT_CWND(tcp, mss, def_max_init_cwnd)			\
204 {									\
205 	if ((tcp)->tcp_init_cwnd == 0) {				\
206 		(tcp)->tcp_cwnd = MIN(def_max_init_cwnd * (mss),	\
207 		    MIN(4 * (mss), MAX(2 * (mss), 4380 / (mss) * (mss)))); \
208 	} else {							\
209 		(tcp)->tcp_cwnd = (tcp)->tcp_init_cwnd * (mss);		\
210 	}								\
211 	tcp->tcp_cwnd_cnt = 0;						\
212 }
213 
214 /*
215  * Set ECN capable transport (ECT) code point in IP header.
216  *
217  * Note that there are 2 ECT code points '01' and '10', which are called
218  * ECT(1) and ECT(0) respectively.  Here we follow the original ECT code
219  * point ECT(0) for TCP as described in RFC 2481.
220  */
221 #define	TCP_SET_ECT(tcp, iph) \
222 	if ((tcp)->tcp_connp->conn_ipversion == IPV4_VERSION) { \
223 		/* We need to clear the code point first. */ \
224 		((ipha_t *)(iph))->ipha_type_of_service &= 0xFC; \
225 		((ipha_t *)(iph))->ipha_type_of_service |= IPH_ECN_ECT0; \
226 	} else { \
227 		((ip6_t *)(iph))->ip6_vcf &= htonl(0xFFCFFFFF); \
228 		((ip6_t *)(iph))->ip6_vcf |= htonl(IPH_ECN_ECT0 << 20); \
229 	}
230 
231 /*
232  * TCP options struct returned from tcp_parse_options.
233  */
234 typedef struct tcp_opt_s {
235 	uint32_t	tcp_opt_mss;
236 	uint32_t	tcp_opt_wscale;
237 	uint32_t	tcp_opt_ts_val;
238 	uint32_t	tcp_opt_ts_ecr;
239 	tcp_t		*tcp;
240 } tcp_opt_t;
241 
242 /*
243  * Write-side flow-control is implemented via the per instance STREAMS
244  * write-side Q by explicitly setting QFULL to stop the flow of mblk_t(s)
245  * and clearing QFULL and calling qbackenable() to restart the flow based
246  * on the number of TCP unsent bytes (i.e. those not on the wire waiting
247  * for a remote ACK).
248  *
249  * This is different than a standard STREAMS kmod which when using the
250  * STREAMS Q the framework would automatictly flow-control based on the
251  * defined hiwat/lowat values as mblk_t's are enqueued/dequeued.
252  *
253  * As of FireEngine TCP write-side flow-control needs to take into account
254  * both the unsent tcp_xmit list bytes but also any squeue_t enqueued bytes
255  * (i.e. from tcp_wput() -> tcp_output()).
256  *
257  * This is accomplished by adding a new tcp_t fields, tcp_squeue_bytes, to
258  * count the number of bytes enqueued by tcp_wput() and the number of bytes
259  * dequeued and processed by tcp_output().
260  *
261  * So, the total number of bytes unsent is (squeue_bytes + unsent) with all
262  * flow-control uses of unsent replaced with the macro TCP_UNSENT_BYTES.
263  */
264 extern void	tcp_clrqfull(tcp_t *);
265 extern void	tcp_setqfull(tcp_t *);
266 
267 #define	TCP_UNSENT_BYTES(tcp) \
268 	((tcp)->tcp_squeue_bytes + (tcp)->tcp_unsent)
269 
270 /*
271  * Linked list struct to store listener connection limit configuration per
272  * IP stack.  The list is stored at tcps_listener_conf in tcp_stack_t.
273  *
274  * tl_port: the listener port of this limit configuration
275  * tl_ratio: the maximum amount of memory consumed by all concurrent TCP
276  *           connections created by a listener does not exceed 1/tl_ratio
277  *           of the total system memory.  Note that this is only an
278  *           approximation.
279  * tl_link: linked list struct
280  */
281 typedef struct tcp_listener_s {
282 	in_port_t	tl_port;
283 	uint32_t	tl_ratio;
284 	list_node_t	tl_link;
285 } tcp_listener_t;
286 
287 /*
288  * If there is a limit set on the number of connections allowed per each
289  * listener, the following struct is used to store that counter.  It keeps
290  * the number of TCP connection created by a listener.  Note that this needs
291  * to be separated from the listener since the listener can go away before
292  * all the connections are gone.
293  *
294  * When the struct is allocated, tlc_cnt is set to 1.  When a new connection
295  * is created by the listener, tlc_cnt is incremented by 1.  When a connection
296  * created by the listener goes away, tlc_count is decremented by 1.  When the
297  * listener itself goes away, tlc_cnt is decremented  by one.  The last
298  * connection (or the listener) which decrements tlc_cnt to zero frees the
299  * struct.
300  *
301  * tlc_max is the threshold value tcps_conn_listen_port.  It is set when the
302  * tcp_listen_cnt_t is allocated.
303  *
304  * tlc_report_time stores the time when cmn_err() is called to report that the
305  * max has been exceeeded.  Report is done at most once every
306  * TCP_TLC_REPORT_INTERVAL mins for a listener.
307  *
308  * tlc_drop stores the number of connection attempt dropped because the
309  * limit has reached.
310  */
311 typedef struct tcp_listen_cnt_s {
312 	uint32_t	tlc_max;
313 	uint32_t	tlc_cnt;
314 	int64_t		tlc_report_time;
315 	uint32_t	tlc_drop;
316 } tcp_listen_cnt_t;
317 
318 #define	TCP_TLC_REPORT_INTERVAL	(30 * MINUTES)
319 
320 #define	TCP_DECR_LISTEN_CNT(tcp)					\
321 {									\
322 	ASSERT((tcp)->tcp_listen_cnt->tlc_cnt > 0);			\
323 	if (atomic_add_32_nv(&(tcp)->tcp_listen_cnt->tlc_cnt, -1) == 0) \
324 		kmem_free((tcp)->tcp_listen_cnt, sizeof (tcp_listen_cnt_t)); \
325 	(tcp)->tcp_listen_cnt = NULL;					\
326 }
327 
328 /* Increment and decrement the number of connections in tcp_stack_t. */
329 #define	TCPS_CONN_INC(tcps)						\
330 	atomic_inc_64(							\
331 	    (uint64_t *)&(tcps)->tcps_sc[CPU->cpu_seqid]->tcp_sc_conn_cnt)
332 
333 #define	TCPS_CONN_DEC(tcps)						\
334 	atomic_dec_64(							\
335 	    (uint64_t *)&(tcps)->tcps_sc[CPU->cpu_seqid]->tcp_sc_conn_cnt)
336 
337 /*
338  * When the system is under memory pressure, stack variable tcps_reclaim is
339  * true, we shorten the connection timeout abort interval to tcp_early_abort
340  * seconds.  Defined in tcp.c.
341  */
342 extern uint32_t tcp_early_abort;
343 
344 /*
345  * To reach to an eager in Q0 which can be dropped due to an incoming
346  * new SYN request when Q0 is full, a new doubly linked list is
347  * introduced. This list allows to select an eager from Q0 in O(1) time.
348  * This is needed to avoid spending too much time walking through the
349  * long list of eagers in Q0 when tcp_drop_q0() is called. Each member of
350  * this new list has to be a member of Q0.
351  * This list is headed by listener's tcp_t. When the list is empty,
352  * both the pointers - tcp_eager_next_drop_q0 and tcp_eager_prev_drop_q0,
353  * of listener's tcp_t point to listener's tcp_t itself.
354  *
355  * Given an eager in Q0 and a listener, MAKE_DROPPABLE() puts the eager
356  * in the list. MAKE_UNDROPPABLE() takes the eager out of the list.
357  * These macros do not affect the eager's membership to Q0.
358  */
359 #define	MAKE_DROPPABLE(listener, eager)					\
360 	if ((eager)->tcp_eager_next_drop_q0 == NULL) {			\
361 		(listener)->tcp_eager_next_drop_q0->tcp_eager_prev_drop_q0\
362 		    = (eager);						\
363 		(eager)->tcp_eager_prev_drop_q0 = (listener);		\
364 		(eager)->tcp_eager_next_drop_q0 =			\
365 		    (listener)->tcp_eager_next_drop_q0;			\
366 		(listener)->tcp_eager_next_drop_q0 = (eager);		\
367 	}
368 
369 #define	MAKE_UNDROPPABLE(eager)						\
370 	if ((eager)->tcp_eager_next_drop_q0 != NULL) {			\
371 		(eager)->tcp_eager_next_drop_q0->tcp_eager_prev_drop_q0	\
372 		    = (eager)->tcp_eager_prev_drop_q0;			\
373 		(eager)->tcp_eager_prev_drop_q0->tcp_eager_next_drop_q0	\
374 		    = (eager)->tcp_eager_next_drop_q0;			\
375 		(eager)->tcp_eager_prev_drop_q0 = NULL;			\
376 		(eager)->tcp_eager_next_drop_q0 = NULL;			\
377 	}
378 
379 /*
380  * The format argument to pass to tcp_display().
381  * DISP_PORT_ONLY means that the returned string has only port info.
382  * DISP_ADDR_AND_PORT means that the returned string also contains the
383  * remote and local IP address.
384  */
385 #define	DISP_PORT_ONLY		1
386 #define	DISP_ADDR_AND_PORT	2
387 
388 #define	IP_ADDR_CACHE_SIZE	2048
389 #define	IP_ADDR_CACHE_HASH(faddr)					\
390 	(ntohl(faddr) & (IP_ADDR_CACHE_SIZE -1))
391 
392 /* TCP cwnd burst factor. */
393 #define	TCP_CWND_INFINITE	65535
394 #define	TCP_CWND_SS		3
395 #define	TCP_CWND_NORMAL		5
396 
397 /*
398  * TCP reassembly macros.  We hide starting and ending sequence numbers in
399  * b_next and b_prev of messages on the reassembly queue.  The messages are
400  * chained using b_cont.  These macros are used in tcp_reass() so we don't
401  * have to see the ugly casts and assignments.
402  */
403 #define	TCP_REASS_SEQ(mp)		((uint32_t)(uintptr_t)((mp)->b_next))
404 #define	TCP_REASS_SET_SEQ(mp, u)	((mp)->b_next = \
405 					(mblk_t *)(uintptr_t)(u))
406 #define	TCP_REASS_END(mp)		((uint32_t)(uintptr_t)((mp)->b_prev))
407 #define	TCP_REASS_SET_END(mp, u)	((mp)->b_prev = \
408 					(mblk_t *)(uintptr_t)(u))
409 
410 /* Named Dispatch Parameter Management Structure */
411 typedef struct tcpparam_s {
412 	uint32_t	tcp_param_min;
413 	uint32_t	tcp_param_max;
414 	uint32_t	tcp_param_val;
415 	char		*tcp_param_name;
416 } tcpparam_t;
417 
418 
419 #define	tcps_time_wait_interval		tcps_params[0].tcp_param_val
420 #define	tcps_conn_req_max_q		tcps_params[1].tcp_param_val
421 #define	tcps_conn_req_max_q0		tcps_params[2].tcp_param_val
422 #define	tcps_conn_req_min		tcps_params[3].tcp_param_val
423 #define	tcps_conn_grace_period		tcps_params[4].tcp_param_val
424 #define	tcps_cwnd_max_			tcps_params[5].tcp_param_val
425 #define	tcps_dbg			tcps_params[6].tcp_param_val
426 #define	tcps_smallest_nonpriv_port	tcps_params[7].tcp_param_val
427 #define	tcps_ip_abort_cinterval		tcps_params[8].tcp_param_val
428 #define	tcps_ip_abort_linterval		tcps_params[9].tcp_param_val
429 #define	tcps_ip_abort_interval		tcps_params[10].tcp_param_val
430 #define	tcps_ip_notify_cinterval	tcps_params[11].tcp_param_val
431 #define	tcps_ip_notify_interval		tcps_params[12].tcp_param_val
432 #define	tcps_ipv4_ttl			tcps_params[13].tcp_param_val
433 #define	tcps_keepalive_interval_high	tcps_params[14].tcp_param_max
434 #define	tcps_keepalive_interval		tcps_params[14].tcp_param_val
435 #define	tcps_keepalive_interval_low	tcps_params[14].tcp_param_min
436 #define	tcps_maxpsz_multiplier		tcps_params[15].tcp_param_val
437 #define	tcps_mss_def_ipv4		tcps_params[16].tcp_param_val
438 #define	tcps_mss_max_ipv4		tcps_params[17].tcp_param_val
439 #define	tcps_mss_min			tcps_params[18].tcp_param_val
440 #define	tcps_naglim_def			tcps_params[19].tcp_param_val
441 #define	tcps_rexmit_interval_initial	tcps_params[20].tcp_param_val
442 #define	tcps_rexmit_interval_max	tcps_params[21].tcp_param_val
443 #define	tcps_rexmit_interval_min	tcps_params[22].tcp_param_val
444 #define	tcps_deferred_ack_interval	tcps_params[23].tcp_param_val
445 #define	tcps_snd_lowat_fraction		tcps_params[24].tcp_param_val
446 #define	tcps_dupack_fast_retransmit	tcps_params[25].tcp_param_val
447 #define	tcps_ignore_path_mtu		tcps_params[26].tcp_param_val
448 #define	tcps_smallest_anon_port		tcps_params[27].tcp_param_val
449 #define	tcps_largest_anon_port		tcps_params[28].tcp_param_val
450 #define	tcps_xmit_hiwat			tcps_params[29].tcp_param_val
451 #define	tcps_xmit_lowat			tcps_params[30].tcp_param_val
452 #define	tcps_recv_hiwat			tcps_params[31].tcp_param_val
453 #define	tcps_recv_hiwat_minmss		tcps_params[32].tcp_param_val
454 #define	tcps_fin_wait_2_flush_interval	tcps_params[33].tcp_param_val
455 #define	tcps_max_buf			tcps_params[34].tcp_param_val
456 #define	tcps_strong_iss			tcps_params[35].tcp_param_val
457 #define	tcps_rtt_updates		tcps_params[36].tcp_param_val
458 #define	tcps_wscale_always		tcps_params[37].tcp_param_val
459 #define	tcps_tstamp_always		tcps_params[38].tcp_param_val
460 #define	tcps_tstamp_if_wscale		tcps_params[39].tcp_param_val
461 #define	tcps_rexmit_interval_extra	tcps_params[40].tcp_param_val
462 #define	tcps_deferred_acks_max		tcps_params[41].tcp_param_val
463 #define	tcps_slow_start_after_idle	tcps_params[42].tcp_param_val
464 #define	tcps_slow_start_initial		tcps_params[43].tcp_param_val
465 #define	tcps_sack_permitted		tcps_params[44].tcp_param_val
466 #define	tcps_ipv6_hoplimit		tcps_params[45].tcp_param_val
467 #define	tcps_mss_def_ipv6		tcps_params[46].tcp_param_val
468 #define	tcps_mss_max_ipv6		tcps_params[47].tcp_param_val
469 #define	tcps_rev_src_routes		tcps_params[48].tcp_param_val
470 #define	tcps_local_dack_interval	tcps_params[49].tcp_param_val
471 #define	tcps_local_dacks_max		tcps_params[50].tcp_param_val
472 #define	tcps_ecn_permitted		tcps_params[51].tcp_param_val
473 #define	tcps_rst_sent_rate_enabled	tcps_params[52].tcp_param_val
474 #define	tcps_rst_sent_rate		tcps_params[53].tcp_param_val
475 #define	tcps_push_timer_interval	tcps_params[54].tcp_param_val
476 #define	tcps_use_smss_as_mss_opt	tcps_params[55].tcp_param_val
477 #define	tcps_keepalive_abort_interval_high	tcps_params[56].tcp_param_max
478 #define	tcps_keepalive_abort_interval		tcps_params[56].tcp_param_val
479 #define	tcps_keepalive_abort_interval_low	tcps_params[56].tcp_param_min
480 #define	tcps_dev_flow_ctl		tcps_params[57].tcp_param_val
481 #define	tcps_reass_timeout		tcps_params[58].tcp_param_val
482 
483 #define	tcps_wroff_xtra	tcps_wroff_xtra_param->tcp_param_val
484 
485 extern struct qinit tcp_rinitv4, tcp_rinitv6;
486 extern boolean_t do_tcp_fusion;
487 
488 /*
489  * Object to represent database of options to search passed to
490  * {sock,tpi}optcom_req() interface routine to take care of option
491  * management and associated methods.
492  */
493 extern optdb_obj_t	tcp_opt_obj;
494 extern uint_t		tcp_max_optsize;
495 
496 extern int tcp_squeue_flag;
497 
498 extern uint_t tcp_free_list_max_cnt;
499 
500 /*
501  * Functions in tcp.c.
502  */
503 extern int	tcp_accept_common(conn_t *, conn_t *, cred_t *);
504 extern void	tcp_accept_finish(void *, mblk_t *, void *, ip_recv_attr_t *);
505 extern void	tcp_acceptor_hash_insert(t_uscalar_t, tcp_t *);
506 extern tcp_t	*tcp_acceptor_hash_lookup(t_uscalar_t, tcp_stack_t *);
507 extern void	tcp_acceptor_hash_remove(tcp_t *);
508 extern mblk_t	*tcp_ack_mp(tcp_t *);
509 extern int	tcp_build_hdrs(tcp_t *);
510 extern void	tcp_cleanup(tcp_t *);
511 extern int	tcp_clean_death(tcp_t *, int);
512 extern void	tcp_clean_death_wrapper(void *, mblk_t *, void *,
513 		    ip_recv_attr_t *);
514 extern void	tcp_close_common(conn_t *, int);
515 extern void	tcp_close_detached(tcp_t *);
516 extern void	tcp_close_mpp(mblk_t **);
517 extern void	tcp_closei_local(tcp_t *);
518 extern sock_lower_handle_t tcp_create(int, int, int, sock_downcalls_t **,
519 		    uint_t *, int *, int, cred_t *);
520 extern conn_t	*tcp_create_common(cred_t *, boolean_t, boolean_t, int *);
521 extern void	tcp_disconnect(tcp_t *, mblk_t *);
522 extern char	*tcp_display(tcp_t *, char *, char);
523 extern int	tcp_do_bind(conn_t *, struct sockaddr *, socklen_t, cred_t *,
524 		    boolean_t);
525 extern int	tcp_do_connect(conn_t *, const struct sockaddr *, socklen_t,
526 		    cred_t *, pid_t);
527 extern int	tcp_do_listen(conn_t *, struct sockaddr *, socklen_t, int,
528 		    cred_t *, boolean_t);
529 extern int	tcp_do_unbind(conn_t *);
530 extern boolean_t	tcp_eager_blowoff(tcp_t *, t_scalar_t);
531 extern void	tcp_eager_cleanup(tcp_t *, boolean_t);
532 extern void	tcp_eager_kill(void *, mblk_t *, void *, ip_recv_attr_t *);
533 extern void	tcp_eager_unlink(tcp_t *);
534 extern int	tcp_getpeername(sock_lower_handle_t, struct sockaddr *,
535 		    socklen_t *, cred_t *);
536 extern int	tcp_getsockname(sock_lower_handle_t, struct sockaddr *,
537 		    socklen_t *, cred_t *);
538 extern void	tcp_init_values(tcp_t *);
539 extern void	tcp_ipsec_cleanup(tcp_t *);
540 extern int	tcp_maxpsz_set(tcp_t *, boolean_t);
541 extern void	tcp_mss_set(tcp_t *, uint32_t);
542 extern void	tcp_reinput(conn_t *, mblk_t *, ip_recv_attr_t *, ip_stack_t *);
543 extern void	tcp_rsrv(queue_t *);
544 extern uint_t	tcp_rwnd_reopen(tcp_t *);
545 extern int	tcp_rwnd_set(tcp_t *, uint32_t);
546 extern int	tcp_set_destination(tcp_t *);
547 extern void	tcp_set_ws_value(tcp_t *);
548 extern void	tcp_stop_lingering(tcp_t *);
549 extern void	tcp_update_pmtu(tcp_t *, boolean_t);
550 extern mblk_t	*tcp_zcopy_backoff(tcp_t *, mblk_t *, boolean_t);
551 extern boolean_t	tcp_zcopy_check(tcp_t *);
552 extern void	tcp_zcopy_notify(tcp_t *);
553 
554 /*
555  * Bind related functions in tcp_bind.c
556  */
557 extern int	tcp_bind_check(conn_t *, struct sockaddr *, socklen_t,
558 		    cred_t *, boolean_t);
559 extern void	tcp_bind_hash_insert(tf_t *, tcp_t *, int);
560 extern void	tcp_bind_hash_remove(tcp_t *);
561 extern in_port_t	tcp_bindi(tcp_t *, in_port_t, const in6_addr_t *,
562 			    int, boolean_t, boolean_t, boolean_t);
563 extern in_port_t	tcp_update_next_port(in_port_t, const tcp_t *,
564 			    boolean_t);
565 
566 /*
567  * Fusion related functions in tcp_fusion.c.
568  */
569 extern void	tcp_fuse(tcp_t *, uchar_t *, tcpha_t *);
570 extern void	tcp_unfuse(tcp_t *);
571 extern boolean_t tcp_fuse_output(tcp_t *, mblk_t *, uint32_t);
572 extern void	tcp_fuse_output_urg(tcp_t *, mblk_t *);
573 extern boolean_t tcp_fuse_rcv_drain(queue_t *, tcp_t *, mblk_t **);
574 extern size_t	tcp_fuse_set_rcv_hiwat(tcp_t *, size_t);
575 extern int	tcp_fuse_maxpsz(tcp_t *);
576 extern void	tcp_fuse_backenable(tcp_t *);
577 
578 /*
579  * Output related functions in tcp_output.c.
580  */
581 extern void	tcp_close_output(void *, mblk_t *, void *, ip_recv_attr_t *);
582 extern void	tcp_output(void *, mblk_t *, void *, ip_recv_attr_t *);
583 extern void	tcp_output_urgent(void *, mblk_t *, void *, ip_recv_attr_t *);
584 extern void	tcp_rexmit_after_error(tcp_t *);
585 extern void	tcp_sack_rexmit(tcp_t *, uint_t *);
586 extern void	tcp_send_data(tcp_t *, mblk_t *);
587 extern void	tcp_send_synack(void *, mblk_t *, void *, ip_recv_attr_t *);
588 extern void	tcp_shutdown_output(void *, mblk_t *, void *, ip_recv_attr_t *);
589 extern void	tcp_ss_rexmit(tcp_t *);
590 extern void	tcp_update_xmit_tail(tcp_t *, uint32_t);
591 extern void	tcp_wput(queue_t *, mblk_t *);
592 extern void	tcp_wput_data(tcp_t *, mblk_t *, boolean_t);
593 extern void	tcp_wput_sock(queue_t *, mblk_t *);
594 extern void	tcp_wput_fallback(queue_t *, mblk_t *);
595 extern void	tcp_xmit_ctl(char *, tcp_t *, uint32_t, uint32_t, int);
596 extern void	tcp_xmit_listeners_reset(mblk_t *, ip_recv_attr_t *,
597 		    ip_stack_t *i, conn_t *);
598 extern mblk_t	*tcp_xmit_mp(tcp_t *, mblk_t *, int32_t, int32_t *,
599 		    mblk_t **, uint32_t, boolean_t, uint32_t *, boolean_t);
600 
601 /*
602  * Input related functions in tcp_input.c.
603  */
604 extern void	tcp_icmp_input(void *, mblk_t *, void *, ip_recv_attr_t *);
605 extern void	tcp_input_data(void *, mblk_t *, void *, ip_recv_attr_t *);
606 extern void	tcp_input_listener_unbound(void *, mblk_t *, void *,
607 		    ip_recv_attr_t *);
608 extern boolean_t	tcp_paws_check(tcp_t *, tcpha_t *, tcp_opt_t *);
609 extern uint_t	tcp_rcv_drain(tcp_t *);
610 extern void	tcp_rcv_enqueue(tcp_t *, mblk_t *, uint_t, cred_t *);
611 extern boolean_t	tcp_verifyicmp(conn_t *, void *, icmph_t *, icmp6_t *,
612 			    ip_recv_attr_t *);
613 
614 /*
615  * Kernel socket related functions in tcp_socket.c.
616  */
617 extern int tcp_fallback(sock_lower_handle_t, queue_t *, boolean_t,
618     so_proto_quiesced_cb_t);
619 
620 /*
621  * Timer related functions in tcp_timers.c.
622  */
623 extern void	tcp_ack_timer(void *);
624 extern void	tcp_close_linger_timeout(void *);
625 extern void	tcp_keepalive_timer(void *);
626 extern void	tcp_push_timer(void *);
627 extern void	tcp_reass_timer(void *);
628 extern mblk_t	*tcp_timermp_alloc(int);
629 extern void	tcp_timermp_free(tcp_t *);
630 extern timeout_id_t tcp_timeout(conn_t *, void (*)(void *), clock_t);
631 extern clock_t	tcp_timeout_cancel(conn_t *, timeout_id_t);
632 extern void	tcp_timer(void *arg);
633 extern void	tcp_timers_stop(tcp_t *);
634 
635 /*
636  * TCP TPI related functions in tcp_tpi.c.
637  */
638 extern void	tcp_addr_req(tcp_t *, mblk_t *);
639 extern void	tcp_capability_req(tcp_t *, mblk_t *);
640 extern boolean_t	tcp_conn_con(tcp_t *, uchar_t *, mblk_t *,
641 			    mblk_t **, ip_recv_attr_t *);
642 extern void	tcp_err_ack(tcp_t *, mblk_t *, int, int);
643 extern void	tcp_err_ack_prim(tcp_t *, mblk_t *, int, int, int);
644 extern void	tcp_fallback_eager(tcp_t *, boolean_t);
645 extern void	tcp_fallback_noneager(tcp_t *, mblk_t *, queue_t *,
646 		    boolean_t, so_proto_quiesced_cb_t);
647 extern void	tcp_info_req(tcp_t *, mblk_t *);
648 extern void	tcp_send_conn_ind(void *, mblk_t *, void *);
649 extern void	tcp_send_pending(void *, mblk_t *, void *, ip_recv_attr_t *);
650 extern void	tcp_tpi_accept(queue_t *, mblk_t *);
651 extern void	tcp_tpi_bind(tcp_t *, mblk_t *);
652 extern int	tcp_tpi_close(queue_t *, int);
653 extern int	tcp_tpi_close_accept(queue_t *);
654 extern void	tcp_tpi_connect(tcp_t *, mblk_t *);
655 extern int	tcp_tpi_opt_get(queue_t *, t_scalar_t, t_scalar_t, uchar_t *);
656 extern int	tcp_tpi_opt_set(queue_t *, uint_t, int, int, uint_t, uchar_t *,
657 		    uint_t *, uchar_t *, void *, cred_t *);
658 extern void	tcp_tpi_unbind(tcp_t *, mblk_t *);
659 extern void	tcp_tli_accept(tcp_t *, mblk_t *);
660 extern void	tcp_use_pure_tpi(tcp_t *);
661 
662 /*
663  * TCP option processing related functions in tcp_opt_data.c
664  */
665 extern int	tcp_opt_default(queue_t *, t_scalar_t, t_scalar_t, uchar_t *);
666 extern int	tcp_opt_get(conn_t *, int, int, uchar_t *);
667 extern int	tcp_opt_set(conn_t *, uint_t, int, int, uint_t, uchar_t *,
668 		    uint_t *, uchar_t *, void *, cred_t *);
669 
670 /*
671  * TCP time wait processing related functions in tcp_time_wait.c.
672  */
673 extern void		tcp_time_wait_append(tcp_t *);
674 extern void		tcp_time_wait_collector(void *);
675 extern boolean_t	tcp_time_wait_remove(tcp_t *, tcp_squeue_priv_t *);
676 extern void		tcp_time_wait_processing(tcp_t *, mblk_t *, uint32_t,
677 			    uint32_t, int, tcpha_t *, ip_recv_attr_t *);
678 
679 /*
680  * Misc functions in tcp_misc.c.
681  */
682 extern int	tcp_cpu_update(cpu_setup_t, int, void *);
683 extern void	tcp_ioctl_abort_conn(queue_t *, mblk_t *);
684 extern uint32_t	tcp_find_listener_conf(tcp_stack_t *, in_port_t);
685 extern int	tcp_listener_conf_get(queue_t *, mblk_t *, caddr_t, cred_t *);
686 extern int	tcp_listener_conf_add(queue_t *, mblk_t *, char *, caddr_t,
687 		    cred_t *);
688 extern int	tcp_listener_conf_del(queue_t *, mblk_t *, char *, caddr_t,
689 		    cred_t *);
690 extern void	tcp_listener_conf_cleanup(tcp_stack_t *);
691 
692 #endif	/* _KERNEL */
693 
694 #ifdef	__cplusplus
695 }
696 #endif
697 
698 #endif	/* _INET_TCP_IMPL_H */
699