xref: /illumos-gate/usr/src/uts/common/inet/tcp/tcp_opt_data.c (revision 89b2a9fbeabf42fa54594df0e5927bcc50a07cc9)
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 2009 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #include <sys/types.h>
27 #include <sys/stream.h>
28 #define	_SUN_TPI_VERSION 2
29 #include <sys/tihdr.h>
30 #include <sys/socket.h>
31 #include <sys/xti_xtiopt.h>
32 #include <sys/xti_inet.h>
33 
34 #include <inet/common.h>
35 #include <netinet/ip6.h>
36 #include <inet/ip.h>
37 
38 #include <netinet/in.h>
39 #include <netinet/tcp.h>
40 #include <inet/optcom.h>
41 
42 #include <inet/tcp_impl.h>
43 
44 /*
45  * Table of all known options handled on a TCP protocol stack.
46  *
47  * Note: This table contains options processed by both TCP and IP levels
48  *       and is the superset of options that can be performed on a TCP over IP
49  *       stack.
50  */
51 opdes_t	tcp_opt_arr[] = {
52 
53 { SO_LINGER,	SOL_SOCKET, OA_RW, OA_RW, OP_NP, 0,
54 	sizeof (struct linger), 0 },
55 
56 { SO_DEBUG,	SOL_SOCKET, OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0 },
57 { SO_KEEPALIVE,	SOL_SOCKET, OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0 },
58 { SO_DONTROUTE,	SOL_SOCKET, OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0 },
59 { SO_USELOOPBACK, SOL_SOCKET, OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0
60 	},
61 { SO_BROADCAST,	SOL_SOCKET, OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0 },
62 { SO_REUSEADDR, SOL_SOCKET, OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0 },
63 { SO_OOBINLINE, SOL_SOCKET, OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0 },
64 { SO_TYPE,	SOL_SOCKET, OA_R, OA_R, OP_NP, 0, sizeof (int), 0 },
65 { SO_SNDBUF,	SOL_SOCKET, OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0 },
66 { SO_RCVBUF,	SOL_SOCKET, OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0 },
67 { SO_SNDTIMEO,	SOL_SOCKET, OA_RW, OA_RW, OP_NP, 0,
68 	sizeof (struct timeval), 0 },
69 { SO_RCVTIMEO,	SOL_SOCKET, OA_RW, OA_RW, OP_NP, 0,
70 	sizeof (struct timeval), 0 },
71 { SO_DGRAM_ERRIND, SOL_SOCKET, OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0
72 	},
73 { SO_SND_COPYAVOID, SOL_SOCKET, OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0 },
74 { SO_ANON_MLP, SOL_SOCKET, OA_RW, OA_RW, OP_NP, 0, sizeof (int),
75 	0 },
76 { SO_MAC_EXEMPT, SOL_SOCKET, OA_RW, OA_RW, OP_NP, 0, sizeof (int),
77 	0 },
78 { SO_MAC_IMPLICIT, SOL_SOCKET, OA_RW, OA_RW, OP_NP, 0, sizeof (int),
79 	0 },
80 { SO_ALLZONES, SOL_SOCKET, OA_R, OA_RW, OP_CONFIG, 0, sizeof (int),
81 	0 },
82 { SO_EXCLBIND, SOL_SOCKET, OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0 },
83 
84 { SO_DOMAIN,	SOL_SOCKET, OA_R, OA_R, OP_NP, 0, sizeof (int), 0 },
85 
86 { SO_PROTOTYPE,	SOL_SOCKET, OA_R, OA_R, OP_NP, 0, sizeof (int), 0 },
87 
88 { TCP_NODELAY,	IPPROTO_TCP, OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0
89 	},
90 { TCP_MAXSEG,	IPPROTO_TCP, OA_R, OA_R, OP_NP, 0, sizeof (uint_t),
91 	536 },
92 
93 { TCP_NOTIFY_THRESHOLD, IPPROTO_TCP, OA_RW, OA_RW, OP_NP,
94 	OP_DEF_FN, sizeof (int), -1 /* not initialized */ },
95 
96 { TCP_ABORT_THRESHOLD, IPPROTO_TCP, OA_RW, OA_RW, OP_NP,
97 	OP_DEF_FN, sizeof (int), -1 /* not initialized */ },
98 
99 { TCP_CONN_NOTIFY_THRESHOLD, IPPROTO_TCP, OA_RW, OA_RW, OP_NP,
100 	OP_DEF_FN, sizeof (int), -1 /* not initialized */ },
101 
102 { TCP_CONN_ABORT_THRESHOLD, IPPROTO_TCP, OA_RW, OA_RW, OP_NP,
103 	OP_DEF_FN, sizeof (int), -1 /* not initialized */ },
104 
105 { TCP_RECVDSTADDR, IPPROTO_TCP, OA_RW, OA_RW, OP_NP, 0, sizeof (int),
106 	0 },
107 
108 { TCP_ANONPRIVBIND, IPPROTO_TCP, OA_R, OA_RW, OP_PRIVPORT, 0,
109 	sizeof (int), 0 },
110 
111 { TCP_EXCLBIND, IPPROTO_TCP, OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0
112 	},
113 
114 { TCP_INIT_CWND, IPPROTO_TCP, OA_RW, OA_RW, OP_CONFIG, 0,
115 	sizeof (int), 0 },
116 
117 { TCP_KEEPALIVE_THRESHOLD, IPPROTO_TCP, OA_RW, OA_RW, OP_NP, 0,
118 	sizeof (int), 0	},
119 
120 { TCP_KEEPALIVE_ABORT_THRESHOLD, IPPROTO_TCP, OA_RW, OA_RW, OP_NP, 0,
121 	sizeof (int), 0	},
122 
123 { TCP_CORK, IPPROTO_TCP, OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0 },
124 
125 { IP_OPTIONS,	IPPROTO_IP, OA_RW, OA_RW, OP_NP,
126 	(OP_VARLEN|OP_NODEFAULT),
127 	IP_MAX_OPT_LENGTH + IP_ADDR_LEN, -1 /* not initialized */ },
128 { T_IP_OPTIONS,	IPPROTO_IP, OA_RW, OA_RW, OP_NP,
129 	(OP_VARLEN|OP_NODEFAULT),
130 	IP_MAX_OPT_LENGTH + IP_ADDR_LEN, -1 /* not initialized */ },
131 
132 { IP_TOS,	IPPROTO_IP, OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0 },
133 { T_IP_TOS,	IPPROTO_IP, OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0 },
134 { IP_TTL,	IPPROTO_IP, OA_RW, OA_RW, OP_NP, OP_DEF_FN,
135 	sizeof (int), -1 /* not initialized */ },
136 
137 { IP_SEC_OPT, IPPROTO_IP, OA_RW, OA_RW, OP_NP, OP_NODEFAULT,
138 	sizeof (ipsec_req_t), -1 /* not initialized */ },
139 
140 { IP_BOUND_IF, IPPROTO_IP, OA_RW, OA_RW, OP_NP, 0,
141 	sizeof (int),	0 /* no ifindex */ },
142 
143 { IP_UNSPEC_SRC, IPPROTO_IP, OA_R, OA_RW, OP_RAW, 0,
144 	sizeof (int), 0 },
145 
146 { IPV6_UNICAST_HOPS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_DEF_FN,
147 	sizeof (int), -1 /* not initialized */ },
148 
149 { IPV6_BOUND_IF, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, 0,
150 	sizeof (int),	0 /* no ifindex */ },
151 
152 { IP_DONTFRAG, IPPROTO_IP, OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0 },
153 
154 { IP_NEXTHOP, IPPROTO_IP, OA_R, OA_RW, OP_CONFIG, 0,
155 	sizeof (in_addr_t),	-1 /* not initialized  */ },
156 
157 { IPV6_UNSPEC_SRC, IPPROTO_IPV6, OA_R, OA_RW, OP_RAW, 0,
158 	sizeof (int), 0 },
159 
160 { IPV6_PKTINFO, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP,
161 	(OP_NODEFAULT|OP_VARLEN),
162 	sizeof (struct in6_pktinfo), -1 /* not initialized */ },
163 { IPV6_NEXTHOP, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP,
164 	OP_NODEFAULT,
165 	sizeof (sin6_t), -1 /* not initialized */ },
166 { IPV6_HOPOPTS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP,
167 	(OP_VARLEN|OP_NODEFAULT), 255*8,
168 	-1 /* not initialized */ },
169 { IPV6_DSTOPTS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP,
170 	(OP_VARLEN|OP_NODEFAULT), 255*8,
171 	-1 /* not initialized */ },
172 { IPV6_RTHDRDSTOPTS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP,
173 	(OP_VARLEN|OP_NODEFAULT), 255*8,
174 	-1 /* not initialized */ },
175 { IPV6_RTHDR, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP,
176 	(OP_VARLEN|OP_NODEFAULT), 255*8,
177 	-1 /* not initialized */ },
178 { IPV6_TCLASS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP,
179 	OP_NODEFAULT,
180 	sizeof (int), -1 /* not initialized */ },
181 { IPV6_PATHMTU, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP,
182 	OP_NODEFAULT,
183 	sizeof (struct ip6_mtuinfo), -1 /* not initialized */ },
184 { IPV6_DONTFRAG, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, 0,
185 	sizeof (int), 0 },
186 { IPV6_USE_MIN_MTU, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, 0,
187 	sizeof (int), 0 },
188 { IPV6_V6ONLY, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, 0,
189 	sizeof (int), 0 },
190 
191 /* Enable receipt of ancillary data */
192 { IPV6_RECVPKTINFO, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, 0,
193 	sizeof (int), 0 },
194 { IPV6_RECVHOPLIMIT, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, 0,
195 	sizeof (int), 0 },
196 { IPV6_RECVHOPOPTS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, 0,
197 	sizeof (int), 0 },
198 { _OLD_IPV6_RECVDSTOPTS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, 0,
199 	sizeof (int), 0 },
200 { IPV6_RECVDSTOPTS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, 0,
201 	sizeof (int), 0 },
202 { IPV6_RECVRTHDR, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, 0,
203 	sizeof (int), 0 },
204 { IPV6_RECVRTHDRDSTOPTS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, 0,
205 	sizeof (int), 0 },
206 { IPV6_RECVTCLASS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, 0,
207 	sizeof (int), 0 },
208 
209 { IPV6_SEC_OPT, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_NODEFAULT,
210 	sizeof (ipsec_req_t), -1 /* not initialized */ },
211 { IPV6_SRC_PREFERENCES, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, 0,
212 	sizeof (uint32_t), IPV6_PREFER_SRC_DEFAULT },
213 };
214 
215 /*
216  * Table of all supported levels
217  * Note: Some levels (e.g. XTI_GENERIC) may be valid but may not have
218  * any supported options so we need this info separately.
219  *
220  * This is needed only for topmost tpi providers and is used only by
221  * XTI interfaces.
222  */
223 optlevel_t	tcp_valid_levels_arr[] = {
224 	XTI_GENERIC,
225 	SOL_SOCKET,
226 	IPPROTO_TCP,
227 	IPPROTO_IP,
228 	IPPROTO_IPV6
229 };
230 
231 
232 #define	TCP_OPT_ARR_CNT		A_CNT(tcp_opt_arr)
233 #define	TCP_VALID_LEVELS_CNT	A_CNT(tcp_valid_levels_arr)
234 
235 uint_t tcp_max_optsize; /* initialized when TCP driver is loaded */
236 
237 /*
238  * Initialize option database object for TCP
239  *
240  * This object represents database of options to search passed to
241  * {sock,tpi}optcom_req() interface routine to take care of option
242  * management and associated methods.
243  */
244 
245 optdb_obj_t tcp_opt_obj = {
246 	tcp_opt_default,	/* TCP default value function pointer */
247 	tcp_tpi_opt_get,	/* TCP get function pointer */
248 	tcp_tpi_opt_set,	/* TCP set function pointer */
249 	TCP_OPT_ARR_CNT,	/* TCP option database count of entries */
250 	tcp_opt_arr,		/* TCP option database */
251 	TCP_VALID_LEVELS_CNT,	/* TCP valid level count of entries */
252 	tcp_valid_levels_arr	/* TCP valid level array */
253 };
254