sysctl.h revision 330897
1/*-
2 * SPDX-License-Identifier: BSD-3-Clause
3 *
4 * Copyright (c) 1989, 1993
5 *	The Regents of the University of California.  All rights reserved.
6 *
7 * This code is derived from software contributed to Berkeley by
8 * Mike Karels at Berkeley Software Design, Inc.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 *    notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 *    notice, this list of conditions and the following disclaimer in the
17 *    documentation and/or other materials provided with the distribution.
18 * 4. Neither the name of the University nor the names of its contributors
19 *    may be used to endorse or promote products derived from this software
20 *    without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
33 *
34 *	@(#)sysctl.h	8.1 (Berkeley) 6/2/93
35 * $FreeBSD: stable/11/sys/sys/sysctl.h 330897 2018-03-14 03:19:51Z eadler $
36 */
37
38#ifndef _SYS_SYSCTL_H_
39#define	_SYS_SYSCTL_H_
40
41#include <sys/queue.h>
42
43struct thread;
44/*
45 * Definitions for sysctl call.  The sysctl call uses a hierarchical name
46 * for objects that can be examined or modified.  The name is expressed as
47 * a sequence of integers.  Like a file path name, the meaning of each
48 * component depends on its place in the hierarchy.  The top-level and kern
49 * identifiers are defined here, and other identifiers are defined in the
50 * respective subsystem header files.
51 */
52
53#define	CTL_MAXNAME	24	/* largest number of components supported */
54
55/*
56 * Each subsystem defined by sysctl defines a list of variables
57 * for that subsystem. Each name is either a node with further
58 * levels defined below it, or it is a leaf of some particular
59 * type given below. Each sysctl level defines a set of name/type
60 * pairs to be used by sysctl(8) in manipulating the subsystem.
61 */
62struct ctlname {
63	char	*ctl_name;	/* subsystem name */
64	int	 ctl_type;	/* type of name */
65};
66
67#define	CTLTYPE		0xf	/* mask for the type */
68#define	CTLTYPE_NODE	1	/* name is a node */
69#define	CTLTYPE_INT	2	/* name describes an integer */
70#define	CTLTYPE_STRING	3	/* name describes a string */
71#define	CTLTYPE_S64	4	/* name describes a signed 64-bit number */
72#define	CTLTYPE_OPAQUE	5	/* name describes a structure */
73#define	CTLTYPE_STRUCT	CTLTYPE_OPAQUE	/* name describes a structure */
74#define	CTLTYPE_UINT	6	/* name describes an unsigned integer */
75#define	CTLTYPE_LONG	7	/* name describes a long */
76#define	CTLTYPE_ULONG	8	/* name describes an unsigned long */
77#define	CTLTYPE_U64	9	/* name describes an unsigned 64-bit number */
78#define	CTLTYPE_U8	0xa	/* name describes an unsigned 8-bit number */
79#define	CTLTYPE_U16	0xb	/* name describes an unsigned 16-bit number */
80#define	CTLTYPE_S8	0xc	/* name describes a signed 8-bit number */
81#define	CTLTYPE_S16	0xd	/* name describes a signed 16-bit number */
82#define	CTLTYPE_S32	0xe	/* name describes a signed 32-bit number */
83#define	CTLTYPE_U32	0xf	/* name describes an unsigned 32-bit number */
84
85#define	CTLFLAG_RD	0x80000000	/* Allow reads of variable */
86#define	CTLFLAG_WR	0x40000000	/* Allow writes to the variable */
87#define	CTLFLAG_RW	(CTLFLAG_RD|CTLFLAG_WR)
88#define	CTLFLAG_DORMANT	0x20000000	/* This sysctl is not active yet */
89#define	CTLFLAG_ANYBODY	0x10000000	/* All users can set this var */
90#define	CTLFLAG_SECURE	0x08000000	/* Permit set only if securelevel<=0 */
91#define	CTLFLAG_PRISON	0x04000000	/* Prisoned roots can fiddle */
92#define	CTLFLAG_DYN	0x02000000	/* Dynamic oid - can be freed */
93#define	CTLFLAG_SKIP	0x01000000	/* Skip this sysctl when listing */
94#define	CTLMASK_SECURE	0x00F00000	/* Secure level */
95#define	CTLFLAG_TUN	0x00080000	/* Default value is loaded from getenv() */
96#define	CTLFLAG_RDTUN	(CTLFLAG_RD|CTLFLAG_TUN)
97#define	CTLFLAG_RWTUN	(CTLFLAG_RW|CTLFLAG_TUN)
98#define	CTLFLAG_MPSAFE	0x00040000	/* Handler is MP safe */
99#define	CTLFLAG_VNET	0x00020000	/* Prisons with vnet can fiddle */
100#define	CTLFLAG_DYING	0x00010000	/* Oid is being removed */
101#define	CTLFLAG_CAPRD	0x00008000	/* Can be read in capability mode */
102#define	CTLFLAG_CAPWR	0x00004000	/* Can be written in capability mode */
103#define	CTLFLAG_STATS	0x00002000	/* Statistics, not a tuneable */
104#define	CTLFLAG_NOFETCH	0x00001000	/* Don't fetch tunable from getenv() */
105#define	CTLFLAG_CAPRW	(CTLFLAG_CAPRD|CTLFLAG_CAPWR)
106
107/*
108 * Secure level.   Note that CTLFLAG_SECURE == CTLFLAG_SECURE1.
109 *
110 * Secure when the securelevel is raised to at least N.
111 */
112#define	CTLSHIFT_SECURE	20
113#define	CTLFLAG_SECURE1	(CTLFLAG_SECURE | (0 << CTLSHIFT_SECURE))
114#define	CTLFLAG_SECURE2	(CTLFLAG_SECURE | (1 << CTLSHIFT_SECURE))
115#define	CTLFLAG_SECURE3	(CTLFLAG_SECURE | (2 << CTLSHIFT_SECURE))
116
117/*
118 * USE THIS instead of a hardwired number from the categories below
119 * to get dynamically assigned sysctl entries using the linker-set
120 * technology. This is the way nearly all new sysctl variables should
121 * be implemented.
122 * e.g. SYSCTL_INT(_parent, OID_AUTO, name, CTLFLAG_RW, &variable, 0, "");
123 */
124#define	OID_AUTO	(-1)
125
126/*
127 * The starting number for dynamically-assigned entries.  WARNING!
128 * ALL static sysctl entries should have numbers LESS than this!
129 */
130#define	CTL_AUTO_START	0x100
131
132#ifdef _KERNEL
133#include <sys/linker_set.h>
134
135#ifdef KLD_MODULE
136/* XXX allow overspecification of type in external kernel modules */
137#define	SYSCTL_CT_ASSERT_MASK CTLTYPE
138#else
139#define	SYSCTL_CT_ASSERT_MASK 0
140#endif
141
142#define	SYSCTL_HANDLER_ARGS struct sysctl_oid *oidp, void *arg1,	\
143	intmax_t arg2, struct sysctl_req *req
144
145/* definitions for sysctl_req 'lock' member */
146#define	REQ_UNWIRED	1
147#define	REQ_WIRED	2
148
149/* definitions for sysctl_req 'flags' member */
150#if defined(__amd64__) || defined(__powerpc64__) ||\
151    (defined(__mips__) && defined(__mips_n64))
152#define	SCTL_MASK32	1	/* 32 bit emulation */
153#endif
154
155/*
156 * This describes the access space for a sysctl request.  This is needed
157 * so that we can use the interface from the kernel or from user-space.
158 */
159struct sysctl_req {
160	struct thread	*td;		/* used for access checking */
161	int		 lock;		/* wiring state */
162	void		*oldptr;
163	size_t		 oldlen;
164	size_t		 oldidx;
165	int		(*oldfunc)(struct sysctl_req *, const void *, size_t);
166	void		*newptr;
167	size_t		 newlen;
168	size_t		 newidx;
169	int		(*newfunc)(struct sysctl_req *, void *, size_t);
170	size_t		 validlen;
171	int		 flags;
172};
173
174SLIST_HEAD(sysctl_oid_list, sysctl_oid);
175
176/*
177 * This describes one "oid" in the MIB tree.  Potentially more nodes can
178 * be hidden behind it, expanded by the handler.
179 */
180struct sysctl_oid {
181	struct sysctl_oid_list oid_children;
182	struct sysctl_oid_list *oid_parent;
183	SLIST_ENTRY(sysctl_oid) oid_link;
184	int		 oid_number;
185	u_int		 oid_kind;
186	void		*oid_arg1;
187	intmax_t	 oid_arg2;
188	const char	*oid_name;
189	int		(*oid_handler)(SYSCTL_HANDLER_ARGS);
190	const char	*oid_fmt;
191	int		 oid_refcnt;
192	u_int		 oid_running;
193	const char	*oid_descr;
194};
195
196#define	SYSCTL_IN(r, p, l)	(r->newfunc)(r, p, l)
197#define	SYSCTL_OUT(r, p, l)	(r->oldfunc)(r, p, l)
198#define	SYSCTL_OUT_STR(r, p)	(r->oldfunc)(r, p, strlen(p) + 1)
199
200int sysctl_handle_bool(SYSCTL_HANDLER_ARGS);
201int sysctl_handle_8(SYSCTL_HANDLER_ARGS);
202int sysctl_handle_16(SYSCTL_HANDLER_ARGS);
203int sysctl_handle_32(SYSCTL_HANDLER_ARGS);
204int sysctl_handle_64(SYSCTL_HANDLER_ARGS);
205int sysctl_handle_int(SYSCTL_HANDLER_ARGS);
206int sysctl_msec_to_ticks(SYSCTL_HANDLER_ARGS);
207int sysctl_handle_long(SYSCTL_HANDLER_ARGS);
208int sysctl_handle_string(SYSCTL_HANDLER_ARGS);
209int sysctl_handle_opaque(SYSCTL_HANDLER_ARGS);
210int sysctl_handle_counter_u64(SYSCTL_HANDLER_ARGS);
211int sysctl_handle_counter_u64_array(SYSCTL_HANDLER_ARGS);
212
213int sysctl_handle_uma_zone_max(SYSCTL_HANDLER_ARGS);
214int sysctl_handle_uma_zone_cur(SYSCTL_HANDLER_ARGS);
215
216int sysctl_dpcpu_int(SYSCTL_HANDLER_ARGS);
217int sysctl_dpcpu_long(SYSCTL_HANDLER_ARGS);
218int sysctl_dpcpu_quad(SYSCTL_HANDLER_ARGS);
219
220/*
221 * These functions are used to add/remove an oid from the mib.
222 */
223void sysctl_register_oid(struct sysctl_oid *oidp);
224void sysctl_register_disabled_oid(struct sysctl_oid *oidp);
225void sysctl_enable_oid(struct sysctl_oid *oidp);
226void sysctl_unregister_oid(struct sysctl_oid *oidp);
227
228/* Declare a static oid to allow child oids to be added to it. */
229#define	SYSCTL_DECL(name)			\
230	extern struct sysctl_oid sysctl__##name
231
232/* Hide these in macros. */
233#define	SYSCTL_CHILDREN(oid_ptr)		(&(oid_ptr)->oid_children)
234#define	SYSCTL_PARENT(oid_ptr)					\
235    (((oid_ptr)->oid_parent != &sysctl__children) ?		\
236	__containerof((oid_ptr)->oid_parent, struct sysctl_oid,	\
237	oid_children) : (struct sysctl_oid *)NULL)
238#define	SYSCTL_STATIC_CHILDREN(oid_name)	(&sysctl__##oid_name.oid_children)
239
240/* === Structs and macros related to context handling. === */
241
242/* All dynamically created sysctls can be tracked in a context list. */
243struct sysctl_ctx_entry {
244	struct sysctl_oid *entry;
245	TAILQ_ENTRY(sysctl_ctx_entry) link;
246};
247
248TAILQ_HEAD(sysctl_ctx_list, sysctl_ctx_entry);
249
250#define	SYSCTL_NODE_CHILDREN(parent, name) \
251	sysctl__##parent##_##name.oid_children
252
253#ifndef NO_SYSCTL_DESCR
254#define	__DESCR(d) d
255#else
256#define	__DESCR(d) ""
257#endif
258
259/* This macro is only for internal use */
260#define	SYSCTL_OID_RAW(id, parent_child_head, nbr, name, kind, a1, a2, handler, fmt, descr) \
261	struct sysctl_oid id = {					\
262		.oid_parent = (parent_child_head),			\
263		.oid_children = SLIST_HEAD_INITIALIZER(&id.oid_children), \
264		.oid_number = (nbr),					\
265		.oid_kind = (kind),					\
266		.oid_arg1 = (a1),					\
267		.oid_arg2 = (a2),					\
268		.oid_name = (name),					\
269		.oid_handler = (handler),				\
270		.oid_fmt = (fmt),					\
271		.oid_descr = __DESCR(descr)				\
272	};								\
273	DATA_SET(sysctl_set, id)
274
275/* This constructs a static "raw" MIB oid. */
276#define	SYSCTL_OID(parent, nbr, name, kind, a1, a2, handler, fmt, descr) \
277    static SYSCTL_OID_RAW(sysctl__##parent##_##name, \
278	SYSCTL_CHILDREN(&sysctl__##parent), \
279	nbr, #name, kind, a1, a2, handler, fmt, descr)
280
281/* This constructs a global "raw" MIB oid. */
282#define	SYSCTL_OID_GLOBAL(parent, nbr, name, kind, a1, a2, handler, fmt, descr) \
283    SYSCTL_OID_RAW(sysctl__##parent##_##name, \
284	SYSCTL_CHILDREN(&sysctl__##parent),	\
285	nbr, #name, kind, a1, a2, handler, fmt, descr)
286
287#define	SYSCTL_ADD_OID(ctx, parent, nbr, name, kind, a1, a2, handler, fmt, descr) \
288	sysctl_add_oid(ctx, parent, nbr, name, kind, a1, a2, handler, fmt, __DESCR(descr))
289
290/* This constructs a root node from which other nodes can hang. */
291#define	SYSCTL_ROOT_NODE(nbr, name, access, handler, descr)	\
292	SYSCTL_OID_RAW(sysctl___##name, &sysctl__children,	\
293	    nbr, #name, CTLTYPE_NODE|(access), NULL, 0,		\
294	    handler, "N", descr);				\
295	CTASSERT(((access) & CTLTYPE) == 0 ||			\
296	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_NODE)
297
298/* This constructs a node from which other oids can hang. */
299#define	SYSCTL_NODE(parent, nbr, name, access, handler, descr)		\
300	SYSCTL_OID_GLOBAL(parent, nbr, name, CTLTYPE_NODE|(access),	\
301	    NULL, 0, handler, "N", descr);				\
302	CTASSERT(((access) & CTLTYPE) == 0 ||				\
303	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_NODE)
304
305#define	SYSCTL_ADD_NODE(ctx, parent, nbr, name, access, handler, descr)	\
306({									\
307	CTASSERT(((access) & CTLTYPE) == 0 ||				\
308	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_NODE);	\
309	sysctl_add_oid(ctx, parent, nbr, name, CTLTYPE_NODE|(access),	\
310	    NULL, 0, handler, "N", __DESCR(descr));			\
311})
312
313#define	SYSCTL_ADD_ROOT_NODE(ctx, nbr, name, access, handler, descr)	\
314({									\
315	CTASSERT(((access) & CTLTYPE) == 0 ||				\
316	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_NODE);	\
317	sysctl_add_oid(ctx, &sysctl__children, nbr, name,		\
318	    CTLTYPE_NODE|(access),					\
319	    NULL, 0, handler, "N", __DESCR(descr));			\
320})
321
322/* Oid for a string.  len can be 0 to indicate '\0' termination. */
323#define	SYSCTL_STRING(parent, nbr, name, access, arg, len, descr)	\
324	SYSCTL_OID(parent, nbr, name, CTLTYPE_STRING|(access),		\
325	    arg, len, sysctl_handle_string, "A", descr);		\
326	CTASSERT(((access) & CTLTYPE) == 0 ||				\
327	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_STRING)
328
329#define	SYSCTL_ADD_STRING(ctx, parent, nbr, name, access, arg, len, descr) \
330({									\
331	char *__arg = (arg);						\
332	CTASSERT(((access) & CTLTYPE) == 0 ||				\
333	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_STRING);	\
334	sysctl_add_oid(ctx, parent, nbr, name, CTLTYPE_STRING|(access),	\
335	    __arg, len, sysctl_handle_string, "A", __DESCR(descr));	\
336})
337
338/* Oid for a bool.  If ptr is NULL, val is returned. */
339#define	SYSCTL_NULL_BOOL_PTR ((bool *)NULL)
340#define	SYSCTL_BOOL(parent, nbr, name, access, ptr, val, descr)	\
341	SYSCTL_OID(parent, nbr, name,				\
342	    CTLTYPE_U8 | CTLFLAG_MPSAFE | (access),		\
343	    ptr, val, sysctl_handle_bool, "CU", descr);		\
344	CTASSERT(((access) & CTLTYPE) == 0 &&			\
345	    sizeof(bool) == sizeof(*(ptr)))
346
347#define	SYSCTL_ADD_BOOL(ctx, parent, nbr, name, access, ptr, val, descr) \
348({									\
349	bool *__ptr = (ptr);						\
350	CTASSERT(((access) & CTLTYPE) == 0);				\
351	sysctl_add_oid(ctx, parent, nbr, name,				\
352	    CTLTYPE_U8 | CTLFLAG_MPSAFE | (access),			\
353	    __ptr, val, sysctl_handle_bool, "CU", __DESCR(descr));	\
354})
355
356/* Oid for a signed 8-bit int.  If ptr is NULL, val is returned. */
357#define	SYSCTL_NULL_S8_PTR ((int8_t *)NULL)
358#define	SYSCTL_S8(parent, nbr, name, access, ptr, val, descr)	\
359	SYSCTL_OID(parent, nbr, name,				\
360	    CTLTYPE_S8 | CTLFLAG_MPSAFE | (access),		\
361	    ptr, val, sysctl_handle_8, "C", descr);		\
362	CTASSERT((((access) & CTLTYPE) == 0 ||			\
363	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_S8) && \
364	    sizeof(int8_t) == sizeof(*(ptr)))
365
366#define	SYSCTL_ADD_S8(ctx, parent, nbr, name, access, ptr, val, descr)	\
367({									\
368	int8_t *__ptr = (ptr);						\
369	CTASSERT(((access) & CTLTYPE) == 0 ||				\
370	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_S8);		\
371	sysctl_add_oid(ctx, parent, nbr, name,				\
372	    CTLTYPE_S8 | CTLFLAG_MPSAFE | (access),			\
373	    __ptr, val, sysctl_handle_8, "C", __DESCR(descr));	\
374})
375
376/* Oid for an unsigned 8-bit int.  If ptr is NULL, val is returned. */
377#define	SYSCTL_NULL_U8_PTR ((uint8_t *)NULL)
378#define	SYSCTL_U8(parent, nbr, name, access, ptr, val, descr)	\
379	SYSCTL_OID(parent, nbr, name,				\
380	    CTLTYPE_U8 | CTLFLAG_MPSAFE | (access),		\
381	    ptr, val, sysctl_handle_8, "CU", descr);		\
382	CTASSERT((((access) & CTLTYPE) == 0 ||			\
383	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_U8) && \
384	    sizeof(uint8_t) == sizeof(*(ptr)))
385
386#define	SYSCTL_ADD_U8(ctx, parent, nbr, name, access, ptr, val, descr)	\
387({									\
388	uint8_t *__ptr = (ptr);						\
389	CTASSERT(((access) & CTLTYPE) == 0 ||				\
390	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_U8);		\
391	sysctl_add_oid(ctx, parent, nbr, name,				\
392	    CTLTYPE_U8 | CTLFLAG_MPSAFE | (access),			\
393	    __ptr, val, sysctl_handle_8, "CU", __DESCR(descr));	\
394})
395
396/* Oid for a signed 16-bit int.  If ptr is NULL, val is returned. */
397#define	SYSCTL_NULL_S16_PTR ((int16_t *)NULL)
398#define	SYSCTL_S16(parent, nbr, name, access, ptr, val, descr)	\
399	SYSCTL_OID(parent, nbr, name,				\
400	    CTLTYPE_S16 | CTLFLAG_MPSAFE | (access),		\
401	    ptr, val, sysctl_handle_16, "S", descr);		\
402	CTASSERT((((access) & CTLTYPE) == 0 ||			\
403	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_S16) && \
404	    sizeof(int16_t) == sizeof(*(ptr)))
405
406#define	SYSCTL_ADD_S16(ctx, parent, nbr, name, access, ptr, val, descr)	\
407({									\
408	int16_t *__ptr = (ptr);						\
409	CTASSERT(((access) & CTLTYPE) == 0 ||				\
410	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_S16);		\
411	sysctl_add_oid(ctx, parent, nbr, name,				\
412	    CTLTYPE_S16 | CTLFLAG_MPSAFE | (access),			\
413	    __ptr, val, sysctl_handle_16, "S", __DESCR(descr));	\
414})
415
416/* Oid for an unsigned 16-bit int.  If ptr is NULL, val is returned. */
417#define	SYSCTL_NULL_U16_PTR ((uint16_t *)NULL)
418#define	SYSCTL_U16(parent, nbr, name, access, ptr, val, descr)	\
419	SYSCTL_OID(parent, nbr, name,				\
420	    CTLTYPE_U16 | CTLFLAG_MPSAFE | (access),		\
421	    ptr, val, sysctl_handle_16, "SU", descr);		\
422	CTASSERT((((access) & CTLTYPE) == 0 ||			\
423	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_U16) && \
424	    sizeof(uint16_t) == sizeof(*(ptr)))
425
426#define	SYSCTL_ADD_U16(ctx, parent, nbr, name, access, ptr, val, descr)	\
427({									\
428	uint16_t *__ptr = (ptr);					\
429	CTASSERT(((access) & CTLTYPE) == 0 ||				\
430	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_U16);		\
431	sysctl_add_oid(ctx, parent, nbr, name,				\
432	    CTLTYPE_U16 | CTLFLAG_MPSAFE | (access),			\
433	    __ptr, val, sysctl_handle_16, "SU", __DESCR(descr));	\
434})
435
436/* Oid for a signed 32-bit int.  If ptr is NULL, val is returned. */
437#define	SYSCTL_NULL_S32_PTR ((int32_t *)NULL)
438#define	SYSCTL_S32(parent, nbr, name, access, ptr, val, descr)	\
439	SYSCTL_OID(parent, nbr, name,				\
440	    CTLTYPE_S32 | CTLFLAG_MPSAFE | (access),		\
441	    ptr, val, sysctl_handle_32, "I", descr);		\
442	CTASSERT((((access) & CTLTYPE) == 0 ||			\
443	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_S32) && \
444	    sizeof(int32_t) == sizeof(*(ptr)))
445
446#define	SYSCTL_ADD_S32(ctx, parent, nbr, name, access, ptr, val, descr)	\
447({									\
448	int32_t *__ptr = (ptr);						\
449	CTASSERT(((access) & CTLTYPE) == 0 ||				\
450	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_S32);		\
451	sysctl_add_oid(ctx, parent, nbr, name,				\
452	    CTLTYPE_S32 | CTLFLAG_MPSAFE | (access),			\
453	    __ptr, val, sysctl_handle_32, "I", __DESCR(descr));	\
454})
455
456/* Oid for an unsigned 32-bit int.  If ptr is NULL, val is returned. */
457#define	SYSCTL_NULL_U32_PTR ((uint32_t *)NULL)
458#define	SYSCTL_U32(parent, nbr, name, access, ptr, val, descr)	\
459	SYSCTL_OID(parent, nbr, name,				\
460	    CTLTYPE_U32 | CTLFLAG_MPSAFE | (access),		\
461	    ptr, val, sysctl_handle_32, "IU", descr);		\
462	CTASSERT((((access) & CTLTYPE) == 0 ||			\
463	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_U32) && \
464	    sizeof(uint32_t) == sizeof(*(ptr)))
465
466#define	SYSCTL_ADD_U32(ctx, parent, nbr, name, access, ptr, val, descr)	\
467({									\
468	uint32_t *__ptr = (ptr);					\
469	CTASSERT(((access) & CTLTYPE) == 0 ||				\
470	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_U32);		\
471	sysctl_add_oid(ctx, parent, nbr, name,				\
472	    CTLTYPE_U32 | CTLFLAG_MPSAFE | (access),			\
473	    __ptr, val, sysctl_handle_32, "IU", __DESCR(descr));	\
474})
475
476/* Oid for a signed 64-bit int.  If ptr is NULL, val is returned. */
477#define	SYSCTL_NULL_S64_PTR ((int64_t *)NULL)
478#define	SYSCTL_S64(parent, nbr, name, access, ptr, val, descr)	\
479	SYSCTL_OID(parent, nbr, name,				\
480	    CTLTYPE_S64 | CTLFLAG_MPSAFE | (access),		\
481	    ptr, val, sysctl_handle_64, "Q", descr);		\
482	CTASSERT((((access) & CTLTYPE) == 0 ||			\
483	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_S64) && \
484	    sizeof(int64_t) == sizeof(*(ptr)))
485
486#define	SYSCTL_ADD_S64(ctx, parent, nbr, name, access, ptr, val, descr)	\
487({									\
488	int64_t *__ptr = (ptr);						\
489	CTASSERT(((access) & CTLTYPE) == 0 ||				\
490	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_S64);		\
491	sysctl_add_oid(ctx, parent, nbr, name,				\
492	    CTLTYPE_S64 | CTLFLAG_MPSAFE | (access),			\
493	    __ptr, val, sysctl_handle_64, "Q", __DESCR(descr));	\
494})
495
496/* Oid for an unsigned 64-bit int.  If ptr is NULL, val is returned. */
497#define	SYSCTL_NULL_U64_PTR ((uint64_t *)NULL)
498#define	SYSCTL_U64(parent, nbr, name, access, ptr, val, descr)	\
499	SYSCTL_OID(parent, nbr, name,				\
500	    CTLTYPE_U64 | CTLFLAG_MPSAFE | (access),		\
501	    ptr, val, sysctl_handle_64, "QU", descr);		\
502	CTASSERT((((access) & CTLTYPE) == 0 ||			\
503	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_U64) && \
504	    sizeof(uint64_t) == sizeof(*(ptr)))
505
506#define	SYSCTL_ADD_U64(ctx, parent, nbr, name, access, ptr, val, descr)	\
507({									\
508	uint64_t *__ptr = (ptr);					\
509	CTASSERT(((access) & CTLTYPE) == 0 ||				\
510	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_U64);		\
511	sysctl_add_oid(ctx, parent, nbr, name,				\
512	    CTLTYPE_U64 | CTLFLAG_MPSAFE | (access),			\
513	    __ptr, val, sysctl_handle_64, "QU", __DESCR(descr));	\
514})
515
516/* Oid for an int.  If ptr is SYSCTL_NULL_INT_PTR, val is returned. */
517#define	SYSCTL_NULL_INT_PTR ((int *)NULL)
518#define	SYSCTL_INT(parent, nbr, name, access, ptr, val, descr)	\
519	SYSCTL_OID(parent, nbr, name,				\
520	    CTLTYPE_INT | CTLFLAG_MPSAFE | (access),		\
521	    ptr, val, sysctl_handle_int, "I", descr);		\
522	CTASSERT((((access) & CTLTYPE) == 0 ||			\
523	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_INT) && \
524	    sizeof(int) == sizeof(*(ptr)))
525
526#define	SYSCTL_ADD_INT(ctx, parent, nbr, name, access, ptr, val, descr)	\
527({									\
528	int *__ptr = (ptr);						\
529	CTASSERT(((access) & CTLTYPE) == 0 ||				\
530	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_INT);		\
531	sysctl_add_oid(ctx, parent, nbr, name,				\
532	    CTLTYPE_INT | CTLFLAG_MPSAFE | (access),			\
533	    __ptr, val, sysctl_handle_int, "I", __DESCR(descr));	\
534})
535
536/* Oid for an unsigned int.  If ptr is NULL, val is returned. */
537#define	SYSCTL_NULL_UINT_PTR ((unsigned *)NULL)
538#define	SYSCTL_UINT(parent, nbr, name, access, ptr, val, descr)	\
539	SYSCTL_OID(parent, nbr, name,				\
540	    CTLTYPE_UINT | CTLFLAG_MPSAFE | (access),		\
541	    ptr, val, sysctl_handle_int, "IU", descr);		\
542	CTASSERT((((access) & CTLTYPE) == 0 ||			\
543	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_UINT) && \
544	    sizeof(unsigned) == sizeof(*(ptr)))
545
546#define	SYSCTL_ADD_UINT(ctx, parent, nbr, name, access, ptr, val, descr) \
547({									\
548	unsigned *__ptr = (ptr);					\
549	CTASSERT(((access) & CTLTYPE) == 0 ||				\
550	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_UINT);	\
551	sysctl_add_oid(ctx, parent, nbr, name,				\
552	    CTLTYPE_UINT | CTLFLAG_MPSAFE | (access),			\
553	    __ptr, val, sysctl_handle_int, "IU", __DESCR(descr));	\
554})
555
556/* Oid for a long.  The pointer must be non NULL. */
557#define	SYSCTL_NULL_LONG_PTR ((long *)NULL)
558#define	SYSCTL_LONG(parent, nbr, name, access, ptr, val, descr)	\
559	SYSCTL_OID(parent, nbr, name,				\
560	    CTLTYPE_LONG | CTLFLAG_MPSAFE | (access),		\
561	    ptr, val, sysctl_handle_long, "L", descr);		\
562	CTASSERT((((access) & CTLTYPE) == 0 ||			\
563	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_LONG) && \
564	    sizeof(long) == sizeof(*(ptr)))
565
566#define	SYSCTL_ADD_LONG(ctx, parent, nbr, name, access, ptr, descr)	\
567({									\
568	long *__ptr = (ptr);						\
569	CTASSERT(((access) & CTLTYPE) == 0 ||				\
570	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_LONG);	\
571	sysctl_add_oid(ctx, parent, nbr, name,				\
572	    CTLTYPE_LONG | CTLFLAG_MPSAFE | (access),			\
573	    __ptr, 0, sysctl_handle_long, "L", __DESCR(descr));		\
574})
575
576/* Oid for an unsigned long.  The pointer must be non NULL. */
577#define	SYSCTL_NULL_ULONG_PTR ((unsigned long *)NULL)
578#define	SYSCTL_ULONG(parent, nbr, name, access, ptr, val, descr)	\
579	SYSCTL_OID(parent, nbr, name,					\
580	    CTLTYPE_ULONG | CTLFLAG_MPSAFE | (access),			\
581	    ptr, val, sysctl_handle_long, "LU", descr);			\
582	CTASSERT((((access) & CTLTYPE) == 0 ||				\
583	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_ULONG) &&	\
584	    sizeof(unsigned long) == sizeof(*(ptr)))
585
586#define	SYSCTL_ADD_ULONG(ctx, parent, nbr, name, access, ptr, descr)	\
587({									\
588	unsigned long *__ptr = (ptr);					\
589	CTASSERT(((access) & CTLTYPE) == 0 ||				\
590	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_ULONG);	\
591	sysctl_add_oid(ctx, parent, nbr, name,				\
592	    CTLTYPE_ULONG | CTLFLAG_MPSAFE | (access),			\
593	    __ptr, 0, sysctl_handle_long, "LU", __DESCR(descr));	\
594})
595
596/* Oid for a quad.  The pointer must be non NULL. */
597#define	SYSCTL_NULL_QUAD_PTR ((int64_t *)NULL)
598#define	SYSCTL_QUAD(parent, nbr, name, access, ptr, val, descr)	\
599	SYSCTL_OID(parent, nbr, name,				\
600	    CTLTYPE_S64 | CTLFLAG_MPSAFE | (access),		\
601	    ptr, val, sysctl_handle_64, "Q", descr);		\
602	CTASSERT((((access) & CTLTYPE) == 0 ||			\
603	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_S64) && \
604	    sizeof(int64_t) == sizeof(*(ptr)))
605
606#define	SYSCTL_ADD_QUAD(ctx, parent, nbr, name, access, ptr, descr)	\
607({									\
608	int64_t *__ptr = (ptr);						\
609	CTASSERT(((access) & CTLTYPE) == 0 ||				\
610	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_S64);		\
611	sysctl_add_oid(ctx, parent, nbr, name,				\
612	    CTLTYPE_S64 | CTLFLAG_MPSAFE | (access),			\
613	    __ptr, 0, sysctl_handle_64, "Q", __DESCR(descr));		\
614})
615
616#define	SYSCTL_NULL_UQUAD_PTR ((uint64_t *)NULL)
617#define	SYSCTL_UQUAD(parent, nbr, name, access, ptr, val, descr)	\
618	SYSCTL_OID(parent, nbr, name,					\
619	    CTLTYPE_U64 | CTLFLAG_MPSAFE | (access),			\
620	     ptr, val, sysctl_handle_64, "QU", descr);			\
621	CTASSERT((((access) & CTLTYPE) == 0 ||				\
622	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_U64) &&	\
623	    sizeof(uint64_t) == sizeof(*(ptr)))
624
625#define	SYSCTL_ADD_UQUAD(ctx, parent, nbr, name, access, ptr, descr)	\
626({									\
627	uint64_t *__ptr = (ptr);					\
628	CTASSERT(((access) & CTLTYPE) == 0 ||				\
629	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_U64);		\
630	sysctl_add_oid(ctx, parent, nbr, name,				\
631	    CTLTYPE_U64 | CTLFLAG_MPSAFE | (access),			\
632	    __ptr, 0, sysctl_handle_64, "QU", __DESCR(descr));		\
633})
634
635/* Oid for a CPU dependent variable */
636#define	SYSCTL_ADD_UAUTO(ctx, parent, nbr, name, access, ptr, descr)	\
637({									\
638	struct sysctl_oid *__ret;					\
639	CTASSERT((sizeof(uint64_t) == sizeof(*(ptr)) ||			\
640	    sizeof(unsigned) == sizeof(*(ptr))) &&			\
641	    ((access) & CTLTYPE) == 0);					\
642	if (sizeof(uint64_t) == sizeof(*(ptr))) {			\
643		__ret = sysctl_add_oid(ctx, parent, nbr, name,		\
644		    CTLTYPE_U64 | CTLFLAG_MPSAFE | (access),		\
645		    (ptr), 0, sysctl_handle_64, "QU",			\
646		    __DESCR(descr));					\
647	} else {							\
648		__ret = sysctl_add_oid(ctx, parent, nbr, name,		\
649		    CTLTYPE_UINT | CTLFLAG_MPSAFE | (access),		\
650		    (ptr), 0, sysctl_handle_int, "IU",			\
651		    __DESCR(descr));					\
652	}								\
653	__ret;								\
654})
655
656/* Oid for a 64-bit unsigned counter(9).  The pointer must be non NULL. */
657#define	SYSCTL_COUNTER_U64(parent, nbr, name, access, ptr, descr)	\
658	SYSCTL_OID(parent, nbr, name,					\
659	    CTLTYPE_U64 | CTLFLAG_MPSAFE | (access),			\
660	    (ptr), 0, sysctl_handle_counter_u64, "QU", descr);		\
661	CTASSERT((((access) & CTLTYPE) == 0 ||				\
662	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_U64) &&	\
663	    sizeof(counter_u64_t) == sizeof(*(ptr)) &&			\
664	    sizeof(uint64_t) == sizeof(**(ptr)))
665
666#define	SYSCTL_ADD_COUNTER_U64(ctx, parent, nbr, name, access, ptr, descr) \
667({									\
668	counter_u64_t *__ptr = (ptr);					\
669	CTASSERT(((access) & CTLTYPE) == 0 ||				\
670	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_U64);		\
671	sysctl_add_oid(ctx, parent, nbr, name,				\
672	    CTLTYPE_U64 | CTLFLAG_MPSAFE | (access),			\
673	    __ptr, 0, sysctl_handle_counter_u64, "QU", __DESCR(descr));	\
674})
675
676/* Oid for an array of counter(9)s.  The pointer and length must be non zero. */
677#define	SYSCTL_COUNTER_U64_ARRAY(parent, nbr, name, access, ptr, len, descr) \
678	SYSCTL_OID(parent, nbr, name,					\
679	    CTLTYPE_OPAQUE | CTLFLAG_MPSAFE | (access),			\
680	    (ptr), (len), sysctl_handle_counter_u64_array, "S", descr);	\
681	CTASSERT((((access) & CTLTYPE) == 0 ||				\
682	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_OPAQUE) &&	\
683	    sizeof(counter_u64_t) == sizeof(*(ptr)) &&			\
684	    sizeof(uint64_t) == sizeof(**(ptr)))
685
686#define	SYSCTL_ADD_COUNTER_U64_ARRAY(ctx, parent, nbr, name, access,	\
687    ptr, len, descr)							\
688({									\
689	counter_u64_t *__ptr = (ptr);					\
690	CTASSERT(((access) & CTLTYPE) == 0 ||				\
691	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_OPAQUE);	\
692	sysctl_add_oid(ctx, parent, nbr, name,				\
693	    CTLTYPE_OPAQUE | CTLFLAG_MPSAFE | (access),			\
694	    __ptr, len, sysctl_handle_counter_u64_array, "S",		\
695	    __DESCR(descr));						\
696})
697
698/* Oid for an opaque object.  Specified by a pointer and a length. */
699#define	SYSCTL_OPAQUE(parent, nbr, name, access, ptr, len, fmt, descr)	\
700	SYSCTL_OID(parent, nbr, name, CTLTYPE_OPAQUE|(access),		\
701	    ptr, len, sysctl_handle_opaque, fmt, descr);		\
702	CTASSERT(((access) & CTLTYPE) == 0 ||				\
703	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_OPAQUE)
704
705#define	SYSCTL_ADD_OPAQUE(ctx, parent, nbr, name, access, ptr, len, fmt, descr)	\
706({									\
707	CTASSERT(((access) & CTLTYPE) == 0 ||				\
708	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_OPAQUE);	\
709	sysctl_add_oid(ctx, parent, nbr, name, CTLTYPE_OPAQUE|(access),	\
710	    ptr, len, sysctl_handle_opaque, fmt, __DESCR(descr));	\
711})
712
713/* Oid for a struct.  Specified by a pointer and a type. */
714#define	SYSCTL_STRUCT(parent, nbr, name, access, ptr, type, descr)	\
715	SYSCTL_OID(parent, nbr, name, CTLTYPE_OPAQUE|(access),		\
716	    ptr, sizeof(struct type), sysctl_handle_opaque,		\
717	    "S," #type, descr);						\
718	CTASSERT(((access) & CTLTYPE) == 0 ||				\
719	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_OPAQUE)
720
721#define	SYSCTL_ADD_STRUCT(ctx, parent, nbr, name, access, ptr, type, descr) \
722({									\
723	CTASSERT(((access) & CTLTYPE) == 0 ||				\
724	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_OPAQUE);	\
725	sysctl_add_oid(ctx, parent, nbr, name, CTLTYPE_OPAQUE|(access),	\
726	    (ptr), sizeof(struct type),					\
727	    sysctl_handle_opaque, "S," #type, __DESCR(descr));		\
728})
729
730/* Oid for a procedure.  Specified by a pointer and an arg. */
731#define	SYSCTL_PROC(parent, nbr, name, access, ptr, arg, handler, fmt, descr) \
732	SYSCTL_OID(parent, nbr, name, (access),				\
733	    ptr, arg, handler, fmt, descr);				\
734	CTASSERT(((access) & CTLTYPE) != 0)
735
736#define	SYSCTL_ADD_PROC(ctx, parent, nbr, name, access, ptr, arg, handler, fmt, descr) \
737({									\
738	CTASSERT(((access) & CTLTYPE) != 0);				\
739	sysctl_add_oid(ctx, parent, nbr, name, (access),		\
740	    (ptr), (arg), (handler), (fmt), __DESCR(descr));		\
741})
742
743/* Oid to handle limits on uma(9) zone specified by pointer. */
744#define	SYSCTL_UMA_MAX(parent, nbr, name, access, ptr, descr)	\
745	SYSCTL_OID(parent, nbr, name,				\
746	    CTLTYPE_INT | CTLFLAG_MPSAFE | (access),		\
747	    (ptr), 0, sysctl_handle_uma_zone_max, "I", descr);	\
748	CTASSERT(((access) & CTLTYPE) == 0 ||			\
749	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_INT)
750
751#define	SYSCTL_ADD_UMA_MAX(ctx, parent, nbr, name, access, ptr, descr)	\
752({									\
753	uma_zone_t __ptr = (ptr);					\
754	CTASSERT(((access) & CTLTYPE) == 0 ||				\
755	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_INT);		\
756	sysctl_add_oid(ctx, parent, nbr, name,				\
757	    CTLTYPE_INT | CTLFLAG_MPSAFE | (access),			\
758	    __ptr, 0, sysctl_handle_uma_zone_max, "I", __DESCR(descr));	\
759})
760
761/* Oid to obtain current use of uma(9) zone specified by pointer. */
762#define	SYSCTL_UMA_CUR(parent, nbr, name, access, ptr, descr)		\
763	SYSCTL_OID(parent, nbr, name,					\
764	    CTLTYPE_INT | CTLFLAG_MPSAFE | CTLFLAG_RD | (access),	\
765	    (ptr), 0, sysctl_handle_uma_zone_cur, "I", descr);		\
766	CTASSERT(((access) & CTLTYPE) == 0 ||				\
767	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_INT)
768
769#define	SYSCTL_ADD_UMA_CUR(ctx, parent, nbr, name, access, ptr, descr)	\
770({									\
771	uma_zone_t __ptr = (ptr);					\
772	CTASSERT(((access) & CTLTYPE) == 0 ||				\
773	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_INT);		\
774	sysctl_add_oid(ctx, parent, nbr, name,				\
775	    CTLTYPE_INT | CTLFLAG_MPSAFE | CTLFLAG_RD | (access),	\
776	    __ptr, 0, sysctl_handle_uma_zone_cur, "I", __DESCR(descr));	\
777})
778
779/*
780 * A macro to generate a read-only sysctl to indicate the presence of optional
781 * kernel features.
782 */
783#define	FEATURE(name, desc)						\
784	SYSCTL_INT(_kern_features, OID_AUTO, name, CTLFLAG_RD | CTLFLAG_CAPRD, \
785	    SYSCTL_NULL_INT_PTR, 1, desc)
786
787#endif /* _KERNEL */
788
789/*
790 * Top-level identifiers
791 */
792#define	CTL_UNSPEC	0		/* unused */
793#define	CTL_KERN	1		/* "high kernel": proc, limits */
794#define	CTL_VM		2		/* virtual memory */
795#define	CTL_VFS		3		/* filesystem, mount type is next */
796#define	CTL_NET		4		/* network, see socket.h */
797#define	CTL_DEBUG	5		/* debugging parameters */
798#define	CTL_HW		6		/* generic cpu/io */
799#define	CTL_MACHDEP	7		/* machine dependent */
800#define	CTL_USER	8		/* user-level */
801#define	CTL_P1003_1B	9		/* POSIX 1003.1B */
802
803/*
804 * CTL_KERN identifiers
805 */
806#define	KERN_OSTYPE		 1	/* string: system version */
807#define	KERN_OSRELEASE		 2	/* string: system release */
808#define	KERN_OSREV		 3	/* int: system revision */
809#define	KERN_VERSION		 4	/* string: compile time info */
810#define	KERN_MAXVNODES		 5	/* int: max vnodes */
811#define	KERN_MAXPROC		 6	/* int: max processes */
812#define	KERN_MAXFILES		 7	/* int: max open files */
813#define	KERN_ARGMAX		 8	/* int: max arguments to exec */
814#define	KERN_SECURELVL		 9	/* int: system security level */
815#define	KERN_HOSTNAME		10	/* string: hostname */
816#define	KERN_HOSTID		11	/* int: host identifier */
817#define	KERN_CLOCKRATE		12	/* struct: struct clockrate */
818#define	KERN_VNODE		13	/* struct: vnode structures */
819#define	KERN_PROC		14	/* struct: process entries */
820#define	KERN_FILE		15	/* struct: file entries */
821#define	KERN_PROF		16	/* node: kernel profiling info */
822#define	KERN_POSIX1		17	/* int: POSIX.1 version */
823#define	KERN_NGROUPS		18	/* int: # of supplemental group ids */
824#define	KERN_JOB_CONTROL	19	/* int: is job control available */
825#define	KERN_SAVED_IDS		20	/* int: saved set-user/group-ID */
826#define	KERN_BOOTTIME		21	/* struct: time kernel was booted */
827#define	KERN_NISDOMAINNAME	22	/* string: YP domain name */
828#define	KERN_UPDATEINTERVAL	23	/* int: update process sleep time */
829#define	KERN_OSRELDATE		24	/* int: kernel release date */
830#define	KERN_NTP_PLL		25	/* node: NTP PLL control */
831#define	KERN_BOOTFILE		26	/* string: name of booted kernel */
832#define	KERN_MAXFILESPERPROC	27	/* int: max open files per proc */
833#define	KERN_MAXPROCPERUID	28	/* int: max processes per uid */
834#define	KERN_DUMPDEV		29	/* struct cdev *: device to dump on */
835#define	KERN_IPC		30	/* node: anything related to IPC */
836#define	KERN_DUMMY		31	/* unused */
837#define	KERN_PS_STRINGS		32	/* int: address of PS_STRINGS */
838#define	KERN_USRSTACK		33	/* int: address of USRSTACK */
839#define	KERN_LOGSIGEXIT		34	/* int: do we log sigexit procs? */
840#define	KERN_IOV_MAX		35	/* int: value of UIO_MAXIOV */
841#define	KERN_HOSTUUID		36	/* string: host UUID identifier */
842#define	KERN_ARND		37	/* int: from arc4rand() */
843/*
844 * KERN_PROC subtypes
845 */
846#define	KERN_PROC_ALL		0	/* everything */
847#define	KERN_PROC_PID		1	/* by process id */
848#define	KERN_PROC_PGRP		2	/* by process group id */
849#define	KERN_PROC_SESSION	3	/* by session of pid */
850#define	KERN_PROC_TTY		4	/* by controlling tty */
851#define	KERN_PROC_UID		5	/* by effective uid */
852#define	KERN_PROC_RUID		6	/* by real uid */
853#define	KERN_PROC_ARGS		7	/* get/set arguments/proctitle */
854#define	KERN_PROC_PROC		8	/* only return procs */
855#define	KERN_PROC_SV_NAME	9	/* get syscall vector name */
856#define	KERN_PROC_RGID		10	/* by real group id */
857#define	KERN_PROC_GID		11	/* by effective group id */
858#define	KERN_PROC_PATHNAME	12	/* path to executable */
859#define	KERN_PROC_OVMMAP	13	/* Old VM map entries for process */
860#define	KERN_PROC_OFILEDESC	14	/* Old file descriptors for process */
861#define	KERN_PROC_KSTACK	15	/* Kernel stacks for process */
862#define	KERN_PROC_INC_THREAD	0x10	/*
863					 * modifier for pid, pgrp, tty,
864					 * uid, ruid, gid, rgid and proc
865					 * This effectively uses 16-31
866					 */
867#define	KERN_PROC_VMMAP		32	/* VM map entries for process */
868#define	KERN_PROC_FILEDESC	33	/* File descriptors for process */
869#define	KERN_PROC_GROUPS	34	/* process groups */
870#define	KERN_PROC_ENV		35	/* get environment */
871#define	KERN_PROC_AUXV		36	/* get ELF auxiliary vector */
872#define	KERN_PROC_RLIMIT	37	/* process resource limits */
873#define	KERN_PROC_PS_STRINGS	38	/* get ps_strings location */
874#define	KERN_PROC_UMASK		39	/* process umask */
875#define	KERN_PROC_OSREL		40	/* osreldate for process binary */
876#define	KERN_PROC_SIGTRAMP	41	/* signal trampoline location */
877#define	KERN_PROC_CWD		42	/* process current working directory */
878#define	KERN_PROC_NFDS		43	/* number of open file descriptors */
879
880/*
881 * KERN_IPC identifiers
882 */
883#define	KIPC_MAXSOCKBUF		1	/* int: max size of a socket buffer */
884#define	KIPC_SOCKBUF_WASTE	2	/* int: wastage factor in sockbuf */
885#define	KIPC_SOMAXCONN		3	/* int: max length of connection q */
886#define	KIPC_MAX_LINKHDR	4	/* int: max length of link header */
887#define	KIPC_MAX_PROTOHDR	5	/* int: max length of network header */
888#define	KIPC_MAX_HDR		6	/* int: max total length of headers */
889#define	KIPC_MAX_DATALEN	7	/* int: max length of data? */
890
891/*
892 * CTL_HW identifiers
893 */
894#define	HW_MACHINE	 1		/* string: machine class */
895#define	HW_MODEL	 2		/* string: specific machine model */
896#define	HW_NCPU		 3		/* int: number of cpus */
897#define	HW_BYTEORDER	 4		/* int: machine byte order */
898#define	HW_PHYSMEM	 5		/* int: total memory */
899#define	HW_USERMEM	 6		/* int: non-kernel memory */
900#define	HW_PAGESIZE	 7		/* int: software page size */
901#define	HW_DISKNAMES	 8		/* strings: disk drive names */
902#define	HW_DISKSTATS	 9		/* struct: diskstats[] */
903#define	HW_FLOATINGPT	10		/* int: has HW floating point? */
904#define	HW_MACHINE_ARCH	11		/* string: machine architecture */
905#define	HW_REALMEM	12		/* int: 'real' memory */
906
907/*
908 * CTL_USER definitions
909 */
910#define	USER_CS_PATH		 1	/* string: _CS_PATH */
911#define	USER_BC_BASE_MAX	 2	/* int: BC_BASE_MAX */
912#define	USER_BC_DIM_MAX		 3	/* int: BC_DIM_MAX */
913#define	USER_BC_SCALE_MAX	 4	/* int: BC_SCALE_MAX */
914#define	USER_BC_STRING_MAX	 5	/* int: BC_STRING_MAX */
915#define	USER_COLL_WEIGHTS_MAX	 6	/* int: COLL_WEIGHTS_MAX */
916#define	USER_EXPR_NEST_MAX	 7	/* int: EXPR_NEST_MAX */
917#define	USER_LINE_MAX		 8	/* int: LINE_MAX */
918#define	USER_RE_DUP_MAX		 9	/* int: RE_DUP_MAX */
919#define	USER_POSIX2_VERSION	10	/* int: POSIX2_VERSION */
920#define	USER_POSIX2_C_BIND	11	/* int: POSIX2_C_BIND */
921#define	USER_POSIX2_C_DEV	12	/* int: POSIX2_C_DEV */
922#define	USER_POSIX2_CHAR_TERM	13	/* int: POSIX2_CHAR_TERM */
923#define	USER_POSIX2_FORT_DEV	14	/* int: POSIX2_FORT_DEV */
924#define	USER_POSIX2_FORT_RUN	15	/* int: POSIX2_FORT_RUN */
925#define	USER_POSIX2_LOCALEDEF	16	/* int: POSIX2_LOCALEDEF */
926#define	USER_POSIX2_SW_DEV	17	/* int: POSIX2_SW_DEV */
927#define	USER_POSIX2_UPE		18	/* int: POSIX2_UPE */
928#define	USER_STREAM_MAX		19	/* int: POSIX2_STREAM_MAX */
929#define	USER_TZNAME_MAX		20	/* int: POSIX2_TZNAME_MAX */
930
931#define	CTL_P1003_1B_ASYNCHRONOUS_IO		1	/* boolean */
932#define	CTL_P1003_1B_MAPPED_FILES		2	/* boolean */
933#define	CTL_P1003_1B_MEMLOCK			3	/* boolean */
934#define	CTL_P1003_1B_MEMLOCK_RANGE		4	/* boolean */
935#define	CTL_P1003_1B_MEMORY_PROTECTION		5	/* boolean */
936#define	CTL_P1003_1B_MESSAGE_PASSING		6	/* boolean */
937#define	CTL_P1003_1B_PRIORITIZED_IO		7	/* boolean */
938#define	CTL_P1003_1B_PRIORITY_SCHEDULING	8	/* boolean */
939#define	CTL_P1003_1B_REALTIME_SIGNALS		9	/* boolean */
940#define	CTL_P1003_1B_SEMAPHORES			10	/* boolean */
941#define	CTL_P1003_1B_FSYNC			11	/* boolean */
942#define	CTL_P1003_1B_SHARED_MEMORY_OBJECTS	12	/* boolean */
943#define	CTL_P1003_1B_SYNCHRONIZED_IO		13	/* boolean */
944#define	CTL_P1003_1B_TIMERS			14	/* boolean */
945#define	CTL_P1003_1B_AIO_LISTIO_MAX		15	/* int */
946#define	CTL_P1003_1B_AIO_MAX			16	/* int */
947#define	CTL_P1003_1B_AIO_PRIO_DELTA_MAX		17	/* int */
948#define	CTL_P1003_1B_DELAYTIMER_MAX		18	/* int */
949#define	CTL_P1003_1B_MQ_OPEN_MAX		19	/* int */
950#define	CTL_P1003_1B_PAGESIZE			20	/* int */
951#define	CTL_P1003_1B_RTSIG_MAX			21	/* int */
952#define	CTL_P1003_1B_SEM_NSEMS_MAX		22	/* int */
953#define	CTL_P1003_1B_SEM_VALUE_MAX		23	/* int */
954#define	CTL_P1003_1B_SIGQUEUE_MAX		24	/* int */
955#define	CTL_P1003_1B_TIMER_MAX			25	/* int */
956
957#define	CTL_P1003_1B_MAXID		26
958
959#ifdef _KERNEL
960
961/*
962 * Declare some common oids.
963 */
964extern struct sysctl_oid_list sysctl__children;
965SYSCTL_DECL(_kern);
966SYSCTL_DECL(_kern_features);
967SYSCTL_DECL(_kern_ipc);
968SYSCTL_DECL(_kern_proc);
969SYSCTL_DECL(_kern_sched);
970SYSCTL_DECL(_kern_sched_stats);
971SYSCTL_DECL(_sysctl);
972SYSCTL_DECL(_vm);
973SYSCTL_DECL(_vm_stats);
974SYSCTL_DECL(_vm_stats_misc);
975SYSCTL_DECL(_vfs);
976SYSCTL_DECL(_net);
977SYSCTL_DECL(_debug);
978SYSCTL_DECL(_debug_sizeof);
979SYSCTL_DECL(_dev);
980SYSCTL_DECL(_hw);
981SYSCTL_DECL(_hw_bus);
982SYSCTL_DECL(_hw_bus_devices);
983SYSCTL_DECL(_hw_bus_info);
984SYSCTL_DECL(_machdep);
985SYSCTL_DECL(_user);
986SYSCTL_DECL(_compat);
987SYSCTL_DECL(_regression);
988SYSCTL_DECL(_security);
989SYSCTL_DECL(_security_bsd);
990
991extern char	machine[];
992extern char	osrelease[];
993extern char	ostype[];
994extern char	kern_ident[];
995
996/* Dynamic oid handling */
997struct sysctl_oid *sysctl_add_oid(struct sysctl_ctx_list *clist,
998	    struct sysctl_oid_list *parent, int nbr, const char *name, int kind,
999	    void *arg1, intmax_t arg2, int (*handler)(SYSCTL_HANDLER_ARGS),
1000	    const char *fmt, const char *descr);
1001int	sysctl_remove_name(struct sysctl_oid *parent, const char *name, int del,
1002	    int recurse);
1003void	sysctl_rename_oid(struct sysctl_oid *oidp, const char *name);
1004int	sysctl_move_oid(struct sysctl_oid *oidp,
1005	    struct sysctl_oid_list *parent);
1006int	sysctl_remove_oid(struct sysctl_oid *oidp, int del, int recurse);
1007int	sysctl_ctx_init(struct sysctl_ctx_list *clist);
1008int	sysctl_ctx_free(struct sysctl_ctx_list *clist);
1009struct	sysctl_ctx_entry *sysctl_ctx_entry_add(struct sysctl_ctx_list *clist,
1010	    struct sysctl_oid *oidp);
1011struct	sysctl_ctx_entry *sysctl_ctx_entry_find(struct sysctl_ctx_list *clist,
1012	    struct sysctl_oid *oidp);
1013int	sysctl_ctx_entry_del(struct sysctl_ctx_list *clist,
1014	    struct sysctl_oid *oidp);
1015
1016int	kernel_sysctl(struct thread *td, int *name, u_int namelen, void *old,
1017	    size_t *oldlenp, void *new, size_t newlen, size_t *retval,
1018	    int flags);
1019int	kernel_sysctlbyname(struct thread *td, char *name, void *old,
1020	    size_t *oldlenp, void *new, size_t newlen, size_t *retval,
1021	    int flags);
1022int	userland_sysctl(struct thread *td, int *name, u_int namelen, void *old,
1023	    size_t *oldlenp, int inkernel, void *new, size_t newlen,
1024	    size_t *retval, int flags);
1025int	sysctl_find_oid(int *name, u_int namelen, struct sysctl_oid **noid,
1026	    int *nindx, struct sysctl_req *req);
1027void	sysctl_wlock(void);
1028void	sysctl_wunlock(void);
1029int	sysctl_wire_old_buffer(struct sysctl_req *req, size_t len);
1030
1031struct sbuf;
1032struct sbuf *sbuf_new_for_sysctl(struct sbuf *, char *, int,
1033	    struct sysctl_req *);
1034#else	/* !_KERNEL */
1035#include <sys/cdefs.h>
1036
1037__BEGIN_DECLS
1038int	sysctl(const int *, u_int, void *, size_t *, const void *, size_t);
1039int	sysctlbyname(const char *, void *, size_t *, const void *, size_t);
1040int	sysctlnametomib(const char *, int *, size_t *);
1041__END_DECLS
1042#endif	/* _KERNEL */
1043
1044#endif	/* !_SYS_SYSCTL_H_ */
1045