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 2009 Sun Microsystems, Inc. All rights reserved. 23 * Use is subject to license terms. 24 */ 25 26 #include <sys/types.h> 27 #include <sys/stream.h> 28 #define _SUN_TPI_VERSION 2 29 #include <sys/tihdr.h> 30 #include <sys/socket.h> 31 #include <sys/xti_inet.h> 32 33 #include <inet/common.h> 34 #include <netinet/ip6.h> 35 #include <inet/ip.h> 36 37 #include <netinet/in.h> 38 #include <netinet/ip_mroute.h> 39 #include <inet/optcom.h> 40 41 42 extern int ip_opt_default(queue_t *q, int level, int name, uchar_t *ptr); 43 extern int ip_opt_get(queue_t *q, int level, int name, uchar_t *ptr); 44 extern int ip_opt_set(queue_t *q, uint_t optset_context, int level, 45 int name, uint_t inlen, uchar_t *invalp, uint_t *outlenp, uchar_t *outvalp, 46 void *dummy, cred_t *cr, mblk_t *first_mp); 47 48 /* 49 * Table of all known options handled on a IP protocol stack. 50 * 51 * Note: Not all of these options are available through all protocol stacks 52 * For example, multicast options are not accessible in TCP over IP. 53 * The filtering for that happens in option table at transport level. 54 * Also, this table excludes any options processed exclusively at the 55 * transport protocol level. 56 */ 57 opdes_t ip_opt_arr[] = { 58 59 { SO_DONTROUTE, SOL_SOCKET, OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0 }, 60 { SO_BROADCAST, SOL_SOCKET, OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0 }, 61 { SO_REUSEADDR, SOL_SOCKET, OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0 }, 62 { SO_PROTOTYPE, SOL_SOCKET, OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0 }, 63 { SO_ANON_MLP, SOL_SOCKET, OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0 }, 64 { SO_MAC_EXEMPT, SOL_SOCKET, OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0 }, 65 { SO_MAC_IMPLICIT, SOL_SOCKET, OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0 }, 66 67 { SO_ALLZONES, SOL_SOCKET, OA_R, OA_RW, OP_CONFIG, 0, sizeof (int), 68 0 }, 69 70 71 { IP_OPTIONS, IPPROTO_IP, OA_RW, OA_RW, OP_NP, 72 (OP_VARLEN|OP_NODEFAULT), 73 IP_MAX_OPT_LENGTH + IP_ADDR_LEN, -1 /* not initialized */ }, 74 { T_IP_OPTIONS, IPPROTO_IP, OA_RW, OA_RW, OP_NP, 75 (OP_VARLEN|OP_NODEFAULT), 76 IP_MAX_OPT_LENGTH + IP_ADDR_LEN, -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_DHCPINIT_IF, IPPROTO_IP, OA_R, OA_RW, OP_CONFIG, 0, 123 sizeof (int), 0 }, 124 125 { IP_UNSPEC_SRC, IPPROTO_IP, OA_R, OA_RW, OP_RAW, 0, 126 sizeof (int), 0 }, 127 128 { IP_SEC_OPT, IPPROTO_IP, OA_RW, OA_RW, OP_NP, (OP_NODEFAULT), 129 sizeof (ipsec_req_t), -1 /* not initialized */ }, 130 131 { IP_NEXTHOP, IPPROTO_IP, OA_R, OA_RW, OP_CONFIG, 0, 132 sizeof (in_addr_t), -1 /* not initialized */ }, 133 134 { MRT_INIT, IPPROTO_IP, 0, OA_X, OP_CONFIG, 135 (OP_NODEFAULT), sizeof (int), -1 /* not initialized */ }, 136 137 { MRT_DONE, IPPROTO_IP, 0, OA_X, OP_CONFIG, 138 (OP_NODEFAULT), 0, -1 /* not initialized */ }, 139 140 { MRT_ADD_VIF, IPPROTO_IP, 0, OA_X, OP_CONFIG, (OP_NODEFAULT), 141 sizeof (struct vifctl), -1 /* not initialized */ }, 142 143 { MRT_DEL_VIF, IPPROTO_IP, 0, OA_X, OP_CONFIG, (OP_NODEFAULT), 144 sizeof (vifi_t), -1 /* not initialized */ }, 145 146 { MRT_ADD_MFC, IPPROTO_IP, 0, OA_X, OP_CONFIG, (OP_NODEFAULT), 147 sizeof (struct mfcctl), -1 /* not initialized */ }, 148 149 { MRT_DEL_MFC, IPPROTO_IP, 0, OA_X, OP_CONFIG, (OP_NODEFAULT), 150 sizeof (struct mfcctl), -1 /* not initialized */ }, 151 152 { MRT_VERSION, IPPROTO_IP, OA_R, OA_R, OP_NP, (OP_NODEFAULT), 153 sizeof (int), -1 /* not initialized */ }, 154 155 { MRT_ASSERT, IPPROTO_IP, 0, OA_RW, OP_CONFIG, (OP_NODEFAULT), 156 sizeof (int), -1 /* not initialized */ }, 157 158 { MCAST_JOIN_GROUP, IPPROTO_IP, OA_X, OA_X, OP_NP, 159 (OP_NODEFAULT), sizeof (struct group_req), 160 -1 /* not initialized */ }, 161 { MCAST_LEAVE_GROUP, IPPROTO_IP, OA_X, OA_X, OP_NP, 162 (OP_NODEFAULT), sizeof (struct group_req), 163 -1 /* not initialized */ }, 164 { MCAST_BLOCK_SOURCE, IPPROTO_IP, OA_X, OA_X, OP_NP, 165 (OP_NODEFAULT), sizeof (struct group_source_req), 166 -1 /* not initialized */ }, 167 { MCAST_UNBLOCK_SOURCE, IPPROTO_IP, OA_X, OA_X, OP_NP, 168 (OP_NODEFAULT), sizeof (struct group_source_req), 169 -1 /* not initialized */ }, 170 { MCAST_JOIN_SOURCE_GROUP, IPPROTO_IP, OA_X, OA_X, OP_NP, 171 (OP_NODEFAULT), sizeof (struct group_source_req), 172 -1 /* not initialized */ }, 173 { MCAST_LEAVE_SOURCE_GROUP, IPPROTO_IP, OA_X, OA_X, OP_NP, 174 (OP_NODEFAULT), sizeof (struct group_source_req), 175 -1 /* not initialized */ }, 176 177 { IPV6_MULTICAST_IF, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, 0, 178 sizeof (int), 0 }, 179 180 { IPV6_MULTICAST_HOPS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, 181 (OP_DEF_FN), sizeof (int), -1 /* not initialized */ }, 182 183 { IPV6_MULTICAST_LOOP, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, 184 (OP_DEF_FN), sizeof (int), -1 /* not initialized */}, 185 186 { IPV6_JOIN_GROUP, IPPROTO_IPV6, OA_X, OA_X, OP_NP, (OP_NODEFAULT), 187 sizeof (struct ipv6_mreq), -1 /* not initialized */ }, 188 189 { IPV6_LEAVE_GROUP, IPPROTO_IPV6, OA_X, OA_X, OP_NP, 190 (OP_NODEFAULT), 191 sizeof (struct ipv6_mreq), -1 /* not initialized */ }, 192 193 { IPV6_UNICAST_HOPS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, 194 (OP_DEF_FN), sizeof (int), -1 /* not initialized */ }, 195 196 { IPV6_BOUND_IF, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, 0, 197 sizeof (int), 0 /* no ifindex */ }, 198 199 { IPV6_UNSPEC_SRC, IPPROTO_IPV6, OA_R, OA_RW, OP_RAW, 0, 200 sizeof (int), 0 }, 201 202 { IPV6_PKTINFO, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, 203 (OP_NODEFAULT|OP_VARLEN), 204 sizeof (struct in6_pktinfo), -1 /* not initialized */ }, 205 { IPV6_HOPLIMIT, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, 206 (OP_NODEFAULT|OP_VARLEN), 207 sizeof (int), -1 /* not initialized */ }, 208 { IPV6_NEXTHOP, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, 209 (OP_NODEFAULT|OP_VARLEN), 210 sizeof (sin6_t), -1 /* not initialized */ }, 211 { IPV6_HOPOPTS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, 212 (OP_VARLEN|OP_NODEFAULT), 255*8, 213 -1 /* not initialized */ }, 214 { IPV6_DSTOPTS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, 215 (OP_VARLEN|OP_NODEFAULT), 255*8, 216 -1 /* not initialized */ }, 217 { IPV6_RTHDRDSTOPTS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, 218 (OP_VARLEN|OP_NODEFAULT), 255*8, 219 -1 /* not initialized */ }, 220 { IPV6_RTHDR, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, 221 (OP_VARLEN|OP_NODEFAULT), 255*8, 222 -1 /* not initialized */ }, 223 { IPV6_TCLASS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, 224 (OP_NODEFAULT|OP_VARLEN), 225 sizeof (int), -1 /* not initialized */ }, 226 { IPV6_PATHMTU, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, 0, 227 sizeof (struct ip6_mtuinfo), -1 }, 228 { IPV6_DONTFRAG, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, 0, 229 sizeof (int), 0 }, 230 { IPV6_USE_MIN_MTU, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, 0, 231 sizeof (int), -1 }, 232 { IPV6_V6ONLY, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, 0, 233 sizeof (int), 0 }, 234 235 /* Enable receipt of ancillary data */ 236 { IPV6_RECVPKTINFO, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, 0, 237 sizeof (int), 0 }, 238 { IPV6_RECVHOPLIMIT, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, 0, 239 sizeof (int), 0 }, 240 { IPV6_RECVHOPOPTS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, 0, 241 sizeof (int), 0 }, 242 { _OLD_IPV6_RECVDSTOPTS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, 0, 243 sizeof (int), 0 }, 244 { IPV6_RECVDSTOPTS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, 0, 245 sizeof (int), 0 }, 246 { IPV6_RECVRTHDR, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, 0, 247 sizeof (int), 0 }, 248 { IPV6_RECVRTHDRDSTOPTS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, 0, 249 sizeof (int), 0 }, 250 { IPV6_RECVTCLASS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, 0, 251 sizeof (int), 0 }, 252 { IPV6_RECVPATHMTU, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, 0, 253 sizeof (int), 0 }, 254 255 { IPV6_SEC_OPT, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, (OP_NODEFAULT), 256 sizeof (ipsec_req_t), -1 /* not initialized */ }, 257 { IPV6_SRC_PREFERENCES, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, 0, 258 sizeof (uint32_t), IPV6_PREFER_SRC_DEFAULT }, 259 260 { MCAST_JOIN_GROUP, IPPROTO_IPV6, OA_X, OA_X, OP_NP, 261 (OP_NODEFAULT), sizeof (struct group_req), 262 -1 /* not initialized */ }, 263 { MCAST_LEAVE_GROUP, IPPROTO_IPV6, OA_X, OA_X, OP_NP, 264 (OP_NODEFAULT), sizeof (struct group_req), 265 -1 /* not initialized */ }, 266 { MCAST_BLOCK_SOURCE, IPPROTO_IPV6, OA_X, OA_X, OP_NP, 267 (OP_NODEFAULT), sizeof (struct group_source_req), 268 -1 /* not initialized */ }, 269 { MCAST_UNBLOCK_SOURCE, IPPROTO_IPV6, OA_X, OA_X, OP_NP, 270 (OP_NODEFAULT), sizeof (struct group_source_req), 271 -1 /* not initialized */ }, 272 { MCAST_JOIN_SOURCE_GROUP, IPPROTO_IPV6, OA_X, OA_X, OP_NP, 273 (OP_NODEFAULT), sizeof (struct group_source_req), 274 -1 /* not initialized */ }, 275 { MCAST_LEAVE_SOURCE_GROUP, IPPROTO_IPV6, OA_X, OA_X, OP_NP, 276 (OP_NODEFAULT), sizeof (struct group_source_req), 277 -1 /* not initialized */ }, 278 }; 279 280 281 #define IP_OPT_ARR_CNT A_CNT(ip_opt_arr) 282 283 284 /* 285 * Initialize option database object for IP 286 * 287 * This object represents database of options to search passed to 288 * {sock,tpi}optcom_req() interface routine to take care of option 289 * management and associated methods. 290 */ 291 292 optdb_obj_t ip_opt_obj = { 293 ip_opt_default, /* IP default value function pointer */ 294 ip_opt_get, /* IP get function pointer */ 295 ip_opt_set, /* IP set function pointer */ 296 B_FALSE, /* IP is NOT a tpi provider */ 297 IP_OPT_ARR_CNT, /* IP option database count of entries */ 298 ip_opt_arr, /* IP option database */ 299 0, /* 0 - not needed if not top tpi provider */ 300 (optlevel_t *)0 /* null - not needed if not top tpi provider */ 301 }; 302