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.4.3.1 */ 33*0Sstevel@tonic-gate 34*0Sstevel@tonic-gate #include "mt.h" 35*0Sstevel@tonic-gate #include <rpc/trace.h> 36*0Sstevel@tonic-gate #include <errno.h> 37*0Sstevel@tonic-gate #include <unistd.h> 38*0Sstevel@tonic-gate #include <stropts.h> 39*0Sstevel@tonic-gate #include <sys/stream.h> 40*0Sstevel@tonic-gate #define _SUN_TPI_VERSION 2 41*0Sstevel@tonic-gate #include <sys/tihdr.h> 42*0Sstevel@tonic-gate #include <sys/timod.h> 43*0Sstevel@tonic-gate #include <xti.h> 44*0Sstevel@tonic-gate #include <signal.h> 45*0Sstevel@tonic-gate #include <syslog.h> 46*0Sstevel@tonic-gate #include "tx.h" 47*0Sstevel@tonic-gate 48*0Sstevel@tonic-gate int 49*0Sstevel@tonic-gate _tx_snddis(int fd, const struct t_call *call, int api_semantics) 50*0Sstevel@tonic-gate { 51*0Sstevel@tonic-gate struct T_discon_req dreq; 52*0Sstevel@tonic-gate struct strbuf ctlbuf; 53*0Sstevel@tonic-gate struct strbuf databuf; 54*0Sstevel@tonic-gate struct _ti_user *tiptr; 55*0Sstevel@tonic-gate int sv_errno; 56*0Sstevel@tonic-gate int retval; 57*0Sstevel@tonic-gate 58*0Sstevel@tonic-gate trace2(TR_t_snddis, 0, fd); 59*0Sstevel@tonic-gate if ((tiptr = _t_checkfd(fd, 0, api_semantics)) == NULL) { 60*0Sstevel@tonic-gate sv_errno = errno; 61*0Sstevel@tonic-gate trace2(TR_t_snddis, 1, fd); 62*0Sstevel@tonic-gate errno = sv_errno; 63*0Sstevel@tonic-gate return (-1); 64*0Sstevel@tonic-gate } 65*0Sstevel@tonic-gate sig_mutex_lock(&tiptr->ti_lock); 66*0Sstevel@tonic-gate 67*0Sstevel@tonic-gate if (tiptr->ti_servtype == T_CLTS) { 68*0Sstevel@tonic-gate t_errno = TNOTSUPPORT; 69*0Sstevel@tonic-gate sig_mutex_unlock(&tiptr->ti_lock); 70*0Sstevel@tonic-gate trace2(TR_t_snddis, 1, fd); 71*0Sstevel@tonic-gate return (-1); 72*0Sstevel@tonic-gate } 73*0Sstevel@tonic-gate 74*0Sstevel@tonic-gate if (_T_IS_XTI(api_semantics)) { 75*0Sstevel@tonic-gate /* 76*0Sstevel@tonic-gate * User level state verification only done for XTI 77*0Sstevel@tonic-gate * because doing for TLI may break existing applications 78*0Sstevel@tonic-gate * Note: This is documented in TLI man page but never 79*0Sstevel@tonic-gate * done. 80*0Sstevel@tonic-gate */ 81*0Sstevel@tonic-gate if (! (tiptr->ti_state == T_DATAXFER || 82*0Sstevel@tonic-gate tiptr->ti_state == T_OUTCON || 83*0Sstevel@tonic-gate tiptr->ti_state == T_OUTREL || 84*0Sstevel@tonic-gate tiptr->ti_state == T_INREL || 85*0Sstevel@tonic-gate (tiptr->ti_state == T_INCON && tiptr->ti_ocnt > 0))) { 86*0Sstevel@tonic-gate t_errno = TOUTSTATE; 87*0Sstevel@tonic-gate sig_mutex_unlock(&tiptr->ti_lock); 88*0Sstevel@tonic-gate trace2(TR_t_snddis, 1, fd); 89*0Sstevel@tonic-gate return (-1); 90*0Sstevel@tonic-gate } 91*0Sstevel@tonic-gate 92*0Sstevel@tonic-gate /* 93*0Sstevel@tonic-gate * Following check only done for XTI as it may be a risk 94*0Sstevel@tonic-gate * to existing buggy TLI applications. 95*0Sstevel@tonic-gate */ 96*0Sstevel@tonic-gate } 97*0Sstevel@tonic-gate 98*0Sstevel@tonic-gate if (call != NULL && call->udata.len) { 99*0Sstevel@tonic-gate if ((tiptr->ti_ddatasize == T_INVALID /* -2 */) || 100*0Sstevel@tonic-gate ((tiptr->ti_ddatasize != T_INFINITE /* -1*/) && 101*0Sstevel@tonic-gate (call->udata.len > 102*0Sstevel@tonic-gate (uint32_t)tiptr->ti_ddatasize))) { 103*0Sstevel@tonic-gate /* 104*0Sstevel@tonic-gate * user data not valid with disconnect or it 105*0Sstevel@tonic-gate * exceeds the limits specified by the 106*0Sstevel@tonic-gate * transport provider 107*0Sstevel@tonic-gate */ 108*0Sstevel@tonic-gate t_errno = TBADDATA; 109*0Sstevel@tonic-gate sig_mutex_unlock(&tiptr->ti_lock); 110*0Sstevel@tonic-gate trace2(TR_t_snddis, 1, fd); 111*0Sstevel@tonic-gate return (-1); 112*0Sstevel@tonic-gate } 113*0Sstevel@tonic-gate } 114*0Sstevel@tonic-gate 115*0Sstevel@tonic-gate /* 116*0Sstevel@tonic-gate * If disconnect is done on a listener, the 'call' parameter 117*0Sstevel@tonic-gate * must be non-null 118*0Sstevel@tonic-gate */ 119*0Sstevel@tonic-gate if ((tiptr->ti_state == T_INCON) && 120*0Sstevel@tonic-gate (call == NULL)) { 121*0Sstevel@tonic-gate t_errno = TBADSEQ; 122*0Sstevel@tonic-gate sig_mutex_unlock(&tiptr->ti_lock); 123*0Sstevel@tonic-gate trace2(TR_t_snddis, 1, fd); 124*0Sstevel@tonic-gate return (-1); 125*0Sstevel@tonic-gate } 126*0Sstevel@tonic-gate 127*0Sstevel@tonic-gate /* 128*0Sstevel@tonic-gate * look at look buffer to see if there is a discon there 129*0Sstevel@tonic-gate */ 130*0Sstevel@tonic-gate 131*0Sstevel@tonic-gate if (_t_look_locked(fd, tiptr, 0, api_semantics) == T_DISCONNECT) { 132*0Sstevel@tonic-gate t_errno = TLOOK; 133*0Sstevel@tonic-gate sig_mutex_unlock(&tiptr->ti_lock); 134*0Sstevel@tonic-gate trace2(TR_t_snddis, 1, fd); 135*0Sstevel@tonic-gate return (-1); 136*0Sstevel@tonic-gate } 137*0Sstevel@tonic-gate 138*0Sstevel@tonic-gate if ((tiptr->ti_lookcnt > 0) && (call == 0)) 139*0Sstevel@tonic-gate _t_flush_lookevents(tiptr); /* flush but not on listener */ 140*0Sstevel@tonic-gate 141*0Sstevel@tonic-gate do { 142*0Sstevel@tonic-gate retval = _ioctl(fd, I_FLUSH, FLUSHW); 143*0Sstevel@tonic-gate } while (retval < 0 && errno == EINTR); 144*0Sstevel@tonic-gate if (retval < 0) { 145*0Sstevel@tonic-gate sv_errno = errno; 146*0Sstevel@tonic-gate t_errno = TSYSERR; 147*0Sstevel@tonic-gate sig_mutex_unlock(&tiptr->ti_lock); 148*0Sstevel@tonic-gate trace2(TR_t_snddis, 1, fd); 149*0Sstevel@tonic-gate errno = sv_errno; 150*0Sstevel@tonic-gate return (-1); 151*0Sstevel@tonic-gate } 152*0Sstevel@tonic-gate 153*0Sstevel@tonic-gate ctlbuf.len = (int)sizeof (struct T_discon_req); 154*0Sstevel@tonic-gate ctlbuf.maxlen = (int)sizeof (struct T_discon_req); 155*0Sstevel@tonic-gate ctlbuf.buf = (char *)&dreq; 156*0Sstevel@tonic-gate 157*0Sstevel@tonic-gate dreq.PRIM_type = T_DISCON_REQ; 158*0Sstevel@tonic-gate dreq.SEQ_number = (call? call->sequence: -1); 159*0Sstevel@tonic-gate 160*0Sstevel@tonic-gate databuf.maxlen = (call? call->udata.len: 0); 161*0Sstevel@tonic-gate databuf.len = (call? call->udata.len: 0); 162*0Sstevel@tonic-gate databuf.buf = (call? call->udata.buf: NULL); 163*0Sstevel@tonic-gate 164*0Sstevel@tonic-gate /* 165*0Sstevel@tonic-gate * Calls to send data (write or putmsg) can potentially 166*0Sstevel@tonic-gate * block, for MT case, we drop the lock and enable signals here 167*0Sstevel@tonic-gate * and acquire it back 168*0Sstevel@tonic-gate */ 169*0Sstevel@tonic-gate sig_mutex_unlock(&tiptr->ti_lock); 170*0Sstevel@tonic-gate if (putmsg(fd, &ctlbuf, (databuf.len? &databuf: NULL), 0) < 0) { 171*0Sstevel@tonic-gate sv_errno = errno; 172*0Sstevel@tonic-gate 173*0Sstevel@tonic-gate t_errno = TSYSERR; 174*0Sstevel@tonic-gate trace2(TR_t_snddis, 1, fd); 175*0Sstevel@tonic-gate errno = sv_errno; 176*0Sstevel@tonic-gate return (-1); 177*0Sstevel@tonic-gate } 178*0Sstevel@tonic-gate sig_mutex_lock(&tiptr->ti_lock); 179*0Sstevel@tonic-gate 180*0Sstevel@tonic-gate if (_t_is_ok(fd, tiptr, T_DISCON_REQ) < 0) { 181*0Sstevel@tonic-gate sv_errno = errno; 182*0Sstevel@tonic-gate sig_mutex_unlock(&tiptr->ti_lock); 183*0Sstevel@tonic-gate trace2(TR_t_snddis, 1, fd); 184*0Sstevel@tonic-gate errno = sv_errno; 185*0Sstevel@tonic-gate return (-1); 186*0Sstevel@tonic-gate } 187*0Sstevel@tonic-gate 188*0Sstevel@tonic-gate tiptr->ti_flags &= ~(MORE|EXPEDITED); 189*0Sstevel@tonic-gate 190*0Sstevel@tonic-gate if (tiptr->ti_ocnt <= 1) { 191*0Sstevel@tonic-gate if (tiptr->ti_state == T_INCON) { 192*0Sstevel@tonic-gate tiptr->ti_ocnt--; 193*0Sstevel@tonic-gate tiptr->ti_flags &= ~TX_TQFULL_NOTIFIED; 194*0Sstevel@tonic-gate } 195*0Sstevel@tonic-gate _T_TX_NEXTSTATE(T_SNDDIS1, tiptr, 196*0Sstevel@tonic-gate "t_snddis: invalid state event T_SNDDIS1"); 197*0Sstevel@tonic-gate } else { 198*0Sstevel@tonic-gate if (tiptr->ti_state == T_INCON) { 199*0Sstevel@tonic-gate tiptr->ti_ocnt--; 200*0Sstevel@tonic-gate tiptr->ti_flags &= ~TX_TQFULL_NOTIFIED; 201*0Sstevel@tonic-gate } 202*0Sstevel@tonic-gate _T_TX_NEXTSTATE(T_SNDDIS2, tiptr, 203*0Sstevel@tonic-gate "t_snddis: invalid state event T_SNDDIS2"); 204*0Sstevel@tonic-gate } 205*0Sstevel@tonic-gate 206*0Sstevel@tonic-gate sig_mutex_unlock(&tiptr->ti_lock); 207*0Sstevel@tonic-gate trace2(TR_t_snddis, 1, fd); 208*0Sstevel@tonic-gate return (0); 209*0Sstevel@tonic-gate } 210