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
51907Sedp * Common Development and Distribution License (the "License").
61907Sedp * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate *
80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate * See the License for the specific language governing permissions
110Sstevel@tonic-gate * and limitations under the License.
120Sstevel@tonic-gate *
130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate *
190Sstevel@tonic-gate * CDDL HEADER END
200Sstevel@tonic-gate */
211907Sedp
220Sstevel@tonic-gate /*
231907Sedp * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
240Sstevel@tonic-gate * Use is subject to license terms.
250Sstevel@tonic-gate */
260Sstevel@tonic-gate
270Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
280Sstevel@tonic-gate
290Sstevel@tonic-gate /*
300Sstevel@tonic-gate * Redirection STREAMS module.
310Sstevel@tonic-gate *
320Sstevel@tonic-gate * This module is intended for use in conjunction with instantiations of the
330Sstevel@tonic-gate * redirection driver. Its purpose in life is to detect when the stream that
340Sstevel@tonic-gate * it's pushed on is closed, thereupon calling back into the redirection
350Sstevel@tonic-gate * driver so that the driver can cancel redirection to the stream.
361907Sedp * It passes all messages on unchanged, in both directions.
370Sstevel@tonic-gate */
380Sstevel@tonic-gate
390Sstevel@tonic-gate #include <sys/types.h>
400Sstevel@tonic-gate #include <sys/param.h>
410Sstevel@tonic-gate #include <sys/errno.h>
420Sstevel@tonic-gate #include <sys/stream.h>
430Sstevel@tonic-gate #include <sys/stropts.h>
440Sstevel@tonic-gate #include <sys/debug.h>
450Sstevel@tonic-gate #include <sys/strredir.h>
461907Sedp #include <sys/strsubr.h>
47*2485Sns92644 #include <sys/strsun.h>
480Sstevel@tonic-gate #include <sys/conf.h>
490Sstevel@tonic-gate #include <sys/ddi.h>
500Sstevel@tonic-gate #include <sys/sunddi.h>
510Sstevel@tonic-gate #include <sys/modctl.h>
520Sstevel@tonic-gate
530Sstevel@tonic-gate /*
540Sstevel@tonic-gate * Forward declarations for private routines.
550Sstevel@tonic-gate */
560Sstevel@tonic-gate static int wcmopen(queue_t *, dev_t *, int, int, cred_t *);
570Sstevel@tonic-gate static int wcmclose(queue_t *, int, cred_t *);
58*2485Sns92644 static int wcmrput(queue_t *, mblk_t *);
590Sstevel@tonic-gate
600Sstevel@tonic-gate static struct module_info wcminfo = {
611907Sedp STRREDIR_MODID,
621907Sedp STRREDIR_MOD,
630Sstevel@tonic-gate 0,
640Sstevel@tonic-gate INFPSZ,
650Sstevel@tonic-gate 5120,
660Sstevel@tonic-gate 1024
670Sstevel@tonic-gate };
680Sstevel@tonic-gate
690Sstevel@tonic-gate static struct qinit wcmrinit = {
70*2485Sns92644 wcmrput, /* put */
711907Sedp NULL, /* service */
721907Sedp wcmopen, /* open */
731907Sedp wcmclose, /* close */
741907Sedp NULL, /* qadmin */
750Sstevel@tonic-gate &wcminfo,
761907Sedp NULL /* mstat */
770Sstevel@tonic-gate };
780Sstevel@tonic-gate
790Sstevel@tonic-gate static struct qinit wcmwinit = {
801907Sedp (int (*)())putnext, /* put */
811907Sedp NULL, /* service */
821907Sedp wcmopen, /* open */
831907Sedp wcmclose, /* close */
841907Sedp NULL, /* qadmin */
850Sstevel@tonic-gate &wcminfo,
861907Sedp NULL /* mstat */
870Sstevel@tonic-gate };
880Sstevel@tonic-gate
890Sstevel@tonic-gate static struct streamtab redirminfo = {
900Sstevel@tonic-gate &wcmrinit,
910Sstevel@tonic-gate &wcmwinit,
920Sstevel@tonic-gate NULL,
930Sstevel@tonic-gate NULL
940Sstevel@tonic-gate };
950Sstevel@tonic-gate
960Sstevel@tonic-gate static struct fmodsw fsw = {
970Sstevel@tonic-gate "redirmod",
980Sstevel@tonic-gate &redirminfo,
991907Sedp D_MP
1000Sstevel@tonic-gate };
1010Sstevel@tonic-gate
1020Sstevel@tonic-gate static struct modlstrmod modlstrmod = {
1030Sstevel@tonic-gate &mod_strmodops,
1040Sstevel@tonic-gate "redirection module",
1050Sstevel@tonic-gate &fsw
1060Sstevel@tonic-gate };
1070Sstevel@tonic-gate
1080Sstevel@tonic-gate static struct modlinkage modlinkage = {
1090Sstevel@tonic-gate MODREV_1, &modlstrmod, NULL
1100Sstevel@tonic-gate };
1110Sstevel@tonic-gate
1120Sstevel@tonic-gate int
_init()1130Sstevel@tonic-gate _init()
1140Sstevel@tonic-gate {
1150Sstevel@tonic-gate return (mod_install(&modlinkage));
1160Sstevel@tonic-gate }
1170Sstevel@tonic-gate
1180Sstevel@tonic-gate int
_fini()1190Sstevel@tonic-gate _fini()
1200Sstevel@tonic-gate {
1210Sstevel@tonic-gate return (EBUSY);
1220Sstevel@tonic-gate }
1230Sstevel@tonic-gate
1240Sstevel@tonic-gate int
_info(struct modinfo * modinfop)1250Sstevel@tonic-gate _info(struct modinfo *modinfop)
1260Sstevel@tonic-gate {
1270Sstevel@tonic-gate return (mod_info(&modlinkage, modinfop));
1280Sstevel@tonic-gate }
1290Sstevel@tonic-gate
1300Sstevel@tonic-gate /* ARGSUSED */
1310Sstevel@tonic-gate static int
wcmopen(queue_t * q,dev_t * dev,int flag,int sflag,cred_t * cred)1320Sstevel@tonic-gate wcmopen(queue_t *q, dev_t *dev, int flag, int sflag, cred_t *cred)
1330Sstevel@tonic-gate {
1340Sstevel@tonic-gate if (sflag != MODOPEN)
1350Sstevel@tonic-gate return (EINVAL);
1360Sstevel@tonic-gate qprocson(q);
1370Sstevel@tonic-gate return (0);
1380Sstevel@tonic-gate }
1390Sstevel@tonic-gate
1400Sstevel@tonic-gate /* ARGSUSED */
1410Sstevel@tonic-gate static int
wcmclose(queue_t * q,int flag,cred_t * cred)1420Sstevel@tonic-gate wcmclose(queue_t *q, int flag, cred_t *cred)
1430Sstevel@tonic-gate {
1440Sstevel@tonic-gate qprocsoff(q);
145*2485Sns92644 srpop(q->q_stream->sd_vnode, B_TRUE);
1460Sstevel@tonic-gate return (0);
1470Sstevel@tonic-gate }
148*2485Sns92644
149*2485Sns92644 /*
150*2485Sns92644 * Upstream messages are passed unchanged.
151*2485Sns92644 * If a hangup occurs the target is no longer usable, so deprecate it.
152*2485Sns92644 */
153*2485Sns92644 static int
wcmrput(queue_t * q,mblk_t * mp)154*2485Sns92644 wcmrput(queue_t *q, mblk_t *mp)
155*2485Sns92644 {
156*2485Sns92644 if (DB_TYPE(mp) == M_HANGUP)
157*2485Sns92644 /* Don't block waiting for outstanding operations to complete */
158*2485Sns92644 srpop(q->q_stream->sd_vnode, B_FALSE);
159*2485Sns92644 putnext(q, mp);
160*2485Sns92644 return (0);
161*2485Sns92644 }
162