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_inet.h> 34 35 #include <inet/common.h> 36 #include <netinet/ip6.h> 37 #include <inet/ip.h> 38 39 #include <netinet/in.h> 40 #include <netinet/ip_mroute.h> 41 #include <inet/optcom.h> 42 43 44 extern int ip_opt_default(queue_t *q, int level, int name, uchar_t *ptr); 45 extern int ip_opt_get(queue_t *q, int level, int name, uchar_t *ptr); 46 extern int ip_opt_set(queue_t *q, uint_t optset_context, int level, 47 int name, uint_t inlen, uchar_t *invalp, uint_t *outlenp, uchar_t *outvalp, 48 void *, cred_t *cr, mblk_t *); 49 50 /* 51 * Table of all known options handled on a IP protocol stack. 52 * 53 * Note: Not all of these options are available through all protocol stacks 54 * For example, multicast options are not accessible in TCP over IP. 55 * The filtering for that happens in option table at transport level. 56 * Also, this table excludes any options processed exclusively at the 57 * transport protocol level. 58 */ 59 opdes_t ip_opt_arr[] = { 60 61 { SO_DONTROUTE, SOL_SOCKET, OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0 }, 62 { SO_BROADCAST, SOL_SOCKET, OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0 }, 63 { SO_REUSEADDR, SOL_SOCKET, OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0 }, 64 { SO_PROTOTYPE, SOL_SOCKET, OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0 }, 65 { SO_ANON_MLP, SOL_SOCKET, OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0 }, 66 { SO_MAC_EXEMPT, SOL_SOCKET, OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0 67 }, 68 69 { SO_ALLZONES, SOL_SOCKET, OA_R, OA_RW, OP_CONFIG, 0, sizeof (int), 70 0 }, 71 72 73 { IP_OPTIONS, IPPROTO_IP, OA_RW, OA_RW, OP_NP, 74 (OP_VARLEN|OP_NODEFAULT), 40, -1 /* not initialized */ }, 75 { T_IP_OPTIONS, IPPROTO_IP, OA_RW, OA_RW, OP_NP, 76 (OP_VARLEN|OP_NODEFAULT), 40, -1 /* not initialized */ }, 77 78 { IP_TOS, IPPROTO_IP, OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0 }, 79 { T_IP_TOS, IPPROTO_IP, OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0 }, 80 { IP_TTL, IPPROTO_IP, OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0 }, 81 { IP_MULTICAST_IF, IPPROTO_IP, OA_RW, OA_RW, OP_NP, 0, 82 sizeof (struct in_addr), 0 /* INADDR_ANY */ }, 83 84 { IP_MULTICAST_LOOP, IPPROTO_IP, OA_RW, OA_RW, OP_NP, (OP_DEF_FN), 85 sizeof (uchar_t), -1 /* not initialized */}, 86 87 { IP_MULTICAST_TTL, IPPROTO_IP, OA_RW, OA_RW, OP_NP, (OP_DEF_FN), 88 sizeof (uchar_t), -1 /* not initialized */ }, 89 90 { IP_ADD_MEMBERSHIP, IPPROTO_IP, OA_X, OA_X, OP_NP, (OP_NODEFAULT), 91 sizeof (struct ip_mreq), -1 /* not initialized */ }, 92 93 { IP_DROP_MEMBERSHIP, IPPROTO_IP, OA_X, OA_X, OP_NP, (OP_NODEFAULT), 94 sizeof (struct ip_mreq), -1 /* not initialized */ }, 95 96 { IP_BLOCK_SOURCE, IPPROTO_IP, OA_X, OA_X, OP_NP, (OP_NODEFAULT), 97 sizeof (struct ip_mreq_source), -1 /* not initialized */ }, 98 99 { IP_UNBLOCK_SOURCE, IPPROTO_IP, OA_X, OA_X, OP_NP, (OP_NODEFAULT), 100 sizeof (struct ip_mreq_source), -1 /* not initialized */ }, 101 102 { IP_ADD_SOURCE_MEMBERSHIP, IPPROTO_IP, OA_X, OA_X, OP_NP, 103 (OP_NODEFAULT), sizeof (struct ip_mreq_source), -1 }, 104 105 { IP_DROP_SOURCE_MEMBERSHIP, IPPROTO_IP, OA_X, OA_X, OP_NP, 106 (OP_NODEFAULT), sizeof (struct ip_mreq_source), -1 }, 107 108 { IP_RECVOPTS, IPPROTO_IP, OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0 }, 109 110 { IP_RECVDSTADDR, IPPROTO_IP, OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0 111 }, 112 113 { IP_RECVIF, IPPROTO_IP, OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0 }, 114 115 { IP_PKTINFO, IPPROTO_IP, OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0 }, 116 117 { IP_RECVSLLA, IPPROTO_IP, OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0 }, 118 119 { IP_BOUND_IF, IPPROTO_IP, OA_RW, OA_RW, OP_NP, 0, 120 sizeof (int), 0 /* no ifindex */ }, 121 122 { IP_DONTFAILOVER_IF, IPPROTO_IP, OA_RW, OA_RW, OP_NP, 0, 123 sizeof (struct in_addr), 0 /* not initialized */ }, 124 125 { IP_DHCPINIT_IF, IPPROTO_IP, OA_R, OA_RW, OP_CONFIG, 0, 126 sizeof (int), 0 }, 127 128 { IP_UNSPEC_SRC, IPPROTO_IP, OA_R, OA_RW, OP_RAW, 0, 129 sizeof (int), 0 }, 130 131 { IP_SEC_OPT, IPPROTO_IP, OA_RW, OA_RW, OP_NP, (OP_NODEFAULT), 132 sizeof (ipsec_req_t), -1 /* not initialized */ }, 133 134 { IP_NEXTHOP, IPPROTO_IP, OA_R, OA_RW, OP_CONFIG, 0, 135 sizeof (in_addr_t), -1 /* not initialized */ }, 136 137 { MRT_INIT, IPPROTO_IP, 0, OA_X, OP_CONFIG, 138 (OP_NODEFAULT), sizeof (int), -1 /* not initialized */ }, 139 140 { MRT_DONE, IPPROTO_IP, 0, OA_X, OP_CONFIG, 141 (OP_NODEFAULT), 0, -1 /* not initialized */ }, 142 143 { MRT_ADD_VIF, IPPROTO_IP, 0, OA_X, OP_CONFIG, (OP_NODEFAULT), 144 sizeof (struct vifctl), -1 /* not initialized */ }, 145 146 { MRT_DEL_VIF, IPPROTO_IP, 0, OA_X, OP_CONFIG, (OP_NODEFAULT), 147 sizeof (vifi_t), -1 /* not initialized */ }, 148 149 { MRT_ADD_MFC, IPPROTO_IP, 0, OA_X, OP_CONFIG, (OP_NODEFAULT), 150 sizeof (struct mfcctl), -1 /* not initialized */ }, 151 152 { MRT_DEL_MFC, IPPROTO_IP, 0, OA_X, OP_CONFIG, (OP_NODEFAULT), 153 sizeof (struct mfcctl), -1 /* not initialized */ }, 154 155 { MRT_VERSION, IPPROTO_IP, OA_R, OA_R, OP_NP, (OP_NODEFAULT), 156 sizeof (int), -1 /* not initialized */ }, 157 158 { MRT_ASSERT, IPPROTO_IP, 0, OA_RW, OP_CONFIG, (OP_NODEFAULT), 159 sizeof (int), -1 /* not initialized */ }, 160 161 { MCAST_JOIN_GROUP, IPPROTO_IP, OA_X, OA_X, OP_NP, 162 (OP_NODEFAULT), sizeof (struct group_req), 163 -1 /* not initialized */ }, 164 { MCAST_LEAVE_GROUP, IPPROTO_IP, OA_X, OA_X, OP_NP, 165 (OP_NODEFAULT), sizeof (struct group_req), 166 -1 /* not initialized */ }, 167 { MCAST_BLOCK_SOURCE, IPPROTO_IP, OA_X, OA_X, OP_NP, 168 (OP_NODEFAULT), sizeof (struct group_source_req), 169 -1 /* not initialized */ }, 170 { MCAST_UNBLOCK_SOURCE, IPPROTO_IP, OA_X, OA_X, OP_NP, 171 (OP_NODEFAULT), sizeof (struct group_source_req), 172 -1 /* not initialized */ }, 173 { MCAST_JOIN_SOURCE_GROUP, IPPROTO_IP, OA_X, OA_X, OP_NP, 174 (OP_NODEFAULT), sizeof (struct group_source_req), 175 -1 /* not initialized */ }, 176 { MCAST_LEAVE_SOURCE_GROUP, IPPROTO_IP, OA_X, OA_X, OP_NP, 177 (OP_NODEFAULT), sizeof (struct group_source_req), 178 -1 /* not initialized */ }, 179 180 { IPV6_MULTICAST_IF, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, 0, 181 sizeof (int), 0 }, 182 183 { IPV6_MULTICAST_HOPS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, 184 (OP_DEF_FN), sizeof (int), -1 /* not initialized */ }, 185 186 { IPV6_MULTICAST_LOOP, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, 187 (OP_DEF_FN), sizeof (int), -1 /* not initialized */}, 188 189 { IPV6_JOIN_GROUP, IPPROTO_IPV6, OA_X, OA_X, OP_NP, (OP_NODEFAULT), 190 sizeof (struct ipv6_mreq), -1 /* not initialized */ }, 191 192 { IPV6_LEAVE_GROUP, IPPROTO_IPV6, OA_X, OA_X, OP_NP, 193 (OP_NODEFAULT), 194 sizeof (struct ipv6_mreq), -1 /* not initialized */ }, 195 196 { IPV6_UNICAST_HOPS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, 197 (OP_DEF_FN), sizeof (int), -1 /* not initialized */ }, 198 199 { IPV6_BOUND_IF, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, 0, 200 sizeof (int), 0 /* no ifindex */ }, 201 202 { IPV6_BOUND_PIF, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, 0, 203 sizeof (int), 0 /* no ifindex */ }, 204 205 { IPV6_DONTFAILOVER_IF, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, 0, 206 sizeof (int), 0 /* no ifindex */ }, 207 208 { IPV6_UNSPEC_SRC, IPPROTO_IPV6, OA_R, OA_RW, OP_RAW, 0, 209 sizeof (int), 0 }, 210 211 { IPV6_PKTINFO, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, 212 (OP_NODEFAULT|OP_VARLEN), 213 sizeof (struct in6_pktinfo), -1 /* not initialized */ }, 214 { IPV6_HOPLIMIT, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, 215 (OP_NODEFAULT|OP_VARLEN), 216 sizeof (int), -1 /* not initialized */ }, 217 { IPV6_NEXTHOP, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, 218 (OP_NODEFAULT|OP_VARLEN), 219 sizeof (sin6_t), -1 /* not initialized */ }, 220 { IPV6_HOPOPTS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, 221 (OP_VARLEN|OP_NODEFAULT), 255*8, 222 -1 /* not initialized */ }, 223 { IPV6_DSTOPTS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, 224 (OP_VARLEN|OP_NODEFAULT), 255*8, 225 -1 /* not initialized */ }, 226 { IPV6_RTHDRDSTOPTS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, 227 (OP_VARLEN|OP_NODEFAULT), 255*8, 228 -1 /* not initialized */ }, 229 { IPV6_RTHDR, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, 230 (OP_VARLEN|OP_NODEFAULT), 255*8, 231 -1 /* not initialized */ }, 232 { IPV6_TCLASS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, 233 (OP_NODEFAULT|OP_VARLEN), 234 sizeof (int), -1 /* not initialized */ }, 235 { IPV6_PATHMTU, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, 0, 236 sizeof (struct ip6_mtuinfo), -1 }, 237 { IPV6_DONTFRAG, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, 0, 238 sizeof (int), 0 }, 239 { IPV6_USE_MIN_MTU, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, 0, 240 sizeof (int), -1 }, 241 { IPV6_V6ONLY, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, 0, 242 sizeof (int), 0 }, 243 244 /* Enable receipt of ancillary data */ 245 { IPV6_RECVPKTINFO, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, 0, 246 sizeof (int), 0 }, 247 { IPV6_RECVHOPLIMIT, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, 0, 248 sizeof (int), 0 }, 249 { IPV6_RECVHOPOPTS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, 0, 250 sizeof (int), 0 }, 251 { _OLD_IPV6_RECVDSTOPTS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, 0, 252 sizeof (int), 0 }, 253 { IPV6_RECVDSTOPTS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, 0, 254 sizeof (int), 0 }, 255 { IPV6_RECVRTHDR, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, 0, 256 sizeof (int), 0 }, 257 { IPV6_RECVRTHDRDSTOPTS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, 0, 258 sizeof (int), 0 }, 259 { IPV6_RECVTCLASS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, 0, 260 sizeof (int), 0 }, 261 { IPV6_RECVPATHMTU, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, 0, 262 sizeof (int), 0 }, 263 264 { IPV6_SEC_OPT, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, (OP_NODEFAULT), 265 sizeof (ipsec_req_t), -1 /* not initialized */ }, 266 { IPV6_SRC_PREFERENCES, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, 0, 267 sizeof (uint32_t), IPV6_PREFER_SRC_DEFAULT }, 268 269 { MCAST_JOIN_GROUP, IPPROTO_IPV6, OA_X, OA_X, OP_NP, 270 (OP_NODEFAULT), sizeof (struct group_req), 271 -1 /* not initialized */ }, 272 { MCAST_LEAVE_GROUP, IPPROTO_IPV6, OA_X, OA_X, OP_NP, 273 (OP_NODEFAULT), sizeof (struct group_req), 274 -1 /* not initialized */ }, 275 { MCAST_BLOCK_SOURCE, IPPROTO_IPV6, OA_X, OA_X, OP_NP, 276 (OP_NODEFAULT), sizeof (struct group_source_req), 277 -1 /* not initialized */ }, 278 { MCAST_UNBLOCK_SOURCE, IPPROTO_IPV6, OA_X, OA_X, OP_NP, 279 (OP_NODEFAULT), sizeof (struct group_source_req), 280 -1 /* not initialized */ }, 281 { MCAST_JOIN_SOURCE_GROUP, IPPROTO_IPV6, OA_X, OA_X, OP_NP, 282 (OP_NODEFAULT), sizeof (struct group_source_req), 283 -1 /* not initialized */ }, 284 { MCAST_LEAVE_SOURCE_GROUP, IPPROTO_IPV6, OA_X, OA_X, OP_NP, 285 (OP_NODEFAULT), sizeof (struct group_source_req), 286 -1 /* not initialized */ }, 287 }; 288 289 290 #define IP_OPT_ARR_CNT A_CNT(ip_opt_arr) 291 292 293 /* 294 * Initialize option database object for IP 295 * 296 * This object represents database of options to search passed to 297 * {sock,tpi}optcom_req() interface routine to take care of option 298 * management and associated methods. 299 */ 300 301 optdb_obj_t ip_opt_obj = { 302 ip_opt_default, /* IP default value function pointer */ 303 ip_opt_get, /* IP get function pointer */ 304 ip_opt_set, /* IP set function pointer */ 305 B_FALSE, /* IP is NOT a tpi provider */ 306 IP_OPT_ARR_CNT, /* IP option database count of entries */ 307 ip_opt_arr, /* IP option database */ 308 0, /* 0 - not needed if not top tpi provider */ 309 (optlevel_t *)0 /* null - not needed if not top tpi provider */ 310 }; 311