10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
50Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
60Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
70Sstevel@tonic-gate * with the License.
80Sstevel@tonic-gate *
90Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
100Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
110Sstevel@tonic-gate * See the License for the specific language governing permissions
120Sstevel@tonic-gate * and limitations under the License.
130Sstevel@tonic-gate *
140Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
150Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
160Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
170Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
180Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
190Sstevel@tonic-gate *
200Sstevel@tonic-gate * CDDL HEADER END
210Sstevel@tonic-gate */
22*132Srobinson
230Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
240Sstevel@tonic-gate /* All Rights Reserved */
250Sstevel@tonic-gate
260Sstevel@tonic-gate /*
27*132Srobinson * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
280Sstevel@tonic-gate * Use is subject to license terms.
290Sstevel@tonic-gate */
300Sstevel@tonic-gate
310Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.5 */
320Sstevel@tonic-gate
330Sstevel@tonic-gate #include "mt.h"
340Sstevel@tonic-gate #include <errno.h>
350Sstevel@tonic-gate #include <string.h>
360Sstevel@tonic-gate #include <stdlib.h>
370Sstevel@tonic-gate #include <stropts.h>
380Sstevel@tonic-gate #include <sys/stream.h>
390Sstevel@tonic-gate #define _SUN_TPI_VERSION 2
400Sstevel@tonic-gate #include <sys/tihdr.h>
410Sstevel@tonic-gate #include <sys/timod.h>
420Sstevel@tonic-gate #include <xti.h>
430Sstevel@tonic-gate #include <syslog.h>
440Sstevel@tonic-gate #include <assert.h>
450Sstevel@tonic-gate #include "tx.h"
460Sstevel@tonic-gate
470Sstevel@tonic-gate int
_tx_rcvuderr(int fd,struct t_uderr * uderr,int api_semantics)480Sstevel@tonic-gate _tx_rcvuderr(int fd, struct t_uderr *uderr, int api_semantics)
490Sstevel@tonic-gate {
500Sstevel@tonic-gate struct strbuf ctlbuf, databuf;
510Sstevel@tonic-gate int flg;
520Sstevel@tonic-gate int retval;
530Sstevel@tonic-gate union T_primitives *pptr;
540Sstevel@tonic-gate struct _ti_user *tiptr;
550Sstevel@tonic-gate int sv_errno;
560Sstevel@tonic-gate int didalloc;
570Sstevel@tonic-gate int use_lookbufs = 0;
580Sstevel@tonic-gate
590Sstevel@tonic-gate
60*132Srobinson if ((tiptr = _t_checkfd(fd, 0, api_semantics)) == NULL)
610Sstevel@tonic-gate return (-1);
620Sstevel@tonic-gate sig_mutex_lock(&tiptr->ti_lock);
630Sstevel@tonic-gate
640Sstevel@tonic-gate if (tiptr->ti_servtype != T_CLTS) {
650Sstevel@tonic-gate t_errno = TNOTSUPPORT;
660Sstevel@tonic-gate sig_mutex_unlock(&tiptr->ti_lock);
670Sstevel@tonic-gate return (-1);
680Sstevel@tonic-gate }
690Sstevel@tonic-gate /*
700Sstevel@tonic-gate * is there a unitdata error indication in look buffer
710Sstevel@tonic-gate */
720Sstevel@tonic-gate if (tiptr->ti_lookcnt > 0) {
730Sstevel@tonic-gate ctlbuf.len = tiptr->ti_lookbufs.tl_lookclen;
740Sstevel@tonic-gate ctlbuf.buf = tiptr->ti_lookbufs.tl_lookcbuf;
750Sstevel@tonic-gate /* Note: cltbuf.maxlen not used in this case */
760Sstevel@tonic-gate
77*132Srobinson /* LINTED pointer cast */
780Sstevel@tonic-gate assert(((union T_primitives *)ctlbuf.buf)->type
790Sstevel@tonic-gate == T_UDERROR_IND);
800Sstevel@tonic-gate
810Sstevel@tonic-gate databuf.maxlen = 0;
820Sstevel@tonic-gate databuf.len = 0;
830Sstevel@tonic-gate databuf.buf = NULL;
840Sstevel@tonic-gate
850Sstevel@tonic-gate use_lookbufs = 1;
860Sstevel@tonic-gate
870Sstevel@tonic-gate } else {
880Sstevel@tonic-gate if ((retval = _t_look_locked(fd, tiptr, 0,
890Sstevel@tonic-gate api_semantics)) < 0) {
900Sstevel@tonic-gate sv_errno = errno;
910Sstevel@tonic-gate sig_mutex_unlock(&tiptr->ti_lock);
920Sstevel@tonic-gate errno = sv_errno;
930Sstevel@tonic-gate return (-1);
940Sstevel@tonic-gate }
950Sstevel@tonic-gate if (retval != T_UDERR) {
960Sstevel@tonic-gate t_errno = TNOUDERR;
970Sstevel@tonic-gate sig_mutex_unlock(&tiptr->ti_lock);
980Sstevel@tonic-gate return (-1);
990Sstevel@tonic-gate }
1000Sstevel@tonic-gate
1010Sstevel@tonic-gate /*
1020Sstevel@tonic-gate * Acquire ctlbuf for use in sending/receiving control part
1030Sstevel@tonic-gate * of the message.
1040Sstevel@tonic-gate */
1050Sstevel@tonic-gate if (_t_acquire_ctlbuf(tiptr, &ctlbuf, &didalloc) < 0) {
1060Sstevel@tonic-gate sv_errno = errno;
1070Sstevel@tonic-gate sig_mutex_unlock(&tiptr->ti_lock);
1080Sstevel@tonic-gate errno = sv_errno;
1090Sstevel@tonic-gate return (-1);
1100Sstevel@tonic-gate }
1110Sstevel@tonic-gate
1120Sstevel@tonic-gate databuf.maxlen = 0;
1130Sstevel@tonic-gate databuf.len = 0;
1140Sstevel@tonic-gate databuf.buf = NULL;
1150Sstevel@tonic-gate
1160Sstevel@tonic-gate flg = 0;
1170Sstevel@tonic-gate
1180Sstevel@tonic-gate /*
1190Sstevel@tonic-gate * Since we already verified that a unitdata error
1200Sstevel@tonic-gate * indication is pending, we assume that this getmsg()
1210Sstevel@tonic-gate * will not block indefinitely.
1220Sstevel@tonic-gate */
1230Sstevel@tonic-gate if ((retval = getmsg(fd, &ctlbuf, &databuf, &flg)) < 0) {
1240Sstevel@tonic-gate
1250Sstevel@tonic-gate t_errno = TSYSERR;
1260Sstevel@tonic-gate goto err_out;
1270Sstevel@tonic-gate }
1280Sstevel@tonic-gate /*
1290Sstevel@tonic-gate * did I get entire message?
1300Sstevel@tonic-gate */
1310Sstevel@tonic-gate if (retval > 0) {
1320Sstevel@tonic-gate t_errno = TSYSERR;
1330Sstevel@tonic-gate errno = EIO;
1340Sstevel@tonic-gate goto err_out;
1350Sstevel@tonic-gate }
1360Sstevel@tonic-gate
1370Sstevel@tonic-gate }
1380Sstevel@tonic-gate
139*132Srobinson /* LINTED pointer cast */
1400Sstevel@tonic-gate pptr = (union T_primitives *)ctlbuf.buf;
1410Sstevel@tonic-gate
1420Sstevel@tonic-gate if ((ctlbuf.len < (int)sizeof (struct T_uderror_ind)) ||
1430Sstevel@tonic-gate (pptr->type != T_UDERROR_IND)) {
1440Sstevel@tonic-gate t_errno = TSYSERR;
1450Sstevel@tonic-gate errno = EPROTO;
1460Sstevel@tonic-gate goto err_out;
1470Sstevel@tonic-gate }
1480Sstevel@tonic-gate
1490Sstevel@tonic-gate if (uderr) {
1500Sstevel@tonic-gate if (_T_IS_TLI(api_semantics) || uderr->addr.maxlen > 0) {
1510Sstevel@tonic-gate if (TLEN_GT_NLEN(pptr->uderror_ind.DEST_length,
1520Sstevel@tonic-gate uderr->addr.maxlen)) {
1530Sstevel@tonic-gate t_errno = TBUFOVFLW;
1540Sstevel@tonic-gate goto err_out;
1550Sstevel@tonic-gate }
1560Sstevel@tonic-gate (void) memcpy(uderr->addr.buf, ctlbuf.buf +
1570Sstevel@tonic-gate pptr->uderror_ind.DEST_offset,
1580Sstevel@tonic-gate (size_t)pptr->uderror_ind.DEST_length);
1590Sstevel@tonic-gate uderr->addr.len =
1600Sstevel@tonic-gate (unsigned int)pptr->uderror_ind.DEST_length;
1610Sstevel@tonic-gate }
1620Sstevel@tonic-gate if (_T_IS_TLI(api_semantics) || uderr->addr.maxlen > 0) {
1630Sstevel@tonic-gate if (TLEN_GT_NLEN(pptr->uderror_ind.OPT_length,
1640Sstevel@tonic-gate uderr->opt.maxlen)) {
1650Sstevel@tonic-gate t_errno = TBUFOVFLW;
1660Sstevel@tonic-gate goto err_out;
1670Sstevel@tonic-gate }
1680Sstevel@tonic-gate (void) memcpy(uderr->opt.buf, ctlbuf.buf +
1690Sstevel@tonic-gate pptr->uderror_ind.OPT_offset,
1700Sstevel@tonic-gate (size_t)pptr->uderror_ind.OPT_length);
1710Sstevel@tonic-gate uderr->opt.len =
1720Sstevel@tonic-gate (unsigned int)pptr->uderror_ind.OPT_length;
1730Sstevel@tonic-gate }
1740Sstevel@tonic-gate uderr->error = pptr->uderror_ind.ERROR_type;
1750Sstevel@tonic-gate }
1760Sstevel@tonic-gate
1770Sstevel@tonic-gate _T_TX_NEXTSTATE(T_RCVUDERR, tiptr,
1780Sstevel@tonic-gate "t_rcvuderr: invalid state event T_RCVUDERR");
1790Sstevel@tonic-gate if (use_lookbufs)
1800Sstevel@tonic-gate _t_free_looklist_head(tiptr);
1810Sstevel@tonic-gate else {
1820Sstevel@tonic-gate if (didalloc)
1830Sstevel@tonic-gate free(ctlbuf.buf);
1840Sstevel@tonic-gate else
1850Sstevel@tonic-gate tiptr->ti_ctlbuf = ctlbuf.buf;
1860Sstevel@tonic-gate }
1870Sstevel@tonic-gate sig_mutex_unlock(&tiptr->ti_lock);
1880Sstevel@tonic-gate return (0);
1890Sstevel@tonic-gate
1900Sstevel@tonic-gate err_out:
1910Sstevel@tonic-gate sv_errno = errno;
1920Sstevel@tonic-gate
1930Sstevel@tonic-gate if (use_lookbufs)
1940Sstevel@tonic-gate _t_free_looklist_head(tiptr);
1950Sstevel@tonic-gate else {
1960Sstevel@tonic-gate if (didalloc)
1970Sstevel@tonic-gate free(ctlbuf.buf);
1980Sstevel@tonic-gate else
1990Sstevel@tonic-gate tiptr->ti_ctlbuf = ctlbuf.buf;
2000Sstevel@tonic-gate }
2010Sstevel@tonic-gate sig_mutex_unlock(&tiptr->ti_lock);
2020Sstevel@tonic-gate errno = sv_errno;
2030Sstevel@tonic-gate return (-1);
2040Sstevel@tonic-gate }
205