xref: /illumos-gate/usr/src/uts/common/inet/ip/ip_dummy.c (revision 8a06b3d6)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #include <sys/types.h>
27 #include <sys/conf.h>
28 #include <sys/modctl.h>
29 #include <inet/common.h>
30 
31 /*
32  * Dummy streams module that is used by ICMP, UDP, and TCP by setting
33  * INETMODSTRTAB to dummymodinfo
34  *
35  * It's reason for existance is so that mibopen() that I_PUSH icmp, udp, and
36  * tcp can continue to push modules with those names, even though all the
37  * MIB information comes from IP.
38  */
39 
40 static int	dummy_wput(queue_t *, mblk_t *);
41 static int	dummy_modclose(queue_t *, int, cred_t *);
42 static int	dummy_modopen(queue_t *q, dev_t *devp, int flag,
43 		    int sflag, cred_t *credp);
44 
45 /*
46  * This is common code for the tcp, udp, and icmp streams module which is
47  * an empty STREAMS module provided for compatibility for mibopen()
48  * code which I_PUSH modules with those names.
49  */
50 struct module_info dummy_mod_info = {
51 	5799, "dummymod", 1, INFPSZ, 65536, 1024
52 };
53 
54 
55 static struct qinit dummyrmodinit = {
56 	dummy_wput, NULL, dummy_modopen, dummy_modclose, NULL,
57 	&dummy_mod_info
58 };
59 
60 static struct qinit dummywmodinit = {
61 	dummy_wput, NULL, NULL, NULL, NULL, &dummy_mod_info
62 };
63 
64 struct streamtab dummymodinfo = {
65 	&dummyrmodinit, &dummywmodinit
66 };
67 
68 /* ARGSUSED */
69 static int
dummy_wput(queue_t * q,mblk_t * m)70 dummy_wput(queue_t *q, mblk_t *m)
71 {
72 	putnext(q, m);
73 	return (0);
74 }
75 
76 static int
dummy_modclose(queue_t * q,int flags __unused,cred_t * credp __unused)77 dummy_modclose(queue_t *q, int flags __unused, cred_t *credp __unused)
78 {
79 	qprocsoff(q);
80 	return (0);
81 }
82 
83 /* ARGSUSED */
84 static int
dummy_modopen(queue_t * q,dev_t * devp,int flag,int sflag,cred_t * credp)85 dummy_modopen(queue_t *q, dev_t *devp, int flag, int sflag, cred_t *credp)
86 {
87 	/* If the stream is already open, return immediately. */
88 	if (q->q_ptr != NULL)
89 		return (0);
90 
91 	/* If this is not a push of dummy as a module, fail. */
92 	if (sflag != MODOPEN)
93 		return (EINVAL);
94 
95 	qprocson(q);
96 	return (0);
97 }
98