xref: /titanic_41/usr/src/uts/common/inet/tcp.h (revision b0fc0e77220f1fa4c933fd58a4e1dedcd650b0f1)
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 2006 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 /* Copyright (c) 1990 Mentat Inc. */
26 
27 #ifndef	_INET_TCP_H
28 #define	_INET_TCP_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #ifdef	__cplusplus
33 extern "C" {
34 #endif
35 
36 #include <sys/inttypes.h>
37 #include <netinet/ip6.h>
38 #include <netinet/tcp.h>
39 #include <inet/tcp_sack.h>
40 #include <sys/socket.h>
41 #include <sys/multidata.h>
42 #include <inet/kssl/ksslapi.h>
43 
44 /*
45  * Private (and possibly temporary) ioctl used by configuration code
46  * to lock in the "default" stream for detached closes.
47  */
48 #define	TCP_IOC_DEFAULT_Q	(('T' << 8) + 51)
49 
50 /* TCP states */
51 #define	TCPS_CLOSED		-6
52 #define	TCPS_IDLE		-5	/* idle (opened, but not bound) */
53 #define	TCPS_BOUND		-4	/* bound, ready to connect or accept */
54 #define	TCPS_LISTEN		-3	/* listening for connection */
55 #define	TCPS_SYN_SENT		-2	/* active, have sent syn */
56 #define	TCPS_SYN_RCVD		-1	/* have received syn (and sent ours) */
57 /* states < TCPS_ESTABLISHED are those where connections not established */
58 #define	TCPS_ESTABLISHED	0	/* established */
59 #define	TCPS_CLOSE_WAIT		1	/* rcvd fin, waiting for close */
60 /* states > TCPS_CLOSE_WAIT are those where user has closed */
61 #define	TCPS_FIN_WAIT_1		2	/* have closed and sent fin */
62 #define	TCPS_CLOSING		3	/* closed, xchd FIN, await FIN ACK */
63 #define	TCPS_LAST_ACK		4	/* had fin and close; await FIN ACK */
64 /* states > TCPS_CLOSE_WAIT && < TCPS_FIN_WAIT_2 await ACK of FIN */
65 #define	TCPS_FIN_WAIT_2		5	/* have closed, fin is acked */
66 #define	TCPS_TIME_WAIT		6	/* in 2*msl quiet wait after close */
67 
68 /*
69  * Internal flags used in conjunction with the packet header flags.
70  * Used in tcp_rput_data to keep track of what needs to be done.
71  */
72 #define	TH_LIMIT_XMIT		0x0400	/* Limited xmit is needed */
73 #define	TH_XMIT_NEEDED		0x0800	/* Window opened - send queued data */
74 #define	TH_REXMIT_NEEDED	0x1000	/* Time expired for unacked data */
75 #define	TH_ACK_NEEDED		0x2000	/* Send an ack now. */
76 #define	TH_NEED_SACK_REXMIT	0x4000	/* Use SACK info to retransmission */
77 #define	TH_ACK_TIMER_NEEDED	0x8000	/* Start the delayed ACK timer */
78 #define	TH_ORDREL_NEEDED	0x10000	/* Generate an ordrel indication */
79 #define	TH_MARKNEXT_NEEDED	0x20000	/* Data should have MSGMARKNEXT */
80 #define	TH_SEND_URP_MARK	0x40000	/* Send up tcp_urp_mark_mp */
81 
82 /*
83  * TCP sequence numbers are 32 bit integers operated
84  * on with modular arithmetic.  These macros can be
85  * used to compare such integers.
86  */
87 #define	SEQ_LT(a, b)	((int32_t)((a)-(b)) < 0)
88 #define	SEQ_LEQ(a, b)	((int32_t)((a)-(b)) <= 0)
89 #define	SEQ_GT(a, b)	((int32_t)((a)-(b)) > 0)
90 #define	SEQ_GEQ(a, b)	((int32_t)((a)-(b)) >= 0)
91 
92 /* TCP Protocol header */
93 typedef	struct tcphdr_s {
94 	uint8_t		th_lport[2];	/* Source port */
95 	uint8_t		th_fport[2];	/* Destination port */
96 	uint8_t		th_seq[4];	/* Sequence number */
97 	uint8_t		th_ack[4];	/* Acknowledgement number */
98 	uint8_t		th_offset_and_rsrvd[1]; /* Offset to the packet data */
99 	uint8_t		th_flags[1];
100 	uint8_t		th_win[2];	/* Allocation number */
101 	uint8_t		th_sum[2];	/* TCP checksum */
102 	uint8_t		th_urp[2];	/* Urgent pointer */
103 } tcph_t;
104 
105 #define	TCP_HDR_LENGTH(tcph) (((tcph)->th_offset_and_rsrvd[0] >>2) &(0xF << 2))
106 #define	TCP_MAX_COMBINED_HEADER_LENGTH	(60 + 60) /* Maxed out ip + tcp */
107 #define	TCP_MAX_IP_OPTIONS_LENGTH	(60 - IP_SIMPLE_HDR_LENGTH)
108 #define	TCP_MAX_HDR_LENGTH		60
109 #define	TCP_MAX_TCP_OPTIONS_LENGTH	(60 - sizeof (tcph_t))
110 #define	TCP_MIN_HEADER_LENGTH		20
111 #define	TCP_MAXWIN			65535
112 #define	TCP_PORT_LEN			sizeof (in_port_t)
113 #define	TCP_MAX_WINSHIFT		14
114 #define	TCP_MAX_LARGEWIN		(TCP_MAXWIN << TCP_MAX_WINSHIFT)
115 
116 #define	TCPIP_HDR_LENGTH(mp, n)					\
117 	(n) = IPH_HDR_LENGTH((mp)->b_rptr),			\
118 	(n) += TCP_HDR_LENGTH((tcph_t *)&(mp)->b_rptr[(n)])
119 
120 /* TCP Protocol header (used if the header is known to be 32-bit aligned) */
121 typedef	struct tcphdra_s {
122 	in_port_t	tha_lport;	/* Source port */
123 	in_port_t	tha_fport;	/* Destination port */
124 	uint32_t	tha_seq;	/* Sequence number */
125 	uint32_t	tha_ack;	/* Acknowledgement number */
126 	uint8_t tha_offset_and_reserved; /* Offset to the packet data */
127 	uint8_t		tha_flags;
128 	uint16_t	tha_win;	/* Allocation number */
129 	uint16_t	tha_sum;	/* TCP checksum */
130 	uint16_t	tha_urp;	/* Urgent pointer */
131 } tcpha_t;
132 
133 struct conn_s;
134 
135 /*
136  * Control structure for each open TCP stream,
137  * defined only within the kernel or for a kmem user.
138  * NOTE: tcp_reinit_values MUST have a line for each field in this structure!
139  */
140 #if (defined(_KERNEL) || defined(_KMEMUSER))
141 
142 typedef struct tcp_s {
143 				/* Pointer to previous bind hash next. */
144 	struct tcp_s *tcp_time_wait_next;
145 				/* Pointer to next T/W block */
146 	struct tcp_s *tcp_time_wait_prev;
147 				/* Pointer to previous T/W next */
148 	clock_t	tcp_time_wait_expire;
149 	struct conn_s *tcp_connp;
150 
151 	int32_t	tcp_state;
152 	int32_t	tcp_rcv_ws;		/* My window scale power */
153 	int32_t	tcp_snd_ws;		/* Sender's window scale power */
154 	uint32_t tcp_ts_recent;		/* Timestamp of earliest unacked */
155 					/*  data segment */
156 	clock_t	tcp_rto;		/* Round trip timeout */
157 	clock_t	tcp_last_rcv_lbolt;
158 				/* lbolt on last packet, used for PAWS */
159 
160 	uint32_t tcp_snxt;		/* Senders next seq num */
161 	uint32_t tcp_swnd;		/* Senders window (relative to suna) */
162 	uint32_t tcp_mss;		/* Max segment size */
163 	uint32_t tcp_iss;		/* Initial send seq num */
164 	uint32_t tcp_rnxt;		/* Seq we expect to recv next */
165 	uint32_t tcp_rwnd;
166 
167 	queue_t	*tcp_rq;		/* Our upstream neighbor (client) */
168 	queue_t	*tcp_wq;		/* Our downstream neighbor */
169 
170 	/* Fields arranged in approximate access order along main paths */
171 	mblk_t	*tcp_xmit_head;		/* Head of rexmit list */
172 	mblk_t	*tcp_xmit_last;		/* last valid data seen by tcp_wput */
173 	mblk_t	*tcp_xmit_tail;		/* Last rexmit data sent */
174 	uint32_t tcp_unsent;		/* # of bytes in hand that are unsent */
175 	uint32_t tcp_xmit_tail_unsent;	/* # of unsent bytes in xmit_tail */
176 
177 	uint32_t tcp_suna;		/* Sender unacknowledged */
178 	uint32_t tcp_rexmit_nxt;	/* Next rexmit seq num */
179 	uint32_t tcp_rexmit_max;	/* Max retran seq num */
180 	int32_t	tcp_snd_burst;		/* Send burst factor */
181 	uint32_t tcp_cwnd;		/* Congestion window */
182 	int32_t tcp_cwnd_cnt;		/* cwnd cnt in congestion avoidance */
183 
184 	uint32_t tcp_ibsegs;		/* Inbound segments on this stream */
185 	uint32_t tcp_obsegs;		/* Outbound segments on this stream */
186 
187 	uint32_t tcp_naglim;		/* Tunable nagle limit */
188 	uint32_t	tcp_valid_bits;
189 #define	TCP_ISS_VALID	0x1	/* Is the tcp_iss seq num active? */
190 #define	TCP_FSS_VALID	0x2	/* Is the tcp_fss seq num active? */
191 #define	TCP_URG_VALID	0x4	/* Is the tcp_urg seq num active? */
192 #define	TCP_OFO_FIN_VALID 0x8	/* Has TCP received an out of order FIN? */
193 
194 
195 	int32_t	tcp_xmit_hiwater;	/* Send buffer high water mark. */
196 
197 	timeout_id_t	tcp_timer_tid;	/* Control block for timer service */
198 	uchar_t	tcp_timer_backoff;	/* Backoff shift count. */
199 	int64_t tcp_last_recv_time;	/* Last time we receive a segment. */
200 	uint32_t tcp_init_cwnd;		/* Initial cwnd (start/restart) */
201 
202 	/*
203 	 * Following socket options are set by sockfs outside the squeue
204 	 * and we want to separate these bit fields from the other bit fields
205 	 * set by TCP to avoid grabbing locks. sockfs ensures that only one
206 	 * thread in sockfs can set a socket option at a time on a conn_t.
207 	 * However TCP may read these options concurrently. The linger option
208 	 * needs atomicity since tcp_lingertime also needs to be in sync.
209 	 * However TCP uses it only during close, and by then no socket option
210 	 * can come down. So we don't need any locks, instead just separating
211 	 * the sockfs settable bit fields from the other bit fields is
212 	 * sufficient.
213 	 */
214 	uint32_t
215 		tcp_debug : 1,		/* SO_DEBUG "socket" option. */
216 		tcp_dontroute : 1,	/* SO_DONTROUTE "socket" option. */
217 		tcp_broadcast : 1,	/* SO_BROADCAST "socket" option. */
218 		tcp_useloopback : 1,	/* SO_USELOOPBACK "socket" option. */
219 
220 		tcp_oobinline : 1,	/* SO_OOBINLINE "socket" option. */
221 		tcp_dgram_errind : 1,	/* SO_DGRAM_ERRIND option */
222 		tcp_linger : 1,		/* SO_LINGER turned on */
223 		tcp_reuseaddr	: 1,	/* SO_REUSEADDR "socket" option. */
224 
225 		tcp_junk_to_bit_31 : 24;
226 
227 	/* Following manipulated by TCP under squeue protection */
228 	uint32_t
229 		tcp_urp_last_valid : 1,	/* Is tcp_urp_last valid? */
230 		tcp_hard_binding : 1,	/* If we've started a full bind */
231 		tcp_hard_bound : 1,	/* If we've done a full bind with IP */
232 		tcp_fin_acked : 1,	/* Has our FIN been acked? */
233 
234 		tcp_fin_rcvd : 1,	/* Have we seen a FIN? */
235 		tcp_fin_sent : 1,	/* Have we sent our FIN yet? */
236 		tcp_ordrel_done : 1,	/* Have we sent the ord_rel upstream? */
237 		tcp_flow_stopped : 1,	/* Have we flow controlled xmitter? */
238 
239 		tcp_detached : 1,	/* If we're detached from a stream */
240 		tcp_bind_pending : 1,	/* Client is waiting for bind ack */
241 		tcp_unbind_pending : 1, /* Client sent T_UNBIND_REQ */
242 		tcp_deferred_clean_death : 1,
243 					/* defer tcp endpoint cleanup etc. */
244 
245 		tcp_conn_def_q0: 1,	/* move from q0 to q deferred */
246 		tcp_ka_enabled: 1,	/* Connection KeepAlive Timer needed */
247 		tcp_zero_win_probe: 1,	/* Zero win probing is in progress */
248 		tcp_loopback: 1,	/* src and dst are the same machine */
249 
250 		tcp_localnet: 1,	/* src and dst are on the same subnet */
251 		tcp_syn_defense: 1,	/* For defense against SYN attack */
252 #define	tcp_dontdrop	tcp_syn_defense
253 		tcp_set_timer : 1,
254 		tcp_active_open: 1,	/* This is a active open */
255 
256 		tcp_timeout : 1,	/* qbufcall failed, qtimeout pending */
257 		tcp_rexmit : 1,		/* TCP is retransmitting */
258 		tcp_snd_sack_ok : 1,	/* Can use SACK for this connection */
259 		tcp_empty_flag : 1,	/* Empty flag for future use */
260 
261 		tcp_recvdstaddr : 1,	/* return T_EXTCONN_IND with dst addr */
262 		tcp_hwcksum : 1,	/* The NIC is capable of hwcksum */
263 		tcp_ip_forward_progress : 1,
264 		tcp_anon_priv_bind : 1,
265 
266 		tcp_ecn_ok : 1,		/* Can use ECN for this connection */
267 		tcp_ecn_echo_on : 1,	/* Need to do ECN echo */
268 		tcp_ecn_cwr_sent : 1,	/* ECN_CWR has been sent */
269 		tcp_cwr : 1;		/* Cwnd has reduced recently */
270 
271 	/* Following manipulated by TCP under squeue protection */
272 	uint32_t
273 		tcp_mdt : 1,		/* Lower layer is capable of MDT */
274 		tcp_snd_ts_ok  : 1,
275 		tcp_snd_ws_ok  : 1,
276 		tcp_exclbind	: 1,	/* ``exclusive'' binding */
277 
278 		tcp_reserved_port : 1,
279 		tcp_hdr_grown	: 1,
280 		tcp_in_free_list : 1,
281 		tcp_snd_zcopy_on : 1,	/* xmit zero-copy enabled */
282 
283 		tcp_snd_zcopy_aware : 1, /* client is zero-copy aware */
284 		tcp_xmit_zc_clean : 1,	/* the xmit list is free of zc-mblk */
285 		tcp_wait_for_eagers : 1, /* Wait for eagers to disappear */
286 		tcp_accept_error : 1,	/* Error during TLI accept */
287 
288 		tcp_send_discon_ind : 1, /* TLI accept err, send discon ind */
289 		tcp_cork : 1,		/* tcp_cork option */
290 		tcp_pad_to_bit_31 : 18;
291 
292 	uint32_t	tcp_if_mtu;	/* Outgoing interface MTU. */
293 
294 	mblk_t	*tcp_reass_head;	/* Out of order reassembly list head */
295 	mblk_t	*tcp_reass_tail;	/* Out of order reassembly list tail */
296 
297 	tcp_sack_info_t	*tcp_sack_info;
298 
299 #define	tcp_pipe	tcp_sack_info->tcp_pipe
300 #define	tcp_fack	tcp_sack_info->tcp_fack
301 #define	tcp_sack_snxt	tcp_sack_info->tcp_sack_snxt
302 #define	tcp_max_sack_blk	tcp_sack_info->tcp_max_sack_blk
303 #define	tcp_num_sack_blk	tcp_sack_info->tcp_num_sack_blk
304 #define	tcp_sack_list		tcp_sack_info->tcp_sack_list
305 #define	tcp_num_notsack_blk	tcp_sack_info->tcp_num_notsack_blk
306 #define	tcp_cnt_notsack_list	tcp_sack_info->tcp_cnt_notsack_list
307 #define	tcp_notsack_list		tcp_sack_info->tcp_notsack_list
308 
309 	mblk_t	*tcp_rcv_list;		/* Queued until push, urgent data, */
310 	mblk_t	*tcp_rcv_last_head;	/* optdata, or the count exceeds */
311 	mblk_t	*tcp_rcv_last_tail;	/* tcp_rcv_push_wait. */
312 	uint32_t tcp_rcv_cnt;		/* tcp_rcv_list is b_next chain. */
313 
314 	uint32_t tcp_cwnd_ssthresh;	/* Congestion window */
315 	uint32_t tcp_cwnd_max;
316 	uint32_t tcp_csuna;		/* Clear (no rexmits in window) suna */
317 
318 	clock_t	tcp_rtt_sa;		/* Round trip smoothed average */
319 	clock_t	tcp_rtt_sd;		/* Round trip smoothed deviation */
320 	clock_t	tcp_rtt_update;		/* Round trip update(s) */
321 	clock_t tcp_ms_we_have_waited;	/* Total retrans time */
322 
323 	uint32_t tcp_swl1;		/* These help us avoid using stale */
324 	uint32_t tcp_swl2;		/*  packets to update state */
325 
326 	uint32_t tcp_rack;		/* Seq # we have acked */
327 	uint32_t tcp_rack_cnt;		/* # of segs we have deferred ack */
328 	uint32_t tcp_rack_cur_max;	/* # of segs we may defer ack for now */
329 	uint32_t tcp_rack_abs_max;	/* # of segs we may defer ack ever */
330 	timeout_id_t	tcp_ack_tid;	/* Delayed ACK timer ID */
331 	timeout_id_t	tcp_push_tid;	/* Push timer ID */
332 
333 	uint32_t tcp_max_swnd;		/* Maximum swnd we have seen */
334 
335 	struct tcp_s *tcp_listener;	/* Our listener */
336 
337 	int32_t	tcp_xmit_lowater;	/* Send buffer low water mark. */
338 
339 	uint32_t tcp_irs;		/* Initial recv seq num */
340 	uint32_t tcp_fss;		/* Final/fin send seq num */
341 	uint32_t tcp_urg;		/* Urgent data seq num */
342 
343 	clock_t	tcp_first_timer_threshold;  /* When to prod IP */
344 	clock_t	tcp_second_timer_threshold; /* When to give up completely */
345 	clock_t	tcp_first_ctimer_threshold; /* 1st threshold while connecting */
346 	clock_t tcp_second_ctimer_threshold; /* 2nd ... while connecting */
347 
348 	int	tcp_lingertime;		/* Close linger time (in seconds) */
349 
350 	uint32_t tcp_urp_last;		/* Last urp for which signal sent */
351 	mblk_t	*tcp_urp_mp;		/* T_EXDATA_IND for urgent byte */
352 	mblk_t	*tcp_urp_mark_mp;	/* zero-length marked/unmarked msg */
353 
354 	int tcp_conn_req_cnt_q0;	/* # of conn reqs in SYN_RCVD */
355 	int tcp_conn_req_cnt_q;	/* # of conn reqs in ESTABLISHED */
356 	int tcp_conn_req_max;	/* # of ESTABLISHED conn reqs allowed */
357 	t_scalar_t tcp_conn_req_seqnum;	/* Incrementing pending conn req ID */
358 #define	tcp_ip_addr_cache	tcp_reass_tail
359 					/* Cache ip addresses that */
360 					/* complete the 3-way handshake */
361 	kmutex_t  tcp_eager_lock;
362 	struct tcp_s *tcp_eager_next_q; /* next eager in ESTABLISHED state */
363 	struct tcp_s *tcp_eager_last_q;	/* last eager in ESTABLISHED state */
364 	struct tcp_s *tcp_eager_next_q0; /* next eager in SYN_RCVD state */
365 	struct tcp_s *tcp_eager_prev_q0; /* prev eager in SYN_RCVD state */
366 					/* all eagers form a circular list */
367 	union {
368 	    mblk_t *tcp_eager_conn_ind; /* T_CONN_IND waiting for 3rd ack. */
369 	    mblk_t *tcp_opts_conn_req; /* T_CONN_REQ w/ options processed */
370 	} tcp_conn;
371 	uint32_t tcp_syn_rcvd_timeout;	/* How many SYN_RCVD timeout in q0 */
372 
373 	/* TCP Keepalive Timer members */
374 	int32_t	tcp_ka_last_intrvl;	/* Last probe interval */
375 	timeout_id_t tcp_ka_tid;	/* Keepalive timer ID */
376 	uint32_t tcp_ka_interval;	/* Keepalive interval */
377 	uint32_t tcp_ka_abort_thres;	/* Keepalive abort threshold */
378 
379 	int32_t	tcp_client_errno;	/* How the client screwed up */
380 
381 	char	*tcp_iphc;		/* Buffer holding tcp/ip hdr template */
382 	int	tcp_iphc_len;		/* actual allocated buffer size */
383 	int32_t	tcp_hdr_len;		/* Byte len of combined TCP/IP hdr */
384 	ipha_t	*tcp_ipha;		/* IPv4 header in the buffer */
385 	ip6_t	*tcp_ip6h;		/* IPv6 header in the buffer */
386 	int	tcp_ip_hdr_len;		/* Byte len of our current IPvx hdr */
387 	tcph_t	*tcp_tcph;		/* tcp header within combined hdr */
388 	int32_t	tcp_tcp_hdr_len;	/* tcp header len within combined */
389 
390 	uint32_t tcp_sum;		/* checksum to compensate for source */
391 					/* routed packets. Host byte order */
392 	uint16_t tcp_last_sent_len;	/* Record length for nagle */
393 	uint16_t tcp_dupack_cnt;	/* # of consequtive duplicate acks */
394 
395 	kmutex_t	*tcp_acceptor_lockp;	/* Ptr to tf_lock */
396 
397 	timeout_id_t	tcp_ordrelid;		/* qbufcall/qtimeout id */
398 	t_uscalar_t	tcp_acceptor_id;	/* ACCEPTOR_id */
399 
400 	int		tcp_ipsec_overhead;
401 	/*
402 	 * Address family that app wishes returned addrsses to be in.
403 	 * Currently taken from address family used in T_BIND_REQ, but
404 	 * should really come from family used in original socket() call.
405 	 * Value can be AF_INET or AF_INET6.
406 	 */
407 	uint_t	tcp_family;
408 	/*
409 	 * used for a quick test to determine if any ancillary bits are
410 	 * set
411 	 */
412 	uint_t		tcp_ipv6_recvancillary;		/* Flags */
413 #define	TCP_IPV6_RECVPKTINFO	0x01	/* IPV6_RECVPKTINFO option  */
414 #define	TCP_IPV6_RECVHOPLIMIT	0x02	/* IPV6_RECVHOPLIMIT option */
415 #define	TCP_IPV6_RECVHOPOPTS	0x04	/* IPV6_RECVHOPOPTS option */
416 #define	TCP_IPV6_RECVDSTOPTS	0x08	/* IPV6_RECVDSTOPTS option */
417 #define	TCP_IPV6_RECVRTHDR	0x10	/* IPV6_RECVRTHDR option */
418 #define	TCP_IPV6_RECVRTDSTOPTS	0x20	/* IPV6_RECVRTHDRDSTOPTS option */
419 #define	TCP_IPV6_RECVTCLASS	0x40	/* IPV6_RECVTCLASS option */
420 #define	TCP_OLD_IPV6_RECVDSTOPTS 0x80	/* old IPV6_RECVDSTOPTS option */
421 
422 	uint_t		tcp_recvifindex; /* Last received IPV6_RCVPKTINFO */
423 	uint_t		tcp_recvhops;	/* Last received IPV6_RECVHOPLIMIT */
424 	uint_t		tcp_recvtclass;	/* Last received IPV6_RECVTCLASS */
425 	ip6_hbh_t	*tcp_hopopts;	/* Last received IPV6_RECVHOPOPTS */
426 	ip6_dest_t	*tcp_dstopts;	/* Last received IPV6_RECVDSTOPTS */
427 	ip6_dest_t	*tcp_rtdstopts;	/* Last recvd IPV6_RECVRTHDRDSTOPTS */
428 	ip6_rthdr_t	*tcp_rthdr;	/* Last received IPV6_RECVRTHDR */
429 	uint_t		tcp_hopoptslen;
430 	uint_t		tcp_dstoptslen;
431 	uint_t		tcp_rtdstoptslen;
432 	uint_t		tcp_rthdrlen;
433 
434 	mblk_t		*tcp_timercache;
435 	cred_t		*tcp_cred;	/* Credentials when this was opened */
436 	pid_t		tcp_cpid;	/* Process id when this was opened */
437 
438 
439 	union {
440 		struct {
441 			uchar_t	v4_ttl;
442 				/* Dup of tcp_ipha.iph_type_of_service */
443 			uchar_t	v4_tos; /* Dup of tcp_ipha.iph_ttl */
444 		} v4_hdr_info;
445 		struct {
446 			uint_t	v6_vcf;		/* Dup of tcp_ip6h.ip6h_vcf */
447 			uchar_t	v6_hops;	/* Dup of tcp_ip6h.ip6h_hops */
448 		} v6_hdr_info;
449 	} tcp_hdr_info;
450 #define	tcp_ttl	tcp_hdr_info.v4_hdr_info.v4_ttl
451 #define	tcp_tos	tcp_hdr_info.v4_hdr_info.v4_tos
452 #define	tcp_ip6_vcf	tcp_hdr_info.v6_hdr_info.v6_vcf
453 #define	tcp_ip6_hops	tcp_hdr_info.v6_hdr_info.v6_hops
454 
455 	ushort_t	tcp_ipversion;
456 	uint_t		tcp_bound_if;	/* IPV6_BOUND_IF */
457 
458 #define	tcp_lport	tcp_connp->conn_lport
459 #define	tcp_fport	tcp_connp->conn_fport
460 #define	tcp_ports	tcp_connp->conn_ports
461 
462 #define	tcp_remote	tcp_connp->conn_rem
463 #define	tcp_ip_src	tcp_connp->conn_src
464 
465 #define	tcp_remote_v6	tcp_connp->conn_remv6
466 #define	tcp_ip_src_v6	tcp_connp->conn_srcv6
467 #define	tcp_bound_source_v6	tcp_connp->conn_bound_source_v6
468 #define	tcp_bound_source	tcp_connp->conn_bound_source
469 
470 	kmutex_t	tcp_closelock;
471 	kcondvar_t	tcp_closecv;
472 	uint8_t		tcp_closed;
473 	uint8_t		tcp_closeflags;
474 	uint8_t		tcp_cleandeathtag;
475 	mblk_t		tcp_closemp;
476 	timeout_id_t	tcp_linger_tid;	/* Linger timer ID */
477 	void		*tcp_tracebuf;
478 
479 	struct tcp_s *tcp_acceptor_hash; /* Acceptor hash chain */
480 	struct tcp_s **tcp_ptpahn; /* Pointer to previous accept hash next. */
481 	struct tcp_s *tcp_bind_hash; /* Bind hash chain */
482 	struct tcp_s **tcp_ptpbhn;
483 
484 	boolean_t	tcp_ire_ill_check_done;
485 	uint_t		tcp_maxpsz;
486 
487 	/*
488 	 * used for Multidata Transmit
489 	 */
490 	uint_t	tcp_mdt_hdr_head; /* leading header fragment extra space */
491 	uint_t	tcp_mdt_hdr_tail; /* trailing header fragment extra space */
492 	int	tcp_mdt_max_pld;  /* maximum payload buffers per Multidata */
493 
494 	uint32_t	tcp_ofo_fin_seq; /* Recv out of order FIN seq num */
495 	uint32_t	tcp_cwr_snd_max;
496 	uint_t		tcp_drop_opt_ack_cnt; /* # tcp generated optmgmt */
497 	ip6_pkt_t	tcp_sticky_ipp;			/* Sticky options */
498 #define	tcp_ipp_fields	tcp_sticky_ipp.ipp_fields	/* valid fields */
499 #define	tcp_ipp_ifindex	tcp_sticky_ipp.ipp_ifindex	/* pktinfo ifindex */
500 #define	tcp_ipp_addr	tcp_sticky_ipp.ipp_addr	/* pktinfo src/dst addr */
501 #define	tcp_ipp_hoplimit	tcp_sticky_ipp.ipp_hoplimit
502 #define	tcp_ipp_hopoptslen	tcp_sticky_ipp.ipp_hopoptslen
503 #define	tcp_ipp_rtdstoptslen	tcp_sticky_ipp.ipp_rtdstoptslen
504 #define	tcp_ipp_rthdrlen	tcp_sticky_ipp.ipp_rthdrlen
505 #define	tcp_ipp_dstoptslen	tcp_sticky_ipp.ipp_dstoptslen
506 #define	tcp_ipp_hopopts		tcp_sticky_ipp.ipp_hopopts
507 #define	tcp_ipp_rtdstopts	tcp_sticky_ipp.ipp_rtdstopts
508 #define	tcp_ipp_rthdr		tcp_sticky_ipp.ipp_rthdr
509 #define	tcp_ipp_dstopts		tcp_sticky_ipp.ipp_dstopts
510 #define	tcp_ipp_nexthop		tcp_sticky_ipp.ipp_nexthop
511 #define	tcp_ipp_use_min_mtu	tcp_sticky_ipp.ipp_use_min_mtu
512 	struct tcp_s *tcp_saved_listener;	/* saved value of listener */
513 
514 	uint32_t	tcp_in_ack_unsent;	/* ACK for unsent data cnt. */
515 
516 	/*
517 	 * The following fusion-related fields are protected by squeue.
518 	 */
519 	struct tcp_s *tcp_loopback_peer;	/* peer tcp for loopback */
520 	mblk_t	*tcp_fused_sigurg_mp;		/* M_PCSIG mblk for SIGURG */
521 	size_t	tcp_fuse_rcv_hiwater;		/* fusion receive queue size */
522 	uint_t	tcp_fuse_rcv_unread_hiwater;	/* max # of outstanding pkts */
523 	/*
524 	 * The following fusion-related fields and bit fields are to be
525 	 * manipulated with squeue protection or with tcp_fuse_lock held.
526 	 */
527 	kmutex_t tcp_fuse_lock;
528 	kcondvar_t tcp_fuse_plugcv;
529 	uint_t tcp_fuse_rcv_unread_cnt;	/* # of outstanding pkts */
530 	uint32_t
531 		tcp_fused : 1,		/* loopback tcp in fusion mode */
532 		tcp_unfusable : 1,	/* fusion not allowed on endpoint */
533 		tcp_fused_sigurg : 1,	/* send SIGURG upon draining */
534 		tcp_direct_sockfs : 1,	/* direct calls to sockfs */
535 
536 		tcp_fuse_syncstr_stopped : 1, /* synchronous streams stopped */
537 		tcp_fuse_syncstr_plugged : 1, /* synchronous streams plugged */
538 		tcp_fuse_to_bit_31 : 26;
539 
540 	/*
541 	 * This variable is accessed without any lock protection
542 	 * and therefore must not be declared as a bit field along
543 	 * with the rest which require such condition.
544 	 */
545 	boolean_t	tcp_issocket;	/* this is a socket tcp */
546 
547 	uint32_t	tcp_squeue_bytes;
548 	/*
549 	 * Kernel SSL session information
550 	 */
551 	boolean_t		tcp_kssl_pending; /* waiting for 1st SSL rec. */
552 	boolean_t		tcp_kssl_inhandshake; /* during SSL handshake */
553 	kssl_ent_t		tcp_kssl_ent;	/* SSL table entry */
554 	kssl_ctx_t		tcp_kssl_ctx;	/* SSL session */
555 	uint_t	tcp_label_len;	/* length of cached label */
556 } tcp_t;
557 
558 extern void 	tcp_free(tcp_t *tcp);
559 extern void	tcp_ddi_init(void);
560 extern void	tcp_ddi_destroy(void);
561 extern void	tcp_xmit_listeners_reset(mblk_t *mp, uint_t ip_hdr_len,
562 		    zoneid_t zoneid);
563 extern void	tcp_conn_request(void *arg, mblk_t *mp, void *arg2);
564 extern void	tcp_conn_request_unbound(void *arg, mblk_t *mp, void *arg2);
565 extern void 	tcp_input(void *arg, mblk_t *mp, void *arg2);
566 extern void	tcp_rput_data(void *arg, mblk_t *mp, void *arg2);
567 extern void 	*tcp_get_conn(void *arg);
568 extern void	tcp_time_wait_collector(void *arg);
569 extern int	tcp_snmp_get(queue_t *, mblk_t *);
570 extern int	tcp_snmp_set(queue_t *, int, int, uchar_t *, int len);
571 extern mblk_t	*tcp_xmit_mp(tcp_t *tcp, mblk_t *mp, int32_t max_to_send,
572 		    int32_t *offset, mblk_t **end_mp, uint32_t seq,
573 		    boolean_t sendall, uint32_t *seg_len, boolean_t rexmit);
574 /*
575  * The TCP Fanout structure.
576  * The hash tables and their linkage (tcp_*_hash_next, tcp_ptp*hn) are
577  * protected by the per-bucket tf_lock. Each tcp_t
578  * inserted in the list points back at this lock using tcp_*_lockp.
579  *
580  * The listener and acceptor hash queues are lists of tcp_t.
581  */
582 
583 /* listener hash and acceptor hash queue head */
584 typedef struct tf_s {
585 	tcp_t		*tf_tcp;
586 	kmutex_t	tf_lock;
587 } tf_t;
588 
589 extern mib2_tcp_t tcp_mib;
590 
591 #endif	/* (defined(_KERNEL) || defined(_KMEMUSER)) */
592 
593 /* Contract private interface between TCP and Clustering. */
594 
595 #define	CL_TCPI_V1	1	/* cl_tcpi_version number */
596 
597 typedef struct cl_tcp_info_s {
598 	ushort_t	cl_tcpi_version;	/* cl_tcp_info_t's version no */
599 	ushort_t	cl_tcpi_ipversion;	/* IP version */
600 	int32_t		cl_tcpi_state;		/* TCP state */
601 	in_port_t	cl_tcpi_lport;		/* Local port */
602 	in_port_t	cl_tcpi_fport;		/* Remote port */
603 	in6_addr_t	cl_tcpi_laddr_v6;	/* Local IP address */
604 	in6_addr_t	cl_tcpi_faddr_v6;	/* Remote IP address */
605 #ifdef _KERNEL
606 /* Note: V4_PART_OF_V6 is meant to be used only for _KERNEL defined stuff */
607 #define	cl_tcpi_laddr	V4_PART_OF_V6(cl_tcpi_laddr_v6)
608 #define	cl_tcpi_faddr	V4_PART_OF_V6(cl_tcpi_faddr_v6)
609 
610 #endif	/* _KERNEL */
611 } cl_tcp_info_t;
612 
613 /*
614  * Hook functions to enable cluster networking
615  * On non-clustered systems these vectors must always be NULL.
616  */
617 
618 extern void	(*cl_inet_listen)(uint8_t, sa_family_t, uint8_t *, in_port_t);
619 extern void	(*cl_inet_unlisten)(uint8_t, sa_family_t, uint8_t *,
620 		    in_port_t);
621 
622 /*
623  * Contracted Consolidation Private ioctl for aborting TCP connections.
624  * In order to keep the offsets and size of the structure the same between
625  * a 32-bit application and a 64-bit amd64 kernel, we use a #pragma
626  * pack(4).
627  */
628 #define	TCP_IOC_ABORT_CONN	(('T' << 8) + 91)
629 
630 #if _LONG_LONG_ALIGNMENT == 8 && _LONG_LONG_ALIGNMENT_32 == 4
631 #pragma pack(4)
632 #endif
633 
634 typedef struct tcp_ioc_abort_conn_s {
635 	struct sockaddr_storage ac_local;	/* local addr and port */
636 	struct sockaddr_storage ac_remote;	/* remote addr and port */
637 	int32_t ac_start;			/* start state */
638 	int32_t ac_end;				/* end state  */
639 	int32_t ac_zoneid;			/* zoneid */
640 } tcp_ioc_abort_conn_t;
641 
642 #if _LONG_LONG_ALIGNMENT == 8 && _LONG_LONG_ALIGNMENT_32 == 4
643 #pragma pack()
644 #endif
645 
646 #if (defined(_KERNEL) || defined(_KMEMUSER))
647 extern void tcp_rput_other(tcp_t *tcp, mblk_t *mp);
648 #endif
649 
650 #ifdef	__cplusplus
651 }
652 #endif
653 
654 #endif	/* _INET_TCP_H */
655