xref: /dragonfly/sys/sys/sysctl.h (revision 0b29ed9d)
1 /*
2  * Copyright (c) 1989, 1993
3  *	The Regents of the University of California.  All rights reserved.
4  *
5  * This code is derived from software contributed to Berkeley by
6  * Mike Karels at Berkeley Software Design, Inc.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  * 3. Neither the name of the University nor the names of its contributors
17  *    may be used to endorse or promote products derived from this software
18  *    without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30  * SUCH DAMAGE.
31  *
32  *	@(#)sysctl.h	8.1 (Berkeley) 6/2/93
33  * $FreeBSD: head/sys/sys/sysctl.h 204170 2010-02-21 13:57:02Z ed $
34  */
35 
36 #ifndef _SYS_SYSCTL_H_
37 #define	_SYS_SYSCTL_H_
38 
39 #ifndef _SYS_TYPES_H_
40 #include <sys/types.h>
41 #endif
42 #ifndef _SYS_QUEUE_H_
43 #include <sys/queue.h>
44 #endif
45 
46 /*
47  * Definitions for sysctl call.  The sysctl call uses a hierarchical name
48  * for objects that can be examined or modified.  The name is expressed as
49  * a sequence of integers.  Like a file path name, the meaning of each
50  * component depends on its place in the hierarchy.  The top-level and kern
51  * identifiers are defined here, and other identifiers are defined in the
52  * respective subsystem header files.
53  */
54 
55 #define CTL_MAXNAME	12	/* largest number of components supported */
56 
57 /*
58  * Each subsystem defined by sysctl defines a list of variables
59  * for that subsystem. Each name is either a node with further
60  * levels defined below it, or it is a leaf of some particular
61  * type given below. Each sysctl level defines a set of name/type
62  * pairs to be used by sysctl(1) in manipulating the subsystem.
63  */
64 struct ctlname {
65 	char	*ctl_name;	/* subsystem name */
66 	int	ctl_type;	/* type of name */
67 };
68 
69 #define CTLTYPE		0xf	/* Mask for the type */
70 #define	CTLTYPE_NODE	1	/* name is a node */
71 #define	CTLTYPE_INT	2	/* name describes an integer */
72 #define	CTLTYPE_STRING	3	/* name describes a string */
73 #define	CTLTYPE_S64	4	/* name describes a signed 64-bit number */
74 #define	CTLTYPE_QUAD	CTLTYPE_S64 /* name describes a signed 64-bit number */
75 #define	CTLTYPE_OPAQUE	5	/* name describes a structure */
76 #define	CTLTYPE_STRUCT	CTLTYPE_OPAQUE	/* name describes a structure */
77 #define	CTLTYPE_UINT	6	/* name describes an unsigned integer */
78 #define	CTLTYPE_LONG	7	/* name describes a long */
79 #define	CTLTYPE_ULONG	8	/* name describes an unsigned long */
80 #define	CTLTYPE_U64	9	/* name describes an unsigned 64-bit number */
81 #define	CTLTYPE_UQUAD	CTLTYPE_U64 /* name describes an unsigned 64-bit number */
82 #define	CTLTYPE_U8	0xa	/* name describes an unsigned 8-bit number */
83 #define	CTLTYPE_U16	0xb	/* name describes an unsigned 16-bit number */
84 #define	CTLTYPE_S8	0xc	/* name describes a signed 8-bit number */
85 #define	CTLTYPE_S16	0xd	/* name describes a signed 16-bit number */
86 #define	CTLTYPE_S32	0xe	/* name describes a signed 32-bit number */
87 #define	CTLTYPE_U32	0xf	/* name describes an unsigned 32-bit number */
88 
89 #define	CTLFLAG_RD	0x80000000	/* Allow reads of variable */
90 #define	CTLFLAG_WR	0x40000000	/* Allow writes to the variable */
91 #define	CTLFLAG_RW	(CTLFLAG_RD|CTLFLAG_WR)
92 #define	CTLFLAG_ANYBODY	0x10000000	/* All users can set this var */
93 #define	CTLFLAG_SECURE	0x08000000	/* Permit set only if securelevel<=0 */
94 #define	CTLFLAG_PRISON	0x04000000	/* Prisoned roots can fiddle */
95 #define	CTLFLAG_DYN	0x02000000	/* Dynamic oid - can be freed */
96 #define	CTLFLAG_SKIP	0x01000000	/* Skip this sysctl when listing */
97 #define	CTLMASK_SECURE	0x00F00000	/* Secure level */
98 #define	CTLFLAG_DYING	0x00010000	/* Oid is being removed */
99 #define CTLFLAG_SHLOCK	0x00008000	/* shlock on write (def is exlock) */
100 #define CTLFLAG_EXLOCK	0x00004000	/* exlock on read (def is shlock) */
101 #define CTLFLAG_NOLOCK	0x00002000	/* no lock required */
102 #define CTLMASK_TYPE	0x0000000F	/* type field */
103 
104 /*
105  * USE THIS instead of a hardwired number from the categories below
106  * to get dynamically assigned sysctl entries using the linker-set
107  * technology. This is the way nearly all new sysctl variables should
108  * be implemented.
109  * e.g. SYSCTL_INT(_parent, OID_AUTO, name, CTLFLAG_RW, &variable, 0, "");
110  */
111 #define OID_AUTO	(-1)
112 
113 #ifdef _KERNEL
114 
115 #include <sys/kernel.h>			/* for DATA_SET */
116 #ifndef _SYS_LOCK_H_
117 #include <sys/lock.h>
118 #endif
119 
120 #define SYSCTL_HANDLER_ARGS struct sysctl_oid *oidp, void *arg1, int arg2, \
121 	struct sysctl_req *req
122 
123 /*
124  * This describes the access space for a sysctl request.  This is needed
125  * so that we can use the interface from the kernel or from user-space.
126  */
127 struct sysctl_req {
128 	struct thread	*td;		/* used for access checking */
129 	int		 lock;		/* wiring state */
130 	void		*oldptr;
131 	size_t		 oldlen;
132 	size_t		 oldidx;
133 	int		(*oldfunc)(struct sysctl_req *, const void *, size_t);
134 	void		*newptr;
135 	size_t		 newlen;
136 	size_t		 newidx;
137 	int		(*newfunc)(struct sysctl_req *, void *, size_t);
138 	size_t		 validlen;
139 	int		 flags;
140 };
141 
142 SLIST_HEAD(sysctl_oid_list, sysctl_oid);
143 
144 /*
145  * This describes one "oid" in the MIB tree.  Potentially more nodes can
146  * be hidden behind it, expanded by the handler.
147  */
148 struct sysctl_oid {
149 	struct sysctl_oid_list *oid_parent;
150 	SLIST_ENTRY(sysctl_oid) oid_link;
151 	int		oid_number;
152 	int		oid_kind;
153 	void		*oid_arg1;
154 	int		oid_arg2;
155 	const char	*oid_name;
156 	int 		(*oid_handler)(SYSCTL_HANDLER_ARGS);
157 	const char	*oid_fmt;
158 	int		oid_refcnt;
159 	u_int		 oid_running;
160 	const char	*oid_descr;
161 	struct lock	oid_lock;	/* per-node lock */
162 };
163 
164 #define SYSCTL_IN(r, p, l)	(r->newfunc)(r, p, l)
165 #define SYSCTL_OUT(r, p, l)	(r->oldfunc)(r, p, l)
166 #define SYSCTL_OUT_STR(r, p)	(r->oldfunc)(r, p, strlen(p) + 1)
167 
168 int sysctl_handle_8(SYSCTL_HANDLER_ARGS);
169 int sysctl_handle_16(SYSCTL_HANDLER_ARGS);
170 int sysctl_handle_32(SYSCTL_HANDLER_ARGS);
171 int sysctl_handle_64(SYSCTL_HANDLER_ARGS);
172 int sysctl_handle_int(SYSCTL_HANDLER_ARGS);
173 int sysctl_handle_long(SYSCTL_HANDLER_ARGS);
174 int sysctl_handle_quad(SYSCTL_HANDLER_ARGS);
175 int sysctl_handle_intptr(SYSCTL_HANDLER_ARGS);
176 int sysctl_handle_string(SYSCTL_HANDLER_ARGS);
177 int sysctl_handle_opaque(SYSCTL_HANDLER_ARGS);
178 
179 extern struct lock sysctllock;
180 
181 #define	SYSCTL_XLOCK()		_sysctl_xlock()
182 #define	SYSCTL_XUNLOCK()	_sysctl_xunlock()
183 #define	SYSCTL_SLOCK()		lockmgr(&mycpu->gd_sysctllock, LK_SHARED)
184 #define	SYSCTL_SUNLOCK()	lockmgr(&mycpu->gd_sysctllock, LK_RELEASE)
185 #define	SYSCTL_ASSERT_LOCKED() \
186 	KKASSERT(lockstatus(&mycpu->gd_sysctllock, curthread) != 0)
187 
188 /*
189  * These functions are used to add/remove an oid from the mib.
190  */
191 void sysctl_register_oid(struct sysctl_oid *oidp);
192 void sysctl_unregister_oid(struct sysctl_oid *oidp);
193 
194 /* Declare a static oid to allow child oids to be added to it. */
195 #define SYSCTL_DECL(name)					\
196 	extern struct sysctl_oid_list sysctl_##name##_children
197 
198 /* Hide these in macros */
199 #define	SYSCTL_SET_CHILDREN(oid_ptr, children) do {			\
200 	(oid_ptr)->oid_arg1 = (children);				\
201 } while(0)
202 #define	SYSCTL_CHILDREN(oid_ptr) (struct sysctl_oid_list *) \
203 	(oid_ptr)->oid_arg1
204 #define	SYSCTL_STATIC_CHILDREN(oid_name) \
205 	(&sysctl_##oid_name##_children)
206 
207 /* === Structs and macros related to context handling === */
208 
209 /* All dynamically created sysctls can be tracked in a context list. */
210 struct sysctl_ctx_entry {
211 	struct sysctl_oid *entry;
212 	TAILQ_ENTRY(sysctl_ctx_entry) link;
213 };
214 
215 TAILQ_HEAD(sysctl_ctx_list, sysctl_ctx_entry);
216 
217 #define	SYSCTL_NODE_CHILDREN(parent, name) \
218 	sysctl_##parent##_##name##_children
219 
220 #ifndef NO_SYSCTL_DESCR
221 #define	__DESCR(d) d
222 #else
223 #define	__DESCR(d) ""
224 #endif
225 
226 /* This constructs a "raw" MIB oid. */
227 #define	SYSCTL_OID(parent, nbr, name, kind, a1, a2, handler, fmt, descr)\
228 	static struct sysctl_oid sysctl__##parent##_##name = {		\
229 		&sysctl_##parent##_children,				\
230 		{ NULL },						\
231 		nbr,							\
232 		kind,							\
233 		a1,							\
234 		a2,							\
235 		#name,							\
236 		handler,						\
237 		fmt,							\
238 		0,							\
239 		0,							\
240 		__DESCR(descr)						\
241 		};							\
242 	DATA_SET(sysctl_set, sysctl__##parent##_##name)
243 
244 #define	SYSCTL_ADD_OID(ctx, parent, nbr, name, kind, a1, a2, handler, fmt, descr) \
245 	sysctl_add_oid(ctx, parent, nbr, name, kind, a1, a2, handler, fmt, descr);
246 
247 /* This constructs a node from which other oids can hang. */
248 #define	SYSCTL_NODE(parent, nbr, name, access, handler, descr)		\
249 	struct sysctl_oid_list SYSCTL_NODE_CHILDREN(parent, name);	\
250 	SYSCTL_OID(parent, nbr, name, CTLTYPE_NODE|(access),		\
251 	    (void*)&SYSCTL_NODE_CHILDREN(parent, name), 0, handler, "N", descr)
252 
253 #define SYSCTL_ADD_NODE(ctx, parent, nbr, name, access, handler, descr)	\
254 	sysctl_add_oid(ctx, parent, nbr, name, CTLTYPE_NODE|(access),	\
255 	0, 0, handler, "N", descr)
256 
257 /* Oid for a string.  len can be 0 to indicate '\0' termination. */
258 #define SYSCTL_STRING(parent, nbr, name, access, arg, len, descr)	\
259 	SYSCTL_OID(parent, nbr, name, CTLTYPE_STRING|(access),		\
260 		arg, len, sysctl_handle_string, "A", descr)
261 
262 #define SYSCTL_ADD_STRING(ctx, parent, nbr, name, access, arg, len, descr) \
263 	sysctl_add_oid(ctx, parent, nbr, name, CTLTYPE_STRING|(access),	\
264 	arg, len, sysctl_handle_string, "A", descr)
265 
266 /* Oid for an int.  If ptr is NULL, val is returned. */
267 #define	SYSCTL_INT(parent, nbr, name, access, ptr, val, descr)		\
268 	SYSCTL_OID(parent, nbr, name,					\
269 		CTLTYPE_INT|CTLFLAG_NOLOCK|(access),			\
270 		ptr, val, sysctl_handle_int, "I", descr)
271 
272 #define SYSCTL_ADD_INT(ctx, parent, nbr, name, access, ptr, val, descr)	\
273 	sysctl_add_oid(ctx, parent, nbr, name,				\
274 		CTLTYPE_INT|CTLFLAG_NOLOCK|(access),			\
275 	ptr, val, sysctl_handle_int, "I", descr)
276 
277 /* Oid for a quad.  If ptr is NULL, val is returned. */
278 #define SYSCTL_QUAD(parent, nbr, name, access, ptr, val, descr)		\
279 	SYSCTL_OID(parent, nbr, name,					\
280 		CTLTYPE_QUAD|CTLFLAG_NOLOCK|(access),			\
281 		ptr, val, sysctl_handle_quad, "Q", descr)
282 
283 #define SYSCTL_ADD_QUAD(ctx, parent, nbr, name, access, ptr, val, descr) \
284 	sysctl_add_oid(ctx, parent, nbr, name,				\
285 		CTLTYPE_QUAD|CTLFLAG_NOLOCK|(access),			\
286 		ptr, val, sysctl_handle_quad, "Q", descr)
287 
288 /* Oid for an unsigned quad.  If ptr is NULL, val is returned. */
289 #define SYSCTL_UQUAD(parent, nbr, name, access, ptr, val, descr)	\
290 	SYSCTL_OID(parent, nbr, name,					\
291 		CTLTYPE_UQUAD|CTLFLAG_NOLOCK|(access),			\
292 		ptr, val, sysctl_handle_quad, "QU", descr)
293 
294 #define SYSCTL_ADD_UQUAD(ctx, parent, nbr, name, access, ptr, val, descr) \
295 	sysctl_add_oid(ctx, parent, nbr, name,				\
296 		CTLTYPE_UQUAD|CTLFLAG_NOLOCK|(access),			\
297 		ptr, val, sysctl_handle_quad, "QU", descr)
298 
299 /* Oid for an unsigned int.  If ptr is NULL, val is returned. */
300 #define SYSCTL_UINT(parent, nbr, name, access, ptr, val, descr)		\
301 	SYSCTL_OID(parent, nbr, name,					\
302 		CTLTYPE_UINT|CTLFLAG_NOLOCK|(access),			\
303 		ptr, val, sysctl_handle_int, "IU", descr)
304 
305 #define SYSCTL_ADD_UINT(ctx, parent, nbr, name, access, ptr, val, descr) \
306 	sysctl_add_oid(ctx, parent, nbr, name,				\
307 		CTLTYPE_UINT|CTLFLAG_NOLOCK|(access),			\
308 		ptr, val, sysctl_handle_int, "IU", descr)
309 
310 /* Oid for a long.  The pointer must be non NULL. */
311 #define SYSCTL_LONG(parent, nbr, name, access, ptr, val, descr)		\
312 	SYSCTL_OID(parent, nbr, name,					\
313 		CTLTYPE_LONG|CTLFLAG_NOLOCK|(access),			\
314 		ptr, val, sysctl_handle_long, "L", descr)
315 
316 #define SYSCTL_ADD_LONG(ctx, parent, nbr, name, access, ptr, descr)	\
317 	sysctl_add_oid(ctx, parent, nbr, name,				\
318 		CTLTYPE_LONG|CTLFLAG_NOLOCK|(access),			\
319 		ptr, 0, sysctl_handle_long, "L", descr)
320 
321 /* Oid for a long.  The pointer must be non NULL. */
322 #define SYSCTL_ULONG(parent, nbr, name, access, ptr, val, descr)	\
323 	SYSCTL_OID(parent, nbr, name,					\
324 		CTLTYPE_ULONG|CTLFLAG_NOLOCK|(access),			\
325 		ptr, val, sysctl_handle_long, "LU", descr)
326 
327 #define SYSCTL_ADD_ULONG(ctx, parent, nbr, name, access, ptr, descr)	\
328 	sysctl_add_oid(ctx, parent, nbr, name,				\
329 		CTLTYPE_ULONG|CTLFLAG_NOLOCK|(access),			\
330 		ptr, 0, sysctl_handle_long, "LU", descr)
331 
332 /* Oid for a signed 8-bit int.  The pointer must be non NULL. */
333 #define SYSCTL_S8(parent, nbr, name, access, ptr, val, descr)	\
334 	SYSCTL_OID(parent, nbr, name, CTLTYPE_S8|(access),		\
335 		ptr, val, sysctl_handle_8, "C", descr)
336 
337 #define SYSCTL_ADD_S8(ctx, parent, nbr, name, access, ptr, descr)	\
338 	sysctl_add_oid(ctx, parent, nbr, name, CTLTYPE_S8|(access),	\
339 	ptr, 0, sysctl_handle_8, "C", descr)
340 
341 /* Oid for a signed 16-bit int.  The pointer must be non NULL. */
342 #define SYSCTL_S16(parent, nbr, name, access, ptr, val, descr)	\
343 	SYSCTL_OID(parent, nbr, name, CTLTYPE_S16|(access),		\
344 		ptr, val, sysctl_handle_16, "S", descr)
345 
346 #define SYSCTL_ADD_S16(ctx, parent, nbr, name, access, ptr, descr)	\
347 	sysctl_add_oid(ctx, parent, nbr, name, CTLTYPE_S16|(access),	\
348 	ptr, 0, sysctl_handle_16, "S", descr)
349 
350 /* Oid for a signed 32-bit int.  The pointer must be non NULL. */
351 #define SYSCTL_S32(parent, nbr, name, access, ptr, val, descr)	\
352 	SYSCTL_OID(parent, nbr, name, CTLTYPE_S32|(access),		\
353 		ptr, val, sysctl_handle_32, "I", descr)
354 
355 #define SYSCTL_ADD_S32(ctx, parent, nbr, name, access, ptr, descr)	\
356 	sysctl_add_oid(ctx, parent, nbr, name, CTLTYPE_S32|(access),	\
357 	ptr, 0, sysctl_handle_32, "I", descr)
358 
359 /* Oid for a signed 64-bit int.  The pointer must be non NULL. */
360 #define SYSCTL_S64(parent, nbr, name, access, ptr, val, descr)	\
361 	SYSCTL_OID(parent, nbr, name, CTLTYPE_S64|(access),		\
362 		ptr, val, sysctl_handle_64, "Q", descr)
363 
364 #define SYSCTL_ADD_S64(ctx, parent, nbr, name, access, ptr, descr)	\
365 	sysctl_add_oid(ctx, parent, nbr, name, CTLTYPE_S64|(access),	\
366 	ptr, 0, sysctl_handle_64, "Q", descr)
367 
368 /* Oid for an unsigned 8-bit int.  The pointer must be non NULL. */
369 #define SYSCTL_U8(parent, nbr, name, access, ptr, val, descr)	\
370 	SYSCTL_OID(parent, nbr, name, CTLTYPE_U8|(access),		\
371 		ptr, val, sysctl_handle_8, "CU", descr)
372 
373 #define SYSCTL_ADD_U8(ctx, parent, nbr, name, access, ptr, descr)	\
374 	sysctl_add_oid(ctx, parent, nbr, name, CTLTYPE_U8|(access),	\
375 	ptr, 0, sysctl_handle_8, "CU", descr)
376 
377 /* Oid for an unsigned 16-bit int.  The pointer must be non NULL. */
378 #define SYSCTL_U16(parent, nbr, name, access, ptr, val, descr)	\
379 	SYSCTL_OID(parent, nbr, name, CTLTYPE_U16|(access),		\
380 		ptr, val, sysctl_handle_16, "SU", descr)
381 
382 #define SYSCTL_ADD_U16(ctx, parent, nbr, name, access, ptr, descr)	\
383 	sysctl_add_oid(ctx, parent, nbr, name, CTLTYPE_U16|(access),	\
384 	ptr, 0, sysctl_handle_16, "SU", descr)
385 
386 /* Oid for an unsigned 32-bit int.  The pointer must be non NULL. */
387 #define SYSCTL_U32(parent, nbr, name, access, ptr, val, descr)	\
388 	SYSCTL_OID(parent, nbr, name, CTLTYPE_U32|(access),		\
389 		ptr, val, sysctl_handle_32, "IU", descr)
390 
391 #define SYSCTL_ADD_U32(ctx, parent, nbr, name, access, ptr, descr)	\
392 	sysctl_add_oid(ctx, parent, nbr, name, CTLTYPE_U32|(access),	\
393 	ptr, 0, sysctl_handle_32, "IU", descr)
394 
395 /* Oid for an unsigned 64-bit int.  The pointer must be non NULL. */
396 #define SYSCTL_U64(parent, nbr, name, access, ptr, val, descr)	\
397 	SYSCTL_OID(parent, nbr, name, CTLTYPE_U64|(access),		\
398 		ptr, val, sysctl_handle_64, "QU", descr)
399 
400 #define SYSCTL_ADD_U64(ctx, parent, nbr, name, access, ptr, descr)	\
401 	sysctl_add_oid(ctx, parent, nbr, name, CTLTYPE_U64|(access),	\
402 	ptr, 0, sysctl_handle_64, "QU", descr)
403 
404 /* Oid for an opaque object.  Specified by a pointer and a length. */
405 #define SYSCTL_OPAQUE(parent, nbr, name, access, ptr, len, fmt, descr)	\
406 	SYSCTL_OID(parent, nbr, name, CTLTYPE_OPAQUE|(access),		\
407 		ptr, len, sysctl_handle_opaque, fmt, descr)
408 
409 #define SYSCTL_ADD_OPAQUE(ctx, parent, nbr, name, access, ptr, len, fmt, descr) \
410 	sysctl_add_oid(ctx, parent, nbr, name, CTLTYPE_OPAQUE|(access),	\
411 	ptr, len, sysctl_handle_opaque, fmt, descr)
412 
413 /* Oid for a struct.  Specified by a pointer and a type. */
414 #define SYSCTL_STRUCT(parent, nbr, name, access, ptr, type, descr)	\
415 	SYSCTL_OID(parent, nbr, name, CTLTYPE_OPAQUE|(access),		\
416 		ptr, sizeof(struct type), sysctl_handle_opaque,		\
417 		"S," #type, descr)
418 
419 #define SYSCTL_ADD_STRUCT(ctx, parent, nbr, name, access, ptr, type, descr) \
420 	sysctl_add_oid(ctx, parent, nbr, name, CTLTYPE_OPAQUE|(access),	\
421 	ptr, sizeof(struct type), sysctl_handle_opaque, "S," #type, descr)
422 
423 /* Oid for a procedure.  Specified by a pointer and an arg. */
424 #define SYSCTL_PROC(parent, nbr, name, access, ptr, arg, handler, fmt, descr) \
425 	SYSCTL_OID(parent, nbr, name, (access),				\
426 		ptr, arg, handler, fmt, descr)
427 
428 #define SYSCTL_ADD_PROC(ctx, parent, nbr, name, access, ptr, arg, handler, fmt, descr) \
429 	sysctl_add_oid(ctx, parent, nbr, name, (access),		\
430 	ptr, arg, handler, fmt, descr)
431 
432 #endif /* _KERNEL */
433 
434 /*
435  * Top-level identifiers
436  */
437 #define	CTL_UNSPEC	0		/* unused */
438 #define	CTL_KERN	1		/* "high kernel": proc, limits */
439 #define	CTL_VM		2		/* virtual memory */
440 #define	CTL_VFS		3		/* file system, mount type is next */
441 #define	CTL_NET		4		/* network, see socket.h */
442 #define	CTL_DEBUG	5		/* debugging parameters */
443 #define	CTL_HW		6		/* generic cpu/io */
444 #define	CTL_MACHDEP	7		/* machine dependent */
445 #define	CTL_USER	8		/* user-level */
446 #define	CTL_P1003_1B	9		/* POSIX 1003.1B */
447 #define CTL_LWKT	10		/* light weight kernel threads */
448 #define	CTL_MAXID	11		/* number of valid top-level ids */
449 
450 #define CTL_NAMES { \
451 	{ 0, 0 }, \
452 	{ "kern", CTLTYPE_NODE }, \
453 	{ "vm", CTLTYPE_NODE }, \
454 	{ "vfs", CTLTYPE_NODE }, \
455 	{ "net", CTLTYPE_NODE }, \
456 	{ "debug", CTLTYPE_NODE }, \
457 	{ "hw", CTLTYPE_NODE }, \
458 	{ "machdep", CTLTYPE_NODE }, \
459 	{ "user", CTLTYPE_NODE }, \
460 	{ "p1003_1b", CTLTYPE_NODE }, \
461 	{ "lwkt", CTLTYPE_NODE }, \
462 }
463 
464 /*
465  * CTL_KERN identifiers
466  */
467 #define	KERN_OSTYPE	 	 1	/* string: system version */
468 #define	KERN_OSRELEASE	 	 2	/* string: system release */
469 #define	KERN_OSREV	 	 3	/* int: system revision */
470 #define	KERN_VERSION	 	 4	/* string: compile time info */
471 #define	KERN_MAXVNODES	 	 5	/* int: max vnodes */
472 #define	KERN_MAXPROC	 	 6	/* int: max processes */
473 #define	KERN_MAXFILES	 	 7	/* int: max open files */
474 #define	KERN_ARGMAX	 	 8	/* int: max arguments to exec */
475 #define	KERN_SECURELVL	 	 9	/* int: system security level */
476 #define	KERN_HOSTNAME		10	/* string: hostname */
477 #define	KERN_HOSTID		11	/* int: host identifier */
478 #define	KERN_CLOCKRATE		12	/* struct: struct clockrate */
479 #define	KERN_VNODE		13	/* struct: vnode structures */
480 #define	KERN_PROC		14	/* struct: process entries */
481 #define	KERN_FILE		15	/* struct: file entries */
482 #define	KERN_UNUSED16		16	/* was: node: kernel profiling info */
483 #define	KERN_POSIX1		17	/* int: POSIX.1 version */
484 #define	KERN_NGROUPS		18	/* int: # of supplemental group ids */
485 #define	KERN_JOB_CONTROL	19	/* int: is job control available */
486 #define	KERN_SAVED_IDS		20	/* int: saved set-user/group-ID */
487 #define	KERN_BOOTTIME		21	/* struct: time kernel was booted */
488 #define KERN_NISDOMAINNAME	22	/* string: YP domain name */
489 #define KERN_UPDATEINTERVAL	23	/* int: update process sleep time */
490 #define KERN_OSRELDATE		24	/* int: OS release date */
491 #define KERN_NTP_PLL		25	/* node: NTP PLL control */
492 #define	KERN_BOOTFILE		26	/* string: name of booted kernel */
493 #define	KERN_MAXFILESPERPROC	27	/* int: max open files per proc */
494 #define	KERN_MAXPROCPERUID 	28	/* int: max processes per uid */
495 #define KERN_DUMPDEV		29	/* udev_t: device to dump on */
496 #define	KERN_IPC		30	/* node: anything related to IPC */
497 #define	KERN_DUMMY		31	/* unused */
498 #define	KERN_PS_STRINGS		32	/* int: address of PS_STRINGS */
499 #define	KERN_USRSTACK		33	/* int: address of USRSTACK */
500 #define	KERN_LOGSIGEXIT		34	/* int: do we log sigexit procs? */
501 #define	KERN_IOV_MAX		35	/* int: value of UIO_MAXIOV */
502 #define KERN_MAXPOSIXLOCKSPERUID 36	/* int: max POSIX locks per uid */
503 #define KERN_MAXID		37      /* number of valid kern ids */
504 
505 #define CTL_KERN_NAMES { \
506 	{ 0, 0 }, \
507 	{ "ostype", CTLTYPE_STRING }, \
508 	{ "osrelease", CTLTYPE_STRING }, \
509 	{ "osrevision", CTLTYPE_INT }, \
510 	{ "version", CTLTYPE_STRING }, \
511 	{ "maxvnodes", CTLTYPE_INT }, \
512 	{ "maxproc", CTLTYPE_INT }, \
513 	{ "maxfiles", CTLTYPE_INT }, \
514 	{ "argmax", CTLTYPE_INT }, \
515 	{ "securelevel", CTLTYPE_INT }, \
516 	{ "hostname", CTLTYPE_STRING }, \
517 	{ "hostid", CTLTYPE_UINT }, \
518 	{ "clockrate", CTLTYPE_STRUCT }, \
519 	{ "vnode", CTLTYPE_STRUCT }, \
520 	{ "proc", CTLTYPE_STRUCT }, \
521 	{ "file", CTLTYPE_STRUCT }, \
522 	{ "profiling", CTLTYPE_NODE }, \
523 	{ "posix1version", CTLTYPE_INT }, \
524 	{ "ngroups", CTLTYPE_INT }, \
525 	{ "job_control", CTLTYPE_INT }, \
526 	{ "saved_ids", CTLTYPE_INT }, \
527 	{ "boottime", CTLTYPE_STRUCT }, \
528 	{ "nisdomainname", CTLTYPE_STRING }, \
529 	{ "update", CTLTYPE_INT }, \
530 	{ "osreldate", CTLTYPE_INT }, \
531 	{ "ntp_pll", CTLTYPE_NODE }, \
532 	{ "bootfile", CTLTYPE_STRING }, \
533 	{ "maxfilesperproc", CTLTYPE_INT }, \
534 	{ "maxprocperuid", CTLTYPE_INT }, \
535 	{ "dumpdev", CTLTYPE_STRUCT }, /* we lie; don't print as int */ \
536 	{ "ipc", CTLTYPE_NODE }, \
537 	{ "dummy", CTLTYPE_INT }, \
538 	{ "ps_strings", CTLTYPE_INT }, \
539 	{ "usrstack", CTLTYPE_INT }, \
540 	{ "logsigexit", CTLTYPE_INT }, \
541 	{ "iov_max", CTLTYPE_INT }, \
542 	{ "maxposixlocksperuid", CTLTYPE_INT }, \
543 }
544 
545 /*
546  * CTL_VFS identifiers
547  */
548 #define CTL_VFS_NAMES { \
549 	{ "vfsconf", CTLTYPE_STRUCT }, \
550 }
551 
552 /*
553  * KERN_PROC subtypes
554  */
555 #define KERN_PROC_ALL		0	/* everything */
556 #define	KERN_PROC_PID		1	/* by process id */
557 #define	KERN_PROC_PGRP		2	/* by process group id */
558 #define	KERN_PROC_SESSION	3	/* by session of pid */
559 #define	KERN_PROC_TTY		4	/* by controlling tty */
560 #define	KERN_PROC_UID		5	/* by effective uid */
561 #define	KERN_PROC_RUID		6	/* by real uid */
562 #define	KERN_PROC_ARGS		7	/* get/set arguments/proctitle */
563 #define	KERN_PROC_CWD		8	/* get cwd */
564 #define	KERN_PROC_PATHNAME      9	/* path to executable */
565 #define KERN_PROC_SIGTRAMP	10	/* addr[2]: sigtramp addr range */
566 
567 #define KERN_PROC_FLAGMASK	0x10
568 #define KERN_PROC_FLAG_LWP	0x10
569 
570 /*
571  * KERN_IPC identifiers
572  */
573 #define KIPC_MAXSOCKBUF		1	/* int: max size of a socket buffer */
574 #define	KIPC_SOCKBUF_WASTE	2	/* int: wastage factor in sockbuf */
575 #define	KIPC_SOMAXCONN		3	/* int: max length of connection q */
576 #define	KIPC_MAX_LINKHDR	4	/* int: max length of link header */
577 #define	KIPC_MAX_PROTOHDR	5	/* int: max length of network header */
578 #define	KIPC_MAX_HDR		6	/* int: max total length of headers */
579 #define	KIPC_MAX_DATALEN	7	/* int: max length of data? */
580 #define	KIPC_MBSTAT		8	/* struct: mbuf usage statistics */
581 #define	KIPC_NMBCLUSTERS	9	/* int: maximum mbuf clusters */
582 
583 /*
584  * CTL_HW identifiers
585  */
586 #define	HW_MACHINE	 1		/* string: machine class */
587 #define	HW_MODEL	 2		/* string: specific machine model */
588 #define	HW_NCPU		 3		/* int: number of cpus */
589 #define	HW_BYTEORDER	 4		/* int: machine byte order */
590 #define	HW_PHYSMEM	 5		/* int: total memory */
591 #define	HW_USERMEM	 6		/* int: non-kernel memory */
592 #define	HW_PAGESIZE	 7		/* int: software page size */
593 #define	HW_DISKNAMES	 8		/* strings: disk drive names */
594 #define	HW_DISKSTATS	 9		/* struct: diskstats[] */
595 #define HW_FLOATINGPT	10		/* int: has HW floating point? */
596 #define HW_MACHINE_ARCH	11		/* string: machine architecture */
597 #define HW_MACHINE_PLATFORM 12		/* string: platform architecture */
598 #define HW_SENSORS	13		/* node: hardware sensors */
599 #define HW_MAXID	14		/* number of valid hw ids */
600 
601 #define CTL_HW_NAMES { \
602 	{ 0, 0 }, \
603 	{ "machine", CTLTYPE_STRING }, \
604 	{ "model", CTLTYPE_STRING }, \
605 	{ "ncpu", CTLTYPE_INT }, \
606 	{ "byteorder", CTLTYPE_INT }, \
607 	{ "physmem", CTLTYPE_ULONG }, \
608 	{ "usermem", CTLTYPE_UINT }, \
609 	{ "pagesize", CTLTYPE_INT }, \
610 	{ "disknames", CTLTYPE_STRUCT }, \
611 	{ "diskstats", CTLTYPE_STRUCT }, \
612 	{ "floatingpoint", CTLTYPE_INT }, \
613 	{ "arch", CTLTYPE_STRING }, \
614 	{ "platform", CTLTYPE_STRING }, \
615 	{ "sensors", CTLTYPE_NODE }, \
616 }
617 
618 /*
619  * CTL_USER definitions
620  */
621 #define	USER_CS_PATH		 1	/* string: _CS_PATH */
622 #define	USER_BC_BASE_MAX	 2	/* int: BC_BASE_MAX */
623 #define	USER_BC_DIM_MAX		 3	/* int: BC_DIM_MAX */
624 #define	USER_BC_SCALE_MAX	 4	/* int: BC_SCALE_MAX */
625 #define	USER_BC_STRING_MAX	 5	/* int: BC_STRING_MAX */
626 #define	USER_COLL_WEIGHTS_MAX	 6	/* int: COLL_WEIGHTS_MAX */
627 #define	USER_EXPR_NEST_MAX	 7	/* int: EXPR_NEST_MAX */
628 #define	USER_LINE_MAX		 8	/* int: LINE_MAX */
629 #define	USER_RE_DUP_MAX		 9	/* int: RE_DUP_MAX */
630 #define	USER_POSIX2_VERSION	10	/* int: _POSIX2_VERSION */
631 #define	USER_POSIX2_C_BIND	11	/* int: _POSIX2_C_BIND */
632 #define	USER_POSIX2_C_DEV	12	/* int: _POSIX2_C_DEV */
633 #define	USER_POSIX2_CHAR_TERM	13	/* int: _POSIX2_CHAR_TERM */
634 #define	USER_POSIX2_FORT_DEV	14	/* int: _POSIX2_FORT_DEV */
635 #define	USER_POSIX2_FORT_RUN	15	/* int: _POSIX2_FORT_RUN */
636 #define	USER_POSIX2_LOCALEDEF	16	/* int: _POSIX2_LOCALEDEF */
637 #define	USER_POSIX2_SW_DEV	17	/* int: _POSIX2_SW_DEV */
638 #define	USER_POSIX2_UPE		18	/* int: _POSIX2_UPE */
639 #define	USER_STREAM_MAX		19	/* int: _POSIX2_STREAM_MAX */
640 #define	USER_TZNAME_MAX		20	/* int: _POSIX2_TZNAME_MAX */
641 #define	USER_MAXID		21	/* number of valid user ids */
642 
643 #define	CTL_USER_NAMES { \
644 	{ 0, 0 }, \
645 	{ "cs_path", CTLTYPE_STRING }, \
646 	{ "bc_base_max", CTLTYPE_INT }, \
647 	{ "bc_dim_max", CTLTYPE_INT }, \
648 	{ "bc_scale_max", CTLTYPE_INT }, \
649 	{ "bc_string_max", CTLTYPE_INT }, \
650 	{ "coll_weights_max", CTLTYPE_INT }, \
651 	{ "expr_nest_max", CTLTYPE_INT }, \
652 	{ "line_max", CTLTYPE_INT }, \
653 	{ "re_dup_max", CTLTYPE_INT }, \
654 	{ "posix2_version", CTLTYPE_INT }, \
655 	{ "posix2_c_bind", CTLTYPE_INT }, \
656 	{ "posix2_c_dev", CTLTYPE_INT }, \
657 	{ "posix2_char_term", CTLTYPE_INT }, \
658 	{ "posix2_fort_dev", CTLTYPE_INT }, \
659 	{ "posix2_fort_run", CTLTYPE_INT }, \
660 	{ "posix2_localedef", CTLTYPE_INT }, \
661 	{ "posix2_sw_dev", CTLTYPE_INT }, \
662 	{ "posix2_upe", CTLTYPE_INT }, \
663 	{ "stream_max", CTLTYPE_INT }, \
664 	{ "tzname_max", CTLTYPE_INT }, \
665 }
666 
667 #define CTL_P1003_1B_ASYNCHRONOUS_IO		1	/* boolean */
668 #define CTL_P1003_1B_MAPPED_FILES		2	/* boolean */
669 #define CTL_P1003_1B_MEMLOCK			3	/* boolean */
670 #define CTL_P1003_1B_MEMLOCK_RANGE		4	/* boolean */
671 #define CTL_P1003_1B_MEMORY_PROTECTION		5	/* boolean */
672 #define CTL_P1003_1B_MESSAGE_PASSING		6	/* boolean */
673 #define CTL_P1003_1B_PRIORITIZED_IO		7	/* boolean */
674 #define CTL_P1003_1B_PRIORITY_SCHEDULING	8	/* boolean */
675 #define CTL_P1003_1B_REALTIME_SIGNALS		9	/* boolean */
676 #define CTL_P1003_1B_SEMAPHORES			10	/* boolean */
677 #define CTL_P1003_1B_FSYNC			11	/* boolean */
678 #define CTL_P1003_1B_SHARED_MEMORY_OBJECTS	12	/* boolean */
679 #define CTL_P1003_1B_SYNCHRONIZED_IO		13	/* boolean */
680 #define CTL_P1003_1B_TIMERS			14	/* boolean */
681 #define CTL_P1003_1B_AIO_LISTIO_MAX		15	/* int */
682 #define CTL_P1003_1B_AIO_MAX			16	/* int */
683 #define CTL_P1003_1B_AIO_PRIO_DELTA_MAX		17	/* int */
684 #define CTL_P1003_1B_DELAYTIMER_MAX		18	/* int */
685 #define CTL_P1003_1B_UNUSED1			19	/* int */
686 #define CTL_P1003_1B_PAGESIZE			20	/* int */
687 #define CTL_P1003_1B_RTSIG_MAX			21	/* int */
688 #define CTL_P1003_1B_SEM_NSEMS_MAX		22	/* int */
689 #define CTL_P1003_1B_SEM_VALUE_MAX		23	/* int */
690 #define CTL_P1003_1B_SIGQUEUE_MAX		24	/* int */
691 #define CTL_P1003_1B_TIMER_MAX			25	/* int */
692 
693 #define CTL_P1003_1B_MAXID		26
694 
695 #define	CTL_P1003_1B_NAMES { \
696 	{ 0, 0 }, \
697 	{ "asynchronous_io", CTLTYPE_INT }, \
698 	{ "mapped_files", CTLTYPE_INT }, \
699 	{ "memlock", CTLTYPE_INT }, \
700 	{ "memlock_range", CTLTYPE_INT }, \
701 	{ "memory_protection", CTLTYPE_INT }, \
702 	{ "message_passing", CTLTYPE_INT }, \
703 	{ "prioritized_io", CTLTYPE_INT }, \
704 	{ "priority_scheduling", CTLTYPE_INT }, \
705 	{ "realtime_signals", CTLTYPE_INT }, \
706 	{ "semaphores", CTLTYPE_INT }, \
707 	{ "fsync", CTLTYPE_INT }, \
708 	{ "shared_memory_objects", CTLTYPE_INT }, \
709 	{ "synchronized_io", CTLTYPE_INT }, \
710 	{ "timers", CTLTYPE_INT }, \
711 	{ "aio_listio_max", CTLTYPE_INT }, \
712 	{ "aio_max", CTLTYPE_INT }, \
713 	{ "aio_prio_delta_max", CTLTYPE_INT }, \
714 	{ "delaytimer_max", CTLTYPE_INT }, \
715 	{ "unused1", CTLTYPE_INT }, \
716 	{ "pagesize", CTLTYPE_INT }, \
717 	{ "rtsig_max", CTLTYPE_INT }, \
718 	{ "nsems_max", CTLTYPE_INT }, \
719 	{ "sem_value_max", CTLTYPE_INT }, \
720 	{ "sigqueue_max", CTLTYPE_INT }, \
721 	{ "timer_max", CTLTYPE_INT }, \
722 }
723 
724 #ifdef _KERNEL
725 
726 /*
727  * Declare some common oids.
728  */
729 extern struct sysctl_oid_list sysctl__children;
730 SYSCTL_DECL(_kern);
731 SYSCTL_DECL(_sysctl);
732 SYSCTL_DECL(_vm);
733 SYSCTL_DECL(_vfs);
734 SYSCTL_DECL(_net);
735 SYSCTL_DECL(_debug);
736 SYSCTL_DECL(_debug_sizeof);
737 SYSCTL_DECL(_dev);
738 SYSCTL_DECL(_hw);
739 SYSCTL_DECL(_hw_bus);
740 SYSCTL_DECL(_machdep);
741 SYSCTL_DECL(_user);
742 SYSCTL_DECL(_compat);
743 SYSCTL_DECL(_lwkt);
744 SYSCTL_DECL(_security);
745 
746 /*
747  * Common second-level oids.
748  */
749 SYSCTL_DECL(_kern_ipc);
750 
751 extern char	machine[];
752 extern char	osrelease[];
753 extern char	ostype[];
754 extern char	kern_ident[];
755 
756 /* Dynamic oid handling */
757 struct sysctl_oid *sysctl_add_oid(struct sysctl_ctx_list *clist,
758 		struct sysctl_oid_list *parent, int nbr, const char *name,
759 		int kind, void *arg1, int arg2,
760 		int (*handler) (SYSCTL_HANDLER_ARGS),
761 		const char *fmt, const char *descr);
762 void	sysctl_rename_oid(struct sysctl_oid *oidp, const char *name);
763 int	sysctl_remove_name(struct sysctl_oid *parent, const char *name, int del,
764 	    int recurse);
765 int	sysctl_remove_oid(struct sysctl_oid *oidp, int del, int recurse);
766 int	sysctl_ctx_init(struct sysctl_ctx_list *clist);
767 int	sysctl_ctx_free(struct sysctl_ctx_list *clist);
768 struct	sysctl_ctx_entry *sysctl_ctx_entry_add(struct sysctl_ctx_list *clist,
769 		struct sysctl_oid *oidp);
770 struct	sysctl_ctx_entry *sysctl_ctx_entry_find(struct sysctl_ctx_list *clist,
771 		struct sysctl_oid *oidp);
772 int	sysctl_ctx_entry_del(struct sysctl_ctx_list *clist,
773 		struct sysctl_oid *oidp);
774 
775 int	kernel_sysctl(int *name, u_int namelen, void *old,
776 		      size_t *oldlenp, void *new, size_t newlen,
777 		      size_t *retval);
778 int	kernel_sysctlbyname(char *name,
779 		void *old, size_t *oldlenp, void *new, size_t newlen,
780 		size_t *retval);
781 int	userland_sysctl(int *name, u_int namelen, void *old,
782 	    size_t *oldlenp, int inkernel, void *new, size_t newlen,
783 	    size_t *retval);
784 int	sysctl_find_oid(int *name, u_int namelen, struct sysctl_oid **noid,
785 			int *nindx, struct sysctl_req *req);
786 
787 int	sysctl_int_range(SYSCTL_HANDLER_ARGS, int low, int high);
788 void	_sysctl_xlock(void);
789 void	_sysctl_xunlock(void);
790 
791 struct sbuf;
792 struct sbuf *sbuf_new_for_sysctl(struct sbuf *, char *, int,
793 	    struct sysctl_req *);
794 
795 #endif	/* _KERNEL */
796 
797 #if !defined(_KERNEL) || defined(_KERNEL_VIRTUAL)
798 
799 #include <sys/cdefs.h>
800 
801 __BEGIN_DECLS
802 int	sysctl(const int *, u_int, void *, size_t *, const void *, size_t);
803 int	sysctlbyname(const char *, void *, size_t *, const void *, size_t);
804 int	sysctlnametomib (const char *, int *, size_t *);
805 __END_DECLS
806 
807 #endif	/* _KERNEL && _KERNEL_VIRTUAL */
808 
809 #endif	/* !_SYS_SYSCTL_H_ */
810