Print this page
13175 Add support for IP_RECVTOS
13182 CMSG_ macros should have man pages
Change-ID: I784aa36cfd3c17e3cccbf1fd329fa7e69b663ef9


   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 (c) 2010, Oracle and/or its affiliates. All rights reserved.
  23  * Copyright (c) 2011 Nexenta Systems, Inc. All rights reserved.
  24  * Copyright 2019 Joyent, Inc.
  25  * Copyright (c) 2016 by Delphix. All rights reserved.

  26  */
  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 #include <sys/policy.h>
  36 
  37 #include <inet/cc.h>
  38 #include <inet/common.h>
  39 #include <netinet/ip6.h>
  40 #include <inet/ip.h>
  41 
  42 #include <netinet/in.h>
  43 #include <netinet/tcp.h>
  44 #include <inet/optcom.h>
  45 #include <inet/proto_set.h>


 139 { TCP_RTO_MIN, IPPROTO_TCP, OA_RW, OA_RW, OP_NP, 0, sizeof (uint32_t), 0 },
 140 
 141 { TCP_RTO_MAX, IPPROTO_TCP, OA_RW, OA_RW, OP_NP, 0, sizeof (uint32_t), 0 },
 142 
 143 { TCP_LINGER2, IPPROTO_TCP, OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0 },
 144 
 145 { TCP_CONGESTION, IPPROTO_TCP, OA_RW, OA_RW, OP_NP,
 146         OP_VARLEN, CC_ALGO_NAME_MAX, 0 },
 147 
 148 { IP_OPTIONS,   IPPROTO_IP, OA_RW, OA_RW, OP_NP,
 149         (OP_VARLEN|OP_NODEFAULT),
 150         IP_MAX_OPT_LENGTH + IP_ADDR_LEN, -1 /* not initialized */ },
 151 { T_IP_OPTIONS, IPPROTO_IP, OA_RW, OA_RW, OP_NP,
 152         (OP_VARLEN|OP_NODEFAULT),
 153         IP_MAX_OPT_LENGTH + IP_ADDR_LEN, -1 /* not initialized */ },
 154 
 155 { IP_TOS,       IPPROTO_IP, OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0 },
 156 { T_IP_TOS,     IPPROTO_IP, OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0 },
 157 { IP_TTL,       IPPROTO_IP, OA_RW, OA_RW, OP_NP, OP_DEF_FN,
 158         sizeof (int), -1 /* not initialized */ },

 159 
 160 { IP_SEC_OPT, IPPROTO_IP, OA_RW, OA_RW, OP_NP, OP_NODEFAULT,
 161         sizeof (ipsec_req_t), -1 /* not initialized */ },
 162 
 163 { IP_BOUND_IF, IPPROTO_IP, OA_RW, OA_RW, OP_NP, 0,
 164         sizeof (int),   0 /* no ifindex */ },
 165 
 166 { IP_UNSPEC_SRC, IPPROTO_IP, OA_R, OA_RW, OP_RAW, 0,
 167         sizeof (int), 0 },
 168 
 169 { IPV6_UNICAST_HOPS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_DEF_FN,
 170         sizeof (int), -1 /* not initialized */ },
 171 
 172 { IPV6_BOUND_IF, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, 0,
 173         sizeof (int),   0 /* no ifindex */ },
 174 
 175 { IP_DONTFRAG, IPPROTO_IP, OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0 },
 176 
 177 { IP_NEXTHOP, IPPROTO_IP, OA_R, OA_RW, OP_CONFIG, 0,
 178         sizeof (in_addr_t),     -1 /* not initialized  */ },


