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 <inet/common.h> 37 #include <netinet/ip6.h> 38 #include <inet/ip.h> 39 #include <inet/udp_impl.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/udp.h> 50 #include <inet/optcom.h> 51 52 /* 53 * Table of all known options handled on a UDP protocol stack. 54 * 55 * Note: This table contains options processed by both UDP and IP levels 56 * and is the superset of options that can be performed on a UDP over IP 57 * stack. 58 */ 59 opdes_t udp_opt_arr[] = { 60 61 { SO_DEBUG, SOL_SOCKET, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, sizeof (int), 0 }, 62 { SO_DONTROUTE, SOL_SOCKET, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, sizeof (int), 0 }, 63 { SO_USELOOPBACK, SOL_SOCKET, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, sizeof (int), 0 64 }, 65 { SO_BROADCAST, SOL_SOCKET, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, sizeof (int), 0 }, 66 { SO_REUSEADDR, SOL_SOCKET, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, sizeof (int), 0 }, 67 { SO_TYPE, SOL_SOCKET, OA_R, OA_R, OP_NP, OP_PASSNEXT, sizeof (int), 0 }, 68 { SO_SNDBUF, SOL_SOCKET, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, sizeof (int), 0 }, 69 { SO_RCVBUF, SOL_SOCKET, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, sizeof (int), 0 }, 70 { SO_DGRAM_ERRIND, SOL_SOCKET, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, sizeof (int), 71 0 }, 72 { SO_RECVUCRED, SOL_SOCKET, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, sizeof (int), 0 73 }, 74 { SO_ALLZONES, SOL_SOCKET, OA_R, OA_RW, OP_CONFIG, OP_PASSNEXT, sizeof (int), 75 0 }, 76 { SO_TIMESTAMP, SOL_SOCKET, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, sizeof (int), 0 77 }, 78 { SO_ANON_MLP, SOL_SOCKET, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, sizeof (int), 79 0 }, 80 { SO_MAC_EXEMPT, SOL_SOCKET, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, sizeof (int), 81 0 }, 82 { SCM_UCRED, SOL_SOCKET, OA_W, OA_W, OP_NP, OP_VARLEN|OP_NODEFAULT, 512, 0 }, 83 { SO_EXCLBIND, SOL_SOCKET, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, sizeof (int), 0 }, 84 85 { IP_OPTIONS, IPPROTO_IP, OA_RW, OA_RW, OP_NP, 86 (OP_PASSNEXT|OP_VARLEN|OP_NODEFAULT), 40, -1 /* not initialized */ }, 87 { T_IP_OPTIONS, IPPROTO_IP, OA_RW, OA_RW, OP_NP, 88 (OP_PASSNEXT|OP_VARLEN|OP_NODEFAULT), 40, -1 /* not initialized */ }, 89 90 { IP_TOS, IPPROTO_IP, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, sizeof (int), 0 }, 91 { T_IP_TOS, IPPROTO_IP, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, sizeof (int), 0 }, 92 { IP_TTL, IPPROTO_IP, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, sizeof (int), 0 }, 93 { IP_RECVOPTS, IPPROTO_IP, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, sizeof (int), 0 }, 94 { IP_RECVDSTADDR, IPPROTO_IP, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, sizeof (int), 0 95 }, 96 { IP_RECVIF, IPPROTO_IP, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, sizeof (int), 0 }, 97 { IP_RECVSLLA, IPPROTO_IP, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, sizeof (int), 0 }, 98 { IP_RECVTTL, IPPROTO_IP, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, sizeof (int), 99 0 }, 100 { IP_MULTICAST_IF, IPPROTO_IP, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, 101 sizeof (struct in_addr), 0 /* INADDR_ANY */ }, 102 103 { IP_MULTICAST_LOOP, IPPROTO_IP, OA_RW, OA_RW, OP_NP, (OP_PASSNEXT|OP_DEF_FN), 104 sizeof (uchar_t), -1 /* not initialized */}, 105 106 { IP_MULTICAST_TTL, IPPROTO_IP, OA_RW, OA_RW, OP_NP, (OP_PASSNEXT|OP_DEF_FN), 107 sizeof (uchar_t), -1 /* not initialized */ }, 108 109 { IP_ADD_MEMBERSHIP, IPPROTO_IP, OA_X, OA_X, OP_NP, (OP_PASSNEXT|OP_NODEFAULT), 110 sizeof (struct ip_mreq), -1 /* not initialized */ }, 111 112 { IP_DROP_MEMBERSHIP, IPPROTO_IP, OA_X, OA_X, OP_NP, (OP_PASSNEXT|OP_NODEFAULT), 113 sizeof (struct ip_mreq), -1 /* not initialized */ }, 114 115 { IP_BLOCK_SOURCE, IPPROTO_IP, OA_X, OA_X, OP_NP, (OP_PASSNEXT|OP_NODEFAULT), 116 sizeof (struct ip_mreq_source), -1 /* not initialized */ }, 117 118 { IP_UNBLOCK_SOURCE, IPPROTO_IP, OA_X, OA_X, OP_NP, (OP_PASSNEXT|OP_NODEFAULT), 119 sizeof (struct ip_mreq_source), -1 /* not initialized */ }, 120 121 { IP_ADD_SOURCE_MEMBERSHIP, IPPROTO_IP, OA_X, OA_X, OP_NP, 122 (OP_PASSNEXT|OP_NODEFAULT), sizeof (struct ip_mreq_source), -1 }, 123 124 { IP_DROP_SOURCE_MEMBERSHIP, IPPROTO_IP, OA_X, OA_X, OP_NP, 125 (OP_PASSNEXT|OP_NODEFAULT), sizeof (struct ip_mreq_source), -1 }, 126 127 { IP_SEC_OPT, IPPROTO_IP, OA_RW, OA_RW, OP_NP, (OP_PASSNEXT|OP_NODEFAULT), 128 sizeof (ipsec_req_t), -1 /* not initialized */ }, 129 130 { IP_BOUND_IF, IPPROTO_IP, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, 131 sizeof (int), 0 /* no ifindex */ }, 132 { IP_XMIT_IF, IPPROTO_IP, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, 133 sizeof (int), 0 /* no ifindex */ }, 134 135 { IP_DONTFAILOVER_IF, IPPROTO_IP, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, 136 sizeof (struct in_addr), 0 /* not initialized */ }, 137 138 { IP_UNSPEC_SRC, IPPROTO_IP, OA_R, OA_RW, OP_RAW, OP_PASSNEXT, 139 sizeof (int), 0 }, 140 141 { IP_NEXTHOP, IPPROTO_IP, OA_RW, OA_RW, OP_CONFIG, OP_PASSNEXT, 142 sizeof (in_addr_t), -1 /* not initialized */ }, 143 144 { MCAST_JOIN_GROUP, IPPROTO_IP, OA_X, OA_X, OP_NP, 145 (OP_PASSNEXT|OP_NODEFAULT), sizeof (struct group_req), 146 -1 /* not initialized */ }, 147 { MCAST_LEAVE_GROUP, IPPROTO_IP, OA_X, OA_X, OP_NP, 148 (OP_PASSNEXT|OP_NODEFAULT), sizeof (struct group_req), 149 -1 /* not initialized */ }, 150 { MCAST_BLOCK_SOURCE, IPPROTO_IP, OA_X, OA_X, OP_NP, 151 (OP_PASSNEXT|OP_NODEFAULT), sizeof (struct group_source_req), 152 -1 /* not initialized */ }, 153 { MCAST_UNBLOCK_SOURCE, IPPROTO_IP, OA_X, OA_X, OP_NP, 154 (OP_PASSNEXT|OP_NODEFAULT), sizeof (struct group_source_req), 155 -1 /* not initialized */ }, 156 { MCAST_JOIN_SOURCE_GROUP, IPPROTO_IP, OA_X, OA_X, OP_NP, 157 (OP_PASSNEXT|OP_NODEFAULT), sizeof (struct group_source_req), 158 -1 /* not initialized */ }, 159 { MCAST_LEAVE_SOURCE_GROUP, IPPROTO_IP, OA_X, OA_X, OP_NP, 160 (OP_PASSNEXT|OP_NODEFAULT), sizeof (struct group_source_req), 161 -1 /* not initialized */ }, 162 163 { IPV6_MULTICAST_IF, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, 164 sizeof (int), 0 }, 165 166 { IPV6_MULTICAST_HOPS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, 167 (OP_PASSNEXT|OP_DEF_FN), sizeof (int), -1 /* not initialized */ }, 168 169 { IPV6_MULTICAST_LOOP, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, 170 (OP_PASSNEXT|OP_DEF_FN), sizeof (int), -1 /* not initialized */}, 171 172 { IPV6_JOIN_GROUP, IPPROTO_IPV6, OA_X, OA_X, OP_NP, (OP_PASSNEXT|OP_NODEFAULT), 173 sizeof (struct ipv6_mreq), -1 /* not initialized */ }, 174 175 { IPV6_LEAVE_GROUP, IPPROTO_IPV6, OA_X, OA_X, OP_NP, 176 (OP_PASSNEXT|OP_NODEFAULT), 177 sizeof (struct ipv6_mreq), -1 /* not initialized */ }, 178 179 { IPV6_UNICAST_HOPS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, (OP_PASSNEXT|OP_DEF_FN), 180 sizeof (int), -1 /* not initialized */ }, 181 182 { IPV6_BOUND_IF, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, 183 sizeof (int), 0 /* no ifindex */ }, 184 185 { IPV6_BOUND_PIF, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, 186 sizeof (int), 0 /* no ifindex */ }, 187 188 { IPV6_DONTFAILOVER_IF, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, 189 sizeof (int), 0 /* no ifindex */ }, 190 191 { IPV6_UNSPEC_SRC, IPPROTO_IPV6, OA_R, OA_RW, OP_RAW, OP_PASSNEXT, 192 sizeof (int), 0 }, 193 194 { IPV6_PKTINFO, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, 195 (OP_PASSNEXT|OP_NODEFAULT|OP_VARLEN), 196 sizeof (struct in6_pktinfo), -1 /* not initialized */ }, 197 { IPV6_HOPLIMIT, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, 198 (OP_PASSNEXT|OP_NODEFAULT), 199 sizeof (int), -1 /* not initialized */ }, 200 { IPV6_NEXTHOP, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, 201 (OP_PASSNEXT|OP_NODEFAULT|OP_VARLEN), 202 sizeof (sin6_t), -1 /* not initialized */ }, 203 { IPV6_HOPOPTS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, 204 (OP_PASSNEXT|OP_VARLEN|OP_NODEFAULT), 205 MAX_EHDR_LEN, -1 /* not initialized */ }, 206 { IPV6_DSTOPTS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, 207 (OP_PASSNEXT|OP_VARLEN|OP_NODEFAULT), 208 MAX_EHDR_LEN, -1 /* not initialized */ }, 209 { IPV6_RTHDRDSTOPTS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, 210 (OP_PASSNEXT|OP_VARLEN|OP_NODEFAULT), 211 MAX_EHDR_LEN, -1 /* not initialized */ }, 212 { IPV6_RTHDR, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, 213 (OP_PASSNEXT|OP_VARLEN|OP_NODEFAULT), 214 MAX_EHDR_LEN, -1 /* not initialized */ }, 215 { IPV6_TCLASS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, 216 (OP_PASSNEXT|OP_NODEFAULT), 217 sizeof (int), -1 /* not initialized */ }, 218 { IPV6_PATHMTU, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, 219 (OP_PASSNEXT|OP_NODEFAULT), 220 sizeof (int), -1 /* not initialized */ }, 221 { IPV6_DONTFRAG, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, 222 sizeof (int), 0 }, 223 { IPV6_USE_MIN_MTU, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, 224 sizeof (int), 0 }, 225 { IPV6_V6ONLY, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, 226 sizeof (int), 0 }, 227 228 { IPV6_RECVPKTINFO, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, 229 sizeof (int), 0 }, 230 { IPV6_RECVHOPLIMIT, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, 231 sizeof (int), 0 }, 232 { IPV6_RECVHOPOPTS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, 233 sizeof (int), 0 }, 234 { _OLD_IPV6_RECVDSTOPTS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, 235 sizeof (int), 0 }, 236 { IPV6_RECVDSTOPTS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, 237 sizeof (int), 0 }, 238 { IPV6_RECVRTHDR, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, 239 sizeof (int), 0 }, 240 { IPV6_RECVRTHDRDSTOPTS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, 241 sizeof (int), 0 }, 242 { IPV6_RECVPATHMTU, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, 243 OP_PASSNEXT, sizeof (int), 0 }, 244 { IPV6_RECVTCLASS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, 245 sizeof (int), 0 }, 246 247 { IPV6_SEC_OPT, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, (OP_PASSNEXT|OP_NODEFAULT), 248 sizeof (ipsec_req_t), -1 /* not initialized */ }, 249 { IPV6_SRC_PREFERENCES, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, 250 sizeof (uint32_t), IPV6_PREFER_SRC_DEFAULT }, 251 252 { MCAST_JOIN_GROUP, IPPROTO_IPV6, OA_X, OA_X, OP_NP, 253 (OP_PASSNEXT|OP_NODEFAULT), sizeof (struct group_req), 254 -1 /* not initialized */ }, 255 { MCAST_LEAVE_GROUP, IPPROTO_IPV6, OA_X, OA_X, OP_NP, 256 (OP_PASSNEXT|OP_NODEFAULT), sizeof (struct group_req), 257 -1 /* not initialized */ }, 258 { MCAST_BLOCK_SOURCE, IPPROTO_IPV6, OA_X, OA_X, OP_NP, 259 (OP_PASSNEXT|OP_NODEFAULT), sizeof (struct group_source_req), 260 -1 /* not initialized */ }, 261 { MCAST_UNBLOCK_SOURCE, IPPROTO_IPV6, OA_X, OA_X, OP_NP, 262 (OP_PASSNEXT|OP_NODEFAULT), sizeof (struct group_source_req), 263 -1 /* not initialized */ }, 264 { MCAST_JOIN_SOURCE_GROUP, IPPROTO_IPV6, OA_X, OA_X, OP_NP, 265 (OP_PASSNEXT|OP_NODEFAULT), sizeof (struct group_source_req), 266 -1 /* not initialized */ }, 267 { MCAST_LEAVE_SOURCE_GROUP, IPPROTO_IPV6, OA_X, OA_X, OP_NP, 268 (OP_PASSNEXT|OP_NODEFAULT), sizeof (struct group_source_req), 269 -1 /* not initialized */ }, 270 271 { UDP_ANONPRIVBIND, IPPROTO_UDP, OA_R, OA_RW, OP_PRIVPORT, OP_PASSNEXT, 272 sizeof (int), 0 }, 273 { UDP_EXCLBIND, IPPROTO_UDP, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, sizeof (int), 0 274 }, 275 { UDP_RCVHDR, IPPROTO_UDP, OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0 276 }, 277 }; 278 279 /* 280 * Table of all supported levels 281 * Note: Some levels (e.g. XTI_GENERIC) may be valid but may not have 282 * any supported options so we need this info separately. 283 * 284 * This is needed only for topmost tpi providers and is used only by 285 * XTI interfaces. 286 */ 287 optlevel_t udp_valid_levels_arr[] = { 288 XTI_GENERIC, 289 SOL_SOCKET, 290 IPPROTO_UDP, 291 IPPROTO_IP, 292 IPPROTO_IPV6 293 }; 294 295 #define UDP_VALID_LEVELS_CNT A_CNT(udp_valid_levels_arr) 296 #define UDP_OPT_ARR_CNT A_CNT(udp_opt_arr) 297 298 uint_t udp_max_optsize; /* initialized when UDP driver is loaded */ 299 300 /* 301 * Initialize option database object for UDP 302 * 303 * This object represents database of options to search passed to 304 * {sock,tpi}optcom_req() interface routine to take care of option 305 * management and associated methods. 306 */ 307 308 optdb_obj_t udp_opt_obj = { 309 udp_opt_default, /* UDP default value function pointer */ 310 udp_opt_get, /* UDP get function pointer */ 311 udp_opt_set, /* UDP set function pointer */ 312 B_TRUE, /* UDP is tpi provider */ 313 UDP_OPT_ARR_CNT, /* UDP option database count of entries */ 314 udp_opt_arr, /* UDP option database */ 315 UDP_VALID_LEVELS_CNT, /* UDP valid level count of entries */ 316 udp_valid_levels_arr /* UDP valid level array */ 317 }; 318