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