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