xref: /illumos-gate/usr/src/uts/common/inet/tcp_stack.h (revision 56f33205c9ed776c3c909e07d52e94610a675740)
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_detach_non_time_wait;
46 	kstat_named_t	tcp_detach_time_wait;
47 	kstat_named_t	tcp_time_wait_reap;
48 	kstat_named_t	tcp_clean_death_nondetached;
49 	kstat_named_t	tcp_reinit_calls;
50 	kstat_named_t	tcp_eager_err1;
51 	kstat_named_t	tcp_eager_err2;
52 	kstat_named_t	tcp_eager_blowoff_calls;
53 	kstat_named_t	tcp_eager_blowoff_q;
54 	kstat_named_t	tcp_eager_blowoff_q0;
55 	kstat_named_t	tcp_not_hard_bound;
56 	kstat_named_t	tcp_no_listener;
57 	kstat_named_t	tcp_found_eager;
58 	kstat_named_t	tcp_wrong_queue;
59 	kstat_named_t	tcp_found_eager_binding1;
60 	kstat_named_t	tcp_found_eager_bound1;
61 	kstat_named_t	tcp_eager_has_listener1;
62 	kstat_named_t	tcp_open_alloc;
63 	kstat_named_t	tcp_open_detached_alloc;
64 	kstat_named_t	tcp_rput_time_wait;
65 	kstat_named_t	tcp_listendrop;
66 	kstat_named_t	tcp_listendropq0;
67 	kstat_named_t	tcp_wrong_rq;
68 	kstat_named_t	tcp_rsrv_calls;
69 	kstat_named_t	tcp_eagerfree2;
70 	kstat_named_t	tcp_eagerfree3;
71 	kstat_named_t	tcp_eagerfree4;
72 	kstat_named_t	tcp_eagerfree5;
73 	kstat_named_t	tcp_timewait_syn_fail;
74 	kstat_named_t	tcp_listen_badflags;
75 	kstat_named_t	tcp_timeout_calls;
76 	kstat_named_t	tcp_timeout_cached_alloc;
77 	kstat_named_t	tcp_timeout_cancel_reqs;
78 	kstat_named_t	tcp_timeout_canceled;
79 	kstat_named_t	tcp_timermp_freed;
80 	kstat_named_t	tcp_push_timer_cnt;
81 	kstat_named_t	tcp_ack_timer_cnt;
82 	kstat_named_t   tcp_wsrv_called;
83 	kstat_named_t   tcp_flwctl_on;
84 	kstat_named_t	tcp_timer_fire_early;
85 	kstat_named_t	tcp_timer_fire_miss;
86 	kstat_named_t	tcp_rput_v6_error;
87 	kstat_named_t	tcp_zcopy_on;
88 	kstat_named_t	tcp_zcopy_off;
89 	kstat_named_t	tcp_zcopy_backoff;
90 	kstat_named_t	tcp_fusion_flowctl;
91 	kstat_named_t	tcp_fusion_backenabled;
92 	kstat_named_t	tcp_fusion_urg;
93 	kstat_named_t	tcp_fusion_putnext;
94 	kstat_named_t	tcp_fusion_unfusable;
95 	kstat_named_t	tcp_fusion_aborted;
96 	kstat_named_t	tcp_fusion_unqualified;
97 	kstat_named_t	tcp_fusion_rrw_busy;
98 	kstat_named_t	tcp_fusion_rrw_msgcnt;
99 	kstat_named_t	tcp_fusion_rrw_plugged;
100 	kstat_named_t	tcp_in_ack_unsent_drop;
101 	kstat_named_t	tcp_sock_fallback;
102 	kstat_named_t	tcp_lso_enabled;
103 	kstat_named_t	tcp_lso_disabled;
104 	kstat_named_t	tcp_lso_times;
105 	kstat_named_t	tcp_lso_pkt_out;
106 	kstat_named_t	tcp_listen_cnt_drop;
107 	kstat_named_t	tcp_listen_mem_drop;
108 	kstat_named_t	tcp_zwin_ack_syn;
109 	kstat_named_t	tcp_rst_unsent;
110 } tcp_stat_t;
111 
112 #define	TCP_STAT(tcps, x)	((tcps)->tcps_statistics.x.value.ui64++)
113 #define	TCP_STAT_UPDATE(tcps, x, n)	\
114 	((tcps)->tcps_statistics.x.value.ui64 += (n))
115 #define	TCP_STAT_SET(tcps, x, n)	\
116 	((tcps)->tcps_statistics.x.value.ui64 = (n))
117 
118 typedef struct tcp_g_stat {
119 	kstat_named_t	tcp_timermp_alloced;
120 	kstat_named_t	tcp_timermp_allocfail;
121 	kstat_named_t	tcp_timermp_allocdblfail;
122 	kstat_named_t	tcp_freelist_cleanup;
123 } tcp_g_stat_t;
124 
125 #ifdef _KERNEL
126 
127 /*
128  * TCP stack instances
129  */
130 struct tcp_stack {
131 	netstack_t	*tcps_netstack;	/* Common netstack */
132 
133 	mib2_tcp_t	tcps_mib;
134 
135 	/*
136 	 * Extra privileged ports. In host byte order.
137 	 * Protected by tcp_epriv_port_lock.
138 	 */
139 #define	TCP_NUM_EPRIV_PORTS	64
140 	int		tcps_g_num_epriv_ports;
141 	uint16_t	tcps_g_epriv_ports[TCP_NUM_EPRIV_PORTS];
142 	kmutex_t	tcps_epriv_port_lock;
143 
144 	/*
145 	 * The smallest anonymous port in the priviledged port range which TCP
146 	 * looks for free port.  Use in the option TCP_ANONPRIVBIND.
147 	 */
148 	in_port_t	tcps_min_anonpriv_port;
149 
150 	/* Only modified during _init and _fini thus no locking is needed. */
151 	caddr_t		tcps_g_nd;
152 	struct tcpparam_s *tcps_params;	/* ndd parameters */
153 	struct tcpparam_s *tcps_wroff_xtra_param;
154 
155 	/* Hint not protected by any lock */
156 	uint_t		tcps_next_port_to_try;
157 
158 	/* TCP bind hash list - all tcp_t with state >= BOUND. */
159 	struct tf_s	*tcps_bind_fanout;
160 
161 	/* TCP queue hash list - all tcp_t in case they will be an acceptor. */
162 	struct tf_s	*tcps_acceptor_fanout;
163 
164 	/*
165 	 * MIB-2 stuff for SNMP
166 	 * Note: tcpInErrs {tcp 15} is accumulated in ip.c
167 	 */
168 	kstat_t		*tcps_mibkp;	/* kstat exporting tcp_mib data */
169 	kstat_t		*tcps_kstat;
170 	tcp_stat_t	tcps_statistics;
171 
172 	uint32_t	tcps_iss_incr_extra;
173 				/* Incremented for each connection */
174 	kmutex_t	tcps_iss_key_lock;
175 	MD5_CTX		tcps_iss_key;
176 
177 	/* Packet dropper for TCP IPsec policy drops. */
178 	ipdropper_t	tcps_dropper;
179 
180 	/*
181 	 * These two variables control the rate for TCP to generate RSTs in
182 	 * response to segments not belonging to any connections.  We limit
183 	 * TCP to sent out tcp_rst_sent_rate (ndd param) number of RSTs in
184 	 * each 1 second interval.  This is to protect TCP against DoS attack.
185 	 */
186 	int64_t		tcps_last_rst_intrvl;
187 	uint32_t	tcps_rst_cnt;
188 
189 	ldi_ident_t	tcps_ldi_ident;
190 
191 	/* Used to synchronize access when reclaiming memory */
192 	mblk_t		*tcps_ixa_cleanup_mp;
193 	kmutex_t	tcps_ixa_cleanup_lock;
194 	kcondvar_t	tcps_ixa_cleanup_cv;
195 
196 	/* Variables for handling kmem reclaim call back. */
197 	kmutex_t	tcps_reclaim_lock;
198 	boolean_t	tcps_reclaim;
199 	timeout_id_t	tcps_reclaim_tid;
200 	uint32_t	tcps_reclaim_period;
201 
202 	/* Listener connection limit configuration. */
203 	kmutex_t	tcps_listener_conf_lock;
204 	list_t		tcps_listener_conf;
205 };
206 typedef struct tcp_stack tcp_stack_t;
207 
208 #endif /* _KERNEL */
209 #ifdef	__cplusplus
210 }
211 #endif
212 
213 #endif	/* _INET_TCP_STACK_H */
214