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