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 5f4b3ec61Sdh155122 * Common Development and Distribution License (the "License"). 6f4b3ec61Sdh155122 * 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 /* 22*3e95bd4aSAnders Persson * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved. 237c478bd9Sstevel@tonic-gate */ 247c478bd9Sstevel@tonic-gate 257c478bd9Sstevel@tonic-gate #include <sys/types.h> 267c478bd9Sstevel@tonic-gate #include <sys/stat.h> 277c478bd9Sstevel@tonic-gate #include <sys/stream.h> 287c478bd9Sstevel@tonic-gate #include <sys/ddi.h> 297c478bd9Sstevel@tonic-gate #include <sys/sunddi.h> 307c478bd9Sstevel@tonic-gate #include <sys/priv_names.h> 317c478bd9Sstevel@tonic-gate 327c478bd9Sstevel@tonic-gate /* 337c478bd9Sstevel@tonic-gate * This file contains generic goo needed to hook the STREAMS modules and 347c478bd9Sstevel@tonic-gate * drivers that live under uts/common/inet into the DDI. In order to use it, 357c478bd9Sstevel@tonic-gate * each module/driver should #define the symbols below (as appropriate) and 367c478bd9Sstevel@tonic-gate * then #include this source file; see the other uts/common/inet/<star>ddi.c 377c478bd9Sstevel@tonic-gate * files for examples of this in action. 387c478bd9Sstevel@tonic-gate * 397c478bd9Sstevel@tonic-gate * The symbols that all modules and drivers must define are: 407c478bd9Sstevel@tonic-gate * 417c478bd9Sstevel@tonic-gate * INET_NAME The name of the module/driver. 427c478bd9Sstevel@tonic-gate * 437c478bd9Sstevel@tonic-gate * The symbols that all modules must define are: 447c478bd9Sstevel@tonic-gate * 45fc80c0dfSnordmark * INET_MODSTRTAB The name of the `streamtab' structure for this module. 467c478bd9Sstevel@tonic-gate * INET_MODDESC The one-line description for this module. 477c478bd9Sstevel@tonic-gate * INET_MODMTFLAGS The mt-streams(9F) flags for the module. 487c478bd9Sstevel@tonic-gate * 497c478bd9Sstevel@tonic-gate * The symbols that all drivers must define are: 507c478bd9Sstevel@tonic-gate * 51fc80c0dfSnordmark * INET_DEVSTRTAB The name of the `streamtab' structure for this driver. 527c478bd9Sstevel@tonic-gate * INET_DEVDESC The one-line description for this driver. 537c478bd9Sstevel@tonic-gate * INET_DEVMTFLAGS The mt-streams(9F) flags for the driver. 547c478bd9Sstevel@tonic-gate * INET_DEVMINOR The minor number of the driver (usually 0). 557c478bd9Sstevel@tonic-gate * 567c478bd9Sstevel@tonic-gate * Drivers that need to masquerade as IP should set INET_DEVMTFLAGS to 57fc80c0dfSnordmark * IP_DEVMTFLAGS and set INET_DEVSTRTAB to ipinfo. 580f1702c5SYu Xiangning * 590f1702c5SYu Xiangning * The symbols that all socket modules must define are: 600f1702c5SYu Xiangning * 610f1702c5SYu Xiangning * INET_SOCKDESC The one-line description for this socket module 620f1702c5SYu Xiangning * INET_SOCK_PROTO_CREATE_FUNC The function used to create PCBs 630f1702c5SYu Xiangning * 640f1702c5SYu Xiangning * In addition, socket modules that can be converted to TPI must define: 650f1702c5SYu Xiangning * 660f1702c5SYu Xiangning * INET_SOCK_PROTO_FB_FUNC The function used to fallback to TPI 677c478bd9Sstevel@tonic-gate */ 687c478bd9Sstevel@tonic-gate 69fc80c0dfSnordmark #if !defined(INET_NAME) 707c478bd9Sstevel@tonic-gate #error inetddi.c: INET_NAME is not defined! 710f1702c5SYu Xiangning #elif !defined(INET_DEVDESC) && !defined(INET_MODDESC) && \ 720f1702c5SYu Xiangning !defined(INET_SOCKDESC) 730f1702c5SYu Xiangning #error inetddi.c: at least one of INET_DEVDESC or INET_MODDESC or \ 740f1702c5SYu Xiangning INET_SOCKDESC must be defined! 75fc80c0dfSnordmark #elif defined(INET_DEVDESC) && !defined(INET_DEVSTRTAB) 76fc80c0dfSnordmark #error inetddi.c: INET_DEVDESC is defined but INET_DEVSTRTAB is not! 777c478bd9Sstevel@tonic-gate #elif defined(INET_DEVDESC) && !defined(INET_DEVMTFLAGS) 787c478bd9Sstevel@tonic-gate #error inetddi.c: INET_DEVDESC is defined but INET_DEVMTFLAGS is not! 797c478bd9Sstevel@tonic-gate #elif defined(INET_DEVDESC) && !defined(INET_DEVMINOR) 807c478bd9Sstevel@tonic-gate #error inetddi.c: INET_DEVDESC is defined but INET_DEVMINOR is not! 81fc80c0dfSnordmark #elif defined(INET_MODDESC) && !defined(INET_MODSTRTAB) 82fc80c0dfSnordmark #error inetddi.c: INET_MODDESC is defined but INET_MODSTRTAB is not! 837c478bd9Sstevel@tonic-gate #elif defined(INET_MODDESC) && !defined(INET_MODMTFLAGS) 847c478bd9Sstevel@tonic-gate #error inetddi.c: INET_MODDESC is defined but INET_MODMTFLAGS is not! 850f1702c5SYu Xiangning #elif defined(INET_SOCKDESC) && !defined(SOCKMOD_VERSION) 860f1702c5SYu Xiangning #error inetddi.c: INET_SOCKDESC is defined but SOCKMOD_VERSION is not! 870f1702c5SYu Xiangning #elif defined(INET_SOCKDESC) && !defined(INET_SOCK_PROTO_CREATE_FUNC) 880f1702c5SYu Xiangning #error inetddi.c: INET_SOCKDESC is defined but INET_SOCK_PROTO_CREATE_FUNC \ 890f1702c5SYu Xiangning is not! 90*3e95bd4aSAnders Persson #elif defined(INET_SOCK_PROTO_FB_FUNC) && !defined(INET_SOCK_FALLBACK_DEV_V4) 91*3e95bd4aSAnders Persson #error inetddi.c: INET_SOCK_PROTO_FB_FUNC is defined but \ 92*3e95bd4aSAnders Persson INET_SOCK_FALLBACK_DEV_V4 is not! 93*3e95bd4aSAnders Persson #elif defined(INET_SOCK_PROTO_FB_FUNC) && !defined(INET_SOCK_FALLBACK_DEV_V6) 94*3e95bd4aSAnders Persson #error inetddi.c: INET_SOCK_PROTO_FB_FUNC is defined but \ 95*3e95bd4aSAnders Persson INET_SOCK_FALLBACK_DEV_V6 is not! 967c478bd9Sstevel@tonic-gate #endif 977c478bd9Sstevel@tonic-gate 987c478bd9Sstevel@tonic-gate #ifdef INET_DEVDESC 997c478bd9Sstevel@tonic-gate 100fc80c0dfSnordmark extern struct streamtab INET_DEVSTRTAB; 101fc80c0dfSnordmark 1027c478bd9Sstevel@tonic-gate /* 103fc80c0dfSnordmark * Drivers that actually want to be IP would set INET_DEVSTRTAB to ipinfo. 1047c478bd9Sstevel@tonic-gate */ 1057c478bd9Sstevel@tonic-gate 1067c478bd9Sstevel@tonic-gate static dev_info_t *inet_dev_info; 1077c478bd9Sstevel@tonic-gate 1087c478bd9Sstevel@tonic-gate #define INET_DEFAULT_PRIV_MODE 0666 1097c478bd9Sstevel@tonic-gate 1107c478bd9Sstevel@tonic-gate static struct dev_priv { 1117c478bd9Sstevel@tonic-gate char *driver; 1127c478bd9Sstevel@tonic-gate int privonly; 1137c478bd9Sstevel@tonic-gate const char *read_priv; 1147c478bd9Sstevel@tonic-gate const char *write_priv; 1157c478bd9Sstevel@tonic-gate } netdev_privs[] = { 1167c478bd9Sstevel@tonic-gate {"icmp", PRIVONLY_DEV, PRIV_NET_ICMPACCESS, PRIV_NET_ICMPACCESS}, 1177c478bd9Sstevel@tonic-gate {"icmp6", PRIVONLY_DEV, PRIV_NET_ICMPACCESS, PRIV_NET_ICMPACCESS}, 1187c478bd9Sstevel@tonic-gate {"ip", PRIVONLY_DEV, PRIV_NET_RAWACCESS, PRIV_NET_RAWACCESS}, 1197c478bd9Sstevel@tonic-gate {"ip6", PRIVONLY_DEV, PRIV_NET_RAWACCESS, PRIV_NET_RAWACCESS}, 120f4b3ec61Sdh155122 {"keysock", PRIVONLY_DEV, PRIV_SYS_IP_CONFIG, PRIV_SYS_IP_CONFIG}, 121f4b3ec61Sdh155122 {"ipsecah", PRIVONLY_DEV, PRIV_SYS_IP_CONFIG, PRIV_SYS_IP_CONFIG}, 122f4b3ec61Sdh155122 {"ipsecesp", PRIVONLY_DEV, PRIV_SYS_IP_CONFIG, PRIV_SYS_IP_CONFIG}, 123f4b3ec61Sdh155122 {"spdsock", PRIVONLY_DEV, PRIV_SYS_IP_CONFIG, PRIV_SYS_IP_CONFIG}, 1247c478bd9Sstevel@tonic-gate {NULL, 0, NULL, NULL} 1257c478bd9Sstevel@tonic-gate }; 1267c478bd9Sstevel@tonic-gate 1277c478bd9Sstevel@tonic-gate static int 1287c478bd9Sstevel@tonic-gate inet_attach(dev_info_t *devi, ddi_attach_cmd_t cmd) 1297c478bd9Sstevel@tonic-gate { 1307c478bd9Sstevel@tonic-gate int i, ndevs; 1317c478bd9Sstevel@tonic-gate 1327c478bd9Sstevel@tonic-gate if (cmd != DDI_ATTACH) 1337c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 1347c478bd9Sstevel@tonic-gate 1357c478bd9Sstevel@tonic-gate inet_dev_info = devi; 1367c478bd9Sstevel@tonic-gate 1377c478bd9Sstevel@tonic-gate ndevs = sizeof (netdev_privs) / sizeof (struct dev_priv); 1387c478bd9Sstevel@tonic-gate for (i = 0; i < ndevs; i++) { 1397c478bd9Sstevel@tonic-gate char *drv = netdev_privs[i].driver; 1407c478bd9Sstevel@tonic-gate if (drv == NULL || strcmp(drv, ddi_driver_name(devi)) == 0) 1417c478bd9Sstevel@tonic-gate break; 1427c478bd9Sstevel@tonic-gate } 1437c478bd9Sstevel@tonic-gate 1447c478bd9Sstevel@tonic-gate return (ddi_create_priv_minor_node(devi, INET_NAME, S_IFCHR, 1457c478bd9Sstevel@tonic-gate INET_DEVMINOR, DDI_PSEUDO, netdev_privs[i].privonly, 1467c478bd9Sstevel@tonic-gate netdev_privs[i].read_priv, netdev_privs[i].write_priv, 1477c478bd9Sstevel@tonic-gate INET_DEFAULT_PRIV_MODE)); 1487c478bd9Sstevel@tonic-gate } 1497c478bd9Sstevel@tonic-gate 1507c478bd9Sstevel@tonic-gate static int 1517c478bd9Sstevel@tonic-gate inet_detach(dev_info_t *devi, ddi_detach_cmd_t cmd) 1527c478bd9Sstevel@tonic-gate { 1537c478bd9Sstevel@tonic-gate if (cmd != DDI_DETACH) 1547c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 1557c478bd9Sstevel@tonic-gate 1567c478bd9Sstevel@tonic-gate ASSERT(devi == inet_dev_info); 1577c478bd9Sstevel@tonic-gate 1587c478bd9Sstevel@tonic-gate ddi_remove_minor_node(devi, NULL); 1597c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 1607c478bd9Sstevel@tonic-gate } 1617c478bd9Sstevel@tonic-gate 1627c478bd9Sstevel@tonic-gate 1637c478bd9Sstevel@tonic-gate /* ARGSUSED */ 1647c478bd9Sstevel@tonic-gate static int 1657c478bd9Sstevel@tonic-gate inet_info(dev_info_t *dip, ddi_info_cmd_t cmd, void *arg, void **result) 1667c478bd9Sstevel@tonic-gate { 1677c478bd9Sstevel@tonic-gate int error = DDI_FAILURE; 1687c478bd9Sstevel@tonic-gate 1697c478bd9Sstevel@tonic-gate switch (cmd) { 1707c478bd9Sstevel@tonic-gate case DDI_INFO_DEVT2DEVINFO: 1717c478bd9Sstevel@tonic-gate if (inet_dev_info != NULL) { 1727c478bd9Sstevel@tonic-gate *result = (void *)inet_dev_info; 1737c478bd9Sstevel@tonic-gate error = DDI_SUCCESS; 1747c478bd9Sstevel@tonic-gate } 1757c478bd9Sstevel@tonic-gate break; 1767c478bd9Sstevel@tonic-gate 1777c478bd9Sstevel@tonic-gate case DDI_INFO_DEVT2INSTANCE: 1787c478bd9Sstevel@tonic-gate *result = NULL; 1797c478bd9Sstevel@tonic-gate error = DDI_SUCCESS; 1807c478bd9Sstevel@tonic-gate break; 1817c478bd9Sstevel@tonic-gate 1827c478bd9Sstevel@tonic-gate default: 1837c478bd9Sstevel@tonic-gate break; 1847c478bd9Sstevel@tonic-gate } 1857c478bd9Sstevel@tonic-gate 1867c478bd9Sstevel@tonic-gate return (error); 1877c478bd9Sstevel@tonic-gate } 1887c478bd9Sstevel@tonic-gate 1897c478bd9Sstevel@tonic-gate DDI_DEFINE_STREAM_OPS(inet_devops, nulldev, nulldev, inet_attach, inet_detach, 19019397407SSherry Moore nulldev, inet_info, INET_DEVMTFLAGS, &INET_DEVSTRTAB, 19119397407SSherry Moore ddi_quiesce_not_supported); 1927c478bd9Sstevel@tonic-gate 1937c478bd9Sstevel@tonic-gate static struct modldrv modldrv = { 1947c478bd9Sstevel@tonic-gate &mod_driverops, 1957c478bd9Sstevel@tonic-gate INET_DEVDESC, 1967c478bd9Sstevel@tonic-gate &inet_devops 1977c478bd9Sstevel@tonic-gate }; 1987c478bd9Sstevel@tonic-gate 1997c478bd9Sstevel@tonic-gate #endif /* INET_DEVDESC */ 2007c478bd9Sstevel@tonic-gate 2017c478bd9Sstevel@tonic-gate #ifdef INET_MODDESC 202fc80c0dfSnordmark extern struct streamtab INET_MODSTRTAB; 203fc80c0dfSnordmark 2047c478bd9Sstevel@tonic-gate static struct fmodsw fsw = { 2057c478bd9Sstevel@tonic-gate INET_NAME, 206fc80c0dfSnordmark &INET_MODSTRTAB, 2077c478bd9Sstevel@tonic-gate INET_MODMTFLAGS 2087c478bd9Sstevel@tonic-gate }; 2097c478bd9Sstevel@tonic-gate 2107c478bd9Sstevel@tonic-gate static struct modlstrmod modlstrmod = { 2117c478bd9Sstevel@tonic-gate &mod_strmodops, 2127c478bd9Sstevel@tonic-gate INET_MODDESC, 2137c478bd9Sstevel@tonic-gate &fsw 2147c478bd9Sstevel@tonic-gate }; 2150f1702c5SYu Xiangning 2167c478bd9Sstevel@tonic-gate #endif /* INET_MODDESC */ 2177c478bd9Sstevel@tonic-gate 2180f1702c5SYu Xiangning #ifdef INET_SOCKDESC 2190f1702c5SYu Xiangning 2200f1702c5SYu Xiangning #ifdef INET_SOCK_PROTO_FB_FUNC 2210f1702c5SYu Xiangning static __smod_priv_t smodpriv = { 2220f1702c5SYu Xiangning NULL, 2230f1702c5SYu Xiangning NULL, 224*3e95bd4aSAnders Persson INET_SOCK_PROTO_FB_FUNC, 225*3e95bd4aSAnders Persson INET_SOCK_FALLBACK_DEV_V4, 226*3e95bd4aSAnders Persson INET_SOCK_FALLBACK_DEV_V6 2270f1702c5SYu Xiangning }; 2280f1702c5SYu Xiangning #endif /* INET_SOCK_PROTO_FB_FUNC */ 2290f1702c5SYu Xiangning 2300f1702c5SYu Xiangning static struct smod_reg_s smodreg = { 2310f1702c5SYu Xiangning SOCKMOD_VERSION, 2320f1702c5SYu Xiangning INET_NAME, 2330f1702c5SYu Xiangning SOCK_UC_VERSION, 2340f1702c5SYu Xiangning SOCK_DC_VERSION, 2350f1702c5SYu Xiangning INET_SOCK_PROTO_CREATE_FUNC, 2360f1702c5SYu Xiangning #ifdef INET_SOCK_PROTO_FB_FUNC 2370f1702c5SYu Xiangning &smodpriv 2380f1702c5SYu Xiangning #else 2390f1702c5SYu Xiangning NULL 2400f1702c5SYu Xiangning #endif /* INET_SOCK_PROTO_FB_FUNC */ 2410f1702c5SYu Xiangning }; 2420f1702c5SYu Xiangning 2430f1702c5SYu Xiangning static struct modlsockmod modlsockmod = { 2440f1702c5SYu Xiangning &mod_sockmodops, 2450f1702c5SYu Xiangning INET_SOCKDESC, 2460f1702c5SYu Xiangning &smodreg 2470f1702c5SYu Xiangning }; 2480f1702c5SYu Xiangning #endif /* INET_SOCKDESC */ 2490f1702c5SYu Xiangning 2507c478bd9Sstevel@tonic-gate static struct modlinkage modlinkage = { 2517c478bd9Sstevel@tonic-gate MODREV_1, 2527c478bd9Sstevel@tonic-gate #ifdef INET_DEVDESC 2537c478bd9Sstevel@tonic-gate &modldrv, 2547c478bd9Sstevel@tonic-gate #endif 2557c478bd9Sstevel@tonic-gate #ifdef INET_MODDESC 2567c478bd9Sstevel@tonic-gate &modlstrmod, 2577c478bd9Sstevel@tonic-gate #endif 2580f1702c5SYu Xiangning #ifdef INET_SOCKDESC 2590f1702c5SYu Xiangning &modlsockmod, 2600f1702c5SYu Xiangning #endif 2617c478bd9Sstevel@tonic-gate NULL 2627c478bd9Sstevel@tonic-gate }; 263