strredirm.c revision 8ec5a1426a1784db6978a9712f6228fc7fb382c8
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * CDDL HEADER START
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * The contents of this file are subject to the terms of the
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Common Development and Distribution License (the "License").
199767f8919635c4928607450d9e0abb932109ceToomas Soome * You may not use this file except in compliance with the License.
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
199767f8919635c4928607450d9e0abb932109ceToomas Soome * or http://www.opensolaris.org/os/licensing.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * See the License for the specific language governing permissions
199767f8919635c4928607450d9e0abb932109ceToomas Soome * and limitations under the License.
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * When distributing Covered Code, include this CDDL HEADER in each
199767f8919635c4928607450d9e0abb932109ceToomas Soome * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * If applicable, add the following below this CDDL HEADER, with the
199767f8919635c4928607450d9e0abb932109ceToomas Soome * fields enclosed by brackets "[]" replaced with your own identifying
199767f8919635c4928607450d9e0abb932109ceToomas Soome * information: Portions Copyright [yyyy] [name of copyright owner]
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * CDDL HEADER END
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Use is subject to license terms.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#pragma ident "%Z%%M% %I% %E% SMI"
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Redirection STREAMS module.
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * This module is intended for use in conjunction with instantiations of the
199767f8919635c4928607450d9e0abb932109ceToomas Soome * redirection driver. Its purpose in life is to detect when the stream that
199767f8919635c4928607450d9e0abb932109ceToomas Soome * it's pushed on is closed, thereupon calling back into the redirection
199767f8919635c4928607450d9e0abb932109ceToomas Soome * driver so that the driver can cancel redirection to the stream.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * It passes all messages on unchanged, in both directions.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#include <sys/types.h>
199767f8919635c4928607450d9e0abb932109ceToomas Soome#include <sys/param.h>
199767f8919635c4928607450d9e0abb932109ceToomas Soome#include <sys/errno.h>
199767f8919635c4928607450d9e0abb932109ceToomas Soome#include <sys/stream.h>
199767f8919635c4928607450d9e0abb932109ceToomas Soome#include <sys/stropts.h>
199767f8919635c4928607450d9e0abb932109ceToomas Soome#include <sys/debug.h>
199767f8919635c4928607450d9e0abb932109ceToomas Soome#include <sys/strredir.h>
199767f8919635c4928607450d9e0abb932109ceToomas Soome#include <sys/strsubr.h>
199767f8919635c4928607450d9e0abb932109ceToomas Soome#include <sys/conf.h>
199767f8919635c4928607450d9e0abb932109ceToomas Soome#include <sys/ddi.h>
199767f8919635c4928607450d9e0abb932109ceToomas Soome#include <sys/sunddi.h>
199767f8919635c4928607450d9e0abb932109ceToomas Soome#include <sys/modctl.h>
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Forward declarations for private routines.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic int wcmopen(queue_t *, dev_t *, int, int, cred_t *);
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic int wcmclose(queue_t *, int, cred_t *);
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic int wcmput(queue_t *, mblk_t *);
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic struct module_info wcminfo = {
199767f8919635c4928607450d9e0abb932109ceToomas Soome STRREDIR_MODID,
199767f8919635c4928607450d9e0abb932109ceToomas Soome STRREDIR_MOD,
199767f8919635c4928607450d9e0abb932109ceToomas Soome 0,
199767f8919635c4928607450d9e0abb932109ceToomas Soome INFPSZ,
199767f8919635c4928607450d9e0abb932109ceToomas Soome 5120,
199767f8919635c4928607450d9e0abb932109ceToomas Soome 1024
199767f8919635c4928607450d9e0abb932109ceToomas Soome};
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic struct qinit wcmrinit = {
199767f8919635c4928607450d9e0abb932109ceToomas Soome (int (*)())putnext, /* put */
199767f8919635c4928607450d9e0abb932109ceToomas Soome NULL, /* service */
199767f8919635c4928607450d9e0abb932109ceToomas Soome wcmopen, /* open */
199767f8919635c4928607450d9e0abb932109ceToomas Soome wcmclose, /* close */
199767f8919635c4928607450d9e0abb932109ceToomas Soome NULL, /* qadmin */
199767f8919635c4928607450d9e0abb932109ceToomas Soome &wcminfo,
199767f8919635c4928607450d9e0abb932109ceToomas Soome NULL /* mstat */
199767f8919635c4928607450d9e0abb932109ceToomas Soome};
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic struct qinit wcmwinit = {
199767f8919635c4928607450d9e0abb932109ceToomas Soome (int (*)())putnext, /* put */
199767f8919635c4928607450d9e0abb932109ceToomas Soome NULL, /* service */
199767f8919635c4928607450d9e0abb932109ceToomas Soome wcmopen, /* open */
199767f8919635c4928607450d9e0abb932109ceToomas Soome wcmclose, /* close */
199767f8919635c4928607450d9e0abb932109ceToomas Soome NULL, /* qadmin */
199767f8919635c4928607450d9e0abb932109ceToomas Soome &wcminfo,
199767f8919635c4928607450d9e0abb932109ceToomas Soome NULL /* mstat */
199767f8919635c4928607450d9e0abb932109ceToomas Soome};
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic struct streamtab redirminfo = {
199767f8919635c4928607450d9e0abb932109ceToomas Soome &wcmrinit,
199767f8919635c4928607450d9e0abb932109ceToomas Soome &wcmwinit,
199767f8919635c4928607450d9e0abb932109ceToomas Soome NULL,
199767f8919635c4928607450d9e0abb932109ceToomas Soome NULL
199767f8919635c4928607450d9e0abb932109ceToomas Soome};
199767f8919635c4928607450d9e0abb932109ceToomas Soome
static struct fmodsw fsw = {
"redirmod",
&redirminfo,
D_MP
};
static struct modlstrmod modlstrmod = {
&mod_strmodops,
"redirection module",
&fsw
};
static struct modlinkage modlinkage = {
MODREV_1, &modlstrmod, NULL
};
int
_init()
{
return (mod_install(&modlinkage));
}
int
_fini()
{
return (EBUSY);
}
int
_info(struct modinfo *modinfop)
{
return (mod_info(&modlinkage, modinfop));
}
/* ARGSUSED */
static int
wcmopen(queue_t *q, dev_t *dev, int flag, int sflag, cred_t *cred)
{
if (sflag != MODOPEN)
return (EINVAL);
qprocson(q);
return (0);
}
/* ARGSUSED */
static int
wcmclose(queue_t *q, int flag, cred_t *cred)
{
qprocsoff(q);
srpop(q->q_stream->sd_vnode);
return (0);
}