xref: /onnv-gate/usr/src/uts/common/inet/tcp_impl.h (revision 12869:fb36eaeb6ee0)
1741Smasputra /*
2741Smasputra  * CDDL HEADER START
3741Smasputra  *
4741Smasputra  * The contents of this file are subject to the terms of the
52578Smeem  * Common Development and Distribution License (the "License").
62578Smeem  * You may not use this file except in compliance with the License.
7741Smasputra  *
8741Smasputra  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9741Smasputra  * or http://www.opensolaris.org/os/licensing.
10741Smasputra  * See the License for the specific language governing permissions
11741Smasputra  * and limitations under the License.
12741Smasputra  *
13741Smasputra  * When distributing Covered Code, include this CDDL HEADER in each
14741Smasputra  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15741Smasputra  * If applicable, add the following below this CDDL HEADER, with the
16741Smasputra  * fields enclosed by brackets "[]" replaced with your own identifying
17741Smasputra  * information: Portions Copyright [yyyy] [name of copyright owner]
18741Smasputra  *
19741Smasputra  * CDDL HEADER END
20741Smasputra  */
21741Smasputra /*
2212056SKacheong.Poon@Sun.COM  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23741Smasputra  */
24741Smasputra 
25741Smasputra #ifndef	_INET_TCP_IMPL_H
26741Smasputra #define	_INET_TCP_IMPL_H
27741Smasputra 
28741Smasputra /*
29741Smasputra  * TCP implementation private declarations.  These interfaces are
30741Smasputra  * used to build the IP module and are not meant to be accessed
31741Smasputra  * by any modules except IP itself.  They are undocumented and are
32741Smasputra  * subject to change without notice.
33741Smasputra  */
34741Smasputra 
35741Smasputra #ifdef	__cplusplus
36741Smasputra extern "C" {
37741Smasputra #endif
38741Smasputra 
39741Smasputra #ifdef _KERNEL
40741Smasputra 
4111754SKacheong.Poon@Sun.COM #include <sys/cpuvar.h>
4211754SKacheong.Poon@Sun.COM #include <sys/clock_impl.h>	/* For LBOLT_FASTPATH{,64} */
438348SEric.Yu@Sun.COM #include <inet/optcom.h>
44741Smasputra #include <inet/tcp.h>
4512016SGirish.Moodalbail@Sun.COM #include <inet/tunables.h>
46741Smasputra 
47741Smasputra #define	TCP_MOD_ID	5105
48741Smasputra 
4911754SKacheong.Poon@Sun.COM extern struct qinit	tcp_sock_winit;
5011754SKacheong.Poon@Sun.COM extern struct qinit	tcp_winit;
5111754SKacheong.Poon@Sun.COM 
5211754SKacheong.Poon@Sun.COM extern sock_downcalls_t sock_tcp_downcalls;
5311754SKacheong.Poon@Sun.COM 
5411754SKacheong.Poon@Sun.COM /*
5511754SKacheong.Poon@Sun.COM  * Bind hash list size and has function.  It has to be a power of 2 for
5611754SKacheong.Poon@Sun.COM  * hashing.
5711754SKacheong.Poon@Sun.COM  */
5811754SKacheong.Poon@Sun.COM #define	TCP_BIND_FANOUT_SIZE	512
5911754SKacheong.Poon@Sun.COM #define	TCP_BIND_HASH(lport) (ntohs(lport) & (TCP_BIND_FANOUT_SIZE - 1))
6011754SKacheong.Poon@Sun.COM 
6111754SKacheong.Poon@Sun.COM /*
6211754SKacheong.Poon@Sun.COM  * This implementation follows the 4.3BSD interpretation of the urgent
6311754SKacheong.Poon@Sun.COM  * pointer and not RFC 1122. Switching to RFC 1122 behavior would cause
6411754SKacheong.Poon@Sun.COM  * incompatible changes in protocols like telnet and rlogin.
6511754SKacheong.Poon@Sun.COM  */
6611754SKacheong.Poon@Sun.COM #define	TCP_OLD_URP_INTERPRETATION	1
6711754SKacheong.Poon@Sun.COM 
6811754SKacheong.Poon@Sun.COM /* TCP option length */
6911754SKacheong.Poon@Sun.COM #define	TCPOPT_NOP_LEN		1
7011754SKacheong.Poon@Sun.COM #define	TCPOPT_MAXSEG_LEN	4
7111754SKacheong.Poon@Sun.COM #define	TCPOPT_WS_LEN		3
7211754SKacheong.Poon@Sun.COM #define	TCPOPT_REAL_WS_LEN	(TCPOPT_WS_LEN+1)
7311754SKacheong.Poon@Sun.COM #define	TCPOPT_TSTAMP_LEN	10
7411754SKacheong.Poon@Sun.COM #define	TCPOPT_REAL_TS_LEN	(TCPOPT_TSTAMP_LEN+2)
7511754SKacheong.Poon@Sun.COM #define	TCPOPT_SACK_OK_LEN	2
7611754SKacheong.Poon@Sun.COM #define	TCPOPT_REAL_SACK_OK_LEN	(TCPOPT_SACK_OK_LEN+2)
7711754SKacheong.Poon@Sun.COM #define	TCPOPT_REAL_SACK_LEN	4
7811754SKacheong.Poon@Sun.COM #define	TCPOPT_MAX_SACK_LEN	36
7911754SKacheong.Poon@Sun.COM #define	TCPOPT_HEADER_LEN	2
8011754SKacheong.Poon@Sun.COM 
8111754SKacheong.Poon@Sun.COM /* Round up the value to the nearest mss. */
8211754SKacheong.Poon@Sun.COM #define	MSS_ROUNDUP(value, mss)		((((value) - 1) / (mss) + 1) * (mss))
8311754SKacheong.Poon@Sun.COM 
84741Smasputra /*
85741Smasputra  * Was this tcp created via socket() interface?
86741Smasputra  */
87741Smasputra #define	TCP_IS_SOCKET(tcp)	((tcp)->tcp_issocket)
88741Smasputra 
89741Smasputra /*
90741Smasputra  * Is this tcp not attached to any upper client?
91741Smasputra  */
92741Smasputra #define	TCP_IS_DETACHED(tcp)	((tcp)->tcp_detached)
93741Smasputra 
9411754SKacheong.Poon@Sun.COM /* TCP timers related data strucutres.  Refer to tcp_timers.c. */
9511754SKacheong.Poon@Sun.COM typedef struct tcp_timer_s {
9611754SKacheong.Poon@Sun.COM 	conn_t	*connp;
9711754SKacheong.Poon@Sun.COM 	void 	(*tcpt_proc)(void *);
9811754SKacheong.Poon@Sun.COM 	callout_id_t   tcpt_tid;
9911754SKacheong.Poon@Sun.COM } tcp_timer_t;
10011754SKacheong.Poon@Sun.COM 
10111754SKacheong.Poon@Sun.COM extern kmem_cache_t *tcp_timercache;
10211754SKacheong.Poon@Sun.COM 
10311754SKacheong.Poon@Sun.COM /*
10411754SKacheong.Poon@Sun.COM  * Macro for starting various timers.  Retransmission timer has its own macro,
10512056SKacheong.Poon@Sun.COM  * TCP_TIMER_RESTART().  tim is in millisec.
10611754SKacheong.Poon@Sun.COM  */
107741Smasputra #define	TCP_TIMER(tcp, f, tim)		\
108741Smasputra 	tcp_timeout(tcp->tcp_connp, f, tim)
109741Smasputra #define	TCP_TIMER_CANCEL(tcp, id)	\
110741Smasputra 	tcp_timeout_cancel(tcp->tcp_connp, id)
111741Smasputra 
112741Smasputra /*
11312056SKacheong.Poon@Sun.COM  * To restart the TCP retransmission timer.  intvl is in millisec.
114741Smasputra  */
115741Smasputra #define	TCP_TIMER_RESTART(tcp, intvl) {					\
116741Smasputra 	if ((tcp)->tcp_timer_tid != 0)					\
117741Smasputra 		(void) TCP_TIMER_CANCEL((tcp), (tcp)->tcp_timer_tid);	\
11812056SKacheong.Poon@Sun.COM 	(tcp)->tcp_timer_tid = TCP_TIMER((tcp), tcp_timer, (intvl));	\
119741Smasputra }
120741Smasputra 
121741Smasputra /*
12211754SKacheong.Poon@Sun.COM  * For scalability, we must not run a timer for every TCP connection
12311754SKacheong.Poon@Sun.COM  * in TIME_WAIT state.  To see why, consider (for time wait interval of
12411754SKacheong.Poon@Sun.COM  * 1 minutes):
12511754SKacheong.Poon@Sun.COM  *	10,000 connections/sec * 60 seconds/time wait = 600,000 active conn's
12611754SKacheong.Poon@Sun.COM  *
12711754SKacheong.Poon@Sun.COM  * This list is ordered by time, so you need only delete from the head
12811754SKacheong.Poon@Sun.COM  * until you get to entries which aren't old enough to delete yet.
12911754SKacheong.Poon@Sun.COM  * The list consists of only the detached TIME_WAIT connections.
13011754SKacheong.Poon@Sun.COM  *
13111754SKacheong.Poon@Sun.COM  * When a tcp_t enters TIME_WAIT state, a timer is started (timeout is
13211754SKacheong.Poon@Sun.COM  * tcps_time_wait_interval).  When the tcp_t is detached (upper layer closes
13311754SKacheong.Poon@Sun.COM  * the end point), it is moved to the time wait list and another timer is
13411754SKacheong.Poon@Sun.COM  * started (expiry time is set at tcp_time_wait_expire, which is
13511754SKacheong.Poon@Sun.COM  * also calculated using tcps_time_wait_interval).  This means that the
13611754SKacheong.Poon@Sun.COM  * TIME_WAIT state can be extended (up to doubled) if the tcp_t doesn't
13711754SKacheong.Poon@Sun.COM  * become detached for a long time.
13811754SKacheong.Poon@Sun.COM  *
13911754SKacheong.Poon@Sun.COM  * The list manipulations (including tcp_time_wait_next/prev)
14011754SKacheong.Poon@Sun.COM  * are protected by the tcp_time_wait_lock. The content of the
14111754SKacheong.Poon@Sun.COM  * detached TIME_WAIT connections is protected by the normal perimeters.
14211754SKacheong.Poon@Sun.COM  *
14311754SKacheong.Poon@Sun.COM  * This list is per squeue and squeues are shared across the tcp_stack_t's.
14411754SKacheong.Poon@Sun.COM  * Things on tcp_time_wait_head remain associated with the tcp_stack_t
14511754SKacheong.Poon@Sun.COM  * and conn_netstack.
14611754SKacheong.Poon@Sun.COM  * The tcp_t's that are added to tcp_free_list are disassociated and
14711754SKacheong.Poon@Sun.COM  * have NULL tcp_tcps and conn_netstack pointers.
14811754SKacheong.Poon@Sun.COM  */
14911754SKacheong.Poon@Sun.COM typedef struct tcp_squeue_priv_s {
15011754SKacheong.Poon@Sun.COM 	kmutex_t	tcp_time_wait_lock;
15111754SKacheong.Poon@Sun.COM 	callout_id_t	tcp_time_wait_tid;
15211754SKacheong.Poon@Sun.COM 	tcp_t		*tcp_time_wait_head;
15311754SKacheong.Poon@Sun.COM 	tcp_t		*tcp_time_wait_tail;
15411754SKacheong.Poon@Sun.COM 	tcp_t		*tcp_free_list;
15511754SKacheong.Poon@Sun.COM 	uint_t		tcp_free_list_cnt;
15612175SKacheong.Poon@Sun.COM #ifdef DEBUG
15712175SKacheong.Poon@Sun.COM 	/*
15812175SKacheong.Poon@Sun.COM 	 * For debugging purpose, true when tcp_time_wait_collector() is
15912175SKacheong.Poon@Sun.COM 	 * running.
16012175SKacheong.Poon@Sun.COM 	 */
16112175SKacheong.Poon@Sun.COM 	boolean_t	tcp_time_wait_running;
16212175SKacheong.Poon@Sun.COM #endif
16311754SKacheong.Poon@Sun.COM } tcp_squeue_priv_t;
16411754SKacheong.Poon@Sun.COM 
16511754SKacheong.Poon@Sun.COM /*
16611754SKacheong.Poon@Sun.COM  * Parameters for TCP Initial Send Sequence number (ISS) generation.  When
16711754SKacheong.Poon@Sun.COM  * tcp_strong_iss is set to 1, which is the default, the ISS is calculated
16811754SKacheong.Poon@Sun.COM  * by adding three components: a time component which grows by 1 every 4096
16911754SKacheong.Poon@Sun.COM  * nanoseconds (versus every 4 microseconds suggested by RFC 793, page 27);
17011754SKacheong.Poon@Sun.COM  * a per-connection component which grows by 125000 for every new connection;
17111754SKacheong.Poon@Sun.COM  * and an "extra" component that grows by a random amount centered
17211754SKacheong.Poon@Sun.COM  * approximately on 64000.  This causes the ISS generator to cycle every
17311754SKacheong.Poon@Sun.COM  * 4.89 hours if no TCP connections are made, and faster if connections are
17411754SKacheong.Poon@Sun.COM  * made.
17511754SKacheong.Poon@Sun.COM  *
17611754SKacheong.Poon@Sun.COM  * When tcp_strong_iss is set to 0, ISS is calculated by adding two
17711754SKacheong.Poon@Sun.COM  * components: a time component which grows by 250000 every second; and
17811754SKacheong.Poon@Sun.COM  * a per-connection component which grows by 125000 for every new connections.
17911754SKacheong.Poon@Sun.COM  *
18011754SKacheong.Poon@Sun.COM  * A third method, when tcp_strong_iss is set to 2, for generating ISS is
18111754SKacheong.Poon@Sun.COM  * prescribed by Steve Bellovin.  This involves adding time, the 125000 per
18211754SKacheong.Poon@Sun.COM  * connection, and a one-way hash (MD5) of the connection ID <sport, dport,
18311754SKacheong.Poon@Sun.COM  * src, dst>, a "truly" random (per RFC 1750) number, and a console-entered
18411754SKacheong.Poon@Sun.COM  * password.
18511754SKacheong.Poon@Sun.COM  */
18611754SKacheong.Poon@Sun.COM #define	ISS_INCR	250000
18711754SKacheong.Poon@Sun.COM #define	ISS_NSEC_SHT	12
18811754SKacheong.Poon@Sun.COM 
18911754SKacheong.Poon@Sun.COM /* Macros for timestamp comparisons */
19011754SKacheong.Poon@Sun.COM #define	TSTMP_GEQ(a, b)	((int32_t)((a)-(b)) >= 0)
19111754SKacheong.Poon@Sun.COM #define	TSTMP_LT(a, b)	((int32_t)((a)-(b)) < 0)
19211754SKacheong.Poon@Sun.COM 
19311754SKacheong.Poon@Sun.COM /*
19411754SKacheong.Poon@Sun.COM  * Initialize cwnd according to RFC 3390.  def_max_init_cwnd is
19511754SKacheong.Poon@Sun.COM  * either tcp_slow_start_initial or tcp_slow_start_after idle
19611754SKacheong.Poon@Sun.COM  * depending on the caller.  If the upper layer has not used the
19711754SKacheong.Poon@Sun.COM  * TCP_INIT_CWND option to change the initial cwnd, tcp_init_cwnd
19811754SKacheong.Poon@Sun.COM  * should be 0 and we use the formula in RFC 3390 to set tcp_cwnd.
19911754SKacheong.Poon@Sun.COM  * If the upper layer has changed set the tcp_init_cwnd, just use
20011754SKacheong.Poon@Sun.COM  * it to calculate the tcp_cwnd.
20111754SKacheong.Poon@Sun.COM  */
20211754SKacheong.Poon@Sun.COM #define	TCP_SET_INIT_CWND(tcp, mss, def_max_init_cwnd)			\
20311754SKacheong.Poon@Sun.COM {									\
20411754SKacheong.Poon@Sun.COM 	if ((tcp)->tcp_init_cwnd == 0) {				\
20511754SKacheong.Poon@Sun.COM 		(tcp)->tcp_cwnd = MIN(def_max_init_cwnd * (mss),	\
20611754SKacheong.Poon@Sun.COM 		    MIN(4 * (mss), MAX(2 * (mss), 4380 / (mss) * (mss)))); \
20711754SKacheong.Poon@Sun.COM 	} else {							\
20811754SKacheong.Poon@Sun.COM 		(tcp)->tcp_cwnd = (tcp)->tcp_init_cwnd * (mss);		\
20911754SKacheong.Poon@Sun.COM 	}								\
21011754SKacheong.Poon@Sun.COM 	tcp->tcp_cwnd_cnt = 0;						\
21111754SKacheong.Poon@Sun.COM }
21211754SKacheong.Poon@Sun.COM 
21311754SKacheong.Poon@Sun.COM /*
21411754SKacheong.Poon@Sun.COM  * Set ECN capable transport (ECT) code point in IP header.
21511754SKacheong.Poon@Sun.COM  *
21611754SKacheong.Poon@Sun.COM  * Note that there are 2 ECT code points '01' and '10', which are called
21711754SKacheong.Poon@Sun.COM  * ECT(1) and ECT(0) respectively.  Here we follow the original ECT code
21811754SKacheong.Poon@Sun.COM  * point ECT(0) for TCP as described in RFC 2481.
21911754SKacheong.Poon@Sun.COM  */
22011754SKacheong.Poon@Sun.COM #define	TCP_SET_ECT(tcp, iph) \
22111754SKacheong.Poon@Sun.COM 	if ((tcp)->tcp_connp->conn_ipversion == IPV4_VERSION) { \
22211754SKacheong.Poon@Sun.COM 		/* We need to clear the code point first. */ \
22311754SKacheong.Poon@Sun.COM 		((ipha_t *)(iph))->ipha_type_of_service &= 0xFC; \
22411754SKacheong.Poon@Sun.COM 		((ipha_t *)(iph))->ipha_type_of_service |= IPH_ECN_ECT0; \
22511754SKacheong.Poon@Sun.COM 	} else { \
22611754SKacheong.Poon@Sun.COM 		((ip6_t *)(iph))->ip6_vcf &= htonl(0xFFCFFFFF); \
22711754SKacheong.Poon@Sun.COM 		((ip6_t *)(iph))->ip6_vcf |= htonl(IPH_ECN_ECT0 << 20); \
22811754SKacheong.Poon@Sun.COM 	}
22911754SKacheong.Poon@Sun.COM 
23011754SKacheong.Poon@Sun.COM /*
23112544SKacheong.Poon@Sun.COM  * Set tcp_rto with boundary checking.
23212544SKacheong.Poon@Sun.COM  */
23312544SKacheong.Poon@Sun.COM #define	TCP_SET_RTO(tcp, rto) \
23412544SKacheong.Poon@Sun.COM 	if ((rto) < (tcp)->tcp_rto_min)			\
23512544SKacheong.Poon@Sun.COM 		(tcp)->tcp_rto = (tcp)->tcp_rto_min;	\
23612544SKacheong.Poon@Sun.COM 	else if ((rto) > (tcp)->tcp_rto_max)		\
23712544SKacheong.Poon@Sun.COM 		(tcp)->tcp_rto = (tcp)->tcp_rto_max;	\
23812544SKacheong.Poon@Sun.COM 	else						\
23912544SKacheong.Poon@Sun.COM 		(tcp)->tcp_rto = (rto);
24012544SKacheong.Poon@Sun.COM 
24112544SKacheong.Poon@Sun.COM /*
24211754SKacheong.Poon@Sun.COM  * TCP options struct returned from tcp_parse_options.
24311754SKacheong.Poon@Sun.COM  */
24411754SKacheong.Poon@Sun.COM typedef struct tcp_opt_s {
24511754SKacheong.Poon@Sun.COM 	uint32_t	tcp_opt_mss;
24611754SKacheong.Poon@Sun.COM 	uint32_t	tcp_opt_wscale;
24711754SKacheong.Poon@Sun.COM 	uint32_t	tcp_opt_ts_val;
24811754SKacheong.Poon@Sun.COM 	uint32_t	tcp_opt_ts_ecr;
24911754SKacheong.Poon@Sun.COM 	tcp_t		*tcp;
25011754SKacheong.Poon@Sun.COM } tcp_opt_t;
25111754SKacheong.Poon@Sun.COM 
25211754SKacheong.Poon@Sun.COM /*
253741Smasputra  * Write-side flow-control is implemented via the per instance STREAMS
254741Smasputra  * write-side Q by explicitly setting QFULL to stop the flow of mblk_t(s)
255741Smasputra  * and clearing QFULL and calling qbackenable() to restart the flow based
256741Smasputra  * on the number of TCP unsent bytes (i.e. those not on the wire waiting
257741Smasputra  * for a remote ACK).
258741Smasputra  *
259741Smasputra  * This is different than a standard STREAMS kmod which when using the
260741Smasputra  * STREAMS Q the framework would automatictly flow-control based on the
261741Smasputra  * defined hiwat/lowat values as mblk_t's are enqueued/dequeued.
262741Smasputra  *
263741Smasputra  * As of FireEngine TCP write-side flow-control needs to take into account
264741Smasputra  * both the unsent tcp_xmit list bytes but also any squeue_t enqueued bytes
265741Smasputra  * (i.e. from tcp_wput() -> tcp_output()).
266741Smasputra  *
267741Smasputra  * This is accomplished by adding a new tcp_t fields, tcp_squeue_bytes, to
268741Smasputra  * count the number of bytes enqueued by tcp_wput() and the number of bytes
269741Smasputra  * dequeued and processed by tcp_output().
270741Smasputra  *
271741Smasputra  * So, the total number of bytes unsent is (squeue_bytes + unsent) with all
272741Smasputra  * flow-control uses of unsent replaced with the macro TCP_UNSENT_BYTES.
273741Smasputra  */
274741Smasputra extern void	tcp_clrqfull(tcp_t *);
275741Smasputra extern void	tcp_setqfull(tcp_t *);
276741Smasputra 
277741Smasputra #define	TCP_UNSENT_BYTES(tcp) \
278741Smasputra 	((tcp)->tcp_squeue_bytes + (tcp)->tcp_unsent)
279741Smasputra 
28011754SKacheong.Poon@Sun.COM /*
28111754SKacheong.Poon@Sun.COM  * Linked list struct to store listener connection limit configuration per
28211754SKacheong.Poon@Sun.COM  * IP stack.  The list is stored at tcps_listener_conf in tcp_stack_t.
28311754SKacheong.Poon@Sun.COM  *
28411754SKacheong.Poon@Sun.COM  * tl_port: the listener port of this limit configuration
28511754SKacheong.Poon@Sun.COM  * tl_ratio: the maximum amount of memory consumed by all concurrent TCP
28611754SKacheong.Poon@Sun.COM  *           connections created by a listener does not exceed 1/tl_ratio
28711754SKacheong.Poon@Sun.COM  *           of the total system memory.  Note that this is only an
28811754SKacheong.Poon@Sun.COM  *           approximation.
28911754SKacheong.Poon@Sun.COM  * tl_link: linked list struct
29011754SKacheong.Poon@Sun.COM  */
29111754SKacheong.Poon@Sun.COM typedef struct tcp_listener_s {
29211754SKacheong.Poon@Sun.COM 	in_port_t	tl_port;
29311754SKacheong.Poon@Sun.COM 	uint32_t	tl_ratio;
29411754SKacheong.Poon@Sun.COM 	list_node_t	tl_link;
29511754SKacheong.Poon@Sun.COM } tcp_listener_t;
29611754SKacheong.Poon@Sun.COM 
29711754SKacheong.Poon@Sun.COM /*
29811754SKacheong.Poon@Sun.COM  * If there is a limit set on the number of connections allowed per each
29911754SKacheong.Poon@Sun.COM  * listener, the following struct is used to store that counter.  It keeps
30011754SKacheong.Poon@Sun.COM  * the number of TCP connection created by a listener.  Note that this needs
30111754SKacheong.Poon@Sun.COM  * to be separated from the listener since the listener can go away before
30211754SKacheong.Poon@Sun.COM  * all the connections are gone.
30311754SKacheong.Poon@Sun.COM  *
30411754SKacheong.Poon@Sun.COM  * When the struct is allocated, tlc_cnt is set to 1.  When a new connection
30511754SKacheong.Poon@Sun.COM  * is created by the listener, tlc_cnt is incremented by 1.  When a connection
30611754SKacheong.Poon@Sun.COM  * created by the listener goes away, tlc_count is decremented by 1.  When the
30711754SKacheong.Poon@Sun.COM  * listener itself goes away, tlc_cnt is decremented  by one.  The last
30811754SKacheong.Poon@Sun.COM  * connection (or the listener) which decrements tlc_cnt to zero frees the
30911754SKacheong.Poon@Sun.COM  * struct.
31011754SKacheong.Poon@Sun.COM  *
311*12869SKacheong.Poon@Sun.COM  * tlc_max is the maximum number of concurrent TCP connections created from a
312*12869SKacheong.Poon@Sun.COM  * listner.  It is calculated when the tcp_listen_cnt_t is allocated.
31311754SKacheong.Poon@Sun.COM  *
31411754SKacheong.Poon@Sun.COM  * tlc_report_time stores the time when cmn_err() is called to report that the
31511754SKacheong.Poon@Sun.COM  * max has been exceeeded.  Report is done at most once every
31611754SKacheong.Poon@Sun.COM  * TCP_TLC_REPORT_INTERVAL mins for a listener.
31711754SKacheong.Poon@Sun.COM  *
31811754SKacheong.Poon@Sun.COM  * tlc_drop stores the number of connection attempt dropped because the
31911754SKacheong.Poon@Sun.COM  * limit has reached.
32011754SKacheong.Poon@Sun.COM  */
32111754SKacheong.Poon@Sun.COM typedef struct tcp_listen_cnt_s {
32211754SKacheong.Poon@Sun.COM 	uint32_t	tlc_max;
32311754SKacheong.Poon@Sun.COM 	uint32_t	tlc_cnt;
32411754SKacheong.Poon@Sun.COM 	int64_t		tlc_report_time;
32511754SKacheong.Poon@Sun.COM 	uint32_t	tlc_drop;
32611754SKacheong.Poon@Sun.COM } tcp_listen_cnt_t;
32711754SKacheong.Poon@Sun.COM 
32811754SKacheong.Poon@Sun.COM #define	TCP_TLC_REPORT_INTERVAL	(30 * MINUTES)
32911754SKacheong.Poon@Sun.COM 
33011754SKacheong.Poon@Sun.COM #define	TCP_DECR_LISTEN_CNT(tcp)					\
33111754SKacheong.Poon@Sun.COM {									\
33211754SKacheong.Poon@Sun.COM 	ASSERT((tcp)->tcp_listen_cnt->tlc_cnt > 0);			\
33311754SKacheong.Poon@Sun.COM 	if (atomic_add_32_nv(&(tcp)->tcp_listen_cnt->tlc_cnt, -1) == 0) \
33411754SKacheong.Poon@Sun.COM 		kmem_free((tcp)->tcp_listen_cnt, sizeof (tcp_listen_cnt_t)); \
33511754SKacheong.Poon@Sun.COM 	(tcp)->tcp_listen_cnt = NULL;					\
33611754SKacheong.Poon@Sun.COM }
33711754SKacheong.Poon@Sun.COM 
33811754SKacheong.Poon@Sun.COM /* Increment and decrement the number of connections in tcp_stack_t. */
33911754SKacheong.Poon@Sun.COM #define	TCPS_CONN_INC(tcps)						\
34011754SKacheong.Poon@Sun.COM 	atomic_inc_64(							\
34111754SKacheong.Poon@Sun.COM 	    (uint64_t *)&(tcps)->tcps_sc[CPU->cpu_seqid]->tcp_sc_conn_cnt)
34211754SKacheong.Poon@Sun.COM 
34311754SKacheong.Poon@Sun.COM #define	TCPS_CONN_DEC(tcps)						\
34411754SKacheong.Poon@Sun.COM 	atomic_dec_64(							\
34511754SKacheong.Poon@Sun.COM 	    (uint64_t *)&(tcps)->tcps_sc[CPU->cpu_seqid]->tcp_sc_conn_cnt)
34611754SKacheong.Poon@Sun.COM 
34711754SKacheong.Poon@Sun.COM /*
34811754SKacheong.Poon@Sun.COM  * When the system is under memory pressure, stack variable tcps_reclaim is
34911754SKacheong.Poon@Sun.COM  * true, we shorten the connection timeout abort interval to tcp_early_abort
35011754SKacheong.Poon@Sun.COM  * seconds.  Defined in tcp.c.
35111754SKacheong.Poon@Sun.COM  */
35211754SKacheong.Poon@Sun.COM extern uint32_t tcp_early_abort;
35311754SKacheong.Poon@Sun.COM 
35411754SKacheong.Poon@Sun.COM /*
35511754SKacheong.Poon@Sun.COM  * To reach to an eager in Q0 which can be dropped due to an incoming
35611754SKacheong.Poon@Sun.COM  * new SYN request when Q0 is full, a new doubly linked list is
35711754SKacheong.Poon@Sun.COM  * introduced. This list allows to select an eager from Q0 in O(1) time.
35811754SKacheong.Poon@Sun.COM  * This is needed to avoid spending too much time walking through the
35911754SKacheong.Poon@Sun.COM  * long list of eagers in Q0 when tcp_drop_q0() is called. Each member of
36011754SKacheong.Poon@Sun.COM  * this new list has to be a member of Q0.
36111754SKacheong.Poon@Sun.COM  * This list is headed by listener's tcp_t. When the list is empty,
36211754SKacheong.Poon@Sun.COM  * both the pointers - tcp_eager_next_drop_q0 and tcp_eager_prev_drop_q0,
36311754SKacheong.Poon@Sun.COM  * of listener's tcp_t point to listener's tcp_t itself.
36411754SKacheong.Poon@Sun.COM  *
36511754SKacheong.Poon@Sun.COM  * Given an eager in Q0 and a listener, MAKE_DROPPABLE() puts the eager
36611754SKacheong.Poon@Sun.COM  * in the list. MAKE_UNDROPPABLE() takes the eager out of the list.
36711754SKacheong.Poon@Sun.COM  * These macros do not affect the eager's membership to Q0.
36811754SKacheong.Poon@Sun.COM  */
36911754SKacheong.Poon@Sun.COM #define	MAKE_DROPPABLE(listener, eager)					\
37011754SKacheong.Poon@Sun.COM 	if ((eager)->tcp_eager_next_drop_q0 == NULL) {			\
37111754SKacheong.Poon@Sun.COM 		(listener)->tcp_eager_next_drop_q0->tcp_eager_prev_drop_q0\
37211754SKacheong.Poon@Sun.COM 		    = (eager);						\
37311754SKacheong.Poon@Sun.COM 		(eager)->tcp_eager_prev_drop_q0 = (listener);		\
37411754SKacheong.Poon@Sun.COM 		(eager)->tcp_eager_next_drop_q0 =			\
37511754SKacheong.Poon@Sun.COM 		    (listener)->tcp_eager_next_drop_q0;			\
37611754SKacheong.Poon@Sun.COM 		(listener)->tcp_eager_next_drop_q0 = (eager);		\
37711754SKacheong.Poon@Sun.COM 	}
37811754SKacheong.Poon@Sun.COM 
37911754SKacheong.Poon@Sun.COM #define	MAKE_UNDROPPABLE(eager)						\
38011754SKacheong.Poon@Sun.COM 	if ((eager)->tcp_eager_next_drop_q0 != NULL) {			\
38111754SKacheong.Poon@Sun.COM 		(eager)->tcp_eager_next_drop_q0->tcp_eager_prev_drop_q0	\
38211754SKacheong.Poon@Sun.COM 		    = (eager)->tcp_eager_prev_drop_q0;			\
38311754SKacheong.Poon@Sun.COM 		(eager)->tcp_eager_prev_drop_q0->tcp_eager_next_drop_q0	\
38411754SKacheong.Poon@Sun.COM 		    = (eager)->tcp_eager_next_drop_q0;			\
38511754SKacheong.Poon@Sun.COM 		(eager)->tcp_eager_prev_drop_q0 = NULL;			\
38611754SKacheong.Poon@Sun.COM 		(eager)->tcp_eager_next_drop_q0 = NULL;			\
38711754SKacheong.Poon@Sun.COM 	}
38811754SKacheong.Poon@Sun.COM 
38911754SKacheong.Poon@Sun.COM /*
39011754SKacheong.Poon@Sun.COM  * The format argument to pass to tcp_display().
39111754SKacheong.Poon@Sun.COM  * DISP_PORT_ONLY means that the returned string has only port info.
39211754SKacheong.Poon@Sun.COM  * DISP_ADDR_AND_PORT means that the returned string also contains the
39311754SKacheong.Poon@Sun.COM  * remote and local IP address.
39411754SKacheong.Poon@Sun.COM  */
39511754SKacheong.Poon@Sun.COM #define	DISP_PORT_ONLY		1
39611754SKacheong.Poon@Sun.COM #define	DISP_ADDR_AND_PORT	2
39711754SKacheong.Poon@Sun.COM 
39811754SKacheong.Poon@Sun.COM #define	IP_ADDR_CACHE_SIZE	2048
39911754SKacheong.Poon@Sun.COM #define	IP_ADDR_CACHE_HASH(faddr)					\
40011754SKacheong.Poon@Sun.COM 	(ntohl(faddr) & (IP_ADDR_CACHE_SIZE -1))
40111754SKacheong.Poon@Sun.COM 
40211754SKacheong.Poon@Sun.COM /* TCP cwnd burst factor. */
40311754SKacheong.Poon@Sun.COM #define	TCP_CWND_INFINITE	65535
40411754SKacheong.Poon@Sun.COM #define	TCP_CWND_SS		3
40511754SKacheong.Poon@Sun.COM #define	TCP_CWND_NORMAL		5
40611754SKacheong.Poon@Sun.COM 
40711754SKacheong.Poon@Sun.COM /*
40811754SKacheong.Poon@Sun.COM  * TCP reassembly macros.  We hide starting and ending sequence numbers in
40911754SKacheong.Poon@Sun.COM  * b_next and b_prev of messages on the reassembly queue.  The messages are
41011754SKacheong.Poon@Sun.COM  * chained using b_cont.  These macros are used in tcp_reass() so we don't
41111754SKacheong.Poon@Sun.COM  * have to see the ugly casts and assignments.
41211754SKacheong.Poon@Sun.COM  */
41311754SKacheong.Poon@Sun.COM #define	TCP_REASS_SEQ(mp)		((uint32_t)(uintptr_t)((mp)->b_next))
41411754SKacheong.Poon@Sun.COM #define	TCP_REASS_SET_SEQ(mp, u)	((mp)->b_next = \
41511754SKacheong.Poon@Sun.COM 					(mblk_t *)(uintptr_t)(u))
41611754SKacheong.Poon@Sun.COM #define	TCP_REASS_END(mp)		((uint32_t)(uintptr_t)((mp)->b_prev))
41711754SKacheong.Poon@Sun.COM #define	TCP_REASS_SET_END(mp, u)	((mp)->b_prev = \
41811754SKacheong.Poon@Sun.COM 					(mblk_t *)(uintptr_t)(u))
41911754SKacheong.Poon@Sun.COM 
42012016SGirish.Moodalbail@Sun.COM #define	tcps_time_wait_interval		tcps_propinfo_tbl[0].prop_cur_uval
42112016SGirish.Moodalbail@Sun.COM #define	tcps_conn_req_max_q		tcps_propinfo_tbl[1].prop_cur_uval
42212016SGirish.Moodalbail@Sun.COM #define	tcps_conn_req_max_q0		tcps_propinfo_tbl[2].prop_cur_uval
42312016SGirish.Moodalbail@Sun.COM #define	tcps_conn_req_min		tcps_propinfo_tbl[3].prop_cur_uval
42412016SGirish.Moodalbail@Sun.COM #define	tcps_conn_grace_period		tcps_propinfo_tbl[4].prop_cur_uval
42512016SGirish.Moodalbail@Sun.COM #define	tcps_cwnd_max_			tcps_propinfo_tbl[5].prop_cur_uval
42612016SGirish.Moodalbail@Sun.COM #define	tcps_dbg			tcps_propinfo_tbl[6].prop_cur_uval
42712016SGirish.Moodalbail@Sun.COM #define	tcps_smallest_nonpriv_port	tcps_propinfo_tbl[7].prop_cur_uval
42812016SGirish.Moodalbail@Sun.COM #define	tcps_ip_abort_cinterval		tcps_propinfo_tbl[8].prop_cur_uval
42912016SGirish.Moodalbail@Sun.COM #define	tcps_ip_abort_linterval		tcps_propinfo_tbl[9].prop_cur_uval
43012016SGirish.Moodalbail@Sun.COM #define	tcps_ip_abort_interval		tcps_propinfo_tbl[10].prop_cur_uval
43112016SGirish.Moodalbail@Sun.COM #define	tcps_ip_notify_cinterval	tcps_propinfo_tbl[11].prop_cur_uval
43212016SGirish.Moodalbail@Sun.COM #define	tcps_ip_notify_interval		tcps_propinfo_tbl[12].prop_cur_uval
43312016SGirish.Moodalbail@Sun.COM #define	tcps_ipv4_ttl			tcps_propinfo_tbl[13].prop_cur_uval
43412016SGirish.Moodalbail@Sun.COM #define	tcps_keepalive_interval_high	tcps_propinfo_tbl[14].prop_max_uval
43512016SGirish.Moodalbail@Sun.COM #define	tcps_keepalive_interval		tcps_propinfo_tbl[14].prop_cur_uval
43612016SGirish.Moodalbail@Sun.COM #define	tcps_keepalive_interval_low	tcps_propinfo_tbl[14].prop_min_uval
43712016SGirish.Moodalbail@Sun.COM #define	tcps_maxpsz_multiplier		tcps_propinfo_tbl[15].prop_cur_uval
43812016SGirish.Moodalbail@Sun.COM #define	tcps_mss_def_ipv4		tcps_propinfo_tbl[16].prop_cur_uval
43912016SGirish.Moodalbail@Sun.COM #define	tcps_mss_max_ipv4		tcps_propinfo_tbl[17].prop_cur_uval
44012016SGirish.Moodalbail@Sun.COM #define	tcps_mss_min			tcps_propinfo_tbl[18].prop_cur_uval
44112016SGirish.Moodalbail@Sun.COM #define	tcps_naglim_def			tcps_propinfo_tbl[19].prop_cur_uval
44212544SKacheong.Poon@Sun.COM #define	tcps_rexmit_interval_initial_high	\
44312544SKacheong.Poon@Sun.COM 					tcps_propinfo_tbl[20].prop_max_uval
44412016SGirish.Moodalbail@Sun.COM #define	tcps_rexmit_interval_initial	tcps_propinfo_tbl[20].prop_cur_uval
44512544SKacheong.Poon@Sun.COM #define	tcps_rexmit_interval_initial_low	\
44612544SKacheong.Poon@Sun.COM 					tcps_propinfo_tbl[20].prop_min_uval
44712544SKacheong.Poon@Sun.COM #define	tcps_rexmit_interval_max_high	tcps_propinfo_tbl[21].prop_max_uval
44812016SGirish.Moodalbail@Sun.COM #define	tcps_rexmit_interval_max	tcps_propinfo_tbl[21].prop_cur_uval
44912544SKacheong.Poon@Sun.COM #define	tcps_rexmit_interval_max_low	tcps_propinfo_tbl[21].prop_min_uval
45012544SKacheong.Poon@Sun.COM #define	tcps_rexmit_interval_min_high	tcps_propinfo_tbl[22].prop_max_uval
45112016SGirish.Moodalbail@Sun.COM #define	tcps_rexmit_interval_min	tcps_propinfo_tbl[22].prop_cur_uval
45212544SKacheong.Poon@Sun.COM #define	tcps_rexmit_interval_min_low	tcps_propinfo_tbl[22].prop_min_uval
45312016SGirish.Moodalbail@Sun.COM #define	tcps_deferred_ack_interval	tcps_propinfo_tbl[23].prop_cur_uval
45412016SGirish.Moodalbail@Sun.COM #define	tcps_snd_lowat_fraction		tcps_propinfo_tbl[24].prop_cur_uval
45512016SGirish.Moodalbail@Sun.COM #define	tcps_dupack_fast_retransmit	tcps_propinfo_tbl[25].prop_cur_uval
45612016SGirish.Moodalbail@Sun.COM #define	tcps_ignore_path_mtu		tcps_propinfo_tbl[26].prop_cur_bval
45712016SGirish.Moodalbail@Sun.COM #define	tcps_smallest_anon_port		tcps_propinfo_tbl[27].prop_cur_uval
45812016SGirish.Moodalbail@Sun.COM #define	tcps_largest_anon_port		tcps_propinfo_tbl[28].prop_cur_uval
45912016SGirish.Moodalbail@Sun.COM #define	tcps_xmit_hiwat			tcps_propinfo_tbl[29].prop_cur_uval
46012016SGirish.Moodalbail@Sun.COM #define	tcps_xmit_lowat			tcps_propinfo_tbl[30].prop_cur_uval
46112016SGirish.Moodalbail@Sun.COM #define	tcps_recv_hiwat			tcps_propinfo_tbl[31].prop_cur_uval
46212016SGirish.Moodalbail@Sun.COM #define	tcps_recv_hiwat_minmss		tcps_propinfo_tbl[32].prop_cur_uval
46312544SKacheong.Poon@Sun.COM #define	tcps_fin_wait_2_flush_interval_high	\
46412544SKacheong.Poon@Sun.COM 					tcps_propinfo_tbl[33].prop_max_uval
46512016SGirish.Moodalbail@Sun.COM #define	tcps_fin_wait_2_flush_interval	tcps_propinfo_tbl[33].prop_cur_uval
46612544SKacheong.Poon@Sun.COM #define	tcps_fin_wait_2_flush_interval_low	\
46712544SKacheong.Poon@Sun.COM 					tcps_propinfo_tbl[33].prop_min_uval
46812016SGirish.Moodalbail@Sun.COM #define	tcps_max_buf			tcps_propinfo_tbl[34].prop_cur_uval
46912016SGirish.Moodalbail@Sun.COM #define	tcps_strong_iss			tcps_propinfo_tbl[35].prop_cur_uval
47012016SGirish.Moodalbail@Sun.COM #define	tcps_rtt_updates		tcps_propinfo_tbl[36].prop_cur_uval
47112016SGirish.Moodalbail@Sun.COM #define	tcps_wscale_always		tcps_propinfo_tbl[37].prop_cur_bval
47212016SGirish.Moodalbail@Sun.COM #define	tcps_tstamp_always		tcps_propinfo_tbl[38].prop_cur_bval
47312016SGirish.Moodalbail@Sun.COM #define	tcps_tstamp_if_wscale		tcps_propinfo_tbl[39].prop_cur_bval
47412016SGirish.Moodalbail@Sun.COM #define	tcps_rexmit_interval_extra	tcps_propinfo_tbl[40].prop_cur_uval
47512016SGirish.Moodalbail@Sun.COM #define	tcps_deferred_acks_max		tcps_propinfo_tbl[41].prop_cur_uval
47612016SGirish.Moodalbail@Sun.COM #define	tcps_slow_start_after_idle	tcps_propinfo_tbl[42].prop_cur_uval
47712016SGirish.Moodalbail@Sun.COM #define	tcps_slow_start_initial		tcps_propinfo_tbl[43].prop_cur_uval
47812016SGirish.Moodalbail@Sun.COM #define	tcps_sack_permitted		tcps_propinfo_tbl[44].prop_cur_uval
47912016SGirish.Moodalbail@Sun.COM #define	tcps_ipv6_hoplimit		tcps_propinfo_tbl[45].prop_cur_uval
48012016SGirish.Moodalbail@Sun.COM #define	tcps_mss_def_ipv6		tcps_propinfo_tbl[46].prop_cur_uval
48112016SGirish.Moodalbail@Sun.COM #define	tcps_mss_max_ipv6		tcps_propinfo_tbl[47].prop_cur_uval
48212016SGirish.Moodalbail@Sun.COM #define	tcps_rev_src_routes		tcps_propinfo_tbl[48].prop_cur_bval
48312016SGirish.Moodalbail@Sun.COM #define	tcps_local_dack_interval	tcps_propinfo_tbl[49].prop_cur_uval
48412016SGirish.Moodalbail@Sun.COM #define	tcps_local_dacks_max		tcps_propinfo_tbl[50].prop_cur_uval
48512016SGirish.Moodalbail@Sun.COM #define	tcps_ecn_permitted		tcps_propinfo_tbl[51].prop_cur_uval
48612016SGirish.Moodalbail@Sun.COM #define	tcps_rst_sent_rate_enabled	tcps_propinfo_tbl[52].prop_cur_bval
48712016SGirish.Moodalbail@Sun.COM #define	tcps_rst_sent_rate		tcps_propinfo_tbl[53].prop_cur_uval
48812016SGirish.Moodalbail@Sun.COM #define	tcps_push_timer_interval	tcps_propinfo_tbl[54].prop_cur_uval
48912016SGirish.Moodalbail@Sun.COM #define	tcps_use_smss_as_mss_opt	tcps_propinfo_tbl[55].prop_cur_bval
49012016SGirish.Moodalbail@Sun.COM #define	tcps_keepalive_abort_interval_high \
49112016SGirish.Moodalbail@Sun.COM 					tcps_propinfo_tbl[56].prop_max_uval
49212016SGirish.Moodalbail@Sun.COM #define	tcps_keepalive_abort_interval \
49312016SGirish.Moodalbail@Sun.COM 					tcps_propinfo_tbl[56].prop_cur_uval
49412016SGirish.Moodalbail@Sun.COM #define	tcps_keepalive_abort_interval_low \
49512016SGirish.Moodalbail@Sun.COM 					tcps_propinfo_tbl[56].prop_min_uval
49612016SGirish.Moodalbail@Sun.COM #define	tcps_wroff_xtra			tcps_propinfo_tbl[57].prop_cur_uval
49712016SGirish.Moodalbail@Sun.COM #define	tcps_dev_flow_ctl		tcps_propinfo_tbl[58].prop_cur_bval
49812016SGirish.Moodalbail@Sun.COM #define	tcps_reass_timeout		tcps_propinfo_tbl[59].prop_cur_uval
49911754SKacheong.Poon@Sun.COM 
5009993SAnders.Persson@Sun.COM extern struct qinit tcp_rinitv4, tcp_rinitv6;
501741Smasputra extern boolean_t do_tcp_fusion;
502741Smasputra 
5035240Snordmark /*
5045240Snordmark  * Object to represent database of options to search passed to
5055240Snordmark  * {sock,tpi}optcom_req() interface routine to take care of option
5065240Snordmark  * management and associated methods.
5075240Snordmark  */
5085240Snordmark extern optdb_obj_t	tcp_opt_obj;
5095240Snordmark extern uint_t		tcp_max_optsize;
5105240Snordmark 
51111754SKacheong.Poon@Sun.COM extern int tcp_squeue_flag;
51211754SKacheong.Poon@Sun.COM 
51311754SKacheong.Poon@Sun.COM extern uint_t tcp_free_list_max_cnt;
51411754SKacheong.Poon@Sun.COM 
51511754SKacheong.Poon@Sun.COM /*
51611754SKacheong.Poon@Sun.COM  * Functions in tcp.c.
51711754SKacheong.Poon@Sun.COM  */
51811754SKacheong.Poon@Sun.COM extern void	tcp_acceptor_hash_insert(t_uscalar_t, tcp_t *);
51911754SKacheong.Poon@Sun.COM extern tcp_t	*tcp_acceptor_hash_lookup(t_uscalar_t, tcp_stack_t *);
52011754SKacheong.Poon@Sun.COM extern void	tcp_acceptor_hash_remove(tcp_t *);
52111754SKacheong.Poon@Sun.COM extern mblk_t	*tcp_ack_mp(tcp_t *);
52211754SKacheong.Poon@Sun.COM extern int	tcp_build_hdrs(tcp_t *);
52311754SKacheong.Poon@Sun.COM extern void	tcp_cleanup(tcp_t *);
52411754SKacheong.Poon@Sun.COM extern int	tcp_clean_death(tcp_t *, int);
52511754SKacheong.Poon@Sun.COM extern void	tcp_clean_death_wrapper(void *, mblk_t *, void *,
52611754SKacheong.Poon@Sun.COM 		    ip_recv_attr_t *);
52711754SKacheong.Poon@Sun.COM extern void	tcp_close_common(conn_t *, int);
52811754SKacheong.Poon@Sun.COM extern void	tcp_close_detached(tcp_t *);
52911754SKacheong.Poon@Sun.COM extern void	tcp_close_mpp(mblk_t **);
53011754SKacheong.Poon@Sun.COM extern void	tcp_closei_local(tcp_t *);
5318348SEric.Yu@Sun.COM extern sock_lower_handle_t tcp_create(int, int, int, sock_downcalls_t **,
53211754SKacheong.Poon@Sun.COM 		    uint_t *, int *, int, cred_t *);
53311754SKacheong.Poon@Sun.COM extern conn_t	*tcp_create_common(cred_t *, boolean_t, boolean_t, int *);
53411754SKacheong.Poon@Sun.COM extern void	tcp_disconnect(tcp_t *, mblk_t *);
53511754SKacheong.Poon@Sun.COM extern char	*tcp_display(tcp_t *, char *, char);
53611754SKacheong.Poon@Sun.COM extern int	tcp_do_bind(conn_t *, struct sockaddr *, socklen_t, cred_t *,
53711754SKacheong.Poon@Sun.COM 		    boolean_t);
53811754SKacheong.Poon@Sun.COM extern int	tcp_do_connect(conn_t *, const struct sockaddr *, socklen_t,
53911754SKacheong.Poon@Sun.COM 		    cred_t *, pid_t);
54011754SKacheong.Poon@Sun.COM extern int	tcp_do_listen(conn_t *, struct sockaddr *, socklen_t, int,
54111754SKacheong.Poon@Sun.COM 		    cred_t *, boolean_t);
54211754SKacheong.Poon@Sun.COM extern int	tcp_do_unbind(conn_t *);
54311754SKacheong.Poon@Sun.COM extern boolean_t	tcp_eager_blowoff(tcp_t *, t_scalar_t);
54411754SKacheong.Poon@Sun.COM extern void	tcp_eager_cleanup(tcp_t *, boolean_t);
54511754SKacheong.Poon@Sun.COM extern void	tcp_eager_kill(void *, mblk_t *, void *, ip_recv_attr_t *);
54611754SKacheong.Poon@Sun.COM extern void	tcp_eager_unlink(tcp_t *);
54711754SKacheong.Poon@Sun.COM extern int	tcp_getpeername(sock_lower_handle_t, struct sockaddr *,
54811754SKacheong.Poon@Sun.COM 		    socklen_t *, cred_t *);
54911754SKacheong.Poon@Sun.COM extern int	tcp_getsockname(sock_lower_handle_t, struct sockaddr *,
55011754SKacheong.Poon@Sun.COM 		    socklen_t *, cred_t *);
55112544SKacheong.Poon@Sun.COM extern void	tcp_init_values(tcp_t *, tcp_t *);
55211754SKacheong.Poon@Sun.COM extern void	tcp_ipsec_cleanup(tcp_t *);
55311754SKacheong.Poon@Sun.COM extern int	tcp_maxpsz_set(tcp_t *, boolean_t);
55411754SKacheong.Poon@Sun.COM extern void	tcp_mss_set(tcp_t *, uint32_t);
55511754SKacheong.Poon@Sun.COM extern void	tcp_reinput(conn_t *, mblk_t *, ip_recv_attr_t *, ip_stack_t *);
55611754SKacheong.Poon@Sun.COM extern void	tcp_rsrv(queue_t *);
55711754SKacheong.Poon@Sun.COM extern uint_t	tcp_rwnd_reopen(tcp_t *);
55811754SKacheong.Poon@Sun.COM extern int	tcp_rwnd_set(tcp_t *, uint32_t);
55911754SKacheong.Poon@Sun.COM extern int	tcp_set_destination(tcp_t *);
56011754SKacheong.Poon@Sun.COM extern void	tcp_set_ws_value(tcp_t *);
56111754SKacheong.Poon@Sun.COM extern void	tcp_stop_lingering(tcp_t *);
56211754SKacheong.Poon@Sun.COM extern void	tcp_update_pmtu(tcp_t *, boolean_t);
56311754SKacheong.Poon@Sun.COM extern mblk_t	*tcp_zcopy_backoff(tcp_t *, mblk_t *, boolean_t);
56411754SKacheong.Poon@Sun.COM extern boolean_t	tcp_zcopy_check(tcp_t *);
56511754SKacheong.Poon@Sun.COM extern void	tcp_zcopy_notify(tcp_t *);
56612643SAnders.Persson@Sun.COM extern void	tcp_get_proto_props(tcp_t *, struct sock_proto_props *);
56711754SKacheong.Poon@Sun.COM 
56811754SKacheong.Poon@Sun.COM /*
56911754SKacheong.Poon@Sun.COM  * Bind related functions in tcp_bind.c
57011754SKacheong.Poon@Sun.COM  */
57111754SKacheong.Poon@Sun.COM extern int	tcp_bind_check(conn_t *, struct sockaddr *, socklen_t,
57211754SKacheong.Poon@Sun.COM 		    cred_t *, boolean_t);
57311754SKacheong.Poon@Sun.COM extern void	tcp_bind_hash_insert(tf_t *, tcp_t *, int);
57411754SKacheong.Poon@Sun.COM extern void	tcp_bind_hash_remove(tcp_t *);
57511754SKacheong.Poon@Sun.COM extern in_port_t	tcp_bindi(tcp_t *, in_port_t, const in6_addr_t *,
57611754SKacheong.Poon@Sun.COM 			    int, boolean_t, boolean_t, boolean_t);
57711754SKacheong.Poon@Sun.COM extern in_port_t	tcp_update_next_port(in_port_t, const tcp_t *,
57811754SKacheong.Poon@Sun.COM 			    boolean_t);
57911754SKacheong.Poon@Sun.COM 
58011754SKacheong.Poon@Sun.COM /*
58111754SKacheong.Poon@Sun.COM  * Fusion related functions in tcp_fusion.c.
58211754SKacheong.Poon@Sun.COM  */
58311754SKacheong.Poon@Sun.COM extern void	tcp_fuse(tcp_t *, uchar_t *, tcpha_t *);
58411754SKacheong.Poon@Sun.COM extern void	tcp_unfuse(tcp_t *);
58511754SKacheong.Poon@Sun.COM extern boolean_t tcp_fuse_output(tcp_t *, mblk_t *, uint32_t);
58611754SKacheong.Poon@Sun.COM extern void	tcp_fuse_output_urg(tcp_t *, mblk_t *);
58711754SKacheong.Poon@Sun.COM extern boolean_t tcp_fuse_rcv_drain(queue_t *, tcp_t *, mblk_t **);
58811754SKacheong.Poon@Sun.COM extern size_t	tcp_fuse_set_rcv_hiwat(tcp_t *, size_t);
58911754SKacheong.Poon@Sun.COM extern int	tcp_fuse_maxpsz(tcp_t *);
59011754SKacheong.Poon@Sun.COM extern void	tcp_fuse_backenable(tcp_t *);
59112016SGirish.Moodalbail@Sun.COM extern void	tcp_iss_key_init(uint8_t *, int, tcp_stack_t *);
59211754SKacheong.Poon@Sun.COM 
59311754SKacheong.Poon@Sun.COM /*
59411754SKacheong.Poon@Sun.COM  * Output related functions in tcp_output.c.
59511754SKacheong.Poon@Sun.COM  */
59611754SKacheong.Poon@Sun.COM extern void	tcp_close_output(void *, mblk_t *, void *, ip_recv_attr_t *);
59711754SKacheong.Poon@Sun.COM extern void	tcp_output(void *, mblk_t *, void *, ip_recv_attr_t *);
59811754SKacheong.Poon@Sun.COM extern void	tcp_output_urgent(void *, mblk_t *, void *, ip_recv_attr_t *);
59911754SKacheong.Poon@Sun.COM extern void	tcp_rexmit_after_error(tcp_t *);
60011754SKacheong.Poon@Sun.COM extern void	tcp_sack_rexmit(tcp_t *, uint_t *);
60111754SKacheong.Poon@Sun.COM extern void	tcp_send_data(tcp_t *, mblk_t *);
60211754SKacheong.Poon@Sun.COM extern void	tcp_send_synack(void *, mblk_t *, void *, ip_recv_attr_t *);
60311754SKacheong.Poon@Sun.COM extern void	tcp_shutdown_output(void *, mblk_t *, void *, ip_recv_attr_t *);
60411754SKacheong.Poon@Sun.COM extern void	tcp_ss_rexmit(tcp_t *);
60511754SKacheong.Poon@Sun.COM extern void	tcp_update_xmit_tail(tcp_t *, uint32_t);
60611754SKacheong.Poon@Sun.COM extern void	tcp_wput(queue_t *, mblk_t *);
60711754SKacheong.Poon@Sun.COM extern void	tcp_wput_data(tcp_t *, mblk_t *, boolean_t);
60811754SKacheong.Poon@Sun.COM extern void	tcp_wput_sock(queue_t *, mblk_t *);
60911754SKacheong.Poon@Sun.COM extern void	tcp_wput_fallback(queue_t *, mblk_t *);
61011754SKacheong.Poon@Sun.COM extern void	tcp_xmit_ctl(char *, tcp_t *, uint32_t, uint32_t, int);
61111754SKacheong.Poon@Sun.COM extern void	tcp_xmit_listeners_reset(mblk_t *, ip_recv_attr_t *,
61211754SKacheong.Poon@Sun.COM 		    ip_stack_t *i, conn_t *);
61311754SKacheong.Poon@Sun.COM extern mblk_t	*tcp_xmit_mp(tcp_t *, mblk_t *, int32_t, int32_t *,
61411754SKacheong.Poon@Sun.COM 		    mblk_t **, uint32_t, boolean_t, uint32_t *, boolean_t);
61511754SKacheong.Poon@Sun.COM 
61611754SKacheong.Poon@Sun.COM /*
61711754SKacheong.Poon@Sun.COM  * Input related functions in tcp_input.c.
61811754SKacheong.Poon@Sun.COM  */
61911754SKacheong.Poon@Sun.COM extern void	tcp_icmp_input(void *, mblk_t *, void *, ip_recv_attr_t *);
62011754SKacheong.Poon@Sun.COM extern void	tcp_input_data(void *, mblk_t *, void *, ip_recv_attr_t *);
62111754SKacheong.Poon@Sun.COM extern void	tcp_input_listener_unbound(void *, mblk_t *, void *,
62211754SKacheong.Poon@Sun.COM 		    ip_recv_attr_t *);
62311754SKacheong.Poon@Sun.COM extern boolean_t	tcp_paws_check(tcp_t *, tcpha_t *, tcp_opt_t *);
62411754SKacheong.Poon@Sun.COM extern uint_t	tcp_rcv_drain(tcp_t *);
62511754SKacheong.Poon@Sun.COM extern void	tcp_rcv_enqueue(tcp_t *, mblk_t *, uint_t, cred_t *);
62611754SKacheong.Poon@Sun.COM extern boolean_t	tcp_verifyicmp(conn_t *, void *, icmph_t *, icmp6_t *,
62711754SKacheong.Poon@Sun.COM 			    ip_recv_attr_t *);
62811754SKacheong.Poon@Sun.COM 
62911754SKacheong.Poon@Sun.COM /*
63011754SKacheong.Poon@Sun.COM  * Kernel socket related functions in tcp_socket.c.
63111754SKacheong.Poon@Sun.COM  */
63212643SAnders.Persson@Sun.COM extern int	tcp_fallback(sock_lower_handle_t, queue_t *, boolean_t,
63312643SAnders.Persson@Sun.COM 		    so_proto_quiesced_cb_t, sock_quiesce_arg_t *);
63412643SAnders.Persson@Sun.COM extern boolean_t tcp_newconn_notify(tcp_t *, ip_recv_attr_t *);
6358348SEric.Yu@Sun.COM 
63611754SKacheong.Poon@Sun.COM /*
63711754SKacheong.Poon@Sun.COM  * Timer related functions in tcp_timers.c.
63811754SKacheong.Poon@Sun.COM  */
63911754SKacheong.Poon@Sun.COM extern void	tcp_ack_timer(void *);
64011754SKacheong.Poon@Sun.COM extern void	tcp_close_linger_timeout(void *);
64111754SKacheong.Poon@Sun.COM extern void	tcp_keepalive_timer(void *);
64211754SKacheong.Poon@Sun.COM extern void	tcp_push_timer(void *);
64311754SKacheong.Poon@Sun.COM extern void	tcp_reass_timer(void *);
64411754SKacheong.Poon@Sun.COM extern mblk_t	*tcp_timermp_alloc(int);
64511754SKacheong.Poon@Sun.COM extern void	tcp_timermp_free(tcp_t *);
64612056SKacheong.Poon@Sun.COM extern timeout_id_t tcp_timeout(conn_t *, void (*)(void *), hrtime_t);
64711754SKacheong.Poon@Sun.COM extern clock_t	tcp_timeout_cancel(conn_t *, timeout_id_t);
64811754SKacheong.Poon@Sun.COM extern void	tcp_timer(void *arg);
64911754SKacheong.Poon@Sun.COM extern void	tcp_timers_stop(tcp_t *);
6508348SEric.Yu@Sun.COM 
65111754SKacheong.Poon@Sun.COM /*
65211754SKacheong.Poon@Sun.COM  * TCP TPI related functions in tcp_tpi.c.
65311754SKacheong.Poon@Sun.COM  */
65411754SKacheong.Poon@Sun.COM extern void	tcp_addr_req(tcp_t *, mblk_t *);
65511754SKacheong.Poon@Sun.COM extern void	tcp_capability_req(tcp_t *, mblk_t *);
65611754SKacheong.Poon@Sun.COM extern boolean_t	tcp_conn_con(tcp_t *, uchar_t *, mblk_t *,
65711754SKacheong.Poon@Sun.COM 			    mblk_t **, ip_recv_attr_t *);
65811754SKacheong.Poon@Sun.COM extern void	tcp_err_ack(tcp_t *, mblk_t *, int, int);
65911754SKacheong.Poon@Sun.COM extern void	tcp_err_ack_prim(tcp_t *, mblk_t *, int, int, int);
66011754SKacheong.Poon@Sun.COM extern void	tcp_info_req(tcp_t *, mblk_t *);
66111754SKacheong.Poon@Sun.COM extern void	tcp_send_conn_ind(void *, mblk_t *, void *);
66211754SKacheong.Poon@Sun.COM extern void	tcp_send_pending(void *, mblk_t *, void *, ip_recv_attr_t *);
66311754SKacheong.Poon@Sun.COM extern void	tcp_tpi_accept(queue_t *, mblk_t *);
66411754SKacheong.Poon@Sun.COM extern void	tcp_tpi_bind(tcp_t *, mblk_t *);
66511754SKacheong.Poon@Sun.COM extern int	tcp_tpi_close(queue_t *, int);
66611754SKacheong.Poon@Sun.COM extern int	tcp_tpi_close_accept(queue_t *);
66711754SKacheong.Poon@Sun.COM extern void	tcp_tpi_connect(tcp_t *, mblk_t *);
66811042SErik.Nordmark@Sun.COM extern int	tcp_tpi_opt_get(queue_t *, t_scalar_t, t_scalar_t, uchar_t *);
66911042SErik.Nordmark@Sun.COM extern int	tcp_tpi_opt_set(queue_t *, uint_t, int, int, uint_t, uchar_t *,
67011042SErik.Nordmark@Sun.COM 		    uint_t *, uchar_t *, void *, cred_t *);
67111754SKacheong.Poon@Sun.COM extern void	tcp_tpi_unbind(tcp_t *, mblk_t *);
67211754SKacheong.Poon@Sun.COM extern void	tcp_tli_accept(tcp_t *, mblk_t *);
67311754SKacheong.Poon@Sun.COM extern void	tcp_use_pure_tpi(tcp_t *);
67412643SAnders.Persson@Sun.COM extern void	tcp_do_capability_ack(tcp_t *, struct T_capability_ack *,
67512643SAnders.Persson@Sun.COM 		    t_uscalar_t);
67611754SKacheong.Poon@Sun.COM 
67711754SKacheong.Poon@Sun.COM /*
67811754SKacheong.Poon@Sun.COM  * TCP option processing related functions in tcp_opt_data.c
67911754SKacheong.Poon@Sun.COM  */
68011754SKacheong.Poon@Sun.COM extern int	tcp_opt_default(queue_t *, t_scalar_t, t_scalar_t, uchar_t *);
68111754SKacheong.Poon@Sun.COM extern int	tcp_opt_get(conn_t *, int, int, uchar_t *);
68211754SKacheong.Poon@Sun.COM extern int	tcp_opt_set(conn_t *, uint_t, int, int, uint_t, uchar_t *,
68311754SKacheong.Poon@Sun.COM 		    uint_t *, uchar_t *, void *, cred_t *);
68411754SKacheong.Poon@Sun.COM 
68511754SKacheong.Poon@Sun.COM /*
68611754SKacheong.Poon@Sun.COM  * TCP time wait processing related functions in tcp_time_wait.c.
68711754SKacheong.Poon@Sun.COM  */
68811754SKacheong.Poon@Sun.COM extern void		tcp_time_wait_append(tcp_t *);
68911754SKacheong.Poon@Sun.COM extern void		tcp_time_wait_collector(void *);
69011754SKacheong.Poon@Sun.COM extern boolean_t	tcp_time_wait_remove(tcp_t *, tcp_squeue_priv_t *);
69111754SKacheong.Poon@Sun.COM extern void		tcp_time_wait_processing(tcp_t *, mblk_t *, uint32_t,
69211754SKacheong.Poon@Sun.COM 			    uint32_t, int, tcpha_t *, ip_recv_attr_t *);
69311754SKacheong.Poon@Sun.COM 
69411754SKacheong.Poon@Sun.COM /*
69511754SKacheong.Poon@Sun.COM  * Misc functions in tcp_misc.c.
69611754SKacheong.Poon@Sun.COM  */
697*12869SKacheong.Poon@Sun.COM extern uint32_t	tcp_find_listener_conf(tcp_stack_t *, in_port_t);
69811754SKacheong.Poon@Sun.COM extern void	tcp_ioctl_abort_conn(queue_t *, mblk_t *);
69911754SKacheong.Poon@Sun.COM extern void	tcp_listener_conf_cleanup(tcp_stack_t *);
700*12869SKacheong.Poon@Sun.COM extern void	tcp_stack_cpu_add(tcp_stack_t *, processorid_t);
70111042SErik.Nordmark@Sun.COM 
702741Smasputra #endif	/* _KERNEL */
703741Smasputra 
704741Smasputra #ifdef	__cplusplus
705741Smasputra }
706741Smasputra #endif
707741Smasputra 
708741Smasputra #endif	/* _INET_TCP_IMPL_H */
709