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