xref: /titanic_41/usr/src/uts/common/inet/tcp_stack.h (revision 6f8d59d8fcaf391990ca04c7bdcf65ab23320fe0)
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 /*
23  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_INET_TCP_STACK_H
28 #define	_INET_TCP_STACK_H
29 
30 #include <sys/netstack.h>
31 #include <inet/ip.h>
32 #include <inet/ipdrop.h>
33 #include <sys/sunddi.h>
34 #include <sys/sunldi.h>
35 
36 #ifdef	__cplusplus
37 extern "C" {
38 #endif
39 
40 /* Kstats */
41 typedef struct tcp_stat {
42 	kstat_named_t	tcp_time_wait;
43 	kstat_named_t	tcp_time_wait_syn;
44 	kstat_named_t	tcp_time_wait_syn_success;
45 	kstat_named_t	tcp_time_wait_syn_fail;
46 	kstat_named_t	tcp_reinput_syn;
47 	kstat_named_t	tcp_ip_output;
48 	kstat_named_t	tcp_detach_non_time_wait;
49 	kstat_named_t	tcp_detach_time_wait;
50 	kstat_named_t	tcp_time_wait_reap;
51 	kstat_named_t	tcp_clean_death_nondetached;
52 	kstat_named_t	tcp_reinit_calls;
53 	kstat_named_t	tcp_eager_err1;
54 	kstat_named_t	tcp_eager_err2;
55 	kstat_named_t	tcp_eager_blowoff_calls;
56 	kstat_named_t	tcp_eager_blowoff_q;
57 	kstat_named_t	tcp_eager_blowoff_q0;
58 	kstat_named_t	tcp_not_hard_bound;
59 	kstat_named_t	tcp_no_listener;
60 	kstat_named_t	tcp_found_eager;
61 	kstat_named_t	tcp_wrong_queue;
62 	kstat_named_t	tcp_found_eager_binding1;
63 	kstat_named_t	tcp_found_eager_bound1;
64 	kstat_named_t	tcp_eager_has_listener1;
65 	kstat_named_t	tcp_open_alloc;
66 	kstat_named_t	tcp_open_detached_alloc;
67 	kstat_named_t	tcp_rput_time_wait;
68 	kstat_named_t	tcp_listendrop;
69 	kstat_named_t	tcp_listendropq0;
70 	kstat_named_t	tcp_wrong_rq;
71 	kstat_named_t	tcp_rsrv_calls;
72 	kstat_named_t	tcp_eagerfree2;
73 	kstat_named_t	tcp_eagerfree3;
74 	kstat_named_t	tcp_eagerfree4;
75 	kstat_named_t	tcp_eagerfree5;
76 	kstat_named_t	tcp_timewait_syn_fail;
77 	kstat_named_t	tcp_listen_badflags;
78 	kstat_named_t	tcp_timeout_calls;
79 	kstat_named_t	tcp_timeout_cached_alloc;
80 	kstat_named_t	tcp_timeout_cancel_reqs;
81 	kstat_named_t	tcp_timeout_canceled;
82 	kstat_named_t	tcp_timermp_freed;
83 	kstat_named_t	tcp_push_timer_cnt;
84 	kstat_named_t	tcp_ack_timer_cnt;
85 	kstat_named_t	tcp_ire_null1;
86 	kstat_named_t	tcp_ire_null;
87 	kstat_named_t	tcp_ip_send;
88 	kstat_named_t	tcp_ip_ire_send;
89 	kstat_named_t   tcp_wsrv_called;
90 	kstat_named_t   tcp_flwctl_on;
91 	kstat_named_t	tcp_timer_fire_early;
92 	kstat_named_t	tcp_timer_fire_miss;
93 	kstat_named_t	tcp_rput_v6_error;
94 	kstat_named_t	tcp_out_sw_cksum;
95 	kstat_named_t	tcp_out_sw_cksum_bytes;
96 	kstat_named_t	tcp_zcopy_on;
97 	kstat_named_t	tcp_zcopy_off;
98 	kstat_named_t	tcp_zcopy_backoff;
99 	kstat_named_t	tcp_zcopy_disable;
100 	kstat_named_t	tcp_mdt_pkt_out;
101 	kstat_named_t	tcp_mdt_pkt_out_v4;
102 	kstat_named_t	tcp_mdt_pkt_out_v6;
103 	kstat_named_t	tcp_mdt_discarded;
104 	kstat_named_t	tcp_mdt_conn_halted1;
105 	kstat_named_t	tcp_mdt_conn_halted2;
106 	kstat_named_t	tcp_mdt_conn_halted3;
107 	kstat_named_t	tcp_mdt_conn_resumed1;
108 	kstat_named_t	tcp_mdt_conn_resumed2;
109 	kstat_named_t	tcp_mdt_legacy_small;
110 	kstat_named_t	tcp_mdt_legacy_all;
111 	kstat_named_t	tcp_mdt_legacy_ret;
112 	kstat_named_t	tcp_mdt_allocfail;
113 	kstat_named_t	tcp_mdt_addpdescfail;
114 	kstat_named_t	tcp_mdt_allocd;
115 	kstat_named_t	tcp_mdt_linked;
116 	kstat_named_t	tcp_fusion_flowctl;
117 	kstat_named_t	tcp_fusion_backenabled;
118 	kstat_named_t	tcp_fusion_urg;
119 	kstat_named_t	tcp_fusion_putnext;
120 	kstat_named_t	tcp_fusion_unfusable;
121 	kstat_named_t	tcp_fusion_aborted;
122 	kstat_named_t	tcp_fusion_unqualified;
123 	kstat_named_t	tcp_fusion_rrw_busy;
124 	kstat_named_t	tcp_fusion_rrw_msgcnt;
125 	kstat_named_t	tcp_fusion_rrw_plugged;
126 	kstat_named_t	tcp_in_ack_unsent_drop;
127 	kstat_named_t	tcp_sock_fallback;
128 	kstat_named_t	tcp_lso_enabled;
129 	kstat_named_t	tcp_lso_disabled;
130 	kstat_named_t	tcp_lso_times;
131 	kstat_named_t	tcp_lso_pkt_out;
132 } tcp_stat_t;
133 
134 #define	TCP_STAT(tcps, x)	((tcps)->tcps_statistics.x.value.ui64++)
135 #define	TCP_STAT_UPDATE(tcps, x, n)	\
136 	((tcps)->tcps_statistics.x.value.ui64 += (n))
137 #define	TCP_STAT_SET(tcps, x, n)	\
138 	((tcps)->tcps_statistics.x.value.ui64 = (n))
139 
140 typedef struct tcp_g_stat {
141 	kstat_named_t	tcp_timermp_alloced;
142 	kstat_named_t	tcp_timermp_allocfail;
143 	kstat_named_t	tcp_timermp_allocdblfail;
144 	kstat_named_t	tcp_freelist_cleanup;
145 } tcp_g_stat_t;
146 
147 #ifdef _KERNEL
148 
149 /*
150  * TCP stack instances
151  */
152 struct tcp_stack {
153 	netstack_t	*tcps_netstack;	/* Common netstack */
154 
155 	mib2_tcp_t	tcps_mib;
156 
157 	/* Protected by tcps_g_q_lock */
158 	queue_t		*tcps_g_q;	/* Default queue */
159 	uint_t		tcps_refcnt;	/* Total number of tcp_t's */
160 	kmutex_t	tcps_g_q_lock;
161 	kcondvar_t	tcps_g_q_cv;
162 	kthread_t	*tcps_g_q_creator;
163 	struct __ldi_handle *tcps_g_q_lh;
164 	cred_t		*tcps_g_q_cr;    /* For _inactive close call */
165 
166 	/*
167 	 * Extra privileged ports. In host byte order.
168 	 * Protected by tcp_epriv_port_lock.
169 	 */
170 #define	TCP_NUM_EPRIV_PORTS	64
171 	int		tcps_g_num_epriv_ports;
172 	uint16_t	tcps_g_epriv_ports[TCP_NUM_EPRIV_PORTS];
173 	kmutex_t	tcps_epriv_port_lock;
174 
175 	/*
176 	 * The smallest anonymous port in the priviledged port range which TCP
177 	 * looks for free port.  Use in the option TCP_ANONPRIVBIND.
178 	 */
179 	in_port_t	tcps_min_anonpriv_port;
180 
181 	/* Only modified during _init and _fini thus no locking is needed. */
182 	caddr_t		tcps_g_nd;
183 	struct tcpparam_s *tcps_params;	/* ndd parameters */
184 	struct tcpparam_s *tcps_wroff_xtra_param;
185 	struct tcpparam_s *tcps_mdt_head_param;
186 	struct tcpparam_s *tcps_mdt_tail_param;
187 	struct tcpparam_s *tcps_mdt_max_pbufs_param;
188 
189 	/* Hint not protected by any lock */
190 	uint_t		tcps_next_port_to_try;
191 
192 	/* TCP bind hash list - all tcp_t with state >= BOUND. */
193 	struct tf_s	*tcps_bind_fanout;
194 
195 	/* TCP queue hash list - all tcp_t in case they will be an acceptor. */
196 	struct tf_s	*tcps_acceptor_fanout;
197 
198 	/*
199 	 * MIB-2 stuff for SNMP
200 	 * Note: tcpInErrs {tcp 15} is accumulated in ip.c
201 	 */
202 	kstat_t		*tcps_mibkp;	/* kstat exporting tcp_mib data */
203 	kstat_t		*tcps_kstat;
204 	tcp_stat_t	tcps_statistics;
205 
206 	uint32_t	tcps_iss_incr_extra;
207 				/* Incremented for each connection */
208 	kmutex_t	tcps_iss_key_lock;
209 	MD5_CTX		tcps_iss_key;
210 
211 	/* Packet dropper for TCP IPsec policy drops. */
212 	ipdropper_t	tcps_dropper;
213 
214 	/*
215 	 * These two variables control the rate for TCP to generate RSTs in
216 	 * response to segments not belonging to any connections.  We limit
217 	 * TCP to sent out tcp_rst_sent_rate (ndd param) number of RSTs in
218 	 * each 1 second interval.  This is to protect TCP against DoS attack.
219 	 */
220 	clock_t		tcps_last_rst_intrvl;
221 	uint32_t	tcps_rst_cnt;
222 	/* The number of RST not sent because of the rate limit. */
223 	uint32_t	tcps_rst_unsent;
224 	ldi_ident_t	tcps_ldi_ident;
225 };
226 typedef struct tcp_stack tcp_stack_t;
227 
228 #endif /* _KERNEL */
229 #ifdef	__cplusplus
230 }
231 #endif
232 
233 #endif	/* _INET_TCP_STACK_H */
234