xref: /illumos-gate/usr/src/uts/common/io/tirdwr.c (revision c6026c81)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate  * with the License.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate  * and limitations under the License.
137c478bd9Sstevel@tonic-gate  *
147c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * CDDL HEADER END
217c478bd9Sstevel@tonic-gate  */
227c478bd9Sstevel@tonic-gate /*
237c478bd9Sstevel@tonic-gate  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
28*c6026c81SToomas Soome /*	  All Rights Reserved	*/
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate /*
317c478bd9Sstevel@tonic-gate  * Transport Interface Library read/write module - issue 1
327c478bd9Sstevel@tonic-gate  */
337c478bd9Sstevel@tonic-gate 
347c478bd9Sstevel@tonic-gate #include	<sys/types.h>
357c478bd9Sstevel@tonic-gate #include	<sys/param.h>
367c478bd9Sstevel@tonic-gate #include	<sys/stream.h>
377c478bd9Sstevel@tonic-gate #include	<sys/stropts.h>
387c478bd9Sstevel@tonic-gate #include	<sys/tihdr.h>
397c478bd9Sstevel@tonic-gate #include	<sys/debug.h>
407c478bd9Sstevel@tonic-gate #include	<sys/errno.h>
417c478bd9Sstevel@tonic-gate #include	<sys/kmem.h>
427c478bd9Sstevel@tonic-gate #include	<sys/tirdwr.h>
437c478bd9Sstevel@tonic-gate #include	<sys/conf.h>
447c478bd9Sstevel@tonic-gate #include	<sys/modctl.h>
457c478bd9Sstevel@tonic-gate #include	<sys/ddi.h>
467c478bd9Sstevel@tonic-gate #include	<sys/sunddi.h>
477c478bd9Sstevel@tonic-gate 
487c478bd9Sstevel@tonic-gate #define	ORDREL		002
497c478bd9Sstevel@tonic-gate #define	DISCON		004
507c478bd9Sstevel@tonic-gate #define	FATAL		010
517c478bd9Sstevel@tonic-gate #define	WAITACK		020
527c478bd9Sstevel@tonic-gate #define	TIRDWR_ID	4
537c478bd9Sstevel@tonic-gate 
547c478bd9Sstevel@tonic-gate /*
557c478bd9Sstevel@tonic-gate  * Per-Stream private data structure.
567c478bd9Sstevel@tonic-gate  */
577c478bd9Sstevel@tonic-gate struct trw_trw {
587c478bd9Sstevel@tonic-gate 	queue_t	*trw_rdq;
597c478bd9Sstevel@tonic-gate 	uint_t	trw_flags;
607c478bd9Sstevel@tonic-gate };
617c478bd9Sstevel@tonic-gate 
627c478bd9Sstevel@tonic-gate /*
637c478bd9Sstevel@tonic-gate  * stream data structure definitions
647c478bd9Sstevel@tonic-gate  */
657c478bd9Sstevel@tonic-gate static	int tirdwropen(queue_t *q, dev_t *dev,
667c478bd9Sstevel@tonic-gate     int flag, int sflag, cred_t	*cr);
677c478bd9Sstevel@tonic-gate 
687c478bd9Sstevel@tonic-gate static	int tirdwrclose(queue_t *q, int flag, cred_t *cr);
697c478bd9Sstevel@tonic-gate 
707c478bd9Sstevel@tonic-gate static	int check_strhead(queue_t *q);
717c478bd9Sstevel@tonic-gate 
727c478bd9Sstevel@tonic-gate /*
737c478bd9Sstevel@tonic-gate  * To save instructions, since STREAMS ignores the return value
747c478bd9Sstevel@tonic-gate  * from these functions, they are defined as void here. Kind of icky, but...
757c478bd9Sstevel@tonic-gate  */
76*c6026c81SToomas Soome static int tirdwrrput(queue_t *q, mblk_t *mp);
77*c6026c81SToomas Soome static int tirdwrwput(queue_t *q, mblk_t *mp);
787c478bd9Sstevel@tonic-gate 
797c478bd9Sstevel@tonic-gate static struct module_info tirdwr_info = {
807c478bd9Sstevel@tonic-gate 	TIRDWR_ID,
817c478bd9Sstevel@tonic-gate 	"tirdwr",
827c478bd9Sstevel@tonic-gate 	0,
837c478bd9Sstevel@tonic-gate 	INFPSZ,
847c478bd9Sstevel@tonic-gate 	4096,
857c478bd9Sstevel@tonic-gate 	1024
867c478bd9Sstevel@tonic-gate };
877c478bd9Sstevel@tonic-gate 
887c478bd9Sstevel@tonic-gate static struct qinit tirdwrrinit = {
89*c6026c81SToomas Soome 	tirdwrrput,
90*c6026c81SToomas Soome 	NULL,
917c478bd9Sstevel@tonic-gate 	tirdwropen,
927c478bd9Sstevel@tonic-gate 	tirdwrclose,
937c478bd9Sstevel@tonic-gate 	nulldev,
947c478bd9Sstevel@tonic-gate 	&tirdwr_info,
957c478bd9Sstevel@tonic-gate 	NULL
967c478bd9Sstevel@tonic-gate };
977c478bd9Sstevel@tonic-gate 
987c478bd9Sstevel@tonic-gate static struct qinit tirdwrwinit = {
99*c6026c81SToomas Soome 	tirdwrwput,
100*c6026c81SToomas Soome 	NULL,
1017c478bd9Sstevel@tonic-gate 	tirdwropen,
1027c478bd9Sstevel@tonic-gate 	tirdwrclose,
1037c478bd9Sstevel@tonic-gate 	nulldev,
1047c478bd9Sstevel@tonic-gate 	&tirdwr_info,
1057c478bd9Sstevel@tonic-gate 	NULL
1067c478bd9Sstevel@tonic-gate };
1077c478bd9Sstevel@tonic-gate 
1087c478bd9Sstevel@tonic-gate static struct streamtab trwinfo = {
1097c478bd9Sstevel@tonic-gate 	&tirdwrrinit,
1107c478bd9Sstevel@tonic-gate 	&tirdwrwinit,
1117c478bd9Sstevel@tonic-gate 	NULL,
1127c478bd9Sstevel@tonic-gate 	NULL
1137c478bd9Sstevel@tonic-gate };
1147c478bd9Sstevel@tonic-gate 
1157c478bd9Sstevel@tonic-gate static struct fmodsw fsw = {
1167c478bd9Sstevel@tonic-gate 	"tirdwr",
1177c478bd9Sstevel@tonic-gate 	&trwinfo,
1187c478bd9Sstevel@tonic-gate 	D_NEW|D_MTQPAIR|D_MP
1197c478bd9Sstevel@tonic-gate };
1207c478bd9Sstevel@tonic-gate 
1217c478bd9Sstevel@tonic-gate static struct modlstrmod modlstrmod = {
1227c478bd9Sstevel@tonic-gate 	&mod_strmodops, "xport interface rd/wr str mod", &fsw
1237c478bd9Sstevel@tonic-gate };
1247c478bd9Sstevel@tonic-gate 
1257c478bd9Sstevel@tonic-gate static struct modlinkage modlinkage = {
1267c478bd9Sstevel@tonic-gate 	MODREV_1, &modlstrmod, NULL
1277c478bd9Sstevel@tonic-gate };
1287c478bd9Sstevel@tonic-gate 
1297c478bd9Sstevel@tonic-gate int
_init(void)1307c478bd9Sstevel@tonic-gate _init(void)
1317c478bd9Sstevel@tonic-gate {
1327c478bd9Sstevel@tonic-gate 	return (mod_install(&modlinkage));
1337c478bd9Sstevel@tonic-gate }
1347c478bd9Sstevel@tonic-gate 
1357c478bd9Sstevel@tonic-gate int
_fini(void)1367c478bd9Sstevel@tonic-gate _fini(void)
1377c478bd9Sstevel@tonic-gate {
1387c478bd9Sstevel@tonic-gate 	return (mod_remove(&modlinkage));
1397c478bd9Sstevel@tonic-gate }
1407c478bd9Sstevel@tonic-gate 
1417c478bd9Sstevel@tonic-gate int
_info(struct modinfo * modinfop)1427c478bd9Sstevel@tonic-gate _info(struct modinfo *modinfop)
1437c478bd9Sstevel@tonic-gate {
1447c478bd9Sstevel@tonic-gate 	return (mod_info(&modlinkage, modinfop));
1457c478bd9Sstevel@tonic-gate }
1467c478bd9Sstevel@tonic-gate 
1477c478bd9Sstevel@tonic-gate static void send_fatal(queue_t *q, mblk_t *mp);
1487c478bd9Sstevel@tonic-gate static void strip_strhead(queue_t *q);
1497c478bd9Sstevel@tonic-gate 
1507c478bd9Sstevel@tonic-gate 
1517c478bd9Sstevel@tonic-gate /*
1527c478bd9Sstevel@tonic-gate  * tirdwropen - open routine gets called when the
1537c478bd9Sstevel@tonic-gate  *		module gets pushed onto the stream.
1547c478bd9Sstevel@tonic-gate  */
1557c478bd9Sstevel@tonic-gate /*ARGSUSED*/
1567c478bd9Sstevel@tonic-gate static int
tirdwropen(queue_t * q,dev_t * dev,int flag,int sflag,cred_t * cr)1577c478bd9Sstevel@tonic-gate tirdwropen(
1587c478bd9Sstevel@tonic-gate 	queue_t *q,
1597c478bd9Sstevel@tonic-gate 	dev_t	*dev,
1607c478bd9Sstevel@tonic-gate 	int flag,
1617c478bd9Sstevel@tonic-gate 	int sflag,
1627c478bd9Sstevel@tonic-gate 	cred_t	*cr)
1637c478bd9Sstevel@tonic-gate {
1647c478bd9Sstevel@tonic-gate 	struct trw_trw *trwptr;
1657c478bd9Sstevel@tonic-gate 
1667c478bd9Sstevel@tonic-gate 	/* check if already open */
1677c478bd9Sstevel@tonic-gate 	if (q->q_ptr) {
1687c478bd9Sstevel@tonic-gate 		return (0);
1697c478bd9Sstevel@tonic-gate 	}
1707c478bd9Sstevel@tonic-gate 
1717c478bd9Sstevel@tonic-gate 	/*
1727c478bd9Sstevel@tonic-gate 	 * Allocate a new trw_trw struct.
1737c478bd9Sstevel@tonic-gate 	 */
1747c478bd9Sstevel@tonic-gate 	trwptr = kmem_alloc(sizeof (struct trw_trw), KM_SLEEP);
1757c478bd9Sstevel@tonic-gate 
1767c478bd9Sstevel@tonic-gate 	/* initialize data structure */
1777c478bd9Sstevel@tonic-gate 	trwptr->trw_flags = 0;
1787c478bd9Sstevel@tonic-gate 	trwptr->trw_rdq = q;
1797c478bd9Sstevel@tonic-gate 	q->q_ptr = (caddr_t)trwptr;
1807c478bd9Sstevel@tonic-gate 	WR(q)->q_ptr = (caddr_t)trwptr;
1817c478bd9Sstevel@tonic-gate 	qprocson(q);
1827c478bd9Sstevel@tonic-gate 
1837c478bd9Sstevel@tonic-gate 	freezestr(q);
1847c478bd9Sstevel@tonic-gate 
1857c478bd9Sstevel@tonic-gate 	(void) strqset(WR(q), QMAXPSZ, 0, (uintptr_t)WR(q)->q_next->q_maxpsz);
1867c478bd9Sstevel@tonic-gate 	(void) strqset(q, QMAXPSZ, 0, (uintptr_t)q->q_next->q_maxpsz);
1877c478bd9Sstevel@tonic-gate 
1887c478bd9Sstevel@tonic-gate 	if (!check_strhead(q)) {
1897c478bd9Sstevel@tonic-gate 		unfreezestr(q);
1907c478bd9Sstevel@tonic-gate 		qprocsoff(q);
1917c478bd9Sstevel@tonic-gate 		kmem_free(trwptr, sizeof (struct trw_trw));
1927c478bd9Sstevel@tonic-gate 		return (EPROTO);
1937c478bd9Sstevel@tonic-gate 	}
1947c478bd9Sstevel@tonic-gate 	strip_strhead(q);
1957c478bd9Sstevel@tonic-gate 	unfreezestr(q);
1967c478bd9Sstevel@tonic-gate 
1977c478bd9Sstevel@tonic-gate 	return (0);
1987c478bd9Sstevel@tonic-gate }
1997c478bd9Sstevel@tonic-gate 
2007c478bd9Sstevel@tonic-gate /*
2017c478bd9Sstevel@tonic-gate  * tirdwrclose - This routine gets called when the module
2027c478bd9Sstevel@tonic-gate  *		gets popped off of the stream.
2037c478bd9Sstevel@tonic-gate  */
2047c478bd9Sstevel@tonic-gate 
2057c478bd9Sstevel@tonic-gate /*ARGSUSED1*/
2067c478bd9Sstevel@tonic-gate static int
tirdwrclose(queue_t * q,int flag,cred_t * cr)2077c478bd9Sstevel@tonic-gate tirdwrclose(queue_t *q, int flag, cred_t *cr)
2087c478bd9Sstevel@tonic-gate {
2097c478bd9Sstevel@tonic-gate 	struct trw_trw *trwptr;
2107c478bd9Sstevel@tonic-gate 	mblk_t *mp;
2117c478bd9Sstevel@tonic-gate 	union T_primitives *pptr;
2127c478bd9Sstevel@tonic-gate 
2137c478bd9Sstevel@tonic-gate 	qprocsoff(q);
2147c478bd9Sstevel@tonic-gate 	trwptr = (struct trw_trw *)q->q_ptr;
2157c478bd9Sstevel@tonic-gate 
2167c478bd9Sstevel@tonic-gate 	ASSERT(trwptr != NULL);
2177c478bd9Sstevel@tonic-gate 
2187c478bd9Sstevel@tonic-gate 	/*
2197c478bd9Sstevel@tonic-gate 	 * Send up a T_DISCON_IND if necessary.
2207c478bd9Sstevel@tonic-gate 	 */
2217c478bd9Sstevel@tonic-gate 	if ((trwptr->trw_flags & ORDREL) && !(trwptr->trw_flags & FATAL))
2227c478bd9Sstevel@tonic-gate 		if (mp = allocb(sizeof (struct T_discon_req), BPRI_LO)) {
2237c478bd9Sstevel@tonic-gate 			pptr = (union T_primitives *)mp->b_rptr;
2247c478bd9Sstevel@tonic-gate 			mp->b_wptr = mp->b_rptr + sizeof (struct T_ordrel_req);
2257c478bd9Sstevel@tonic-gate 			pptr->type = T_ORDREL_REQ;
2267c478bd9Sstevel@tonic-gate 			mp->b_datap->db_type = M_PROTO;
2277c478bd9Sstevel@tonic-gate 			putnext(WR(q), mp);
2287c478bd9Sstevel@tonic-gate 		}
2297c478bd9Sstevel@tonic-gate 
2307c478bd9Sstevel@tonic-gate 	kmem_free(trwptr, sizeof (struct trw_trw));
2317c478bd9Sstevel@tonic-gate 
2327c478bd9Sstevel@tonic-gate 	return (0);
2337c478bd9Sstevel@tonic-gate }
2347c478bd9Sstevel@tonic-gate 
2357c478bd9Sstevel@tonic-gate /*
2367c478bd9Sstevel@tonic-gate  * tirdwrrput - Module read queue put procedure.
2377c478bd9Sstevel@tonic-gate  *		This is called from the module or
2387c478bd9Sstevel@tonic-gate  *		driver downstream.
2397c478bd9Sstevel@tonic-gate  */
2407c478bd9Sstevel@tonic-gate 
241*c6026c81SToomas Soome static int
tirdwrrput(queue_t * q,mblk_t * mp)2427c478bd9Sstevel@tonic-gate tirdwrrput(queue_t *q, mblk_t *mp)
2437c478bd9Sstevel@tonic-gate {
2447c478bd9Sstevel@tonic-gate 	union T_primitives *pptr;
2457c478bd9Sstevel@tonic-gate 	struct trw_trw *trwptr;
2467c478bd9Sstevel@tonic-gate 	mblk_t *tmp;
2477c478bd9Sstevel@tonic-gate 
2487c478bd9Sstevel@tonic-gate 	trwptr = (struct trw_trw *)q->q_ptr;
2497c478bd9Sstevel@tonic-gate 
2507c478bd9Sstevel@tonic-gate 	ASSERT(trwptr != NULL);
2517c478bd9Sstevel@tonic-gate 
2527c478bd9Sstevel@tonic-gate 	if ((trwptr->trw_flags & FATAL) && !(trwptr->trw_flags & WAITACK)) {
2537c478bd9Sstevel@tonic-gate 		freemsg(mp);
254*c6026c81SToomas Soome 		return (0);
2557c478bd9Sstevel@tonic-gate 	}
2567c478bd9Sstevel@tonic-gate 
2577c478bd9Sstevel@tonic-gate 	switch (mp->b_datap->db_type) {
2587c478bd9Sstevel@tonic-gate 
2597c478bd9Sstevel@tonic-gate 	default:
2607c478bd9Sstevel@tonic-gate 		putnext(q, mp);
2617c478bd9Sstevel@tonic-gate 		break;
2627c478bd9Sstevel@tonic-gate 
2637c478bd9Sstevel@tonic-gate 	case M_DATA:
2647c478bd9Sstevel@tonic-gate 		putnext(q, mp);
2657c478bd9Sstevel@tonic-gate 		break;
2667c478bd9Sstevel@tonic-gate 
2677c478bd9Sstevel@tonic-gate 	case M_PCPROTO:
2687c478bd9Sstevel@tonic-gate 	case M_PROTO:
2697c478bd9Sstevel@tonic-gate 		/* is there enough data to check type */
2707c478bd9Sstevel@tonic-gate 		if ((mp->b_wptr - mp->b_rptr) < sizeof (t_scalar_t)) {
2717c478bd9Sstevel@tonic-gate 			/* malformed message */
2727c478bd9Sstevel@tonic-gate 			freemsg(mp);
2737c478bd9Sstevel@tonic-gate 			break;
2747c478bd9Sstevel@tonic-gate 		}
2757c478bd9Sstevel@tonic-gate 		pptr = (union T_primitives *)mp->b_rptr;
2767c478bd9Sstevel@tonic-gate 
2777c478bd9Sstevel@tonic-gate 		switch (pptr->type) {
2787c478bd9Sstevel@tonic-gate 
2797c478bd9Sstevel@tonic-gate 		case T_EXDATA_IND:
2807c478bd9Sstevel@tonic-gate 			send_fatal(q, mp);
2817c478bd9Sstevel@tonic-gate 			break;
2827c478bd9Sstevel@tonic-gate 		case T_DATA_IND:
2837c478bd9Sstevel@tonic-gate 			if (msgdsize(mp) == 0) {
2847c478bd9Sstevel@tonic-gate 				freemsg(mp);
2857c478bd9Sstevel@tonic-gate 				break;
2867c478bd9Sstevel@tonic-gate 			}
2877c478bd9Sstevel@tonic-gate 
2887c478bd9Sstevel@tonic-gate 			tmp = (mblk_t *)unlinkb(mp);
2897c478bd9Sstevel@tonic-gate 			freemsg(mp);
2907c478bd9Sstevel@tonic-gate 			putnext(q, tmp);
2917c478bd9Sstevel@tonic-gate 			break;
2927c478bd9Sstevel@tonic-gate 
2937c478bd9Sstevel@tonic-gate 		case T_ORDREL_IND:
2947c478bd9Sstevel@tonic-gate 			trwptr->trw_flags |= ORDREL;
2957c478bd9Sstevel@tonic-gate 			mp->b_datap->db_type = M_DATA;
2967c478bd9Sstevel@tonic-gate 			mp->b_wptr = mp->b_rptr;
2977c478bd9Sstevel@tonic-gate 			putnext(q, mp);
2987c478bd9Sstevel@tonic-gate 			break;
2997c478bd9Sstevel@tonic-gate 
3007c478bd9Sstevel@tonic-gate 		case T_DISCON_IND:
3017c478bd9Sstevel@tonic-gate 			trwptr->trw_flags |= DISCON;
3027c478bd9Sstevel@tonic-gate 			trwptr->trw_flags &= ~ORDREL;
3037c478bd9Sstevel@tonic-gate 			if (msgdsize(mp) != 0) {
3047c478bd9Sstevel@tonic-gate 				tmp = (mblk_t *)unlinkb(mp);
3057c478bd9Sstevel@tonic-gate 				putnext(q, tmp);
3067c478bd9Sstevel@tonic-gate 			}
3077c478bd9Sstevel@tonic-gate 			mp->b_datap->db_type = M_HANGUP;
3087c478bd9Sstevel@tonic-gate 			mp->b_wptr = mp->b_rptr;
3097c478bd9Sstevel@tonic-gate 			putnext(q, mp);
3107c478bd9Sstevel@tonic-gate 			break;
3117c478bd9Sstevel@tonic-gate 
3127c478bd9Sstevel@tonic-gate 		default:
3137c478bd9Sstevel@tonic-gate 			send_fatal(q, mp);
3147c478bd9Sstevel@tonic-gate 			break;
3157c478bd9Sstevel@tonic-gate 		}
3167c478bd9Sstevel@tonic-gate 	}
317*c6026c81SToomas Soome 	return (0);
3187c478bd9Sstevel@tonic-gate }
3197c478bd9Sstevel@tonic-gate 
3207c478bd9Sstevel@tonic-gate 
3217c478bd9Sstevel@tonic-gate /*
3227c478bd9Sstevel@tonic-gate  * tirdwrwput - Module write queue put procedure.
3237c478bd9Sstevel@tonic-gate  *		This is called from the module or
3247c478bd9Sstevel@tonic-gate  *		stream head upstream.
3257c478bd9Sstevel@tonic-gate  */
326*c6026c81SToomas Soome static int
tirdwrwput(queue_t * q,mblk_t * mp)3277c478bd9Sstevel@tonic-gate tirdwrwput(queue_t *q, mblk_t *mp)
3287c478bd9Sstevel@tonic-gate {
3297c478bd9Sstevel@tonic-gate 	struct trw_trw *trwptr;
3307c478bd9Sstevel@tonic-gate 
3317c478bd9Sstevel@tonic-gate 	trwptr = (struct trw_trw *)q->q_ptr;
3327c478bd9Sstevel@tonic-gate 
3337c478bd9Sstevel@tonic-gate 	ASSERT(trwptr != NULL);
3347c478bd9Sstevel@tonic-gate 
3357c478bd9Sstevel@tonic-gate 	if (trwptr->trw_flags & FATAL) {
3367c478bd9Sstevel@tonic-gate 		freemsg(mp);
337*c6026c81SToomas Soome 		return (0);
3387c478bd9Sstevel@tonic-gate 	}
3397c478bd9Sstevel@tonic-gate 
3407c478bd9Sstevel@tonic-gate 	switch (mp->b_datap->db_type) {
3417c478bd9Sstevel@tonic-gate 	default:
3427c478bd9Sstevel@tonic-gate 		putnext(q, mp);
3437c478bd9Sstevel@tonic-gate 		break;
3447c478bd9Sstevel@tonic-gate 
3457c478bd9Sstevel@tonic-gate 	case M_DATA:
3467c478bd9Sstevel@tonic-gate 		putnext(q, mp);
3477c478bd9Sstevel@tonic-gate 		break;
3487c478bd9Sstevel@tonic-gate 
3497c478bd9Sstevel@tonic-gate 	case M_PROTO:
3507c478bd9Sstevel@tonic-gate 	case M_PCPROTO:
3517c478bd9Sstevel@tonic-gate 		send_fatal(q, mp);
3527c478bd9Sstevel@tonic-gate 		break;
3537c478bd9Sstevel@tonic-gate 	}
354*c6026c81SToomas Soome 	return (0);
3557c478bd9Sstevel@tonic-gate }
3567c478bd9Sstevel@tonic-gate 
3577c478bd9Sstevel@tonic-gate 
3587c478bd9Sstevel@tonic-gate static void
send_fatal(queue_t * q,mblk_t * mp)3597c478bd9Sstevel@tonic-gate send_fatal(queue_t *q, mblk_t *mp)
3607c478bd9Sstevel@tonic-gate {
3617c478bd9Sstevel@tonic-gate 	struct trw_trw *trwptr;
3627c478bd9Sstevel@tonic-gate 
3637c478bd9Sstevel@tonic-gate 	trwptr = (struct trw_trw *)q->q_ptr;
3647c478bd9Sstevel@tonic-gate 
3657c478bd9Sstevel@tonic-gate 	trwptr->trw_flags |= FATAL;
3667c478bd9Sstevel@tonic-gate 	mp->b_datap->db_type = M_ERROR;
3677c478bd9Sstevel@tonic-gate 	*mp->b_datap->db_base = EPROTO;
3687c478bd9Sstevel@tonic-gate 	mp->b_rptr = mp->b_datap->db_base;
3697c478bd9Sstevel@tonic-gate 	mp->b_wptr = mp->b_datap->db_base + sizeof (char);
3707c478bd9Sstevel@tonic-gate 	freemsg(unlinkb(mp));
3717c478bd9Sstevel@tonic-gate 	if (q->q_flag&QREADR)
3727c478bd9Sstevel@tonic-gate 		putnext(q, mp);
3737c478bd9Sstevel@tonic-gate 	else
3747c478bd9Sstevel@tonic-gate 		qreply(q, mp);
3757c478bd9Sstevel@tonic-gate }
3767c478bd9Sstevel@tonic-gate 
3777c478bd9Sstevel@tonic-gate static int
check_strhead(queue_t * q)3787c478bd9Sstevel@tonic-gate check_strhead(queue_t *q)
3797c478bd9Sstevel@tonic-gate {
3807c478bd9Sstevel@tonic-gate 	mblk_t *mp;
3817c478bd9Sstevel@tonic-gate 	union T_primitives *pptr;
3827c478bd9Sstevel@tonic-gate 
3837c478bd9Sstevel@tonic-gate 	for (mp = q->q_next->q_first; mp != NULL; mp = mp->b_next) {
3847c478bd9Sstevel@tonic-gate 
3857c478bd9Sstevel@tonic-gate 		switch (mp->b_datap->db_type) {
3867c478bd9Sstevel@tonic-gate 		case M_PROTO:
3877c478bd9Sstevel@tonic-gate 			pptr = (union T_primitives *)mp->b_rptr;
3887c478bd9Sstevel@tonic-gate 			if ((mp->b_wptr - mp->b_rptr) < sizeof (t_scalar_t))
3897c478bd9Sstevel@tonic-gate 				return (0);
3907c478bd9Sstevel@tonic-gate 			switch (pptr->type) {
3917c478bd9Sstevel@tonic-gate 
3927c478bd9Sstevel@tonic-gate 			case T_EXDATA_IND:
3937c478bd9Sstevel@tonic-gate 				return (0);
3947c478bd9Sstevel@tonic-gate 			case T_DATA_IND:
3957c478bd9Sstevel@tonic-gate 				if (mp->b_cont &&
3967c478bd9Sstevel@tonic-gate 				    (mp->b_cont->b_datap->db_type != M_DATA))
3977c478bd9Sstevel@tonic-gate 					return (0);
3987c478bd9Sstevel@tonic-gate 				break;
3997c478bd9Sstevel@tonic-gate 			default:
4007c478bd9Sstevel@tonic-gate 				return (0);
4017c478bd9Sstevel@tonic-gate 			}
4027c478bd9Sstevel@tonic-gate 			break;
4037c478bd9Sstevel@tonic-gate 
4047c478bd9Sstevel@tonic-gate 		case M_PCPROTO:
4057c478bd9Sstevel@tonic-gate 			return (0);
4067c478bd9Sstevel@tonic-gate 
4077c478bd9Sstevel@tonic-gate 		case M_DATA:
4087c478bd9Sstevel@tonic-gate 		case M_SIG:
4097c478bd9Sstevel@tonic-gate 			break;
4107c478bd9Sstevel@tonic-gate 		default:
4117c478bd9Sstevel@tonic-gate 			return (0);
4127c478bd9Sstevel@tonic-gate 		}
4137c478bd9Sstevel@tonic-gate 	}
4147c478bd9Sstevel@tonic-gate 	return (1);
4157c478bd9Sstevel@tonic-gate }
4167c478bd9Sstevel@tonic-gate 
4177c478bd9Sstevel@tonic-gate static void
strip_strhead(queue_t * q)4187c478bd9Sstevel@tonic-gate strip_strhead(queue_t *q)
4197c478bd9Sstevel@tonic-gate {
4207c478bd9Sstevel@tonic-gate 	mblk_t *mp;
4217c478bd9Sstevel@tonic-gate 	mblk_t *emp;
4227c478bd9Sstevel@tonic-gate 	mblk_t *tmp;
4237c478bd9Sstevel@tonic-gate 	union T_primitives *pptr;
4247c478bd9Sstevel@tonic-gate 
4257c478bd9Sstevel@tonic-gate 	q = q->q_next;
4267c478bd9Sstevel@tonic-gate 	/*CSTYLED*/
4277c478bd9Sstevel@tonic-gate 	for (mp = q->q_first; mp != NULL; ) {
4287c478bd9Sstevel@tonic-gate 
4297c478bd9Sstevel@tonic-gate 		switch (mp->b_datap->db_type) {
4307c478bd9Sstevel@tonic-gate 		case M_PROTO:
4317c478bd9Sstevel@tonic-gate 			pptr = (union T_primitives *)mp->b_rptr;
4327c478bd9Sstevel@tonic-gate 			switch (pptr->type) {
4337c478bd9Sstevel@tonic-gate 
4347c478bd9Sstevel@tonic-gate 			case T_DATA_IND:
4357c478bd9Sstevel@tonic-gate 				if (msgdsize(mp) == 0) {
4367c478bd9Sstevel@tonic-gate strip0:
4377c478bd9Sstevel@tonic-gate 					tmp = mp->b_next;
4387c478bd9Sstevel@tonic-gate 					rmvq(q, mp);
4397c478bd9Sstevel@tonic-gate 					freemsg(mp);
4407c478bd9Sstevel@tonic-gate 					mp = tmp;
4417c478bd9Sstevel@tonic-gate 					break;
4427c478bd9Sstevel@tonic-gate 				}
4437c478bd9Sstevel@tonic-gate 				emp = mp->b_next;
4447c478bd9Sstevel@tonic-gate 				rmvq(q, mp);
4457c478bd9Sstevel@tonic-gate 				tmp = (mblk_t *)unlinkb(mp);
4467c478bd9Sstevel@tonic-gate 				freeb(mp);
4477c478bd9Sstevel@tonic-gate 				(void) insq(q, emp, tmp);
4487c478bd9Sstevel@tonic-gate 				mp = emp;
4497c478bd9Sstevel@tonic-gate 				break;
4507c478bd9Sstevel@tonic-gate 			}
4517c478bd9Sstevel@tonic-gate 			break;
4527c478bd9Sstevel@tonic-gate 
4537c478bd9Sstevel@tonic-gate 		case M_DATA:
4547c478bd9Sstevel@tonic-gate 			if (msgdsize(mp) == 0)
4557c478bd9Sstevel@tonic-gate 				goto strip0;
4567c478bd9Sstevel@tonic-gate 			mp = mp->b_next;
4577c478bd9Sstevel@tonic-gate 			break;
4587c478bd9Sstevel@tonic-gate 
4597c478bd9Sstevel@tonic-gate 		case M_SIG:
4607c478bd9Sstevel@tonic-gate 			mp = mp->b_next;
4617c478bd9Sstevel@tonic-gate 			break;
4627c478bd9Sstevel@tonic-gate 		}
4637c478bd9Sstevel@tonic-gate 	}
4647c478bd9Sstevel@tonic-gate }
465