xref: /titanic_52/usr/src/uts/common/inet/tcp_impl.h (revision 06e1a7147edd272b7296f208141627a5b1191731)
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 
26 #ifndef	_INET_TCP_IMPL_H
27 #define	_INET_TCP_IMPL_H
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 /*
32  * TCP implementation private declarations.  These interfaces are
33  * used to build the IP module and are not meant to be accessed
34  * by any modules except IP itself.  They are undocumented and are
35  * subject to change without notice.
36  */
37 
38 #ifdef	__cplusplus
39 extern "C" {
40 #endif
41 
42 #ifdef _KERNEL
43 
44 #include <inet/tcp.h>
45 
46 #define	TCP_MOD_ID	5105
47 
48 /*
49  * Was this tcp created via socket() interface?
50  */
51 #define	TCP_IS_SOCKET(tcp)	((tcp)->tcp_issocket)
52 
53 /*
54  * Is this tcp not attached to any upper client?
55  */
56 #define	TCP_IS_DETACHED(tcp)	((tcp)->tcp_detached)
57 
58 #define	TCP_TIMER(tcp, f, tim)		\
59 	tcp_timeout(tcp->tcp_connp, f, tim)
60 #define	TCP_TIMER_CANCEL(tcp, id)	\
61 	tcp_timeout_cancel(tcp->tcp_connp, id)
62 
63 /*
64  * To restart the TCP retransmission timer.
65  */
66 #define	TCP_TIMER_RESTART(tcp, intvl) {					\
67 	if ((tcp)->tcp_timer_tid != 0)					\
68 		(void) TCP_TIMER_CANCEL((tcp), (tcp)->tcp_timer_tid);	\
69 	(tcp)->tcp_timer_tid = TCP_TIMER((tcp), tcp_timer,		\
70 	    MSEC_TO_TICK(intvl));					\
71 }
72 
73 /*
74  * This stops synchronous streams for a fused tcp endpoint
75  * and prevents tcp_fuse_rrw() from pulling data from it.
76  */
77 #define	TCP_FUSE_SYNCSTR_STOP(tcp) {				\
78 	if ((tcp)->tcp_direct_sockfs) {				\
79 		mutex_enter(&(tcp)->tcp_fuse_lock);		\
80 		(tcp)->tcp_fuse_syncstr_stopped = B_TRUE;	\
81 		mutex_exit(&(tcp)->tcp_fuse_lock);		\
82 	}							\
83 }
84 
85 /*
86  * This causes all calls to tcp_fuse_rrw() to block until
87  * TCP_FUSE_SYNCSTR_UNPLUG_DRAIN() is called.
88  */
89 #define	TCP_FUSE_SYNCSTR_PLUG_DRAIN(tcp) {			\
90 	if ((tcp)->tcp_direct_sockfs) {				\
91 		mutex_enter(&(tcp)->tcp_fuse_lock);		\
92 		ASSERT(!(tcp)->tcp_fuse_syncstr_plugged);	\
93 		(tcp)->tcp_fuse_syncstr_plugged = B_TRUE;	\
94 		mutex_exit(&(tcp)->tcp_fuse_lock);		\
95 	}							\
96 }
97 
98 /*
99  * This unplugs the draining of data through tcp_fuse_rrw(); see
100  * the comments in tcp_fuse_rrw() for how we preserve ordering.
101  */
102 #define	TCP_FUSE_SYNCSTR_UNPLUG_DRAIN(tcp) {			\
103 	if ((tcp)->tcp_direct_sockfs) {				\
104 		mutex_enter(&(tcp)->tcp_fuse_lock);		\
105 		(tcp)->tcp_fuse_syncstr_plugged = B_FALSE;	\
106 		(void) cv_broadcast(&(tcp)->tcp_fuse_plugcv);	\
107 		mutex_exit(&(tcp)->tcp_fuse_lock);		\
108 	}							\
109 }
110 
111 /*
112  * Write-side flow-control is implemented via the per instance STREAMS
113  * write-side Q by explicitly setting QFULL to stop the flow of mblk_t(s)
114  * and clearing QFULL and calling qbackenable() to restart the flow based
115  * on the number of TCP unsent bytes (i.e. those not on the wire waiting
116  * for a remote ACK).
117  *
118  * This is different than a standard STREAMS kmod which when using the
119  * STREAMS Q the framework would automatictly flow-control based on the
120  * defined hiwat/lowat values as mblk_t's are enqueued/dequeued.
121  *
122  * As of FireEngine TCP write-side flow-control needs to take into account
123  * both the unsent tcp_xmit list bytes but also any squeue_t enqueued bytes
124  * (i.e. from tcp_wput() -> tcp_output()).
125  *
126  * This is accomplished by adding a new tcp_t fields, tcp_squeue_bytes, to
127  * count the number of bytes enqueued by tcp_wput() and the number of bytes
128  * dequeued and processed by tcp_output().
129  *
130  * So, the total number of bytes unsent is (squeue_bytes + unsent) with all
131  * flow-control uses of unsent replaced with the macro TCP_UNSENT_BYTES.
132  */
133 extern void	tcp_clrqfull(tcp_t *);
134 extern void	tcp_setqfull(tcp_t *);
135 
136 #define	TCP_UNSENT_BYTES(tcp) \
137 	((tcp)->tcp_squeue_bytes + (tcp)->tcp_unsent)
138 
139 /* Named Dispatch Parameter Management Structure */
140 typedef struct tcpparam_s {
141 	uint32_t	tcp_param_min;
142 	uint32_t	tcp_param_max;
143 	uint32_t	tcp_param_val;
144 	char		*tcp_param_name;
145 } tcpparam_t;
146 
147 extern tcpparam_t tcp_param_arr[];
148 
149 #define	tcp_time_wait_interval			tcp_param_arr[0].tcp_param_val
150 #define	tcp_conn_req_max_q			tcp_param_arr[1].tcp_param_val
151 #define	tcp_conn_req_max_q0			tcp_param_arr[2].tcp_param_val
152 #define	tcp_conn_req_min			tcp_param_arr[3].tcp_param_val
153 #define	tcp_conn_grace_period			tcp_param_arr[4].tcp_param_val
154 #define	tcp_cwnd_max_				tcp_param_arr[5].tcp_param_val
155 #define	tcp_dbg					tcp_param_arr[6].tcp_param_val
156 #define	tcp_smallest_nonpriv_port		tcp_param_arr[7].tcp_param_val
157 #define	tcp_ip_abort_cinterval			tcp_param_arr[8].tcp_param_val
158 #define	tcp_ip_abort_linterval			tcp_param_arr[9].tcp_param_val
159 #define	tcp_ip_abort_interval			tcp_param_arr[10].tcp_param_val
160 #define	tcp_ip_notify_cinterval			tcp_param_arr[11].tcp_param_val
161 #define	tcp_ip_notify_interval			tcp_param_arr[12].tcp_param_val
162 #define	tcp_ipv4_ttl				tcp_param_arr[13].tcp_param_val
163 #define	tcp_keepalive_interval_high		tcp_param_arr[14].tcp_param_max
164 #define	tcp_keepalive_interval			tcp_param_arr[14].tcp_param_val
165 #define	tcp_keepalive_interval_low		tcp_param_arr[14].tcp_param_min
166 #define	tcp_maxpsz_multiplier			tcp_param_arr[15].tcp_param_val
167 #define	tcp_mss_def_ipv4			tcp_param_arr[16].tcp_param_val
168 #define	tcp_mss_max_ipv4			tcp_param_arr[17].tcp_param_val
169 #define	tcp_mss_min				tcp_param_arr[18].tcp_param_val
170 #define	tcp_naglim_def				tcp_param_arr[19].tcp_param_val
171 #define	tcp_rexmit_interval_initial		tcp_param_arr[20].tcp_param_val
172 #define	tcp_rexmit_interval_max			tcp_param_arr[21].tcp_param_val
173 #define	tcp_rexmit_interval_min			tcp_param_arr[22].tcp_param_val
174 #define	tcp_deferred_ack_interval		tcp_param_arr[23].tcp_param_val
175 #define	tcp_snd_lowat_fraction			tcp_param_arr[24].tcp_param_val
176 #define	tcp_sth_rcv_hiwat			tcp_param_arr[25].tcp_param_val
177 #define	tcp_sth_rcv_lowat			tcp_param_arr[26].tcp_param_val
178 #define	tcp_dupack_fast_retransmit		tcp_param_arr[27].tcp_param_val
179 #define	tcp_ignore_path_mtu			tcp_param_arr[28].tcp_param_val
180 #define	tcp_smallest_anon_port			tcp_param_arr[29].tcp_param_val
181 #define	tcp_largest_anon_port			tcp_param_arr[30].tcp_param_val
182 #define	tcp_xmit_hiwat				tcp_param_arr[31].tcp_param_val
183 #define	tcp_xmit_lowat				tcp_param_arr[32].tcp_param_val
184 #define	tcp_recv_hiwat				tcp_param_arr[33].tcp_param_val
185 #define	tcp_recv_hiwat_minmss			tcp_param_arr[34].tcp_param_val
186 #define	tcp_fin_wait_2_flush_interval		tcp_param_arr[35].tcp_param_val
187 #define	tcp_co_min				tcp_param_arr[36].tcp_param_val
188 #define	tcp_max_buf				tcp_param_arr[37].tcp_param_val
189 #define	tcp_strong_iss				tcp_param_arr[38].tcp_param_val
190 #define	tcp_rtt_updates				tcp_param_arr[39].tcp_param_val
191 #define	tcp_wscale_always			tcp_param_arr[40].tcp_param_val
192 #define	tcp_tstamp_always			tcp_param_arr[41].tcp_param_val
193 #define	tcp_tstamp_if_wscale			tcp_param_arr[42].tcp_param_val
194 #define	tcp_rexmit_interval_extra		tcp_param_arr[43].tcp_param_val
195 #define	tcp_deferred_acks_max			tcp_param_arr[44].tcp_param_val
196 #define	tcp_slow_start_after_idle		tcp_param_arr[45].tcp_param_val
197 #define	tcp_slow_start_initial			tcp_param_arr[46].tcp_param_val
198 #define	tcp_co_timer_interval			tcp_param_arr[47].tcp_param_val
199 #define	tcp_sack_permitted			tcp_param_arr[48].tcp_param_val
200 #define	tcp_trace				tcp_param_arr[49].tcp_param_val
201 #define	tcp_compression_enabled			tcp_param_arr[50].tcp_param_val
202 #define	tcp_ipv6_hoplimit			tcp_param_arr[51].tcp_param_val
203 #define	tcp_mss_def_ipv6			tcp_param_arr[52].tcp_param_val
204 #define	tcp_mss_max_ipv6			tcp_param_arr[53].tcp_param_val
205 #define	tcp_rev_src_routes			tcp_param_arr[54].tcp_param_val
206 #define	tcp_local_dack_interval			tcp_param_arr[55].tcp_param_val
207 #define	tcp_ndd_get_info_interval		tcp_param_arr[56].tcp_param_val
208 #define	tcp_local_dacks_max			tcp_param_arr[57].tcp_param_val
209 #define	tcp_ecn_permitted			tcp_param_arr[58].tcp_param_val
210 #define	tcp_rst_sent_rate_enabled		tcp_param_arr[59].tcp_param_val
211 #define	tcp_rst_sent_rate			tcp_param_arr[60].tcp_param_val
212 #define	tcp_push_timer_interval			tcp_param_arr[61].tcp_param_val
213 #define	tcp_use_smss_as_mss_opt			tcp_param_arr[62].tcp_param_val
214 #define	tcp_keepalive_abort_interval_high	tcp_param_arr[63].tcp_param_max
215 #define	tcp_keepalive_abort_interval		tcp_param_arr[63].tcp_param_val
216 #define	tcp_keepalive_abort_interval_low	tcp_param_arr[63].tcp_param_min
217 
218 /* Kstats */
219 typedef struct tcp_stat {
220 	kstat_named_t	tcp_time_wait;
221 	kstat_named_t	tcp_time_wait_syn;
222 	kstat_named_t	tcp_time_wait_syn_success;
223 	kstat_named_t	tcp_time_wait_syn_fail;
224 	kstat_named_t	tcp_reinput_syn;
225 	kstat_named_t	tcp_ip_output;
226 	kstat_named_t	tcp_detach_non_time_wait;
227 	kstat_named_t	tcp_detach_time_wait;
228 	kstat_named_t	tcp_time_wait_reap;
229 	kstat_named_t	tcp_clean_death_nondetached;
230 	kstat_named_t	tcp_reinit_calls;
231 	kstat_named_t	tcp_eager_err1;
232 	kstat_named_t	tcp_eager_err2;
233 	kstat_named_t	tcp_eager_blowoff_calls;
234 	kstat_named_t	tcp_eager_blowoff_q;
235 	kstat_named_t	tcp_eager_blowoff_q0;
236 	kstat_named_t	tcp_not_hard_bound;
237 	kstat_named_t	tcp_no_listener;
238 	kstat_named_t	tcp_found_eager;
239 	kstat_named_t	tcp_wrong_queue;
240 	kstat_named_t	tcp_found_eager_binding1;
241 	kstat_named_t	tcp_found_eager_bound1;
242 	kstat_named_t	tcp_eager_has_listener1;
243 	kstat_named_t	tcp_open_alloc;
244 	kstat_named_t	tcp_open_detached_alloc;
245 	kstat_named_t	tcp_rput_time_wait;
246 	kstat_named_t	tcp_listendrop;
247 	kstat_named_t	tcp_listendropq0;
248 	kstat_named_t	tcp_wrong_rq;
249 	kstat_named_t	tcp_rsrv_calls;
250 	kstat_named_t	tcp_eagerfree2;
251 	kstat_named_t	tcp_eagerfree3;
252 	kstat_named_t	tcp_eagerfree4;
253 	kstat_named_t	tcp_eagerfree5;
254 	kstat_named_t	tcp_timewait_syn_fail;
255 	kstat_named_t	tcp_listen_badflags;
256 	kstat_named_t	tcp_timeout_calls;
257 	kstat_named_t	tcp_timeout_cached_alloc;
258 	kstat_named_t	tcp_timeout_cancel_reqs;
259 	kstat_named_t	tcp_timeout_canceled;
260 	kstat_named_t	tcp_timermp_alloced;
261 	kstat_named_t	tcp_timermp_freed;
262 	kstat_named_t	tcp_timermp_allocfail;
263 	kstat_named_t	tcp_timermp_allocdblfail;
264 	kstat_named_t	tcp_push_timer_cnt;
265 	kstat_named_t	tcp_ack_timer_cnt;
266 	kstat_named_t	tcp_ire_null1;
267 	kstat_named_t	tcp_ire_null;
268 	kstat_named_t	tcp_ip_send;
269 	kstat_named_t	tcp_ip_ire_send;
270 	kstat_named_t   tcp_wsrv_called;
271 	kstat_named_t   tcp_flwctl_on;
272 	kstat_named_t	tcp_timer_fire_early;
273 	kstat_named_t	tcp_timer_fire_miss;
274 	kstat_named_t	tcp_freelist_cleanup;
275 	kstat_named_t	tcp_rput_v6_error;
276 	kstat_named_t	tcp_out_sw_cksum;
277 	kstat_named_t	tcp_out_sw_cksum_bytes;
278 	kstat_named_t	tcp_zcopy_on;
279 	kstat_named_t	tcp_zcopy_off;
280 	kstat_named_t	tcp_zcopy_backoff;
281 	kstat_named_t	tcp_zcopy_disable;
282 	kstat_named_t	tcp_mdt_pkt_out;
283 	kstat_named_t	tcp_mdt_pkt_out_v4;
284 	kstat_named_t	tcp_mdt_pkt_out_v6;
285 	kstat_named_t	tcp_mdt_discarded;
286 	kstat_named_t	tcp_mdt_conn_halted1;
287 	kstat_named_t	tcp_mdt_conn_halted2;
288 	kstat_named_t	tcp_mdt_conn_halted3;
289 	kstat_named_t	tcp_mdt_conn_resumed1;
290 	kstat_named_t	tcp_mdt_conn_resumed2;
291 	kstat_named_t	tcp_mdt_legacy_small;
292 	kstat_named_t	tcp_mdt_legacy_all;
293 	kstat_named_t	tcp_mdt_legacy_ret;
294 	kstat_named_t	tcp_mdt_allocfail;
295 	kstat_named_t	tcp_mdt_addpdescfail;
296 	kstat_named_t	tcp_mdt_allocd;
297 	kstat_named_t	tcp_mdt_linked;
298 	kstat_named_t	tcp_fusion_flowctl;
299 	kstat_named_t	tcp_fusion_backenabled;
300 	kstat_named_t	tcp_fusion_urg;
301 	kstat_named_t	tcp_fusion_putnext;
302 	kstat_named_t	tcp_fusion_unfusable;
303 	kstat_named_t	tcp_fusion_aborted;
304 	kstat_named_t	tcp_fusion_unqualified;
305 	kstat_named_t	tcp_fusion_rrw_busy;
306 	kstat_named_t	tcp_fusion_rrw_msgcnt;
307 	kstat_named_t	tcp_fusion_rrw_plugged;
308 	kstat_named_t	tcp_in_ack_unsent_drop;
309 	kstat_named_t	tcp_sock_fallback;
310 } tcp_stat_t;
311 
312 extern tcp_stat_t tcp_statistics;
313 
314 #define	TCP_STAT(x)		(tcp_statistics.x.value.ui64++)
315 #define	TCP_STAT_UPDATE(x, n)	(tcp_statistics.x.value.ui64 += (n))
316 #define	TCP_STAT_SET(x, n)	(tcp_statistics.x.value.ui64 = (n))
317 
318 extern struct qinit tcp_loopback_rinit, tcp_rinit;
319 extern boolean_t do_tcp_fusion;
320 
321 extern int	tcp_maxpsz_set(tcp_t *, boolean_t);
322 extern void	tcp_timers_stop(tcp_t *);
323 extern void	tcp_rcv_enqueue(tcp_t *, mblk_t *, uint_t);
324 extern void	tcp_push_timer(void *);
325 extern timeout_id_t tcp_timeout(conn_t *, void (*)(void *), clock_t);
326 extern clock_t	tcp_timeout_cancel(conn_t *, timeout_id_t);
327 
328 extern void	tcp_fuse(tcp_t *, uchar_t *, tcph_t *);
329 extern void	tcp_unfuse(tcp_t *);
330 extern boolean_t tcp_fuse_output(tcp_t *, mblk_t *, uint32_t);
331 extern void	tcp_fuse_output_urg(tcp_t *, mblk_t *);
332 extern boolean_t tcp_fuse_rcv_drain(queue_t *, tcp_t *, mblk_t **);
333 extern void	tcp_fuse_syncstr_enable_pair(tcp_t *);
334 extern void	tcp_fuse_disable_pair(tcp_t *, boolean_t);
335 extern int	tcp_fuse_rrw(queue_t *, struiod_t *);
336 extern int	tcp_fuse_rinfop(queue_t *, infod_t *);
337 extern size_t	tcp_fuse_set_rcv_hiwat(tcp_t *, size_t);
338 extern int	tcp_fuse_maxpsz_set(tcp_t *);
339 
340 #endif	/* _KERNEL */
341 
342 #ifdef	__cplusplus
343 }
344 #endif
345 
346 #endif	/* _INET_TCP_IMPL_H */
347