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