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