xref: /titanic_52/usr/src/uts/common/inet/tcp_stack.h (revision 55f5292c612446ce6f93ddd248c0019b5974618b)
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 } tcp_stat_t;
107 
108 #define	TCP_STAT(tcps, x)	((tcps)->tcps_statistics.x.value.ui64++)
109 #define	TCP_STAT_UPDATE(tcps, x, n)	\
110 	((tcps)->tcps_statistics.x.value.ui64 += (n))
111 #define	TCP_STAT_SET(tcps, x, n)	\
112 	((tcps)->tcps_statistics.x.value.ui64 = (n))
113 
114 typedef struct tcp_g_stat {
115 	kstat_named_t	tcp_timermp_alloced;
116 	kstat_named_t	tcp_timermp_allocfail;
117 	kstat_named_t	tcp_timermp_allocdblfail;
118 	kstat_named_t	tcp_freelist_cleanup;
119 } tcp_g_stat_t;
120 
121 #ifdef _KERNEL
122 
123 /*
124  * TCP stack instances
125  */
126 struct tcp_stack {
127 	netstack_t	*tcps_netstack;	/* Common netstack */
128 
129 	mib2_tcp_t	tcps_mib;
130 
131 	/*
132 	 * Extra privileged ports. In host byte order.
133 	 * Protected by tcp_epriv_port_lock.
134 	 */
135 #define	TCP_NUM_EPRIV_PORTS	64
136 	int		tcps_g_num_epriv_ports;
137 	uint16_t	tcps_g_epriv_ports[TCP_NUM_EPRIV_PORTS];
138 	kmutex_t	tcps_epriv_port_lock;
139 
140 	/*
141 	 * The smallest anonymous port in the priviledged port range which TCP
142 	 * looks for free port.  Use in the option TCP_ANONPRIVBIND.
143 	 */
144 	in_port_t	tcps_min_anonpriv_port;
145 
146 	/* Only modified during _init and _fini thus no locking is needed. */
147 	caddr_t		tcps_g_nd;
148 	struct tcpparam_s *tcps_params;	/* ndd parameters */
149 	struct tcpparam_s *tcps_wroff_xtra_param;
150 
151 	/* Hint not protected by any lock */
152 	uint_t		tcps_next_port_to_try;
153 
154 	/* TCP bind hash list - all tcp_t with state >= BOUND. */
155 	struct tf_s	*tcps_bind_fanout;
156 
157 	/* TCP queue hash list - all tcp_t in case they will be an acceptor. */
158 	struct tf_s	*tcps_acceptor_fanout;
159 
160 	/*
161 	 * MIB-2 stuff for SNMP
162 	 * Note: tcpInErrs {tcp 15} is accumulated in ip.c
163 	 */
164 	kstat_t		*tcps_mibkp;	/* kstat exporting tcp_mib data */
165 	kstat_t		*tcps_kstat;
166 	tcp_stat_t	tcps_statistics;
167 
168 	uint32_t	tcps_iss_incr_extra;
169 				/* Incremented for each connection */
170 	kmutex_t	tcps_iss_key_lock;
171 	MD5_CTX		tcps_iss_key;
172 
173 	/* Packet dropper for TCP IPsec policy drops. */
174 	ipdropper_t	tcps_dropper;
175 
176 	/*
177 	 * These two variables control the rate for TCP to generate RSTs in
178 	 * response to segments not belonging to any connections.  We limit
179 	 * TCP to sent out tcp_rst_sent_rate (ndd param) number of RSTs in
180 	 * each 1 second interval.  This is to protect TCP against DoS attack.
181 	 */
182 	clock_t		tcps_last_rst_intrvl;
183 	uint32_t	tcps_rst_cnt;
184 	/* The number of RST not sent because of the rate limit. */
185 	uint32_t	tcps_rst_unsent;
186 	ldi_ident_t	tcps_ldi_ident;
187 
188 	/* Used to synchronize access when reclaiming memory */
189 	mblk_t		*tcps_ixa_cleanup_mp;
190 	kmutex_t	tcps_ixa_cleanup_lock;
191 	kcondvar_t	tcps_ixa_cleanup_cv;
192 };
193 typedef struct tcp_stack tcp_stack_t;
194 
195 #endif /* _KERNEL */
196 #ifdef	__cplusplus
197 }
198 #endif
199 
200 #endif	/* _INET_TCP_STACK_H */
201