xref: /freebsd/sys/sys/sysctl.h (revision 1de7b4b805ddbf2429da511c053686ac4591ed89)
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  *	@(#)sysctl.h	8.1 (Berkeley) 6/2/93
35  * $FreeBSD$
36  */
37 
38 #ifndef _SYS_SYSCTL_H_
39 #define	_SYS_SYSCTL_H_
40 
41 #include <sys/queue.h>
42 
43 struct 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  */
62 struct 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(__aarch64__) || 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  */
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 	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 SLIST_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  */
180 struct 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 	const char	*oid_label;
195 };
196 
197 #define	SYSCTL_IN(r, p, l)	(r->newfunc)(r, p, l)
198 #define	SYSCTL_OUT(r, p, l)	(r->oldfunc)(r, p, l)
199 #define	SYSCTL_OUT_STR(r, p)	(r->oldfunc)(r, p, strlen(p) + 1)
200 
201 int sysctl_handle_bool(SYSCTL_HANDLER_ARGS);
202 int sysctl_handle_8(SYSCTL_HANDLER_ARGS);
203 int sysctl_handle_16(SYSCTL_HANDLER_ARGS);
204 int sysctl_handle_32(SYSCTL_HANDLER_ARGS);
205 int sysctl_handle_64(SYSCTL_HANDLER_ARGS);
206 int sysctl_handle_int(SYSCTL_HANDLER_ARGS);
207 int sysctl_msec_to_ticks(SYSCTL_HANDLER_ARGS);
208 int sysctl_handle_long(SYSCTL_HANDLER_ARGS);
209 int sysctl_handle_string(SYSCTL_HANDLER_ARGS);
210 int sysctl_handle_opaque(SYSCTL_HANDLER_ARGS);
211 int sysctl_handle_counter_u64(SYSCTL_HANDLER_ARGS);
212 int sysctl_handle_counter_u64_array(SYSCTL_HANDLER_ARGS);
213 
214 int sysctl_handle_uma_zone_max(SYSCTL_HANDLER_ARGS);
215 int sysctl_handle_uma_zone_cur(SYSCTL_HANDLER_ARGS);
216 
217 int sysctl_dpcpu_int(SYSCTL_HANDLER_ARGS);
218 int sysctl_dpcpu_long(SYSCTL_HANDLER_ARGS);
219 int sysctl_dpcpu_quad(SYSCTL_HANDLER_ARGS);
220 
221 /*
222  * These functions are used to add/remove an oid from the mib.
223  */
224 void sysctl_register_oid(struct sysctl_oid *oidp);
225 void sysctl_register_disabled_oid(struct sysctl_oid *oidp);
226 void sysctl_enable_oid(struct sysctl_oid *oidp);
227 void sysctl_unregister_oid(struct sysctl_oid *oidp);
228 
229 /* Declare a static oid to allow child oids to be added to it. */
230 #define	SYSCTL_DECL(name)			\
231 	extern struct sysctl_oid sysctl__##name
232 
233 /* Hide these in macros. */
234 #define	SYSCTL_CHILDREN(oid_ptr)		(&(oid_ptr)->oid_children)
235 #define	SYSCTL_PARENT(oid_ptr)					\
236     (((oid_ptr)->oid_parent != &sysctl__children) ?		\
237 	__containerof((oid_ptr)->oid_parent, struct sysctl_oid,	\
238 	oid_children) : (struct sysctl_oid *)NULL)
239 #define	SYSCTL_STATIC_CHILDREN(oid_name)	(&sysctl__##oid_name.oid_children)
240 
241 /* === Structs and macros related to context handling. === */
242 
243 /* All dynamically created sysctls can be tracked in a context list. */
244 struct sysctl_ctx_entry {
245 	struct sysctl_oid *entry;
246 	TAILQ_ENTRY(sysctl_ctx_entry) link;
247 };
248 
249 TAILQ_HEAD(sysctl_ctx_list, sysctl_ctx_entry);
250 
251 #define	SYSCTL_NODE_CHILDREN(parent, name) \
252 	sysctl__##parent##_##name.oid_children
253 
254 #ifndef NO_SYSCTL_DESCR
255 #define	__DESCR(d) d
256 #else
257 #define	__DESCR(d) ""
258 #endif
259 
260 /* This macro is only for internal use */
261 #define	SYSCTL_OID_RAW(id, parent_child_head, nbr, name, kind, a1, a2, handler, fmt, descr, label) \
262 	struct sysctl_oid id = {					\
263 		.oid_parent = (parent_child_head),			\
264 		.oid_children = SLIST_HEAD_INITIALIZER(&id.oid_children), \
265 		.oid_number = (nbr),					\
266 		.oid_kind = (kind),					\
267 		.oid_arg1 = (a1),					\
268 		.oid_arg2 = (a2),					\
269 		.oid_name = (name),					\
270 		.oid_handler = (handler),				\
271 		.oid_fmt = (fmt),					\
272 		.oid_descr = __DESCR(descr),				\
273 		.oid_label = (label),					\
274 	};								\
275 	DATA_SET(sysctl_set, id)
276 
277 /* This constructs a static "raw" MIB oid. */
278 #define	SYSCTL_OID(parent, nbr, name, kind, a1, a2, handler, fmt, descr) \
279 	SYSCTL_OID_WITH_LABEL(parent, nbr, name, kind, a1, a2,		\
280 	    handler, fmt, descr, NULL)
281 
282 #define	SYSCTL_OID_WITH_LABEL(parent, nbr, name, kind, a1, a2, handler, fmt, descr, label) \
283     static SYSCTL_OID_RAW(sysctl__##parent##_##name,			\
284 	SYSCTL_CHILDREN(&sysctl__##parent),				\
285 	nbr, #name, kind, a1, a2, handler, fmt, descr, label)
286 
287 /* This constructs a global "raw" MIB oid. */
288 #define	SYSCTL_OID_GLOBAL(parent, nbr, name, kind, a1, a2, handler, fmt, descr, label) \
289     SYSCTL_OID_RAW(sysctl__##parent##_##name, \
290 	SYSCTL_CHILDREN(&sysctl__##parent),	\
291 	nbr, #name, kind, a1, a2, handler, fmt, descr, label)
292 
293 #define	SYSCTL_ADD_OID(ctx, parent, nbr, name, kind, a1, a2, handler, fmt, descr) \
294 	sysctl_add_oid(ctx, parent, nbr, name, kind, a1, a2, handler, fmt, __DESCR(descr), NULL)
295 
296 /* This constructs a root node from which other nodes can hang. */
297 #define	SYSCTL_ROOT_NODE(nbr, name, access, handler, descr)	\
298 	SYSCTL_OID_RAW(sysctl___##name, &sysctl__children,	\
299 	    nbr, #name, CTLTYPE_NODE|(access), NULL, 0,		\
300 	    handler, "N", descr, NULL);				\
301 	CTASSERT(((access) & CTLTYPE) == 0 ||			\
302 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_NODE)
303 
304 /* This constructs a node from which other oids can hang. */
305 #define	SYSCTL_NODE(parent, nbr, name, access, handler, descr) \
306 	SYSCTL_NODE_WITH_LABEL(parent, nbr, name, access, handler, descr, NULL)
307 
308 #define	SYSCTL_NODE_WITH_LABEL(parent, nbr, name, access, handler, descr, label) \
309 	SYSCTL_OID_GLOBAL(parent, nbr, name, CTLTYPE_NODE|(access),	\
310 	    NULL, 0, handler, "N", descr, label);			\
311 	CTASSERT(((access) & CTLTYPE) == 0 ||				\
312 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_NODE)
313 
314 #define	SYSCTL_ADD_NODE(ctx, parent, nbr, name, access, handler, descr)	\
315 	SYSCTL_ADD_NODE_WITH_LABEL(ctx, parent, nbr, name, access, \
316 	    handler, descr, NULL)
317 
318 #define	SYSCTL_ADD_NODE_WITH_LABEL(ctx, parent, nbr, name, access, handler, descr, label) \
319 ({									\
320 	CTASSERT(((access) & CTLTYPE) == 0 ||				\
321 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_NODE);	\
322 	sysctl_add_oid(ctx, parent, nbr, name, CTLTYPE_NODE|(access),	\
323 	    NULL, 0, handler, "N", __DESCR(descr), label);		\
324 })
325 
326 #define	SYSCTL_ADD_ROOT_NODE(ctx, nbr, name, access, handler, descr)	\
327 ({									\
328 	CTASSERT(((access) & CTLTYPE) == 0 ||				\
329 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_NODE);	\
330 	sysctl_add_oid(ctx, &sysctl__children, nbr, name,		\
331 	    CTLTYPE_NODE|(access),					\
332 	    NULL, 0, handler, "N", __DESCR(descr), NULL);		\
333 })
334 
335 /* Oid for a string.  len can be 0 to indicate '\0' termination. */
336 #define	SYSCTL_STRING(parent, nbr, name, access, arg, len, descr)	\
337 	SYSCTL_OID(parent, nbr, name, CTLTYPE_STRING|(access),		\
338 	    arg, len, sysctl_handle_string, "A", descr);		\
339 	CTASSERT(((access) & CTLTYPE) == 0 ||				\
340 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_STRING)
341 
342 #define	SYSCTL_ADD_STRING(ctx, parent, nbr, name, access, arg, len, descr) \
343 ({									\
344 	char *__arg = (arg);						\
345 	CTASSERT(((access) & CTLTYPE) == 0 ||				\
346 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_STRING);	\
347 	sysctl_add_oid(ctx, parent, nbr, name, CTLTYPE_STRING|(access),	\
348 	    __arg, len, sysctl_handle_string, "A", __DESCR(descr),	\
349 	    NULL); \
350 })
351 
352 /* Oid for a bool.  If ptr is NULL, val is returned. */
353 #define	SYSCTL_NULL_BOOL_PTR ((bool *)NULL)
354 #define	SYSCTL_BOOL(parent, nbr, name, access, ptr, val, descr)	\
355 	SYSCTL_OID(parent, nbr, name,				\
356 	    CTLTYPE_U8 | CTLFLAG_MPSAFE | (access),		\
357 	    ptr, val, sysctl_handle_bool, "CU", descr);		\
358 	CTASSERT(((access) & CTLTYPE) == 0 &&			\
359 	    sizeof(bool) == sizeof(*(ptr)))
360 
361 #define	SYSCTL_ADD_BOOL(ctx, parent, nbr, name, access, ptr, val, descr) \
362 ({									\
363 	bool *__ptr = (ptr);						\
364 	CTASSERT(((access) & CTLTYPE) == 0);				\
365 	sysctl_add_oid(ctx, parent, nbr, name,				\
366 	    CTLTYPE_U8 | CTLFLAG_MPSAFE | (access),			\
367 	    __ptr, val, sysctl_handle_bool, "CU", __DESCR(descr),	\
368 	    NULL);							\
369 })
370 
371 /* Oid for a signed 8-bit int.  If ptr is NULL, val is returned. */
372 #define	SYSCTL_NULL_S8_PTR ((int8_t *)NULL)
373 #define	SYSCTL_S8(parent, nbr, name, access, ptr, val, descr)	\
374 	SYSCTL_OID(parent, nbr, name,				\
375 	    CTLTYPE_S8 | CTLFLAG_MPSAFE | (access),		\
376 	    ptr, val, sysctl_handle_8, "C", descr);		\
377 	CTASSERT((((access) & CTLTYPE) == 0 ||			\
378 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_S8) && \
379 	    sizeof(int8_t) == sizeof(*(ptr)))
380 
381 #define	SYSCTL_ADD_S8(ctx, parent, nbr, name, access, ptr, val, descr)	\
382 ({									\
383 	int8_t *__ptr = (ptr);						\
384 	CTASSERT(((access) & CTLTYPE) == 0 ||				\
385 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_S8);		\
386 	sysctl_add_oid(ctx, parent, nbr, name,				\
387 	    CTLTYPE_S8 | CTLFLAG_MPSAFE | (access),			\
388 	    __ptr, val, sysctl_handle_8, "C", __DESCR(descr), NULL);	\
389 })
390 
391 /* Oid for an unsigned 8-bit int.  If ptr is NULL, val is returned. */
392 #define	SYSCTL_NULL_U8_PTR ((uint8_t *)NULL)
393 #define	SYSCTL_U8(parent, nbr, name, access, ptr, val, descr)	\
394 	SYSCTL_OID(parent, nbr, name,				\
395 	    CTLTYPE_U8 | CTLFLAG_MPSAFE | (access),		\
396 	    ptr, val, sysctl_handle_8, "CU", descr);		\
397 	CTASSERT((((access) & CTLTYPE) == 0 ||			\
398 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_U8) && \
399 	    sizeof(uint8_t) == sizeof(*(ptr)))
400 
401 #define	SYSCTL_ADD_U8(ctx, parent, nbr, name, access, ptr, val, descr)	\
402 ({									\
403 	uint8_t *__ptr = (ptr);						\
404 	CTASSERT(((access) & CTLTYPE) == 0 ||				\
405 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_U8);		\
406 	sysctl_add_oid(ctx, parent, nbr, name,				\
407 	    CTLTYPE_U8 | CTLFLAG_MPSAFE | (access),			\
408 	    __ptr, val, sysctl_handle_8, "CU", __DESCR(descr), NULL);	\
409 })
410 
411 /* Oid for a signed 16-bit int.  If ptr is NULL, val is returned. */
412 #define	SYSCTL_NULL_S16_PTR ((int16_t *)NULL)
413 #define	SYSCTL_S16(parent, nbr, name, access, ptr, val, descr)	\
414 	SYSCTL_OID(parent, nbr, name,				\
415 	    CTLTYPE_S16 | CTLFLAG_MPSAFE | (access),		\
416 	    ptr, val, sysctl_handle_16, "S", descr);		\
417 	CTASSERT((((access) & CTLTYPE) == 0 ||			\
418 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_S16) && \
419 	    sizeof(int16_t) == sizeof(*(ptr)))
420 
421 #define	SYSCTL_ADD_S16(ctx, parent, nbr, name, access, ptr, val, descr)	\
422 ({									\
423 	int16_t *__ptr = (ptr);						\
424 	CTASSERT(((access) & CTLTYPE) == 0 ||				\
425 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_S16);		\
426 	sysctl_add_oid(ctx, parent, nbr, name,				\
427 	    CTLTYPE_S16 | CTLFLAG_MPSAFE | (access),			\
428 	    __ptr, val, sysctl_handle_16, "S", __DESCR(descr), NULL);	\
429 })
430 
431 /* Oid for an unsigned 16-bit int.  If ptr is NULL, val is returned. */
432 #define	SYSCTL_NULL_U16_PTR ((uint16_t *)NULL)
433 #define	SYSCTL_U16(parent, nbr, name, access, ptr, val, descr)	\
434 	SYSCTL_OID(parent, nbr, name,				\
435 	    CTLTYPE_U16 | CTLFLAG_MPSAFE | (access),		\
436 	    ptr, val, sysctl_handle_16, "SU", descr);		\
437 	CTASSERT((((access) & CTLTYPE) == 0 ||			\
438 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_U16) && \
439 	    sizeof(uint16_t) == sizeof(*(ptr)))
440 
441 #define	SYSCTL_ADD_U16(ctx, parent, nbr, name, access, ptr, val, descr)	\
442 ({									\
443 	uint16_t *__ptr = (ptr);					\
444 	CTASSERT(((access) & CTLTYPE) == 0 ||				\
445 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_U16);		\
446 	sysctl_add_oid(ctx, parent, nbr, name,				\
447 	    CTLTYPE_U16 | CTLFLAG_MPSAFE | (access),			\
448 	    __ptr, val, sysctl_handle_16, "SU", __DESCR(descr), NULL);	\
449 })
450 
451 /* Oid for a signed 32-bit int.  If ptr is NULL, val is returned. */
452 #define	SYSCTL_NULL_S32_PTR ((int32_t *)NULL)
453 #define	SYSCTL_S32(parent, nbr, name, access, ptr, val, descr)	\
454 	SYSCTL_OID(parent, nbr, name,				\
455 	    CTLTYPE_S32 | CTLFLAG_MPSAFE | (access),		\
456 	    ptr, val, sysctl_handle_32, "I", descr);		\
457 	CTASSERT((((access) & CTLTYPE) == 0 ||			\
458 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_S32) && \
459 	    sizeof(int32_t) == sizeof(*(ptr)))
460 
461 #define	SYSCTL_ADD_S32(ctx, parent, nbr, name, access, ptr, val, descr)	\
462 ({									\
463 	int32_t *__ptr = (ptr);						\
464 	CTASSERT(((access) & CTLTYPE) == 0 ||				\
465 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_S32);		\
466 	sysctl_add_oid(ctx, parent, nbr, name,				\
467 	    CTLTYPE_S32 | CTLFLAG_MPSAFE | (access),			\
468 	    __ptr, val, sysctl_handle_32, "I", __DESCR(descr), NULL);	\
469 })
470 
471 /* Oid for an unsigned 32-bit int.  If ptr is NULL, val is returned. */
472 #define	SYSCTL_NULL_U32_PTR ((uint32_t *)NULL)
473 #define	SYSCTL_U32(parent, nbr, name, access, ptr, val, descr)	\
474 	SYSCTL_OID(parent, nbr, name,				\
475 	    CTLTYPE_U32 | CTLFLAG_MPSAFE | (access),		\
476 	    ptr, val, sysctl_handle_32, "IU", descr);		\
477 	CTASSERT((((access) & CTLTYPE) == 0 ||			\
478 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_U32) && \
479 	    sizeof(uint32_t) == sizeof(*(ptr)))
480 
481 #define	SYSCTL_ADD_U32(ctx, parent, nbr, name, access, ptr, val, descr)	\
482 ({									\
483 	uint32_t *__ptr = (ptr);					\
484 	CTASSERT(((access) & CTLTYPE) == 0 ||				\
485 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_U32);		\
486 	sysctl_add_oid(ctx, parent, nbr, name,				\
487 	    CTLTYPE_U32 | CTLFLAG_MPSAFE | (access),			\
488 	    __ptr, val, sysctl_handle_32, "IU", __DESCR(descr), NULL);	\
489 })
490 
491 /* Oid for a signed 64-bit int.  If ptr is NULL, val is returned. */
492 #define	SYSCTL_NULL_S64_PTR ((int64_t *)NULL)
493 #define	SYSCTL_S64(parent, nbr, name, access, ptr, val, descr)	\
494 	SYSCTL_OID(parent, nbr, name,				\
495 	    CTLTYPE_S64 | CTLFLAG_MPSAFE | (access),		\
496 	    ptr, val, sysctl_handle_64, "Q", descr);		\
497 	CTASSERT((((access) & CTLTYPE) == 0 ||			\
498 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_S64) && \
499 	    sizeof(int64_t) == sizeof(*(ptr)))
500 
501 #define	SYSCTL_ADD_S64(ctx, parent, nbr, name, access, ptr, val, descr)	\
502 ({									\
503 	int64_t *__ptr = (ptr);						\
504 	CTASSERT(((access) & CTLTYPE) == 0 ||				\
505 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_S64);		\
506 	sysctl_add_oid(ctx, parent, nbr, name,				\
507 	    CTLTYPE_S64 | CTLFLAG_MPSAFE | (access),			\
508 	    __ptr, val, sysctl_handle_64, "Q", __DESCR(descr), NULL);	\
509 })
510 
511 /* Oid for an unsigned 64-bit int.  If ptr is NULL, val is returned. */
512 #define	SYSCTL_NULL_U64_PTR ((uint64_t *)NULL)
513 #define	SYSCTL_U64(parent, nbr, name, access, ptr, val, descr)	\
514 	SYSCTL_OID(parent, nbr, name,				\
515 	    CTLTYPE_U64 | CTLFLAG_MPSAFE | (access),		\
516 	    ptr, val, sysctl_handle_64, "QU", descr);		\
517 	CTASSERT((((access) & CTLTYPE) == 0 ||			\
518 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_U64) && \
519 	    sizeof(uint64_t) == sizeof(*(ptr)))
520 
521 #define	SYSCTL_ADD_U64(ctx, parent, nbr, name, access, ptr, val, descr)	\
522 ({									\
523 	uint64_t *__ptr = (ptr);					\
524 	CTASSERT(((access) & CTLTYPE) == 0 ||				\
525 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_U64);		\
526 	sysctl_add_oid(ctx, parent, nbr, name,				\
527 	    CTLTYPE_U64 | CTLFLAG_MPSAFE | (access),			\
528 	    __ptr, val, sysctl_handle_64, "QU", __DESCR(descr), NULL);	\
529 })
530 
531 /* Oid for an int.  If ptr is SYSCTL_NULL_INT_PTR, val is returned. */
532 #define	SYSCTL_NULL_INT_PTR ((int *)NULL)
533 #define	SYSCTL_INT(parent, nbr, name, access, ptr, val, descr) \
534 	SYSCTL_INT_WITH_LABEL(parent, nbr, name, access, ptr, val, descr, NULL)
535 
536 #define	SYSCTL_INT_WITH_LABEL(parent, nbr, name, access, ptr, val, descr, label) \
537 	SYSCTL_OID_WITH_LABEL(parent, nbr, name,			\
538 	    CTLTYPE_INT | CTLFLAG_MPSAFE | (access),			\
539 	    ptr, val, sysctl_handle_int, "I", descr, label);		\
540 	CTASSERT((((access) & CTLTYPE) == 0 ||				\
541 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_INT) && \
542 	    sizeof(int) == sizeof(*(ptr)))
543 
544 #define	SYSCTL_ADD_INT(ctx, parent, nbr, name, access, ptr, val, descr)	\
545 ({									\
546 	int *__ptr = (ptr);						\
547 	CTASSERT(((access) & CTLTYPE) == 0 ||				\
548 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_INT);		\
549 	sysctl_add_oid(ctx, parent, nbr, name,				\
550 	    CTLTYPE_INT | CTLFLAG_MPSAFE | (access),			\
551 	    __ptr, val, sysctl_handle_int, "I", __DESCR(descr), NULL);	\
552 })
553 
554 /* Oid for an unsigned int.  If ptr is NULL, val is returned. */
555 #define	SYSCTL_NULL_UINT_PTR ((unsigned *)NULL)
556 #define	SYSCTL_UINT(parent, nbr, name, access, ptr, val, descr)	\
557 	SYSCTL_OID(parent, nbr, name,				\
558 	    CTLTYPE_UINT | CTLFLAG_MPSAFE | (access),		\
559 	    ptr, val, sysctl_handle_int, "IU", descr);		\
560 	CTASSERT((((access) & CTLTYPE) == 0 ||			\
561 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_UINT) && \
562 	    sizeof(unsigned) == sizeof(*(ptr)))
563 
564 #define	SYSCTL_ADD_UINT(ctx, parent, nbr, name, access, ptr, val, descr) \
565 ({									\
566 	unsigned *__ptr = (ptr);					\
567 	CTASSERT(((access) & CTLTYPE) == 0 ||				\
568 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_UINT);	\
569 	sysctl_add_oid(ctx, parent, nbr, name,				\
570 	    CTLTYPE_UINT | CTLFLAG_MPSAFE | (access),			\
571 	    __ptr, val, sysctl_handle_int, "IU", __DESCR(descr), NULL);	\
572 })
573 
574 /* Oid for a long.  The pointer must be non NULL. */
575 #define	SYSCTL_NULL_LONG_PTR ((long *)NULL)
576 #define	SYSCTL_LONG(parent, nbr, name, access, ptr, val, descr)	\
577 	SYSCTL_OID(parent, nbr, name,				\
578 	    CTLTYPE_LONG | CTLFLAG_MPSAFE | (access),		\
579 	    ptr, val, sysctl_handle_long, "L", descr);		\
580 	CTASSERT((((access) & CTLTYPE) == 0 ||			\
581 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_LONG) && \
582 	    sizeof(long) == sizeof(*(ptr)))
583 
584 #define	SYSCTL_ADD_LONG(ctx, parent, nbr, name, access, ptr, descr)	\
585 ({									\
586 	long *__ptr = (ptr);						\
587 	CTASSERT(((access) & CTLTYPE) == 0 ||				\
588 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_LONG);	\
589 	sysctl_add_oid(ctx, parent, nbr, name,				\
590 	    CTLTYPE_LONG | CTLFLAG_MPSAFE | (access),			\
591 	    __ptr, 0, sysctl_handle_long, "L", __DESCR(descr), NULL);	\
592 })
593 
594 /* Oid for an unsigned long.  The pointer must be non NULL. */
595 #define	SYSCTL_NULL_ULONG_PTR ((unsigned long *)NULL)
596 #define	SYSCTL_ULONG(parent, nbr, name, access, ptr, val, descr)	\
597 	SYSCTL_OID(parent, nbr, name,					\
598 	    CTLTYPE_ULONG | CTLFLAG_MPSAFE | (access),			\
599 	    ptr, val, sysctl_handle_long, "LU", descr);			\
600 	CTASSERT((((access) & CTLTYPE) == 0 ||				\
601 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_ULONG) &&	\
602 	    sizeof(unsigned long) == sizeof(*(ptr)))
603 
604 #define	SYSCTL_ADD_ULONG(ctx, parent, nbr, name, access, ptr, descr)	\
605 ({									\
606 	unsigned long *__ptr = (ptr);					\
607 	CTASSERT(((access) & CTLTYPE) == 0 ||				\
608 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_ULONG);	\
609 	sysctl_add_oid(ctx, parent, nbr, name,				\
610 	    CTLTYPE_ULONG | CTLFLAG_MPSAFE | (access),			\
611 	    __ptr, 0, sysctl_handle_long, "LU", __DESCR(descr), NULL);	\
612 })
613 
614 /* Oid for a quad.  The pointer must be non NULL. */
615 #define	SYSCTL_NULL_QUAD_PTR ((int64_t *)NULL)
616 #define	SYSCTL_QUAD(parent, nbr, name, access, ptr, val, descr)	\
617 	SYSCTL_OID(parent, nbr, name,				\
618 	    CTLTYPE_S64 | CTLFLAG_MPSAFE | (access),		\
619 	    ptr, val, sysctl_handle_64, "Q", descr);		\
620 	CTASSERT((((access) & CTLTYPE) == 0 ||			\
621 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_S64) && \
622 	    sizeof(int64_t) == sizeof(*(ptr)))
623 
624 #define	SYSCTL_ADD_QUAD(ctx, parent, nbr, name, access, ptr, descr)	\
625 ({									\
626 	int64_t *__ptr = (ptr);						\
627 	CTASSERT(((access) & CTLTYPE) == 0 ||				\
628 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_S64);		\
629 	sysctl_add_oid(ctx, parent, nbr, name,				\
630 	    CTLTYPE_S64 | CTLFLAG_MPSAFE | (access),			\
631 	    __ptr, 0, sysctl_handle_64, "Q", __DESCR(descr), NULL);	\
632 })
633 
634 #define	SYSCTL_NULL_UQUAD_PTR ((uint64_t *)NULL)
635 #define	SYSCTL_UQUAD(parent, nbr, name, access, ptr, val, descr)	\
636 	SYSCTL_OID(parent, nbr, name,					\
637 	    CTLTYPE_U64 | CTLFLAG_MPSAFE | (access),			\
638 	     ptr, val, sysctl_handle_64, "QU", descr);			\
639 	CTASSERT((((access) & CTLTYPE) == 0 ||				\
640 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_U64) &&	\
641 	    sizeof(uint64_t) == sizeof(*(ptr)))
642 
643 #define	SYSCTL_ADD_UQUAD(ctx, parent, nbr, name, access, ptr, descr)	\
644 ({									\
645 	uint64_t *__ptr = (ptr);					\
646 	CTASSERT(((access) & CTLTYPE) == 0 ||				\
647 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_U64);		\
648 	sysctl_add_oid(ctx, parent, nbr, name,				\
649 	    CTLTYPE_U64 | CTLFLAG_MPSAFE | (access),			\
650 	    __ptr, 0, sysctl_handle_64, "QU", __DESCR(descr), NULL);	\
651 })
652 
653 /* Oid for a CPU dependent variable */
654 #define	SYSCTL_ADD_UAUTO(ctx, parent, nbr, name, access, ptr, descr)	\
655 ({									\
656 	struct sysctl_oid *__ret;					\
657 	CTASSERT((sizeof(uint64_t) == sizeof(*(ptr)) ||			\
658 	    sizeof(unsigned) == sizeof(*(ptr))) &&			\
659 	    ((access) & CTLTYPE) == 0);					\
660 	if (sizeof(uint64_t) == sizeof(*(ptr))) {			\
661 		__ret = sysctl_add_oid(ctx, parent, nbr, name,		\
662 		    CTLTYPE_U64 | CTLFLAG_MPSAFE | (access),		\
663 		    (ptr), 0, sysctl_handle_64, "QU",			\
664 		    __DESCR(descr), NULL);				\
665 	} else {							\
666 		__ret = sysctl_add_oid(ctx, parent, nbr, name,		\
667 		    CTLTYPE_UINT | CTLFLAG_MPSAFE | (access),		\
668 		    (ptr), 0, sysctl_handle_int, "IU",			\
669 		    __DESCR(descr), NULL);				\
670 	}								\
671 	__ret;								\
672 })
673 
674 /* Oid for a 64-bit unsigned counter(9).  The pointer must be non NULL. */
675 #define	SYSCTL_COUNTER_U64(parent, nbr, name, access, ptr, descr)	\
676 	SYSCTL_OID(parent, nbr, name,					\
677 	    CTLTYPE_U64 | CTLFLAG_MPSAFE | (access),			\
678 	    (ptr), 0, sysctl_handle_counter_u64, "QU", descr);		\
679 	CTASSERT((((access) & CTLTYPE) == 0 ||				\
680 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_U64) &&	\
681 	    sizeof(counter_u64_t) == sizeof(*(ptr)) &&			\
682 	    sizeof(uint64_t) == sizeof(**(ptr)))
683 
684 #define	SYSCTL_ADD_COUNTER_U64(ctx, parent, nbr, name, access, ptr, descr) \
685 ({									\
686 	counter_u64_t *__ptr = (ptr);					\
687 	CTASSERT(((access) & CTLTYPE) == 0 ||				\
688 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_U64);		\
689 	sysctl_add_oid(ctx, parent, nbr, name,				\
690 	    CTLTYPE_U64 | CTLFLAG_MPSAFE | (access),			\
691 	    __ptr, 0, sysctl_handle_counter_u64, "QU", __DESCR(descr),	\
692 	    NULL);							\
693 })
694 
695 /* Oid for an array of counter(9)s.  The pointer and length must be non zero. */
696 #define	SYSCTL_COUNTER_U64_ARRAY(parent, nbr, name, access, ptr, len, descr) \
697 	SYSCTL_OID(parent, nbr, name,					\
698 	    CTLTYPE_OPAQUE | CTLFLAG_MPSAFE | (access),			\
699 	    (ptr), (len), sysctl_handle_counter_u64_array, "S", descr);	\
700 	CTASSERT((((access) & CTLTYPE) == 0 ||				\
701 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_OPAQUE) &&	\
702 	    sizeof(counter_u64_t) == sizeof(*(ptr)) &&			\
703 	    sizeof(uint64_t) == sizeof(**(ptr)))
704 
705 #define	SYSCTL_ADD_COUNTER_U64_ARRAY(ctx, parent, nbr, name, access,	\
706     ptr, len, descr)							\
707 ({									\
708 	counter_u64_t *__ptr = (ptr);					\
709 	CTASSERT(((access) & CTLTYPE) == 0 ||				\
710 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_OPAQUE);	\
711 	sysctl_add_oid(ctx, parent, nbr, name,				\
712 	    CTLTYPE_OPAQUE | CTLFLAG_MPSAFE | (access),			\
713 	    __ptr, len, sysctl_handle_counter_u64_array, "S",		\
714 	    __DESCR(descr), NULL);					\
715 })
716 
717 /* Oid for an opaque object.  Specified by a pointer and a length. */
718 #define	SYSCTL_OPAQUE(parent, nbr, name, access, ptr, len, fmt, descr)	\
719 	SYSCTL_OID(parent, nbr, name, CTLTYPE_OPAQUE|(access),		\
720 	    ptr, len, sysctl_handle_opaque, fmt, descr);		\
721 	CTASSERT(((access) & CTLTYPE) == 0 ||				\
722 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_OPAQUE)
723 
724 #define	SYSCTL_ADD_OPAQUE(ctx, parent, nbr, name, access, ptr, len, fmt, descr)	\
725 ({									\
726 	CTASSERT(((access) & CTLTYPE) == 0 ||				\
727 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_OPAQUE);	\
728 	sysctl_add_oid(ctx, parent, nbr, name, CTLTYPE_OPAQUE|(access),	\
729 	    ptr, len, sysctl_handle_opaque, fmt, __DESCR(descr), NULL);	\
730 })
731 
732 /* Oid for a struct.  Specified by a pointer and a type. */
733 #define	SYSCTL_STRUCT(parent, nbr, name, access, ptr, type, descr)	\
734 	SYSCTL_OID(parent, nbr, name, CTLTYPE_OPAQUE|(access),		\
735 	    ptr, sizeof(struct type), sysctl_handle_opaque,		\
736 	    "S," #type, descr);						\
737 	CTASSERT(((access) & CTLTYPE) == 0 ||				\
738 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_OPAQUE)
739 
740 #define	SYSCTL_ADD_STRUCT(ctx, parent, nbr, name, access, ptr, type, descr) \
741 ({									\
742 	CTASSERT(((access) & CTLTYPE) == 0 ||				\
743 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_OPAQUE);	\
744 	sysctl_add_oid(ctx, parent, nbr, name, CTLTYPE_OPAQUE|(access),	\
745 	    (ptr), sizeof(struct type),					\
746 	    sysctl_handle_opaque, "S," #type, __DESCR(descr), NULL);	\
747 })
748 
749 /* Oid for a procedure.  Specified by a pointer and an arg. */
750 #define	SYSCTL_PROC(parent, nbr, name, access, ptr, arg, handler, fmt, descr) \
751 	SYSCTL_OID(parent, nbr, name, (access),				\
752 	    ptr, arg, handler, fmt, descr);				\
753 	CTASSERT(((access) & CTLTYPE) != 0)
754 
755 #define	SYSCTL_ADD_PROC(ctx, parent, nbr, name, access, ptr, arg, handler, fmt, descr) \
756 ({									\
757 	CTASSERT(((access) & CTLTYPE) != 0);				\
758 	sysctl_add_oid(ctx, parent, nbr, name, (access),		\
759 	    (ptr), (arg), (handler), (fmt), __DESCR(descr), NULL);	\
760 })
761 
762 /* Oid to handle limits on uma(9) zone specified by pointer. */
763 #define	SYSCTL_UMA_MAX(parent, nbr, name, access, ptr, descr)	\
764 	SYSCTL_OID(parent, nbr, name,				\
765 	    CTLTYPE_INT | CTLFLAG_MPSAFE | (access),		\
766 	    (ptr), 0, sysctl_handle_uma_zone_max, "I", descr);	\
767 	CTASSERT(((access) & CTLTYPE) == 0 ||			\
768 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_INT)
769 
770 #define	SYSCTL_ADD_UMA_MAX(ctx, parent, nbr, name, access, ptr, descr)	\
771 ({									\
772 	uma_zone_t __ptr = (ptr);					\
773 	CTASSERT(((access) & CTLTYPE) == 0 ||				\
774 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_INT);		\
775 	sysctl_add_oid(ctx, parent, nbr, name,				\
776 	    CTLTYPE_INT | CTLFLAG_MPSAFE | (access),			\
777 	    __ptr, 0, sysctl_handle_uma_zone_max, "I", __DESCR(descr),	\
778 	    NULL);							\
779 })
780 
781 /* Oid to obtain current use of uma(9) zone specified by pointer. */
782 #define	SYSCTL_UMA_CUR(parent, nbr, name, access, ptr, descr)		\
783 	SYSCTL_OID(parent, nbr, name,					\
784 	    CTLTYPE_INT | CTLFLAG_MPSAFE | CTLFLAG_RD | (access),	\
785 	    (ptr), 0, sysctl_handle_uma_zone_cur, "I", descr);		\
786 	CTASSERT(((access) & CTLTYPE) == 0 ||				\
787 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_INT)
788 
789 #define	SYSCTL_ADD_UMA_CUR(ctx, parent, nbr, name, access, ptr, descr)	\
790 ({									\
791 	uma_zone_t __ptr = (ptr);					\
792 	CTASSERT(((access) & CTLTYPE) == 0 ||				\
793 	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_INT);		\
794 	sysctl_add_oid(ctx, parent, nbr, name,				\
795 	    CTLTYPE_INT | CTLFLAG_MPSAFE | CTLFLAG_RD | (access),	\
796 	    __ptr, 0, sysctl_handle_uma_zone_cur, "I", __DESCR(descr),	\
797 	    NULL);							\
798 })
799 
800 /*
801  * A macro to generate a read-only sysctl to indicate the presence of optional
802  * kernel features.
803  */
804 #define	FEATURE(name, desc)						\
805 	SYSCTL_INT_WITH_LABEL(_kern_features, OID_AUTO, name,		\
806 	    CTLFLAG_RD | CTLFLAG_CAPRD, SYSCTL_NULL_INT_PTR, 1, desc, "feature")
807 
808 #endif /* _KERNEL */
809 
810 /*
811  * Top-level identifiers
812  */
813 #define	CTL_UNSPEC	0		/* unused */
814 #define	CTL_KERN	1		/* "high kernel": proc, limits */
815 #define	CTL_VM		2		/* virtual memory */
816 #define	CTL_VFS		3		/* filesystem, mount type is next */
817 #define	CTL_NET		4		/* network, see socket.h */
818 #define	CTL_DEBUG	5		/* debugging parameters */
819 #define	CTL_HW		6		/* generic cpu/io */
820 #define	CTL_MACHDEP	7		/* machine dependent */
821 #define	CTL_USER	8		/* user-level */
822 #define	CTL_P1003_1B	9		/* POSIX 1003.1B */
823 
824 /*
825  * CTL_KERN identifiers
826  */
827 #define	KERN_OSTYPE		 1	/* string: system version */
828 #define	KERN_OSRELEASE		 2	/* string: system release */
829 #define	KERN_OSREV		 3	/* int: system revision */
830 #define	KERN_VERSION		 4	/* string: compile time info */
831 #define	KERN_MAXVNODES		 5	/* int: max vnodes */
832 #define	KERN_MAXPROC		 6	/* int: max processes */
833 #define	KERN_MAXFILES		 7	/* int: max open files */
834 #define	KERN_ARGMAX		 8	/* int: max arguments to exec */
835 #define	KERN_SECURELVL		 9	/* int: system security level */
836 #define	KERN_HOSTNAME		10	/* string: hostname */
837 #define	KERN_HOSTID		11	/* int: host identifier */
838 #define	KERN_CLOCKRATE		12	/* struct: struct clockrate */
839 #define	KERN_VNODE		13	/* struct: vnode structures */
840 #define	KERN_PROC		14	/* struct: process entries */
841 #define	KERN_FILE		15	/* struct: file entries */
842 #define	KERN_PROF		16	/* node: kernel profiling info */
843 #define	KERN_POSIX1		17	/* int: POSIX.1 version */
844 #define	KERN_NGROUPS		18	/* int: # of supplemental group ids */
845 #define	KERN_JOB_CONTROL	19	/* int: is job control available */
846 #define	KERN_SAVED_IDS		20	/* int: saved set-user/group-ID */
847 #define	KERN_BOOTTIME		21	/* struct: time kernel was booted */
848 #define	KERN_NISDOMAINNAME	22	/* string: YP domain name */
849 #define	KERN_UPDATEINTERVAL	23	/* int: update process sleep time */
850 #define	KERN_OSRELDATE		24	/* int: kernel release date */
851 #define	KERN_NTP_PLL		25	/* node: NTP PLL control */
852 #define	KERN_BOOTFILE		26	/* string: name of booted kernel */
853 #define	KERN_MAXFILESPERPROC	27	/* int: max open files per proc */
854 #define	KERN_MAXPROCPERUID	28	/* int: max processes per uid */
855 #define	KERN_DUMPDEV		29	/* struct cdev *: device to dump on */
856 #define	KERN_IPC		30	/* node: anything related to IPC */
857 #define	KERN_DUMMY		31	/* unused */
858 #define	KERN_PS_STRINGS		32	/* int: address of PS_STRINGS */
859 #define	KERN_USRSTACK		33	/* int: address of USRSTACK */
860 #define	KERN_LOGSIGEXIT		34	/* int: do we log sigexit procs? */
861 #define	KERN_IOV_MAX		35	/* int: value of UIO_MAXIOV */
862 #define	KERN_HOSTUUID		36	/* string: host UUID identifier */
863 #define	KERN_ARND		37	/* int: from arc4rand() */
864 #define	KERN_MAXPHYS		38	/* int: MAXPHYS value */
865 /*
866  * KERN_PROC subtypes
867  */
868 #define	KERN_PROC_ALL		0	/* everything */
869 #define	KERN_PROC_PID		1	/* by process id */
870 #define	KERN_PROC_PGRP		2	/* by process group id */
871 #define	KERN_PROC_SESSION	3	/* by session of pid */
872 #define	KERN_PROC_TTY		4	/* by controlling tty */
873 #define	KERN_PROC_UID		5	/* by effective uid */
874 #define	KERN_PROC_RUID		6	/* by real uid */
875 #define	KERN_PROC_ARGS		7	/* get/set arguments/proctitle */
876 #define	KERN_PROC_PROC		8	/* only return procs */
877 #define	KERN_PROC_SV_NAME	9	/* get syscall vector name */
878 #define	KERN_PROC_RGID		10	/* by real group id */
879 #define	KERN_PROC_GID		11	/* by effective group id */
880 #define	KERN_PROC_PATHNAME	12	/* path to executable */
881 #define	KERN_PROC_OVMMAP	13	/* Old VM map entries for process */
882 #define	KERN_PROC_OFILEDESC	14	/* Old file descriptors for process */
883 #define	KERN_PROC_KSTACK	15	/* Kernel stacks for process */
884 #define	KERN_PROC_INC_THREAD	0x10	/*
885 					 * modifier for pid, pgrp, tty,
886 					 * uid, ruid, gid, rgid and proc
887 					 * This effectively uses 16-31
888 					 */
889 #define	KERN_PROC_VMMAP		32	/* VM map entries for process */
890 #define	KERN_PROC_FILEDESC	33	/* File descriptors for process */
891 #define	KERN_PROC_GROUPS	34	/* process groups */
892 #define	KERN_PROC_ENV		35	/* get environment */
893 #define	KERN_PROC_AUXV		36	/* get ELF auxiliary vector */
894 #define	KERN_PROC_RLIMIT	37	/* process resource limits */
895 #define	KERN_PROC_PS_STRINGS	38	/* get ps_strings location */
896 #define	KERN_PROC_UMASK		39	/* process umask */
897 #define	KERN_PROC_OSREL		40	/* osreldate for process binary */
898 #define	KERN_PROC_SIGTRAMP	41	/* signal trampoline location */
899 #define	KERN_PROC_CWD		42	/* process current working directory */
900 #define	KERN_PROC_NFDS		43	/* number of open file descriptors */
901 
902 /*
903  * KERN_IPC identifiers
904  */
905 #define	KIPC_MAXSOCKBUF		1	/* int: max size of a socket buffer */
906 #define	KIPC_SOCKBUF_WASTE	2	/* int: wastage factor in sockbuf */
907 #define	KIPC_SOMAXCONN		3	/* int: max length of connection q */
908 #define	KIPC_MAX_LINKHDR	4	/* int: max length of link header */
909 #define	KIPC_MAX_PROTOHDR	5	/* int: max length of network header */
910 #define	KIPC_MAX_HDR		6	/* int: max total length of headers */
911 #define	KIPC_MAX_DATALEN	7	/* int: max length of data? */
912 
913 /*
914  * CTL_HW identifiers
915  */
916 #define	HW_MACHINE	 1		/* string: machine class */
917 #define	HW_MODEL	 2		/* string: specific machine model */
918 #define	HW_NCPU		 3		/* int: number of cpus */
919 #define	HW_BYTEORDER	 4		/* int: machine byte order */
920 #define	HW_PHYSMEM	 5		/* int: total memory */
921 #define	HW_USERMEM	 6		/* int: non-kernel memory */
922 #define	HW_PAGESIZE	 7		/* int: software page size */
923 #define	HW_DISKNAMES	 8		/* strings: disk drive names */
924 #define	HW_DISKSTATS	 9		/* struct: diskstats[] */
925 #define	HW_FLOATINGPT	10		/* int: has HW floating point? */
926 #define	HW_MACHINE_ARCH	11		/* string: machine architecture */
927 #define	HW_REALMEM	12		/* int: 'real' memory */
928 
929 /*
930  * CTL_USER definitions
931  */
932 #define	USER_CS_PATH		 1	/* string: _CS_PATH */
933 #define	USER_BC_BASE_MAX	 2	/* int: BC_BASE_MAX */
934 #define	USER_BC_DIM_MAX		 3	/* int: BC_DIM_MAX */
935 #define	USER_BC_SCALE_MAX	 4	/* int: BC_SCALE_MAX */
936 #define	USER_BC_STRING_MAX	 5	/* int: BC_STRING_MAX */
937 #define	USER_COLL_WEIGHTS_MAX	 6	/* int: COLL_WEIGHTS_MAX */
938 #define	USER_EXPR_NEST_MAX	 7	/* int: EXPR_NEST_MAX */
939 #define	USER_LINE_MAX		 8	/* int: LINE_MAX */
940 #define	USER_RE_DUP_MAX		 9	/* int: RE_DUP_MAX */
941 #define	USER_POSIX2_VERSION	10	/* int: POSIX2_VERSION */
942 #define	USER_POSIX2_C_BIND	11	/* int: POSIX2_C_BIND */
943 #define	USER_POSIX2_C_DEV	12	/* int: POSIX2_C_DEV */
944 #define	USER_POSIX2_CHAR_TERM	13	/* int: POSIX2_CHAR_TERM */
945 #define	USER_POSIX2_FORT_DEV	14	/* int: POSIX2_FORT_DEV */
946 #define	USER_POSIX2_FORT_RUN	15	/* int: POSIX2_FORT_RUN */
947 #define	USER_POSIX2_LOCALEDEF	16	/* int: POSIX2_LOCALEDEF */
948 #define	USER_POSIX2_SW_DEV	17	/* int: POSIX2_SW_DEV */
949 #define	USER_POSIX2_UPE		18	/* int: POSIX2_UPE */
950 #define	USER_STREAM_MAX		19	/* int: POSIX2_STREAM_MAX */
951 #define	USER_TZNAME_MAX		20	/* int: POSIX2_TZNAME_MAX */
952 
953 #define	CTL_P1003_1B_ASYNCHRONOUS_IO		1	/* boolean */
954 #define	CTL_P1003_1B_MAPPED_FILES		2	/* boolean */
955 #define	CTL_P1003_1B_MEMLOCK			3	/* boolean */
956 #define	CTL_P1003_1B_MEMLOCK_RANGE		4	/* boolean */
957 #define	CTL_P1003_1B_MEMORY_PROTECTION		5	/* boolean */
958 #define	CTL_P1003_1B_MESSAGE_PASSING		6	/* boolean */
959 #define	CTL_P1003_1B_PRIORITIZED_IO		7	/* boolean */
960 #define	CTL_P1003_1B_PRIORITY_SCHEDULING	8	/* boolean */
961 #define	CTL_P1003_1B_REALTIME_SIGNALS		9	/* boolean */
962 #define	CTL_P1003_1B_SEMAPHORES			10	/* boolean */
963 #define	CTL_P1003_1B_FSYNC			11	/* boolean */
964 #define	CTL_P1003_1B_SHARED_MEMORY_OBJECTS	12	/* boolean */
965 #define	CTL_P1003_1B_SYNCHRONIZED_IO		13	/* boolean */
966 #define	CTL_P1003_1B_TIMERS			14	/* boolean */
967 #define	CTL_P1003_1B_AIO_LISTIO_MAX		15	/* int */
968 #define	CTL_P1003_1B_AIO_MAX			16	/* int */
969 #define	CTL_P1003_1B_AIO_PRIO_DELTA_MAX		17	/* int */
970 #define	CTL_P1003_1B_DELAYTIMER_MAX		18	/* int */
971 #define	CTL_P1003_1B_MQ_OPEN_MAX		19	/* int */
972 #define	CTL_P1003_1B_PAGESIZE			20	/* int */
973 #define	CTL_P1003_1B_RTSIG_MAX			21	/* int */
974 #define	CTL_P1003_1B_SEM_NSEMS_MAX		22	/* int */
975 #define	CTL_P1003_1B_SEM_VALUE_MAX		23	/* int */
976 #define	CTL_P1003_1B_SIGQUEUE_MAX		24	/* int */
977 #define	CTL_P1003_1B_TIMER_MAX			25	/* int */
978 
979 #define	CTL_P1003_1B_MAXID		26
980 
981 #ifdef _KERNEL
982 
983 /*
984  * Declare some common oids.
985  */
986 extern struct sysctl_oid_list sysctl__children;
987 SYSCTL_DECL(_kern);
988 SYSCTL_DECL(_kern_features);
989 SYSCTL_DECL(_kern_ipc);
990 SYSCTL_DECL(_kern_proc);
991 SYSCTL_DECL(_kern_sched);
992 SYSCTL_DECL(_kern_sched_stats);
993 SYSCTL_DECL(_sysctl);
994 SYSCTL_DECL(_vm);
995 SYSCTL_DECL(_vm_stats);
996 SYSCTL_DECL(_vm_stats_misc);
997 SYSCTL_DECL(_vfs);
998 SYSCTL_DECL(_net);
999 SYSCTL_DECL(_debug);
1000 SYSCTL_DECL(_debug_sizeof);
1001 SYSCTL_DECL(_dev);
1002 SYSCTL_DECL(_hw);
1003 SYSCTL_DECL(_hw_bus);
1004 SYSCTL_DECL(_hw_bus_devices);
1005 SYSCTL_DECL(_hw_bus_info);
1006 SYSCTL_DECL(_machdep);
1007 SYSCTL_DECL(_user);
1008 SYSCTL_DECL(_compat);
1009 SYSCTL_DECL(_regression);
1010 SYSCTL_DECL(_security);
1011 SYSCTL_DECL(_security_bsd);
1012 #ifdef EXT_RESOURCES
1013 SYSCTL_DECL(_clock);
1014 #endif
1015 
1016 extern char	machine[];
1017 extern char	osrelease[];
1018 extern char	ostype[];
1019 extern char	kern_ident[];
1020 
1021 /* Dynamic oid handling */
1022 struct sysctl_oid *sysctl_add_oid(struct sysctl_ctx_list *clist,
1023 	    struct sysctl_oid_list *parent, int nbr, const char *name, int kind,
1024 	    void *arg1, intmax_t arg2, int (*handler)(SYSCTL_HANDLER_ARGS),
1025 	    const char *fmt, const char *descr, const char *label);
1026 int	sysctl_remove_name(struct sysctl_oid *parent, const char *name, int del,
1027 	    int recurse);
1028 void	sysctl_rename_oid(struct sysctl_oid *oidp, const char *name);
1029 int	sysctl_move_oid(struct sysctl_oid *oidp,
1030 	    struct sysctl_oid_list *parent);
1031 int	sysctl_remove_oid(struct sysctl_oid *oidp, int del, int recurse);
1032 int	sysctl_ctx_init(struct sysctl_ctx_list *clist);
1033 int	sysctl_ctx_free(struct sysctl_ctx_list *clist);
1034 struct	sysctl_ctx_entry *sysctl_ctx_entry_add(struct sysctl_ctx_list *clist,
1035 	    struct sysctl_oid *oidp);
1036 struct	sysctl_ctx_entry *sysctl_ctx_entry_find(struct sysctl_ctx_list *clist,
1037 	    struct sysctl_oid *oidp);
1038 int	sysctl_ctx_entry_del(struct sysctl_ctx_list *clist,
1039 	    struct sysctl_oid *oidp);
1040 
1041 int	kernel_sysctl(struct thread *td, int *name, u_int namelen, void *old,
1042 	    size_t *oldlenp, void *new, size_t newlen, size_t *retval,
1043 	    int flags);
1044 int	kernel_sysctlbyname(struct thread *td, char *name, void *old,
1045 	    size_t *oldlenp, void *new, size_t newlen, size_t *retval,
1046 	    int flags);
1047 int	userland_sysctl(struct thread *td, int *name, u_int namelen, void *old,
1048 	    size_t *oldlenp, int inkernel, void *new, size_t newlen,
1049 	    size_t *retval, int flags);
1050 int	sysctl_find_oid(int *name, u_int namelen, struct sysctl_oid **noid,
1051 	    int *nindx, struct sysctl_req *req);
1052 void	sysctl_wlock(void);
1053 void	sysctl_wunlock(void);
1054 int	sysctl_wire_old_buffer(struct sysctl_req *req, size_t len);
1055 
1056 struct sbuf;
1057 struct sbuf *sbuf_new_for_sysctl(struct sbuf *, char *, int,
1058 	    struct sysctl_req *);
1059 #else	/* !_KERNEL */
1060 #include <sys/cdefs.h>
1061 
1062 __BEGIN_DECLS
1063 int	sysctl(const int *, u_int, void *, size_t *, const void *, size_t);
1064 int	sysctlbyname(const char *, void *, size_t *, const void *, size_t);
1065 int	sysctlnametomib(const char *, int *, size_t *);
1066 __END_DECLS
1067 #endif	/* _KERNEL */
1068 
1069 #endif	/* !_SYS_SYSCTL_H_ */
1070