xref: /illumos-gate/usr/src/uts/common/inet/udp/udp_opt_data.c (revision 65a89a64c60f3061bbe2381edaacc81660af9a95)
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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 #include <sys/types.h>
30 #include <sys/stream.h>
31 #define	_SUN_TPI_VERSION 2
32 #include <sys/tihdr.h>
33 #include <sys/socket.h>
34 #include <sys/xti_xtiopt.h>
35 #include <sys/xti_inet.h>
36 
37 #include <inet/common.h>
38 #include <netinet/ip6.h>
39 #include <inet/ip.h>
40 /*
41  * MK_XXX Following 2 includes temporary to import ip6_rthdr_t
42  *        definition. May not be needed if we fix ip6_dg_snd_attrs_t
43  *        to do all extension headers in identical manner.
44  */
45 #include <net/if.h>
46 #include <inet/ip6.h>
47 
48 #include <netinet/in.h>
49 #include <netinet/tcp.h>
50 #include <netinet/udp.h>
51 #include <netinet/ip_mroute.h>
52 #include <inet/optcom.h>
53 
54 extern int	udp_opt_default(queue_t *q, t_scalar_t level, t_scalar_t name,
55     uchar_t *ptr);
56 extern int	udp_opt_get(queue_t *q, t_scalar_t level, t_scalar_t name,
57     uchar_t *ptr);
58 extern int	udp_opt_set(queue_t *q, uint_t optset_context,
59     int level, int name, uint_t inlen, uchar_t *invalp, uint_t *outlenp,
60     uchar_t *outvalp, void *thisdg_attrs, cred_t *cr, mblk_t *mblk);
61 
62 /*
63  * Table of all known options handled on a UDP protocol stack.
64  *
65  * Note: This table contains options processed by both UDP and IP levels
66  *       and is the superset of options that can be performed on a UDP over IP
67  *       stack.
68  */
69 opdes_t	udp_opt_arr[] = {
70 
71 { SO_DEBUG,	SOL_SOCKET, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, sizeof (int), 0 },
72 { SO_DONTROUTE,	SOL_SOCKET, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, sizeof (int), 0 },
73 { SO_USELOOPBACK, SOL_SOCKET, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, sizeof (int), 0
74 	},
75 { SO_BROADCAST,	SOL_SOCKET, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, sizeof (int), 0 },
76 { SO_REUSEADDR, SOL_SOCKET, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, sizeof (int), 0 },
77 { SO_TYPE,	SOL_SOCKET, OA_R, OA_R, OP_NP, OP_PASSNEXT, sizeof (int), 0 },
78 { SO_SNDBUF,	SOL_SOCKET, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, sizeof (int), 0 },
79 { SO_RCVBUF,	SOL_SOCKET, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, sizeof (int), 0 },
80 { SO_DGRAM_ERRIND, SOL_SOCKET, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, sizeof (int),
81 	0 },
82 { SO_RECVUCRED, SOL_SOCKET, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, sizeof (int), 0
83 	},
84 { IP_OPTIONS,	IPPROTO_IP, OA_RW, OA_RW, OP_NP,
85 	(OP_PASSNEXT|OP_VARLEN|OP_NODEFAULT), 40, -1 /* not initialized */ },
86 { T_IP_OPTIONS,	IPPROTO_IP, OA_RW, OA_RW, OP_NP,
87 	(OP_PASSNEXT|OP_VARLEN|OP_NODEFAULT), 40, -1 /* not initialized */ },
88 
89 { IP_TOS,	IPPROTO_IP, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, sizeof (int), 0 },
90 { T_IP_TOS,	IPPROTO_IP, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, sizeof (int), 0 },
91 { IP_TTL,	IPPROTO_IP, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, sizeof (int), 0 },
92 { IP_RECVOPTS,	IPPROTO_IP, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, sizeof (int), 0 },
93 { IP_RECVDSTADDR, IPPROTO_IP, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, sizeof (int), 0
94 	},
95 { IP_RECVIF, IPPROTO_IP, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, sizeof (int), 0 },
96 { IP_RECVSLLA, IPPROTO_IP, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, sizeof (int), 0 },
97 { IP_RECVTTL,	IPPROTO_IP,  OA_RW, OA_RW, OP_NP, OP_PASSNEXT, sizeof (int),
98 	0 },
99 { IP_MULTICAST_IF, IPPROTO_IP, OA_RW, OA_RW, OP_NP, OP_PASSNEXT,
100 	sizeof (struct in_addr),	0 /* INADDR_ANY */ },
101 
102 { IP_MULTICAST_LOOP, IPPROTO_IP, OA_RW, OA_RW, OP_NP, (OP_PASSNEXT|OP_DEF_FN),
103 	sizeof (uchar_t), -1 /* not initialized */},
104 
105 { IP_MULTICAST_TTL, IPPROTO_IP, OA_RW, OA_RW, OP_NP, (OP_PASSNEXT|OP_DEF_FN),
106 	sizeof (uchar_t), -1 /* not initialized */ },
107 
108 { IP_ADD_MEMBERSHIP, IPPROTO_IP, OA_X, OA_X, OP_NP, (OP_PASSNEXT|OP_NODEFAULT),
109 	sizeof (struct ip_mreq), -1 /* not initialized */ },
110 
111 { IP_DROP_MEMBERSHIP, IPPROTO_IP, OA_X, OA_X, OP_NP, (OP_PASSNEXT|OP_NODEFAULT),
112 	sizeof (struct ip_mreq), -1 /* not initialized */ },
113 
114 { IP_BLOCK_SOURCE, IPPROTO_IP, OA_X, OA_X, OP_NP, (OP_PASSNEXT|OP_NODEFAULT),
115 	sizeof (struct ip_mreq_source), -1 /* not initialized */ },
116 
117 { IP_UNBLOCK_SOURCE, IPPROTO_IP, OA_X, OA_X, OP_NP, (OP_PASSNEXT|OP_NODEFAULT),
118 	sizeof (struct ip_mreq_source), -1 /* not initialized */ },
119 
120 { IP_ADD_SOURCE_MEMBERSHIP, IPPROTO_IP, OA_X, OA_X, OP_NP,
121 	(OP_PASSNEXT|OP_NODEFAULT), sizeof (struct ip_mreq_source), -1 },
122 
123 { IP_DROP_SOURCE_MEMBERSHIP, IPPROTO_IP, OA_X, OA_X, OP_NP,
124 	(OP_PASSNEXT|OP_NODEFAULT), sizeof (struct ip_mreq_source), -1 },
125 
126 { IP_SEC_OPT, IPPROTO_IP, OA_RW, OA_RW, OP_NP, (OP_PASSNEXT|OP_NODEFAULT),
127 	sizeof (ipsec_req_t), -1 /* not initialized */ },
128 
129 { IP_BOUND_IF, IPPROTO_IP, OA_RW, OA_RW, OP_NP, OP_PASSNEXT,
130 	sizeof (int),	0 /* no ifindex */ },
131 { IP_XMIT_IF, IPPROTO_IP, OA_RW, OA_RW, OP_NP, OP_PASSNEXT,
132 	sizeof (int), 0 /* no ifindex */ },
133 
134 { IP_DONTFAILOVER_IF, IPPROTO_IP, OA_RW, OA_RW, OP_NP, OP_PASSNEXT,
135 	sizeof (struct in_addr),	0 /* not initialized */ },
136 
137 { IP_UNSPEC_SRC, IPPROTO_IP, OA_R, OA_RW, OP_RAW, OP_PASSNEXT,
138 	sizeof (int), 0 },
139 
140 { IP_NEXTHOP, IPPROTO_IP, OA_RW, OA_RW, OP_CONFIG, OP_PASSNEXT,
141 	sizeof (in_addr_t),	-1 /* not initialized  */ },
142 
143 { MCAST_JOIN_GROUP, IPPROTO_IP, OA_X, OA_X, OP_NP,
144 	(OP_PASSNEXT|OP_NODEFAULT), sizeof (struct group_req),
145 	-1 /* not initialized */ },
146 { MCAST_LEAVE_GROUP, IPPROTO_IP, OA_X, OA_X, OP_NP,
147 	(OP_PASSNEXT|OP_NODEFAULT), sizeof (struct group_req),
148 	-1 /* not initialized */ },
149 { MCAST_BLOCK_SOURCE, IPPROTO_IP, OA_X, OA_X, OP_NP,
150 	(OP_PASSNEXT|OP_NODEFAULT), sizeof (struct group_source_req),
151 	-1 /* not initialized */ },
152 { MCAST_UNBLOCK_SOURCE, IPPROTO_IP, OA_X, OA_X, OP_NP,
153 	(OP_PASSNEXT|OP_NODEFAULT), sizeof (struct group_source_req),
154 	-1 /* not initialized */ },
155 { MCAST_JOIN_SOURCE_GROUP, IPPROTO_IP, OA_X, OA_X, OP_NP,
156 	(OP_PASSNEXT|OP_NODEFAULT), sizeof (struct group_source_req),
157 	-1 /* not initialized */ },
158 { MCAST_LEAVE_SOURCE_GROUP, IPPROTO_IP, OA_X, OA_X, OP_NP,
159 	(OP_PASSNEXT|OP_NODEFAULT), sizeof (struct group_source_req),
160 	-1 /* not initialized */ },
161 
162 { IPV6_MULTICAST_IF, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_PASSNEXT,
163 	sizeof (int), 0 },
164 
165 { IPV6_MULTICAST_HOPS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP,
166 	(OP_PASSNEXT|OP_DEF_FN), sizeof (int), -1 /* not initialized */ },
167 
168 { IPV6_MULTICAST_LOOP, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP,
169 	(OP_PASSNEXT|OP_DEF_FN), sizeof (int), -1 /* not initialized */},
170 
171 { IPV6_JOIN_GROUP, IPPROTO_IPV6, OA_X, OA_X, OP_NP, (OP_PASSNEXT|OP_NODEFAULT),
172 	sizeof (struct ipv6_mreq), -1 /* not initialized */ },
173 
174 { IPV6_LEAVE_GROUP,	IPPROTO_IPV6, OA_X, OA_X, OP_NP,
175 	(OP_PASSNEXT|OP_NODEFAULT),
176 	sizeof (struct ipv6_mreq), -1 /* not initialized */ },
177 
178 { IPV6_UNICAST_HOPS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, (OP_PASSNEXT|OP_DEF_FN),
179 	sizeof (int), -1 /* not initialized */ },
180 
181 { IPV6_BOUND_IF, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_PASSNEXT,
182 	sizeof (int),	0 /* no ifindex */ },
183 
184 { IPV6_BOUND_PIF, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_PASSNEXT,
185 	sizeof (int),	0 /* no ifindex */ },
186 
187 { IPV6_DONTFAILOVER_IF, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_PASSNEXT,
188 	sizeof (int),	0 /* no ifindex */ },
189 
190 { IPV6_UNSPEC_SRC, IPPROTO_IPV6, OA_R, OA_RW, OP_RAW, OP_PASSNEXT,
191 	sizeof (int), 0 },
192 
193 { IPV6_PKTINFO, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP,
194 	(OP_PASSNEXT|OP_NODEFAULT|OP_VARLEN),
195 	sizeof (struct in6_pktinfo), -1 /* not initialized */ },
196 { IPV6_HOPLIMIT, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP,
197 	(OP_PASSNEXT|OP_NODEFAULT),
198 	sizeof (int), -1 /* not initialized */ },
199 { IPV6_NEXTHOP, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP,
200 	(OP_PASSNEXT|OP_NODEFAULT|OP_VARLEN),
201 	sizeof (sin6_t), -1 /* not initialized */ },
202 { IPV6_HOPOPTS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP,
203 	(OP_PASSNEXT|OP_VARLEN|OP_NODEFAULT),
204 	MAX_EHDR_LEN, -1 /* not initialized */ },
205 { IPV6_DSTOPTS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP,
206 	(OP_PASSNEXT|OP_VARLEN|OP_NODEFAULT),
207 	MAX_EHDR_LEN, -1 /* not initialized */ },
208 { IPV6_RTHDRDSTOPTS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP,
209 	(OP_PASSNEXT|OP_VARLEN|OP_NODEFAULT),
210 	MAX_EHDR_LEN, -1 /* not initialized */ },
211 { IPV6_RTHDR, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP,
212 	(OP_PASSNEXT|OP_VARLEN|OP_NODEFAULT),
213 	MAX_EHDR_LEN, -1 /* not initialized */ },
214 { IPV6_TCLASS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP,
215 	(OP_PASSNEXT|OP_NODEFAULT),
216 	sizeof (int), -1 /* not initialized */ },
217 { IPV6_PATHMTU, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP,
218 	(OP_PASSNEXT|OP_NODEFAULT),
219 	sizeof (int), -1 /* not initialized */ },
220 { IPV6_DONTFRAG, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_PASSNEXT,
221 	sizeof (int), 0 },
222 { IPV6_USE_MIN_MTU, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_PASSNEXT,
223 	sizeof (int), 0 },
224 { IPV6_V6ONLY, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_PASSNEXT,
225 	sizeof (int), 0 },
226 
227 { IPV6_RECVPKTINFO, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_PASSNEXT,
228 	sizeof (int), 0 },
229 { IPV6_RECVHOPLIMIT, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_PASSNEXT,
230 	sizeof (int), 0 },
231 { IPV6_RECVHOPOPTS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_PASSNEXT,
232 	sizeof (int), 0 },
233 { _OLD_IPV6_RECVDSTOPTS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_PASSNEXT,
234 	sizeof (int), 0 },
235 { IPV6_RECVDSTOPTS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_PASSNEXT,
236 	sizeof (int), 0 },
237 { IPV6_RECVRTHDR, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_PASSNEXT,
238 	sizeof (int), 0 },
239 { IPV6_RECVRTHDRDSTOPTS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_PASSNEXT,
240 	sizeof (int), 0 },
241 { IPV6_RECVPATHMTU, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP,
242 	OP_PASSNEXT, sizeof (int), 0 },
243 { IPV6_RECVTCLASS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_PASSNEXT,
244 	sizeof (int), 0 },
245 
246 { IPV6_SEC_OPT, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, (OP_PASSNEXT|OP_NODEFAULT),
247 	sizeof (ipsec_req_t), -1 /* not initialized */ },
248 { IPV6_SRC_PREFERENCES, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_PASSNEXT,
249 	sizeof (uint32_t), IPV6_PREFER_SRC_DEFAULT },
250 
251 { MCAST_JOIN_GROUP, IPPROTO_IPV6, OA_X, OA_X, OP_NP,
252 	(OP_PASSNEXT|OP_NODEFAULT), sizeof (struct group_req),
253 	-1 /* not initialized */ },
254 { MCAST_LEAVE_GROUP, IPPROTO_IPV6, OA_X, OA_X, OP_NP,
255 	(OP_PASSNEXT|OP_NODEFAULT), sizeof (struct group_req),
256 	-1 /* not initialized */ },
257 { MCAST_BLOCK_SOURCE, IPPROTO_IPV6, OA_X, OA_X, OP_NP,
258 	(OP_PASSNEXT|OP_NODEFAULT), sizeof (struct group_source_req),
259 	-1 /* not initialized */ },
260 { MCAST_UNBLOCK_SOURCE, IPPROTO_IPV6, OA_X, OA_X, OP_NP,
261 	(OP_PASSNEXT|OP_NODEFAULT), sizeof (struct group_source_req),
262 	-1 /* not initialized */ },
263 { MCAST_JOIN_SOURCE_GROUP, IPPROTO_IPV6, OA_X, OA_X, OP_NP,
264 	(OP_PASSNEXT|OP_NODEFAULT), sizeof (struct group_source_req),
265 	-1 /* not initialized */ },
266 { MCAST_LEAVE_SOURCE_GROUP, IPPROTO_IPV6, OA_X, OA_X, OP_NP,
267 	(OP_PASSNEXT|OP_NODEFAULT), sizeof (struct group_source_req),
268 	-1 /* not initialized */ },
269 
270 { UDP_ANONPRIVBIND, IPPROTO_UDP, OA_R, OA_RW, OP_PRIVPORT, OP_PASSNEXT,
271 	sizeof (int), 0 },
272 { UDP_EXCLBIND, IPPROTO_UDP, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, sizeof (int), 0
273 	},
274 { UDP_RCVHDR, IPPROTO_UDP, OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0
275 	},
276 };
277 
278 /*
279  * Table of all supported levels
280  * Note: Some levels (e.g. XTI_GENERIC) may be valid but may not have
281  * any supported options so we need this info separately.
282  *
283  * This is needed only for topmost tpi providers and is used only by
284  * XTI interfaces.
285  */
286 optlevel_t	udp_valid_levels_arr[] = {
287 	XTI_GENERIC,
288 	SOL_SOCKET,
289 	IPPROTO_UDP,
290 	IPPROTO_IP,
291 	IPPROTO_IPV6
292 };
293 
294 #define	UDP_VALID_LEVELS_CNT	A_CNT(udp_valid_levels_arr)
295 #define	UDP_OPT_ARR_CNT		A_CNT(udp_opt_arr)
296 
297 uint_t udp_max_optsize; /* initialized when UDP driver is loaded */
298 
299 /*
300  * Initialize option database object for UDP
301  *
302  * This object represents database of options to search passed to
303  * {sock,tpi}optcom_req() interface routine to take care of option
304  * management and associated methods.
305  */
306 
307 optdb_obj_t udp_opt_obj = {
308 	udp_opt_default,	/* UDP default value function pointer */
309 	udp_opt_get,		/* UDP get function pointer */
310 	udp_opt_set,		/* UDP set function pointer */
311 	B_TRUE,			/* UDP is tpi provider */
312 	UDP_OPT_ARR_CNT,	/* UDP option database count of entries */
313 	udp_opt_arr,		/* UDP option database */
314 	UDP_VALID_LEVELS_CNT,	/* UDP valid level count of entries */
315 	udp_valid_levels_arr	/* UDP valid level array */
316 };
317