1015                         break;
1016                 default:
1017                         break;
1018                 }
1019                 break;
1020         case IPPROTO_IP:
1021                 if (connp->conn_family != AF_INET) {
1022                         *outlenp = 0;
1023                         return (EINVAL);
1024                 }
1025                 switch (name) {
1026                 case IP_SEC_OPT:
1027                         /*
1028                          * We should not allow policy setting after
1029                          * we start listening for connections.
1030                          */
1031                         if (tcp->tcp_state == TCPS_LISTEN) {
1032                                 return (EINVAL);
1033                         }
1034                         break;










1035                 }
1036                 break;
1037         case IPPROTO_IPV6:
1038                 /*
1039                  * IPPROTO_IPV6 options are only supported for sockets
1040                  * that are using IPv6 on the wire.
1041                  */
1042                 if (connp->conn_ipversion != IPV6_VERSION) {
1043                         *outlenp = 0;
1044                         return (EINVAL);
1045                 }
1046 
1047                 switch (name) {
1048                 case IPV6_RECVPKTINFO:
1049                         if (!checkonly) {
1050                                 /* Force it to be sent up with the next msg */
1051                                 tcp->tcp_recvifindex = 0;
1052                         }
1053                         break;
1054                 case IPV6_RECVTCLASS:




   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 (c) 2010, Oracle and/or its affiliates. All rights reserved.
  23  * Copyright (c) 2011 Nexenta Systems, Inc. All rights reserved.
  24  * Copyright 2019 Joyent, Inc.
  25  * Copyright (c) 2016 by Delphix. All rights reserved.
  26  * Copyright 2020 OmniOS Community Edition (OmniOSce) Association.
  27  */
  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 #include <sys/policy.h>
  37 
  38 #include <inet/cc.h>
  39 #include <inet/common.h>
  40 #include <netinet/ip6.h>
  41 #include <inet/ip.h>
  42 
  43 #include <netinet/in.h>
  44 #include <netinet/tcp.h>
  45 #include <inet/optcom.h>
  46 #include <inet/proto_set.h>


 140 { TCP_RTO_MIN, IPPROTO_TCP, OA_RW, OA_RW, OP_NP, 0, sizeof (uint32_t), 0 },
 141 
 142 { TCP_RTO_MAX, IPPROTO_TCP, OA_RW, OA_RW, OP_NP, 0, sizeof (uint32_t), 0 },
 143 
 144 { TCP_LINGER2, IPPROTO_TCP, OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0 },
 145 
 146 { TCP_CONGESTION, IPPROTO_TCP, OA_RW, OA_RW, OP_NP,
 147         OP_VARLEN, CC_ALGO_NAME_MAX, 0 },
 148 
 149 { IP_OPTIONS,   IPPROTO_IP, OA_RW, OA_RW, OP_NP,
 150         (OP_VARLEN|OP_NODEFAULT),
 151         IP_MAX_OPT_LENGTH + IP_ADDR_LEN, -1 /* not initialized */ },
 152 { T_IP_OPTIONS, IPPROTO_IP, OA_RW, OA_RW, OP_NP,
 153         (OP_VARLEN|OP_NODEFAULT),
 154         IP_MAX_OPT_LENGTH + IP_ADDR_LEN, -1 /* not initialized */ },
 155 
 156 { IP_TOS,       IPPROTO_IP, OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0 },
 157 { T_IP_TOS,     IPPROTO_IP, OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0 },
 158 { IP_TTL,       IPPROTO_IP, OA_RW, OA_RW, OP_NP, OP_DEF_FN,
 159         sizeof (int), -1 /* not initialized */ },
 160 { IP_RECVTOS,   IPPROTO_IP,  OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0 },
 161 
 162 { IP_SEC_OPT, IPPROTO_IP, OA_RW, OA_RW, OP_NP, OP_NODEFAULT,
 163         sizeof (ipsec_req_t), -1 /* not initialized */ },
 164 
 165 { IP_BOUND_IF, IPPROTO_IP, OA_RW, OA_RW, OP_NP, 0,
 166         sizeof (int),   0 /* no ifindex */ },
 167 
 168 { IP_UNSPEC_SRC, IPPROTO_IP, OA_R, OA_RW, OP_RAW, 0,
 169         sizeof (int), 0 },
 170 
 171 { IPV6_UNICAST_HOPS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_DEF_FN,
 172         sizeof (int), -1 /* not initialized */ },
 173 
 174 { IPV6_BOUND_IF, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, 0,
 175         sizeof (int),   0 /* no ifindex */ },
 176 
 177 { IP_DONTFRAG, IPPROTO_IP, OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0 },
 178 
 179 { IP_NEXTHOP, IPPROTO_IP, OA_R, OA_RW, OP_CONFIG, 0,
 180         sizeof (in_addr_t),     -1 /* not initialized  */ },


1017                         break;
1018                 default:
1019                         break;
1020                 }
1021                 break;
1022         case IPPROTO_IP:
1023                 if (connp->conn_family != AF_INET) {
1024                         *outlenp = 0;
1025                         return (EINVAL);
1026                 }
1027                 switch (name) {
1028                 case IP_SEC_OPT:
1029                         /*
1030                          * We should not allow policy setting after
1031                          * we start listening for connections.
1032                          */
1033                         if (tcp->tcp_state == TCPS_LISTEN) {
1034                                 return (EINVAL);
1035                         }
1036                         break;
1037                 case IP_RECVTOS:
1038                         if (!checkonly) {
1039                                 /*
1040                                  * Force it to be sent up with the next msg
1041                                  * by setting it to a value which cannot
1042                                  * appear in a packet (TOS is only 8-bits)
1043                                  */
1044                                 tcp->tcp_recvtos = 0xffffffffU;
1045                         }
1046                         break;
1047                 }
1048                 break;
1049         case IPPROTO_IPV6:
1050                 /*
1051                  * IPPROTO_IPV6 options are only supported for sockets
1052                  * that are using IPv6 on the wire.
1053                  */
1054                 if (connp->conn_ipversion != IPV6_VERSION) {
1055                         *outlenp = 0;
1056                         return (EINVAL);
1057                 }
1058 
1059                 switch (name) {
1060                 case IPV6_RECVPKTINFO:
1061                         if (!checkonly) {
1062                                 /* Force it to be sent up with the next msg */
1063                                 tcp->tcp_recvifindex = 0;
1064                         }
1065                         break;
1066                 case IPV6_RECVTCLASS: