xref: /illumos-gate/usr/src/uts/common/inet/ip/icmp_opt_data.c (revision 7ae111d47a973fff4c6e231cc31f271dd9cef473)
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 2006 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 <netinet/in.h>
37 #include <netinet/icmp6.h>
38 #include <inet/common.h>
39 #include <netinet/ip6.h>
40 #include <inet/ip.h>
41 /*
42  * MK_XXX Following 2 includes temporary to import ip6_rthdr_t
43  *        definition. May not be needed if we fix ip6_dg_snd_attrs_t
44  *        to do all extension headers in identical manner.
45  */
46 #include <net/if.h>
47 #include <inet/ip6.h>
48 
49 #include <netinet/tcp.h>
50 #include <netinet/ip_mroute.h>
51 #include <inet/optcom.h>
52 
53 
54 extern int icmp_opt_default(queue_t *, int, int, uchar_t *);
55 extern int icmp_opt_get(queue_t *, int, int, uchar_t *);
56 extern int icmp_opt_set(queue_t *, uint_t, int, int, uint_t, uchar_t *,
57     uint_t *, uchar_t *, void *, cred_t *, mblk_t *);
58 
59 /*
60  * Table of all known options handled on a ICMP protocol stack.
61  *
62  * Note: This table contains options processed by both ICMP and IP levels
63  *       and is the superset of options that can be performed on a ICMP over IP
64  *       stack.
65  */
66 opdes_t	icmp_opt_arr[] = {
67 
68 { SO_DEBUG,	SOL_SOCKET, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, sizeof (int), 0 },
69 { SO_DONTROUTE,	SOL_SOCKET, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, sizeof (int), 0 },
70 { SO_USELOOPBACK, SOL_SOCKET, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, sizeof (int), 0
71 	},
72 { SO_BROADCAST,	SOL_SOCKET, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, sizeof (int), 0 },
73 { SO_REUSEADDR, SOL_SOCKET, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, sizeof (int), 0 },
74 
75 #ifdef	SO_PROTOTYPE
76 	/*
77 	 * icmp will only allow IPPROTO_ICMP for non-privileged streams
78 	 * that check is made on an adhoc basis.
79 	 */
80 { SO_PROTOTYPE, SOL_SOCKET, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, sizeof (int), 0 },
81 #endif
82 
83 { SO_TYPE,	SOL_SOCKET, OA_R, OA_R, OP_NP, OP_PASSNEXT, sizeof (int), 0 },
84 { SO_SNDBUF,	SOL_SOCKET, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, sizeof (int), 0 },
85 { SO_RCVBUF,	SOL_SOCKET, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, sizeof (int), 0 },
86 { SO_DGRAM_ERRIND, SOL_SOCKET, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, sizeof (int),
87 	0 },
88 { SO_TIMESTAMP, SOL_SOCKET, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, sizeof (int), 0
89 	},
90 { SO_MAC_EXEMPT, SOL_SOCKET, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, sizeof (int),
91 	0 },
92 
93 { SO_ALLZONES, SOL_SOCKET, OA_R, OA_RW, OP_CONFIG, OP_PASSNEXT, sizeof (int),
94 	0 },
95 
96 { IP_OPTIONS,	IPPROTO_IP, OA_RW, OA_RW, OP_NP,
97 	(OP_PASSNEXT|OP_VARLEN|OP_NODEFAULT),
98 	40, -1 /* not initialized */ },
99 { T_IP_OPTIONS,	IPPROTO_IP, OA_RW, OA_RW, OP_NP,
100 	(OP_PASSNEXT|OP_VARLEN|OP_NODEFAULT),
101 	40, -1 /* not initialized */ },
102 
103 { IP_HDRINCL,	IPPROTO_IP, OA_R,  OA_RW, OP_RAW, OP_PASSNEXT,
104 	sizeof (int), 0 },
105 { IP_TOS,	IPPROTO_IP, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, sizeof (int), 0 },
106 { T_IP_TOS,	IPPROTO_IP, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, sizeof (int), 0 },
107 { IP_TTL,	IPPROTO_IP, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, sizeof (int), 0 },
108 
109 { IP_MULTICAST_IF, IPPROTO_IP, OA_RW, OA_RW, OP_NP, OP_PASSNEXT,
110 	sizeof (struct in_addr), 0 /* INADDR_ANY */ },
111 
112 { IP_MULTICAST_LOOP, IPPROTO_IP, OA_RW, OA_RW, OP_NP, (OP_PASSNEXT|OP_DEF_FN),
113 	sizeof (uchar_t), -1 /* not initialized */},
114 
115 { IP_MULTICAST_TTL, IPPROTO_IP, OA_RW, OA_RW, OP_NP, (OP_PASSNEXT|OP_DEF_FN),
116 	sizeof (uchar_t), -1 /* not initialized */ },
117 
118 { IP_ADD_MEMBERSHIP, IPPROTO_IP, OA_X, OA_X, OP_NP, (OP_PASSNEXT|OP_NODEFAULT),
119 	sizeof (struct ip_mreq), -1 /* not initialized */ },
120 
121 { IP_DROP_MEMBERSHIP, IPPROTO_IP, OA_X, OA_X, OP_NP, (OP_PASSNEXT|OP_NODEFAULT),
122 	sizeof (struct ip_mreq), 0 },
123 
124 { IP_BLOCK_SOURCE, IPPROTO_IP, OA_X, OA_X, OP_NP, (OP_PASSNEXT|OP_NODEFAULT),
125 	sizeof (struct ip_mreq_source), -1 },
126 
127 { IP_UNBLOCK_SOURCE, IPPROTO_IP, OA_X, OA_X, OP_NP, (OP_PASSNEXT|OP_NODEFAULT),
128 	sizeof (struct ip_mreq_source), -1 },
129 
130 { IP_ADD_SOURCE_MEMBERSHIP, IPPROTO_IP, OA_X, OA_X, OP_NP,
131 	(OP_PASSNEXT|OP_NODEFAULT), sizeof (struct ip_mreq_source), -1 },
132 
133 { IP_DROP_SOURCE_MEMBERSHIP, IPPROTO_IP, OA_X, OA_X, OP_NP,
134 	(OP_PASSNEXT|OP_NODEFAULT), sizeof (struct ip_mreq_source), -1 },
135 
136 { IP_SEC_OPT, IPPROTO_IP, OA_RW, OA_RW, OP_NP, (OP_PASSNEXT|OP_NODEFAULT),
137 	sizeof (ipsec_req_t), -1 /* not initialized */ },
138 
139 { IP_BOUND_IF, IPPROTO_IP, OA_RW, OA_RW, OP_NP, OP_PASSNEXT,
140 	sizeof (int),	0 /* no ifindex */ },
141 
142 { IP_XMIT_IF, IPPROTO_IP, OA_RW, OA_RW, OP_NP, OP_PASSNEXT,
143 	sizeof (int),	0 /* no ifindex */ },
144 
145 { IP_DONTFAILOVER_IF, IPPROTO_IP, OA_RW, OA_RW, OP_NP, OP_PASSNEXT,
146 	sizeof (struct in_addr), 0 /* not initialized */ },
147 
148 { IP_UNSPEC_SRC, IPPROTO_IP, OA_R, OA_RW, OP_RAW, OP_PASSNEXT,
149 	sizeof (int), 0 },
150 
151 { IP_RECVIF, IPPROTO_IP, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, sizeof (int), 0 },
152 
153 { IP_NEXTHOP, IPPROTO_IP, OA_RW, OA_RW, OP_CONFIG, OP_PASSNEXT,
154 	sizeof (in_addr_t),	-1 /* not initialized */ },
155 
156 { MRT_INIT, IPPROTO_IP, 0, OA_X, OP_CONFIG,
157 	(OP_PASSNEXT|OP_NODEFAULT), sizeof (int),
158 	-1 /* not initialized */ },
159 
160 { MRT_DONE, IPPROTO_IP, 0, OA_X, OP_CONFIG,
161 	(OP_PASSNEXT|OP_NODEFAULT), 0, -1 /* not initialized */ },
162 
163 { MRT_ADD_VIF, IPPROTO_IP, 0, OA_X, OP_CONFIG, (OP_PASSNEXT|OP_NODEFAULT),
164 	sizeof (struct vifctl), -1 /* not initialized */ },
165 
166 { MRT_DEL_VIF, 	IPPROTO_IP, 0, OA_X, OP_CONFIG, (OP_PASSNEXT|OP_NODEFAULT),
167 	sizeof (vifi_t), -1 /* not initialized */ },
168 
169 { MRT_ADD_MFC, 	IPPROTO_IP, 0, OA_X, OP_CONFIG, (OP_PASSNEXT|OP_NODEFAULT),
170 	sizeof (struct mfcctl), -1 /* not initialized */ },
171 
172 { MRT_DEL_MFC, 	IPPROTO_IP, 0, OA_X, OP_CONFIG, (OP_PASSNEXT|OP_NODEFAULT),
173 	sizeof (struct mfcctl), -1 /* not initialized */ },
174 
175 { MRT_VERSION, 	IPPROTO_IP, OA_R, OA_R, OP_NP, (OP_PASSNEXT|OP_NODEFAULT),
176 	sizeof (int), -1 /* not initialized */ },
177 
178 { MRT_ASSERT, 	IPPROTO_IP, 0, OA_RW, OP_CONFIG,
179 	(OP_PASSNEXT|OP_NODEFAULT),
180 	sizeof (int), -1 /* not initialized */ },
181 
182 { MCAST_JOIN_GROUP, IPPROTO_IP, OA_X, OA_X, OP_NP,
183 	(OP_PASSNEXT|OP_NODEFAULT), sizeof (struct group_req),
184 	-1 /* not initialized */ },
185 { MCAST_LEAVE_GROUP, IPPROTO_IP, OA_X, OA_X, OP_NP,
186 	(OP_PASSNEXT|OP_NODEFAULT), sizeof (struct group_req),
187 	-1 /* not initialized */ },
188 { MCAST_BLOCK_SOURCE, IPPROTO_IP, OA_X, OA_X, OP_NP,
189 	(OP_PASSNEXT|OP_NODEFAULT), sizeof (struct group_source_req),
190 	-1 /* not initialized */ },
191 { MCAST_UNBLOCK_SOURCE, IPPROTO_IP, OA_X, OA_X, OP_NP,
192 	(OP_PASSNEXT|OP_NODEFAULT), sizeof (struct group_source_req),
193 	-1 /* not initialized */ },
194 { MCAST_JOIN_SOURCE_GROUP, IPPROTO_IP, OA_X, OA_X, OP_NP,
195 	(OP_PASSNEXT|OP_NODEFAULT), sizeof (struct group_source_req),
196 	-1 /* not initialized */ },
197 { MCAST_LEAVE_SOURCE_GROUP, IPPROTO_IP, OA_X, OA_X, OP_NP,
198 	(OP_PASSNEXT|OP_NODEFAULT), sizeof (struct group_source_req),
199 	-1 /* not initialized */ },
200 
201 { IPV6_MULTICAST_IF, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_PASSNEXT,
202 	sizeof (int), 0 },
203 
204 { IPV6_MULTICAST_HOPS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP,
205 	(OP_PASSNEXT|OP_DEF_FN), sizeof (int), -1 /* not initialized */ },
206 
207 { IPV6_MULTICAST_LOOP, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP,
208 	(OP_PASSNEXT|OP_DEF_FN), sizeof (int), -1 /* not initialized */},
209 
210 { IPV6_JOIN_GROUP, IPPROTO_IPV6, OA_X, OA_X, OP_NP, (OP_PASSNEXT|OP_NODEFAULT),
211 	sizeof (struct ipv6_mreq), -1 /* not initialized */ },
212 
213 { IPV6_LEAVE_GROUP, IPPROTO_IPV6, OA_X, OA_X, OP_NP, (OP_PASSNEXT|OP_NODEFAULT),
214 	sizeof (struct ipv6_mreq), -1 /* not initialized */ },
215 
216 { IPV6_UNICAST_HOPS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, (OP_PASSNEXT|OP_DEF_FN),
217 	sizeof (int), -1 /* not initialized */ },
218 
219 { IPV6_BOUND_IF, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_PASSNEXT,
220 	sizeof (int),	0 /* no ifindex */ },
221 
222 { IPV6_BOUND_PIF, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_PASSNEXT,
223 	sizeof (int),	0 /* no ifindex */ },
224 
225 { IPV6_DONTFAILOVER_IF, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_PASSNEXT,
226 	sizeof (int),	0 /* no ifindex */ },
227 
228 { IPV6_UNSPEC_SRC, IPPROTO_IPV6, OA_R, OA_RW, OP_RAW, OP_PASSNEXT,
229 	sizeof (int), 0 },
230 
231 { IPV6_CHECKSUM, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, sizeof (int),
232 	-1 },
233 
234 { ICMP6_FILTER, IPPROTO_ICMPV6, OA_RW, OA_RW, OP_NP, OP_DEF_FN|OP_VARLEN,
235 	sizeof (icmp6_filter_t), 0 },
236 { IPV6_PKTINFO, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP,
237 	(OP_PASSNEXT|OP_NODEFAULT|OP_VARLEN),
238 	sizeof (struct in6_pktinfo), -1 /* not initialized */ },
239 { IPV6_HOPLIMIT, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP,
240 	(OP_PASSNEXT|OP_NODEFAULT|OP_VARLEN),
241 	sizeof (int), -1 /* not initialized */ },
242 { IPV6_NEXTHOP, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP,
243 	(OP_PASSNEXT|OP_NODEFAULT|OP_VARLEN),
244 	sizeof (sin6_t), -1 /* not initialized */ },
245 { IPV6_HOPOPTS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP,
246 	(OP_PASSNEXT|OP_VARLEN|OP_NODEFAULT),
247 	MAX_EHDR_LEN, -1 /* not initialized */ },
248 { IPV6_DSTOPTS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP,
249 	(OP_PASSNEXT|OP_VARLEN|OP_NODEFAULT),
250 	MAX_EHDR_LEN, -1 /* not initialized */ },
251 { IPV6_RTHDRDSTOPTS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP,
252 	(OP_PASSNEXT|OP_VARLEN|OP_NODEFAULT),
253 	MAX_EHDR_LEN, -1 /* not initialized */ },
254 { IPV6_RTHDR, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP,
255 	(OP_PASSNEXT|OP_VARLEN|OP_NODEFAULT),
256 	MAX_EHDR_LEN, -1 /* not initialized */ },
257 { IPV6_TCLASS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP,
258 	(OP_PASSNEXT|OP_NODEFAULT|OP_VARLEN),
259 	sizeof (int), -1 /* not initialized */ },
260 { IPV6_PATHMTU, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_PASSNEXT,
261 	sizeof (struct ip6_mtuinfo), -1 },
262 { IPV6_DONTFRAG, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_PASSNEXT,
263 	sizeof (int), 0 },
264 { IPV6_USE_MIN_MTU, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_PASSNEXT,
265 	sizeof (int), 0 },
266 { IPV6_V6ONLY, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_PASSNEXT,
267 	sizeof (int), 0 },
268 
269 { IPV6_RECVPKTINFO, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_PASSNEXT,
270 	sizeof (int), 0 },
271 { IPV6_RECVHOPLIMIT, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_PASSNEXT,
272 	sizeof (int), 0 },
273 { IPV6_RECVHOPOPTS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_PASSNEXT,
274 	sizeof (int), 0 },
275 { _OLD_IPV6_RECVDSTOPTS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_PASSNEXT,
276 	sizeof (int), 0 },
277 { IPV6_RECVDSTOPTS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_PASSNEXT,
278 	sizeof (int), 0 },
279 { IPV6_RECVRTHDR, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_PASSNEXT,
280 	sizeof (int), 0 },
281 { IPV6_RECVRTHDRDSTOPTS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_PASSNEXT,
282 	sizeof (int), 0 },
283 { IPV6_RECVPATHMTU, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_PASSNEXT,
284 	sizeof (int), 0 },
285 { IPV6_RECVTCLASS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_PASSNEXT,
286 	sizeof (int), 0 },
287 
288 { IPV6_SEC_OPT, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, (OP_PASSNEXT|OP_NODEFAULT),
289 	sizeof (ipsec_req_t), -1 /* not initialized */ },
290 { IPV6_SRC_PREFERENCES, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_PASSNEXT,
291 	sizeof (uint32_t), IPV6_PREFER_SRC_DEFAULT },
292 
293 { MCAST_JOIN_GROUP, IPPROTO_IPV6, OA_X, OA_X, OP_NP,
294 	(OP_PASSNEXT|OP_NODEFAULT), sizeof (struct group_req),
295 	-1 /* not initialized */ },
296 { MCAST_LEAVE_GROUP, IPPROTO_IPV6, OA_X, OA_X, OP_NP,
297 	(OP_PASSNEXT|OP_NODEFAULT), sizeof (struct group_req),
298 	-1 /* not initialized */ },
299 { MCAST_BLOCK_SOURCE, IPPROTO_IPV6, OA_X, OA_X, OP_NP,
300 	(OP_PASSNEXT|OP_NODEFAULT), sizeof (struct group_source_req),
301 	-1 /* not initialized */ },
302 { MCAST_UNBLOCK_SOURCE, IPPROTO_IPV6, OA_X, OA_X, OP_NP,
303 	(OP_PASSNEXT|OP_NODEFAULT), sizeof (struct group_source_req),
304 	-1 /* not initialized */ },
305 { MCAST_JOIN_SOURCE_GROUP, IPPROTO_IPV6, OA_X, OA_X, OP_NP,
306 	(OP_PASSNEXT|OP_NODEFAULT), sizeof (struct group_source_req),
307 	-1 /* not initialized */ },
308 { MCAST_LEAVE_SOURCE_GROUP, IPPROTO_IPV6, OA_X, OA_X, OP_NP,
309 	(OP_PASSNEXT|OP_NODEFAULT), sizeof (struct group_source_req),
310 	-1 /* not initialized */ },
311 };
312 
313 /*
314  * Table of all supported levels
315  * Note: Some levels (e.g. XTI_GENERIC) may be valid but may not have
316  * any supported options so we need this info separately.
317  *
318  * This is needed only for topmost tpi providers and is used only by
319  * XTI interfaces.
320  */
321 optlevel_t	icmp_valid_levels_arr[] = {
322 	XTI_GENERIC,
323 	SOL_SOCKET,
324 	IPPROTO_ICMP,
325 	IPPROTO_IP,
326 	IPPROTO_IPV6,
327 	IPPROTO_ICMPV6
328 };
329 
330 #define	ICMP_VALID_LEVELS_CNT	A_CNT(icmp_valid_levels_arr)
331 #define	ICMP_OPT_ARR_CNT		A_CNT(icmp_opt_arr)
332 
333 uint_t	icmp_max_optsize; /* initialized when ICMP driver is loaded */
334 
335 /*
336  * Initialize option database object for ICMP
337  *
338  * This object represents database of options to search passed to
339  * {sock,tpi}optcom_req() interface routine to take care of option
340  * management and associated methods.
341  */
342 
343 optdb_obj_t icmp_opt_obj = {
344 	icmp_opt_default,	/* ICMP default value function pointer */
345 	icmp_opt_get,		/* ICMP get function pointer */
346 	icmp_opt_set,		/* ICMP set function pointer */
347 	B_TRUE,			/* ICMP is tpi provider */
348 	ICMP_OPT_ARR_CNT,	/* ICMP option database count of entries */
349 	icmp_opt_arr,		/* ICMP option database */
350 	ICMP_VALID_LEVELS_CNT,	/* ICMP valid level count of entries */
351 	icmp_valid_levels_arr	/* ICMP valid level array */
352 };
353