xref: /illumos-gate/usr/src/uts/common/sys/sad.h (revision 9ec394dbf343c1f23c6e13c39df427f238e5a369)
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 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
27 /*	  All Rights Reserved  	*/
28 
29 
30 #ifndef _SYS_SAD_H
31 #define	_SYS_SAD_H
32 
33 #pragma ident	"%Z%%M%	%I%	%E% SMI"	/* SVr4.0 1.5 */
34 
35 #include <sys/types.h>
36 #ifdef	_KERNEL
37 #include <sys/strsubr.h>
38 #endif
39 #include <sys/modhash.h>
40 
41 #ifdef	__cplusplus
42 extern "C" {
43 #endif
44 
45 /*
46  * Streams Administrative Driver
47  */
48 
49 /*
50  * As time has passed, it has become necessary to add members to some
51  * of the structures passed downstream with these ioctls.  Currently,
52  * only the SAD_GAP/SAD_SAP ioctls are versioned, (which use the
53  * strapush structure), but the versioning mechanism is general enough
54  * to be applied to any SAD ioctls.  This is done by repartitioning
55  * the SAD ioctl namespace to include a version number in addition to
56  * the command (see below).
57  *
58  * In the case of the SAD_GAP/SAD_SAP ioctls, an application can
59  * choose which "version" of the ioctl to use by #defining AP_VERSION
60  * before including this file. Old code implicitly has AP_VERSION set
61  * to 0, and even newly compiled code defaults to an AP_VERSION of 0,
62  * since it may not be aware of the new structure members and
63  * therefore not know to set them to reasonable values.  In order for
64  * programs to make use of a newer version, they must explicitly
65  * #define AP_VERSION to the appropriate value. Note that the kernel
66  * always defaults to the latest version, since it is internally
67  * self-consistent.
68  */
69 #ifndef	AP_VERSION
70 #ifdef	_KERNEL
71 #define	AP_VERSION		1		/* latest version */
72 #else
73 #define	AP_VERSION		0		/* SVR4 version */
74 #endif
75 #endif
76 
77 /*
78  * ioctl defines
79  *
80  * The layout for the low 16 bits is 01000101VVVVCCCC, where the
81  * first bitpattern is `D' in binary, followed by a 4 bit version
82  * field (limiting the number of versions to 16), followed by a
83  * 4 bit command field (limiting the number of commands to 16).
84  */
85 #define	SADIOC		('D' << 8)
86 #define	SAD_SAP		(SADIOC|AP_VERSION << 4|01)
87 #define	SAD_GAP		(SADIOC|AP_VERSION << 4|02)
88 #define	SAD_VML		(SADIOC|03)		/* validate module list */
89 
90 /*
91  * Device naming and numbering conventions.
92  */
93 #define	USERDEV		"/dev/sad/user"
94 #define	ADMINDEV	"/dev/sad/admin"
95 
96 #define	USRMIN		0
97 #define	ADMMIN		1
98 
99 /*
100  * The maximum modules you can push on a stream using the autopush
101  * feature.  This should be less than NSTRPUSH.
102  */
103 #define	MAXAPUSH	8
104 
105 /*
106  * autopush info common to user and kernel
107  */
108 struct apcommon {
109 	uint_t	apc_cmd;		/* command (see below) */
110 	major_t	apc_major;		/* major # of device */
111 	minor_t	apc_minor;		/* minor # of device */
112 	minor_t	apc_lastminor;		/* last minor for range */
113 	uint_t	apc_npush;		/* number of modules to push */
114 };
115 
116 /*
117  * New autopush information structure.  This wouldn't be necessary
118  * except `struct apcommon' wasn't defined last in the `strapush'
119  * structure, making it difficult to grow the structure without
120  * breaking binary compatibility.  Note that new members can be added
121  * to this structure in the future, at which point AP_VERSION should
122  * be incremented (of course, a new STRAPUSH_Vx_LEN macro should be
123  * added and sad.c should be changed to handle the new member).
124  */
125 struct apdata {
126 	uint_t		apd_anchor;	/* position of anchor in stream */
127 };
128 
129 /*
130  * ap_cmd: various flavors of autopush
131  */
132 #define	SAP_CLEAR	0		/* remove configuration list */
133 #define	SAP_ONE		1		/* configure one minor device */
134 #define	SAP_RANGE	2		/* configure range of minor devices */
135 #define	SAP_ALL		3		/* configure all minor devices */
136 
137 /*
138  * format for autopush ioctls
139  */
140 struct strapush {
141 	struct apcommon	sap_common;			  /* see above */
142 	char		sap_list[MAXAPUSH][FMNAMESZ + 1]; /* module list */
143 #if AP_VERSION > 0
144 	struct apdata	sap_data;			  /* see above */
145 #endif
146 };
147 
148 #define	sap_cmd		sap_common.apc_cmd
149 #define	sap_major	sap_common.apc_major
150 #define	sap_minor	sap_common.apc_minor
151 #define	sap_lastminor	sap_common.apc_lastminor
152 #define	sap_npush	sap_common.apc_npush
153 #define	sap_anchor	sap_data.apd_anchor
154 
155 #ifdef _KERNEL
156 
157 /*
158  * state values for ioctls
159  */
160 #define	GETSTRUCT	1
161 #define	GETRESULT	2
162 #define	GETLIST		3
163 
164 #define	SAD_VER(ioccmd)	(((ioccmd) >> 4) & 0x0f)
165 #define	SAD_CMD(ioccmd)	((ioccmd) & ~0xf0)
166 
167 #define	STRAPUSH_V0_LEN	(size_t)(&((struct strapush *)0)->sap_data)
168 #define	STRAPUSH_V1_LEN	(size_t)(STRAPUSH_V0_LEN + sizeof (uint_t))
169 
170 struct saddev {
171 	queue_t	*sa_qp;		/* pointer to read queue */
172 	caddr_t	 sa_addr;	/* saved address for copyout */
173 	int	 sa_flags;	/* see below */
174 	str_stack_t *sa_ss;
175 };
176 
177 /*
178  * values for saddev flags field.
179  */
180 #define	SADPRIV		0x01
181 
182 /*
183  * Module Autopush Cache
184  */
185 struct autopush {
186 	struct apcommon  ap_common;		/* see above */
187 	char		 ap_list[MAXAPUSH][FMNAMESZ + 1];
188 						/* list of modules to push */
189 	int		 ap_cnt;		/* in use count */
190 	struct apdata	 ap_data;		/* see above */
191 };
192 
193 /*
194  * The command issued by the user ultimately becomes
195  * the type of the autopush entry.  Therefore, occurrences of
196  * "type" in the code refer to an existing autopush entry.
197  * Occurrences of "cmd" in the code refer to the command the
198  * user is currently trying to complete.  types and cmds take
199  * on the same values.
200  */
201 #define	ap_type		ap_common.apc_cmd
202 #define	ap_major	ap_common.apc_major
203 #define	ap_minor	ap_common.apc_minor
204 #define	ap_lastminor	ap_common.apc_lastminor
205 #define	ap_npush	ap_common.apc_npush
206 #define	ap_anchor	ap_data.apd_anchor
207 
208 /*
209  * function prototypes
210  */
211 void audit_stropen(struct vnode *, dev_t *, int, cred_t *);
212 void audit_strclose(struct vnode *, int, cred_t *);
213 void audit_strioctl(struct vnode *, int, intptr_t, int, int, cred_t *, int *);
214 struct strbuf;
215 void audit_strputmsg(struct vnode *, struct strbuf *, struct strbuf *,
216 						unsigned char, int, int);
217 void audit_fdsend(int, struct file *, int);
218 void audit_fdrecv(int, struct file *);
219 
220 extern void sad_initspace(str_stack_t *);
221 extern void sad_freespace(str_stack_t *);
222 
223 /*
224  * The following interfaces do not care about ss_sad_lock.
225  */
226 extern struct autopush *sad_ap_alloc(void);
227 extern int sad_apc_verify(struct apcommon *);
228 extern int sad_ap_verify(struct autopush *);
229 
230 /*
231  * The following interfaces attempt to acquire ss_sad_lock.
232  */
233 extern void sad_ap_rele(struct autopush *, str_stack_t *);
234 extern struct autopush *sad_ap_find_by_dev(dev_t, str_stack_t *);
235 
236 /*
237  * The following interfaces require ss_sad_lock to be held when invoked.
238  */
239 extern void sad_ap_insert(struct autopush *, str_stack_t *);
240 extern void sad_ap_remove(struct autopush *, str_stack_t *);
241 extern struct autopush *sad_ap_find(struct apcommon *, str_stack_t *);
242 
243 #endif /* _KERNEL */
244 
245 #ifdef	__cplusplus
246 }
247 #endif
248 
249 #endif	/* _SYS_SAD_H */
250