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.7.3.1 */ 33*0Sstevel@tonic-gate 34*0Sstevel@tonic-gate /* 35*0Sstevel@tonic-gate * t_rcvrel.c and t_rcvreldata.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 <rpc/trace.h> 42*0Sstevel@tonic-gate #include <stdlib.h> 43*0Sstevel@tonic-gate #include <errno.h> 44*0Sstevel@tonic-gate #include <stropts.h> 45*0Sstevel@tonic-gate #include <sys/stream.h> 46*0Sstevel@tonic-gate #define _SUN_TPI_VERSION 2 47*0Sstevel@tonic-gate #include <sys/tihdr.h> 48*0Sstevel@tonic-gate #include <sys/timod.h> 49*0Sstevel@tonic-gate #include <xti.h> 50*0Sstevel@tonic-gate #include <signal.h> 51*0Sstevel@tonic-gate #include <syslog.h> 52*0Sstevel@tonic-gate #include "tx.h" 53*0Sstevel@tonic-gate 54*0Sstevel@tonic-gate int 55*0Sstevel@tonic-gate _tx_rcvrel(int fd, int api_semantics) 56*0Sstevel@tonic-gate { 57*0Sstevel@tonic-gate struct strbuf ctlbuf; 58*0Sstevel@tonic-gate struct strbuf databuf; 59*0Sstevel@tonic-gate int retval; 60*0Sstevel@tonic-gate union T_primitives *pptr; 61*0Sstevel@tonic-gate struct _ti_user *tiptr; 62*0Sstevel@tonic-gate int sv_errno; 63*0Sstevel@tonic-gate int didalloc, didralloc; 64*0Sstevel@tonic-gate 65*0Sstevel@tonic-gate int flg = 0; 66*0Sstevel@tonic-gate 67*0Sstevel@tonic-gate 68*0Sstevel@tonic-gate trace2(TR_t_rcvrel, 0, fd); 69*0Sstevel@tonic-gate if ((tiptr = _t_checkfd(fd, 0, api_semantics)) == 0) { 70*0Sstevel@tonic-gate sv_errno = errno; 71*0Sstevel@tonic-gate trace2(TR_t_rcvrel, 1, fd); 72*0Sstevel@tonic-gate errno = sv_errno; 73*0Sstevel@tonic-gate return (-1); 74*0Sstevel@tonic-gate } 75*0Sstevel@tonic-gate sig_mutex_lock(&tiptr->ti_lock); 76*0Sstevel@tonic-gate 77*0Sstevel@tonic-gate if (tiptr->ti_servtype != T_COTS_ORD) { 78*0Sstevel@tonic-gate t_errno = TNOTSUPPORT; 79*0Sstevel@tonic-gate sig_mutex_unlock(&tiptr->ti_lock); 80*0Sstevel@tonic-gate trace2(TR_t_rcvrel, 1, fd); 81*0Sstevel@tonic-gate return (-1); 82*0Sstevel@tonic-gate } 83*0Sstevel@tonic-gate 84*0Sstevel@tonic-gate if (_T_IS_XTI(api_semantics)) { 85*0Sstevel@tonic-gate /* 86*0Sstevel@tonic-gate * User level state verification only done for XTI 87*0Sstevel@tonic-gate * because doing for TLI may break existing applications 88*0Sstevel@tonic-gate */ 89*0Sstevel@tonic-gate if (! (tiptr->ti_state == T_DATAXFER || 90*0Sstevel@tonic-gate tiptr->ti_state == T_OUTREL)) { 91*0Sstevel@tonic-gate t_errno = TOUTSTATE; 92*0Sstevel@tonic-gate sig_mutex_unlock(&tiptr->ti_lock); 93*0Sstevel@tonic-gate trace2(TR_t_rcvrel, 1, fd); 94*0Sstevel@tonic-gate return (-1); 95*0Sstevel@tonic-gate } 96*0Sstevel@tonic-gate } 97*0Sstevel@tonic-gate 98*0Sstevel@tonic-gate if ((retval = _t_look_locked(fd, tiptr, 0, api_semantics)) < 0) { 99*0Sstevel@tonic-gate sv_errno = errno; 100*0Sstevel@tonic-gate sig_mutex_unlock(&tiptr->ti_lock); 101*0Sstevel@tonic-gate trace2(TR_t_rcvrel, 1, fd); 102*0Sstevel@tonic-gate errno = sv_errno; 103*0Sstevel@tonic-gate return (-1); 104*0Sstevel@tonic-gate } 105*0Sstevel@tonic-gate 106*0Sstevel@tonic-gate if (retval == T_DISCONNECT) { 107*0Sstevel@tonic-gate /* 108*0Sstevel@tonic-gate * This ensures preference to T_DISCON_IND which is 109*0Sstevel@tonic-gate * the design model for TPI 110*0Sstevel@tonic-gate */ 111*0Sstevel@tonic-gate t_errno = TLOOK; 112*0Sstevel@tonic-gate sig_mutex_unlock(&tiptr->ti_lock); 113*0Sstevel@tonic-gate trace2(TR_t_rcvrel, 1, fd); 114*0Sstevel@tonic-gate return (-1); 115*0Sstevel@tonic-gate } 116*0Sstevel@tonic-gate 117*0Sstevel@tonic-gate if ((tiptr->ti_lookcnt > 0) && 118*0Sstevel@tonic-gate (*((t_scalar_t *)tiptr->ti_lookbufs.tl_lookcbuf) == T_ORDREL_IND)) { 119*0Sstevel@tonic-gate /* 120*0Sstevel@tonic-gate * Current look buffer event is T_ORDREL_IND. 121*0Sstevel@tonic-gate * Remove it from look buffer event list. 122*0Sstevel@tonic-gate */ 123*0Sstevel@tonic-gate _t_free_looklist_head(tiptr); 124*0Sstevel@tonic-gate _T_TX_NEXTSTATE(T_RCVREL, tiptr, 125*0Sstevel@tonic-gate "t_rcv: invalid state event T_RCVREL"); 126*0Sstevel@tonic-gate sig_mutex_unlock(&tiptr->ti_lock); 127*0Sstevel@tonic-gate trace2(TR_t_rcvrel, 1, fd); 128*0Sstevel@tonic-gate return (0); 129*0Sstevel@tonic-gate } else { 130*0Sstevel@tonic-gate if (retval != T_ORDREL) { 131*0Sstevel@tonic-gate t_errno = TNOREL; 132*0Sstevel@tonic-gate sig_mutex_unlock(&tiptr->ti_lock); 133*0Sstevel@tonic-gate trace2(TR_t_rcvrel, 1, fd); 134*0Sstevel@tonic-gate return (-1); 135*0Sstevel@tonic-gate } 136*0Sstevel@tonic-gate } 137*0Sstevel@tonic-gate 138*0Sstevel@tonic-gate /* 139*0Sstevel@tonic-gate * get ordrel off read queue. 140*0Sstevel@tonic-gate * use ctl and rcv buffers 141*0Sstevel@tonic-gate * 142*0Sstevel@tonic-gate * Acquire ctlbuf for use in sending/receiving control part 143*0Sstevel@tonic-gate * of the message. 144*0Sstevel@tonic-gate */ 145*0Sstevel@tonic-gate if (_t_acquire_ctlbuf(tiptr, &ctlbuf, &didalloc) < 0) { 146*0Sstevel@tonic-gate sv_errno = errno; 147*0Sstevel@tonic-gate sig_mutex_unlock(&tiptr->ti_lock); 148*0Sstevel@tonic-gate trace2(TR_t_rcvrel, 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 /* 154*0Sstevel@tonic-gate * Acquire databuf for use in sending/receiving data part 155*0Sstevel@tonic-gate */ 156*0Sstevel@tonic-gate if (_t_acquire_databuf(tiptr, &databuf, &didralloc) < 0) { 157*0Sstevel@tonic-gate sv_errno = errno; 158*0Sstevel@tonic-gate if (didalloc) 159*0Sstevel@tonic-gate free(ctlbuf.buf); 160*0Sstevel@tonic-gate else 161*0Sstevel@tonic-gate tiptr->ti_ctlbuf = ctlbuf.buf; 162*0Sstevel@tonic-gate sig_mutex_unlock(&tiptr->ti_lock); 163*0Sstevel@tonic-gate trace2(TR_t_rcvrel, 1, fd); 164*0Sstevel@tonic-gate errno = sv_errno; 165*0Sstevel@tonic-gate return (-1); 166*0Sstevel@tonic-gate } 167*0Sstevel@tonic-gate 168*0Sstevel@tonic-gate /* 169*0Sstevel@tonic-gate * Since we have verified above that an orderly release event 170*0Sstevel@tonic-gate * is pending on this endpoint, we assume that this getmsg() 171*0Sstevel@tonic-gate * cannot block forever. 172*0Sstevel@tonic-gate */ 173*0Sstevel@tonic-gate do { 174*0Sstevel@tonic-gate retval = getmsg(fd, &ctlbuf, &databuf, &flg); 175*0Sstevel@tonic-gate } while (retval < 0 && errno == EINTR); 176*0Sstevel@tonic-gate 177*0Sstevel@tonic-gate if (retval < 0) { 178*0Sstevel@tonic-gate t_errno = TSYSERR; 179*0Sstevel@tonic-gate goto err_out; 180*0Sstevel@tonic-gate } 181*0Sstevel@tonic-gate 182*0Sstevel@tonic-gate /* 183*0Sstevel@tonic-gate * did I get entire message? 184*0Sstevel@tonic-gate */ 185*0Sstevel@tonic-gate if (retval > 0) { 186*0Sstevel@tonic-gate t_errno = TSYSERR; 187*0Sstevel@tonic-gate errno = EIO; 188*0Sstevel@tonic-gate goto err_out; 189*0Sstevel@tonic-gate } 190*0Sstevel@tonic-gate pptr = (union T_primitives *)ctlbuf.buf; 191*0Sstevel@tonic-gate 192*0Sstevel@tonic-gate if (ctlbuf.len < (int)sizeof (struct T_ordrel_ind)) { 193*0Sstevel@tonic-gate t_errno = TSYSERR; 194*0Sstevel@tonic-gate errno = EPROTO; 195*0Sstevel@tonic-gate goto err_out; 196*0Sstevel@tonic-gate } 197*0Sstevel@tonic-gate if (pptr->type != T_ORDREL_IND) { 198*0Sstevel@tonic-gate if (pptr->type == T_DISCON_IND) { 199*0Sstevel@tonic-gate /* 200*0Sstevel@tonic-gate * T_DISCON_IND gets priority following 201*0Sstevel@tonic-gate * TPI design philosphy. 202*0Sstevel@tonic-gate * 203*0Sstevel@tonic-gate * Add it to the events in the "look buffer" 204*0Sstevel@tonic-gate * list of events. This routine may defer signals. 205*0Sstevel@tonic-gate */ 206*0Sstevel@tonic-gate if (_t_register_lookevent(tiptr, databuf.buf, 207*0Sstevel@tonic-gate databuf.len, ctlbuf.buf, 208*0Sstevel@tonic-gate ctlbuf.len) < 0) { 209*0Sstevel@tonic-gate t_errno = TSYSERR; 210*0Sstevel@tonic-gate errno = ENOMEM; 211*0Sstevel@tonic-gate goto err_out; 212*0Sstevel@tonic-gate } 213*0Sstevel@tonic-gate t_errno = TLOOK; 214*0Sstevel@tonic-gate goto err_out; 215*0Sstevel@tonic-gate } else { 216*0Sstevel@tonic-gate t_errno = TSYSERR; 217*0Sstevel@tonic-gate errno = EPROTO; 218*0Sstevel@tonic-gate goto err_out; 219*0Sstevel@tonic-gate } 220*0Sstevel@tonic-gate } 221*0Sstevel@tonic-gate 222*0Sstevel@tonic-gate _T_TX_NEXTSTATE(T_RCVREL, tiptr, 223*0Sstevel@tonic-gate "t_rcvrel: invalid state event T_RCVREL"); 224*0Sstevel@tonic-gate 225*0Sstevel@tonic-gate if (didalloc) 226*0Sstevel@tonic-gate free(ctlbuf.buf); 227*0Sstevel@tonic-gate else 228*0Sstevel@tonic-gate tiptr->ti_ctlbuf = ctlbuf.buf; 229*0Sstevel@tonic-gate if (didralloc) 230*0Sstevel@tonic-gate free(databuf.buf); 231*0Sstevel@tonic-gate else 232*0Sstevel@tonic-gate tiptr->ti_rcvbuf = databuf.buf; 233*0Sstevel@tonic-gate sig_mutex_unlock(&tiptr->ti_lock); 234*0Sstevel@tonic-gate trace2(TR_t_rcvrel, 1, fd); 235*0Sstevel@tonic-gate return (0); 236*0Sstevel@tonic-gate 237*0Sstevel@tonic-gate err_out: 238*0Sstevel@tonic-gate sv_errno = errno; 239*0Sstevel@tonic-gate 240*0Sstevel@tonic-gate if (didalloc) 241*0Sstevel@tonic-gate free(ctlbuf.buf); 242*0Sstevel@tonic-gate else 243*0Sstevel@tonic-gate tiptr->ti_ctlbuf = ctlbuf.buf; 244*0Sstevel@tonic-gate if (didralloc) 245*0Sstevel@tonic-gate free(databuf.buf); 246*0Sstevel@tonic-gate else 247*0Sstevel@tonic-gate tiptr->ti_rcvbuf = databuf.buf; 248*0Sstevel@tonic-gate sig_mutex_unlock(&tiptr->ti_lock); 249*0Sstevel@tonic-gate trace2(TR_t_rcvrel, 1, fd); 250*0Sstevel@tonic-gate errno = sv_errno; 251*0Sstevel@tonic-gate return (-1); 252*0Sstevel@tonic-gate } 253