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
58ec5a142Sedp * Common Development and Distribution License (the "License").
68ec5a142Sedp * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate *
87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate * and limitations under the License.
127c478bd9Sstevel@tonic-gate *
137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate *
197c478bd9Sstevel@tonic-gate * CDDL HEADER END
207c478bd9Sstevel@tonic-gate */
218ec5a142Sedp
227c478bd9Sstevel@tonic-gate /*
238ec5a142Sedp * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
247c478bd9Sstevel@tonic-gate * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate */
267c478bd9Sstevel@tonic-gate
277c478bd9Sstevel@tonic-gate /*
287c478bd9Sstevel@tonic-gate * Redirection STREAMS module.
297c478bd9Sstevel@tonic-gate *
307c478bd9Sstevel@tonic-gate * This module is intended for use in conjunction with instantiations of the
317c478bd9Sstevel@tonic-gate * redirection driver. Its purpose in life is to detect when the stream that
327c478bd9Sstevel@tonic-gate * it's pushed on is closed, thereupon calling back into the redirection
337c478bd9Sstevel@tonic-gate * driver so that the driver can cancel redirection to the stream.
348ec5a142Sedp * It passes all messages on unchanged, in both directions.
357c478bd9Sstevel@tonic-gate */
367c478bd9Sstevel@tonic-gate
377c478bd9Sstevel@tonic-gate #include <sys/types.h>
387c478bd9Sstevel@tonic-gate #include <sys/param.h>
397c478bd9Sstevel@tonic-gate #include <sys/errno.h>
407c478bd9Sstevel@tonic-gate #include <sys/stream.h>
417c478bd9Sstevel@tonic-gate #include <sys/stropts.h>
427c478bd9Sstevel@tonic-gate #include <sys/debug.h>
437c478bd9Sstevel@tonic-gate #include <sys/strredir.h>
448ec5a142Sedp #include <sys/strsubr.h>
45e493d0faSns #include <sys/strsun.h>
467c478bd9Sstevel@tonic-gate #include <sys/conf.h>
477c478bd9Sstevel@tonic-gate #include <sys/ddi.h>
487c478bd9Sstevel@tonic-gate #include <sys/sunddi.h>
497c478bd9Sstevel@tonic-gate #include <sys/modctl.h>
507c478bd9Sstevel@tonic-gate
517c478bd9Sstevel@tonic-gate /*
527c478bd9Sstevel@tonic-gate * Forward declarations for private routines.
537c478bd9Sstevel@tonic-gate */
547c478bd9Sstevel@tonic-gate static int wcmopen(queue_t *, dev_t *, int, int, cred_t *);
557c478bd9Sstevel@tonic-gate static int wcmclose(queue_t *, int, cred_t *);
56e493d0faSns static int wcmrput(queue_t *, mblk_t *);
57*203710acSToomas Soome static int wcmwput(queue_t *, mblk_t *);
587c478bd9Sstevel@tonic-gate
597c478bd9Sstevel@tonic-gate static struct module_info wcminfo = {
608ec5a142Sedp STRREDIR_MODID,
618ec5a142Sedp STRREDIR_MOD,
627c478bd9Sstevel@tonic-gate 0,
637c478bd9Sstevel@tonic-gate INFPSZ,
647c478bd9Sstevel@tonic-gate 5120,
657c478bd9Sstevel@tonic-gate 1024
667c478bd9Sstevel@tonic-gate };
677c478bd9Sstevel@tonic-gate
687c478bd9Sstevel@tonic-gate static struct qinit wcmrinit = {
69e493d0faSns wcmrput, /* put */
708ec5a142Sedp NULL, /* service */
718ec5a142Sedp wcmopen, /* open */
728ec5a142Sedp wcmclose, /* close */
738ec5a142Sedp NULL, /* qadmin */
747c478bd9Sstevel@tonic-gate &wcminfo,
758ec5a142Sedp NULL /* mstat */
767c478bd9Sstevel@tonic-gate };
777c478bd9Sstevel@tonic-gate
787c478bd9Sstevel@tonic-gate static struct qinit wcmwinit = {
79*203710acSToomas Soome wcmwput, /* put */
808ec5a142Sedp NULL, /* service */
818ec5a142Sedp wcmopen, /* open */
828ec5a142Sedp wcmclose, /* close */
838ec5a142Sedp NULL, /* qadmin */
847c478bd9Sstevel@tonic-gate &wcminfo,
858ec5a142Sedp NULL /* mstat */
867c478bd9Sstevel@tonic-gate };
877c478bd9Sstevel@tonic-gate
887c478bd9Sstevel@tonic-gate static struct streamtab redirminfo = {
897c478bd9Sstevel@tonic-gate &wcmrinit,
907c478bd9Sstevel@tonic-gate &wcmwinit,
917c478bd9Sstevel@tonic-gate NULL,
927c478bd9Sstevel@tonic-gate NULL
937c478bd9Sstevel@tonic-gate };
947c478bd9Sstevel@tonic-gate
957c478bd9Sstevel@tonic-gate static struct fmodsw fsw = {
967c478bd9Sstevel@tonic-gate "redirmod",
977c478bd9Sstevel@tonic-gate &redirminfo,
988ec5a142Sedp D_MP
997c478bd9Sstevel@tonic-gate };
1007c478bd9Sstevel@tonic-gate
1017c478bd9Sstevel@tonic-gate static struct modlstrmod modlstrmod = {
1027c478bd9Sstevel@tonic-gate &mod_strmodops,
1037c478bd9Sstevel@tonic-gate "redirection module",
1047c478bd9Sstevel@tonic-gate &fsw
1057c478bd9Sstevel@tonic-gate };
1067c478bd9Sstevel@tonic-gate
1077c478bd9Sstevel@tonic-gate static struct modlinkage modlinkage = {
1087c478bd9Sstevel@tonic-gate MODREV_1, &modlstrmod, NULL
1097c478bd9Sstevel@tonic-gate };
1107c478bd9Sstevel@tonic-gate
1117c478bd9Sstevel@tonic-gate int
_init()1127c478bd9Sstevel@tonic-gate _init()
1137c478bd9Sstevel@tonic-gate {
1147c478bd9Sstevel@tonic-gate return (mod_install(&modlinkage));
1157c478bd9Sstevel@tonic-gate }
1167c478bd9Sstevel@tonic-gate
1177c478bd9Sstevel@tonic-gate int
_fini()1187c478bd9Sstevel@tonic-gate _fini()
1197c478bd9Sstevel@tonic-gate {
1207c478bd9Sstevel@tonic-gate return (EBUSY);
1217c478bd9Sstevel@tonic-gate }
1227c478bd9Sstevel@tonic-gate
1237c478bd9Sstevel@tonic-gate int
_info(struct modinfo * modinfop)1247c478bd9Sstevel@tonic-gate _info(struct modinfo *modinfop)
1257c478bd9Sstevel@tonic-gate {
1267c478bd9Sstevel@tonic-gate return (mod_info(&modlinkage, modinfop));
1277c478bd9Sstevel@tonic-gate }
1287c478bd9Sstevel@tonic-gate
1297c478bd9Sstevel@tonic-gate /* ARGSUSED */
1307c478bd9Sstevel@tonic-gate static int
wcmopen(queue_t * q,dev_t * dev,int flag,int sflag,cred_t * cred)1317c478bd9Sstevel@tonic-gate wcmopen(queue_t *q, dev_t *dev, int flag, int sflag, cred_t *cred)
1327c478bd9Sstevel@tonic-gate {
1337c478bd9Sstevel@tonic-gate if (sflag != MODOPEN)
1347c478bd9Sstevel@tonic-gate return (EINVAL);
1357c478bd9Sstevel@tonic-gate qprocson(q);
1367c478bd9Sstevel@tonic-gate return (0);
1377c478bd9Sstevel@tonic-gate }
1387c478bd9Sstevel@tonic-gate
1397c478bd9Sstevel@tonic-gate /* ARGSUSED */
1407c478bd9Sstevel@tonic-gate static int
wcmclose(queue_t * q,int flag,cred_t * cred)1417c478bd9Sstevel@tonic-gate wcmclose(queue_t *q, int flag, cred_t *cred)
1427c478bd9Sstevel@tonic-gate {
1437c478bd9Sstevel@tonic-gate qprocsoff(q);
144e493d0faSns srpop(q->q_stream->sd_vnode, B_TRUE);
145e493d0faSns return (0);
146e493d0faSns }
147e493d0faSns
148e493d0faSns /*
149e493d0faSns * Upstream messages are passed unchanged.
150e493d0faSns * If a hangup occurs the target is no longer usable, so deprecate it.
151e493d0faSns */
152e493d0faSns static int
wcmrput(queue_t * q,mblk_t * mp)153e493d0faSns wcmrput(queue_t *q, mblk_t *mp)
154e493d0faSns {
155e493d0faSns if (DB_TYPE(mp) == M_HANGUP)
156e493d0faSns /* Don't block waiting for outstanding operations to complete */
157e493d0faSns srpop(q->q_stream->sd_vnode, B_FALSE);
158e493d0faSns putnext(q, mp);
1597c478bd9Sstevel@tonic-gate return (0);
1607c478bd9Sstevel@tonic-gate }
161*203710acSToomas Soome
162*203710acSToomas Soome static int
wcmwput(queue_t * q,mblk_t * mp)163*203710acSToomas Soome wcmwput(queue_t *q, mblk_t *mp)
164*203710acSToomas Soome {
165*203710acSToomas Soome putnext(q, mp);
166*203710acSToomas Soome return (0);
167*203710acSToomas Soome }
168