xref: /illumos-gate/usr/src/uts/common/inet/ip/icmp_opt_data.c (revision 1a220b56b93ff1dc80855691548503117af4cc10)
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 { IP_OPTIONS,	IPPROTO_IP, OA_RW, OA_RW, OP_NP,
94 	(OP_PASSNEXT|OP_VARLEN|OP_NODEFAULT),
95 	40, -1 /* not initialized */ },
96 { T_IP_OPTIONS,	IPPROTO_IP, OA_RW, OA_RW, OP_NP,
97 	(OP_PASSNEXT|OP_VARLEN|OP_NODEFAULT),
98 	40, -1 /* not initialized */ },
99 
100 { IP_HDRINCL,	IPPROTO_IP, OA_R,  OA_RW, OP_RAW, OP_PASSNEXT,
101 	sizeof (int), 0 },
102 { IP_TOS,	IPPROTO_IP, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, sizeof (int), 0 },
103 { T_IP_TOS,	IPPROTO_IP, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, sizeof (int), 0 },
104 { IP_TTL,	IPPROTO_IP, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, sizeof (int), 0 },
105 
106 { IP_MULTICAST_IF, IPPROTO_IP, OA_RW, OA_RW, OP_NP, OP_PASSNEXT,
107 	sizeof (struct in_addr), 0 /* INADDR_ANY */ },
108 
109 { IP_MULTICAST_LOOP, IPPROTO_IP, OA_RW, OA_RW, OP_NP, (OP_PASSNEXT|OP_DEF_FN),
110 	sizeof (uchar_t), -1 /* not initialized */},
111 
112 { IP_MULTICAST_TTL, IPPROTO_IP, OA_RW, OA_RW, OP_NP, (OP_PASSNEXT|OP_DEF_FN),
113 	sizeof (uchar_t), -1 /* not initialized */ },
114 
115 { IP_ADD_MEMBERSHIP, IPPROTO_IP, OA_X, OA_X, OP_NP, (OP_PASSNEXT|OP_NODEFAULT),
116 	sizeof (struct ip_mreq), -1 /* not initialized */ },
117 
118 { IP_DROP_MEMBERSHIP, IPPROTO_IP, OA_X, OA_X, OP_NP, (OP_PASSNEXT|OP_NODEFAULT),
119 	sizeof (struct ip_mreq), 0 },
120 
121 { IP_BLOCK_SOURCE, IPPROTO_IP, OA_X, OA_X, OP_NP, (OP_PASSNEXT|OP_NODEFAULT),
122 	sizeof (struct ip_mreq_source), -1 },
123 
124 { IP_UNBLOCK_SOURCE, IPPROTO_IP, OA_X, OA_X, OP_NP, (OP_PASSNEXT|OP_NODEFAULT),
125 	sizeof (struct ip_mreq_source), -1 },
126 
127 { IP_ADD_SOURCE_MEMBERSHIP, IPPROTO_IP, OA_X, OA_X, OP_NP,
128 	(OP_PASSNEXT|OP_NODEFAULT), sizeof (struct ip_mreq_source), -1 },
129 
130 { IP_DROP_SOURCE_MEMBERSHIP, IPPROTO_IP, OA_X, OA_X, OP_NP,
131 	(OP_PASSNEXT|OP_NODEFAULT), sizeof (struct ip_mreq_source), -1 },
132 
133 { IP_SEC_OPT, IPPROTO_IP, OA_RW, OA_RW, OP_NP, (OP_PASSNEXT|OP_NODEFAULT),
134 	sizeof (ipsec_req_t), -1 /* not initialized */ },
135 
136 { IP_BOUND_IF, IPPROTO_IP, OA_RW, OA_RW, OP_NP, OP_PASSNEXT,
137 	sizeof (int),	0 /* no ifindex */ },
138 
139 { IP_XMIT_IF, IPPROTO_IP, OA_RW, OA_RW, OP_NP, OP_PASSNEXT,
140 	sizeof (int),	0 /* no ifindex */ },
141 
142 { IP_DONTFAILOVER_IF, IPPROTO_IP, OA_RW, OA_RW, OP_NP, OP_PASSNEXT,
143 	sizeof (struct in_addr), 0 /* not initialized */ },
144 
145 { IP_UNSPEC_SRC, IPPROTO_IP, OA_R, OA_RW, OP_RAW, OP_PASSNEXT,
146 	sizeof (int), 0 },
147 
148 { IP_RECVIF, IPPROTO_IP, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, sizeof (int), 0 },
149 
150 { IP_NEXTHOP, IPPROTO_IP, OA_RW, OA_RW, OP_CONFIG, OP_PASSNEXT,
151 	sizeof (in_addr_t),	-1 /* not initialized */ },
152 
153 { MRT_INIT, IPPROTO_IP, 0, OA_X, OP_CONFIG,
154 	(OP_PASSNEXT|OP_NODEFAULT), sizeof (int),
155 	-1 /* not initialized */ },
156 
157 { MRT_DONE, IPPROTO_IP, 0, OA_X, OP_CONFIG,
158 	(OP_PASSNEXT|OP_NODEFAULT), 0, -1 /* not initialized */ },
159 
160 { MRT_ADD_VIF, IPPROTO_IP, 0, OA_X, OP_CONFIG, (OP_PASSNEXT|OP_NODEFAULT),
161 	sizeof (struct vifctl), -1 /* not initialized */ },
162 
163 { MRT_DEL_VIF, 	IPPROTO_IP, 0, OA_X, OP_CONFIG, (OP_PASSNEXT|OP_NODEFAULT),
164 	sizeof (vifi_t), -1 /* not initialized */ },
165 
166 { MRT_ADD_MFC, 	IPPROTO_IP, 0, OA_X, OP_CONFIG, (OP_PASSNEXT|OP_NODEFAULT),
167 	sizeof (struct mfcctl), -1 /* not initialized */ },
168 
169 { MRT_DEL_MFC, 	IPPROTO_IP, 0, OA_X, OP_CONFIG, (OP_PASSNEXT|OP_NODEFAULT),
170 	sizeof (struct mfcctl), -1 /* not initialized */ },
171 
172 { MRT_VERSION, 	IPPROTO_IP, OA_R, OA_R, OP_NP, (OP_PASSNEXT|OP_NODEFAULT),
173 	sizeof (int), -1 /* not initialized */ },
174 
175 { MRT_ASSERT, 	IPPROTO_IP, 0, OA_RW, OP_CONFIG,
176 	(OP_PASSNEXT|OP_NODEFAULT),
177 	sizeof (int), -1 /* not initialized */ },
178 
179 { MCAST_JOIN_GROUP, IPPROTO_IP, OA_X, OA_X, OP_NP,
180 	(OP_PASSNEXT|OP_NODEFAULT), sizeof (struct group_req),
181 	-1 /* not initialized */ },
182 { MCAST_LEAVE_GROUP, IPPROTO_IP, OA_X, OA_X, OP_NP,
183 	(OP_PASSNEXT|OP_NODEFAULT), sizeof (struct group_req),
184 	-1 /* not initialized */ },
185 { MCAST_BLOCK_SOURCE, IPPROTO_IP, OA_X, OA_X, OP_NP,
186 	(OP_PASSNEXT|OP_NODEFAULT), sizeof (struct group_source_req),
187 	-1 /* not initialized */ },
188 { MCAST_UNBLOCK_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_JOIN_SOURCE_GROUP, IPPROTO_IP, OA_X, OA_X, OP_NP,
192 	(OP_PASSNEXT|OP_NODEFAULT), sizeof (struct group_source_req),
193 	-1 /* not initialized */ },
194 { MCAST_LEAVE_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 
198 { IPV6_MULTICAST_IF, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_PASSNEXT,
199 	sizeof (int), 0 },
200 
201 { IPV6_MULTICAST_HOPS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP,
202 	(OP_PASSNEXT|OP_DEF_FN), sizeof (int), -1 /* not initialized */ },
203 
204 { IPV6_MULTICAST_LOOP, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP,
205 	(OP_PASSNEXT|OP_DEF_FN), sizeof (int), -1 /* not initialized */},
206 
207 { IPV6_JOIN_GROUP, IPPROTO_IPV6, OA_X, OA_X, OP_NP, (OP_PASSNEXT|OP_NODEFAULT),
208 	sizeof (struct ipv6_mreq), -1 /* not initialized */ },
209 
210 { IPV6_LEAVE_GROUP, IPPROTO_IPV6, OA_X, OA_X, OP_NP, (OP_PASSNEXT|OP_NODEFAULT),
211 	sizeof (struct ipv6_mreq), -1 /* not initialized */ },
212 
213 { IPV6_UNICAST_HOPS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, (OP_PASSNEXT|OP_DEF_FN),
214 	sizeof (int), -1 /* not initialized */ },
215 
216 { IPV6_BOUND_IF, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_PASSNEXT,
217 	sizeof (int),	0 /* no ifindex */ },
218 
219 { IPV6_BOUND_PIF, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_PASSNEXT,
220 	sizeof (int),	0 /* no ifindex */ },
221 
222 { IPV6_DONTFAILOVER_IF, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_PASSNEXT,
223 	sizeof (int),	0 /* no ifindex */ },
224 
225 { IPV6_UNSPEC_SRC, IPPROTO_IPV6, OA_R, OA_RW, OP_RAW, OP_PASSNEXT,
226 	sizeof (int), 0 },
227 
228 { IPV6_CHECKSUM, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, sizeof (int),
229 	-1 },
230 
231 { ICMP6_FILTER, IPPROTO_ICMPV6, OA_RW, OA_RW, OP_NP, OP_DEF_FN|OP_VARLEN,
232 	sizeof (icmp6_filter_t), 0 },
233 { IPV6_PKTINFO, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP,
234 	(OP_PASSNEXT|OP_NODEFAULT|OP_VARLEN),
235 	sizeof (struct in6_pktinfo), -1 /* not initialized */ },
236 { IPV6_HOPLIMIT, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP,
237 	(OP_PASSNEXT|OP_NODEFAULT|OP_VARLEN),
238 	sizeof (int), -1 /* not initialized */ },
239 { IPV6_NEXTHOP, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP,
240 	(OP_PASSNEXT|OP_NODEFAULT|OP_VARLEN),
241 	sizeof (sin6_t), -1 /* not initialized */ },
242 { IPV6_HOPOPTS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP,
243 	(OP_PASSNEXT|OP_VARLEN|OP_NODEFAULT),
244 	MAX_EHDR_LEN, -1 /* not initialized */ },
245 { IPV6_DSTOPTS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP,
246 	(OP_PASSNEXT|OP_VARLEN|OP_NODEFAULT),
247 	MAX_EHDR_LEN, -1 /* not initialized */ },
248 { IPV6_RTHDRDSTOPTS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP,
249 	(OP_PASSNEXT|OP_VARLEN|OP_NODEFAULT),
250 	MAX_EHDR_LEN, -1 /* not initialized */ },
251 { IPV6_RTHDR, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP,
252 	(OP_PASSNEXT|OP_VARLEN|OP_NODEFAULT),
253 	MAX_EHDR_LEN, -1 /* not initialized */ },
254 { IPV6_TCLASS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP,
255 	(OP_PASSNEXT|OP_NODEFAULT|OP_VARLEN),
256 	sizeof (int), -1 /* not initialized */ },
257 { IPV6_PATHMTU, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_PASSNEXT,
258 	sizeof (struct ip6_mtuinfo), -1 },
259 { IPV6_DONTFRAG, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_PASSNEXT,
260 	sizeof (int), 0 },
261 { IPV6_USE_MIN_MTU, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_PASSNEXT,
262 	sizeof (int), 0 },
263 { IPV6_V6ONLY, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_PASSNEXT,
264 	sizeof (int), 0 },
265 
266 { IPV6_RECVPKTINFO, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_PASSNEXT,
267 	sizeof (int), 0 },
268 { IPV6_RECVHOPLIMIT, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_PASSNEXT,
269 	sizeof (int), 0 },
270 { IPV6_RECVHOPOPTS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_PASSNEXT,
271 	sizeof (int), 0 },
272 { _OLD_IPV6_RECVDSTOPTS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_PASSNEXT,
273 	sizeof (int), 0 },
274 { IPV6_RECVDSTOPTS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_PASSNEXT,
275 	sizeof (int), 0 },
276 { IPV6_RECVRTHDR, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_PASSNEXT,
277 	sizeof (int), 0 },
278 { IPV6_RECVRTHDRDSTOPTS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_PASSNEXT,
279 	sizeof (int), 0 },
280 { IPV6_RECVPATHMTU, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_PASSNEXT,
281 	sizeof (int), 0 },
282 { IPV6_RECVTCLASS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_PASSNEXT,
283 	sizeof (int), 0 },
284 
285 { IPV6_SEC_OPT, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, (OP_PASSNEXT|OP_NODEFAULT),
286 	sizeof (ipsec_req_t), -1 /* not initialized */ },
287 { IPV6_SRC_PREFERENCES, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_PASSNEXT,
288 	sizeof (uint32_t), IPV6_PREFER_SRC_DEFAULT },
289 
290 { MCAST_JOIN_GROUP, IPPROTO_IPV6, OA_X, OA_X, OP_NP,
291 	(OP_PASSNEXT|OP_NODEFAULT), sizeof (struct group_req),
292 	-1 /* not initialized */ },
293 { MCAST_LEAVE_GROUP, IPPROTO_IPV6, OA_X, OA_X, OP_NP,
294 	(OP_PASSNEXT|OP_NODEFAULT), sizeof (struct group_req),
295 	-1 /* not initialized */ },
296 { MCAST_BLOCK_SOURCE, IPPROTO_IPV6, OA_X, OA_X, OP_NP,
297 	(OP_PASSNEXT|OP_NODEFAULT), sizeof (struct group_source_req),
298 	-1 /* not initialized */ },
299 { MCAST_UNBLOCK_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_JOIN_SOURCE_GROUP, IPPROTO_IPV6, OA_X, OA_X, OP_NP,
303 	(OP_PASSNEXT|OP_NODEFAULT), sizeof (struct group_source_req),
304 	-1 /* not initialized */ },
305 { MCAST_LEAVE_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 };
309 
310 /*
311  * Table of all supported levels
312  * Note: Some levels (e.g. XTI_GENERIC) may be valid but may not have
313  * any supported options so we need this info separately.
314  *
315  * This is needed only for topmost tpi providers and is used only by
316  * XTI interfaces.
317  */
318 optlevel_t	icmp_valid_levels_arr[] = {
319 	XTI_GENERIC,
320 	SOL_SOCKET,
321 	IPPROTO_ICMP,
322 	IPPROTO_IP,
323 	IPPROTO_IPV6,
324 	IPPROTO_ICMPV6
325 };
326 
327 #define	ICMP_VALID_LEVELS_CNT	A_CNT(icmp_valid_levels_arr)
328 #define	ICMP_OPT_ARR_CNT		A_CNT(icmp_opt_arr)
329 
330 uint_t	icmp_max_optsize; /* initialized when ICMP driver is loaded */
331 
332 /*
333  * Initialize option database object for ICMP
334  *
335  * This object represents database of options to search passed to
336  * {sock,tpi}optcom_req() interface routine to take care of option
337  * management and associated methods.
338  */
339 
340 optdb_obj_t icmp_opt_obj = {
341 	icmp_opt_default,	/* ICMP default value function pointer */
342 	icmp_opt_get,		/* ICMP get function pointer */
343 	icmp_opt_set,		/* ICMP set function pointer */
344 	B_TRUE,			/* ICMP is tpi provider */
345 	ICMP_OPT_ARR_CNT,	/* ICMP option database count of entries */
346 	icmp_opt_arr,		/* ICMP option database */
347 	ICMP_VALID_LEVELS_CNT,	/* ICMP valid level count of entries */
348 	icmp_valid_levels_arr	/* ICMP valid level array */
349 };
350