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 /*
  23  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
  24  * Use is subject to license terms.
  25  */
  26 
  27 /*
  28  * Copyright 2012 David Hoeppner.  All rights reserved.
  29  */
  30 
  31 /*
  32  * This file contains functions related to getting and setting options
  33  * thought the getsockopt and setsockopt socket functions.
  34  */
  35 
  36 #include <sys/types.h>
  37 #include <sys/stream.h>
  38 #define _SUN_TPI_VERSION 2
  39 #include <sys/tihdr.h>
  40 #include <sys/xti_xtiopt.h>
  41 #include <sys/xti_inet.h>
  42 #include <sys/policy.h>
  43 
  44 #include <inet/common.h>
  45 #include <inet/dccp_impl.h>
  46 #include <inet/ip.h>
  47 #include <inet/optcom.h>
  48 #include <netinet/ip.h>
  49 
  50 #include <sys/cmn_err.h>
  51 
  52 static int dccp_opt_default(queue_t *, int, int, uchar_t *);
  53 
  54 /*
  55  * Supported options.
  56  */
  57 opdes_t dccp_opt_arr[] = {
  58 { SO_DEBUG, SOL_SOCKET, OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0 },
  59 }; 
  60 
  61 /*
  62  * Supported levels.
  63  */
  64 optlevel_t dccp_valid_levels_arr[] = {
  65         SOL_SOCKET,
  66 };
  67 
  68 #define DCCP_OPT_ARR_CNT        A_CNT(dccp_opt_arr)
  69 #define DCCP_VALID_LEVELS_CNT   A_CNT(dccp_valid_levels_arr)
  70 
  71 uint_t dccp_max_optsize;
  72 
  73 /*
  74  * Options database object.
  75  */
  76 optdb_obj_t dccp_opt_obj = {
  77         dccp_opt_default,
  78         dccp_tpi_opt_get,
  79         dccp_tpi_opt_set,
  80         DCCP_OPT_ARR_CNT,
  81         dccp_opt_arr,
  82         DCCP_VALID_LEVELS_CNT,
  83         dccp_valid_levels_arr,
  84 };
  85 
  86 /*
  87  * Default value for certain options.
  88  */
  89 int
  90 dccp_opt_default(queue_t *q, int level, int name, uchar_t *ptr)
  91 {
  92         dccp_stack_t    *dccps = Q_TO_DCCP(q)->dccp_dccps;
  93         int32_t         *il = (int32_t *)ptr;
  94 
  95         return (sizeof (int));
  96 }
  97 
  98 int
  99 dccp_opt_get(conn_t *connp, int level, int name, uchar_t *ptr)
 100 {
 101         dccp_t          *dccp = connp->conn_dccp;
 102         conn_opt_arg_t  coas;
 103         int             retval;
 104 
 105         coas.coa_connp = connp;
 106         coas.coa_ixa = connp->conn_ixa;
 107         coas.coa_ipp = &connp->conn_xmit_ipp;
 108         coas.coa_ancillary = B_FALSE;
 109         coas.coa_changed = 0;
 110 
 111         switch (level) {
 112         case SOL_SOCKET:
 113                 break;
 114         case IPPROTO_TCP:
 115                 break;
 116         case IPPROTO_IP:
 117                 break;
 118         case IPPROTO_IPV6:
 119                 break;
 120         }
 121 
 122         mutex_enter(&connp->conn_lock);
 123         retval = conn_opt_get(&coas, level, name, ptr);
 124         mutex_exit(&connp->conn_lock);
 125 
 126         return (retval);
 127 }
 128 
 129 /* ARGSUSED */
 130 int
 131 dccp_opt_set(conn_t *connp, uint_t optset_context, int level, int name,
 132     uint_t inlen, uchar_t *invalp, uint_t *outlenp, uchar_t *outvalp,
 133     void *thisdg_attrs, cred_t *cr)
 134 {
 135         dccp_t          *dccp = connp->conn_dccp;
 136         dccp_stack_t    *dccps = dccp->dccp_dccps;
 137         conn_opt_arg_t  coas;
 138         int             *i1 = (int *)invalp;
 139         int             error;
 140 
 141         coas.coa_connp = connp;
 142         coas.coa_ancillary = B_FALSE;
 143         coas.coa_changed = 0;
 144 
 145         error = conn_opt_set(&coas, level, name, inlen, invalp,
 146             B_FALSE, cr);
 147         if (error !=0) {
 148                 *outlenp = 0;
 149                 return (error);
 150         }
 151 
 152         return (0);
 153 }