xref: /illumos-gate/usr/src/uts/common/inet/tcp/tcp_opt_data.c (revision 29e83d4b25fd82feb8e0e0fbe89f7e2a8438533d)
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 2007 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #pragma ident	"%Z%%M%	%I%	%E% SMI"
27 
28 #include <sys/types.h>
29 #include <sys/stream.h>
30 #define	_SUN_TPI_VERSION 2
31 #include <sys/tihdr.h>
32 #include <sys/socket.h>
33 #include <sys/xti_xtiopt.h>
34 #include <sys/xti_inet.h>
35 
36 #include <inet/common.h>
37 #include <netinet/ip6.h>
38 #include <inet/ip.h>
39 
40 #include <netinet/in.h>
41 #include <netinet/tcp.h>
42 #include <inet/optcom.h>
43 
44 
45 extern int	tcp_opt_default(queue_t *q, int level, int name, uchar_t *ptr);
46 extern int	tcp_opt_get(queue_t *q, int level, int name, uchar_t *ptr);
47 extern int	tcp_opt_set(queue_t *q, uint_t optset_context, int level,
48     int name, uint_t inlen, uchar_t *invalp, uint_t *outlenp, uchar_t *outvalp,
49     void *thisdg_attrs, cred_t *cr, mblk_t *mblk);
50 
51 /*
52  * Table of all known options handled on a TCP protocol stack.
53  *
54  * Note: This table contains options processed by both TCP and IP levels
55  *       and is the superset of options that can be performed on a TCP over IP
56  *       stack.
57  */
58 opdes_t	tcp_opt_arr[] = {
59 
60 { SO_LINGER,	SOL_SOCKET, OA_RW, OA_RW, OP_NP, OP_PASSNEXT,
61 	sizeof (struct linger), 0 },
62 
63 { SO_DEBUG,	SOL_SOCKET, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, sizeof (int), 0 },
64 { SO_KEEPALIVE,	SOL_SOCKET, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, sizeof (int), 0 },
65 { SO_DONTROUTE,	SOL_SOCKET, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, sizeof (int), 0 },
66 { SO_USELOOPBACK, SOL_SOCKET, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, sizeof (int), 0
67 	},
68 { SO_BROADCAST,	SOL_SOCKET, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, sizeof (int), 0 },
69 { SO_REUSEADDR, SOL_SOCKET, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, sizeof (int), 0 },
70 { SO_OOBINLINE, SOL_SOCKET, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, sizeof (int), 0 },
71 { SO_TYPE,	SOL_SOCKET, OA_R, OA_R, OP_NP, OP_PASSNEXT, sizeof (int), 0 },
72 { SO_SNDBUF,	SOL_SOCKET, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, sizeof (int), 0 },
73 { SO_RCVBUF,	SOL_SOCKET, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, sizeof (int), 0 },
74 { SO_DGRAM_ERRIND, SOL_SOCKET, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, sizeof (int), 0
75 	},
76 { SO_SND_COPYAVOID, SOL_SOCKET, OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0 },
77 { SO_ANON_MLP, SOL_SOCKET, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, sizeof (int),
78 	0 },
79 { SO_MAC_EXEMPT, SOL_SOCKET, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, sizeof (int),
80 	0 },
81 { SO_ALLZONES, SOL_SOCKET, OA_R, OA_RW, OP_CONFIG, OP_PASSNEXT, sizeof (int),
82 	0 },
83 { SO_EXCLBIND, SOL_SOCKET, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, sizeof (int), 0 },
84 
85 { SO_DOMAIN,	SOL_SOCKET, OA_R, OA_R, OP_NP, OP_PASSNEXT, sizeof (int), 0 },
86 
87 { SO_PROTOTYPE,	SOL_SOCKET, OA_R, OA_R, OP_NP, OP_PASSNEXT, sizeof (int), 0 },
88 
89 { TCP_NODELAY,	IPPROTO_TCP, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, sizeof (int), 0
90 	},
91 { TCP_MAXSEG,	IPPROTO_TCP, OA_R, OA_R, OP_NP, OP_PASSNEXT, sizeof (uint_t),
92 	536 },
93 
94 { TCP_NOTIFY_THRESHOLD, IPPROTO_TCP, OA_RW, OA_RW, OP_NP,
95 	(OP_PASSNEXT|OP_DEF_FN), sizeof (int), -1 /* not initialized */ },
96 
97 { TCP_ABORT_THRESHOLD, IPPROTO_TCP, OA_RW, OA_RW, OP_NP,
98 	(OP_PASSNEXT|OP_DEF_FN), sizeof (int), -1 /* not initialized */ },
99 
100 { TCP_CONN_NOTIFY_THRESHOLD, IPPROTO_TCP, OA_RW, OA_RW, OP_NP,
101 	(OP_PASSNEXT|OP_DEF_FN), sizeof (int), -1 /* not initialized */ },
102 
103 { TCP_CONN_ABORT_THRESHOLD, IPPROTO_TCP, OA_RW, OA_RW, OP_NP,
104 	(OP_PASSNEXT|OP_DEF_FN), sizeof (int), -1 /* not initialized */ },
105 
106 { TCP_RECVDSTADDR, IPPROTO_TCP, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, sizeof (int),
107 	0 },
108 
109 { TCP_ANONPRIVBIND, IPPROTO_TCP, OA_R, OA_RW, OP_PRIVPORT, OP_PASSNEXT,
110 	sizeof (int), 0 },
111 
112 { TCP_EXCLBIND, IPPROTO_TCP, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, sizeof (int), 0
113 	},
114 
115 { TCP_INIT_CWND, IPPROTO_TCP, OA_RW, OA_RW, OP_CONFIG, OP_PASSNEXT,
116 	sizeof (int), 0 },
117 
118 { TCP_KEEPALIVE_THRESHOLD, IPPROTO_TCP, OA_RW, OA_RW, OP_NP, OP_PASSNEXT,
119 	sizeof (int), 0	},
120 
121 { TCP_KEEPALIVE_ABORT_THRESHOLD, IPPROTO_TCP, OA_RW, OA_RW, OP_NP, OP_PASSNEXT,
122 	sizeof (int), 0	},
123 
124 { TCP_CORK, IPPROTO_TCP, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, sizeof (int), 0 },
125 
126 { IP_OPTIONS,	IPPROTO_IP, OA_RW, OA_RW, OP_NP,
127 	(OP_PASSNEXT|OP_VARLEN|OP_NODEFAULT),
128 	40, -1 /* not initialized */ },
129 { T_IP_OPTIONS,	IPPROTO_IP, OA_RW, OA_RW, OP_NP,
130 	(OP_PASSNEXT|OP_VARLEN|OP_NODEFAULT),
131 	40, -1 /* not initialized */ },
132 
133 { IP_TOS,	IPPROTO_IP, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, sizeof (int), 0 },
134 { T_IP_TOS,	IPPROTO_IP, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, sizeof (int), 0 },
135 { IP_TTL,	IPPROTO_IP, OA_RW, OA_RW, OP_NP, (OP_PASSNEXT|OP_DEF_FN),
136 	sizeof (int), -1 /* not initialized */ },
137 
138 { IP_SEC_OPT, IPPROTO_IP, OA_RW, OA_RW, OP_NP, (OP_PASSNEXT|OP_NODEFAULT),
139 	sizeof (ipsec_req_t), -1 /* not initialized */ },
140 
141 { IP_BOUND_IF, IPPROTO_IP, OA_RW, OA_RW, OP_NP, OP_PASSNEXT,
142 	sizeof (int),	0 /* no ifindex */ },
143 
144 { IP_UNSPEC_SRC, IPPROTO_IP, OA_R, OA_RW, OP_RAW, OP_PASSNEXT,
145 	sizeof (int), 0 },
146 
147 { IPV6_UNICAST_HOPS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, (OP_PASSNEXT|OP_DEF_FN),
148 	sizeof (int), -1 /* not initialized */ },
149 
150 { IPV6_BOUND_IF, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_PASSNEXT,
151 	sizeof (int),	0 /* no ifindex */ },
152 
153 { IP_NEXTHOP, IPPROTO_IP, OA_R, OA_RW, OP_CONFIG, OP_PASSNEXT,
154 	sizeof (in_addr_t),	-1 /* not initialized  */ },
155 
156 { IPV6_BOUND_PIF, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_PASSNEXT,
157 	sizeof (int),	0 /* no ifindex */ },
158 
159 { IPV6_UNSPEC_SRC, IPPROTO_IPV6, OA_R, OA_RW, OP_RAW, OP_PASSNEXT,
160 	sizeof (int), 0 },
161 
162 { IPV6_PKTINFO, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP,
163 	(OP_PASSNEXT|OP_NODEFAULT|OP_VARLEN),
164 	sizeof (struct in6_pktinfo), -1 /* not initialized */ },
165 { IPV6_NEXTHOP, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP,
166 	(OP_PASSNEXT|OP_NODEFAULT),
167 	sizeof (sin6_t), -1 /* not initialized */ },
168 { IPV6_HOPOPTS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP,
169 	(OP_PASSNEXT|OP_VARLEN|OP_NODEFAULT), 255*8,
170 	-1 /* not initialized */ },
171 { IPV6_DSTOPTS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP,
172 	(OP_PASSNEXT|OP_VARLEN|OP_NODEFAULT), 255*8,
173 	-1 /* not initialized */ },
174 { IPV6_RTHDRDSTOPTS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP,
175 	(OP_PASSNEXT|OP_VARLEN|OP_NODEFAULT), 255*8,
176 	-1 /* not initialized */ },
177 { IPV6_RTHDR, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP,
178 	(OP_PASSNEXT|OP_VARLEN|OP_NODEFAULT), 255*8,
179 	-1 /* not initialized */ },
180 { IPV6_TCLASS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP,
181 	(OP_PASSNEXT|OP_NODEFAULT),
182 	sizeof (int), -1 /* not initialized */ },
183 { IPV6_PATHMTU, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP,
184 	(OP_PASSNEXT|OP_NODEFAULT),
185 	sizeof (struct ip6_mtuinfo), -1 /* not initialized */ },
186 { IPV6_USE_MIN_MTU, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_PASSNEXT,
187 	sizeof (int), 0 },
188 { IPV6_V6ONLY, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_PASSNEXT,
189 	sizeof (int), 0 },
190 
191 /* Enable receipt of ancillary data */
192 { IPV6_RECVPKTINFO, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_PASSNEXT,
193 	sizeof (int), 0 },
194 { IPV6_RECVHOPLIMIT, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_PASSNEXT,
195 	sizeof (int), 0 },
196 { IPV6_RECVHOPOPTS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_PASSNEXT,
197 	sizeof (int), 0 },
198 { _OLD_IPV6_RECVDSTOPTS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_PASSNEXT,
199 	sizeof (int), 0 },
200 { IPV6_RECVDSTOPTS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_PASSNEXT,
201 	sizeof (int), 0 },
202 { IPV6_RECVRTHDR, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_PASSNEXT,
203 	sizeof (int), 0 },
204 { IPV6_RECVRTHDRDSTOPTS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_PASSNEXT,
205 	sizeof (int), 0 },
206 { IPV6_RECVTCLASS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_PASSNEXT,
207 	sizeof (int), 0 },
208 
209 { IPV6_SEC_OPT, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, (OP_PASSNEXT|OP_NODEFAULT),
210 	sizeof (ipsec_req_t), -1 /* not initialized */ },
211 { IPV6_SRC_PREFERENCES, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_PASSNEXT,
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_opt_get,		/* TCP get function pointer */
248 	tcp_opt_set,		/* TCP set function pointer */
249 	B_TRUE,			/* TCP is tpi provider */
250 	TCP_OPT_ARR_CNT,	/* TCP option database count of entries */
251 	tcp_opt_arr,		/* TCP option database */
252 	TCP_VALID_LEVELS_CNT,	/* TCP valid level count of entries */
253 	tcp_valid_levels_arr	/* TCP valid level array */
254 };
255