xref: /illumos-gate/usr/src/uts/common/inet/tcp.h (revision 20a7641f9918de8574b8b3b47dbe35c4bfc78df1)
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) 1991, 2010, Oracle and/or its affiliates. All rights reserved.
23  * Copyright (c) 2011, Joyent, Inc. All rights reserved.
24  * Copyright (c) 2011 Nexenta Systems, Inc. All rights reserved.
25  * Copyright (c) 2014, 2017 by Delphix. All rights reserved.
26  * Copyright 2020 OmniOS Community Edition (OmniOSce) Association.
27  * Copyright 2022 Oxide Computer Company
28  */
29 /* Copyright (c) 1990 Mentat Inc. */
30 
31 #ifndef	_INET_TCP_H
32 #define	_INET_TCP_H
33 
34 #ifdef	__cplusplus
35 extern "C" {
36 #endif
37 
38 #include <sys/inttypes.h>
39 #include <netinet/ip6.h>
40 #include <netinet/tcp.h>
41 #include <sys/socket.h>
42 #include <sys/socket_proto.h>
43 #include <sys/md5.h>
44 #include <inet/common.h>
45 #include <inet/ip.h>
46 #include <inet/ip6.h>
47 #include <inet/mi.h>
48 #include <inet/mib2.h>
49 #include <inet/tcp_stack.h>
50 #include <inet/tcp_sack.h>
51 #include <inet/cc.h>
52 
53 /* TCP states */
54 #define	TCPS_CLOSED		-6
55 #define	TCPS_IDLE		-5	/* idle (opened, but not bound) */
56 #define	TCPS_BOUND		-4	/* bound, ready to connect or accept */
57 #define	TCPS_LISTEN		-3	/* listening for connection */
58 #define	TCPS_SYN_SENT		-2	/* active, have sent syn */
59 #define	TCPS_SYN_RCVD		-1	/* have received syn (and sent ours) */
60 /* states < TCPS_ESTABLISHED are those where connections not established */
61 #define	TCPS_ESTABLISHED	0	/* established */
62 #define	TCPS_CLOSE_WAIT		1	/* rcvd fin, waiting for close */
63 /* states > TCPS_CLOSE_WAIT are those where user has closed */
64 #define	TCPS_FIN_WAIT_1		2	/* have closed and sent fin */
65 #define	TCPS_CLOSING		3	/* closed, xchd FIN, await FIN ACK */
66 #define	TCPS_LAST_ACK		4	/* had fin and close; await FIN ACK */
67 /* states > TCPS_CLOSE_WAIT && < TCPS_FIN_WAIT_2 await ACK of FIN */
68 #define	TCPS_FIN_WAIT_2		5	/* have closed, fin is acked */
69 #define	TCPS_TIME_WAIT		6	/* in 2*msl quiet wait after close */
70 
71 /*
72  * Internal flags used in conjunction with the packet header flags.
73  * Used in tcp_input_data to keep track of what needs to be done.
74  */
75 #define	TH_LIMIT_XMIT		0x0400	/* Limited xmit is needed */
76 #define	TH_XMIT_NEEDED		0x0800	/* Window opened - send queued data */
77 #define	TH_REXMIT_NEEDED	0x1000	/* Time expired for unacked data */
78 #define	TH_ACK_NEEDED		0x2000	/* Send an ack now. */
79 #define	TH_NEED_SACK_REXMIT	0x4000	/* Use SACK info to retransmission */
80 #define	TH_ACK_TIMER_NEEDED	0x8000	/* Start the delayed ACK timer */
81 #define	TH_ORDREL_NEEDED	0x10000	/* Generate an ordrel indication */
82 #define	TH_MARKNEXT_NEEDED	0x20000	/* Data should have MSGMARKNEXT */
83 #define	TH_SEND_URP_MARK	0x40000	/* Send up tcp_urp_mark_mp */
84 
85 /*
86  * TCP sequence numbers are 32 bit integers operated
87  * on with modular arithmetic.  These macros can be
88  * used to compare such integers.
89  */
90 #define	SEQ_LT(a, b)	((int32_t)((a)-(b)) < 0)
91 #define	SEQ_LEQ(a, b)	((int32_t)((a)-(b)) <= 0)
92 #define	SEQ_GT(a, b)	((int32_t)((a)-(b)) > 0)
93 #define	SEQ_GEQ(a, b)	((int32_t)((a)-(b)) >= 0)
94 
95 /* TCP Protocol header */
96 typedef	struct tcphdr_s {
97 	uint8_t		th_lport[2];	/* Source port */
98 	uint8_t		th_fport[2];	/* Destination port */
99 	uint8_t		th_seq[4];	/* Sequence number */
100 	uint8_t		th_ack[4];	/* Acknowledgement number */
101 	uint8_t		th_offset_and_rsrvd[1]; /* Offset to the packet data */
102 	uint8_t		th_flags[1];
103 	uint8_t		th_win[2];	/* Allocation number */
104 	uint8_t		th_sum[2];	/* TCP checksum */
105 	uint8_t		th_urp[2];	/* Urgent pointer */
106 } tcph_t;
107 
108 #define	TCP_HDR_LENGTH(tcph) \
109 	((((tcph_t *)tcph)->th_offset_and_rsrvd[0] >>2) &(0xF << 2))
110 #define	TCP_MAX_COMBINED_HEADER_LENGTH	(60 + 60) /* Maxed out ip + tcp */
111 #define	TCP_MAX_IP_OPTIONS_LENGTH	(60 - IP_SIMPLE_HDR_LENGTH)
112 #define	TCP_MAX_HDR_LENGTH		60
113 #define	TCP_MAX_TCP_OPTIONS_LENGTH	(60 - sizeof (tcpha_t))
114 #define	TCP_MIN_HEADER_LENGTH		20
115 #define	TCP_MAXWIN			65535
116 #define	TCP_PORT_LEN			sizeof (in_port_t)
117 #define	TCP_MAX_WINSHIFT		14
118 #define	TCP_MAX_LARGEWIN		(TCP_MAXWIN << TCP_MAX_WINSHIFT)
119 #define	TCP_MAX_LSO_LENGTH	(IP_MAXPACKET - TCP_MAX_COMBINED_HEADER_LENGTH)
120 
121 #define	TCPIP_HDR_LENGTH(mp, n)					\
122 	(n) = IPH_HDR_LENGTH((mp)->b_rptr),			\
123 	(n) += TCP_HDR_LENGTH((tcpha_t *)&(mp)->b_rptr[(n)])
124 
125 /* TCP Protocol header (used if the header is known to be 32-bit aligned) */
126 typedef	struct tcphdra_s {
127 	in_port_t	tha_lport;	/* Source port */
128 	in_port_t	tha_fport;	/* Destination port */
129 	uint32_t	tha_seq;	/* Sequence number */
130 	uint32_t	tha_ack;	/* Acknowledgement number */
131 	uint8_t tha_offset_and_reserved; /* Offset to the packet data */
132 	uint8_t		tha_flags;
133 	uint16_t	tha_win;	/* Allocation number */
134 	uint16_t	tha_sum;	/* TCP checksum */
135 	uint16_t	tha_urp;	/* Urgent pointer */
136 } tcpha_t;
137 
138 struct conn_s;
139 struct tcp_listen_cnt_s;
140 
141 /*
142  * Control structure for each open TCP stream,
143  * defined only within the kernel or for a kmem user.
144  * NOTE: tcp_reinit_values MUST have a line for each field in this structure!
145  */
146 #if (defined(_KERNEL) || defined(_KMEMUSER))
147 
148 typedef struct tcp_s {
149 	struct tcp_s	*tcp_time_wait_next;
150 				/* Pointer to next T/W block */
151 	struct tcp_s	*tcp_time_wait_prev;
152 				/* Pointer to previous T/W next */
153 	int64_t		tcp_time_wait_expire;
154 
155 	struct conn_s	*tcp_connp;	/* back pointer to conn_t */
156 	tcp_stack_t	*tcp_tcps;	/* back pointer to tcp_stack_t */
157 
158 	struct cc_algo	*tcp_cc_algo;	/* congestion control algorithm */
159 	struct cc_var	tcp_ccv;	/* congestion control specific vars */
160 
161 	int32_t	tcp_state;
162 	int32_t	tcp_rcv_ws;		/* My window scale power */
163 	int32_t	tcp_snd_ws;		/* Sender's window scale power */
164 	uint32_t tcp_ts_recent;		/* Timestamp of earliest unacked */
165 					/*  data segment */
166 	clock_t	tcp_rto;		/* Round trip timeout */
167 	int64_t	tcp_last_rcv_lbolt;
168 				/* lbolt on last packet, used for PAWS */
169 	uint32_t tcp_rto_initial;	/* Initial RTO */
170 	uint32_t tcp_rto_min;		/* Minimum RTO */
171 	uint32_t tcp_rto_max;		/* Maximum RTO */
172 
173 	uint32_t tcp_snxt;		/* Senders next seq num */
174 	uint32_t tcp_swnd;		/* Senders window (relative to suna) */
175 	uint32_t tcp_mss;		/* Max segment size */
176 	uint32_t tcp_iss;		/* Initial send seq num */
177 	uint32_t tcp_rnxt;		/* Seq we expect to recv next */
178 	uint32_t tcp_rwnd;
179 
180 	/* Fields arranged in approximate access order along main paths */
181 	mblk_t	*tcp_xmit_head;		/* Head of xmit/rexmit list */
182 	mblk_t	*tcp_xmit_last;		/* Last valid data seen by tcp_wput */
183 	mblk_t	*tcp_xmit_tail;		/* Last data sent */
184 	uint32_t tcp_unsent;		/* # of bytes in hand that are unsent */
185 	uint32_t tcp_xmit_tail_unsent;	/* # of unsent bytes in xmit_tail */
186 	uint32_t tcp_suna;		/* Sender unacknowledged */
187 	uint32_t tcp_rexmit_nxt;	/* Next rexmit seq num */
188 	uint32_t tcp_rexmit_max;	/* Max retran seq num */
189 	uint32_t tcp_cwnd;		/* Congestion window */
190 	int32_t tcp_cwnd_cnt;		/* cwnd cnt in congestion avoidance */
191 	uint32_t tcp_naglim;		/* Tunable nagle limit */
192 	uint32_t	tcp_valid_bits;
193 #define	TCP_ISS_VALID	0x1	/* Is the tcp_iss seq num active? */
194 #define	TCP_FSS_VALID	0x2	/* Is the tcp_fss seq num active? */
195 #define	TCP_URG_VALID	0x4	/* Is the tcp_urg seq num active? */
196 #define	TCP_OFO_FIN_VALID 0x8	/* Has TCP received an out of order FIN? */
197 
198 	timeout_id_t	tcp_timer_tid;	/* Control block for timer service */
199 	uchar_t	tcp_timer_backoff;	/* Backoff shift count. */
200 	int64_t tcp_last_recv_time;	/* Last time we receive a segment. */
201 	uint32_t tcp_init_cwnd;		/* Initial cwnd (start/restart) */
202 
203 	/* Following manipulated by TCP under squeue protection */
204 	uint32_t
205 		tcp_urp_last_valid : 1,	/* Is tcp_urp_last valid? */
206 		tcp_hard_binding : 1,	/* TCP_DETACHED_NONEAGER */
207 		tcp_fin_acked : 1,	/* Has our FIN been acked? */
208 		tcp_fin_rcvd : 1,	/* Have we seen a FIN? */
209 
210 		tcp_fin_sent : 1,	/* Have we sent our FIN yet? */
211 		tcp_ordrel_done : 1,	/* Have we sent the ord_rel upstream? */
212 		tcp_detached : 1,	/* If we're detached from a stream */
213 		tcp_zero_win_probe: 1,	/* Zero win probing is in progress */
214 
215 		tcp_loopback: 1,	/* src and dst are the same machine */
216 		tcp_localnet: 1,	/* src and dst are on the same subnet */
217 		tcp_syn_defense: 1,	/* For defense against SYN attack */
218 #define	tcp_dontdrop	tcp_syn_defense
219 		tcp_set_timer : 1,
220 
221 		tcp_active_open: 1,	/* This is a active open */
222 		tcp_rexmit : 1,		/* TCP is retransmitting */
223 		tcp_snd_sack_ok : 1,	/* Can use SACK for this connection */
224 		tcp_hwcksum : 1,	/* The NIC is capable of hwcksum */
225 
226 		tcp_ip_forward_progress : 1,
227 		tcp_ecn_ok : 1,		/* Can use ECN for this connection */
228 		tcp_ecn_echo_on : 1,	/* Need to do ECN echo */
229 		tcp_ecn_cwr_sent : 1,	/* ECN_CWR has been sent */
230 
231 		tcp_cwr : 1,		/* Cwnd has reduced recently */
232 
233 		tcp_pad_to_bit31 : 11;
234 
235 	/* Following manipulated by TCP under squeue protection */
236 	uint32_t
237 		tcp_snd_ts_ok  : 1,
238 		tcp_snd_ws_ok  : 1,
239 		tcp_reserved_port : 1,
240 		tcp_in_free_list : 1,
241 
242 		tcp_snd_zcopy_on : 1,	/* xmit zero-copy enabled */
243 		tcp_snd_zcopy_aware : 1, /* client is zero-copy aware */
244 		tcp_xmit_zc_clean : 1,	/* the xmit list is free of zc-mblk */
245 		tcp_wait_for_eagers : 1, /* Wait for eagers to disappear */
246 
247 		tcp_accept_error : 1,	/* Error during TLI accept */
248 		tcp_send_discon_ind : 1, /* TLI accept err, send discon ind */
249 		tcp_cork : 1,		/* tcp_cork option */
250 		tcp_quickack : 1,	/* Send acks immediately */
251 		tcp_tconnind_started : 1, /* conn_ind message is being sent */
252 
253 		tcp_lso :1,		/* Lower layer is capable of LSO */
254 		tcp_is_wnd_shrnk : 1,	/* Window has shrunk */
255 
256 		tcp_pad_to_bit_31 : 17;
257 
258 	uint32_t	tcp_initial_pmtu; /* Initial outgoing Path MTU. */
259 
260 	mblk_t	*tcp_reass_head;	/* Out of order reassembly list head */
261 	mblk_t	*tcp_reass_tail;	/* Out of order reassembly list tail */
262 
263 	/* SACK related info */
264 	tcp_sack_info_t	tcp_sack_info;
265 
266 #define	tcp_pipe		tcp_sack_info.tcp_pipe
267 #define	tcp_fack		tcp_sack_info.tcp_fack
268 #define	tcp_sack_snxt		tcp_sack_info.tcp_sack_snxt
269 #define	tcp_max_sack_blk	tcp_sack_info.tcp_max_sack_blk
270 #define	tcp_num_sack_blk	tcp_sack_info.tcp_num_sack_blk
271 #define	tcp_sack_list		tcp_sack_info.tcp_sack_list
272 #define	tcp_num_notsack_blk	tcp_sack_info.tcp_num_notsack_blk
273 #define	tcp_cnt_notsack_list	tcp_sack_info.tcp_cnt_notsack_list
274 #define	tcp_notsack_list	tcp_sack_info.tcp_notsack_list
275 
276 	mblk_t	*tcp_rcv_list;		/* Queued until push, urgent data, */
277 	mblk_t	*tcp_rcv_last_head;	/* optdata, or the count exceeds */
278 	mblk_t	*tcp_rcv_last_tail;	/* tcp_rcv_push_wait. */
279 	uint32_t tcp_rcv_cnt;		/* tcp_rcv_list is b_next chain. */
280 
281 	uint32_t tcp_cwnd_ssthresh;	/* Congestion window */
282 	uint32_t tcp_cwnd_max;
283 	uint32_t tcp_csuna;		/* Clear (no rexmits in window) suna */
284 
285 	hrtime_t tcp_rtt_sum;		/* Round trip sum */
286 	uint32_t tcp_rtt_cnt;		/* Round trip count (non_dup ACKs) */
287 	hrtime_t tcp_rtt_sa;		/* Round trip smoothed average */
288 	hrtime_t tcp_rtt_sd;		/* Round trip smoothed deviation */
289 	uint32_t tcp_rtt_update;	/* Round trip update(s) */
290 	clock_t tcp_ms_we_have_waited;	/* Total retrans time */
291 
292 	uint32_t tcp_swl1;		/* These help us avoid using stale */
293 	uint32_t tcp_swl2;		/*  packets to update state */
294 
295 	uint32_t tcp_rack;		/* Seq # we have acked */
296 	uint32_t tcp_rack_cnt;		/* # of segs we have deferred ack */
297 	uint32_t tcp_rack_cur_max;	/* # of segs we may defer ack for now */
298 	uint32_t tcp_rack_abs_max;	/* # of segs we may defer ack ever */
299 	timeout_id_t	tcp_ack_tid;	/* Delayed ACK timer ID */
300 	timeout_id_t	tcp_push_tid;	/* Push timer ID */
301 
302 	uint32_t tcp_max_swnd;		/* Maximum swnd we have seen */
303 
304 	struct tcp_s *tcp_listener;	/* Our listener */
305 
306 	uint32_t tcp_irs;		/* Initial recv seq num */
307 	uint32_t tcp_fss;		/* Final/fin send seq num */
308 	uint32_t tcp_urg;		/* Urgent data seq num */
309 
310 	clock_t	tcp_first_timer_threshold;  /* When to prod IP */
311 	clock_t	tcp_second_timer_threshold; /* When to give up completely */
312 	clock_t	tcp_first_ctimer_threshold; /* 1st threshold while connecting */
313 	clock_t tcp_second_ctimer_threshold; /* 2nd ... while connecting */
314 
315 	uint32_t tcp_urp_last;		/* Last urp for which signal sent */
316 	mblk_t	*tcp_urp_mp;		/* T_EXDATA_IND for urgent byte */
317 	mblk_t	*tcp_urp_mark_mp;	/* zero-length marked/unmarked msg */
318 
319 	int tcp_conn_req_cnt_q0;	/* # of conn reqs in SYN_RCVD */
320 	int tcp_conn_req_cnt_q;	/* # of conn reqs in ESTABLISHED */
321 	int tcp_conn_req_max;	/* # of ESTABLISHED conn reqs allowed */
322 	t_scalar_t tcp_conn_req_seqnum;	/* Incrementing pending conn req ID */
323 #define	tcp_ip_addr_cache	tcp_reass_tail
324 					/* Cache ip addresses that */
325 					/* complete the 3-way handshake */
326 	kmutex_t  tcp_eager_lock;
327 	struct tcp_s *tcp_eager_next_q; /* next eager in ESTABLISHED state */
328 	struct tcp_s *tcp_eager_last_q;	/* last eager in ESTABLISHED state */
329 	struct tcp_s *tcp_eager_next_q0; /* next eager in SYN_RCVD state */
330 	struct tcp_s *tcp_eager_prev_q0; /* prev eager in SYN_RCVD state */
331 					/* all eagers form a circular list */
332 	boolean_t tcp_conn_def_q0;	/* move from q0 to q deferred */
333 
334 	union {
335 	    mblk_t *tcp_eager_conn_ind; /* T_CONN_IND waiting for 3rd ack. */
336 	    mblk_t *tcp_opts_conn_req; /* T_CONN_REQ w/ options processed */
337 	} tcp_conn;
338 	uint32_t tcp_syn_rcvd_timeout;	/* How many SYN_RCVD timeout in q0 */
339 
340 	/*
341 	 * TCP Keepalive Timer members.
342 	 * All keepalive timer intervals are in milliseconds.
343 	 */
344 	int32_t	tcp_ka_last_intrvl;	/* Last probe interval */
345 	timeout_id_t tcp_ka_tid;	/* Keepalive timer ID */
346 	uint32_t tcp_ka_interval;	/* Keepalive interval */
347 
348 	/*
349 	 * TCP connection is terminated if we don't hear back from the peer
350 	 * for tcp_ka_abort_thres milliseconds after the first keepalive probe.
351 	 * tcp_ka_rinterval is the interval in milliseconds between successive
352 	 * keepalive probes. tcp_ka_cnt is the number of keepalive probes to
353 	 * be sent before terminating the connection, if we don't hear back from
354 	 * peer.
355 	 * tcp_ka_abort_thres = tcp_ka_rinterval * tcp_ka_cnt
356 	 */
357 	uint32_t tcp_ka_rinterval;	/* keepalive retransmit interval */
358 	uint32_t tcp_ka_abort_thres;	/* Keepalive abort threshold */
359 	uint32_t tcp_ka_cnt;		/* count of keepalive probes */
360 
361 	int32_t	tcp_client_errno;	/* How the client screwed up */
362 
363 	/*
364 	 * The header template lives in conn_ht_iphc allocated by tcp_build_hdrs
365 	 * We maintain three pointers into conn_ht_iphc.
366 	 */
367 	ipha_t	*tcp_ipha;		/* IPv4 header in conn_ht_iphc */
368 	ip6_t	*tcp_ip6h;		/* IPv6 header in conn_ht_iphc */
369 	tcpha_t	*tcp_tcpha;		/* TCP header in conn_ht_iphc */
370 
371 	uint16_t tcp_last_sent_len;	/* Record length for nagle */
372 	uint16_t tcp_last_recv_len;	/* Used by DTrace */
373 	uint16_t tcp_dupack_cnt;	/* # of consequtive duplicate acks */
374 
375 	kmutex_t	*tcp_acceptor_lockp;	/* Ptr to tf_lock */
376 
377 	mblk_t		*tcp_ordrel_mp;		/* T_ordrel_ind mblk */
378 	t_uscalar_t	tcp_acceptor_id;	/* ACCEPTOR_id */
379 
380 	int		tcp_ipsec_overhead;
381 
382 	uint_t		tcp_recvtos;	/* Last received IP_RECVTOS */
383 	uint_t		tcp_recvifindex; /* Last received IPV6_RCVPKTINFO */
384 	uint_t		tcp_recvhops;	/* Last received IPV6_RECVHOPLIMIT */
385 	uint_t		tcp_recvtclass;	/* Last received IPV6_RECVTCLASS */
386 	ip6_hbh_t	*tcp_hopopts;	/* Last received IPV6_RECVHOPOPTS */
387 	ip6_dest_t	*tcp_dstopts;	/* Last received IPV6_RECVDSTOPTS */
388 	ip6_dest_t	*tcp_rthdrdstopts; /* Last recv IPV6_RECVRTHDRDSTOPTS */
389 	ip6_rthdr_t	*tcp_rthdr;	/* Last received IPV6_RECVRTHDR */
390 	uint_t		tcp_hopoptslen;
391 	uint_t		tcp_dstoptslen;
392 	uint_t		tcp_rthdrdstoptslen;
393 	uint_t		tcp_rthdrlen;
394 
395 	mblk_t		*tcp_timercache;
396 
397 	kmutex_t	tcp_closelock;
398 	kcondvar_t	tcp_closecv;
399 	uint8_t		tcp_closed;
400 	uint8_t		tcp_closeflags;
401 	mblk_t		tcp_closemp;
402 	timeout_id_t	tcp_linger_tid;	/* Linger timer ID */
403 
404 	struct tcp_s *tcp_acceptor_hash; /* Acceptor hash chain */
405 	struct tcp_s **tcp_ptpahn; /* Pointer to previous accept hash next. */
406 	struct tcp_s *tcp_bind_hash; /* Bind hash chain */
407 	struct tcp_s *tcp_bind_hash_port; /* tcp_t's bound to the same lport */
408 	struct tcp_s **tcp_ptpbhn;
409 
410 	uint_t		tcp_maxpsz_multiplier;
411 
412 	uint32_t	tcp_lso_max; /* maximum LSO payload */
413 
414 	uint32_t	tcp_ofo_fin_seq; /* Recv out of order FIN seq num */
415 	uint32_t	tcp_cwr_snd_max;
416 
417 	struct tcp_s *tcp_saved_listener;	/* saved value of listener */
418 
419 	uint32_t	tcp_in_ack_unsent;	/* ACK for unsent data cnt. */
420 
421 	/*
422 	 * All fusion-related fields are protected by squeue.
423 	 */
424 	struct tcp_s *tcp_loopback_peer;	/* peer tcp for loopback */
425 	mblk_t	*tcp_fused_sigurg_mp;		/* M_PCSIG mblk for SIGURG */
426 
427 	uint32_t
428 		tcp_fused : 1,		/* loopback tcp in fusion mode */
429 		tcp_unfusable : 1,	/* fusion not allowed on endpoint */
430 		tcp_fused_sigurg : 1,	/* send SIGURG upon draining */
431 
432 		tcp_fuse_to_bit_31 : 29;
433 
434 	kmutex_t tcp_non_sq_lock;
435 
436 	/*
437 	 * This variable is accessed without any lock protection
438 	 * and therefore must not be declared as a bit field along
439 	 * with the rest which require such condition.
440 	 */
441 	boolean_t	tcp_issocket;	/* this is a socket tcp */
442 
443 	/* protected by the tcp_non_sq_lock lock */
444 	uint32_t	tcp_squeue_bytes;
445 
446 	/*
447 	 * tcp_closemp_used is protected by listener's tcp_eager_lock
448 	 * when used for eagers. When used for a tcp in TIME_WAIT state
449 	 * or in tcp_close(), it is not protected by any lock as we
450 	 * do not expect any other thread to use it concurrently.
451 	 * We do allow re-use of tcp_closemp in tcp_time_wait_collector()
452 	 * and tcp_close() but not concurrently.
453 	 */
454 	boolean_t tcp_closemp_used;
455 
456 	/*
457 	 * previous and next eagers in the list of droppable eagers. See
458 	 * the comments before MAKE_DROPPABLE(). These pointers are
459 	 * protected by listener's tcp_eager_lock.
460 	 */
461 	struct tcp_s	*tcp_eager_prev_drop_q0;
462 	struct tcp_s	*tcp_eager_next_drop_q0;
463 
464 	/*
465 	 * Have we flow controlled xmitter?
466 	 * This variable can be modified outside the squeue and hence must
467 	 * not be declared as a bit field along with the rest that are
468 	 * modified only within the squeue.
469 	 * protected by the tcp_non_sq_lock lock.
470 	 */
471 	boolean_t	tcp_flow_stopped;
472 
473 	/*
474 	 * Sender's next sequence number at the time the window was shrunk.
475 	 */
476 	uint32_t	tcp_snxt_shrunk;
477 
478 	/*
479 	 * Socket generation number which is bumped when a connection attempt
480 	 * is initiated. Its main purpose is to ensure that the socket does not
481 	 * miss the asynchronous connected/disconnected notification.
482 	 */
483 	sock_connid_t	tcp_connid;
484 
485 	/* mblk_t used to enter TCP's squeue from the service routine. */
486 	mblk_t		*tcp_rsrv_mp;
487 	/* Mutex for accessing tcp_rsrv_mp */
488 	kmutex_t	tcp_rsrv_mp_lock;
489 
490 	/* For connection counting. */
491 	struct tcp_listen_cnt_s	*tcp_listen_cnt;
492 
493 	/* Segment reassembly timer. */
494 	timeout_id_t		tcp_reass_tid;
495 
496 	/* FIN-WAIT-2 flush timeout */
497 	uint32_t		tcp_fin_wait_2_flush_interval;
498 
499 	tcp_conn_stats_t	tcp_cs;
500 
501 #ifdef DEBUG
502 	pc_t			tcmp_stk[15];
503 #endif
504 } tcp_t;
505 
506 #ifdef DEBUG
507 #define	TCP_DEBUG_GETPCSTACK(buffer, depth)	((void) getpcstack(buffer, \
508 						    depth))
509 #else
510 #define	TCP_DEBUG_GETPCSTACK(buffer, depth)
511 #endif
512 
513 extern void	tcp_conn_reclaim(void *);
514 extern void	tcp_free(tcp_t *tcp);
515 extern void	tcp_ddi_g_init(void);
516 extern void	tcp_ddi_g_destroy(void);
517 extern conn_t	*tcp_get_conn(void *arg, tcp_stack_t *);
518 extern mblk_t	*tcp_snmp_get(queue_t *, mblk_t *, boolean_t);
519 extern int	tcp_snmp_set(queue_t *, int, int, uchar_t *, int len);
520 
521 /* Pad for the tf_t structure to avoid false cache line sharing. */
522 #define	TF_CACHEL_PAD	64
523 
524 /*
525  * The TCP Fanout structure for bind and acceptor hashes.
526  * The hash tables and their linkage (tcp_*_hash, tcp_ptp*hn) are
527  * protected by the per-bucket tf_lock.  Each tcp_t
528  * inserted in the list points back at this lock using tcp_*_lockp.
529  *
530  * The bind and acceptor hash queues are lists of tcp_t.
531  */
532 /* listener hash and acceptor hash queue head */
533 typedef struct tf_s {
534 	tcp_t		*tf_tcp;
535 	kmutex_t	tf_lock;
536 	unsigned char	tf_pad[TF_CACHEL_PAD -
537 	    (sizeof (tcp_t *) + sizeof (kmutex_t))];
538 } tf_t;
539 
540 
541 /* Also used in ipclassifier.c */
542 extern struct kmem_cache  *tcp_sack_info_cache;
543 
544 #endif	/* (defined(_KERNEL) || defined(_KMEMUSER)) */
545 
546 /* Contract private interface between TCP and Clustering. */
547 
548 #define	CL_TCPI_V1	1	/* cl_tcpi_version number */
549 
550 typedef struct cl_tcp_info_s {
551 	ushort_t	cl_tcpi_version;	/* cl_tcp_info_t's version no */
552 	ushort_t	cl_tcpi_ipversion;	/* IP version */
553 	int32_t		cl_tcpi_state;		/* TCP state */
554 	in_port_t	cl_tcpi_lport;		/* Local port */
555 	in_port_t	cl_tcpi_fport;		/* Remote port */
556 	in6_addr_t	cl_tcpi_laddr_v6;	/* Local IP address */
557 	in6_addr_t	cl_tcpi_faddr_v6;	/* Remote IP address */
558 #ifdef _KERNEL
559 /* Note: V4_PART_OF_V6 is meant to be used only for _KERNEL defined stuff */
560 #define	cl_tcpi_laddr	V4_PART_OF_V6(cl_tcpi_laddr_v6)
561 #define	cl_tcpi_faddr	V4_PART_OF_V6(cl_tcpi_faddr_v6)
562 
563 #endif	/* _KERNEL */
564 } cl_tcp_info_t;
565 
566 /*
567  * Hook functions to enable cluster networking
568  * On non-clustered systems these vectors must always be NULL.
569  */
570 extern void	(*cl_inet_listen)(netstackid_t, uint8_t, sa_family_t,
571 		    uint8_t *, in_port_t, void *);
572 extern void	(*cl_inet_unlisten)(netstackid_t, uint8_t, sa_family_t,
573 		    uint8_t *, in_port_t, void *);
574 
575 /*
576  * Contracted Consolidation Private ioctl for aborting TCP connections.
577  * In order to keep the offsets and size of the structure the same between
578  * a 32-bit application and a 64-bit amd64 kernel, we use a #pragma
579  * pack(4).
580  */
581 #define	TCP_IOC_ABORT_CONN	(('T' << 8) + 91)
582 
583 #if _LONG_LONG_ALIGNMENT == 8 && _LONG_LONG_ALIGNMENT_32 == 4
584 #pragma pack(4)
585 #endif
586 
587 typedef struct tcp_ioc_abort_conn_s {
588 	struct sockaddr_storage ac_local;	/* local addr and port */
589 	struct sockaddr_storage ac_remote;	/* remote addr and port */
590 	int32_t ac_start;			/* start state */
591 	int32_t ac_end;				/* end state  */
592 	int32_t ac_zoneid;			/* zoneid */
593 } tcp_ioc_abort_conn_t;
594 
595 #if _LONG_LONG_ALIGNMENT == 8 && _LONG_LONG_ALIGNMENT_32 == 4
596 #pragma pack()
597 #endif
598 
599 #ifdef	__cplusplus
600 }
601 #endif
602 
603 #endif	/* _INET_TCP_H */
604