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]
22 * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
25 #include <sys/types.h>
27 #include <sys/stream.h>
29 #include <sys/sunddi.h>
30 #include <sys/priv_names.h>
33 * This file contains generic goo needed to hook the STREAMS modules and
34 * drivers that live under uts/common/inet into the DDI. In order to use it,
35 * each module/driver should #define the symbols below (as appropriate) and
36 * then #include this source file; see the other uts/common/inet/<star>ddi.c
37 * files for examples of this in action.
39 * The symbols that all modules and drivers must define are:
41 * INET_NAME The name of the module/driver.
43 * The symbols that all modules must define are:
45 * INET_MODSTRTAB The name of the `streamtab' structure for this module.
46 * INET_MODDESC The one-line description for this module.
47 * INET_MODMTFLAGS The mt-streams(9F) flags for the module.
49 * The symbols that all drivers must define are:
51 * INET_DEVSTRTAB The name of the `streamtab' structure for this driver.
52 * INET_DEVDESC The one-line description for this driver.
53 * INET_DEVMTFLAGS The mt-streams(9F) flags for the driver.
54 * INET_DEVMINOR The minor number of the driver (usually 0).
56 * Drivers that need to masquerade as IP should set INET_DEVMTFLAGS to
57 * IP_DEVMTFLAGS and set INET_DEVSTRTAB to ipinfo.
59 * The symbols that all socket modules must define are:
61 * INET_SOCKDESC The one-line description for this socket module
62 * INET_SOCK_PROTO_CREATE_FUNC The function used to create PCBs
64 * In addition, socket modules that can be converted to TPI must define:
66 * INET_SOCK_PROTO_FB_FUNC The function used to fallback to TPI
69 #if !defined(INET_NAME)
70 #error inetddi.c: INET_NAME is not defined!
71 #elif !defined(INET_DEVDESC) && !defined(INET_MODDESC) && \
72 !defined(INET_SOCKDESC)
73 #error inetddi.c: at least one of INET_DEVDESC or INET_MODDESC or \
74 INET_SOCKDESC must be defined!
75 #elif defined(INET_DEVDESC) && !defined(INET_DEVSTRTAB)
76 #error inetddi.c: INET_DEVDESC is defined but INET_DEVSTRTAB is not!
77 #elif defined(INET_DEVDESC) && !defined(INET_DEVMTFLAGS)
78 #error inetddi.c: INET_DEVDESC is defined but INET_DEVMTFLAGS is not!
79 #elif defined(INET_DEVDESC) && !defined(INET_DEVMINOR)
80 #error inetddi.c: INET_DEVDESC is defined but INET_DEVMINOR is not!
81 #elif defined(INET_MODDESC) && !defined(INET_MODSTRTAB)
82 #error inetddi.c: INET_MODDESC is defined but INET_MODSTRTAB is not!
83 #elif defined(INET_MODDESC) && !defined(INET_MODMTFLAGS)
84 #error inetddi.c: INET_MODDESC is defined but INET_MODMTFLAGS is not!
85 #elif defined(INET_SOCKDESC) && !defined(SOCKMOD_VERSION)
86 #error inetddi.c: INET_SOCKDESC is defined but SOCKMOD_VERSION is not!
87 #elif defined(INET_SOCKDESC) && !defined(INET_SOCK_PROTO_CREATE_FUNC)
88 #error inetddi.c: INET_SOCKDESC is defined but INET_SOCK_PROTO_CREATE_FUNC \
90 #elif defined(INET_SOCK_PROTO_FB_FUNC) && !defined(INET_SOCK_FALLBACK_DEV_V4)
91 #error inetddi.c: INET_SOCK_PROTO_FB_FUNC is defined but \
92 INET_SOCK_FALLBACK_DEV_V4 is not!
93 #elif defined(INET_SOCK_PROTO_FB_FUNC) && !defined(INET_SOCK_FALLBACK_DEV_V6)
94 #error inetddi.c: INET_SOCK_PROTO_FB_FUNC is defined but \
95 INET_SOCK_FALLBACK_DEV_V6 is not!
100 extern struct streamtab INET_DEVSTRTAB
;
103 * Drivers that actually want to be IP would set INET_DEVSTRTAB to ipinfo.
106 static dev_info_t
*inet_dev_info
;
108 #define INET_DEFAULT_PRIV_MODE 0666
110 static struct dev_priv
{
113 const char *read_priv
;
114 const char *write_priv
;
116 {"icmp", PRIVONLY_DEV
, PRIV_NET_ICMPACCESS
, PRIV_NET_ICMPACCESS
},
117 {"icmp6", PRIVONLY_DEV
, PRIV_NET_ICMPACCESS
, PRIV_NET_ICMPACCESS
},
118 {"ip", PRIVONLY_DEV
, PRIV_NET_RAWACCESS
, PRIV_NET_RAWACCESS
},
119 {"ip6", PRIVONLY_DEV
, PRIV_NET_RAWACCESS
, PRIV_NET_RAWACCESS
},
120 {"keysock", PRIVONLY_DEV
, PRIV_SYS_IP_CONFIG
, PRIV_SYS_IP_CONFIG
},
121 {"ipsecah", PRIVONLY_DEV
, PRIV_SYS_IP_CONFIG
, PRIV_SYS_IP_CONFIG
},
122 {"ipsecesp", PRIVONLY_DEV
, PRIV_SYS_IP_CONFIG
, PRIV_SYS_IP_CONFIG
},
123 {"spdsock", PRIVONLY_DEV
, PRIV_SYS_IP_CONFIG
, PRIV_SYS_IP_CONFIG
},
124 {NULL
, 0, NULL
, NULL
}
128 inet_attach(dev_info_t
*devi
, ddi_attach_cmd_t cmd
)
132 if (cmd
!= DDI_ATTACH
)
133 return (DDI_FAILURE
);
135 inet_dev_info
= devi
;
137 ndevs
= sizeof (netdev_privs
) / sizeof (struct dev_priv
);
138 for (i
= 0; i
< ndevs
; i
++) {
139 char *drv
= netdev_privs
[i
].driver
;
140 if (drv
== NULL
|| strcmp(drv
, ddi_driver_name(devi
)) == 0)
144 return (ddi_create_priv_minor_node(devi
, INET_NAME
, S_IFCHR
,
145 INET_DEVMINOR
, DDI_PSEUDO
, netdev_privs
[i
].privonly
,
146 netdev_privs
[i
].read_priv
, netdev_privs
[i
].write_priv
,
147 INET_DEFAULT_PRIV_MODE
));
151 inet_detach(dev_info_t
*devi
, ddi_detach_cmd_t cmd
)
153 if (cmd
!= DDI_DETACH
)
154 return (DDI_FAILURE
);
156 ASSERT(devi
== inet_dev_info
);
158 ddi_remove_minor_node(devi
, NULL
);
159 return (DDI_SUCCESS
);
165 inet_info(dev_info_t
*dip
, ddi_info_cmd_t cmd
, void *arg
, void **result
)
167 int error
= DDI_FAILURE
;
170 case DDI_INFO_DEVT2DEVINFO
:
171 if (inet_dev_info
!= NULL
) {
172 *result
= (void *)inet_dev_info
;
177 case DDI_INFO_DEVT2INSTANCE
:
189 DDI_DEFINE_STREAM_OPS(inet_devops
, nulldev
, nulldev
, inet_attach
, inet_detach
,
190 nulldev
, inet_info
, INET_DEVMTFLAGS
, &INET_DEVSTRTAB
,
191 ddi_quiesce_not_supported
);
193 static struct modldrv modldrv
= {
199 #endif /* INET_DEVDESC */
202 extern struct streamtab INET_MODSTRTAB
;
204 static struct fmodsw fsw
= {
210 static struct modlstrmod modlstrmod
= {
216 #endif /* INET_MODDESC */
220 #ifdef INET_SOCK_PROTO_FB_FUNC
221 static __smod_priv_t smodpriv
= {
224 INET_SOCK_PROTO_FB_FUNC
,
225 INET_SOCK_FALLBACK_DEV_V4
,
226 INET_SOCK_FALLBACK_DEV_V6
228 #endif /* INET_SOCK_PROTO_FB_FUNC */
230 static struct smod_reg_s smodreg
= {
235 INET_SOCK_PROTO_CREATE_FUNC
,
236 #ifdef INET_SOCK_PROTO_FB_FUNC
240 #endif /* INET_SOCK_PROTO_FB_FUNC */
243 static struct modlsockmod modlsockmod
= {
248 #endif /* INET_SOCKDESC */
250 static struct modlinkage modlinkage
= {