xref: /freebsd/sys/sys/sysctl.h (revision d37eb51047221dc3322b34db1038ff3aa533883f)
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  * 3. 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 
35 #ifndef _SYS_SYSCTL_H_
36 #define	_SYS_SYSCTL_H_
37 
38 #ifdef _KERNEL
39 #include <sys/queue.h>
40 #include <sys/tree.h>
41 #endif
42 
43 /*
44  * Definitions for sysctl call.  The sysctl call uses a hierarchical name
45  * for objects that can be examined or modified.  The name is expressed as
46  * a sequence of integers.  Like a file path name, the meaning of each
47  * component depends on its place in the hierarchy.  The top-level and kern
48  * identifiers are defined here, and other identifiers are defined in the
49  * respective subsystem header files.
50  *
51  * Each subsystem defined by sysctl defines a list of variables for that
52  * subsystem. Each name is either a node with further levels defined below it,
53  * or it is a leaf of some particular type given below. Each sysctl level
54  * defines a set of name/type pairs to be used by sysctl(8) in manipulating the
55  * subsystem.
56  */
57 
58 #define	CTL_MAXNAME	24	/* largest number of components supported */
59 
60 #define	CTLTYPE		0xf	/* mask for the type */
61 #define	CTLTYPE_NODE	1	/* name is a node */
62 #define	CTLTYPE_INT	2	/* name describes an integer */
63 #define	CTLTYPE_STRING	3	/* name describes a string */
64 #define	CTLTYPE_S64	4	/* name describes a signed 64-bit number */
65 #define	CTLTYPE_OPAQUE	5	/* name describes a structure */
66 #define	CTLTYPE_STRUCT	CTLTYPE_OPAQUE	/* name describes a structure */
67 #define	CTLTYPE_UINT	6	/* name describes an unsigned integer */
68 #define	CTLTYPE_LONG	7	/* name describes a long */
69 #define	CTLTYPE_ULONG	8	/* name describes an unsigned long */
70 #define	CTLTYPE_U64	9	/* name describes an unsigned 64-bit number */
71 #define	CTLTYPE_U8	0xa	/* name describes an unsigned 8-bit number */
72 #define	CTLTYPE_U16	0xb	/* name describes an unsigned 16-bit number */
73 #define	CTLTYPE_S8	0xc	/* name describes a signed 8-bit number */
74 #define	CTLTYPE_S16	0xd	/* name describes a signed 16-bit number */
75 #define	CTLTYPE_S32	0xe	/* name describes a signed 32-bit number */
76 #define	CTLTYPE_U32	0xf	/* name describes an unsigned 32-bit number */
77 
78 #define	CTLFLAG_RD	0x80000000	/* Allow reads of variable */
79 #define	CTLFLAG_WR	0x40000000	/* Allow writes to the variable */
80 #define	CTLFLAG_RW	(CTLFLAG_RD|CTLFLAG_WR)
81 #define	CTLFLAG_DORMANT	0x20000000	/* This sysctl is not active yet */
82 #define	CTLFLAG_ANYBODY	0x10000000	/* All users can set this var */
83 #define	CTLFLAG_SECURE	0x08000000	/* Permit set only if securelevel<=0 */
84 #define	CTLFLAG_PRISON	0x04000000	/* Prisoned roots can fiddle */
85 #define	CTLFLAG_DYN	0x02000000	/* Dynamic oid - can be freed */
86 #define	CTLFLAG_SKIP	0x01000000	/* Skip this sysctl when listing */
87 #define	CTLMASK_SECURE	0x00F00000	/* Secure level */
88 #define	CTLFLAG_TUN	0x00080000	/* Default value is loaded from getenv() */
89 #define	CTLFLAG_RDTUN	(CTLFLAG_RD|CTLFLAG_TUN)
90 #define	CTLFLAG_RWTUN	(CTLFLAG_RW|CTLFLAG_TUN)
91 #define	CTLFLAG_MPSAFE	0x00040000	/* Handler is MP safe */
92 #define	CTLFLAG_VNET	0x00020000	/* Prisons with vnet can fiddle */
93 #define	CTLFLAG_DYING	0x00010000	/* Oid is being removed */
94 #define	CTLFLAG_CAPRD	0x00008000	/* Can be read in capability mode */
95 #define	CTLFLAG_CAPWR	0x00004000	/* Can be written in capability mode */
96 #define	CTLFLAG_STATS	0x00002000	/* Statistics, not a tuneable */
97 #define	CTLFLAG_NOFETCH	0x00001000	/* Don't fetch tunable from getenv() */
98 #define	CTLFLAG_CAPRW	(CTLFLAG_CAPRD|CTLFLAG_CAPWR)
99 /*
100  * This is transient flag to be used until all sysctl handlers are converted
101  * to not lock Giant.
102  * One, and only one of CTLFLAG_MPSAFE or CTLFLAG_NEEDGIANT is required
103  * for SYSCTL_PROC and SYSCTL_NODE.
104  */
105 #define	CTLFLAG_NEEDGIANT 0x00000800	/* Handler require Giant */
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 #ifdef COMPAT_FREEBSD32
151 #define	SCTL_MASK32	1	/* 32 bit emulation */
152 #endif
153 
154 /*
155  * This describes the access space for a sysctl request.  This is needed
156  * so that we can use the interface from the kernel or from user-space.
157  */
158 struct thread;
159 struct 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 	const 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 
174 struct sysctl_oid;
175 
176 /* RB Tree handling */
177 RB_HEAD(sysctl_oid_list, sysctl_oid);
178 
179 /*
180  * This describes one "oid" in the MIB tree.  Potentially more nodes can
181  * be hidden behind it, expanded by the handler.
182  */
183 struct sysctl_oid {
184 	struct sysctl_oid_list	oid_children;
185 	struct sysctl_oid_list*	oid_parent;
186 	RB_ENTRY(sysctl_oid) oid_link;
187 	/* Sort key for all siblings, and lookup key for userland */
188 	int		 oid_number;
189 	u_int		 oid_kind;
190 	void		*oid_arg1;
191 	intmax_t	 oid_arg2;
192 	/* Must be unique amongst all siblings. */
193 	const char	*oid_name;
194 	int		(*oid_handler)(SYSCTL_HANDLER_ARGS);
195 	const char	*oid_fmt;
196 	int		 oid_refcnt;
197 	u_int		 oid_running;
198 	const char	*oid_descr;
199 	const char	*oid_label;
200 };
201 
202 static inline int
203 cmp_sysctl_oid(struct sysctl_oid *a, struct sysctl_oid *b)
204 {
205 	if (a->oid_number > b->oid_number)
206 		return (1);
207 	else if (a->oid_number < b->oid_number)
208 		return (-1);
209 	else
210 		return (0);
211 }
212 
213 RB_PROTOTYPE(sysctl_oid_list, sysctl_oid, oid_link, cmp_sysctl_oid);
214 
215 #define	SYSCTL_IN(r, p, l)	(r->newfunc)(r, p, l)
216 #define	SYSCTL_OUT(r, p, l)	(r->oldfunc)(r, p, l)
217 #define	SYSCTL_OUT_STR(r, p)	(r->oldfunc)(r, p, strlen(p) + 1)
218 
219 int sysctl_handle_bool(SYSCTL_HANDLER_ARGS);
220 int sysctl_handle_8(SYSCTL_HANDLER_ARGS);
221 int sysctl_handle_16(SYSCTL_HANDLER_ARGS);
222 int sysctl_handle_32(SYSCTL_HANDLER_ARGS);
223 int sysctl_handle_64(SYSCTL_HANDLER_ARGS);
224 int sysctl_handle_int(SYSCTL_HANDLER_ARGS);
225 int sysctl_msec_to_ticks(SYSCTL_HANDLER_ARGS);
226 int sysctl_handle_long(SYSCTL_HANDLER_ARGS);
227 int sysctl_handle_string(SYSCTL_HANDLER_ARGS);
228 int sysctl_handle_opaque(SYSCTL_HANDLER_ARGS);
229 int sysctl_handle_counter_u64(SYSCTL_HANDLER_ARGS);
230 int sysctl_handle_counter_u64_array(SYSCTL_HANDLER_ARGS);
231 
232 int sysctl_handle_uma_zone_max(SYSCTL_HANDLER_ARGS);
233 int sysctl_handle_uma_zone_cur(SYSCTL_HANDLER_ARGS);
234 
235 int sysctl_msec_to_sbintime(SYSCTL_HANDLER_ARGS);
236 int sysctl_usec_to_sbintime(SYSCTL_HANDLER_ARGS);
237 int sysctl_sec_to_timeval(SYSCTL_HANDLER_ARGS);
238 
239 int sysctl_dpcpu_int(SYSCTL_HANDLER_ARGS);
240 int sysctl_dpcpu_long(SYSCTL_HANDLER_ARGS);
241 int sysctl_dpcpu_quad(SYSCTL_HANDLER_ARGS);
242 
243 /*
244  * These functions are used to add/remove an oid from the mib.
245  */
246 void sysctl_register_oid(struct sysctl_oid *oidp);
247 void sysctl_register_disabled_oid(struct sysctl_oid *oidp);
248 void sysctl_enable_oid(struct sysctl_oid *oidp);
249 void sysctl_unregister_oid(struct sysctl_oid *oidp);
250 
251 /* Declare a static oid to allow child oids to be added to it. */
252 #define	SYSCTL_DECL(name)			\
253 	extern struct sysctl_oid sysctl__##name
254 
255 /* Hide these in macros. */
256 #define	SYSCTL_CHILDREN(oid_ptr)		(&(oid_ptr)->oid_children)
257 #define	SYSCTL_PARENT(oid_ptr)					\
258     (((oid_ptr)->oid_parent != &sysctl__children) ?		\
259 	__containerof((oid_ptr)->oid_parent, struct sysctl_oid,	\
260 	oid_children) : (struct sysctl_oid *)NULL)
261 #define	SYSCTL_STATIC_CHILDREN(oid_name)	(&sysctl__##oid_name.oid_children)
262 
263 /* === Structs and macros related to context handling. === */
264 
265 /* All dynamically created sysctls can be tracked in a context list. */
266 struct sysctl_ctx_entry {
267 	struct sysctl_oid *entry;
268 	TAILQ_ENTRY(sysctl_ctx_entry) link;
269 };
270 
271 TAILQ_HEAD(sysctl_ctx_list, sysctl_ctx_entry);
272 
273 #define	SYSCTL_NODE_CHILDREN(parent, name) \
274 	sysctl__##parent##_##name.oid_children
275 
276 #ifndef NO_SYSCTL_DESCR
277 #define	__DESCR(d) d
278 #else
279 #define	__DESCR(d) ""
280 #endif
281 
282 #ifdef	notyet
283 #define	SYSCTL_ENFORCE_FLAGS(x)						\
284     _Static_assert((((x) & CTLFLAG_MPSAFE) != 0) ^ (((x) & CTLFLAG_NEEDGIANT) != 0), \
285         "Has to be either CTLFLAG_MPSAFE or CTLFLAG_NEEDGIANT")
286 #else
287 #define	SYSCTL_ENFORCE_FLAGS(x)
288 #endif
289 
290 /* This macro is only for internal use */
291 #define	SYSCTL_OID_RAW(id, parent_child_head, nbr, name, kind, a1, a2, handler, fmt, descr, label) \
292 	struct sysctl_oid id = {					\
293 		.oid_parent = (parent_child_head),			\
294 		.oid_children = RB_INITIALIZER(&id.oid_children), \
295 		.oid_number = (nbr),					\
296 		.oid_kind = (kind),					\
297 		.oid_arg1 = (a1),					\
298 		.oid_arg2 = (a2),					\
299 		.oid_name = (name),					\
300 		.oid_handler = (handler),				\
301 		.oid_fmt = (fmt),					\
302 		.oid_descr = __DESCR(descr),				\
303 		.oid_label = (label),					\
304 	};								\
305 	DATA_SET(sysctl_set, id);					\
306 	SYSCTL_ENFORCE_FLAGS(kind)
307 
308 /* This constructs a static "raw" MIB oid. */
309 #define	SYSCTL_OID(parent, nbr, name, kind, a1, a2, handler, fmt, descr) \
310 	SYSCTL_OID_WITH_LABEL(parent, nbr, name, kind, a1, a2,		\
311 	    handler, fmt, descr, NULL)
312 
313 #define	SYSCTL_OID_WITH_LABEL(parent, nbr, name, kind, a1, a2, handler, fmt, descr, label) \
314     static SYSCTL_OID_RAW(sysctl__##parent##_##name,			\
315 	SYSCTL_CHILDREN(&sysctl__##parent),				\
316 	nbr, #name, kind, a1, a2, handler, fmt, descr, label)
317 
318 /* This constructs a global "raw" MIB oid. */
319 #define	SYSCTL_OID_GLOBAL(parent, nbr, name, kind, a1, a2, handler, fmt, descr, label) \
320     SYSCTL_OID_RAW(sysctl__##parent##_##name, \
321 	SYSCTL_CHILDREN(&sysctl__##parent),	\
322 	nbr, #name, kind, a1, a2, handler, fmt, descr, label)
323 
324 #define	SYSCTL_ADD_OID(ctx, parent, nbr, name, kind, a1, a2, handler, fmt, descr) \
325 ({									\
326 	SYSCTL_ENFORCE_FLAGS(kind);					\
327 	sysctl_add_oid(ctx, parent, nbr, name, kind, a1, a2,handler,	\
328 	    fmt, __DESCR(descr), NULL);					\
329 })
330 
331 /* This constructs a root node from which other nodes can hang. */
332 #define	SYSCTL_ROOT_NODE(nbr, name, access, handler, descr)	\
333 	SYSCTL_OID_RAW(sysctl___##name, &sysctl__children,	\
334 	    nbr, #name, CTLTYPE_NODE|(access), NULL, 0,		\
335 	    handler, "N", descr, NULL);				\
336 	CTASSERT(((access) & CTLTYPE) == 0 ||			\
337 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_NODE)
338 
339 /* This constructs a node from which other oids can hang. */
340 #define	SYSCTL_NODE(parent, nbr, name, access, handler, descr) \
341 	SYSCTL_NODE_WITH_LABEL(parent, nbr, name, access, handler, descr, NULL)
342 
343 #define	SYSCTL_NODE_WITH_LABEL(parent, nbr, name, access, handler, descr, label) \
344 	SYSCTL_OID_GLOBAL(parent, nbr, name, CTLTYPE_NODE|(access),	\
345 	    NULL, 0, handler, "N", descr, label);			\
346 	SYSCTL_ENFORCE_FLAGS(access);					\
347 	CTASSERT(((access) & CTLTYPE) == 0 ||				\
348 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_NODE)
349 
350 #define	SYSCTL_ADD_NODE(ctx, parent, nbr, name, access, handler, descr)	\
351 	SYSCTL_ADD_NODE_WITH_LABEL(ctx, parent, nbr, name, access, \
352 	    handler, descr, NULL)
353 
354 #define	SYSCTL_ADD_NODE_WITH_LABEL(ctx, parent, nbr, name, access, handler, descr, label) \
355 ({									\
356 	CTASSERT(((access) & CTLTYPE) == 0 ||				\
357 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_NODE);	\
358 	SYSCTL_ENFORCE_FLAGS(access);					\
359 	sysctl_add_oid(ctx, parent, nbr, name, CTLTYPE_NODE|(access),	\
360 	    NULL, 0, handler, "N", __DESCR(descr), label);		\
361 })
362 
363 #define	SYSCTL_ADD_ROOT_NODE(ctx, nbr, name, access, handler, descr)	\
364 ({									\
365 	CTASSERT(((access) & CTLTYPE) == 0 ||				\
366 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_NODE);	\
367 	SYSCTL_ENFORCE_FLAGS(access);					\
368 	sysctl_add_oid(ctx, &sysctl__children, nbr, name,		\
369 	    CTLTYPE_NODE|(access),					\
370 	    NULL, 0, handler, "N", __DESCR(descr), NULL);		\
371 })
372 
373 /* Oid for a string.  len can be 0 to indicate '\0' termination. */
374 #define	SYSCTL_STRING(parent, nbr, name, access, arg, len, descr)	\
375 	SYSCTL_OID(parent, nbr, name,					\
376 	    CTLTYPE_STRING | CTLFLAG_MPSAFE | (access),			\
377 	    arg, len, sysctl_handle_string, "A", descr);		\
378 	CTASSERT(((access) & CTLTYPE) == 0 ||				\
379 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_STRING)
380 
381 #define	SYSCTL_ADD_STRING(ctx, parent, nbr, name, access, arg, len, descr) \
382 ({									\
383 	char *__arg = (arg);						\
384 	CTASSERT(((access) & CTLTYPE) == 0 ||				\
385 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_STRING);	\
386 	sysctl_add_oid(ctx, parent, nbr, name,				\
387 	    CTLTYPE_STRING | CTLFLAG_MPSAFE | (access),			\
388 	    __arg, len, sysctl_handle_string, "A", __DESCR(descr),	\
389 	    NULL); \
390 })
391 
392 /* Oid for a constant '\0' terminated string. */
393 #define	SYSCTL_CONST_STRING(parent, nbr, name, access, arg, descr)	\
394 	SYSCTL_OID(parent, nbr, name, CTLTYPE_STRING | CTLFLAG_MPSAFE | (access),\
395 	    __DECONST(char *, arg), 0, sysctl_handle_string, "A", descr); \
396 	CTASSERT(!(access & CTLFLAG_WR));				\
397 	CTASSERT(((access) & CTLTYPE) == 0 ||				\
398 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_STRING)
399 
400 #define	SYSCTL_ADD_CONST_STRING(ctx, parent, nbr, name, access, arg, descr) \
401 ({									\
402 	char *__arg = __DECONST(char *, arg);				\
403 	CTASSERT(!(access & CTLFLAG_WR));				\
404 	CTASSERT(((access) & CTLTYPE) == 0 ||				\
405 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_STRING);	\
406 	sysctl_add_oid(ctx, parent, nbr, name, CTLTYPE_STRING | 	\
407 	    CTLFLAG_MPSAFE | (access), __arg, 0, sysctl_handle_string, "A",\
408 	    __DESCR(descr), NULL); 					\
409 })
410 
411 /* Oid for a bool.  If ptr is NULL, val is returned. */
412 #define	SYSCTL_NULL_BOOL_PTR ((bool *)NULL)
413 #define	SYSCTL_BOOL(parent, nbr, name, access, ptr, val, descr)	\
414 	SYSCTL_OID(parent, nbr, name,				\
415 	    CTLTYPE_U8 | CTLFLAG_MPSAFE | (access),		\
416 	    ptr, val, sysctl_handle_bool, "CU", descr);		\
417 	CTASSERT(((access) & CTLTYPE) == 0 &&			\
418 	    sizeof(bool) == sizeof(*(ptr)))
419 
420 #define	SYSCTL_ADD_BOOL(ctx, parent, nbr, name, access, ptr, val, descr) \
421 ({									\
422 	bool *__ptr = (ptr);						\
423 	CTASSERT(((access) & CTLTYPE) == 0);				\
424 	sysctl_add_oid(ctx, parent, nbr, name,				\
425 	    CTLTYPE_U8 | CTLFLAG_MPSAFE | (access),			\
426 	    __ptr, val, sysctl_handle_bool, "CU", __DESCR(descr),	\
427 	    NULL);							\
428 })
429 
430 /* Oid for a signed 8-bit int.  If ptr is NULL, val is returned. */
431 #define	SYSCTL_NULL_S8_PTR ((int8_t *)NULL)
432 #define	SYSCTL_S8(parent, nbr, name, access, ptr, val, descr)	\
433 	SYSCTL_OID(parent, nbr, name,				\
434 	    CTLTYPE_S8 | CTLFLAG_MPSAFE | (access),		\
435 	    ptr, val, sysctl_handle_8, "C", descr);		\
436 	CTASSERT((((access) & CTLTYPE) == 0 ||			\
437 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_S8) && \
438 	    sizeof(int8_t) == sizeof(*(ptr)))
439 
440 #define	SYSCTL_ADD_S8(ctx, parent, nbr, name, access, ptr, val, descr)	\
441 ({									\
442 	int8_t *__ptr = (ptr);						\
443 	CTASSERT(((access) & CTLTYPE) == 0 ||				\
444 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_S8);		\
445 	sysctl_add_oid(ctx, parent, nbr, name,				\
446 	    CTLTYPE_S8 | CTLFLAG_MPSAFE | (access),			\
447 	    __ptr, val, sysctl_handle_8, "C", __DESCR(descr), NULL);	\
448 })
449 
450 /* Oid for an unsigned 8-bit int.  If ptr is NULL, val is returned. */
451 #define	SYSCTL_NULL_U8_PTR ((uint8_t *)NULL)
452 #define	SYSCTL_U8(parent, nbr, name, access, ptr, val, descr)	\
453 	SYSCTL_OID(parent, nbr, name,				\
454 	    CTLTYPE_U8 | CTLFLAG_MPSAFE | (access),		\
455 	    ptr, val, sysctl_handle_8, "CU", descr);		\
456 	CTASSERT((((access) & CTLTYPE) == 0 ||			\
457 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_U8) && \
458 	    sizeof(uint8_t) == sizeof(*(ptr)))
459 
460 #define	SYSCTL_ADD_U8(ctx, parent, nbr, name, access, ptr, val, descr)	\
461 ({									\
462 	uint8_t *__ptr = (ptr);						\
463 	CTASSERT(((access) & CTLTYPE) == 0 ||				\
464 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_U8);		\
465 	sysctl_add_oid(ctx, parent, nbr, name,				\
466 	    CTLTYPE_U8 | CTLFLAG_MPSAFE | (access),			\
467 	    __ptr, val, sysctl_handle_8, "CU", __DESCR(descr), NULL);	\
468 })
469 
470 /* Oid for a signed 16-bit int.  If ptr is NULL, val is returned. */
471 #define	SYSCTL_NULL_S16_PTR ((int16_t *)NULL)
472 #define	SYSCTL_S16(parent, nbr, name, access, ptr, val, descr)	\
473 	SYSCTL_OID(parent, nbr, name,				\
474 	    CTLTYPE_S16 | CTLFLAG_MPSAFE | (access),		\
475 	    ptr, val, sysctl_handle_16, "S", descr);		\
476 	CTASSERT((((access) & CTLTYPE) == 0 ||			\
477 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_S16) && \
478 	    sizeof(int16_t) == sizeof(*(ptr)))
479 
480 #define	SYSCTL_ADD_S16(ctx, parent, nbr, name, access, ptr, val, descr)	\
481 ({									\
482 	int16_t *__ptr = (ptr);						\
483 	CTASSERT(((access) & CTLTYPE) == 0 ||				\
484 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_S16);		\
485 	sysctl_add_oid(ctx, parent, nbr, name,				\
486 	    CTLTYPE_S16 | CTLFLAG_MPSAFE | (access),			\
487 	    __ptr, val, sysctl_handle_16, "S", __DESCR(descr), NULL);	\
488 })
489 
490 /* Oid for an unsigned 16-bit int.  If ptr is NULL, val is returned. */
491 #define	SYSCTL_NULL_U16_PTR ((uint16_t *)NULL)
492 #define	SYSCTL_U16(parent, nbr, name, access, ptr, val, descr)	\
493 	SYSCTL_OID(parent, nbr, name,				\
494 	    CTLTYPE_U16 | CTLFLAG_MPSAFE | (access),		\
495 	    ptr, val, sysctl_handle_16, "SU", descr);		\
496 	CTASSERT((((access) & CTLTYPE) == 0 ||			\
497 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_U16) && \
498 	    sizeof(uint16_t) == sizeof(*(ptr)))
499 
500 #define	SYSCTL_ADD_U16(ctx, parent, nbr, name, access, ptr, val, descr)	\
501 ({									\
502 	uint16_t *__ptr = (ptr);					\
503 	CTASSERT(((access) & CTLTYPE) == 0 ||				\
504 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_U16);		\
505 	sysctl_add_oid(ctx, parent, nbr, name,				\
506 	    CTLTYPE_U16 | CTLFLAG_MPSAFE | (access),			\
507 	    __ptr, val, sysctl_handle_16, "SU", __DESCR(descr), NULL);	\
508 })
509 
510 /* Oid for a signed 32-bit int.  If ptr is NULL, val is returned. */
511 #define	SYSCTL_NULL_S32_PTR ((int32_t *)NULL)
512 #define	SYSCTL_S32(parent, nbr, name, access, ptr, val, descr)	\
513 	SYSCTL_OID(parent, nbr, name,				\
514 	    CTLTYPE_S32 | CTLFLAG_MPSAFE | (access),		\
515 	    ptr, val, sysctl_handle_32, "I", descr);		\
516 	CTASSERT((((access) & CTLTYPE) == 0 ||			\
517 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_S32) && \
518 	    sizeof(int32_t) == sizeof(*(ptr)))
519 
520 #define	SYSCTL_ADD_S32(ctx, parent, nbr, name, access, ptr, val, descr)	\
521 ({									\
522 	int32_t *__ptr = (ptr);						\
523 	CTASSERT(((access) & CTLTYPE) == 0 ||				\
524 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_S32);		\
525 	sysctl_add_oid(ctx, parent, nbr, name,				\
526 	    CTLTYPE_S32 | CTLFLAG_MPSAFE | (access),			\
527 	    __ptr, val, sysctl_handle_32, "I", __DESCR(descr), NULL);	\
528 })
529 
530 /* Oid for an unsigned 32-bit int.  If ptr is NULL, val is returned. */
531 #define	SYSCTL_NULL_U32_PTR ((uint32_t *)NULL)
532 #define	SYSCTL_U32(parent, nbr, name, access, ptr, val, descr)	\
533 	SYSCTL_OID(parent, nbr, name,				\
534 	    CTLTYPE_U32 | CTLFLAG_MPSAFE | (access),		\
535 	    ptr, val, sysctl_handle_32, "IU", descr);		\
536 	CTASSERT((((access) & CTLTYPE) == 0 ||			\
537 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_U32) && \
538 	    sizeof(uint32_t) == sizeof(*(ptr)))
539 
540 #define	SYSCTL_ADD_U32(ctx, parent, nbr, name, access, ptr, val, descr)	\
541 ({									\
542 	uint32_t *__ptr = (ptr);					\
543 	CTASSERT(((access) & CTLTYPE) == 0 ||				\
544 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_U32);		\
545 	sysctl_add_oid(ctx, parent, nbr, name,				\
546 	    CTLTYPE_U32 | CTLFLAG_MPSAFE | (access),			\
547 	    __ptr, val, sysctl_handle_32, "IU", __DESCR(descr), NULL);	\
548 })
549 
550 /* Oid for a signed 64-bit int.  If ptr is NULL, val is returned. */
551 #define	SYSCTL_NULL_S64_PTR ((int64_t *)NULL)
552 #define	SYSCTL_S64(parent, nbr, name, access, ptr, val, descr)	\
553 	SYSCTL_OID(parent, nbr, name,				\
554 	    CTLTYPE_S64 | CTLFLAG_MPSAFE | (access),		\
555 	    ptr, val, sysctl_handle_64, "Q", descr);		\
556 	CTASSERT((((access) & CTLTYPE) == 0 ||			\
557 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_S64) && \
558 	    sizeof(int64_t) == sizeof(*(ptr)))
559 
560 #define	SYSCTL_ADD_S64(ctx, parent, nbr, name, access, ptr, val, descr)	\
561 ({									\
562 	int64_t *__ptr = (ptr);						\
563 	CTASSERT(((access) & CTLTYPE) == 0 ||				\
564 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_S64);		\
565 	sysctl_add_oid(ctx, parent, nbr, name,				\
566 	    CTLTYPE_S64 | CTLFLAG_MPSAFE | (access),			\
567 	    __ptr, val, sysctl_handle_64, "Q", __DESCR(descr), NULL);	\
568 })
569 
570 /* Oid for an unsigned 64-bit int.  If ptr is NULL, val is returned. */
571 #define	SYSCTL_NULL_U64_PTR ((uint64_t *)NULL)
572 #define	SYSCTL_U64(parent, nbr, name, access, ptr, val, descr)	\
573 	SYSCTL_OID(parent, nbr, name,				\
574 	    CTLTYPE_U64 | CTLFLAG_MPSAFE | (access),		\
575 	    ptr, val, sysctl_handle_64, "QU", descr);		\
576 	CTASSERT((((access) & CTLTYPE) == 0 ||			\
577 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_U64) && \
578 	    sizeof(uint64_t) == sizeof(*(ptr)))
579 
580 #define	SYSCTL_ADD_U64(ctx, parent, nbr, name, access, ptr, val, descr)	\
581 ({									\
582 	uint64_t *__ptr = (ptr);					\
583 	CTASSERT(((access) & CTLTYPE) == 0 ||				\
584 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_U64);		\
585 	sysctl_add_oid(ctx, parent, nbr, name,				\
586 	    CTLTYPE_U64 | CTLFLAG_MPSAFE | (access),			\
587 	    __ptr, val, sysctl_handle_64, "QU", __DESCR(descr), NULL);	\
588 })
589 
590 /* Oid for an int.  If ptr is SYSCTL_NULL_INT_PTR, val is returned. */
591 #define	SYSCTL_NULL_INT_PTR ((int *)NULL)
592 #define	SYSCTL_INT(parent, nbr, name, access, ptr, val, descr) \
593 	SYSCTL_INT_WITH_LABEL(parent, nbr, name, access, ptr, val, descr, NULL)
594 
595 #define	SYSCTL_INT_WITH_LABEL(parent, nbr, name, access, ptr, val, descr, label) \
596 	SYSCTL_OID_WITH_LABEL(parent, nbr, name,			\
597 	    CTLTYPE_INT | CTLFLAG_MPSAFE | (access),			\
598 	    ptr, val, sysctl_handle_int, "I", descr, label);		\
599 	CTASSERT((((access) & CTLTYPE) == 0 ||				\
600 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_INT) && \
601 	    sizeof(int) == sizeof(*(ptr)))
602 
603 #define	SYSCTL_ADD_INT(ctx, parent, nbr, name, access, ptr, val, descr)	\
604 ({									\
605 	int *__ptr = (ptr);						\
606 	CTASSERT(((access) & CTLTYPE) == 0 ||				\
607 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_INT);		\
608 	sysctl_add_oid(ctx, parent, nbr, name,				\
609 	    CTLTYPE_INT | CTLFLAG_MPSAFE | (access),			\
610 	    __ptr, val, sysctl_handle_int, "I", __DESCR(descr), NULL);	\
611 })
612 
613 /* Oid for an unsigned int.  If ptr is NULL, val is returned. */
614 #define	SYSCTL_NULL_UINT_PTR ((unsigned *)NULL)
615 #define	SYSCTL_UINT(parent, nbr, name, access, ptr, val, descr)	\
616 	SYSCTL_OID(parent, nbr, name,				\
617 	    CTLTYPE_UINT | CTLFLAG_MPSAFE | (access),		\
618 	    ptr, val, sysctl_handle_int, "IU", descr);		\
619 	CTASSERT((((access) & CTLTYPE) == 0 ||			\
620 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_UINT) && \
621 	    sizeof(unsigned) == sizeof(*(ptr)))
622 
623 #define	SYSCTL_ADD_UINT(ctx, parent, nbr, name, access, ptr, val, descr) \
624 ({									\
625 	unsigned *__ptr = (ptr);					\
626 	CTASSERT(((access) & CTLTYPE) == 0 ||				\
627 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_UINT);	\
628 	sysctl_add_oid(ctx, parent, nbr, name,				\
629 	    CTLTYPE_UINT | CTLFLAG_MPSAFE | (access),			\
630 	    __ptr, val, sysctl_handle_int, "IU", __DESCR(descr), NULL);	\
631 })
632 
633 /* Oid for a long.  The pointer must be non NULL. */
634 #define	SYSCTL_NULL_LONG_PTR ((long *)NULL)
635 #define	SYSCTL_LONG(parent, nbr, name, access, ptr, val, descr)	\
636 	SYSCTL_OID(parent, nbr, name,				\
637 	    CTLTYPE_LONG | CTLFLAG_MPSAFE | (access),		\
638 	    ptr, val, sysctl_handle_long, "L", descr);		\
639 	CTASSERT((((access) & CTLTYPE) == 0 ||			\
640 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_LONG) && \
641 	    sizeof(long) == sizeof(*(ptr)))
642 
643 #define	SYSCTL_ADD_LONG(ctx, parent, nbr, name, access, ptr, descr)	\
644 ({									\
645 	long *__ptr = (ptr);						\
646 	CTASSERT(((access) & CTLTYPE) == 0 ||				\
647 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_LONG);	\
648 	sysctl_add_oid(ctx, parent, nbr, name,				\
649 	    CTLTYPE_LONG | CTLFLAG_MPSAFE | (access),			\
650 	    __ptr, 0, sysctl_handle_long, "L", __DESCR(descr), NULL);	\
651 })
652 
653 /* Oid for an unsigned long.  The pointer must be non NULL. */
654 #define	SYSCTL_NULL_ULONG_PTR ((unsigned long *)NULL)
655 #define	SYSCTL_ULONG(parent, nbr, name, access, ptr, val, descr)	\
656 	SYSCTL_OID(parent, nbr, name,					\
657 	    CTLTYPE_ULONG | CTLFLAG_MPSAFE | (access),			\
658 	    ptr, val, sysctl_handle_long, "LU", descr);			\
659 	CTASSERT((((access) & CTLTYPE) == 0 ||				\
660 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_ULONG) &&	\
661 	    sizeof(unsigned long) == sizeof(*(ptr)))
662 
663 #define	SYSCTL_ADD_ULONG(ctx, parent, nbr, name, access, ptr, descr)	\
664 ({									\
665 	unsigned long *__ptr = (ptr);					\
666 	CTASSERT(((access) & CTLTYPE) == 0 ||				\
667 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_ULONG);	\
668 	sysctl_add_oid(ctx, parent, nbr, name,				\
669 	    CTLTYPE_ULONG | CTLFLAG_MPSAFE | (access),			\
670 	    __ptr, 0, sysctl_handle_long, "LU", __DESCR(descr), NULL);	\
671 })
672 
673 /* Oid for a quad.  The pointer must be non NULL. */
674 #define	SYSCTL_NULL_QUAD_PTR ((int64_t *)NULL)
675 #define	SYSCTL_QUAD(parent, nbr, name, access, ptr, val, descr)	\
676 	SYSCTL_OID(parent, nbr, name,				\
677 	    CTLTYPE_S64 | CTLFLAG_MPSAFE | (access),		\
678 	    ptr, val, sysctl_handle_64, "Q", descr);		\
679 	CTASSERT((((access) & CTLTYPE) == 0 ||			\
680 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_S64) && \
681 	    sizeof(int64_t) == sizeof(*(ptr)))
682 
683 #define	SYSCTL_ADD_QUAD(ctx, parent, nbr, name, access, ptr, descr)	\
684 ({									\
685 	int64_t *__ptr = (ptr);						\
686 	CTASSERT(((access) & CTLTYPE) == 0 ||				\
687 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_S64);		\
688 	sysctl_add_oid(ctx, parent, nbr, name,				\
689 	    CTLTYPE_S64 | CTLFLAG_MPSAFE | (access),			\
690 	    __ptr, 0, sysctl_handle_64, "Q", __DESCR(descr), NULL);	\
691 })
692 
693 #define	SYSCTL_NULL_UQUAD_PTR ((uint64_t *)NULL)
694 #define	SYSCTL_UQUAD(parent, nbr, name, access, ptr, val, descr)	\
695 	SYSCTL_OID(parent, nbr, name,					\
696 	    CTLTYPE_U64 | CTLFLAG_MPSAFE | (access),			\
697 	     ptr, val, sysctl_handle_64, "QU", descr);			\
698 	CTASSERT((((access) & CTLTYPE) == 0 ||				\
699 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_U64) &&	\
700 	    sizeof(uint64_t) == sizeof(*(ptr)))
701 
702 #define	SYSCTL_ADD_UQUAD(ctx, parent, nbr, name, access, ptr, descr)	\
703 ({									\
704 	uint64_t *__ptr = (ptr);					\
705 	CTASSERT(((access) & CTLTYPE) == 0 ||				\
706 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_U64);		\
707 	sysctl_add_oid(ctx, parent, nbr, name,				\
708 	    CTLTYPE_U64 | CTLFLAG_MPSAFE | (access),			\
709 	    __ptr, 0, sysctl_handle_64, "QU", __DESCR(descr), NULL);	\
710 })
711 
712 /* Oid for a CPU dependent variable */
713 #define	SYSCTL_ADD_UAUTO(ctx, parent, nbr, name, access, ptr, descr)	\
714 ({									\
715 	struct sysctl_oid *__ret;					\
716 	CTASSERT((sizeof(uint64_t) == sizeof(*(ptr)) ||			\
717 	    sizeof(unsigned) == sizeof(*(ptr))) &&			\
718 	    ((access) & CTLTYPE) == 0);					\
719 	if (sizeof(uint64_t) == sizeof(*(ptr))) {			\
720 		__ret = sysctl_add_oid(ctx, parent, nbr, name,		\
721 		    CTLTYPE_U64 | CTLFLAG_MPSAFE | (access),		\
722 		    (ptr), 0, sysctl_handle_64, "QU",			\
723 		    __DESCR(descr), NULL);				\
724 	} else {							\
725 		__ret = sysctl_add_oid(ctx, parent, nbr, name,		\
726 		    CTLTYPE_UINT | CTLFLAG_MPSAFE | (access),		\
727 		    (ptr), 0, sysctl_handle_int, "IU",			\
728 		    __DESCR(descr), NULL);				\
729 	}								\
730 	__ret;								\
731 })
732 
733 /* Oid for a 64-bit unsigned counter(9).  The pointer must be non NULL. */
734 #define	SYSCTL_COUNTER_U64(parent, nbr, name, access, ptr, descr)	\
735 	SYSCTL_OID(parent, nbr, name,					\
736 	    CTLTYPE_U64 | CTLFLAG_MPSAFE | CTLFLAG_STATS | (access),	\
737 	    (ptr), 0, sysctl_handle_counter_u64, "QU", descr);		\
738 	CTASSERT((((access) & CTLTYPE) == 0 ||				\
739 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_U64) &&	\
740 	    sizeof(counter_u64_t) == sizeof(*(ptr)) &&			\
741 	    sizeof(uint64_t) == sizeof(**(ptr)))
742 
743 #define	SYSCTL_ADD_COUNTER_U64(ctx, parent, nbr, name, access, ptr, descr) \
744 ({									\
745 	counter_u64_t *__ptr = (ptr);					\
746 	CTASSERT(((access) & CTLTYPE) == 0 ||				\
747 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_U64);		\
748 	sysctl_add_oid(ctx, parent, nbr, name,				\
749 	    CTLTYPE_U64 | CTLFLAG_MPSAFE | CTLFLAG_STATS | (access),	\
750 	    __ptr, 0, sysctl_handle_counter_u64, "QU", __DESCR(descr),	\
751 	    NULL);							\
752 })
753 
754 /* Oid for an array of counter(9)s.  The pointer and length must be non zero. */
755 #define	SYSCTL_COUNTER_U64_ARRAY(parent, nbr, name, access, ptr, len, descr) \
756 	SYSCTL_OID(parent, nbr, name,					\
757 	    CTLTYPE_U64 | CTLFLAG_MPSAFE | CTLFLAG_STATS | (access),	\
758 	    (ptr), (len), sysctl_handle_counter_u64_array, "QU", descr);\
759 	CTASSERT((((access) & CTLTYPE) == 0 ||				\
760 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_OPAQUE) &&	\
761 	    sizeof(counter_u64_t) == sizeof(*(ptr)) &&			\
762 	    sizeof(uint64_t) == sizeof(**(ptr)))
763 
764 #define	SYSCTL_ADD_COUNTER_U64_ARRAY(ctx, parent, nbr, name, access,	\
765     ptr, len, descr)							\
766 ({									\
767 	counter_u64_t *__ptr = (ptr);					\
768 	CTASSERT(((access) & CTLTYPE) == 0 ||				\
769 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_OPAQUE);	\
770 	sysctl_add_oid(ctx, parent, nbr, name,				\
771 	    CTLTYPE_OPAQUE | CTLFLAG_MPSAFE | CTLFLAG_STATS | (access),	\
772 	    __ptr, len, sysctl_handle_counter_u64_array, "S",		\
773 	    __DESCR(descr), NULL);					\
774 })
775 
776 /* Oid for an opaque object.  Specified by a pointer and a length. */
777 #define	SYSCTL_OPAQUE(parent, nbr, name, access, ptr, len, fmt, descr)	\
778 	SYSCTL_OID(parent, nbr, name,					\
779 	    CTLTYPE_OPAQUE | CTLFLAG_MPSAFE | (access),			\
780 	    ptr, len, sysctl_handle_opaque, fmt, descr);		\
781 	CTASSERT(((access) & CTLTYPE) == 0 ||				\
782 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_OPAQUE)
783 
784 #define	SYSCTL_ADD_OPAQUE(ctx, parent, nbr, name, access, ptr, len, fmt, descr)	\
785 ({									\
786 	CTASSERT(((access) & CTLTYPE) == 0 ||				\
787 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_OPAQUE);	\
788 	sysctl_add_oid(ctx, parent, nbr, name,				\
789 	    CTLTYPE_OPAQUE | CTLFLAG_MPSAFE | (access),			\
790 	    ptr, len, sysctl_handle_opaque, fmt, __DESCR(descr), NULL);	\
791 })
792 
793 /* Oid for a struct.  Specified by a pointer and a type. */
794 #define	SYSCTL_STRUCT(parent, nbr, name, access, ptr, type, descr)	\
795 	SYSCTL_OID(parent, nbr, name,					\
796 	    CTLTYPE_OPAQUE | CTLFLAG_MPSAFE | (access),			\
797 	    ptr, sizeof(struct type), sysctl_handle_opaque,		\
798 	    "S," #type, descr);						\
799 	CTASSERT(((access) & CTLTYPE) == 0 ||				\
800 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_OPAQUE)
801 
802 #define	SYSCTL_ADD_STRUCT(ctx, parent, nbr, name, access, ptr, type, descr) \
803 ({									\
804 	CTASSERT(((access) & CTLTYPE) == 0 ||				\
805 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_OPAQUE);	\
806 	sysctl_add_oid(ctx, parent, nbr, name,				\
807 	    CTLTYPE_OPAQUE | CTLFLAG_MPSAFE | (access),			\
808 	    (ptr), sizeof(struct type),					\
809 	    sysctl_handle_opaque, "S," #type, __DESCR(descr), NULL);	\
810 })
811 
812 /* Oid for a procedure.  Specified by a pointer and an arg. */
813 #define	SYSCTL_PROC(parent, nbr, name, access, ptr, arg, handler, fmt, descr) \
814 	SYSCTL_OID(parent, nbr, name, (access),				\
815 	    ptr, arg, handler, fmt, descr);				\
816 	CTASSERT(((access) & CTLTYPE) != 0)
817 
818 #define	SYSCTL_ADD_PROC(ctx, parent, nbr, name, access, ptr, arg, handler, fmt, descr) \
819 ({									\
820 	CTASSERT(((access) & CTLTYPE) != 0);				\
821 	SYSCTL_ENFORCE_FLAGS(access);					\
822 	sysctl_add_oid(ctx, parent, nbr, name, (access),		\
823 	    (ptr), (arg), (handler), (fmt), __DESCR(descr), NULL);	\
824 })
825 
826 /* Oid to handle limits on uma(9) zone specified by pointer. */
827 #define	SYSCTL_UMA_MAX(parent, nbr, name, access, ptr, descr)	\
828 	SYSCTL_OID(parent, nbr, name,				\
829 	    CTLTYPE_INT | CTLFLAG_MPSAFE | (access),		\
830 	    (ptr), 0, sysctl_handle_uma_zone_max, "I", descr);	\
831 	CTASSERT(((access) & CTLTYPE) == 0 ||			\
832 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_INT)
833 
834 #define	SYSCTL_ADD_UMA_MAX(ctx, parent, nbr, name, access, ptr, descr)	\
835 ({									\
836 	uma_zone_t __ptr = (ptr);					\
837 	CTASSERT(((access) & CTLTYPE) == 0 ||				\
838 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_INT);		\
839 	sysctl_add_oid(ctx, parent, nbr, name,				\
840 	    CTLTYPE_INT | CTLFLAG_MPSAFE | (access),			\
841 	    __ptr, 0, sysctl_handle_uma_zone_max, "I", __DESCR(descr),	\
842 	    NULL);							\
843 })
844 
845 /* Oid to obtain current use of uma(9) zone specified by pointer. */
846 #define	SYSCTL_UMA_CUR(parent, nbr, name, access, ptr, descr)		\
847 	SYSCTL_OID(parent, nbr, name,					\
848 	    CTLTYPE_INT | CTLFLAG_MPSAFE | CTLFLAG_RD | (access),	\
849 	    (ptr), 0, sysctl_handle_uma_zone_cur, "I", descr);		\
850 	CTASSERT(((access) & CTLTYPE) == 0 ||				\
851 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_INT)
852 
853 #define	SYSCTL_ADD_UMA_CUR(ctx, parent, nbr, name, access, ptr, descr)	\
854 ({									\
855 	uma_zone_t __ptr = (ptr);					\
856 	CTASSERT(((access) & CTLTYPE) == 0 ||				\
857 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_INT);		\
858 	sysctl_add_oid(ctx, parent, nbr, name,				\
859 	    CTLTYPE_INT | CTLFLAG_MPSAFE | CTLFLAG_RD | (access),	\
860 	    __ptr, 0, sysctl_handle_uma_zone_cur, "I", __DESCR(descr),	\
861 	    NULL);							\
862 })
863 
864 /* OID expressing a sbintime_t as microseconds */
865 #define	SYSCTL_SBINTIME_USEC(parent, nbr, name, access, ptr, descr)	\
866 	SYSCTL_OID(parent, nbr, name,					\
867 	    CTLTYPE_INT | CTLFLAG_MPSAFE | CTLFLAG_RD | (access),	\
868 	    (ptr), 0, sysctl_usec_to_sbintime, "Q", descr);		\
869 	CTASSERT(((access) & CTLTYPE) == 0 ||				\
870 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_S64)
871 #define	SYSCTL_ADD_SBINTIME_USEC(ctx, parent, nbr, name, access, ptr, descr) \
872 ({									\
873 	sbintime_t *__ptr = (ptr);					\
874 	CTASSERT(((access) & CTLTYPE) == 0 ||				\
875 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_S64);		\
876 	sysctl_add_oid(ctx, parent, nbr, name,				\
877 	    CTLTYPE_INT | CTLFLAG_MPSAFE | CTLFLAG_RD | (access),	\
878 	    __ptr, 0, sysctl_usec_to_sbintime, "Q", __DESCR(descr),	\
879 	    NULL);							\
880 })
881 
882 /* OID expressing a sbintime_t as milliseconds */
883 #define	SYSCTL_SBINTIME_MSEC(parent, nbr, name, access, ptr, descr)	\
884 	SYSCTL_OID(parent, nbr, name,					\
885 	    CTLTYPE_INT | CTLFLAG_MPSAFE | CTLFLAG_RD | (access),	\
886 	    (ptr), 0, sysctl_msec_to_sbintime, "Q", descr);		\
887 	CTASSERT(((access) & CTLTYPE) == 0 ||				\
888 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_S64)
889 #define	SYSCTL_ADD_SBINTIME_MSEC(ctx, parent, nbr, name, access, ptr, descr) \
890 ({									\
891 	sbintime_t *__ptr = (ptr);					\
892 	CTASSERT(((access) & CTLTYPE) == 0 ||				\
893 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_S64);		\
894 	sysctl_add_oid(ctx, parent, nbr, name,				\
895 	    CTLTYPE_INT | CTLFLAG_MPSAFE | CTLFLAG_RD | (access),	\
896 	    __ptr, 0, sysctl_msec_to_sbintime, "Q", __DESCR(descr),	\
897 	    NULL);							\
898 })
899 
900 /* OID expressing a struct timeval as seconds */
901 #define	SYSCTL_TIMEVAL_SEC(parent, nbr, name, access, ptr, descr)	\
902 	SYSCTL_OID(parent, nbr, name,					\
903 	    CTLTYPE_INT | CTLFLAG_MPSAFE | CTLFLAG_RD | (access),	\
904 	    (ptr), 0, sysctl_sec_to_timeval, "I", descr);		\
905 	CTASSERT(((access) & CTLTYPE) == 0 ||				\
906 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_INT)
907 #define	SYSCTL_ADD_TIMEVAL_SEC(ctx, parent, nbr, name, access, ptr, descr) \
908 ({									\
909 	struct timeval *__ptr = (ptr);					\
910 	CTASSERT(((access) & CTLTYPE) == 0 ||				\
911 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_INT);		\
912 	sysctl_add_oid(ctx, parent, nbr, name,				\
913 	    CTLTYPE_INT | CTLFLAG_MPSAFE | CTLFLAG_RD | (access),	\
914 	    __ptr, 0, sysctl_sec_to_timeval, "I", __DESCR(descr),	\
915 	    NULL);							\
916 })
917 
918 #define	SYSCTL_FOREACH(oidp, list) \
919 	RB_FOREACH(oidp, sysctl_oid_list, list)
920 
921 /*
922  * A macro to generate a read-only sysctl to indicate the presence of optional
923  * kernel features.
924  */
925 #define	FEATURE(name, desc)						\
926 	SYSCTL_INT_WITH_LABEL(_kern_features, OID_AUTO, name,		\
927 	    CTLFLAG_RD | CTLFLAG_CAPRD, SYSCTL_NULL_INT_PTR, 1, desc, "feature")
928 /* Same for the dynamic registration. */
929 #define	FEATURE_ADD(name, desc)						\
930 	sysctl_add_oid(NULL, SYSCTL_CHILDREN(&sysctl___kern_features),	\
931 	    OID_AUTO, name,						\
932 	    CTLFLAG_RD | CTLFLAG_CAPRD | CTLTYPE_INT | CTLFLAG_MPSAFE,	\
933 	    NULL, 1, sysctl_handle_int, "I", desc, "feature");
934 
935 #endif /* _KERNEL */
936 
937 /*
938  * Top-level identifiers
939  */
940 #define	CTL_SYSCTL	0		/* "magic" numbers */
941 #define	CTL_KERN	1		/* "high kernel": proc, limits */
942 #define	CTL_VM		2		/* virtual memory */
943 #define	CTL_VFS		3		/* filesystem, mount type is next */
944 #define	CTL_NET		4		/* network, see socket.h */
945 #define	CTL_DEBUG	5		/* debugging parameters */
946 #define	CTL_HW		6		/* generic cpu/io */
947 #define	CTL_MACHDEP	7		/* machine dependent */
948 #define	CTL_USER	8		/* user-level */
949 #define	CTL_P1003_1B	9		/* POSIX 1003.1B */
950 
951 /*
952  * CTL_SYSCTL identifiers
953  */
954 #define	CTL_SYSCTL_DEBUG	0	/* printf all nodes */
955 #define	CTL_SYSCTL_NAME		1	/* string name of OID */
956 #define	CTL_SYSCTL_NEXT		2	/* next OID, honoring CTLFLAG_SKIP */
957 #define	CTL_SYSCTL_NAME2OID	3	/* int array of name */
958 #define	CTL_SYSCTL_OIDFMT	4	/* OID's kind and format */
959 #define	CTL_SYSCTL_OIDDESCR	5	/* OID's description */
960 #define	CTL_SYSCTL_OIDLABEL	6	/* aggregation label */
961 #define	CTL_SYSCTL_NEXTNOSKIP	7	/* next OID, ignoring CTLFLAG_SKIP */
962 
963 /*
964  * CTL_KERN identifiers
965  */
966 #define	KERN_OSTYPE		 1	/* string: system version */
967 #define	KERN_OSRELEASE		 2	/* string: system release */
968 #define	KERN_OSREV		 3	/* int: system revision */
969 #define	KERN_VERSION		 4	/* string: compile time info */
970 #define	KERN_MAXVNODES		 5	/* int: max vnodes */
971 #define	KERN_MAXPROC		 6	/* int: max processes */
972 #define	KERN_MAXFILES		 7	/* int: max open files */
973 #define	KERN_ARGMAX		 8	/* int: max arguments to exec */
974 #define	KERN_SECURELVL		 9	/* int: system security level */
975 #define	KERN_HOSTNAME		10	/* string: hostname */
976 #define	KERN_HOSTID		11	/* int: host identifier */
977 #define	KERN_CLOCKRATE		12	/* struct: struct clockrate */
978 /* was: #define	KERN_VNODE	13	; disabled in 2003 and removed in 2023 */
979 #define	KERN_PROC		14	/* struct: process entries */
980 #define	KERN_FILE		15	/* struct: file entries */
981 #define	KERN_PROF		16	/* node: kernel profiling info */
982 #define	KERN_POSIX1		17	/* int: POSIX.1 version */
983 #define	KERN_NGROUPS		18	/* int: # of supplemental group ids */
984 #define	KERN_JOB_CONTROL	19	/* int: is job control available */
985 #define	KERN_SAVED_IDS		20	/* int: saved set-user/group-ID */
986 #define	KERN_BOOTTIME		21	/* struct: time kernel was booted */
987 #define	KERN_NISDOMAINNAME	22	/* string: YP domain name */
988 #define	KERN_UPDATEINTERVAL	23	/* int: update process sleep time */
989 #define	KERN_OSRELDATE		24	/* int: kernel release date */
990 #define	KERN_NTP_PLL		25	/* node: NTP PLL control */
991 #define	KERN_BOOTFILE		26	/* string: name of booted kernel */
992 #define	KERN_MAXFILESPERPROC	27	/* int: max open files per proc */
993 #define	KERN_MAXPROCPERUID	28	/* int: max processes per uid */
994 #define	KERN_DUMPDEV		29	/* struct cdev *: device to dump on */
995 #define	KERN_IPC		30	/* node: anything related to IPC */
996 #define	KERN_DUMMY		31	/* unused */
997 #define	KERN_PS_STRINGS		32	/* int: address of PS_STRINGS */
998 #define	KERN_USRSTACK		33	/* int: address of USRSTACK */
999 #define	KERN_LOGSIGEXIT		34	/* int: do we log sigexit procs? */
1000 #define	KERN_IOV_MAX		35	/* int: value of UIO_MAXIOV */
1001 #define	KERN_HOSTUUID		36	/* string: host UUID identifier */
1002 #define	KERN_ARND		37	/* int: from arc4rand() */
1003 #define	KERN_MAXPHYS		38	/* int: MAXPHYS value */
1004 #define	KERN_LOCKF		39	/* struct: lockf reports */
1005 /*
1006  * KERN_PROC subtypes
1007  */
1008 #define	KERN_PROC_ALL		0	/* everything */
1009 #define	KERN_PROC_PID		1	/* by process id */
1010 #define	KERN_PROC_PGRP		2	/* by process group id */
1011 #define	KERN_PROC_SESSION	3	/* by session of pid */
1012 #define	KERN_PROC_TTY		4	/* by controlling tty */
1013 #define	KERN_PROC_UID		5	/* by effective uid */
1014 #define	KERN_PROC_RUID		6	/* by real uid */
1015 #define	KERN_PROC_ARGS		7	/* get/set arguments/proctitle */
1016 #define	KERN_PROC_PROC		8	/* only return procs */
1017 #define	KERN_PROC_SV_NAME	9	/* get syscall vector name */
1018 #define	KERN_PROC_RGID		10	/* by real group id */
1019 #define	KERN_PROC_GID		11	/* by effective group id */
1020 #define	KERN_PROC_PATHNAME	12	/* path to executable */
1021 #define	KERN_PROC_OVMMAP	13	/* Old VM map entries for process */
1022 #define	KERN_PROC_OFILEDESC	14	/* Old file descriptors for process */
1023 #define	KERN_PROC_KSTACK	15	/* Kernel stacks for process */
1024 #define	KERN_PROC_INC_THREAD	0x10	/*
1025 					 * modifier for pid, pgrp, tty,
1026 					 * uid, ruid, gid, rgid and proc
1027 					 * This effectively uses 16-31
1028 					 */
1029 #define	KERN_PROC_VMMAP		32	/* VM map entries for process */
1030 #define	KERN_PROC_FILEDESC	33	/* File descriptors for process */
1031 #define	KERN_PROC_GROUPS	34	/* process groups */
1032 #define	KERN_PROC_ENV		35	/* get environment */
1033 #define	KERN_PROC_AUXV		36	/* get ELF auxiliary vector */
1034 #define	KERN_PROC_RLIMIT	37	/* process resource limits */
1035 #define	KERN_PROC_PS_STRINGS	38	/* get ps_strings location */
1036 #define	KERN_PROC_UMASK		39	/* process umask */
1037 #define	KERN_PROC_OSREL		40	/* osreldate for process binary */
1038 #define	KERN_PROC_SIGTRAMP	41	/* signal trampoline location */
1039 #define	KERN_PROC_CWD		42	/* process current working directory */
1040 #define	KERN_PROC_NFDS		43	/* number of open file descriptors */
1041 #define	KERN_PROC_SIGFASTBLK	44	/* address of fastsigblk magic word */
1042 #define	KERN_PROC_VM_LAYOUT	45	/* virtual address space layout info */
1043 
1044 /*
1045  * KERN_IPC identifiers
1046  */
1047 #define	KIPC_MAXSOCKBUF		1	/* int: max size of a socket buffer */
1048 #define	KIPC_SOCKBUF_WASTE	2	/* int: wastage factor in sockbuf */
1049 #define	KIPC_SOMAXCONN		3	/* int: max length of connection q */
1050 #define	KIPC_MAX_LINKHDR	4	/* int: max length of link header */
1051 #define	KIPC_MAX_PROTOHDR	5	/* int: max length of network header */
1052 #define	KIPC_MAX_HDR		6	/* int: max total length of headers */
1053 #define	KIPC_MAX_DATALEN	7	/* int: max length of data? */
1054 
1055 /*
1056  * CTL_HW identifiers
1057  */
1058 #define	HW_MACHINE	 1		/* string: machine class */
1059 #define	HW_MODEL	 2		/* string: specific machine model */
1060 #define	HW_NCPU		 3		/* int: number of cpus */
1061 #define	HW_BYTEORDER	 4		/* int: machine byte order */
1062 #define	HW_PHYSMEM	 5		/* int: total memory */
1063 #define	HW_USERMEM	 6		/* int: non-kernel memory */
1064 #define	HW_PAGESIZE	 7		/* int: software page size */
1065 #define	HW_DISKNAMES	 8		/* strings: disk drive names */
1066 #define	HW_DISKSTATS	 9		/* struct: diskstats[] */
1067 #define	HW_FLOATINGPT	10		/* int: has HW floating point? */
1068 #define	HW_MACHINE_ARCH	11		/* string: machine architecture */
1069 #define	HW_REALMEM	12		/* int: 'real' memory */
1070 
1071 /*
1072  * CTL_USER definitions
1073  */
1074 #define	USER_CS_PATH		 1	/* string: _CS_PATH */
1075 #define	USER_BC_BASE_MAX	 2	/* int: BC_BASE_MAX */
1076 #define	USER_BC_DIM_MAX		 3	/* int: BC_DIM_MAX */
1077 #define	USER_BC_SCALE_MAX	 4	/* int: BC_SCALE_MAX */
1078 #define	USER_BC_STRING_MAX	 5	/* int: BC_STRING_MAX */
1079 #define	USER_COLL_WEIGHTS_MAX	 6	/* int: COLL_WEIGHTS_MAX */
1080 #define	USER_EXPR_NEST_MAX	 7	/* int: EXPR_NEST_MAX */
1081 #define	USER_LINE_MAX		 8	/* int: LINE_MAX */
1082 #define	USER_RE_DUP_MAX		 9	/* int: RE_DUP_MAX */
1083 #define	USER_POSIX2_VERSION	10	/* int: POSIX2_VERSION */
1084 #define	USER_POSIX2_C_BIND	11	/* int: POSIX2_C_BIND */
1085 #define	USER_POSIX2_C_DEV	12	/* int: POSIX2_C_DEV */
1086 #define	USER_POSIX2_CHAR_TERM	13	/* int: POSIX2_CHAR_TERM */
1087 #define	USER_POSIX2_FORT_DEV	14	/* int: POSIX2_FORT_DEV */
1088 #define	USER_POSIX2_FORT_RUN	15	/* int: POSIX2_FORT_RUN */
1089 #define	USER_POSIX2_LOCALEDEF	16	/* int: POSIX2_LOCALEDEF */
1090 #define	USER_POSIX2_SW_DEV	17	/* int: POSIX2_SW_DEV */
1091 #define	USER_POSIX2_UPE		18	/* int: POSIX2_UPE */
1092 #define	USER_STREAM_MAX		19	/* int: POSIX2_STREAM_MAX */
1093 #define	USER_TZNAME_MAX		20	/* int: POSIX2_TZNAME_MAX */
1094 #define	USER_LOCALBASE		21	/* string: _PATH_LOCALBASE */
1095 
1096 #define	CTL_P1003_1B_ASYNCHRONOUS_IO		1	/* boolean */
1097 #define	CTL_P1003_1B_MAPPED_FILES		2	/* boolean */
1098 #define	CTL_P1003_1B_MEMLOCK			3	/* boolean */
1099 #define	CTL_P1003_1B_MEMLOCK_RANGE		4	/* boolean */
1100 #define	CTL_P1003_1B_MEMORY_PROTECTION		5	/* boolean */
1101 #define	CTL_P1003_1B_MESSAGE_PASSING		6	/* boolean */
1102 #define	CTL_P1003_1B_PRIORITIZED_IO		7	/* boolean */
1103 #define	CTL_P1003_1B_PRIORITY_SCHEDULING	8	/* boolean */
1104 #define	CTL_P1003_1B_REALTIME_SIGNALS		9	/* boolean */
1105 #define	CTL_P1003_1B_SEMAPHORES			10	/* boolean */
1106 #define	CTL_P1003_1B_FSYNC			11	/* boolean */
1107 #define	CTL_P1003_1B_SHARED_MEMORY_OBJECTS	12	/* boolean */
1108 #define	CTL_P1003_1B_SYNCHRONIZED_IO		13	/* boolean */
1109 #define	CTL_P1003_1B_TIMERS			14	/* boolean */
1110 #define	CTL_P1003_1B_AIO_LISTIO_MAX		15	/* int */
1111 #define	CTL_P1003_1B_AIO_MAX			16	/* int */
1112 #define	CTL_P1003_1B_AIO_PRIO_DELTA_MAX		17	/* int */
1113 #define	CTL_P1003_1B_DELAYTIMER_MAX		18	/* int */
1114 #define	CTL_P1003_1B_MQ_OPEN_MAX		19	/* int */
1115 #define	CTL_P1003_1B_PAGESIZE			20	/* int */
1116 #define	CTL_P1003_1B_RTSIG_MAX			21	/* int */
1117 #define	CTL_P1003_1B_SEM_NSEMS_MAX		22	/* int */
1118 #define	CTL_P1003_1B_SEM_VALUE_MAX		23	/* int */
1119 #define	CTL_P1003_1B_SIGQUEUE_MAX		24	/* int */
1120 #define	CTL_P1003_1B_TIMER_MAX			25	/* int */
1121 
1122 #ifdef _KERNEL
1123 
1124 #define	CTL_P1003_1B_MAXID		26
1125 
1126 /*
1127  * Declare some common oids.
1128  */
1129 extern struct sysctl_oid_list sysctl__children;
1130 SYSCTL_DECL(_kern);
1131 SYSCTL_DECL(_kern_features);
1132 SYSCTL_DECL(_kern_ipc);
1133 SYSCTL_DECL(_kern_proc);
1134 SYSCTL_DECL(_kern_sched);
1135 SYSCTL_DECL(_kern_sched_stats);
1136 SYSCTL_DECL(_sysctl);
1137 SYSCTL_DECL(_vm);
1138 SYSCTL_DECL(_vm_stats);
1139 SYSCTL_DECL(_vm_stats_misc);
1140 SYSCTL_DECL(_vfs);
1141 SYSCTL_DECL(_net);
1142 SYSCTL_DECL(_debug);
1143 SYSCTL_DECL(_debug_sizeof);
1144 SYSCTL_DECL(_dev);
1145 SYSCTL_DECL(_hw);
1146 SYSCTL_DECL(_hw_bus);
1147 SYSCTL_DECL(_hw_bus_devices);
1148 SYSCTL_DECL(_machdep);
1149 SYSCTL_DECL(_machdep_mitigations);
1150 SYSCTL_DECL(_user);
1151 SYSCTL_DECL(_compat);
1152 SYSCTL_DECL(_regression);
1153 SYSCTL_DECL(_security);
1154 SYSCTL_DECL(_security_bsd);
1155 
1156 extern char	machine[];
1157 extern char	osrelease[];
1158 extern char	ostype[];
1159 extern char	kern_ident[];
1160 
1161 /* Dynamic oid handling */
1162 struct sysctl_oid *sysctl_add_oid(struct sysctl_ctx_list *clist,
1163 	    struct sysctl_oid_list *parent, int nbr, const char *name, int kind,
1164 	    void *arg1, intmax_t arg2, int (*handler)(SYSCTL_HANDLER_ARGS),
1165 	    const char *fmt, const char *descr, const char *label);
1166 int	sysctl_remove_name(struct sysctl_oid *parent, const char *name, int del,
1167 	    int recurse);
1168 void	sysctl_rename_oid(struct sysctl_oid *oidp, const char *name);
1169 int	sysctl_move_oid(struct sysctl_oid *oidp,
1170 	    struct sysctl_oid_list *parent);
1171 int	sysctl_remove_oid(struct sysctl_oid *oidp, int del, int recurse);
1172 int	sysctl_ctx_init(struct sysctl_ctx_list *clist);
1173 int	sysctl_ctx_free(struct sysctl_ctx_list *clist);
1174 struct	sysctl_ctx_entry *sysctl_ctx_entry_add(struct sysctl_ctx_list *clist,
1175 	    struct sysctl_oid *oidp);
1176 struct	sysctl_ctx_entry *sysctl_ctx_entry_find(struct sysctl_ctx_list *clist,
1177 	    struct sysctl_oid *oidp);
1178 int	sysctl_ctx_entry_del(struct sysctl_ctx_list *clist,
1179 	    struct sysctl_oid *oidp);
1180 
1181 int	kernel_sysctl(struct thread *td, int *name, u_int namelen, void *old,
1182 	    size_t *oldlenp, void *new, size_t newlen, size_t *retval,
1183 	    int flags);
1184 int	kernel_sysctlbyname(struct thread *td, char *name, void *old,
1185 	    size_t *oldlenp, void *new, size_t newlen, size_t *retval,
1186 	    int flags);
1187 int	userland_sysctl(struct thread *td, int *name, u_int namelen, void *old,
1188 	    size_t *oldlenp, int inkernel, const void *new, size_t newlen,
1189 	    size_t *retval, int flags);
1190 int	sysctl_find_oid(int *name, u_int namelen, struct sysctl_oid **noid,
1191 	    int *nindx, struct sysctl_req *req);
1192 void	sysctl_wlock(void);
1193 void	sysctl_wunlock(void);
1194 int	sysctl_wire_old_buffer(struct sysctl_req *req, size_t len);
1195 int	kern___sysctlbyname(struct thread *td, const char *name,
1196 	    size_t namelen, void *old, size_t *oldlenp, void *new,
1197 	    size_t newlen, size_t *retval, int flags, bool inkernel);
1198 
1199 struct sbuf;
1200 struct sbuf *sbuf_new_for_sysctl(struct sbuf *, char *, int,
1201 	    struct sysctl_req *);
1202 #else	/* !_KERNEL */
1203 #include <sys/cdefs.h>
1204 #include <sys/_types.h>
1205 #ifndef _SIZE_T_DECLARED
1206 typedef	__size_t	size_t;
1207 #define	_SIZE_T_DECLARED
1208 #endif
1209 
1210 __BEGIN_DECLS
1211 int	sysctl(const int *, unsigned int, void *, size_t *, const void *, size_t);
1212 int	sysctlbyname(const char *, void *, size_t *, const void *, size_t);
1213 int	sysctlnametomib(const char *, int *, size_t *);
1214 __END_DECLS
1215 #endif	/* _KERNEL */
1216 
1217 #endif	/* !_SYS_SYSCTL_H_ */
1218