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
5fc80c0dfSnordmark * Common Development and Distribution License (the "License").
6fc80c0dfSnordmark * 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 */
217c478bd9Sstevel@tonic-gate /*
22fc80c0dfSnordmark * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
237c478bd9Sstevel@tonic-gate * Use is subject to license terms.
24*89b43686SBayard Bell * Copyright (c) 2011 Bayard G. Bell. All rights reserved.
257c478bd9Sstevel@tonic-gate */
267c478bd9Sstevel@tonic-gate
277c478bd9Sstevel@tonic-gate #include <sys/types.h>
287c478bd9Sstevel@tonic-gate #include <sys/conf.h>
297c478bd9Sstevel@tonic-gate #include <sys/modctl.h>
307c478bd9Sstevel@tonic-gate #include <sys/stream.h>
317c478bd9Sstevel@tonic-gate #include <sys/strsubr.h>
327c478bd9Sstevel@tonic-gate #include <sys/strsun.h>
337c478bd9Sstevel@tonic-gate #include <sys/zone.h>
347c478bd9Sstevel@tonic-gate #include <inet/common.h>
357c478bd9Sstevel@tonic-gate #include <inet/led.h>
367c478bd9Sstevel@tonic-gate #include <inet/nd.h>
377c478bd9Sstevel@tonic-gate #include <netinet/in.h>
387c478bd9Sstevel@tonic-gate
397c478bd9Sstevel@tonic-gate #include "ncaconf.h"
407c478bd9Sstevel@tonic-gate
417c478bd9Sstevel@tonic-gate extern caddr_t nca_g_nd; /* Head of 'named dispatch' variable list */
427c478bd9Sstevel@tonic-gate
437c478bd9Sstevel@tonic-gate #define INET_NAME "nca"
44fc80c0dfSnordmark #define INET_MODSTRTAB ncainfo
45fc80c0dfSnordmark #define INET_DEVSTRTAB ncainfo
467c478bd9Sstevel@tonic-gate #define INET_MODDESC "NCA STREAMS module 1.6"
477c478bd9Sstevel@tonic-gate #define INET_DEVDESC "NCA STREAMS driver 1.6"
487c478bd9Sstevel@tonic-gate #define INET_DEVMINOR 0
497c478bd9Sstevel@tonic-gate #define INET_DEVMTFLAGS D_MP
507c478bd9Sstevel@tonic-gate #define INET_MODMTFLAGS D_MP
517c478bd9Sstevel@tonic-gate
527c478bd9Sstevel@tonic-gate #include "../inetddi.c"
537c478bd9Sstevel@tonic-gate
547c478bd9Sstevel@tonic-gate /*ARGSUSED*/
557c478bd9Sstevel@tonic-gate static int
nca_open(queue_t * q,dev_t * devp,int flag,int sflag,cred_t * credp)567c478bd9Sstevel@tonic-gate nca_open(queue_t *q, dev_t *devp, int flag, int sflag, cred_t *credp)
577c478bd9Sstevel@tonic-gate {
587c478bd9Sstevel@tonic-gate /* Reopen supported */
597c478bd9Sstevel@tonic-gate if (q->q_ptr != NULL)
607c478bd9Sstevel@tonic-gate return (0);
617c478bd9Sstevel@tonic-gate
627c478bd9Sstevel@tonic-gate /*
637c478bd9Sstevel@tonic-gate * NCA is not supported in non-global zones; we enforce this restriction
647c478bd9Sstevel@tonic-gate * here.
657c478bd9Sstevel@tonic-gate */
667c478bd9Sstevel@tonic-gate if (credp != NULL && crgetzoneid(credp) != GLOBAL_ZONEID) {
677c478bd9Sstevel@tonic-gate return (ENOTSUP);
687c478bd9Sstevel@tonic-gate }
697c478bd9Sstevel@tonic-gate
707c478bd9Sstevel@tonic-gate if (! (sflag & MODOPEN)) {
717c478bd9Sstevel@tonic-gate /* Device instance */
727c478bd9Sstevel@tonic-gate RD(q)->q_ptr = (void *)B_TRUE;
737c478bd9Sstevel@tonic-gate WR(q)->q_ptr = (void *)B_TRUE;
747c478bd9Sstevel@tonic-gate } else {
757c478bd9Sstevel@tonic-gate /* Modopen just pass through */
767c478bd9Sstevel@tonic-gate RD(q)->q_ptr = (void *)B_FALSE;
777c478bd9Sstevel@tonic-gate WR(q)->q_ptr = (void *)B_FALSE;
787c478bd9Sstevel@tonic-gate }
797c478bd9Sstevel@tonic-gate qprocson(q);
807c478bd9Sstevel@tonic-gate return (0);
817c478bd9Sstevel@tonic-gate }
827c478bd9Sstevel@tonic-gate
837c478bd9Sstevel@tonic-gate static int
nca_close(queue_t * q)847c478bd9Sstevel@tonic-gate nca_close(queue_t *q)
857c478bd9Sstevel@tonic-gate {
867c478bd9Sstevel@tonic-gate qprocsoff(q);
877c478bd9Sstevel@tonic-gate RD(q)->q_ptr = NULL;
887c478bd9Sstevel@tonic-gate WR(q)->q_ptr = NULL;
897c478bd9Sstevel@tonic-gate return (0);
907c478bd9Sstevel@tonic-gate }
917c478bd9Sstevel@tonic-gate
927c478bd9Sstevel@tonic-gate static void
nca_rput(queue_t * q,mblk_t * mp)937c478bd9Sstevel@tonic-gate nca_rput(queue_t *q, mblk_t *mp)
947c478bd9Sstevel@tonic-gate {
957c478bd9Sstevel@tonic-gate /* Passthrough */
967c478bd9Sstevel@tonic-gate putnext(q, mp);
977c478bd9Sstevel@tonic-gate }
987c478bd9Sstevel@tonic-gate
997c478bd9Sstevel@tonic-gate static void
nca_wput(queue_t * q,mblk_t * mp)1007c478bd9Sstevel@tonic-gate nca_wput(queue_t *q, mblk_t *mp)
1017c478bd9Sstevel@tonic-gate {
1027c478bd9Sstevel@tonic-gate struct iocblk *iocp;
1037c478bd9Sstevel@tonic-gate
1047c478bd9Sstevel@tonic-gate if (! (boolean_t)q->q_ptr) {
1057c478bd9Sstevel@tonic-gate iocp = (struct iocblk *)mp->b_rptr;
1067c478bd9Sstevel@tonic-gate if (DB_TYPE(mp) == M_IOCTL && iocp->ioc_cmd == NCA_SET_IF) {
1077c478bd9Sstevel@tonic-gate miocnak(q, mp, 0, ENOTSUP);
1087c478bd9Sstevel@tonic-gate return;
1097c478bd9Sstevel@tonic-gate }
1107c478bd9Sstevel@tonic-gate /* Module, passthrough */
1117c478bd9Sstevel@tonic-gate putnext(q, mp);
1127c478bd9Sstevel@tonic-gate return;
1137c478bd9Sstevel@tonic-gate }
1147c478bd9Sstevel@tonic-gate
1157c478bd9Sstevel@tonic-gate switch (DB_TYPE(mp)) {
1167c478bd9Sstevel@tonic-gate case M_IOCTL:
1177c478bd9Sstevel@tonic-gate iocp = (struct iocblk *)mp->b_rptr;
1187c478bd9Sstevel@tonic-gate switch (iocp->ioc_cmd) {
1197c478bd9Sstevel@tonic-gate case ND_SET:
1207c478bd9Sstevel@tonic-gate case ND_GET:
1217c478bd9Sstevel@tonic-gate if (! nd_getset(q, nca_g_nd, mp)) {
1227c478bd9Sstevel@tonic-gate miocnak(q, mp, 0, ENOENT);
1237c478bd9Sstevel@tonic-gate return;
1247c478bd9Sstevel@tonic-gate }
1257c478bd9Sstevel@tonic-gate qreply(q, mp);
1267c478bd9Sstevel@tonic-gate break;
1277c478bd9Sstevel@tonic-gate default:
1287c478bd9Sstevel@tonic-gate miocnak(q, mp, 0, ENOTSUP);
1297c478bd9Sstevel@tonic-gate break;
1307c478bd9Sstevel@tonic-gate }
1317c478bd9Sstevel@tonic-gate break;
1327c478bd9Sstevel@tonic-gate default:
1337c478bd9Sstevel@tonic-gate freemsg(mp);
1347c478bd9Sstevel@tonic-gate break;
1357c478bd9Sstevel@tonic-gate }
1367c478bd9Sstevel@tonic-gate }
1377c478bd9Sstevel@tonic-gate
1387c478bd9Sstevel@tonic-gate static struct module_info info = {
1397c478bd9Sstevel@tonic-gate 0, "nca", 1, INFPSZ, 65536, 1024
1407c478bd9Sstevel@tonic-gate };
1417c478bd9Sstevel@tonic-gate
1427c478bd9Sstevel@tonic-gate static struct qinit rinit = {
1437c478bd9Sstevel@tonic-gate (pfi_t)nca_rput, NULL, nca_open, nca_close, NULL, &info
1447c478bd9Sstevel@tonic-gate };
1457c478bd9Sstevel@tonic-gate
1467c478bd9Sstevel@tonic-gate static struct qinit winit = {
1477c478bd9Sstevel@tonic-gate (pfi_t)nca_wput, NULL, nca_open, nca_close, NULL, &info
1487c478bd9Sstevel@tonic-gate };
1497c478bd9Sstevel@tonic-gate
1507c478bd9Sstevel@tonic-gate struct streamtab ncainfo = {
1517c478bd9Sstevel@tonic-gate &rinit, &winit
1527c478bd9Sstevel@tonic-gate };
1537c478bd9Sstevel@tonic-gate
1547c478bd9Sstevel@tonic-gate int
_init(void)1557c478bd9Sstevel@tonic-gate _init(void)
1567c478bd9Sstevel@tonic-gate {
1577c478bd9Sstevel@tonic-gate return (mod_install(&modlinkage));
1587c478bd9Sstevel@tonic-gate }
1597c478bd9Sstevel@tonic-gate
1607c478bd9Sstevel@tonic-gate int
_fini(void)1617c478bd9Sstevel@tonic-gate _fini(void)
1627c478bd9Sstevel@tonic-gate {
1637c478bd9Sstevel@tonic-gate return (EBUSY);
1647c478bd9Sstevel@tonic-gate }
1657c478bd9Sstevel@tonic-gate
1667c478bd9Sstevel@tonic-gate int
_info(struct modinfo * modinfop)1677c478bd9Sstevel@tonic-gate _info(struct modinfo *modinfop)
1687c478bd9Sstevel@tonic-gate {
1697c478bd9Sstevel@tonic-gate return (mod_info(&modlinkage, modinfop));
1707c478bd9Sstevel@tonic-gate }
171