9903 qinfo: add typed members
[unleashed.git] / usr / src / uts / common / inet / nca / ncaddi.c
blobe4fa85ef001344f442070297464d7e4bff0a76fd
1 /*
2 * CDDL HEADER START
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.
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.
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]
19 * CDDL HEADER END
22 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
24 * Copyright (c) 2011 Bayard G. Bell. All rights reserved.
27 #include <sys/types.h>
28 #include <sys/conf.h>
29 #include <sys/modctl.h>
30 #include <sys/stream.h>
31 #include <sys/strsubr.h>
32 #include <sys/strsun.h>
33 #include <sys/zone.h>
34 #include <inet/common.h>
35 #include <inet/led.h>
36 #include <inet/nd.h>
37 #include <netinet/in.h>
39 #include "ncaconf.h"
41 extern caddr_t nca_g_nd; /* Head of 'named dispatch' variable list */
43 #define INET_NAME "nca"
44 #define INET_MODSTRTAB ncainfo
45 #define INET_DEVSTRTAB ncainfo
46 #define INET_MODDESC "NCA STREAMS module 1.6"
47 #define INET_DEVDESC "NCA STREAMS driver 1.6"
48 #define INET_DEVMINOR 0
49 #define INET_DEVMTFLAGS D_MP
50 #define INET_MODMTFLAGS D_MP
52 #include "../inetddi.c"
54 /*ARGSUSED*/
55 static int
56 nca_open(queue_t *q, dev_t *devp, int flag, int sflag, cred_t *credp)
58 /* Reopen supported */
59 if (q->q_ptr != NULL)
60 return (0);
63 * NCA is not supported in non-global zones; we enforce this restriction
64 * here.
66 if (credp != NULL && crgetzoneid(credp) != GLOBAL_ZONEID) {
67 return (ENOTSUP);
70 if (! (sflag & MODOPEN)) {
71 /* Device instance */
72 RD(q)->q_ptr = (void *)B_TRUE;
73 WR(q)->q_ptr = (void *)B_TRUE;
74 } else {
75 /* Modopen just pass through */
76 RD(q)->q_ptr = (void *)B_FALSE;
77 WR(q)->q_ptr = (void *)B_FALSE;
79 qprocson(q);
80 return (0);
83 /* ARGSUSED */
84 static int
85 nca_close(queue_t *q, int flags __unused, cred_t *credp __unused)
87 qprocsoff(q);
88 RD(q)->q_ptr = NULL;
89 WR(q)->q_ptr = NULL;
90 return (0);
93 static void
94 nca_rput(queue_t *q, mblk_t *mp)
96 /* Passthrough */
97 putnext(q, mp);
100 static void
101 nca_wput(queue_t *q, mblk_t *mp)
103 struct iocblk *iocp;
105 if (! (boolean_t)q->q_ptr) {
106 iocp = (struct iocblk *)mp->b_rptr;
107 if (DB_TYPE(mp) == M_IOCTL && iocp->ioc_cmd == NCA_SET_IF) {
108 miocnak(q, mp, 0, ENOTSUP);
109 return;
111 /* Module, passthrough */
112 putnext(q, mp);
113 return;
116 switch (DB_TYPE(mp)) {
117 case M_IOCTL:
118 iocp = (struct iocblk *)mp->b_rptr;
119 switch (iocp->ioc_cmd) {
120 case ND_SET:
121 case ND_GET:
122 if (! nd_getset(q, nca_g_nd, mp)) {
123 miocnak(q, mp, 0, ENOENT);
124 return;
126 qreply(q, mp);
127 break;
128 default:
129 miocnak(q, mp, 0, ENOTSUP);
130 break;
132 break;
133 default:
134 freemsg(mp);
135 break;
139 static struct module_info info = {
140 0, "nca", 1, INFPSZ, 65536, 1024
143 static struct qinit rinit = {
144 (pfi_t)nca_rput, NULL, nca_open, nca_close, NULL, &info
147 static struct qinit winit = {
148 (pfi_t)nca_wput, NULL, nca_open, nca_close, NULL, &info
151 struct streamtab ncainfo = {
152 &rinit, &winit
156 _init(void)
158 return (mod_install(&modlinkage));
162 _fini(void)
164 return (EBUSY);
168 _info(struct modinfo *modinfop)
170 return (mod_info(&modlinkage, modinfop));