1*0Sstevel@tonic-gate /* 2*0Sstevel@tonic-gate * CDDL HEADER START 3*0Sstevel@tonic-gate * 4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*0Sstevel@tonic-gate * with the License. 8*0Sstevel@tonic-gate * 9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*0Sstevel@tonic-gate * See the License for the specific language governing permissions 12*0Sstevel@tonic-gate * and limitations under the License. 13*0Sstevel@tonic-gate * 14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*0Sstevel@tonic-gate * 20*0Sstevel@tonic-gate * CDDL HEADER END 21*0Sstevel@tonic-gate */ 22*0Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 23*0Sstevel@tonic-gate /* All Rights Reserved */ 24*0Sstevel@tonic-gate 25*0Sstevel@tonic-gate 26*0Sstevel@tonic-gate /* 27*0Sstevel@tonic-gate * Copyright 1993-2003 Sun Microsystems, Inc. All rights reserved. 28*0Sstevel@tonic-gate * Use is subject to license terms. 29*0Sstevel@tonic-gate */ 30*0Sstevel@tonic-gate 31*0Sstevel@tonic-gate 32*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.5 */ 33*0Sstevel@tonic-gate 34*0Sstevel@tonic-gate /* 35*0Sstevel@tonic-gate * t_sndudata.c and t_sndvudata.c are very similar and contain common code. 36*0Sstevel@tonic-gate * Any changes to either of them should be reviewed to see whether they 37*0Sstevel@tonic-gate * are applicable to the other file. 38*0Sstevel@tonic-gate */ 39*0Sstevel@tonic-gate #include "mt.h" 40*0Sstevel@tonic-gate #include <rpc/trace.h> 41*0Sstevel@tonic-gate #include <stdlib.h> 42*0Sstevel@tonic-gate #include <errno.h> 43*0Sstevel@tonic-gate #include <stropts.h> 44*0Sstevel@tonic-gate #include <sys/stream.h> 45*0Sstevel@tonic-gate #define _SUN_TPI_VERSION 2 46*0Sstevel@tonic-gate #include <sys/tihdr.h> 47*0Sstevel@tonic-gate #include <sys/timod.h> 48*0Sstevel@tonic-gate #include <xti.h> 49*0Sstevel@tonic-gate #include <syslog.h> 50*0Sstevel@tonic-gate #include "tx.h" 51*0Sstevel@tonic-gate 52*0Sstevel@tonic-gate int 53*0Sstevel@tonic-gate _tx_sndudata(int fd, const struct t_unitdata *unitdata, int api_semantics) 54*0Sstevel@tonic-gate { 55*0Sstevel@tonic-gate struct T_unitdata_req *udreq; 56*0Sstevel@tonic-gate struct strbuf ctlbuf; 57*0Sstevel@tonic-gate int size; 58*0Sstevel@tonic-gate struct _ti_user *tiptr; 59*0Sstevel@tonic-gate int sv_errno; 60*0Sstevel@tonic-gate int didalloc; 61*0Sstevel@tonic-gate 62*0Sstevel@tonic-gate trace2(TR_t_sndudata, 0, fd); 63*0Sstevel@tonic-gate if ((tiptr = _t_checkfd(fd, 0, api_semantics)) == NULL) { 64*0Sstevel@tonic-gate sv_errno = errno; 65*0Sstevel@tonic-gate trace2(TR_t_sndudata, 1, fd); 66*0Sstevel@tonic-gate errno = sv_errno; 67*0Sstevel@tonic-gate return (-1); 68*0Sstevel@tonic-gate } 69*0Sstevel@tonic-gate sig_mutex_lock(&tiptr->ti_lock); 70*0Sstevel@tonic-gate 71*0Sstevel@tonic-gate if (tiptr->ti_servtype != T_CLTS) { 72*0Sstevel@tonic-gate t_errno = TNOTSUPPORT; 73*0Sstevel@tonic-gate sig_mutex_unlock(&tiptr->ti_lock); 74*0Sstevel@tonic-gate trace2(TR_t_sndudata, 1, fd); 75*0Sstevel@tonic-gate return (-1); 76*0Sstevel@tonic-gate } 77*0Sstevel@tonic-gate 78*0Sstevel@tonic-gate if (_T_IS_XTI(api_semantics)) { 79*0Sstevel@tonic-gate /* 80*0Sstevel@tonic-gate * User level state verification only done for XTI 81*0Sstevel@tonic-gate * because doing for TLI may break existing applications 82*0Sstevel@tonic-gate */ 83*0Sstevel@tonic-gate if (tiptr->ti_state != T_IDLE) { 84*0Sstevel@tonic-gate t_errno = TOUTSTATE; 85*0Sstevel@tonic-gate sig_mutex_unlock(&tiptr->ti_lock); 86*0Sstevel@tonic-gate trace2(TR_t_sndudata, 1, fd); 87*0Sstevel@tonic-gate return (-1); 88*0Sstevel@tonic-gate } 89*0Sstevel@tonic-gate } 90*0Sstevel@tonic-gate 91*0Sstevel@tonic-gate if (((int)unitdata->udata.len == 0) && 92*0Sstevel@tonic-gate !(tiptr->ti_prov_flag & (SENDZERO|OLD_SENDZERO))) { 93*0Sstevel@tonic-gate t_errno = TBADDATA; 94*0Sstevel@tonic-gate sig_mutex_unlock(&tiptr->ti_lock); 95*0Sstevel@tonic-gate trace2(TR_t_sndudata, 1, fd); 96*0Sstevel@tonic-gate return (-1); 97*0Sstevel@tonic-gate } 98*0Sstevel@tonic-gate 99*0Sstevel@tonic-gate if ((tiptr->ti_maxpsz > 0) && 100*0Sstevel@tonic-gate (unitdata->udata.len > (uint32_t)tiptr->ti_maxpsz)) { 101*0Sstevel@tonic-gate if (_T_IS_TLI(api_semantics)) { 102*0Sstevel@tonic-gate t_errno = TSYSERR; 103*0Sstevel@tonic-gate errno = EPROTO; 104*0Sstevel@tonic-gate } else 105*0Sstevel@tonic-gate t_errno = TBADDATA; 106*0Sstevel@tonic-gate sv_errno = errno; 107*0Sstevel@tonic-gate sig_mutex_unlock(&tiptr->ti_lock); 108*0Sstevel@tonic-gate trace2(TR_t_sndudata, 1, fd); 109*0Sstevel@tonic-gate errno = sv_errno; 110*0Sstevel@tonic-gate return (-1); 111*0Sstevel@tonic-gate } 112*0Sstevel@tonic-gate 113*0Sstevel@tonic-gate /* 114*0Sstevel@tonic-gate * Acquire ctlbuf for use in sending/receiving control part 115*0Sstevel@tonic-gate * of the message. 116*0Sstevel@tonic-gate */ 117*0Sstevel@tonic-gate if (_t_acquire_ctlbuf(tiptr, &ctlbuf, &didalloc) < 0) { 118*0Sstevel@tonic-gate sv_errno = errno; 119*0Sstevel@tonic-gate sig_mutex_unlock(&tiptr->ti_lock); 120*0Sstevel@tonic-gate trace2(TR_t_sndudata, 1, fd); 121*0Sstevel@tonic-gate errno = sv_errno; 122*0Sstevel@tonic-gate return (-1); 123*0Sstevel@tonic-gate } 124*0Sstevel@tonic-gate 125*0Sstevel@tonic-gate udreq = (struct T_unitdata_req *)ctlbuf.buf; 126*0Sstevel@tonic-gate 127*0Sstevel@tonic-gate udreq->PRIM_type = T_UNITDATA_REQ; 128*0Sstevel@tonic-gate udreq->DEST_length = unitdata->addr.len; 129*0Sstevel@tonic-gate udreq->DEST_offset = 0; 130*0Sstevel@tonic-gate udreq->OPT_length = unitdata->opt.len; 131*0Sstevel@tonic-gate udreq->OPT_offset = 0; 132*0Sstevel@tonic-gate size = (int)sizeof (struct T_unitdata_req); 133*0Sstevel@tonic-gate 134*0Sstevel@tonic-gate if (unitdata->addr.len) { 135*0Sstevel@tonic-gate if (_t_aligned_copy(&ctlbuf, unitdata->addr.len, size, 136*0Sstevel@tonic-gate unitdata->addr.buf, &udreq->DEST_offset) < 0) { 137*0Sstevel@tonic-gate /* 138*0Sstevel@tonic-gate * Aligned copy based will overflow buffer 139*0Sstevel@tonic-gate * allocated based on maximum transport address 140*0Sstevel@tonic-gate * size information 141*0Sstevel@tonic-gate */ 142*0Sstevel@tonic-gate t_errno = TSYSERR; 143*0Sstevel@tonic-gate errno = EPROTO; 144*0Sstevel@tonic-gate goto err_out; 145*0Sstevel@tonic-gate } 146*0Sstevel@tonic-gate size = udreq->DEST_offset + udreq->DEST_length; 147*0Sstevel@tonic-gate } 148*0Sstevel@tonic-gate if (unitdata->opt.len) { 149*0Sstevel@tonic-gate if (_t_aligned_copy(&ctlbuf, unitdata->opt.len, size, 150*0Sstevel@tonic-gate unitdata->opt.buf, &udreq->OPT_offset) < 0) { 151*0Sstevel@tonic-gate /* 152*0Sstevel@tonic-gate * Aligned copy based will overflow buffer 153*0Sstevel@tonic-gate * allocated based on maximum transport option 154*0Sstevel@tonic-gate * size information 155*0Sstevel@tonic-gate */ 156*0Sstevel@tonic-gate t_errno = TSYSERR; 157*0Sstevel@tonic-gate errno = EPROTO; 158*0Sstevel@tonic-gate goto err_out; 159*0Sstevel@tonic-gate } 160*0Sstevel@tonic-gate size = udreq->OPT_offset + udreq->OPT_length; 161*0Sstevel@tonic-gate } 162*0Sstevel@tonic-gate 163*0Sstevel@tonic-gate if (size > (int)ctlbuf.maxlen) { 164*0Sstevel@tonic-gate t_errno = TSYSERR; 165*0Sstevel@tonic-gate errno = EIO; 166*0Sstevel@tonic-gate goto err_out; 167*0Sstevel@tonic-gate } 168*0Sstevel@tonic-gate 169*0Sstevel@tonic-gate ctlbuf.len = size; 170*0Sstevel@tonic-gate 171*0Sstevel@tonic-gate /* 172*0Sstevel@tonic-gate * Calls to send data (write or putmsg) can potentially 173*0Sstevel@tonic-gate * block, for MT case, we drop the lock and enable signals here 174*0Sstevel@tonic-gate * and acquire it back. 175*0Sstevel@tonic-gate * At this point, we are sure SENDZERO is supported and the 176*0Sstevel@tonic-gate * putmsg below may send a zero length message, 177*0Sstevel@tonic-gate * (i.e with valid control part, but zero data part) 178*0Sstevel@tonic-gate */ 179*0Sstevel@tonic-gate sig_mutex_unlock(&tiptr->ti_lock); 180*0Sstevel@tonic-gate if (putmsg(fd, &ctlbuf, (struct strbuf *)&unitdata->udata, 0) < 0) { 181*0Sstevel@tonic-gate if (errno == EAGAIN) 182*0Sstevel@tonic-gate t_errno = TFLOW; 183*0Sstevel@tonic-gate else 184*0Sstevel@tonic-gate t_errno = TSYSERR; 185*0Sstevel@tonic-gate sv_errno = errno; 186*0Sstevel@tonic-gate sig_mutex_lock(&tiptr->ti_lock); 187*0Sstevel@tonic-gate errno = sv_errno; 188*0Sstevel@tonic-gate goto err_out; 189*0Sstevel@tonic-gate } 190*0Sstevel@tonic-gate sig_mutex_lock(&tiptr->ti_lock); 191*0Sstevel@tonic-gate 192*0Sstevel@tonic-gate _T_TX_NEXTSTATE(T_SNDUDATA, tiptr, 193*0Sstevel@tonic-gate "t_sndudata: invalid state event T_SNDUDATA"); 194*0Sstevel@tonic-gate if (didalloc) 195*0Sstevel@tonic-gate free(ctlbuf.buf); 196*0Sstevel@tonic-gate else 197*0Sstevel@tonic-gate tiptr->ti_ctlbuf = ctlbuf.buf; 198*0Sstevel@tonic-gate sig_mutex_unlock(&tiptr->ti_lock); 199*0Sstevel@tonic-gate trace2(TR_t_sndudata, 1, fd); 200*0Sstevel@tonic-gate return (0); 201*0Sstevel@tonic-gate err_out: 202*0Sstevel@tonic-gate sv_errno = errno; 203*0Sstevel@tonic-gate if (didalloc) 204*0Sstevel@tonic-gate free(ctlbuf.buf); 205*0Sstevel@tonic-gate else 206*0Sstevel@tonic-gate tiptr->ti_ctlbuf = ctlbuf.buf; 207*0Sstevel@tonic-gate sig_mutex_unlock(&tiptr->ti_lock); 208*0Sstevel@tonic-gate trace2(TR_t_sndudata, 1, fd); 209*0Sstevel@tonic-gate errno = sv_errno; 210*0Sstevel@tonic-gate return (-1); 211*0Sstevel@tonic-gate } 212