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 5*8ec5a142Sedp * Common Development and Distribution License (the "License"). 6*8ec5a142Sedp * 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 */ 21*8ec5a142Sedp 227c478bd9Sstevel@tonic-gate /* 23*8ec5a142Sedp * 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 #pragma ident "%Z%%M% %I% %E% SMI" 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate /* 307c478bd9Sstevel@tonic-gate * Redirection STREAMS module. 317c478bd9Sstevel@tonic-gate * 327c478bd9Sstevel@tonic-gate * This module is intended for use in conjunction with instantiations of the 337c478bd9Sstevel@tonic-gate * redirection driver. Its purpose in life is to detect when the stream that 347c478bd9Sstevel@tonic-gate * it's pushed on is closed, thereupon calling back into the redirection 357c478bd9Sstevel@tonic-gate * driver so that the driver can cancel redirection to the stream. 36*8ec5a142Sedp * It passes all messages on unchanged, in both directions. 377c478bd9Sstevel@tonic-gate */ 387c478bd9Sstevel@tonic-gate 397c478bd9Sstevel@tonic-gate #include <sys/types.h> 407c478bd9Sstevel@tonic-gate #include <sys/param.h> 417c478bd9Sstevel@tonic-gate #include <sys/errno.h> 427c478bd9Sstevel@tonic-gate #include <sys/stream.h> 437c478bd9Sstevel@tonic-gate #include <sys/stropts.h> 447c478bd9Sstevel@tonic-gate #include <sys/debug.h> 457c478bd9Sstevel@tonic-gate #include <sys/strredir.h> 46*8ec5a142Sedp #include <sys/strsubr.h> 477c478bd9Sstevel@tonic-gate #include <sys/conf.h> 487c478bd9Sstevel@tonic-gate #include <sys/ddi.h> 497c478bd9Sstevel@tonic-gate #include <sys/sunddi.h> 507c478bd9Sstevel@tonic-gate #include <sys/modctl.h> 517c478bd9Sstevel@tonic-gate 527c478bd9Sstevel@tonic-gate /* 537c478bd9Sstevel@tonic-gate * Forward declarations for private routines. 547c478bd9Sstevel@tonic-gate */ 557c478bd9Sstevel@tonic-gate static int wcmopen(queue_t *, dev_t *, int, int, cred_t *); 567c478bd9Sstevel@tonic-gate static int wcmclose(queue_t *, int, cred_t *); 577c478bd9Sstevel@tonic-gate static int wcmput(queue_t *, mblk_t *); 587c478bd9Sstevel@tonic-gate 597c478bd9Sstevel@tonic-gate static struct module_info wcminfo = { 60*8ec5a142Sedp STRREDIR_MODID, 61*8ec5a142Sedp 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 = { 69*8ec5a142Sedp (int (*)())putnext, /* put */ 707c478bd9Sstevel@tonic-gate NULL, /* service */ 717c478bd9Sstevel@tonic-gate wcmopen, /* open */ 727c478bd9Sstevel@tonic-gate wcmclose, /* close */ 737c478bd9Sstevel@tonic-gate NULL, /* qadmin */ 747c478bd9Sstevel@tonic-gate &wcminfo, 757c478bd9Sstevel@tonic-gate NULL /* mstat */ 767c478bd9Sstevel@tonic-gate }; 777c478bd9Sstevel@tonic-gate 787c478bd9Sstevel@tonic-gate static struct qinit wcmwinit = { 79*8ec5a142Sedp (int (*)())putnext, /* put */ 807c478bd9Sstevel@tonic-gate NULL, /* service */ 817c478bd9Sstevel@tonic-gate wcmopen, /* open */ 827c478bd9Sstevel@tonic-gate wcmclose, /* close */ 837c478bd9Sstevel@tonic-gate NULL, /* qadmin */ 847c478bd9Sstevel@tonic-gate &wcminfo, 857c478bd9Sstevel@tonic-gate 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, 98*8ec5a142Sedp 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 1127c478bd9Sstevel@tonic-gate _init() 1137c478bd9Sstevel@tonic-gate { 1147c478bd9Sstevel@tonic-gate return (mod_install(&modlinkage)); 1157c478bd9Sstevel@tonic-gate } 1167c478bd9Sstevel@tonic-gate 1177c478bd9Sstevel@tonic-gate int 1187c478bd9Sstevel@tonic-gate _fini() 1197c478bd9Sstevel@tonic-gate { 1207c478bd9Sstevel@tonic-gate return (EBUSY); 1217c478bd9Sstevel@tonic-gate } 1227c478bd9Sstevel@tonic-gate 1237c478bd9Sstevel@tonic-gate int 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 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 1417c478bd9Sstevel@tonic-gate wcmclose(queue_t *q, int flag, cred_t *cred) 1427c478bd9Sstevel@tonic-gate { 1437c478bd9Sstevel@tonic-gate qprocsoff(q); 144*8ec5a142Sedp srpop(q->q_stream->sd_vnode); 1457c478bd9Sstevel@tonic-gate return (0); 1467c478bd9Sstevel@tonic-gate } 147