udp_opt_data.c revision 8348:4137e18bfaf0
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 2008 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 */ 57opdes_t udp_opt_arr[] = { 58 59{ SO_DEBUG, SOL_SOCKET, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, sizeof (int), 0 }, 60{ SO_DONTROUTE, SOL_SOCKET, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, sizeof (int), 0 }, 61{ SO_USELOOPBACK, SOL_SOCKET, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, sizeof (int), 0 62 }, 63{ SO_BROADCAST, SOL_SOCKET, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, sizeof (int), 0 }, 64{ SO_REUSEADDR, SOL_SOCKET, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, sizeof (int), 0 }, 65{ SO_TYPE, SOL_SOCKET, OA_R, OA_R, OP_NP, OP_PASSNEXT, sizeof (int), 0 }, 66{ SO_SNDBUF, SOL_SOCKET, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, sizeof (int), 0 }, 67{ SO_RCVBUF, SOL_SOCKET, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, sizeof (int), 0 }, 68{ SO_DGRAM_ERRIND, SOL_SOCKET, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, sizeof (int), 69 0 }, 70{ SO_RECVUCRED, SOL_SOCKET, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, sizeof (int), 0 71 }, 72{ SO_ALLZONES, SOL_SOCKET, OA_R, OA_RW, OP_CONFIG, OP_PASSNEXT, sizeof (int), 73 0 }, 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{ SO_EXCLBIND, SOL_SOCKET, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, sizeof (int), 0 }, 82{ SO_DOMAIN, SOL_SOCKET, OA_R, OA_R, OP_NP, OP_PASSNEXT, sizeof (int), 0 }, 83{ SO_PROTOTYPE, SOL_SOCKET, OA_R, OA_R, 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), 87 IP_MAX_OPT_LENGTH + IP_ADDR_LEN, -1 /* not initialized */ }, 88{ T_IP_OPTIONS, IPPROTO_IP, OA_RW, OA_RW, OP_NP, 89 (OP_PASSNEXT|OP_VARLEN|OP_NODEFAULT), 90 IP_MAX_OPT_LENGTH + IP_ADDR_LEN, -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 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_DHCPINIT_IF, IPPROTO_IP, OA_R, OA_RW, OP_CONFIG, OP_PASSNEXT, 139 sizeof (int), 0 }, 140 141{ IP_UNSPEC_SRC, IPPROTO_IP, OA_R, OA_RW, OP_RAW, OP_PASSNEXT, 142 sizeof (int), 0 }, 143 144{ IP_BROADCAST_TTL, IPPROTO_IP, OA_R, OA_RW, OP_RAW, 0, sizeof (uchar_t), 145 0 /* disabled */ }, 146 147{ IP_PKTINFO, IPPROTO_IP, OA_RW, OA_RW, OP_NP, 148 (OP_PASSNEXT|OP_NODEFAULT|OP_VARLEN), 149 sizeof (struct in_pktinfo), -1 /* not initialized */ }, 150{ IP_NEXTHOP, IPPROTO_IP, OA_R, OA_RW, OP_CONFIG, OP_PASSNEXT, 151 sizeof (in_addr_t), -1 /* not initialized */ }, 152 153{ MCAST_JOIN_GROUP, IPPROTO_IP, OA_X, OA_X, OP_NP, 154 (OP_PASSNEXT|OP_NODEFAULT), sizeof (struct group_req), 155 -1 /* not initialized */ }, 156{ MCAST_LEAVE_GROUP, IPPROTO_IP, OA_X, OA_X, OP_NP, 157 (OP_PASSNEXT|OP_NODEFAULT), sizeof (struct group_req), 158 -1 /* not initialized */ }, 159{ MCAST_BLOCK_SOURCE, IPPROTO_IP, OA_X, OA_X, OP_NP, 160 (OP_PASSNEXT|OP_NODEFAULT), sizeof (struct group_source_req), 161 -1 /* not initialized */ }, 162{ MCAST_UNBLOCK_SOURCE, IPPROTO_IP, OA_X, OA_X, OP_NP, 163 (OP_PASSNEXT|OP_NODEFAULT), sizeof (struct group_source_req), 164 -1 /* not initialized */ }, 165{ MCAST_JOIN_SOURCE_GROUP, IPPROTO_IP, OA_X, OA_X, OP_NP, 166 (OP_PASSNEXT|OP_NODEFAULT), sizeof (struct group_source_req), 167 -1 /* not initialized */ }, 168{ MCAST_LEAVE_SOURCE_GROUP, IPPROTO_IP, OA_X, OA_X, OP_NP, 169 (OP_PASSNEXT|OP_NODEFAULT), sizeof (struct group_source_req), 170 -1 /* not initialized */ }, 171 172{ IPV6_MULTICAST_IF, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, 173 sizeof (int), 0 }, 174 175{ IPV6_MULTICAST_HOPS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, 176 (OP_PASSNEXT|OP_DEF_FN), sizeof (int), -1 /* not initialized */ }, 177 178{ IPV6_MULTICAST_LOOP, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, 179 (OP_PASSNEXT|OP_DEF_FN), sizeof (int), -1 /* not initialized */}, 180 181{ IPV6_JOIN_GROUP, IPPROTO_IPV6, OA_X, OA_X, OP_NP, (OP_PASSNEXT|OP_NODEFAULT), 182 sizeof (struct ipv6_mreq), -1 /* not initialized */ }, 183 184{ IPV6_LEAVE_GROUP, IPPROTO_IPV6, OA_X, OA_X, OP_NP, 185 (OP_PASSNEXT|OP_NODEFAULT), 186 sizeof (struct ipv6_mreq), -1 /* not initialized */ }, 187 188{ IPV6_UNICAST_HOPS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, (OP_PASSNEXT|OP_DEF_FN), 189 sizeof (int), -1 /* not initialized */ }, 190 191{ IPV6_BOUND_IF, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, 192 sizeof (int), 0 /* no ifindex */ }, 193 194{ IPV6_BOUND_PIF, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, 195 sizeof (int), 0 /* no ifindex */ }, 196 197{ IPV6_DONTFAILOVER_IF, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, 198 sizeof (int), 0 /* no ifindex */ }, 199 200{ IPV6_UNSPEC_SRC, IPPROTO_IPV6, OA_R, OA_RW, OP_RAW, OP_PASSNEXT, 201 sizeof (int), 0 }, 202 203{ IPV6_PKTINFO, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, 204 (OP_PASSNEXT|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_PASSNEXT|OP_NODEFAULT), 208 sizeof (int), -1 /* not initialized */ }, 209{ IPV6_NEXTHOP, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, 210 (OP_PASSNEXT|OP_NODEFAULT|OP_VARLEN), 211 sizeof (sin6_t), -1 /* not initialized */ }, 212{ IPV6_HOPOPTS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, 213 (OP_PASSNEXT|OP_VARLEN|OP_NODEFAULT), 214 MAX_EHDR_LEN, -1 /* not initialized */ }, 215{ IPV6_DSTOPTS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, 216 (OP_PASSNEXT|OP_VARLEN|OP_NODEFAULT), 217 MAX_EHDR_LEN, -1 /* not initialized */ }, 218{ IPV6_RTHDRDSTOPTS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, 219 (OP_PASSNEXT|OP_VARLEN|OP_NODEFAULT), 220 MAX_EHDR_LEN, -1 /* not initialized */ }, 221{ IPV6_RTHDR, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, 222 (OP_PASSNEXT|OP_VARLEN|OP_NODEFAULT), 223 MAX_EHDR_LEN, -1 /* not initialized */ }, 224{ IPV6_TCLASS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, 225 (OP_PASSNEXT|OP_NODEFAULT), 226 sizeof (int), -1 /* not initialized */ }, 227{ IPV6_PATHMTU, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, 228 (OP_PASSNEXT|OP_NODEFAULT), 229 sizeof (int), -1 /* not initialized */ }, 230{ IPV6_DONTFRAG, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, 231 sizeof (int), 0 }, 232{ IPV6_USE_MIN_MTU, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, 233 sizeof (int), 0 }, 234{ IPV6_V6ONLY, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, 235 sizeof (int), 0 }, 236 237{ IPV6_RECVPKTINFO, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, 238 sizeof (int), 0 }, 239{ IPV6_RECVHOPLIMIT, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, 240 sizeof (int), 0 }, 241{ IPV6_RECVHOPOPTS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, 242 sizeof (int), 0 }, 243{ _OLD_IPV6_RECVDSTOPTS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, 244 sizeof (int), 0 }, 245{ IPV6_RECVDSTOPTS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, 246 sizeof (int), 0 }, 247{ IPV6_RECVRTHDR, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, 248 sizeof (int), 0 }, 249{ IPV6_RECVRTHDRDSTOPTS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, 250 sizeof (int), 0 }, 251{ IPV6_RECVPATHMTU, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, 252 OP_PASSNEXT, sizeof (int), 0 }, 253{ IPV6_RECVTCLASS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, 254 sizeof (int), 0 }, 255 256{ IPV6_SEC_OPT, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, (OP_PASSNEXT|OP_NODEFAULT), 257 sizeof (ipsec_req_t), -1 /* not initialized */ }, 258{ IPV6_SRC_PREFERENCES, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, 259 sizeof (uint32_t), IPV6_PREFER_SRC_DEFAULT }, 260 261{ MCAST_JOIN_GROUP, IPPROTO_IPV6, OA_X, OA_X, OP_NP, 262 (OP_PASSNEXT|OP_NODEFAULT), sizeof (struct group_req), 263 -1 /* not initialized */ }, 264{ MCAST_LEAVE_GROUP, IPPROTO_IPV6, OA_X, OA_X, OP_NP, 265 (OP_PASSNEXT|OP_NODEFAULT), sizeof (struct group_req), 266 -1 /* not initialized */ }, 267{ MCAST_BLOCK_SOURCE, IPPROTO_IPV6, OA_X, OA_X, OP_NP, 268 (OP_PASSNEXT|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_PASSNEXT|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_PASSNEXT|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_PASSNEXT|OP_NODEFAULT), sizeof (struct group_source_req), 278 -1 /* not initialized */ }, 279 280{ UDP_ANONPRIVBIND, IPPROTO_UDP, OA_R, OA_RW, OP_PRIVPORT, OP_PASSNEXT, 281 sizeof (int), 0 }, 282{ UDP_EXCLBIND, IPPROTO_UDP, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, 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 */ 298optlevel_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 309uint_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 319optdb_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 B_TRUE, /* UDP is tpi provider */ 324 UDP_OPT_ARR_CNT, /* UDP option database count of entries */ 325 udp_opt_arr, /* UDP option database */ 326 UDP_VALID_LEVELS_CNT, /* UDP valid level count of entries */ 327 udp_valid_levels_arr /* UDP valid level array */ 328}; 329