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, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. 8 * 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 * or http://www.opensolaris.org/os/licensing. 11 * See the License for the specific language governing permissions 12 * and limitations under the License. 13 * 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ 22 /* 23 * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 27 #pragma ident "%Z%%M% %I% %E% SMI" 28 29 #include <sys/types.h> 30 #include <sys/stream.h> 31 #define _SUN_TPI_VERSION 2 32 #include <sys/tihdr.h> 33 #include <sys/socket.h> 34 #include <sys/xti_xtiopt.h> 35 #include <sys/xti_inet.h> 36 37 #include <inet/common.h> 38 #include <netinet/ip6.h> 39 #include <inet/ip.h> 40 41 #include <netinet/in.h> 42 #include <netinet/tcp.h> 43 #include <netinet/ip_mroute.h> 44 #include <inet/optcom.h> 45 46 47 extern int tcp_opt_default(queue_t *q, int level, int name, uchar_t *ptr); 48 extern int tcp_opt_get(queue_t *q, int level, int name, uchar_t *ptr); 49 extern int tcp_opt_set(queue_t *q, uint_t optset_context, int level, 50 int name, uint_t inlen, uchar_t *invalp, uint_t *outlenp, uchar_t *outvalp, 51 void *thisdg_attrs, cred_t *cr, mblk_t *mblk); 52 53 /* 54 * Table of all known options handled on a TCP protocol stack. 55 * 56 * Note: This table contains options processed by both TCP and IP levels 57 * and is the superset of options that can be performed on a TCP over IP 58 * stack. 59 */ 60 opdes_t tcp_opt_arr[] = { 61 62 { SO_LINGER, SOL_SOCKET, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, 63 sizeof (struct linger), 0 }, 64 65 { SO_DEBUG, SOL_SOCKET, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, sizeof (int), 0 }, 66 { SO_KEEPALIVE, SOL_SOCKET, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, sizeof (int), 0 }, 67 { SO_DONTROUTE, SOL_SOCKET, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, sizeof (int), 0 }, 68 { SO_USELOOPBACK, SOL_SOCKET, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, sizeof (int), 0 69 }, 70 { SO_BROADCAST, SOL_SOCKET, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, sizeof (int), 0 }, 71 { SO_REUSEADDR, SOL_SOCKET, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, sizeof (int), 0 }, 72 { SO_OOBINLINE, SOL_SOCKET, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, sizeof (int), 0 }, 73 { SO_TYPE, SOL_SOCKET, OA_R, OA_R, OP_NP, OP_PASSNEXT, sizeof (int), 0 }, 74 { SO_SNDBUF, SOL_SOCKET, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, sizeof (int), 0 }, 75 { SO_RCVBUF, SOL_SOCKET, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, sizeof (int), 0 }, 76 { SO_DGRAM_ERRIND, SOL_SOCKET, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, sizeof (int), 0 77 }, 78 { SO_SND_COPYAVOID, SOL_SOCKET, OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0 }, 79 { TCP_NODELAY, IPPROTO_TCP, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, sizeof (int), 0 80 }, 81 { TCP_MAXSEG, IPPROTO_TCP, OA_R, OA_R, OP_NP, OP_PASSNEXT, sizeof (uint_t), 82 536 }, 83 84 { TCP_NOTIFY_THRESHOLD, IPPROTO_TCP, OA_RW, OA_RW, OP_NP, 85 (OP_PASSNEXT|OP_DEF_FN), sizeof (int), -1 /* not initialized */ }, 86 87 { TCP_ABORT_THRESHOLD, IPPROTO_TCP, OA_RW, OA_RW, OP_NP, 88 (OP_PASSNEXT|OP_DEF_FN), sizeof (int), -1 /* not initialized */ }, 89 90 { TCP_CONN_NOTIFY_THRESHOLD, IPPROTO_TCP, OA_RW, OA_RW, OP_NP, 91 (OP_PASSNEXT|OP_DEF_FN), sizeof (int), -1 /* not initialized */ }, 92 93 { TCP_CONN_ABORT_THRESHOLD, IPPROTO_TCP, OA_RW, OA_RW, OP_NP, 94 (OP_PASSNEXT|OP_DEF_FN), sizeof (int), -1 /* not initialized */ }, 95 96 { TCP_RECVDSTADDR, IPPROTO_TCP, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, sizeof (int), 97 0 }, 98 99 { TCP_ANONPRIVBIND, IPPROTO_TCP, OA_R, OA_RW, OP_PRIVPORT, OP_PASSNEXT, 100 sizeof (int), 0 }, 101 102 { TCP_EXCLBIND, IPPROTO_TCP, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, sizeof (int), 0 103 }, 104 105 { TCP_INIT_CWND, IPPROTO_TCP, OA_RW, OA_RW, OP_CONFIG, OP_PASSNEXT, 106 sizeof (int), 0 }, 107 108 { TCP_KEEPALIVE_THRESHOLD, IPPROTO_TCP, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, 109 sizeof (int), 0 }, 110 111 { TCP_KEEPALIVE_ABORT_THRESHOLD, IPPROTO_TCP, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, 112 sizeof (int), 0 }, 113 114 { TCP_CORK, IPPROTO_TCP, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, sizeof (int), 0 }, 115 116 { IP_OPTIONS, IPPROTO_IP, OA_RW, OA_RW, OP_NP, 117 (OP_PASSNEXT|OP_VARLEN|OP_NODEFAULT), 118 40, -1 /* not initialized */ }, 119 { T_IP_OPTIONS, IPPROTO_IP, OA_RW, OA_RW, OP_NP, 120 (OP_PASSNEXT|OP_VARLEN|OP_NODEFAULT), 121 40, -1 /* not initialized */ }, 122 123 { IP_TOS, IPPROTO_IP, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, sizeof (int), 0 }, 124 { T_IP_TOS, IPPROTO_IP, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, sizeof (int), 0 }, 125 { IP_TTL, IPPROTO_IP, OA_RW, OA_RW, OP_NP, (OP_PASSNEXT|OP_DEF_FN), 126 sizeof (int), -1 /* not initialized */ }, 127 128 { IP_SEC_OPT, IPPROTO_IP, OA_RW, OA_RW, OP_NP, (OP_PASSNEXT|OP_NODEFAULT), 129 sizeof (ipsec_req_t), -1 /* not initialized */ }, 130 131 { IP_BOUND_IF, IPPROTO_IP, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, 132 sizeof (int), 0 /* no ifindex */ }, 133 134 { IP_UNSPEC_SRC, IPPROTO_IP, OA_R, OA_RW, OP_RAW, OP_PASSNEXT, 135 sizeof (int), 0 }, 136 137 { IPV6_UNICAST_HOPS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, (OP_PASSNEXT|OP_DEF_FN), 138 sizeof (int), -1 /* not initialized */ }, 139 140 { IPV6_BOUND_IF, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, 141 sizeof (int), 0 /* no ifindex */ }, 142 143 { IPV6_BOUND_PIF, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, 144 sizeof (int), 0 /* no ifindex */ }, 145 146 { IPV6_UNSPEC_SRC, IPPROTO_IPV6, OA_R, OA_RW, OP_RAW, OP_PASSNEXT, 147 sizeof (int), 0 }, 148 149 { IPV6_PKTINFO, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, 150 (OP_PASSNEXT|OP_NODEFAULT|OP_VARLEN), 151 sizeof (struct in6_pktinfo), -1 /* not initialized */ }, 152 { IPV6_NEXTHOP, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, 153 (OP_PASSNEXT|OP_NODEFAULT), 154 sizeof (sin6_t), -1 /* not initialized */ }, 155 { IPV6_HOPOPTS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, 156 (OP_PASSNEXT|OP_VARLEN|OP_NODEFAULT), 255*8, 157 -1 /* not initialized */ }, 158 { IPV6_DSTOPTS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, 159 (OP_PASSNEXT|OP_VARLEN|OP_NODEFAULT), 255*8, 160 -1 /* not initialized */ }, 161 { IPV6_RTHDRDSTOPTS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, 162 (OP_PASSNEXT|OP_VARLEN|OP_NODEFAULT), 255*8, 163 -1 /* not initialized */ }, 164 { IPV6_RTHDR, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, 165 (OP_PASSNEXT|OP_VARLEN|OP_NODEFAULT), 255*8, 166 -1 /* not initialized */ }, 167 { IPV6_TCLASS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, 168 (OP_PASSNEXT|OP_NODEFAULT), 169 sizeof (int), -1 /* not initialized */ }, 170 { IPV6_PATHMTU, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, 171 (OP_PASSNEXT|OP_NODEFAULT), 172 sizeof (struct ip6_mtuinfo), -1 /* not initialized */ }, 173 { IPV6_USE_MIN_MTU, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, 174 sizeof (int), 0 }, 175 { IPV6_V6ONLY, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, 176 sizeof (int), 0 }, 177 178 /* Enable receipt of ancillary data */ 179 { IPV6_RECVPKTINFO, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, 180 sizeof (int), 0 }, 181 { IPV6_RECVHOPLIMIT, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, 182 sizeof (int), 0 }, 183 { IPV6_RECVHOPOPTS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, 184 sizeof (int), 0 }, 185 { _OLD_IPV6_RECVDSTOPTS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, 186 sizeof (int), 0 }, 187 { IPV6_RECVDSTOPTS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, 188 sizeof (int), 0 }, 189 { IPV6_RECVRTHDR, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, 190 sizeof (int), 0 }, 191 { IPV6_RECVRTHDRDSTOPTS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, 192 sizeof (int), 0 }, 193 { IPV6_RECVTCLASS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, 194 sizeof (int), 0 }, 195 196 { IPV6_SEC_OPT, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, (OP_PASSNEXT|OP_NODEFAULT), 197 sizeof (ipsec_req_t), -1 /* not initialized */ }, 198 { IPV6_SRC_PREFERENCES, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, 199 sizeof (uint32_t), IPV6_PREFER_SRC_DEFAULT }, 200 }; 201 202 /* 203 * Table of all supported levels 204 * Note: Some levels (e.g. XTI_GENERIC) may be valid but may not have 205 * any supported options so we need this info separately. 206 * 207 * This is needed only for topmost tpi providers and is used only by 208 * XTI interfaces. 209 */ 210 optlevel_t tcp_valid_levels_arr[] = { 211 XTI_GENERIC, 212 SOL_SOCKET, 213 IPPROTO_TCP, 214 IPPROTO_IP, 215 IPPROTO_IPV6 216 }; 217 218 219 #define TCP_OPT_ARR_CNT A_CNT(tcp_opt_arr) 220 #define TCP_VALID_LEVELS_CNT A_CNT(tcp_valid_levels_arr) 221 222 uint_t tcp_max_optsize; /* initialized when TCP driver is loaded */ 223 224 /* 225 * Initialize option database object for TCP 226 * 227 * This object represents database of options to search passed to 228 * {sock,tpi}optcom_req() interface routine to take care of option 229 * management and associated methods. 230 */ 231 232 optdb_obj_t tcp_opt_obj = { 233 tcp_opt_default, /* TCP default value function pointer */ 234 tcp_opt_get, /* TCP get function pointer */ 235 tcp_opt_set, /* TCP set function pointer */ 236 B_TRUE, /* TCP is tpi provider */ 237 TCP_OPT_ARR_CNT, /* TCP option database count of entries */ 238 tcp_opt_arr, /* TCP option database */ 239 TCP_VALID_LEVELS_CNT, /* TCP valid level count of entries */ 240 tcp_valid_levels_arr /* TCP valid level array */ 241 }; 242